LeagueCreatView.cs 3.3 KB

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