public MapEditorUI(MapEditor editorInstance) { mapRefreshRequested = true; currentColor = 0; currentSection = EditorUISection.EditMap; EditorInstance = editorInstance; }
private void WaitForInputEscMenu() { bool previousVisibility = Console.CursorVisible; Console.CursorVisible = false; currentCursorIndex = 0; Console.SetWindowSize(35, 14); Console.SetBufferSize(35, 14); Console.SetWindowSize(35, 14); while (true) { DisplayEscMenu(); ConsoleKey input = Console.ReadKey().Key; switch (input) { case ConsoleKey.UpArrow: if (currentCursorIndex > 0) { currentCursorIndex--; } break; case ConsoleKey.DownArrow: if (currentCursorIndex < 2) { currentCursorIndex++; } break; case ConsoleKey.Enter: if (currentCursorIndex == 0) { currentSection = EditorUISection.EditMap; Console.Clear(); mapRefreshRequested = true; Console.CursorVisible = previousVisibility; return; } else if (currentCursorIndex == 1) { shutDown = true; Console.Clear(); EditorInstance.SaveMap(); return; } else if (currentCursorIndex == 2) { shutDown = true; Console.Clear(); return; } break; } } }
private void WaitForInputRightPanel() { Console.CursorVisible = false; while (true) { DisplayEditor(); DisplayRightPanel(); //Handling an enter press if (enterPressed) { Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Cyan; if (currentCursorIndex == 0) { currentColor = SafeUserInput.OneByOneConsoleColor("Current color: ", Console.WindowWidth - 29, 8, currentColor); } else if (currentCursorIndex == 1) { if (SafeUserInput.OneByOneInt(Console.WindowWidth - 29 + 12, 10, 4, out int result)) { EditorInstance.SetMapSize(EditorInstance.MapWidth, result); mapRefreshRequested = true; } } else if (currentCursorIndex == 2) { if (SafeUserInput.OneByOneInt(Console.WindowWidth - 29 + 12, 11, 4, out int result)) { EditorInstance.SetMapSize(result, EditorInstance.MapHeight); mapRefreshRequested = true; } } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; enterPressed = false; continue; } ConsoleKeyInfo input = Console.ReadKey(true); switch (input.Key) { case ConsoleKey.UpArrow: if (currentCursorIndex > 0) { currentCursorIndex--; } break; case ConsoleKey.DownArrow: if (currentCursorIndex < 2) { currentCursorIndex++; } break; case ConsoleKey.Tab: currentTabIndex = 0; enterPressed = false; Console.CursorVisible = true; return; case ConsoleKey.Enter: enterPressed = !enterPressed; break; case ConsoleKey.Escape: currentSection = EditorUISection.EscMenu; Console.Clear(); return; } } }
//Methods for reading input private void WaitForInputMapEdit() { while (true) { Console.CursorVisible = false; DisplayRightPanel(); DisplayEditor(); Console.CursorVisible = true; ConsoleKeyInfo input = Console.ReadKey(true); switch (input.Key) { case ConsoleKey.UpArrow: if (cursorTopPosition > 0) { cursorTopPosition--; } break; case ConsoleKey.DownArrow: //Check if cursor isn't on the edge of the map if (cursorTopPosition < EditorInstance.MapHeight - 1) { //Cursor isn't in the right edge of the screen (no scrolling required) if (cursorTopPosition < currentTopMargin + maxMapHeight) { cursorTopPosition++; } else if (cursorLeftPosition < EditorInstance.MapHeight - 1) { cursorTopPosition++; currentTopMargin++; mapRefreshRequested = true; } } break; case ConsoleKey.LeftArrow: if (cursorLeftPosition > currentLeftMargin) { cursorLeftPosition--; } else if (currentLeftMargin > 0) { currentLeftMargin--; cursorLeftPosition--; mapRefreshRequested = true; } break; case ConsoleKey.RightArrow: //Check if cursor isn't on the edge of the map if (cursorLeftPosition < EditorInstance.MapWidth - 1) { //Cursor isn't in the right edge of the screen (no scrolling required) if (cursorLeftPosition < currentLeftMargin + maxMapWidth) { cursorLeftPosition++; } else if (cursorLeftPosition < EditorInstance.MapWidth - 1) { cursorLeftPosition++; currentLeftMargin++; mapRefreshRequested = true; } } break; case ConsoleKey.Tab: currentTabIndex = 1; return; case ConsoleKey.Escape: currentSection = EditorUISection.EscMenu; Console.Clear(); return; case ConsoleKey.Home: mapRefreshRequested = true; break; case ConsoleKey.Backspace: if (currentTabIndex == 0) { EditorInstance.ClearValueFromAll(cursorLeftPosition, cursorTopPosition); mapRefreshRequested = true; } break; default: if (currentTabIndex == 0) { string inputChar = input.KeyChar.ToString().Trim(); if (inputChar.Length == 1) { EditorInstance.SetIndex(cursorLeftPosition, cursorTopPosition, inputChar[0], currentColor); } mapRefreshRequested = true; } break; } } }