Inventory

The inventory screen and all elements shown in the inventory are defined in the inventory INI file (as specified in the language.ini file; inventory.ini by default) located in the install folder. The behaviour of the inventory is controlled via scripting.

General Inventory Definitions


[General]
script script controlling the behaviour of the inventory (required)
gamestate defines the game state whose default window is used as parent for the inventory window; use dialog for the dialog game state, play for the play game state (required)
showalways true to always show the inventory in play state (optional, default is false)
slotmanagement true to automatically rearrange DragContainer based Inventory Elements so that there are no empty slots between them; requires the slots to be named and arranged in a sequential order (optional, default is false)

[Schemes]

section to define all CEGUI schemes required by the inventory
... any scheme required by the inventory (optional)

[Layouts]

section to define any CEGUI layout required by the inventory
main main layout displayed when activating the inventory (required)
... any other layout that may be needed for the inventory (optional)

Inventory Item Definitions

Inventory items can be either represented by a DragContainer or an ItemEntry window. All element definitions start with a section name corresponding to the attribute definition in the AttributeInfoFile and have the following parameters:

category user defined string that may, for example, be used to group items
window window representing item (DragContainer or ItemEntry)
textwindow window displaying item text
valuewindow window displaying item value (value gets updated automatically upon changes)
tooltip tooltip text section in the inventory text file
parentwindow base name of parent window if window is a Dragcontainer (an increasing index starting with 0 will be appended to this name) or
name of containing ItemListbox if window is an ItemEntry

Inventory Text

The text used in the inventory is defined in a utf-8 encoded inventory text file as specified in the language.ini file. This allows for each language you wish to support to have its own text file.

Each text snippet in the inventory text file is defined by a section declaration followed by the actual text. If a section name matches one of the attribute definitions in the AttributeInfoFile its text will be automatically used in the textwindow of the corresponding Inventory Element.

The character sequence <CR> indicates a new line in the inventory text and must be placed on a separate line in the TXT file. The expression <Player> will be replaced automatically with the player's name.

Inventory Script

Note:
All orders and variables in conversation, inventory and message scripts are globally visible, hence they all must have unique names.
Exception: All GUI related scripts may contain an initialization order named main. This order will be executed once when the corresponding game component is created and the script is loaded. Afterwards this order is inaccessible.

The inventory script executes at low level and is mainly driven by GUI events. When the inventory is invoked the main inventory layout will receive a show command (unless it is placed on the play state default window and the showalways flag is true). You can react to this event by binding a script method to the Shown event (see GUI Event Reference and Handling GUI Events from Simkin). For an inventory living in the dialog state this is a required task, because you explicitly have to switch to the dialog state by using

DialogState.Enter();

In this case you will also have to call

DialogState.Exit();

upon exiting the inventory to return to the play state.

The Global Script Object Inventory provides access to the inventory items and text. You can use the InventoryItem class to manipulate or get information about individual items. Items can be made combinable by using the AddCombination method.

Example

Suppose you want to combine a rubber band [rubberband] with a V-shaped branch [branch] to create a slingshot [slingshot]. The following code fragment will enable this combination:

rb = Inventory.GetItem("rubberband");
rb.AddCombination("branch", "slingshot");

When it comes to actually combining the items you will have to use the Combine method.

Inventory.GetItem("rubberband").Combine("branch");

or alternatively

Inventory.GetItem("branch").Combine("rubberband");

This will increase the amount of the slingshot attribute by one and decrease the amount of both, the rubberband and branch attribute, by one.

It is up to you to choose the event that triggers the combination. In case of DragContainers representing the items you may for example bind an event handler to the DragDropItemDropped event of the DragContainer like this:

Add the item definition to the inventory INI file.

[rubberband]
category = combinable
window = Item/RubberBand
textwindow = Item/RubberBand
valuewindow = Item/RubberBand/Value
tooltip = rubberband_tt
parentwindow = Inventory/MainWindow/Slot

Define the window representing the item in the inventory layout file and bind the script method to the DragDropItemDropped event.

<Window Type="DragContainer" Name="Item/RubberBand" >
<Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.05,0},{0.95,0},{0.95,0}" />
<Event Name="DragDropItemDropped" Function="Inventory_OnItemCombine" />
<Window Type="RFLook/StaticImage" Name="Item/RubberBand/Image" >
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}" />
<Property Name="Image" Value="set:ItemIcons image:RubberBand" />
<Property Name="MousePassThroughEnabled" Value="True" />
<Window Type="RFLook/StaticText" Name="Item/RubberBand/Value" >
<Property Name="Text">-1</Property>
<Property Name="FrameEnabled" Value="False" />
<Property Name="HorzFormatting" Value="RightAligned" />
<Property Name="VertFormatting" Value="VertCentred" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.7,0},{0.7,0},{0.9,0},{0.9,0}}" />
<Property Name="BackgroundEnabled" Value="False" />
</Window>
</Window>
</Window>

Finally, add the event handler to the inventory script.

Inventory_OnItemCombine[(eargs)
{
dd_args = GUI.toDragDropEventArgs(eargs);
item0 = Inventory.GetItem(dd_args.window);
item1 = Inventory.GetItem(dd_args.dragDropItem);
if(item0 != null and item1 != null)
{
item0.Combine(item1);
}
}]