| | |
| | | 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 ""; |
| | | } |
| | | } |
| | | |
| | | // 通过货币类型获取物品ID |
| | | public static int GetItemIDWithMoneyType(int moneyType) |
| | | { |
| | | if (GeneralDefine.MoneyDisplayModel.ContainsKey(moneyType)) |
| | | { |
| | | return GeneralDefine.MoneyDisplayModel[moneyType]; |
| | | } |
| | | else |
| | | { |
| | | Debug.LogError("MoneyDisplayModel 未配置货币类型:" + moneyType); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 获取消逝的时间 |
| | | /// 获取过去的时间 |
| | | /// </summary> |
| | | /// <param name="lastTime"></param> |
| | | /// <returns></returns> |
| | |
| | | return val.Replace(@"</r>", "\n"); |
| | | } |
| | | |
| | | public static double numto2Decimals(double value) |
| | | { |
| | | //为什么要value * 1000/10 这么写,特殊的数字会有问题,比如36.80000,会(int)(value * 100)被计算为3679 |
| | | //测试下只有30几点8000的才会这样 |
| | | return (int)(value * 1000 / 10) / 100.00; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大数值转化 格式 最多两个小数 |
| | | /// 大数值转化 格式 最多两个小数 ,向下取整 |
| | | /// K -千,M -百萬,B-十億,T -萬億 |
| | | /// 不四舍五入,不用Math.Round,因为当玩家只有23.3456,但是Math.Round会显示23.35, 当购买价格为23.35时无法购买的 |
| | | /// </summary> |
| | | public static string ReplaceLargeNum(double num) |
| | | { |
| | |
| | | |
| | | if (num >= T) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / T).ToString("0.##"), Language.Get("L1070_0")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / T, 2), Language.Get("L1070_0")); |
| | | } |
| | | else if (num >= B) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / B).ToString("0.##"), Language.Get("L1070_1")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / B, 2), Language.Get("L1070_1")); |
| | | } |
| | | else if (num >= M) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / M).ToString("0.#"), Language.Get("L1070")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / M, 1), Language.Get("L1070")); |
| | | } |
| | | else if (num >= K) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / K).ToString("0.#"), Language.Get("L1071")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / K, 1), Language.Get("L1071")); |
| | | } |
| | | else |
| | | { |
| | | return numto2Decimals(num).ToString("0.#"); |
| | | return FormatWithoutRounding(num, 1); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (num >= T) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / T).ToString("0.##"), "t"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / T, 2), "t"); |
| | | } |
| | | else if (num >= B) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / B).ToString("0.##"), "b"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / B, 2), "b"); |
| | | } |
| | | else if (num >= M) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / M).ToString("0.#"), "m"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / M, 1), "m"); |
| | | } |
| | | else if (num >= K) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / K).ToString("0.#"), "k"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / K, 1), "k"); |
| | | } |
| | | else |
| | | { |
| | | return numto2Decimals(num).ToString("0.#"); |
| | | return FormatWithoutRounding(num, 1); |
| | | } |
| | | } |
| | | |
| | | //根据小数位数直接截断不做四舍五入 |
| | | public static string FormatWithoutRounding(double value, int decimalPlaces) |
| | | { |
| | | double factor = Math.Pow(10, decimalPlaces); |
| | | double truncated = Math.Truncate(value * factor) / factor; |
| | | return truncated.ToString($"0.{new string('#', decimalPlaces)}"); |
| | | } |
| | | |
| | | |
| | | // 转化大数值带单位的显示,如果小于200000则显示原值,否则显示大数值 |
| | | public static string ReplaceLargeNumEx(double num) |
| | |
| | | return false; |
| | | } |
| | | |
| | | // 检查字符串是不是纯整数 |
| | | public static bool IsNumeric(string input) |
| | | { |
| | | return int.TryParse(input, out _); |
| | | } |
| | | |
| | | |
| | | public static string GetColorNameByItemColor(int itemColor) |
| | | { |
| | | switch (itemColor) |
| | |
| | | public static readonly Color s_NavyYellow = new Color32(242, 238, 2, 255); //f2ee02 |
| | | public static readonly Color s_LightGreen = new Color32(42, 227, 55, 255);//2ae337 |
| | | public static readonly Color s_LightWhite = new Color32(245, 246, 230, 255); //f5f6e6 |
| | | public static readonly Color s_Gray = new Color32(104, 104, 104,255); //bbbbbb |
| | | public static readonly Color s_Gray = new Color32(187, 187, 187, 255); //bbbbbb |
| | | public static readonly Color s_Gold = new Color32(255, 239, 71, 255);//ffef47 |
| | | public static readonly Color s_EarthYellow = new Color32(248, 152, 59, 255);//f8983b |
| | | |
| | |
| | | // 5d1d52 永恒 |
| | | return new Color32(93, 29, 82, 128); |
| | | case QualityTextColType.red: |
| | | return s_BrightRedColor; |
| | | return s_DarkRedColor; |
| | | } |
| | | return new Color32(0, 0, 0, 128); |
| | | } |
| | |
| | | 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>"); |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | public static string AppendColor(Color color, string msg) |
| | | { |
| | | return StringUtility.Contact("<color=#", ColorToHexWithHash(color), ">", msg, "</color>"); |
| | | } |
| | | |
| | | |
| | | public static string ColorToHexWithHash(Color color, bool includeAlpha = false) |
| | | { |
| | | int r = Mathf.RoundToInt(color.r * 255); |
| | | int g = Mathf.RoundToInt(color.g * 255); |
| | | int b = Mathf.RoundToInt(color.b * 255); |
| | | if (includeAlpha) |
| | | { |
| | | int a = Mathf.RoundToInt(color.a * 255); |
| | | return string.Format("{0:X2}{1:X2}{2:X2}{3:X2}", r, g, b, a); |
| | | } |
| | | else |
| | | { |
| | | return string.Format("{0:X2}{1:X2}{2:X2}", r, g, b); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //needName 指官职0是否需要名称 |
| | | public static string GetRealmName(int realmLv, bool bright = true, bool needName = false) |
| | |
| | | /// <param name="itemColor"></param> |
| | | /// <param name="msg"></param> |
| | | /// <param name="bright"></param> |
| | | /// <param name="colorGroupType"></param> |
| | | /// <param name="colorGroupType">0 通用功能品质分组精良到神话</param> |
| | | /// <returns></returns> |
| | | public static string AppendColor(int itemColor, string msg, bool bright = true, int colorGroupType = 0) |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | |
| | | #region 得到金钱数量根据金钱类型 |
| | | |
| | |
| | | {1, PlayerDataType.Gold}, |
| | | {2, PlayerDataType.GoldPaper}, |
| | | {3, PlayerDataType.Silver}, |
| | | {15, PlayerDataType.UnionLiven}, |
| | | {41, PlayerDataType.default26}, |
| | | {43, PlayerDataType.default34}, |
| | | {42, PlayerDataType.default33}, |
| | | |
| | | {53, PlayerDataType.ChallengeVoucher}, |
| | | {99, PlayerDataType.ExAttr11}, |
| | | }; |
| | | |
| | | public static long GetMoneyCnt(int moneyType) |
| | |
| | | } |
| | | case 15: |
| | | { |
| | | // 公会贡献币 |
| | | return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.UnionLiven); |
| | | //return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.UnionLiven); |
| | | } |
| | |
| | | } |
| | | case 43: |
| | | { |
| | | //凭证积分 |
| | | //将魂 |
| | | return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default34); |
| | | } |
| | | case 44: |
| | |
| | | //武将招募积分 |
| | | return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default44); |
| | | } |
| | | case 52: |
| | | { |
| | | //淘金令 |
| | | return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.GoldRush); |
| | | } |
| | | case 53: |
| | | { |
| | | //挑战凭证 |
| | | return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.ChallengeVoucher); |
| | | } |
| | | case 98: |
| | | { |
| | | //过期型代金券 |
| | |
| | | } |
| | | |
| | | //显示数量, 格式n/m, 足够绿色不足红色 |
| | | public static string ShowUseMoney(int moneyType, long useCnt, TextColType engoughColor = TextColType.Green) |
| | | public static string ShowUseMoney(int moneyType, long useCnt, bool showLargeNum = false) |
| | | { |
| | | long cnt = GetMoneyCnt(moneyType); |
| | | return AppendColor(useCnt <= cnt ? engoughColor : TextColType.Red, $"{ReplaceLargeNum(useCnt)}/{ReplaceLargeNum(cnt)}"); |
| | | if (showLargeNum) |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{useCnt}"); |
| | | else |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{cnt}/{useCnt}"); |
| | | } |
| | | |
| | | public static string ShowUseItem(PackType type, int itemId, long useCnt, TextColType engoughColor = TextColType.Green) |
| | | public static string ShowUseItem(PackType type, int itemId, long useCnt, bool showLargeNum = false) |
| | | { |
| | | long cnt = PackManager.Instance.GetItemCountByID(type, itemId); |
| | | return AppendColor(useCnt <= cnt ? engoughColor : TextColType.Red, $"{ReplaceLargeNum(useCnt)}/{ReplaceLargeNum(cnt)}"); |
| | | if (showLargeNum) |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{useCnt}"); |
| | | else |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{cnt}/{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); |
| | | } |
| | |
| | | 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) |
| | | { |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |