This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
SettingsForm.cs
189 lines (162 loc) · 6.99 KB
/
SettingsForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace AstroModLoader
{
public partial class SettingsForm : Form
{
public SettingsForm()
{
InitializeComponent();
versionLabel.Text = "";
}
private void UpdateColorBoxText()
{
foreach (KeyValuePair<string, Color> entry in AMLPalette.PresetMap)
{
if (entry.Value.Equals(AMLPalette.AccentColor))
{
accentComboBox.Text = entry.Key;
return;
}
}
accentComboBox.Text = AMLUtils.ColorToHTML(AMLPalette.AccentColor);
}
private void UpdateLabels()
{
gamePathBox.Text = BaseForm.ModManager.GamePath;
localPathBox.Text = BaseForm.ModManager.BasePath;
versionLabel.Text = (BaseForm.ModManager.InstalledAstroBuild?.ToString() ?? "Unknown") + (BaseForm.ModManager.MismatchedSteamworksDLL ? "\n(Pirated?)" : "");
versionLabel.ForeColor = BaseForm.ModManager.MismatchedSteamworksDLL ? AMLPalette.WarningColor : AMLPalette.ForeColor;
if (Program.CommandLineOptions.ServerMode)
{
platformComboBox.Enabled = false;
platformComboBox.DataSource = new string[] { "Server" };
platformComboBox.SelectedIndex = 0;
}
else
{
platformComboBox.Enabled = true;
platformComboBox.DataSource = BaseForm.ModManager.AllPlatforms;
platformComboBox.SelectedIndex = platformComboBox.FindStringExact(BaseForm.ModManager.Platform.ToString());
}
refuseMismatchedConnectionsCheckbox.Checked = ModHandler.OurIntegrator.RefuseMismatchedConnections;
}
private Form1 BaseForm;
private bool _readyToUpdateTheme = false;
private void SettingsForm_Load(object sender, EventArgs e)
{
if (this.Owner is Form1)
{
BaseForm = (Form1)this.Owner;
AMLPalette.RefreshTheme(BaseForm);
this.UpdateLabels();
UpdateColorBoxText();
}
themeComboBox.DataSource = Enum.GetValues(typeof(ModLoaderTheme));
themeComboBox.SelectedIndex = (int)AMLPalette.CurrentTheme;
accentComboBox.Items.AddRange(AMLPalette.PresetMap.Keys.ToArray());
AMLPalette.RefreshTheme(this);
this.AdjustFormPosition();
gamePathBox.SelectionStart = 0;
accentComboBox.SelectionLength = 0;
_readyToUpdateTheme = true;
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void accentComboBox_UpdateColor(object sender, EventArgs e)
{
Color backupColor = Color.FromArgb(AMLPalette.AccentColor.ToArgb());
try
{
if (AMLPalette.PresetMap.ContainsKey(accentComboBox.Text))
{
AMLPalette.AccentColor = AMLPalette.PresetMap[accentComboBox.Text];
}
else
{
AMLPalette.AccentColor = AMLUtils.ColorFromHTML(accentComboBox.Text);
}
AMLPalette.RefreshTheme(BaseForm);
BaseForm.ModManager.SyncConfigToDisk();
AMLPalette.RefreshTheme(this);
}
catch
{
this.ShowBasicButton("Invalid color!", "OK", null, null);
AMLPalette.AccentColor = backupColor;
}
UpdateColorBoxText();
}
private void themeBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_readyToUpdateTheme) return;
Enum.TryParse(themeComboBox.SelectedValue.ToString(), out ModLoaderTheme nextTheme);
AMLPalette.CurrentTheme = nextTheme;
AMLPalette.RefreshTheme(BaseForm);
BaseForm.ModManager.SyncConfigToDisk();
AMLPalette.RefreshTheme(this);
}
private void platformComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_readyToUpdateTheme) return;
if (BaseForm == null) return;
Enum.TryParse(platformComboBox.SelectedValue.ToString(), out PlatformType nextPlatform);
BaseForm.SwitchPlatform(nextPlatform);
this.UpdateLabels();
}
private void UpdatePathing(object sender, EventArgs e)
{
string correctedGamePath = AMLUtils.FixGamePath(gamePathBox.Text);
string correctedLocalPath = AMLUtils.FixBasePath(localPathBox.Text);
if (string.IsNullOrEmpty(correctedGamePath) || !AMLUtils.IsValidPath(correctedGamePath))
{
gamePathBox.Text = BaseForm.ModManager.GamePath;
this.ShowBasicButton("The specified game path is invalid!", "OK", null, null);
return;
}
if (string.IsNullOrEmpty(correctedLocalPath) || !AMLUtils.IsValidPath(correctedLocalPath))
{
localPathBox.Text = BaseForm.ModManager.BasePath;
this.ShowBasicButton("The specified local path is invalid!", "OK", null, null);
return;
}
BaseForm.ModManager.ValidPlatformTypesToPaths[PlatformType.Custom] = correctedGamePath;
BaseForm.ModManager.CustomBasePath = correctedLocalPath;
BaseForm.ModManager.RefreshAllPlatformsList();
BaseForm.SwitchPlatform(PlatformType.Custom);
this.UpdateLabels();
}
private void refuseMismatchedConnectionsCheckbox_CheckedChanged(object sender, EventArgs e)
{
ModHandler.OurIntegrator.RefuseMismatchedConnections = refuseMismatchedConnectionsCheckbox.Checked;
BaseForm.ModManager.SyncDependentConfigToDisk();
AMLUtils.InvokeUI(BaseForm.TableManager.Refresh);
this.UpdateLabels();
}
private static string AboutText;
private void aboutButton_Click(object sender, EventArgs e)
{
AboutText = "AstroModLoader v" + Application.ProductVersion + "\n" +
"By AstroTechies\n" +
"\nThanks to the folks in the Astroneer Modding Discord community for their contributions\n" +
"\nThanks to you for making this little modding venture what it is\n";
var formPopup = new AboutPopup();
formPopup.StartPosition = FormStartPosition.CenterParent;
formPopup.Controls.Add(new Label()
{
AutoSize = false,
TextAlign = ContentAlignment.MiddleCenter,
Dock = DockStyle.Fill,
Text = AboutText,
Font = new Font(this.Font.FontFamily, 10)
});
AMLPalette.RefreshTheme(formPopup);
formPopup.ShowDialog(this);
}
}
}