First draft of making main dropdown binding

pull/45/head
Miepee 4 years ago
parent 5b22daf4ac
commit 2b4f4b2b7e

@ -532,7 +532,7 @@ public partial class MainForm : Form
/// <summary>Gets called when user selects a different item from <see cref="profileDropDown"/> and changes <see cref="profileAuthorLabel"/> accordingly.</summary>
private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{
if ((profileDropDown.SelectedIndex == -1) && (profileDropDown.Items.Count == 0)) return;
if ((profileDropDown.SelectedIndex == -1) && (!profileDropDown.DataStore.Any())) return;
profileIndex = profileDropDown.SelectedIndex;
log.Debug("profileDropDown.SelectedIndex has been changed to " + profileIndex + ".");
@ -779,7 +779,7 @@ public partial class MainForm : Form
// Reload list so mod gets recognized
LoadProfilesAndAdjustLists();
// Adjust profileIndex to point to newly added mod. if its not found for whatever reason, we default to first community updates
modSettingsProfileDropDown.SelectedIndex = profileList.FindIndex(p => p.Name == profile.Name);
modSettingsProfileDropDown.SelectedIndex = profileList.IndexOf(profileList.FirstOrDefault(p => p.Name == profile.Name));
if (modSettingsProfileDropDown.SelectedIndex == -1)
modSettingsProfileDropDown.SelectedIndex = 0;
@ -792,11 +792,11 @@ public partial class MainForm : Form
/// </summary>
private void ModSettingsProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{
if (modSettingsProfileDropDown.SelectedIndex == -1 && !modSettingsProfileDropDown.DataStore.Any()) return;
if (modSettingsProfileDropDown.SelectedIndex == -1 || !modSettingsProfileDropDown.DataStore.Any()) return;
string profileName = modSettingsProfileDropDown.SelectedKey;
log.Info("SettingsProfileDropDown.SelectedIndex has been changed to " + modSettingsProfileDropDown.SelectedIndex + ".");
log.Info("ModSettingsProfileDropDown.SelectedIndex has been changed to " + modSettingsProfileDropDown.SelectedIndex + ".");
if (modSettingsProfileDropDown.SelectedIndex <= 0 || !modSettingsProfileDropDown.DataStore.Any())
{
deleteModButton.Enabled = false;
@ -1067,7 +1067,7 @@ public partial class MainForm : Form
// Adjust our lists so it gets recognized
LoadProfilesAndAdjustLists();
modSettingsProfileDropDown.SelectedIndex = profileList.FindIndex(p => p.Name == currentProfile.Name);
modSettingsProfileDropDown.SelectedIndex = profileList.IndexOf(profileList.FirstOrDefault(p => p.Name == currentProfile.Name));
if (modSettingsProfileDropDown.SelectedIndex == -1)
modSettingsProfileDropDown.SelectedIndex = 0;

@ -127,7 +127,7 @@ public partial class MainForm
case PlayButtonState.Playing: return;
case PlayButtonState.Install:
case PlayButtonState.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?.SelectedKey ?? ""); break;
}
}
@ -280,7 +280,7 @@ public partial class MainForm
/// <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 : "";
string profileName = ((profileDropDown != null) && (profileDropDown.DataStore.Any())) ? profileDropDown.SelectedKey : "";
switch (updateState)
{
case PlayButtonState.Download: return Text.PlayButtonDownloadToolTip;
@ -314,15 +314,11 @@ public partial class MainForm
private void LoadProfilesAndAdjustLists()
{
// Reset loaded profiles
profileDropDown.Items.Clear();
profileList.Clear();
profileIndex = null;
// Load the profileList
profileList = Profile.LoadProfiles();
// Add profile names to the profileDropDown
foreach (ProfileXML profile in profileList)
foreach (ProfileXML profile in Profile.LoadProfiles())
{
// Archive version notes
if (!profile.Installable)
@ -333,14 +329,14 @@ public partial class MainForm
profile.ProfileNotes = Text.ArchiveNotesMods + "\n\n" + profile.ProfileNotes;
}
profileDropDown.Items.Add(profile.Name);
profileList.Add(profile);
}
// Read the value from the config
string profIndexString = ReadFromConfig("ProfileIndex");
// Check if either no profile was found or the setting says that the last current profile didn't exist
if (profileDropDown.Items.Count == 0)
if (!profileDropDown.DataStore.Any())
profileIndex = null;
else
{
@ -351,13 +347,13 @@ public partial class MainForm
// We parse from the settings, and check if profiles got deleted from the last time the launcher has been selected. if yes, we revert the last selection to 0;
int intParseResult = Int32.Parse(profIndexString);
profileIndex = intParseResult;
if (profileIndex >= profileDropDown.Items.Count)
if (profileIndex >= profileDropDown.DataStore.Count())
profileIndex = 0;
profileDropDown.SelectedIndex = profileIndex.Value;
}
// Update stored profiles in the Profile Settings tab
modSettingsProfileDropDown.SelectedIndex = profileDropDown.Items.Count != 0 ? 0 : -1;
modSettingsProfileDropDown.SelectedIndex = profileDropDown.DataStore.Any() ? 0 : -1;
// Refresh the author and version label on the main tab
if (profileList.Count > 0)

@ -7,6 +7,7 @@ using Eto.Forms;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@ -111,14 +112,6 @@ public partial class MainForm : Form
if (OS.IsMac)
Menu = new MenuBar();
// Create array from validCount
profileList = new List<ProfileXML>();
//TODO: whenever profileDropDown gets rewritten to use a datastore, scrap this
List<ListItem> profileNames = new List<ListItem>();
foreach (ProfileXML profile in profileList)
profileNames.Add(profile.Name);
// Custom splash texts
string splash = Splash.GetSplash();
log.Info($"Randomly chosen splash: {splash}");
@ -228,7 +221,7 @@ public partial class MainForm : Form
if (OS.IsLinux)
profileDropDown = new DropDown();
profileDropDown.Items.AddRange(profileNames); // It's actually more comfortable if it's outside, because of GTK shenanigans
profileDropDown.DataStore = (profileList);
centerInterface.AddRow(profileDropDown);
@ -646,8 +639,7 @@ public partial class MainForm : Form
private readonly TrayIndicator trayIndicator;
/// <summary><see cref="List{T}"/> of <see cref="ProfileXML"/>s, used for actually working with profile data.</summary>
//TODO: this should be moved into AM2RLauncherLib
private List<ProfileXML> profileList;
private ObservableCollection<ProfileXML> profileList = new ObservableCollection<ProfileXML>();
/// <summary>The planet Background.</summary>
private readonly Bitmap formBG = new Bitmap(Resources.bgCentered);
@ -708,7 +700,6 @@ public partial class MainForm : Form
/// <summary>A <see cref="DropDown"/> where profiles can be chosen.</summary>
private readonly DropDown profileDropDown;
/// <summary>A <see cref="DropDown"/> where profiles can be chosen (located in Profile Settings).</summary>
//TODO: Use MVVM bindings: https://github.com/picoe/Eto/wiki/Data-Binding#mvvm-binding
private readonly DropDown modSettingsProfileDropDown;
/// <summary>A <see cref="TextBox"/>, where the user can input their custom mirror.</summary>

@ -95,4 +95,9 @@ public class ProfileXML
Installable = installable;
ProfileNotes = profileNotes;
}
public override string ToString()
{
return Name;
}
}
Loading…
Cancel
Save