123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package pathgame.gameplay.menu;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import me.hammerle.snuviengine.api.Key;
- import pathgame.gameplay.Keys;
- public class OptionMenu extends BaseMenu {
- private final MenuButton[] options;
- public OptionMenu(int id, int mainId, Keys keys) {
- super(id);
- int menuLength = keys.keys.length;
- options = new MenuButton[menuLength + 1];
- for(int i = 0; i < menuLength; ++i) {
- options[i] = getButton(keys.keyNames[i], keys, keys.keys[i]);
- }
- options[menuLength] = new MenuButton("Back to Main Menu", (gamestate) -> {
- File f = new File("resources/config.bin");
- try(DataOutputStream writer = new DataOutputStream(new FileOutputStream(f))) {
- for(int i = 0; i < keys.keys.length; ++i) {
- writer.writeInt(keys.keys[i].getKey());
- }
- } catch(IOException ex) {
- }
- setReturnId(mainId);
- });
- }
- private MenuButton getButton(String name, Keys keys, Key key) {
- return new MenuButton(name, (gamestate) -> {
- keys.rebind(key);
- });
- }
- /**
- * Returns the options of the OptionMenu
- *
- * @return the options of the OptionMenu
- */
- @Override
- public MenuButton[] getOptions() {
- return options;
- }
- /**
- * Returns if this is the OptionMenu
- *
- * @return if this is the OptionMenu
- */
- @Override
- public boolean isOptionMenu() {
- return true;
- }
- }
|