490 lines
20 KiB
C#
490 lines
20 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
using XFrame.Core.UI;
|
|
using RDate;
|
|
using UnityEngine.Networking;
|
|
|
|
[Serializable]
|
|
public class ReturnRoomID
|
|
{
|
|
public bool state;
|
|
public string message;
|
|
public string data;
|
|
}
|
|
public class RoomInfo
|
|
{
|
|
public string Name;
|
|
public string MissionModel;
|
|
public string ThinkingId;
|
|
}
|
|
|
|
public class View_Panel2 : XUIPanel
|
|
{
|
|
public Button training_task_btn;//训练任务按钮
|
|
public Button append_btn;//添加按钮
|
|
public Button scenario_btn;//想定编辑
|
|
public Image append_room_panl;//添加房间页面
|
|
public InputField room_input;//输入房间名字
|
|
public Button Fork_off_btn;//叉掉添加房间页面
|
|
public Button verify_btn;//添加房间确认按钮
|
|
public Button cancel_btno;//取消添加房间按钮
|
|
public Text tips_txt;//提示文本
|
|
public Image distribution_panl;//席位分配面板
|
|
public Button off_btn;//席位分配叉掉页面
|
|
public Button submit_btn;//席位分配提交按钮
|
|
public Image selector_panl;//选择人员页面
|
|
public Button off3_btn;//选择人员页面叉掉按钮
|
|
|
|
public Button tijiao_btn;//提交按钮
|
|
public Button quxiao_btn;//取消按钮
|
|
public Image Storm_and_capture_panl;//红方蓝方
|
|
public Button Cancel4_btn;//红蓝方叉掉页面
|
|
public Button start_training_btn;//开始训练按钮
|
|
public Button entering_key_btn;//进入导调按钮
|
|
public Transform place;//需要生成地方
|
|
public GameObject root_pan;//需要生成房间预设体
|
|
public List<Text> roomnamelist = new List<Text>();//创建房间的名字
|
|
public List<string> rootlist = new List<string>();//存入房间的名字
|
|
public List<Button> buttonlist = new List<Button>();//克隆出来房间按钮
|
|
|
|
|
|
public string roomUrl = "http://111.229.30.246:48888/Handler/Practice.ashx?action=query&state=0,1,2";
|
|
public string userUrl = "http://111.229.30.246:48888/Handler/User.ashx?action=all&role_code=04";
|
|
public RoomData roomdata = new RoomData();
|
|
public UserData userData = new UserData();
|
|
public Dropdown roomModelDropdown;//房间模式
|
|
public Dropdown thinkingDropdown;//选择想定
|
|
public Transform reveal;
|
|
public Transform subjectContent;
|
|
public GameObject revealPrefab;
|
|
public GameObject subjectItem;
|
|
public string currentThinkName;
|
|
public GameObject userItem;
|
|
public Transform userConent;
|
|
public InputField nameInputField;
|
|
public InputField jobInputField;
|
|
public string currentRoomName;
|
|
public string currentMissionModel;
|
|
public string currentThinkingId;
|
|
public GameObject currentRoomSubjectItem;
|
|
public Transform currentRoomSubjectItemConnect;
|
|
public Dictionary<int, string> currentThinkingIds = new Dictionary<int, string>();
|
|
public View_Panel2() : base(UIType.Normal, UIMode.HideOther, UICollider.Normal)
|
|
{
|
|
uiPath = "UIPanel/View_Panel2";
|
|
}
|
|
public override void Awake(GameObject go)
|
|
{
|
|
roomModelDropdown = this.transform.Find("append_room_panl/roomModelDropdown").GetComponent<Dropdown>();
|
|
thinkingDropdown = this.transform.Find("append_room_panl/thinkingDropdown").GetComponent<Dropdown>();
|
|
|
|
append_room_panl = GameObject.Find("View_Panel2(Clone)").transform.GetChild(2).GetComponent<Image>();
|
|
Fork_off_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(2).transform.GetChild(1).GetComponent<Button>();
|
|
room_input = GameObject.Find("View_Panel2(Clone)").transform.GetChild(2).transform.GetChild(3).GetComponent<InputField>();
|
|
scenario_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(0).transform.GetChild(2).GetComponent<Button>();
|
|
verify_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(2).transform.GetChild(8).GetComponent<Button>();
|
|
cancel_btno = GameObject.Find("View_Panel2(Clone)").transform.GetChild(2).transform.GetChild(9).GetComponent<Button>();
|
|
tips_txt = GameObject.Find("View_Panel2(Clone)").transform.GetChild(2).transform.GetChild(10).GetComponent<Text>();
|
|
distribution_panl = GameObject.Find("View_Panel2(Clone)").transform.GetChild(3).GetComponent<Image>();
|
|
off_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(3).transform.GetChild(1).GetComponent<Button>();
|
|
selector_panl = GameObject.Find("View_Panel2(Clone)").transform.GetChild(4).GetComponent<Image>();
|
|
off3_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(4).transform.GetChild(1).GetComponent<Button>();
|
|
place = GameObject.Find("View_Panel2(Clone)").transform.GetChild(1).transform.GetChild(0).transform.GetChild(0).GetComponent<Transform>();
|
|
|
|
tijiao_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(4).transform.GetChild(8).GetComponent<Button>();
|
|
quxiao_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(4).transform.GetChild(9).GetComponent<Button>();
|
|
Storm_and_capture_panl = GameObject.Find("View_Panel2(Clone)").transform.GetChild(5).GetComponent<Image>();
|
|
Cancel4_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(5).transform.GetChild(1).GetComponent<Button>();
|
|
start_training_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(5).transform.GetChild(6).GetComponent<Button>();
|
|
entering_key_btn = GameObject.Find("View_Panel2(Clone)").transform.GetChild(5).transform.GetChild(7).GetComponent<Button>();
|
|
root_pan = Resources.Load<GameObject>("UIPanel/generate_panl");
|
|
|
|
this.transform.Find("UPBG/Refresh_btn").GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
GetAllRoomData();
|
|
});
|
|
currentRoomSubjectItemConnect = Storm_and_capture_panl.transform.Find("Campsite_iamg/Subjects").GetComponent<ScrollRect>().content;
|
|
currentRoomSubjectItem = currentRoomSubjectItemConnect.GetChild(0).gameObject;
|
|
currentRoomSubjectItem.SetActive(false);
|
|
submit_btn = distribution_panl.transform.Find("submit_btn").GetComponent<Button>();
|
|
subjectContent = distribution_panl.transform.Find("SubjectsScrollView").GetComponent<ScrollRect>().content;
|
|
subjectItem = subjectContent.GetChild(0).gameObject;
|
|
revealPrefab = Resources.Load<GameObject>("Prefabs/reveal1_iam");
|
|
userConent = selector_panl.transform.Find("ID_panl/Personnel").GetComponent<ScrollRect>().content;
|
|
nameInputField = selector_panl.transform.Find("NameInputField").GetComponent<InputField>();
|
|
jobInputField = selector_panl.transform.Find("JobInputField").GetComponent<InputField>();
|
|
userItem = userConent.GetChild(0).gameObject;
|
|
thinkingDropdown.options.Clear();
|
|
for (int i = 0; i < UIBootstrap.Instance.traininginformations.Count; i++)
|
|
{
|
|
int index = i;
|
|
Dropdown.OptionData data = new Dropdown.OptionData();
|
|
data.text = UIBootstrap.Instance.traininginformations[index].Name;
|
|
currentThinkingIds.Add(index, UIBootstrap.Instance.traininginformations[index].Id);
|
|
thinkingDropdown.options.Add(data);
|
|
}
|
|
thinkingDropdown.onValueChanged.AddListener((index) =>
|
|
{
|
|
currentThinkName = thinkingDropdown.options[index].text;
|
|
currentThinkingId = currentThinkingIds[index];
|
|
CreateSubject();
|
|
});
|
|
roomModelDropdown.onValueChanged.AddListener(OnRoomModelDropdown);
|
|
currentMissionModel = roomModelDropdown.options[0].text;
|
|
|
|
this.transform.Find("UPBG/append_btn").GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
append_room_panl.gameObject.SetActive(true);
|
|
});
|
|
|
|
nameInputField.onValueChanged.AddListener((info) =>
|
|
{
|
|
Debug.Log("onValueChanged" + info);
|
|
FuzzySearch(info);
|
|
});
|
|
jobInputField.onValueChanged.AddListener((info) =>
|
|
{
|
|
FuzzySearch(info);
|
|
});
|
|
|
|
nameInputField.onEndEdit.AddListener((info) =>
|
|
{
|
|
Debug.Log("onEndEdit" + info);
|
|
});
|
|
|
|
Forkoffbtn();
|
|
Verify();
|
|
Submit();
|
|
Cance();
|
|
Scenejump();//场景跳转按钮
|
|
append_room_panl.gameObject.SetActive(false);
|
|
GetAllRoomData();
|
|
GetAllUserData();
|
|
subjectItem.SetActive(false);
|
|
userItem.SetActive(false);
|
|
currentThinkName = thinkingDropdown.options[0].text;
|
|
CreateSubject();
|
|
}
|
|
|
|
public async void GetAllRoomData()
|
|
{
|
|
roomdata = await AsyncWebReq.Post<RoomData>(roomUrl, null);
|
|
if (place.childCount > 0)
|
|
{
|
|
for (int i = 0; i < place.childCount; i++)
|
|
{
|
|
GameObject.Destroy(place.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
CreateRoom();
|
|
}
|
|
|
|
public async void GetAllUserData()
|
|
{
|
|
userData = await AsyncWebReq.Post<UserData>(userUrl, null);
|
|
}
|
|
|
|
public void CreateAllUser(List<DataItem> userInfo)
|
|
{
|
|
if (userConent.childCount > 1)
|
|
{
|
|
for (int i = 1; i < userConent.childCount; i++)
|
|
{
|
|
GameObject.Destroy(userConent.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
for (int i = 0; i < userInfo.Count; i++)
|
|
{
|
|
GameObject obj = GameObject.Instantiate(userItem, userConent);
|
|
obj.SetActive(true);
|
|
obj.transform.GetChild(0).GetComponent<Text>().text = userData.data[i].login_name;
|
|
obj.transform.GetChild(1).GetComponent<Text>().text = userData.data[i].job_number;
|
|
obj.transform.GetChild(2).GetComponent<Toggle>().group = userConent.GetComponent<ToggleGroup>();
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建 新建房间的科目
|
|
/// </summary>
|
|
public void CreateSubject()
|
|
{
|
|
if (subjectContent.childCount > 1)
|
|
{
|
|
for (int i = 1; i < subjectContent.childCount; i++)
|
|
{
|
|
GameObject.Destroy(subjectContent.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
for (int i = 0; i < UIBootstrap.Instance.traininginformations.Count; i++)
|
|
{
|
|
if (currentThinkName.Equals(UIBootstrap.Instance.traininginformations[i].Name))
|
|
{
|
|
for (int j = 0; j < UIBootstrap.Instance.traininginformations[i].subjectsInfo.Count; j++)
|
|
{
|
|
GameObject subjectTemp = GameObject.Instantiate(subjectItem, subjectContent);
|
|
subjectTemp.SetActive(true);
|
|
subjectTemp.transform.Find("Text").GetComponent<Text>().text = UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].subjectName;
|
|
subjectTemp.transform.Find("Text").GetComponent<Text>().enabled = true;
|
|
if (UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].TrainDestList.Count < 2)
|
|
{
|
|
subjectTemp.transform.GetChild(2).gameObject.SetActive(false);
|
|
}
|
|
if (subjectTemp != null)
|
|
{
|
|
Transform redParent = subjectTemp.transform.Find("red_panl/RedReveal");
|
|
Transform greenParent = subjectTemp.transform.Find("green_paml/GreenReveal");
|
|
if (redParent.childCount > 0)
|
|
{
|
|
for (int ii = 0; ii < redParent.childCount; ii++)
|
|
{
|
|
GameObject.Destroy(redParent.GetChild(ii).gameObject);
|
|
}
|
|
}
|
|
if (greenParent.childCount > 0)
|
|
{
|
|
for (int ii = 0; ii < greenParent.childCount; ii++)
|
|
{
|
|
GameObject.Destroy(greenParent.GetChild(ii).gameObject);
|
|
}
|
|
}
|
|
for (int k = 0; k < UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos.Count; k++)
|
|
{
|
|
///0 红方 1 蓝方
|
|
if (UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].role.Equals("0"))
|
|
{
|
|
GameObject obj = GameObject.Instantiate(revealPrefab, redParent);
|
|
obj.transform.GetChild(0).GetComponent<Text>().text = Spilt(UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].seatName, 0, 2);
|
|
obj.transform.GetChild(1).GetComponent<Text>().text = Spilt(UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].seatName, 2, 2);
|
|
obj.transform.GetChild(2).GetComponent<Text>().text = UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].seatno;
|
|
obj.transform.GetChild(3).GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
selector_panl.gameObject.SetActive(true);
|
|
CreateAllUser(userData.data);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
GameObject obj = GameObject.Instantiate(revealPrefab, greenParent);
|
|
obj.transform.GetChild(0).GetComponent<Text>().text = Spilt(UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].seatName, 0, 1);
|
|
obj.transform.GetChild(1).GetComponent<Text>().text = Spilt(UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].seatName, 2, 2);
|
|
obj.transform.GetChild(2).GetComponent<Text>().text = UIBootstrap.Instance.traininginformations[i].subjectsInfo[j].seatInfos[k].seatno;
|
|
obj.transform.GetChild(3).GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
selector_panl.gameObject.SetActive(true);
|
|
CreateAllUser(userData.data);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Spilt(string data, int startIndex, int endIndex)
|
|
{
|
|
string msg = data.Substring(startIndex, endIndex);
|
|
return msg;
|
|
}
|
|
|
|
private void Scenejump()
|
|
{
|
|
start_training_btn.onClick.AddListener(() =>
|
|
{
|
|
GameMain.model = false;
|
|
//SceneManager.LoadScene("Training_pilot_terminal_panl");
|
|
SceneManager.LoadScene("AdamTraining_pilot_terminal_panl 1");
|
|
});
|
|
entering_key_btn.onClick.AddListener(() =>
|
|
{
|
|
GameMain.model = true;
|
|
SceneManager.LoadScene("Training_pilot_terminal_panl");
|
|
});
|
|
scenario_btn.onClick.AddListener(() =>
|
|
{
|
|
SceneManager.LoadScene("Contingenc_yediting_panl");
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 红蓝作战叉掉按钮
|
|
/// </summary>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private void Cance()
|
|
{
|
|
Cancel4_btn.onClick.AddListener(() =>
|
|
{
|
|
Storm_and_capture_panl.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
|
|
public void CreateRoom()
|
|
{
|
|
for (int i = 0; i < roomdata.data.Count; i++)
|
|
{
|
|
if (roomdata.data[i].State != 2)
|
|
{
|
|
CreateRoomBase(roomdata.data[i].Id, roomdata.data[i].Name);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public RDate.DataItem currentRoomData = new RDate.DataItem();
|
|
|
|
public void CreateRoomBase(string roomId, string name)
|
|
{
|
|
GameObject roomItem = GameObject.Instantiate(root_pan, place);
|
|
roomItem.name = roomId;
|
|
roomItem.transform.Find("Text").GetComponent<Text>().text = name;
|
|
roomItem.transform.Find("view_btn").GetComponent<Button>().onClick.AddListener(async () =>
|
|
{
|
|
Storm_and_capture_panl.gameObject.SetActive(true);
|
|
//currentRoomData = await AsyncWebReq.Get<RDate.DataItem>("http://111.229.30.246:48888/Handler/Practice.ashx?action=queryone&Id=" + roomItem.name);
|
|
for (int i = 0; i < roomdata.data.Count; i++)
|
|
{
|
|
if (roomItem.name.Equals(roomdata.data[i].Id))
|
|
{
|
|
currentRoomData = roomdata.data[i];
|
|
}
|
|
}
|
|
Debug.Log(currentRoomData.Id + "====" + roomItem.name);
|
|
Traininginformation tt = new Traininginformation();
|
|
tt = Jsonanalyze.FromJson<Traininginformation>(currentRoomData.ThinkingData);
|
|
CreateSubjectItem(tt);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 创建查看房间的科目
|
|
/// </summary>
|
|
/// <param name="t"></param>
|
|
public void CreateSubjectItem(Traininginformation t)
|
|
{
|
|
if (currentRoomSubjectItemConnect.childCount > 1)
|
|
{
|
|
for (int i = 1; i < currentRoomSubjectItemConnect.childCount; i++)
|
|
{
|
|
GameObject.Destroy(currentRoomSubjectItemConnect.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
for (int i = 0; i < t.subjectsInfo.Count; i++)
|
|
{
|
|
int index = i;
|
|
GameObject subjectTemp = GameObject.Instantiate(currentRoomSubjectItem, currentRoomSubjectItemConnect);
|
|
subjectTemp.name = t.subjectsInfo[index].subjectId;
|
|
subjectTemp.transform.GetChild(0).GetComponent<Text>().text = t.subjectsInfo[index].subjectName;
|
|
subjectTemp.SetActive(true);
|
|
subjectTemp.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
Debug.Log(" subjectTemp.name ===" + subjectTemp.name);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分配面板提交按钮和取消人员选择按钮
|
|
/// </summary>
|
|
private void Submit()
|
|
{
|
|
submit_btn.onClick.AddListener(async () =>
|
|
{
|
|
append_room_panl.gameObject.SetActive(false);
|
|
distribution_panl.gameObject.SetActive(false);
|
|
selector_panl.gameObject.SetActive(false);
|
|
|
|
ReturnRoomID returnRoomId = await AsyncWebReq.Post<ReturnRoomID>("http://111.229.30.246:48888/Handler/Practice.ashx?action=add&Name=" + currentRoomName + "&MissionModel=" + currentMissionModel + "&ThinkingId=" + currentThinkingId, null);
|
|
if (returnRoomId.state)
|
|
{
|
|
CreateRoomBase(returnRoomId.data, currentRoomName);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log(returnRoomId.message);
|
|
}
|
|
});
|
|
|
|
|
|
off3_btn.onClick.AddListener(() =>
|
|
{
|
|
selector_panl.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加分配面板和取消
|
|
/// </summary>
|
|
private void Verify()
|
|
{
|
|
|
|
verify_btn.onClick.AddListener(() =>
|
|
{
|
|
if (room_input.text.Length >= 1)
|
|
{
|
|
distribution_panl.gameObject.SetActive(true);
|
|
currentRoomName = room_input.text;
|
|
}
|
|
else
|
|
{
|
|
tips_txt.text = "请输入房间名称";
|
|
}
|
|
});
|
|
off_btn.onClick.AddListener(() =>
|
|
{
|
|
distribution_panl.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
public void OnRoomModelDropdown(int index)
|
|
{
|
|
currentMissionModel = roomModelDropdown.options[index].text;
|
|
}
|
|
public void OnTinkingDropdown(int index)
|
|
{
|
|
currentThinkingId = thinkingDropdown.options[index].text;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 叉掉房间按钮
|
|
/// </summary>
|
|
private void Forkoffbtn()
|
|
{
|
|
Fork_off_btn.onClick.AddListener(() =>
|
|
{
|
|
append_room_panl.gameObject.SetActive(false);
|
|
});
|
|
cancel_btno.onClick.AddListener(() =>
|
|
{
|
|
append_room_panl.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
private char[] _specialChar = { '_', ' ', '\'', '\\', };
|
|
|
|
private List<DataItem> dataItemTemp = new List<DataItem>();
|
|
|
|
public void FuzzySearch(string searchName)
|
|
{
|
|
dataItemTemp.Clear();
|
|
string name = searchName.Trim(_specialChar).Replace(" ", "");
|
|
for (int i = 0; i < userData.data.Count; i++)
|
|
{
|
|
if (userData.data[i].login_name.Contains(name) || userData.data[i].job_number.Contains(name))
|
|
{
|
|
if (!dataItemTemp.Contains(userData.data[i]))
|
|
dataItemTemp.Add(userData.data[i]);
|
|
}
|
|
}
|
|
|
|
if (dataItemTemp.Count > 0)
|
|
{
|
|
CreateAllUser(dataItemTemp);
|
|
}
|
|
|
|
}
|
|
}
|