void AddObjects() { KingInfo kInfo = Informations.Instance.GetKingInfo(Controller.kingIndex); for (int i = 0; i < kInfo.cities.Count; i++) { int cIdx = (int)kInfo.cities[i]; List <int> obj = Informations.Instance.GetCityInfo(cIdx).objects; if (obj.Count > 0) { for (int j = 0; j < obj.Count; j++) { string objName = ""; int code = (int)obj[j]; int idx = code & 0xFFFF; int type = code >> 16; switch (type) { case 1: objName = ZhongWen.Instance.GetEquipmentName(idx); break; case 2: objName = ZhongWen.Instance.GetArmsName(idx) + ZhongWen.Instance.bingfu; break; case 3: objName = ZhongWen.Instance.GetFormationName(idx) + ZhongWen.Instance.zhishu; break; } CityObjectsData data = new CityObjectsData(cIdx, code); ListItem li = objsList.AddItem(objName); li.SetItemData(data); } } } }
void OnConfirmButton() { confirmBox.SetActive(false); int gIdx = (int)generalsInfoList.GetSelectItem().GetItemData(); GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(gIdx); CityObjectsData cityData = (CityObjectsData)objsList.GetSelectItem().GetItemData(); int data = cityData.code; if (data == -1) { state = 0; string objName = ZhongWen.Instance.GetEquipmentName(gInfo.equipment); int code = (1 << 16) + gInfo.equipment; List <int> o = Informations.Instance.GetCityInfo(gInfo.city).objects; o.Add(code); CityObjectsData d = new CityObjectsData(gInfo.city, code); objsList.AddItem(objName).SetItemData(d); EquipmentInfo eInfo = Informations.Instance.GetEquipmentInfo(gInfo.equipment); if (eInfo.type == 0) { gInfo.intellect -= eInfo.data; } else if (eInfo.type == 3) { gInfo.strength -= eInfo.data; } gInfo.equipment = -1; objsList.DeleteItem(objsList.GetSelectIndex()); } else { List <int> objs = Informations.Instance.GetCityInfo(cityData.city).objects; int code = data & 0xFFFF; int type = data >> 16; int cObjIdx = 0; for (; cObjIdx < objs.Count; cObjIdx++) { if ((int)objs[cObjIdx] == cityData.code) { break; } } objs.RemoveAt(cObjIdx); switch (type) { case 1: state = 0; if (gInfo.equipment != -1) { string objName = ZhongWen.Instance.GetEquipmentName(gInfo.equipment); int d = (1 << 16) + gInfo.equipment; cityData.code = d; objsList.GetSelectItem().GetComponent <exSpriteFont>().text = objName; objsList.GetSelectItem().SetItemData(cityData); objsList.SetItemSelected(-1, false); objs.Insert(cObjIdx, d); } else { objsList.DeleteItem(objsList.GetSelectIndex()); } ChangeGeneralsEquitment(gInfo, code); break; case 2: state = 2; gInfo.arms += code; objsList.DeleteItem(objsList.GetSelectIndex()); dialogue.SetDialogue(Informations.Instance.GetKingInfo(Controller.kingIndex).generalIdx, ZhongWen.Instance.GetGeneralName(gIdx) + ZhongWen.Instance.jublzh + ZhongWen.Instance.GetArmsName(code) + ZhongWen.Instance.denengli, MenuDisplayAnim.AnimType.InsertFromBottom); break; case 3: state = 2; gInfo.formation += code; objsList.DeleteItem(objsList.GetSelectIndex()); dialogue.SetDialogue(Informations.Instance.GetKingInfo(Controller.kingIndex).generalIdx, ZhongWen.Instance.GetGeneralName(gIdx) + ZhongWen.Instance.xuehuile + ZhongWen.Instance.GetFormationName(code), MenuDisplayAnim.AnimType.InsertFromBottom); break; } } generalsInfoList.GetSelectItem().GetComponent <exSpriteFont>().text = GetGeneralInfo(gIdx); OnSelectGeneral(); }
void OnSelectGeneral() { if (state != 0) { return; } int count = objsList.GetCount(); int gIdx = (int)generalsInfoList.GetSelectItem().GetItemData(); GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(gIdx); for (int i = 0; i < count; i++) { ListItem item = objsList.GetListItem(i); CityObjectsData cityData = (CityObjectsData)item.GetItemData(); int data = cityData.code; if (data == -1) { continue; } int code = data & 0xFFFF; int type = data >> 16; bool flag = true; switch (type) { case 1: if (gInfo.equipment == code) { flag = false; } break; case 2: if ((gInfo.arms & code) != 0) { flag = false; } break; case 3: if ((gInfo.formation & code) != 0) { flag = false; } break; } item.SetSelectEnable(flag); } if (count > 0 && ((CityObjectsData)objsList.GetListItem(count - 1).GetItemData()).code == -1) { if (gInfo.equipment == -1) { objsList.DeleteItem(count - 1); } } else { if (gInfo.equipment != -1) { ListItem li = objsList.AddItem(ZhongWen.Instance.xiexia); CityObjectsData data = new CityObjectsData(0, -1); li.SetItemData(data); } } }