Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
0.8.3:inventory [2021/09/03 12:59] – [Inventory-Designer] admin0.8.3:inventory [2021/09/03 13:11] (current) – [Visual Items] admin
Line 370: Line 370:
 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+. 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.) You can now define 3 levels of detail plus a model filename for each visual item. (This may be extended in future releases.)
- 
-This is also the first step to work together with a specific assets package. At the moment use the "OnLoadResource" callback event of your inventory component. This is getting called on each visual item resource request. 
  
 A visual item standalone entity inside of the inventory component and can be freely linked by image-index of each item template. A visual item standalone entity inside of the inventory component and can be freely linked by image-index of each item template.
Line 386: Line 384:
 </file> </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>
 +[...]
 +
 +/// define callback event for assets loading
 +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
 +  /// get your package previously created
 +  LPckg := GorillaAssetsManager1.GetPackage('InMemory');
 +  if not Assigned(LPckg) then
 +    raise Exception.Create('package "InMemory" not found');
 +    
 +  /// try to find an asset by resource filename + extension
 +  LAsset := LPckg.FindAsset(AResource);
 +  if not Assigned(LAsset) then
 +    raise Exception.CreateFmt('asset "%s" not found', [AResource]);
 +    
 +  /// check if it really is a texture / image asset
 +  if not (LAsset is TGorillaTextureAsset) then
 +    raise Exception.CreateFmt('asset "%s" not a valid texture asset', [AResource]);
 +    
 +  /// copy the image to inventory image (duplication!)
 +  LBmp := TGorillaTextureAsset(LAsset).GetBitmap();
 +  try
 +    ADestBitmap.Assign(LBmp);
 +  finally
 +    FreeAndNil(LBmp);
 +  end;
 +end;
 +</file>
 ==== Inventory-Designer ==== ==== Inventory-Designer ====