v1.2.0: implemented emulated mouse clicks via keybinds
This commit is contained in:
parent
a010144551
commit
3a6c4fdeb1
|
@ -54,6 +54,10 @@ public class GameAction {
|
|||
public static final GameAction NONE = new GameAction( "none" );
|
||||
public static final GameAction BACK = new GameAction( "back" );
|
||||
|
||||
public static final GameAction LEFT_CLICK = new GameAction( "left_click" );
|
||||
public static final GameAction RIGHT_CLICK = new GameAction( "right_click" );
|
||||
public static final GameAction MIDDLE_CLICK = new GameAction( "middle_click" );
|
||||
|
||||
public static ArrayList<GameAction> allActions(){
|
||||
return new ArrayList<>(ALL_ACTIONS);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,15 @@ public class KeyEvent {
|
|||
|
||||
public static synchronized void processKeyEvents(){
|
||||
for (KeyEvent k : keyEvents){
|
||||
keySignal.dispatch(k);
|
||||
if (KeyBindings.getActionForKey(k) == GameAction.LEFT_CLICK){
|
||||
PointerEvent.emulateMouseButton(PointerEvent.LEFT, k.pressed);
|
||||
} else if (KeyBindings.getActionForKey(k) == GameAction.RIGHT_CLICK){
|
||||
PointerEvent.emulateMouseButton(PointerEvent.RIGHT, k.pressed);
|
||||
} else if (KeyBindings.getActionForKey(k) == GameAction.MIDDLE_CLICK){
|
||||
PointerEvent.emulateMouseButton(PointerEvent.MIDDLE, k.pressed);
|
||||
} else {
|
||||
keySignal.dispatch(k);
|
||||
}
|
||||
}
|
||||
keyEvents.clear();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ public class PointerEvent {
|
|||
public static final int LEFT = Input.Buttons.LEFT;
|
||||
public static final int RIGHT = Input.Buttons.RIGHT;
|
||||
public static final int MIDDLE = Input.Buttons.MIDDLE;
|
||||
public static final int BACK = Input.Buttons.BACK; //currently unused
|
||||
public static final int FORWARD = Input.Buttons.FORWARD;//currently unused
|
||||
|
||||
public PointF start;
|
||||
public PointF current;
|
||||
|
@ -106,15 +108,43 @@ public class PointerEvent {
|
|||
public static PointF currentHoverPos(){
|
||||
return lastHoverPos.clone();
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void emulateMouseButton( int button, boolean down ){
|
||||
if (down){
|
||||
addPointerEvent(new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, 1000+button, Type.DOWN, button));
|
||||
} else {
|
||||
addPointerEvent(new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, 1000+button, Type.UP, button));
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void addPointerEvent( PointerEvent event ){
|
||||
pointerEvents.add( event );
|
||||
}
|
||||
|
||||
public static synchronized void processPointerEvents(){
|
||||
//handle any hover events separately first as we may need to add drag events
|
||||
boolean hovered = false;
|
||||
for (PointerEvent p : pointerEvents){
|
||||
if (p.type == Type.HOVER){
|
||||
lastHoverPos.set(p.current);
|
||||
pointerSignal.dispatch(p);
|
||||
hovered = true;
|
||||
}
|
||||
}
|
||||
|
||||
//add drag events for any emulated presses
|
||||
if (hovered){
|
||||
for (int i = 1000+LEFT; i <= 1000+FORWARD; i++){
|
||||
if (activePointers.containsKey(i)){
|
||||
addPointerEvent(new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, i, Type.DOWN, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PointerEvent p : pointerEvents){
|
||||
if (p.type == Type.HOVER){
|
||||
continue;
|
||||
}
|
||||
if (activePointers.containsKey(p.id)){
|
||||
PointerEvent existing = activePointers.get(p.id);
|
||||
|
|
|
@ -96,6 +96,9 @@ windows.wndkeybindings.confirm=Confirm
|
|||
windows.wndkeybindings.cancel=Cancel
|
||||
windows.wndkeybindings.none=None
|
||||
windows.wndkeybindings.back=Back
|
||||
windows.wndkeybindings.left_click=Left Click
|
||||
windows.wndkeybindings.right_click=Right Click
|
||||
windows.wndkeybindings.middle_click=Middle Click
|
||||
windows.wndkeybindings.menu=Menu
|
||||
windows.wndkeybindings.hero_info=Hero Info
|
||||
windows.wndkeybindings.journal=Journal
|
||||
|
|
|
@ -39,6 +39,10 @@ public class SPDAction extends GameAction {
|
|||
//--New references to existing actions from GameAction
|
||||
public static final GameAction NONE = GameAction.NONE;
|
||||
public static final GameAction BACK = GameAction.BACK;
|
||||
|
||||
public static final GameAction LEFT_CLICK = GameAction.LEFT_CLICK;
|
||||
public static final GameAction RIGHT_CLICK = GameAction.RIGHT_CLICK;
|
||||
public static final GameAction MIDDLE_CLICK = GameAction.MIDDLE_CLICK;
|
||||
//--
|
||||
|
||||
public static final GameAction N = new SPDAction("n");
|
||||
|
|
|
@ -186,7 +186,7 @@ public class WndKeyBindings extends Window {
|
|||
|
||||
private class BindingItem extends Component {
|
||||
|
||||
private static final int HEIGHT = 12;
|
||||
private static final int HEIGHT = 13;
|
||||
|
||||
private static final int CHANGED = TITLE_COLOR;
|
||||
private static final int DEFAULT = 0xFFFFFF;
|
||||
|
@ -284,13 +284,13 @@ public class WndKeyBindings extends Window {
|
|||
|
||||
actionName.maxWidth((int) (2*width/5));
|
||||
key1Name.maxWidth((int) (width/5) - 2);
|
||||
key2Name.maxWidth((int) (width/5));
|
||||
key3Name.maxWidth((int) (width/5));
|
||||
key2Name.maxWidth((int) (width/5) - 2);
|
||||
key3Name.maxWidth((int) (width/5) - 2);
|
||||
|
||||
actionName.setPos( x, y + (height() - actionName.height())/2);
|
||||
key1Name.setPos(x + 2*width()/5 + 1, y + (height() - key1Name.height())/2);
|
||||
key2Name.setPos(x + 3*width()/5 + 1, y + (height() - key2Name.height())/2);
|
||||
key3Name.setPos(x + 4*width()/5 + 1, y + (height() - key3Name.height())/2);
|
||||
key1Name.setPos(x + 2*width()/5 + 1, y + 0.5f + (height() - key1Name.height())/2f);
|
||||
key2Name.setPos(x + 3*width()/5 + 1, y + 0.5f + (height() - key2Name.height())/2f);
|
||||
key3Name.setPos(x + 4*width()/5 + 1, y + 0.5f + (height() - key3Name.height())/2f);
|
||||
|
||||
sep1.size(width, 1);
|
||||
sep1.x = x;
|
||||
|
@ -312,11 +312,11 @@ public class WndKeyBindings extends Window {
|
|||
private boolean onClick( float x, float y ){
|
||||
if (inside(x, y)){
|
||||
//assigning third key
|
||||
if (x >= this.x + 4*width()/5 && key2 != 0) {
|
||||
if (x >= this.x + 4*width()/5 - 1 && key2 != 0) {
|
||||
ShatteredPixelDungeon.scene().addToFront( new WndChangeBinding(gameAction, this, 3, key3, key1, key2));
|
||||
|
||||
//assigning second key
|
||||
} else if (x >= this.x + 3*width()/5 && key1 != 0) {
|
||||
} else if (x >= this.x + 3*width()/5 - 1 && key1 != 0) {
|
||||
ShatteredPixelDungeon.scene().addToFront( new WndChangeBinding(gameAction, this, 2, key2, key1, key3));
|
||||
|
||||
//assigning first key
|
||||
|
|
Loading…
Reference in New Issue
Block a user