|
|
@@ -13,6 +13,8 @@ public class MeView : MonoBehaviour, MenuBackInterface
|
|
|
{
|
|
|
PersistenHandler.ins?.menuBackCtr.views.Add(this);
|
|
|
|
|
|
+ meUserInfo = new MeUserInfo(this);
|
|
|
+
|
|
|
this.transform.Find("AvatarFrame").GetComponent<Button>().onClick.AddListener(ShowAvatarSelectView);
|
|
|
|
|
|
RenderAfterSave();
|
|
|
@@ -24,48 +26,48 @@ public class MeView : MonoBehaviour, MenuBackInterface
|
|
|
}
|
|
|
|
|
|
public bool OnMenuBack() {
|
|
|
- Destroy(gameObject);
|
|
|
- return true;
|
|
|
+ if (!meUserInfo.ShowModalForSave()) {
|
|
|
+ ExcuteLogic_Destroy();
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Back() {
|
|
|
AudioMgr.ins.PlayBtn();
|
|
|
- Destroy(this.gameObject);
|
|
|
+ if (!meUserInfo.ShowModalForSave()) {
|
|
|
+ ExcuteLogic_Destroy();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExcuteLogic_Destroy() {
|
|
|
+ Destroy(gameObject);
|
|
|
}
|
|
|
|
|
|
- JCUnityLib.Throttler throttlerSave = new JCUnityLib.Throttler(2000);
|
|
|
public void Save()
|
|
|
{
|
|
|
AudioMgr.ins.PlayBtn();
|
|
|
- string[] texts = new string[7];
|
|
|
- for (int i = 0; i < inputs.transform.childCount; i++)
|
|
|
- {
|
|
|
- if (i == 3) {
|
|
|
- Transform toggleGroup = inputs.transform.GetChild(i).Find("ToggleGroup");
|
|
|
- texts[i] = toggleGroup.GetChild(0).GetComponent<Toggle>().isOn ? "1" : "2";
|
|
|
- continue;
|
|
|
- }
|
|
|
- InputField inputField = GetInputField(inputs.transform.GetChild(i));
|
|
|
- if (i == 1 && inputField.text.Trim().Length == 0) {
|
|
|
+ ExcuteLogic_SaveUserInfo(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ JCUnityLib.Throttler throttlerSave = new JCUnityLib.Throttler(3000);
|
|
|
+ private bool ExcuteLogic_SaveUserInfo(bool useThrottler) {
|
|
|
+ System.Func<bool> interceptor = delegate() {
|
|
|
+ if (string.IsNullOrEmpty(meUserInfo.nickname)) {
|
|
|
PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("昵称不能为空"));
|
|
|
- return;
|
|
|
+ return true;
|
|
|
}
|
|
|
- texts[i] = inputField.text.Trim();
|
|
|
- }
|
|
|
- if (throttlerSave.CanPass() == false) {
|
|
|
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
|
|
|
- return;
|
|
|
- }
|
|
|
- LoginMgr.myUserInfo.nickname = texts[1];
|
|
|
- LoginMgr.myUserInfo.phone = texts[2];
|
|
|
- LoginMgr.myUserInfo.gender = int.Parse(texts[3]);
|
|
|
- LoginMgr.myUserInfo.birthday = texts[4];
|
|
|
- LoginMgr.myUserInfo.country = countryCode;
|
|
|
- LoginMgr.myUserInfo.state = stateCode;
|
|
|
- LoginMgr.myUserInfo.city = cityCode;
|
|
|
- LoginMgr.myUserInfo.Save();
|
|
|
+ if (useThrottler && throttlerSave.CanPass() == false) {
|
|
|
+ PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ if (!meUserInfo.Save(interceptor)) return false;
|
|
|
PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("保存成功"));
|
|
|
RenderAfterSave();
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
InputField GetInputField(Transform transform)
|
|
|
@@ -201,4 +203,90 @@ public class MeView : MonoBehaviour, MenuBackInterface
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
+ MeUserInfo meUserInfo;
|
|
|
+ private class MeUserInfo {
|
|
|
+ private MeView m_context;
|
|
|
+ public MeUserInfo(MeView context) {
|
|
|
+ m_context = context;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region UserInfo关联属性
|
|
|
+ public string nickname;
|
|
|
+ public int gender;
|
|
|
+ public string phone;
|
|
|
+ public string birthday;
|
|
|
+ public string country;
|
|
|
+ public string state;
|
|
|
+ public string city;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ private void RefreshValues() {
|
|
|
+ //从组件中读取值
|
|
|
+ string[] texts = new string[7];
|
|
|
+ for (int i = 0; i < m_context.inputs.transform.childCount; i++)
|
|
|
+ {
|
|
|
+ if (i == 3) {
|
|
|
+ Transform toggleGroup = m_context.inputs.transform.GetChild(i).Find("ToggleGroup");
|
|
|
+ texts[i] = toggleGroup.GetChild(0).GetComponent<Toggle>().isOn ? "1" : "2";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ InputField inputField = m_context.GetInputField(m_context.inputs.transform.GetChild(i));
|
|
|
+ texts[i] = inputField.text.Trim();
|
|
|
+ }
|
|
|
+ //缓存读取到的值
|
|
|
+ this.nickname = texts[1];
|
|
|
+ this.phone = texts[2];
|
|
|
+ this.gender = int.Parse(texts[3]);
|
|
|
+ this.birthday = texts[4];
|
|
|
+ this.country = m_context.countryCode;
|
|
|
+ this.state = m_context.stateCode;
|
|
|
+ this.city = m_context.cityCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool Save(System.Func<bool> interceptor = null) {
|
|
|
+ RefreshValues();
|
|
|
+ if (interceptor != null) {
|
|
|
+ if (interceptor.Invoke()) return false;
|
|
|
+ }
|
|
|
+ LoginMgr.myUserInfo.nickname = this.nickname;
|
|
|
+ LoginMgr.myUserInfo.phone = this.phone;
|
|
|
+ LoginMgr.myUserInfo.gender = this.gender;
|
|
|
+ LoginMgr.myUserInfo.birthday = this.birthday;
|
|
|
+ LoginMgr.myUserInfo.country = this.country;
|
|
|
+ LoginMgr.myUserInfo.state = this.state;
|
|
|
+ LoginMgr.myUserInfo.city = this.city;
|
|
|
+ LoginMgr.myUserInfo.Save();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ private bool IsEqualOrigin() {
|
|
|
+ return
|
|
|
+ LoginMgr.myUserInfo.nickname == this.nickname &&
|
|
|
+ LoginMgr.myUserInfo.phone == this.phone &&
|
|
|
+ LoginMgr.myUserInfo.gender == this.gender &&
|
|
|
+ LoginMgr.myUserInfo.birthday == this.birthday &&
|
|
|
+ LoginMgr.myUserInfo.country == this.country &&
|
|
|
+ LoginMgr.myUserInfo.state == this.state &&
|
|
|
+ LoginMgr.myUserInfo.city == this.city;
|
|
|
+ }
|
|
|
+ ModalView modalViewForSave;
|
|
|
+ public bool ShowModalForSave() {
|
|
|
+ RefreshValues();
|
|
|
+ if (IsEqualOrigin()) return false;
|
|
|
+ if (!modalViewForSave) {
|
|
|
+ modalViewForSave = ModalView.Show();
|
|
|
+ modalViewForSave.textKey= "me_askSave";
|
|
|
+ modalViewForSave.onAgreeTextKey = "common_yes";
|
|
|
+ modalViewForSave.onRejectTextKey = "common_no";
|
|
|
+ modalViewForSave.onAgree = () => {
|
|
|
+ bool res = m_context.ExcuteLogic_SaveUserInfo(false);
|
|
|
+ if (res) {
|
|
|
+ m_context.ExcuteLogic_Destroy();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ modalViewForSave.onReject = () => m_context.ExcuteLogic_Destroy();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|