hch
3 天以前 cfe2a2d5bc6fe9a85488542597d4f73dddbfeee8
Main/Utility/UIHelper.cs
@@ -69,26 +69,31 @@
    public static void SetIconWithMoneyType(this Image _image, int moneyType)
    {
        if (_image == null) return;
        // string iconKey = StringUtility.Contact("Money_Type_", moneyType);
        if (GeneralDefine.MoneyDisplayModel.ContainsKey(moneyType))
        {
            _image.SetOrgSprite(ItemConfig.Get(GeneralDefine.MoneyDisplayModel[moneyType]).IconKey);
        }
        else
        {
            Debug.LogError("MoneyDisplayModel 为配置货币类型:" + moneyType);
        {
            // 不需要物品的情况补充
            // string iconKey = StringUtility.Contact("Money_Type_", moneyType);
            Debug.LogError("MoneyDisplayModel 未配置货币类型:" + moneyType);
        }
    }
    public static string GetIconNameWithMoneyType(int moneyType)
    {
        if (GeneralDefine.MoneyDisplayModel.ContainsKey(moneyType))
        if (IconConfig.HasKey("MoneyType_" + moneyType))
        {
            return IconConfig.Get("MoneyType_" + moneyType).sprite;
        }
        else if (GeneralDefine.MoneyDisplayModel.ContainsKey(moneyType))
        {
            return ItemConfig.Get(GeneralDefine.MoneyDisplayModel[moneyType]).IconKey;
        }
        else
        {
            Debug.LogError("MoneyDisplayModel 为配置货币类型:" + moneyType);
            Debug.LogError("MoneyDisplayModel 未配置货币类型:" + moneyType);
            return "";
        }
    }
@@ -173,7 +178,7 @@
    }
    /// <summary>
    /// 获取消逝的时间
    /// 获取过去的时间
    /// </summary>
    /// <param name="lastTime"></param>
    /// <returns></returns>
@@ -323,6 +328,13 @@
        }
        return false;
    }
    // 检查字符串是不是纯整数
    public static bool IsNumeric(string input)
    {
        return int.TryParse(input, out _);
    }
    public static string GetColorNameByItemColor(int itemColor)
    {
@@ -753,7 +765,7 @@
                return StringUtility.Contact("<color=#dfbbed>", msg, "</color>");
            case TextColType.itembuxiu:
                // 5eeff2 不朽
                return  StringUtility.Contact("<color=#5eeff2>", msg, "</color>");
                return StringUtility.Contact("<color=#5eeff2>", msg, "</color>");
            case TextColType.itemyonghen:
                // f5b4ea 永恒
                return StringUtility.Contact("<color=#f5b4ea>", msg, "</color>");
@@ -762,7 +774,7 @@
    }
    public static string AppendColor(Color color, string msg)
    {
    {
        return StringUtility.Contact("<color=#", ColorToHexWithHash(color), ">", msg, "</color>");
    }
@@ -927,7 +939,7 @@
    }
    #endregion
    #region 得到金钱数量根据金钱类型
@@ -968,7 +980,7 @@
        {3, PlayerDataType.Silver},
        {41, PlayerDataType.default26},
        {42, PlayerDataType.default33},
        {53, PlayerDataType.ChallengeVoucher},
    };
    public static long GetMoneyCnt(int moneyType)
@@ -1002,6 +1014,7 @@
                }
            case 15:
                {
                    // 公会贡献币
                    return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.UnionLiven);
                    //return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.UnionLiven);
                }
@@ -1105,6 +1118,16 @@
                    //武将招募积分
                    return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default44);
                }
            case 52:
                {
                    //淘金令
                    return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.GoldRush);
                }
            case 53:
                {
                    //挑战凭证
                    return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.ChallengeVoucher);
                }
            case 98:
                {
                    //过期型代金券
@@ -1138,10 +1161,39 @@
        return AppendColor(useCnt <= cnt ? engoughColor : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{ReplaceLargeNum(useCnt)}");
    }
    /// <param name="needTips">0 不响应 1 弹提示 2 弹获取途径tips</param>
    public static bool CheckMoneyCount(int moneyType, long needCount, int needTips = 0)
    {
        if (needCount <= 0)
        {
            return true;
        }
        long haveCount = GetMoneyCnt(moneyType);
        bool isEnough = haveCount >= needCount;
        if (!isEnough)
        {
            if (needTips == 1)
            {
                SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
            }
            else if (needTips == 2)
            {
                ItemTipUtility.ShowMoneyTip(moneyType);
            }
        }
        return isEnough;
    }
    #endregion
    #region 得到装备位或者祝福树品质名称 带颜色
    public static string GetQualityNameWithColor(int quality, string format="{0}")
    public static string GetQualityNameWithColor(int quality, string format = "{0}")
    {
        return AppendColor(quality, string.Format(format, Language.Get("equipQuality" + quality)), true, 1);
    }
@@ -1221,13 +1273,15 @@
        return content;
    }
    //检查名字长度,玩家名和公会名
    //不同国家长度不同,排版不同
    public static bool SatisfyNameLength(string name, out int error)
    {
        error = 0;
        //bool pureChinese = Regex.IsMatch(name, "^[\u4e00-\u9fa5]+$");
        //var chsCount = GetChsCount(name);
        int length = Encoding.Default.GetBytes(name).Length;
        var maxlength = 20;
        var maxlength = 14;  //纯中文不建议超过7个字
        var minlength = 3;
        if (length > maxlength)
        {
@@ -1325,4 +1379,26 @@
        return money / scale;
    }
    public static string RemoveColor(string content)
    {
        content = WordAnalysis.Color_Start_Regex.Replace(content, string.Empty);
        content = WordAnalysis.Color_End_Regex.Replace(content, string.Empty);
        return content;
    }
    //复制到剪贴板
    // TODO 暂不支持web后续补充
    public static void CopyToClipboard(string text)
    {
        GUIUtility.systemCopyBuffer = text;
        Debug.Log("文字已复制到剪贴板: " + text);
    }
    //获取剪切板内容
    public static string GetClipboardText()
    {
        return GUIUtility.systemCopyBuffer;
    }
}