package createAccountGui { import achievement.AchievementXtCommManager; import avatar.AvatarUtility; import avatar.NewWorldAvatar; import com.sbi.analytics.SBTracker; import com.sbi.popup.SBOkPopup; import com.sbi.popup.SBScreen; import com.sbi.popup.SBWizard; import createAccountFlow.CreateAccountGui; import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import gui.ItemWindowAvatarSelect; import gui.LoadingSpiral; import gui.SBScrollbar; import gui.UpsellManager; import gui.WindowGenerator; import item.Item; import localization.LocalizationManager; public class GuiChooseAnimal extends SBScreen { private var _chooseScreen:MovieClip; private var _voBtn:MovieClip; private var _backBtn:MovieClip; private var _nextBtn:MovieClip; private var _playBtn:MovieClip; private var _itemWindow:MovieClip; private var _avatarHolder:MovieClip; private var _currAvatar:MovieClip; private var _buyBtnGreen:MovieClip; private var _buyBtnRed:MovieClip; private var _tag:MovieClip; private var _amlNameTxt:TextField; private var _titleText:TextField; private var _avatarWindows:WindowGenerator; private var _scrollBar:SBScrollbar; private var _itemsLoadingSpiral:LoadingSpiral; private var _currAvatarIconIds:Array; private var _currAvatarTypes:Array; private var _oceanOnlyIconIds:Array; private var _oceanOnlyTypes:Array; private var _usableAvatarIconIds:Array; private var _usableAvatarTypes:Array; private var _currBG:String; private var _avatarNamesByType:Object; private var _newAvatarFacilitator:NewWorldAvatar; private var _currType:int; private var _avtViewsFlag:int; private var _myCurrencyCount:int; private var _currCost:int; private var _currIndex:int; private var _isChoosingOceanAvatars:Boolean; private var _isChoosingFirstNonMember:Boolean; private var _isFromWorld:Boolean; private var _hasEnoughGems:Boolean; private var _wizard:SBWizard; private var _isCreatingWithoutChoosing:Boolean; private var _diamondCost:int; private var _currencyType:int; private var _scrollYValue:int; private var _isMovingScreens:Boolean; private var _registrationPanel:MovieClip; private var _avatarSelect:MovieClip; public function GuiChooseAnimal(param1:Object, param2:SBWizard, param3:Boolean) { this._chooseScreen = param3 ? param1.registrationPanel.chooseAnimal : param1.accountCreation.registrationPanel.chooseAnimal; super(this._chooseScreen,param2); this._registrationPanel = MovieClip(this._chooseScreen.parent); this._avatarSelect = MovieClip(this._chooseScreen.parent.parent); this._amlNameTxt = this._chooseScreen.animalNameText; this._itemWindow = this._chooseScreen.itemWindow; this._titleText = this._chooseScreen.titleText; this._isFromWorld = param3; this._wizard = param2; if(param3) { this._backBtn = param1.back_btn; this._nextBtn = param1.next_btn; this._playBtn = param1.play_btn; this._avatarHolder = param1.allAvatars; this._buyBtnGreen = param1.buy_btn_green; this._buyBtnRed = param1.buy_btn_red; this._tag = this._chooseScreen.tag; } else { this._voBtn = this._chooseScreen.vo_btn; this._playBtn = param1.accountCreation.play_btn; this._backBtn = param1.accountCreation.back_btn; this._nextBtn = param1.accountCreation.next_btn; this._avatarHolder = param1.accountCreation.allAvatars; } } public function init() : void { onEnterFromNext = this.enterFromNext; onEnterFromPrev = this.enterFromPrev; onLeaveToPrev = this.leaveToPrev; onLeaveToNext = this.leaveToNext; onClose = this.leaveToPrev; updateScreen = this.updateScreenAssets; if(!this._isFromWorld) { this._playBtn.visible = false; this._voBtn.stop(); this._voBtn.gotoAndStop(1); this._voBtn.addEventListener(MouseEvent.CLICK,this.voBtnClickHandler,false,0,true); } else { this._buyBtnGreen.visible = false; this._buyBtnRed.visible = false; this._tag.visible = false; } this._backBtn.visible = false; this._amlNameTxt.text = ""; this._myCurrencyCount = gMainFrame.clientInfo.gemCount; this._newAvatarFacilitator = new NewWorldAvatar(); this._usableAvatarIconIds = []; this._usableAvatarTypes = []; this._currAvatarIconIds = []; this._currAvatarTypes = []; this._avatarNamesByType = []; this._oceanOnlyIconIds = []; this._oceanOnlyTypes = []; this._avtViewsFlag = gMainFrame.userInfo.userVarCache.getUserVarValueById(AchievementXtCommManager.UV_AVT_VIEWABLE_FLAG); this._itemsLoadingSpiral = new LoadingSpiral(this._itemWindow,this._itemWindow.width * 0.5,this._itemWindow.height * 0.5); this._itemsLoadingSpiral.visible = true; this.setupIcons(); if(!this._isFromWorld && Boolean(CreateAccountGui.vo1Sound)) { CreateAccountGui.vo1Sound.play(); if(CreateAccountGui.vo1Sound.sc) { CreateAccountGui.vo1Sound.sc.addEventListener(Event.SOUND_COMPLETE,this.stopVOButton,false,0,true); this._voBtn.play(); } } } override public function destroy() : void { if(this._avatarWindows) { this._avatarWindows.destroy(); this._avatarWindows = null; } if(this._scrollBar) { this._scrollBar.destroy(); this._scrollBar = null; } super.destroy(); } public function destroyReloadedItems() : void { if(this._avatarWindows) { this._avatarWindows.destroy(); this._avatarWindows = null; } if(this._scrollBar) { this._scrollBar.destroy(); this._scrollBar = null; } } public function reload(param1:Boolean, param2:Boolean, param3:int = -1, param4:Boolean = false, param5:int = 0, param6:int = -1) : void { this._isMovingScreens = false; this._avtViewsFlag = gMainFrame.userInfo.userVarCache.getUserVarValueById(AchievementXtCommManager.UV_AVT_VIEWABLE_FLAG); this._itemsLoadingSpiral = new LoadingSpiral(this._itemWindow,this._itemWindow.width * 0.5,this._itemWindow.height * 0.5); this._itemsLoadingSpiral.visible = true; this._currencyType = param5; this.setupIcons(true); if(param5 == Item.GEM_CURRENCY) { this._myCurrencyCount = gMainFrame.clientInfo.gemCount; } else if(param5 == Item.DIAMOND_CURRENCY) { this._myCurrencyCount = gMainFrame.clientInfo.diamondCount; } this._isChoosingOceanAvatars = param1; this._isChoosingFirstNonMember = param2; this._nextBtn.visible = true; this._buyBtnGreen.visible = false; this._buyBtnRed.visible = false; this._backBtn.visible = false; this._isCreatingWithoutChoosing = param4; if(this._isChoosingOceanAvatars) { this._currAvatarIconIds = this._oceanOnlyIconIds; this._currAvatarTypes = this._oceanOnlyTypes; } else { this._currAvatarIconIds = this._usableAvatarIconIds; this._currAvatarTypes = this._usableAvatarTypes; } this.pickRandomAvatar(param3,param6); AvatarUtility.creationAssets.creationWiz.step = param4 ? 2 : 1; if(Boolean(this._currAvatar) && Boolean(this._currBG)) { if(!param4) { this.enterFromPrev(); this._nextBtn.visible = true; this._tag.visible = true; } else { this._nextBtn.visible = false; this._tag.visible = false; } } if(!param4) { this.createAvatarWindows(); } } public function enterFromNext() : void { this._registrationPanel.gotoAndPlay("backChooseAnAnimal"); this._currAvatar.gotoAndPlay("backChooseAnAnimal"); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndPlay("backChooseAnAnimal"); if(this._isFromWorld) { this._buyBtnGreen.visible = false; this._buyBtnRed.visible = false; this._nextBtn.visible = true; } this.enterFromBoth(); } public function enterFromPrev() : void { this._registrationPanel.gotoAndStop("intro"); this._currAvatar.gotoAndStop("chooseAnAnimal"); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndPlay("intro"); this.enterFromBoth(); } public function enterFromBoth() : void { if(!this._isFromWorld && Boolean(CreateAccountGui.vo1Sound)) { CreateAccountGui.vo1Sound.play(); if(CreateAccountGui.vo1Sound.sc) { CreateAccountGui.vo1Sound.sc.addEventListener(Event.SOUND_COMPLETE,this.stopVOButton,false,0,true); this._voBtn.play(); } } this._isMovingScreens = false; if(this._isFromWorld) { SBTracker.trackPageview("/game/play/popup/avatarCreation/ChooseAnimal"); } else { CreateAccountGui.trackUserCreateAccountPageChange("ChooseAnimal"); } } public function leaveToNext() : Boolean { var _loc1_:Object = null; if(this._nextBtn.isGray) { return false; } if(!this._isFromWorld) { if(CreateAccountGui.vo1Sound) { CreateAccountGui.vo1Sound.stop(); } this._voBtn.stop(); this._voBtn.gotoAndStop(1); } if(!gMainFrame.userInfo.isMember) { _loc1_ = AvatarUtility.avatarDefInfo[AvatarUtility.findAvDefIndexByType(this._currType)]; if(_loc1_.isMemberOnly) { if(this._isCreatingWithoutChoosing) { if(this._registrationPanel.currentFrameLabel != "chooseAName") { this._registrationPanel.gotoAndStop("chooseAName"); } if(this._currAvatar.currentFrameLabel != "chooseAName") { this._currAvatar.gotoAndStop("chooseAName"); } if(this._avatarSelect.bg[this._currBG + "Bg"].currentFrameLabel != "chooseAName") { this._avatarSelect.bg[this._currBG + "Bg"].gotoAndStop("chooseAName"); } return true; } UpsellManager.displayPopup(UpsellManager.ANIMALS,"createMembersOnlyAvatar"); } else if(AvatarUtility.numNonMemberAvatars() >= 2 && !this._isChoosingFirstNonMember) { UpsellManager.displayPopup(UpsellManager.ANIMAL_SLOTS,"buyThirdAvatar"); } else { if(!(this._isChoosingFirstNonMember && _loc1_.enviroFlag == 2)) { if(this._isCreatingWithoutChoosing) { this._registrationPanel.gotoAndStop("chooseAName"); this._currAvatar.gotoAndStop("chooseAName"); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndStop("chooseAName"); } else { this._registrationPanel.gotoAndPlay("playChooseAName"); this._currAvatar.gotoAndPlay("playChooseAName"); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndPlay("playChooseAName"); } this._isMovingScreens = true; return true; } new SBOkPopup(this._avatarSelect.parent.parent,LocalizationManager.translateIdOnly(14689)); } return false; } if(this._isCreatingWithoutChoosing) { this._registrationPanel.gotoAndStop("chooseAName"); this._currAvatar.gotoAndStop("chooseAName"); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndStop("chooseAName"); } else { this._registrationPanel.gotoAndPlay("playChooseAName"); this._currAvatar.gotoAndPlay("playChooseAName"); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndPlay("playChooseAName"); } this._isMovingScreens = true; return true; } public function leaveToPrev() : Boolean { if(!this._isFromWorld) { if(CreateAccountGui.vo1Sound) { CreateAccountGui.vo1Sound.stop(); } this._voBtn.stop(); this._voBtn.gotoAndStop(1); } this._newAvatarFacilitator.nameTypeScreenDone(); this._isMovingScreens = true; return true; } public function leaveToBoth() : Boolean { return true; } public function updateScreenAssets(param1:Boolean = false) : void { this._chooseScreen = this._registrationPanel.chooseAnimal; this._amlNameTxt = this._chooseScreen.animalNameText; this._itemWindow = this._chooseScreen.itemWindow; this._titleText = this._chooseScreen.titleText; if(this._isFromWorld) { this._tag = this._chooseScreen.tag; this._buyBtnGreen = this._avatarSelect.buy_btn_green; this._buyBtnRed = this._avatarSelect.buy_btn_red; } if(param1) { this.setupAvatarTextItems(); this.createAvatarWindows(); if(this._isFromWorld) { this._buyBtnGreen.visible = false; this._buyBtnRed.visible = false; this._tag.visible = true; } else { this._playBtn.visible = false; this._voBtn.stop(); this._voBtn.gotoAndStop(1); this._voBtn.addEventListener(MouseEvent.CLICK,this.voBtnClickHandler,false,0,true); this._voBtn = this._chooseScreen.vo_btn; } if(!this._isFromWorld && Boolean(CreateAccountGui.vo1Sound)) { if(CreateAccountGui.vo1Sound.sc) { this._voBtn.play(); } } } } public function get currencyType() : int { return this._currencyType; } public function get isCreatingWithoutChoosing() : Boolean { return this._isCreatingWithoutChoosing; } public function get currAvatar() : MovieClip { return this._currAvatar; } public function get currBG() : String { return this._currBG; } public function get currType() : int { return this._currType; } public function get hasEnoughGems() : Boolean { return this._hasEnoughGems; } public function get currAvatarCost() : int { return this._diamondCost == -1 ? this._currCost : this._diamondCost; } public function get currAvatarName() : String { return LocalizationManager.translateIdOnly(this._avatarNamesByType[this._currType]); } private function setupIcons(param1:Boolean = false) : void { var _loc3_:int = 0; var _loc4_:Object = null; var _loc2_:Array = AvatarUtility.creationAvatars; this._usableAvatarIconIds = []; this._usableAvatarTypes = []; this._oceanOnlyIconIds = []; this._oceanOnlyTypes = []; var _loc5_:int = 0; for(; _loc5_ < _loc2_.length; _loc5_++) { try { if(Boolean(AvatarUtility.avatarDefInfo && AvatarUtility.avatarDefInfo.length > 0) && Boolean(_loc5_ < AvatarUtility.avatarDefInfo.length) && Boolean(AvatarUtility.avatarDefInfo[_loc5_])) { _loc3_ = int(gMainFrame.userInfo.getAvatarDefByAvType(_loc2_[_loc5_].avTypeId).iconMediaId); _loc4_ = AvatarUtility.avatarDefInfo[_loc5_]; if((this._avtViewsFlag & 1 << AvatarUtility.avatarTypes[_loc5_] - 1) != 0) { if(!this._isFromWorld && (AvatarUtility.isEndangered(_loc4_.availability) || AvatarUtility.isExtinct(_loc4_.availability))) { continue; } this._usableAvatarIconIds.push(_loc3_); this._usableAvatarTypes.push(_loc2_[_loc5_].avTypeId); } if(Utility.isOcean(AvatarUtility.avatarDefInfo[_loc5_].enviroFlag)) { this._oceanOnlyIconIds.push(_loc3_); this._oceanOnlyTypes.push(_loc2_[_loc5_].avTypeId); } this._avatarNamesByType[_loc2_[_loc5_].avTypeId] = gMainFrame.userInfo.getAvatarDefByAvType(_loc2_[_loc5_].avTypeId).titleStrRef; if(Boolean(this._currType) && _loc2_[_loc5_].avTypeId == this._currType) { LocalizationManager.translateId(this._amlNameTxt,this._avatarNamesByType[this._currType]); } } } catch(e:Error) { } } this._currAvatarIconIds = this._usableAvatarIconIds; this._currAvatarTypes = this._usableAvatarTypes; if(!this._isFromWorld && !param1) { this.pickRandomAvatar(); this.createAvatarWindows(); } } private function pickRandomAvatar(param1:int = -1, param2:int = -1) : void { var _loc3_:int = 0; if(param1 == -1) { this._currIndex = Math.floor(Math.random() * (this._currAvatarTypes.length - 1 - 0 + 1)) + 0; param1 = int(this._currAvatarTypes[this._currIndex]); } else { _loc3_ = 0; while(_loc3_ < this._currAvatarTypes.length) { if(this._currAvatarTypes[_loc3_] == param1) { this._currIndex = _loc3_; break; } _loc3_++; } } this._diamondCost = param2; this._currType = param1; this.setupCurrAvatar(); } private function createAvatarWindows() : void { if(Boolean(this._avatarWindows) && this._avatarWindows.numWindowsCreated > 0) { this._itemWindow.addChild(this._avatarWindows); if(this._isFromWorld) { if(this._scrollBar) { this._scrollYValue = this._scrollBar.scrollYValue; this._scrollBar.destroy(); this._scrollBar = null; } this._scrollBar = new SBScrollbar(); this._scrollBar.init(this._avatarWindows,this._avatarWindows.width,this._avatarWindows.boxHeight * 3 + 2 * 3,10,"scrollbar2",this._avatarWindows.boxHeight + 2,this._scrollYValue,this._avatarWindows.height); } return; } this._itemsLoadingSpiral.visible = true; if(this._scrollBar) { this._scrollYValue = this._scrollBar.scrollYValue; this._scrollBar.destroy(); this._scrollBar = null; } if(this._avatarWindows) { this._avatarWindows.destroy(); this._avatarWindows = null; } this._avatarWindows = new WindowGenerator(); this._avatarWindows.init(3,3,this._currAvatarIconIds.length,2,2,2,ItemWindowAvatarSelect,this._currAvatarIconIds,"",{ "mouseDown":this.winMouseDown, "mouseOver":this.winMouseOver, "mouseOut":this.winMouseOut },{ "forCreation":!this._isFromWorld, "avTypes":this._currAvatarTypes },this.onAvatarIconWindowsLoaded,false,false); this._itemWindow.addChild(this._avatarWindows); } private function onAvatarIconWindowsLoaded() : void { if(this._isFromWorld && this._scrollBar == null) { this._scrollBar = new SBScrollbar(); this._scrollBar.init(this._avatarWindows,this._avatarWindows.width,this._avatarWindows.boxHeight * 3 + 2 * 3,10,"scrollbar2",this._avatarWindows.boxHeight + 2,this._scrollYValue,this._avatarWindows.height); } this._itemsLoadingSpiral.visible = false; if(MovieClip(this._avatarWindows.bg.getChildAt(this._currIndex)).currWindow.currentFrameLabel != "down") { MovieClip(this._avatarWindows.bg.getChildAt(this._currIndex)).currWindow.gotoAndStop("down"); } } private function winMouseDown(param1:MouseEvent) : void { param1.stopPropagation(); if(!this._isMovingScreens && this._currIndex != param1.currentTarget.index) { MovieClip(this._avatarWindows.bg.getChildAt(this._currIndex)).deselect(); this._currIndex = param1.currentTarget.index; this._currType = this._currAvatarTypes[param1.currentTarget.index]; if(param1.currentTarget.currWindow.currentFrameLabel != "down") { param1.currentTarget.currWindow.gotoAndStop("down"); } this.setupCurrAvatar(); } } private function setupCurrAvatar() : void { var _loc2_:Array = null; var _loc1_:Array = this._avatarHolder.currentLabels; var _loc3_:int = 0; while(_loc3_ < _loc1_.length) { _loc2_ = _loc1_[_loc3_].name.split("_"); if(_loc2_[1] == this._currType) { this._currBG = _loc2_[0]; this._avatarHolder.gotoAndStop(this._currBG + "_" + this._currType); this._currAvatar = this._avatarHolder["avatar" + this._currType]; break; } _loc3_++; } if(this._currAvatar) { this._currAvatar.gotoAndPlay("intro"); this.setupAvatarTextItems(); } if(this._currBG) { if(this._avatarSelect.bg.currentFrameLabel != this._currBG) { this._avatarSelect.bg.gotoAndStop(this._currBG); this._avatarSelect.bg[this._currBG + "Bg"].gotoAndPlay("intro"); } } } private function setupAvatarTextItems() : void { var _loc1_:Object = null; if(this._currAvatar) { if(this._avatarNamesByType[this._currType]) { LocalizationManager.translateId(this._amlNameTxt,this._avatarNamesByType[this._currType]); } _loc1_ = AvatarUtility.avatarDefInfo[AvatarUtility.findAvatarIndexByType(this._currType)]; if(this._isFromWorld) { this._currCost = this._diamondCost == -1 ? int(_loc1_.cost) : this._diamondCost; if(!this._isChoosingFirstNonMember) { this._tag.txt.text = String(this._currCost); if(this._myCurrencyCount < this._currCost) { this._hasEnoughGems = false; this._tag.gotoAndStop("red"); this._tag.txt.textColor = "0x800000"; } else { this._hasEnoughGems = true; this._tag.gotoAndStop("green"); this._tag.textColor = "0xFFFFFFFF"; } } else { this._hasEnoughGems = true; LocalizationManager.translateId(this._tag.txt,11176); } } if(AvatarUtility.isEndangered(_loc1_.availability)) { if(this._currType == 13 || this._currType == 16 || this._currType == 26) { LocalizationManager.translateId(this._avatarSelect.endangeredSign.txt,11177); } else if(this._currType == 6) { LocalizationManager.translateId(this._avatarSelect.endangeredSign.txt,14226); } else { LocalizationManager.translateId(this._avatarSelect.endangeredSign.txt,11178); } this._avatarSelect.endangeredSign.visible = true; } else { this._avatarSelect.endangeredSign.visible = false; } if(AvatarUtility.isEndangered(_loc1_.availability) || AvatarUtility.isExtinct(_loc1_.availability)) { this._nextBtn.activateGrayState(true); if(this._isFromWorld) { this._tag.visible = false; } } else { this._nextBtn.activateGrayState(false); if(this._isFromWorld) { this._tag.visible = true; } } } } private function winMouseOver(param1:MouseEvent) : void { if(param1) { param1.stopPropagation(); } if(param1.currentTarget.currWindow.currentFrameLabel == "down") { param1.currentTarget.currWindow.gotoAndStop("downMouse"); } else if(param1.currentTarget.currWindow.currentFrameLabel != "downMouse") { param1.currentTarget.currWindow.gotoAndStop("over"); } AJAudio.playSubMenuBtnRollover(); } private function winMouseOut(param1:MouseEvent) : void { if(param1) { param1.stopPropagation(); } if(param1.currentTarget.currWindow.currentFrameLabel == "downMouse") { param1.currentTarget.currWindow.gotoAndStop("down"); } else if(param1.currentTarget.currWindow.currentFrameLabel != "down") { param1.currentTarget.currWindow.gotoAndStop("up"); } } private function stopVOButton(param1:Event) : void { if(CreateAccountGui) { CreateAccountGui.vo1Sound.stop(); } this._voBtn.stop(); this._voBtn.gotoAndStop(1); } private function voBtnClickHandler(param1:MouseEvent) : void { param1.stopPropagation(); if(CreateAccountGui.vo1Sound.isPlaying) { CreateAccountGui.vo1Sound.stop(); this._voBtn.stop(); this._voBtn.gotoAndStop(1); } else { CreateAccountGui.vo1Sound.play(); if(CreateAccountGui.vo1Sound.sc) { CreateAccountGui.vo1Sound.sc.addEventListener(Event.SOUND_COMPLETE,this.stopVOButton,false,0,true); this._voBtn.play(); } } } } }