diff --git a/Unity/Assets/Scripts/TH1_UI/HintUI/HeroHintPanel.cs b/Unity/Assets/Scripts/TH1_UI/HintUI/HeroHintPanel.cs index 0356593cf..d5222221a 100644 --- a/Unity/Assets/Scripts/TH1_UI/HintUI/HeroHintPanel.cs +++ b/Unity/Assets/Scripts/TH1_UI/HintUI/HeroHintPanel.cs @@ -72,11 +72,25 @@ namespace TH1_UI.HintUI private Canvas _cachedCanvas; private int _pinnedFrame = -1; private bool _embeddedMode; + private bool _libraryBattleMode; + private Image _backgroundImage; + private Color _defaultBackgroundColor; + private bool _hasDefaultBackgroundColor; + private readonly Dictionary _defaultTextColors = new Dictionary(); + private static readonly Color EmbeddedInkColor = new Color(0.25f, 0.23f, 0.42f, 1f); + private static readonly Color EmbeddedSecondaryInkColor = new Color(0.42f, 0.40f, 0.54f, 1f); + private static readonly Color EmbeddedPanelColor = new Color(1f, 1f, 1f, 0f); private void Awake() { _cachedRectTransform = GetComponent(); _cachedCanvas = GetComponentInParent(); + _backgroundImage = GetComponent(); + if (_backgroundImage != null) + { + _defaultBackgroundColor = _backgroundImage.color; + _hasDefaultBackgroundColor = true; + } InitializeButtons(); } @@ -114,21 +128,21 @@ namespace TH1_UI.HintUI }); } - public void SetEmbeddedMode(bool embedded) + public void SetEmbeddedMode(bool embedded, bool libraryBattleMode = false) { _embeddedMode = embedded; + _libraryBattleMode = embedded && libraryBattleMode; UpdatePinState(false); - if (!embedded) return; - - if (CloseButton != null) CloseButton.gameObject.SetActive(false); - if (ClickHint != null) ClickHint.SetActive(false); + if (CloseButton != null) CloseButton.gameObject.SetActive(!embedded && IsPinned); + if (ClickHint != null) ClickHint.SetActive(!embedded); + ApplyEmbeddedVisuals(embedded); var cg = GetComponent(); if (cg != null) { cg.interactable = true; - cg.blocksRaycasts = true; + cg.blocksRaycasts = embedded || IsPinned; } } @@ -164,6 +178,7 @@ namespace TH1_UI.HintUI UpdateSkills(); UpdateActionArea(); UpdateUpgradeSection(); + ApplyEmbeddedVisuals(_embeddedMode); // 强制重建布局,避免动态显隐模块后视觉错乱 LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent()); @@ -232,6 +247,12 @@ namespace TH1_UI.HintUI /// private void UpdateCharInfo() { + if (_libraryBattleMode) + { + UpdateLibraryBattleCharInfo(); + return; + } + if (!Table.Instance.LibraryDataAssets.GetLibraryInfoByGiant(_currentGiantType, out var libraryData)) { if (CharDescSection != null) CharDescSection.SetActive(false); @@ -473,6 +494,72 @@ namespace TH1_UI.HintUI } } + private void UpdateLibraryBattleCharInfo() + { + if (CharDiagSection != null) CharDiagSection.SetActive(false); + if (CharDescSection == null || CharDescText == null) return; + + var unitFullType = new UnitFullType(UnitType.Giant, _currentGiantType, _currentLevel); + if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(unitFullType, out var unitTypeInfo)) + { + CharDescSection.SetActive(false); + return; + } + + CharDescSection.SetActive(!string.IsNullOrEmpty(unitTypeInfo.Desc)); + SetUITextOrRaw(CharDescText, unitTypeInfo.Desc); + } + + private void ApplyEmbeddedVisuals(bool embedded) + { + if (_backgroundImage == null) _backgroundImage = GetComponent(); + if (_backgroundImage != null) + { + if (!_hasDefaultBackgroundColor) + { + _defaultBackgroundColor = _backgroundImage.color; + _hasDefaultBackgroundColor = true; + } + + _backgroundImage.color = embedded ? EmbeddedPanelColor : _defaultBackgroundColor; + _backgroundImage.raycastTarget = !embedded; + } + + if (embedded) + { + SetAllTextColor(EmbeddedInkColor); + SetTextColor(SubtitleText, EmbeddedSecondaryInkColor); + } + else + { + RestoreAllTextColors(); + } + } + + private void SetAllTextColor(Color color) + { + var texts = GetComponentsInChildren(true); + for (int i = 0; i < texts.Length; i++) + { + SetTextColor(texts[i], color); + } + } + + private void SetTextColor(TextMeshProUGUI text, Color color) + { + if (text == null) return; + if (!_defaultTextColors.ContainsKey(text)) _defaultTextColors[text] = text.color; + text.color = color; + } + + private void RestoreAllTextColors() + { + foreach (var pair in _defaultTextColors) + { + if (pair.Key != null) pair.Key.color = pair.Value; + } + } + /// /// 根据固定状态切换 CloseButton / ClickHint 的显隐 /// diff --git a/Unity/Assets/Scripts/TH1_UI/View/Outside/UIOutsideLibraryHeroPanelMono.cs b/Unity/Assets/Scripts/TH1_UI/View/Outside/UIOutsideLibraryHeroPanelMono.cs index d3da74d1c..73be72c5d 100644 --- a/Unity/Assets/Scripts/TH1_UI/View/Outside/UIOutsideLibraryHeroPanelMono.cs +++ b/Unity/Assets/Scripts/TH1_UI/View/Outside/UIOutsideLibraryHeroPanelMono.cs @@ -41,6 +41,8 @@ namespace TH1_UI.View.Outside private const string TabButtonSpritePath = "TH1UI/Common/CommonButton/ItemButtonBG"; private static readonly Color SelectedTabColor = new Color(0.42f, 0.22f, 0.42f, 1f); private static readonly Color NormalTabColor = new Color(1f, 1f, 1f, 0.88f); + private static readonly Color SelectedTabTextColor = Color.white; + private static readonly Color NormalTabTextColor = new Color(0.25f, 0.23f, 0.42f, 1f); private GiantType _currentGiantType = GiantType.None; private HeroHintPanel _battlePanel; @@ -205,7 +207,7 @@ namespace TH1_UI.View.Outside text.text = label; if (Name != null && Name.font != null) text.font = Name.font; text.fontSize = 26f; - text.color = Color.white; + text.color = selected ? SelectedTabTextColor : NormalTabTextColor; text.alignment = TextAlignmentOptions.Center; text.raycastTarget = false; @@ -277,6 +279,8 @@ namespace TH1_UI.View.Outside SetTabVisual(SettingTabBG, tab == HeroPanelTab.Setting); SetTabVisual(BattleTabBG, tab == HeroPanelTab.Battle); + SetTabTextVisual(SettingTabButton, tab == HeroPanelTab.Setting); + SetTabTextVisual(BattleTabButton, tab == HeroPanelTab.Battle); if (tab == HeroPanelTab.Battle) RefreshBattlePanel(); } @@ -287,6 +291,14 @@ namespace TH1_UI.View.Outside image.color = selected ? SelectedTabColor : NormalTabColor; } + private static void SetTabTextVisual(Button button, bool selected) + { + if (button == null) return; + var text = button.GetComponentInChildren(true); + if (text == null) return; + text.color = selected ? SelectedTabTextColor : NormalTabTextColor; + } + private void RefreshBattlePanel() { if (_currentGiantType == GiantType.None || BattleContentRoot == null) return; @@ -301,7 +313,7 @@ namespace TH1_UI.View.Outside _battlePanel = go.GetComponent(); if (_battlePanel == null) return; - _battlePanel.SetEmbeddedMode(true); + _battlePanel.SetEmbeddedMode(true, true); var rect = go.GetComponent(); if (rect != null) { @@ -314,7 +326,7 @@ namespace TH1_UI.View.Outside } _battlePanel.gameObject.SetActive(true); - _battlePanel.SetEmbeddedMode(true); + _battlePanel.SetEmbeddedMode(true, true); _battlePanel.SetHeroInfo(_currentGiantType); }