renaming + variable cleanup

- rename UpdateState to PlayButtonState for better clarity
- move variables that are only used in constructor to local scope
- make colors and formBG readonly
pull/32/head
Miepee 4 years ago
parent 386bcf623d
commit 0067a6b9a5

@ -38,7 +38,7 @@ namespace AM2RLauncher
if (!Profile.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked) if (!Profile.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked)
return; return;
SetPlayButtonState(UpdateState.Downloading); SetPlayButtonState(PlayButtonState.Downloading);
progressBar.Visible = true; progressBar.Visible = true;
progressLabel.Visible = true; progressLabel.Visible = true;
@ -113,7 +113,7 @@ namespace AM2RLauncher
} }
} }
SetPlayButtonState(UpdateState.Install); SetPlayButtonState(PlayButtonState.Install);
UpdateStateMachine(); UpdateStateMachine();
} }
@ -160,7 +160,7 @@ namespace AM2RLauncher
/// <summary> /// <summary>
/// Gets called when user tries to close <see cref="MainForm"/>. This does a few things:<br/> /// Gets called when user tries to close <see cref="MainForm"/>. This does a few things:<br/>
/// 1) Writes the Width, Height, the check if <see cref="MainForm"/> is currently maximized and the ProfileIndex to the Config<br/> /// 1) Writes the Width, Height, the check if <see cref="MainForm"/> is currently maximized and the ProfileIndex to the Config<br/>
/// 2) Checks if current <see cref="updateState"/> is <see cref="UpdateState.Downloading"/>. If yes, it creates a Warning to the end user. /// 2) Checks if current <see cref="updateState"/> is <see cref="PlayButtonState.Downloading"/>. If yes, it creates a Warning to the end user.
/// </summary> /// </summary>
private void MainformClosing(object sender, CancelEventArgs e) private void MainformClosing(object sender, CancelEventArgs e)
{ {
@ -174,7 +174,7 @@ namespace AM2RLauncher
switch (updateState) switch (updateState)
{ {
// If we're currently still downloading, ask first if user really wants to close and cancel the event if necessary // If we're currently still downloading, ask first if user really wants to close and cancel the event if necessary
case UpdateState.Downloading: case PlayButtonState.Downloading:
{ {
var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo,
MessageBoxType.Warning, MessageBoxDefaultButton.No); MessageBoxType.Warning, MessageBoxDefaultButton.No);
@ -187,7 +187,7 @@ namespace AM2RLauncher
break; break;
} }
// We can't close during installing, so we cancel the event. // We can't close during installing, so we cancel the event.
case UpdateState.Installing: case PlayButtonState.Installing:
{ {
MessageBox.Show(this, Text.CloseOnInstallingText, Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning); MessageBox.Show(this, Text.CloseOnInstallingText, Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning);
e.Cancel = true; e.Cancel = true;
@ -232,13 +232,13 @@ namespace AM2RLauncher
switch (updateState) switch (updateState)
{ {
#region Download #region Download
case UpdateState.Download: case PlayButtonState.Download:
log.Info("Attempting to clone repository " + currentMirror + "..."); log.Info("Attempting to clone repository " + currentMirror + "...");
bool successful = true; bool successful = true;
// Update playButton states // Update playButton states
SetPlayButtonState(UpdateState.Downloading); SetPlayButtonState(PlayButtonState.Downloading);
// Enable progressBar // Enable progressBar
progressBar.Visible = true; progressBar.Visible = true;
@ -306,7 +306,7 @@ namespace AM2RLauncher
progressBar.Value = 0; progressBar.Value = 0;
// Just need to switch this to anything that isn't an "active" state so SetUpdateState() actually does something // Just need to switch this to anything that isn't an "active" state so SetUpdateState() actually does something
SetPlayButtonState(UpdateState.Install); SetPlayButtonState(PlayButtonState.Install);
// This needs to be run BEFORE the state check so that the Mod Settings tab doesn't weird out // This needs to be run BEFORE the state check so that the Mod Settings tab doesn't weird out
LoadProfilesAndAdjustLists(); LoadProfilesAndAdjustLists();
@ -319,7 +319,7 @@ namespace AM2RLauncher
#region Downloading #region Downloading
case UpdateState.Downloading: case PlayButtonState.Downloading:
var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, MessageBoxType.Warning, MessageBoxDefaultButton.No); var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, MessageBoxType.Warning, MessageBoxDefaultButton.No);
if (result != DialogResult.Yes) if (result != DialogResult.Yes)
return; return;
@ -336,7 +336,7 @@ namespace AM2RLauncher
#endregion #endregion
#region Select11 #region Select11
case UpdateState.Select11: case PlayButtonState.Select11:
log.Info("Requesting user input for AM2R_11.zip..."); log.Info("Requesting user input for AM2R_11.zip...");
@ -381,10 +381,10 @@ namespace AM2RLauncher
#endregion #endregion
#region Install #region Install
case UpdateState.Install: case PlayButtonState.Install:
progressBar.Visible = true; progressBar.Visible = true;
progressBar.Value = 0; progressBar.Value = 0;
SetPlayButtonState(UpdateState.Installing); SetPlayButtonState(PlayButtonState.Installing);
// Make sure the main interface state machines properly // Make sure the main interface state machines properly
UpdateApkState(); UpdateApkState();
@ -398,7 +398,7 @@ namespace AM2RLauncher
{ {
MessageBox.Show(this, Text.XdeltaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK); MessageBox.Show(this, Text.XdeltaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK);
SetPlayButtonState(UpdateState.Install); SetPlayButtonState(PlayButtonState.Install);
UpdateStateMachine(); UpdateStateMachine();
log.Error("Xdelta not found. Aborting installing a profile..."); log.Error("Xdelta not found. Aborting installing a profile...");
return; return;
@ -419,20 +419,20 @@ namespace AM2RLauncher
progressBar.Value = 0; progressBar.Value = 0;
// Just need to switch this to anything that isn't an "active" state so SetUpdateState() actually does something // Just need to switch this to anything that isn't an "active" state so SetUpdateState() actually does something
SetPlayButtonState(UpdateState.Play); SetPlayButtonState(PlayButtonState.Play);
UpdateStateMachine(); UpdateStateMachine();
break; break;
#endregion #endregion
#region Play #region Play
case UpdateState.Play: case PlayButtonState.Play:
if (!IsProfileIndexValid()) if (!IsProfileIndexValid())
return; return;
ProfileXML profile = profileList[profileIndex.Value]; ProfileXML profile = profileList[profileIndex.Value];
Visible = false; Visible = false;
SetPlayButtonState(UpdateState.Playing); SetPlayButtonState(PlayButtonState.Playing);
// Make sure the main interface state machines properly // Make sure the main interface state machines properly
UpdateApkState(); UpdateApkState();
@ -455,7 +455,7 @@ namespace AM2RLauncher
Visible = true; Visible = true;
WindowState = windowStateBeforeLaunching; WindowState = windowStateBeforeLaunching;
SetPlayButtonState(UpdateState.Play); SetPlayButtonState(PlayButtonState.Play);
UpdateStateMachine(); UpdateStateMachine();
break; break;
@ -602,7 +602,7 @@ namespace AM2RLauncher
} }
/// <summary>Gets called when user selects a different item from <see cref="mirrorDropDown"/>. /// <summary>Gets called when user selects a different item from <see cref="mirrorDropDown"/>.
/// It then writes that to the config, and if <see cref="updateState"/> is not <see cref="UpdateState.Downloading"/> /// It then writes that to the config, and if <see cref="updateState"/> is not <see cref="PlayButtonState.Downloading"/>
/// it also overwrites the upstream URL in .git/config.</summary> /// it also overwrites the upstream URL in .git/config.</summary>
private void MirrorDropDownSelectedIndexChanged(object sender, EventArgs e) private void MirrorDropDownSelectedIndexChanged(object sender, EventArgs e)
{ {
@ -613,7 +613,7 @@ namespace AM2RLauncher
CrossPlatformOperations.WriteToConfig("MirrorIndex", mirrorDropDown.SelectedIndex); CrossPlatformOperations.WriteToConfig("MirrorIndex", mirrorDropDown.SelectedIndex);
// Don't overwrite the git config while we download!!! // Don't overwrite the git config while we download!!!
if (updateState == UpdateState.Downloading) return; if (updateState == PlayButtonState.Downloading) return;
log.Info("Overwriting mirror in gitconfig."); log.Info("Overwriting mirror in gitconfig.");

@ -23,12 +23,12 @@ namespace AM2RLauncher
} }
/// <summary> /// <summary>
/// Determines current conditions and calls <see cref="SetPlayButtonState(UpdateState)"/> accordingly. /// Determines current conditions and calls <see cref="SetPlayButtonState(PlayButtonState)"/> accordingly.
/// </summary> /// </summary>
private void UpdatePlayState() private void UpdatePlayState()
{ {
// If we're downloading or installing, dont't change anything // If we're downloading or installing, dont't change anything
if ((updateState == UpdateState.Downloading) || (updateState == UpdateState.Installing)) if ((updateState == PlayButtonState.Downloading) || (updateState == PlayButtonState.Installing))
return; return;
// If we're currently creating an APK, we disable the play button // If we're currently creating an APK, we disable the play button
@ -42,14 +42,14 @@ namespace AM2RLauncher
// If PatchData isn't cloned, we still need to download // If PatchData isn't cloned, we still need to download
if (!Profile.IsPatchDataCloned()) if (!Profile.IsPatchDataCloned())
{ {
SetPlayButtonState(UpdateState.Download); SetPlayButtonState(PlayButtonState.Download);
return; return;
} }
// If 1.1 isn't installed, we still need to select it // If 1.1 isn't installed, we still need to select it
if (!Profile.Is11Installed()) if (!Profile.Is11Installed())
{ {
SetPlayButtonState(UpdateState.Select11); SetPlayButtonState(PlayButtonState.Select11);
return; return;
} }
@ -57,7 +57,7 @@ namespace AM2RLauncher
// If current profile is installed, we're ready to play! // If current profile is installed, we're ready to play!
if (isProfileValid && Profile.IsProfileInstalled(profileList[profileIndex.Value])) if (isProfileValid && Profile.IsProfileInstalled(profileList[profileIndex.Value]))
{ {
SetPlayButtonState(UpdateState.Play); SetPlayButtonState(PlayButtonState.Play);
return; return;
} }
// Otherwise, if profile is NOT installable, we delete the profile because we can't install it and therefore holds no value! // Otherwise, if profile is NOT installable, we delete the profile because we can't install it and therefore holds no value!
@ -68,7 +68,7 @@ namespace AM2RLauncher
} }
// Otherwise, we still need to install. // Otherwise, we still need to install.
SetPlayButtonState(UpdateState.Install); SetPlayButtonState(PlayButtonState.Install);
} }
/// <summary> /// <summary>
@ -95,14 +95,14 @@ namespace AM2RLauncher
// Switch status based on main button's state // Switch status based on main button's state
switch (updateState) switch (updateState)
{ {
case UpdateState.Download: case PlayButtonState.Download:
case UpdateState.Downloading: case PlayButtonState.Downloading:
case UpdateState.Select11: case PlayButtonState.Select11:
case UpdateState.Installing: case PlayButtonState.Installing:
case UpdateState.Playing: return; case PlayButtonState.Playing: return;
case UpdateState.Install: case PlayButtonState.Install:
case UpdateState.Play: apkButton.Enabled = true; apkButton.ToolTip = HelperMethods.GetText(Text.ApkButtonEnabledToolTip, profileDropDown?.Items[profileDropDown.SelectedIndex]?.Text ?? ""); break; case PlayButtonState.Play: apkButton.Enabled = true; apkButton.ToolTip = HelperMethods.GetText(Text.ApkButtonEnabledToolTip, profileDropDown?.Items[profileDropDown.SelectedIndex]?.Text ?? ""); break;
} }
} }
@ -116,14 +116,14 @@ namespace AM2RLauncher
return; return;
switch (updateState) switch (updateState)
{ {
case UpdateState.Download: case PlayButtonState.Download:
case UpdateState.Downloading: case PlayButtonState.Downloading:
case UpdateState.Select11: case PlayButtonState.Select11:
case UpdateState.Installing: case PlayButtonState.Installing:
case UpdateState.Playing: profileDropDown.Enabled = false; break; case PlayButtonState.Playing: profileDropDown.Enabled = false; break;
case UpdateState.Install: case PlayButtonState.Install:
case UpdateState.Play: profileDropDown.Enabled = true; break; case PlayButtonState.Play: profileDropDown.Enabled = true; break;
} }
if (apkButtonState == ApkButtonState.Creating) profileDropDown.Enabled = false; if (apkButtonState == ApkButtonState.Creating) profileDropDown.Enabled = false;
@ -148,14 +148,14 @@ namespace AM2RLauncher
bool enabled = false; bool enabled = false;
switch (updateState) switch (updateState)
{ {
case UpdateState.Download: case PlayButtonState.Download:
case UpdateState.Downloading: case PlayButtonState.Downloading:
case UpdateState.Select11: case PlayButtonState.Select11:
case UpdateState.Installing: case PlayButtonState.Installing:
case UpdateState.Playing: enabled = false; break; case PlayButtonState.Playing: enabled = false; break;
case UpdateState.Install: case PlayButtonState.Install:
case UpdateState.Play: enabled = true; break; case PlayButtonState.Play: enabled = true; break;
} }
if (apkButtonState == ApkButtonState.Creating) enabled = false; if (apkButtonState == ApkButtonState.Creating) enabled = false;
@ -195,19 +195,19 @@ namespace AM2RLauncher
/// Sets the global <see cref="updateState"/> and then changes the state of <see cref="playButton"/> accordingly. /// Sets the global <see cref="updateState"/> and then changes the state of <see cref="playButton"/> accordingly.
/// </summary> /// </summary>
/// <param name="state">The state that should be set to.</param> /// <param name="state">The state that should be set to.</param>
private void SetPlayButtonState(UpdateState state) private void SetPlayButtonState(PlayButtonState state)
{ {
updateState = state; updateState = state;
switch (updateState) switch (updateState)
{ {
case UpdateState.Download: case PlayButtonState.Download:
case UpdateState.Downloading: case PlayButtonState.Downloading:
case UpdateState.Select11: case PlayButtonState.Select11:
case UpdateState.Install: case PlayButtonState.Install:
case UpdateState.Play: playButton.Enabled = true; break; case PlayButtonState.Play: playButton.Enabled = true; break;
case UpdateState.Installing: case PlayButtonState.Installing:
case UpdateState.Playing: playButton.Enabled = false; break; case PlayButtonState.Playing: playButton.Enabled = false; break;
} }
playButton.Text = GetPlayButtonText(); playButton.Text = GetPlayButtonText();
playButton.ToolTip = GetPlayButtonTooltip(); playButton.ToolTip = GetPlayButtonTooltip();
@ -240,13 +240,13 @@ namespace AM2RLauncher
{ {
switch (updateState) switch (updateState)
{ {
case UpdateState.Download: return Text.Download; case PlayButtonState.Download: return Text.Download;
case UpdateState.Downloading: return Text.Abort; case PlayButtonState.Downloading: return Text.Abort;
case UpdateState.Select11: return Text.Select11; case PlayButtonState.Select11: return Text.Select11;
case UpdateState.Install: return Text.Install; case PlayButtonState.Install: return Text.Install;
case UpdateState.Installing: return Text.Installing; case PlayButtonState.Installing: return Text.Installing;
case UpdateState.Play: return Text.Play; case PlayButtonState.Play: return Text.Play;
case UpdateState.Playing: return Text.Playing; case PlayButtonState.Playing: return Text.Playing;
default: return null; default: return null;
} }
} }
@ -260,13 +260,13 @@ namespace AM2RLauncher
string profileName = ((profileDropDown != null) && (profileDropDown.Items.Count > 0)) ? profileDropDown.Items[profileDropDown.SelectedIndex].Text : ""; string profileName = ((profileDropDown != null) && (profileDropDown.Items.Count > 0)) ? profileDropDown.Items[profileDropDown.SelectedIndex].Text : "";
switch (updateState) switch (updateState)
{ {
case UpdateState.Download: return Text.PlayButtonDownloadToolTip; case PlayButtonState.Download: return Text.PlayButtonDownloadToolTip;
case UpdateState.Downloading: return Text.PlayButtonDownloadToolTip; case PlayButtonState.Downloading: return Text.PlayButtonDownloadToolTip;
case UpdateState.Select11: return Text.PlayButtonSelect11ToolTip; case PlayButtonState.Select11: return Text.PlayButtonSelect11ToolTip;
case UpdateState.Install: return playButton.ToolTip = HelperMethods.GetText(Text.PlayButtonInstallToolTip, profileName); case PlayButtonState.Install: return playButton.ToolTip = HelperMethods.GetText(Text.PlayButtonInstallToolTip, profileName);
case UpdateState.Installing: return Text.PlayButtonInstallingToolTip; case PlayButtonState.Installing: return Text.PlayButtonInstallingToolTip;
case UpdateState.Play: return HelperMethods.GetText(Text.PlayButtonPlayToolTip, profileName); case PlayButtonState.Play: return HelperMethods.GetText(Text.PlayButtonPlayToolTip, profileName);
case UpdateState.Playing: return Text.PlayButtonPlayingToolTip; case PlayButtonState.Playing: return Text.PlayButtonPlayingToolTip;
default: return null; default: return null;
} }
} }
@ -374,7 +374,7 @@ namespace AM2RLauncher
customMirrorTextBox.Enabled = enabled; customMirrorTextBox.Enabled = enabled;
mirrorDropDown.Enabled = !enabled; mirrorDropDown.Enabled = !enabled;
// Not sure why the dropdown menu needs this hack, but the textBox does not. // Not sure why the dropdown menu needs this hack, but the textBox does not.
//TODO: eto issue? //TODO: eto feature request
if (OS.IsWindows) if (OS.IsWindows)
mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive;
mirrorLabel.TextColor = !enabled ? colGreen : colInactive; mirrorLabel.TextColor = !enabled ? colGreen : colInactive;

@ -1,6 +1,7 @@
using AM2RLauncher.Core; using AM2RLauncher.Core;
using AM2RLauncher.Core.XML; using AM2RLauncher.Core.XML;
using AM2RLauncher.Language; using AM2RLauncher.Language;
using AM2RLauncher.Properties;
using Eto.Drawing; using Eto.Drawing;
using Eto.Forms; using Eto.Forms;
using log4net; using log4net;
@ -31,15 +32,11 @@ namespace AM2RLauncher
/// </summary> /// </summary>
private const string VERSION = LauncherUpdater.VERSION; private const string VERSION = LauncherUpdater.VERSION;
/// <summary>
/// A <see cref="Bitmap"/> of the AM2R icon.
/// </summary>
private static readonly Bitmap am2rIcon = new Bitmap(AM2RLauncher.Properties.Resources.AM2RIcon);
/// <summary> /// <summary>
/// An enum, that has possible states for our Launcher. /// An enum, that has possible states for the play button.
/// </summary> /// </summary>
public enum UpdateState public enum PlayButtonState
{ {
Download, Download,
Downloading, Downloading,
@ -62,7 +59,7 @@ namespace AM2RLauncher
/// <summary> /// <summary>
/// This variable has the current global state of the Launcher. /// This variable has the current global state of the Launcher.
/// </summary> /// </summary>
private static UpdateState updateState = UpdateState.Download; private static PlayButtonState updateState = PlayButtonState.Download;
/// <summary> /// <summary>
/// This variable has the current global statue of the <see cref="apkButton"/>. /// This variable has the current global statue of the <see cref="apkButton"/>.
/// </summary> /// </summary>
@ -101,13 +98,9 @@ namespace AM2RLauncher
if (OS.IsWindows) if (OS.IsWindows)
{ {
Process current = Process.GetCurrentProcess(); Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName)) Process process = Process.GetProcessesByName(current.ProcessName).First(p => p.Id == current.Id);
{ if (process != null)
if (process.Id == current.Id)
continue;
Core.Core.SetForegroundWindow(process.MainWindowHandle); Core.Core.SetForegroundWindow(process.MainWindowHandle);
break;
}
} }
Environment.Exit(0); Environment.Exit(0);
} }
@ -134,8 +127,10 @@ namespace AM2RLauncher
#region VARIABLE INITIALIZATION #region VARIABLE INITIALIZATION
log.Info("Beginning UI initialization..."); log.Info("Beginning UI initialization...");
Bitmap am2rIcon = new Bitmap(AM2RLauncher.Properties.Resources.AM2RIcon);
// System tray indicator // System tray indicator
showButton = new ButtonMenuItem { Text = Text.TrayButtonShow }; ButtonMenuItem showButton = new ButtonMenuItem { Text = Text.TrayButtonShow };
trayIndicator = new TrayIndicator trayIndicator = new TrayIndicator
{ {
Menu = new ContextMenu(showButton), Menu = new ContextMenu(showButton),
@ -151,6 +146,7 @@ namespace AM2RLauncher
// Create array from validCount // Create array from validCount
profileList = new List<ProfileXML>(); profileList = new List<ProfileXML>();
//TODO: whenever profileDropDown gets rewritten to use a datastore, scrap this
profileNames = new List<ListItem>(); profileNames = new List<ListItem>();
foreach (var profile in profileList) foreach (var profile in profileList)
{ {
@ -161,23 +157,6 @@ namespace AM2RLauncher
string splash = Splash.GetSplash(); string splash = Splash.GetSplash();
log.Info("Randomly chosen splash: " + splash); log.Info("Randomly chosen splash: " + splash);
// Load bitmaps
redditIcon = new Bitmap(AM2RLauncher.Properties.Resources.redditIcon48);
githubIcon = new Bitmap(AM2RLauncher.Properties.Resources.githubIcon48);
youtubeIcon = new Bitmap(AM2RLauncher.Properties.Resources.youtubeIcon48);
discordIcon = new Bitmap(AM2RLauncher.Properties.Resources.discordIcon48);
formBG = new Bitmap(AM2RLauncher.Properties.Resources.bgCentered);
// Load colors
colGreen = Color.FromArgb(142, 188, 35);
colRed = Color.FromArgb(188, 10, 35);
colInactive = Color.FromArgb(109, 109, 109);
colBGNoAlpha = Color.FromArgb(10, 10, 10);
colBG = Color.FromArgb(10, 10, 10, 80);
if (OS.IsLinux) colBG = colBGNoAlpha; // XORG can't display alpha anyway, and Wayland breaks with it.
// TODO: that sounds like an Eto bug. investigate, try to open eto issue.
colBGHover = Color.FromArgb(17, 28, 13);
Font smallButtonFont = new Font(SystemFont.Default, 10); Font smallButtonFont = new Font(SystemFont.Default, 10);
// Create mirror list - eventually this should be platform specific! // Create mirror list - eventually this should be platform specific!
@ -347,15 +326,19 @@ namespace AM2RLauncher
// Social buttons // Social buttons
Bitmap redditIcon = new Bitmap(Resources.redditIcon48);
var redditButton = new ImageButton { ToolTip = Text.RedditToolTip, Image = redditIcon }; var redditButton = new ImageButton { ToolTip = Text.RedditToolTip, Image = redditIcon };
redditButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.reddit.com/r/AM2R"); redditButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.reddit.com/r/AM2R");
Bitmap githubIcon = new Bitmap(Resources.githubIcon48);
var githubButton = new ImageButton { ToolTip = Text.GithubToolTip, Image = githubIcon }; var githubButton = new ImageButton { ToolTip = Text.GithubToolTip, Image = githubIcon };
githubButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.github.com/AM2R-Community-Developers"); githubButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.github.com/AM2R-Community-Developers");
Bitmap youtubeIcon = new Bitmap(Resources.youtubeIcon48);
var youtubeButton = new ImageButton { ToolTip = Text.YoutubeToolTip, Image = youtubeIcon }; var youtubeButton = new ImageButton { ToolTip = Text.YoutubeToolTip, Image = youtubeIcon };
youtubeButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.youtube.com/c/AM2RCommunityUpdates"); youtubeButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.youtube.com/c/AM2RCommunityUpdates");
Bitmap discordIcon = new Bitmap(Resources.discordIcon48);
var discordButton = new ImageButton { ToolTip = Text.DiscordToolTip, Image = discordIcon }; var discordButton = new ImageButton { ToolTip = Text.DiscordToolTip, Image = discordIcon };
discordButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://discord.gg/nk7UYPbd5u"); discordButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://discord.gg/nk7UYPbd5u");
@ -371,7 +354,12 @@ namespace AM2RLauncher
// Version number label // Version number label
versionLabel = new Label { Text = "v" + VERSION + (isThisRunningFromWine ? "-WINE" : ""), Width = 48, TextAlignment = TextAlignment.Right, TextColor = colGreen, Font = new Font(SystemFont.Default, 12) }; Label versionLabel = new Label
{
Text = "v" + VERSION + (isThisRunningFromWine ? "-WINE" : ""),
Width = 48, TextAlignment = TextAlignment.Right, TextColor = colGreen,
Font = new Font(SystemFont.Default, 12)
};
// Tie everything together // Tie everything together
var mainLayout = new DynamicLayout(); var mainLayout = new DynamicLayout();
@ -394,7 +382,7 @@ namespace AM2RLauncher
#region MAIN PAGE #region MAIN PAGE
// [MAIN PAGE] // [MAIN PAGE]
mainPage = new TabPage TabPage mainPage = new TabPage
{ {
BackgroundColor = colBGNoAlpha, BackgroundColor = colBGNoAlpha,
Text = Text.PlayTab, Text = Text.PlayTab,
@ -404,20 +392,19 @@ namespace AM2RLauncher
#region CHANGELOG PAGE #region CHANGELOG PAGE
// [CHANGELOG] // [CHANGELOG]
changelogUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/changelog.html"); Uri changelogUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/changelog.html");
WebView changelogWebView = new WebView { Url = changelogUri };
changelogWebView = new WebView { Url = changelogUri };
if (OS.IsUnix && !isInternetThere) if (OS.IsUnix && !isInternetThere)
changelogWebView = new WebView(); changelogWebView = new WebView();
changelogNoConnectionLabel = new Label Label changelogNoConnectionLabel = new Label
{ {
Text = Text.NoInternetConnection, Text = Text.NoInternetConnection,
TextColor = colGreen TextColor = colGreen
}; };
changelogPage = new TabPage TabPage changelogPage = new TabPage
{ {
BackgroundColor = colBGNoAlpha, BackgroundColor = colBGNoAlpha,
Text = Text.ChangelogTab, Text = Text.ChangelogTab,
@ -436,19 +423,20 @@ namespace AM2RLauncher
#region NEWS PAGE #region NEWS PAGE
// [NEWS] // [NEWS]
newsUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/news.html"); Uri newsUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/news.html");
newsWebView = new WebView { Url = newsUri }; WebView newsWebView = new WebView { Url = newsUri };
//TODO: why exactly is this check necessary?
if (OS.IsUnix && !isInternetThere) if (OS.IsUnix && !isInternetThere)
newsWebView = new WebView(); newsWebView = new WebView();
newsNoConnectionLabel = new Label Label newsNoConnectionLabel = new Label
{ {
Text = Text.NoInternetConnection, Text = Text.NoInternetConnection,
TextColor = colGreen TextColor = colGreen
}; };
newsPage = new TabPage TabPage newsPage = new TabPage
{ {
Text = Text.NewsTab, Text = Text.NewsTab,
BackgroundColor = colBGNoAlpha, BackgroundColor = colBGNoAlpha,
@ -462,6 +450,7 @@ namespace AM2RLauncher
} }
}; };
//TODO: this is hack because on linux / mac the other way doesn't work. eto issue?
if (OS.IsUnix && !isInternetThere) if (OS.IsUnix && !isInternetThere)
{ {
changelogPage.Content = new TableLayout changelogPage.Content = new TableLayout
@ -492,7 +481,7 @@ namespace AM2RLauncher
DynamicLayout settingsLayout = new DynamicLayout(); DynamicLayout settingsLayout = new DynamicLayout();
// LanguageLabel // LanguageLabel
languageLabel = new Label Label languageLabel = new Label
{ {
Text = Text.LanguageNotice, Text = Text.LanguageNotice,
TextColor = colGreen TextColor = colGreen
@ -575,7 +564,7 @@ namespace AM2RLauncher
}; };
// Custom environment variables label // Custom environment variables label
customEnvVarLabel = new Label(); Label customEnvVarLabel = new Label();
if (OS.IsLinux) if (OS.IsLinux)
{ {
customEnvVarLabel = new Label customEnvVarLabel = new Label
@ -653,7 +642,7 @@ namespace AM2RLauncher
#region MODSETTINGS PAGE #region MODSETTINGS PAGE
// [MOD SETTINGS] // [MOD SETTINGS]
DynamicLayout profileLayout = new DynamicLayout(); DynamicLayout modSettingsLayout = new DynamicLayout();
addModButton = new ColorButton addModButton = new ColorButton
@ -756,15 +745,15 @@ namespace AM2RLauncher
Text = Text.ProfileNotes Text = Text.ProfileNotes
}; };
profileLayout.BeginHorizontal(); modSettingsLayout.BeginHorizontal();
profileLayout.AddSpace(); modSettingsLayout.AddSpace();
profileLayout.AddColumn(null, addModButton, modSpacer, settingsProfileLabel, modSettingsProfileDropDown, profileButton, saveButton, updateModButton, deleteModButton, profileNotesTextArea, null); modSettingsLayout.AddColumn(null, addModButton, modSpacer, settingsProfileLabel, modSettingsProfileDropDown, profileButton, saveButton, updateModButton, deleteModButton, profileNotesTextArea, null);
profileLayout.AddSpace(); modSettingsLayout.AddSpace();
profilePage = new TabPage TabPage modSettingsPage = new TabPage
{ {
BackgroundColor = colBGNoAlpha, BackgroundColor = colBGNoAlpha,
Content = profileLayout, Content = modSettingsLayout,
Text = Text.ModSettingsTab Text = Text.ModSettingsTab
}; };
@ -784,7 +773,7 @@ namespace AM2RLauncher
settingsPage, settingsPage,
profilePage modSettingsPage
} }
}; };
@ -808,7 +797,7 @@ namespace AM2RLauncher
playButton.LoadComplete += PlayButtonLoadComplete; playButton.LoadComplete += PlayButtonLoadComplete;
customMirrorTextBox.LostFocus += CustomMirrorTextBoxLostFocus; customMirrorTextBox.LostFocus += CustomMirrorTextBoxLostFocus;
mirrorDropDown.SelectedIndexChanged += MirrorDropDownSelectedIndexChanged; mirrorDropDown.SelectedIndexChanged += MirrorDropDownSelectedIndexChanged;
profileLayout.LoadComplete += ProfileLayoutLoadComplete; modSettingsLayout.LoadComplete += ProfileLayoutLoadComplete;
addModButton.Click += AddModButtonClicked; addModButton.Click += AddModButtonClicked;
profileButton.Click += ProfileDataButtonClickEvent; profileButton.Click += ProfileDataButtonClickEvent;
saveButton.Click += SaveButtonClickEvent; saveButton.Click += SaveButtonClickEvent;
@ -833,9 +822,7 @@ namespace AM2RLauncher
// Visual studio does it like this for normal winforms projects, so I just used the same format. // Visual studio does it like this for normal winforms projects, so I just used the same format.
/// <summary>The tray indicator</summary> /// <summary>The tray indicator</summary>
TrayIndicator trayIndicator; private TrayIndicator trayIndicator;
/// <summary>The "Show" Button on the tray indicator</summary>
ButtonMenuItem showButton;
/// <summary><see cref="List{T}"/> of <see cref="ProfileXML"/>s, used for actually working with profile data.</summary> /// <summary><see cref="List{T}"/> of <see cref="ProfileXML"/>s, used for actually working with profile data.</summary>
//TODO: this should be moved into AM2RLauncher.Core //TODO: this should be moved into AM2RLauncher.Core
@ -843,31 +830,24 @@ namespace AM2RLauncher
/// <summary><see cref="List{T}"/> of <see cref="ListItem"/>s so that Eto's annoying <see cref="IListItem"/> interface is appeased. Used for profile name display in DropDowns.</summary> /// <summary><see cref="List{T}"/> of <see cref="ListItem"/>s so that Eto's annoying <see cref="IListItem"/> interface is appeased. Used for profile name display in DropDowns.</summary>
List<ListItem> profileNames; List<ListItem> profileNames;
// Bitmaps
/// <summary>The Reddit icon.</summary>
private Bitmap redditIcon;
/// <summary>The Github icon.</summary>
private Bitmap githubIcon;
/// <summary>The YouTube icon.</summary>
private Bitmap youtubeIcon;
/// <summary>The Discord icon.</summary>
private Bitmap discordIcon;
/// <summary>The planet Background.</summary> /// <summary>The planet Background.</summary>
private Bitmap formBG; private readonly Bitmap formBG = new Bitmap(Resources.bgCentered);
// Colors // Colors
/// <summary>The main green color.</summary> /// <summary>The main green color.</summary>
private Color colGreen; private readonly Color colGreen = Color.FromArgb(142, 188, 35);
/// <summary>The warning red color.</summary> /// <summary>The warning red color.</summary>
private Color colRed; private readonly Color colRed = Color.FromArgb(188, 10, 35);
/// <summary>The main inactive color.</summary> /// <summary>The main inactive color.</summary>
private Color colInactive; private readonly Color colInactive = Color.FromArgb(109, 109, 109);
/// <summary>The black background color without alpha value.</summary> /// <summary>The black background color without alpha value.</summary>
private Color colBGNoAlpha; private readonly Color colBGNoAlpha = Color.FromArgb(10, 10, 10);
/// <summary>The black background color.</summary> /// <summary>The black background color.</summary>
private Color colBG; // XORG can't display alpha anyway, and Wayland breaks with it.
// TODO: that sounds like an Eto bug. investigate, try to open eto issue.
private readonly Color colBG = OS.IsLinux ? Color.FromArgb(10, 10, 10) : Color.FromArgb(10, 10, 10, 80);
/// <summary>The lighter green color on hover.</summary> /// <summary>The lighter green color on hover.</summary>
private Color colBGHover; private readonly Color colBGHover = Color.FromArgb(17, 28, 13);
// Mirror lists // Mirror lists
/// <summary><see cref="List{String}"/> of mirror <see cref="string"/>s, used for actually working with mirrors.</summary> /// <summary><see cref="List{String}"/> of mirror <see cref="string"/>s, used for actually working with mirrors.</summary>
@ -876,7 +856,7 @@ namespace AM2RLauncher
private List<ListItem> mirrorDescriptionList; private List<ListItem> mirrorDescriptionList;
// UI Elements // UI Elements
/// <summary>The main control of the <see cref="mainPage"/>, used to draw the <see cref="formBG"/> and hold the main interface.</summary> /// <summary>The main control of the main page, used to draw the <see cref="formBG"/> and hold the main interface.</summary>
private Drawable drawable; private Drawable drawable;
/// <summary>A <see cref="ColorButton"/> that acts as the main Button</summary> /// <summary>A <see cref="ColorButton"/> that acts as the main Button</summary>
@ -894,8 +874,6 @@ namespace AM2RLauncher
/// <summary>A <see cref="ColorButton"/> that is used to delete a mod</summary> /// <summary>A <see cref="ColorButton"/> that is used to delete a mod</summary>
private ColorButton deleteModButton; private ColorButton deleteModButton;
/// <summary>The <see cref="Label"/> that gives information for <see cref="languageDropDown"/>.</summary>
private Label languageLabel;
/// <summary>The <see cref="Label"/> that entitles <see cref="profileDropDown"/>.</summary> /// <summary>The <see cref="Label"/> that entitles <see cref="profileDropDown"/>.</summary>
private Label profileLabel; private Label profileLabel;
/// <summary>The <see cref="Label"/> that gives author information for <see cref="profileDropDown"/>.</summary> /// <summary>The <see cref="Label"/> that gives author information for <see cref="profileDropDown"/>.</summary>
@ -904,22 +882,12 @@ namespace AM2RLauncher
private Label profileVersionLabel; private Label profileVersionLabel;
/// <summary>The <see cref="Label"/> that gives information for <see cref="mirrorDropDown"/>.</summary> /// <summary>The <see cref="Label"/> that gives information for <see cref="mirrorDropDown"/>.</summary>
private Label mirrorLabel; private Label mirrorLabel;
/// <summary>The <see cref="Label"/> that displays <see cref="VERSION"/>, aka the current launcher version.</summary>
private Label versionLabel;
/// <summary>The <see cref="Label"/> that gives information for <see cref="modSettingsProfileDropDown"/>.</summary> /// <summary>The <see cref="Label"/> that gives information for <see cref="modSettingsProfileDropDown"/>.</summary>
private Label settingsProfileLabel; private Label settingsProfileLabel;
/// <summary>The <see cref="Label"/> that compliments <see cref="progressBar"/>.</summary> /// <summary>The <see cref="Label"/> that compliments <see cref="progressBar"/>.</summary>
private Label progressLabel; private Label progressLabel;
/// <summary>The <see cref="Label"/> that gives a warning on failure to load the <see cref="newsWebView"/>.</summary>
private Label newsNoConnectionLabel;
/// <summary>The <see cref="Label"/> that gives a warning on failure to load the <see cref="changelogWebView"/>.</summary>
private Label changelogNoConnectionLabel;
/// <summary>The <see cref="Label"/> that gives a warning if the current selected <see cref="ProfileXML"/> shares the same save location has default AM2R.</summary> /// <summary>The <see cref="Label"/> that gives a warning if the current selected <see cref="ProfileXML"/> shares the same save location has default AM2R.</summary>
private Label saveWarningLabel; private Label saveWarningLabel;
/// <summary>The <see cref="Label"/> that describes <see cref="customEnvVarTextBox"/>.</summary>
private Label customEnvVarLabel;
/// <summary>A <see cref="CheckBox"/>, that indicates wether to automatically update AM2R or not.</summary> /// <summary>A <see cref="CheckBox"/>, that indicates wether to automatically update AM2R or not.</summary>
private CheckBox autoUpdateAM2RCheck; private CheckBox autoUpdateAM2RCheck;
@ -955,25 +923,6 @@ namespace AM2RLauncher
/// <summary>A <see cref="ProgressBar"/> that can be used to show progress for a specific task.</summary> /// <summary>A <see cref="ProgressBar"/> that can be used to show progress for a specific task.</summary>
private ProgressBar progressBar; private ProgressBar progressBar;
/// <summary>The Uri used by <see cref="newsWebView"/>.</summary>
private Uri newsUri;
/// <summary>The Uri used by <see cref="changelogWebView"/>.</summary>
private Uri changelogUri;
/// <summary>A <see cref="WebView"/> to display the DistributionCenter news page.</summary>
private WebView newsWebView;
/// <summary>A <see cref="WebView"/> to display the DistributionCenter changelog page.</summary>
private WebView changelogWebView;
/// <summary>A <see cref="TabPage"/> for the Launcher's main interface.</summary>
private TabPage mainPage;
/// <summary>A <see cref="TabPage"/> for the Launcher's news integration.</summary>
private TabPage newsPage;
/// <summary>A <see cref="TabPage"/> for the Launcher's changelog integration.</summary>
private TabPage changelogPage;
/// <summary>A <see cref="TabPage"/> for the Launcher's profile settings.</summary>
private TabPage profilePage;
#endregion #endregion
} }
} }
Loading…
Cancel
Save