innit
This commit is contained in:
parent
e4b8069dda
commit
c313e93dd4
101
Menu/Menu.cs
Normal file
101
Menu/Menu.cs
Normal file
@ -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<List<string>> pageItems = new List<List<string>>();
|
||||
|
||||
for (int x = 0; x < maxPage; x++)
|
||||
{
|
||||
List<string> pi = new List<string>();
|
||||
|
||||
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<string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
Menu/Menu.csproj
Normal file
9
Menu/Menu.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
25
Menu/Menu.sln
Normal file
25
Menu/Menu.sln
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user