aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms/Applications')
-rw-r--r--ShiftOS.WinForms/Applications/FormatEditor.cs3
-rw-r--r--ShiftOS.WinForms/Applications/Shiftnet.Designer.cs30
-rw-r--r--ShiftOS.WinForms/Applications/Shiftnet.cs301
-rw-r--r--ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs2
4 files changed, 118 insertions, 218 deletions
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<CommandFormat> parts = new List<CommandFormat>();
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 = $@"<html>
- <head>
- <style>
- body {{
- background-color: rgb({LoadedSkin.ControlColor.R}, {LoadedSkin.ControlColor.G}, {LoadedSkin.ControlColor.B});
- color: rgb({LoadedSkin.ControlTextColor.R}, {LoadedSkin.ControlTextColor.G}, {LoadedSkin.ControlTextColor.B});
- font-family: ""{LoadedSkin.MainFont.Name}"";
- font-size: {LoadedSkin.MainFont.SizeInPoints}pt;
- }}
-
- h1 {{
- font-family: ""{LoadedSkin.HeaderFont.Name}"";
- font-size: {LoadedSkin.HeaderFont.SizeInPoints}pt;
- }}
-
- h2 {{
- font-family: ""{LoadedSkin.Header2Font.Name}"";
- font-size: {LoadedSkin.Header2Font.SizeInPoints}pt;
- }}
-
- h3 {{
- font-family: ""{LoadedSkin.Header3Font.Name}"";
- font-size: {LoadedSkin.Header3Font.SizeInPoints}pt;
- }}
-
- pre, code {{
- font-family: ""{LoadedSkin.TerminalFont.Name}"";
- font-size: {LoadedSkin.TerminalFont.SizeInPoints}pt;
- color: rgb({TerminalForeColor.R}, {TerminalForeColor.G}, {TerminalForeColor.B});
- background-color: rgb({TerminalBackColor.R}, {TerminalBackColor.G}, {TerminalBackColor.B});
- }}
- </style>
- </head>
- <body>
- <markdown/>
- </body>
-</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("<markdown/>", 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<bool>((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<string> History = new Stack<string>();
public Stack<string> Future = new Stack<string>();
- 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<byte[]>(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<string>((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<string, int> UpgradesToBuy = new Dictionary<string, int>();
+ Dictionary<string, long> UpgradesToBuy = new Dictionary<string, long>();
foreach (var itm in lbupgrades.SelectedItems)
{
cpCost += upgrades[itm.ToString()].Cost;