public MenuStateManager(TotemGame game) { Game = game; Menus = new Dictionary <string, Menu>() { { "main", new Menu(game) } }; // Building main menu Menus["main"].Controls.Add(new MenuButton(game) { OnClick = () => { game.LoadNewGame(); }, Text = "New Game", Position = new ResolutionResolver(game, new Vector2(0, .9f), new Vector2(12, -64 * 2)) }); Menus["main"].Controls.Add(new MenuButton(game) { OnClick = () => { game.Exit(); }, Text = "Exit", Position = new ResolutionResolver(game, new Vector2(0, .9f), new Vector2(12, -64)) }); }
/// <summary> /// Primary constructor. /// </summary> /// <param name="game">Game.</param> public DeveloperConsole(TotemGame game) { Game = game; // Test input handling TextInputEXT.TextInput += (ch) => { if (Enabled && ch != '`' && ch != '~' && Font.Characters.Contains(ch)) { if (!string.IsNullOrEmpty(Input)) { Input = Input.Substring(0, Input.Length - _cursorIndex) + ch + Input.Substring(Input.Length - _cursorIndex); // Insert character at cursor } else { Input = string.Empty + ch; } RefreshCursor(); } }; Console.SetOut(new ConsoleWriter(this)); AddCommand("help", "Shows the help menu.", args => // Help command { if (args.Length == 0) { WriteLine(Constants.ProjectName + ", ver: " + Constants.Version); Commands.ToList().ForEach(pair => { Console.WriteLine("{0} - {1} {2}", pair.Key, pair.Value.Description, pair.Value.ArgumentString != null ? "(args: " + pair.Value.ArgumentString + ")" : string.Empty); }); } else { if (Commands.ContainsKey(args[0])) { var command = Commands[args[0]]; Console.WriteLine("{0} - {1} {2}", args[0], command.Description, command.ArgumentString != null ? "(args: " + command.ArgumentString + ")" : string.Empty); } else { Console.WriteLine("Command '{0}' does not exist.", args[0]); } } }, "[command]"); AddCommand("clear", "Clears the console output.", args => { Output.Clear(); Output.Add(string.Empty); }); AddCommand("echo", "Prints every argument to the console.", args => // Echo command { for (int i = 0; i < args.Length; ++i) { WriteLine(args[i]); } }, "strings"); AddCommand("exit", "Quits the game.", args => // Exit command { Game.Exit(); }); #region Entity commands AddCommand("list_ents", "Lists all entities in GameWorld.", args => // List of entities { int index = 0; WorldInstance.Entities.ForEach(e => { string pos = "none"; var body = e.GetComponent <BodyComponent>(); if (body != null) { pos = body.Position.ToString(); } Console.WriteLine("Index: {0}, UID: {1}, Position: {2}", index++, e.UID, pos); }); }); AddCommand("ent_spawn", "Spawns an entity loaded from assets.", args => { var terrain = WorldInstance.GetComponent <TerrainComponent>(); Vector2 pos = new Vector2(float.Parse(args[1]), args.Length >= 3 ? float.Parse(args[2]) : terrain != null ? terrain.HeightMap(float.Parse(args[1])) : 0); var ent = WorldInstance.CreateEntity(args[0]); var body = ent.GetComponent <BodyComponent>(); if (body != null) { body.LegPosition = pos; } }, "asset", "x", "[y]"); #endregion /*AddCommand("terrain_test", "Spawns an entity loaded from assets.", args => * { * Game.World.Terrain.CreateDamage(new List<IntPoint>() { new IntPoint(200, 0), new IntPoint(250, 0), new IntPoint(250, 1990), new IntPoint(200, 2000) }); * }, "asset", "x", "y"); */ AddCommand("camera_controls", "Set camera controls on/off.", args => { WorldInstance.CameraControls = bool.Parse(args[0]); }, "true/false"); AddCommand("timescale", "Set the timescale.", args => { WorldInstance.TimeScale = float.Parse(args[0]); }, "float"); AddCommand("heightmap", "Get the height for specified x.", args => { var x = float.Parse(args[0]); var terrain = WorldInstance.GetComponent <TerrainComponent>(); Console.WriteLine("Height on {0}: {1}", x, terrain?.HeightMap(x)); }, "x"); AddCommand("weather", "Set the weather.", args => { var weather = WorldInstance?.GetComponent <WeatherComponent>(); if (weather == null) { return; } switch (args[0].ToLower()) { case "rain": weather.CurrentWeather = new RainWeather(); break; default: weather.CurrentWeather = null; break; } }, "float"); AddCommand("guitest", "Show GUI test.", args => { if (args.Length > 0) { Game.GuiManager.Add(new Gui.MessageBox(args[0])); } }, "text"); AddCommand("chat", "Show GUI test.", args => { Game.Hud.Chat(args[0]); }, "text", "[color]"); AddCommand("hurt", "Hurt yourself.", args => { Game.Hud.Observed.GetComponent <CharacterComponent>().Stamina -= int.Parse(args[0]); }, "amount"); AddCommand("additem", "Add an item to your inventory.", args => { Game.Hud.Observed.GetComponent <InventoryComponent>() .AddItem(Item.Create(args[0], args.Length >= 2 ? int.Parse(args[1]) : 1)); }, "id", "[count]"); AddCommand("debugview", "Toggle debugview.", args => { if (args.Length > 0) { WorldInstance.DebugView.Enabled = bool.Parse(args[0]); } else { WorldInstance.DebugView.Enabled = !WorldInstance.DebugView.Enabled; } }, "[on]"); }