Skip to content

Commit

Permalink
Add bools
Browse files Browse the repository at this point in the history
  • Loading branch information
VoltCruelerz committed Nov 1, 2023
1 parent d0b9249 commit 96cf497
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 107 deletions.
12 changes: 12 additions & 0 deletions Greed/Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
"groups": [
{
"name": "Empire",
"bools": [
{
"name": "All Research Complete",
"type": "ALL_RESEARCH",
"value": false
},
{
"name": "Infinite(ish) Money",
"type": "INFINITE_MONEY",
"value": false
}
],
"scalars": [
{
"name": "Max Fleet Supply",
Expand Down
3 changes: 1 addition & 2 deletions Greed/Controls/Online/OnlineWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Greed.Models.ListItem;
using Greed.Models.Online;
using Greed.Utils;
using System;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -27,7 +26,7 @@ public partial class OnlineWindow : Window
public OnlineWindow(OnlineCatalog listing, MainWindow parent)
{
InitializeComponent();
Title = $"Online Catalog of Greedy Mods (Channel: {Settings.GetChannel()})";
Title = $"Online Catalog of Greedy Mods (Channel: {Greed.Utils.Settings.GetChannel()})";
Log.Info("OnlineWindow()");
Catalog = listing;
ParentWindow = parent;
Expand Down
15 changes: 14 additions & 1 deletion Greed/Controls/Popups/CriticalAlertPopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.Media;
using System.Threading.Tasks;
using System.Windows;

namespace Greed.Controls.Popups
Expand Down Expand Up @@ -73,7 +74,19 @@ public static void Throw(string title, Exception ex)

public static void ThrowAsync(string title, Exception ex)
{
MainWindow.Instance!.Dispatcher.Invoke(() => Throw(title, ex));
// If the main window hasn't loaded yet, delay until then.
if (MainWindow.Instance == null)
{
Task.Run(() =>
{
Task.Delay(5000);
ThrowAsync(title, ex);
});
}
else
{
MainWindow.Instance!.Dispatcher.Invoke(() => Throw(title, ex));
}
}
}
}
34 changes: 34 additions & 0 deletions Greed/Controls/Settings/CheckBoxBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Windows.Controls;
using System.Windows.Media;

namespace Greed.Controls.Settings
{
public class CheckBoxBox : SettingsBox
{
private readonly CheckBox ChkSetter;

public CheckBoxBox(string name, int groupIndex, int subIndex, int posIndex, bool isChecked) : base(name, groupIndex, subIndex, posIndex)
{
ChkSetter = new CheckBox()
{
IsChecked = isChecked,
Margin = new System.Windows.Thickness(10, 6, 0, 0),
Foreground = new SolidColorBrush(Color.FromRgb(255, 157, 160)),
};
ChkSetter.Checked += ChkSetter_Checked;
ChkSetter.Unchecked += ChkSetter_Unchecked;

GrdContent.Children.Add(ChkSetter);
}

private void ChkSetter_Checked(object sender, System.Windows.RoutedEventArgs e)
{
Greed.Utils.Settings.SetBool(GroupIndex, ArrayIndex, true);
}

private void ChkSetter_Unchecked(object sender, System.Windows.RoutedEventArgs e)
{
Greed.Utils.Settings.SetBool(GroupIndex, ArrayIndex, false);
}
}
}
30 changes: 30 additions & 0 deletions Greed/Controls/Settings/SettingsBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Windows.Controls;
using System.Windows.Media;

namespace Greed.Controls.Settings
{
public class SettingsBox : GroupBox
{
public const int BoxSpacing = 50;
public int GroupIndex;
public int ArrayIndex;
public int PositionIndex;
protected readonly Grid GrdContent;

public SettingsBox(string name, int groupIndex, int subIndex, int positionIndex)
{
GroupIndex = groupIndex;
ArrayIndex = subIndex;
PositionIndex = positionIndex;

Header = name;
Height = 53;
VerticalAlignment = System.Windows.VerticalAlignment.Top;
BorderBrush = new SolidColorBrush(Color.FromRgb(255, 200, 210));
Margin = new System.Windows.Thickness(0, positionIndex * BoxSpacing, 0, 0);

GrdContent = new Grid();
AddChild(GrdContent);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
using Greed.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls;
using System.Windows.Media;

namespace Greed.Controls
namespace Greed.Controls.Settings
{
public class SliderBox : GroupBox
public class SliderBox : SettingsBox
{
public int GroupIndex;
public int ScalarIndex;

private readonly Label LblPercentage;
private readonly Slider SldSetter;

public SliderBox(string name, int groupIndex, int scalarIndex, int tickIndex)
public SliderBox(string name, int groupIndex, int subIndex, int posIndex, int tickIndex) : base(name, groupIndex, subIndex, posIndex)
{
GroupIndex = groupIndex;
ScalarIndex = scalarIndex;

Header = name;
Height = 53;
VerticalAlignment = System.Windows.VerticalAlignment.Top;
BorderBrush = new SolidColorBrush(Color.FromRgb(255, 200, 210));
Margin = new System.Windows.Thickness(0, 50 * scalarIndex, 0, 0);

LblPercentage = new Label()
{
Content = Settings.SliderValue[tickIndex].ToString("P0"),
Content = Greed.Utils.Settings.SliderValue[tickIndex].ToString("P0"),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
VerticalAlignment = System.Windows.VerticalAlignment.Bottom,
Width = 60,
Expand All @@ -50,15 +32,13 @@ public SliderBox(string name, int groupIndex, int scalarIndex, int tickIndex)
};
SldSetter.ValueChanged += Slider_ValueChanged;

var grid = new Grid();
grid.Children.Add(LblPercentage);
grid.Children.Add(SldSetter);
AddChild(grid);
GrdContent.Children.Add(LblPercentage);
GrdContent.Children.Add(SldSetter);
}

private void Slider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
{
Settings.SetSlider(GroupIndex, ScalarIndex, LblPercentage, e.NewValue);
Greed.Utils.Settings.SetSlider(GroupIndex, ArrayIndex, LblPercentage, e.NewValue);
}
}
}
2 changes: 0 additions & 2 deletions Greed/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Greed.Exceptions;
using Greed.Utils;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
Expand All @@ -12,7 +11,6 @@
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Threading;
using static System.Text.Json.JsonSerializer;
Expand Down
2 changes: 1 addition & 1 deletion Greed/Greed.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<Version>2.7.0</Version>
<Version>2.8.0</Version>
<Title>Greed Mod Manager</Title>
<Authors>Volt Cruelerz</Authors>
<Description>A mod loader for Sins of a Solar Empire II.</Description>
Expand Down
5 changes: 2 additions & 3 deletions Greed/ModManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Greed.Controls;
using Greed.Controls.Popups;
using Greed.Exceptions;
using Greed.Extensions;
using Greed.Interfaces;
using Greed.Models;
using Greed.Models.Config;
using Greed.Models.EnabledMods;
using Greed.Models.Online;
using Greed.Models.Vault;
Expand Down Expand Up @@ -83,6 +81,7 @@ public void ExportGreedyMods(List<Mod> active, ProgressBar pgbProgress, MainWind
{
Log.Info($"Exporting {active.Count} Active Mods");
var slidersChanged = Settings.GetScalars().Any(s => s.HasChanged());
var boolsChanged = Settings.GetBools().Any(s => s.HasChanged());
string modDir = Settings.GetModDir();
string sinsDir = Settings.GetSinsDir();
var greedPath = modDir + "\\greed";
Expand All @@ -99,7 +98,7 @@ public void ExportGreedyMods(List<Mod> active, ProgressBar pgbProgress, MainWind
int i = 0;
try
{
if (!active.Any() && !slidersChanged)
if (!active.Any() && !slidersChanged && !boolsChanged)
{
Log.Info("No active mods or scalars. Cleaning up...");
DeactivateGreed();
Expand Down
6 changes: 1 addition & 5 deletions Greed/Models/Config/Config.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using Greed.Utils;

namespace Greed.Models.Config
{
public class Config
{
[JsonRequired]
[JsonProperty(PropertyName = "version")]
public Version Version { get; set; } = new Version(0,0,0);
public Version Version { get; set; } = new Version(0, 0, 0);

[JsonRequired]
[JsonProperty(PropertyName = "channel")]
Expand Down
5 changes: 0 additions & 5 deletions Greed/Models/Config/DirConfig.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Greed.Models.Config
{
Expand Down
13 changes: 4 additions & 9 deletions Greed/Models/Config/EditLocation.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using Greed.Models.Mutations;
using Greed.Models.Mutations.Operations.Functions;
using Greed.Models.Mutations.Paths;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Greed.Models.Config.GlobalScalar;
using System.Xml.Linq;

namespace Greed.Models.Config
{
Expand Down Expand Up @@ -52,12 +47,12 @@ public int Exec(JObject root, GlobalScalar parent)
var fp = (FieldPath)NodePath[^1];
var child = obj[fp.Name];
if (child == null) return;
if (parent.Type == GlobalType.DOUBLE)
if (parent.Type == ScalarType.DOUBLE)
{
obj[fp.Name] = child!.Value<double>() * parent.Value;
changes++;
}
else if (parent.Type == GlobalType.INT)
else if (parent.Type == ScalarType.INT)
{
obj[fp.Name] = (int)(child!.Value<int>() * parent.Value);
changes++;
Expand All @@ -66,12 +61,12 @@ public int Exec(JObject root, GlobalScalar parent)
else if (token is JArray arr)
{
var i = arr.IndexOf(token);
if (parent.Type == GlobalType.DOUBLE)
if (parent.Type == ScalarType.DOUBLE)
{
arr[i] = token.Value<double>() * parent.Value;
changes++;
}
else if (parent.Type == GlobalType.INT)
else if (parent.Type == ScalarType.INT)
{
arr[i] = (int)(token.Value<int>() * parent.Value);
changes++;
Expand Down
Loading

0 comments on commit 96cf497

Please sign in to comment.