This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Vanity.as
1183 lines (961 loc) · 34.5 KB
/
Vanity.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
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package {
import caurina.transitions.Tweener;
import com.adobe.serialization.json.JSON;
import com.tinyspeck.bootstrap.BootUtil;
import com.tinyspeck.bridge.FlashVarModel;
import com.tinyspeck.core.beacon.StageBeacon;
import com.tinyspeck.core.data.AvatarSwfParticulars;
import com.tinyspeck.core.data.FlashVarData;
import com.tinyspeck.debug.Console;
import com.tinyspeck.engine.data.pc.AvatarConfig;
import com.tinyspeck.engine.event.TSEvent;
import com.tinyspeck.engine.loader.AvatarConfigRecord;
import com.tinyspeck.engine.loader.AvatarResourceManager;
import com.tinyspeck.engine.loader.SmartLoader;
import com.tinyspeck.engine.loader.SmartURLLoader;
import com.tinyspeck.engine.memory.EnginePools;
import com.tinyspeck.engine.model.TSEngineConstants;
import com.tinyspeck.engine.port.AssetManager;
import com.tinyspeck.engine.port.CSSManager;
import com.tinyspeck.engine.spritesheet.AvatarSSManager;
import com.tinyspeck.engine.util.ColorUtil;
import com.tinyspeck.engine.util.ObjectUtil;
import com.tinyspeck.engine.util.PNGUtil;
import com.tinyspeck.engine.util.TFUtil;
import com.tinyspeck.engine.view.gameoverlay.TipDisplayManager;
import com.tinyspeck.engine.view.loadedswfs.AvatarSwf;
import com.tinyspeck.engine.view.util.StaticFilters;
import com.tinyspeck.tstweener.TSTweener;
import com.tinyspeck.vanity.ColorsVanityTabPane;
import com.tinyspeck.vanity.DimsPane;
import com.tinyspeck.vanity.FeaturesVanityTabPane;
import com.tinyspeck.vanity.HatVanityDialog;
import com.tinyspeck.vanity.LeavingVanityDialog;
import com.tinyspeck.vanity.LoadingVanityDialog;
import com.tinyspeck.vanity.SavingVanityDialog;
import com.tinyspeck.vanity.SubscribeFreePromptVanityDialog;
import com.tinyspeck.vanity.SubscribePayPromptVanityDialog;
import com.tinyspeck.vanity.SubscribedVanityDialog;
import com.tinyspeck.vanity.VanityMirror;
import com.tinyspeck.vanity.VanityModel;
import flash.display.Bitmap;
import flash.display.BlendMode;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.events.UncaughtErrorEvent;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.net.navigateToURL;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.text.TextField;
public class Vanity extends Sprite {
private var standalone:Boolean;
private var new_skin_coloring:Boolean;
private var www_pngs_str:String;
private var cssLoader:SmartURLLoader;
private var avaConfigLoader:SmartURLLoader;
private var optionsLoader:SmartURLLoader;
private var subscribeLoader:SmartURLLoader;
private var saveWardrobeLoader:SmartURLLoader;
private var saveFaceLoader:SmartURLLoader;
private var ava_loader:SmartLoader;
private var ava_swf:AvatarSwf;
private var current_ac:AvatarConfig;
private var load_steps:int;
private var current_load_step:int;
private var w:int;
private var h:int;
private var vanity_mirror:VanityMirror;
private var features_pane:FeaturesVanityTabPane;
private var colors_pane:ColorsVanityTabPane;
private var dims_pane:DimsPane;
private var blocker_sp:Sprite = new Sprite();
private var loading_sp:Sprite = new Sprite();
private var loading_dialog:LoadingVanityDialog;
//private var loading_pb:ProgressBar = new ProgressBar(200, 20);
private var content_sp:Sprite = new Sprite();
private var saving_sp:Sprite = new Sprite();
private var saving_dialog:SavingVanityDialog;
private var subbed_sp:Sprite = new Sprite();
private var subbed_dialog:SubscribedVanityDialog;
private var sub_free_sp:Sprite = new Sprite();
private var sub_free_dialog:SubscribeFreePromptVanityDialog;
private var sub_pay_sp:Sprite = new Sprite();
private var sub_pay_dialog:SubscribePayPromptVanityDialog;
private var leaving_sp:Sprite = new Sprite();
private var leaving_dialog:LeavingVanityDialog;
private var hat_sp:Sprite = new Sprite();
private var hat_dialog:HatVanityDialog;
private var bt_that_trigger_sub:Sprite;
private var logo_sp:Sprite = new Sprite();
private var home_tf:TextField = new TextField();
public function Vanity() {
// disable yellow tabbing rectangle
stage.stageFocusRect = false;
init();
}
private function handleGlobalErrors(e:UncaughtErrorEvent):void {
if (e.error) {
if (e.error.getStackTrace) {
;
CONFIG::debugging {
Console.error(e.error.getStackTrace());
}
} else {
;
CONFIG::debugging {
Console.error(e.error);
}
}
} else {
;
CONFIG::debugging {
Console.error(e);
}
}
}
private function init():void {
this.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleGlobalErrors);
const fvm:FlashVarModel = new FlashVarModel(FlashVarData.createFlashVarData(this));
StageBeacon.init(stage, fvm);
EnginePools.init();
AvatarSSManager.init('');
logo_sp.useHandCursor = logo_sp.buttonMode = true;
logo_sp.visible = false;
logo_sp.addEventListener(MouseEvent.CLICK, onLogoClick, false, 0, true);
stage.addChild(logo_sp);
TFUtil.prepTF(home_tf, false);
home_tf.embedFonts = false;
home_tf.htmlText = '<span class="vanity_nav"><a href="event:wardrobe" class="vanity_nav_link"> Wardrobe</a> | <a href="event:home" class="vanity_nav_link">Return to Site</a></span>';
home_tf.addEventListener(TextEvent.LINK, onTextLinkClick, false, 0, true);
logo_sp.addChild(home_tf);
content_sp.visible = false;
content_sp.blendMode = BlendMode.LAYER;
addChild(content_sp);
blocker_sp.visible = false;
blocker_sp.alpha = 0;
addChild(blocker_sp);
addChild(loading_sp);
saving_sp.visible = false;
addChild(saving_sp);
subbed_sp.visible = false;
addChild(subbed_sp);
sub_free_sp.visible = false;
addChild(sub_free_sp);
sub_pay_sp.visible = false;
addChild(sub_pay_sp);
leaving_sp.visible = false;
addChild(leaving_sp);
hat_sp.visible = false;
addChild(hat_sp);
var fvd:FlashVarData = FlashVarData.createFlashVarData(this);
standalone = fvd.getFlashvar('standalone') == 'true';
new_skin_coloring = fvd.getFlashvar('new_skin_coloring') == 'true';
www_pngs_str = fvd.getFlashvar('www_pngs');
if (standalone) {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = TSEngineConstants.TARGET_FRAMERATE;
var base_w:int = 960;
var base_h:int = 600;
go(base_w, base_h, new FlashVarModel(fvd));
function onStageResize():void {
var widthScale:Number = stage.stageWidth / base_w; // base_w is the original width of the swf, you should replace it with your width
scaleX = scaleY = widthScale;
logo_sp.scaleX = logo_sp.scaleY = widthScale;
}
StageBeacon.resize_sig.add(onStageResize);
onStageResize();
}
}
// called from here if running as standalone
// called from client if loaded as module
public function go(w:int, h:int, fvm:FlashVarModel, mc:MovieClip = null):void {
this.w = w;
this.h = h;
AvatarResourceManager.avatar_url = fvm.avatar_url;
VanityModel.fvm = fvm;
VanityModel.ava_settings = fvm.ava_settings;
//Console.dir(fvm.ava_settings);
drawBlocker(blocker_sp.graphics);
//loading_sp.addChild(loading_pb);
//loading_pb.x = Math.round((w-loading_pb.w)/2);
//loading_pb.y = Math.round((h-loading_pb.h)/2);
load_steps = 4;
if (www_pngs_str) {
VanityModel.imgs_to_loadH = (www_pngs_str) ? com.adobe.serialization.json.JSON.decode(www_pngs_str) : [];
CONFIG::debugging {
Console.dir(VanityModel.imgs_to_loadH);
}
}
for (var k:String in VanityModel.imgs_to_loadH) {
load_steps++
}
if (standalone) {
load_steps+= 2;
TSTweener.useEngine(TSTweener.TWEENER);
// we have to set up stuff ourselves
BootUtil.setUpAPIAndConsole(fvm);
PNGUtil.setAPIUrl(fvm.api_url, fvm.api_token);
addChild(TipDisplayManager.instance);
} else {
// we should expect all the relevant data etc to be sent to us
setMc(mc);
}
loadBASE64bitmaps();
}
private var BASE64_loaded:int;
private function loadBASE64bitmaps():void {
for each (var bm:Object in VanityModel.base64_bitmaps_to_load_for_preloaderA) {
AssetManager.instance.loadBitmapFromBASE64(bm.key, bm.str, onBASE64bitmapLoaded);
}
}
private function onBASE64bitmapLoaded(key:String, bm:Bitmap):void {
BASE64_loaded++;
if (BASE64_loaded == VanityModel.base64_bitmaps_to_load_for_preloaderA.length) {
doneLoadingBASE64bitmaps();
}
}
private function doneLoadingBASE64bitmaps():void {
if (standalone) {
loadCSS();
} else {
showLoadingDialog();
loadAvaConfig();
}
}
private function setMc(mc:MovieClip):void {
ava_swf = new AvatarSwf(mc, new_skin_coloring);
}
private function showProgess(step:int, secs:Number=2):void {
current_load_step = step;
//Console.info('perc:'+(current_load_step/load_steps)+' secs:'+secs)
if (loading_dialog) loading_dialog.pb.updateWithAnimation(secs, current_load_step/load_steps);
}
private function loadCSS():void {
showProgess(current_load_step+1, 1);
cssLoader = new SmartURLLoader('css');
// these are automatically removed on complete or error:
cssLoader.complete_sig.add(onCSSLoadComplete);
//cssLoader.error_sig.add(function():void{});
cssLoader.load(new URLRequest(VanityModel.fvm.css_file));
}
private function onCSSLoadComplete(loader:SmartURLLoader):void {
CSSManager.instance.init(loader.data);
VanityModel.updateFromCSS();
StaticFilters.updateFromCSS();
content_sp.x = Math.round((w-VanityModel.ui_w)/2);
var bm:Bitmap = AssetManager.instance.getLoadedBitmap('vanity_logo_str');
if (bm) {
logo_sp.addChild(bm);
} else {
; // satisfy compiler
CONFIG::debugging {
Console.warn('We should have this fucker loaded, damnit.');
}
}
logo_sp.x = content_sp.x;
logo_sp.y = (VanityModel.logo_y);
home_tf.x = VanityModel.ui_w-home_tf.width;
home_tf.y = Math.round((bm.height-home_tf.height)/2);
// only called here if is standalone, I believe, since otherwise we already have the css
showLoadingDialog();
loadAvatar();
}
private function showLoadingDialog():void {
loading_dialog = new LoadingVanityDialog();
loading_dialog.x = Math.round((w-loading_dialog.width)/2);
loading_dialog.y = Math.round((h-loading_dialog.height)/2);
loading_sp.addChild(loading_dialog);
}
private function areChanges():Boolean {
if (AvatarConfig.fromAnonymous(VanityModel.ava_config).sig != AvatarConfig.fromAnonymous(VanityModel.ava_config_saved).sig) return true;
return false;
}
private function onTextLinkClick(event:TextEvent):void {
if (areChanges()) {
showLeavingOverlay(false);
return;
}
if (event.text == 'wardrobe') {
exit('/wardrobe/');
} else if (event.text == 'home') {
exit('/');
}
}
private function onLogoClick(event:Event):void {
if (event.target is TextField) return; // the tf is handled by onTextLinkClick
if (areChanges()) {
showLeavingOverlay(false);
return;
}
exit();
}
private function exit(url:String = '/'):void {
CONFIG::debugging {
Console.info('exit to '+url);
}
navigateToURL(new URLRequest(url), '_self');
}
private function loadAvatar():void {
showProgess(current_load_step+1, 2);
ava_loader = new SmartLoader('avatar');
// these are automatically removed on complete or error:
ava_loader.complete_sig.add(onAvatarLoadComplete);
//ava_loader.error_sig.add(function():void{});
var loaderContext:LoaderContext = new LoaderContext(false,new ApplicationDomain(ApplicationDomain.currentDomain), null);
ava_loader.load(new URLRequest(VanityModel.fvm.avatar_url), loaderContext);
/*CONFIG::debugging {
Console.log(66, VanityModel.fvm.avatar_url);
}*/
}
private function onAvatarLoadComplete(loader:SmartLoader):void {
setMc(ava_loader.content as MovieClip);
loadAvaConfig();
}
private function loadAvaConfig():void {
showProgess(current_load_step+1, 1);
if (!ava_swf) {
CONFIG::debugging {
Console.error('loadAvaConfig called, but we have no ava_swf');
}
return;
}
avaConfigLoader = new SmartURLLoader('avaConfig');
// these are automatically removed on complete or error:
avaConfigLoader.complete_sig.add(onConfigLoadComplete);
CONFIG::debugging {
avaConfigLoader.error_sig.add(
function (loader:SmartURLLoader):void {
Console.error('failed to load '+url);
}
);
}
var url:String = VanityModel.fvm.api_url+'simple/avatar.getDetails?ctoken='+VanityModel.fvm.api_token+'&cb='+String(new Date().getTime());
CONFIG::debugging {
Console.log(66, url);
}
avaConfigLoader.load(new URLRequest(url));
}
private function onConfigLoadComplete(loader:SmartURLLoader):void {
var json_str:String = loader.data;
var rsp:Object = (json_str) ? com.adobe.serialization.json.JSON.decode(json_str) : {};
if (!rsp || !rsp.ok) {
CONFIG::debugging {
Console.warn('error loading item info');
}
return;
}
// the one with the db ids
VanityModel.base_hash = rsp.base_hash;
VanityModel.base_hash_saved = ObjectUtil.copyOb(VanityModel.base_hash);
// the ava_config
VanityModel.ava_config = rsp.hash;
VanityModel.ava_config_saved = ObjectUtil.copyOb(VanityModel.ava_config);
CONFIG::debugging {
Console.dir(rsp);
}
loadOptions();
}
private function loadOptions():void {
showProgess(current_load_step+1, 1);
if (!ava_swf) {
CONFIG::debugging {
Console.error('loadOptions called, but we have no ava_swf');
}
return;
}
optionsLoader = new SmartURLLoader('options');
// these are automatically removed on complete or error:
optionsLoader.complete_sig.add(onOptionsLoadComplete);
CONFIG::debugging {
optionsLoader.error_sig.add(
function(loader:SmartURLLoader):void {
Console.error('failed to load '+url);
}
);
}
var url:String = VanityModel.fvm.api_url+'simple/faces.getCatalog?ctoken='+VanityModel.fvm.api_token+'&cb='+String(new Date().getTime());
CONFIG::debugging {
Console.log(66, url);
}
optionsLoader.load(new URLRequest(url));
}
private function onOptionsLoadComplete(loader:SmartURLLoader):void {
var json_str:String = loader.data;
var rsp:Object = (json_str) ? com.adobe.serialization.json.JSON.decode(json_str) : {};
if (!rsp || !rsp.ok) {
CONFIG::debugging {
Console.warn('error loading item info');
}
return;
}
VanityModel.color_options = rsp.colors;
for (var ctype:String in VanityModel.color_options) {
for (var id:String in VanityModel.color_options[ctype]) {
var color:Object = VanityModel.color_options[ctype][id];
var HSV:Object = ColorUtil.rgb2hsv(ColorUtil.colorStrToNum(color.color));
color.h = HSV.h;
color.s = HSV.s;
color.v = HSV.v;
}
}
VanityModel.feature_options = rsp.features;
// add in 0 ('none') options for the non-required features
for (var type:String in VanityModel.features_required_map) {
if (VanityModel.features_required_map[type] === false) {
if (!VanityModel.feature_options[type]['0']) {
VanityModel.feature_options[type]['0'] = {
package_url: '',
article_class_name: 'none'
}
}
}
}
CONFIG::debugging {
Console.dir(rsp);
}
loadFaceSwfs();
}
private function loadFaceSwfs():void {
// let's make options_ava_config a "fake" config record! so we can load all the swfs we need through the arm:AvatarResourceManager
// and have aca's ready for arm.getArticlePartMC(aca, part_class_name) to display the options
var collection:Object;
var option:Object;
for (var type:String in VanityModel.features_name_map) {
collection = VanityModel.feature_options[type];
for (var id:String in collection) {
option = collection[id];
VanityModel.options_ava_config.articles[type+id] = {
article_class_name: option.article_class_name,
package_swf_url: option.package_url
}
}
}
CONFIG::debugging {
Console.dir(VanityModel.options_ava_config);
}
var ac:AvatarConfig = AvatarConfig.fromAnonymous(VanityModel.options_ava_config);
var acr:AvatarConfigRecord = AvatarResourceManager.instance.getAvatarConfigRecord(ac, ava_swf);
if (!acr.ready) {
load_steps+=5;
showProgess(current_load_step+5, 3);
acr.addCallback(function(ac:AvatarConfig):void {
onFaceSwfsLoaded();
});
} else {
onFaceSwfsLoaded();
}
}
private function onFaceSwfsLoaded():void {
showProgess(current_load_step+1, 2);
var c:int;
for (var k:String in VanityModel.imgs_to_loadH) {
var url:String = VanityModel.imgs_to_loadH[k];
if (!url) continue;
c++
if (url.indexOf('/img/') == 0) {
//url = url.replace('/img/', '');
}
AssetManager.instance.loadBitmapFromWeb(url, onWWWimgBitmapLoaded, 'onFaceSwfsLoaded()');
}
if (!c) {
//doneLoading();
}
}
private function onWWWimgBitmapLoaded(filename:String, bm:Bitmap):void {
showProgess(current_load_step+1, .5);
if (current_load_step == load_steps-1) {
doneLoading();
}
}
private function doneLoading():void {
vanity_mirror = new VanityMirror(ava_swf, doReset, doSave, doAnimation);
vanity_mirror.x = Math.round((VanityModel.ui_w-VanityModel.mirror_column_w)/2);
vanity_mirror.y = VanityModel.mirror_y;
content_sp.addChild(vanity_mirror);
vanity_mirror.init();
features_pane = new FeaturesVanityTabPane(onFeatureChange, showSubOverlay);
features_pane.hatHideCallBack = function(hide:Boolean):void {
if (hide) {
hideHat();
} else {
showHat();
}
initializeHead();
}
features_pane.hatRemoveCallBack = function():void {
removeHat();
initializeHead();
}
features_pane.y = VanityModel.tab_panel_y;
content_sp.addChild(features_pane);
colors_pane = new ColorsVanityTabPane(onColorChange, showSubOverlay);
colors_pane.x = VanityModel.ui_w - VanityModel.features_tab_panel_w;
colors_pane.y = VanityModel.tab_panel_y;
content_sp.addChild(colors_pane);
dims_pane = new DimsPane(onDimChange);
dims_pane.x = Math.round((VanityModel.ui_w-VanityModel.dimensions_panel_w)/2);
dims_pane.y = VanityModel.tab_panel_y+VanityModel.tab_panel_h+VanityModel.panel_margin;
content_sp.addChild(dims_pane);
features_pane.addEventListener(TSEvent.CHANGED, onFeaturesTabChanged);
colors_pane.addEventListener(TSEvent.CHANGED, onColorsTabChanged);
////------
saving_dialog = new SavingVanityDialog();
saving_dialog.x = Math.round((w-saving_dialog.width)/2);
saving_dialog.y = Math.round((h-saving_dialog.height)/2);
saving_sp.addChild(saving_dialog);
////------
subbed_dialog = new SubscribedVanityDialog();
subbed_dialog.ok_bt.addEventListener(MouseEvent.CLICK, onSubOkBtClick, false, 0, true);
subbed_dialog.x = Math.round((w-subbed_dialog.width)/2);
subbed_dialog.y = Math.round((h-subbed_dialog.height)/2);
subbed_sp.addChild(subbed_dialog);
////------
sub_free_dialog = new SubscribeFreePromptVanityDialog();
sub_free_dialog.sub_bt.addEventListener(MouseEvent.CLICK, onFreeSubBtClick, false, 0, true);
sub_free_dialog.no_bt.addEventListener(MouseEvent.CLICK, onFreeSubNoBtClick, false, 0, true);
sub_free_dialog.x = Math.round((w-sub_free_dialog.width)/2);
sub_free_dialog.y = Math.round((h-sub_free_dialog.height)/2);
sub_free_sp.addChild(sub_free_dialog);
////------
sub_pay_dialog = new SubscribePayPromptVanityDialog();
sub_pay_dialog.sub_bt.addEventListener(MouseEvent.CLICK, onPaySubBtClick, false, 0, true);
sub_pay_dialog.no_bt.addEventListener(MouseEvent.CLICK, onPaySubNoBtClick, false, 0, true);
sub_pay_dialog.x = Math.round((w-sub_pay_dialog.width)/2);
sub_pay_dialog.y = Math.round((h-sub_pay_dialog.height)/2);
sub_pay_sp.addChild(sub_pay_dialog);
////------
leaving_dialog = new LeavingVanityDialog();
leaving_dialog.home_bt.addEventListener(MouseEvent.CLICK, onLeavingHomeBtClick, false, 0, true);
leaving_dialog.wardrobe_bt.addEventListener(MouseEvent.CLICK, onLeavingWardrobeBtClick, false, 0, true);
leaving_dialog.stay_bt.addEventListener(MouseEvent.CLICK, onLeavingStayBtClick, false, 0, true);
leaving_dialog.x = Math.round((w-leaving_dialog.width)/2);
leaving_dialog.y = Math.round((h-leaving_dialog.height)/2);
leaving_sp.addChild(leaving_dialog);
////------
hat_dialog = new HatVanityDialog();
hat_dialog.remove_bt.addEventListener(MouseEvent.CLICK, onHatRemoveBtClick, false, 0, true);
hat_dialog.hide_bt.addEventListener(MouseEvent.CLICK, onHatHideBtClick, false, 0, true);
hat_dialog.x = Math.round((w-hat_dialog.width)/2);
hat_dialog.y = Math.round((h-hat_dialog.height)/2);
hat_sp.addChild(hat_dialog);
////-------
showProgess(load_steps, 3);
initializeHead();
//ava_swf.gotoFrameNumAndStop(VanityModel.ava_frame);
doAnimation('idle3');
}
private function drawBlocker(g:Graphics):void {
g.lineStyle(0, 0, 0);
g.beginFill(0xffffff, .8);
g.drawRect(0, 0, w, h);
}
////------
private function onLeavingHomeBtClick(event:Event):void {
//hideLeavingOverlay();
leaving_sp.visible = false; // leave the blocker
exit();
}
private function onLeavingWardrobeBtClick(event:Event):void {
//hideLeavingOverlay();
leaving_sp.visible = false; // leave the blocker
exit('/wardrobe/');
}
private function onLeavingStayBtClick(event:Event):void {
hideLeavingOverlay();
}
private function showBlocker():void {
//if (blocker_sp.visible) return;
blocker_sp.visible = true;
//blocker_sp.alpha = 0;
Tweener.removeTweens(blocker_sp);
Tweener.addTween(blocker_sp, {alpha:1, time:VanityModel.fade_secs});
}
private function hideBlocker():void {
Tweener.removeTweens(blocker_sp);
Tweener.addTween(blocker_sp, {_autoAlpha:0, time:VanityModel.fade_secs});
}
private function showLeavingOverlay(saved:Boolean):void {
if (saved) {
leaving_dialog.makeForSaved();
} else {
leaving_dialog.makeForUnsaved()
}
leaving_sp.visible = true;
showBlocker();
}
private function hideLeavingOverlay():void {
leaving_sp.visible = false;
hideBlocker();
}
private function onHatHideBtClick(event:Event):void {
features_pane.showHatControls();
hideHat();
hideHatOverlay();
}
private function onHatRemoveBtClick(event:Event):void {
removeHat();
hideHatOverlay();
}
private function showHatOverlay():void {
hat_sp.visible = true;
showBlocker();
}
private function hideHatOverlay():void {
initializeHead();
hat_sp.visible = false;
hideBlocker();
}
////------
private function showSubscribeDoneOverlay():void {
subbed_sp.visible = true;
showBlocker();
}
private function onSubOkBtClick(event:Event):void {
subbed_dialog.visible = false;
hideBlocker();
}
////------
private function onFreeSubBtClick(event:Event):void {
hideSubOverlay();
doSubscribe();
}
private function onFreeSubNoBtClick(event:Event):void {
hideSubOverlay();
}
private function onPaySubBtClick(event:Event):void {
// redirect
exit(VanityModel.sub_url);
}
private function onPaySubNoBtClick(event:Event):void {
hideSubOverlay();
}
private function doSubscribe():void {
//Console.warn('saving...');
saving_sp.visible = true;
showBlocker();
saving_dialog.setTxt('Subscribing...');
saving_dialog.pb.update(0);
sub_free_dialog.sub_bt.removeEventListener(MouseEvent.CLICK, onFreeSubBtClick);
subscribeLoader = new SmartURLLoader('subscribe');
// these are automatically removed on complete or error:
subscribeLoader.complete_sig.add(onTrialSubscriptionLoadComplete);
CONFIG::debugging {
subscribeLoader.error_sig.add(
function(loader:SmartURLLoader):void {
Console.error('failed to load '+url);
}
);
}
var url:String = VanityModel.fvm.api_url+'simple/users.trialSubscription?ctoken='+VanityModel.fvm.api_token+'&cb='+String(new Date().getTime());
CONFIG::debugging {
Console.log(66, url);
}
subscribeLoader.load(new URLRequest(url));
}
private function showSubOverlay(bt:Sprite):void {
bt_that_trigger_sub = bt;
if (VanityModel.fvm.player_had_free_sub) {
sub_pay_sp.visible = true;
showBlocker();
} else {
sub_free_sp.visible = true;
showBlocker();
}
}
private function hideSubOverlay():void {
// just in case, re sub
sub_free_dialog.sub_bt.addEventListener(MouseEvent.CLICK, onFreeSubBtClick, false, 0, true);
sub_free_sp.visible = false;
// just in case, re sub
sub_free_dialog.sub_bt.addEventListener(MouseEvent.CLICK, onPaySubBtClick, false, 0, true);
sub_pay_sp.visible = false;
hideBlocker();
}
////------
private function onTrialSubscriptionLoadComplete(loader:SmartURLLoader):void {
var json_str:String = loader.data;
var rsp:Object = (json_str) ? com.adobe.serialization.json.JSON.decode(json_str) : {};
if (!rsp || (!rsp.ok && rsp.error != 'previous_subscriber')) {
CONFIG::debugging {
Console.warn('error calling api');
}
return;
}
saving_dialog.pb.addEventListener(TSEvent.COMPLETE, onSavingSubscribePBComplete);
saving_dialog.pb.updateWithAnimation(1, 1);
CONFIG::debugging {
Console.dir(rsp);
}
VanityModel.fvm.player_is_subscriber = true;
colors_pane.onPlayerSubscribed(bt_that_trigger_sub);
features_pane.onPlayerSubscribed(bt_that_trigger_sub);
}
private function onFeaturesTabChanged(e:TSEvent):void {
//Console.warn('feat tab is '+e.data);
if (e.data == 'hair') {
colors_pane.activateTab('hair');
}
}
private function onColorsTabChanged(e:TSEvent):void {
//Console.warn('color tab is '+e.data);
}
private function initializeHead():void {
var ac:AvatarConfig = AvatarConfig.fromAnonymous(VanityModel.ava_config);
var acr:AvatarConfigRecord = AvatarResourceManager.instance.getAvatarConfigRecord(ac, ava_swf);
current_ac = ac;
//ava_swf.gotoFrameNumAndStop(VanityModel.ava_frame);
ava_swf.initializeHead(ac);
//ava_swf.gotoFrameNumAndStop(VanityModel.ava_frame);
if (!acr.ready) {
acr.addCallback(function(ac:AvatarConfig):void {
if (current_ac.sig == ac.sig) {
ava_swf.initializeHead(ac);
avaReadyCallback();
} else {
; // satisfy compiler
CONFIG::debugging {
Console.priwarn(89, ac.sig+' IS NOT '+current_ac.sig);
}
}
});
} else {
avaReadyCallback();
}
}
private function avaReadyCallback():void {
if (content_sp.visible) return;
content_sp.alpha = 0;
content_sp.visible = true;
logo_sp.visible = true;
Tweener.addTween(content_sp, {alpha:1, time:VanityModel.fade_secs});
Tweener.addTween(loading_sp, {_autoAlpha:0, time:VanityModel.fade_secs});
loading_dialog.clean();
}
private function doReset():void {
VanityModel.ava_config = ObjectUtil.copyOb(VanityModel.ava_config_saved);
VanityModel.base_hash = ObjectUtil.copyOb(VanityModel.base_hash_saved);
features_pane.unCheckHatCb();
updateAllUI();
}
private function updateAllUI():void {
initializeHead();
dims_pane.updateFromAvaConfig();
features_pane.updateFromAvaConfig();
colors_pane.updateFromAvaConfig();
}
private function doAnimation(anim:String):void {
//Console.warn('anim:'+anim);
ava_swf.playAnimation(anim, function():void {
ava_swf.playFrameSeq([VanityModel.ava_frame]);
});
}
private function doSave():void {
//Console.warn('saving...');
saving_sp.visible = true;
showBlocker();
saving_dialog.setTxt('Saving...');
saving_dialog.pb.update(0);
if (hat_removed) {
saveWardrobe();
} else {
saveFace();
}
}
private function saveWardrobe():void {
saving_dialog.pb.updateWithAnimation(1, .4);
saveWardrobeLoader = new SmartURLLoader('wardrobe');
var url:String = VanityModel.fvm.api_url+'simple/wardrobe.setClothes';
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.ctoken = VanityModel.fvm.api_token;
for (var k:String in VanityModel.base_hash) {
variables[k] = VanityModel.base_hash[k];
}
// get all the dims from the ava_config
for (k in VanityModel.dims_name_map) {
//Console.info('setting '+k+' to '+VanityModel.ava_config[k])
variables[k] = VanityModel.ava_config[k];
}
CONFIG::debugging {
Console.dir(variables);
}
request.data = variables;
request.method = URLRequestMethod.POST;
// these are automatically removed on complete or error:
saveWardrobeLoader.complete_sig.add(onSavedWardrobe);
CONFIG::debugging {
saveWardrobeLoader.error_sig.add(
function(loader:SmartURLLoader):void {
Console.warn('failed to load '+url);
}
);
}
CONFIG::debugging {
Console.log(66, url)
}
saveWardrobeLoader.load(request);
}
private function onSavedWardrobe(loader:SmartURLLoader):void {
saveFace();
}
private function saveFace():void {
saving_dialog.pb.updateWithAnimation(1, (hat_removed) ? .4 : .8);
saveFaceLoader = new SmartURLLoader('face');
var url:String = VanityModel.fvm.api_url+'simple/faces.setFace';