some interaction fixes

This commit is contained in:
yugecin 2016-11-12 23:55:39 +01:00
parent 43e1109f40
commit 15f560ee68
3 changed files with 43 additions and 8 deletions

View File

@ -981,7 +981,7 @@ public class Game extends BasicGameState {
@Override @Override
public void keyPressed(int key, char c) { public void keyPressed(int key, char c) {
if (sbOverlay.keyPressed(key)) { if (sbOverlay.keyPressed(key, c)) {
return; return;
} }
@ -1305,10 +1305,6 @@ public class Game extends BasicGameState {
// container.setMouseGrabbed(true); // container.setMouseGrabbed(true);
if (!checkpointLoaded) {
sbOverlay.updateIndex(0);
}
// restart the game // restart the game
if (restart != Restart.FALSE) { if (restart != Restart.FALSE) {
// load mods // load mods
@ -1450,7 +1446,11 @@ public class Game extends BasicGameState {
SoundController.mute(false); SoundController.mute(false);
} }
sbOverlay.setGameObjects(gameObjects); sbOverlay.setGameObjects(gameObjects);
if (!checkpointLoaded) {
sbOverlay.updateIndex(0);
}
Pippi.reset(); Pippi.reset();
mirrorFrom = 0; mirrorFrom = 0;

View File

@ -70,8 +70,10 @@ public class OptionsOverlay {
private final ItemList list; private final ItemList list;
private GameContainer container; private GameContainer container;
private Options.GameOption selectedOption; private Options.GameOption selectedOption;
private final SBOverlay overlay;
public OptionsOverlay() { public OptionsOverlay(SBOverlay overlay) {
this.overlay = overlay;
list = new ItemList(); list = new ItemList();
} }
@ -176,6 +178,9 @@ public class OptionsOverlay {
} }
public boolean mouseReleased(int button, int x, int y) { public boolean mouseReleased(int button, int x, int y) {
if (selectedOption != null) {
overlay.saveOption(selectedOption, selectedOption.write());
}
selectedOption = null; selectedOption = null;
if (list.isVisible()) { if (list.isVisible()) {
list.mouseReleased(button, x, y); list.mouseReleased(button, x, y);
@ -191,4 +196,12 @@ public class OptionsOverlay {
} }
return true; return true;
} }
public boolean keyPressed(int key, char c) {
if (list.isVisible()) {
list.keyPressed(key, c);
return true;
}
return false;
}
} }

View File

@ -17,6 +17,7 @@
*/ */
package yugecin.opsudance.ui; package yugecin.opsudance.ui;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.states.Game; import itdelatrisu.opsu.states.Game;
@ -28,7 +29,11 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.StateBasedGame;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@SuppressWarnings("unchecked")
public class SBOverlay { public class SBOverlay {
public static boolean isActive = true; public static boolean isActive = true;
@ -50,7 +55,7 @@ public class SBOverlay {
public SBOverlay(Game game) { public SBOverlay(Game game) {
this.game = game; this.game = game;
options = new OptionsOverlay(); options = new OptionsOverlay(this);
} }
public void init(GameContainer container, Input input, int width, int height) { public void init(GameContainer container, Input input, int width, int height) {
@ -84,10 +89,13 @@ public class SBOverlay {
} }
} }
public boolean keyPressed(int key) { public boolean keyPressed(int key, char c) {
if (!isActive) { if (!isActive) {
return false; return false;
} }
if (options.keyPressed(key, c)) {
return true;
}
if (key == Input.KEY_C && speed > 0) { if (key == Input.KEY_C && speed > 0) {
speed -= 1; speed -= 1;
if (speed == 0) { if (speed == 0) {
@ -137,6 +145,13 @@ public class SBOverlay {
this.gameObjects = gameObjects; this.gameObjects = gameObjects;
} }
public void saveOption(Options.GameOption option, String value) {
if (optionsMap[index] == null) {
optionsMap[index] = new HashMap<>();
}
optionsMap[index].put(option, value);
}
public boolean mousePressed(int button, int x, int y) { public boolean mousePressed(int button, int x, int y) {
return menu && options.mousePressed(button, x, y); return menu && options.mousePressed(button, x, y);
} }
@ -147,6 +162,13 @@ public class SBOverlay {
public void updateIndex(int index) { public void updateIndex(int index) {
this.index = index; this.index = index;
HashMap options = optionsMap[index];
if (options != null) {
for (Object o : options.entrySet()) {
Map.Entry<Options.GameOption, String> next = (Map.Entry<Options.GameOption, String>) o;
next.getKey().read(next.getValue());
}
}
} }
public boolean mouseReleased(int button, int x, int y) { public boolean mouseReleased(int button, int x, int y) {