Package menu

Class MacaoInventory

Inherited from MacaoMenu

          Using the Inventory
          Inventory Items with a Quantity
          Adding an Inventory to your Page
          Initializing Inventory Items
          Storing the Inventory Content

Constructor   Methods

Create a MacaoInventory in one frame of your frameset. The inventory can be used to place items, which the user takes from page to page.

Using the Inventory

You can call the method addInventoryItem() to add items to the inventory. The item is normally represented by an image. It may also have a subtitle, which is displayed below the image. Or it may have just a title, which is displayed as a tool tip. Use setInventoryItemVisibility() to hide an inventory item. Currently there is no functionality to completely remove a single item from the inventory.

When the user clicks an item in the inventory, the event MacaoObject.onClickOtherItem() is send to all objects in all frames. The recommended way to use the inventory items is to include a MacaoSentenceController in one of the frames. When the user clicks on an item in the inventory, the item is added as object to the sentence in the Sentence Controller.

Because the MacaoInventory is inherited from the MacaoMenu, see the MacaoMenu on how to define the CSS style of the inventory and its items.

The following example shows how to add an item to the inventory using a MacaoTalkItem at an object. The Talk Item is triggered when the hero object is clicked. It sends an addInventoryItem event to the inventory object adding a spoon.

// create the hero
var hero = new MacaoObject("Hero", "Arnold", 100, 100)

// define the image of the hero
hero.setImage("myapp/arnold.gif")

// add the talk item
var talkItem = hero.createTalkItem("Hero_AddSpoon", "onClick")

// define the talk item's event
talkItem.setBeforeEvent(
	"addInventoryItem",
	["Spoon", "Silver spoon", "myapp/spoon.gif"],
	"Inventory"
)

Inventory Items with a Quantity

The inventory item may have a quantity, which can be used to administer the amount of goods or money. Use the method setQuantity() and addQuantity() to set or change the quantity. Use the method hasQuantity() to check, if the user has a required quantity of the good. This method can send different events back, if the user has the required quantity or has not.

Provide a subtitle with a placeholder of the form +#.##, to display the quantity. Provide the + sign, if you want a - sign be displayed for negative values. You can use a dot or a comma to separate the decimal places. Provide as many # characters as many decimal places you want to be displayed.

Adding an Inventory to your Page

The page optional/controllers/inventory.html contains an Inventory. You can add this page to a frame in your application. Or you can use the class MacaoInventory to create your own inventory controllers.

The following example adds an inventory to a page.

new MacaoInventory("Inventory", 10, 5)

Initializing Inventory Items

When you load a content page into the content frame, you may want to initialize the inventory with some items. Because the inventory will usually be in another frame, you cannot be sure, that the inventory is fully loaded yet. Send an event to the inventory object and provide the name of the frameset. When you provide the name of a frameset, the event is buffered until the destination page is fully loaded. The name of the frame, which contains the inventory, is usually 'inventory'.

The following example sends two events to the inventory, to add a spoon and sugar to the inventory. It sets the quantity of sugar to 1.2 kg.

sendEvent(
	"addInventoryItem",
	["Spoon", "Silver spoon", "myapp/spoon.gif"],
	"Inventory", "inventory"
)
sendEvent(
	"addInventoryItem",
	["Sugar", "Sugar", "myapp/sugar.gif", "#.# kg sugar", 1.2],
	"Inventory", "inventory"
)

Storing the Inventory Content

Call the method setAutoRestore() to activate the automatic storage function of the inventory. When the page containing the Inventory is closed, the Inventory stores its content to the Storage Manager (see MacaoPage). The Storage Manager is normally in the parent frame. When the Inventory page is reopened, it loads its content from the Storage Manager. So you can close the Inventory temporary and use the frame to display another page. The information of the Storage Manager will be lost, when the parent frame is closed.

Constructor Summary
MacaoInventory(String name, integer left, integer top)
     Use this constructor to create an Inventory on your page.

Method Summary
void addInventoryItem(String itemName, String title, String imageSource, optional String subTitle, optional number quantity)
     Call this method to add an item to the inventory or refresh an item in the inventory.
void addQuantity(String itemName, number quantity)
     Call this method to change the quantity of an inventory item.
MacaoMenuItem getInventoryItem(String itemName)
     Call this method to get the menu item, which is representing the inventory item.
number getQuantity(String itemName)
     Call this method to get the quantity of an inventory item.
boolean hasQuantity(String itemName, number quantity, optional String responseObjectName, optional String positiveEventType, optional Array positiveParams, optional String negativeEventType, optional Array negeativeParams)
     Call this method to test, if an inventory item has at least a specific quantity.
void restore()
     Call this method to restore the inventory content from the Storage Manager.
void setAutoRestore(boolean autoRestore)
     Call this method to activate or deactivate auto restore of the inventory content.
void setInventoryItemVisibility(String itemName, boolean visibility)
     Call this method to change an inventory items visibility.
void setItemSubTitle(String itemName, String subTitle)
     Call this method to change an inventory items subtitle.
void setQuantity(String itemName, number quantity)
     Call this method to set the quantity of an inventory item.
void store(boolean force)
     Call this method to store the inventory content to the Storage Manager.

Inherited Methods
addMenuItem, getCssClassName, getMenuItem, initMenu, removeAllMenuItems, setFocusToInput, setMenuCharacteristics, setMenuItemActive, setMenuItemImageSource, setMenuItemVisibilityactivateDrag, activateDrop, addController, broadcastEvent, createLayer, createLook, displayMeasures, getActualLook, getCollisionCheck, getCssClassName, getFrameName, getHeight, getLayer, getLeft, getLook, getName, getTitle, getTop, getType, getVisibility, getWidth, getZIndex, getZoom, hasLook, initObject, isController, isDragActive, isDragged, isDropActive, isDropAllowed, moveTo, moveToCenter, notifyControllers, onClick, onClickOther, onClickOtherItem, onClickWindow, onCollisionOut, onCollisionOver, onDblClick, onDblClickOther, onDblClickWindow, onDragEnd, onDragOut, onDragOver, onDragStart, onDrop, onKeyDown, onKeyPress, onKeyUp, onLoad, onMouseDown, onMouseDownWindow, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onMouseUpWindow, onUnload, openPage, postEvent, refreshZoom, removeController, removeObject, say, scrollVisible, sendEvent, setActualLook, setBaseSize, setCollisionCheck, setCssClassName, setForwardMouseEvents, setHTML, setImage, setScrollVisibleOptions, setTitle, setToolTip, setType, setVisibility, setZIndex, setZoom, toBack, toFront

Constructor Details
MacaoInventory(String name, integer left, integer top)

Method Details
void addInventoryItem(String itemName, String title, String imageSource, optional String subTitle, optional number quantity)

void addQuantity(String itemName, number quantity)

MacaoMenuItem getInventoryItem(String itemName)

number getQuantity(String itemName)

boolean hasQuantity(String itemName, number quantity, optional String responseObjectName, optional String positiveEventType, optional Array positiveParams, optional String negativeEventType, optional Array negeativeParams)

void restore()

void setAutoRestore(boolean autoRestore)

void setInventoryItemVisibility(String itemName, boolean visibility)

void setItemSubTitle(String itemName, String subTitle)

void setQuantity(String itemName, number quantity)

void store(boolean force)