From ab4a65e6c19fc19fd2a119c0d2a7b0d1466f790d Mon Sep 17 00:00:00 2001 From: Zsolt Zitting Date: Thu, 24 Aug 2023 15:25:44 -0700 Subject: [PATCH] WIP half-broken garbage --- MainForm.Designer.cs | 19 +++- MainForm.cs | 225 +++++++++++++++++++------------------------ WACCALauncher.csproj | 3 + WaccaList.cs | 54 +++++++++++ 4 files changed, 172 insertions(+), 129 deletions(-) create mode 100644 WaccaList.cs diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 80b5ed7..82d859c 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { this.menuLabel = new System.Windows.Forms.Label(); + this.waccaListTest = new WACCALauncher.WaccaList(); this.SuspendLayout(); // // menuLabel @@ -44,12 +45,28 @@ this.menuLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.menuLabel.Visible = false; // + // waccaListTest + // + this.waccaListTest.BackColor = System.Drawing.Color.Black; + this.waccaListTest.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.waccaListTest.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.waccaListTest.Enabled = false; + this.waccaListTest.ForeColor = System.Drawing.Color.White; + this.waccaListTest.FormattingEnabled = true; + this.waccaListTest.ItemHeight = 40; + this.waccaListTest.Location = new System.Drawing.Point(200, 240); + this.waccaListTest.Name = "waccaListTest"; + this.waccaListTest.Size = new System.Drawing.Size(680, 600); + this.waccaListTest.TabIndex = 1; + this.waccaListTest.Visible = false; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(1080, 1080); + this.Controls.Add(this.waccaListTest); this.Controls.Add(this.menuLabel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.KeyPreview = true; @@ -59,7 +76,6 @@ this.Text = "WACCA Launcher"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); - this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.KeyPressed); this.ResumeLayout(false); } @@ -67,6 +83,7 @@ #endregion private System.Windows.Forms.Label menuLabel; + public WaccaList waccaListTest; } } diff --git a/MainForm.cs b/MainForm.cs index 0b77bc1..d32be43 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -44,6 +44,8 @@ namespace WACCALauncher private readonly Process _gameProcess = new Process(); private bool _gameRunning = false; + public MenuManager _menuManager; + public MainForm() { InitializeComponent(); @@ -93,16 +95,6 @@ namespace WACCALauncher private bool _autoLaunch = true; private int _currentMenuItem; - public ConfigMenu CurrentMenu; - - public readonly ConfigMenu MainMenu = new ConfigMenu("Launcher Settings", rootMenu: true) { - //new ConfigMenuItem("bruh"), - //new ConfigMenuItem("moments"), - //new ConfigMenuItem("of"), - //new ConfigMenuItem("history") - }; - - protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { @@ -110,11 +102,19 @@ namespace WACCALauncher { if (keyData == Keys.Up) { CursorUp(); return true; } else if (keyData == Keys.Down) { CursorDown(); return true; } + else if (keyData == Keys.Enter) { MenuSelect(); return true; } + else if (keyData == Keys.Escape) + { + if (_autoLaunch) MenuShow(); + else MenuBack(); + return true; + } } return base.ProcessCmdKey(ref msg, keyData); } + /* private void KeyPressed(object sender, KeyPressEventArgs e) { if (_gameRunning) return; @@ -130,7 +130,7 @@ namespace WACCALauncher e.Handled = true; break; } - } + }*/ private async void Tick(object sender, EventArgs e) { @@ -194,29 +194,24 @@ namespace WACCALauncher private void CursorUp() { // move cursor up - Console.WriteLine("CursorUp"); - CurrentMenu[_currentMenuItem].Deactivate(); - _currentMenuItem = ((_currentMenuItem - 1) + CurrentMenu.Count) % CurrentMenu.Count; - Console.WriteLine($"Item {_currentMenuItem}"); - RefreshMenu(); + var idx = ((waccaListTest.SelectedIndex - 1) + waccaListTest.Items.Count) % waccaListTest.Items.Count; + waccaListTest.SelectedIndex = idx; } private void CursorDown() { // move cursor down - Console.WriteLine("CursorDown"); - CurrentMenu[_currentMenuItem].Deactivate(); - _currentMenuItem = (_currentMenuItem + 1) % CurrentMenu.Count; - Console.WriteLine($"Item {_currentMenuItem}"); - RefreshMenu(); + var idx = (waccaListTest.SelectedIndex + 1) % waccaListTest.Items.Count; + waccaListTest.SelectedIndex = idx; } public void MenuShow() { _delayTimer.Stop(); - _loadingLabel.Visible = false; - menuLabel.Visible = true; - GenerateMenu(MainMenu); + _loadingLabel.Hide(); + menuLabel.Show(); + waccaListTest.Visible = waccaListTest.Enabled = true; + waccaListTest.SelectedIndex = 0; _autoLaunch = false; } @@ -224,10 +219,7 @@ namespace WACCALauncher { _autoLaunch = true; menuLabel.Hide(); - foreach (var item in CurrentMenu) - { - item.label.Dispose(); - } + waccaListTest.Visible = waccaListTest.Enabled = false; _loadingLabel.Show(); _delayTimer = new System.Timers.Timer(5000); @@ -240,15 +232,18 @@ namespace WACCALauncher { // select menu item Console.WriteLine("MenuSelect"); - CurrentMenu[_currentMenuItem].Select(this, CurrentMenu); + (waccaListTest.SelectedItem as ConfigMenuItem).Select(this); } - + private void MenuBack() { // back from current menu item Console.WriteLine("MenuBack"); } + /* + + private void MenuReturn() { GenerateMenu(MainMenu); @@ -261,6 +256,8 @@ namespace WACCALauncher this.Controls.Add(CurrentMenu[_currentMenuItem].label); } + */ + private static void vfd_test() { var vfd = new WaccaVFD(); @@ -279,6 +276,7 @@ namespace WACCALauncher private void Form1_Load(object sender, EventArgs e) { _loadingLabel = new Label(); + waccaListTest.Font = _menuFont; SuspendLayout(); _loadingLabel.Font = _menuFont; @@ -309,7 +307,7 @@ namespace WACCALauncher LoadVersionsFromConfig(); - var defVerMenu = new ConfigMenu("default version"); + var defVerMenu = new List(); foreach (var ver in Versions) { @@ -319,18 +317,22 @@ namespace WACCALauncher defVerMenu.Add(new ConfigMenuItem("Return to settings", ConfigMenuAction.Return)); - MainMenu.Add(new ConfigMenuItem("set default version", ConfigMenuAction.Submenu, submenu: defVerMenu)); + var mainMenu = new List() { + new ConfigMenuItem("set default version", ConfigMenuAction.Submenu, submenu: defVerMenu), + new ConfigMenuItem("test VFD", ConfigMenuAction.Command, method: vfd_test), + new ConfigMenuItem("exit to windows", ConfigMenuAction.Command, method: Application.Exit), + new ConfigMenuItem("launch game", ConfigMenuAction.Return) + }; - MainMenu.Add(new ConfigMenuItem("test VFD", ConfigMenuAction.Command, method: vfd_test)); - - MainMenu.Add(new ConfigMenuItem("exit to windows", ConfigMenuAction.Command, method: Application.Exit)); - - MainMenu.Add(new ConfigMenuItem("launch game", ConfigMenuAction.Return)); + _menuManager = new MenuManager(mainMenu, "Launcher Settings"); + waccaListTest.AssignMenuManager(_menuManager); _loadingLabel.Font = _menuFont; menuLabel.Font = _menuFont; } + /* + public void GenerateMenu(ConfigMenu menu, int selectedIndex = 0) { if (menu == null || menu == CurrentMenu) return; @@ -367,6 +369,8 @@ namespace WACCALauncher RefreshMenu(); } + */ + private static void KillExplorer() { Process.Start(@"C:\Windows\System32\taskkill.exe", @"/F /IM explorer.exe"); @@ -409,8 +413,8 @@ namespace WACCALauncher private void LaunchDefault(Object source, ElapsedEventArgs e) { _delayTimer.Stop(); - KillExplorer(); - LaunchGame(DefaultVer); + //KillExplorer(); + //LaunchGame(DefaultVer); } private void LoadVersionsFromConfig() @@ -581,93 +585,18 @@ namespace WACCALauncher Return } - public class ConfigMenu : IList - { - public readonly string Name; - public bool RootMenu = false; - public ConfigMenu ParentMenu = null; - private readonly List _items = new List(); - - public ConfigMenu(string name, bool rootMenu = false) - { - this.Name = name; - this.RootMenu = rootMenu; - } - - public ConfigMenuItem this[int index] { get => _items[index]; set => _items[index] = value; } - - public int Count => _items.Count; - - public bool IsReadOnly => false; - - public void Add(ConfigMenuItem item) - { - _items.Add(item); - } - - public void Clear() - { - _items.Clear(); - } - - public bool Contains(ConfigMenuItem item) - { - return _items.Contains(item); - } - - public void CopyTo(ConfigMenuItem[] array, int arrayIndex) - { - _items.CopyTo(array, arrayIndex); - } - - public IEnumerator GetEnumerator() - { - return _items.GetEnumerator(); - } - - public int IndexOf(ConfigMenuItem item) - { - return _items.IndexOf(item); - } - - public void Insert(int index, ConfigMenuItem item) - { - _items.Insert(index, item); - } - - public bool Remove(ConfigMenuItem item) - { - return _items.Remove(item); - } - - public void RemoveAt(int index) - { - _items.RemoveAt(index); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return _items.GetEnumerator(); - } - - public void Destroy() - { - Clear(); - } - } - public class ConfigMenuItem { public readonly string Name; private readonly ConfigMenuAction _action; private readonly Action _method; - private readonly ConfigMenu _submenu; + public readonly List submenu; private readonly List _options; private readonly Version _version; public Label label; - public ConfigMenuItem(string name, ConfigMenuAction action = ConfigMenuAction.None, Action method = null, ConfigMenu submenu = null, List options = null, Version version = null) { + public ConfigMenuItem(string name, ConfigMenuAction action = ConfigMenuAction.None, Action method = null, List submenu = null, List options = null, Version version = null) { this.Name = name; this._action = action; @@ -681,7 +610,7 @@ namespace WACCALauncher throw new ArgumentException($"Menu item '{name}' was defined with VersionSelect type, but has no version associated."); this._method = method; - this._submenu = submenu; + this.submenu = submenu; this._options = options; this._version = version; } @@ -696,17 +625,19 @@ namespace WACCALauncher label.ForeColor = Color.White; } - public void Select(MainForm form, ConfigMenu menu) + public void Select(MainForm form) { if (_action == ConfigMenuAction.Command) { // only works with static methods, why this._method(); } - else if (_action == ConfigMenuAction.Submenu && _submenu != null) + else if (_action == ConfigMenuAction.Submenu && submenu != null) { Console.WriteLine("attempting submenu"); - form.GenerateMenu(_submenu); + form._menuManager.NavigateToSubMenu(Name); + form.waccaListTest.Update(); + //form.GenerateMenu(_submenu); } else if (_action == ConfigMenuAction.ItemSelect && _options != null) { @@ -720,16 +651,54 @@ namespace WACCALauncher for (int i = 0; i < form.Versions.Count; i++) { var name = form.Versions[i].GameVersion == VersionType.Custom ? form.Versions[i].CustomName : form.Versions[i].ToString(); - menu[i].label.Text = $"({(form.Versions[i] == form.DefaultVer ? 'X' : ' ')}) {name}".ToUpper(); + //menu[i].label.Text = $"({(form.Versions[i] == form.DefaultVer ? 'X' : ' ')}) {name}".ToUpper(); } - form.RefreshMenu(); + //form.RefreshMenu(); } - else if (_action == ConfigMenuAction.Return) - if(form.CurrentMenu == form.MainMenu) - { - form.MenuHide(); - } - else form.GenerateMenu(form.CurrentMenu.ParentMenu); + else if (_action == ConfigMenuAction.Return) { form.MenuHide(); } + } + + public override string ToString() + { + return Name; } } + + public class MenuManager + { + private List currentMenu; + public readonly string name; + + public MenuManager(List menu, string menuName) + { + currentMenu = menu; + name = menuName; + } + + public List GetCurrentMenu() + { + return currentMenu; + } + + public void NavigateToSubMenu(string optionName) + { + if (optionName != string.Empty && optionName != null) + { + var selectedItem = currentMenu.Find(x => x.Name == optionName); + if (selectedItem.submenu != null && selectedItem.submenu.Count > 0) + { + currentMenu = selectedItem.submenu; + } + } + } + + //public void NavigateBack() + //{ + // if (currentMenu > 0 && currentMenu[0].Parent != null) + // { + // currentMenu = currentMenu[0].Parent.SubItems; + // } + //} + } + } diff --git a/WACCALauncher.csproj b/WACCALauncher.csproj index fc70ca6..ba4fa89 100644 --- a/WACCALauncher.csproj +++ b/WACCALauncher.csproj @@ -66,6 +66,9 @@ + + Component + MainForm.cs diff --git a/WaccaList.cs b/WaccaList.cs new file mode 100644 index 0000000..2dae140 --- /dev/null +++ b/WaccaList.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WACCALauncher +{ + public partial class WaccaList : System.Windows.Forms.ListBox + { + private MenuManager menuManager; + + public WaccaList() + { + BackColor = Color.Black; + BorderStyle = BorderStyle.None; + DrawMode = DrawMode.OwnerDrawVariable; + ItemHeight = 40; + Size = new System.Drawing.Size(680, 600); + Location = new System.Drawing.Point(200, 240); + } + + public void AssignMenuManager(MenuManager manager) + { + menuManager = manager; + Items.Clear(); + Items.AddRange(menuManager.GetCurrentMenu().ToArray()); + } + + protected override void OnDrawItem(DrawItemEventArgs e) + { + e.Graphics.FillRectangle(new SolidBrush(BackColor), e.Bounds); + + if (Items.Count < 1) return; + + var text = Items[e.Index].ToString().ToUpper(); + var selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected; + + e.Graphics.DrawString(text, Font, selected ? Brushes.Red : Brushes.White, e.Bounds); + } + + protected override void OnInvalidated(InvalidateEventArgs e) + { + Items.Clear(); + Items.AddRange(menuManager.GetCurrentMenu().ToArray()); + SelectedIndex = 0; + base.OnInvalidated(e); + } + } +}