You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
298 lines
10 KiB
298 lines
10 KiB
using Ability; |
|
using Equip; |
|
using UnityEngine; |
|
using UnityEngine.EventSystems; |
|
using UnityEngine.UI; |
|
using TMPro; |
|
|
|
public class ChangeSkinDialog : BaseDialog |
|
{ |
|
[SerializeField] Button m_applaySkinButton; |
|
[SerializeField] Button m_raccoonIcon; |
|
[SerializeField] Button m_foxIcon; |
|
[SerializeField] Button m_skunkIcon; |
|
[SerializeField] Button m_exitButton; |
|
[SerializeField] Button m_buyFoxButton; |
|
[SerializeField] Button m_buySkunkButton; |
|
|
|
[SerializeField] Image m_skillIcon; |
|
|
|
[SerializeField] TextMeshProUGUI m_nameLabel; |
|
[SerializeField] TextMeshProUGUI m_specialLabel; |
|
[SerializeField] TextMeshProUGUI m_skillNameLabel; |
|
[SerializeField] TextMeshProUGUI m_infoLabel; |
|
[SerializeField] TextMeshProUGUI m_damageLabel; |
|
[SerializeField] TextMeshProUGUI m_healthLabel; |
|
[SerializeField] TextMeshProUGUI m_headerLabel; |
|
|
|
[SerializeField] GameObject m_selectedObj; |
|
[SerializeField] GameObject m_foxModel; |
|
[SerializeField] GameObject m_skunkModel; |
|
[SerializeField] GameObject m_raccoonModel; |
|
|
|
[SerializeField] Sprite m_raccoonSpriteSpecial; |
|
[SerializeField] Sprite m_foxSpriteSpecial; |
|
[SerializeField] Sprite m_skunkSpriteSpecial; |
|
|
|
private Button m_currentSelectedButton; |
|
|
|
SkinsInfo m_skinInfo; |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Start () |
|
{ |
|
m_type = DialogType.CHANGE_SKIN_DIALOG; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void Init() |
|
{ |
|
SkinType type = GlobalsVar.gUser.CurrentSkin; |
|
m_skinInfo = CommonFunctions.GetSkinInfoByType(type); |
|
|
|
InitSpecialIcon(); |
|
InitTexts(); |
|
InitButton(); |
|
InitSkinsIcons(); |
|
SetCurrentSelectedSkin(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void Repaint() |
|
{ |
|
InitTexts(); |
|
InitSpecialIcon(); |
|
SetCurrentSelectedSkin(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void SetCurrentSelectedSkin() |
|
{ |
|
if (m_skinInfo.m_type == SkinType.RACCOON) |
|
{ |
|
m_selectedObj.transform.position = m_raccoonIcon.transform.position; |
|
m_currentSelectedButton = m_raccoonIcon.GetComponent<Button>(); |
|
|
|
m_raccoonModel.SetActive(true); |
|
m_foxModel.SetActive(false); |
|
m_skunkModel.SetActive(false); |
|
} |
|
else if (m_skinInfo.m_type == SkinType.FOX) |
|
{ |
|
m_selectedObj.transform.position = m_foxIcon.transform.position; |
|
m_currentSelectedButton = m_foxIcon.GetComponent<Button>(); |
|
|
|
m_raccoonModel.SetActive(false); |
|
m_foxModel.SetActive(true); |
|
m_skunkModel.SetActive(false); |
|
} |
|
else if (m_skinInfo.m_type == SkinType.SKUNK) |
|
{ |
|
m_selectedObj.transform.position = m_skunkIcon.transform.position; |
|
m_currentSelectedButton = m_skunkIcon.GetComponent<Button>(); |
|
|
|
m_raccoonModel.SetActive(false); |
|
m_foxModel.SetActive(false); |
|
m_skunkModel.SetActive(true); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void InitSpecialIcon() |
|
{ |
|
if (m_skinInfo.m_type == SkinType.RACCOON) |
|
m_skillIcon.sprite = m_raccoonSpriteSpecial; |
|
else if (m_skinInfo.m_type == SkinType.FOX) |
|
m_skillIcon.sprite = m_foxSpriteSpecial; |
|
else if (m_skinInfo.m_type == SkinType.SKUNK) |
|
m_skillIcon.sprite = m_skunkSpriteSpecial; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void InitSkinsIcons() |
|
{ |
|
string flagVal = GlobalsVar.gUser.GetFlagByName("fox_owned"); |
|
if (flagVal != "yes") |
|
m_foxIcon.GetComponent<Image>().material = GlobalsVar.gGrayscaleMaterial; |
|
else |
|
m_buyFoxButton.gameObject.SetActive(false); |
|
|
|
flagVal = GlobalsVar.gUser.GetFlagByName("skunk_owned"); |
|
if (flagVal != "yes") |
|
m_skunkIcon.GetComponent<Image>().material = GlobalsVar.gGrayscaleMaterial; |
|
else |
|
m_buySkunkButton.gameObject.SetActive(false); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void InitTexts() |
|
{ |
|
if (m_nameLabel) |
|
m_nameLabel.text = GlobalsVar.gGameTextMng.GetGameText(m_skinInfo.m_nameTextId).ToUpper(); |
|
|
|
if (m_specialLabel) |
|
m_specialLabel.text = GlobalsVar.gGameTextMng.GetGameText(159).ToUpper(); |
|
|
|
if (m_skillNameLabel) |
|
m_skillNameLabel.text = GlobalsVar.gGameTextMng.GetGameText(m_skinInfo.m_skillTextId); |
|
|
|
if (m_infoLabel) |
|
m_infoLabel.text = GlobalsVar.gGameTextMng.GetGameText(m_skinInfo.m_infoTextId); |
|
|
|
if (m_healthLabel) |
|
{ |
|
int health = GlobalsVar.gBaseHealth; |
|
int healthFromAb = (int)GlobalsVar.gMainAbilities.GetAbilityValueByType(MainAbilityType.ADD_HEALTH); |
|
var items = EquipSettings.GetItems(); |
|
foreach (var item in items) |
|
{ |
|
health += (int)item.AddHp; |
|
} |
|
health += healthFromAb; |
|
m_healthLabel.text = health.ToString(); |
|
} |
|
|
|
if (m_damageLabel) |
|
{ |
|
int damage = GlobalsVar.gBaseDamage; |
|
int damageFromAb = (int)GlobalsVar.gMainAbilities.GetAbilityValueByType(MainAbilityType.ADD_DAMAGE); |
|
damage += damageFromAb; |
|
m_damageLabel.text = damage.ToString(); |
|
} |
|
|
|
if (m_headerLabel) |
|
m_headerLabel.text = GlobalsVar.gGameTextMng.GetGameText(62).ToUpper(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void InitButton() |
|
{ |
|
if (m_applaySkinButton) |
|
{ |
|
CommonFunctions.SetDisableButtonColor(m_applaySkinButton); |
|
CommonFunctions.SetButtonText(m_applaySkinButton.gameObject, GlobalsVar.gGameTextMng.GetGameText(158)); |
|
m_applaySkinButton.onClick.AddListener(ButtonPress); |
|
} |
|
|
|
if (m_raccoonIcon) |
|
m_raccoonIcon.onClick.AddListener(ButtonPress); |
|
|
|
if (m_foxIcon) |
|
m_foxIcon.onClick.AddListener(ButtonPress); |
|
|
|
if (m_skunkIcon) |
|
m_skunkIcon.onClick.AddListener(ButtonPress); |
|
|
|
if (m_exitButton) |
|
m_exitButton.onClick.AddListener(ButtonPress); |
|
|
|
if (m_buyFoxButton) |
|
{ |
|
m_buyFoxButton.onClick.AddListener(ButtonPress); |
|
CommonFunctions.SetButtonText(m_buyFoxButton.gameObject, GlobalsVar.gBuySkinPrice.ToString()); |
|
} |
|
|
|
if (m_buySkunkButton) |
|
{ |
|
m_buySkunkButton.onClick.AddListener(ButtonPress); |
|
CommonFunctions.SetButtonText(m_buySkunkButton.gameObject, GlobalsVar.gBuySkinPrice.ToString()); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void ButtonPress() |
|
{ |
|
GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject; |
|
if (currentClickedObj == m_applaySkinButton.gameObject) |
|
{ |
|
GlobalsVar.gUser.CurrentSkin = m_skinInfo.m_type; |
|
MainMenu mainMenu = GlobalsVar.gBoard as MainMenu; |
|
if (mainMenu) |
|
mainMenu.RepaintArsenal(); |
|
|
|
HideDialog(); |
|
} |
|
else if (currentClickedObj == m_exitButton.gameObject) |
|
HideDialog(); |
|
else if (currentClickedObj == m_raccoonIcon.gameObject) |
|
{ |
|
ChangeSkin(SkinType.RACCOON, m_raccoonIcon); |
|
} |
|
else if (currentClickedObj == m_foxIcon.gameObject) |
|
{ |
|
ChangeSkin(SkinType.FOX, m_foxIcon); |
|
} |
|
else if (currentClickedObj == m_skunkIcon.gameObject) |
|
{ |
|
ChangeSkin(SkinType.SKUNK, m_skunkIcon); |
|
} |
|
else if (currentClickedObj == m_buyFoxButton.gameObject) |
|
{ |
|
BuySkin(m_buyFoxButton); |
|
} |
|
else if (currentClickedObj == m_buySkunkButton.gameObject) |
|
{ |
|
BuySkin(m_buySkunkButton); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void BuySkin(Button btn) |
|
{ |
|
if (GlobalsVar.gUser.Crystals < GlobalsVar.gBuySkinPrice) |
|
{ |
|
HideDialog(); |
|
GameObject dlg = GlobalsVar.gBoard.StartDialog("NotEnoughDialog"); |
|
dlg.GetComponent<NotEnoughDialog>().Init(Shop.ShopType.Gems); |
|
return; |
|
} |
|
|
|
GlobalsVar.gUser.IncCurrency(Shop.ShopType.Gems, -GlobalsVar.gBuySkinPrice); |
|
MainMenu mainMenu = GlobalsVar.gBoard as MainMenu; |
|
if (mainMenu) |
|
mainMenu.Repaint(); |
|
|
|
if (btn == m_buyFoxButton) |
|
{ |
|
GlobalsVar.gUser.SetFlagByName("fox_owned", "yes"); |
|
m_buyFoxButton.gameObject.SetActive(false); |
|
m_foxIcon.GetComponent<Image>().material = null; |
|
} |
|
else if (btn == m_buySkunkButton) |
|
{ |
|
GlobalsVar.gUser.SetFlagByName("skunk_owned", "yes"); |
|
m_buySkunkButton.gameObject.SetActive(false); |
|
m_skunkIcon.GetComponent<Image>().material = null; |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void ChangeSkin(SkinType type, Button btn) |
|
{ |
|
if (m_currentSelectedButton == btn) |
|
return; |
|
|
|
if (btn == m_foxIcon) |
|
{ |
|
string flagVal = GlobalsVar.gUser.GetFlagByName("fox_owned"); |
|
if (flagVal != "yes") |
|
return; |
|
} |
|
else if (btn == m_skunkIcon) |
|
{ |
|
string flagVal = GlobalsVar.gUser.GetFlagByName("skunk_owned"); |
|
if (flagVal != "yes") |
|
return; |
|
} |
|
|
|
m_currentSelectedButton = btn; |
|
m_skinInfo = CommonFunctions.GetSkinInfoByType(type); |
|
Repaint(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public override void Update () |
|
{ |
|
base.Update(); |
|
} |
|
}
|
|
|