//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, September 06, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
using Snxxz.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class RoleEquipWin : Window
|
{
|
#region 成员变量
|
[SerializeField] EquipBehaviours equipPlaces;
|
|
[SerializeField] RawImage m_Role;
|
[SerializeField] private Button m_OneKeySell;
|
[SerializeField] private Button m_Sort; //整理
|
[SerializeField] private Image m_SortImage;
|
[SerializeField] private Text m_TimeCountDown;
|
[SerializeField] private Text m_Copper;
|
[SerializeField] private Text m_Diamond;
|
|
#endregion
|
|
float sortableTime = 0f;
|
LogicUpdate sortableLogicUpdate;
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
private bool levelUpDirty;
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
m_OneKeySell.SetListener(OnClickOneKeySell);
|
m_Sort.SetListener(OnClickSortBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
levelUpDirty = false;
|
|
packModel.refreshItemCountEvent += OnPackUpdate;
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataUpdate;
|
WindowCenter.Instance.windowBeforeCloseEvent += BeforeWindowClose;
|
GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
|
|
UpdateMoney();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
var config = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
if (config != null && config.Type == 95)
|
{
|
packModel.SetJumpToOneKeySell(m_OneKeySell.transform);
|
}
|
}
|
|
protected override void OnPreClose()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
|
packModel.refreshItemCountEvent -= OnPackUpdate;
|
WindowCenter.Instance.windowBeforeCloseEvent -= BeforeWindowClose;
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataUpdate;
|
UI3DModelExhibition.Instance.StopShow();
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (sortableLogicUpdate != null)
|
{
|
sortableLogicUpdate.Destroy();
|
sortableLogicUpdate = null;
|
}
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
if (Time.time < sortableTime)
|
{
|
if (sortableLogicUpdate != null)
|
{
|
sortableLogicUpdate.Destroy();
|
}
|
sortableLogicUpdate = new LogicUpdate(1);
|
sortableLogicUpdate.Start(DisplaySortableCountDown);
|
}
|
else
|
{
|
DisplaySortableCountDown();
|
}
|
|
equipPlaces.DisplayAll();
|
UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
|
}
|
|
private void BeforeWindowClose(Window window)
|
{
|
if ("PetMatInfoWin" != window.name && "ItemInfoWin" != window.name) return;
|
|
UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
|
}
|
|
private void UpdateSecond()
|
{
|
if (levelUpDirty)
|
{
|
equipPlaces.DisplayAll();
|
UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
|
levelUpDirty = false;
|
}
|
}
|
|
void OnPackUpdate(PackType type, int index, int Id)
|
{
|
if (type != PackType.Equip)
|
{
|
return;
|
}
|
|
var equipPosition = EquipSet.ServerPlaceToClientPlace(index);
|
if (equipPosition.x != 0)
|
{
|
return;
|
}
|
|
var equipType = (RoleEquipType)equipPosition.y;
|
if (!equipPlaces.Contain(equipType))
|
{
|
return;
|
}
|
|
equipPlaces[equipType].Display(equipType);
|
UI3DModelExhibition.Instance.ShowPlayer(m_Role, PlayerDatas.Instance.baseData.Job);
|
}
|
|
private void OnPlayerDataUpdate(PlayerDataType type)
|
{
|
switch (type)
|
{
|
case PlayerDataType.LV:
|
levelUpDirty = true;
|
break;
|
case PlayerDataType.Gold:
|
case PlayerDataType.GoldPaper:
|
case PlayerDataType.Silver:
|
case PlayerDataType.ExAttr6:
|
UpdateMoney();
|
break;
|
}
|
}
|
|
void OnClickSortBtn()
|
{
|
ItemLogicUtility.Instance.ResetPack(PackType.Item);
|
sortableTime = Time.time + 5f;
|
|
if (sortableLogicUpdate != null)
|
{
|
sortableLogicUpdate.Destroy();
|
}
|
sortableLogicUpdate = new LogicUpdate(1);
|
sortableLogicUpdate.Start(DisplaySortableCountDown);
|
}
|
|
private void DisplaySortableCountDown()
|
{
|
var countDown = sortableTime - Time.time;
|
if (countDown <= 0f)
|
{
|
m_SortImage.SetSprite("SecondBtn1");
|
m_TimeCountDown.text = Language.Get("BagWin_Sortbtn_Text_1");
|
m_Sort.enabled = true;
|
|
if (sortableLogicUpdate != null)
|
{
|
sortableLogicUpdate.Destroy();
|
sortableLogicUpdate = null;
|
}
|
}
|
else
|
{
|
m_SortImage.SetSprite("BlackBtn");
|
m_TimeCountDown.text = Language.Get("BagWin_SortCDbtn_Text_1", Mathf.RoundToInt(countDown));
|
m_Sort.enabled = false;
|
}
|
}
|
|
void UpdateMoney()
|
{
|
m_Copper.text = PlayerDatas.Instance.baseData.diamond.ToString();
|
m_Diamond.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(PlayerDatas.Instance.baseData.allCopper);
|
}
|
|
private void OnClickOneKeySell()
|
{
|
if (!ItemLogicUtility.Instance.isPackResetOk)
|
{
|
return;
|
}
|
|
if (ItemLogicUtility.Instance.GetSellItemList().Count > 0)
|
{
|
WindowCenter.Instance.Open<OneKeySellWin>();
|
}
|
else
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("KnapS129"));
|
}
|
|
}
|
|
[System.Serializable]
|
public class EquipBehaviours
|
{
|
public EquipPlaceCell wing;
|
public EquipPlaceCell guard1;
|
public EquipPlaceCell guard2;
|
public EquipPlaceCell peerlessWeapon1;
|
public EquipPlaceCell peerlessWeapon2;
|
|
public EquipPlaceCell this[RoleEquipType type] {
|
get {
|
switch (type)
|
{
|
case RoleEquipType.Wing:
|
return wing;
|
case RoleEquipType.Guard1:
|
return guard1;
|
case RoleEquipType.Guard2:
|
return guard2;
|
case RoleEquipType.PeerlessWeapon1:
|
return peerlessWeapon1;
|
case RoleEquipType.PeerlessWeapon2:
|
return peerlessWeapon2;
|
default:
|
return null;
|
}
|
}
|
}
|
|
public bool Contain(RoleEquipType type)
|
{
|
return type == RoleEquipType.Wing
|
|| type == RoleEquipType.Guard1 ||
|
type == RoleEquipType.Guard2 ||
|
type == RoleEquipType.PeerlessWeapon1 ||
|
type == RoleEquipType.PeerlessWeapon2;
|
}
|
|
public void Display(RoleEquipType type)
|
{
|
this[type].Display(type);
|
}
|
|
public void DisplayAll()
|
{
|
wing.Display(RoleEquipType.Wing);
|
guard1.Display(RoleEquipType.Guard1);
|
guard2.Display(RoleEquipType.Guard2);
|
peerlessWeapon1.Display(RoleEquipType.PeerlessWeapon1);
|
peerlessWeapon2.Display(RoleEquipType.PeerlessWeapon2);
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|