private void DisplayNewMap() { while (true) { currentCursorIndexLimit = 2; Console.SetWindowSize(30, 14); Console.SetBufferSize(30, 14); MainMenuHelper.MakeFrame(); MainMenuHelper.WriteInCenter("New map", 2); MainMenuHelper.FillALine('=', 1, 4); MainMenuHelper.WriteInCenter("Map name: ", 6); MainMenuHelper.WriteText(mapNameInput.PadRight(14), 8, 8); MainMenuHelper.WriteInCenter("‾‾‾‾‾‾‾‾‾‾‾‾‾‾", 9); Console.SetCursorPosition(8 + mapNameInput.Length, 8); Console.CursorVisible = true; ConsoleKeyInfo input = Console.ReadKey(); switch (input.Key) { case ConsoleKey.Enter: StartEditor(); return; case ConsoleKey.Backspace: if (mapNameInput.Length > 0) { mapNameInput = mapNameInput.Remove(mapNameInput.Length - 1); } break; case ConsoleKey.Escape: currentSection = MapEditorSection.Menu; Console.Clear(); Console.CursorVisible = false; DisplayMenu(); //I need to display the menu here, or else the player will be on a blank screen. return; default: if (mapNameInput.Length < 14) { if (input.KeyChar == ' ') { mapNameInput += ' '; } else { //trim used for getting rid of characters like pgup, del, insert, tab mapNameInput += input.KeyChar.ToString().Trim(); } } break; } } }
public MapEditorMenu() { mapNameInput = ""; currentSection = MapEditorSection.Menu; //Do not remove this! This code looks like a duplicate but without it the console window size gets a bit larger before the user presses a button. //This fixes it, no idea why but it does Console.SetWindowSize(30, 14); Console.SetBufferSize(30, 14); Console.Clear(); DisplaySection(); WaitForInput(); }
private void WaitForInput() { while (true) { ConsoleKey input = Console.ReadKey(true).Key; switch (input) { case ConsoleKey.W: case ConsoleKey.UpArrow: if (currentCursorIndex > 0) { currentCursorIndex--; } break; case ConsoleKey.S: case ConsoleKey.DownArrow: if (currentCursorIndex < currentCursorIndexLimit) { currentCursorIndex++; } break; case ConsoleKey.Enter: if (currentSection == MapEditorSection.Menu) { switch (currentCursorIndex) { case 0: currentSection = MapEditorSection.NewMap; currentCursorIndex = 0; Console.Clear(); break; case 1: currentSection = MapEditorSection.EditMap; currentCursorIndex = 0; Console.Clear(); break; case 2: currentCursorIndex = 0; Console.Clear(); return; } } else if (currentSection == MapEditorSection.EditMap) { StartEditor(foundMaps[currentCursorIndex]); } break; case ConsoleKey.Escape: if (currentSection == MapEditorSection.EditMap) { currentSection = MapEditorSection.Menu; currentCursorIndex = 0; Console.Clear(); } else if (currentSection == MapEditorSection.Menu) { Console.Clear(); return; } break; } DisplaySection(); } }