mirror of
https://github.com/YellowberryHN/WACCALauncher
synced 2025-02-25 14:04:54 +01:00
Refactor menu control methods into MenuManager
This commit is contained in:
parent
18e493e9c6
commit
0400ee4472
2
MainForm.Designer.cs
generated
2
MainForm.Designer.cs
generated
@ -83,7 +83,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Label menuLabel;
|
private System.Windows.Forms.Label menuLabel;
|
||||||
public WaccaList waccaListTest;
|
private WaccaList waccaListTest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
119
MainForm.cs
119
MainForm.cs
@ -91,20 +91,20 @@ namespace WACCALauncher
|
|||||||
private bool[] _buttonStates;
|
private bool[] _buttonStates;
|
||||||
private bool[] _lastButtonStates = new bool[4];
|
private bool[] _lastButtonStates = new bool[4];
|
||||||
|
|
||||||
private bool _autoLaunch = true;
|
public bool _autoLaunch = true;
|
||||||
private int _currentMenuItem;
|
private int _currentMenuItem;
|
||||||
|
|
||||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||||
{
|
{
|
||||||
if (!_gameRunning)
|
if (!_gameRunning)
|
||||||
{
|
{
|
||||||
if (keyData == Keys.Up) { CursorUp(); return true; }
|
if (keyData == Keys.Up) { _menuManager.CursorUp(); return true; }
|
||||||
else if (keyData == Keys.Down) { CursorDown(); return true; }
|
else if (keyData == Keys.Down) { _menuManager.CursorDown(); return true; }
|
||||||
else if (keyData == Keys.Enter) { MenuSelect(); return true; }
|
else if (keyData == Keys.Enter) { _menuManager.MenuSelect(); return true; }
|
||||||
else if (keyData == Keys.Escape)
|
else if (keyData == Keys.Escape)
|
||||||
{
|
{
|
||||||
if (_autoLaunch) MenuShow();
|
if (_autoLaunch) MenuShow();
|
||||||
else MenuBack();
|
else _menuManager.MenuBack();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,21 +157,21 @@ namespace WACCALauncher
|
|||||||
if (_buttonStates[0] && !_lastButtonStates[0])
|
if (_buttonStates[0] && !_lastButtonStates[0])
|
||||||
{
|
{
|
||||||
Console.WriteLine("vol down");
|
Console.WriteLine("vol down");
|
||||||
CursorDown();
|
_menuManager.CursorDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// vol up
|
// vol up
|
||||||
if (_buttonStates[1] && !_lastButtonStates[1])
|
if (_buttonStates[1] && !_lastButtonStates[1])
|
||||||
{
|
{
|
||||||
Console.WriteLine("vol up");
|
Console.WriteLine("vol up");
|
||||||
CursorUp();
|
_menuManager.CursorUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
// service
|
// service
|
||||||
if (_buttonStates[6] && !_lastButtonStates[6])
|
if (_buttonStates[6] && !_lastButtonStates[6])
|
||||||
{
|
{
|
||||||
Console.WriteLine("service button");
|
Console.WriteLine("service button");
|
||||||
CursorDown();
|
_menuManager.CursorDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -182,27 +182,13 @@ namespace WACCALauncher
|
|||||||
{
|
{
|
||||||
MenuShow();
|
MenuShow();
|
||||||
}
|
}
|
||||||
else MenuSelect();
|
else _menuManager.MenuSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastButtonStates = _buttonStates;
|
_lastButtonStates = _buttonStates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CursorUp()
|
|
||||||
{
|
|
||||||
// move cursor up
|
|
||||||
var idx = ((waccaListTest.SelectedIndex - 1) + waccaListTest.Items.Count) % waccaListTest.Items.Count;
|
|
||||||
waccaListTest.SelectedIndex = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CursorDown()
|
|
||||||
{
|
|
||||||
// move cursor down
|
|
||||||
var idx = (waccaListTest.SelectedIndex + 1) % waccaListTest.Items.Count;
|
|
||||||
waccaListTest.SelectedIndex = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MenuShow()
|
public void MenuShow()
|
||||||
{
|
{
|
||||||
_delayTimer.Stop();
|
_delayTimer.Stop();
|
||||||
@ -225,39 +211,11 @@ namespace WACCALauncher
|
|||||||
_delayTimer.Enabled = true;
|
_delayTimer.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MenuBack()
|
public void MenuUpdateLabel(string text)
|
||||||
{
|
{
|
||||||
// back from current menu item
|
menuLabel.Text = text.ToUpper();
|
||||||
Console.WriteLine("MenuBack");
|
|
||||||
if (_menuManager.GetCurrentMenu().ParentMenu == null)
|
|
||||||
MenuHide();
|
|
||||||
else _menuManager.NavigateBack();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuSelect()
|
|
||||||
{
|
|
||||||
// select menu item
|
|
||||||
Console.WriteLine("MenuSelect");
|
|
||||||
(waccaListTest.SelectedItem as ConfigMenu).Select(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
private void MenuReturn()
|
|
||||||
{
|
|
||||||
GenerateMenu(MainMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RefreshMenu()
|
|
||||||
{
|
|
||||||
this.Controls.Remove(CurrentMenu[_currentMenuItem].label);
|
|
||||||
CurrentMenu[_currentMenuItem].Activate();
|
|
||||||
this.Controls.Add(CurrentMenu[_currentMenuItem].label);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static void vfd_test()
|
private static void vfd_test()
|
||||||
{
|
{
|
||||||
var vfd = new WaccaVFD();
|
var vfd = new WaccaVFD();
|
||||||
@ -269,7 +227,7 @@ namespace WACCALauncher
|
|||||||
vfd.Write("Testing VFD!");
|
vfd.Write("Testing VFD!");
|
||||||
vfd.Cursor(0, 16);
|
vfd.Cursor(0, 16);
|
||||||
vfd.ScrollSpeed(2);
|
vfd.ScrollSpeed(2);
|
||||||
vfd.ScrollText(Math.PI.ToString()+" ");
|
vfd.ScrollText(Math.PI.ToString() + " ");
|
||||||
vfd.ScrollStart();
|
vfd.ScrollStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +272,7 @@ namespace WACCALauncher
|
|||||||
new ConfigMenu("launch game", ConfigMenuAction.Return)
|
new ConfigMenu("launch game", ConfigMenuAction.Return)
|
||||||
});
|
});
|
||||||
|
|
||||||
_menuManager = new MenuManager(mainMenu, waccaListTest);
|
_menuManager = new MenuManager(mainMenu, waccaListTest, this);
|
||||||
|
|
||||||
_loadingLabel.Font = _menuFont;
|
_loadingLabel.Font = _menuFont;
|
||||||
menuLabel.Font = _menuFont;
|
menuLabel.Font = _menuFont;
|
||||||
@ -376,8 +334,8 @@ namespace WACCALauncher
|
|||||||
private void LaunchDefault(Object source, ElapsedEventArgs e)
|
private void LaunchDefault(Object source, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
_delayTimer.Stop();
|
_delayTimer.Stop();
|
||||||
//KillExplorer();
|
KillExplorer();
|
||||||
//LaunchGame(DefaultVer);
|
LaunchGame(DefaultVer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadVersionsFromConfig()
|
private void LoadVersionsFromConfig()
|
||||||
@ -582,7 +540,7 @@ namespace WACCALauncher
|
|||||||
// TODO: this is kinda jank, fix this
|
// TODO: this is kinda jank, fix this
|
||||||
form._menuManager.UpdateCurrentMenuItems(form.GetDefaultVersionMenu());
|
form._menuManager.UpdateCurrentMenuItems(form.GetDefaultVersionMenu());
|
||||||
}
|
}
|
||||||
else if (_action == ConfigMenuAction.Return) { form.MenuBack(); }
|
else if (_action == ConfigMenuAction.Return) { form._menuManager.MenuBack(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMenu(string name, ConfigMenuAction action = ConfigMenuAction.None, Action method = null, List<ConfigMenu> items = null, List<string> options = null, Version version = null)
|
public ConfigMenu(string name, ConfigMenuAction action = ConfigMenuAction.None, Action method = null, List<ConfigMenu> items = null, List<string> options = null, Version version = null)
|
||||||
@ -616,14 +574,54 @@ namespace WACCALauncher
|
|||||||
private ConfigMenu _rootMenu;
|
private ConfigMenu _rootMenu;
|
||||||
private ConfigMenu _currentMenu;
|
private ConfigMenu _currentMenu;
|
||||||
private WaccaList _list;
|
private WaccaList _list;
|
||||||
|
private MainForm _form;
|
||||||
|
|
||||||
public MenuManager(ConfigMenu root, WaccaList list)
|
public MenuManager(ConfigMenu root, WaccaList list, MainForm form)
|
||||||
{
|
{
|
||||||
_rootMenu = root;
|
_rootMenu = root;
|
||||||
_currentMenu = _rootMenu;
|
_currentMenu = _rootMenu;
|
||||||
_list = list;
|
_list = list;
|
||||||
_list.AssignMenuManager(this);
|
_list.AssignMenuManager(this);
|
||||||
UpdateList();
|
_form = form;
|
||||||
|
UpdateList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CursorUp()
|
||||||
|
{
|
||||||
|
// move cursor up
|
||||||
|
if (_form._autoLaunch) return;
|
||||||
|
|
||||||
|
var idx = ((_list.SelectedIndex - 1) + _list.Items.Count) % _list.Items.Count;
|
||||||
|
_list.SelectedIndex = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CursorDown()
|
||||||
|
{
|
||||||
|
// move cursor down
|
||||||
|
if (_form._autoLaunch) return;
|
||||||
|
|
||||||
|
var idx = (_list.SelectedIndex + 1) % _list.Items.Count;
|
||||||
|
_list.SelectedIndex = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MenuBack()
|
||||||
|
{
|
||||||
|
// back from current menu item
|
||||||
|
if (_form._autoLaunch) return;
|
||||||
|
|
||||||
|
Console.WriteLine("MenuBack");
|
||||||
|
if (_form._menuManager.GetCurrentMenu().ParentMenu == null)
|
||||||
|
_form.MenuHide();
|
||||||
|
else _form._menuManager.NavigateBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MenuSelect()
|
||||||
|
{
|
||||||
|
// select menu item
|
||||||
|
if (_form._autoLaunch) return;
|
||||||
|
|
||||||
|
Console.WriteLine("MenuSelect");
|
||||||
|
(_list.SelectedItem as ConfigMenu).Select(_form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMenu GetCurrentMenu()
|
public ConfigMenu GetCurrentMenu()
|
||||||
@ -655,6 +653,7 @@ namespace WACCALauncher
|
|||||||
var oldIndex = _list.SelectedIndex;
|
var oldIndex = _list.SelectedIndex;
|
||||||
_list.Items.Clear();
|
_list.Items.Clear();
|
||||||
_list.Items.AddRange(_currentMenu.Items.ToArray());
|
_list.Items.AddRange(_currentMenu.Items.ToArray());
|
||||||
|
_form.MenuUpdateLabel(_currentMenu.Name);
|
||||||
if (_list.Items.Count > 0) _list.SelectedIndex = preserveIndex ? oldIndex : 0;
|
if (_list.Items.Count > 0) _list.SelectedIndex = preserveIndex ? oldIndex : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.9.0.1")]
|
[assembly: AssemblyVersion("0.10.0.0")]
|
||||||
[assembly: AssemblyFileVersion("0.9.0.1")]
|
[assembly: AssemblyFileVersion("0.10.0.0")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user