public void UpdateAvatarIcon() { for (int i = 0; i < BUTTON_NUM; i++) { if (GameApp.GetInstance().GetGameState().GetAvatarData((AvatarType)(BUTTON_NUM - 1 - i)) == AvatarState.ToBuy) { avatarScroller.SetOverlay(i, 0); } else if (GameApp.GetInstance().GetGameState().GetAvatarData((AvatarType)(BUTTON_NUM - 1 - i)) == AvatarState.Avaliable) { avatarScroller.SetOverlay(i, -1); } } }
public void HandleEvent(UIControl control, int command, float wparam, float lparam) { if (control == weaponScroller && command == (int)UIImageScroller.Command.ScrollSelect) { currentWeaponIndex = (int)wparam - 1; upgradeSelection = 1; if (currentWeaponIndex >= 0) { //Debug.Log("selection weapon:" + weaponList[currentWeaponIndex].Name); selectedWeapon = weaponList[currentWeaponIndex]; UpdateWeaponInfo(); InitSelection(); } else { selectedWeapon = null; UpdateWeaponInfo(); InitSelection(); } //weaponList[weaponID].IsSelectedForBattle = true; } else if (control == upgradePanels[0]) { AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>()); upgradeSelection = 1; UpdateSelectionButtonsState(); UpdateWeaponInfo(); /* * if (selectedWeapon != null) * { * cashPanel.SetCost(selectedWeapon.GetDamageUpgradePrice()); * } * else * { * GameConfig gConf = GameApp.GetInstance().GetGameConfig(); * cashPanel.SetCost(gConf.playerConf.upgradeArmorPrice); * } */ } else if (control == upgradePanels[1]) { AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>()); upgradeSelection = 2; UpdateSelectionButtonsState(); UpdateWeaponInfo(); //cashPanel.SetCost(selectedWeapon.GetFrequencyUpgradePrice()); } else if (control == upgradePanels[2]) { AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>()); upgradeSelection = 3; UpdateSelectionButtonsState(); UpdateWeaponInfo(); //cashPanel.SetCost(selectedWeapon.GetAccuracyUpgradePrice()); } else if (control == upgradePanels[3]) { AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>()); upgradeSelection = 4; UpdateSelectionButtonsState(); UpdateWeaponInfo(); //cashPanel.SetCost(selectedWeapon.WConf.bulletPrice); } else if (control == upgradeButton) { if (selectedWeapon != null) { if (selectedWeapon.Exist == WeaponExistState.Owned) { switch (upgradeSelection) { case 1: if (!selectedWeapon.IsMaxLevelDamage()) { if (gameState.UpgradeWeapon(selectedWeapon, selectedWeapon.Damage * selectedWeapon.WConf.damageConf.upFactor, 0f, 0f, selectedWeapon.GetDamageUpgradePrice())) { Debug.Log("upgrade"); ArenaMenuUI.GetInstance().GetAudioPlayer().PlayAudio("Upgrade"); } else { iapDialog.SetText(IAPDialog.NOT_ENOUGH_CASH); iapDialog.Show(); } } break; case 2: if (!selectedWeapon.IsMaxLevelCD()) { if (gameState.UpgradeWeapon(selectedWeapon, 0f, selectedWeapon.AttackFrequency * selectedWeapon.WConf.attackRateConf.upFactor, 0f, selectedWeapon.GetFrequencyUpgradePrice())) { ArenaMenuUI.GetInstance().GetAudioPlayer().PlayAudio("Upgrade"); } else { iapDialog.SetText(IAPDialog.NOT_ENOUGH_CASH); iapDialog.Show(); } } break; case 3: if (!selectedWeapon.IsMaxLevelAccuracy()) { if (gameState.UpgradeWeapon(selectedWeapon, 0f, 0f, selectedWeapon.Accuracy * selectedWeapon.WConf.accuracyConf.upFactor, selectedWeapon.GetAccuracyUpgradePrice())) { ArenaMenuUI.GetInstance().GetAudioPlayer().PlayAudio("Upgrade"); } else { iapDialog.SetText(IAPDialog.NOT_ENOUGH_CASH); iapDialog.Show(); } } break; case 4: if (selectedWeapon.BulletCount < 9999) { if (gameState.BuyBullets(selectedWeapon, selectedWeapon.WConf.bullet, selectedWeapon.WConf.bulletPrice)) { ArenaMenuUI.GetInstance().GetAudioPlayer().PlayAudio("Upgrade"); } else { iapDialog.SetText(IAPDialog.NOT_ENOUGH_CASH); iapDialog.Show(); } } break; } } else { WeaponBuyStatus wBuyStatus = gameState.BuyWeapon(selectedWeapon, selectedWeapon.WConf.price); if (wBuyStatus == WeaponBuyStatus.Succeed) { ArenaMenuUI.GetInstance().GetAudioPlayer().PlayAudio("Upgrade"); } else if (wBuyStatus == WeaponBuyStatus.NotEnoughCash) { iapDialog.SetText(IAPDialog.NOT_ENOUGH_CASH); iapDialog.Show(); } else if (wBuyStatus == WeaponBuyStatus.Locked) { iapDialog.SetText(IAPDialog.NOT_AVAILABLE); iapDialog.Show(); } if (selectedWeapon.Exist == WeaponExistState.Owned) { upgradePanels[0].Select(true); int index = gameState.GetWeaponIndex(selectedWeapon); if (weaponScroller != null) { weaponScroller.SetOverlay(index + 1, -1); } } } } else { GameConfig gConf = GameApp.GetInstance().GetGameConfig(); if (gameState.ArmorLevel != gConf.playerConf.maxArmorLevel) { if (gameState.UpgradeArmor(gameState.GetArmorPrice())) { ArenaMenuUI.GetInstance().GetAudioPlayer().PlayAudio("Upgrade"); } else { iapDialog.SetText(IAPDialog.NOT_ENOUGH_CASH); iapDialog.Show(); } } } UpdateWeaponInfo(); } else if (control == returnButton) { AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>()); GameApp.GetInstance().Save(); Hide(); GameObject.Find("ArenaMenuUI").GetComponent <ArenaMenuUI>().GetPanel(MenuName.ARENA).Show(); } else if (control == getMoreMoneyButton) { AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>()); Hide(); ShopUI shopUI = GameObject.Find("ArenaMenuUI").GetComponent <ArenaMenuUI>().GetPanel(MenuName.SHOP) as ShopUI; shopUI.SetFromPanel(this); shopUI.Show(); } }
// Use this for initialization public WeaponUpgradeUI() { uiPos = new WeaponUpgradeUIPosition(); GameApp.GetInstance().Init(); gameState = GameApp.GetInstance().GetGameState(); currentWeaponIndex = -1; selectedWeapon = null; weaponList = GameApp.GetInstance().GetGameState().GetWeapons(); arenaMaterial = UIResourceMgr.GetInstance().GetMaterial("ArenaMenu"); background = new UIImage(); background.SetTexture(arenaMaterial, ArenaMenuTexturePosition.Background, AutoRect.AutoSize(ArenaMenuTexturePosition.Background)); background.Rect = AutoRect.AutoPos(uiPos.Background); for (int i = 0; i < 4; i++) { upgradePanels[i] = new UpgradePanel(new Rect(500, 465 - i * 100, 424, 108), i); upgradePanels[i].Show(); } upgradePanels[0].SetButtonText("DAMAGE"); upgradePanels[1].SetButtonText("FIRE RATE"); upgradePanels[2].SetButtonText("ACCURACY"); upgradePanels[3].SetButtonText("AMMO"); returnButton = new UIClickButton(); returnButton.SetTexture(UIButtonBase.State.Normal, arenaMaterial, ArenaMenuTexturePosition.ReturnButtonNormal, AutoRect.AutoSize(ArenaMenuTexturePosition.ReturnButtonNormal)); returnButton.SetTexture(UIButtonBase.State.Pressed, arenaMaterial, ArenaMenuTexturePosition.ReturnButtonPressed, AutoRect.AutoSize(ArenaMenuTexturePosition.ReturnButtonPressed)); returnButton.Rect = AutoRect.AutoPos(uiPos.ReturnButton); Material buttonsMaterial = UIResourceMgr.GetInstance().GetMaterial("Buttons"); upgradeButton = new UITextButton(); upgradeButton.SetTexture(UIButtonBase.State.Normal, buttonsMaterial, ButtonsTexturePosition.ButtonNormal, AutoRect.AutoSize(ButtonsTexturePosition.ButtonNormal)); upgradeButton.SetTexture(UIButtonBase.State.Pressed, buttonsMaterial, ButtonsTexturePosition.ButtonPressed, AutoRect.AutoSize(ButtonsTexturePosition.ButtonPressed)); upgradeButton.Rect = AutoRect.AutoPos(uiPos.UpgradeButton); getMoreMoneyButton = new UITextButton(); getMoreMoneyButton.SetTexture(UIButtonBase.State.Normal, arenaMaterial, ArenaMenuTexturePosition.GetMoneyButtonNormal, AutoRect.AutoSize(ArenaMenuTexturePosition.GetMoneyButtonSmallSize)); getMoreMoneyButton.SetTexture(UIButtonBase.State.Pressed, arenaMaterial, ArenaMenuTexturePosition.GetMoneyButtonPressed, AutoRect.AutoSize(ArenaMenuTexturePosition.GetMoneyButtonSmallSize)); getMoreMoneyButton.Rect = AutoRect.AutoPos(uiPos.GetMoreMoneyButton); cashPanel = new CashPanel(); upgradeButton.SetText(ConstData.FONT_NAME0, " UPGRADE", ColorName.fontColor_orange); UpdateWeaponInfo(); InitSelection(); this.Add(background); this.Add(returnButton); this.Add(getMoreMoneyButton); this.Add(upgradeButton); for (int i = 0; i < 4; i++) { this.Add(upgradePanels[i]); } weaponUI = UIResourceMgr.GetInstance().GetMaterial("Weapons"); weaponUI2 = UIResourceMgr.GetInstance().GetMaterial("Weapons2"); weaponScroller = new UIImageScroller(AutoRect.AutoPos(new Rect(0, 0, 500, 640)), AutoRect.AutoPos(new Rect(10, 120, 500, 440)), 1, AutoRect.AutoSize(WeaponsLogoTexturePosition.WeaponLogoSize), ScrollerDir.Vertical, true); weaponScroller.SetImageSpacing(AutoRect.AutoSize(WeaponsLogoTexturePosition.WeaponLogoSpacing)); Material shopMaterial = UIResourceMgr.GetInstance().GetMaterial("ShopUI"); Material avatarMaterial = UIResourceMgr.GetInstance().GetMaterial("Avatar"); weaponScroller.SetCenterFrameTexture(avatarMaterial, AvatarTexturePosition.Frame); weaponScroller.AddOverlay(shopMaterial, ShopTexturePosition.LockedLogo); weaponScroller.AddOverlay(shopMaterial, ShopTexturePosition.BuyLogo); UIImage uiImage = new UIImage(); TexturePosInfo info = WeaponsLogoTexturePosition.GetWeaponTextureRect(weaponList.Count); uiImage.SetTexture(info.m_Material, info.m_TexRect, AutoRect.AutoSize(info.m_TexRect)); uiImage.Rect = info.m_TexRect; weaponScroller.Add(uiImage); for (int i = 0; i < weaponList.Count; i++) { uiImage = new UIImage(); info = WeaponsLogoTexturePosition.GetWeaponTextureRect(i); uiImage.SetTexture(info.m_Material, info.m_TexRect, AutoRect.AutoSize(info.m_TexRect)); uiImage.Rect = info.m_TexRect; weaponScroller.Add(uiImage); } this.Add(weaponScroller); weaponScroller.EnableScroll(); this.Add(cashPanel); for (int i = 0; i < weaponList.Count; i++) { if (weaponList[i].Exist == WeaponExistState.Locked) { weaponScroller.SetOverlay(i + 1, 0); } else if (weaponList[i].Exist == WeaponExistState.Unlocked) { weaponScroller.SetOverlay(i + 1, 1); } } Material avatarLogoMaterial = UIResourceMgr.GetInstance().GetMaterial("Avatar"); weaponScroller.SetMaskImage(avatarLogoMaterial, AvatarTexturePosition.Mask); weaponScroller.Show(); iapDialog = new IAPDialog(UIDialog.DialogMode.YES_OR_NO); iapDialog.SetDialogEventHandler(this); this.Add(iapDialog); cashPanel.Show(); SetUIHandler(this); uiInited = true; Hide(); }