forked from Just2good/TFT-Overlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
297 lines (250 loc) · 10.8 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
using System;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using TFT_Overlay.Properties;
using TFT_Overlay.Utilities;
namespace TFT_Overlay
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public IntPtr myHandle;
private System.Timers.Timer tTop;
private readonly Cursor LoLNormal = CustomCursor.FromByteArray(Properties.Resources.LoLNormal);
private readonly Cursor LoLPointer = CustomCursor.FromByteArray(Properties.Resources.LoLPointer);
private readonly Cursor LoLHover = CustomCursor.FromByteArray(Properties.Resources.LoLHover);
private string CurrentVersion { get; } = Utilities.Version.version;
private bool OnTop { get; set; } = true;
private bool canDrag;
public bool CanDrag
{
get => canDrag;
set
{
canDrag = value;
Settings.FindAndUpdate("Lock", !value);
}
}
public MainWindow()
{
InitializeComponent();
LoadStringResource(Settings.Default.Language);
this.Cursor = LoLNormal;
this.WindowState = System.Windows.WindowState.Normal;
this.ShowInTaskbar = true;
this.Topmost = OnTop;
myHandle = new System.Windows.Interop.WindowInteropHelper(this).Handle;
//...
tTop = new System.Timers.Timer(15000);//set Timer
tTop.Elapsed += new System.Timers.ElapsedEventHandler(theout);
tTop.AutoReset = true;
tTop.Enabled = true;
CanDrag = !Settings.Default.Lock;
if (Settings.Default.AutoDim == true)
{
Thread t = new Thread(new ThreadStart(AutoDim))
{
IsBackground = true
};
t.Start();
}
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
if (OnTop)
{
if (myHandle != GetForegroundWindow()) //let the win always on focus
{
SetForegroundWindow(myHandle);
}
try
{
this.Dispatcher.Invoke(
new Action(
delegate
{
this.Topmost = false;
this.Topmost = true;
}
)
);
}
catch (System.Threading.Tasks.TaskCanceledException errMsg)
{
tTop.Stop();
}
}
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Settings.Default.Save();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void MenuItem_Click_About(object sender, RoutedEventArgs e)
{
MessageBox.Show("TFT Information Overlay V" + CurrentVersion + " by J2GKaze/Jinsoku#4019\n\nDM me on Discord if you have any questions\n\nLast Updated: August 11th, 2019 @ 2:06AM PDT", "About");
}
private void MenuItem_Click_Credits(object sender, RoutedEventArgs e)
{
MessageBox.Show("Big thanks to:\nChaoticoz: Lock Window, Always on Top, and Mouseover\nAsemco/Asemco#7390: Adding Origins and Classes\nAthenyx#9406: Designs\nTenebris: Auto-Updater\nOBJECT#3031: Items/Origins/Classes Strings Base\nJpgdev: Readme format\nKbphan\nEerilai\nꙅꙅɘᴎTqAbɘbᴎɘld#1175: Window Position/Size Saving, CPU Threading Fix\nNarcolic#6374: Item Builder\nIzoyo: Fullscreen\n\nShoutout to:\nAlexander321#7153 for the Discord Nitro Gift!\nAnonymous for Reddit Gold\nu/test01011 for Reddit Gold\n\nmac#0001 & bNatural#0001(Feel free to bug these 2 on Discord) ;)\nShamish#4895 (Make sure you bug this guy a lot)\nDekinosai#7053 (Buy this man tons of drinks)", "Credits");
}
private void MenuItem_Click_Lock(object sender, RoutedEventArgs e)
{
CanDrag = !CanDrag;
}
private void MenuItem_AutoUpdate(object sender, RoutedEventArgs e)
{
string state = Settings.Default.AutoUpdate == true ? "OFF" : "ON";
MessageBoxResult result = MessageBox.Show($"Would you like to turn {state} Auto-Update? This will restart the program.", "Auto-Updater", MessageBoxButton.OKCancel);
if (result != MessageBoxResult.OK)
{
return;
}
Settings.FindAndUpdate("AutoUpdate", !Settings.Default.AutoUpdate);
System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
private void MenuItem_Click_OnTop(object sender, RoutedEventArgs e)
{
if (OnTop)
{
this.Topmost = false;
OnTop = false;
}
else
{
this.Topmost = true;
OnTop = true;
}
}
private void MainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
((Control)sender).Cursor = LoLPointer;
if (CanDrag)
{
this.DragMove();
}
}
private void MainWindow_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
((Control)sender).Cursor = LoLNormal;
}
private void MainWindow_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
((Control)sender).Cursor = LoLHover;
}
private void MainWindow_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
((Control)sender).Cursor = LoLNormal;
}
private void AutoDim_Click(object sender, RoutedEventArgs e)
{
string state = Settings.Default.AutoDim == true ? "OFF" : "ON";
MessageBoxResult result = MessageBox.Show($"Would you like to turn {state} Auto-Dim? This will restart the program.", "Auto-Dim", MessageBoxButton.OKCancel);
if (result != MessageBoxResult.OK)
{
return;
}
Settings.FindAndUpdate("AutoDim", !Settings.Default.AutoDim);
System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
private void AutoDim()
{
while (true)
{
if (IsLeagueOrOverlayActive())
{
Dispatcher.BeginInvoke(new ThreadStart(() => App.Current.MainWindow.Opacity = 1));
}
else if (!IsLeagueOrOverlayActive())
{
Dispatcher.BeginInvoke(new ThreadStart(() => App.Current.MainWindow.Opacity = .2));
}
Thread.Sleep(500);
}
}
private bool IsLeagueOrOverlayActive()
{
string currentActiveProcessName = ProcessHelper.GetActiveProcessName();
return currentActiveProcessName.Contains("League of Legends") || currentActiveProcessName.Contains("TFT Overlay");
}
/// <summary>
/// Removes previous ItemStrings.xaml from MergedDictionaries and adds the one matching locale tag
/// </summary>
/// <param name="locale">localization tag</param>
private void LoadStringResource(string locale)
{
try
{
var resources = new ResourceDictionary();
resources.Source = new Uri("pack://application:,,,/Resource/Localization/ItemStrings_" + locale + ".xaml", UriKind.Absolute);
var current = Application.Current.Resources.MergedDictionaries.FirstOrDefault(
m => m.Source.OriginalString.EndsWith("ItemStrings_" + locale + ".xaml"));
if (current != null)
{
Application.Current.Resources.MergedDictionaries.Remove(current);
}
Application.Current.Resources.MergedDictionaries.Add(resources);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
LoadStringResource("en-US");
}
}
private void Localization_Credits(object sender, RoutedEventArgs e)
{
MessageBox.Show("de-DE: Revyn#0969\nes-AR: Oscarinom\nes-MX: Jukai#3434\nfr-FR: Darkneight\nHU: Edizone#6157\nit-IT: BlackTYWhite#0943\nJA: つかぽん@PKMotion#8731\nPL: Czapson#9774\npt-BR: Bigg#4019\nRU: Jeremy Buttson#2586\nSL: Shokugeki#0012\nvi-VN: GodV759\nzh-CN: nevex#4441\nzh-TW: noheart#6977\n", "Localization Credits");
}
/// <summary>
/// Takes MenuItem, and passes its Header into LoadStringresource()
/// </summary>
/// <param name="sender">Should be of type MenuItem</param>
/// <param name="e"></param>
private void Localization_Handler(object sender, RoutedEventArgs e)
{
if (sender is MenuItem menuItem)
{
string tag = menuItem.Header.ToString();
LoadStringResource(tag);
Settings.FindAndUpdate("Language", tag);
}
}
private void ResetToDefault_Click(object sender, RoutedEventArgs e)
{
Settings.Default.Reset();
CanDrag = true;
LoadStringResource(Settings.Default.Language);
}
private void IconOpacityHandler_Click(object sender, RoutedEventArgs e)
{
if (sender is MenuItem menuItem)
{
string header = menuItem.Header.ToString();
double opacity = double.Parse(header.Substring(0, header.Length - 1)) / 100;
Settings.FindAndUpdate("IconOpacity", opacity);
}
}
private void OpenChangelog_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/Just2good/TFT-Overlay/blob/master/README.md#version-history");
}
private void LocalizationHelp_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/Just2good/TFT-Overlay/blob/master/Localization.md");
}
}
}