177 lines
5.3 KiB
C#
177 lines
5.3 KiB
C#
using HxGame.Data;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.UI;
|
||
using static HxGame.Data.MonstersConfig;
|
||
using static MapManager;
|
||
|
||
public class UIMonsterItem : UIBaseItem
|
||
{
|
||
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; //序号ID
|
||
public Text txtMonsterID; //怪物ID
|
||
public Text txtName; //怪物名称
|
||
public InputField txtPos; //中心点坐标
|
||
|
||
public Button btnDel; //删除
|
||
public Button btnCopy; //复制
|
||
public Button btnHide; //隐藏
|
||
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
|
||
protected override void Awake()
|
||
{
|
||
base.Awake();
|
||
groupId = -1;
|
||
btnDel.onClick.AddListener(RemoveSelf);
|
||
paths = new List<string>();
|
||
btnCopy.onClick.AddListener(OnCopySelf);
|
||
btnHide.onClick.AddListener(OnHideSelf);
|
||
txtPos.onEndEdit.AddListener(OnEndEditPos);
|
||
}
|
||
|
||
private void OnEndEditPos(string arg0)
|
||
{
|
||
if (!UtilityClass.IsPosValidFormat(arg0))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请输入正确格式 x,y");
|
||
txtPos.text = $"{monster.pos.x},{monster.pos.y}";
|
||
return;
|
||
}
|
||
monster.pos = UtilityClass.GetVector2Pos(arg0);
|
||
sceneArea?.SetAreaPos(monster.pos);
|
||
UIWindow.Instance.uiMonstersPanel.UpdateGroupInfo(this);
|
||
}
|
||
|
||
//public void SetItem(int idx, MonstersConfig.MonsterConfig m)
|
||
public void SetItem(MonstersConfig.MonsterConfig m)
|
||
{
|
||
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;
|
||
txtPos.enabled = m.itemIdx != -1;
|
||
txtID.gameObject.SetActive(m.itemIdx != -1);
|
||
if (m.groupId > 0)
|
||
return;
|
||
MapManager.Instance.SetMonsterPoint(m.itemIdx, monster.radius, monster.id, monster.num);
|
||
MapManager.Instance.CreateSpecialPoint(monster.pos, this);
|
||
}
|
||
internal override void SetSelectPosItem()
|
||
{
|
||
base.SetSelectPosItem();
|
||
btnClickSelf.Select();
|
||
UIWindow.Instance.uiMonstersPanel.OnClickItem(this);
|
||
|
||
}
|
||
public override void SetItemPos(Vector2Int pos)
|
||
{
|
||
base.SetItemPos(pos);
|
||
monster.pos = pos;
|
||
txtPos.text = pos.ToString();
|
||
btnClickSelf.Select();
|
||
UIWindow.Instance.uiMonstersPanel.UpdateGroupInfo(this);
|
||
}
|
||
public void RefreshItem()
|
||
{
|
||
txtMonsterID.text = monster.id.ToString();
|
||
txtName.text = monster.id.ToString();
|
||
paths = monster.paths;
|
||
txtPos.text = monster.pos.ToString();
|
||
//刷新场景中的东西
|
||
sceneArea?.RefSAreaInfo();
|
||
}
|
||
|
||
public void SetGroup(int group)
|
||
{
|
||
//属于group的,隐藏位置、索引,删除,复制
|
||
groupId = group;
|
||
txtID.gameObject.SetActive(false);
|
||
txtPos.gameObject.SetActive(false);
|
||
btnCopy.gameObject.SetActive(false);
|
||
btnDel.gameObject.SetActive(false);
|
||
btnHide.gameObject.SetActive(false);
|
||
}
|
||
|
||
private void RemoveSelf()
|
||
{
|
||
DestroyImmediate(transform.parent.gameObject);
|
||
UIWindow.Instance.uiMonstersPanel.monstersConfig.monsterConfigs.Remove(monster);
|
||
if (monster.itemIdx != -1)
|
||
{
|
||
UIWindow.Instance.uiMonstersPanel.RemoveAllGrop(monster);
|
||
}
|
||
}
|
||
public void DestoryGrop()
|
||
{
|
||
if (monster.itemIdx != -1) return;
|
||
UIWindow.Instance.uiMonstersPanel.monstersConfig.monsterConfigs.Remove(monster);
|
||
DestroyImmediate(transform.parent.gameObject);
|
||
}
|
||
private void OnDestroy()
|
||
{
|
||
if (sceneArea == null) return;
|
||
DestroyImmediate(sceneArea.gameObject);
|
||
}
|
||
|
||
public bool CheckValid()
|
||
{
|
||
if (string.IsNullOrEmpty(txtID.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写怪物ID");
|
||
return false;
|
||
}
|
||
if (string.IsNullOrEmpty(txtPos.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写刷怪坐标");
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
private void OnCopySelf()
|
||
{
|
||
if (OnCopyItem == null)
|
||
return;
|
||
OnCopyItem(this);
|
||
}
|
||
|
||
private void OnHideSelf()
|
||
{
|
||
MapManager.Instance.HideMonsterPoint(monster.itemIdx);
|
||
btnHide.transform.GetChild(0).GetComponent<Text>().text = "显示";
|
||
btnHide.onClick.RemoveAllListeners();
|
||
btnHide.onClick.AddListener(OnShowSelf);
|
||
}
|
||
|
||
private void OnShowSelf()
|
||
{
|
||
MapManager.Instance.ShowMonsterPoint(monster.itemIdx);
|
||
btnHide.transform.GetChild(0).GetComponent<Text>().text = "隐藏";
|
||
btnHide.onClick.RemoveAllListeners();
|
||
btnHide.onClick.AddListener(OnHideSelf);
|
||
}
|
||
public override void OnClickItemSelf()
|
||
{
|
||
base.OnClickItemSelf();
|
||
UIWindow.Instance.uiMonstersPanel.OnClickItem(this);
|
||
}
|
||
}
|