-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMain2Window.cs
294 lines (221 loc) · 8.93 KB
/
Main2Window.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
using ComponentFactory.Krypton.Toolkit;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DualSenseAT
{
public partial class Main2Window : KryptonForm
{
public Main2Window()
{
InitializeComponent();
}
public static JObject homejson_Object;
JObject repojson = Functions.apiFunctions.getGames();
public static ImageList sliderImages;
static int slider_step = 0;
private Point CenterOfMenuPanel<T>(T control, int height = 0) where T : Control
{
Point center = new Point(
kryptonPanel1.Size.Width / 2 - kryptonPanel1.Width * 2,
height);
return center;
}
private void LoadLang()
{
//Load Tab Buttons
HomeTabButton.Text = Functions.UIFunctions.getLangString("HomeTabButton");
GamesTabButton.Text = Functions.UIFunctions.getLangString("GamesTabButton");
SettingsTabButton.Text = Functions.UIFunctions.getLangString("SettingsTabButton");
InfoTabButton.Text = Functions.UIFunctions.getLangString("InfoTabButton");
//Apply LangList to ComboBox
foreach (FileInfo file in Session.langList)
{
langCBox.Items.Add(file.Name.Replace(".json", ""));
}
langCBox.SelectedItem = UserPreferences.LANG_CODE;
}
private void LoadGamesList()
{
kryptonListBox1.Items.Clear();
foreach (var item in repojson["games"])
{
kryptonListBox1.Items.Add(item["name"].ToString());
}
}
private void setTab(TabPage selectedTab)
{
materialTabControl1.SelectedTab = selectedTab;
//Update Tab Btn backcolor
if (materialTabControl1.SelectedTab == HomePage)
HomeTabButton.BackColor = Color.FromArgb(25, 25, 25);
else
HomeTabButton.BackColor = Color.Transparent;
if (materialTabControl1.SelectedTab == GamesPage)
GamesTabButton.BackColor = Color.FromArgb(25, 25, 25);
else
GamesTabButton.BackColor = Color.Transparent;
if (materialTabControl1.SelectedTab == SettingsPage)
SettingsTabButton.BackColor = Color.FromArgb(25, 25, 25);
else
SettingsTabButton.BackColor = Color.Transparent;
if (materialTabControl1.SelectedTab == InfoPage)
InfoTabButton.BackColor = Color.FromArgb(25, 25, 25);
else
InfoTabButton.BackColor = Color.Transparent;
}
private void ShowGameDetails(int app_id)
{
}
private void LoadGameMod(int index)
{
if (index == -1)
return;
//Functions.Console.log("Loading Game: " + repojson["games"][index]["name"].ToString(), this.consoleOutput);
// Functions.Console.log(repojson["games"][index].ToString(), this.consoleOutput);
// Functions.Console.log("========================================================", this.consoleOutput);
gameloadDialog gameDialog = new gameloadDialog();
gameDialog.gameName = repojson["games"][index]["name"].ToString();
gameDialog.picture_url = repojson["games"][index]["picture_url"].ToString();
gameDialog.app_id = int.Parse(repojson["games"][index]["app_id"].ToString());
gameDialog.isSteamGame = bool.Parse(repojson["games"][index]["isSteamGame"].ToString());
gameDialog.StartPosition = FormStartPosition.Manual;
gameDialog.Location = new Point(this.Location.X + this.Width / 2, this.Location.Y + this.Height / 2);
gameDialog.ShowDialog();
}
public void setgameWindow(int index)
{
if (index == -1)
return;
label3.Text = repojson["games"][index]["name"].ToString();
WebClient client = new WebClient();
Stream stream_data = new MemoryStream(client.DownloadData(repojson["games"][index]["picture_url"].ToString()));
pictureBox1.Image = Image.FromStream(stream_data);
//label3.Location = CenterOfMenuPanel(label3, 10);
kryptonPanel1.Visible = true;
}
private void Main2Window_Load(object sender, EventArgs e)
{
LoadLang();
//Set window title
this.Text = "DualSense AT v" + Application.ProductVersion;
materialTabControl1.Update();
//Set Start Tab
setTab(HomePage);
//Load Home Json
homeJson.RunWorkerAsync();
//Load Game List
LoadGamesList();
//Init Timers
everyTicker.Enabled = true;
}
private void StatusLedController()
{
if (!Functions.UIFunctions.isDSXRunning())
{
StatusLED.BackColor = Color.Red;
StatusLbl.Text = "DSX is closed!";
return;
}
if (!Functions.NetworkServices.CheckAvailableServerPort(6969))
{
StatusLED.BackColor = Color.Red;
StatusLbl.Text = "UDP Server offline!";
return;
}
StatusLED.BackColor = Color.Lime;
StatusLbl.Text = "Ready!";
}
private void everyTicker_Tick(object sender, EventArgs e)
{
StatusLedController();
}
private void HomeTabButton_Click(object sender, EventArgs e)
{
setTab(HomePage);
}
private void GamesTabButton_Click(object sender, EventArgs e)
{
setTab(GamesPage);
}
private void SettingsTabButton_Click(object sender, EventArgs e)
{
setTab(SettingsPage);
}
private void InfoTabButton_Click(object sender, EventArgs e)
{
setTab(InfoPage);
}
private void materialTabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void homeJson_DoWork(object sender, DoWorkEventArgs e)
{
homejson_Object = JObject.Parse(File.ReadAllText(Constants.BASE_TEMP_PATH + "home.json"));
if (!Directory.Exists(Constants.BASE_TEMP_PATH + "sliders"))
{
Directory.CreateDirectory(Constants.BASE_TEMP_PATH + "sliders");
}
foreach (var featured in homejson_Object["featured"])
{
using (WebClient client = new WebClient()) {
client.DownloadFile(featured["picture_url"].ToString(), Constants.BASE_TEMP_PATH + "sliders/"+featured["app_id"] + ".jpg");
Console.Write(featured["picture_url"].ToString());
}
}
e.Result = homejson_Object;
}
private void homeJson_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
sliderTrade.Interval = Constants.HomeFeaturedSlider_Intervalms;
sliderTrade.Enabled = true;
featuredPicBox.Image = Image.FromFile(Constants.BASE_TEMP_PATH + "sliders/" + homejson_Object["featured"][slider_step]["app_id"].ToString() + ".jpg");
}
private void sliderTrade_Tick(object sender, EventArgs e)
{
featuredPicBox.Image = Image.FromFile(Constants.BASE_TEMP_PATH + "sliders/" + homejson_Object["featured"][slider_step]["app_id"].ToString() + ".jpg");
if (slider_step == (homejson_Object["featured"].Count() -1))
{
slider_step = 0;
return;
}
else
{
slider_step++;
}
}
private void featuredPicBox_Click(object sender, EventArgs e)
{
//setgameWindow(kryptonListBox1);
}
private void Main2Window_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void kryptonListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
setgameWindow(kryptonListBox1.SelectedIndex);
}
private void atButton3_Click(object sender, EventArgs e)
{
LoadGameMod(kryptonListBox1.SelectedIndex);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void langCBox_SelectedIndexChanged(object sender, EventArgs e)
{
Functions.UIFunctions.setDefaultLang(langCBox.SelectedItem.ToString());
}
}
}