LeagueChangeNameView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System.Text.RegularExpressions;
  2. using ET;
  3. using FairyGUI;
  4. using UI.League;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. //修改联盟名称、徽章
  9. public class LeagueChangeNameView : BaseWindow
  10. {
  11. private UI_LeagueChangeNameUI _ui;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. packageName = UI_LeagueChangeNameUI.PACKAGE_NAME;
  25. _ui = UI_LeagueChangeNameUI.Create();
  26. this.viewCom = _ui.target;
  27. isfullScreen = true;
  28. // _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  29. _ui.m_c1.onChanged.Add(UpdateView);
  30. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  31. _ui.m_listIcon.itemRenderer = RenderListItem;
  32. }
  33. protected override void AddEventListener()
  34. {
  35. base.AddEventListener();
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. _ui.m_c1.selectedIndex = 0;
  41. _ui.m_listIcon.numItems = GlobalCfgArray.globalCfg.badgeResArr.Length;
  42. UpdateView();
  43. }
  44. protected override void OnHide()
  45. {
  46. base.OnHide();
  47. }
  48. protected override void RemoveEventListener()
  49. {
  50. base.RemoveEventListener();
  51. }
  52. private void UpdateView()
  53. {
  54. _ui.m_txtName.text = "";
  55. if (_ui.m_listIcon.numItems > 0)
  56. {
  57. _ui.m_listIcon.selectedIndex = 0;
  58. _ui.m_listIcon.ScrollToView(0);
  59. }
  60. if (_ui.m_c1.selectedIndex == 0)
  61. {
  62. ItemUtil.UpdateItemNeedNum(_ui.m_comCost, GlobalCfgArray.globalCfg.consumeChangeBadgeArr[0][0], GlobalCfgArray.globalCfg.consumeChangeBadgeArr[0][1]);
  63. }
  64. else
  65. {
  66. ItemUtil.UpdateItemNeedNum(_ui.m_comCost, GlobalCfgArray.globalCfg.consumeChangeNameArr[0][0], GlobalCfgArray.globalCfg.consumeChangeNameArr[0][1]);
  67. }
  68. }
  69. private void RenderListItem(int index, GObject obj)
  70. {
  71. UI_ListIconItem item = UI_ListIconItem.Proxy(obj);
  72. item.m_loaIcon.url = ResPathUtil.GetLeagueIconPath(GlobalCfgArray.globalCfg.badgeResArr[index]);
  73. UI_ListIconItem.ProxyEnd();
  74. }
  75. private void OnBtnChangeClick()
  76. {
  77. if (LeagueDataManager.Instance.LeagueData.LeagueMemberDatas[RoleDataManager.roleId].Pos != LeaguePos.Owner)
  78. {
  79. PromptController.Instance.ShowFloatTextPrompt("权限不足");
  80. return;
  81. }
  82. if (_ui.m_c1.selectedIndex == 0)//改徽章
  83. {
  84. int needCount = GlobalCfgArray.globalCfg.consumeChangeBadgeArr[0][1];
  85. long hasCount = ItemDataManager.GetItemNum(GlobalCfgArray.globalCfg.consumeChangeBadgeArr[0][0]);
  86. if (needCount > hasCount)
  87. {
  88. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  89. return;
  90. }
  91. LeagueSproxy.ReqChangeLeagueNameOrIcon(2, GlobalCfgArray.globalCfg.badgeResArr[_ui.m_listIcon.selectedIndex]).Coroutine();
  92. }
  93. else//改联盟名称
  94. {
  95. string leagueName = _ui.m_txtName.text;
  96. if (string.IsNullOrEmpty(leagueName))
  97. {
  98. PromptController.Instance.ShowFloatTextPrompt("雅集名字不能为空");
  99. return;
  100. }
  101. if (leagueName.Length > GFGGame.GlobalConst.MaxNameLen)
  102. {
  103. PromptController.Instance.ShowFloatTextPrompt("雅集名字最多七个字");
  104. return;
  105. }
  106. if (!Regex.IsMatch(leagueName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线
  107. {
  108. PromptController.Instance.ShowFloatTextPrompt("雅集名字仅允许汉字、数字、下划线");
  109. return;
  110. }
  111. int needCount = GlobalCfgArray.globalCfg.consumeChangeNameArr[0][1];
  112. long hasCount = ItemDataManager.GetItemNum(GlobalCfgArray.globalCfg.consumeChangeNameArr[0][0]);
  113. if (needCount > hasCount)
  114. {
  115. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  116. return;
  117. }
  118. LeagueSproxy.ReqChangeLeagueNameOrIcon(1, leagueName).Coroutine();
  119. }
  120. }
  121. }
  122. }