第一次提交
This commit is contained in:
242
Assets/Scripts/UI/UIMonsterItem.cs
Normal file
242
Assets/Scripts/UI/UIMonsterItem.cs
Normal file
@@ -0,0 +1,242 @@
|
||||
using HxGame.Data;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIMonsterItem : MonoBehaviour
|
||||
{
|
||||
public delegate void ClickItemEvent(UIMonsterItem item);
|
||||
public ClickItemEvent OnClick;
|
||||
|
||||
//public delegate void CopyItemEvent(MonstersConfig.MonsterConfig item);
|
||||
public delegate void CopyItemEvent(UIMonsterItem item);
|
||||
public CopyItemEvent OnCopyItem;
|
||||
|
||||
public Text txtID; //<2F><><EFBFBD><EFBFBD>ID
|
||||
public Text txtMonsterID; //<2F><><EFBFBD><EFBFBD>ID
|
||||
public Text txtName; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public InputField txtPos; //<2F><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
public Button btnDel; //ɾ<><C9BE>
|
||||
public Button btnCopy; //<2F><><EFBFBD><EFBFBD>
|
||||
public Button btnHide; //<2F><><EFBFBD><EFBFBD>
|
||||
public Button btnClickSelf; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
public List<string> paths;
|
||||
//public int itemIdx;
|
||||
public int pathIdx;
|
||||
public int groupId;
|
||||
|
||||
public MonstersConfig.MonsterConfig monster;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
groupId = -1;
|
||||
AddInputNameClickEvent(txtPos);
|
||||
//AddInputNameClickEvent(txtPath, true);
|
||||
btnDel.onClick.AddListener(RemoveSelf);
|
||||
//itemIdx = 0;
|
||||
paths = new List<string>();
|
||||
btnClickSelf.onClick.AddListener(OnClickSelf);
|
||||
btnCopy.onClick.AddListener(OnCopySelf);
|
||||
btnHide.onClick.AddListener(OnHideSelf);
|
||||
}
|
||||
|
||||
//public void SetItem(int idx, MonstersConfig.MonsterConfig m)
|
||||
public void SetItem(MonstersConfig.MonsterConfig m)
|
||||
{
|
||||
//itemIdx = idx;
|
||||
txtID.text = m.itemIdx.ToString();
|
||||
txtMonsterID.text = m.id.ToString();
|
||||
txtName.text = m.id.ToString();
|
||||
txtPos.text = m.pos.ToString();
|
||||
paths = m.paths;
|
||||
monster = m;
|
||||
|
||||
if (m.groupId > 0)
|
||||
return;
|
||||
|
||||
MapManager.Instance.SetMonsterPoint(m.itemIdx, monster.radius, monster.id, monster.num);
|
||||
MapManager.Instance.CreateSpecialPoint(monster.pos.x, monster.pos.y, MapManager.EditCellType.MonsterArea);
|
||||
MapManager.Instance.SetCurMonsterPathIdx(pathIdx);
|
||||
}
|
||||
|
||||
public void RefreshItem()
|
||||
{
|
||||
txtMonsterID.text = monster.id.ToString();
|
||||
txtName.text = monster.id.ToString();
|
||||
paths = monster.paths;
|
||||
}
|
||||
|
||||
public void SetGroup(int group)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD>group<75>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>á<EFBFBD><C3A1><EFBFBD><EFBFBD><EFBFBD>,ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
groupId = group;
|
||||
txtID.gameObject.SetActive(false);
|
||||
txtPos.gameObject.SetActive(false);
|
||||
btnCopy.gameObject.SetActive(false);
|
||||
btnDel.gameObject.SetActive(false);
|
||||
btnHide.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void AddInputNameClickEvent(InputField input, bool isPath = false) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
|
||||
{
|
||||
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
|
||||
UnityAction<BaseEventData> selectEvent = null;
|
||||
if (isPath)
|
||||
selectEvent = OnPathInputFieldClicked;
|
||||
else
|
||||
selectEvent = OnInputFieldClicked;
|
||||
|
||||
EventTrigger.Entry onClick = new EventTrigger.Entry()
|
||||
{
|
||||
eventID = EventTriggerType.PointerClick
|
||||
};
|
||||
|
||||
onClick.callback.AddListener(selectEvent);
|
||||
eventTrigger.triggers.Add(onClick);
|
||||
}
|
||||
|
||||
private void OnInputFieldClicked(BaseEventData data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(txtMonsterID.text))
|
||||
return;
|
||||
|
||||
if (OnClick == null)
|
||||
return;
|
||||
|
||||
OnClick(this);
|
||||
|
||||
UIWindow.Instance.uiMonstersPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
int radius = Convert.ToInt32(UIWindow.Instance.uiMonstersPanel.txtRadius.text);
|
||||
int count = Convert.ToInt32(UIWindow.Instance.uiMonstersPanel.txtCount.text);
|
||||
MapManager.Instance.SetMonsterPoint(monster.itemIdx, radius, Convert.ToInt32(txtMonsterID.text), count);
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.MonsterArea);
|
||||
}
|
||||
|
||||
private void OnPathInputFieldClicked(BaseEventData data)
|
||||
{
|
||||
UIWindow.Instance.uiMonstersPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
UIWindow.Instance.uiMonstersPanel.curActiveList = paths;
|
||||
MapManager.Instance.SetCurMonsterPathIdx(pathIdx);
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.MonsterPath);
|
||||
}
|
||||
|
||||
private void RemoveSelf()
|
||||
{
|
||||
DestroyImmediate(transform.parent.gameObject);
|
||||
MapManager.Instance.RemoveMonsterPoint(monster.itemIdx);
|
||||
}
|
||||
|
||||
public bool CheckValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(txtID.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ID");
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(txtPos.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дˢ<D0B4><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
//if (string.IsNullOrEmpty(txtRadius.text))
|
||||
//{
|
||||
// UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дˢ<D0B4>ְ뾶");
|
||||
// return false;
|
||||
//}
|
||||
//if (string.IsNullOrEmpty(txtNum.text))
|
||||
//{
|
||||
// UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дˢ<D0B4><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//if (string.IsNullOrEmpty(txtTime.text))
|
||||
//{
|
||||
// UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дˢ<D0B4><CBA2>ʱ<EFBFBD><CAB1>");
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//if (dropType.value == (int)CreateMonsterMode.Death)
|
||||
//{
|
||||
// if(!APIs.IsUInt(txtTime.text))
|
||||
// {
|
||||
// UIWindow.Instance.ShowMessage("ˢ<><CBA2>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
//else if(dropType.value == (int)CreateMonsterMode.FixedTime)
|
||||
//{
|
||||
// string[] tmp = txtTime.text.Split(',');
|
||||
// if (tmp.Length != 2)
|
||||
// {
|
||||
// UIWindow.Instance.ShowMessage("ˢ<><CBA2>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if(!APIs.IsUInt(tmp[0]))
|
||||
// {
|
||||
// UIWindow.Instance.ShowMessage("ˢ<><CBA2>ʱ<EFBFBD><CAB1>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// string[] strTime = tmp[1].Split(':');
|
||||
// if (strTime.Length != 2)
|
||||
// {
|
||||
// UIWindow.Instance.ShowMessage("ˢ<><CBA2>ʱ<EFBFBD><CAB1>-ʱ<><CAB1><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
// for (int i = 0; i < strTime.Length; i++)
|
||||
// {
|
||||
// if (!APIs.IsUInt(strTime[i]))
|
||||
// {
|
||||
// UIWindow.Instance.ShowMessage("ˢ<><CBA2>ʱ<EFBFBD><CAB1>-ʱ<><CAB1><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnClickSelf()
|
||||
{
|
||||
if (OnClick == null)
|
||||
return;
|
||||
|
||||
OnClick(this);
|
||||
}
|
||||
|
||||
private void OnCopySelf()
|
||||
{
|
||||
if (OnCopyItem == null)
|
||||
return;
|
||||
|
||||
//OnCopyItem(monster);
|
||||
OnCopyItem(this);
|
||||
}
|
||||
|
||||
private void OnHideSelf()
|
||||
{
|
||||
MapManager.Instance.HideMonsterPoint(monster.itemIdx);
|
||||
btnHide.transform.GetChild(0).GetComponent<Text>().text = "<22><>ʾ";
|
||||
btnHide.onClick.RemoveAllListeners();
|
||||
btnHide.onClick.AddListener(OnShowSelf);
|
||||
}
|
||||
|
||||
private void OnShowSelf()
|
||||
{
|
||||
MapManager.Instance.ShowMonsterPoint(monster.itemIdx);
|
||||
btnHide.transform.GetChild(0).GetComponent<Text>().text = "<22><><EFBFBD><EFBFBD>";
|
||||
btnHide.onClick.RemoveAllListeners();
|
||||
btnHide.onClick.AddListener(OnHideSelf);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user