make options menu use lists
This commit is contained in:
parent
d2ff927ab6
commit
4769c1cfda
|
@ -40,6 +40,8 @@ public class Container extends AppGameContainer {
|
|||
/** SlickException causing game failure. */
|
||||
protected SlickException e = null;
|
||||
|
||||
public static Container instance;
|
||||
|
||||
/**
|
||||
* Create a new container wrapping a game
|
||||
*
|
||||
|
@ -48,6 +50,7 @@ public class Container extends AppGameContainer {
|
|||
*/
|
||||
public Container(Game game) throws SlickException {
|
||||
super(game);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,6 +64,7 @@ public class Container extends AppGameContainer {
|
|||
*/
|
||||
public Container(Game game, int width, int height, boolean fullscreen) throws SlickException {
|
||||
super(game, width, height, fullscreen);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,9 +34,7 @@ import java.io.IOException;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.net.URI;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
|
@ -282,20 +280,20 @@ public class Options {
|
|||
public String getValueString() { return resolution.toString(); }
|
||||
|
||||
@Override
|
||||
public void click(GameContainer container) {
|
||||
do {
|
||||
resolution = resolution.next();
|
||||
} while (resolution != Resolution.RES_800_600 && (
|
||||
container.getScreenWidth() < resolution.getWidth() ||
|
||||
container.getScreenHeight() < resolution.getHeight()));
|
||||
public Object[] getListItems() {
|
||||
return Resolution.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clickListItem(int index) {
|
||||
resolution = Resolution.values()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(String s) {
|
||||
try {
|
||||
Resolution res = Resolution.valueOf(String.format("RES_%s", s.replace('x', '_')));
|
||||
resolution = res;
|
||||
} catch (IllegalArgumentException e) {}
|
||||
resolution = Resolution.valueOf(String.format("RES_%s", s.replace('x', '_')));
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
},
|
||||
// FULLSCREEN ("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false),
|
||||
|
@ -304,9 +302,13 @@ public class Options {
|
|||
public String getValueString() { return skinName; }
|
||||
|
||||
@Override
|
||||
public void click(GameContainer container) {
|
||||
skinDirIndex = (skinDirIndex + 1) % skinDirs.length;
|
||||
skinName = skinDirs[skinDirIndex];
|
||||
public Object[] getListItems() {
|
||||
return skinDirs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clickListItem(int index) {
|
||||
skinName = skinDirs[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,10 +321,19 @@ public class Options {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void click(GameContainer container) {
|
||||
targetFPSindex = (targetFPSindex + 1) % targetFPS.length;
|
||||
container.setTargetFrameRate(getTargetFPS());
|
||||
container.setVSync(getTargetFPS() == 60);
|
||||
public Object[] getListItems() {
|
||||
String[] list = new String[targetFPS.length];
|
||||
for (int i = 0; i < targetFPS.length; i++) {
|
||||
list[i] = String.format(targetFPS[i] == 60 ? "%dfps (vsync)" : "%dfps", targetFPS[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clickListItem(int index) {
|
||||
targetFPSindex = index;
|
||||
Container.instance.setTargetFrameRate(targetFPS[index]);
|
||||
Container.instance.setVSync(targetFPS[index] == 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -360,7 +371,14 @@ public class Options {
|
|||
public String getValueString() { return screenshotFormat[screenshotFormatIndex].toUpperCase(); }
|
||||
|
||||
@Override
|
||||
public void click(GameContainer container) { screenshotFormatIndex = (screenshotFormatIndex + 1) % screenshotFormat.length; }
|
||||
public Object[] getListItems() {
|
||||
return screenshotFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clickListItem(int index) {
|
||||
screenshotFormatIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String write() { return Integer.toString(screenshotFormatIndex); }
|
||||
|
@ -658,6 +676,18 @@ public class Options {
|
|||
*/
|
||||
public void click(GameContainer container) { bool = !bool; }
|
||||
|
||||
/**
|
||||
* Get a list of values to choose from
|
||||
* @return list with value string or null if no list should be shown
|
||||
*/
|
||||
public Object[] getListItems() { return null; }
|
||||
|
||||
/**
|
||||
* Fired when an item in the value list has been clicked
|
||||
* @param index the itemindex which has been clicked
|
||||
*/
|
||||
public void clickListItem(int index) { };
|
||||
|
||||
/**
|
||||
* Processes a mouse drag action (via override).
|
||||
* <p>
|
||||
|
|
|
@ -31,8 +31,7 @@ import itdelatrisu.opsu.ui.Fonts;
|
|||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.*;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
|
@ -44,6 +43,7 @@ import org.newdawn.slick.state.BasicGameState;
|
|||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.state.transition.FadeInTransition;
|
||||
import org.newdawn.slick.state.transition.EmptyTransition;
|
||||
import yugecin.opsudance.ui.ItemList;
|
||||
|
||||
/**
|
||||
* "Game Options" state.
|
||||
|
@ -174,13 +174,18 @@ public class OptionsMenu extends BasicGameState {
|
|||
private Graphics g;
|
||||
private final int state;
|
||||
|
||||
private final ItemList list;
|
||||
|
||||
public OptionsMenu(int state) {
|
||||
this.state = state;
|
||||
list = new ItemList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(GameContainer container, StateBasedGame game)
|
||||
throws SlickException {
|
||||
list.init(container);
|
||||
|
||||
this.container = container;
|
||||
this.game = game;
|
||||
this.input = container.getInput();
|
||||
|
@ -241,7 +246,7 @@ public class OptionsMenu extends BasicGameState {
|
|||
for (OptionTab tab : OptionTab.VALUES_REVERSED) {
|
||||
if (tab != currentTab)
|
||||
UI.drawTab(tab.button.getX(), tab.button.getY(),
|
||||
tab.getName(), false, tab == hoverTab);
|
||||
tab.getName(), false, tab == hoverTab && !list.isVisible());
|
||||
}
|
||||
UI.drawTab(currentTab.button.getX(), currentTab.button.getY(),
|
||||
currentTab.getName(), true, false);
|
||||
|
@ -251,6 +256,10 @@ public class OptionsMenu extends BasicGameState {
|
|||
g.drawLine(0, lineY, width, lineY);
|
||||
g.resetLineWidth();
|
||||
|
||||
if (list.isVisible()) {
|
||||
list.render(container, game, g);
|
||||
}
|
||||
|
||||
UI.getBackButton().draw();
|
||||
|
||||
// key entry state
|
||||
|
@ -282,8 +291,20 @@ public class OptionsMenu extends BasicGameState {
|
|||
@Override
|
||||
public int getID() { return state; }
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int button, int x, int y) {
|
||||
if (list.isVisible()) {
|
||||
list.mouseReleased(button, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
if (list.isVisible()) {
|
||||
list.mousePressed(button, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
// key entry state
|
||||
if (keyEntryLeft || keyEntryRight) {
|
||||
keyEntryLeft = keyEntryRight = false;
|
||||
|
@ -313,9 +334,22 @@ public class OptionsMenu extends BasicGameState {
|
|||
}
|
||||
|
||||
// options (click only)
|
||||
GameOption option = getOptionAt(y);
|
||||
if (option != null)
|
||||
final GameOption option = getOptionAt(y);
|
||||
if (option != null) {
|
||||
Object[] listItems = option.getListItems();
|
||||
if (listItems == null) {
|
||||
option.click(container);
|
||||
} else {
|
||||
list.setItems(listItems);
|
||||
list.setClickListener(new Observer() {
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
option.clickListItem((int) arg);
|
||||
}
|
||||
});
|
||||
list.show();
|
||||
}
|
||||
}
|
||||
|
||||
// special key entry states
|
||||
if (option == GameOption.KEY_LEFT) {
|
||||
|
@ -329,6 +363,11 @@ public class OptionsMenu extends BasicGameState {
|
|||
|
||||
@Override
|
||||
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
||||
if (list.isVisible()) {
|
||||
list.mouseDragged(oldx, oldy, newx, newy);
|
||||
return;
|
||||
}
|
||||
|
||||
// key entry state
|
||||
if (keyEntryLeft || keyEntryRight)
|
||||
return;
|
||||
|
@ -356,12 +395,20 @@ public class OptionsMenu extends BasicGameState {
|
|||
|
||||
@Override
|
||||
public void mouseWheelMoved(int newValue) {
|
||||
if (list.isVisible()) {
|
||||
list.mouseWheelMoved(newValue);
|
||||
}
|
||||
if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT))
|
||||
UI.changeVolume((newValue < 0) ? -1 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(int key, char c) {
|
||||
if (list.isVisible()) {
|
||||
list.keyPressed(key, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// key entry state
|
||||
if (keyEntryLeft || keyEntryRight) {
|
||||
if (keyEntryLeft)
|
||||
|
|
Loading…
Reference in New Issue
Block a user