public void onInput(InputHandler input) { bool interacting = ui.onInput(input); if (interacting) { return; } if (input.isKeyPressed(Keys.T)) // title screen image { ui.pushElement(new UiTextInput("BG Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { GameInfo.titleBackground = input.text; titleScreen.updateBackground(); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.N)) // game name { ui.pushElement(new UiTextInput("Name: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { GameInfo.title = input.text; } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.S)) // game start { ui.pushElement(new UiOptionBox(Content, "Start game where?", "Overworld", "Map").addCallback(element => { UiOptionBox option = (UiOptionBox)element; ui.pushElement(new UiTextInput("Filename: ").addCallback(element2 => { UiTextInput filename = (UiTextInput)element2; if (filename.text != "") { GameInfo.startMap = filename.text; GameInfo.startOverworld = (option.selected == 0); } }), new Vector2(0, 65)); }), Vector2.Zero); } else if (input.isKeyPressed(Keys.F2)) // save { GameInfo.save(); } }
public void onInput(InputHandler input) { if (editing) { editor.onInput(input); } else { bool interacting = ui.onInput(input); if (interacting) { return; } if (input.isCommandPressed(Bindings.Left) && index > 0) { index--; setPlayerLocation(); } else if (input.isCommandPressed(Bindings.Right) && index < locations.Count - 1) { index++; setPlayerLocation(); } else if (input.isCommandPressed(Bindings.Interact)) { game.goToWorld(player.p, selected.filename); } if (input.isCommandPressed(Bindings.Start)) { ui.pushElement(new UiPauseMenu(game, Content, player.p, selected.filename, true), new Vector2(Tile.TILE_SIZE, Tile.TILE_SIZE)); } } if (input.isKeyPressed(Keys.F1)) { if (editing) { editor = null; } else { editor = new OverworldEditor(Content, this); } } }
public void onInput(InputHandler input) { // normal game controls if (!editing) { bool interacting = ui.onInput(input); if (!interacting && scripts.Count == 0) { player.onInput(input); if (input.isCommandPressed(Bindings.Start)) { ui.pushElement(new UiPauseMenu(game, Content, player, map.filename, false), new Vector2(Tile.TILE_SIZE, Tile.TILE_SIZE)); } } } else { editor.onInput(input); } // enter/exit editing mode if (input.isKeyPressed(Keys.F1)) { editing = !editing; if (editing) { editor = new WorldEditor(Content, this); } else { editor = null; camera.setCenteringEntity(player); // editing mode stole this resetEntities(); // reload entities for ones created in the editor } } }
public void onInput(InputHandler input) { bool interacting = ui.onInput(input); if (interacting) { return; } cursor.onInput(input); if (input.isKeyPressed(Keys.F2)) // Save { UiElement filename = new UiTextInput("Save Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { string json = JsonSerializer.Serialize <OverworldMeta>(map.meta, SerializableMap.OPTIONS); File.WriteAllText("Content/map/" + input.text, json); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.F3)) // Load { UiElement filename = new UiTextInput("Load Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.loadMap("Content/map/" + input.text); map.setPlayerLocation(); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.E)) // Create new map location { ui.pushElement(new UiTextInput("Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.addLocation(input.text, cursor.getLocation()); map.setPlayerLocation(); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.R)) // Delete map location { for (int i = 0; i < map.meta.locations.Count; i++) { if (Vector2.Distance(map.meta.locations[i].center, cursor.center) < 10) { map.meta.locations.Remove(map.meta.locations[i]); map.setPlayerLocation(); break; } } } else if (input.isKeyPressed(Keys.L)) // Layer editor { ui.pushElement(new UiLayerEditor(Content, map), new Vector2(10, 30)); } }
public void pushUiElement(UiElement element, int x, int y) { ui.pushElement(element, makeVector2(x, y)); }
public void onInput(InputHandler input) { bool interactingWithUi = ui.onInput(input); if (interactingWithUi) { return; } cursor.onInput(input); if (input.isKeyPressed(Keys.F2)) // Save { UiElement filename = new UiTextInput("Save Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { SerializableMap.Save(Content, map, input.text); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.F3)) // Load { UiElement filename = new UiTextInput("Load Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { TileMap newMap = SerializableMap.Load(Content, input.text); if (newMap != null) { this.world.setMap(newMap); cursor.setLocation(Vector2.Zero); } } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.E)) // Edit tile properties { Tile selected = map.getTile(cursor.getTileLocation()); NPC npc = map.getNPC(cursor.getTileLocation()); LuaScript script = map.getScript(cursor.getTileLocation()); if (selected != null) { ui.pushElement(new UiTileEditor(Content, selected, npc, script).addCallback(element => { UiTileEditor editor = (UiTileEditor)element; map.setTile(cursor.getTileLocation(), editor.tile); map.setNPC(cursor.getTileLocation(), editor.npc); map.setScript(cursor.getTileLocation(), editor.script); lastEditedTile = editor.tile; lastEditedScript = editor.script; }), new Vector2(160, 0)); } } else if (input.isKeyHeld(Keys.P)) // Tile painter { if (lastEditedTile != null) { map.setTile(cursor.getTileLocation(), new Tile(lastEditedTile)); if (lastEditedScript != null) { map.setScript(cursor.getTileLocation(), new LuaScript(lastEditedScript.filename)); } } } else if (input.isKeyPressed(Keys.M)) // Edit map meta info { ui.pushElement(new UiMapMetaEditor(Content, map), new Vector2(160, 0)); } }
public override void start() { system.pushElement(element, Vector2.Zero); base.start(); }
public TitleScreen(Game1 game, ContentManager Content) { this.game = game; this.Content = Content; bg = Content.Load <Texture2D>(GameInfo.titleBackground); ui = new UiSystem(false); mainList = new UiList(Content, new string[4] { "New Game", "Load Game", "Options", "Quit" }); mainList.addCallback(element => { element.finished = false; // cancel removing the main list UiList list = (UiList)element; int selected = list.selected; switch (selected) { case -1: // thwart attempt to close the main menu { list.selected = 0; break; } case 0: // new game { TimeOfDay.restart(); Flags.reset(); if (GameInfo.startOverworld) { game.goToOverworld(new Player(Content, null, null), GameInfo.startMap); } else { game.goToWorld(new Player(Content, null, null), GameInfo.startMap); } break; } case 1: // load game { ui.pushElement(new UiSavePicker(Content, false).addCallback(element => { UiSavePicker saves = (UiSavePicker)element; string chosen = saves.selectedString; if (chosen == UiSavePicker.NO_FILES || chosen == null) { return; } SaveGame game = SaveGame.Load(Content, chosen); TimeOfDay.restart(); Flags.reset(); // restore data from save Player player = new Player(Content, null, null); foreach (string s in game.inventory.Keys) { player.addItem(s, game.inventory[s]); } Flags.setAllFlags(game.flags, game.strings); TimeOfDay.addMillis(game.time); player.setTileLocation(game.location); // go to overworld or map if (game.overworld) { this.game.goToOverworld(player, game.map); } else { this.game.goToWorld(player, game.map, false); } }), new Vector2(Tile.TILE_SIZE, Tile.TILE_SIZE)); break; } case 2: // options { ui.pushElement(new UiOptionsMenu(game, Content), new Vector2( Game1.INTERNAL_WIDTH / 2 - UiOptionsMenu.WIDTH / 2, Game1.INTERNAL_HEIGHT / 2 - UiOptionsMenu.HEIGHT / 2) ); break; } case 3: // quit { game.Exit(); break; } } }); Vector2 center = Vector2.Round(new Vector2( Game1.INTERNAL_WIDTH / 2 - mainList.size.X / 2, (Game1.INTERNAL_HEIGHT / 2 - mainList.size.Y / 2) + 20)); ui.pushElement(mainList, center); }