257 lines
11 KiB
C#
257 lines
11 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using GCGame.Table;
|
|||
|
using UnityEngine.UI;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
public class FashionItem : MonoBehaviour {
|
|||
|
|
|||
|
#region
|
|||
|
public Image icon;
|
|||
|
public Text fashionName;
|
|||
|
public Text haveOrNotDescText;
|
|||
|
public Text btnDesc;
|
|||
|
public Button getBtn;
|
|||
|
public Sprite hadIcon;
|
|||
|
public Sprite noIcon;
|
|||
|
public Color hadColor;
|
|||
|
public Color noColor;
|
|||
|
public Image markBG; //选择标记背景
|
|||
|
public Image itemQuality;
|
|||
|
#endregion
|
|||
|
|
|||
|
private int curIndex = -1;
|
|||
|
private int itemVisualId = -1; //武器或者衣服的索引ID 对应fashionItem的ID
|
|||
|
private int curClassId = -1;
|
|||
|
private int fashiomItemId = -1;
|
|||
|
private List<int> commonItemidLsit = new List<int>();
|
|||
|
public void InitItem(Tab_FashionItem item, int index)
|
|||
|
{
|
|||
|
fashionName.text = item.Name;
|
|||
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(item.GetCommonitemIdbyIndex(0), 0);
|
|||
|
if(commonItem != null)
|
|||
|
{
|
|||
|
#region 时装图标分男女
|
|||
|
int _PlayerProfession = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession; //获取玩家职业
|
|||
|
//名字 Icon
|
|||
|
if (_PlayerProfession == 0 || _PlayerProfession == 2)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(icon, commonItem.Icon);//男
|
|||
|
}
|
|||
|
else if (_PlayerProfession == 1 || _PlayerProfession == 3)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(icon, commonItem.Iconnv); //女
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
//名字 Icon
|
|||
|
//LoadAssetBundle.Instance.SetImageSprite(icon, commonItem.Icon);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(itemQuality, GCGame.Utils.GetItemQualityFrame(commonItem.Quality));
|
|||
|
if (commonItem.QualityEffect > 0)
|
|||
|
{
|
|||
|
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, icon.transform);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, icon.transform);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
itemVisualId = item.ItemVisualId;
|
|||
|
curClassId = item.ClassId;
|
|||
|
curIndex = index;
|
|||
|
fashiomItemId = item.Id;
|
|||
|
commonItemidLsit = new List<int>();
|
|||
|
for (int itemIndex = 0; itemIndex < item.getCommonitemIdCount(); itemIndex++)
|
|||
|
{
|
|||
|
commonItemidLsit.Add(item.GetCommonitemIdbyIndex(itemIndex));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnItemClick()
|
|||
|
{
|
|||
|
int weaponId = 0;
|
|||
|
Tab_FashionItem fashionItem = TableManager.GetFashionItemByID(fashiomItemId, 0);
|
|||
|
if (fashionItem != null)
|
|||
|
{
|
|||
|
weaponId = fashionItem.GetCommonitemIdbyIndex(0); //因为有可能无法再EquipAttr中
|
|||
|
}
|
|||
|
|
|||
|
if (curClassId == 1) //0为衣服 1位武器
|
|||
|
{
|
|||
|
GlobalData.IsSelectedWeaponFashion = true;
|
|||
|
FashionPanelCtr.Instance.SetCurSelectedWeaponDataId(weaponId);
|
|||
|
}
|
|||
|
|
|||
|
FashionPanelCtr.Instance.ShowModelOnTexture(itemVisualId, curClassId, fashiomItemId);
|
|||
|
FashionPanelCtr.Instance.ShowFashionAttr(fashionItem, curClassId);
|
|||
|
FashionPanelCtr.Instance.ShowSelectedBG(curIndex); //设置当前SelectedBG
|
|||
|
}
|
|||
|
|
|||
|
private FashionPanelCtr.FashionItemState curBtnState = FashionPanelCtr.FashionItemState.INVALID; //通过判断状态判断当前的点击事件
|
|||
|
private FashionPanelCtr.FashionItemState lastState = FashionPanelCtr.FashionItemState.INVALID;
|
|||
|
public void InitState(FashionPanelCtr.FashionItemState state)
|
|||
|
{
|
|||
|
curBtnState = state;
|
|||
|
Tab_FashionItem fashionItem = TableManager.GetFashionItemByID(fashiomItemId, 0);
|
|||
|
switch (state)
|
|||
|
{
|
|||
|
case FashionPanelCtr.FashionItemState.OWN:
|
|||
|
//判断是否穿戴
|
|||
|
getBtn.image.overrideSprite = hadIcon;
|
|||
|
btnDesc.color = hadColor;
|
|||
|
|
|||
|
if (fashionItem == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if(curClassId == 0) //衣服
|
|||
|
{
|
|||
|
if (fashionItem.ItemVisualId == GameManager.gameManager.PlayerDataPool.ModelVisualID)
|
|||
|
{
|
|||
|
curBtnState = FashionPanelCtr.FashionItemState.ISON;
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42651}"); //"卸下";
|
|||
|
haveOrNotDescText.text = calculateEndTime();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState.ContainsKey(fashiomItemId))
|
|||
|
{
|
|||
|
curBtnState = FashionPanelCtr.FashionItemState.ISOFF;
|
|||
|
haveOrNotDescText.text = calculateEndTime();
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42652}"); //"穿戴";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
curBtnState = FashionPanelCtr.FashionItemState.OWN;
|
|||
|
haveOrNotDescText.text = StrDictionary.GetClientDictionaryString("#{42654}"); //"未激活";
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42653}"); //"激活";
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
else //武器
|
|||
|
{
|
|||
|
bool _HasFind = false;
|
|||
|
for(int index = 0; index < fashionItem.getCommonitemIdCount(); index++)
|
|||
|
{
|
|||
|
if (fashionItem.GetCommonitemIdbyIndex(index) == GameManager.gameManager.PlayerDataPool.WeaponFashionId
|
|||
|
&& fashionItem.GetCommonitemIdbyIndex(index) != -1) //服务器同步的是武器时装的道具ID
|
|||
|
{
|
|||
|
curBtnState = FashionPanelCtr.FashionItemState.ISON;
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42651}"); // "卸下";
|
|||
|
haveOrNotDescText.text = calculateEndTime();
|
|||
|
_HasFind = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if(!_HasFind)
|
|||
|
{
|
|||
|
if (GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState.ContainsKey(fashiomItemId))
|
|||
|
{
|
|||
|
curBtnState = FashionPanelCtr.FashionItemState.ISOFF;
|
|||
|
haveOrNotDescText.text = calculateEndTime();
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42652}"); // "穿戴";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
curBtnState = FashionPanelCtr.FashionItemState.OWN;
|
|||
|
haveOrNotDescText.text = StrDictionary.GetClientDictionaryString("#{42655}"); //"<color= E9E9E9FF>未激活</color>";
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42653}"); //"激活";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
case FashionPanelCtr.FashionItemState.OVERTIME:
|
|||
|
{
|
|||
|
getBtn.image.overrideSprite = noIcon;
|
|||
|
btnDesc.color = noColor;
|
|||
|
haveOrNotDescText.text = StrDictionary.GetClientDictionaryString("#{42656}"); //"<color=C3F5C1FF>已过期</color>";
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42657}"); //"获取途径";
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
{
|
|||
|
getBtn.image.overrideSprite = noIcon;
|
|||
|
btnDesc.color = noColor;
|
|||
|
haveOrNotDescText.text = StrDictionary.GetClientDictionaryString("#{42658}"); //"<color=C3F5C1FF>未获得</color>";
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{42657}"); //"获取途径";
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
string calculateEndTime()
|
|||
|
{
|
|||
|
string endYear = "";
|
|||
|
string endMonth = "";
|
|||
|
string endDay = "";
|
|||
|
if (GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState.ContainsKey(fashiomItemId))
|
|||
|
{
|
|||
|
if(GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState[fashiomItemId] == -1)
|
|||
|
{
|
|||
|
//永久
|
|||
|
return StrDictionary.GetClientDictionaryString("#{1442}");
|
|||
|
}
|
|||
|
DateTime startTime = new System.DateTime(1970, 1, 1).ToLocalTime();
|
|||
|
DateTime nowTime = GCGame.Utils.GetServerDateTime().AddSeconds(GlobalData.ServerAnsiTime);
|
|||
|
DateTime endTime = startTime.AddSeconds((GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState[fashiomItemId]));
|
|||
|
|
|||
|
endYear = endTime.Year.ToString();
|
|||
|
endMonth = endTime.Month.ToString();
|
|||
|
endDay = endTime.Day.ToString();
|
|||
|
|
|||
|
if (nowTime.Year == endTime.Year && nowTime.Month == endTime.Month && nowTime.Day == endTime.Day)
|
|||
|
{
|
|||
|
//返回剩余的小时
|
|||
|
return StrDictionary.GetClientDictionaryString("#{1518}", (endTime - nowTime).TotalHours.ToString("0.0"));
|
|||
|
}
|
|||
|
}
|
|||
|
return StrDictionary.GetClientDictionaryString("#{1517}", (endYear + "/" + endMonth + "/" + endDay));
|
|||
|
}
|
|||
|
|
|||
|
public void OnBtnClick()
|
|||
|
{
|
|||
|
switch(curBtnState)
|
|||
|
{
|
|||
|
case FashionPanelCtr.FashionItemState.ISON:
|
|||
|
//脱下
|
|||
|
CG_TAKEOFF_FASHION takeOffPacket = (CG_TAKEOFF_FASHION)PacketDistributed.CreatePacket(MessageID.PACKET_CG_TAKEOFF_FASHION);
|
|||
|
takeOffPacket.SetFashionType(curClassId);
|
|||
|
takeOffPacket.SetFashionId(fashiomItemId);
|
|||
|
takeOffPacket.SendPacket();
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
case FashionPanelCtr.FashionItemState.ISOFF:
|
|||
|
//穿上
|
|||
|
CG_WEAR_FASHION wearPacket = (CG_WEAR_FASHION)PacketDistributed.CreatePacket(MessageID.PACKET_CG_WEAR_FASHION);
|
|||
|
wearPacket.SetFashionID(fashiomItemId);
|
|||
|
wearPacket.SendPacket();
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
case FashionPanelCtr.FashionItemState.OWN:
|
|||
|
//激活
|
|||
|
//CG_BUY_FASHION buyPacket = (CG_BUY_FASHION)PacketDistributed.CreatePacket(MessageID.PACKET_CG_BUY_FASHION);
|
|||
|
//buyPacket.SetFashionID(fashiomItemId);
|
|||
|
//buyPacket.SendPacket();
|
|||
|
|
|||
|
//跳转到背包界面
|
|||
|
BackPackLogic.Instance()._TagPanel.ShowPage(0);
|
|||
|
break;
|
|||
|
|
|||
|
default:
|
|||
|
//显示获取途径
|
|||
|
ItemTooltipsLogic.ShowItemTooltip(commonItemidLsit[0], ItemTooltipsLogic.ShowType.GetPath, transform.position);
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|