FieldTaskView.cs 2.7 KB

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