12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using FairyGUI;
- using UI.Field;
- using UnityEngine;
- namespace GFGGame
- {
- public class FieldTaskView : BaseWindow
- {
- private UI_FieldTaskUI _ui;
- private List<FieldTaskCfg> _cfgs;
- private string[] difficulty = new string[] { "初级", "中级", "高级" };
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- _ui = UI_FieldTaskUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
- _ui.m_list.itemRenderer = ListItemRender;
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateList();
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- private void UpdateList()
- {
- _cfgs = FieldDataManager.Instance.GetTaskCfgs();
- _ui.m_list.numItems = _cfgs.Count;
- }
- private void ListItemRender(int index, GObject obj)
- {
- UI_ListItem item = UI_ListItem.Proxy(obj);
- FieldCfg cfg = FieldCfgArray.Instance.GetCfg(_cfgs[index].chapterId);
- item.m_txtDesc.text = string.Format("{0}难度挑战成功{1}轮", cfg.name, _cfgs[index].target);
- item.m_btnGet.m_txtTitle.text = string.Format("每周上限+{0}", _cfgs[index].addRewardLimit);
- item.m_btnGet.m_c1.selectedIndex = FieldDataManager.Instance.GetTaskState(_cfgs[index].id);
- if (item.m_btnGet.target.data == null)
- {
- item.m_btnGet.target.onClick.Add(OnBtnGetClick);
- }
- item.m_btnGet.target.data = _cfgs[index].id;
- UI_ListItem.ClearProxy();
- }
- private async void OnBtnGetClick(EventContext context)
- {
- int taskId = (int)(context.sender as GObject).data;
- int state = FieldDataManager.Instance.GetTaskState(taskId);
- if (state == 1)
- {
- bool result = await FieldSProxy.ReqFieldTaskBonus(taskId);
- if (result)
- {
- PromptController.Instance.ShowFloatTextPrompt("每周奖励上限提升");
- UpdateList();
- }
- }
- }
- }
- }
|