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.
130 lines
4.6 KiB
130 lines
4.6 KiB
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using UnityEngine.SceneManagement; |
|
|
|
using TMPro; |
|
using Meta; |
|
|
|
public class EndRunDialog : BaseDialog |
|
{ |
|
[SerializeField] GameObject _roomIcon; |
|
|
|
[SerializeField] TextMeshProUGUI m_tapText; |
|
[SerializeField] TextMeshProUGUI m_headerText; |
|
[SerializeField] TextMeshProUGUI m_rewardText; |
|
[SerializeField] TextMeshProUGUI m_progressText; |
|
|
|
[SerializeField] List<GameObject> m_placements = new List<GameObject>(); |
|
|
|
bool m_needToMapByClick = true; |
|
bool m_allComplete = false; |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Start () |
|
{ |
|
SoundsManager.Instance.PlaySound("level_up"); |
|
m_type = DialogType.END_RUN_DIALOG; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void Init(bool allComplete = false) |
|
{ |
|
m_allComplete = allComplete; |
|
|
|
InitTexts(); |
|
InitRewards(); |
|
InitLocIcon(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
private void InitLocIcon() |
|
{ |
|
int stageId = CommonFunctions.GetStageId(); |
|
GameObject roomIcon = Instantiate(Resources.Load("Prefabs/UI/Locations/loc_" + stageId.ToString()) as GameObject); |
|
roomIcon.transform.SetParent(transform); |
|
roomIcon.transform.position = _roomIcon.transform.position; |
|
roomIcon.transform.localScale = Vector3.one; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitRewards() |
|
{ |
|
GameObject coinsObj = Instantiate(Resources.Load("Prefabs/reward") as GameObject); |
|
coinsObj.transform.SetParent(transform); |
|
coinsObj.transform.localScale = Vector3.one; |
|
coinsObj.transform.Find("count").GetComponent<TextMeshProUGUI>().text = PlayerResources.Instance.CurrentCoins.ToString(); |
|
GlobalsVar.gUser.IncCurrency(Shop.ShopType.Coins, PlayerResources.Instance.CurrentCoins); |
|
|
|
AddToPlacement(coinsObj, 0); |
|
|
|
List<Equip.EquipItem> items = PlayerResources.Instance.Items; |
|
for (int i = 0; i < items.Count; ++i) |
|
{ |
|
GameObject itemObj = Instantiate(Resources.Load("Prefabs/reward") as GameObject); |
|
itemObj.transform.SetParent(transform); |
|
itemObj.transform.localScale = Vector3.one; |
|
itemObj.transform.Find("count").GetComponent<TextMeshProUGUI>().text = "1"; |
|
itemObj.transform.Find("icon").GetComponent<Image>().sprite = Resources.Load<Sprite>(string.Format("Equipment/{0}", items[i].Icon)); |
|
|
|
Sprite back = Resources.Load<Sprite>(string.Format("Equipment/OBJ_arsenal_{0}", items[i].Rarity)); |
|
AddToPlacement(itemObj, i + 1, back); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void AddToPlacement(GameObject obj, int idx, Sprite back = null) |
|
{ |
|
if (idx > m_placements.Count - 1) |
|
return; |
|
|
|
obj.transform.position = m_placements[idx].transform.position; |
|
|
|
if (back) |
|
m_placements[idx].GetComponent<Image>().sprite = back; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitTexts() |
|
{ |
|
if (m_headerText) |
|
m_headerText.text = GlobalsVar.gGameTextMng.GetGameText(23).ToUpper(); |
|
|
|
if (m_rewardText) |
|
m_rewardText.text = GlobalsVar.gGameTextMng.GetGameText(24).ToUpper(); |
|
|
|
if (m_tapText) |
|
m_tapText.text = GlobalsVar.gGameTextMng.GetGameText(9); |
|
|
|
if (m_progressText) |
|
{ |
|
int stageId = CommonFunctions.GetStageId(); |
|
int maxRooms = GlobalsVar.gRoomByStage[stageId - 1]; |
|
|
|
int completedRooms = GlobalsVar.gCurrentRoomInRun - 1; |
|
if (m_allComplete) |
|
completedRooms = maxRooms; |
|
|
|
string progressStr = string.Format(GlobalsVar.gGameTextMng.GetGameText(25), completedRooms, maxRooms); |
|
m_progressText.text = progressStr; |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public override void Update () |
|
{ |
|
base.Update(); |
|
|
|
if (Input.GetMouseButtonDown(0)) |
|
{ |
|
if (m_needToMapByClick) |
|
{ |
|
GlobalsVar.gSkipClickTime = 0.2f; |
|
m_needToMapByClick = false; |
|
Time.timeScale = 1f; |
|
SceneManager.LoadScene("Scenes/MainMenu"); |
|
} |
|
} |
|
} |
|
}
|
|
|