diff --git a/Menu/Menu.cs b/Menu/Menu.cs new file mode 100644 index 0000000..a1608a3 --- /dev/null +++ b/Menu/Menu.cs @@ -0,0 +1,101 @@ +namespace Valorant_Chiral +{ + public class Menu + { + private static ConsoleKey[] inputKeys = + { + ConsoleKey.D1, + ConsoleKey.D2, + ConsoleKey.D3, + ConsoleKey.D4, + ConsoleKey.D5, + ConsoleKey.D6, + ConsoleKey.D7, + ConsoleKey.D8, + ConsoleKey.D9, + }; + + private static ConsoleKey pageUp = ConsoleKey.UpArrow; + private static ConsoleKey pageDown = ConsoleKey.DownArrow; + + public static int NumberMenu(string[] menuItems, string inputPrompt = "", ConsoleKey? menuReturn = null) + { + int width = 0, page = 0, maxPage = (int)((((float)menuItems.Length) / 9f) + .9f); // MAX PAYNE - absolute horrible + + List> pageItems = new List>(); + + for (int x = 0; x < maxPage; x++) + { + List pi = new List(); + + for (int y = 0; y < 9; y++) + { + int xy = (x * 9) + y; + + if (menuItems.Length <= xy) + break; + + pi.Add(menuItems[xy]); + } + + pageItems.Add(pi); + } + + foreach (List pageItem in pageItems) + foreach (string menuItem in pageItem) + if (menuItem.Length > width) + width = menuItem.Length; + + for (int x = 0; x < pageItems.Count; x++) + for (int y = 0; y < pageItems[x].Count; y++) + pageItems[x][y] = + "[ " + (y + 1).ToString() + ": " + pageItems[x][y] + + String.Concat(Enumerable.Repeat(" ", (width - pageItems[x][y].Length) + 1)) + "]"; // please just trust me that this 'works' + + while (true) + { + Console.Clear(); + + for (int i = 0; i < pageItems[page].Count; i++) + Console.WriteLine(pageItems[page][i]); + + Console.WriteLine(); + + if (maxPage > 1) + Console.WriteLine("[PAGE : " + (page + 1).ToString() + " / " + (maxPage).ToString() + "]" + Environment.NewLine); + + if (menuReturn != null) + Console.WriteLine("Press [" + menuReturn.ToString() + "] to go back" + Environment.NewLine); + + Console.Write((inputPrompt == "") ? "Option: " : inputPrompt); + + while (true) + { + ConsoleKey input = Console.ReadKey().Key; + + if (input == menuReturn) + return -1; + + if (input == pageUp) + { + if (page-- <= 0) page = 0; + else break; + } + + if (input == pageDown) + { + if (page++ >= (maxPage - 1)) page = maxPage - 1; + else break; + } + + if (input == ConsoleKey.Enter) + break; + + for (int i = 1; i <= pageItems[page].Count; i++) // always do this last as it is least efficient + if (input == inputKeys[i - 1]) + return (page * 9) + i; + } + } + } + } +} diff --git a/Menu/Menu.csproj b/Menu/Menu.csproj new file mode 100644 index 0000000..bafd05b --- /dev/null +++ b/Menu/Menu.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Menu/Menu.sln b/Menu/Menu.sln new file mode 100644 index 0000000..5a23cec --- /dev/null +++ b/Menu/Menu.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1704.4 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Menu", "Menu.csproj", "{43F2E17A-FFA0-4ABD-AD9A-4E4D9CEDAA98}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {43F2E17A-FFA0-4ABD-AD9A-4E4D9CEDAA98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43F2E17A-FFA0-4ABD-AD9A-4E4D9CEDAA98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43F2E17A-FFA0-4ABD-AD9A-4E4D9CEDAA98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43F2E17A-FFA0-4ABD-AD9A-4E4D9CEDAA98}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {77116DDA-3C61-4518-B4D9-6D68A5696716} + EndGlobalSection +EndGlobal