示例#1
0
        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();
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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
                }
            }
        }
示例#4
0
        public void onInput(InputHandler input)
        {
            if (editing)
            {
                editor.onInput(input);
            }
            else
            {
                ui.onInput(input);
            }

            if (input.isKeyPressed(Keys.F1))
            {
                if (editing)
                {
                    editor = null;
                }
                else
                {
                    editor = new GameEditor(game, Content, this);
                }
            }
        }
示例#5
0
        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));
            }
        }
示例#6
0
        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));
            }
        }