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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
using ShiftOS.WinForms.Tools;
using System.IO;
using System.Reflection;
using System.Threading;
namespace ShiftOS.WinForms.ShiftnetSites
{
[ShiftnetSite("shiftnet/appscape", "Appscape", "Bringing ShiftOS to life")]
[ShiftnetFundamental]
public partial class AppscapeMain : UserControl, IShiftnetSite
{
public AppscapeMain()
{
InitializeComponent();
}
public event Action GoBack;
public event Action<string> GoToUrl;
public void OnSkinLoad()
{
ControlManager.SetupControls(this);
}
public void OnUpgrade()
{
}
public string Category = "All";
public string[] GetCategories()
{
var upgrades = Shiftorium.GetDefaults().Where(x => (x.Dependencies == null) ? false : x.Dependencies.Contains("appscape_"));
List<string> cats = new List<string>();
cats.Add("All");
try
{
if (upgrades.Count() > 0)
foreach (var upg in upgrades)
{
if (!cats.Contains(Localization.Parse(upg.Category)))
cats.Add(Localization.Parse(upg.Category));
}
}
catch { }
return cats.ToArray();
}
public ShiftoriumUpgrade CurrentUpgrade = null;
public void SetupCategory(string cat)
{
pnlappslist.Controls.Clear();
pnlappslist.Show();
pnlappslist.BringToFront();
Category = Localization.Parse(cat);
var upgrades = GetAllInCategory();
lbtitle.Text = Localization.Parse(cat);
if(upgrades.Length == 0)
{
var err = new Label();
err.AutoSize = true;
err.Text = "There are no apps in this list! Come back later for more.";
pnlappslist.Controls.Add(err);
err.Show();
}
else
{
var fl = new FlowLayoutPanel();
fl.Dock = DockStyle.Fill;
pnlappslist.Controls.Add(fl);
fl.AutoScroll = true;
fl.Show();
foreach(var upg in upgrades)
{
var pnl = new Panel();
pnl.Height = 250;
pnl.Width = 200;
fl.Controls.Add(pnl);
pnl.Show();
var upgTitle = new Label();
upgTitle.Text = upg.Name;
upgTitle.Dock = DockStyle.Top;
upgTitle.AutoSize = true;
upgTitle.MaximumSize = new Size(pnl.Width, 0);
upgTitle.Tag = "header3";
pnl.Controls.Add(upgTitle);
upgTitle.Show();
var cp_display = new Panel();
cp_display.Height = 30;
cp_display.Dock = DockStyle.Bottom;
pnl.Controls.Add(cp_display);
cp_display.Show();
var cp_value = new Label();
if (Shiftorium.UpgradeInstalled(upg.ID))
{
cp_value.Text = "Already Purchased.";
}
else
{
cp_value.Text = $"{upg.Cost} CP";
}
cp_value.AutoSize = true;
cp_value.Top = (cp_display.Height - cp_value.Height) / 2;
cp_value.Left = 5;
cp_display.Controls.Add(cp_value);
cp_value.Show();
if(cp_value.Text != "Already Purchased.")
{
var more_info = new Button();
more_info.Text = "More info";
more_info.Click += (o, a) =>
{
ViewMoreInfo(upg);
};
more_info.AutoSize = false;
more_info.AutoSizeMode = AutoSizeMode.GrowAndShrink;
more_info.Top = (cp_display.Height - more_info.Height) / 2;
more_info.Left = cp_display.Width - more_info.Width - 5;
cp_display.Controls.Add(more_info);
more_info.Show();
}
var desc = new Label();
desc.Text = upg.Description;
desc.AutoSize = false;
desc.Dock = DockStyle.Fill;
pnl.Controls.Add(desc);
desc.Show();
desc.BringToFront();
ControlManager.SetupControls(pnl);
}
}
}
public bool DependenciesInstalled(ShiftoriumUpgrade upg)
{
string[] split = upg.Dependencies.Split(';');
foreach(var u in split)
{
if (!u.StartsWith("appscape_handled"))
{
if (!Shiftorium.UpgradeInstalled(u))
return false;
}
}
return true;
}
public void ViewMoreInfo(ShiftoriumUpgrade upg)
{
lbtitle.Text = upg.Name;
pnlappslist.Controls.Clear();
var cp_display = new Panel();
cp_display.Height = 30;
cp_display.Dock = DockStyle.Bottom;
pnlappslist.Controls.Add(cp_display);
cp_display.Show();
var cp_value = new Label();
if (Shiftorium.UpgradeInstalled(upg.ID))
{
cp_value.Text = "Already Purchased.";
}
else
{
cp_value.Text = $"{upg.Cost} CP";
}
cp_value.AutoSize = true;
cp_value.Top = (cp_display.Height - cp_value.Height) / 2;
cp_value.Left = 5;
cp_display.Controls.Add(cp_value);
cp_value.Show();
if (cp_value.Text != "Already Purchased.")
{
var more_info = new Button();
more_info.Text = "Buy";
more_info.Click += (o, a) =>
{
//Detect if dependencies are installed.
if (DependenciesInstalled(upg))
{
//Detect sufficient codepoints
if (SaveSystem.CurrentSave.Codepoints >= upg.Cost)
{
Infobox.PromptYesNo("Confirm Purchase", "Do you want to purchase " + upg.Name + " from Appscape for " + upg.Cost.ToString() + " Codepoints?", (result) =>
{
if (result == true)
{
SaveSystem.CurrentSave.Codepoints -= upg.Cost;
foreach (var type in ReflectMan.Types)
{
var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is AppscapeEntryAttribute) as AppscapeEntryAttribute;
if (attrib != null)
{
if (attrib.Name == upg.Name)
{
var installer = new Applications.Installer();
var installation = new AppscapeInstallation(upg.Name, attrib.DownloadSize, upg.ID);
AppearanceManager.SetupWindow(installer);
installer.InitiateInstall(installation);
return;
}
}
}
}
});
}
else
{
Infobox.Show("Not enough Codepoints", "You do not have enough Codepoints to buy this package.");
}
}
else
{
Infobox.Show("Missing dependencies", "You are missing some Shiftorium upgrades that this package requires. Please upgrade your system and try again!");
}
};
more_info.AutoSize = false;
more_info.AutoSizeMode = AutoSizeMode.GrowAndShrink;
more_info.Top = (cp_display.Height - more_info.Height) / 2;
more_info.Left = cp_display.Width - more_info.Width - 5;
cp_display.Controls.Add(more_info);
more_info.Show();
ControlManager.SetupControls(pnlappslist);
}
var desc = new Label();
desc.Text = upg.Description;
desc.AutoSize = false;
desc.Dock = DockStyle.Fill;
pnlappslist.Controls.Add(desc);
desc.Show();
desc.BringToFront();
desc.Text += Environment.NewLine + Environment.NewLine + "Dependencies:" + Environment.NewLine;
string[] deplist = upg.Dependencies.Split(';');
if(deplist.Length > 1)
{
for(int i = 1; i < deplist.Length; i++)
{
ShiftoriumUpgrade dep = Shiftorium.GetDefaults().FirstOrDefault(x => x.ID == deplist[i]);
if(dep != null)
{
desc.Text += $" - {dep.Name}{Environment.NewLine}";
}
}
}
else
{
desc.Text += " - No dependencies.";
}
}
public ShiftoriumUpgrade[] GetAllInCategory()
{
var upgrades = Shiftorium.GetDefaults().Where(x => (x.Dependencies == null) ? false : x.Dependencies.Contains("appscape_"));
if (upgrades.Count() == 0)
return new ShiftoriumUpgrade[0];
if (Category == "All")
return upgrades.ToArray();
else
return upgrades.Where(x => Localization.Parse(x.Category) == Localization.Parse(Category)).ToArray();
}
public void Setup()
{
flcategories.Controls.Clear();
foreach(var cat in this.GetCategories())
{
var btn = new Button();
btn.Text = cat;
btn.Click += (o, a) =>
{
SetupCategory(cat);
};
ControlManager.SetupControl(btn);
btn.Width = flcategories.Width - 10;
flcategories.Controls.Add(btn);
btn.Show();
}
SetupCategory("All");
}
}
public class AppscapeInstallation : Applications.Installation
{
public AppscapeInstallation(string name, int size, string s_id)
{
Name = name;
ShiftoriumId = s_id;
Size = size;
}
public string ShiftoriumId { get; private set; }
public int Size { get; private set; }
protected override void Run()
{
this.SetStatus("Downloading...");
SetProgress(0);
int i = 0;
while (i <= Size)
{
double progress = ((i / Size) * 100);
SetProgress((int)progress);
i += Applications.DownloadManager.GetDownloadSpeed();
Thread.Sleep(1000);
}
SetProgress(0);
SetStatus("Installing...");
i = 0;
while (i <= Size)
{
double progress = ((i / Size) * 100);
SetProgress((int)progress);
i+=1024;
Thread.Sleep(1000);
}
Desktop.InvokeOnWorkerThread(() =>
{
Shiftorium.Buy(ShiftoriumId, 0);
Infobox.Show("Install complete!", "The installation of " + Name + " has completed.");
SaveSystem.SaveGame();
});
}
}
}
namespace ShiftOS.WinForms
{
/// <summary>
/// Special version of <see cref="RequiresUpgradeAttribute"/> for specifying Appscape applications as Shiftorium upgrades.
/// </summary>
public class AppscapeEntryAttribute : RequiresUpgradeAttribute
{
public AppscapeEntryAttribute(string id, string name, string description, int downloadSize, ulong cost, string dependencies = "", string category = "Misc") : base(id)
{
Name = name;
Description = description;
Category = category;
Cost = cost;
DependencyString = dependencies;
DownloadSize = downloadSize;
}
public string Name { get; private set; }
public string Description { get; private set; }
public string Category { get; private set; }
public ulong Cost { get; private set; }
public string DependencyString { get; private set; }
public int DownloadSize { get; private set; }
}
}
|