Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
inventory [2019/04/10 08:52] – [Crafting] admin | inventory [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Inventory-System ====== | ||
- | Besides 3D features Gorilla3D also provides basic utility components like the inventory system. | ||
- | Most games or multimedia apps need some kind of inventory or item management. | ||
- | |||
- | By the **TGorillaInventory** component you are able to: | ||
- | |||
- | * | ||
- | * hold items with thumbnail and preview models | ||
- | * | ||
- | * | ||
- | * have up- and downgradable items | ||
- | * setup manufacturers for crafting and item combinations | ||
- | * | ||
- | * craft items in editable time in asynchrone backend thread | ||
- | * | ||
- | * | ||
- | * | ||
- | * | ||
- | * set variables to implement gaming elements | ||
- | * set parameters to interact back with your game/ | ||
- | |||
- | ===== Layout ===== | ||
- | |||
- | An inventory consists of 3 basic components: | ||
- | * item templates | ||
- | * item groups | ||
- | * manufacturers | ||
- | |||
- | First of all the inventory needs to know all possible items. These are called item templates. | ||
- | Item templates can be linked to item groups, to somehow categorize your collection. | ||
- | If you are interested in crafting or combining, manufacturers come in place. | ||
- | |||
- | ==== Item Template ==== | ||
- | An item template holds information about the item itself. For example: a maximum global number of elements, its weight or dependencies to other items. | ||
- | |||
- | See in the following how you can add templates at runtime. | ||
- | <file pascal> | ||
- | uses | ||
- | Gorilla.Utils.Inventory, | ||
- | Gorilla.Utils.Language; | ||
- | |||
- | var | ||
- | FInventory : TGorillaInventory; | ||
- | |||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LMainGrp | ||
- | LAxe : TGorillaInventoryItemTemplate; | ||
- | LWood : TGorillaInventoryItemTemplate; | ||
- | LGrass : TGorillaInventoryItemTemplate; | ||
- | begin | ||
- | // create inventory system | ||
- | FInventory := TGorillaInventory.Create(Self); | ||
- | | ||
- | // we need a first group, where the templates belong to | ||
- | LMainGrp := FInventory.AddGroup(' | ||
- | |||
- | // get the language identifiers | ||
- | LLangEN_US := GetLanguageName(GORILLA_LANG_EN_US); | ||
- | LLangDE_DE := GetLanguageName(GORILLA_LANG_DE_DE); | ||
- | |||
- | // create the axe item template | ||
- | LAxe := FInventory.AddItemTemplate(' | ||
- | LAxe.Group := LMainGrp; | ||
- | LAxe.ImageIndex := 4; | ||
- | // add multilingual texts | ||
- | LAxe.Name.Add(LLangEN_US, | ||
- | LAxe.Name.Add(LLangDE_DE, | ||
- | // set quantity and weight values | ||
- | LAxe.MaxQuantity := 1; | ||
- | LAxe.Weight := 1; | ||
- | LAxe.MaxWeight := 1; | ||
- | |||
- | // create the wood item template | ||
- | LWood := FInventory.AddItemTemplate(' | ||
- | LWood.Group := LMainGrp; | ||
- | LWood.ImageIndex := 0; | ||
- | // we collect wood, but it will be stacked | ||
- | LWood.IsPooled := true; | ||
- | // add dependency to an axe - only if we have an axe collected, we can colled wood | ||
- | LWood.AddDependency(LAxe, | ||
- | // add multilingual texts | ||
- | LWood.Name.Add(LLangEN_US, | ||
- | LWood.Name.Add(LLangDE_DE, | ||
- | | ||
- | // create a grass item template | ||
- | LGrass := FInventory.AddItemTemplate(' | ||
- | LGrass.Group := LMainGrp; | ||
- | LGrass.ImageIndex := 2; | ||
- | LGrass.Name.Add(LLangEN_US, | ||
- | LGrass.Name.Add(LLangDE_DE, | ||
- | end; | ||
- | </ | ||
- | ==== Item Group ==== | ||
- | As seen above we can simply add item groups at runtime and attach them to items. | ||
- | |||
- | <file pascal> | ||
- | LMainGrp := FInventory.AddGroup(' | ||
- | </ | ||
- | <file pascal> | ||
- | LWood.Group := LMainGrp; | ||
- | </ | ||
- | ==== Manufacturer ==== | ||
- | |||
- | Manufacturers allow us to craft, combine or up-/ | ||
- | As mentioned also this resulting items need to be registered as templates in the inventory. | ||
- | |||
- | === Crafting === | ||
- | <file pascal> | ||
- | LFire : TGorillaInventoryItemTemplate; | ||
- | LMan : TGorillaInventoryManufacturer; | ||
- | | ||
- | [...] | ||
- | | ||
- | // register the resulting fire item template | ||
- | LFire := FInventory.AddItemTemplate(' | ||
- | LFire.Group := LMainGrp; | ||
- | LFire.ImageIndex := 3; | ||
- | LFire.Name.Add(LLangEN_US, | ||
- | LFire.Name.Add(LLangDE_DE, | ||
- | | ||
- | // add a new manufacturer | ||
- | LMan := FInventory.AddManufacturer(' | ||
- | | ||
- | // setup a time for how long the manufacturing process takes (in milliseconds) | ||
- | LMan.TimeNeeded := 10000; | ||
- | | ||
- | // add items which are necessary to build a result item | ||
- | LMan.AddIngredient(LWood, | ||
- | LMan.AddIngredient(LGrass, | ||
- | | ||
- | // set the resulting item template | ||
- | LMan.ResultItem.Template := LFire; | ||
- | </ | ||
- | |||
- | ==== Up-/ | ||
- | |||
- | To allow up-/ | ||
- | |||
- | <file pascal> | ||
- | // register the upgrade item template | ||
- | LChimney := FInventory.AddItemTemplate(' | ||
- | LChimney.Group := LMainGrp; | ||
- | LChimney.ImageIndex := 6; | ||
- | | ||
- | // link with fire template for possible downgrade | ||
- | LChimney.DowngradeItem := LFire; | ||
- | | ||
- | LChimney.Name.Add(LLangEN_US, | ||
- | LChimney.Name.Add(LLangDE_DE, | ||
- | |||
- | // link with chimney template for possible upgrade | ||
- | LFire.UpgradeItem := LChimney; | ||
- | </ | ||
- | |||
- | |||
- | ==== Multilingual ==== | ||
- | |||
- | The component supports multilingual text content for your items and groups names. | ||
- | To set the value for a specific language we need the language-name, | ||
- | By this index we can set a multilingual name for the item as shown below: | ||
- | |||
- | <file pascal> | ||
- | uses | ||
- | Gorilla.Utils.Language; | ||
- | |||
- | var LLangEN_US, | ||
- | LLangDE_DE : String; | ||
- | | ||
- | LLangEN_US := GetLanguageName(GORILLA_LANG_EN_US); | ||
- | LLangDE_DE := GetLanguageName(GORILLA_LANG_DE_DE); | ||
- | |||
- | [...] | ||
- | LAxe.Name.Add(LLangEN_US, | ||
- | LAxe.Name.Add(LLangDE_DE, | ||
- | </ | ||
- | |||
- | In the inventory component itself we can set the active language. | ||
- | This is the base setting for auto-language detection by the user-interface. | ||
- | |||
- | <file pascal> | ||
- | FInventory.Language := GORILLA_LANG_EN_US; | ||
- | </ | ||
- | |||
- | Currently supported languages are: | ||
- | |||
- | ^Language ^ID ^ | ||
- | | english | GORILLA_LANG_EN_US | | ||
- | | english | GORILLA_LANG_EN_UK | | ||
- | | german | GORILLA_LANG_DE_DE | | ||
- | | german | GORILLA_LANG_DE_AT | | ||
- | | german | GORILLA_LANG_DE_CH | | ||
- | ==== Collect ==== | ||
- | |||
- | Collecting items is the most used feature of the inventory component running your app. | ||
- | Due to settings it is not always possible to really collect an item. | ||
- | Imagine, you already have 10 blocks of wood and the maximum is reached. | ||
- | |||
- | Until you can collect an item you'll need the item template to supply to the Collect() method. | ||
- | Afterwards the method will output a state value, telling you if collecting was successful. | ||
- | |||
- | Take a look at the following code: | ||
- | |||
- | <file pascal> | ||
- | procedure TForm1.Button1Click(Sender: | ||
- | var LIdx : Integer; | ||
- | LTemp : TGorillaInventoryItemTemplate; | ||
- | LState : TGorillaInventoryCollectState; | ||
- | begin | ||
- | // select a specific item template from a combobox | ||
- | LIdx := TemplateSelector.ItemIndex; | ||
- | if (LIdx < 0) then | ||
- | Exit; | ||
- | |||
- | LTemp := TemplateSelector.Items.Objects[LIdx] as TGorillaInventoryItemTemplate; | ||
- | | ||
- | // run the collecting process | ||
- | FInventory.Collect(LTemp, | ||
- | | ||
- | // check feedback | ||
- | if (LState <> TGorillaInventoryCollectState.Collected) then | ||
- | begin | ||
- | ShowMessage(' | ||
- | GetEnumName(TypeInfo(TGorillaInventoryCollectState), | ||
- | Exit; | ||
- | end; | ||
- | | ||
- | // update the user-interface | ||
- | FIFrame.UpdateInventory(); | ||
- | end; | ||
- | </ | ||
- | ==== Drop ==== | ||
- | |||
- | In some cases you'll need a method to release collected items from your inventory. | ||
- | Maybe you have a weight managed inventory and need more space, or you just lose an items due to some story event in your game. | ||
- | |||
- | <file pascal> | ||
- | procedure TForm1.MenuItem6Click(Sender: | ||
- | var LColl : TGorillaInventoryCollectable; | ||
- | LCount : Integer; | ||
- | begin | ||
- | // get the collected item you want to release | ||
- | LColl := [...] | ||
- | |||
- | // check if it is a pooled item and we want to release all of it | ||
- | LCount := -1; | ||
- | if LColl.Template.IsPooled then | ||
- | begin | ||
- | if (FMX.DialogService.Sync.TDialogServiceSync.MessageDialog( | ||
- | 'Would you like to drop all instances of that item?', | ||
- | TMsgDlgType.mtConfirmation, | ||
- | begin | ||
- | LCount := 1; | ||
- | end; | ||
- | end; | ||
- | |||
- | // drop the item with a supplied count of it | ||
- | FInventory.DropCollectedItem(LColl, | ||
- | | ||
- | // update the user-interface | ||
- | FIFrame.UpdateInventory(); | ||
- | end; | ||
- | </ | ||
- | ==== Manufacture ==== | ||
- | === Manufacture manually === | ||
- | Manually means, you are selecting the itended manufacturer and supply a number of collected items. The Manufacture() method will return a process instance and start building. | ||
- | Depending on your settings this can take some time. Because in most cases you'd like to simulate realistic manufacturing. | ||
- | |||
- | You will receive nil as result of Manufacture() if ingredients are missing or supplied items are not suitable. | ||
- | |||
- | <file pascal> | ||
- | procedure TForm1.Button4Click(Sender: | ||
- | var LMan : TGorillaInventoryManufacturer; | ||
- | LProc : TGorillaInventoryManufacturingProcess; | ||
- | begin | ||
- | // manufacture with a specific manufacturer | ||
- | if Assigned(ManufacturerSelector.Selected) then | ||
- | begin | ||
- | LMan := ManufacturerSelector.Selected.Data as TGorillaInventoryManufacturer; | ||
- | if Assigned(LMan) then | ||
- | begin | ||
- | LProc := FInventory.Manufacture(LMan, | ||
- | if not Assigned(LProc) then | ||
- | begin | ||
- | ShowMessage(' | ||
- | end; | ||
- | end; | ||
- | end | ||
- | else ShowMessage(' | ||
- | end; | ||
- | </ | ||
- | |||
- | === Manufacture automatically === | ||
- | |||
- | The Gorilla3D inventory component allows to automatically manufacture items by a supplied array of items. This means: It will automatically detect the first suitable manufacturer by the provided items and start the process. | ||
- | |||
- | The method returns a process instance in case the manufacturing was started. | ||
- | |||
- | <file pascal> | ||
- | procedure TForm1.Button2Click(Sender: | ||
- | var LProc : TGorillaInventoryManufacturingProcess; | ||
- | begin | ||
- | // start manufacturing process by automatically detecting | ||
- | LProc := FInventory.Manufacture( | ||
- | FInventory.CollectedItems.ToArray() | ||
- | ); | ||
- | |||
- | // if result was nil, no suitable manufacturer could be found | ||
- | if not Assigned(LProc) then | ||
- | begin | ||
- | ShowMessage(' | ||
- | end; | ||
- | end; | ||
- | </ | ||
- | ==== UserInterface ==== | ||
- | |||
- | The inventory component is a non-visual component which needs an user-interface to make your items visible. | ||
- | You can extend the **TInventoryFrame** [Gorilla.UI.Inventory] component to build your own user-interface. | ||
- | ==== Inventory-Designer ==== | ||
- | |||
- | We offer a free ui-tool for easy inventory design. You can save your designed inventory to file and load it in your application. | ||
- | |||
- | {{:: | ||
- | {{:: | ||
- | {{:: | ||
- | {{:: | ||
- | |||
- | The tool provides a sandbox mode, where you can test your item and manufacturer settings directly. | ||
- | |||
- | Inventory-Files are also supported in AssetsManager packages, so you add those to your application package without extra file handling. |