FieldTaskView.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using FairyGUI;
  4. using UI.Field;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class FieldTaskView : BaseWindow
  9. {
  10. private UI_FieldTaskUI _ui;
  11. private List<FieldTaskCfg> _cfgs;
  12. private string[] difficulty = new string[] { "初级", "中级", "高级" };
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. _ui = UI_FieldTaskUI.Create();
  26. this.viewCom = _ui.target;
  27. this.viewCom.Center();
  28. this.modal = true;
  29. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  30. _ui.m_list.itemRenderer = ListItemRender;
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. UpdateList();
  36. }
  37. protected override void OnHide()
  38. {
  39. base.OnHide();
  40. }
  41. private void UpdateList()
  42. {
  43. _cfgs = FieldDataManager.Instance.GetTaskCfgs();
  44. _ui.m_list.numItems = _cfgs.Count;
  45. }
  46. private void ListItemRender(int index, GObject obj)
  47. {
  48. UI_ListItem item = UI_ListItem.Proxy(obj);
  49. FieldCfg cfg = FieldCfgArray.Instance.GetCfg(_cfgs[index].chapterId);
  50. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_cfgs[index].chapterId);
  51. item.m_txtDesc.text = string.Format("通关主线第{0}章", chapterCfg.order);
  52. item.m_btnGet.m_txtTitle.text = string.Format("每周上限+{0}", _cfgs[index].addRewardLimit);
  53. item.m_btnGet.m_c1.selectedIndex = FieldDataManager.Instance.GetTaskState(_cfgs[index].id);
  54. if (item.m_btnGet.target.data == null)
  55. {
  56. item.m_btnGet.target.onClick.Add(OnBtnGetClick);
  57. }
  58. item.m_btnGet.target.data = _cfgs[index].id;
  59. UI_ListItem.ClearProxy();
  60. }
  61. private async void OnBtnGetClick(EventContext context)
  62. {
  63. int taskId = (int)(context.sender as GObject).data;
  64. int state = FieldDataManager.Instance.GetTaskState(taskId);
  65. if (state == 1)
  66. {
  67. bool result = await FieldSProxy.ReqFieldTaskBonus(taskId);
  68. if (result)
  69. {
  70. PromptController.Instance.ShowFloatTextPrompt("每周奖励上限提升");
  71. UpdateList();
  72. }
  73. }
  74. }
  75. }
  76. }