condense imageButtonEvents, make statemachines slightly easier to read

pull/32/head
Miepee 4 years ago
parent 514934cd1f
commit a41d8d6312

@ -697,19 +697,6 @@ namespace AM2RLauncher
e.Graphics.DrawImage(formBG, ((width / 2) - (height / 1.4745f)) / scale, 0);
}
#region ICON EVENTS
/// <summary>Gets called when <see cref="redditIcon"/> gets clicked.</summary>
private void RedditIconOnClick(object sender, EventArgs e) { CrossPlatformOperations.OpenURL("https://www.reddit.com/r/AM2R"); }
/// <summary>Gets called when <see cref="githubIcon"/> gets clicked.</summary>
private void GithubIconOnClick(object sender, EventArgs e) { CrossPlatformOperations.OpenURL("https://www.github.com/AM2R-Community-Developers"); }
/// <summary>Gets called when <see cref="youtubeIcon"/> gets clicked.</summary>
private void YoutubeIconOnClick(object sender, EventArgs e) { CrossPlatformOperations.OpenURL("https://www.youtube.com/c/AM2RCommunityUpdates"); }
/// <summary>Gets called when <see cref="discordIcon"/> gets clicked.</summary>
private void DiscordIconOnClick(object sender, EventArgs e) { CrossPlatformOperations.OpenURL("https://discord.gg/nk7UYPbd5u"); }
#endregion
/// <summary>Gets called when <see cref="showButton"/> gets clicked and shows the <see cref="MainForm"/> and brings it to the front again.</summary>
private void ShowButtonClick(object sender, EventArgs e)
{

@ -118,18 +118,15 @@ namespace AM2RLauncher
{
case UpdateState.Download:
case UpdateState.Downloading:
case UpdateState.Select11:
case UpdateState.Installing:
case UpdateState.Playing: profileDropDown.Enabled = false; break;
case UpdateState.Select11:
case UpdateState.Install:
case UpdateState.Play: profileDropDown.Enabled = true; break;
}
switch (apkButtonState)
{
case ApkButtonState.Creating: profileDropDown.Enabled = false; break;
}
if (apkButtonState == ApkButtonState.Creating) profileDropDown.Enabled = false;
Color col = profileDropDown.Enabled ? colGreen : colInactive;
@ -156,6 +153,7 @@ namespace AM2RLauncher
case UpdateState.Select11:
case UpdateState.Installing:
case UpdateState.Playing: enabled = false; break;
case UpdateState.Install:
case UpdateState.Play: enabled = true; break;
@ -200,19 +198,19 @@ namespace AM2RLauncher
private void SetPlayButtonState(UpdateState state)
{
updateState = state;
string profileName = ((profileDropDown != null) && (profileDropDown.Items.Count > 0)) ? profileDropDown.Items[profileDropDown.SelectedIndex].Text : "";
switch (updateState)
{
//TODO: seperate this into a "onenabledchanged" delegate?
case UpdateState.Download: playButton.Enabled = true; playButton.ToolTip = Text.PlayButtonDownloadToolTip; break;
case UpdateState.Downloading: playButton.Enabled = true; playButton.ToolTip = ""; playButton.ToolTip = Text.PlayButtonDownladingToolTip; break;
case UpdateState.Select11: playButton.Enabled = true; playButton.ToolTip = Text.PlayButtonSelect11ToolTip; break;
case UpdateState.Install: playButton.Enabled = true; playButton.ToolTip = HelperMethods.GetText(Text.PlayButtonInstallToolTip, profileName); break;
case UpdateState.Installing: playButton.Enabled = false; playButton.ToolTip = Text.PlayButtonInstallingToolTip; break;
case UpdateState.Play: playButton.Enabled = true; playButton.ToolTip = HelperMethods.GetText(Text.PlayButtonPlayToolTip, profileName); break;
case UpdateState.Playing: playButton.Enabled = false; playButton.ToolTip = Text.PlayButtonPlayingToolTip; break;
case UpdateState.Download:
case UpdateState.Downloading:
case UpdateState.Select11:
case UpdateState.Install:
case UpdateState.Play: playButton.Enabled = true; break;
case UpdateState.Installing:
case UpdateState.Playing: playButton.Enabled = false; break;
}
playButton.Text = GetPlayButtonText();
playButton.ToolTip = GetPlayButtonTooltip();
playButton.Invalidate();
@ -253,6 +251,26 @@ namespace AM2RLauncher
}
}
/// <summary>
/// This returns the tooltip that <see cref="playButton"/> should have depending on the global updateState.
/// </summary>
/// <returns>The tooltip as a <see cref="String"/>, or <see langword="null"/> if the current State is invalid.</returns>
private string GetPlayButtonTooltip()
{
string profileName = ((profileDropDown != null) && (profileDropDown.Items.Count > 0)) ? profileDropDown.Items[profileDropDown.SelectedIndex].Text : "";
switch (updateState)
{
case UpdateState.Download: return Text.PlayButtonDownloadToolTip;
case UpdateState.Downloading: return Text.PlayButtonDownloadToolTip;
case UpdateState.Select11: return Text.PlayButtonSelect11ToolTip;
case UpdateState.Install: return playButton.ToolTip = HelperMethods.GetText(Text.PlayButtonInstallToolTip, profileName);
case UpdateState.Installing: return Text.PlayButtonInstallingToolTip;
case UpdateState.Play: return HelperMethods.GetText(Text.PlayButtonPlayToolTip, profileName);
case UpdateState.Playing: return Text.PlayButtonPlayingToolTip;
default: return null;
}
}
/// <summary>
/// This returns the text that the apkButton should have depending on the global updateState.
/// </summary>

@ -347,16 +347,16 @@ namespace AM2RLauncher
// Social buttons
var redditButton = new ImageButton { ToolTip = Text.RedditToolTip, Image = redditIcon };
redditButton.Click += RedditIconOnClick;
redditButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.reddit.com/r/AM2R");
var githubButton = new ImageButton { ToolTip = Text.GithubToolTip, Image = githubIcon };
githubButton.Click += GithubIconOnClick;
githubButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.github.com/AM2R-Community-Developers");
var youtubeButton = new ImageButton { ToolTip = Text.YoutubeToolTip, Image = youtubeIcon };
youtubeButton.Click += YoutubeIconOnClick;
youtubeButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.youtube.com/c/AM2RCommunityUpdates");
var discordButton = new ImageButton { ToolTip = Text.DiscordToolTip, Image = discordIcon };
discordButton.Click += DiscordIconOnClick;
discordButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://discord.gg/nk7UYPbd5u");
// Social button panel

Loading…
Cancel
Save