415 lines
14 KiB
C#
415 lines
14 KiB
C#
using UnityEngine;
|
||
using System.Collections;
|
||
using UnityEngine.UI;
|
||
using Games.Item;
|
||
using GCGame.Table;
|
||
using System.Collections.Generic;
|
||
using Games.Events;
|
||
using Module.Log;
|
||
|
||
public class AdvanceItemPanelCtr : MonoBehaviour {
|
||
|
||
public AdvancePanelCtr advancePanelCtr;
|
||
public Image itemIcon;
|
||
public Text needCostValue;
|
||
public Text curOwnValue;
|
||
public Toggle autoAdvanceToggle;
|
||
public GameObject canAdvanceRedIcon;
|
||
|
||
public Image quality;
|
||
private int type; //当前进阶类型
|
||
|
||
//private int curOwnItemCount = 0;
|
||
private int curAdvanceNeedCostCount = 0;
|
||
|
||
private int curNeedCostItemId = -1;
|
||
private int curNeedCostGoodItemId = -1;
|
||
[HideInInspector]
|
||
public int curNeedCostItemPrice = -1;
|
||
[HideInInspector]
|
||
public int lackItemCount;
|
||
//private GameItemContainer bagPack;
|
||
private int curAdvanceLevel = -1;
|
||
private int curAdvanceGrade = -1;
|
||
|
||
public GameObject _GainBtn;
|
||
|
||
public Text btnDesc;
|
||
|
||
private void Awake()
|
||
{
|
||
Hashtable calbackMoveparam1 = new Hashtable();
|
||
calbackMoveparam1["name"] = "OnItemUsed";
|
||
MessageEventCallBack fun1 = OnItemUsed;
|
||
calbackMoveparam1.Add("callFun", fun1);
|
||
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FRESHSAMEUSETIP, calbackMoveparam1);
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FRESHSAMEUSETIP, "OnItemUsed");
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
_IsConfirmConsumeMoney = false;
|
||
_IsAutoAdvance = false;
|
||
}
|
||
private int _AdvanceRemainCount = 0;
|
||
public void InitItemPanel(AdvanceInfo info)
|
||
{
|
||
_IsOutsideSetting = false;
|
||
type = info.type;
|
||
_AdvanceRemainCount = info._RemainAdvanceItemCount;
|
||
Tab_AdvanceBase advanceBase = TableManager.GetAdvanceBaseByID(info.baseId + 1, 0); //本级升下级 读取下级的消耗
|
||
if(advanceBase == null || (advanceBase.Id - advanceBase.Level) / 1000 - 1 != type)
|
||
{
|
||
this.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
//var bagPack = GameManager.gameManager.PlayerDataPool.GetItemContainer(GameItemContainer.Type.TYPE_BACKPACK);
|
||
//if (bagPack == null)
|
||
// return;
|
||
//curOwnValue.text = bagPack.GetItemCountByDataId(advanceBase.AdvanceCostItemId) + "";
|
||
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(advanceBase.AdvanceCostItemId, 0);
|
||
if(commonItem == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
//设置图片
|
||
LoadAssetBundle.Instance.SetImageSprite(itemIcon, commonItem.Icon);
|
||
LoadAssetBundle.Instance.SetImageSprite(quality, GCGame.Utils.GetItemQualityFrame(commonItem.Quality));
|
||
if (commonItem.QualityEffect > 0)
|
||
{
|
||
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, itemIcon.transform);
|
||
}
|
||
else
|
||
{
|
||
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, itemIcon.transform);
|
||
}
|
||
|
||
curNeedCostItemId = advanceBase.AdvanceCostItemId;
|
||
|
||
needCostValue.text = advanceBase.AdvanceCostItemNum.ToString();
|
||
curAdvanceNeedCostCount = advanceBase.AdvanceCostItemNum;
|
||
curAdvanceLevel = advanceBase.Level; //记录当前的level
|
||
curAdvanceGrade = advanceBase.Grade; //记录当前的Grade
|
||
RefreshOwnItemInfo();
|
||
GetCostItemGoodInfo();
|
||
}
|
||
|
||
public void RefreshOwnItemInfo()
|
||
{
|
||
//bagPack = GameManager.gameManager.PlayerDataPool.GetItemContainer(GameItemContainer.Type.TYPE_BACKPACK);
|
||
//if (bagPack == null)
|
||
// return;
|
||
//curOwnItemCount = bagPack.GetItemCountByDataId(curNeedCostItemId);
|
||
curOwnValue.text = _AdvanceRemainCount >= curAdvanceNeedCostCount ? _AdvanceRemainCount.ToString() : StrDictionary.GetClientDictionaryString("#{1997}", _AdvanceRemainCount.ToString());
|
||
|
||
_GainBtn.gameObject.SetActive(_AdvanceRemainCount < curAdvanceNeedCostCount);
|
||
}
|
||
|
||
public void OnGetBtnClick()
|
||
{
|
||
ItemTooltipsLogic.ShowItemTooltip(curNeedCostItemId, ItemTooltipsLogic.ShowType.GetPath, _GainBtn.transform.position);
|
||
}
|
||
|
||
public void RefreshNeedCostPanel(int baseId)
|
||
{
|
||
Tab_AdvanceBase advanceBase = TableManager.GetAdvanceBaseByID(baseId, 0);
|
||
if(advanceBase == null)
|
||
{
|
||
return;
|
||
}
|
||
curAdvanceNeedCostCount = advanceBase.AdvanceCostItemNum;
|
||
needCostValue.text = advanceBase.AdvanceCostItemNum.ToString();
|
||
}
|
||
|
||
private bool _IsOutsideSetting = false;
|
||
public void SetOutsideSetting()
|
||
{
|
||
_IsOutsideSetting = true;
|
||
}
|
||
|
||
public void OnToggleClick(bool isOn)
|
||
{
|
||
if(isOn)
|
||
{
|
||
if(!_IsOutsideSetting)
|
||
{
|
||
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{42693}"), "",
|
||
delegate ()
|
||
{
|
||
UIManager.CloseUI(UIInfo.MessageBox);
|
||
OnAdvanceBtnClick();
|
||
},
|
||
delegate ()
|
||
{
|
||
autoAdvanceToggle.isOn = false;
|
||
UIManager.CloseUI(UIInfo.MessageBox);
|
||
});
|
||
}
|
||
}else
|
||
{
|
||
if(isOnAdvance)
|
||
{
|
||
isOnAdvance = false;
|
||
SetAdvanceBtnState();
|
||
}
|
||
}
|
||
}
|
||
|
||
//获取当前升阶所需物品价格
|
||
public void GetCostItemGoodInfo()
|
||
{
|
||
foreach (var item in TableManager.GetYuanBaoShop().Values)
|
||
{
|
||
if (item.ItemID == curNeedCostItemId
|
||
&& item.MoneyType == (int)MONEYTYPE.MONEYTYPE_YUANBAO)
|
||
{
|
||
curNeedCostGoodItemId = item.Id;
|
||
curNeedCostItemPrice = item.PriceWeek;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
//获取当前进阶的等级,刷新界面的物品数量
|
||
public void RefreshPanelInfo(int baseId, int curWish, int remainCount)
|
||
{
|
||
_AdvanceRemainCount = remainCount;
|
||
Tab_AdvanceBase advanceBase = TableManager.GetAdvanceBaseByID(baseId + 1, 0); //需要读取的是下一级的消耗 所以这边加1
|
||
if(advanceBase == null)
|
||
{
|
||
return;
|
||
}
|
||
//bagPack = GameManager.gameManager.PlayerDataPool.GetItemContainer(GameItemContainer.Type.TYPE_BACKPACK);
|
||
//if (bagPack == null)
|
||
// return;
|
||
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(advanceBase.AdvanceCostItemId, 0);
|
||
if (commonItem == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
curNeedCostItemId = advanceBase.AdvanceCostItemId;
|
||
//curOwnItemCount = bagPack.GetItemCountByDataId(advanceBase.AdvanceCostItemId);
|
||
curAdvanceNeedCostCount = advanceBase.AdvanceCostItemNum;
|
||
curOwnValue.text = _AdvanceRemainCount >= curAdvanceNeedCostCount ? _AdvanceRemainCount.ToString() : StrDictionary.GetClientDictionaryString("#{1997}", _AdvanceRemainCount.ToString());
|
||
|
||
Tab_AdvanceBase curAdvanceBase = TableManager.GetAdvanceBaseByID(baseId, 0); //需要读取的是下一级的消耗 所以这边加1
|
||
if (advanceBase == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (curAdvanceBase.Level > curAdvanceLevel)
|
||
{
|
||
curAdvanceLevel = curAdvanceBase.Level;
|
||
}
|
||
|
||
if (curAdvanceBase.Grade > curAdvanceGrade) //等阶提升的时候关闭当前的自动进阶
|
||
{
|
||
isOnAdvance = false;
|
||
curAdvanceGrade = curAdvanceBase.Grade;
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (isOnAdvance)
|
||
{
|
||
Invoke("ReqAdvancePacket", 0.2f);
|
||
isOnAdvance = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
public bool isOnAdvance = false; //正在进阶
|
||
|
||
private bool ClickStop = false; //当按钮是停止的时候,点击不会再发协议。
|
||
public void SetAdvanceBtnState()
|
||
{
|
||
if(isOnAdvance)
|
||
{
|
||
ClickStop = true;
|
||
btnDesc.text = StrDictionary.GetClientDictionaryString("#{43011}");
|
||
|
||
AskForAdvance();
|
||
}
|
||
else
|
||
{
|
||
ClickStop = false;
|
||
autoAdvanceToggle.isOn = false;
|
||
btnDesc.text = StrDictionary.GetClientDictionaryString("#{43010}");
|
||
}
|
||
}
|
||
|
||
public void ReqAdvancePacket()
|
||
{
|
||
if (isOnAdvance)
|
||
{
|
||
AskForAdvance();
|
||
}
|
||
}
|
||
|
||
public void OnAdvanceBtnClick()
|
||
{
|
||
if (autoAdvanceToggle.isOn)
|
||
{
|
||
isOnAdvance = !isOnAdvance;
|
||
SetAdvanceBtnState();
|
||
}
|
||
else
|
||
{
|
||
if (_AdvanceRemainCount < curAdvanceNeedCostCount)
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42674}"));
|
||
return;
|
||
}
|
||
AskForAdvance();
|
||
}
|
||
//ShowCanAdvanceOrNotRedIcon(false); //点击之后隐藏可以升级的RedIcon
|
||
}
|
||
|
||
// 控制红点状态
|
||
public void SetRedTips(bool isShow)
|
||
{
|
||
// 优化:不同时才更新
|
||
if(canAdvanceRedIcon.activeSelf != isShow)
|
||
{
|
||
canAdvanceRedIcon.SetActive(isShow);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检测并更新进阶界面红点信息(不包括菜单)
|
||
/// </summary>
|
||
/// <returns>
|
||
/// true:有红点信息
|
||
/// fasle: 无红点信息,或存在错误
|
||
/// </returns>
|
||
public bool UpdateRedPoint()
|
||
{
|
||
if (advancePanelCtr == null)
|
||
{
|
||
LogModule.ErrorLog("Can't get AdvancePanelCtr.Instance, can't update red point tips !!!");
|
||
return false;
|
||
}
|
||
|
||
if(AdvancePanelCtr.Instance == null)
|
||
{
|
||
advancePanelCtr.PreInit();
|
||
}
|
||
|
||
var advanceBase = TableManager.GetAdvanceBaseByID(AdvancePanelCtr.Instance.CurAdvanceBaseId, 0);
|
||
if (advanceBase == null)
|
||
return false;
|
||
|
||
if (advanceBase.DayDecWishValuePercent > 0)
|
||
{
|
||
SetRedTips(false);
|
||
return false;
|
||
}
|
||
|
||
// 未到达最大等级 且 (物品足够 或 金钱足够代替物品)
|
||
if (advancePanelCtr.CurAdvanceLevel < advancePanelCtr.MaxAdvanceBase.Level)
|
||
{
|
||
int lackItemCount = curAdvanceNeedCostCount - _AdvanceRemainCount;
|
||
//bool moneyEnought = GameManager.gameManager.PlayerDataPool.Money.GetMoneyByType(MONEYTYPE.MONEYTYPE_YUANBAO) >= lackItemCount * curNeedCostItemPrice;
|
||
if (lackItemCount <= 0)
|
||
{
|
||
SetRedTips(true);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
if (AdvanceMountPanelCtr.Instance != null)
|
||
{
|
||
AdvanceMountPanelCtr.Instance.UpdateAdvanceRedPoint();
|
||
}
|
||
SetRedTips(false);
|
||
return false;
|
||
}
|
||
|
||
public void OnItemUsed(Hashtable addParam = null, Hashtable sendParam = null)
|
||
{
|
||
UpdateRedPoint();
|
||
}
|
||
|
||
private bool _IsAutoAdvance = false; //道具足够的时候是false,道具不足需要消耗金钱的时候确定之后置为true
|
||
private bool _IsConfirmConsumeMoney = false; // shigfo
|
||
public void AskForAdvance()
|
||
{
|
||
CG_REQ_ADVANCE req = (CG_REQ_ADVANCE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ADVANCE);
|
||
if (_AdvanceRemainCount >= curAdvanceNeedCostCount)
|
||
{
|
||
req.SetOptionType((int)AdvanceBase.ReqType.ADVANCE_OPTION);
|
||
req.SetType(type);
|
||
req.SetParam1(_IsAutoAdvance ? 1 : 0);
|
||
req.SetParam2(0);
|
||
req.SendPacket();
|
||
}
|
||
else
|
||
{
|
||
if(!_IsConfirmConsumeMoney)
|
||
{
|
||
ClickStop = false;
|
||
autoAdvanceToggle.isOn = false;
|
||
|
||
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{42723}"), "", delegate ()
|
||
{
|
||
if (!_IsAutoAdvance)
|
||
_IsAutoAdvance = true;
|
||
_IsConfirmConsumeMoney = true;
|
||
_IsOutsideSetting = true;
|
||
ClickStop = true;
|
||
autoAdvanceToggle.isOn = true;
|
||
isOnAdvance = true;
|
||
SetAdvanceBtnState();
|
||
UIManager.CloseUI(UIInfo.MessageBox);
|
||
}, delegate ()
|
||
{
|
||
if (_IsAutoAdvance)
|
||
_IsAutoAdvance = false;
|
||
ClickStop = false;
|
||
autoAdvanceToggle.isOn = false;
|
||
isOnAdvance = false;
|
||
SetAdvanceBtnState();
|
||
UIManager.CloseUI(UIInfo.MessageBox);
|
||
});
|
||
}else
|
||
{
|
||
//判断当前金钱是否足够
|
||
if (isOnAdvance)
|
||
{
|
||
int lackItemCount = curAdvanceNeedCostCount - _AdvanceRemainCount;
|
||
if (JudgeMoneyLogic.IsMoneyEnoughWhenSwitch(lackItemCount * curNeedCostItemPrice))
|
||
{
|
||
req.SetOptionType((int)AdvanceBase.ReqType.ADVANCE_OPTION);
|
||
req.SetType(type);
|
||
req.SetParam1(autoAdvanceToggle.isOn ? 1 : 0);
|
||
req.SetParam2(0);
|
||
req.SendPacket();
|
||
}
|
||
else
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42600}"));
|
||
isOnAdvance = false;
|
||
SetAdvanceBtnState();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42674}"));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public void OnItemIconClick()
|
||
{
|
||
ItemTooltipsLogic.ShowItemTooltip(curNeedCostItemId, ItemTooltipsLogic.ShowType.Info, transform.position);
|
||
}
|
||
}
|