-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardFanSelector.mxml
217 lines (160 loc) · 7.62 KB
/
CardFanSelector.mxml
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
217
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.events.DragEvent;
import mx.containers.Box;
import mx.containers.Canvas;
import mx.managers.DragManager;
import mx.core.DragSource;
import flash.events.MouseEvent;
import com.BlueToken;
import com.Card;
import com.Deck;
import mx.controls.Alert;
import mx.core.BitmapAsset;
import mx.core.UIComponent;
import mx.effects.Rotate;
[Embed("images/runner_back.jpg")]
[Bindable]
public var RunnerCardBack:Class;
[Embed("images/corp_back.jpg")]
[Bindable]
public var CorpCardBack:Class;
// Offset for cards
public var cardXOff:Number;
public var cardYOff:Number;
[Bindable]
public var runnerCardsLeft:Number;
[Bindable]
public var corpCardsLeft:Number;
internal static var debugMode:Boolean = true;
// Debug stuff
[Bindable]
public var debugText:String;
[Bindable]
public var debugLines:Number = 0;
public var myCorpDeck:Deck = new Deck("Corp");
public var myRunnerDeck:Deck = new Deck("Runner");
// Create the hand deck
public var myHandDeck:Deck = new Deck("Hand");
public var currentCard:Card = new Card;
public function doDebug(text:String):void {
if(debugMode == true){
debugText = debugText + "\n" + text;
debugLines++;
}
}
public function init():void {
doDebug("Initializing Decks");
doDebug("Initiating Corp Deck");
myCorpDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "corp"));
myCorpDeck.addCard(new Card("Clown", "Program", "images/clown.jpg", "corp"));
myCorpDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "corp"));
myCorpDeck.addCard(new Card("Clown", "Program", "images/clown.jpg", "corp"));
myCorpDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "corp"));
myCorpDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "corp"));
// trace (myCorpDeck);
doDebug("Shuffling Corp Deck");
myCorpDeck.shuffle();
doDebug("Done Shuffling Corp Deck");
// trace (myCorpDeck);
doDebug("Initializing Runner Deck");
myRunnerDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "runner"));
myRunnerDeck.addCard(new Card("Clown", "Program", "images/clown.jpg", "runner"));
myRunnerDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "runner"));
myRunnerDeck.addCard(new Card("Clown", "Program", "images/clown.jpg", "runner"));
myRunnerDeck.addCard(new Card("On-call Solo Team", "Agenda", "images/on-call_solo_team.gif", "runner"));
// trace (myRunnerDeck);
doDebug("Shuffling Runner Deck");
myRunnerDeck.shuffle();
doDebug("Done Shuffling Runner Deck");
// trace (myRunnerDeck);
doDebug("Counting cards in each Deck");
corpCardsLeft = myCorpDeck.deck.length;
runnerCardsLeft = myRunnerDeck.deck.length;
// need to add the event listener to the button
fan.addEventListener(MouseEvent.CLICK, doFan);
}
// this is the trigger to the fanning the cards
public function doFan(event:MouseEvent):void {
var angleStepper:Number = 90/myHandDeck.deck.length;
var angle:Number = -90;
for each (var card:Card in myHandDeck.deck) {
card.fanCards(event, angle);
angle = angle + angleStepper;
}
}
public function cardOffSet(event:MouseEvent):void {
// doDebug("Triggered Card Offset");
cardXOff = event.localX;
cardYOff = event.localY;
}
public function makeCorpCard():void {
var myCard:Card = currentCard = myCorpDeck.draw();
myCard.addEventListener(MouseEvent.MOUSE_MOVE, cardOffSet);
corpCardsLeft = myCorpDeck.deck.length;
base.addChild(myCard);
doDebug("Drawing Corp Card");
}
public function makeRunnerCard():void {
var myCard:Card = currentCard = myRunnerDeck.draw();
myCard.addEventListener(MouseEvent.MOUSE_MOVE, cardOffSet);
// Setting the cards to around the middle of the canvas
myCard.x = 300;
myCard.y = 200;
myHandDeck.addCard(myCard);
runnerCardsLeft = myRunnerDeck.deck.length;
base.addChild(myCard);
doDebug("Drawing Runner Card");
}
private function baseDoDragDrop(event:DragEvent):void
{
if (event.dragSource.hasFormat('cardType')) {
event.dragInitiator.x = event.currentTarget.mouseX - cardXOff;
event.dragInitiator.y = event.currentTarget.mouseY - cardYOff;
base.setChildIndex(Card(event.dragInitiator), base.numChildren-1);
} else {
// event.dragInitiator.x = event.currentTarget.mouseX - xOff;
// event.dragInitiator.y = event.currentTarget.mouseY - yOff;
// base.setChildIndex(BlueToken(event.dragInitiator), base.numChildren-1);
}
}
private function cardDragEnterHandler(event:DragEvent):void
{
// Get the drop target component from the event object.
var dropTarget:Canvas=Canvas(event.currentTarget);
// Accept the drag only if the user is dragging data
// identified by the 'cardType' format value.
if (event.dragSource.hasFormat('cardType')) {
DragManager.acceptDragDrop(dropTarget);
}
}
private function cardDragExitHandler(event:DragEvent):void
{
// Get the drop target component from the event object.
var dropTarget:Card=event.currentTarget as Card;
}
private function tokenDoDragEnter(event:DragEvent):void
{
if(event.dragSource.dataForFormat('format') == "bit") {
doDebug("Cannot drop Bit here");
} else {
DragManager.acceptDragDrop(Canvas(event.target));
// doDebug("Bit Dropped");
}
}
]]>
</mx:Script>
<mx:Canvas id="base"
width="717" height="489"
dragEnter="tokenDoDragEnter(event);"
dragDrop="baseDoDragDrop(event); " borderStyle="none" cornerRadius="0" backgroundColor="gray" x="0" y="0">
</mx:Canvas>
<mx:Panel x="10" y="497" width="206" height="140" layout="absolute" toolTip="Play Field Actions" title="Play Field Actions">
<mx:Button label="[{corpCardsLeft}]Draw Corp Card" click="makeCorpCard();" fontWeight="normal" y="10" x="10" width="176"/>
<mx:Button label="[{runnerCardsLeft}]Draw Runner Card" click="makeRunnerCard();" fontWeight="normal" y="40" x="10" width="176"/>
<mx:Button id="fan" label="fan cards" x="10" y="70"/>
</mx:Panel>
</mx:Application>