/// <summary> /// This method uses the list <c>settings</c> to draw menu items /// </summary> /// <param name="title">Text shown at top</param> /// <returns>A bool indicating if the user has pressed <c>DONE</c></returns> public bool DrawSettings(string title) { ConsoleKey pressedKey = ConsoleKey.NoName; bool isDone = false; int i; //make sure "selectedSetting" int doesn't go out of bounds selectedSetting = Math.Clamp(selectedSetting, 0, Settings.Count); //clear console Console.Clear(); //draw title //jump to the position Console.SetCursorPosition(5, 5); Console.WriteLine(title + " [Arrow Keys, Enter]"); //while (Settings[selectedSetting].EnumInteractable == SettingsEntry.InteractionType.nonSelectableAndNonInteractable) //{ // selectedSetting++; //} TODO: fix for (i = 0; i < Settings.Count; i++) { SettingsEntry settingsElement = Settings[i]; settingsElement.IntSelection = Math.Clamp(settingsElement.IntSelection, 0, settingsElement.StrValueLabels.Count - 1); //jump to the position Console.SetCursorPosition(5, 5 + i + 2); //invert colors if the setting is selected Console.ForegroundColor = selectedSetting == i ? ConsoleColor.Black : ConsoleColor.White; Console.BackgroundColor = selectedSetting == i ? ConsoleColor.White : ConsoleColor.Black; //write the settings properties Console.Write(settingsElement.StrLabel); //reset color for space and insert spacer Console.ResetColor(); if (settingsElement.StrLabel.Length > 0 && settingsElement.StrValueLabels[0].Length > 0) { Console.Write(" - "); } //invert colors if the setting is selected Console.ForegroundColor = selectedSetting == i ? ConsoleColor.Black : ConsoleColor.White; Console.BackgroundColor = selectedSetting == i ? ConsoleColor.White : ConsoleColor.Black; //write the selected option to console if (settingsElement.EnumInteractable == SettingsEntry.InteractionType.selectableAndInteractable) { //statement for handling "buttons" if (settingsElement.StrValueLabels[0] == "$Done") { Console.Write("<Done>"); } else if (settingsElement.StrValueLabels[0] == "$Input") { //if the variable is not empty, display it if (settingsElement.StrValueLabels[1].Length > 0) { Console.Write("<" + settingsElement.StrValueLabels[1].ToString() + ">"); } else { Console.Write("<Text field>"); } } else if (settingsElement.StrValueLabels[0] == "$Format") { //if the variable is not empty, display it if (settingsElement.StrValueLabels[2].Length > 0) { Console.Write("<" + settingsElement.StrValueLabels[2].ToString() + ">"); } else { Console.Write("<Text field>"); } } else if (settingsElement.StrValueLabels[0] == "$Path") { //if the variable is not empty, display it if (settingsElement.StrValueLabels[1].Length > 0) { Console.Write("<" + settingsElement.StrValueLabels[1].ToString() + ">"); } else { Console.Write("<Select path>"); } } else { Console.Write("<" + settingsElement.StrValueLabels[settingsElement.IntSelection].ToString() + ">"); } } else { Console.Write(settingsElement.StrValueLabels[settingsElement.IntSelection].ToString()); } //Reset the color even if the setting was not highlighted Console.ResetColor(); //Show a separator for the description Console.SetCursorPosition(0, Console.WindowHeight - 3); Console.Write(LoopString("-", Console.WindowWidth) + "\n"); //show description of selected element if (settingsElement.StrDescription != null && settingsElement == Settings[selectedSetting]) { Console.Write("Description: " + settingsElement.StrDescription); } } //Catch keystroke pressedKey = Console.ReadKey().Key; //Decide what to do with the keys try { SettingsEntry CurrentSetting = Settings[selectedSetting]; bool IsSettingInteractable = CurrentSetting.EnumInteractable == SettingsEntry.InteractionType.selectableAndInteractable; switch (pressedKey) { case ConsoleKey.UpArrow: selectedSetting--; while (Settings[selectedSetting].EnumInteractable == SettingsEntry.InteractionType.nonSelectableAndNonInteractable) { selectedSetting--; } break; case ConsoleKey.DownArrow: selectedSetting++; while (Settings[selectedSetting].EnumInteractable == SettingsEntry.InteractionType.nonSelectableAndNonInteractable) { selectedSetting++; } break; case ConsoleKey.LeftArrow: if (IsSettingInteractable) { CurrentSetting.IntSelection--; } break; case ConsoleKey.RightArrow: if (IsSettingInteractable) { CurrentSetting.IntSelection++; } break; case ConsoleKey.Enter: if (CurrentSetting.StrValueLabels[0] == "$Done" && IsSettingInteractable) { isDone = true; } else if (CurrentSetting.StrValueLabels[0] == "$Input" && IsSettingInteractable) { CurrentSetting.StrValueLabels[1] = new Prompts().UserInput(); } else if (CurrentSetting.StrValueLabels[0] == "$Format" && IsSettingInteractable) { CurrentSetting.StrValueLabels[2] = new Prompts().UserInput("Custom format", CurrentSetting.StrValueLabels[1] + "\nInput> "); } else if (CurrentSetting.StrValueLabels[0] == "$Path" && IsSettingInteractable) { FileExplorer fe = new FileExplorer(CurrentSetting.StrValueLabels[1]); while (!fe.FileExplorerWindow()) { } CurrentSetting.StrValueLabels[1] = fe.selectedPath; if (fe.selectedPath.Length == 0) { Settings[selectedSetting].StrValueLabels[1] = ""; } } break; } } catch (Exception) { } //Clamp "selected setting" just in case :) selectedSetting = Math.Clamp(selectedSetting, 0, Settings.Count - 1); //Return if the done button has been pressed return(isDone); }