Skip to content

Commit

Permalink
Updated source to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsosousah committed Jan 18, 2022
1 parent 4b69489 commit 9d59dc4
Show file tree
Hide file tree
Showing 24 changed files with 1,608 additions and 191 deletions.
Binary file removed Beta/FS22Companion.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion FS22Companion/CustomMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CustomMessageBox(string message)
}
else
{
this.Width = (int)sizeOfString.Width + 40;
this.Width = (int)sizeOfString.Width + 50;
label1.Width = this.Width;
}

Expand Down
17 changes: 16 additions & 1 deletion FS22Companion/FS22Companion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<None Remove="Resources\helvetica_light.ttf" />
<None Remove="Resources\memory.dll" />
<None Remove="Resources\Newtonsoft.Json.dll" />
<None Remove="Resources\Octokit.dll" />
</ItemGroup>

<ItemGroup>
Expand All @@ -25,6 +26,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -36,8 +42,9 @@

<ItemGroup>
<PackageReference Include="FontAwesome.Sharp" Version="5.15.4" />
<PackageReference Include="Guna.UI2.WinForms" Version="2.0.2.7" />
<PackageReference Include="Guna.UI2.WinForms" Version="2.0.2.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Octokit" Version="0.50.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -46,6 +53,7 @@
<EmbeddedResource Include="Resources\helvetica_light.ttf" />
<EmbeddedResource Include="Resources\memory.dll" />
<EmbeddedResource Include="Resources\Newtonsoft.Json.dll" />
<EmbeddedResource Include="Resources\Octokit.dll" />
</ItemGroup>

<ItemGroup>
Expand All @@ -54,4 +62,11 @@
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion FS22Companion/FS22Companion.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Compile Update="CustomMessageBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="getAverageSellPriceTable.cs">
<Compile Update="GameSettingsManager.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Home.cs">
Expand Down
473 changes: 473 additions & 0 deletions FS22Companion/GameSettingsManager.Designer.cs

Large diffs are not rendered by default.

218 changes: 218 additions & 0 deletions FS22Companion/GameSettingsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections.Specialized;
using System.Collections;
using Guna.UI2.WinForms;
using Newtonsoft.Json;
using System.Xml.Serialization;
using System.IO;
using System.Xml.Linq;

namespace FS22Companion
{
public partial class GameSettingsManager : Form
{
public Dictionary<string,GameSetting> gameSettingsCollection;
GameSetting selectedSetting;
string modFolder;

public GameSettingsManager()
{
InitializeComponent();
}

private void GameSettingsManager_Load(object sender, EventArgs e)
{
gameSettingsCollection = JsonConvert.DeserializeObject<Dictionary<string, GameSetting>>(Properties.Settings.Default.GameSettingsDictionary);

if (gameSettingsCollection == null)
gameSettingsCollection = new Dictionary<string, GameSetting>();

XmlSerializer serializer = new XmlSerializer(typeof(GameSetting));
var gameSetting = new GameSetting();
using (Stream stream = new FileStream(Properties.Settings.Default.GameSettingsPath + "\\gameSettings.xml", FileMode.Open))
{
gameSetting = (GameSetting)serializer.Deserialize(stream);
gameSetting.Name = "Current Setting";
}
gameSettingsCollection["Current Setting"] = gameSetting;
//MessageBox.Show(JsonConvert.SerializeObject(i));

UpdateDictionaryEntries();
}

public void UpdateDictionaryEntries()
{
flowLayoutPanel.Controls.Clear();
foreach (var entry in gameSettingsCollection)
{
GameSetting gameSetting = entry.Value;

Guna2Button entryLabel = new Guna2Button();
entryLabel.Text = gameSetting.Name;
entryLabel.Name = gameSetting.Name;
entryLabel.Font = new Font("Segoe UI", 12F);
entryLabel.ForeColor = Color.FromArgb(57, 187, 223);
entryLabel.FillColor = Color.FromArgb(31, 42, 48);
entryLabel.AutoSize = false;
entryLabel.Size = new Size(195, 35);
entryLabel.HoverState.FillColor = Color.FromArgb(57, 187, 223);
entryLabel.HoverState.ForeColor = Color.FromArgb(31, 42, 48);

entryLabel.Click += (sender, e) =>
{
selectedSetting = gameSetting;
ShowSettingPanel(gameSetting);
};

flowLayoutPanel.Controls.Add(entryLabel);
}
}

public void ShowSettingPanel(GameSetting setting)
{
settingNameTextBox.Text = setting.Name;
modDirectoryOverrideCheckBox.Checked = setting.modsDirectoryOverride.active;
modFolderTextBox.Text = setting.modsDirectoryOverride.directory;
usernameTextBox.Text = setting.onlinePresenceName;
serverNameTextBox.Text = setting.joinGame.serverName;
serverPasswordTextBox.Text = setting.joinGame.password;
settingPanel.Show();
}

private void addGameSettingsButton_Click(object sender, EventArgs e)
{
if(gameSettingsCollection.ContainsKey("New Setting"))
{
CustomMessageBox.Show("\"New Setting\" already exists!", MessageBoxButtons.OK);
}
else
{
var gameSetting = new GameSetting("New Setting", true, "", "", "", "");
gameSettingsCollection.Add("New Setting", gameSetting);
Properties.Settings.Default.GameSettingsDictionary = JsonConvert.SerializeObject(gameSettingsCollection);
Properties.Settings.Default.Save();
UpdateDictionaryEntries();
}
}

private void saveSettingButton_Click(object sender, EventArgs e)
{
if (CustomMessageBox.Show("Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
var oldName = selectedSetting.Name;
gameSettingsCollection.Remove(oldName);
selectedSetting = new GameSetting(settingNameTextBox.Text, modDirectoryOverrideCheckBox.Checked, modFolderTextBox.Text, usernameTextBox.Text, serverNameTextBox.Text, serverPasswordTextBox.Text);
gameSettingsCollection[selectedSetting.Name] = selectedSetting;
Properties.Settings.Default.GameSettingsDictionary = JsonConvert.SerializeObject(gameSettingsCollection);
Properties.Settings.Default.Save();
settingPanel.Hide();

XDocument doc = new XDocument();
using (Stream stream = new FileStream(Properties.Settings.Default.GameSettingsPath + "\\gameSettings.xml", FileMode.Open))
{
doc = XDocument.Load(stream);
doc.Root.Element((XName)"modsDirectoryOverride").Attribute((XName)"active").SetValue(modDirectoryOverrideCheckBox.Checked);
doc.Root.Element((XName)"modsDirectoryOverride").Attribute((XName)"directory").Value = modFolderTextBox.Text;
doc.Root.Element((XName)"onlinePresenceName").Value = usernameTextBox.Text;
doc.Root.Element((XName)"joinGame").Attribute((XName)"serverName").Value = serverNameTextBox.Text;
doc.Root.Element((XName)"joinGame").Attribute((XName)"password").Value = serverPasswordTextBox.Text;
}
doc.Save(Properties.Settings.Default.GameSettingsPath + "\\gameSettings.xml");

XmlSerializer serializer = new XmlSerializer(typeof(GameSetting));
var gameSetting = new GameSetting();
using (Stream stream = new FileStream(Properties.Settings.Default.GameSettingsPath + "\\gameSettings.xml", FileMode.Open))
{
gameSetting = (GameSetting)serializer.Deserialize(stream);
gameSetting.Name = "Current Setting";
}
gameSettingsCollection["Current Setting"] = gameSetting;

UpdateDictionaryEntries();
}
}

private void modFolderButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog browserDialog = new FolderBrowserDialog();
if (!String.IsNullOrEmpty(modFolder))
browserDialog.SelectedPath = modFolder;
if(browserDialog.ShowDialog() == DialogResult.OK)
{
modFolder = browserDialog.SelectedPath;
modFolderTextBox.Text = modFolder;
modFolderTextBox.Select(modFolderTextBox.Text.Length, 0);
}
}

private void deleteGameSettingButton_Click(object sender, EventArgs e)
{
if(selectedSetting.Name == "Current Setting")
{
CustomMessageBox.Show("Current Setting can't be deleted", MessageBoxButtons.OK);
}
else if (CustomMessageBox.Show("Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
gameSettingsCollection.Remove(selectedSetting.Name);
Properties.Settings.Default.GameSettingsDictionary = JsonConvert.SerializeObject(gameSettingsCollection);
Properties.Settings.Default.Save();
settingPanel.Hide();
UpdateDictionaryEntries();
}
}

private void backwardButton_Click(object sender, EventArgs e)
{
settingPanel.Hide();
}
}

[XmlRoot("gameSettings"), XmlType("gameSettings")]
public class GameSetting
{
public modsDirectoryOverride modsDirectoryOverride { get; set; }
public string onlinePresenceName { get; set; }
public joinGame joinGame { get; set; }
public string Name { get; set; }

public GameSetting(string name, bool modDirectoryOverride, string modFolderPath, string username, string serverName, string serverPassword)
{
Name = name;
modsDirectoryOverride = new modsDirectoryOverride();
modsDirectoryOverride.active = modDirectoryOverride;
modsDirectoryOverride.directory = modFolderPath;
onlinePresenceName = username;
joinGame = new joinGame();
joinGame.serverName = serverName;
joinGame.password = serverPassword;
}
public GameSetting()
{

}
}

public class joinGame
{
[XmlAttribute]
public string serverName { get; set; }
[XmlAttribute]
public string password { get; set; }
}

public class modsDirectoryOverride
{
[XmlAttribute]
public bool active { get; set; }
[XmlAttribute]
public string directory { get; set; }
}
}
Loading

0 comments on commit 9d59dc4

Please sign in to comment.