From e833a9bf2751f16d8614af9aa20f5b9bec3d81a8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Apr 2017 14:53:10 -0400 Subject: [PATCH] FUCKTONS OF SHIFTORIUM WORK --- ShiftOS.WinForms/Applications/FormatEditor.cs | 3 +- .../Applications/Shiftnet.Designer.cs | 30 +- ShiftOS.WinForms/Applications/Shiftnet.cs | 301 ++++++------------ .../Applications/ShiftoriumFrontend.cs | 2 +- ShiftOS.WinForms/Program.cs | 33 +- ShiftOS.WinForms/Resources/Shiftorium.txt | 7 - ShiftOS.WinForms/ShiftOS.WinForms.csproj | 18 ++ .../ShiftnetSites/AppscapeMain.Designer.cs | 113 +++++++ .../ShiftnetSites/AppscapeMain.cs | 208 ++++++++++++ .../ShiftnetSites/AppscapeMain.resx | 120 +++++++ .../ShiftnetSites/MainHomepage.Designer.cs | 153 +++++++++ .../ShiftnetSites/MainHomepage.cs | 89 ++++++ .../ShiftnetSites/MainHomepage.resx | 128 ++++++++ ShiftOS.WinForms/WindowBorder.cs | 15 +- ShiftOS_TheReturn/Command.cs | 2 +- ShiftOS_TheReturn/Commands.cs | 2 +- ShiftOS_TheReturn/SaveSystem.cs | 2 +- ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + ShiftOS_TheReturn/ShiftnetSite.cs | 46 +++ ShiftOS_TheReturn/Shiftorium.cs | 6 +- 20 files changed, 1040 insertions(+), 239 deletions(-) create mode 100644 ShiftOS.WinForms/ShiftnetSites/AppscapeMain.Designer.cs create mode 100644 ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs create mode 100644 ShiftOS.WinForms/ShiftnetSites/AppscapeMain.resx create mode 100644 ShiftOS.WinForms/ShiftnetSites/MainHomepage.Designer.cs create mode 100644 ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs create mode 100644 ShiftOS.WinForms/ShiftnetSites/MainHomepage.resx create mode 100644 ShiftOS_TheReturn/ShiftnetSite.cs diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs index 7491e36..db52d85 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -36,11 +36,10 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [MultiplayerOnly] [Launcher("Format Editor", true, "al_format_editor", "Customization")] - [RequiresUpgrade("format_editor")] + [AppscapeEntry("Format Editor", "Edit the syntax of your Terminal to be however you like.", 750, "file_skimmer", "Customization")] [WinOpen("formateditor")] [DefaultTitle("Format Editor")] [DefaultIcon("iconFormatEditor")] - public partial class FormatEditor : UserControl, IShiftOSWindow { IList parts = new List(); diff --git a/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs b/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs index eca44ae..a7fe700 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs @@ -57,13 +57,12 @@ namespace ShiftOS.WinForms.Applications this.btnforward = new System.Windows.Forms.Button(); this.txturl = new System.Windows.Forms.TextBox(); this.btngo = new System.Windows.Forms.Button(); - this.wbcanvas = new System.Windows.Forms.WebBrowser(); + this.pnlcanvas = new System.Windows.Forms.Panel(); this.flcontrols.SuspendLayout(); this.SuspendLayout(); // // flcontrols // - this.flcontrols.AutoSize = true; this.flcontrols.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.flcontrols.Controls.Add(this.btnback); this.flcontrols.Controls.Add(this.btnforward); @@ -123,42 +122,35 @@ namespace ShiftOS.WinForms.Applications this.btngo.UseVisualStyleBackColor = true; this.btngo.Click += new System.EventHandler(this.btngo_Click); // - // wbcanvas + // pnlcanvas // - this.wbcanvas.Dock = System.Windows.Forms.DockStyle.Fill; - this.wbcanvas.IsWebBrowserContextMenuEnabled = false; - this.wbcanvas.Location = new System.Drawing.Point(0, 29); - this.wbcanvas.MinimumSize = new System.Drawing.Size(20, 20); - this.wbcanvas.Name = "wbcanvas"; - this.wbcanvas.ScriptErrorsSuppressed = true; - this.wbcanvas.Size = new System.Drawing.Size(805, 510); - this.wbcanvas.TabIndex = 1; - this.wbcanvas.WebBrowserShortcutsEnabled = false; - this.wbcanvas.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.wbcanvas_Navigated); - this.wbcanvas.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(this.wbcanvas_Navigating); + this.pnlcanvas.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pnlcanvas.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlcanvas.Location = new System.Drawing.Point(0, 29); + this.pnlcanvas.Name = "pnlcanvas"; + this.pnlcanvas.Size = new System.Drawing.Size(805, 510); + this.pnlcanvas.TabIndex = 1; // // Shiftnet // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.wbcanvas); + this.Controls.Add(this.pnlcanvas); this.Controls.Add(this.flcontrols); this.Name = "Shiftnet"; this.Size = new System.Drawing.Size(805, 539); this.flcontrols.ResumeLayout(false); this.flcontrols.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - - private System.Windows.Forms.FlowLayoutPanel flcontrols; private System.Windows.Forms.Button btnback; private System.Windows.Forms.Button btnforward; private System.Windows.Forms.TextBox txturl; private System.Windows.Forms.Button btngo; - private System.Windows.Forms.WebBrowser wbcanvas; + private System.Windows.Forms.Panel pnlcanvas; + private System.Windows.Forms.FlowLayoutPanel flcontrols; } } diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs index 54a8aa6..7f5d3c1 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -35,6 +35,8 @@ using ShiftOS.Engine; using Newtonsoft.Json; using static ShiftOS.Engine.SkinEngine; using ShiftOS.WinForms.Tools; +using System.IO; +using System.Reflection; namespace ShiftOS.WinForms.Applications { @@ -50,216 +52,34 @@ namespace ShiftOS.WinForms.Applications [WinOpen("shiftnet")] [RequiresUpgrade("victortran_shiftnet")] [DefaultIcon("iconShiftnet")] - public partial class Shiftnet : UserControl, IShiftOSWindow + public partial class Shiftnet : UserControl, IShiftOSWindow, IShiftnetClient { public Shiftnet() { InitializeComponent(); - ServerManager.MessageReceived += (msg) => - { - try - { - if (msg.Name == "shiftnet_file") - { - if (Objects.ShiftFS.Utils.FileExists("0:/md.txt")) - { - this.Invoke(new Action(() => - { - wbcanvas.DocumentText = ConstructHtml(Objects.ShiftFS.Utils.ReadAllText("0:/md.txt")); - })); - } - else - { - this.Invoke(new Action(() => - { - wbcanvas.DocumentText = ConstructHtml(msg.Contents); - })); - } - } - } - catch - { - - } - }; - } - - public string ConstructHtml(string markdown) - { - var TerminalForeColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalForeColorCC); - var TerminalBackColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalBackColorCC); - string html = $@" - - - - - - -"; - - string body = CommonMark.CommonMarkConverter.Convert(markdown); - for (int i = 0; i <= Encoding.UTF8.GetBytes(body).Length; i += DownloadManager.GetDownloadSpeed()) - { - //halt the page load until 'download' finishes. - } - html = html.Replace("", body); - return html; } public string CurrentUrl { get; set; } - private void wbcanvas_Navigating(object sender, WebBrowserNavigatingEventArgs e) - { - string Url = e.Url.ToString().Replace("http://", ""); - if (CurrentUrl != Url.ToString() && !Url.ToString().StartsWith("about:")) - { - e.Cancel = true; - Future.Clear(); - if (Url.StartsWith("runsyscmd/")) - { - ProcessShiftnetCmd(Url.Replace("runsyscmd/", "")); - } - - ShiftnetNavigate(Url.ToString()); - } - } - - public void ProcessShiftnetCmd(string cmd) - { - var args = cmd.Split('/'); - switch (args[0]) - { - case "setsnsub": - for (int i = 0; i < DownloadManager.GetAllSubscriptions().Length; i++) - { - if (DownloadManager.GetAllSubscriptions()[i].Name == args[1]) - { - var sub = DownloadManager.GetAllSubscriptions()[i]; - Infobox.PromptYesNo("Shiftnet", $"Are you sure you want to switch your system's Shiftnet subscription to {sub.Name} by {sub.Company}?{Environment.NewLine}{Environment.NewLine}Cost per month: {sub.CostPerMonth} CP{Environment.NewLine}Download speed: {sub.DownloadSpeed} bytes per second", new Action((answer) => - { - if (answer == true) - { - if (SaveSystem.CurrentSave.Codepoints >= sub.CostPerMonth) - { - //Initial fee gets deducted. - SaveSystem.CurrentSave.Codepoints -= sub.CostPerMonth; - //Then we set the subscription. - SaveSystem.CurrentSave.ShiftnetSubscription = i; - //Then we say that we have paid this month. - SaveSystem.CurrentSave.LastMonthPaid = DateTime.Now.Month; - //Then we send our save to the MUD. - SaveSystem.SaveGame(); - - } - else - { - //User can't afford this subscription. - Infobox.Show("Shiftnet - Not enough Codepoints", $"You cannot afford to pay for this subscription at this time. You need {sub.CostPerMonth - SaveSystem.CurrentSave.Codepoints} more Codepoints."); - } - } - })); - } - } - return; - } - } - public Stack History = new Stack(); public Stack Future = new Stack(); - public void ShiftnetNavigate(string Url, bool pushHistory = true) - { - if (Url.EndsWith(".rnp") || !Url.Contains(".")) - { - if (!string.IsNullOrEmpty(CurrentUrl) && pushHistory) - History.Push(CurrentUrl); - CurrentUrl = Url; - ServerManager.SendMessage("shiftnet_get", JsonConvert.SerializeObject(new - { - url = Url - })); - txturl.Text = Url; - - } - else - { - ServerMessageReceived smr = null; - smr = (msg) => - { - if (msg.Name == "download_meta") - { - var bytes = JsonConvert.DeserializeObject(msg.Contents); - string destPath = null; - string ext = Url.Split('.')[Url.Split('.').Length - 1]; - this.Invoke(new Action(() => - { - FileSkimmerBackend.GetFile(new[] { ext }, FileOpenerStyle.Save, new Action((file) => - { - destPath = file; - })); - })); - while (string.IsNullOrEmpty(destPath)) - { - - } - var d = new Download - { - ShiftnetUrl = Url, - Destination = destPath, - Bytes = bytes, - Progress = 0, - }; - DownloadManager.StartDownload(d); - this.Invoke(new Action(() => - { - AppearanceManager.SetupWindow(new Downloader()); - })); - ServerManager.MessageReceived -= smr; - } - }; - ServerManager.MessageReceived += smr; - ServerManager.SendMessage("download_start", Url); - } - } + public IShiftnetSite CurrentPage = null; public void OnLoad() { - ShiftnetNavigate("shiftnet/main"); + NavigateToUrl("shiftnet/main"); } public void OnSkinLoad() { - ShiftnetNavigate(CurrentUrl); + CurrentPage?.OnSkinLoad(); + btnback.Location = new Point(2, 2); + btnforward.Location = new Point(btnback.Left + btnback.Width + 2, 2); + txturl.Location = new Point(btnforward.Left + btnforward.Width + 2, 2); + txturl.Width = flcontrols.Width - btnback.Width - 2 - btnforward.Width - 2 - (btngo.Width*2) - 2; + btngo.Location = new Point(flcontrols.Width - btngo.Width - 2, 2); } public bool OnUnload() @@ -269,6 +89,7 @@ namespace ShiftOS.WinForms.Applications public void OnUpgrade() { + CurrentPage?.OnUpgrade(); } private void btnback_Click(object sender, EventArgs e) @@ -279,7 +100,7 @@ namespace ShiftOS.WinForms.Applications if (!string.IsNullOrEmpty(hist)) { Future.Push(hist); - ShiftnetNavigate(hist, false); + NavigateToUrl(hist); } } catch @@ -295,7 +116,8 @@ namespace ShiftOS.WinForms.Applications string fut = Future.Pop(); if (!string.IsNullOrEmpty(fut)) { - ShiftnetNavigate(fut); + History.Push(CurrentUrl); + NavigateToUrl(fut); } } catch @@ -309,8 +131,8 @@ namespace ShiftOS.WinForms.Applications if (!string.IsNullOrWhiteSpace(txturl.Text)) { Future.Clear(); - - ShiftnetNavigate(txturl.Text); + History.Push(CurrentUrl); + NavigateToUrl(txturl.Text); } } @@ -323,8 +145,95 @@ namespace ShiftOS.WinForms.Applications } } - private void wbcanvas_Navigated(object sender, WebBrowserNavigatedEventArgs e) + public void NavigateToUrl(string url) { + txturl.Text = url; + 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()) + { + if (type.GetInterfaces().Contains(typeof(IShiftnetSite))) + { + if (type.BaseType == typeof(UserControl)) + { + var attribute = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetSiteAttribute) as ShiftnetSiteAttribute; + if (attribute != null) + { + if (attribute.Url == url) + { + if (Shiftorium.UpgradeAttributesUnlocked(type)) + { + var obj = (IShiftnetSite)Activator.CreateInstance(type, null); + obj.GoToUrl += (u) => + { + History.Push(u); + NavigateToUrl(u); + }; + obj.GoBack += () => + { + string u = History.Pop(); + Future.Push(u); + NavigateToUrl(u); + }; + CurrentPage = obj; + this.pnlcanvas.Controls.Clear(); + this.pnlcanvas.Controls.Add((UserControl)obj); + ((UserControl)obj).Show(); + ((UserControl)obj).Dock = DockStyle.Fill; + obj.OnUpgrade(); + obj.OnSkinLoad(); + obj.Setup(); + return; + } + } + } + } + } + } + } + catch (Exception ex) + { + pnlcanvas.Controls.Clear(); + var tlbl = new Label(); + tlbl.Text = "Server error in \"" + url + "\" application."; + tlbl.Tag = "header1"; + tlbl.AutoSize = true; + tlbl.Location = new Point(10, 10); + tlbl.Dock = DockStyle.Top; + pnlcanvas.Controls.Add(tlbl); + tlbl.Show(); + + var crash = new Label(); + crash.Dock = DockStyle.Fill; + crash.AutoSize = false; + crash.Text = ex.ToString(); + pnlcanvas.Controls.Add(crash); + crash.Show(); + crash.BringToFront(); + ControlManager.SetupControls(pnlcanvas); + return; + } + } + } + pnlcanvas.Controls.Clear(); + var lbl = new Label(); + lbl.Text = "Page not found!"; + lbl.Tag = "header1"; + lbl.AutoSize = true; + lbl.Location = new Point(10, 10); + pnlcanvas.Controls.Add(lbl); + lbl.Show(); + + } + + public void RefreshSite() + { + NavigateToUrl(CurrentUrl); } } } diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index 0762897..66b0448 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -185,7 +185,7 @@ namespace ShiftOS.WinForms.Applications { long cpCost = 0; backend.Silent = true; - Dictionary UpgradesToBuy = new Dictionary(); + Dictionary UpgradesToBuy = new Dictionary(); foreach (var itm in lbupgrades.SelectedItems) { cpCost += upgrades[itm.ToString()].Cost; diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 36c9338..3343cb0 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -34,6 +34,7 @@ using static ShiftOS.Objects.ShiftFS.Utils; using ShiftOS.WinForms.Applications; using ShiftOS.WinForms.Tools; using System.Reflection; +using System.IO; namespace ShiftOS.WinForms { @@ -98,7 +99,37 @@ namespace ShiftOS.WinForms { public List GetDefaults() { - return JsonConvert.DeserializeObject>(Properties.Resources.Shiftorium); + var defaultList = JsonConvert.DeserializeObject>(Properties.Resources.Shiftorium); + + 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) + { + var upgrade = new ShiftoriumUpgrade + { + Id = attrib.Name.ToLower().Replace(" ", "_"), + Name = attrib.Name, + Description = attrib.Description, + Cost = attrib.Cost, + Category = attrib.Category, + Dependencies = (string.IsNullOrWhiteSpace(attrib.DependencyString)) ? "appscape_handled_nodisplay" : "appscape_handled_nodisplay;" + attrib.DependencyString + }; + defaultList.Add(upgrade); + } + } + } + catch { } + } + } + return defaultList; } } diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index ca555d4..e68277c 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -368,13 +368,6 @@ Category: "GUI", Dependencies:"desktop;wm_unlimited_windows" }, - { - Name: "Format Editor", - Cost: 6000, - Description: "Allows you to change the format of commands.", - Category: "Applications", - Dependencies: "shifter;name_changer" - }, { Name: "Format Editor Optional Text", Cost: 150, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index bd8fd65..3edfd38 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -317,6 +317,18 @@ Resources.resx + + UserControl + + + AppscapeMain.cs + + + UserControl + + + MainHomepage.cs + @@ -463,6 +475,12 @@ Designer Resources.Designer.cs + + AppscapeMain.cs + + + MainHomepage.cs + WindowBorder.cs diff --git a/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.Designer.cs b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.Designer.cs new file mode 100644 index 0000000..6698e5a --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.Designer.cs @@ -0,0 +1,113 @@ +namespace ShiftOS.WinForms.ShiftnetSites +{ + partial class AppscapeMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.flcategories = new System.Windows.Forms.FlowLayoutPanel(); + this.pnlappslist = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.lbtitle = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(17, 17); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(55, 13); + this.label1.TabIndex = 0; + this.label1.Tag = "header1"; + this.label1.Text = "Appscape"; + // + // flcategories + // + this.flcategories.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.flcategories.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flcategories.Location = new System.Drawing.Point(20, 120); + this.flcategories.Margin = new System.Windows.Forms.Padding(0); + this.flcategories.Name = "flcategories"; + this.flcategories.Size = new System.Drawing.Size(187, 310); + this.flcategories.TabIndex = 1; + // + // pnlappslist + // + this.pnlappslist.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pnlappslist.Location = new System.Drawing.Point(221, 120); + this.pnlappslist.Name = "pnlappslist"; + this.pnlappslist.Size = new System.Drawing.Size(459, 310); + this.pnlappslist.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(20, 76); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(57, 13); + this.label2.TabIndex = 3; + this.label2.Tag = "header2"; + this.label2.Text = "Categories"; + // + // lbtitle + // + this.lbtitle.AutoSize = true; + this.lbtitle.Location = new System.Drawing.Point(218, 76); + this.lbtitle.Name = "lbtitle"; + this.lbtitle.Size = new System.Drawing.Size(57, 13); + this.lbtitle.TabIndex = 4; + this.lbtitle.Tag = "header2"; + this.lbtitle.Text = "Categories"; + // + // AppscapeMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lbtitle); + this.Controls.Add(this.label2); + this.Controls.Add(this.pnlappslist); + this.Controls.Add(this.flcategories); + this.Controls.Add(this.label1); + this.Name = "AppscapeMain"; + this.Size = new System.Drawing.Size(709, 457); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.FlowLayoutPanel flcategories; + private System.Windows.Forms.Panel pnlappslist; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label lbtitle; + } +} diff --git a/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs new file mode 100644 index 0000000..88db07b --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs @@ -0,0 +1,208 @@ +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; + +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 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.Contains("appscape_")); + List cats = new List(); + cats.Add("All"); + try + { + if (upgrades.Count() > 0) + foreach (var upg in upgrades) + { + if (!cats.Contains(upg.Category)) + cats.Add(upg.Category); + } + } + catch { } + return cats.ToArray(); + } + + public ShiftoriumUpgrade CurrentUpgrade = null; + + public void SetupCategory(string cat) + { + pnlappslist.Controls.Clear(); + pnlappslist.Show(); + pnlappslist.BringToFront(); + Category = cat; + var upgrades = GetAllInCategory(); + lbtitle.Text = 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.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 = "Out of stock."; + } + 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 != "Out of stock.") + { + 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 void ViewMoreInfo(ShiftoriumUpgrade upg) + { + + } + + 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 => x.Category == 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 - 2; + flcategories.Controls.Add(btn); + btn.Show(); + } + SetupCategory("All"); + } + } +} + +namespace ShiftOS.WinForms +{ + /// + /// Special version of for specifying Appscape applications as Shiftorium upgrades. + /// + 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) + { + Name = name; + Description = description; + Category = category; + Cost = cost; + DependencyString = dependencies; + } + + public string Name { get; private set; } + public string Description { get; private set; } + public string Category { get; private set; } + public long Cost { get; private set; } + public string DependencyString { get; private set; } + } +} \ No newline at end of file diff --git a/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.resx b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/ShiftnetSites/MainHomepage.Designer.cs b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.Designer.cs new file mode 100644 index 0000000..bebc8bd --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.Designer.cs @@ -0,0 +1,153 @@ +namespace ShiftOS.WinForms.ShiftnetSites +{ + partial class MainHomepage + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainHomepage)); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.lbspecheader = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.panel2 = new System.Windows.Forms.Panel(); + this.label4 = new System.Windows.Forms.Label(); + this.flfundamentals = new System.Windows.Forms.FlowLayoutPanel(); + this.panel1.SuspendLayout(); + this.panel2.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Dock = System.Windows.Forms.DockStyle.Top; + this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(710, 65); + this.label1.TabIndex = 0; + this.label1.Tag = "header1"; + this.label1.Text = "Welcome to the Shiftnet!"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label2 + // + this.label2.Dock = System.Windows.Forms.DockStyle.Top; + this.label2.Location = new System.Drawing.Point(0, 65); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(710, 22); + this.label2.TabIndex = 1; + this.label2.Text = "The Shiftnet is a vast network of services, websites, software and so much more f" + + "or ShiftOS. Have a look around!"; + this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.Controls.Add(this.label3); + this.panel1.Controls.Add(this.lbspecheader); + this.panel1.Location = new System.Drawing.Point(27, 140); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(389, 281); + this.panel1.TabIndex = 2; + // + // lbspecheader + // + this.lbspecheader.Dock = System.Windows.Forms.DockStyle.Top; + this.lbspecheader.Location = new System.Drawing.Point(0, 0); + this.lbspecheader.Name = "lbspecheader"; + this.lbspecheader.Size = new System.Drawing.Size(389, 42); + this.lbspecheader.TabIndex = 0; + this.lbspecheader.Tag = "header3"; + this.lbspecheader.Text = "How to use the Shiftnet"; + // + // label3 + // + this.label3.Dock = System.Windows.Forms.DockStyle.Fill; + this.label3.Location = new System.Drawing.Point(0, 42); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(389, 239); + this.label3.TabIndex = 1; + this.label3.Text = resources.GetString("label3.Text"); + // + // panel2 + // + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel2.Controls.Add(this.flfundamentals); + this.panel2.Controls.Add(this.label4); + this.panel2.Location = new System.Drawing.Point(439, 140); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(247, 281); + this.panel2.TabIndex = 3; + // + // label4 + // + this.label4.Dock = System.Windows.Forms.DockStyle.Top; + this.label4.Location = new System.Drawing.Point(0, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(247, 42); + this.label4.TabIndex = 1; + this.label4.Tag = "header3"; + this.label4.Text = "The Fundamentals"; + // + // flfundamentals + // + this.flfundamentals.Dock = System.Windows.Forms.DockStyle.Fill; + this.flfundamentals.Location = new System.Drawing.Point(0, 42); + this.flfundamentals.Name = "flfundamentals"; + this.flfundamentals.Size = new System.Drawing.Size(247, 239); + this.flfundamentals.TabIndex = 2; + // + // MainHomepage + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "MainHomepage"; + this.Size = new System.Drawing.Size(710, 437); + this.panel1.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label lbspecheader; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.FlowLayoutPanel flfundamentals; + private System.Windows.Forms.Label label4; + } +} diff --git a/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs new file mode 100644 index 0000000..cb39cd6 --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs @@ -0,0 +1,89 @@ +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.Reflection; +using System.IO; + +namespace ShiftOS.WinForms.ShiftnetSites +{ + [ShiftnetSite("shiftnet/main", "Main Site", "The main Shiftnet hub.")] + public partial class MainHomepage : UserControl, IShiftnetSite + { + public MainHomepage() + { + InitializeComponent(); + } + + public event Action GoBack; + public event Action GoToUrl; + + public void OnSkinLoad() + { + ControlManager.SetupControls(this); + } + + public void OnUpgrade() + { + + } + + public void Setup() + { + //Get the Fundamentals List + flfundamentals.Controls.Clear(); + 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()) + { + if (type.GetInterfaces().Contains(typeof(IShiftnetSite))) + { + if (type.BaseType == typeof(UserControl)) + { + var attribute = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetSiteAttribute) as ShiftnetSiteAttribute; + if (attribute != null) + { + if (Shiftorium.UpgradeAttributesUnlocked(type)) + { + if (type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetFundamentalAttribute) != null) + { + var dash = new Label(); + dash.Text = " - "; + dash.AutoSize = true; + flfundamentals.Controls.Add(dash); + dash.Show(); + var link = new LinkLabel(); + link.Text = attribute.Name; + link.Click += (o, a) => + { + GoToUrl?.Invoke(attribute.Url); + }; + flfundamentals.Controls.Add(link); + flfundamentals.SetFlowBreak(link, true); + link.Show(); + } + } + } + } + } + } + } + catch { } + } + } + + } + } +} diff --git a/ShiftOS.WinForms/ShiftnetSites/MainHomepage.resx b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.resx new file mode 100644 index 0000000..e9a0c8f --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.resx @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The Shiftnet works a lot like a regular web browser. To browse to a website, you can either click links or you can type a Shiftnet URL into your Address Bar at the top and click "Go". + +An example of a Shiftnet URL would be "shiftnet/main", which you are at right now. This is the main Shiftnet hub. You can also browse to files and folder listings, if you have access to them. + + +There are lots of Shiftnet websites for you to visit - so go ahead and explore, but first, check out some of the fundamental sites and services to the right! + + \ No newline at end of file diff --git a/ShiftOS.WinForms/WindowBorder.cs b/ShiftOS.WinForms/WindowBorder.cs index 64f2da4..2829a3e 100644 --- a/ShiftOS.WinForms/WindowBorder.cs +++ b/ShiftOS.WinForms/WindowBorder.cs @@ -134,18 +134,16 @@ namespace ShiftOS.WinForms } }; - this.Width = LoadedSkin.LeftBorderWidth + _parentWindow.Width + LoadedSkin.RightBorderWidth; - this.Height = LoadedSkin.TitlebarHeight + _parentWindow.Height + LoadedSkin.BottomBorderWidth; - - SetupControls(this); - + + this.pnlcontents.Controls.Add(this._parentWindow); this._parentWindow.Dock = DockStyle.Fill; this._parentWindow.Show(); + SetupControls(this); + this.Width = LoadedSkin.LeftBorderWidth + this.Width + LoadedSkin.RightBorderWidth; + this.Height = LoadedSkin.TitlebarHeight + this.Height + LoadedSkin.BottomBorderWidth; ControlManager.SetupControls(this._parentWindow); - ParentWindow.OnSkinLoad(); - ParentWindow.OnUpgrade(); Shiftorium.Installed += () => { Setup(); @@ -221,6 +219,9 @@ namespace ShiftOS.WinForms this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; ParentWindow.OnLoad(); + ParentWindow.OnSkinLoad(); + ParentWindow.OnUpgrade(); + } /// diff --git a/ShiftOS_TheReturn/Command.cs b/ShiftOS_TheReturn/Command.cs index c6d58e1..09cf206 100644 --- a/ShiftOS_TheReturn/Command.cs +++ b/ShiftOS_TheReturn/Command.cs @@ -104,7 +104,7 @@ namespace ShiftOS.Engine /// /// Gets whether the dependent upgrade(s) are installed. /// - public bool Installed + public virtual bool Installed { get { diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 0257f11..ce94030 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -612,7 +612,7 @@ shiftorium.buy{{upgrade:""{upg.ID}""}}"); cat = args["cat"].ToString(); } - Dictionary upgrades = new Dictionary(); + Dictionary upgrades = new Dictionary(); int maxLength = 5; IEnumerable upglist = Shiftorium.GetAvailable(); diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 998c60d..3e68a70 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -223,7 +223,7 @@ namespace ShiftOS.Engine public static event EmptyEventHandler GameReady; - public static void TransferCodepointsToVoid(int amount) + public static void TransferCodepointsToVoid(long amount) { CurrentSave.Codepoints -= amount; NotificationDaemon.AddNotification(NotificationType.CodepointsSent, amount); diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index b6ff903..f7b730f 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -124,6 +124,7 @@ + diff --git a/ShiftOS_TheReturn/ShiftnetSite.cs b/ShiftOS_TheReturn/ShiftnetSite.cs new file mode 100644 index 0000000..5460171 --- /dev/null +++ b/ShiftOS_TheReturn/ShiftnetSite.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine +{ + public interface IShiftnetSite + { + void Setup(); + void OnSkinLoad(); + void OnUpgrade(); + + event Action GoToUrl; + event Action GoBack; + } + + /// + /// Marks a shiftnet site as a fundamental, and will make it display on the homepage. + /// + public class ShiftnetFundamentalAttribute : Attribute + { + + } + + public interface IShiftnetClient + { + void NavigateToUrl(string url); + void RefreshSite(); + } + + public class ShiftnetSiteAttribute : Attribute + { + public ShiftnetSiteAttribute(string url, string name, string description) + { + Url = url; + Name = name; + Description = description; + } + + public string Url { get; private set; } + public string Name { get; private set; } + public string Description { get; private set; } + } +} diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index 43ea13a..c46aed0 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -85,7 +85,7 @@ namespace ShiftOS.Engine return GetDefaults().Where(x => x.Category == cat).FirstOrDefault(x => x.Installed == false) == null; } - public static bool Buy(string id, int cost) + public static bool Buy(string id, long cost) { if(SaveSystem.CurrentSave.Codepoints >= cost) { @@ -188,7 +188,7 @@ namespace ShiftOS.Engine } - public static int GetCPValue(string id) + public static long GetCPValue(string id) { foreach(var upg in GetDefaults()) { @@ -316,7 +316,7 @@ namespace ShiftOS.Engine { public string Name { get; set; } public string Description { get; set; } - public int Cost { get; set; } + public long Cost { get; set; } public string ID { get { return (this.Id != null ? this.Id : (Name.ToLower().Replace(" ", "_"))); } } public string Id { get; set; } public string Category { get; set; }