-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionButton.as
216 lines (180 loc) · 5.34 KB
/
ActionButton.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package classes {
import starling.display.Sprite
import starling.display.Button;
import starling.events.Event;
public class ActionButton extends Sprite {
public var btn:Button;
public var pic:SuperImage;
public var clickFunc:Function;
public var stockBox:SuperImage = new SuperImage('stockBox0000', GV.HUD_SPRITESHEET, 66, -7); //76 -7
public var apBox:SuperImage = new SuperImage('apBox0000', GV.HUD_SPRITESHEET, -2, -1); //-2 -1 due to stroke length on border
public var lockedPic:SuperImage = new SuperImage('notActiveLargeIcon0000', GV.HUD_SPRITESHEET, 0, 0, true);
public var stockText:SuperText;
public var apText:SuperText;
public var isForTutorial:Boolean = false;
public const CENTER_X:int = 50;
public const CENTER_Y:int = 50;
private var btnGlow = new SuperMovieClip('buttonGlow', GV.HUD_SPRITESHEET, 0, 0, true);
public function ActionButton(_clickFunc:Function, picName:String = null, small:Boolean = false){
clickFunc = _clickFunc;
pic = new SuperImage(picName + '0000', GV.HUD_SPRITESHEET, 0, 0, true);
addEventListener(Event.TRIGGERED, onClick);
addEventListener(Event.ADDED_TO_STAGE, init);
if(small){
btn = new Button(Assets.getAtlasTexture(GV.HUD_SPRITESHEET, 'actionButtonSmall0000'), '', Assets.getAtlasTexture(GV.HUD_SPRITESHEET, 'actionButton0001'));
}else{
btn = new Button(Assets.getAtlasTexture(GV.HUD_SPRITESHEET, 'actionButton0000'), '', Assets.getAtlasTexture(GV.HUD_SPRITESHEET, 'actionButtonSmall0001'));
}
}
public function init(){
addChild(btnGlow);
addChild(btn);
addChild(lockedPic);
addChild(pic);
addChild(stockBox);
addChild(apBox);
btn.x = CENTER_X;
btn.y = CENTER_Y;
btn.pivotX = btn.width/2;
btn.pivotY = btn.height/2;
pic.x = CENTER_X;
pic.y = CENTER_Y;
pic.touchable = false;
stockBox.touchable = false;
stockText = new SuperText(35, 35, '-1', GV.FONT_1, GV.HUD_FONT_SIZE, 0xffffff, 'center', 'never_flat');
stockText.touchable = false;
apBox.touchable = false;
apText = new SuperText(35, 35, '-1', GV.FONT_1, GV.HUD_FONT_SIZE, 0xffffff, 'center', 'never_flat');
apText.touchable = false;
lockedPic.x = CENTER_X;
lockedPic.y = CENTER_Y;
lockedPic.touchable = false;
hideLock();
btnGlow.x = CENTER_X;
btnGlow.y = CENTER_Y;
btnGlow.visible = false;
pivotX = width/2;
pivotY = height/2;
addChild(apText);
addChild(stockText);
stockText.x = 65;
hideStock();
hideAp();
touchable = true;
hideAp();
hideStock();
}
public function reset():void{
show();
hideStock();
hideAp();
btnGlow.visible = false;
scaleX = 1;
scaleY = 1;
visible = true;
setPicture();
}
private function onClick(e:Event):void{
FX.btnClick.play(GV.AUDIO_START_TIME, 0, GV.sfx);
clickFunc();
}
public function setPicture(picName:String = null):void{
if (pic){
removeChild(pic);
pic = null;
}
if(!picName) picName = "notActiveIcon";
pic = new SuperImage(picName + '0000', GV.HUD_SPRITESHEET, 0, 0, true);
addChild(pic);
pic.x = 50;
pic.y = 50;
pic.touchable = false;
}
public function highlightBtn():void{
scaleX = 1;
scaleY = 1;
GV.arena.actionButtonHighlight.visible = true;
GV.arena.actionButtonHighlight.x = x - 8;
GV.arena.actionButtonHighlight.y = y - 95;
GV.s.juggler.removeTweens(GV.arena.actionButtonHighlight);
GV.s.juggler.tween(GV.arena.actionButtonHighlight, 0.35, {
transition: "SINE",
reverse: true,
repeatCount: 0,
y: GV.arena.actionButtonHighlight.y - 10
});
GV.s.juggler.removeTweens(this);
GV.s.juggler.tween(this, 0.35, {
transition: "SINE",
reverse: true,
repeatCount: 0,
scaleX: 1.075,
scaleY: 1.075
});
enable();
}
public function disable():void{
touchable = false;
isForTutorial = false;
}
public function enable():void{
touchable = true;
isForTutorial = true;
}
public function showLock():void{ lockedPic.visible = true;}
public function hideLock():void{ lockedPic.visible = false;}
public function showStock(stock:int = -1):void{
if(stock !== -1) stockText.text = stock.toString();
if(!stockText || stockText.text === '-1') return;
stockText.visible = true;
stockBox.visible = true;
}
public function hideStock():void{
stockText.visible = false;
stockBox.visible = false;
}
public function showAp(ap:int = -1):void{
if(ap !== -1) apText.text = ap.toString();
if(!apText || apText.text === '-1') return;
apText.visible = true;
apBox.visible = true;
}
public function hideAp():void{
apText.visible = false;
apBox.visible = false;
}
public function remove():void{
removeChild(btn)
removeChild(lockedPic);
removeChild(pic);
removeChild(stockBox);
removeChild(apBox);
removeChild(btnGlow);
GV.arena.neverFlatTextContainer.removeChild(stockText);
GV.arena.neverFlatTextContainer.removeChild(apText);
}
public function hide():void{
visible = false;
hideAp();
hideStock();
}
public function show():void{
visible = true;
showAp();
showStock();
}
public function glow(i:int){
btnGlow.visible = true;
btnGlow.currentFrame = i;
}
public function hideGlow(){
btnGlow.visible = false;
}
public function centerX():int{
return x + 50;
}
public function centerY():int{
return y + 50;
}
}
}