From ed98029a88cd89702980ac7c40b711afddc5aeb2 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 20 十一月 2025 14:44:59 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts

---
 Main/Utility/UIHelper.cs |   88 ++++++++++++++++++++++++++++++-------------
 1 files changed, 61 insertions(+), 27 deletions(-)

diff --git a/Main/Utility/UIHelper.cs b/Main/Utility/UIHelper.cs
index 8c204df..2cd0ea7 100644
--- a/Main/Utility/UIHelper.cs
+++ b/Main/Utility/UIHelper.cs
@@ -66,6 +66,8 @@
 
 
     #region UI閫氱敤
+
+    //榛樿璐у竵鍥剧墖鐢ㄩ珮娓呯殑锛屽瘜鏂囨湰鐨勫彲浠ョ敤灏忓浘鏍囧埄浜庢帓鐗堟樉绀�
     public static void SetIconWithMoneyType(this Image _image, int moneyType)
     {
         if (_image == null) return;
@@ -75,6 +77,7 @@
         }
         else
         {
+            // 鏆備笉鑰冭檻瀵屾枃鏈殑鎯呭喌
             // 涓嶉渶瑕佺墿鍝佺殑鎯呭喌琛ュ厖
             // string iconKey = StringUtility.Contact("Money_Type_", moneyType);
             Debug.LogError("MoneyDisplayModel 鏈厤缃揣甯佺被鍨嬶細" + moneyType);
@@ -83,7 +86,12 @@
 
     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;
         }
@@ -91,6 +99,20 @@
         {
             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;
         }
     }
 
@@ -174,7 +196,7 @@
 
     }
     /// <summary>
-    /// 鑾峰彇娑堥�濈殑鏃堕棿
+    /// 鑾峰彇杩囧幓鐨勬椂闂�
     /// </summary>
     /// <param name="lastTime"></param>
     /// <returns></returns>
@@ -201,19 +223,12 @@
         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 -鐧捐惉锛孊-鍗佸剟锛孴 -钀剟
-    /// 涓嶅洓鑸嶄簲鍏ワ紝涓嶇敤Math.Round锛屽洜涓哄綋鐜╁鍙湁23.3456,浣嗘槸Math.Round浼氭樉绀�23.35, 褰撹喘涔颁环鏍间负23.35鏃舵棤娉曡喘涔扮殑
     /// </summary>
-    public static string ReplaceLargeNum(double num)
+    public static string ReplaceLargeNum(double num, int decimalPlaces = 1)
     {
         const long K = 10000;    //鍥藉唴涓轰竾锛屾捣澶栦负鍗�
         const long M = K * 10000;
@@ -222,23 +237,23 @@
 
         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, decimalPlaces), Language.Get("L1070"));
         }
         else if (num >= K)
         {
-            return StringUtility.Contact(numto2Decimals(num / K).ToString("0.#"), Language.Get("L1071"));
+            return StringUtility.Contact(FormatWithoutRounding(num / K, decimalPlaces), Language.Get("L1071"));
         }
         else
         {
-            return numto2Decimals(num).ToString("0.#");
+            return FormatWithoutRounding(num, decimalPlaces);
         }
     }
 
@@ -252,25 +267,34 @@
 
         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)
@@ -974,9 +998,12 @@
         {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)
@@ -1010,6 +1037,7 @@
                 }
             case 15:
                 {
+                    // 鍏細璐$尞甯�
                     return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.UnionLiven);
                     //return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.UnionLiven);
                 }
@@ -1075,7 +1103,7 @@
                 }
             case 43:
                 {
-                    //鍑瘉绉垎
+                    //灏嗛瓊
                     return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default34);
                 }
             case 44:
@@ -1144,16 +1172,22 @@
     }
 
     //鏄剧ず鏁伴噺, 鏍煎紡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(cnt)}/{ReplaceLargeNum(useCnt)}");
+        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(cnt)}/{ReplaceLargeNum(useCnt)}");
+        if (showLargeNum)
+            return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{useCnt}");
+        else
+            return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{cnt}/{useCnt}");
     }
 
 
@@ -1276,7 +1310,7 @@
         //bool pureChinese = Regex.IsMatch(name, "^[\u4e00-\u9fa5]+$");
         //var chsCount = GetChsCount(name);
         int length = Encoding.Default.GetBytes(name).Length;
-        var maxlength = 14;  //绾腑鏂囦笉寤鸿瓒呰繃7涓瓧
+        var maxlength = 21;  //绾腑鏂囦笉寤鸿瓒呰繃7涓瓧
         var minlength = 3;
         if (length > maxlength)
         {

--
Gitblit v1.8.0