FieldTaskView.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. base.Dispose();
  16. }
  17. protected override void OnInit()
  18. {
  19. base.OnInit();
  20. _ui = UI_FieldTaskUI.Create();
  21. this.viewCom = _ui.target;
  22. this.viewCom.Center();
  23. this.modal = true;
  24. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  25. _ui.m_list.itemRenderer = ListItemRender;
  26. }
  27. protected override void OnShown()
  28. {
  29. base.OnShown();
  30. UpdateList();
  31. }
  32. protected override void OnHide()
  33. {
  34. base.OnHide();
  35. }
  36. private void UpdateList()
  37. {
  38. _cfgs = FieldDataManager.Instance.GetTaskCfgs();
  39. _ui.m_list.numItems = _cfgs.Count;
  40. }
  41. private void ListItemRender(int index, GObject obj)
  42. {
  43. UI_ListItem item = UI_ListItem.Proxy(obj);
  44. FieldCfg cfg = FieldCfgArray.Instance.GetCfg(_cfgs[index].chapterId);
  45. item.m_txtDesc.text = string.Format("{0}难度挑战成功{1}轮", cfg.name, _cfgs[index].target);
  46. item.m_btnGet.m_txtTitle.text = string.Format("每周上限+{0}", _cfgs[index].addRewardLimit);
  47. item.m_btnGet.m_c1.selectedIndex = FieldDataManager.Instance.GetTaskState(_cfgs[index].id);
  48. if (item.m_btnGet.target.data == null)
  49. {
  50. item.m_btnGet.target.onClick.Add(OnBtnGetClick);
  51. }
  52. item.m_btnGet.target.data = _cfgs[index].id;
  53. UI_ListItem.ClearProxy();
  54. }
  55. private async void OnBtnGetClick(EventContext context)
  56. {
  57. int taskId = (int)(context.sender as GObject).data;
  58. int state = FieldDataManager.Instance.GetTaskState(taskId);
  59. if (state == 1)
  60. {
  61. bool result = await FieldSProxy.ReqFieldTaskBonus(taskId);
  62. if (result)
  63. {
  64. PromptController.Instance.ShowFloatTextPrompt("每周奖励上限提升");
  65. UpdateList();
  66. }
  67. }
  68. }
  69. }
  70. }