LeagueCreatView.cs 3.4 KB

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