using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using UnityEngine.UI; using AX.NetworkSystem; public class PowerTransferController : MonoBehaviour { public GameObject SelectOne; public GameObject SelectTwo; public DropDownRecordByAC SelectDrop; public Transform ScrollOneParent; public Transform ScrollTwoParent; public GameObject ScrollItemPrefab; public Transform PowerItemParent; public Transform PowerItemParent1; public List AllCarMessage; public GameObject PowerItemPrefab; public InputField PeoPleNumInput; public ButtonRecordByAC SureBtn; public GameObject Shows; public Text ShowsTitle; private List BindList; private List AllOrgDataList; private bool IsTwo; private Dictionary DropDownDic; private Dictionary ToggleDic; private ToggleGroup Tgroup; private List BindCarList; private List BindCarList1; private UserData NowSelectUser; public GameObject Error; public GameObject Caption; public GameObject ShowScroll; public GameObject Caption1; public GameObject ShowScroll1; public GameObject PeopleNum; public GameObject InputFieldPeopleNum; private int shuiGuanCheNum; private int paoMoCheNum; private int gaoPenCheCheNum; private int yunTiCheNum; private int juGaoCheNum; private int paiYanCheNum; private int qiangXianCheNum; private int zhaoMingCheNum; private int qiChaiCheNum; private int gongQiCheNum; private int poChaiCheNum; public GameObject hintWin; private List SelectCars1 = new List(); private List CarsNum1 = new List(); void Bind() { Tgroup = GetComponent(); if (IsTwo) { SelectTwo.gameObject.SetActive(true); SelectOne.gameObject.SetActive(false); } else { SelectTwo.gameObject.SetActive(false); SelectOne.gameObject.SetActive(true); List dataList = new List(); foreach (var item in CurrentUserInfo.room.UserList) { if (GetParentOrgId(item.Org.ParentId) == CurrentUserInfo.organization.Id && item.Role == Role.中队指挥) { dataList.Add(item); } } SelectScrollBind(dataList); } SureBtn.OutInterFaceButton = SureBtnClick; } private void SureBtnClick() { if (GameSettings.othersSettings.mode == Mode.manoeuvre) { List ActiveCars = new List(); List SelectCars = new List(); if (PeoPleNumInput.text == null || PeoPleNumInput.text == "") { //提示需要输入调派人数 Error.SetActive(true); Error.GetComponent().text = "请输入调派人数"; return; } else { int result = int.Parse(PeoPleNumInput.text); if (result <= 0) {//提示请输入正整数 Error.SetActive(true); Error.GetComponent().text = "请输入正整数"; return; } } int num = int.Parse(PeoPleNumInput.text); int minnum, maxnum = 0, persons = 0; if (CurrentUserInfo.role == Role.总队指挥中心) { foreach (Transform child in ScrollTwoParent) { if (child.GetComponent().isOn) { persons = child.GetComponent().Persons; } } } if (CurrentUserInfo.role == Role.支队指挥中心) { foreach (Transform child in ScrollOneParent) { if (child.GetComponent().isOn) { persons = child.GetComponent().Persons; } } } if (num > persons) { //提示调派人数大于此中队的总人数 Error.SetActive(true); Error.GetComponent().text = "调派人数大于中队总人数"; return; } foreach (FireCarEngine f in BindCarList) { if (f.IsActive == 1) { ActiveCars.Add(f); } } if (ActiveCars.Count <= 0) { //提示没有可用的车辆调派 Error.SetActive(true); Error.GetComponent().text = "该中队没有可用的车辆调派"; return; } foreach (Transform t in PowerItemParent) { if (t.GetComponent().ControlToggle.isOn) { SelectCars.Add(t.GetComponent().MyData); } } if (SelectCars.Count == 0) { //提示没有选择要调派的车辆 Error.SetActive(true); Error.GetComponent().text = "请选择要调派的车辆"; return; } foreach (Transform t in PowerItemParent) { if (t.GetComponent().ControlToggle.isOn) { maxnum += int.Parse(t.GetComponent().MyData.PassengerCapacity.ToString()); } } if (num > maxnum) { //提示调派人数大于可载总人数 Error.SetActive(true); Error.GetComponent().text = "调派人数大于可载总人数"; return; } minnum = SelectCars.Count; if (minnum > num) { //提示调派人数少于车辆辆数 Error.SetActive(true); Error.GetComponent().text = "调派人数少于调派的车辆数"; return; } //动态分配人数 int[] PersonNum = new int[SelectCars.Count]; while (num > 0) { for (int i = 0; i < SelectCars.Count; i++) { if (num > 0 && PersonNum[i] < SelectCars[i].PassengerCapacity) { PersonNum[i] += 1; num--; } } } List> tempPowers = new List>(); for (int i = 0; i < SelectCars.Count; i++) { SelectCars[i].PassengerCapacity = PersonNum[i]; tempPowers.Add(new KeyValuePair(SelectCars[i], 1)); } List> powers = new List>(); var GroupResult = from FireCarEngine in tempPowers group FireCarEngine by FireCarEngine.Key.Type; foreach (IGrouping> item in GroupResult) { powers.Add(new KeyValuePair(item.ToList()[0].Key, item.Count())); } //先通报灾情 //合理分配人数给中队派车(出警界面刷出车辆信息开始计时) NetworkManager.Default.SendAsync("COMMANDCENTER_VEHICLETRANSFER_SYNC", new KeyValuePair>>>(NowSelectUser.UserInfo.Id, new KeyValuePair>>(GameSettings.disasterSetting.policeCallData, powers) )); //发送给房间内各个客服端调派车辆数据,作战部署力量列表用 NetworkManager.Default.SendAsync("FIREDEPLOY_ENGINES_SYNC", new KeyValuePair>>(NowSelectUser.Org.DisplayName, powers)); //禁用已经调派车辆 foreach (var item in SelectCars) { foreach (var c in AllCarMessage) { if (c.Id == item.Id) { c.IsActive = 0; break; } } } //刷新显示 foreach (var item in SelectCars) { foreach (Transform t in PowerItemParent) { if (t.GetComponent().MyData.Id == item.Id) { t.GetComponent().Bind(item); } } } } if (GameSettings.othersSettings.mode == Mode.Practice) { SelectCars1.Clear(); CarsNum1.Clear(); foreach (Transform t in PowerItemParent1) { if (t.GetComponent().ControlToggle.isOn) { SelectCars1.Add(t.GetComponent().MyData); int result; if (int.TryParse(t.Find("PoliceCallNum").GetComponent().text, out result)) { CarsNum1.Add(int.Parse(t.Find("PoliceCallNum").GetComponent().text)); } } } if (SelectCars1.Count == 0) { //提示没有选择要调派的车辆 Error.SetActive(true); Error.GetComponent().text = "请选择要调派的车辆"; return; } bool flag = false; foreach (Transform t in PowerItemParent1) { if (t.GetComponent().ControlToggle.isOn) { if (t.Find("PoliceCallNum").GetComponent().text == "") { flag = true; break; } } } if (flag) { //提示没有选择要调派的车辆 Error.SetActive(true); Error.GetComponent().text = "选择的车辆有未输入调派数量的项"; return; } bool flag1 = false; foreach (Transform t in PowerItemParent1) { if (t.GetComponent().ControlToggle.isOn) { int inputCount = int.Parse(t.Find("PoliceCallNum").GetComponent().text); int activeCount = int.Parse(t.Find("ActiveCars").GetComponent().text); if (inputCount > activeCount) { flag1 = true; break; } } } if (flag1) { hintWin.SetActive(true); } else { Sure(); } } } public void Sure() { List> powers = new List>(); for (int i = 0; i < SelectCars1.Count; i++) { powers.Add(new KeyValuePair(SelectCars1[i], CarsNum1[i])); } //先通报灾情 //合理分配人数给中队派车(出警界面刷出车辆信息开始计时) NetworkManager.Default.SendAsync("COMMANDCENTER_VEHICLETRANSFER_SYNC", new KeyValuePair>>>(NowSelectUser.UserInfo.Id, new KeyValuePair>>(GameSettings.disasterSetting.policeCallData, powers) )); hintWin.SetActive(false); //发送给房间内各个客服端调派车辆数据,作战部署力量列表用 NetworkManager.Default.SendAsync("FIREDEPLOY_ENGINES_SYNC", new KeyValuePair>>(NowSelectUser.Org.DisplayName, powers)); } public void Cancel() { hintWin.SetActive(false); } public void SelectDropBind(List DataList) { AllOrgDataList = DataList; BindList = new List(); if (CurrentUserInfo.role == Role.支队指挥中心) { Bind(); return; } IsTwo = true; Organization org = new Organization(); foreach (UserData data in CurrentUserInfo.room.UserList) { if (data.Role == Role.中队指挥) { int ParentId = GetParentOrgId(data.Org.ParentId); foreach (var item in AllOrgDataList) { if (item.Id == ParentId) { org = item; break; } } if (org != null && !BindList.Contains(org)) { BindList.Add(org); } } } DropDownDic = new Dictionary(); SelectDrop.GetComponent().ClearOptions(); Dropdown.OptionData tempData; tempData = new Dropdown.OptionData(); tempData.text = "选择单位"; SelectDrop.GetComponent().options.Add(tempData); for (int i = 0; i < BindList.Count; i++) { tempData = new Dropdown.OptionData(); tempData.text = BindList[i].DisplayName; SelectDrop.GetComponent().options.Add(tempData); DropDownDic.Add(BindList[i].Id, tempData); } SelectDrop.GetComponent().value = 0; SelectDrop.GetComponent().captionText.text = SelectDrop.GetComponent().options[0].text; SelectDrop.GetComponent().OutInterFaceDropDown = SelectDropValueChange; Bind(); } private void SelectDropValueChange(int value) { int id = GetIdByOptionData(DropDownDic, SelectDrop.GetComponent().options[value]); //List dataList = CurrentUserInfo.room.UserList.Where(t => GetParentOrgId(t.Org.ParentId) == id).ToList(); List dataList = new List(); foreach (var item in CurrentUserInfo.room.UserList) { if (GetParentOrgId(item.Org.ParentId) == id && item.Role == Role.中队指挥) { dataList.Add(item); } } SelectScrollBind(dataList); } private void SelectScrollBind(List DataList) { if (IsTwo) { foreach (Transform t in ScrollTwoParent) { Destroy(t.gameObject); } if (DataList.Count <= 0) return; foreach (UserData u in DataList) { GameObject g = Instantiate(ScrollItemPrefab, ScrollTwoParent); g.GetComponent().Persons = GetOrgPersons(u.Org.Id); g.GetComponent().OutInterFaceToggle = (bool ok) => { ShowSelectPower(ok, g.GetComponent()); }; g.GetComponent().group = Tgroup; g.GetComponent().Bind(u); } } else { if (ScrollOneParent.childCount > 0) foreach (Transform t in ScrollOneParent) { Destroy(t.gameObject); } if (DataList.Count <= 0) return; foreach (UserData u in DataList) { GameObject g = Instantiate(ScrollItemPrefab, ScrollOneParent); g.GetComponent().Persons = GetOrgPersons(u.Org.Id); g.GetComponent().OutInterFaceToggle = (bool ok) => { ShowSelectPower(ok, g.GetComponent()); }; g.GetComponent().group = Tgroup; g.GetComponent().Bind(u); } } } private void ShowSelectPower(bool ok, Toggle toggle) { int id = toggle.GetComponent().UData.Org.Id; if (ok) { ShowsTitle.text = toggle.GetComponent().UData.Org.DisplayName; if (PowerItemParent.childCount > 0) foreach (Transform t in PowerItemParent) { Destroy(t.gameObject); } NowSelectUser = toggle.GetComponent().UData; if (!Shows.gameObject.activeSelf) Shows.gameObject.SetActive(true); //获取当前中队消防力量 BindCarList = new List(); foreach (var item in AllCarMessage) { if (item.OrganizationId == id) { BindCarList.Add(item); } } if (GameSettings.othersSettings.mode == Mode.manoeuvre) { foreach (FireCarEngine f in BindCarList) { GameObject g = Instantiate(PowerItemPrefab, PowerItemParent); g.GetComponent().Bind(f); } } if (GameSettings.othersSettings.mode == Mode.Practice) { Caption.SetActive(false); ShowScroll.SetActive(false); Caption1.SetActive(true); ShowScroll1.SetActive(true); PeopleNum.SetActive(false); InputFieldPeopleNum.SetActive(false); GetCarTypeCounts(); foreach (Transform child in PowerItemParent1.transform) { if (child.GetComponent().CarType.text == "水罐车") { child.GetComponent().State.text = shuiGuanCheNum.ToString(); child.GetComponent().MyData = GetCarData(0, "水罐车",child); } if (child.GetComponent().CarType.text == "泡沫车") { child.GetComponent().State.text = paoMoCheNum.ToString(); child.GetComponent().MyData = GetCarData(1, "泡沫车", child); } if (child.GetComponent().CarType.text == "高喷车") { child.GetComponent().State.text = gaoPenCheCheNum.ToString(); child.GetComponent().MyData = GetCarData(4, "高喷车", child); } if (child.GetComponent().CarType.text == "云梯车") { child.GetComponent().State.text = yunTiCheNum.ToString(); child.GetComponent().MyData = GetCarData(5, "云梯车", child); } if (child.GetComponent().CarType.text == "举高车") { child.GetComponent().State.text = juGaoCheNum.ToString(); child.GetComponent().MyData = GetCarData(3, "举高车", child); } if (child.GetComponent().CarType.text == "排烟车") { child.GetComponent().State.text = paiYanCheNum.ToString(); child.GetComponent().MyData = GetCarData(6, "排烟车", child); } if (child.GetComponent().CarType.text == "抢险车") { child.GetComponent().State.text = qiangXianCheNum.ToString(); child.GetComponent().MyData = GetCarData(7, "抢险车", child); } if (child.GetComponent().CarType.text == "照明车") { child.GetComponent().State.text = zhaoMingCheNum.ToString(); child.GetComponent().MyData = GetCarData(9, "照明车", child); } if (child.GetComponent().CarType.text == "器材车") { child.GetComponent().State.text = qiChaiCheNum.ToString(); child.GetComponent().MyData = GetCarData(8, "器材车", child); } if (child.GetComponent().CarType.text == "供气车") { child.GetComponent().State.text = gongQiCheNum.ToString(); child.GetComponent().MyData = GetCarData(12, "供气车", child); } if (child.GetComponent().CarType.text == "破拆车") { child.GetComponent().State.text = poChaiCheNum.ToString(); child.GetComponent().MyData = GetCarData(19, "破拆车", child); } } } } else { if (GameSettings.othersSettings.mode == Mode.manoeuvre) { if (!Tgroup.AnyTogglesOn()) { foreach (Transform t in PowerItemParent) { Destroy(t.gameObject); } NowSelectUser = null; if (Shows.gameObject.activeSelf) Shows.gameObject.SetActive(false); } } if (GameSettings.othersSettings.mode == Mode.Practice) { if (!Tgroup.AnyTogglesOn()) { NowSelectUser = null; if (Shows.gameObject.activeSelf) Shows.gameObject.SetActive(false); } } } } private int GetIdByOptionData(Dictionary Dic, Dropdown.OptionData selected) { foreach (var item in Dic) { if (item.Value == selected) { return item.Key; } } return -1; } private int GetParentOrgId(int orgId) { foreach (var item in AllOrgDataList) { if (item.Id == orgId) { return item.ParentId; } } return -1; } private int GetOrgPersons(int orgId) { foreach (var item in AllOrgDataList) { if (item.Id == orgId) { return item.PersonCount; } } return -1; } private void GetCarTypeCounts() { shuiGuanCheNum = 0; paoMoCheNum = 0; gaoPenCheCheNum = 0; yunTiCheNum = 0; juGaoCheNum = 0; paiYanCheNum = 0; qiangXianCheNum = 0; zhaoMingCheNum = 0; qiChaiCheNum = 0; gongQiCheNum = 0; poChaiCheNum = 0; foreach (FireCarEngine f in BindCarList) { if (f.IsActive == 1) { if (f.Type == 0) { shuiGuanCheNum++; } if (f.Type == 1) { paoMoCheNum++; } if (f.Type == 4) { gaoPenCheCheNum++; } if (f.Type == 5) { yunTiCheNum++; } if (f.Type == 3) { juGaoCheNum++; } if (f.Type == 6) { paiYanCheNum++; } if (f.Type == 7) { qiangXianCheNum++; } if (f.Type == 9) { zhaoMingCheNum++; } if (f.Type == 8) { qiChaiCheNum++; } if (f.Type == 12) { gongQiCheNum++; } if (f.Type == 19) { poChaiCheNum++; } } } } private FireCarEngine GetCarData(int carType ,string carTypeName, Transform child) { FireCarEngine fireCarengine = new FireCarEngine(); fireCarengine.Type = carType; fireCarengine.TypeName = carTypeName; fireCarengine.PassengerCapacity = int.Parse(child.GetComponent().PeoPleNum.text.ToString()); fireCarengine.WaterAmount = int.Parse(child.GetComponent().WaterNum.text.ToString()); fireCarengine.FoamAmount = int.Parse(child.GetComponent().FoamNum.text.ToString()); fireCarengine.DryPowderAmount = int.Parse(child.GetComponent().DryPowderNum.text.ToString()); fireCarengine.Height = int.Parse(child.GetComponent().Height.text.ToString()); fireCarengine.IsActive = 1; fireCarengine.OrganizationId = CurrentUserInfo.organization.Id; fireCarengine.OrganizationName = CurrentUserInfo.organization.DisplayName; return fireCarengine; } }