InventoryAppDev
description: 涓哄簲鐢ㄧ▼搴忓紑鍙戝晢鍜岀敤鎴锋彁渚涘彲浜ゆ槗鐗╁搧鐨勮儗鍖呯┖闂存湇鍔? 鍚屾椂鍖呮嫭鐗╁搧绠$悊锛屼笉鍚岃儗鍖呭唴鐨勭墿鍝佷拱鍗栧拰浜ゆ槗
Inventory app for Paraworld
Title |
Inventory app for Paraworld |
Author(s) |
LiXizhi |
Date |
2008/1/16 |
File |
script/kids/3DMapSystemApp/Inventory/app_main.lua |
Description
db registration insert script
INSERT INTO apps VALUES (NULL, 'Inventory_GUID', 'Inventory', '1.0.0', 'http://www.paraengine.com/apps/Inventory_v1.zip', 'YourCompany', 'enUS', 'script/kids/3DMapSystemApp/Inventory/IP.xml', '', 'script/kids/3DMapSystemApp/Inventory/app_main.lua', 'Map3DSystem.App.Inventory.MSGProc', 1);
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/app_main.lua");
Member Functions
Map3DSystem.App.Inventory.OnConnection
requires
create class
commonlib.setfield("Map3DSystem.App.Inventory", {});
event handlers
OnConnection method is the obvious point to place your UI (menus, mainbars, tool buttons) through which the user will communicate to the app.
This method is also the place to put your validation code if you are licensing the add-in. You would normally do this before putting up the UI.
If the user is not a valid user, you would not want to put the UI into the IDE.
- param app : the object representing the current application in the IDE.
- param connectMode : type of ConnectMode.
syntax
function Map3DSystem.App.Inventory.OnConnection(app, connectMode)
parameters
app |
the object representing the current application in the IDE. |
connectMode |
|
Map3DSystem.App.Inventory.OnDisconnection
Receives notification that the Add-in is being unloaded.
syntax
function Map3DSystem.App.Inventory.OnDisconnection(app, disconnectMode)
parameters
Map3DSystem.App.Inventory.OnQueryStatus
This is called when the command's availability is updated
When the user clicks a command (menu or mainbar button), the
QueryStatus event is fired.
The
QueryStatus event returns the current status of the specified named command, whether it is enabled, disabled,
or hidden in the
CommandStatus parameter, which is passed to the msg by reference (or returned in the event handler).
- param commandName : The name of the command to determine state for. Usually in the string format "Category.SubCate.Name".
- param statusWanted : what status of the command is queried. it is of type CommandStatusWanted
- return __ : returns according to statusWanted. it may return an integer by adding values in CommandStatus.
syntax
function Map3DSystem.App.Inventory.OnQueryStatus(app, commandName, statusWanted)
parameters
app |
|
commandName |
The name of the command to determine state for. Usually in the string format "Category.SubCate.Name". |
statusWanted |
|
return |
returns according to statusWanted. it may return an integer by adding values in CommandStatus. |
Map3DSystem.App.Inventory.OnExec
This is called when the command is invoked.The Exec is fired after the
QueryStatus event is fired, assuming that the return to the statusOption parameter of
QueryStatus is supported and enabled.
This is the event where you place the actual code for handling the response to the user click on the command.
- param commandName : The name of the command to determine state for. Usually in the string format "Category.SubCate.Name".
syntax
function Map3DSystem.App.Inventory.OnExec(app, commandName, params)
parameters
app |
|
commandName |
The name of the command to determine state for. Usually in the string format "Category.SubCate.Name". |
params |
|
Map3DSystem.App.Inventory.OnRenderBox
Change and render the 3D world with mcml data that is usually retrieved from the current user's profile page for this application.
syntax
function Map3DSystem.App.Inventory.OnRenderBox(mcmlData)
parameters
Map3DSystem.App.Inventory.Navigate
called when the user wants to nagivate to the 3D world location relavent to this application
syntax
function Map3DSystem.App.Inventory.Navigate()
Map3DSystem.App.Inventory.GotoHomepage
called when user clicks to check out the homepage of this application. Homepage usually includes:
developer info, support, developer worlds information, app global news, app updates, all community user rating, active users, trade, currency transfer, etc.
syntax
function Map3DSystem.App.Inventory.GotoHomepage()
Map3DSystem.App.Inventory.DoQuickAction
called when user clicks the quick action for this application.
syntax
function Map3DSystem.App.Inventory.DoQuickAction()
Map3DSystem.App.Inventory.MSGProc
client world database function helpers.
all related messages
APPS can be invoked in many ways:
Through app Manager
mainbar or menu command or buttons
Command Line
3D World installed apps
syntax
function Map3DSystem.App.Inventory.MSGProc(window, msg)
parameters
a bag contains stuffs of a person, a bag may contain other bags of the same person.
Title |
a bag contains stuffs of a person, a bag may contain other bags of the same person. |
Author(s) |
LiXizhi, WangTian |
Date |
2008/1/16 |
File |
script/kids/3DMapSystemApp/Inventory/BagCtl.lua |
Description
the bag concept is similar to folder in windows. We can exchange items between bags of the same persons, different persons, a shop and a person.
We can also link a character with a given bag for the character to sell goods while the user is offline.
NOTE: implemented by
WangTian, the bag control is a universal item container. The control displays in grid view and
almost all the items allows drag and drop. According to develop note 2008/1/17, drag and drop between different bags
works in different dragging behaviors.
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/BagCtl.lua");
local ctl = Map3DSystem.App.Inventory.BagCtl:new{
name = "BagCtl1",
alignment = "_lt",
left=0, top=0,
width = 512,
height = 290,
parent = nil,
};
ctl:Show();
Member Functions
Map3DSystem.App.Inventory.Bag:new
-----------------------------------------------------
bag object
-----------------------------------------------------
bag status.
Map3DSystem.App.Inventory.BagStatus = {
-- unsynchronized
LocalBag = nil,
Unsynchronized = 1,
Synchronized = 2,
};
how items in a bag should be drawn
Map3DSystem.App.Inventory.BagDisplayOption = {
GridIconOnly = nil,
GridIconText = 1,
ListIconText = 2,
};
how items in a bag should be drawn
Map3DSystem.App.Inventory.BagType = {
-- the bag is the root bag of a given user
RootBag = nil,
-- give box: objects in the bag are given to the current user free of charge,
-- either because of the user just make them, obtained as trophy, or received as gifts from feeds.
GiveBox = 1,
-- all objects in the bag are for sale. Most marcket pages in application home page uses OnSaleBag to sell products to visitors.
-- personal users can also link sub bags to some of their virtual characters to let them sell their own products to other visitors.
OnSaleBag = 2,
};
NOTE: revised by WangTian
how items in a bag should be drawn
Map3DSystem.App.Inventory.BagType = {
-- the bag is the root bag of a given user
RootBag = 1,
-- the bag is the sub bag of a root bag
MiniBag = 2,
-- give box: objects in the bag are given to the current user free of charge,
-- either because of the user just make them, obtained as trophy, or received as gifts from feeds.
GiveBox = 3,
-- all objects in the bag are for sale. Most marcket pages in application home page uses OnSaleBag to sell products to visitors.
-- personal users can also link sub bags to some of their virtual characters to let them sell their own products to other visitors.
OnSaleBag = 4,
-- exchange bag: objects in the bag are for exchange purpose, ExchangeBagSelf shows the objects user want to exchange,
-- and ExchangeBagOpponent shows the opponent objects exchange back
ExchangeBagSelf = 5,
ExchangeBagOpponent = 6,
};
a single bag template containing stuffs of a person, a bag may contain other bags of the same person.
the bag concept is similar to folder in windows. We can exchange items between bags.
Map3DSystem.App.Inventory.Bag = {
-- the bag id in the server's bag database. If this is a locally created bag, id is nil.
id = nil,
-- the user_id of this bag's owner, if nil it means local or the current user.
owner_id = nil,
-- name of this bag, like folder name.
name = nil,
-- display name of the bag
text = nil,
-- E price and P price. only for display purposes, if the bag carries some money.
priceE = nil,
priceP = nil,
-- array {} of tradable item commands (some commands will open other bag objects)
objects = nil,
-- capacity of the bag
capacity = 49,
-- bag type of Map3DSystem.App.Inventory.BagType
BagType = nil,
-------------------------------------------
-- appearances
-------------------------------------------
-- how many rows and columns of the bag
col = 7,
row = 7,
-- which page to display, starting from 1
pageNo = nil,
-- display option of type Map3DSystem.App.Inventory.BagDisplayOption
DisplayOption = nil,
-- a filter function(item) return true; end, that will return true if the given item in bag should be shown,
-- we can use it to display only a subset of items in the bag.
FilterFunc = nil,
-- status of this bag. current it is not USED.
status = nil,
}
;
a list of active bags in the scene.
Map3DSystem.App.Inventory.Bags = {};
create a new bom
syntax
function Map3DSystem.App.Inventory.Bag:new(o)
parameters
Map3DSystem.App.Inventory.Bag:ClearAll
clear all objects
syntax
function Map3DSystem.App.Inventory.Bag:ClearAll()
Map3DSystem.App.Inventory.Bag:AddObject
add a new object to the bag. One need to call manually update the UI of the bag.
it may return nil if bag is full. otherwise return true.
syntax
function Map3DSystem.App.Inventory.Bag:AddObject(obj)
parameters
BagCtl:new
-----------------------------------------------------
bag control for displaying a bag object
-----------------------------------------------------
default member attributes
local BagCtl = {
-- the top level control name
name = "BagCtl1",
-- normal window size
--alignment = "_lt", -- NOTE: bag control don't suggest "_fi" alignment
left = 0,
top = 0,
--width = 300,
--height = 290,
parent = nil,
-- UI backgrounds
slotBG = "",
highLightBG = "",
-- bag information
type = nil, -- of type: Map3DSystem.App.Inventory.BagType
rows = 8,
columns = 6,
slotwidth = 64,
slotheight = 64,
itemwidth = 48,
itemheight = 48,
itemXoffset = 8,
itemYoffset = 8,
-- the Map3DSystem.App.Inventory.InventoryWnd.Bag object that this control is bound to.
bag = nil,
}
BagCtl =
BagCtl;
record all bag control names, mainly for bag items drag
drag receiver UI container in the
AllBagCtlNames table will be added on drag begin
AllBagCtlNames = {};
constructor
syntax
function BagCtl:new(o)
parameters
BagCtl:Destroy
Destroy the UI control
syntax
function BagCtl:Destroy()
BagCtl:Show
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
syntax
function BagCtl:Show(bShow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
BagCtl.SetSlotStyleButton
make a button inventory slot style
- param uiobject : button UI object
- param backgroundImage : background image always shows on slot
- param highlightImage : highlight image shows only on mouse over indicating available slot for item or item outer glow highlight
syntax
function BagCtl.SetSlotStyleButton(uiobject, backgroundImage, highlightImage)
parameters
uiobject |
button UI object |
backgroundImage |
|
|
highlightImage | highlight image shows only on mouse over indicating available slot for item
or item outer glow highlight |
BagCtl.DrawCellHandler
draw cell according to bag gridcell, if item cell draw, draw item with slot.
if empty cell, draw only empty slot
syntax
function BagCtl.DrawCellHandler(_parent, gridcell)
parameters
BagCtl.OnFakeMouseMove
DEBUG PURPOSE ------------------------
syntax
function BagCtl.OnFakeMouseMove()
BagCtl.OnClick
DEBUG PURPOSE ------------------------
onclick bagctl object will grab the object beneath the mouse cursor
the object then become a floating object on screen waiting for the drop operation(left click),
or the cancel operation(right click)
syntax
function BagCtl.OnClick(bagName, bagObjectIndex)
parameters
BagCtl.OnDragBegin
envisible the drag receiver, currently envisible all
BagCtl drag receiver to allow receiving item drag
syntax
function BagCtl.OnDragBegin(bagName, bagObjectIndex)
parameters
BagCtl.MoveObject
move one item from the source bag to the destination bag
positions are indicated by bag index
syntax
function BagCtl.MoveObject(srcBagName, srcBagObjectIndex, destBagName, destBagObjectIndex)
parameters
srcBagName |
|
srcBagObjectIndex |
|
destBagName |
|
destBagObjectIndex |
|
BagCtl.SwapObject
swap between the source bag item and the destination bag item
both positions are indicated by bag index
syntax
function BagCtl.SwapObject(srcBagName, srcBagObjectIndex, destBagName, destBagObjectIndex)
parameters
srcBagName |
|
srcBagObjectIndex |
|
destBagName |
|
destBagObjectIndex |
|
BagCtl.OnClose
close the given control
syntax
function BagCtl.OnClose(sCtrlName)
parameters
Map3DSystem.App.Inventory.BagCtl.OnClickItemNode
clicked the tree node.
syntax
function Map3DSystem.App.Inventory.BagCtl.OnClickItemNode(treeNode)
parameters
Exchanges bags (instanced) are UI for two bags and their money slots. One bag is for a remote user, the other is for the current user.
Title |
Exchanges bags (instanced) are UI for two bags and their money slots. One bag is for a remote user, the other is for the current user. |
Author(s) |
LiXizhi |
Date |
2008/1/16 |
File |
script/kids/3DMapSystemApp/Inventory/ExchangeBags.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/ExchangeBags.lua");
local ctl = Map3DSystem.App.Inventory.ExchangeBags:new{
name = "ExchangeBags1",
alignment = "_lt",
left=0, top=0,
width = 512,
height = 290,
parent = nil,
bag = nil,
};
ctl:Show();
Member Functions
ExchangeBags:new
default member attributes
local ExchangeBags = {
-- the top level control name
name = "ExchangeBags1",
-- normal window size
alignment = "_lt",
left = 0,
top = 0,
width = 300,
height = 290,
parent = nil,
-- the Map3DSystem.App.Inventory.InventoryWnd.Bag object that this control is bound to.
bag = nil,
}
ExchangeBags =
ExchangeBags;
constructor
syntax
function ExchangeBags:new (o)
parameters
ExchangeBags:Destroy
Destroy the UI control
syntax
function ExchangeBags:Destroy ()
ExchangeBags:Show
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
syntax
function ExchangeBags:Show(bShow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
ExchangeBags.OnClose
close the given control
syntax
function ExchangeBags.OnClose(sCtrlName)
parameters
Give box (instanced) is a special bag that contains stuffs that is free of charge to the current user.
Title |
Give box (instanced) is a special bag that contains stuffs that is free of charge to the current user. |
Author(s) |
LiXizhi |
Date |
2008/1/16 |
File |
script/kids/3DMapSystemApp/Inventory/GiveBox.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/GiveBox.lua");
local ctl = Map3DSystem.App.Inventory.GiveBox:new{
name = "GiveBox1",
alignment = "_lt",
left=0, top=0,
width = 512,
height = 290,
parent = nil,
bag = nil,
};
ctl:Show();
Member Functions
GiveBox:new
default member attributes
local GiveBox = {
-- the top level control name
name = "GiveBox1",
-- normal window size
alignment = "_lt",
left = 0,
top = 0,
width = 300,
height = 290,
parent = nil,
-- the Map3DSystem.App.Inventory.InventoryWnd.Bag object that this control is bound to.
bag = nil,
}
GiveBox =
GiveBox;
constructor
syntax
function GiveBox:new (o)
parameters
GiveBox:Destroy
Destroy the UI control
syntax
function GiveBox:Destroy ()
GiveBox:Show
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
syntax
function GiveBox:Show(bShow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
GiveBox.OnClose
close the given control
syntax
function GiveBox.OnClose(sCtrlName)
parameters
inventory window of a given user
Title |
inventory window of a given user |
Author(s) |
LiXizhi |
Date |
2008/1/12 |
File |
script/kids/3DMapSystemApp/Inventory/InventoryWnd.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/InventoryWnd.lua");
Map3DSystem.App.Inventory.ShowMyInventory(app);
Member Functions
Map3DSystem.App.Inventory.ShowMyInventory
common control library
NPL.load("(gl)script/ide/common_control.lua");
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/BagCtl.lua");
commonlib.setfield("Map3DSystem.App.Inventory.InventoryWnd", {});
the current logged in user's root bag object. of type
Map3DSystem.App.Inventory.Bag
UserBag = nil;
display the main inventory window for the current user.
syntax
function Map3DSystem.App.Inventory.ShowMyInventory(_app)
parameters
Map3DSystem.App.Inventory.GetCurrentUserRootBag
get the current user bag and retrieve data
the user bag contains local, profile, and app inventory data.
syntax
function Map3DSystem.App.Inventory.GetCurrentUserRootBag()
Map3DSystem.App.Inventory.InventoryWnd.Show
NOTE:
InventoryWnd or
InventoryWnd is the rootbag of a user
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
- param __ :_parent: parent window inside which the content is displayed. it can be nil.
syntax
function Map3DSystem.App.Inventory.InventoryWnd.Show(bShow, _parent, parentWindow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
parent |
|
parentWindow |
|
Map3DSystem.App.Inventory.InventoryWnd.ShowTestMini
show mini bag
syntax
function Map3DSystem.App.Inventory.InventoryWnd.ShowTestMini(bShow, _parent, parentWindow)
parameters
bShow |
|
parent |
|
parentWindow |
|
Mini Bag (instanced) is used to display sub folders(bags) of the root bag of the current user.
Title |
Mini Bag (instanced) is used to display sub folders(bags) of the root bag of the current user. |
Author(s) |
LiXizhi |
Date |
2008/1/16 |
File |
script/kids/3DMapSystemApp/Inventory/MiniBag.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/MiniBag.lua");
local ctl = Map3DSystem.App.Inventory.MiniBag:new{
name = "MiniBag1",
alignment = "_lt",
left=0, top=0,
width = 512,
height = 290,
parent = nil,
bag = nil,
};
ctl:Show();
Member Functions
MiniBag:new
default member attributes
local MiniBag = {
-- the top level control name
name = "MiniBag1",
-- normal window size
alignment = "_lt",
left = 0,
top = 0,
width = 300,
height = 290,
parent = nil,
-- the Map3DSystem.App.Inventory.InventoryWnd.Bag object that this control is bound to.
bag = nil,
}
MiniBag =
MiniBag;
constructor
syntax
function MiniBag:new (o)
parameters
MiniBag:Destroy
Destroy the UI control
syntax
function MiniBag:Destroy ()
MiniBag:Show
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
syntax
function MiniBag:Show(bShow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
MiniBag.OnClose
close the given control
syntax
function MiniBag.OnClose(sCtrlName)
parameters
Shop bag (instanced) is used for NPC or application home page to sell stuffs to visitors.
Title |
Shop bag (instanced) is used for NPC or application home page to sell stuffs to visitors. |
Author(s) |
LiXizhi |
Date |
2008/1/16 |
File |
script/kids/3DMapSystemApp/Inventory/ShopBag.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/Inventory/ShopBag.lua");
local ctl = Map3DSystem.App.Inventory.ShopBag:new{
name = "ShopBag1",
alignment = "_lt",
left=0, top=0,
width = 512,
height = 290,
parent = nil,
bag = nil,
};
ctl:Show();
Member Functions
ShopBag:new
default member attributes
local ShopBag = {
-- the top level control name
name = "ShopBag1",
-- normal window size
alignment = "_lt",
left = 0,
top = 0,
width = 300,
height = 290,
parent = nil,
-- the Map3DSystem.App.Inventory.InventoryWnd.Bag object that this control is bound to.
bag = nil,
}
ShopBag =
ShopBag;
constructor
syntax
function ShopBag:new (o)
parameters
ShopBag:Destroy
Destroy the UI control
syntax
function ShopBag:Destroy ()
ShopBag:Show
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
syntax
function ShopBag:Show(bShow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
ShopBag.OnClose
close the given control
syntax
function ShopBag.OnClose(sCtrlName)
parameters