v1.3.2: fixed various inconsistencies with controller tooltip prompts

This commit is contained in:
Evan Debenham
2022-07-26 14:52:18 -04:00
parent cad7c0eb87
commit 3ae14078d8
9 changed files with 61 additions and 12 deletions

View File

@@ -42,6 +42,7 @@ public class ControllerHandler implements ControllerListener {
} }
public static ControllerType lastUsedType = ControllerType.OTHER; public static ControllerType lastUsedType = ControllerType.OTHER;
public static boolean controllerActive = false;
private static void setControllerType(Controller controller){ private static void setControllerType(Controller controller){
if (controller.getName().contains("Xbox")){ if (controller.getName().contains("Xbox")){
@@ -69,6 +70,7 @@ public class ControllerHandler implements ControllerListener {
@Override @Override
public void connected(Controller controller) { public void connected(Controller controller) {
controllerActive = true;
setControllerType(controller); setControllerType(controller);
} }
@@ -80,6 +82,7 @@ public class ControllerHandler implements ControllerListener {
@Override @Override
public boolean buttonDown(Controller controller, int buttonCode) { public boolean buttonDown(Controller controller, int buttonCode) {
setControllerType(controller); setControllerType(controller);
controllerActive = true;
int keyCode = buttonToKey(controller, buttonCode); int keyCode = buttonToKey(controller, buttonCode);
if (keyCode != Input.Keys.UNKNOWN){ if (keyCode != Input.Keys.UNKNOWN){
KeyEvent.addKeyEvent(new KeyEvent(keyCode, true)); KeyEvent.addKeyEvent(new KeyEvent(keyCode, true));
@@ -91,6 +94,7 @@ public class ControllerHandler implements ControllerListener {
@Override @Override
public boolean buttonUp(Controller controller, int buttonCode) { public boolean buttonUp(Controller controller, int buttonCode) {
setControllerType(controller); setControllerType(controller);
controllerActive = true;
int keyCode = buttonToKey(controller, buttonCode); int keyCode = buttonToKey(controller, buttonCode);
if (keyCode != Input.Keys.UNKNOWN){ if (keyCode != Input.Keys.UNKNOWN){
KeyEvent.addKeyEvent(new KeyEvent(keyCode, false)); KeyEvent.addKeyEvent(new KeyEvent(keyCode, false));
@@ -120,8 +124,10 @@ public class ControllerHandler implements ControllerListener {
if (L2Trigger < 0.5f && value >= 0.5f){ if (L2Trigger < 0.5f && value >= 0.5f){
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_L2, true)); KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_L2, true));
controllerActive = true;
} else if (L2Trigger >= 0.5f && value < 0.5f){ } else if (L2Trigger >= 0.5f && value < 0.5f){
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_L2, false)); KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_L2, false));
controllerActive = true;
} }
L2Trigger = value; L2Trigger = value;
@@ -129,8 +135,10 @@ public class ControllerHandler implements ControllerListener {
if (R2Trigger < 0.5f && value >= 0.5f){ if (R2Trigger < 0.5f && value >= 0.5f){
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_R2, true)); KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_R2, true));
controllerActive = true;
} else if (R2Trigger >= 0.5f && value < 0.5f){ } else if (R2Trigger >= 0.5f && value < 0.5f){
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_R2, false)); KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_R2, false));
controllerActive = true;
} }
R2Trigger = value; R2Trigger = value;
@@ -143,6 +151,7 @@ public class ControllerHandler implements ControllerListener {
private static PointF controllerPointerPos; private static PointF controllerPointerPos;
public static void setControllerPointer( boolean active ){ public static void setControllerPointer( boolean active ){
if (active) controllerActive = true;
if (controllerPointerActive == active) return; if (controllerPointerActive == active) return;
controllerPointerActive = active; controllerPointerActive = active;
if (active){ if (active){
@@ -164,6 +173,7 @@ public class ControllerHandler implements ControllerListener {
public static void updateControllerPointer(PointF pos, boolean sendEvent){ public static void updateControllerPointer(PointF pos, boolean sendEvent){
controllerPointerPos.set(pos); controllerPointerPos.set(pos);
if (sendEvent) { if (sendEvent) {
controllerActive = true;
PointerEvent.addPointerEvent(new PointerEvent((int) controllerPointerPos.x, (int) controllerPointerPos.y, 10_000, PointerEvent.Type.HOVER, PointerEvent.NONE)); PointerEvent.addPointerEvent(new PointerEvent((int) controllerPointerPos.x, (int) controllerPointerPos.y, 10_000, PointerEvent.Type.HOVER, PointerEvent.NONE));
} }
} }
@@ -211,9 +221,9 @@ public class ControllerHandler implements ControllerListener {
public static String customButtonName(int keyCode){ public static String customButtonName(int keyCode){
if (lastUsedType == ControllerType.PLAYSTATION){ if (lastUsedType == ControllerType.PLAYSTATION){
if (keyCode == Input.Keys.BUTTON_A){ if (keyCode == Input.Keys.BUTTON_A){
return "Circle Button";
} else if (keyCode == Input.Keys.BUTTON_B){
return "Cross Button"; return "Cross Button";
} else if (keyCode == Input.Keys.BUTTON_B){
return "Circle Button";
} else if (keyCode == Input.Keys.BUTTON_X){ } else if (keyCode == Input.Keys.BUTTON_X){
return "Square Button"; return "Square Button";
} else if (keyCode == Input.Keys.BUTTON_Y){ } else if (keyCode == Input.Keys.BUTTON_Y){

View File

@@ -91,6 +91,7 @@ public class InputHandler extends InputAdapter {
@Override @Override
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) { public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
ControllerHandler.setControllerPointer(false); ControllerHandler.setControllerPointer(false);
ControllerHandler.controllerActive = false;
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) { if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {

View File

@@ -87,10 +87,8 @@ public class KeyBindings {
ArrayList<Integer> buttons = getControllerKeysForAction(action); ArrayList<Integer> buttons = getControllerKeysForAction(action);
if (preferController){ if (preferController){
if (!buttons.isEmpty()) return buttons.get(0); if (!buttons.isEmpty()) return buttons.get(0);
else if (!keys.isEmpty()) return keys.get(0);
} else { } else {
if (!keys.isEmpty()) return keys.get(0); if (!keys.isEmpty()) return keys.get(0);
else if (!buttons.isEmpty()) return buttons.get(0);
} }
return 0; return 0;
} }

View File

@@ -83,11 +83,17 @@ public class Button extends Component {
protected void onHoverStart(PointerEvent event) { protected void onHoverStart(PointerEvent event) {
String text = hoverText(); String text = hoverText();
if (text != null){ if (text != null){
int key = 0;
if (keyAction() != null){ if (keyAction() != null){
int key = KeyBindings.getFirstKeyForAction(keyAction(), ControllerHandler.controllerPointerActive()); key = KeyBindings.getFirstKeyForAction(keyAction(), ControllerHandler.controllerActive);
if (key != 0){ }
text += " _(" + KeyBindings.getKeyName(key) + ")_";
} if (key == 0 && secondaryTooltipAction() != null){
key = KeyBindings.getFirstKeyForAction(secondaryTooltipAction(), ControllerHandler.controllerActive);
}
if (key != 0){
text += " _(" + KeyBindings.getKeyName(key) + ")_";
} }
hoverTip = new Tooltip(Button.this, text, 80); hoverTip = new Tooltip(Button.this, text, 80);
Button.this.parent.addToFront(hoverTip); Button.this.parent.addToFront(hoverTip);
@@ -129,6 +135,11 @@ public class Button extends Component {
public GameAction keyAction(){ public GameAction keyAction(){
return null; return null;
} }
//used in cases where the main key action isn't bound, but a secondary action can be used for the tooltip
public GameAction secondaryTooltipAction(){
return null;
}
@Override @Override
public void update() { public void update() {

View File

@@ -638,6 +638,11 @@ public class InventoryPane extends Component {
} }
} }
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.INVENTORY_SELECTOR;
}
@Override @Override
protected String hoverText() { protected String hoverText() {
if (bag != null) { if (bag != null) {

View File

@@ -59,6 +59,11 @@ public class LootIndicator extends Tag {
public GameAction keyAction() { public GameAction keyAction() {
return SPDAction.TAG_LOOT; return SPDAction.TAG_LOOT;
} }
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.WAIT_OR_PICKUP;
}
}; };
slot.showExtraInfo( false ); slot.showExtraInfo( false );
add( slot ); add( slot );

View File

@@ -119,6 +119,10 @@ public class QuickSlotButton extends Button {
return QuickSlotButton.this.keyAction(); return QuickSlotButton.this.keyAction();
} }
@Override @Override
public GameAction secondaryTooltipAction(){
return QuickSlotButton.this.secondaryTooltipAction();
}
@Override
protected boolean onLongClick() { protected boolean onLongClick() {
return QuickSlotButton.this.onLongClick(); return QuickSlotButton.this.onLongClick();
} }
@@ -190,6 +194,11 @@ public class QuickSlotButton extends Button {
} }
} }
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.QUICKSLOT_SELECTOR;
}
@Override @Override
protected String hoverText() { protected String hoverText() {
if (slot.item == null){ if (slot.item == null){

View File

@@ -135,7 +135,7 @@ public class Toolbar extends Component {
} }
String info = ""; String info = "";
if (ControllerHandler.controllerPointerActive()){ if (ControllerHandler.controllerActive){
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_select") + "\n"; info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_select") + "\n";
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_assign") + "\n"; info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_assign") + "\n";
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_cancel"); info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_cancel");
@@ -208,6 +208,11 @@ public class Toolbar extends Component {
return SPDAction.WAIT; return SPDAction.WAIT;
} }
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.WAIT_OR_PICKUP;
}
@Override @Override
protected String hoverText() { protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "wait")); return Messages.titleCase(Messages.get(WndKeyBindings.class, "wait"));
@@ -323,6 +328,11 @@ public class Toolbar extends Component {
return SPDAction.INVENTORY; return SPDAction.INVENTORY;
} }
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.INVENTORY_SELECTOR;
}
@Override @Override
protected String hoverText() { protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "inventory")); return Messages.titleCase(Messages.get(WndKeyBindings.class, "inventory"));
@@ -371,7 +381,7 @@ public class Toolbar extends Component {
images[i] = new ItemSprite(bags.get(i)); images[i] = new ItemSprite(bags.get(i));
} }
String info = ""; String info = "";
if (ControllerHandler.controllerPointerActive()){ if (ControllerHandler.controllerActive){
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "container_select") + "\n"; info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "container_select") + "\n";
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, true)) + ": " + Messages.get(Toolbar.class, "container_cancel"); info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, true)) + ": " + Messages.get(Toolbar.class, "container_cancel");
} else { } else {
@@ -413,7 +423,7 @@ public class Toolbar extends Component {
} }
String info = ""; String info = "";
if (ControllerHandler.controllerPointerActive()){ if (ControllerHandler.controllerActive){
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_select") + "\n"; info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_select") + "\n";
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_use") + "\n"; info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_use") + "\n";
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, false)) + ": " + Messages.get(Toolbar.class, "item_cancel"); info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, false)) + ": " + Messages.get(Toolbar.class, "item_cancel");

View File

@@ -113,7 +113,7 @@ public class WndSettings extends WndTabbed {
if (DeviceCompat.hasHardKeyboard() || ControllerHandler.isControllerConnected()) { if (DeviceCompat.hasHardKeyboard() || ControllerHandler.isControllerConnected()) {
add( input ); add( input );
Image icon; Image icon;
if (ControllerHandler.controllerPointerActive() || !DeviceCompat.hasHardKeyboard()){ if (ControllerHandler.controllerActive || !DeviceCompat.hasHardKeyboard()){
icon = Icons.get(Icons.CONTROLLER); icon = Icons.get(Icons.CONTROLLER);
} else { } else {
icon = Icons.get(Icons.KEYBOARD); icon = Icons.get(Icons.KEYBOARD);