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] |
|
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 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 |
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.
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
In this case you will also have to call
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.
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:
When it comes to actually combining the items you will have to use the Combine
method.
or alternatively
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.
Finally, add the event handler to the inventory script.