/
StorageMenu.as
133 lines (94 loc) · 2.71 KB
/
StorageMenu.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
//-----------------------
//Purpose: The internal workings of a menu that can hold items
//
//Properties:
//
//Methods:
//
//-----------------------
public class StorageMenu extends InventoryMenu
{
// Constants //
//- Constants -//
// Public Properties //
public override function get gridHeight():int
{
if (_inventory == null)
{
return 1;
}
var iNumRows:int = _inventory.maxSize / UIManager.MENU_INV_ITEMS_PER_ROW;
var iGridHeight:int = iNumRows * UIManager.MENU_INV_ITEM_GRID_HEIGHT;
return iGridHeight;
}
//- Public Properties -//
// Private Properties //
//- Private Properties -//
// Initialization //
public function StorageMenu(inventory:Inventory, gameController:GameController)
{
super(inventory, gameController);
}
//- Initialization -//
// Public Methods //
public override function Paint():MovieClip
{
var mcMenuBody:MovieClip = new MovieClip();
if (_inventory == null)
{
return mcMenuBody;
}
var iX:int = 0;
var iY:int = 0;
for (var i:int = 0; i < _inventory.maxSize; i++)
{
// event graphics
var mcEvent:MovieClip = new MovieClip;
mcEvent.slot = i;
// menu slot graphics
var mcMenuSlot:MenuSlot_MC = new MenuSlot_MC();
mcMenuSlot.x = iX;
mcMenuSlot.y = iY;
mcEvent.addChild(mcMenuSlot);
// item graphics
var oObject:Object = _inventory.GetItemAt(i);
if (oObject is IItem && oObject != null)
{
var oItem:IItem = IItem(oObject);
var mcItem:MovieClip = oItem.GetItemGraphics();
mcItem.x = iX;
mcItem.y = iY;
mcEvent.addChild(mcItem);
}
// add event listeners
mcEvent.item = oObject;
mcEvent.addEventListener(MouseEvent.CLICK, OnSlotClick, false, 0, true);
mcEvent.addEventListener(MouseEvent.ROLL_OUT, OnMouseRollOut, false, 0, true);
mcEvent.addEventListener(MouseEvent.ROLL_OVER, OnMouseRollOver, false, 0, true);
mcMenuBody.addChild(mcEvent);
// update drawing position
iX += UIManager.MENU_INV_ITEM_GRID_WIDTH * UIManager.MENU_INV_GRID_PIXEL_WIDTH;
if (iX >= UIManager.SCREEN_PIXEL_WIDTH)
{
iX = 0;
iY += UIManager.MENU_INV_ITEM_GRID_HEIGHT * UIManager.MENU_INV_GRID_PIXEL_HEIGHT;
}
}
return mcMenuBody;
}
//- Public Methods -//
// Private Methods //
private function OnSlotClick(event:MouseEvent):void
{
event.stopPropagation();
_gameController.OnStorageMenuSlotClick(this, event.currentTarget.slot);
}
//- Private Methods -//
// Testing Methods //
//- Testing Methods -//
}
}