v1.2.0: added hover tooltips to buttons!

This commit is contained in:
Evan Debenham 2022-02-08 23:24:46 -05:00
parent eaffb9f6e4
commit e95b791b26
34 changed files with 317 additions and 86 deletions

View File

@ -1,51 +0,0 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2022 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.noosa.ui;
public class CheckBox extends Button {
protected boolean checked;
public boolean checked() {
return checked;
}
public void checked( boolean value ) {
if (checked != value) {
checked = value;
updateState();
}
}
protected void updateState() {
}
@Override
protected void onClick() {
checked( !checked );
onChange();
}
protected void onChange() {
}
}

View File

@ -40,8 +40,7 @@ import com.shatteredpixel.shatteredpixeldungeon.services.news.NewsImpl;
import com.shatteredpixel.shatteredpixeldungeon.services.updates.UpdateImpl;
import com.shatteredpixel.shatteredpixeldungeon.services.updates.Updates;
import com.watabou.noosa.Game;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.DeviceCompat;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.utils.FileUtils;
public class AndroidGame extends AndroidApplication {

View File

@ -35,6 +35,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.LiquidMetal;
import com.shatteredpixel.shatteredpixeldungeon.items.Recipe;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.AlchemistsToolkit;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.journal.Journal;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
@ -231,6 +232,11 @@ public class AlchemyScene extends PixelScene {
});
}
@Override
protected String hoverText() {
return Messages.titleCase(Document.ALCHEMY_GUIDE.title());
}
};
btnGuide.setRect(0, 0, 20, 20);
add(btnGuide);

View File

@ -391,6 +391,10 @@ public class GameScene extends PixelScene {
log.newLine();
add( log );
if (uiSize > 0){
bringToFront(status);
}
toolbar = new Toolbar();
toolbar.camera = uiCamera;
add( toolbar );

View File

@ -40,6 +40,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.StyledButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndChallenges;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHeroInfo;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
import com.watabou.gltextures.TextureCache;
import com.watabou.input.PointerEvent;
@ -142,6 +143,11 @@ public class HeroSelectScene extends PixelScene {
super.onClick();
ShatteredPixelDungeon.scene().addToFront(new WndHeroInfo(GamesInProgress.selectedClass));
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "hero_info"));
}
};
infoButton.visible = false;
infoButton.setSize(21, 21);
@ -184,6 +190,11 @@ public class HeroSelectScene extends PixelScene {
}
super.update();
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndChallenges.class, "title"));
}
};
challengeButton.setRect(heroBtnleft + 16, Camera.main.height-HeroBtn.HEIGHT-16, 21, 21);
challengeButton.visible = false;

View File

@ -40,7 +40,7 @@ import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.utils.GameMath;
public class RankingsScene extends PixelScene {

View File

@ -38,7 +38,7 @@ import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import java.util.ArrayList;

View File

@ -23,7 +23,9 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction;
import com.watabou.noosa.Image;
@ -100,6 +102,12 @@ public class ActionIndicator extends Tag {
action.doAction();
}
@Override
protected String hoverText() {
//TODO each special action should probably have its own title
return Messages.titleCase(Messages.get(WndKeyBindings.class, "tag_action"));
}
public static void setAction(Action action){
ActionIndicator.action = action;
updateIcon();

View File

@ -25,8 +25,10 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction;
import com.watabou.noosa.Game;
import com.watabou.utils.Random;
@ -179,8 +181,13 @@ public class AttackIndicator extends Tag {
}
}
}
public static void target( Char target ) {
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "tag_attack"));
}
public static void target(Char target ) {
synchronized (instance) {
instance.lastTarget = (Mob) target;
instance.updateImage();

View File

@ -29,7 +29,6 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Random;
@ -152,6 +151,11 @@ public class BadgesGrid extends Component {
Sample.INSTANCE.play( Assets.Sounds.CLICK, 0.7f, 0.7f, 1.2f );
Game.scene().add( new WndBadge( badge, unlocked ) );
}
@Override
protected String hoverText() {
return badge.desc();
}
}
}

View File

@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
@ -283,6 +284,11 @@ public class BuffIndicator extends Component {
protected void onPointerUp() {
//don't affect buff color
}
@Override
protected String hoverText() {
return Messages.titleCase(buff.toString());
}
}
public static void refreshHero() {

View File

@ -19,21 +19,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.noosa.ui;
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.watabou.input.GameAction;
import com.watabou.input.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Signal;
import java.util.ArrayList;
public class Button extends Component {
public static float longClick = 0.5f;
protected PointerArea hotArea;
protected Tooltip hoverTip;
protected boolean pressed;
protected float pressTime;
@ -60,6 +65,28 @@ public class Button extends Component {
Button.this.onClick();
}
}
@Override
protected void onHoverStart(PointerEvent event) {
String text = hoverText();
if (text != null){
if (keyAction() != null){
ArrayList<Integer> bindings = KeyBindings.getBoundKeysForAction(keyAction());
if (!bindings.isEmpty()){
text += " _(" + KeyBindings.getKeyName(bindings.get(0)) + ")_";
}
}
hoverTip = new Tooltip(text, 80);
Button.this.parent.addToFront(hoverTip);
hoverTip.camera = camera();
alignTooltip(hoverTip);
}
}
@Override
protected void onHoverEnd(PointerEvent event) {
killTooltip();
}
};
add( hotArea );
@ -108,6 +135,31 @@ public class Button extends Component {
protected boolean onLongClick() {
return false;
}
protected String hoverText() {
return null;
}
//TODO might be nice for more flexibility here
private void alignTooltip( Tooltip tip ){
tip.setPos(x, y-tip.height()-1);
Camera cam = camera();
//shift left if there's no room on the right
if (tip.right() > (cam.width+cam.scroll.x)){
tip.setPos(tip.left() - (tip.right() - (cam.width+cam.scroll.x)), tip.top());
}
//move to the bottom if there's no room on top
if (tip.top() < 0){
tip.setPos(tip.left(), bottom()+1);
}
}
public void killTooltip(){
if (hoverTip != null){
hoverTip.killAndErase();
hoverTip = null;
}
}
@Override
protected void layout() {

View File

@ -24,7 +24,9 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
@ -117,4 +119,9 @@ public class DangerIndicator extends Tag {
if (Dungeon.hero.curAction == null) Camera.main.panTo(target.sprite.center(), 5f);
}
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "tag_danger"));
}
}

View File

@ -22,7 +22,9 @@
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.noosa.Game;
public class ExitButton extends IconButton {
@ -42,4 +44,9 @@ public class ExitButton extends IconButton {
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
}
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "back"));
}
}

View File

@ -25,7 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class IconButton extends Button {

View File

@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.PotionBandolier;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
@ -551,6 +552,10 @@ public class InventoryPane extends Component {
refresh();
}
@Override
protected String hoverText() {
return Messages.titleCase(bag.name());
}
}
}

View File

@ -33,7 +33,6 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
public class ItemSlot extends Button {
@ -274,4 +273,10 @@ public class ItemSlot extends Button {
}
}
@Override
protected String hoverText() {
if (item != null) return Messages.titleCase(item.name());
else return super.hoverText();
}
}

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.input.GameAction;
public class LootIndicator extends Tag {

View File

@ -26,17 +26,18 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.watabou.input.GameAction;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
public class MenuPane extends Component {
@ -235,6 +236,10 @@ public class MenuPane extends Component {
}
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "journal"));
}
}
private static class MenuButton extends Button {
@ -279,5 +284,15 @@ public class MenuPane extends Component {
protected void onClick() {
GameScene.show( new WndGame() );
}
@Override
public GameAction keyAction() {
return GameAction.BACK;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "menu"));
}
}
}

View File

@ -33,9 +33,9 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.PathFinder;
public class QuickSlotButton extends Button {
@ -118,6 +118,15 @@ public class QuickSlotButton extends Button {
protected void onPointerUp() {
sprite.resetColor();
}
@Override
protected String hoverText() {
if (item == null){
return Messages.titleCase(Messages.get(WndKeyBindings.class, "quickslot_" + (slotNum+1)));
} else {
return super.hoverText();
}
}
};
slot.showExtraInfo( false );
add( slot );
@ -164,6 +173,15 @@ public class QuickSlotButton extends Button {
return super.keyAction();
}
}
@Override
protected String hoverText() {
if (slot.item == null){
return Messages.titleCase(Messages.get(WndKeyBindings.class, "quickslot_" + (slotNum+1)));
} else {
return super.hoverText();
}
}
@Override
protected void onClick() {

View File

@ -23,7 +23,9 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction;
import com.watabou.noosa.Image;
@ -68,6 +70,11 @@ public class ResumeIndicator extends Tag {
Dungeon.hero.resume();
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "tag_resume"));
}
@Override
public void update() {
if (!Dungeon.hero.isAlive())

View File

@ -28,27 +28,25 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.effects.CircleArc;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction;
import com.watabou.input.KeyBindings;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.ColorMath;
import java.util.ArrayList;
public class StatusPane extends Component {
private NinePatch bg;
@ -104,6 +102,11 @@ public class StatusPane extends Component {
public GameAction keyAction() {
return SPDAction.HERO_INFO;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "hero_info"));
}
};
add(heroInfo);

View File

@ -27,7 +27,6 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
//simple button which support a background chrome, text, and an icon.
public class StyledButton extends Button {

View File

@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.watabou.noosa.Game;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.ui.Button;
public class Tag extends Button {

View File

@ -26,23 +26,16 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.InventoryScroll;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ScrollOfMetamorphosis;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoTalent;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.Callback;
import java.util.LinkedHashMap;
@ -230,7 +223,12 @@ public class TalentButton extends Button {
bg.resetColor();
}
public void enable( boolean value ) {
@Override
protected String hoverText() {
return Messages.titleCase(talent.title());
}
public void enable(boolean value ) {
active = value;
icon.alpha( value ? 1.0f : 0.3f );
bg.alpha( value ? 1.0f : 0.3f );

View File

@ -108,6 +108,10 @@ public class TalentsPane extends ScrollPane {
} else {
blockText = null;
}
for (TalentTierPane p : panes){
content.bringToFront(p);
}
}
@Override

View File

@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuickBag;
import com.watabou.input.GameAction;
import com.watabou.noosa.Camera;
@ -94,7 +95,12 @@ public class Toolbar extends Component {
public GameAction keyAction() {
return SPDAction.WAIT;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "wait"));
}
protected boolean onLongClick() {
if (!GameScene.cancel()) {
examining = false;
@ -133,6 +139,11 @@ public class Toolbar extends Component {
public GameAction keyAction() {
return SPDAction.SEARCH;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "search"));
}
@Override
protected boolean onLongClick() {
@ -159,6 +170,11 @@ public class Toolbar extends Component {
public GameAction keyAction() {
return SPDAction.INVENTORY;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "inventory"));
}
@Override
protected boolean onLongClick() {

View File

@ -0,0 +1,90 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2022 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.GameMath;
public class Tooltip extends Component {
//tooltips require .5 seconds to appear, fade in over .1 second
//they then persist until none are visible for .5 seconds or more
private static float tooltipAlpha = -5f;
private static float lastUsedTime = -1;
private NinePatch bg;
private RenderedTextBlock text;
public Tooltip(String msg, int maxWidth){
super();
text.text(msg, maxWidth);
layout();
if (lastUsedTime != -1){
float elapsed = Game.timeTotal - lastUsedTime;
if (elapsed >= 0.5f || tooltipAlpha < 1f){
tooltipAlpha = -5f;
}
lastUsedTime = Game.timeTotal;
}
bg.alpha(GameMath.gate(0, tooltipAlpha, 1));
text.alpha(GameMath.gate(0, tooltipAlpha, 1));
}
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get(Chrome.Type.TOAST_TR);
add(bg);
text = PixelScene.renderTextBlock(6);
add(text);
}
@Override
public synchronized void update() {
super.update();
tooltipAlpha = Math.min(1f, tooltipAlpha + 10f*Game.elapsed);
lastUsedTime = Game.timeTotal;
bg.alpha(GameMath.gate(0, tooltipAlpha, 1));
text.alpha(GameMath.gate(0, tooltipAlpha, 1));
}
@Override
protected void layout() {
text.setPos(x + bg.marginLeft(), y + bg.marginTop());
bg.x = x;
bg.y = y;
bg.size(text.width()+bg.marginHor(), text.height()+bg.marginVer());
width = bg.width;
height = bg.height;
}
}

View File

@ -380,7 +380,11 @@ public class WndBag extends WndTabbed {
this.bag = bag;
}
@Override
protected String hoverText() {
return Messages.titleCase(bag.name());
}
}
public static class Placeholder extends Item {

View File

@ -37,7 +37,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Game;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.utils.Bundle;
import com.watabou.utils.FileUtils;

View File

@ -149,6 +149,12 @@ public class WndHero extends WndTabbed {
ShatteredPixelDungeon.scene().addToFront(new WndHeroInfo(hero.heroClass));
}
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "hero_info"));
}
};
infoButton.setRect(title.right(), 0, 16, 16);
add(infoButton);

View File

@ -46,7 +46,7 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.noosa.ui.Component;
import java.util.Locale;

View File

@ -45,7 +45,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.DeviceCompat;

View File

@ -30,7 +30,7 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.utils.RectF;
import java.util.ArrayList;
@ -153,6 +153,8 @@ public class WndTabbed extends Window {
protected void select( boolean value ) {
active = !(selected = value);
if (!active) killTooltip();
if (bg != null) {
remove( bg );