Finish Appscape.

This commit is contained in:
Michael 2017-04-23 18:22:16 -04:00
parent bc66ccccd7
commit ba157cdedd
2 changed files with 170 additions and 4 deletions

View file

@ -36,7 +36,7 @@ using ShiftOS.Engine;
namespace ShiftOS.WinForms.Applications {
[MultiplayerOnly]
[Launcher("Format Editor", true, "al_format_editor", "Customization")]
[AppscapeEntry("Format Editor", "Edit the syntax of your Terminal to be however you like.", 750, "file_skimmer", "Customization")]
[AppscapeEntry("Format Editor", "Edit the syntax of your Terminal to be however you like.", 740, 750, "file_skimmer", "Customization")]
[WinOpen("formateditor")]
[DefaultTitle("Format Editor")]
[DefaultIcon("iconFormatEditor")]

View file

@ -9,6 +9,9 @@ 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
{
@ -102,7 +105,7 @@ namespace ShiftOS.WinForms.ShiftnetSites
var cp_value = new Label();
if (Shiftorium.UpgradeInstalled(upg.ID))
{
cp_value.Text = "Out of stock.";
cp_value.Text = "Already Purchased.";
}
else
{
@ -115,7 +118,7 @@ namespace ShiftOS.WinForms.ShiftnetSites
cp_value.Show();
if(cp_value.Text != "Out of stock.")
if(cp_value.Text != "Already Purchased.")
{
var more_info = new Button();
more_info.Text = "More info";
@ -147,6 +150,121 @@ namespace ShiftOS.WinForms.ShiftnetSites
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 = "More info";
more_info.Click += (o, a) =>
{
//Detect if dependencies are installed.
if (Shiftorium.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 exe in Directory.GetFiles(Environment.CurrentDirectory))
{
if (exe.EndsWith(".exe") || exe.EndsWith(".dll"))
{
try
{
var asm = Assembly.LoadFile(exe);
foreach (var type in asm.GetTypes())
{
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);
}
}
}
}
catch { }
}
}
}
});
}
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();
}
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.";
}
}
@ -181,6 +299,52 @@ namespace ShiftOS.WinForms.ShiftnetSites
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; }
public string Name { get; private set; }
protected override void Run()
{
this.SetStatus("Downloading...");
SetProgress(0);
new Thread(() =>
{
int i = 0;
while (i <= Size)
{
SetProgress((i / Size) * 100);
i++;
Thread.Sleep(100);
}
SetProgress(0);
SetStatus("Installing...");
i = 0;
while (i <= Size)
{
SetProgress((i / Size) * 100);
i++;
Thread.Sleep(50);
}
Shiftorium.Buy(ShiftoriumId, 0);
Desktop.InvokeOnWorkerThread(() =>
{
Infobox.Show("Install complete!", "The installation of " + Name + " has completed.");
SaveSystem.SaveGame();
});
})
{ IsBackground = true }.Start();
}
}
}
namespace ShiftOS.WinForms
@ -190,13 +354,14 @@ namespace ShiftOS.WinForms
/// </summary>
public class AppscapeEntryAttribute : RequiresUpgradeAttribute
{
public AppscapeEntryAttribute(string name, string description, long cost, string dependencies = "", string category = "Misc") : base((string.IsNullOrWhiteSpace(dependencies)) ? name.ToLower().Replace(" ","_") : name.ToLower().Replace(" ", "_") + dependencies)
public AppscapeEntryAttribute(string name, string description, int downloadSize, long cost, string dependencies = "", string category = "Misc") : base((string.IsNullOrWhiteSpace(dependencies)) ? name.ToLower().Replace(" ", "_") : name.ToLower().Replace(" ", "_") + dependencies)
{
Name = name;
Description = description;
Category = category;
Cost = cost;
DependencyString = dependencies;
DownloadSize = downloadSize;
}
public string Name { get; private set; }
@ -204,5 +369,6 @@ namespace ShiftOS.WinForms
public string Category { get; private set; }
public long Cost { get; private set; }
public string DependencyString { get; private set; }
public int DownloadSize { get; private set; }
}
}