-
Notifications
You must be signed in to change notification settings - Fork 10
/
PathTemplateWindow.xaml.cs
170 lines (155 loc) · 6.35 KB
/
PathTemplateWindow.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
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using RT.Util.Dialogs;
using RT.Util.Forms;
using RT.Util.Lingo;
using WotDataLib;
namespace TankIconMaker
{
partial class PathTemplateWindow : ManagedWindow
{
private WotContext _context;
private Style _style;
private SaveType _saveType;
private WotTank _exampleTank;
internal PathTemplateWindow()
: base(App.Settings.PathTemplateWindow)
{
InitializeComponent();
}
public PathTemplateWindow(string value, WotContext context, Style style, SaveType saveType)
: this()
{
MainWindow.ApplyUiZoom(this);
Title = App.Translation.PathTemplateWindow.Title;
Lingo.TranslateWindow(this, App.Translation.PathTemplateWindow);
_context = context;
_style = style;
_saveType = saveType;
ctValue.Text = value;
ctValue.Focus();
ctValue_TextChanged(null, null);
var isAtlas = saveType != SaveType.Icons;
if (isAtlas)
{
ctIconsPathMacro.Text = "{AtlasPath}";
for (int i = 4; i <= 9; ++i)
{
var row = this.ctHelpGrid.RowDefinitions[i];
row.Height = new GridLength(0);
}
}
else
{
_exampleTank = context.Tanks.FirstOrDefault(x => x.TankId.Contains("Object_260"));
if (_exampleTank == null)
{
_exampleTank = context.Tanks.FirstOrDefault();
}
}
ctIconsPathHelp.Text = isAtlas
? ctIconsPathHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{AtlasPath}", _context, _style, "", "", fragment: true))
: ctIconsPathHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{IconsPath}", _context, _style, "", "", fragment: true));
ctTimPathHelp.Text = ctTimPathHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{TimPath}", _context, _style, "", "", fragment: true));
ctGamePathHelp.Text = ctGamePathHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{GamePath}", _context, _style, "", "", fragment: true));
ctGameVersionHelp.Text = ctGameVersionHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{GameVersion}", _context, _style, "", "", fragment: true));
ctStyleNameHelp.Text = ctStyleNameHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{StyleName}", _context, _style, "", "", fragment: true));
ctStyleAuthorHelp.Text = ctStyleAuthorHelp.Text.Replace("{cur}",
Ut.ExpandIconPath("{StyleAuthor}", _context, _style, "", "", fragment: true));
}
private void ok(object sender, RoutedEventArgs e)
{
if (!checkPath())
{
return;
}
DialogResult = true;
}
private bool checkPath()
{
var text = this.ctValue.Text;
if (string.IsNullOrEmpty(text))
{
return true;
}
if (this._saveType == SaveType.Icons)
{
int res;
string append;
if (!text.Contains("{TankId}") && !text.Contains("{TankFullName}") && !text.Contains("{TankShortName}"))
{
res = DlgMessage.ShowQuestion(
App.Translation.PathTemplateWindow.WarnIconsPathIsFolder,
new string[]
{App.Translation.Prompt.Yes, App.Translation.Prompt.No, App.Translation.Prompt.Cancel});
append = @"\{TankId}{Ext}";
}
else if (!text.EndsWith("{Ext}"))
{
res = DlgMessage.ShowQuestion(
App.Translation.PathTemplateWindow.WarnIconsPathNoExt,
new string[] { App.Translation.Prompt.Yes, App.Translation.Prompt.No, App.Translation.Prompt.Cancel });
append = @"{Ext}";
}
else
{
return true;
}
switch (res)
{
case 0:
this.ctValue.Text += append;
return true;
case 1:
return true;
default:
return false;
}
}
else
{
if (!text.EndsWith(".png"))
{
string atlasName = AtlasBuilder.GetAtlasFilename(this._saveType);
var res = DlgMessage.ShowQuestion(
string.Format(App.Translation.PathTemplateWindow.WarnAtlasPathIsFolder, atlasName),
new string[]
{App.Translation.Prompt.Yes, App.Translation.Prompt.No, App.Translation.Prompt.Cancel});
switch (res)
{
case 0:
this.ctValue.Text += @"\" + atlasName;
return true;
case 1:
return true;
default:
return false;
}
}
}
return true;
}
public static string Show(Window owner, string value, WotContext context, Style style, SaveType saveType)
{
var wnd = new PathTemplateWindow(value, context, style, saveType) { Owner = owner };
if (wnd.ShowDialog() != true)
return null;
return wnd.ctValue.Text;
}
private void ctValue_TextChanged(object sender, TextChangedEventArgs e)
{
ctExpandsTo.Text = Ut.ExpandIconPath(ctValue.Text, _context, _style, _exampleTank, saveType: this._saveType);
}
private void SelectAll(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
(sender as TextBox).SelectAll();
}
}
}