123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System.Collections.Generic;
- using ET;
- using FairyGUI;
- using UI.Travel;
- using UnityEngine;
- namespace GFGGame
- {
- public class TravelDressupView : BaseWindow
- {
- private UI_TravelDressupUI _ui;
- private List<int> _selectTravelSuitIds = new List<int>();
- private List<int> _travelSuitIds = new List<int>();
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_TravelDressupUI.PACKAGE_NAME;
- _ui = UI_TravelDressupUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
- _ui.m_list.itemRenderer = RenderListItem;
- _ui.m_list.onClickItem.Add(OnListItemClick);
- _ui.m_btnCancle.onClick.Add(Hide);
- _ui.m_btnGo.onClick.Add(OnBtnGoClick);
- _ui.m_comDress0.target.onClick.Add(OnComDressClick0);
- _ui.m_comDress1.target.onClick.Add(OnComDressClick);
- _ui.m_comDress2.target.onClick.Add(OnComDressClick);
- _ui.m_comDress0.m_c1.selectedIndex = 2;
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateView();
- }
- protected override void OnHide()
- {
- base.OnHide();
- _selectTravelSuitIds.Clear();
- _travelSuitIds.Clear();
- if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
- _ui.m_comDress1.target.data = null;
- _ui.m_comDress2.target.data = null;
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- }
- private void UpdateView()
- {
- _travelSuitIds = new List<int>(DressUpMenuSuitDataManager.TravelSuitIDList.ToArray());
- for (int i = 0; i < _selectTravelSuitIds.Count; i++)
- {
- if (_travelSuitIds.IndexOf(_selectTravelSuitIds[i]) >= 0)
- {
- _travelSuitIds.Remove(_selectTravelSuitIds[i]);
- }
- }
- _ui.m_list.numItems = _travelSuitIds.Count;
- _ui.m_comDress1.m_c1.selectedIndex = _ui.m_comDress1.target.data == null ? 0 : 1;
- if (_ui.m_comDress1.target.data != null)
- {
- UpdateComDress(_ui.m_comDress1.target, (int)_ui.m_comDress1.target.data);
- }
- _ui.m_comDress2.m_c1.selectedIndex = _ui.m_comDress2.target.data == null ? 0 : 1;
- if (_ui.m_comDress2.target.data != null)
- {
- UpdateComDress(_ui.m_comDress2.target, (int)_ui.m_comDress2.target.data);
- }
- }
- private void RenderListItem(int index, GObject obj)
- {
- UI_ComDress item = UI_ComDress.Proxy(obj);
- item.m_c1.selectedIndex = 1;
- UI_ComDress.ProxyEnd();
- UpdateComDress(obj, _travelSuitIds[index]);
- }
- private void UpdateComDress(GObject obj, int travelSuitId)
- {
- TravelSuitCfg travelSuitCfg = TravelSuitCfgArray.Instance.GetCfg(travelSuitId);
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(travelSuitCfg.suitId);
- UI_ComDress item = UI_ComDress.Proxy(obj);
- item.m_txtName.text = suitCfg.name;
- item.m_loaDress.url = ResPathUtil.GetIconPath(suitCfg.res, "png");
- RarityIconController.UpdateRarityIcon(item.m_loaRarity, suitCfg.id, false, true);
- item.target.data = travelSuitCfg.id;
- UI_ComDress.ProxyEnd();
- }
- private void OnListItemClick(EventContext context)
- {
- if (_selectTravelSuitIds.Count >= 2)
- {
- PromptController.Instance.ShowFloatTextPrompt("行囊已满");
- return;
- }
- GObject obj = context.data as GObject;
- int travelSuitId = (int)obj.data;
- _selectTravelSuitIds.Add(travelSuitId);
- if (_ui.m_comDress1.target.data == null)
- {
- _ui.m_comDress1.target.data = travelSuitId;
- }
- else
- {
- _ui.m_comDress2.target.data = travelSuitId;
- }
- UpdateView();
- }
- private void OnComDressClick0()
- {
- PromptController.Instance.ShowFloatTextPrompt("必带服装不能取消");
- }
- private void OnComDressClick(EventContext context)
- {
- GObject obj = context.sender as GObject;
- if (obj.data == null)
- {
- PromptController.Instance.ShowFloatTextPrompt("请选择游历要带的服装");
- return;
- }
- int travelSuitId = (int)obj.data;
- _selectTravelSuitIds.Remove(travelSuitId);
- obj.data = null;
- UpdateView();
- }
- private async void OnBtnGoClick()
- {
- if (_selectTravelSuitIds.Count < 2)
- {
- PromptController.Instance.ShowFloatTextPrompt("需带齐3套服装才能出发");
- return;
- }
- bool result = await TravelSProxy.ReqGoTravel(_selectTravelSuitIds);
- if (result)
- {
- this.Hide();
- }
- }
- }
- }
|