Skip to content

Commit 26b7fd2

Browse files
committed
Improve skill slot hover state robustness
Enhances UI stability by ensuring skill slot hover states are safely cleared during panel transitions, slot movement, and drag operations, preventing tooltip artifacts and potential null reference issues for a smoother user experience.
1 parent bf68213 commit 26b7fd2

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

Content/LegendWeapon/HalibutLegend/UI/HalibutUI.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ public override void Update() {
505505

506506
Sengs = Math.Clamp(Sengs, 0f, 1f);
507507

508+
//面板关闭时兜底清除悬停状态
509+
if (Sengs <= 0f) {
510+
SkillSlot.ClearHoveredState();
511+
}
512+
508513
Size = Panel.Size();
509514
int leftWeith = (int)(20 - 200 * (1f - Sengs));
510515
int topHeight = (int)Size.Y;
@@ -563,6 +568,10 @@ public override void Update() {
563568
anySlotHovered = true;
564569
}
565570
}
571+
//兜底:如果HoveredSlot引用了不在主面板列表中的槽位,强制清除
572+
if (SkillSlot.HoveredSlot != null && !halibutUISkillSlots.Contains(SkillSlot.HoveredSlot)) {
573+
SkillSlot.ClearHoveredState();
574+
}
566575
if (!anySlotHovered) {
567576
SkillTooltipPanel.Instance.Hide();//如果没有槽位被悬停,隐藏介绍面板(带延迟)
568577
}
@@ -574,7 +583,7 @@ public override void Update() {
574583
draggingSlot.DrawPosition = new Vector2(dragVisualX, MathHelper.Lerp(draggingSlot.DrawPosition.Y, mouse.Y, 0.5f));
575584

576585
//拖拽时清除悬停状态,防止提示窗口残留
577-
SkillSlot.HoveredSlot = null;
586+
SkillSlot.ClearHoveredState();
578587
SkillTooltipPanel.Instance.ForceHide();
579588

580589
//检测是否悬停在技能库区域,设置高亮
@@ -667,9 +676,10 @@ public void MoveSlotToFront(SkillSlot slot) {
667676
}
668677
halibutUISkillSlots.RemoveAt(idx);
669678
halibutUISkillSlots.Insert(0, slot);
670-
//重新设置出现动画:被移动的放大闪动
679+
//重新设置出现动画:被移动的放大闪动(动画期间不响应悬停)
671680
slot.appearProgress = 0f;
672681
slot.isAppearing = true;
682+
SkillSlot.ClearHoveredState();
673683
//为了视觉平滑, 将滚动偏移重置到0并快速过渡
674684
scrollOffset = 0;
675685
//辅以轻微提示音

Content/LegendWeapon/HalibutLegend/UI/SkillLibraryUI.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ public void MoveToLibrary(SkillSlot slot) {
321321
return;
322322
}
323323

324+
//移除前清除悬停状态,避免引用悬空
325+
if (SkillSlot.HoveredSlot == slot) {
326+
SkillSlot.ClearHoveredState();
327+
}
328+
324329
mainSlots.Remove(slot);
325330
LibrarySlots.Add(slot);
326331

@@ -346,6 +351,11 @@ public void MoveToLibraryWithAnimation(SkillSlot slot, Vector2 startPosition) {
346351
return;
347352
}
348353

354+
//移除前清除悬停状态,避免引用悬空
355+
if (SkillSlot.HoveredSlot == slot) {
356+
SkillSlot.ClearHoveredState();
357+
}
358+
349359
mainSlots.Remove(slot);
350360

351361
//计算目标位置(技能库中的位置)
@@ -394,6 +404,11 @@ public void MoveToMainList(SkillSlot slot) {
394404
return;
395405
}
396406

407+
//移除前清除悬停状态
408+
if (SkillSlot.HoveredSlot == slot) {
409+
SkillSlot.ClearHoveredState();
410+
}
411+
397412
LibrarySlots.Remove(slot);
398413
var mainSlots = player.GetModPlayer<HalibutSave>().halibutUISkillSlots;
399414
mainSlots.Add(slot);
@@ -414,6 +429,11 @@ public void MoveToMainListWithAnimation(SkillSlot slot, Vector2 startPosition) {
414429
return;
415430
}
416431

432+
//移除前清除悬停状态
433+
if (SkillSlot.HoveredSlot == slot) {
434+
SkillSlot.ClearHoveredState();
435+
}
436+
417437
LibrarySlots.Remove(slot);
418438

419439
//计算目标位置(主面板技能列表中的位置)

Content/LegendWeapon/HalibutLegend/UI/SkillSlot.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ internal class SkillSlot : UIHandle, ILocalizedModType
3535
private const int HintDelay = 10;//10帧后出现提示
3636
internal static SkillSlot HoveredSlot;//当前悬停的槽位(供面板调用绘制提示)
3737

38+
/// <summary>
39+
/// 安全清除悬停状态,在任何可能导致HoveredSlot悬空的操作中调用
40+
/// </summary>
41+
internal static void ClearHoveredState() {
42+
if (HoveredSlot != null) {
43+
HoveredSlot.hoverTimer = 0;
44+
HoveredSlot.hintTimer = 0;
45+
HoveredSlot.hoverInMainPage = false;
46+
HoveredSlot = null;
47+
}
48+
}
49+
3850
//拖拽相关字段
3951
internal bool beingDragged;//是否正被拖拽(由面板设置)
4052

@@ -97,6 +109,7 @@ public override void Update() {
97109
!Main.oldKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W)) {
98110
if (FishSkill != null && !beingDragged) {
99111
Vector2 startPos = DrawPosition + Size / 2;
112+
ClearHoveredState();
100113
SkillLibraryUI.Instance?.MoveToLibraryWithAnimation(this, startPos);
101114
}
102115
}
@@ -150,6 +163,11 @@ internal void DrawHint(SpriteBatch spriteBatch) {
150163
if (this != HoveredSlot) {
151164
return;
152165
}
166+
//兜底校验:如果面板已关闭、正在拖拽、或鼠标实际不在此槽位上,强制清除
167+
if (!hoverInMainPage || beingDragged || HalibutUIPanel.Instance.Sengs <= 0f || HalibutUIPanel.Instance.IsDragging) {
168+
ClearHoveredState();
169+
return;
170+
}
153171
if (hintTimer < HintDelay) {
154172
return;
155173
}

0 commit comments

Comments
 (0)