543 lines
18 KiB
C#
543 lines
18 KiB
C#
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; //地图名称
|
||
public InputField txtEnterLv; //进入等级
|
||
public InputField txtReturnMapId; //回城地图ID
|
||
public InputField txtReturnMapCellPoint; //回城坐标
|
||
|
||
//模式
|
||
public Toggle togModePK; //PK
|
||
public Toggle togModeSZ; //氏族
|
||
public Toggle togModeTeam; //团队
|
||
public Toggle togModeLJ; //练级
|
||
public Toggle togModeCZ; //城战
|
||
|
||
//使用、掉落
|
||
public Toggle togDeadFall; //是否死亡掉落
|
||
public Toggle togUseRandom; //能否使用随机卷
|
||
public Toggle togUseUnderground; //能否使用地城
|
||
public Toggle togUseBack; //能否使用回城
|
||
public Toggle togUseItem; //能否使用药品
|
||
public Toggle togFuBen; //是否副本地图
|
||
|
||
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) //可以在Awake中调用
|
||
{
|
||
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)
|
||
{
|
||
//必须地图ID与该地图一致,才生成
|
||
|
||
//TODO: 点击事件
|
||
if (data.selectedObject.name.Equals("InputReturnPoint"))
|
||
{
|
||
if (!txtReturnMapId.text.Equals(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||
{
|
||
MapManager.Instance.RemoveSpecialPoint(MapManager.EditCellType.ReturnCell);
|
||
return;
|
||
}
|
||
|
||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.ReturnCell);
|
||
}
|
||
//else if (data.selectedObject.name.Equals("InputRelivePoint"))
|
||
//{
|
||
// if (!txtReliveMapId.text.Equals(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||
// {
|
||
// MapManager.Instance.RemoveSpecialPoint(MapManager.EditCellType.ReliveCell);
|
||
// return;
|
||
// }
|
||
|
||
// MapManager.Instance.SetEditCellType(MapManager.EditCellType.ReliveCell);
|
||
//}
|
||
|
||
}
|
||
|
||
|
||
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(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写地图ID");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(txtMapName.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写地图名称");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(txtEnterLv.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写进入地图等级");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(txtReturnMapId.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写回城地图ID");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(txtReturnMapCellPoint.text))
|
||
{
|
||
UIWindow.Instance.ShowMessage("请填写回城地图坐标");
|
||
return false;
|
||
}
|
||
|
||
string[] tmp = txtReturnMapCellPoint.text.Split(',');
|
||
if (tmp.Length != 2)
|
||
{
|
||
UIWindow.Instance.ShowMessage("回城坐标 错误");
|
||
return false;
|
||
}
|
||
|
||
//if (string.IsNullOrEmpty(txtReliveMapId.text))
|
||
//{
|
||
// UIWindow.Instance.ShowMessage("请填写复活地图ID");
|
||
// return false;
|
||
//}
|
||
|
||
//if (string.IsNullOrEmpty(txtReliveMapCellPoint.text))
|
||
//{
|
||
// UIWindow.Instance.ShowMessage("请填写复活地图坐标");
|
||
// return false;
|
||
//}
|
||
|
||
//tmp = txtReliveMapCellPoint.text.Split(',');
|
||
//if (tmp.Length != 2)
|
||
//{
|
||
// UIWindow.Instance.ShowMessage("复活坐标 错误");
|
||
// 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;
|
||
|
||
//传送点
|
||
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);
|
||
}
|
||
|
||
//复活点
|
||
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);
|
||
}
|
||
|
||
//摆摊区
|
||
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);
|
||
}
|
||
|
||
//音效触发
|
||
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);
|
||
}
|
||
|
||
//进入条件
|
||
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);
|
||
}
|
||
|
||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||
mc.SaveXML(mapId);
|
||
}
|
||
|
||
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 (txtReturnMapId.text.Equals(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||
MapManager.Instance.CreateSpecialPoint(mc.returnMapCellPoint.x, mc.returnMapCellPoint.y, MapManager.EditCellType.ReturnCell);
|
||
|
||
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;
|
||
|
||
//传送点
|
||
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);
|
||
}
|
||
//复活点
|
||
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);
|
||
}
|
||
//摆摊区
|
||
for (int i = 0; i < mc.sellAreasConfig.Count; i++)
|
||
{
|
||
MapConfig.AreaConfig ac = mc.sellAreasConfig[i];
|
||
UIWindow.Instance.uiSellAreasPanel.AddItem(ac.pos, ac.radius);
|
||
}
|
||
//音效触发
|
||
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);
|
||
}
|
||
//进入条件
|
||
for (int i = 0; i < mc.conditionsConfig.Count; i++)
|
||
{
|
||
MapConfig.ConditionConfig cc = mc.conditionsConfig[i];
|
||
UIWindow.Instance.uiConditionsPanel.AddItem(cc);
|
||
}
|
||
}
|
||
}
|