-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlayerDetailWindow.mxml
424 lines (403 loc) · 19.5 KB
/
PlayerDetailWindow.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:eightyOneSquare="*" fontSize="12" horizontalScrollPolicy="off" verticalScrollPolicy="off"
paddingLeft="5" paddingBottom="5" paddingRight="5" paddingTop="5" title="Player Detail" showCloseButton="true" close="_close();" creationPolicy="all" creationComplete="_initWindow();">
<mx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.styles.FillStyle;
import com.google.maps.styles.StrokeStyle;
import flash.events.Event;
import flash.geom.Point;
import mx.controls.*;
import mx.effects.Effect;
import mx.effects.Move;
import mx.managers.PopUpManager;
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
[Bindable]
public var login:String;
[Bindable]
public var connection:String = "offline";
[Bindable]
private var _country:String = "";
[Bindable]
private var _country_code:String = "";
[Bindable]
private var _updated:String = "";
[Bindable]
private var _joined:String = "";
[Bindable]
private var _rating:int = 0;
[Bindable]
private var _maxRating:int = 0;
[Bindable]
private var _rank:String = "";
[Bindable]
public var avatar:String = null;
[Bindable]
public var titleName:String = "none";
[Bindable]
public var titleSubName:String = "無し";
[Bindable]
private var _wins:int = 0;
[Bindable]
private var _losses:int = 0;
[Bindable]
private var _wins34:int = 0;
[Bindable]
private var _losses34:int = 0;
[Bindable]
private var _draws34:int = 0;
[Bindable]
private var _exp:int = 0;
[Bindable]
private var _rank34:String = "";
[Bindable]
private var _percentage:Number = 0;
[Bindable]
private var _percentage34:Number = 0;
[Bindable]
private var _streak:int = 0;
[Bindable]
private var _streak_best:int = 0;
[Bindable]
private var _pr:String = "";
private var _cityName:String;
private var _cityLatitude:Number;
private var _cityLongitude:Number;
private const IMAGE_DIRECTORY:String = "http://49.212.52.151/dojo/images/";
private var _mapLoaded:Boolean = false;
private var _detailLoaded:Boolean = false;
private var _countryMapInfo:String;
private var _ratings:Array = new Array();
private var _openingData:Object = new Object();
private const opening_names:Array = ["double_wing","side_pawn","yagura","bishop_exchange","opposition_static","opposing_rook","3rd_file_rook","4th_file_rook","central_rook","double_ranging","unknown","*"];
private const group_names:Array = ["side_and_wing","side_and_wing","yagura_and_bishop","yagura_and_bishop","opposition_static","opposition_ranging","opposition_ranging","opposition_ranging","opposition_ranging","double_ranging","unknown","*"];
private function _initWindow():void {
this.addEventListener("move", _handleMove);
}
private function _handleMove(e:Event):void {
if (this.y < 0) this.y = 0;
}
public function loadPlayerDetail(player:Object):void {
_detailLoaded = true;
_country_code = String(InfoFetcher.country_codes[parseInt(player["country-id"]) - 1] + 1000).substring(1);
_country = InfoFetcher.country_names[InfoFetcher.country_codes[parseInt(player["country-id"]) - 1]];
_countryMapInfo = InfoFetcher.country_maps[parseInt(player["country-id"]) - 1]
_joined = player["created-at"];
_joined = _joined.substr(0, 10);
_updated = player["updated-at"];
_updated = _updated.substr(0, 10);
_pr = player.pr;
if (!_pr) _pr = "";
_pr = _pr.replace(/\r\n/g, "\n");
if (_pr.match(/^\[object/)) _pr = "";
_rating = parseInt(player.rate);
_maxRating = player["max-rate"];
_rank = InfoFetcher.makeRankFromRating(_rating);
_wins = player.wins;
_losses = player.losses;
if (_wins + _losses < 10) _rank = "-";
_wins34 = player.wins34;
_losses34 = player.losses34;
_draws34 = player.draws34;
_streak = player.streak;
_streak_best = player["streak-best"];
_exp = player.exp34;
_rank34 = InfoFetcher.makeRank34FromExp(_exp);
_percentage = (_wins + _losses == 0) ? 0 : (_wins / (_wins + _losses)*100);
_percentage34 = (_wins34 + _losses34 == 0) ? 0 : (_wins34 / (_wins34 + _losses34) * 100);
_cityName = player["city-name"];
_cityLatitude = player["city-lat"];
_cityLongitude = player["city-lon"];
if (_mapLoaded) _drawMap();
}
private function _close():void {
dispatchEvent(new Event("close_window"));
PopUpManager.removePopUp(this);
}
private function _onMapReady(event:MapEvent):void {
_mapLoaded = true;
if (_detailLoaded) _drawMap();
}
private function _drawMap():void {
if (_countryMapInfo == null) {
map.setCenter(new LatLng(0, 0), 1, MapType.NORMAL_MAP_TYPE);
} else if (_countryMapInfo && _countryMapInfo == "*") {
map.setCenter(new LatLng(0, 0), 1, MapType.NORMAL_MAP_TYPE);
} else {
var tokens:Array = _countryMapInfo.split(",");
map.setCenter(new LatLng(tokens[0], tokens[1]), tokens[2], MapType.PHYSICAL_MAP_TYPE);
map.enableScrollWheelZoom();
var marker:Marker = new Marker(
new LatLng(tokens[3],tokens[4]),
new MarkerOptions({ fillStyle: new FillStyle({color: 0x00ff00}), radius: 4, tooltip: ("Capital: " + tokens[5]), strokeStyle: new StrokeStyle({thickness: 1, color: 0x008800})}));
map.addOverlay(marker);
}
if (_cityLatitude && _cityLongitude) {
if (_cityLatitude >= -90 && _cityLatitude <= 90 && _cityLongitude >= -180 && _cityLongitude <= 180) {
marker = new Marker(
new LatLng(_cityLatitude, _cityLongitude),
new MarkerOptions({ fillStyle: new FillStyle({color: 0xffff00}), radius: 6, tooltip: ("I'm here: " + _cityName), strokeStyle: new StrokeStyle({thickness: 1.5, color: 0x000000})}));
map.addOverlay(marker);
}
}
}
public function showHistory(histories:Array):void {
var n:int = 0;
for (var i:int = histories.length - 1; i >= 0; i--) {
n++;
_ratings.push(new Point(n, Math.abs(histories[i].change)));
}
ratePlot2D.loadData(_ratings);
////////////////////
for (i = 0; i < opening_names.length; i++) _openingData[opening_names[i]] = _openingDatum(group_names[i]);
var match:Array;
var openingName:String;
for each (var history:Object in histories){
if ((match = history.opening.match(/^opposition_(black|white)(\d)$/))) {
if (history.sente && match[1] == "white" || !history.sente && match[1] == "black") {
openingName = "opposition_static";
} else {
switch (parseInt(match[2])) {
case 2:
openingName = "opposing_rook"; break;
case 3:
openingName = "3rd_file_rook"; break;
case 4:
openingName = "4th_file_rook"; break;
case 5:
openingName = "central_rook";
}
}
} else {
openingName = history.opening
}
if (parseInt(history.change) > 0) {
if (history.sente) _openingData[openingName].black_wins += 1;
else _openingData[openingName].white_wins += 1;
} else {
if (history.sente) _openingData[openingName].black_losses += 1;
else _openingData[openingName].white_losses += 1;
}
}
openingPieChart.loadData(_pieDataArray());
/////////////////////////////
openingRadarChart.loadData(_radarDataArray());
/////////////////////////////
dataGrid1.dataProvider = _gridDataArray(["yagura", "bishop_exchange", "double_wing", "side_pawn", "opposition_static", "blank", "total"]);
dataGrid2.dataProvider = _gridDataArray(["central_rook","4th_file_rook","3rd_file_rook","opposing_rook","double_ranging", "blank", "total","blank","unknown"]);
}
private function _pieDataArray():Array{
var arr:Array = new Array();
for each (var str:String in InfoFetcher.pie_chart_order) {
var datum:Object = new Object();
datum.name = str;
datum.black = _openingData[str].black_wins + _openingData[str].black_losses;
datum.white = _openingData[str].white_wins + _openingData[str].white_losses;
datum.color = InfoFetcher.infoOpeningColor(str);
datum.group = _openingData[str].group;
arr.push(datum);
}
return arr;
}
private function _radarDataArray():Array{
var arr:Array = new Array();
for each (var str:String in InfoFetcher.radar_chart_order) arr.push(_openingDatum(str));
for (var i:int = 0; i < opening_names.length; i++) {
if (group_names[i] == "*") continue;
var j:int = InfoFetcher.radar_chart_order.indexOf(group_names[i]);
arr[j].black_wins += _openingData[opening_names[i]].black_wins
arr[j].black_losses += _openingData[opening_names[i]].black_losses
arr[j].white_wins += _openingData[opening_names[i]].white_wins
arr[j].white_losses += _openingData[opening_names[i]].white_losses
}
return arr;
}
private function _gridDataArray(orderArray:Array):Array{
var arr:Array = new Array();
var doSum:Boolean = true;
var black_wins_sum:int = 0;
var black_losses_sum:int = 0;
var white_wins_sum:int = 0;
var white_losses_sum:int = 0;
for each (var str:String in orderArray) {
if (str == "blank") {
var datum:Object = new Object();
datum.tip = "";
} else if (str == "total") {
datum = new Object();
datum.name = parentApplication.lan.total;
datum.tip = ""
datum.black_wins = black_wins_sum;
datum.black_losses = black_losses_sum;
datum.black_total = datum.black_wins + datum.black_losses;
datum.black_percent = datum.black_total == 0 ? 0 : (datum.black_wins / datum.black_total * 100).toFixed(0);
datum.white_wins = white_wins_sum;
datum.white_losses = white_losses_sum;
datum.white_total = datum.white_wins + datum.white_losses;
datum.white_percent = datum.white_total == 0 ? 0 : (datum.white_wins / datum.white_total * 100).toFixed(0);
datum.wins = datum.black_wins + datum.white_wins;
datum.losses = datum.black_losses + datum.white_losses;
datum.total = datum.wins + datum.losses;
datum.percent = datum.total == 0 ? 0 : (datum.wins / datum.total * 100).toFixed(0);
doSum = false;
} else {
datum = new Object();
datum.name = InfoFetcher.openingNameJp(str);
datum.tip = InfoFetcher.openingNameEn(str);
datum.black_wins = _openingData[str].black_wins;
if (doSum) black_wins_sum += datum.black_wins;
datum.black_losses = _openingData[str].black_losses;
if (doSum) black_losses_sum += datum.black_losses;
datum.black_total = datum.black_wins + datum.black_losses;
datum.black_percent = datum.black_total == 0 ? 0 : (datum.black_wins / datum.black_total * 100).toFixed(0);
datum.white_wins = _openingData[str].white_wins;
if (doSum) white_wins_sum += datum.white_wins;
datum.white_losses = _openingData[str].white_losses;
if (doSum) white_losses_sum += datum.white_losses;
datum.white_total = datum.white_wins + datum.white_losses;
datum.white_percent = datum.white_total == 0 ? 0 : (datum.white_wins / datum.white_total * 100).toFixed(0);
datum.wins = datum.black_wins + datum.white_wins;
datum.losses = datum.black_losses + datum.white_losses;
datum.total = datum.wins + datum.losses;
datum.percent = datum.total == 0 ? 0 : (datum.wins / datum.total * 100).toFixed(0);
}
arr.push(datum);
}
return arr;
}
private function _openingDatum(group:String):Object {
var obj:Object = new Object();
obj.black_wins = 0;
obj.black_losses = 0;
obj.white_wins = 0;
obj.white_losses = 0;
obj.group = group;
return obj;
}
]]>
</mx:Script>
<mx:HBox>
<mx:VBox width="150" height="190" horizontalScrollPolicy="off" verticalScrollPolicy="off" borderStyle="solid">
<mx:Canvas id="avatarCanvas" width="133" height="133">
<mx:Image width="128" height="128" source="{avatar}" x="5" y="5" />
</mx:Canvas>
<mx:Label text="{login}" fontSize="15" fontWeight="bold"/>
<mx:Spacer height="-10"/>
<mx:HBox horizontalGap="0">
<mx:Image width="27" height="17" source="{IMAGE_DIRECTORY}flags_s/{_country_code}.gif"/>
<mx:Label text="{_country}"/>
</mx:HBox>
</mx:VBox>
<mx:VBox>
<mx:Label text="{parentApplication.lan.status}: {connection}"/>
<mx:Label text="{parentApplication.lan.signed_up}: {_joined}"/>
<mx:Label text="{parentApplication.lan.last_updated}: {_updated}" />
<mx:Label text="PR:"/>
<mx:Spacer height="-15"/>
<mx:TextArea width="220" height="95" text="{_pr}" fontSize="10" editable="false" />
</mx:VBox>
<maps:Map xmlns:maps="com.google.maps.*" id="map" mapevent_mapready="_onMapReady(event)" width="280" height="190"
key="ABQIAAAA3ixmRh8intDkiLxI7stEWBRRcFstc8fS6PNRbx73gFqDz6uERRTy8n1ZPM6UZ8fRVdmwPSXdTYkA1w" sensor="false" />
</mx:HBox>
<mx:HBox>
<mx:VBox borderStyle="solid">
<mx:HBox>
<mx:Label text="Shogi" fontWeight="bold" fontSize="13" />
<mx:Spacer width="20"/>
<mx:Button label="{parentApplication.lan.tendency}" click="resultViewStack.selectedIndex = 0;" fontSize="10" />
<mx:Button label="{parentApplication.lan.percentage}" click="resultViewStack.selectedIndex = 1;" fontSize="10"/>
<mx:Button label="{parentApplication.lan.rate_history}" click="resultViewStack.selectedIndex = 2;" fontSize="10"/>
<mx:Button label="{parentApplication.lan.data_table}" click="resultViewStack.selectedIndex = resultViewStack.selectedIndex == 3 ? 4 : 3;" fontSize="10"/>
</mx:HBox>
<mx:HBox>
<mx:ViewStack id="resultViewStack" width="400" height="220">
<eightyOneSquare:OpeningPieChart id="openingPieChart" width="400" height="220" horizontalScrollPolicy="off" verticalScrollPolicy="off" />
<eightyOneSquare:OpeningRadarChart id="openingRadarChart" width="400" height="220" horizontalScrollPolicy="off" verticalScrollPolicy="off" />
<mx:Canvas width="400" height="220" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<eightyOneSquare:Plot2D id="ratePlot2D" width="400" height="220"/>
</mx:Canvas>
<mx:HBox width="400" height="220" horizontalAlign="center">
<mx:AdvancedDataGrid id="dataGrid1" width="400" height="215" sortableColumns="false" sortExpertMode="true" fontSize="10" textAlign="right" paddingLeft="0" paddingTop="0" rowHeight="19">
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="Openings" width="76" dataField="name" textAlign="center" showDataTips="true" dataTipField="tip" />
<mx:AdvancedDataGridColumnGroup headerText="{parentApplication.lan.total}">
<mx:AdvancedDataGridColumn width="27" headerText="T" dataField="total" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="W" dataField="wins" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="L" dataField="losses" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="%" dataField="percent" paddingLeft="2" />
</mx:AdvancedDataGridColumnGroup>
<mx:AdvancedDataGridColumnGroup headerText="{parentApplication.lan.black}(▲)">
<mx:AdvancedDataGridColumn width="27" headerText="T" dataField="black_total" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="W" dataField="black_wins" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="L" dataField="black_losses" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="%" dataField="black_percent" paddingLeft="2" />
</mx:AdvancedDataGridColumnGroup>
<mx:AdvancedDataGridColumnGroup headerText="{parentApplication.lan.white}(△)">
<mx:AdvancedDataGridColumn width="27" headerText="T" dataField="white_total" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="W" dataField="white_wins" />
<mx:AdvancedDataGridColumn width="27" headerText="L" dataField="white_losses" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="%" dataField="white_percent" paddingLeft="2"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
</mx:HBox>
<mx:HBox width="400" height="220" horizontalAlign="center">
<mx:AdvancedDataGrid id="dataGrid2" width="400" height="215" sortableColumns="false" sortExpertMode="true" fontSize="10" textAlign="right" paddingLeft="0" paddingTop="0" rowHeight="19" verticalScrollPolicy="off">
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="Openings" width="76" dataField="name" textAlign="center" showDataTips="true" dataTipField="tip" />
<mx:AdvancedDataGridColumnGroup headerText="{parentApplication.lan.total}">
<mx:AdvancedDataGridColumn width="27" headerText="T" dataField="total" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="W" dataField="wins" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="L" dataField="losses" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="%" dataField="percent" paddingLeft="2" />
</mx:AdvancedDataGridColumnGroup>
<mx:AdvancedDataGridColumnGroup headerText="{parentApplication.lan.black}(▲)">
<mx:AdvancedDataGridColumn width="27" headerText="T" dataField="black_total" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="W" dataField="black_wins" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="L" dataField="black_losses" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="%" dataField="black_percent" paddingLeft="2" />
</mx:AdvancedDataGridColumnGroup>
<mx:AdvancedDataGridColumnGroup headerText="{parentApplication.lan.white}(△)">
<mx:AdvancedDataGridColumn width="27" headerText="T" dataField="white_total" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="W" dataField="white_wins" />
<mx:AdvancedDataGridColumn width="27" headerText="L" dataField="white_losses" paddingLeft="2"/>
<mx:AdvancedDataGridColumn width="27" headerText="%" dataField="white_percent" paddingLeft="2"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
</mx:HBox>
</mx:ViewStack>
<mx:VBox width="125" verticalGap="3">
<!-- <mx:Label text="{_title}" toolTip="{_subTitle}" /> -->
<mx:Label text="{_rank}"/>
<mx:Label text="R: {_rating}"/>
<mx:Label text=" (max: )"/>
<mx:Label text="Win: {_wins}"/>
<mx:Label text="Loss: {_losses}"/>
<mx:Label text=" (Total: {_wins + _losses})"/>
<mx:Label text=" ({_percentage.toFixed(1)}% win)"/>
<mx:Label text="Streak: {_streak_best}"/>
</mx:VBox>
</mx:HBox>
</mx:VBox>
<mx:VBox borderStyle="solid" width="125" height="250" verticalGap="0" verticalScrollPolicy="off">
<mx:Label text="3X4" fontWeight="bold" fontSize="13" />
<mx:Canvas id="avatar34Canvas" width="85" height="80">
<mx:Image width="80" height="80" source="{IMAGE_DIRECTORY}avatars34/{_rank34}.jpg" x="5" />
</mx:Canvas>
<mx:Label text="{_rank34}"/>
<mx:Label text="EXP: {_exp}"/>
<mx:Label text="Win: {_wins34}"/>
<mx:Label text="Loss: {_losses34}"/>
<mx:Label text="Draw: {_draws34}"/>
<mx:Label text=" (Total: {_wins34 + _losses34})"/>
<mx:Label text=" ({_percentage34.toFixed(1)}% win)"/>
</mx:VBox>
</mx:HBox>
</mx:TitleWindow>