-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameResultWindow.mxml
166 lines (153 loc) · 6.05 KB
/
GameResultWindow.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
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" width="335" height="105" fontSize="12" horizontalAlign="center" headerHeight="0"
borderThicknessBottom="3" borderThicknessLeft="3" borderThicknessRight="3" borderThicknessTop="3" click="_stopAndRemove();"
cornerRadius="0" horizontalScrollPolicy="off" verticalScrollPolicy="off" backgroundImage="{IMAGE_DIRECTORY}windowBg.jpg" alpha="0">
<mx:Script>
<![CDATA[
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.controls.*;
import mx.managers.PopUpManager;
private static const WIN:String = "win";
private static const LOSE:String = "lose";
private static const DRAW:String = "draw";
[Bindable]
private var _main:String;
[Bindable]
private var _you_before:String;
[Bindable]
private var _you_after:String;
[Bindable]
private var _opponent_before:String;
[Bindable]
private var _opponent_after:String;
[Bindable]
private var _you_rank:String;
[Bindable]
private var _opponent_rank:String;
private var _dy:int;
private const IMAGE_DIRECTORY:String = "http://www.81squareuniverse.com/dojo/images/";
private var _resultType:String;
private var _afterTimer:Timer = new Timer(500, 1);
private var _closeTimer:Timer = new Timer(5000, 1);
private var _fadeInTimer:Timer = new Timer(50, 10);
private var _fadeOutTimer:Timer = new Timer(50, 20);
public function initWindow(you:String, opponent:String, v:int):void {
_you_before = you + ": ";
_opponent_before = opponent + ": ";
_you_rank = "";
_opponent_rank = "";
if (v > 0) {
_resultType = WIN;
_main = "YOU WIN!";
mainLabel.setStyle('color', 0xFF0000);
_dy = - 2;
} else if (v < 0) {
_resultType = LOSE;
_main = "YOU LOST";
mainLabel.setStyle('color', 0x0000FF);
_dy = 2;
} else {
_resultType = DRAW;
_main = "DRAW";
mainLabel.setStyle('color', 0x008800);
_dy = 0;
}
_fadeInTimer.addEventListener(TimerEvent.TIMER, _fadeIn);
_fadeInTimer.start();
_fadeOutTimer.addEventListener(TimerEvent.TIMER, _fadeOut);
_fadeOutTimer.addEventListener(TimerEvent.TIMER_COMPLETE, _remove);
_closeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, _close);
_closeTimer.start();
}
public function readRateChange(you1:int, you2:int, opponent1:int, opponent2:int):void {
_you_before = _you_before + you1;
_opponent_before = _opponent_before + opponent1;
switch (_resultType) {
case WIN:
_you_after = "-> " + you2 + " (+" + (you2 - you1) +")";
_opponent_after = "-> " + opponent2 + " (-" + (opponent1 - opponent2) + ")";
if (InfoFetcher.makeRankFromRating(you1) != InfoFetcher.makeRankFromRating(you2)) {
_you_rank = "Rank Up!";
youRank.setStyle('color', 0xFF0000);
}
if (InfoFetcher.makeRankFromRating(opponent1) != InfoFetcher.makeRankFromRating(opponent2)) {
_opponent_rank = "Rank Down";
opponentRank.setStyle('color', 0x0000FF);
}
break;
case LOSE:
_you_after = "-> " + you2 + " (-" + (you1 - you2) +")";
_opponent_after = "-> " + opponent2 + " (+" + (opponent2 - opponent1) + ")";
if (InfoFetcher.makeRankFromRating(you1) != InfoFetcher.makeRankFromRating(you2)) {
_you_rank = "Rank Down";
youRank.setStyle('color', 0x0000FF);
}
if (InfoFetcher.makeRankFromRating(opponent1) != InfoFetcher.makeRankFromRating(opponent2)) {
_opponent_rank = "Rank Up!";
opponentRank.setStyle('color', 0xFF0000);
}
break;
case DRAW:
_you_after = "-> " + you2;
_opponent_after = "-> " + opponent2;
}
youBefore.visible = true;
opponentBefore.visible = true;
_afterTimer.addEventListener(TimerEvent.TIMER_COMPLETE, _after);
_afterTimer.start();
}
private function _after(e:TimerEvent):void {
youAfter.visible = true;
youRank.visible = true;
opponentAfter.visible = true;
opponentRank.visible = true;
}
private function _close(e:TimerEvent):void {
_fadeOutTimer.start();
}
private function _fadeIn(e:TimerEvent):void {
this.alpha += 0.1;
}
private function _fadeOut(e:TimerEvent):void {
this.alpha -= 0.05;
this.y += _dy;
}
private function _remove(e:TimerEvent):void {
_stopAndRemove();
}
private function _stopAndRemove():void{
youBefore.visible = false;
opponentBefore.visible = false;
youAfter.visible = false;
youRank.visible = false;
opponentAfter.visible = false;
opponentRank.visible = false;
_fadeInTimer.stop();
_fadeOutTimer.stop();
_closeTimer.stop();
_afterTimer.stop();
_fadeInTimer.removeEventListener(TimerEvent.TIMER, _fadeIn);
_fadeOutTimer.removeEventListener(TimerEvent.TIMER, _fadeOut);
_fadeOutTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, _remove);
_closeTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, _close);
_afterTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, _after);
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Fade id="showEffect" alphaFrom="0" alphaTo="1.0" duration="1000" />
<mx:Label id="mainLabel" text="{_main}" fontSize="19" fontWeight="bold" paddingTop="5" />
<mx:VBox horizontalAlign="left">
<mx:HBox>
<mx:Label id="youBefore" text="{_you_before}" visible="false" />
<mx:Label id="youAfter" text="{_you_after}" fontWeight="bold" showEffect="showEffect" visible="false" />
<mx:Label id="youRank" text="{_you_rank}" fontWeight="bold" showEffect="showEffect" visible="false" />
</mx:HBox>
<mx:HBox>
<mx:Label id="opponentBefore" text="{_opponent_before}" visible="false" />
<mx:Label id="opponentAfter" text="{_opponent_after}" fontWeight="bold" showEffect="showEffect" visible="false" />
<mx:Label id="opponentRank" text="{_opponent_rank}" fontWeight="bold" showEffect="showEffect" visible="false" />
</mx:HBox>
</mx:VBox>
</mx:TitleWindow>