forked from iwubcode/DolphinDynamicInputTextureCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
306 lines (257 loc) · 10.1 KB
/
MainWindow.xaml.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
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
using DolphinDynamicInputTexture.Data;
using DolphinDynamicInputTextureCreator.ViewModels;
using Newtonsoft.Json;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace DolphinDynamicInputTextureCreator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
DynamicInputTextureEvents.ImageNotExist = Dialogs.ImageNotExistMessage;
InitializeComponent();
this.Title += " " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
InputPack = Models.DefaultData.NewInputPack();
}
private DynamicInputPackViewModel InputPack
{
get => (DynamicInputPackViewModel)DataContext;
set
{
if (value == null)
return;
value.CheckImagePaths();
DataContext = value;
((PanZoomViewModel)PanZoom.DataContext).InputPack = value;
UnsavedChanges = false;
}
}
private string _saved_document = null;
private Window _edit_emulated_devices_window;
private Window _edit_host_devices_window;
private Window _edit_metadata_window;
private Window _edit_tags_window;
private void QuitProgram_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void EditHostDevices_Click(object sender, RoutedEventArgs e)
{
_edit_host_devices_window?.Close();
_edit_host_devices_window = new Window
{
Title = "Editing Host Devices",
Icon = ResourceShapePathToImage("Icon.HostDevices"),
ResizeMode = ResizeMode.CanResize,
SizeToContent = SizeToContent.Manual,
Owner = Application.Current.MainWindow,
Top = this.Top + 50, Left = this.Left + 70,
Width = 620, Height = 550, MinWidth = 500, MinHeight = 400
};
UpdateEditWindows();
_edit_host_devices_window.Show();
}
private void EditEmulatedDevices_Click(object sender, RoutedEventArgs e)
{
_edit_emulated_devices_window?.Close();
_edit_emulated_devices_window = new Window
{
Title = "Editing Emulated Devices",
Icon = ResourceShapePathToImage("Icon.EmulatedDevices"),
ResizeMode = ResizeMode.CanResize,
SizeToContent = SizeToContent.Manual,
Owner = Application.Current.MainWindow,
Top = this.Top + 50, Left = this.Left + 70,
Width = 620, Height = 550, MinWidth = 500, MinHeight = 400
};
UpdateEditWindows();
_edit_emulated_devices_window.Show();
}
private void EditMetadata_Click(object sender, RoutedEventArgs e)
{
_edit_metadata_window?.Close();
_edit_metadata_window = new Window
{
Title = "Editing Metadata",
Icon = ResourceShapePathToImage("Icon.Metadata"),
ResizeMode = ResizeMode.NoResize,
SizeToContent = SizeToContent.WidthAndHeight,
Owner = Application.Current.MainWindow,
Top = this.Top + 50, Left = this.Left + 70
};
UpdateEditWindows();
_edit_metadata_window.Show();
}
private void EditTags_Click(object sender, RoutedEventArgs e)
{
_edit_tags_window?.Close();
_edit_tags_window = new Window
{
Title = "Editing Tags",
Icon = ResourceShapePathToImage("Icon.EditTags"),
ResizeMode = ResizeMode.CanResize,
SizeToContent = SizeToContent.Manual,
Owner = Application.Current.MainWindow,
Top = this.Top + 50, Left = this.Left + 70,
Width = 340, Height = 300,
MinWidth = 190, MinHeight = 300
};
UpdateEditWindows();
_edit_tags_window.Show();
}
private ImageSource ResourceShapePathToImage(object resourceKey)
{
return ValueConverters.ShapePathToImageConverter.ConvertToDrawingImage((System.Windows.Shapes.Path)FindResource(resourceKey));
}
public static RoutedUICommand SaveAsCmd = new RoutedUICommand("Save as...", "SaveAsCmd", typeof(MainWindow));
#region NEW
private void NewData_Click(object sender, RoutedEventArgs e)
{
InputPack = Models.DefaultData.NewInputPack();
UpdateEditWindows();
_saved_document = null;
}
private void NewData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
#endregion
#region SAVE
private void SaveData_Click(object sender, RoutedEventArgs e)
{
if (_saved_document == null)
{
SaveAsData_Click(sender, e);
}
else
{
string output = JsonConvert.SerializeObject(InputPack, Formatting.Indented);
File.WriteAllText(_saved_document, output);
UnsavedChanges = false;
}
}
private void SaveData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
#endregion
#region OPEN
private void OpenData_Click(object sender, RoutedEventArgs e)
{
InputPack = Dialogs.DialogOpenDIT(ref _saved_document);
UpdateEditWindows();
}
private void OpenData_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
#endregion
#region Export Import
private void ExportData_Click(object sender, RoutedEventArgs e)
{
Dialogs.DialogExportToLocation(InputPack);
}
private void ImportData_Click(object sender, RoutedEventArgs e)
{
DynamicInputPackViewModel inputPack = Dialogs.DialogImportFromLocation(Models.DefaultData.NewInputPack());
if (inputPack != null)
{
InputPack = inputPack;
_saved_document = null;
UpdateEditWindows();
}
}
#endregion
#region SAVE AS
private void SaveAsData_Click(object sender, RoutedEventArgs e)
{
bool result = Dialogs.DialogSaveDIT(InputPack, ref _saved_document);
if (result)
{
UnsavedChanges = false;
}
}
private void SaveStartupSuggestions_Click(object sender, RoutedEventArgs e)
{
Models.DefaultData.SaveSettings();
}
private void SaveAsDefaultPack_Click(object sender, RoutedEventArgs e)
{
Models.DefaultData.SaveInputPack(InputPack);
}
private void SaveDataAs_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
#endregion
private void UpdateEditWindows()
{
if (_edit_emulated_devices_window != null)
{
var user_control = new Controls.EditEmulatedDevices { DataContext = new EmulatedDeviceKeysViewModel { InputPack = InputPack } };
_edit_emulated_devices_window.Content = user_control;
}
if (_edit_host_devices_window != null)
{
var user_control = new Controls.EditHostDevices { DataContext = new HostDeviceKeyViewModel { HostDevices = InputPack.HostDevices, Tags = InputPack.Tags } };
_edit_host_devices_window.Content = user_control;
}
if (_edit_metadata_window != null)
{
var user_control = new Controls.Metadata { DataContext = InputPack };
_edit_metadata_window.Content = user_control;
}
if (_edit_tags_window != null)
{
var user_control = new Controls.EditTags { DataContext = new TagsViewModel { Tags= InputPack.Tags } };
_edit_tags_window.Content = user_control;
}
}
#region Closing
public bool UnsavedChanges
{
get => unsavedChanges;
set
{
unsavedChanges = value;
if (unsavedChanges)
{
InputPack.Textures.CollectionChanged -= ChangesObserved;
InputPack.HostDevices.CollectionChanged -= ChangesObserved;
InputPack.EmulatedDevices.CollectionChanged -= ChangesObserved;
}
else
{
InputPack.Textures.CollectionChanged += ChangesObserved;
InputPack.HostDevices.CollectionChanged += ChangesObserved;
InputPack.EmulatedDevices.CollectionChanged += ChangesObserved;
}
}
}
private bool unsavedChanges = false;
private void ChangesObserved(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) => UnsavedChanges = true;
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (unsavedChanges)
{
switch (MessageBox.Show("The project has unsaved changes, do you want to save?", "unsaved changes!", MessageBoxButton.YesNoCancel, MessageBoxImage.Information))
{
case MessageBoxResult.Cancel:
e.Cancel = true;
break;
case MessageBoxResult.Yes:
SaveData_Click(sender, new RoutedEventArgs());
e.Cancel = unsavedChanges;
break;
}
}
}
#endregion
}
}