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) + ")_";
|
||||
}
|
||||
}
|
||||
hoverTip = new Tooltip(text, 80);
|
||||
hoverTip = new Tooltip(Button.this, text, 80);
|
||||
Button.this.parent.addToFront(hoverTip);
|
||||
hoverTip.camera = camera();
|
||||
alignTooltip(hoverTip);
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.watabou.noosa.Game;
|
|||
import com.watabou.noosa.NinePatch;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.RectF;
|
||||
|
||||
public class Tooltip extends Component {
|
||||
|
||||
|
@ -40,14 +41,20 @@ public class Tooltip extends Component {
|
|||
tooltipAlpha = -5;
|
||||
}
|
||||
|
||||
private Component parent;
|
||||
private RectF parentDims;
|
||||
|
||||
private NinePatch bg;
|
||||
private RenderedTextBlock text;
|
||||
|
||||
public Tooltip(String msg, int maxWidth){
|
||||
public Tooltip(Component parent, String msg, int maxWidth){
|
||||
super();
|
||||
text.text(msg, maxWidth);
|
||||
layout();
|
||||
|
||||
this.parent = parent;
|
||||
parentDims = new RectF(parent.left(), parent.top(), parent.right(), parent.bottom());
|
||||
|
||||
if (lastUsedTime == -1 || lastUsedTime > Game.timeTotal){
|
||||
tooltipAlpha = -5f;
|
||||
|
||||
|
@ -75,6 +82,18 @@ public class Tooltip extends Component {
|
|||
|
||||
@Override
|
||||
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();
|
||||
tooltipAlpha = Math.min(1f, tooltipAlpha + 10f*Game.elapsed);
|
||||
lastUsedTime = Game.timeTotal;
|
||||
|
|
Loading…
Reference in New Issue
Block a user