_xiaofang/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs

329 lines
9.5 KiB
C#
Raw Normal View History

2024-12-01 19:24:07 +08:00
using System;
2024-11-29 09:47:47 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
2024-11-29 09:47:47 +08:00
using UnityEngine;
using UnityEngine.UI;
using static System.Collections.Specialized.BitVector32;
2024-11-29 09:47:47 +08:00
public class EvacuationPanel : MonoBehaviour
{
2024-12-02 01:46:57 +08:00
public Dictionary<string, int> distributePeople = new Dictionary<string, int>();
public List<PersonnelItem> personnelItems;
2024-11-29 09:47:47 +08:00
public Transform personnelContent;
public Panel panel;
public GameObject personnelPrefabs;
2024-11-29 16:20:58 +08:00
public GameObject classPrefab;
public Transform content;
2024-11-30 17:43:21 +08:00
public Text topText;
2024-12-01 19:24:07 +08:00
public List<ClassItem> classItemList = new List<ClassItem>();
2024-12-01 22:24:03 +08:00
public List<ClassMate> classMateList = new List<ClassMate>();
2024-12-01 19:24:07 +08:00
2024-11-30 17:43:21 +08:00
[Header("ѧ<><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
public InputField StuCountInputField;
public Button CountsubmitBtn;
public Sprite rsprite;
public Sprite fsprite;
public GameObject JuesechoicePop;
2024-12-01 19:24:07 +08:00
public JueseChoicePop jc = new JueseChoicePop();
public JSONReader js;
2024-12-01 19:24:07 +08:00
2024-11-30 17:43:21 +08:00
[Header("<22>ܰ<EFBFBD>ť")]
public Button redistributeBtn;
public Button submitBtn;
2024-11-29 16:20:58 +08:00
2024-12-01 15:06:22 +08:00
[Header("Npc<70><63><EFBFBD><EFBFBD>")]
public int npcNum;
[Header("Npc<70><63><EFBFBD><EFBFBD>")]
public string npcType;
public string roleid;
2024-11-29 09:47:47 +08:00
// Start is called before the first frame update
void Start()
{
SetNpcType();
2024-12-01 19:24:07 +08:00
jc = JuesechoicePop.GetComponent<JueseChoicePop>();
redistributeBtn.onClick.AddListener(ClearData);
2024-12-02 01:46:57 +08:00
CountsubmitBtn.onClick.AddListener(Submit);
submitBtn.onClick.AddListener(totalSubmit);
2024-12-01 19:24:07 +08:00
2024-11-30 17:43:21 +08:00
StuCountInputField.onEndEdit.AddListener(CheckInput);
SetClass();
2024-11-29 09:47:47 +08:00
}
2024-12-02 01:46:57 +08:00
public void totalSubmit()
2024-12-01 19:24:07 +08:00
{
2024-12-07 16:18:15 +08:00
Debug.Log("----------------->>>>>>>>>>>" + createTemplateInfo.Instance.auth_CreateTemplate.npcList==null);
2024-12-02 01:46:57 +08:00
foreach(var item in createTemplateInfo.Instance.auth_CreateTemplate.npcList)
{
item.userId = npcType;
item.roleId = roleid;
}
foreach(var item in createTemplateInfo.Instance.auth_CreateTemplate.playerList)
{
2024-12-02 01:46:57 +08:00
}
2024-12-01 19:24:07 +08:00
2024-12-01 19:24:07 +08:00
}
public void SetNpcType()
{
foreach (var scene in panel.sceneDataDictionary)
{
Debug.Log("+++++++++++");
foreach (var npcData in js.locationDictionary)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
string roleLimit = npcData.Value.NpcRatio;
if(npcData.Value.NpcRatio=="-1")
{
continue;
}
else
{
// <20>Ȱ<EFBFBD><C8B0><EFBFBD>,<2C><><EFBFBD>ָ<EFBFBD>
string[] roleLimitSections = roleLimit.Split(',');
if (scene.Key == npcData.Value.Note)
{
// ֻ<>е<EFBFBD> scene.Key <20><> npcData.Value.Note ƥ<><C6A5>ʱ<EFBFBD><CAB1>ִ<EFBFBD><D6B4>
this.npcType = roleLimitSections[1];
roleid = roleLimitSections[0];
}
}
}
}
}
2024-12-02 01:46:57 +08:00
//private void Submit()
//{
// //int count = int.Parse(StuCountInputField.text);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// //StuCountInputField.text = "";
// //int initialPeople = panel.sceneDataDictionary.Keys.Count* panel.sceneDataDictionary.Values.Count;//<2F>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>
// //string[] sceneNames = { };
// //for(int i = 0; i< panel.sceneDataDictionary.Keys.Count;i++)//<2F>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// //{
// // foreach(var item in panel.sceneDataDictionary.Keys)
// // {
// // sceneNames[i] = item;
// // }
// //}
// //distributePeople = DistributePeople(sceneNames, initialPeople, count);
// //foreach(var item in distributePeople)
// //{
// // Debug.Log(item.Value);
// //}
// int count = int.Parse(StuCountInputField.text); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// StuCountInputField.text = "";
// // <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>
// int initialPeople = panel.sceneDataDictionary.Keys.Count * panel.sceneDataDictionary.Values.Count;
// // <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>sceneNames<65><73><EFBFBD><EFBFBD><E9A3AC>СΪ<D0A1><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// string[] sceneNames = new string[panel.sceneDataDictionary.Keys.Count];
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ䲢<D6B5><E4B2A2><EFBFBD><EFBFBD>sceneNames<65><73><EFBFBD><EFBFBD>
// int i = 0;
// foreach (var item in panel.sceneDataDictionary.Keys)
// {
// sceneNames[i] = item;
// i++;
// }
// // <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>
// distributePeople = DistributePeople(sceneNames, initialPeople, count);
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// foreach (var item in distributePeople)
// {
// //Debug.Log(item.Value);
// foreach(var a in personnelItems)
// {
// a.SetInfo(item.Value.ToString());
// }
// }
//}
private void Submit()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int count = int.Parse(StuCountInputField.text); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
StuCountInputField.text = "";
// <20><><EFBFBD><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>
int initialPeople = 0;
foreach (var item in panel.sceneDataDictionary.Values)
{
initialPeople += item.Count; // <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Value<75><65>һ<EFBFBD><D2BB>List<73><74><EFBFBD><EFBFBD><EFBFBD>ƵĽṹ<C4BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա
}
// <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>sceneNames<65><73><EFBFBD><EFBFBD><E9A3AC>СΪ<D0A1><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string[] sceneNames = new string[panel.sceneDataDictionary.Keys.Count];
// <20><><EFBFBD><EFBFBD>sceneNames<65><73><EFBFBD><EFBFBD>
int i = 0;
foreach (var item in panel.sceneDataDictionary.Keys)
{
sceneNames[i] = item;
i++;
}
// <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><DFBC><EFBFBD>
distributePeople = DistributePeople(sceneNames, initialPeople, count);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (var item in distributePeople)
{
// <20><><EFBFBD><EFBFBD> personnelItems <20>Ǵ洢UIԪ<49>ص<EFBFBD><D8B5>б<EFBFBD>
foreach (var a in personnelItems)
{
a.SetInfo(item.Value.ToString());
}
}
}
public static Dictionary<string, int> DistributePeople(string[] scenes, int initialPeople, int totalPeople)
{
// 1. <20><><EFBFBD><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>
int totalAssigned = initialPeople;
//foreach (var scene in scenes)
//{
// if (initialPeople.ContainsKey(scene))
// {
// totalAssigned += initialPeople[scene];
// }
//}
// 2. <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>
int remainingPeople = totalPeople - totalAssigned;
// 3. <20><>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD>Աƽ<D4B1><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4B5BD><EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>
Dictionary<string, int> finalDistribution = new Dictionary<string, int>(initialPeople);
int peoplePerScene = remainingPeople / scenes.Length;
int extraPeople = remainingPeople % scenes.Length; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 4. ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>Ա
foreach (var scene in scenes)
{
if (finalDistribution.ContainsKey(scene))
{
finalDistribution[scene] += peoplePerScene; // <20><><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Ա
}
else
{
finalDistribution[scene] = peoplePerScene; // <20>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
}
}
// 5. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա
System.Random rand = new System.Random();
for (int i = 0; i < extraPeople; i++)
{
string randomScene = scenes[rand.Next(scenes.Length)];
finalDistribution[randomScene]++;
}
return finalDistribution;
}
2024-12-01 19:24:07 +08:00
private void ClearData()
{
2024-12-01 22:24:03 +08:00
jc.classItem.isSet = false;
foreach (var item in classItemList)
2024-12-01 19:24:07 +08:00
{
item.isSet = false;
item.setClassItem("");
}
2024-12-01 22:24:03 +08:00
jc.classMate.isBeSet = false;
foreach(var item in jc.classMateList)
{
item.isBeSet = false;
item.setName();
}
2024-12-01 19:24:07 +08:00
}
2024-11-29 09:47:47 +08:00
// Update is called once per frame
void Update()
{
2024-11-30 17:43:21 +08:00
CheckInput(StuCountInputField.text);
2024-11-29 09:47:47 +08:00
}
public void SetPersonnel()
{
foreach (Transform child in personnelContent)
{
Destroy(child.gameObject);
}
foreach (var sceneEntry in panel.sceneDataDictionary)
{
GameObject item = GameObject.Instantiate<GameObject>(personnelPrefabs, personnelContent);
PersonnelItem personnelItem=item.GetComponent<PersonnelItem>();
2024-12-02 01:46:57 +08:00
personnelItems.Add(personnelItem);
2024-11-29 09:47:47 +08:00
personnelItem.sceneText.text = sceneEntry.Key;
personnelItem.personnelNum.text = sceneEntry.Value.Count.ToString();
}
}
2024-11-30 17:43:21 +08:00
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>1
void CheckInput(string input)
{
// <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
if (float.TryParse(input, out float result))
{
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>1
if (result > 1)
{
CountsubmitBtn.GetComponent<Image>().sprite = rsprite;
CountsubmitBtn.onClick.AddListener(Countsubmit);
2024-12-04 16:37:51 +08:00
}
2024-11-30 17:43:21 +08:00
}
}
public void Countsubmit()
{
//<2F><>ť<EFBFBD>û<EFBFBD>
CountsubmitBtn.GetComponent<Image>().sprite = fsprite;
StuCountInputField.text = string.Empty;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Npc<70><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CountsubmitBtn.onClick.RemoveAllListeners();
}
//<2F><><EFBFBD><EFBFBD>ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SettopText()
{
topText.text = "<22><><EFBFBD>°༶<C2B0><E0BCB6>Ҫ<EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʦ<EFBFBD><CAA6>";
topText.text = "<22><><EFBFBD><EFBFBD>¥<EFBFBD><C2A5><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ʦ<EFBFBD><CAA6>";
}
//ʵ<><CAB5><EFBFBD><EFBFBD>ClassItem
public void SetClass()
{
for (int i = 0; i < 10; i++)
{
GameObject item = GameObject.Instantiate<GameObject>(classPrefab, content);
ClassItem classItem = item.GetComponent<ClassItem>();
classItem.JuesechoicePop = JuesechoicePop;
2024-12-01 19:24:07 +08:00
classItemList.Add(classItem);
2024-11-30 17:43:21 +08:00
}
}
2024-11-29 09:47:47 +08:00
}