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

View File

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

View File

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

View File

@@ -83,11 +83,17 @@ public class Button extends Component {
protected void onHoverStart(PointerEvent event) {
String text = hoverText();
if (text != null){
int key = 0;
if (keyAction() != null){
int key = KeyBindings.getFirstKeyForAction(keyAction(), ControllerHandler.controllerPointerActive());
if (key != 0){
text += " _(" + KeyBindings.getKeyName(key) + ")_";
}
key = KeyBindings.getFirstKeyForAction(keyAction(), ControllerHandler.controllerActive);
}
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);
Button.this.parent.addToFront(hoverTip);
@@ -129,6 +135,11 @@ public class Button extends Component {
public GameAction keyAction(){
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
public void update() {

View File

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

View File

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

View File

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

View File

@@ -135,7 +135,7 @@ public class Toolbar extends Component {
}
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.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_assign") + "\n";
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;
}
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.WAIT_OR_PICKUP;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "wait"));
@@ -323,6 +328,11 @@ public class Toolbar extends Component {
return SPDAction.INVENTORY;
}
@Override
public GameAction secondaryTooltipAction() {
return SPDAction.INVENTORY_SELECTOR;
}
@Override
protected String hoverText() {
return Messages.titleCase(Messages.get(WndKeyBindings.class, "inventory"));
@@ -371,7 +381,7 @@ public class Toolbar extends Component {
images[i] = new ItemSprite(bags.get(i));
}
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.BACK, true)) + ": " + Messages.get(Toolbar.class, "container_cancel");
} else {
@@ -413,7 +423,7 @@ public class Toolbar extends Component {
}
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.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_use") + "\n";
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()) {
add( input );
Image icon;
if (ControllerHandler.controllerPointerActive() || !DeviceCompat.hasHardKeyboard()){
if (ControllerHandler.controllerActive || !DeviceCompat.hasHardKeyboard()){
icon = Icons.get(Icons.CONTROLLER);
} else {
icon = Icons.get(Icons.KEYBOARD);