From 453e96025c4f78888e11f8da85fbdb78245e23f9 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期一, 29 十二月 2025 02:36:23 +0800
Subject: [PATCH] 351 【内政】红颜系统
---
Main/System/Battle/UIComp/BattleTips.cs | 259 +++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 237 insertions(+), 22 deletions(-)
diff --git a/Main/System/Battle/UIComp/BattleTips.cs b/Main/System/Battle/UIComp/BattleTips.cs
index d1b8e07..1ae840f 100644
--- a/Main/System/Battle/UIComp/BattleTips.cs
+++ b/Main/System/Battle/UIComp/BattleTips.cs
@@ -1,45 +1,260 @@
-
using UnityEngine;
using System;
using UnityEngine.UI;
-public class BattleTips : MonoBehaviour
+public class BattleTips : MonoBehaviour, IBattleFloatingUI
{
- public Vector2 beginPos = Vector2.zero;
- public Vector2 endPos = new Vector2(0, 100);
- public float showTime = 0.4f;
- public float timer = 0f;
-
+ #region Inspector瀛楁
+
+ [Header("UI Components")]
public RectTransform rectTransform;
-
public Text tipText;
+ public Text artText;
+ public Image background;
+ public Image arrowUp;
+ public Image arrowDown;
+ [Header("Floating Config")]
+ [Tooltip("椋樺瓧鍔ㄧ敾閰嶇疆锛岃鍦↖nspector涓嫋鎷借祴鍊�")]
+ public FloatingConfig floatingConfig;
+
+ #endregion
+
+ #region 鍏叡瀛楁
+
public Action OnFinish;
+
+ private bool useBuffColor = false;
+ private bool isDebuff = false;
+
+ #endregion
- public void SetText(string text)
+ #region 绉佹湁瀛楁
+
+ public BattleFloatingUIController controller;
+
+ #endregion
+
+ #region 鍏叡鏂规硶
+
+ public void SetRatio(float speed, float scale)
{
- tipText.text = text;
- rectTransform.anchoredPosition = Vector2.zero;
- timer = 0f;
- gameObject.SetActive(true);
+ EnsureControllerInitialized();
+ controller?.SetRatio(speed, scale);
}
-
- // 涓嶈浣跨敤update
- public void Run()
+ public void SetPosition(Vector2 beginPos, Vector2 endPos)
{
- if (!gameObject.activeSelf)
- return;
+ EnsureControllerInitialized();
+ controller?.SetRuntimePosition(beginPos, endPos);
+ }
+
+ public void SetFloatingConfig(FloatingConfig config)
+ {
+ floatingConfig = config;
+
+ if (controller != null)
+ {
+ controller.SetConfig(config);
+ }
+ else
+ {
+ InitController();
+ }
- if (timer >= showTime)
+ arrowUp.SetActive(false);
+ arrowDown.SetActive(false);
+ }
+
+ public void SetBuffColor(bool useBuff, bool isDebuffBuff)
+ {
+ useBuffColor = useBuff;
+ isDebuff = isDebuffBuff;
+
+ if (useBuffColor && floatingConfig != null)
+ {
+ Color buffColor = isDebuff ? floatingConfig.debuffColor : floatingConfig.gainBuffColor;
+ Color beginColor = new Color(buffColor.r, buffColor.g, buffColor.b, floatingConfig.beginColor.a);
+ Color endColor = new Color(buffColor.r, buffColor.g, buffColor.b, floatingConfig.endColor.a);
+
+ EnsureControllerInitialized();
+ controller?.SetRuntimeColor(beginColor, endColor);
+
+ arrowUp.SetActive(!isDebuff);
+ arrowDown.SetActive(isDebuff);
+ }
+ }
+
+ public void SetText(string text, bool useArtText = false, bool isCrit = false)
+ {
+ EnsureControllerInitialized();
+ SwitchTextDisplay(useArtText, text);
+ Play(isCrit);
+ }
+
+ public void ShowBackground(bool show)
+ {
+ if (background != null)
+ background.enabled = show;
+ }
+
+ #endregion
+
+ #region IBattleFloatingUI鎺ュ彛瀹炵幇
+
+ public void Play(bool isCrit, Action onComplete = null)
+ {
+ EnsureControllerInitialized();
+
+ if (controller == null) return;
+
+ Action combinedCallback = () =>
{
OnFinish?.Invoke();
OnFinish = null;
- gameObject.SetActive(false);
+ onComplete?.Invoke();
+ };
+
+ controller.Play(isCrit, combinedCallback);
+ }
+
+ public void Run()
+ {
+ controller?.Run();
+ }
+
+ public void Stop()
+ {
+ controller?.Stop();
+ }
+
+ public void Resume()
+ {
+ controller?.Resume();
+ }
+
+ #endregion
+
+ #region 绉佹湁鏂规硶
+
+ private void InitController()
+ {
+ if (floatingConfig == null)
+ {
+ Debug.LogError($"[BattleTips] FloatingConfig 鏈厤缃�! GameObject: {gameObject.name}");
return;
}
- rectTransform.anchoredPosition = Vector2.Lerp(beginPos, endPos, timer / showTime);
- timer += Time.deltaTime;
+ controller = new BattleFloatingUIController(
+ rectTransform,
+ gameObject,
+ ApplyColor,
+ floatingConfig
+ );
+
+ SetupArrowAnchors();
}
+
+ private void SetupArrowAnchors()
+ {
+ if (arrowDown != null)
+ {
+ RectTransform arrowRect = arrowDown.rectTransform;
+
+ if (arrowRect.parent != artText.transform)
+ {
+ arrowRect.SetParent(artText.transform, false);
+ }
+
+ arrowRect.anchorMin = new Vector2(1, 0.5f);
+ arrowRect.anchorMax = new Vector2(1, 0.5f);
+ arrowRect.pivot = new Vector2(0, 0.5f);
+ arrowRect.anchoredPosition = new Vector2(20f, 0f);
+ }
+
+ if (arrowUp != null)
+ {
+ RectTransform arrowRect = arrowUp.rectTransform;
+
+ if (arrowRect.parent != artText.transform)
+ {
+ arrowRect.SetParent(artText.transform, false);
+ }
+
+ arrowRect.anchorMin = new Vector2(1, 0.5f);
+ arrowRect.anchorMax = new Vector2(1, 0.5f);
+ arrowRect.pivot = new Vector2(0, 0.5f);
+ arrowRect.anchoredPosition = new Vector2(20f, 0f);
+ }
+ }
+
+ private void EnsureControllerInitialized()
+ {
+ if (controller == null || !controller.IsValid())
+ InitController();
+ }
+
+ private void SwitchTextDisplay(bool useArtText, string text)
+ {
+ if (useArtText)
+ {
+ artText.text = text;
+ tipText.gameObject.SetActive(false);
+ artText.gameObject.SetActive(true);
+ SwitchArrowParent(artText.rectTransform);
+ }
+ else
+ {
+ tipText.text = text;
+ artText.gameObject.SetActive(false);
+ tipText.gameObject.SetActive(true);
+ SwitchArrowParent(tipText.rectTransform);
+ }
+ }
+
+ private void SwitchArrowParent(RectTransform newParent)
+ {
+ if (arrowDown != null && arrowDown.rectTransform.parent != newParent)
+ {
+ arrowDown.rectTransform.SetParent(newParent, false);
+ arrowDown.rectTransform.anchorMin = new Vector2(1, 0.5f);
+ arrowDown.rectTransform.anchorMax = new Vector2(1, 0.5f);
+ arrowDown.rectTransform.pivot = new Vector2(0, 0.5f);
+ arrowDown.rectTransform.anchoredPosition = new Vector2(5, 0);
+ }
+
+ if (arrowUp != null && arrowUp.rectTransform.parent != newParent)
+ {
+ arrowUp.rectTransform.SetParent(newParent, false);
+ arrowUp.rectTransform.anchorMin = new Vector2(1, 0.5f);
+ arrowUp.rectTransform.anchorMax = new Vector2(1, 0.5f);
+ arrowUp.rectTransform.pivot = new Vector2(0, 0.5f);
+ arrowUp.rectTransform.anchoredPosition = new Vector2(5, 0);
+ }
+ }
+
+ private void ApplyTextColor(Color textColor)
+ {
+ if (floatingConfig != null)
+ {
+ Color colorWithAlpha = new Color(
+ textColor.r,
+ textColor.g,
+ textColor.b,
+ floatingConfig.beginColor.a
+ );
+ ApplyColor(colorWithAlpha);
+ }
+ }
+
+ private void ApplyColor(Color color)
+ {
+ if (tipText.gameObject.activeSelf)
+ tipText.color = color;
+
+ if (artText.gameObject.activeSelf)
+ artText.color = color;
+ }
+
+ #endregion
}
\ No newline at end of file
--
Gitblit v1.8.0