Files
HX_MapEditor/Assets/Scripts/UI/UIEditMapConfig.cs

508 lines
16 KiB
C#
Raw Normal View History

2025-06-14 13:46:24 +08:00
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 UIEditMapConfig : MonoBehaviour
{
public InputField txtMapName; //<2F><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
public InputField txtEnterLv; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
public InputField txtReturnMapId; //<2F>سǵ<D8B3>ͼID
public InputField txtReturnMapCellPoint; //<2F>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>
//ģʽ
public Toggle togModePK; //PK
public Toggle togModeSZ; //<2F><><EFBFBD><EFBFBD>
public Toggle togModeTeam; //<2F>Ŷ<EFBFBD>
public Toggle togModeLJ; //<2F><><EFBFBD><EFBFBD>
public Toggle togModeCZ; //<2F><>ս
//ʹ<>á<EFBFBD><C3A1><EFBFBD><EFBFBD><EFBFBD>
public Toggle togDeadFall; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Toggle togUseRandom; //<2F>ܷ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Toggle togUseUnderground; //<2F>ܷ<EFBFBD>ʹ<EFBFBD>õس<C3B5>
public Toggle togUseBack; //<2F>ܷ<EFBFBD>ʹ<EFBFBD>ûس<C3BB>
public Toggle togUseItem; //<2F>ܷ<EFBFBD>ʹ<EFBFBD><CAB9>ҩƷ
public Toggle togFuBen; //<2F>Ƿ񸱱<C7B7><F1B8B1B1><EFBFBD>ͼ
public Toggle togEditRelives;
public Toggle togEditTeleports;
//public Toggle togEditSafeAreas;
public Toggle togEditSellAreas;
public Toggle togEditMonsters;
public Toggle togEditNPCs;
public Toggle togEditAudioTriggers;
public Toggle togEditTriggers;
public Toggle togEditConditions;
public Toggle togEditFuBen;
public Toggle togEditJuBao;
// Start is called before the first frame update
void Start()
{
AddInputNameClickEvent(txtReturnMapCellPoint);
//AddInputNameClickEvent(txtReliveMapCellPoint);
}
public void Cleanup()
{
txtMapName.text = string.Empty;
txtEnterLv.text = string.Empty;
txtReturnMapId.text = string.Empty;
txtReturnMapCellPoint.text = string.Empty;
togModePK.isOn = false;
togModeSZ.isOn = false;
togModeTeam.isOn = false;
togModeLJ.isOn = false;
togModeCZ.isOn = false;
togDeadFall.isOn = false;
togUseRandom.isOn = false;
togUseUnderground.isOn = false;
togUseBack.isOn = false;
togUseItem.isOn = false;
togFuBen.isOn = false;
togEditRelives.isOn = false;
togEditTeleports.isOn = false;
togEditSellAreas.isOn = false;
togEditMonsters.isOn = false;
togEditNPCs.isOn = false;
togEditAudioTriggers.isOn = false;
togEditTriggers.isOn = false;
togEditConditions.isOn = false;
togEditFuBen.isOn = false;
togEditJuBao.isOn = false;
UIWindow.Instance.uiRelivesPanel.RemoveAll();
UIWindow.Instance.uiTeleportPanel.RemoveAll();
UIWindow.Instance.uiAudioTriggerPanel.RemoveAll();
UIWindow.Instance.uiSellAreasPanel.RemoveAll();
//UIWindow.Instance.uiMonstersPanel.RemoveAll();
UIWindow.Instance.uiNpcsPanel.RemoveAll();
UIWindow.Instance.uiTriggersPanel.RemoveAll();
UIWindow.Instance.uiConditionsPanel.RemoveAll();
UIWindow.Instance.uiFuBensPanel.RemoveAll();
UIWindow.Instance.uiJuBaosPanel.RemoveAll();
}
private void AddInputNameClickEvent(InputField input) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
{
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
UnityAction<BaseEventData> selectEvent = OnInputFieldClicked;
EventTrigger.Entry onClick = new EventTrigger.Entry()
{
eventID = EventTriggerType.PointerClick
};
onClick.callback.AddListener(selectEvent);
eventTrigger.triggers.Add(onClick);
}
private void OnInputFieldClicked(BaseEventData data)
2025-06-16 00:15:41 +08:00
{
2025-06-14 13:46:24 +08:00
}
public void OnEditTeleportToggle()
{
if (togEditTeleports.isOn)
{
UIWindow.Instance.uiTeleportPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.TeleportCell);
}
else
{
UIWindow.Instance.uiTeleportPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.TeleportCell);
}
}
public void OnEditRelivesToggle()
{
if (togEditRelives.isOn)
{
UIWindow.Instance.uiRelivesPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.ReliveCell);
}
else
{
UIWindow.Instance.uiRelivesPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.ReliveCell);
}
}
public void OnEditSellAreasToggle()
{
if (togEditSellAreas.isOn)
{
UIWindow.Instance.uiSellAreasPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.SellArea);
}
else
{
UIWindow.Instance.uiSellAreasPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.SellArea);
}
}
public void OnEditMonsterToggle()
{
if (togEditMonsters.isOn)
{
UIWindow.Instance.uiMonstersPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.MonsterArea);
}
else
{
UIWindow.Instance.uiMonstersPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.MonsterArea);
}
}
public void OnEditNpcToggle()
{
if (togEditNPCs.isOn)
{
UIWindow.Instance.uiNpcsPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.NpcCell);
}
else
{
UIWindow.Instance.uiNpcsPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.NpcCell);
}
}
public void OnEditAudioTriggerToggle()
{
if(togEditAudioTriggers.isOn)
{
UIWindow.Instance.uiAudioTriggerPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.AudioTrigger);
}
else
{
UIWindow.Instance.uiAudioTriggerPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.AudioTrigger);
}
}
public void OnTriggerToggle()
{
if (togEditTriggers.isOn)
{
UIWindow.Instance.uiTriggersPanel.gameObject.SetActive(true);
MapManager.Instance.ShowSpecialPoint(MapManager.EditCellType.TriggerCell);
}
else
{
UIWindow.Instance.uiTriggersPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.TriggerCell);
}
}
public void OnConditionToggle()
{
if (togEditConditions.isOn)
UIWindow.Instance.uiConditionsPanel.gameObject.SetActive(true);
else
UIWindow.Instance.uiConditionsPanel.gameObject.SetActive(false);
}
public void OnFuBenToggle()
{
if (togEditFuBen.isOn)
UIWindow.Instance.uiFuBensPanel.gameObject.SetActive(true);
else
UIWindow.Instance.uiFuBensPanel.gameObject.SetActive(false);
}
public void OnJuBaoToggle()
{
if (togEditJuBao.isOn)
UIWindow.Instance.uiJuBaosPanel.gameObject.SetActive(true);
else
UIWindow.Instance.uiJuBaosPanel.gameObject.SetActive(false);
}
bool CheckValid()
{
if (string.IsNullOrEmpty(txtMapName.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>");
return false;
}
if (string.IsNullOrEmpty(txtEnterLv.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>ȼ<EFBFBD>");
return false;
}
if (string.IsNullOrEmpty(txtReturnMapId.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD>سǵ<D8B3>ͼID");
return false;
}
if (string.IsNullOrEmpty(txtReturnMapCellPoint.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD>سǵ<D8B3>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>");
return false;
}
string[] tmp = txtReturnMapCellPoint.text.Split(',');
if (tmp.Length != 2)
{
UIWindow.Instance.ShowMessage("<22>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>");
return false;
}
//if (string.IsNullOrEmpty(txtReliveMapId.text))
//{
// UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼID");
// return false;
//}
//if (string.IsNullOrEmpty(txtReliveMapCellPoint.text))
//{
// UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>");
// return false;
//}
//tmp = txtReliveMapCellPoint.text.Split(',');
//if (tmp.Length != 2)
//{
// UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>");
// return false;
//}
return true;
}
public void SaveMapConfig()
{
if (!CheckValid())
return;
MapConfig mc = new MapConfig();
mc.mapName = txtMapName.text;
mc.enterLv = Convert.ToInt32(txtEnterLv.text);
mc.returnMapId = Convert.ToInt32(txtReturnMapId.text);
string[] tmp = txtReturnMapCellPoint.text.Split(',');
int x = Convert.ToInt32(tmp[0]);
int y = Convert.ToInt32(tmp[1]);
mc.returnMapCellPoint = new Vector2Int(x, y);
if (togModePK.isOn)
mc.roleMode |= RoleMode.PK;
if (togModeSZ.isOn)
mc.roleMode |= RoleMode.ShiZu;
if (togModeTeam.isOn)
mc.roleMode |= RoleMode.Team;
if (togModeLJ.isOn)
mc.roleMode |= RoleMode.LianJi;
if (togModeCZ.isOn)
mc.roleMode |= RoleMode.ChengZhan;
if (togUseRandom.isOn)
mc.useMode |= UseMode.UseRandom;
if (togUseUnderground.isOn)
mc.useMode |= UseMode.UseUnderground;
if (togUseBack.isOn)
mc.useMode |= UseMode.UseBack;
if (togUseItem.isOn)
mc.useMode |= UseMode.UseItem;
if (togFuBen.isOn)
mc.useMode |= UseMode.FuBen;
mc.deadFall = togDeadFall.isOn;
//<2F><><EFBFBD>͵<EFBFBD>
Transform trans = UIWindow.Instance.uiTeleportPanel.itemParent;
for(int i=0; i<trans.childCount; i++)
{
UITeleportItem item = trans.GetChild(i).GetComponent<UITeleportItem>();
if (!item.CheckValid())
return;
MapConfig.TeleportConfig tel = new MapConfig.TeleportConfig();
tmp = item.txtPos.text.Split(',');
if (tmp.Length != 2)
return;
x = Convert.ToInt32(tmp[0]);
y = Convert.ToInt32(tmp[1]);
tel.pos = new Vector2Int(x, y);
tel.nextMapId = Convert.ToInt32(item.txtNextMapID.text);
tmp = item.txtNextMapPos.text.Split(',');
if (tmp.Length != 2)
return;
x = Convert.ToInt32(tmp[0]);
y = Convert.ToInt32(tmp[1]);
tel.nextMapPos = new Vector2Int(x, y);
mc.teleportConfigs.Add(tel);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
trans = UIWindow.Instance.uiRelivesPanel.itemParent;
for (int i = 0; i < trans.childCount; i++)
{
UIReliveItem item = trans.GetChild(i).GetComponent<UIReliveItem>();
if (!item.CheckValid())
return;
MapConfig.ReliveConfig relive = new MapConfig.ReliveConfig();
relive.reliveType = (ReliveType)item.dropType.value;
relive.mapId = Convert.ToInt32(item.txtMapId.text);
tmp = item.txtPos.text.Split(',');
if (tmp.Length != 2)
return;
x = Convert.ToInt32(tmp[0]);
y = Convert.ToInt32(tmp[1]);
relive.pos = new Vector2Int(x, y);
relive.radius = Convert.ToInt32(item.txtRadius.text);
mc.relivesConfig.Add(relive);
}
//<2F><>̯<EFBFBD><CCAF>
trans = UIWindow.Instance.uiSellAreasPanel.itemParent;
for (int i = 0; i < trans.childCount; i++)
{
UISellAreaItem item = trans.GetChild(i).GetComponent<UISellAreaItem>();
if (!item.CheckValid())
return;
MapConfig.AreaConfig sellArea = new MapConfig.AreaConfig();
tmp = item.txtPos.text.Split(',');
if (tmp.Length != 2)
return;
x = Convert.ToInt32(tmp[0]);
y = Convert.ToInt32(tmp[1]);
sellArea.pos = new Vector2Int(x, y);
sellArea.radius = Convert.ToInt32(item.txtRadius.text);
mc.sellAreasConfig.Add(sellArea);
}
//<2F><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
trans = UIWindow.Instance.uiAudioTriggerPanel.itemParent;
for (int i = 0; i < trans.childCount; i++)
{
UIAudioTriggerItem item = trans.GetChild(i).GetComponent<UIAudioTriggerItem>();
if (!item.CheckValid())
return;
MapConfig.AudioTriggerConfig audioTrigger = new MapConfig.AudioTriggerConfig();
tmp = item.txtPos.text.Split(',');
if (tmp.Length != 2)
return;
x = Convert.ToInt32(tmp[0]);
y = Convert.ToInt32(tmp[1]);
audioTrigger.pos = new Vector2Int(x, y);
audioTrigger.radius = Convert.ToInt32(item.txtRadius.text);
audioTrigger.name = item.txtName.text;
mc.audioTriggersConfig.Add(audioTrigger);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
trans = UIWindow.Instance.uiConditionsPanel.itemParent;
for (int i = 0; i < trans.childCount; i++)
{
UIConditionItem item = trans.GetChild(i).GetComponent<UIConditionItem>();
if (!item.CheckValid())
return;
var config = new MapConfig.ConditionConfig();
config.mode = (ConditionMode)item.dropMode.value;
config.level = Convert.ToInt32(item.txtLevel.text);
config.itemId = Convert.ToInt32(item.txtItemID.text);
config.money = Convert.ToInt32(item.txtMoney.text);
config.time = Convert.ToInt32(item.txtTime.text);
mc.conditionsConfig.Add(config);
}
2025-06-16 00:15:41 +08:00
mc.SaveXML(MapManager.Instance._curOpenMapId);
2025-06-14 13:46:24 +08:00
}
public void LoadMapConfig(int mapId)
{
MapConfig mc = new MapConfig();
if (!mc.LoadXML(mapId))
return;
txtMapName.text = mc.mapName;
txtEnterLv.text = mc.enterLv.ToString();
txtReturnMapId.text = mc.returnMapId.ToString();
txtReturnMapCellPoint.text = $"{mc.returnMapCellPoint.x},{mc.returnMapCellPoint.y}";
if ((mc.roleMode & RoleMode.PK) != 0)
togModePK.isOn = true;
if ((mc.roleMode & RoleMode.ShiZu) != 0)
togModeSZ.isOn = true;
if ((mc.roleMode & RoleMode.Team) != 0)
togModeTeam.isOn = true;
if ((mc.roleMode & RoleMode.LianJi) != 0)
togModeLJ.isOn = true;
if ((mc.roleMode & RoleMode.ChengZhan) != 0)
togModeCZ.isOn = true;
if ((mc.useMode & UseMode.UseRandom) != 0)
togUseRandom.isOn = true;
if ((mc.useMode & UseMode.UseUnderground) != 0)
togUseUnderground.isOn = true;
if ((mc.useMode & UseMode.UseBack) != 0)
togUseBack.isOn = true;
if ((mc.useMode & UseMode.UseItem) != 0)
togUseItem.isOn = true;
if ((mc.useMode & UseMode.FuBen) != 0)
togFuBen.isOn = true;
//<2F><><EFBFBD>͵<EFBFBD>
for (int i=0; i< mc.teleportConfigs.Count; i++)
{
MapConfig.TeleportConfig rc = mc.teleportConfigs[i];
UIWindow.Instance.uiTeleportPanel.AddItem(rc.pos, rc.nextMapId, rc.nextMapPos);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < mc.relivesConfig.Count; i++)
{
MapConfig.ReliveConfig rc = mc.relivesConfig[i];
UIWindow.Instance.uiRelivesPanel.AddItem((int)rc.reliveType, rc.mapId, rc.pos, rc.radius, mapId);
}
//<2F><>̯<EFBFBD><CCAF>
for (int i = 0; i < mc.sellAreasConfig.Count; i++)
{
MapConfig.AreaConfig ac = mc.sellAreasConfig[i];
UIWindow.Instance.uiSellAreasPanel.AddItem(ac.pos, ac.radius);
}
//<2F><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
for (int i = 0; i < mc.audioTriggersConfig.Count; i++)
{
MapConfig.AudioTriggerConfig ac = mc.audioTriggersConfig[i];
UIWindow.Instance.uiAudioTriggerPanel.AddItem(ac.pos, ac.radius, ac.name);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < mc.conditionsConfig.Count; i++)
{
MapConfig.ConditionConfig cc = mc.conditionsConfig[i];
UIWindow.Instance.uiConditionsPanel.AddItem(cc);
}
}
}