From 3bd7f56906e31e8fe0072108c9d4652707b51de8 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期二, 21 十月 2025 17:59:00 +0800
Subject: [PATCH] 125 战斗 战斗UI

---
 Main/Component/UI/Common/BossLifeBar.cs |   67 +++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 24 deletions(-)

diff --git a/Main/Component/UI/Common/BossLifeBar.cs b/Main/Component/UI/Common/BossLifeBar.cs
index 7634fcd..ebe96d3 100644
--- a/Main/Component/UI/Common/BossLifeBar.cs
+++ b/Main/Component/UI/Common/BossLifeBar.cs
@@ -44,8 +44,10 @@
         set {
             m_CurrentBehaviourValue = value;
             UpdateSurplusSegments(currentBehaviourValue);
-            var behaviourDecimalValue = m_CurrentBehaviourValue - (int)m_CurrentBehaviourValue;
-            var trueDecimalValue = targetValue - (int)targetValue;
+
+            float behaviourDecimalValue = GetSegmentDecimal(m_CurrentBehaviourValue);
+            float trueDecimalValue = GetSegmentDecimal(targetValue);
+
             switch (pattern)
             {
                 case Pattern.Add:
@@ -54,7 +56,7 @@
                     break;
                 case Pattern.Reduce:
                     m_SliderMiddleground.value = behaviourDecimalValue;
-                    m_SliderForeground.value = behaviourDecimalValue < trueDecimalValue ? 0 : trueDecimalValue;
+                    m_SliderForeground.value = behaviourDecimalValue < trueDecimalValue ? 0f : trueDecimalValue;
                     break;
                 case Pattern.None:
                     m_SliderMiddleground.value = behaviourDecimalValue;
@@ -64,24 +66,29 @@
         }
     }
 
-    public void SetBaseInfo(int _npcId, ulong _hp, ulong _maxHp, int _level)
+    public void SetBaseInfo(int _lifeBarCount, ulong _hp, ulong _maxHp)
     {
-        var npcConfig = NPCConfig.Get(_npcId);
-        HeroSkinConfig skinConfig = HeroSkinConfig.Get(npcConfig.SkinID);
-
         surplusSegments = -1;
-        totalSegments = npcConfig.LifeBarCount;
-        targetValue = currentBehaviourValue = ((float)_hp / _maxHp) * totalSegments - 0.0001f;
-        var behaviourDecimalValue = currentBehaviourValue - (int)currentBehaviourValue;
+        totalSegments = _lifeBarCount;
+
+        // 浣跨敤绮剧‘鍊硷紝涓嶅啀浜轰负鍑忓皬
+        float percentage = (_maxHp > 0) ? (float)_hp / (float)_maxHp : 0f;
+        targetValue = currentBehaviourValue = percentage * totalSegments;
+
+        // 浣跨敤缁熶竴鐨� GetSegmentDecimal锛岄伩鍏嶅皬鏁扮簿搴﹀鑷磋繘搴︽潯涓�0
+        var behaviourDecimalValue = GetSegmentDecimal(currentBehaviourValue);
         m_SliderForeground.value = m_SliderMiddleground.value = behaviourDecimalValue;
 
         refValue = 0f;
+
+        // 绔嬪埢鏄剧ず鍩哄噯鐧惧垎姣旓紙浣跨敤 percentage锛�
+        m_SurplusPercent.text = (percentage * 100f).ToString("F2") + "%";
     }
 
     public void Show(ulong _hp, ulong _maxHp)
     {
         var percentage = Mathf.Clamp(_hp, 0, _maxHp) / (float)_maxHp;
-        var tempValue = totalSegments * percentage - 0.00001f;
+        var tempValue = totalSegments * percentage; // 涓嶅啀鍑忓皬
         pattern = tempValue > targetValue ? Pattern.Add : tempValue < targetValue ? Pattern.Reduce : Pattern.None;
 
         behaviourStartValue = currentBehaviourValue;
@@ -89,6 +96,9 @@
 
         timer = 0f;
         refValue = 0f;
+
+        // 绔嬪嵆鏇存柊鐧惧垎姣旀樉绀猴紙鐩存帴浣跨敤 percentage锛�
+        m_SurplusPercent.text = (percentage * 100f).ToString("F2") + "%";
     }
 
     private void LateUpdate()
@@ -117,19 +127,11 @@
 
             m_BackGround.SetActive(surplusSegments > 1);
 
-            // var chars = surplusSegments.ToString();
-            // stringBuild.Remove(0, stringBuild.Length);
-            // for (var i = 0; i < chars.Length; i++)
-            // {
-            //     var numChar = GetNumKey(chars[i]);
-            //     if (numChar > 0)
-            //     {
-            //         stringBuild.Append((char)numChar);
-            //     }
-            // }
-
-            m_Surplus.text = surplusSegments.ToString();
-            m_SurplusPercent.text = Mathf.CeilToInt((_targetValue / totalSegments) * 100f).ToString() + "%";
+            m_Surplus.text = "x" + surplusSegments.ToString();
+            float pct = totalSegments > 0 ? Mathf.Clamp01(_targetValue / totalSegments) : 0f;
+            // 淇鏍煎紡骞跺鐞嗘帴杩� 100% 鐨勬儏鍐�
+            if (1f - pct < 0.00005f) pct = 1f;
+            m_SurplusPercent.text = (pct * 100f).ToString("F2") + "%";
         }
     }
 
@@ -147,6 +149,23 @@
         Reduce,
     }
 
+    // helper: 杩斿洖娈靛唴灏忔暟閮ㄥ垎锛涘綋鎭板ソ涓烘暣鏁颁笖澶т簬0鏃讹紝杩斿洖1浠ヨ〃绀烘弧鏍硷紙閬垮厤0瀵艰嚧杩涘害鏉″彉绌猴級
+    private float GetSegmentDecimal(float value)
+    {
+        if (value <= 0f) return 0f;
+
+        // 浣跨敤涓�涓皬鐨勫蹇嶅�兼潵澶勭悊娴偣璇樊锛岄伩鍏� near-integer 瀵艰嚧 0
+        const float eps = 1e-5f;
+
+        // 鍏堝仛涓�涓悜涓嬬ǔ瀹氱殑 floor锛岄伩鍏� 2.999999 鍙樻垚 2 鐨勯棶棰�
+        float stableFloor = Mathf.Floor(value + eps);
+        float frac = value - stableFloor;
+
+        if (frac <= eps)
+            return 1f; // 瑙嗕负鏁存锛屾樉绀烘弧鏍�
+        return Mathf.Clamp01(frac);
+    }
+
 }
 
 

--
Gitblit v1.8.0