void OnGeneralSelectedHandler(object data) { int gIdx = (int)data; for (int i = 0; i < gList.Count; i++) { PushedButton pbtn = (PushedButton)gList[i]; if (pbtn.GetButtonData() == data) { GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(gIdx); slider.transform.position = new Vector3(slider.transform.position.x, pbtn.transform.position.y, slider.transform.position.z); slider.SetSlider(gInfo.soldierMax + gInfo.knightMax, gInfo.soldierCur + gInfo.knightCur); selectIdx = i; } else { pbtn.SetButtonState(PushedButton.ButtonState.Normal); } } SetGeneralInfo(gIdx); UpdateChangeArms(gIdx); }
void OnSliderMoveController(int offset) { PushedButton pbtn = (PushedButton)gList[selectIdx]; int gIdx = (int)pbtn.GetButtonData(); GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(gIdx); CityInfo cInfo = Informations.Instance.GetCityInfo(gInfo.city); if (cInfo.reservist - offset < 0 || cInfo.reservist - offset > cInfo.reservistMax) { slider.SetSlider(gInfo.soldierMax + gInfo.knightMax, gInfo.soldierCur + gInfo.knightCur); return; } cInfo.reservist -= offset; if (offset > 0) { if (gInfo.knightCur + offset >= gInfo.knightMax) { int sAdd = offset - (gInfo.knightMax - gInfo.knightCur); gInfo.knightCur = gInfo.knightMax; gInfo.soldierCur += sAdd; gInfo.soldierCur = Mathf.Clamp(gInfo.soldierCur, 0, gInfo.soldierMax); } else { gInfo.knightCur += offset; gInfo.knightCur = Mathf.Clamp(gInfo.knightCur, 0, gInfo.knightMax); } } else { if (gInfo.soldierCur + offset <= 0) { int kAdd = offset + gInfo.soldierCur; gInfo.soldierCur = 0; gInfo.knightCur += kAdd; gInfo.knightCur = Mathf.Clamp(gInfo.knightCur, 0, gInfo.knightMax); } else { gInfo.soldierCur += offset; gInfo.soldierCur = Mathf.Clamp(gInfo.soldierCur, 0, gInfo.soldierMax); } } giReservist.text = cInfo.reservist + "/" + cInfo.reservistMax; giSoldier.text = gInfo.soldierCur + "/" + gInfo.soldierMax; giCavalry.text = gInfo.knightCur + "/" + gInfo.knightMax; SetGeneralText(pbtn.gameObject, gIdx); }
void OnChangeArmsClickHandler() { state = 1; PushedButton pbtn = (PushedButton)gList[selectIdx]; int gIdx = (int)pbtn.GetButtonData(); UpdateChangeArms(gIdx); commandsLayout.SetAnim(MenuDisplayAnim.AnimType.OutToLeft); }
void OnArmsButtonHandler(object data) { int idx = (int)data; PushedButton pbtn = (PushedButton)gList[selectIdx]; int gIdx = (int)pbtn.GetButtonData(); Informations.Instance.GetGeneralInfo(gIdx).armsCur = 1 << idx; token.transform.position = new Vector3(token.transform.position.x, arms[idx].transform.position.y, token.transform.position.z); SetGeneralText(pbtn.gameObject, gIdx); }
void OnMaxConsClickHandler() { PushedButton pbtn = (PushedButton)gList[selectIdx]; int gIdx = (int)pbtn.GetButtonData(); GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(gIdx); CityInfo cInfo = Informations.Instance.GetCityInfo(gInfo.city); int num = (gInfo.soldierMax + gInfo.knightMax) - (gInfo.soldierCur + gInfo.knightCur); if (num == 0) { return; } if (cInfo.reservist >= num) { cInfo.reservist -= num; gInfo.soldierCur = gInfo.soldierMax; gInfo.knightCur = gInfo.knightMax; } else { if (cInfo.reservist > gInfo.knightMax - gInfo.knightCur) { int sAdd = cInfo.reservist - (gInfo.knightMax - gInfo.knightCur); gInfo.knightCur = gInfo.knightMax; gInfo.soldierCur += sAdd; gInfo.soldierCur = Mathf.Clamp(gInfo.soldierCur, 0, gInfo.soldierMax); } else { gInfo.knightCur += cInfo.reservist; } cInfo.reservist = 0; } giReservist.text = cInfo.reservist + "/" + cInfo.reservistMax; giSoldier.text = gInfo.soldierCur + "/" + gInfo.soldierMax; giCavalry.text = gInfo.knightCur + "/" + gInfo.knightMax; SetGeneralText(pbtn.gameObject, gIdx); slider.SetSlider(gInfo.soldierMax + gInfo.knightMax, gInfo.soldierCur + gInfo.knightCur); }
void AddGeneral(int gIdx, int pos) { GameObject go = (GameObject)Instantiate(itemPrefab); go.transform.parent = generalsListLayout.transform; go.transform.localPosition = new Vector3(gListPos.x, gListPos.y - pos * 30, gListPos.z); PushedButton pBtn = go.GetComponent <PushedButton>(); gList.Add(pBtn); pBtn.SetButtonData(gIdx); pBtn.SetButtonDownHandler(OnGeneralSelectedHandler); if (pos == 0) { selectIdx = 0; pBtn.SetButtonState(PushedButton.ButtonState.Down); } SetGeneralText(go, gIdx); }