forked from KirillSuxinin/Stalker-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingGroupsElementWin.xaml.cs
406 lines (351 loc) · 19.3 KB
/
SettingGroupsElementWin.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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
using System;
using System.Collections.Generic;
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.Shapes;
using System.IO;
namespace Stalker_Studio
{
/// <summary>
/// Логика взаимодействия для SettingGroupsElementWin.xaml
/// </summary>
public partial class SettingGroupsElementWin : Window
{
public SettingGroupsElementWin()
{
InitializeComponent();
InterfaceHelper.InitializeWindow(this);
InitializerComponentsLtx();
}
Dictionary<string, string> ltx_parametr = new Dictionary<string, string>();
string pathPrm = $"{System.Windows.Forms.Application.StartupPath}\\GroupsParametr.ltx";
private void InitializerComponentsLtx()
{
tree_parametr.Items.Clear();
ltx_parametr.Clear();
if (File.Exists(pathPrm))
{
StalkerClass.HierarchyLtx.LtxFile _prm = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
foreach (var v in _prm.Sections)
{
string nameGroup = v.Name_Section;
TreeViewItem objI = new TreeViewItem();
objI.Header = nameGroup;
List<string> prms = new List<string>();
foreach (var vPrm in v.Parametrs)
{
int Ispace = int.Parse(v.Heir_Section.Trim().Split(';')[1]);
int ISpace2 = int.Parse(v.Heir_Section.Trim().Split(';')[0]);
ltx_parametr.Add(vPrm.Name_Parametr.Trim(), vPrm.Value_Parametr.Trim());
if (vPrm.Desription_Parametr != null && vPrm.Desription_Parametr.Split(':').Length > 1)
{
Ispace = int.Parse(vPrm.Desription_Parametr.Trim().Split(':')[1]);
ISpace2 = int.Parse(vPrm.Desription_Parametr.Trim().Split(':')[0]);
}
AddToGroupElements(objI, Ispace, new string[] { vPrm.Value_Parametr.Trim() }, new FrameworkElement[] { new TextBox() { Name = $"prm_{vPrm.Name_Parametr.Trim()}", Tag = vPrm.Name_Parametr.Trim(), Width = ISpace2 } });
}
tree_parametr.Items.Add(objI);
}
}
}
private void InitializerComponentsLtx(bool saveRec)
{
List<string> headers = new List<string>();
foreach(TreeViewItem v in tree_parametr.Items)
{
if (v.IsExpanded)
headers.Add(v.Header.ToString());
}
TreeViewItem objS = (tree_parametr.SelectedItem as TreeViewItem);
InitializerComponentsLtx();
foreach(TreeViewItem it in tree_parametr.Items)
{
foreach(string v in headers)
{
if (it.Header.ToString() == v)
it.IsExpanded = true;
}
if (objS != null)
if (it.Header.ToString() == objS.Header.ToString())
it.IsSelected = true;
}
}
public void AddToGroupElements(TreeViewItem group, int width_panel, string[] NameElements, FrameworkElement[] elements, FrameworkElement[] centerElement = null)
{
if (NameElements.Length != elements.Length)
return;
for (int el = 0; el < NameElements.Length; el++)
{
StackPanel panel = new StackPanel();
panel.HorizontalAlignment = HorizontalAlignment.Right;
panel.Width = width_panel;
Label labName = new Label();
labName.Content = NameElements[el];
labName.Name = $"lab_{elements[el].Name}";
int _a = 20;
for (int j = 0; j < labName.Content.ToString().Length; j++)
_a += 4;
elements[el].Margin = new Thickness(_a, -25, 0, 0);
elements[el].HorizontalAlignment = HorizontalAlignment.Right;
labName.Margin = new Thickness(-5, 0, 0, 0);
panel.Children.Add(labName);
if (centerElement != null && el <= centerElement.Length)
{
int a = 20;
for (int j = 0; j < labName.Content.ToString().Length; j++)
a += 4;
centerElement[el].HorizontalAlignment = HorizontalAlignment.Center;
centerElement[el].Margin = new Thickness(a, -25, 0, 0);
panel.Children.Add(centerElement[el]);
}
panel.Children.Add(elements[el]);
group.Items.Add(panel);
}
}
private void ClearData()
{
txt_description.Text = "";
txt_parametr.Text = "";
txt_space.Text = "";
txt_spaceTextBox.Text = "";
}
private void btn_close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
if(tree_parametr.SelectedItem != null && (tree_parametr.SelectedItem is TreeViewItem))
{
string Group = (tree_parametr.SelectedItem as TreeViewItem).Header.ToString();
if (MessageBox.Show($"Вы действительно хотите удалить группу?\n\"{Group}\"","Удаления группы",MessageBoxButton.YesNo,MessageBoxImage.Question) == MessageBoxResult.Yes)
{
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
fls.Sections.Remove(fls.Sections.Where(x => x.Name_Section == Group).First());
fls.SaveFile(null, Encoding.UTF8);
InitializerComponentsLtx(true);
ClearData();
// ((TreeViewItem)tree_parametr.SelectedItem).IsSelected = false;
}
}
else if(tree_parametr.SelectedItem != null)
{
StackPanel pnl = (tree_parametr.SelectedItem as StackPanel);
string parentGroup = (pnl.Parent as TreeViewItem).Header.ToString();
Label lbl = (pnl.Children[0] as Label);
string nameParametr = lbl.Content.ToString();
string parametr = lbl.Name.ToString().Replace("lab_prm_", "");
if(MessageBox.Show($"Вы действительно хотите удалить параметр?\n\"{nameParametr}\" - \"{parametr}\"","Удаления параметра",MessageBoxButton.YesNo,MessageBoxImage.Question) == MessageBoxResult.Yes)
{
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
fls.Sections.Where(x => x.Name_Section == parentGroup).First().Parametrs.Remove(fls.Sections.Where(x => x.Name_Section == parentGroup).First().Parametrs.Where(x => x.Name_Parametr == parametr && x.Value_Parametr == nameParametr).First());
fls.SaveFile(null, Encoding.UTF8);
InitializerComponentsLtx(true);
ClearData();
//((TreeViewItem)tree_parametr.SelectedItem).IsSelected = false;
}
}
}
public StalkerClass.HierarchyLtx.Ltx_Parametr PrmInvoke;
private string PrmParentI;
public StalkerClass.HierarchyLtx.Ltx_Section PrmSectInvoke;
private void tree_parametr_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
//ClearData();
if (grid_workParametr.Visibility == Visibility.Hidden)
grid_workParametr.Visibility = Visibility.Visible;
if (tree_parametr.SelectedItem == null)
return;
if(!(tree_parametr.SelectedItem is TreeViewItem))
{
PrmInvoke = null;
PrmSectInvoke = null;
lab_description.Visibility = Visibility.Visible;
lab_parametr.Visibility = Visibility.Visible;
txt_description.Visibility = Visibility.Visible;
txt_parametr.Visibility = Visibility.Visible;
StackPanel pnl = (tree_parametr.SelectedItem as StackPanel);
string parentGroup = (pnl.Parent as TreeViewItem).Header.ToString();
Label lbl = (pnl.Children[0] as Label);
string nameParametr = lbl.Content.ToString();
string parametr = lbl.Name.ToString().Replace("lab_prm_", "");
txt_description.Text = nameParametr;
txt_description.Tag = parametr;
txt_parametr.Text = parametr;
txt_parametr.Tag = parametr;
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
StalkerClass.HierarchyLtx.Ltx_Parametr prm = fls.Sections.Where(x => x.Name_Section == parentGroup).First().Parametrs.Where(x => x.Name_Parametr == parametr && x.Value_Parametr == nameParametr).First();
PrmInvoke = prm;
PrmParentI = parentGroup;
if(prm != null)
{
//change
if(prm.Desription_Parametr != null && prm.Desription_Parametr.Split(':').Length > 1)
{
int Ispace = int.Parse(prm.Desription_Parametr.Trim().Split(':')[1]);
int ISpace2 = int.Parse(prm.Desription_Parametr.Trim().Split(':')[0]);
txt_space.Text = Ispace.ToString();
txt_spaceTextBox.Text = ISpace2.ToString();
}
else
{
txt_space.Text = "";
txt_spaceTextBox.Text = "";
}
}
}
else
{
lab_description.Visibility = Visibility.Hidden;
lab_parametr.Visibility = Visibility.Hidden;
txt_description.Visibility = Visibility.Hidden;
txt_parametr.Visibility = Visibility.Hidden;
PrmInvoke = null;
PrmSectInvoke = null;
//change group
string group = (tree_parametr.SelectedItem as TreeViewItem).Header.ToString();
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
PrmSectInvoke = fls.Sections.Where(x => x.Name_Section == group).First();
int Ispace = int.Parse(PrmSectInvoke.Heir_Section.Trim().Split(';')[1]);
int ISpace2 = int.Parse(PrmSectInvoke.Heir_Section.Trim().Split(';')[0]);
txt_space.Text = Ispace.ToString();
txt_spaceTextBox.Text = ISpace2.ToString();
}
}
private void btn_inv_Click(object sender, RoutedEventArgs e)
{
if(tree_parametr.SelectedItem == null)
{
ClearData();
return;
}
if (!(tree_parametr.SelectedItem is TreeViewItem))
{
//save parametr
string descr = txt_description.Text;
string parametr = txt_parametr.Text;
if(!string.IsNullOrWhiteSpace(descr) && !string.IsNullOrWhiteSpace(parametr))
{
if (PrmInvoke != null)
{
string OparentGroup = PrmParentI;
string OnameParametr = PrmInvoke.Value_Parametr;
string Oparametr = PrmInvoke.Name_Parametr.Replace("lab_prm_", "");//сам параметр
//change
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
if (!string.IsNullOrWhiteSpace(txt_space.Text) && !string.IsNullOrWhiteSpace(txt_spaceTextBox.Text))
{
int a = int.Parse(txt_space.Text);
int b = int.Parse(txt_spaceTextBox.Text);
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Where(x => x.Name_Parametr == Oparametr && x.Value_Parametr == OnameParametr).First().Desription_Parametr = $"{b}:{a}";
}
else
{
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Where(x => x.Name_Parametr == Oparametr && x.Value_Parametr == OnameParametr).First().Desription_Parametr = null;
}
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Where(x => x.Name_Parametr == Oparametr && x.Value_Parametr == OnameParametr).First().Value_Parametr = descr;
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Where(x => x.Name_Parametr == Oparametr).First().Name_Parametr = parametr;
fls.SaveFile(null, Encoding.UTF8,false);
InitializerComponentsLtx(true);
}
else
{
//create
/*
StackPanel pnl = (tree_parametr.SelectedItem as StackPanel);
string OparentGroup = (pnl.Parent as TreeViewItem).Header.ToString();
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Add(new StalkerClass.HierarchyLtx.Ltx_Parametr("ПАРАМЕТР = ОПИСАНИЕ"));
fls.SaveFile(null, Encoding.UTF8);
InitializerComponentsLtx(true);*/
}
}
else
{
MessageBox.Show("Введите данные!\nОбязательные: описание,параметр", "Проблема с данными!", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
else
{
//save group
string group = PrmSectInvoke.Name_Section;
if (!string.IsNullOrWhiteSpace(txt_space.Text) && !string.IsNullOrWhiteSpace(txt_spaceTextBox.Text))
{
int a = int.Parse(txt_space.Text);
int b = int.Parse(txt_spaceTextBox.Text);
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
if (PrmSectInvoke != null)
{
fls.Sections.Where(x => x.Name_Section == PrmSectInvoke.Name_Section).First().Heir_Section = $"{b};{a}";
fls.SaveFile(null,Encoding.UTF8,false);
InitializerComponentsLtx(true);
}
}
else
{
MessageBox.Show("Введите данные!\nОбязательные: пространство,пространство TextBox", "Проблема с данными!", MessageBoxButton.OK, MessageBoxImage.Warning);
// fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Where(x => x.Name_Parametr == Oparametr && x.Value_Parametr == OnameParametr).First().Desription_Parametr = "";
}
}
}
private void MenuItem_Click_1(object sender, RoutedEventArgs e)
{
if(PrmSectInvoke != null)
{
string OparentGroup = PrmSectInvoke.Name_Section;
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
if (fls.Sections.Where(x => x.Name_Section == OparentGroup).Count() > 0)
{
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Add(new StalkerClass.HierarchyLtx.Ltx_Parametr("ПАРАМЕТР = ОПИСАНИЕ"));
fls.SaveFile(null, Encoding.UTF8);
InitializerComponentsLtx(true);
}
else
{
MessageBox.Show("Не удалось создать параметр по причине: \"Нет группы\"", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else if(tree_parametr.SelectedItem is StackPanel)
{
StackPanel pnl = (tree_parametr.SelectedItem as StackPanel);
string OparentGroup = (pnl.Parent as TreeViewItem).Header.ToString();
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
if (fls.Sections.Where(x => x.Name_Section == OparentGroup).Count() > 0)
{
fls.Sections.Where(x => x.Name_Section == OparentGroup).First().Parametrs.Add(new StalkerClass.HierarchyLtx.Ltx_Parametr("ПАРАМЕТР = ОПИСАНИЕ"));
fls.SaveFile(null, Encoding.UTF8);
InitializerComponentsLtx(true);
}
else
{
MessageBox.Show("Не удалось создать параметр по причине: \"Нет группы\"", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
private void MenuItem_Click_2(object sender, RoutedEventArgs e)
{
StalkerClass.HierarchyLtx.LtxFile fls = new StalkerClass.HierarchyLtx.LtxFile(new FileInfo(pathPrm), Encoding.UTF8);
StalkerWin.Dialogs.Enter_string_win stringText = new StalkerWin.Dialogs.Enter_string_win("Введите название группы", "Название группы");
stringText.Owner = this;
stringText.ShowDialog();
if (stringText.IsOk)
{
fls.Sections.Add(new StalkerClass.HierarchyLtx.Ltx_Section()
{
Name_Section = stringText.TextBody,
Heir_Section = "100;170"
});
fls.SaveFile(null, Encoding.UTF8, false);
InitializerComponentsLtx(true);
}
}
}
}