FieldTaskView.cs 2.5 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. item.m_txtDesc.text = string.Format("通关主线第{0}章", _cfgs[index].target);
  51. item.m_btnGet.m_txtTitle.text = string.Format("每周上限+{0}", _cfgs[index].addRewardLimit);
  52. item.m_btnGet.m_c1.selectedIndex = FieldDataManager.Instance.GetTaskState(_cfgs[index].id);
  53. if (item.m_btnGet.target.data == null)
  54. {
  55. item.m_btnGet.target.onClick.Add(OnBtnGetClick);
  56. }
  57. item.m_btnGet.target.data = _cfgs[index].id;
  58. UI_ListItem.ClearProxy();
  59. }
  60. private async void OnBtnGetClick(EventContext context)
  61. {
  62. int taskId = (int)(context.sender as GObject).data;
  63. int state = FieldDataManager.Instance.GetTaskState(taskId);
  64. if (state == 1)
  65. {
  66. bool result = await FieldSProxy.ReqFieldTaskBonus(taskId);
  67. if (result)
  68. {
  69. PromptController.Instance.ShowFloatTextPrompt("每周奖励上限提升");
  70. UpdateList();
  71. }
  72. }
  73. }
  74. }
  75. }