LeagueCreatView.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 LeagueCreatView : BaseWindow
  10. {
  11. private UI_LeagueCreatUI _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_LeagueCreatUI.PACKAGE_NAME;
  25. _ui = UI_LeagueCreatUI.Create();
  26. this.viewCom = _ui.target;
  27. this.viewCom.Center();
  28. this.modal = true;
  29. isReturnWindow = true;
  30. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  31. _ui.m_btnClose.onClick.Add(Hide);
  32. _ui.m_btnCreat.onClick.Add(OnBtnCreatClick);
  33. _ui.m_listIcon.itemRenderer = RenderListItem;
  34. }
  35. protected override void AddEventListener()
  36. {
  37. base.AddEventListener();
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. _ui.m_listIcon.numItems = GlobalCfgArray.globalCfg.badgeResArr.Length;
  43. _ui.m_listIcon.selectedIndex = 0;
  44. _ui.m_txtName.text = "";
  45. ItemUtil.UpdateItemNeedNum(_ui.m_comCost, GlobalCfgArray.globalCfg.consumeCreateArr[0][0], GlobalCfgArray.globalCfg.consumeCreateArr[0][1]);
  46. }
  47. protected override void OnHide()
  48. {
  49. base.OnHide();
  50. }
  51. protected override void RemoveEventListener()
  52. {
  53. base.RemoveEventListener();
  54. }
  55. private async void OnBtnCreatClick()
  56. {
  57. string leagueName = _ui.m_txtName.text;
  58. if (string.IsNullOrEmpty(leagueName))
  59. {
  60. PromptController.Instance.ShowFloatTextPrompt("雅集名字不能为空");
  61. return;
  62. }
  63. if (leagueName.Length > GFGGame.GlobalConst.MaxNameLen)
  64. {
  65. PromptController.Instance.ShowFloatTextPrompt("雅集名字最多七个字");
  66. return;
  67. }
  68. if (!Regex.IsMatch(leagueName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线
  69. {
  70. PromptController.Instance.ShowFloatTextPrompt("雅集名字仅允许汉字、数字、下划线");
  71. return;
  72. }
  73. long hasCount = ItemDataManager.GetItemNum(GlobalCfgArray.globalCfg.consumeCreateArr[0][0]);
  74. long needCount = GlobalCfgArray.globalCfg.consumeCreateArr[0][1];
  75. if (hasCount < needCount)
  76. {
  77. ItemUtil.BuyCurrency(GlobalCfgArray.globalCfg.consumeCreateArr[0][0], needCount - hasCount);
  78. return;
  79. }
  80. bool result = await LeagueSproxy.ReqCreateLeague(leagueName, GlobalCfgArray.globalCfg.badgeResArr[_ui.m_listIcon.selectedIndex]);
  81. if (result)
  82. {
  83. ViewManager.Show<LeagueView>(null, true);
  84. }
  85. }
  86. private void RenderListItem(int index, GObject obj)
  87. {
  88. UI_ListIconItem item = UI_ListIconItem.Proxy(obj);
  89. item.m_loaIcon.url = ResPathUtil.GetLeagueIconPath(GlobalCfgArray.globalCfg.badgeResArr[index]);
  90. UI_ListIconItem.ProxyEnd();
  91. }
  92. }
  93. }