From 54ebdcba2f6d4a0af7d35f4547fb71c922a2e55c Mon Sep 17 00:00:00 2001 From: primehunter326 Date: Sun, 23 Oct 2016 01:21:14 -0400 Subject: [PATCH] Fixes issue #2452, tooltips flicker when forced under the mouse This scenario can occur when a tooltip is unable to render in the preferred location due to the screen boundaries, for instance if an item with a really long tooltip is placed in the lower-right most inventory slot. Because UILists define InteractionRegions around their contents by default and tooltips are rendered last, they are seen as the new top-most interactive element on the following game tick. This causes an immediate reset of the tooltip timer due to the top-most region changing, and the process repeats. This has been fixed by preventing tooltips from defining interaction regions through a new optional flag in UIList that sets whether the list is interactive or not. --- .../org/terasology/rendering/nui/widgets/UIList.java | 9 ++++++++- .../rendering/nui/layers/ingame/inventory/ItemIcon.java | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/src/main/java/org/terasology/rendering/nui/widgets/UIList.java b/engine/src/main/java/org/terasology/rendering/nui/widgets/UIList.java index 8a9ef005fab..4b4e0b1a4af 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/widgets/UIList.java +++ b/engine/src/main/java/org/terasology/rendering/nui/widgets/UIList.java @@ -44,6 +44,7 @@ public class UIList extends CoreWidget { private final List itemListeners = Lists.newArrayList(); private final List> activateListeners = Lists.newArrayList(); private final List> selectionListeners = Lists.newArrayList(); + private Binding interactive = new DefaultBinding<>(true); private Binding selectable = new DefaultBinding<>(true); private Binding selection = new DefaultBinding<>(); private Binding> list = new DefaultBinding<>(new ArrayList<>()); @@ -80,7 +81,9 @@ public void onDraw(Canvas canvas) { } else { canvas.setMode(DEFAULT_MODE); } - canvas.addInteractionRegion(listener, itemRenderer.getTooltip(item), itemRegion); + if (isInteractive()) { + canvas.addInteractionRegion(listener, itemRenderer.getTooltip(item), itemRegion); + } } else { canvas.setMode(DISABLED_MODE); } @@ -134,10 +137,14 @@ public void bindSelectable(Binding binding) { selectable = binding; } + public boolean isInteractive() { return interactive.get(); } + public boolean isSelectable() { return selectable.get(); } + public void setInteractive(boolean value) { interactive.set(value); } + public void setSelectable(boolean value) { selectable.set(value); } diff --git a/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/ItemIcon.java b/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/ItemIcon.java index 76a09e6ddf7..d8537fa2e2c 100644 --- a/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/ItemIcon.java +++ b/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/ItemIcon.java @@ -58,6 +58,7 @@ public class ItemIcon extends CoreWidget { public ItemIcon() { tooltip = new UIList<>(); + tooltip.setInteractive(false); tooltip.setSelectable(false); final UISkin defaultSkin = Assets.getSkin("core:itemTooltip").get(); tooltip.setSkin(defaultSkin);