Extension / BagModule
BagModule Class
Bag instance
The bag system is like a special bag you use when playing games, which can help you manage and store various items and asset. The MW editor has packaged a backpack system that can be used directly.
Your character collect many valuable items in the game, such as weapons, equipment, medicines, materials, etc. These items need a place to store, and the bag system is a virtual bag that can hold these items.
It is a special tool in the game to help you organize, store and manage various items and asset you collect in the game, making your game experience more convenient and orderly.
Example usage: Create a script named BagExample, place it in the object bar, open the script, modify the original content to the following, save and run the game
@Component
export default class BagExample extends Script {
protected onStart(): void {
BagModule. registrant Item (1, "37692", "Golden Shovel", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (2, "37690", "little speaker", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (3, "37697", "Gold Coins", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (4, "37695", "Pumpkin", ItemQuality.Common,20, {a:1,b:2});
if(SystemUtil.isClient()){
BagModule.addItemClickListener(this.onItemClick,this);
BagModule.addItem(1,1);
BagModule.addItem(2,5);
BagModule.addItem(3,10);
BagModule.addItem(4,30);
BagModule.open();
}
}
private onItemClick(cfg:ItemConfig){
Console. log ("click", cfg);
}
}
@Component
export default class BagExample extends Script {
protected onStart(): void {
BagModule. registrant Item (1, "37692", "Golden Shovel", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (2, "37690", "little speaker", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (3, "37697", "Gold Coins", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (4, "37695", "Pumpkin", ItemQuality.Common,20, {a:1,b:2});
if(SystemUtil.isClient()){
BagModule.addItemClickListener(this.onItemClick,this);
BagModule.addItem(1,1);
BagModule.addItem(2,5);
BagModule.addItem(3,10);
BagModule.addItem(4,30);
BagModule.open();
}
}
private onItemClick(cfg:ItemConfig){
Console. log ("click", cfg);
}
}
Table of contents
Accessors
capacity(): number other |
---|
Backpack capacity |
dragEnabled(): boolean other |
Can I drag and drop |
labelVisible(): boolean other |
Is the item name visible |
searchEnabled(): boolean other |
Display search box or not |
Methods
addItem(itemId : number , count? : number , player? : Player ): Promise <number > other |
---|
add item |
addItemClickListener(clickCallback : (cfg : ItemConfig ) => void , thisObject : any ): typeof BagModule other |
Add item click callback |
close(player? : Player ): typeof BagModule other |
Close the bag interface |
getItemCount(itemId : number , player? : Player ): number other |
Get the number of specified props of bag |
open(player? : Player ): typeof BagModule other |
Open the backpack interface |
registerItem(itemId : number , icon : string , name : string , quality? : ItemQuality , stackCount? : number , customData? : any ): typeof BagModule other |
Backpack registration item information, items need to be registered on the client side |
removeItem(itemId : number , count? : number , player? : Player ): typeof BagModule other |
Delete Item |
removeItemClickListener(clickCallback : (cfg : ItemConfig ) => void , thisObject : any ): typeof BagModule other |
Remove props and click callback |
skin(bagSkin : (...args : any []) => IBagSkin , itemSkin : (...args : any []) => IBagItemSkin , itemBgSkin : (...args : any []) => UIScript , deleteDialogSkin : (...args : any []) => IItemDeleteSkin ): typeof BagModule other |
Set bag skin |
sort(): typeof BagModule other |
Organize bag |
Accessors
capacity
• | • | ||||
---|---|---|---|---|---|
Backpack capacity Returns
| Backpack capacity Parameters
|
dragEnabled
• | • | ||||
---|---|---|---|---|---|
Can I drag and drop Returns
| Can I drag and drop Parameters
|
labelVisible
• | • | ||||
---|---|---|---|---|---|
Is the item name visible Returns
| Is the item name visible Parameters
|
searchEnabled
• | • | ||||
---|---|---|---|---|---|
Display search box or not Returns
| Display search box or not Parameters
|
Methods
addItem
• Static
addItem(itemId
, count?
, player?
): Promise
<number
> other
add item
Parameters
itemId number | Usage: Prop ID range: No restrictions type: Integer |
---|---|
count? number | Usage: Number of props default: 1 Range: No limit type: Integer |
player? Player | Usage: Props Owner default: Must be passed to the server |
Returns
Promise <number > | Return the number of items added, and if the addition fails, return 0 |
---|
Usage example: Create a BagExample script and drag it into the object manager. Add the following code and run the project
@Component
export default class BagExample extends Script {
protected onStart(): void {
BagModule. registrant Item (1, "37692", "Golden Shovel", ItemQuality.Legend,10, {a:1,b:2});
if (SystemUtil.isServer()) return;
BagModule.addItem(1).then((count:number)=>{
Console.log ("Number of items added", count);
});
BagModule.open();
}
@Component
export default class BagExample extends Script {
protected onStart(): void {
BagModule. registrant Item (1, "37692", "Golden Shovel", ItemQuality.Legend,10, {a:1,b:2});
if (SystemUtil.isServer()) return;
BagModule.addItem(1).then((count:number)=>{
Console.log ("Number of items added", count);
});
BagModule.open();
}
addItemClickListener
• Static
addItemClickListener(clickCallback
, thisObject
): typeof BagModule
other
Add item click callback
Parameters
clickCallback (cfg : ItemConfig ) => void | Usage: Click on callback |
---|---|
thisObject any | Usage: call context |
Returns
typeof BagModule | Return to bag instance |
---|
close
• Static
close(player?
): typeof BagModule
other
Close the bag interface
Parameters
player? Player | Usage: player needs to be passed in when the server call default: player needs to be passed in when the server calls |
---|
Returns
typeof BagModule | Return to bag instance |
---|
getItemCount
• Static
getItemCount(itemId
, player?
): number
other
Get the number of specified props of bag
Parameters
itemId number | Usage: Prop ID range: Determine type based on prop ID: integer |
---|---|
player? Player | Usage: server input, open the specified player's backpack default: server must input |
Returns
number | Return to bag instance |
---|
open
• Static
open(player?
): typeof BagModule
other
Open the backpack interface
Parameters
player? Player | Usage: owner of the bag default: filled in by the server, not by the client |
---|
Returns
typeof BagModule | Return to bag instance |
---|
registerItem
• Static
registerItem(itemId
, icon
, name
, quality?
, stackCount?
, customData?
): typeof BagModule
other
Backpack registration item information, items need to be registered on the client side
Parameters
itemId number | Usage: Prop ID range: Determine type based on prop ID: integer |
---|---|
icon string | Usage: props image range: unlimited |
name string | Usage: Name Range: No restrictions |
quality? ItemQuality | Usage: prop quality - default ordinary default: ItemQuality Common |
stackCount? number | Usage: stacking quantity default: 1 range: no limit type: integer |
customData? any | Usage: additional data default: null |
Returns
typeof BagModule | Return to bag instance |
---|
Usage example: create a BagExample script and drag it into the object manager. Add the following code So you have registered 4 items, and then add the corresponding ID in the backpack through BagModule. addItem to see these 4 items
@Component
export default class BagExample extends Script {
protected onStart(): void {
BagModule. registrant Item (1, "37692", "Golden Shovel", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (2, "37690", "little speaker", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (3, "37697", "Gold Coins", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (4, "37695", "Pumpkin", ItemQuality.Common,20, {a:1,b:2});
}
}
@Component
export default class BagExample extends Script {
protected onStart(): void {
BagModule. registrant Item (1, "37692", "Golden Shovel", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (2, "37690", "little speaker", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (3, "37697", "Gold Coins", ItemQuality.Legend,10, {a:1,b:2});
BagModule. registrant Item (4, "37695", "Pumpkin", ItemQuality.Common,20, {a:1,b:2});
}
}
removeItem
• Static
removeItem(itemId
, count?
, player?
): typeof BagModule
other
Delete Item
Parameters
itemId number | Usage: Prop ID range: Determine type based on prop ID: integer |
---|---|
count? number | Usage: Number of props default: 1 Range: No limit type: Integer |
player? Player | Usage: Props owner, server must pass in default: server must pass in |
Returns
typeof BagModule | Return to bag instance |
---|
removeItemClickListener
• Static
removeItemClickListener(clickCallback
, thisObject
): typeof BagModule
other
Remove props and click callback
Parameters
clickCallback (cfg : ItemConfig ) => void | Usage: Click on callback |
---|---|
thisObject any | Usage: call context |
Returns
typeof BagModule | Return to bag instance |
---|
skin
• Static
skin(bagSkin
, itemSkin
, itemBgSkin
, deleteDialogSkin
): typeof BagModule
other
Set bag skin
Parameters
bagSkin (...args : any []) => IBagSkin | Usage: bag UI skin, null is the default skin |
---|---|
itemSkin (...args : any []) => IBagItemSkin | Usage: Backpack Item Skin, null is the default skin |
itemBgSkin (...args : any []) => UIScript | Usage: Backpack Item Background Skin, null is the default skin |
deleteDialogSkin (...args : any []) => IItemDeleteSkin | Usage: bag item delete pop-up skin, null is the default skin |
Returns
typeof BagModule | Return to bag instance |
---|
Usage example:
- create a UI named BagUI in the project, and drag the following widget closeBtn: mw.StaleButton; content: mw.Canvas; filterBox: mw.InputBox; filterCanvas: mw.Canvas;
- Export the UI, copy the exported UI file BagUI_Generate to the JavaScript folder, rename it BagSkin, and modify extends to BagUI Create a script named BagExample, place it in the object bar, open the script, modify the original content as follows, save and run the game
- The same applies to other UI skins
@Component
export default class BagExample extends Script {
protected onStart(): void {
if (!SystemUtil.isServer()) return;
BagModule.skin(BagSkin, null, null, null);
BagModule.open();
}
}
@Component
export default class BagExample extends Script {
protected onStart(): void {
if (!SystemUtil.isServer()) return;
BagModule.skin(BagSkin, null, null, null);
BagModule.open();
}
}
sort
• Static
sort(): typeof BagModule
other
Organize bag
Returns
typeof BagModule | Return to bag instance |
---|