From dc7922d80c1d133b6261b8af1d521567d2c0a35d Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 30 十月 2025 16:51:39 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts
---
Main/Utility/UIHelper.cs | 191 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 154 insertions(+), 37 deletions(-)
diff --git a/Main/Utility/UIHelper.cs b/Main/Utility/UIHelper.cs
index 2f6bf80..21ee7a0 100644
--- a/Main/Utility/UIHelper.cs
+++ b/Main/Utility/UIHelper.cs
@@ -69,26 +69,33 @@
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 +180,7 @@
}
/// <summary>
- /// 鑾峰彇娑堥�濈殑鏃堕棿
+ /// 鑾峰彇杩囧幓鐨勬椂闂�
/// </summary>
/// <param name="lastTime"></param>
/// <returns></returns>
@@ -200,17 +207,10 @@
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)
{
@@ -221,23 +221,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, 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);
}
}
@@ -251,25 +251,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)
@@ -324,6 +333,13 @@
return false;
}
+ // 妫�鏌ュ瓧绗︿覆鏄笉鏄函鏁存暟
+ public static bool IsNumeric(string input)
+ {
+ return int.TryParse(input, out _);
+ }
+
+
public static string GetColorNameByItemColor(int itemColor)
{
switch (itemColor)
@@ -372,7 +388,7 @@
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
@@ -543,6 +559,8 @@
return s_LightWhite;
case TextColType.Gray:
return s_Gray;
+ case TextColType.NavyGray:
+ return new Color32(121, 121, 121, 255);
case TextColType.itemjingliang:
// 729de4 绮捐壇
return new Color32(114, 157, 228, 255);
@@ -674,7 +692,7 @@
// 5d1d52 姘告亽
return new Color32(93, 29, 82, 128);
case QualityTextColType.red:
- return s_BrightRedColor;
+ return s_DarkRedColor;
}
return new Color32(0, 0, 0, 128);
}
@@ -716,6 +734,8 @@
return StringUtility.Contact("<color=#8ddc11>", msg, "</color>");
case TextColType.Gray:
return StringUtility.Contact("<color=#bbbbbb>", msg, "</color>");
+ case TextColType.NavyGray:
+ return StringUtility.Contact("<color=#797979>", msg, "</color>");
case TextColType.lightYellow:
return StringUtility.Contact("<color=#fcedb9>", msg, "</color>");
case TextColType.NavyYellow:
@@ -749,13 +769,37 @@
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)
@@ -821,7 +865,7 @@
/// <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)
{
@@ -899,7 +943,7 @@
}
#endregion
-
+
#region 寰楀埌閲戦挶鏁伴噺鏍规嵁閲戦挶绫诲瀷
@@ -938,9 +982,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)
@@ -974,6 +1021,7 @@
}
case 15:
{
+ // 鍏細璐$尞甯�
return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.UnionLiven);
//return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.UnionLiven);
}
@@ -1039,7 +1087,7 @@
}
case 43:
{
- //鍑瘉绉垎
+ //灏嗛瓊
return PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default34);
}
case 44:
@@ -1077,6 +1125,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:
{
//杩囨湡鍨嬩唬閲戝埜
@@ -1098,22 +1156,57 @@
}
//鏄剧ず鏁伴噺, 鏍煎紡n/m, 瓒冲缁胯壊涓嶈冻绾㈣壊
- public static string ShowUseMoney(int moneyType, long useCnt, TextColType engoughColor = TextColType.Green)
+ public static string ShowUseMoney(int moneyType, long useCnt, bool showLargeNum = true)
{
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 = true)
{
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);
}
@@ -1193,13 +1286,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)
{
@@ -1297,4 +1392,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;
+ }
+
}
--
Gitblit v1.8.0