368 lines
12 KiB
C#
368 lines
12 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
|
|
|
|
public class UICurrencyItem : UIItemBase
|
|
{
|
|
|
|
public enum CURRENCY_TYPE
|
|
{
|
|
NONE,
|
|
YUANBAO,
|
|
YUANBAO_BIND,
|
|
TONGQIAN,
|
|
TONGQIAN_BIND,
|
|
}
|
|
#region
|
|
|
|
public Image _CurrencyIcon;
|
|
public Text _CurrencyValue;
|
|
|
|
private string curColor = "<color=white>"; // 每次显示数字,可以指定颜色,用完后自动设置回白色。
|
|
private MONEYTYPE _CurrencyType;
|
|
private long _CurrencyIntValue;
|
|
public long CurrencyIntValue
|
|
{
|
|
get
|
|
{
|
|
return _CurrencyIntValue;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
//设置颜色
|
|
public void SetColor(string color)
|
|
{
|
|
curColor = color;
|
|
}
|
|
|
|
private void ResetColor()
|
|
{
|
|
curColor = "<color=white>";
|
|
}
|
|
|
|
#region
|
|
|
|
public void ShowCurrency(MONEYTYPE currencyType, int currencyValue)
|
|
{
|
|
_CurrencyIcon.gameObject.SetActive(true);
|
|
if (GetCurrencySprite(currencyType) != "")
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(currencyType));
|
|
else
|
|
_CurrencyIcon.gameObject.SetActive(false);
|
|
_CurrencyValue.text = curColor + currencyValue.ToString() + "</color>";
|
|
_CurrencyIntValue = currencyValue;
|
|
_CurrencyType = currencyType;
|
|
|
|
ResetColor();
|
|
}
|
|
|
|
public void ShowCurrency(MONEYTYPE currencyType, long currencyValue)
|
|
{
|
|
_CurrencyIcon.gameObject.SetActive(true);
|
|
if (GetCurrencySprite(currencyType) != "")
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(currencyType));
|
|
else
|
|
_CurrencyIcon.gameObject.SetActive(false);
|
|
_CurrencyValue.text = curColor + currencyValue.ToString() + "</color>";
|
|
_CurrencyIntValue = (int)currencyValue;
|
|
_CurrencyType = currencyType;
|
|
|
|
ResetColor();
|
|
}
|
|
|
|
public void ShowCurrency(int consumType, int consumID, int consumValue)
|
|
{
|
|
if ((int)CONSUM_TYPE.MONEY == consumType)
|
|
{
|
|
ShowCurrency((MONEYTYPE)consumID, consumValue);
|
|
}
|
|
else if ((int)CONSUM_TYPE.PROPVAL == consumType)
|
|
{
|
|
if ((int)PropID.PropertyID.PRIVATEEXP == consumID)
|
|
{
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(MONEYTYPE.MONEYTYPE_SKILLEXP));
|
|
_CurrencyValue.text = curColor + consumValue.ToString() + "</color>";
|
|
_CurrencyIntValue = consumValue;
|
|
}
|
|
else if ((int)PropID.PropertyID.PROPUSER_EXP == consumID)
|
|
{
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(MONEYTYPE.MONEYTYPE_ROLEEXP));
|
|
_CurrencyValue.text = curColor + consumValue.ToString() + "</color>";
|
|
_CurrencyIntValue = consumValue;
|
|
}
|
|
}
|
|
else if ((int)CONSUM_TYPE.SCORE == consumType)
|
|
{
|
|
if ((int)SCORE_TYPE.GUILD_SCORE == consumID)
|
|
{
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetScoreSprite(SCORE_TYPE.GUILD_SCORE));
|
|
_CurrencyValue.text = curColor + consumValue.ToString() + "</color>";
|
|
_CurrencyIntValue = consumValue;
|
|
}
|
|
}
|
|
|
|
ResetColor();
|
|
}
|
|
|
|
public void ShowCurrency(int consumType, int consumID, long consumValue)
|
|
{
|
|
if ((int)CONSUM_TYPE.PROPVAL == consumType)
|
|
{
|
|
if ((int)PropID.PropertyID.PRIVATEEXP == consumID)
|
|
{
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(MONEYTYPE.MONEYTYPE_SKILLEXP));
|
|
_CurrencyValue.text = curColor + consumValue.ToString() + "</color>";
|
|
_CurrencyIntValue = (int)consumValue;
|
|
}
|
|
else if ((int)PropID.PropertyID.PROPUSER_EXP == consumID)
|
|
{
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(MONEYTYPE.MONEYTYPE_ROLEEXP));
|
|
_CurrencyValue.text = curColor + consumValue.ToString() + "</color>";
|
|
_CurrencyIntValue = (int)consumValue;
|
|
}
|
|
}
|
|
else if ((int)CONSUM_TYPE.MONEY == consumType)
|
|
{
|
|
ShowCurrency((MONEYTYPE)consumID, consumValue);
|
|
}
|
|
|
|
ResetColor();
|
|
}
|
|
|
|
public void ShowOwnCurrency(MONEYTYPE currencyType)
|
|
{
|
|
long Ownvalue = 0;
|
|
if ((int)currencyType >= 413 && (int)currencyType <= 418) //属性货币 //写死的特殊判断,以后添加属性货币这里要修改
|
|
{
|
|
Ownvalue = GameManager.gameManager.PlayerDataPool.GetPropInt((PropID.PropertyID)currencyType);
|
|
}
|
|
else
|
|
{
|
|
Ownvalue = GameManager.gameManager.PlayerDataPool.GetLongPropty((int)CONSUM_TYPE.MONEY, (int)currencyType);
|
|
}
|
|
LoadAssetBundle.Instance.SetImageSprite(_CurrencyIcon, GetCurrencySprite(currencyType));
|
|
_CurrencyValue.text = curColor + Ownvalue.ToString() + "</color>";
|
|
_CurrencyIntValue = Ownvalue;
|
|
_CurrencyType = currencyType;
|
|
|
|
ResetColor();
|
|
}
|
|
|
|
public void ShowReplaceOwnCurrency(int consumType, int consumID, int value = 0)
|
|
{
|
|
if ((int)CONSUM_TYPE.MONEY == consumType)
|
|
{
|
|
if (consumID == (int)MONEYTYPE.MONEYTYPE_COIN_BIND)
|
|
{
|
|
if (value > 0)
|
|
{
|
|
ShowCurrency(MONEYTYPE.MONEYTYPE_COIN, value);
|
|
}
|
|
else
|
|
{
|
|
var Ownvalue = GameManager.gameManager.PlayerDataPool.GetLongPropty(consumType, (int)MONEYTYPE.MONEYTYPE_COIN);
|
|
ShowCurrency(MONEYTYPE.MONEYTYPE_COIN, Ownvalue);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
else if ((int)CONSUM_TYPE.PROPVAL == consumType)
|
|
{
|
|
if ((int)PropID.PropertyID.PRIVATEEXP == consumID)
|
|
{
|
|
if (value > 0)
|
|
{
|
|
ShowCurrency(consumType, (int)PropID.PropertyID.PROPUSER_EXP, value);
|
|
}
|
|
else
|
|
{
|
|
var Ownvalue = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Exp;
|
|
ShowCurrency(consumType, (int)PropID.PropertyID.PROPUSER_EXP, Ownvalue);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
else if ((int)CONSUM_TYPE.SCORE == consumType)
|
|
{
|
|
if ((int)SCORE_TYPE.GUILD_SCORE == consumID)
|
|
{
|
|
ShowCurrency(consumType, consumID, value);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowCurrency(consumType, consumID, value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用替代货币和所需货币比较并显示。
|
|
/// </summary>
|
|
/// <param name="consumType">货币主类型</param>
|
|
/// <param name="consumID">货币次级类型</param>
|
|
/// <param name="compareTo">需要比较的数目</param>
|
|
public void ShowReplaceOwnCurrencyCompare(int consumType, int consumID, int compareTo = 0)
|
|
{
|
|
if ((int)CONSUM_TYPE.MONEY == consumType)
|
|
{
|
|
if (consumID == (int)MONEYTYPE.MONEYTYPE_COIN_BIND)
|
|
{
|
|
var ownValue = GameManager.gameManager.PlayerDataPool.GetLongPropty(consumType, (int)MONEYTYPE.MONEYTYPE_COIN);
|
|
if (ownValue < compareTo)
|
|
{
|
|
SetColor("<color=red>");
|
|
}
|
|
|
|
ShowCurrency(MONEYTYPE.MONEYTYPE_COIN, ownValue);
|
|
return;
|
|
}
|
|
}
|
|
else if ((int)CONSUM_TYPE.PROPVAL == consumType)
|
|
{
|
|
if ((int)PropID.PropertyID.PRIVATEEXP == consumID)
|
|
{
|
|
var ownValue = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Exp;
|
|
if (ownValue < compareTo)
|
|
{
|
|
SetColor("<color=red>");
|
|
}
|
|
|
|
ShowCurrency(consumType, (int)PropID.PropertyID.PROPUSER_EXP, ownValue);
|
|
return;
|
|
}
|
|
}
|
|
// 以下代码和 ShowReplaceOwnCurrency 一致,并未添加新功能。原因:尚不知道下方货币使用逻辑。
|
|
else if ((int)CONSUM_TYPE.SCORE == consumType)
|
|
{
|
|
if ((int)SCORE_TYPE.GUILD_SCORE == consumID)
|
|
{
|
|
int ownValue = GameManager.gameManager.PlayerDataPool.GuildInfo.GuildContribute;
|
|
if (ownValue < compareTo)
|
|
{
|
|
SetColor("<color=red>");
|
|
}
|
|
|
|
ShowCurrency(consumType, consumID, ownValue);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowCurrency(consumType, consumID, compareTo);
|
|
}
|
|
}
|
|
|
|
public void ShowCurrency(int value)
|
|
{
|
|
_CurrencyValue.text = curColor + value.ToString() + "</color>";
|
|
_CurrencyIntValue = value;
|
|
|
|
ResetColor();
|
|
}
|
|
|
|
public static string GetScoreSprite(SCORE_TYPE guildScore)
|
|
{
|
|
string spriteName = "";
|
|
|
|
if (guildScore == SCORE_TYPE.GUILD_SCORE)
|
|
{
|
|
spriteName = "banggong";
|
|
}
|
|
|
|
return spriteName;
|
|
}
|
|
|
|
public static string GetMoneyItemIcon(MONEYTYPE currencyType)
|
|
{
|
|
string spriteName = "";
|
|
switch (currencyType)
|
|
{
|
|
case MONEYTYPE.MONEYTYPE_COIN:
|
|
spriteName = "yinliang01";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_YUANBAO:
|
|
spriteName = "lingyu01";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_YUANBAO_BIND:
|
|
spriteName = "yuanbao01";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_COIN_BIND:
|
|
spriteName = "yinpiao01";
|
|
break;
|
|
}
|
|
return spriteName;
|
|
}
|
|
|
|
public static string GetCurrencySprite(MONEYTYPE currencyType)
|
|
{
|
|
string spriteName = "";
|
|
switch(currencyType)
|
|
{
|
|
case MONEYTYPE.MONEYTYPE_COIN:
|
|
spriteName = "qian1";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_YUANBAO:
|
|
spriteName = "qian2";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_YUANBAO_BIND:
|
|
spriteName = "qian3";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_COIN_BIND:
|
|
spriteName = "qian4";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_SKILLEXP:
|
|
spriteName = "skillExp";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_ROLEEXP:
|
|
spriteName = "roleExp";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_USERCHALLENGE:
|
|
spriteName = "menpaiCoin";
|
|
break;
|
|
case MONEYTYPE.MONEYTYPE_SNATCHSCORE:
|
|
spriteName = "duobaoCoin";
|
|
break;
|
|
}
|
|
|
|
// 关宁(或叫演武)积分
|
|
if((int)currencyType == (int)PropID.PropertyID.GUANNING)
|
|
{
|
|
spriteName = "yanwuCoin";
|
|
}
|
|
else if((int)currencyType == (int)PropID.PropertyID.CROSSSERVERSCORE)
|
|
{
|
|
spriteName = "kuafuCoin";
|
|
}
|
|
else if ((int)currencyType == (int)PropID.PropertyID.EXPERIMENTSCORE)
|
|
{
|
|
spriteName = "shilianCoin";
|
|
}
|
|
else if((int)currencyType == (int)PropID.PropertyID.BOSSCORE)
|
|
{
|
|
spriteName = "bosscoin";
|
|
}
|
|
else if ((int)currencyType == 437)//紫禁之巅积分
|
|
{
|
|
spriteName = "zijincoin";
|
|
}
|
|
|
|
return spriteName;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void OnBtnAddClick()
|
|
{
|
|
if((int)_CurrencyType == (int)PropID.PropertyID.BOSSCORE)
|
|
{
|
|
UIManager.ShowUI(UIInfo.Boss);
|
|
return;
|
|
}
|
|
JudgeMoneyLogic.ShowSwitchMoneyPanel(_CurrencyType, true);
|
|
}
|
|
}
|
|
|