-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from georgeness/master
Added controls menu and empty graphics menu
- Loading branch information
Showing
5 changed files
with
275 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
src/main/java/project_16x16/scene/ControlsSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package project_16x16.scene; | ||
|
||
import processing.core.PApplet; | ||
import processing.core.PConstants; | ||
import processing.event.KeyEvent; | ||
import processing.event.MouseEvent; | ||
import project_16x16.Audio; | ||
import project_16x16.Constants; | ||
import project_16x16.Options; | ||
import project_16x16.Options.Option; | ||
import project_16x16.SideScroller; | ||
import project_16x16.ui.Button; | ||
import project_16x16.ui.Notifications; | ||
import project_16x16.ui.Slider; | ||
|
||
public final class ControlsSettings extends PScene { | ||
|
||
private SideScroller game; | ||
|
||
private Button quit; | ||
private Button apply; | ||
private Button changeJumpKey; | ||
private Button changeDashKey; | ||
private Button changeMoveLeftKey; | ||
private Button changeMoveRightKey; | ||
|
||
// Stores key configurations | ||
private int newJumpKey; | ||
private int newDashKey; | ||
private int newMoveLeftKey; | ||
private int newMoveRightKey; | ||
|
||
private int originalJumpKey; | ||
private int originalDashKey; | ||
private int originalMoveLeftKey; | ||
private int originalMoveRightKey; | ||
|
||
private Button activeButton; | ||
|
||
public ControlsSettings(SideScroller a) { | ||
super(a); | ||
game = a; | ||
|
||
apply = new Button(applet); | ||
apply.setText("Apply"); | ||
apply.setPosition(a.width / 2, 500); | ||
|
||
quit = new Button(a); | ||
quit.setText("Quit"); | ||
quit.setPosition(a.width / 2, 600); | ||
|
||
changeJumpKey = new Button(a); | ||
changeJumpKey.setText("Change Jump Key: " + PApplet.str(Options.jumpKey)); | ||
changeJumpKey.setPosition(a.width / 2, 150); | ||
|
||
changeDashKey = new Button(a); | ||
changeDashKey.setText("Change Dash Key: " + PApplet.str(Options.dashKey)); | ||
changeDashKey.setPosition(a.width / 2, 200); | ||
|
||
changeMoveLeftKey = new Button(a); | ||
changeMoveLeftKey.setText("Change Move Left Key: " + PApplet.str(Options.moveLeftKey)); | ||
changeMoveLeftKey.setPosition(a.width / 2, 250); | ||
|
||
changeMoveRightKey = new Button(a); | ||
changeMoveRightKey.setText("Change Move Right Key: " + PApplet.str(Options.moveRightKey)); | ||
changeMoveRightKey.setPosition(a.width / 2, 300); | ||
|
||
newJumpKey = Options.jumpKey; | ||
newDashKey = Options.dashKey; | ||
newMoveLeftKey = Options.moveLeftKey; | ||
newMoveRightKey = Options.moveRightKey; | ||
|
||
activeButton = null; | ||
} | ||
|
||
@Override | ||
public void switchTo() { | ||
originalJumpKey = Options.jumpKey; | ||
originalDashKey = Options.dashKey; | ||
originalMoveLeftKey = Options.moveLeftKey; | ||
originalMoveRightKey = Options.moveRightKey; | ||
super.switchTo(); | ||
} | ||
|
||
@Override | ||
public void drawUI() { | ||
game.background(Constants.Colors.MENU_GREY); | ||
apply.display(); | ||
quit.display(); | ||
|
||
changeJumpKey.display(); | ||
changeDashKey.display(); | ||
changeMoveLeftKey.display(); | ||
changeMoveRightKey.display(); | ||
|
||
if (activeButton != null) { | ||
game.fill(255, 0, 0); | ||
game.textAlign(PConstants.CENTER); | ||
game.text("Press a key to change the control!", game.width / 2, 100); | ||
} | ||
} | ||
|
||
@Override | ||
void mouseReleased(MouseEvent e) { | ||
apply.update(); | ||
quit.update(); | ||
changeJumpKey.update(); | ||
changeDashKey.update(); | ||
changeMoveLeftKey.update(); | ||
changeMoveRightKey.update(); | ||
|
||
if (quit.hover()) { | ||
newJumpKey = originalJumpKey; | ||
newDashKey = originalDashKey; | ||
newMoveLeftKey = originalMoveLeftKey; | ||
newMoveRightKey = originalMoveRightKey; | ||
changeJumpKey.setText("Change Jump Key: " + PApplet.str(originalJumpKey)); | ||
changeDashKey.setText("Change Dash Key: " + PApplet.str(originalDashKey)); | ||
changeMoveLeftKey.setText("Change Move Left Key: " + PApplet.str(originalMoveLeftKey)); | ||
changeMoveRightKey.setText("Change Move Right Key: " + PApplet.str(originalMoveRightKey)); | ||
|
||
game.returnScene(); | ||
return; | ||
} | ||
if (apply.hover()) { | ||
Options.save(Option.jumpKey, newJumpKey); | ||
Options.save(Option.dashKey, newDashKey); | ||
Options.save(Option.moveLeftKey, newMoveLeftKey); | ||
Options.save(Option.moveRightKey, newMoveRightKey); | ||
Options.jumpKey = newJumpKey; | ||
Options.dashKey = newDashKey; | ||
Options.moveLeftKey = newMoveLeftKey; | ||
Options.moveRightKey = newMoveRightKey; | ||
|
||
Notifications.addNotification("Controls Settings Applied", "Your configuration has been successfully applied."); | ||
game.returnScene(); | ||
} | ||
|
||
if (changeJumpKey.hover()) { | ||
activeButton = changeJumpKey; | ||
} else if (changeDashKey.hover()) { | ||
activeButton = changeDashKey; | ||
} else if (changeMoveLeftKey.hover()) { | ||
activeButton = changeMoveLeftKey; | ||
} else if (changeMoveRightKey.hover()) { | ||
activeButton = changeMoveRightKey; | ||
} else { | ||
activeButton = null; | ||
} | ||
} | ||
|
||
@Override | ||
void keyReleased(KeyEvent e) { | ||
if (activeButton != null) { | ||
int key = e.getKeyCode(); | ||
if (activeButton == changeJumpKey) { | ||
newJumpKey = key; | ||
changeJumpKey.setText("Change Jump Key: " + PApplet.str(key)); | ||
} else if (activeButton == changeDashKey) { | ||
newDashKey = key; | ||
changeDashKey.setText("Change Dash Key: " + PApplet.str(key)); | ||
} else if (activeButton == changeMoveLeftKey) { | ||
newMoveLeftKey = key; | ||
changeMoveLeftKey.setText("Change Move Left Key: " + PApplet.str(key)); | ||
} else if (activeButton == changeMoveRightKey) { | ||
newMoveRightKey = key; | ||
changeMoveRightKey.setText("Change Move Right Key: " + PApplet.str(key)); | ||
} | ||
activeButton = null; | ||
} else if (e.getKeyCode() == PConstants.ESC) { | ||
game.returnScene(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package project_16x16.scene; | ||
|
||
import processing.core.PApplet; | ||
import processing.core.PConstants; | ||
import processing.event.KeyEvent; | ||
import processing.event.MouseEvent; | ||
import project_16x16.Audio; | ||
import project_16x16.Constants; | ||
import project_16x16.Options; | ||
import project_16x16.Options.Option; | ||
import project_16x16.SideScroller; | ||
import project_16x16.ui.Button; | ||
import project_16x16.ui.Notifications; | ||
import project_16x16.ui.Slider; | ||
|
||
public final class GraphicsSettings extends PScene { | ||
|
||
private SideScroller game; | ||
|
||
private Button quit; | ||
private Button apply; | ||
|
||
public GraphicsSettings(SideScroller a) { | ||
super(a); | ||
|
||
game = a; | ||
|
||
apply = new Button(applet); | ||
apply.setText("Apply"); | ||
apply.setPosition(a.width / 2, 500); | ||
|
||
quit = new Button(a); | ||
quit.setText("Quit"); | ||
quit.setPosition(a.width / 2, 600); | ||
|
||
} | ||
|
||
@Override | ||
public void switchTo() { | ||
// TODO properly align audio value and slider position | ||
//volumeBGM.setValue(PApplet.map(originalVolumeBGM, -60, 0, 0, 1)); | ||
//volumeSFX.setValue(PApplet.map(originalVolumeSFX, -60, 0, 0, 1)); | ||
super.switchTo(); | ||
} | ||
|
||
@Override | ||
public void drawUI() { | ||
game.background(Constants.Colors.MENU_GREY); | ||
apply.display(); | ||
quit.display(); | ||
|
||
} | ||
|
||
@Override | ||
void mouseDragged(MouseEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
void mouseReleased(MouseEvent e) { | ||
apply.update(); | ||
quit.update(); | ||
|
||
if (quit.hover()) { | ||
// revert sound changes if menu is quit | ||
game.returnScene(); | ||
return; | ||
} | ||
if (apply.hover()) { | ||
Notifications.addNotification("Graphics Settings Applied", "Your configuration has been successfully applied."); | ||
game.returnScene(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
void keyReleased(KeyEvent e) { | ||
switch (e.getKeyCode()) { | ||
case PConstants.ESC : // Pause | ||
game.returnScene(); | ||
break; | ||
default : | ||
break; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters