Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
0.8.3:inventory [2020/11/17 18:53] – external edit 127.0.0.10.8.3:inventory [2021/09/03 13:09] – [Visual Items] admin
Line 366: Line 366:
 | TInventoryGroup | A inventory grouping component. Use this component to categorize your collected items into groups. | | TInventoryGroup | A inventory grouping component. Use this component to categorize your collected items into groups. |
 | TInventoryCollectedItem | A custom collected item component. Use this component as basis for all of your collected items. | | TInventoryCollectedItem | A custom collected item component. Use this component as basis for all of your collected items. |
 +==== Visual Items ====
 +
 +To allow better abstraction and separation between the logical and the visual part of an inventory, we introduced visual items in v0.8.3.1812+.
 +You can now define 3 levels of detail plus a model filename for each visual item. (This may be extended in future releases.)
 +
 +A visual item standalone entity inside of the inventory component and can be freely linked by image-index of each item template.
 +You can also link different item templates to the same visual item.
 +
 +To add a visual item at runtime, use the following code:
 +
 +<file pascal>
 +/// add a visual representation for an axe
 +GorillaInventory1.AddVisualItem(0, 'Item1', 'item1_lod0.png', 'item1_lod1.png', 'item1_lod2.png', 'axe.obj');
 +
 +/// add a visual representation for a pickaxe
 +GorillaInventory1.AddVisualItem(1, 'Item2', 'item2_lod0.png', 'item2_lod1.png', 'item2_lod2.png', 'pickaxe.obj');
 +</file>
 +
 +To remove a visual item, use:
 +<file pascal>
 +/// add a visual representation for an axe
 +GorillaInventory1.RemoveVisualItem('Item1');
 +</file>
 +
 +This is also the first step to work together with asset packages. At the moment you can use the "OnLoadResource" callback event of your inventory component. This is getting called on each visual item resource request.
 +
 +<file pascal>
 +[...]
 +
 +GorillaInventory.OnLoadResource := DoOnInventoryLoadResource;
 +
 +[...]
 +
 +procedure TForm1.DoOnInventoryLoadResource(const AInventory : TGorillaInventory;
 +    const AResIdx : Integer; const AResource : String;
 +    const AItem : TGorillaInventoryVisualItem; const ADestBitmap : TBitmap);
 +var LPckg : TGorillaAssetsPackage;
 +    LAsset : TGorillaAsset;
 +    LBmp : FMX.Graphics.TBitmap;
 +begin
 +  LPckg := GorillaAssetsManager1.GetPackage('InMemory');
 +  if not Assigned(LPckg) then
 +    raise Exception.Create('package "InMemory" not found');
 +    
 +  LAsset := LPckg.FindAsset(AResource);
 +  if not Assigned(LAsset) then
 +    raise Exception.CreateFmt('asset "%s" not found', [AResource]);
 +    
 +  if not (LAsset is TGorillaTextureAsset) then
 +    raise Exception.CreateFmt('asset "%s" not a valid texture asset', [AResource]);
 +    
 +  LBmp := TGorillaTextureAsset(LAsset).GetBitmap();
 +  try
 +    ADestBitmap.Assign(LBmp);
 +  finally
 +    FreeAndNil(LBmp);
 +  end;
 +end;
 +</file>
 ==== Inventory-Designer ==== ==== Inventory-Designer ====