using System; using System.Collections; using System.Linq; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ArmyDropDownDataBind : MonoBehaviour { public RolesInit init; public Dropdown ZongDuiDropDown; public Dropdown ZhiDuiDropDown; public Dropdown DaDuiDropDown; public Dropdown ZhongDuiDropDown; public Dropdown ZhanDouBanDropDown; public static bool IsEmpty = false; public Text UserNameText; private List AllDataList = new List(); private bool ZhanDouBanController = true; private bool ZhiDuiController = true; private bool DaDuiController = true; private bool ZhongDuiController = true; private Organization org; private Dictionary ZongDuiDropDownDic = new Dictionary(); private Dictionary ZhiDuiDropDownDic = new Dictionary(); private Dictionary DaDuiDropDownDic = new Dictionary(); private Dictionary ZhongDuiDropDownDic = new Dictionary(); private Dictionary ZhanDouBanDropDownDic = new Dictionary(); public void GetAllData(List DataList) { AllDataList = DataList; DataBind(); } void Start() { CurrentUserInfo.role = Role.None; } private Organization GetOrganizationById(int Id) { Organization org = new Organization(); foreach (Organization o in AllDataList) { if (o.Id == Id) { org.Id = o.Id; org.DisplayName = o.DisplayName; org.Level = o.Level; org.ParentId = o.ParentId; org.PersonCount = o.PersonCount; } } return org; } private int GetParentIdByName(string DisPlayName) { int result = -100; foreach (Organization o in AllDataList) { if (o.DisplayName == DisPlayName) { result = o.Id; } } return result; } private int GetParentIdByOptionData(Dictionary Dic, Dropdown.OptionData selected) { foreach (var item in Dic) { if (item.Value == selected) { return item.Key; } } return -1; } private void DataBind() { ZongDuiDropDown.interactable = false; ZhiDuiDropDown.interactable = false; DaDuiDropDown.interactable = false; ZhongDuiDropDown.interactable = false; Organization o; CurrentUserInfo.organization = GetOrganizationById(CurrentUserInfo.mySelf.OrganizationId); switch (CurrentUserInfo.organization.Level) { case 1://总队 ZongDuiDropDownBind(0); ManoeuvreDropDownBind(ZongDuiDropDown, CurrentUserInfo.organization.DisplayName); init.Init(SelectionInitType.总队); ZhiDuiDropDown.interactable = true; DaDuiDropDown.interactable = true; ZhongDuiDropDown.interactable = true; if (GameSettings.othersSettings.mode != Mode.manoeuvre) { ZongDuiDropDown.interactable = true; ZhiDuiDropDownBind(CurrentUserInfo.organization.Id); } break; case 2://支队 ZongDuiDropDownBind(0); o = GetOrganizationById(CurrentUserInfo.organization.ParentId); if (o != null) { ManoeuvreDropDownBind(ZongDuiDropDown, o.DisplayName); if (GameSettings.othersSettings.mode != Mode.manoeuvre) ZongDuiDropDown.interactable = true; } ZhiDuiDropDownBind(CurrentUserInfo.organization.ParentId); ManoeuvreDropDownBind(ZhiDuiDropDown, CurrentUserInfo.organization.DisplayName); init.Init(SelectionInitType.支队); DaDuiDropDown.interactable = true; ZhongDuiDropDown.interactable = true; if (GameSettings.othersSettings.mode != Mode.manoeuvre) { ZhiDuiDropDown.interactable = true; DaDuiDropDownBind(CurrentUserInfo.organization.Id); } break; case 3://大队 ZongDuiDropDownBind(0); o = GetOrganizationById(CurrentUserInfo.organization.ParentId); if (o != null) { Organization oo = GetOrganizationById(o.ParentId); if (oo != null) { ManoeuvreDropDownBind(ZongDuiDropDown, oo.DisplayName); if (GameSettings.othersSettings.mode != Mode.manoeuvre) ZongDuiDropDown.interactable = true; } ZhiDuiDropDownBind(o.ParentId); ManoeuvreDropDownBind(ZhiDuiDropDown, o.DisplayName); if (GameSettings.othersSettings.mode != Mode.manoeuvre) ZhiDuiDropDown.interactable = true; } DaDuiDropDownBind(CurrentUserInfo.organization.ParentId); ManoeuvreDropDownBind(DaDuiDropDown, CurrentUserInfo.organization.DisplayName); init.Init(SelectionInitType.大队); if (GameSettings.othersSettings.mode != Mode.manoeuvre) { DaDuiDropDown.interactable = true; ZhongDuiDropDownBind(CurrentUserInfo.organization.Id); } ZhongDuiDropDown.interactable = true; break; case 4://中队 ZongDuiDropDownBind(0); o = GetOrganizationById(CurrentUserInfo.organization.ParentId); if (o != null) { Organization oo = GetOrganizationById(o.ParentId); if (oo != null) { Organization ooo = GetOrganizationById(oo.ParentId); if (ooo != null) { ManoeuvreDropDownBind(ZongDuiDropDown, ooo.DisplayName); if (GameSettings.othersSettings.mode != Mode.manoeuvre) ZongDuiDropDown.interactable = true; } ZhiDuiDropDownBind(oo.ParentId); ManoeuvreDropDownBind(ZhiDuiDropDown, oo.DisplayName); if (GameSettings.othersSettings.mode != Mode.manoeuvre) ZhiDuiDropDown.interactable = true; } DaDuiDropDownBind(o.ParentId); ManoeuvreDropDownBind(DaDuiDropDown, o.DisplayName); if (GameSettings.othersSettings.mode != Mode.manoeuvre) DaDuiDropDown.interactable = true; } ZhongDuiDropDownBind(CurrentUserInfo.organization.ParentId); ManoeuvreDropDownBind(ZhongDuiDropDown, CurrentUserInfo.organization.DisplayName); init.Init(SelectionInitType.中队); ZhanDouBanDropDownBind(1); if (GameSettings.othersSettings.mode != Mode.manoeuvre) ZhongDuiDropDown.interactable = true; break; default: break; } ZongDuiDropDown.onValueChanged.AddListener(OnValueChanged_ZongDuiDropDown); ZhiDuiDropDown.onValueChanged.AddListener(OnValueChanged_ZhiDuiDropDown); DaDuiDropDown.onValueChanged.AddListener(OnValueChanged_DaDuiDropDown); ZhongDuiDropDown.onValueChanged.AddListener(OnValueChanged_ZhongDuiDropDown); ZhanDouBanDropDown.onValueChanged.AddListener(OnValueChanged_ZhanDouBanDropDown); UserNameText.text = CurrentUserInfo.mySelf.Username; } //中队选择 private void OnValueChanged_ZhongDuiDropDown(int value) { if (ZhongDuiController) { ZhanDouBanController = false; if (value == 0) { ZhanDouBanDropDownBind(-1); if (RolesInit.NowInitType != SelectionInitType.大队) init.Init(SelectionInitType.大队); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(DaDuiDropDownDic, DaDuiDropDown.options[DaDuiDropDown.value])); } else { if (RolesInit.NowInitType != SelectionInitType.中队) init.Init(SelectionInitType.中队); ZhanDouBanDropDownBind(1); if (GameSettings.othersSettings.mode != Mode.manoeuvre) //CurrentUserInfo.organization = GetOrganizationById(GetParentIdByName(ZhongDuiDropDown.captionText.text)); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(ZhongDuiDropDownDic, ZhongDuiDropDown.options[value])); } IsEmpty = false; } } //战斗班选择 private void OnValueChanged_ZhanDouBanDropDown(int value) { if (ZhanDouBanController) { if (value != 0) { if (RolesInit.NowInitType != SelectionInitType.战斗班 && value != 0) init.Init(SelectionInitType.战斗班); CurrentUserInfo.organization = new Organization() { Id = value, Level = 5, DisplayName = ZhongDuiDropDown.captionText.text + "_" + ZhanDouBanDropDown.captionText.text, //ParentId = GetParentIdByName(ZhongDuiDropDown.captionText.text), ParentId = GetParentIdByOptionData(ZhongDuiDropDownDic, ZhongDuiDropDown.options[ZhongDuiDropDown.value]), }; } else { if (RolesInit.NowInitType != SelectionInitType.中队) init.Init(SelectionInitType.中队); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(ZhongDuiDropDownDic, ZhongDuiDropDown.options[ZhongDuiDropDown.value])); } IsEmpty = false; } } //大队选择 private void OnValueChanged_DaDuiDropDown(int value) { if (DaDuiController) { ZhongDuiController = false; ZhanDouBanController = false; if (value == 0) { ZhongDuiDropDownBind(-1); ZhanDouBanDropDownBind(-1); if (RolesInit.NowInitType != SelectionInitType.支队) init.Init(SelectionInitType.支队); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(ZhiDuiDropDownDic, ZhiDuiDropDown.options[ZhiDuiDropDown.value])); } else { if (RolesInit.NowInitType != SelectionInitType.大队) init.Init(SelectionInitType.大队); //ZhongDuiDropDownBind(GetParentIdByName(DaDuiDropDown.captionText.text)); ZhongDuiDropDownBind(GetParentIdByOptionData(DaDuiDropDownDic, DaDuiDropDown.options[value])); ZhanDouBanDropDownBind(-1); if (GameSettings.othersSettings.mode != Mode.manoeuvre) //CurrentUserInfo.organization = GetOrganizationById(GetParentIdByName(DaDuiDropDown.captionText.text)); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(DaDuiDropDownDic, DaDuiDropDown.options[value])); } IsEmpty = false; } } //支队选择 private void OnValueChanged_ZhiDuiDropDown(int value) { if (ZhiDuiController) { ZhongDuiController = false; DaDuiController = false; ZhanDouBanController = false; if (value == 0) { DaDuiDropDownBind(-1); ZhongDuiDropDownBind(-1); ZhanDouBanDropDownBind(-1); if (RolesInit.NowInitType != SelectionInitType.总队) init.Init(SelectionInitType.总队); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(ZongDuiDropDownDic, ZongDuiDropDown.options[ZongDuiDropDown.value])); } else { if (RolesInit.NowInitType != SelectionInitType.支队) init.Init(SelectionInitType.支队); //DaDuiDropDownBind(GetParentIdByName(ZhiDuiDropDown.captionText.text)); DaDuiDropDownBind(GetParentIdByOptionData(ZhiDuiDropDownDic, ZhiDuiDropDown.options[value])); ZhongDuiDropDownBind(-1); ZhanDouBanDropDownBind(-1); if (GameSettings.othersSettings.mode != Mode.manoeuvre) //CurrentUserInfo.organization = GetOrganizationById(GetParentIdByName(ZhiDuiDropDown.captionText.text)); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(ZhiDuiDropDownDic, ZhiDuiDropDown.options[value])); } IsEmpty = false; } } //总队选择 private void OnValueChanged_ZongDuiDropDown(int value) { ZhiDuiController = false; ZhongDuiController = false; DaDuiController = false; ZhanDouBanController = false; if (value == 0) { ZhiDuiDropDownBind(-1); DaDuiDropDownBind(-1); ZhongDuiDropDownBind(-1); ZhanDouBanDropDownBind(-1); init.Init(SelectionInitType.所有); IsEmpty = true; return; } else { if (RolesInit.NowInitType != SelectionInitType.总队) init.Init(SelectionInitType.总队); //ZhiDuiDropDownBind(GetParentIdByName(ZongDuiDropDown.captionText.text)); ZhiDuiDropDownBind(GetParentIdByOptionData(ZongDuiDropDownDic, ZongDuiDropDown.options[value])); if (GameSettings.othersSettings.mode != Mode.manoeuvre) //CurrentUserInfo.organization = GetOrganizationById(GetParentIdByName(ZongDuiDropDown.captionText.text)); CurrentUserInfo.organization = GetOrganizationById(GetParentIdByOptionData(ZongDuiDropDownDic, ZongDuiDropDown.options[value])); IsEmpty = false; } } //下拉框数据绑定 private void BindMethord(Dropdown BindDropDown, int ParentId, string ShowText, Dictionary Dic) { BindDropDown.ClearOptions(); Dropdown.OptionData tempData; tempData = new Dropdown.OptionData(); tempData.text = ShowText; BindDropDown.options.Add(tempData); if (ParentId == -1) { BindDropDown.value = 0; BindDropDown.captionText.text = BindDropDown.options[0].text; return; } List BindList = new List(); BindList = AllDataList.Where(a => a.ParentId == ParentId).ToList(); Dic.Clear(); for (int i = 0; i < BindList.Count; i++) { tempData = new Dropdown.OptionData(); tempData.text = BindList[i].DisplayName; BindDropDown.options.Add(tempData); Dic.Add(BindList[i].Id, tempData); } BindDropDown.value = 0; BindDropDown.captionText.text = BindDropDown.options[0].text; } //总队数据绑定 public void ZongDuiDropDownBind(int ParentId) { BindMethord(ZongDuiDropDown, ParentId, "选择总队", ZongDuiDropDownDic); } //支队数据绑定 public void ZhiDuiDropDownBind(int ParentId) { BindMethord(ZhiDuiDropDown, ParentId, "选择支队", ZhiDuiDropDownDic); ZhiDuiController = true; } //大队数据绑定 public void DaDuiDropDownBind(int ParentId) { BindMethord(DaDuiDropDown, ParentId, "选择大队", DaDuiDropDownDic); DaDuiController = true; } //中队数据绑定 public void ZhongDuiDropDownBind(int ParentId) { BindMethord(ZhongDuiDropDown, ParentId, "选择中队", ZhongDuiDropDownDic); ZhongDuiController = true; } //战斗班数据绑定 public void ZhanDouBanDropDownBind(int ParentId) { ZhanDouBanDropDown.ClearOptions(); Dropdown.OptionData tempData; tempData = new Dropdown.OptionData(); tempData.text = "选择战斗班"; ZhanDouBanDropDown.options.Add(tempData); if (ParentId == -1) { ZhanDouBanDropDown.value = 0; ZhanDouBanDropDown.captionText.text = ZhanDouBanDropDown.options[0].text; return; } for (int i = 0; i < 10; i++) { tempData = new Dropdown.OptionData(); tempData.text = "战斗" + (i + 1) + "班"; ZhanDouBanDropDown.options.Add(tempData); } ZhanDouBanDropDown.value = 0; ZhanDouBanDropDown.captionText.text = ZhanDouBanDropDown.options[0].text; ZhanDouBanController = true; } //演习模式下拉数据绑定 public void ManoeuvreDropDownBind(Dropdown Dropdown, string ShowText) { for (int i = 0; i < Dropdown.options.Count; i++) { if (Dropdown.options[i].text == ShowText) { Dropdown.value = i; break; } } Dropdown.captionText.text = ShowText; } }