Skip to content

Commit d3ad317

Browse files
committed
Started adding in hot keys for various functions.
1 parent 98991aa commit d3ad317

2 files changed

Lines changed: 100 additions & 57 deletions

File tree

core/src/main/java/emu/jvic/KeyboardMatrix.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ private void noShift() {
311311
vicKeyUp(VicKeys.RIGHT_SHIFT);
312312
}
313313

314+
/**
315+
* Checks if the ALT key is currently down.
316+
*
317+
* @return true if the ALT key is currently down; otherwise false.
318+
*/
319+
public boolean isAltKeyDown() {
320+
return altKeyDown;
321+
}
322+
314323
/**
315324
* Checks if there are any keys whose release processed has been delayed that
316325
* are now able to be processed due to the minimum release time having been

core/src/main/java/emu/jvic/ui/MachineInputProcessor.java

Lines changed: 91 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,19 @@ public MachineInputProcessor(MachineScreen machineScreen, DialogHandler dialogHa
128128
* @param keycode
129129
*/
130130
public boolean keyUp(int keycode) {
131-
if (keycode == Keys.F6) {
132-
if (!machineScreen.getJvicRunner().isWarpSpeed()) {
133-
speakerOn = false;
134-
machineScreen.getJvicRunner().changeSound(false);
131+
boolean altKeyDown = getKeyboardMatrix().isAltKeyDown();
132+
133+
if (altKeyDown) {
134+
switch (keycode) {
135+
case Keys.P:
136+
handlePauseToggle();
137+
return true;
138+
case Keys.W:
139+
handleWarpSpeedToggle();
140+
return true;
141+
default:
142+
return false;
135143
}
136-
machineScreen.getJvicRunner().toggleWarpSpeed();
137-
return true;
138-
}
139-
else if (keycode == Keys.F3) {
140-
machineScreen.getJvicRunner().sendNmi();
141-
return true;
142144
}
143145
else if (keycode == Keys.F11) {
144146
if (!Gdx.app.getType().equals(ApplicationType.WebGL)) {
@@ -377,72 +379,31 @@ else if ((touchXY.y > (fiveSixths - 100)) && (touchXY.y < (fiveSixths + 26))) {
377379
}
378380

379381
if (keyboardClicked) {
380-
if (keyboardType.equals(KeyboardType.OFF)) {
381-
keyboardType = (viewportManager.isPortrait() ? KeyboardType.PORTRAIT : KeyboardType.LANDSCAPE);
382-
viewportManager.update();
383-
} else {
384-
keyboardType = KeyboardType.OFF;
385-
}
382+
handleKeyboardToggle();
386383
}
387384

388385
if (joystickClicked) {
389-
// Rotate the joystick screen alignment.
390-
joystickAlignment = joystickAlignment.rotateValue();
391-
if (viewportManager.isLandscape() && ((cameraXOffset != 0))) {
392-
if (joystickAlignment.equals(JoystickAlignment.RIGHT)) {
393-
joystickAlignment = joystickAlignment.rotateValue();
394-
}
395-
}
386+
handleJoystickAlignment();
396387
}
397388

398389
if (speakerClicked) {
399-
speakerOn = !speakerOn;
400-
machineScreen.getJvicRunner().changeSound(speakerOn);
390+
handleSoundToggle();
401391
}
402392

403393
if (screenSizeClicked) {
404394
rotateScreenSize();
405395
}
406396

407397
if (pausePlayClicked) {
408-
if (machineScreen.getJvicRunner().isPaused()) {
409-
machineScreen.getJvicRunner().resume();
410-
} else {
411-
machineScreen.getJvicRunner().pause();
412-
}
398+
handlePauseToggle();
413399
}
414400

415401
if (fullScreenClicked) {
416-
Boolean fullScreen = Gdx.graphics.isFullscreen();
417-
if (fullScreen == true) {
418-
switchOutOfFullScreen();
419-
}
420-
else {
421-
switchIntoFullScreen();
422-
}
402+
handleFullScreenToggle();
423403
}
424404

425405
if (backArrowClicked) {
426-
if (Gdx.app.getType().equals(ApplicationType.Desktop) && Gdx.graphics.isFullscreen()) {
427-
// Dialog won't show for desktop unless we exit full screen,
428-
switchOutOfFullScreen();
429-
}
430-
431-
machineScreen.getJvicRunner().pause();
432-
433-
dialogHandler.confirm("Are you sure you want to quit the game?",
434-
new ConfirmResponseHandler() {
435-
@Override
436-
public void yes() {
437-
machineScreen.getJvicRunner().stop();
438-
}
439-
440-
@Override
441-
public void no() {
442-
// Nothing to do.
443-
machineScreen.getJvicRunner().resume();
444-
}
445-
});
406+
handleExitMachine();
446407
}
447408

448409
// If joystick is ON, and the click didn't land on anything else, then treat as fire button.
@@ -458,6 +419,79 @@ public void no() {
458419

459420
return true;
460421
}
422+
423+
private void handlePauseToggle() {
424+
if (machineScreen.getJvicRunner().isPaused()) {
425+
machineScreen.getJvicRunner().resume();
426+
} else {
427+
machineScreen.getJvicRunner().pause();
428+
}
429+
}
430+
431+
private void handleFullScreenToggle() {
432+
Boolean fullScreen = Gdx.graphics.isFullscreen();
433+
if (fullScreen == true) {
434+
switchOutOfFullScreen();
435+
}
436+
else {
437+
switchIntoFullScreen();
438+
}
439+
}
440+
441+
private void handleKeyboardToggle() {
442+
if (keyboardType.equals(KeyboardType.OFF)) {
443+
keyboardType = (viewportManager.isPortrait() ? KeyboardType.PORTRAIT : KeyboardType.LANDSCAPE);
444+
viewportManager.update();
445+
} else {
446+
keyboardType = KeyboardType.OFF;
447+
}
448+
}
449+
450+
private void handleJoystickAlignment() {
451+
// Rotate the joystick screen alignment.
452+
joystickAlignment = joystickAlignment.rotateValue();
453+
if (viewportManager.isLandscape() && ((cameraXOffset != 0))) {
454+
if (joystickAlignment.equals(JoystickAlignment.RIGHT)) {
455+
joystickAlignment = joystickAlignment.rotateValue();
456+
}
457+
}
458+
}
459+
460+
private void handleSoundToggle() {
461+
speakerOn = !speakerOn;
462+
machineScreen.getJvicRunner().changeSound(speakerOn);
463+
}
464+
465+
private void handleExitMachine() {
466+
if (Gdx.app.getType().equals(ApplicationType.Desktop) && Gdx.graphics.isFullscreen()) {
467+
// Dialog won't show for desktop unless we exit full screen,
468+
switchOutOfFullScreen();
469+
}
470+
471+
machineScreen.getJvicRunner().pause();
472+
473+
dialogHandler.confirm("Are you sure you want to quit the game?",
474+
new ConfirmResponseHandler() {
475+
@Override
476+
public void yes() {
477+
machineScreen.getJvicRunner().stop();
478+
}
479+
480+
@Override
481+
public void no() {
482+
// Nothing to do.
483+
machineScreen.getJvicRunner().resume();
484+
}
485+
});
486+
}
487+
488+
private void handleWarpSpeedToggle() {
489+
if (!machineScreen.getJvicRunner().isWarpSpeed()) {
490+
speakerOn = false;
491+
machineScreen.getJvicRunner().changeSound(false);
492+
}
493+
machineScreen.getJvicRunner().toggleWarpSpeed();
494+
}
461495

462496
public void adjustWorldMinMax(int width, int height, MachineType machineType) {
463497
ExtendViewport viewport = machineScreen.getViewport();

0 commit comments

Comments
 (0)