-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMods_UserControl.xaml.cs
More file actions
338 lines (286 loc) · 12.3 KB
/
Mods_UserControl.xaml.cs
File metadata and controls
338 lines (286 loc) · 12.3 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using TD_Loader.Classes;
namespace TD_Loader
{
/// <summary>
/// Interaction logic for Mods_UserControl.xaml
/// </summary>
public partial class Mods_UserControl : UserControl
{
public static Mods_UserControl instance;
public List<string> modPaths = new List<string>();
public List<ModItem_UserControl> modItems = new List<ModItem_UserControl>();
public Mods_UserControl()
{
InitializeComponent();
instance = this;
HighestPriority.IsEnabled = false;
RaisePriority.IsEnabled = false;
LowestPriority.IsEnabled = false;
LowerPriority.IsEnabled = false;
SelectedMods_ListBox.SelectionChanged += SelectedMods_ListBox_SelectionChanged;
}
public void PopulateMods(string game)
{
if (!Guard.IsStringValid(Settings.game.ModsDir))
return;
Mods_ListBox.Items.Clear();
SelectedMods_ListBox.Items.Clear();
modPaths = new List<string>();
modItems = new List<ModItem_UserControl>();
var mods = new DirectoryInfo(Settings.game.ModsDir).GetFiles("*.*");
foreach (var mod in mods)
{
if (!mod.Name.EndsWith(".jet") && !mod.Name.EndsWith(".zip") && !mod.Name.EndsWith(".rar") && !mod.Name.EndsWith(".7z"))
continue;
if (Mods_ListBox.Items.Contains(mod))
continue;
ModItem_UserControl item = new ModItem_UserControl();
if ((Mods_ListBox.ActualWidth - 31) > 0)
item.MinWidth = Mods_ListBox.ActualWidth - 31;
item.ModName.Text = mod.Name;
Thickness margin = item.Margin;
if (Mods_ListBox.Items.Count == 0)
{
margin.Top = 10;
item.Margin = margin;
}
item.modName = mod.Name;
item.modPath = mod.FullName;
modItems.Add(item);
Mods_ListBox.Items.Add(item);
}
foreach (var selected in Settings.game.LoadedMods)
AddToSelectedModLB(selected);
Settings.game.LoadedMods.Clear();
Settings.game.LoadedMods = modPaths;
Settings.SaveGameFile();
Settings.SaveSettings();
SelectedMods_ListBox.SelectedIndex = 0;
}
private void AddToSelectedModLB(string modPath)
{
if(!File.Exists(modPath) || !Guard.IsStringValid(modPath))
{
Log.Output("Attempted to load a selected mod that doesnt exist!");
if(modPaths.Contains(modPath))
modPaths.Remove(modPath);
return;
}
string[] split = modPath.Split('\\');
string modname = split[split.Length - 1];
modPaths.Add(modPath);
SelectedMods_ListBox.Items.Add(modname);
foreach (var modItem in modItems)
{
if (modItem.ToString() == modPath)
modItem.Enable_CheckBox.IsChecked = true;
}
}
private void ModsUserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
foreach (ModItem_UserControl item in Mods_ListBox.Items)
{
if ((Mods_ListBox.ActualWidth - 31) > 0)
item.MinWidth = Mods_ListBox.ActualWidth - 31;
}
}
private void AddMods_Button_Click(object sender, RoutedEventArgs e)
{
if (Guard.IsDoingWork(MainWindow.workType)) return;
MainWindow.doingWork = true;
MainWindow.workType = "Adding mods";
if (Settings.settings.GameName != "" && Settings.settings.GameName != null)
{
List<string> mods = Mods.AddMods();
string modD = Settings.game.ModsDir;
if (modD == "" || modD == null)
{
Log.Output("Your mods directory is invalid");
Game.SetModsDir(Settings.settings.GameName);
}
if (mods != null && (modD != "" && modD != null))
{
MainWindow.workType = "Copying mods";
foreach (string mod in mods)
{
string[] split = mod.Split('\\');
string filename = split[split.Length - 1];
string copiedMod = Mods.CopyMod(mod, modD + "\\" + filename);
if (copiedMod != "" && copiedMod != " ")
{
FileInfo f = new FileInfo(copiedMod);
ModItem_UserControl item = new ModItem_UserControl();
item.MinWidth = Mods_ListBox.ActualWidth - 31;
item.ModName.Text = f.Name;
Thickness margin = item.Margin;
if (Mods_ListBox.Items.Count == 0)
{
margin.Top = 10;
item.Margin = margin;
}
item.modName = f.Name;
item.modPath = f.FullName;
Mods_ListBox.Items.Add(item);
Log.Output("Added " + item);
}
}
}
else
{
Log.Output("Mods directory not found... Please try again");
MainWindow.doingWork = false;
}
}
else
{
Log.Output("You need to choose a game before you can add mods!");
MainWindow.doingWork = false; ;
}
MainWindow.doingWork = false;
MainWindow.workType = "";
}
public void HandlePriorityButtons()
{
HighestPriority.IsEnabled = false;
RaisePriority.IsEnabled = false;
LowestPriority.IsEnabled = false;
LowerPriority.IsEnabled = false;
if(SelectedMods_ListBox.Items.Count == 1)
{
SelectedMods_ListBox.SelectedIndex = 0;
}
else if (SelectedMods_ListBox.SelectedIndex == SelectedMods_ListBox.Items.Count +1)
{
SelectedMods_ListBox.SelectedIndex = SelectedMods_ListBox.Items.Count - 1;
}
else if (SelectedMods_ListBox.Items.Count > 1)
{
if (SelectedMods_ListBox.SelectedIndex == 0)
{
LowestPriority.IsEnabled = true;
LowerPriority.IsEnabled = true;
}
else if (SelectedMods_ListBox.SelectedIndex == SelectedMods_ListBox.Items.Count - 1)
{
HighestPriority.IsEnabled = true;
RaisePriority.IsEnabled = true;
}
else
{
HighestPriority.IsEnabled = true;
RaisePriority.IsEnabled = true;
LowestPriority.IsEnabled = true;
LowerPriority.IsEnabled = true;
}
}
}
private void SelectedMods_ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
HandlePriorityButtons();
}
private void RaisePriority_Click(object sender, RoutedEventArgs e)
{
if (MainWindow.doingWork)
{
MessageBox.Show("Cant do that! Currently doing something else... Please wait");
Log.Output("Cant do that! Currently doing something else... Please wait");
return;
}
int index = SelectedMods_ListBox.SelectedIndex;
string temp = SelectedMods_ListBox.Items.GetItemAt(index - 1).ToString();
string tempPath = modPaths[index - 1];
SelectedMods_ListBox.Items[index - 1] = SelectedMods_ListBox.SelectedItem;
modPaths[index - 1] = modPaths[index];
SelectedMods_ListBox.Items[index] = temp;
modPaths[index] = tempPath;
SelectedMods_ListBox.SelectedIndex = index - 1;
}
private void LowerPriority_Click(object sender, RoutedEventArgs e)
{
if (MainWindow.doingWork)
{
MessageBox.Show("Cant do that! Currently doing something else... Please wait");
Log.Output("Cant do that! Currently doing something else... Please wait");
return;
}
int index = SelectedMods_ListBox.SelectedIndex;
string temp = SelectedMods_ListBox.Items.GetItemAt(index + 1).ToString();
string tempPath = modPaths[index + 1];
SelectedMods_ListBox.Items[index + 1] = SelectedMods_ListBox.SelectedItem;
modPaths[index + 1] = modPaths[index];
SelectedMods_ListBox.Items[index] = temp;
modPaths[index] = tempPath;
SelectedMods_ListBox.SelectedIndex = index + 1;
}
private void HighestPriority_Click(object sender, RoutedEventArgs e)
{
if (MainWindow.doingWork)
{
MessageBox.Show("Cant do that! Currently doing something else... Please wait");
Log.Output("Cant do that! Currently doing something else... Please wait");
return;
}
string temp = SelectedMods_ListBox.Items.GetItemAt(SelectedMods_ListBox.SelectedIndex).ToString();
var newItems = new DataGrid().Items;
string tempPath = modPaths[SelectedMods_ListBox.SelectedIndex];
SelectedMods_ListBox.Items.RemoveAt(SelectedMods_ListBox.SelectedIndex);
newItems.Add(temp);
foreach (var item in SelectedMods_ListBox.Items)
newItems.Add(item);
SelectedMods_ListBox.Items.Clear();
foreach (var i in newItems)
SelectedMods_ListBox.Items.Add(i);
modPaths.Remove(tempPath);
modPaths.Insert(0, tempPath);
SelectedMods_ListBox.SelectedIndex = 0;
}
private void LowestPriority_Click(object sender, RoutedEventArgs e)
{
if (MainWindow.doingWork)
{
MessageBox.Show("Cant do that! Currently doing something else... Please wait");
Log.Output("Cant do that! Currently doing something else... Please wait");
return;
}
string temp = SelectedMods_ListBox.Items.GetItemAt(SelectedMods_ListBox.SelectedIndex).ToString();
var newItems = new DataGrid().Items;
string tempPath = modPaths[SelectedMods_ListBox.SelectedIndex];
SelectedMods_ListBox.Items.RemoveAt(SelectedMods_ListBox.SelectedIndex);
foreach (var item in SelectedMods_ListBox.Items)
newItems.Add(item);
newItems.Add(temp);
SelectedMods_ListBox.Items.Clear();
foreach (var i in newItems)
SelectedMods_ListBox.Items.Add(i);
modPaths.Remove(tempPath);
modPaths.Insert(SelectedMods_ListBox.Items.Count-1, tempPath);
SelectedMods_ListBox.SelectedIndex = SelectedMods_ListBox.Items.Count-1;
}
private void SelectedMods_ListBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
if(SelectedMods_ListBox.Items.Contains("") || SelectedMods_ListBox.Items.Contains(" "))
{
modPaths.Remove("");
modPaths.Remove(" ");
SelectedMods_ListBox.Items.Remove("");
SelectedMods_ListBox.Items.Remove(" ");
}
}
}
}