OptionMenu.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package pathgame.gameplay.menu;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import me.hammerle.snuviengine.api.Key;
  7. import pathgame.gameplay.Keys;
  8. public class OptionMenu extends BaseMenu {
  9. private final MenuButton[] options;
  10. public OptionMenu(int id, int mainId, Keys keys) {
  11. super(id);
  12. int menuLength = keys.keys.length;
  13. options = new MenuButton[menuLength + 1];
  14. for(int i = 0; i < menuLength; ++i) {
  15. options[i] = getButton(keys.keyNames[i], keys, keys.keys[i]);
  16. }
  17. options[menuLength] = new MenuButton("Back to Main Menu", (gamestate) -> {
  18. File f = new File("resources/config.bin");
  19. try(DataOutputStream writer = new DataOutputStream(new FileOutputStream(f))) {
  20. for(int i = 0; i < keys.keys.length; ++i) {
  21. writer.writeInt(keys.keys[i].getKey());
  22. }
  23. } catch(IOException ex) {
  24. }
  25. setReturnId(mainId);
  26. });
  27. }
  28. private MenuButton getButton(String name, Keys keys, Key key) {
  29. return new MenuButton(name, (gamestate) -> {
  30. keys.rebind(key);
  31. });
  32. }
  33. /**
  34. * Returns the options of the OptionMenu
  35. *
  36. * @return the options of the OptionMenu
  37. */
  38. @Override
  39. public MenuButton[] getOptions() {
  40. return options;
  41. }
  42. /**
  43. * Returns if this is the OptionMenu
  44. *
  45. * @return if this is the OptionMenu
  46. */
  47. @Override
  48. public boolean isOptionMenu() {
  49. return true;
  50. }
  51. }