v1.2.1: fixed cases of tooltips not disappearing when buttons do
This commit is contained in:
parent
19c0e8e4cf
commit
8ce89a7e24
|
@ -99,7 +99,7 @@ public class Button extends Component {
|
||||||
text += " _(" + KeyBindings.getKeyName(key) + ")_";
|
text += " _(" + KeyBindings.getKeyName(key) + ")_";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hoverTip = new Tooltip(text, 80);
|
hoverTip = new Tooltip(Button.this, text, 80);
|
||||||
Button.this.parent.addToFront(hoverTip);
|
Button.this.parent.addToFront(hoverTip);
|
||||||
hoverTip.camera = camera();
|
hoverTip.camera = camera();
|
||||||
alignTooltip(hoverTip);
|
alignTooltip(hoverTip);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.NinePatch;
|
import com.watabou.noosa.NinePatch;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
import com.watabou.utils.GameMath;
|
import com.watabou.utils.GameMath;
|
||||||
|
import com.watabou.utils.RectF;
|
||||||
|
|
||||||
public class Tooltip extends Component {
|
public class Tooltip extends Component {
|
||||||
|
|
||||||
|
@ -40,14 +41,20 @@ public class Tooltip extends Component {
|
||||||
tooltipAlpha = -5;
|
tooltipAlpha = -5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Component parent;
|
||||||
|
private RectF parentDims;
|
||||||
|
|
||||||
private NinePatch bg;
|
private NinePatch bg;
|
||||||
private RenderedTextBlock text;
|
private RenderedTextBlock text;
|
||||||
|
|
||||||
public Tooltip(String msg, int maxWidth){
|
public Tooltip(Component parent, String msg, int maxWidth){
|
||||||
super();
|
super();
|
||||||
text.text(msg, maxWidth);
|
text.text(msg, maxWidth);
|
||||||
layout();
|
layout();
|
||||||
|
|
||||||
|
this.parent = parent;
|
||||||
|
parentDims = new RectF(parent.left(), parent.top(), parent.right(), parent.bottom());
|
||||||
|
|
||||||
if (lastUsedTime == -1 || lastUsedTime > Game.timeTotal){
|
if (lastUsedTime == -1 || lastUsedTime > Game.timeTotal){
|
||||||
tooltipAlpha = -5f;
|
tooltipAlpha = -5f;
|
||||||
|
|
||||||
|
@ -75,6 +82,18 @@ public class Tooltip extends Component {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void update() {
|
public synchronized void update() {
|
||||||
|
//kill this tooltip if the parent is removed or moved in any way
|
||||||
|
if (!parent.exists ||
|
||||||
|
!parent.isActive() ||
|
||||||
|
!parent.isVisible() ||
|
||||||
|
parentDims.left != parent.left() ||
|
||||||
|
parentDims.top != parent.top() ||
|
||||||
|
parentDims.right != parent.right() ||
|
||||||
|
parentDims.bottom != parent.bottom()){
|
||||||
|
killAndErase();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
super.update();
|
super.update();
|
||||||
tooltipAlpha = Math.min(1f, tooltipAlpha + 10f*Game.elapsed);
|
tooltipAlpha = Math.min(1f, tooltipAlpha + 10f*Game.elapsed);
|
||||||
lastUsedTime = Game.timeTotal;
|
lastUsedTime = Game.timeTotal;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user