Added game version support.

This commit is contained in:
Assistant 2019-05-18 11:32:14 -04:00
parent 104351a016
commit 45f8dc8c95
9 changed files with 131 additions and 17 deletions

View file

@ -32,6 +32,9 @@
<setting name="SelectInstalled" serializeAs="String">
<value>False</value>
</setting>
<setting name="GameVersion" serializeAs="String">
<value />
</setting>
</ModAssistant.Properties.Settings>
<ModAssistant.Settings1>
<setting name="InstallFolder" serializeAs="String">

View file

@ -23,6 +23,8 @@
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Name="IntroButton" Grid.Row="0" Height="60" Margin="0,0,10,5" Background="white" Click="IntroButton_Click">
@ -53,6 +55,12 @@
</StackPanel>
</Button>
<StackPanel Name="GameVersions" Grid.Row="5" VerticalAlignment="Bottom">
<TextBlock Text="Game Version:" FontSize="10"/>
<ComboBox Name="GameVersionsBox" Margin="0,5,5,0" SelectionChanged="GameVersionsBox_SelectionChanged">
</ComboBox>
</StackPanel>
</Grid>
<StackPanel Grid.Row="1" VerticalAlignment="Center">

View file

@ -27,6 +27,8 @@ namespace ModAssistant
public partial class MainWindow : Window
{
public static MainWindow Instance;
public static bool ModsOpened = false;
public static string GameVersion;
public string MainText
{
@ -47,17 +49,60 @@ namespace ModAssistant
VersionText.Text = App.Version;
if (Properties.Settings.Default.Agreed)
Main.Content = Intro.Instance;
List<string> versions;
string json = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.BeatModsAPIUrl + "version");
request.AutomaticDecompression = DecompressionMethods.GZip;
request.UserAgent = "ModAssistant/" + App.Version;
versions = null;
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
var serializer = new JavaScriptSerializer();
versions = serializer.Deserialize<string[]>(reader.ReadToEnd()).ToList();
}
if (!String.IsNullOrEmpty(Properties.Settings.Default.GameVersion) && versions.Contains(Properties.Settings.Default.GameVersion))
GameVersion = Properties.Settings.Default.GameVersion;
else
GameVersion = versions[versions.Count - 1];
GameVersionsBox.ItemsSource = versions;
GameVersionsBox.SelectedValue = GameVersion;
}
catch (Exception e)
{
MessageBox.Show("Could not load game versions, Mods tab will be unavailable.\n" + e);
}
if (!String.IsNullOrEmpty(GameVersion) && Properties.Settings.Default.Agreed)
{
MainWindow.Instance.ModsButton.IsEnabled = true;
}
Main.Content = Intro.Instance;
}
private void ModsButton_Click(object sender, RoutedEventArgs e)
{
Main.Content = Mods.Instance;
if (!ModsOpened)
{
Mods.Instance.LoadMods();
ModsOpened = true;
return;
}
if (Mods.Instance.PendingChanges)
{
Mods.Instance.LoadMods();
Mods.Instance.PendingChanges = false;
}
}
private void IntroButton_Click(object sender, RoutedEventArgs e)
@ -93,5 +138,22 @@ namespace ModAssistant
System.Diagnostics.Process.Start(infoUrl);
}
}
private void GameVersionsBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string oldGameVersion = GameVersion;
GameVersion = (sender as ComboBox).SelectedItem.ToString();
if (String.IsNullOrEmpty(oldGameVersion)) return;
Properties.Settings.Default.GameVersion = GameVersion;
Properties.Settings.Default.Save();
if (ModsOpened)
{
Mods.Instance.LoadMods();
}
}
}
}

View file

@ -45,11 +45,18 @@ namespace ModAssistant.Pages
private void Agree_Click(object sender, RoutedEventArgs e)
{
MainWindow.Instance.ModsButton.IsEnabled = true;
if (String.IsNullOrEmpty(MainWindow.GameVersion))
{
MessageBox.Show("Could not download versions list.\nMods tab disabled. Please restart to try again.");
}
else
{
MainWindow.Instance.ModsButton.IsEnabled = true;
Utils.SendNotify("You can now use the Mods tab!");
MainWindow.Instance.MainText = "You can now use the Mods tab!";
}
Properties.Settings.Default.Agreed = true;
Properties.Settings.Default.Save();
Utils.SendNotify("You can now use the Mods tab!");
MainWindow.Instance.MainText = "You can now use the Mods tab!";
}
}
}

View file

@ -34,29 +34,44 @@ namespace ModAssistant.Pages
public static List<Mod> InstalledMods = new List<Mod>();
public List<string> CategoryNames = new List<string>();
public CollectionView view;
public bool PendingChanges;
public List<ModListItem> ModList { get; set; }
public Mods()
{
InitializeComponent();
ModList = new List<ModListItem>();
LoadMods();
}
private void RefreshModsList()
{
view.Refresh();
if (view != null)
view.Refresh();
}
private async void LoadMods()
public async void LoadMods()
{
MainWindow.Instance.InstallButton.IsEnabled = false;
MainWindow.Instance.GameVersionsBox.IsEnabled = false;
if (ModsList != null)
Array.Clear(ModsList, 0, ModsList.Length);
if (AllModsList != null)
Array.Clear(AllModsList, 0, AllModsList.Length);
InstalledMods = new List<Mod>();
CategoryNames = new List<string>();
ModList = new List<ModListItem>();
ModsListView.Visibility = Visibility.Hidden;
if (App.CheckInstalledMods)
{
MainWindow.Instance.MainText = "Checking Installed Mods...";
await Task.Run(() => CheckInstalledMods());
InstalledColumn.Width = Double.NaN;
UninstallColumn.Width = 70;
DescriptionColumn.Width = 750;
} else
{
InstalledColumn.Width = 0;
@ -76,8 +91,11 @@ namespace ModAssistant.Pages
this.DataContext = this;
RefreshModsList();
ModsListView.Visibility = Visibility.Visible;
MainWindow.Instance.MainText = "Finished Loading Mods.";
MainWindow.Instance.InstallButton.IsEnabled = true;
MainWindow.Instance.GameVersionsBox.IsEnabled = true;
}
private void CheckInstalledMods()
@ -143,7 +161,7 @@ namespace ModAssistant.Pages
public void PopulateModsList()
{
string json = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.BeatModsAPIUrl + Utils.Constants.BeatModsModsOptions);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.BeatModsAPIUrl + Utils.Constants.BeatModsModsOptions + "&gameVersion=" + MainWindow.GameVersion);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.UserAgent = "ModAssistant/" + App.Version;

View file

@ -47,10 +47,7 @@
<TextBlock Grid.Row="4" Margin="5" Text="Check Installed Mods" FontWeight="Bold" HorizontalAlignment="Left" FontSize="16" />
<CheckBox Grid.Row="4" Grid.Column="1" Name="CheckInstalled" VerticalAlignment="Center" HorizontalAlignment="Left" IsChecked="{Binding CheckInstalledMods, Mode=TwoWay}" Checked="CheckInstalled_Checked" Unchecked="CheckInstalled_Unchecked"/>
<StackPanel Grid.Row="4" Grid.Column="1" Margin="20,0,0,0" Background="LightYellow" HorizontalAlignment="Left">
<TextBlock Margin="5,5,5,0" Text="Will slow down mod list loading" HorizontalAlignment="Left" />
<TextBlock Margin="5,0,5,5" Text="Requires application restart" HorizontalAlignment="Left" />
</StackPanel>
<TextBlock Grid.Row="5" Margin="20,5,5,5" Text="Select Installed Mods" FontWeight="Bold" HorizontalAlignment="Left" FontSize="16" />
<CheckBox Grid.Row="5" Grid.Column="1" Name="SelectInstalled" VerticalAlignment="Center" HorizontalAlignment="Left" IsChecked="{Binding SelectInstalledMods, Mode=TwoWay}" Checked="SelectInstalled_Checked" Unchecked="SelectInstalled_Unchecked"/>

View file

@ -89,6 +89,8 @@ namespace ModAssistant.Pages
CheckInstalledMods = true;
Properties.Settings.Default.Save();
SelectInstalled.IsEnabled = true;
if (MainWindow.ModsOpened)
Mods.Instance.PendingChanges = true;
}
private void CheckInstalled_Unchecked(object sender, RoutedEventArgs e)
@ -98,6 +100,8 @@ namespace ModAssistant.Pages
CheckInstalledMods = false;
Properties.Settings.Default.Save();
SelectInstalled.IsEnabled = false;
if (MainWindow.ModsOpened)
Mods.Instance.PendingChanges = true;
}
public void ModelSaberProtocolHandler_Checked(object sender, RoutedEventArgs e)

View file

@ -106,5 +106,17 @@ namespace ModAssistant.Properties {
this["SelectInstalled"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string GameVersion {
get {
return ((string)(this["GameVersion"]));
}
set {
this["GameVersion"] = value;
}
}
}
}

View file

@ -23,5 +23,8 @@
<Setting Name="SelectInstalled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="GameVersion" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>