Skip to content

Commit 3ae1407

Browse files
committed
v1.3.2: fixed various inconsistencies with controller tooltip prompts
1 parent cad7c0e commit 3ae1407

File tree

9 files changed

+61
-12
lines changed

9 files changed

+61
-12
lines changed

SPD-classes/src/main/java/com/watabou/input/ControllerHandler.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public enum ControllerType {
4242
}
4343

4444
public static ControllerType lastUsedType = ControllerType.OTHER;
45+
public static boolean controllerActive = false;
4546

4647
private static void setControllerType(Controller controller){
4748
if (controller.getName().contains("Xbox")){
@@ -69,6 +70,7 @@ public static boolean isControllerConnected(){
6970

7071
@Override
7172
public void connected(Controller controller) {
73+
controllerActive = true;
7274
setControllerType(controller);
7375
}
7476

@@ -80,6 +82,7 @@ public void disconnected(Controller controller) {
8082
@Override
8183
public boolean buttonDown(Controller controller, int buttonCode) {
8284
setControllerType(controller);
85+
controllerActive = true;
8386
int keyCode = buttonToKey(controller, buttonCode);
8487
if (keyCode != Input.Keys.UNKNOWN){
8588
KeyEvent.addKeyEvent(new KeyEvent(keyCode, true));
@@ -91,6 +94,7 @@ public boolean buttonDown(Controller controller, int buttonCode) {
9194
@Override
9295
public boolean buttonUp(Controller controller, int buttonCode) {
9396
setControllerType(controller);
97+
controllerActive = true;
9498
int keyCode = buttonToKey(controller, buttonCode);
9599
if (keyCode != Input.Keys.UNKNOWN){
96100
KeyEvent.addKeyEvent(new KeyEvent(keyCode, false));
@@ -120,17 +124,21 @@ else if (axisCode == 4) {
120124

121125
if (L2Trigger < 0.5f && value >= 0.5f){
122126
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_L2, true));
127+
controllerActive = true;
123128
} else if (L2Trigger >= 0.5f && value < 0.5f){
124129
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_L2, false));
130+
controllerActive = true;
125131
}
126132
L2Trigger = value;
127133

128134
} else if (axisCode == 5){
129135

130136
if (R2Trigger < 0.5f && value >= 0.5f){
131137
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_R2, true));
138+
controllerActive = true;
132139
} else if (R2Trigger >= 0.5f && value < 0.5f){
133140
KeyEvent.addKeyEvent(new KeyEvent(Input.Keys.BUTTON_R2, false));
141+
controllerActive = true;
134142
}
135143
R2Trigger = value;
136144

@@ -143,6 +151,7 @@ else if (axisCode == 4) {
143151
private static PointF controllerPointerPos;
144152

145153
public static void setControllerPointer( boolean active ){
154+
if (active) controllerActive = true;
146155
if (controllerPointerActive == active) return;
147156
controllerPointerActive = active;
148157
if (active){
@@ -164,6 +173,7 @@ public static PointF getControllerPointerPos(){
164173
public static void updateControllerPointer(PointF pos, boolean sendEvent){
165174
controllerPointerPos.set(pos);
166175
if (sendEvent) {
176+
controllerActive = true;
167177
PointerEvent.addPointerEvent(new PointerEvent((int) controllerPointerPos.x, (int) controllerPointerPos.y, 10_000, PointerEvent.Type.HOVER, PointerEvent.NONE));
168178
}
169179
}
@@ -211,9 +221,9 @@ public static boolean icControllerKey(int keyCode){
211221
public static String customButtonName(int keyCode){
212222
if (lastUsedType == ControllerType.PLAYSTATION){
213223
if (keyCode == Input.Keys.BUTTON_A){
214-
return "Circle Button";
215-
} else if (keyCode == Input.Keys.BUTTON_B){
216224
return "Cross Button";
225+
} else if (keyCode == Input.Keys.BUTTON_B){
226+
return "Circle Button";
217227
} else if (keyCode == Input.Keys.BUTTON_X){
218228
return "Square Button";
219229
} else if (keyCode == Input.Keys.BUTTON_Y){

SPD-classes/src/main/java/com/watabou/input/InputHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void processAllEvents(){
9191
@Override
9292
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
9393
ControllerHandler.setControllerPointer(false);
94+
ControllerHandler.controllerActive = false;
9495
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
9596

9697
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {

SPD-classes/src/main/java/com/watabou/input/KeyBindings.java

-2
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ public static int getFirstKeyForAction(GameAction action, boolean preferControll
8787
ArrayList<Integer> buttons = getControllerKeysForAction(action);
8888
if (preferController){
8989
if (!buttons.isEmpty()) return buttons.get(0);
90-
else if (!keys.isEmpty()) return keys.get(0);
9190
} else {
9291
if (!keys.isEmpty()) return keys.get(0);
93-
else if (!buttons.isEmpty()) return buttons.get(0);
9492
}
9593
return 0;
9694
}

core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Button.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ protected void onClick( PointerEvent event ) {
8383
protected void onHoverStart(PointerEvent event) {
8484
String text = hoverText();
8585
if (text != null){
86+
int key = 0;
8687
if (keyAction() != null){
87-
int key = KeyBindings.getFirstKeyForAction(keyAction(), ControllerHandler.controllerPointerActive());
88-
if (key != 0){
89-
text += " _(" + KeyBindings.getKeyName(key) + ")_";
90-
}
88+
key = KeyBindings.getFirstKeyForAction(keyAction(), ControllerHandler.controllerActive);
89+
}
90+
91+
if (key == 0 && secondaryTooltipAction() != null){
92+
key = KeyBindings.getFirstKeyForAction(secondaryTooltipAction(), ControllerHandler.controllerActive);
93+
}
94+
95+
if (key != 0){
96+
text += " _(" + KeyBindings.getKeyName(key) + ")_";
9197
}
9298
hoverTip = new Tooltip(Button.this, text, 80);
9399
Button.this.parent.addToFront(hoverTip);
@@ -129,6 +135,11 @@ public boolean onSignal ( KeyEvent event ) {
129135
public GameAction keyAction(){
130136
return null;
131137
}
138+
139+
//used in cases where the main key action isn't bound, but a secondary action can be used for the tooltip
140+
public GameAction secondaryTooltipAction(){
141+
return null;
142+
}
132143

133144
@Override
134145
public void update() {

core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java

+5
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ public GameAction keyAction() {
638638
}
639639
}
640640

641+
@Override
642+
public GameAction secondaryTooltipAction() {
643+
return SPDAction.INVENTORY_SELECTOR;
644+
}
645+
641646
@Override
642647
protected String hoverText() {
643648
if (bag != null) {

core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ protected void onClick() {
5959
public GameAction keyAction() {
6060
return SPDAction.TAG_LOOT;
6161
}
62+
63+
@Override
64+
public GameAction secondaryTooltipAction() {
65+
return SPDAction.WAIT_OR_PICKUP;
66+
}
6267
};
6368
slot.showExtraInfo( false );
6469
add( slot );

core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java

+9
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public GameAction keyAction() {
119119
return QuickSlotButton.this.keyAction();
120120
}
121121
@Override
122+
public GameAction secondaryTooltipAction(){
123+
return QuickSlotButton.this.secondaryTooltipAction();
124+
}
125+
@Override
122126
protected boolean onLongClick() {
123127
return QuickSlotButton.this.onLongClick();
124128
}
@@ -190,6 +194,11 @@ public GameAction keyAction() {
190194
}
191195
}
192196

197+
@Override
198+
public GameAction secondaryTooltipAction() {
199+
return SPDAction.QUICKSLOT_SELECTOR;
200+
}
201+
193202
@Override
194203
protected String hoverText() {
195204
if (slot.item == null){

core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected void onClick() {
135135
}
136136

137137
String info = "";
138-
if (ControllerHandler.controllerPointerActive()){
138+
if (ControllerHandler.controllerActive){
139139
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_select") + "\n";
140140
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_assign") + "\n";
141141
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, true)) + ": " + Messages.get(Toolbar.class, "quickslot_cancel");
@@ -208,6 +208,11 @@ public GameAction keyAction() {
208208
return SPDAction.WAIT;
209209
}
210210

211+
@Override
212+
public GameAction secondaryTooltipAction() {
213+
return SPDAction.WAIT_OR_PICKUP;
214+
}
215+
211216
@Override
212217
protected String hoverText() {
213218
return Messages.titleCase(Messages.get(WndKeyBindings.class, "wait"));
@@ -323,6 +328,11 @@ public GameAction keyAction() {
323328
return SPDAction.INVENTORY;
324329
}
325330

331+
@Override
332+
public GameAction secondaryTooltipAction() {
333+
return SPDAction.INVENTORY_SELECTOR;
334+
}
335+
326336
@Override
327337
protected String hoverText() {
328338
return Messages.titleCase(Messages.get(WndKeyBindings.class, "inventory"));
@@ -371,7 +381,7 @@ protected void onClick() {
371381
images[i] = new ItemSprite(bags.get(i));
372382
}
373383
String info = "";
374-
if (ControllerHandler.controllerPointerActive()){
384+
if (ControllerHandler.controllerActive){
375385
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "container_select") + "\n";
376386
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, true)) + ": " + Messages.get(Toolbar.class, "container_cancel");
377387
} else {
@@ -413,7 +423,7 @@ public void onSelect(int idx, boolean alt) {
413423
}
414424

415425
String info = "";
416-
if (ControllerHandler.controllerPointerActive()){
426+
if (ControllerHandler.controllerActive){
417427
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.LEFT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_select") + "\n";
418428
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.RIGHT_CLICK, true)) + ": " + Messages.get(Toolbar.class, "item_use") + "\n";
419429
info += KeyBindings.getKeyName(KeyBindings.getFirstKeyForAction(GameAction.BACK, false)) + ": " + Messages.get(Toolbar.class, "item_cancel");

core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected void select(boolean value) {
113113
if (DeviceCompat.hasHardKeyboard() || ControllerHandler.isControllerConnected()) {
114114
add( input );
115115
Image icon;
116-
if (ControllerHandler.controllerPointerActive() || !DeviceCompat.hasHardKeyboard()){
116+
if (ControllerHandler.controllerActive || !DeviceCompat.hasHardKeyboard()){
117117
icon = Icons.get(Icons.CONTROLLER);
118118
} else {
119119
icon = Icons.get(Icons.KEYBOARD);

0 commit comments

Comments
 (0)