123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class CraftSelectionPanel : PopUpPanel
- {
- public GameObject craftItemPrefab;
- public RectTransform containerTrans;
- public GameObject closeBtn;
- public Text titleTxt;
- public bool useSwap;
- public Player myPlayer;
- void Start()
- {
- myPlayer = Session.GetInstance().GetBattleSession().myPlayer;
- List<CraftConfigData> list = CraftManager.GetInstance().GetDataList();
- for(int i=0; i<list.Count; i++)
- {
- CraftConfigData craftData = list[i];
- GameObject craftObj = Instantiate<GameObject>(craftItemPrefab);
- craftObj.transform.SetParent(containerTrans);
- craftObj.transform.localPosition = Vector3.zero;
- craftObj.transform.localScale = new Vector3(1f, 1f, 1f);
- CraftSelectionItem craftSelectionItem = craftObj.GetComponent<CraftSelectionItem>();
- craftSelectionItem.craftSelectionPanel = this;
- craftSelectionItem.index = i;
- craftSelectionItem.SetCraftData(craftData);
- }
- if(useSwap)
- titleTxt.text = Language.GetStr("GameInfo", "swapCraft");
- else
- titleTxt.text = Language.GetStr("GameInfo", "selectCraft");
- Session.GetInstance().GetBattleSession().GetBattleController().battleUI.powerIconContainer.Hide();
- }
- public static void SelectCraft(Player player, int craftId)
- {
- BattleSession battleSession = Session.GetInstance().GetBattleSession();
- if(currentPanel != null && currentPanel.useSwap)
- {
- if (player != null)
- {
- Player.Hero hero = player.GetHero();
- if(hero.GetCraft() != null)
- battleSession.GetMessageManager ().PrepareSwap (hero.GetCraft().id, craftId);
- }
- }
- else
- {
- Vector3 pos = battleSession.GetBattleController().GetMap().GetStartPosition(player);
- battleSession.GetMessageManager().SelectCraft(player, craftId, Map.XToColumn(pos.x), Map.ZToRow(pos.z));
- }
- }
- void FixedUpdate()
- {
- if(useSwap)
- {
- Player.Hero hero = myPlayer.GetHero();
- if(hero.GetCraft() == null || !hero.GetCraft().IsLeaveDamage())
- Close();
- }
- }
- void OnDestroy()
- {
- BattleController battleController = Session.GetInstance ().GetBattleSession ().GetBattleController ();
- if(battleController.GetCtrlCraft() != null)
- Session.GetInstance().GetBattleSession().GetBattleController().battleUI.powerIconContainer.Show();
- if(BattleController.battleType == BattleController.BattleType.Menu)
- Session.GetInstance ().GetBattleSession ().GetBattleController ().menuUI.startBtnContainer.Show();
- currentPanel = null;
- }
- public static bool IsShown()
- {
- return currentPanel != null;
- }
- private static CraftSelectionPanel currentPanel;
- public static CraftSelectionPanel Show(bool useSwap=false)
- {
- if(currentPanel == null)
- {
- GameObject panelObj = Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/UI/Battle/CraftSelectionPanel"));
- currentPanel = panelObj.GetComponent<CraftSelectionPanel>();
- PopUpManager.AddToMainCanvas(panelObj);
- }
- currentPanel.useSwap = useSwap;
- currentPanel.closeBtn.SetActive(useSwap);
- if (useSwap) {
- Session.GetInstance ().GetBattleSession ().GetBattleController ().battleUI.powerIconContainer.Hide ();
- if(BattleController.battleType == BattleController.BattleType.Menu)
- Session.GetInstance ().GetBattleSession ().GetBattleController ().menuUI.startBtnContainer.Hide();
- }
- return currentPanel;
- }
- public static void Hide()
- {
- if(currentPanel != null)
- Destroy(currentPanel.gameObject);
- }
- }
|