From a9b08eb21676a6c59b0c8bb6046b40bd42e078d5 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 18:15:29 -0500 Subject: FULLY COMPLETE TERMINAL COLORS --- ShiftOS.WinForms/Applications/Shifter.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 4d29cf8..1adc75a 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -446,6 +446,30 @@ namespace ShiftOS.WinForms.Applications flbody.Controls.Add(color); color.Show(); } + else if(c.Field.FieldType.IsEnum == true) + { + var cBox = new ComboBox(); + cBox.Width = 150; + ControlManager.SetupControl(cBox); + + foreach(var itm in Enum.GetNames(c.Field.FieldType)) + { + cBox.Items.Add(itm); + } + + cBox.Text = c.Field.GetValue(LoadedSkin).ToString(); + + cBox.SelectedIndexChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text)); + }; + + labelHeight = cBox.Height; + + flbody.Controls.Add(cBox); + cBox.Show(); + flbody.SetFlowBreak(cBox, true); + } else if(c.Field.FieldType == typeof(int)) { if (c.Field.HasShifterEnumMask()) -- cgit v1.2.3 From a9754b7df28795b6bb2c5cfe04c1b38b19fb0d05 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 10 Mar 2017 12:29:28 -0500 Subject: Lock certain apps away when system offline. --- ShiftOS.WinForms/Applications/Artpad.cs | 1 + ShiftOS.WinForms/Applications/Chat.cs | 1 + ShiftOS.WinForms/Applications/Downloader.cs | 1 + ShiftOS.WinForms/Applications/FormatEditor.cs | 1 + ShiftOS.WinForms/Applications/GraphicPicker.cs | 1 + ShiftOS.WinForms/Applications/MUDControlCentre.cs | 1 + ShiftOS.WinForms/Applications/NameChanger.cs | 1 + ShiftOS.WinForms/Applications/Pong.cs | 1 + ShiftOS.WinForms/Applications/ShiftLetters.cs | 1 + ShiftOS.WinForms/Applications/ShiftLotto.cs | 1 + ShiftOS.WinForms/Applications/ShiftSweeper.cs | 1 + ShiftOS.WinForms/Applications/Shifter.cs | 1 + ShiftOS.WinForms/Applications/Shiftnet.cs | 1 + .../Applications/ShiftoriumFrontend.cs | 1 + ShiftOS.WinForms/HackerCommands.cs | 10 ++++++ ShiftOS.WinForms/WinformsWindowManager.cs | 18 ++++++++++ ShiftOS_TheReturn/AppLauncherDaemon.cs | 20 +++++++++--- ShiftOS_TheReturn/KernelWatchdog.cs | 38 +++++++++++++++++++++- ShiftOS_TheReturn/Scripting.cs | 7 ++-- 19 files changed, 100 insertions(+), 7 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Artpad.cs b/ShiftOS.WinForms/Applications/Artpad.cs index 6c1bc1c..71f7afb 100644 --- a/ShiftOS.WinForms/Applications/Artpad.cs +++ b/ShiftOS.WinForms/Applications/Artpad.cs @@ -41,6 +41,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Artpad", true, "al_artpad", "Graphics")] [RequiresUpgrade("artpad")] [WinOpen("artpad")] diff --git a/ShiftOS.WinForms/Applications/Chat.cs b/ShiftOS.WinForms/Applications/Chat.cs index 06a7873..caf8cd2 100644 --- a/ShiftOS.WinForms/Applications/Chat.cs +++ b/ShiftOS.WinForms/Applications/Chat.cs @@ -36,6 +36,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] public partial class Chat : UserControl, IShiftOSWindow { public Chat(string chatId) diff --git a/ShiftOS.WinForms/Applications/Downloader.cs b/ShiftOS.WinForms/Applications/Downloader.cs index da90c6d..1f240bf 100644 --- a/ShiftOS.WinForms/Applications/Downloader.cs +++ b/ShiftOS.WinForms/Applications/Downloader.cs @@ -41,6 +41,7 @@ using System.IO.Compression; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Downloader", false, null, "Networking")] [DefaultIcon("iconDownloader")] public partial class Downloader : UserControl, IShiftOSWindow diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs index ef44b47..56b0253 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -34,6 +34,7 @@ using System.Windows.Forms; using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("FormatEditor", true, "al_format_editor", "Games")] [RequiresUpgrade("format_editor")] [WinOpen("formateditor")] diff --git a/ShiftOS.WinForms/Applications/GraphicPicker.cs b/ShiftOS.WinForms/Applications/GraphicPicker.cs index 2dfe7ec..b3dd8bf 100644 --- a/ShiftOS.WinForms/Applications/GraphicPicker.cs +++ b/ShiftOS.WinForms/Applications/GraphicPicker.cs @@ -37,6 +37,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [DefaultTitle("Choose graphic")] [DefaultIcon("icongraphicpicker")] public partial class GraphicPicker : UserControl, IShiftOSWindow { diff --git a/ShiftOS.WinForms/Applications/MUDControlCentre.cs b/ShiftOS.WinForms/Applications/MUDControlCentre.cs index 02fe868..e2668bd 100644 --- a/ShiftOS.WinForms/Applications/MUDControlCentre.cs +++ b/ShiftOS.WinForms/Applications/MUDControlCentre.cs @@ -38,6 +38,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [RequiresUpgrade("mud_fundamentals")] [Launcher("MUD Control Centre", true, "al_mud_control_centre", "Networking")] [WinOpen("mud_control_centre")] diff --git a/ShiftOS.WinForms/Applications/NameChanger.cs b/ShiftOS.WinForms/Applications/NameChanger.cs index ca76e57..d7c99f7 100644 --- a/ShiftOS.WinForms/Applications/NameChanger.cs +++ b/ShiftOS.WinForms/Applications/NameChanger.cs @@ -38,6 +38,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Name Changer", true, "al_name_changer", "Customization")] [RequiresUpgrade("name_changer")] [WinOpen("name_changer")] diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs index af1e156..157ce8c 100644 --- a/ShiftOS.WinForms/Applications/Pong.cs +++ b/ShiftOS.WinForms/Applications/Pong.cs @@ -37,6 +37,7 @@ using ShiftOS.Objects; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Pong", true, "al_pong", "Games")] [WinOpen("pong")] [DefaultIcon("iconPong")] diff --git a/ShiftOS.WinForms/Applications/ShiftLetters.cs b/ShiftOS.WinForms/Applications/ShiftLetters.cs index 700df7e..b5e9aa4 100644 --- a/ShiftOS.WinForms/Applications/ShiftLetters.cs +++ b/ShiftOS.WinForms/Applications/ShiftLetters.cs @@ -36,6 +36,7 @@ using System.Windows.Forms; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("ShiftLetters", false, null, "Games")] [RequiresUpgrade("shiftletters")] [WinOpen("shiftletters")] diff --git a/ShiftOS.WinForms/Applications/ShiftLotto.cs b/ShiftOS.WinForms/Applications/ShiftLotto.cs index 7acba3e..33f357f 100644 --- a/ShiftOS.WinForms/Applications/ShiftLotto.cs +++ b/ShiftOS.WinForms/Applications/ShiftLotto.cs @@ -35,6 +35,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [Launcher("ShiftLotto", true, "al_shiftlotto", "Games")] + [MultiplayerOnly] [DefaultIcon("iconShiftLotto")] [RequiresUpgrade("shiftlotto")] [WinOpen("shiftlotto")] diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index b13880f..cf6d331 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -36,6 +36,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [Launcher("ShiftSweeper", true, "al_shiftsweeper", "Games")] [RequiresUpgrade("shiftsweeper")] + [MultiplayerOnly] [WinOpen("shiftsweeper")] [DefaultIcon("iconShiftSweeper")] public partial class ShiftSweeper : UserControl, IShiftOSWindow { diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 1adc75a..fe2bf20 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -40,6 +40,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Shifter", true, "al_shifter", "Customization")] [RequiresUpgrade("shifter")] [WinOpen("shifter")] diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs index 45f37d4..c1c81d5 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -38,6 +38,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { [Launcher("Shiftnet", false, null, "Networking")] + [MultiplayerOnly] [DefaultIcon("iconShiftnet")] public partial class Shiftnet : UserControl, IShiftOSWindow { public Shiftnet() { diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index b3724ae..0580b47 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -39,6 +39,7 @@ namespace ShiftOS.WinForms.Applications { [Launcher("Shiftorium", true, "al_shiftorium", "Utilities")] [RequiresUpgrade("shiftorium_gui")] + [MultiplayerOnly] [WinOpen("shiftorium")] [DefaultTitle("Shiftorium")] [DefaultIcon("iconShiftorium")] diff --git a/ShiftOS.WinForms/HackerCommands.cs b/ShiftOS.WinForms/HackerCommands.cs index 52d8568..d9504d3 100644 --- a/ShiftOS.WinForms/HackerCommands.cs +++ b/ShiftOS.WinForms/HackerCommands.cs @@ -668,5 +668,15 @@ namespace ShiftOS.WinForms return true; } + + [Command("experience", description = "Marks a story plot as experienced without triggering the plot.", usage ="{id:}")] + [RequiresArgument("id")] + [RemoteLock] + public static bool Experience(Dictionary args) + { + SaveSystem.CurrentSave.StoriesExperienced.Add(args["id"].ToString()); + SaveSystem.SaveGame(); + return true; + } } } diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs index b8f0cae..eeaa6c9 100644 --- a/ShiftOS.WinForms/WinformsWindowManager.cs +++ b/ShiftOS.WinForms/WinformsWindowManager.cs @@ -106,6 +106,24 @@ namespace ShiftOS.WinForms return; } + foreach(var attr in form.GetType().GetCustomAttributes(true)) + { + if(attr is MultiplayerOnlyAttribute) + { + if(KernelWatchdog.MudConnected == false) + { + Infobox.PromptYesNo("Disconnected from MUD", "This application requires a connection to the MUD. Would you like to reconnect?", new Action((answer) => + { + if(answer == true) + { + KernelWatchdog.MudConnected = true; + SetupWindow(form); + } + })); + return; + } + } + } if (!Shiftorium.UpgradeAttributesUnlocked(form.GetType())) { diff --git a/ShiftOS_TheReturn/AppLauncherDaemon.cs b/ShiftOS_TheReturn/AppLauncherDaemon.cs index 7ef34c1..5e3bd72 100644 --- a/ShiftOS_TheReturn/AppLauncherDaemon.cs +++ b/ShiftOS_TheReturn/AppLauncherDaemon.cs @@ -66,12 +66,24 @@ namespace ShiftOS.Engine { foreach (var attr in type.GetCustomAttributes(false)) { - if (attr is LauncherAttribute) + bool isAllowed = true; + if(attr is MultiplayerOnlyAttribute) { - var launch = attr as LauncherAttribute; - if (launch.UpgradeInstalled) + if(KernelWatchdog.MudConnected == false) { - win.Add(new LauncherItem { DisplayData = launch, LaunchType = type }); + isAllowed = false; + + } + } + if (isAllowed == true) + { + if (attr is LauncherAttribute) + { + var launch = attr as LauncherAttribute; + if (launch.UpgradeInstalled) + { + win.Add(new LauncherItem { DisplayData = launch, LaunchType = type }); + } } } } diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs index 1b59b25..e69c9ba 100644 --- a/ShiftOS_TheReturn/KernelWatchdog.cs +++ b/ShiftOS_TheReturn/KernelWatchdog.cs @@ -25,8 +25,44 @@ namespace ShiftOS.Engine } } + private static bool _mudConnected = true; + public static bool InKernelMode { get; private set; } - public static bool MudConnected { get; set; } + public static bool MudConnected + { + get + { + return _mudConnected; + } + set + { + if(value == false) + { + foreach(var win in AppearanceManager.OpenForms) + { + foreach(var attr in win.ParentWindow.GetType().GetCustomAttributes(true)) + { + if(attr is MultiplayerOnlyAttribute) + { + ConsoleEx.Bold = true; + ConsoleEx.Underline = false; + ConsoleEx.Italic = true; + ConsoleEx.ForegroundColor = ConsoleColor.Red; + Console.Write("Error:"); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine("Cannot disconnect from multi-user domain because an app that depends on it is open."); + TerminalBackend.PrintPrompt(); + return; + } + } + } + } + + _mudConnected = value; + Desktop.PopulateAppLauncher(); + } + } public static bool IsSafe(Type type) { diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index bb65dc7..6768efb 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -67,11 +67,14 @@ namespace ShiftOS.Engine.Scripting { ServerManager.MessageReceived += (msg) => { - if(msg.Name == "run") + if (msg.Name == "run") { var cntnts = JsonConvert.DeserializeObject(msg.Contents); var interp = new LuaInterpreter(); - interp.Execute(cntnts.script.ToString()); + Desktop.InvokeOnWorkerThread(() => + { + interp.Execute(cntnts.script.ToString()); + }); } }; } -- cgit v1.2.3 From 6460ccee378e15408768337dcdc1bc77da07da53 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 12 Mar 2017 09:29:17 -0700 Subject: Custom Command Syntax --- .../Applications/FormatEditor.Designer.cs | 59 ++-- ShiftOS.WinForms/Applications/FormatEditor.cs | 222 ++----------- ShiftOS.WinForms/Applications/Shifter.cs | 9 +- ShiftOS.WinForms/Applications/Terminal.cs | 282 ++++++---------- ShiftOS_TheReturn/CommandParser.cs | 366 +++++++++++++++++++++ ShiftOS_TheReturn/Commands.cs | 1 + ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + ShiftOS_TheReturn/TerminalBackend.cs | 213 ++++++------ 8 files changed, 634 insertions(+), 519 deletions(-) create mode 100644 ShiftOS_TheReturn/CommandParser.cs (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs index 2f628f1..536ea62 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs @@ -61,8 +61,9 @@ namespace ShiftOS.WinForms.Applications this.btnAddColor = new System.Windows.Forms.Button(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.btnTest = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnLoad = new System.Windows.Forms.Button(); + this.btnApply = new System.Windows.Forms.Button(); this.SuspendLayout(); // // panelEditor @@ -109,9 +110,9 @@ namespace ShiftOS.WinForms.Applications // this.btnAddCommand.Location = new System.Drawing.Point(4, 85); this.btnAddCommand.Name = "btnAddCommand"; - this.btnAddCommand.Size = new System.Drawing.Size(75, 23); + this.btnAddCommand.Size = new System.Drawing.Size(85, 23); this.btnAddCommand.TabIndex = 5; - this.btnAddCommand.Text = "+ Command"; + this.btnAddCommand.Text = "+ Namespace"; this.btnAddCommand.UseVisualStyleBackColor = true; this.btnAddCommand.Click += new System.EventHandler(this.btnAddCommand_Click); // @@ -154,30 +155,43 @@ namespace ShiftOS.WinForms.Applications this.btnTest.UseVisualStyleBackColor = true; this.btnTest.Click += new System.EventHandler(this.btnTest_Click); // - // button1 + // btnSave // - this.button1.Location = new System.Drawing.Point(7, 161); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(47, 23); - this.button1.TabIndex = 12; - this.button1.Text = "Apply"; - this.button1.UseVisualStyleBackColor = true; + this.btnSave.Location = new System.Drawing.Point(7, 161); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(47, 23); + this.btnSave.TabIndex = 13; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // - // button2 + // btnLoad // - this.button2.Location = new System.Drawing.Point(60, 161); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(47, 23); - this.button2.TabIndex = 13; - this.button2.Text = "Save"; - this.button2.UseVisualStyleBackColor = true; + this.btnLoad.Location = new System.Drawing.Point(60, 161); + this.btnLoad.Name = "btnLoad"; + this.btnLoad.Size = new System.Drawing.Size(47, 23); + this.btnLoad.TabIndex = 14; + this.btnLoad.Text = "Load"; + this.btnLoad.UseVisualStyleBackColor = true; + this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); + // + // btnApply + // + this.btnApply.Location = new System.Drawing.Point(113, 161); + this.btnApply.Name = "btnApply"; + this.btnApply.Size = new System.Drawing.Size(47, 23); + this.btnApply.TabIndex = 15; + this.btnApply.Text = "Apply"; + this.btnApply.UseVisualStyleBackColor = true; + this.btnApply.Click += new System.EventHandler(this.btnApply_Click); // // FormatEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.button2); - this.Controls.Add(this.button1); + this.Controls.Add(this.btnApply); + this.Controls.Add(this.btnLoad); + this.Controls.Add(this.btnSave); this.Controls.Add(this.btnTest); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.btnAddColor); @@ -204,7 +218,8 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.Button btnAddColor; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Button btnTest; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnLoad; + private System.Windows.Forms.Button btnApply; } } diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs index ef44b47..bf5e78c 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -42,9 +42,10 @@ namespace ShiftOS.WinForms.Applications { public partial class FormatEditor : UserControl, IShiftOSWindow { IList parts = new List(); + CommandParser parser = new CommandParser(); IList editorBoxes = new List(); - string commandMode = "command"; + string commandMode = "namespace"; int avcount = 0; public FormatEditor() { @@ -66,10 +67,15 @@ namespace ShiftOS.WinForms.Applications { } private void addPart(CommandFormat part) { - parts.Add(part); + parser.AddPart(part); + + addPart(part.Draw()); + } + + private void addPart(Control part) { Panel container = new Panel(); - Control drawnPart = part.Draw(); + Control drawnPart = part; container.Size = drawnPart.Size; container.Controls.Add(drawnPart); @@ -103,6 +109,11 @@ namespace ShiftOS.WinForms.Applications { private void btnAddCommand_Click(object sender, EventArgs e) { switch (commandMode) { + case "namespace": + addPart(new CommandFormatNamespace()); + commandMode = "command"; + btnAddCommand.Text = "+ Command"; + break; case "command": addPart(new CommandFormatCommand()); commandMode = "argument"; @@ -129,215 +140,46 @@ namespace ShiftOS.WinForms.Applications { } private void richTextBox1_TextChanged(object sender, EventArgs e) { - string command = ""; - Dictionary arguments = new Dictionary(); - - string text = richTextBox1.Text; - int position = 0; - - int commandPos; - int firstValuePos = -1; - int lastValuePos = -1; - - for(int ii = 0; ii < parts.Count; ii++) { - CommandFormat part = parts[ii]; - if (part is CommandFormatMarker) { - if (part is CommandFormatCommand) { - commandPos = ii; - } else if (part is CommandFormatValue) { - if (firstValuePos > -1) - lastValuePos = ii; - else - firstValuePos = ii; - } - } - } - - int i = 0; - string currentArgument = ""; - int help = -1; - - while (position < text.Length) { - - if (i >= parts.Count) { - position = text.Length; - command = "+FALSE+"; - i = 0; - } - - CommandFormat part = parts[i]; - string res = part.CheckValidity(text.Substring(position)); - - // ok so: - - // example - // COMMAND text[ --] ARGUMENT VALUE text[ --] ARGUMENT VALUE - // COMMAND text[{] ARGUMENT text[=] VALUE text[, ] ARGUMENT text[=] VALUE text[}] - - if (part is CommandFormatMarker) { - if (part is CommandFormatCommand) { - command = res; - help = -1; - } else if (part is CommandFormatArgument) { - currentArgument = res; - help = -1; - } else if (part is CommandFormatValue) { - arguments[currentArgument] = res; - - if(i == firstValuePos) - help = lastValuePos; - if (i == lastValuePos) - help = firstValuePos; - } - } + var result = parser.ParseCommand(richTextBox1.Text); - if(res == "+FALSE+") { - if(help > -1) { - i = help; - if(i >= parts.Count) { - position = text.Length; - command = "+FALSE+"; - } - }else { - position = text.Length; - command = "+FALSE+"; - } - help = -1; - }else { - position += res.Length; - } - - i++; - } - - if (command == "+FALSE+") { + if (result.Equals(default(KeyValuePair, Dictionary>))) { lblExampleCommand.Text = "Syntax Error"; } else { string argvs = "{"; - foreach (KeyValuePair entry in arguments) { - argvs += entry.Key + "=" + entry.Value + ", "; + foreach (KeyValuePair entry in result.Value) { + argvs += entry.Key + "=\"" + entry.Value + "\", "; } argvs += "}"; - lblExampleCommand.Text = command + argvs; + lblExampleCommand.Text = result.Key + argvs; } } private void btnTest_Click(object sender, EventArgs e) { } - } - - interface CommandFormat { - string CheckValidity(string check); - Control Draw(); - } - class CommandFormatText : CommandFormat { - protected string str; - TextBox textBox; - - public CommandFormatText() { - } - - public virtual string CheckValidity(string check) { - return check.StartsWith(str) ? str : "+FALSE+"; - } - - public Control Draw() { - textBox = new TextBox(); - textBox.TextChanged += new EventHandler(TextChanged); - textBox.Location = new Point(0,0); - - return textBox; - } - - void TextChanged(object sender, EventArgs e) { - str = textBox.Text; - } - } - - class CommandFormatOptionalText : CommandFormatText { - public override string CheckValidity(string check) { - return check.StartsWith(str) ? str : ""; - } - } - - class CommandFormatMarker : CommandFormat { - protected string str; - Button button; - - public CommandFormatMarker() { - } - - public virtual string CheckValidity(string check) { - string res = string.Empty; - string alphanumeric = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890"; // not using regex for performance reasons - - foreach (char c in check) { - if (alphanumeric.IndexOf(c) > -1) { - res += c; - } else { - break; - } - } - - return res; - } - - public virtual Control Draw() { - button = new Button(); - button.Location = new Point(0, 0); - button.Text = "Marker"; - - return button; - } - } - class CommandFormatCommand : CommandFormatMarker { - public override Control Draw() { - Button draw = (Button)base.Draw(); - draw.Text = "Command"; - return draw; - } - } + private void btnSave_Click(object sender, EventArgs e) { + CurrentCommandParser.parser = parser; - class CommandFormatArgument : CommandFormatMarker { - public override Control Draw() { - Button draw = (Button)base.Draw(); - draw.Text = "Argument"; - return draw; + FileSkimmerBackend.GetFile(new string[] { ".cf" }, FileOpenerStyle.Save, new Action((result) => { + Objects.ShiftFS.Utils.WriteAllText(result, parser.Save()); + })); } - } - class CommandFormatValue : CommandFormatMarker { - public override string CheckValidity(string cd) { - string res = string.Empty; - var check = ""; - - if (cd.StartsWith("\"")) - check = cd.Substring(1); - bool done = false; - - foreach (char c in check) { - Console.WriteLine(check); - if (c != '"') { - res += c; - } else { - done = true; - res += "\""; - break; + private void btnLoad_Click(object sender, EventArgs e) { + FileSkimmerBackend.GetFile(new string[] { ".cf" }, FileOpenerStyle.Open, new Action((result) => { + parser = CommandParser.Load(Objects.ShiftFS.Utils.ReadAllText(result)); + foreach(CommandFormat part in parser.parts) { + addPart(part.Draw()); } - } - - return done ? "\""+res : "+FALSE+"; + })); } - public override Control Draw() { - Button draw = (Button)base.Draw(); - draw.Text = "\"Value\""; - return draw; + private void btnApply_Click(object sender, EventArgs e) { + CurrentCommandParser.parser = parser; } } } diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 4d29cf8..9a9b4ad 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -26,20 +26,13 @@ using Newtonsoft.Json; using ShiftOS.Objects.ShiftFS; using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; using ShiftOS.WinForms.Tools; -namespace ShiftOS.WinForms.Applications -{ +namespace ShiftOS.WinForms.Applications { [Launcher("Shifter", true, "al_shifter", "Customization")] [RequiresUpgrade("shifter")] [WinOpen("shifter")] diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 7bab213..9bd9f3c 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -44,13 +44,11 @@ using static ShiftOS.Engine.SkinEngine; using ShiftOS.Engine; using ShiftOS.Objects; -namespace ShiftOS.WinForms.Applications -{ +namespace ShiftOS.WinForms.Applications { [Launcher("Terminal", false, null, "Utilities")] [WinOpen("terminal")] [DefaultIcon("iconTerminal")] - public partial class Terminal : UserControl, IShiftOSWindow - { + public partial class Terminal : UserControl, IShiftOSWindow { public static Stack ConsoleStack = new Stack(); public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer(); @@ -62,81 +60,63 @@ namespace ShiftOS.WinForms.Applications public static string RemoteGuid = ""; [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool PrefixEnabled - { - get - { + public static bool PrefixEnabled { + get { return TerminalBackend.PrefixEnabled; } - set - { + set { TerminalBackend.PrefixEnabled = value; } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool InStory - { - get - { + public static bool InStory { + get { return TerminalBackend.InStory; } - set - { + set { TerminalBackend.InStory = value; } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static string LastCommand - { - get - { + public static string LastCommand { + get { return TerminalBackend.LastCommand; } - set - { + set { TerminalBackend.LastCommand = value; } } - public int TutorialProgress - { - get - { + public int TutorialProgress { + get { throw new NotImplementedException(); } - set - { + set { throw new NotImplementedException(); } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static void InvokeCommand(string text) - { - + public static void InvokeCommand(string text) { + TerminalBackend.InvokeCommand(text); } - public Terminal() - { + public Terminal() { InitializeComponent(); - SaveSystem.GameReady += () => - { - try - { - this.Invoke(new Action(() => - { + SaveSystem.GameReady += () => { + try { + this.Invoke(new Action(() => { ResetAllKeywords(); rtbterm.Text = ""; TerminalBackend.PrefixEnabled = true; TerminalBackend.InStory = false; Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - if (Shiftorium.UpgradeInstalled("wm_free_placement")) - { + if (Shiftorium.UpgradeInstalled("wm_free_placement")) { this.ParentForm.Width = 640; this.ParentForm.Height = 480; this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; @@ -144,8 +124,7 @@ namespace ShiftOS.WinForms.Applications } })); - } - catch { } + } catch { } }; @@ -153,32 +132,21 @@ namespace ShiftOS.WinForms.Applications } - public void FocusOnTerminal() - { + public void FocusOnTerminal() { rtbterm.Focus(); } - public static string GetTime() - { + public static string GetTime() { var time = DateTime.Now; - if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) - { + if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) { return DateTime.Now.ToString("h:mm:ss tt"); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) { return time.TimeOfDay.TotalHours > 12 ? $"{time.Hour - 12} PM" : $"{time.Hour} AM"; - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) { return ((int)time.TimeOfDay.TotalHours).ToString(); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) { return ((int)time.TimeOfDay.TotalMinutes).ToString(); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock")) { return ((int)time.TimeOfDay.TotalSeconds).ToString(); } @@ -188,8 +156,7 @@ namespace ShiftOS.WinForms.Applications public static event TextSentEventHandler TextSent; - public void ResetAllKeywords() - { + public void ResetAllKeywords() { string primary = SaveSystem.CurrentSave.Username + " "; string secondary = "shiftos "; @@ -198,27 +165,18 @@ namespace ShiftOS.WinForms.Applications var types = asm.GetTypes(); - foreach (var type in types) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) - { - if (a is Namespace) - { + foreach (var type in types) { + foreach (var a in type.GetCustomAttributes(false)) { + if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) { + if (a is Namespace) { var ns = a as Namespace; - if (!primary.Contains(ns.name)) - { + if (!primary.Contains(ns.name)) { primary += ns.name + " "; } - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { + foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { + if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) { + foreach (var ma in method.GetCustomAttributes(false)) { + if (ma is Command) { var cmd = ma as Command; if (!secondary.Contains(cmd.name)) secondary += cmd.name + " "; @@ -234,19 +192,14 @@ namespace ShiftOS.WinForms.Applications } - public static void MakeWidget(Controls.TerminalBox txt) - { + public static void MakeWidget(Controls.TerminalBox txt) { AppearanceManager.StartConsoleOut(); - txt.GotFocus += (o, a) => - { + txt.GotFocus += (o, a) => { AppearanceManager.ConsoleOut = txt; }; - txt.KeyDown += (o, a) => - { - if (a.KeyCode == Keys.Enter) - { - try - { + txt.KeyDown += (o, a) => { + if (a.KeyCode == Keys.Enter) { + try { a.SuppressKeyPress = true; Console.WriteLine(""); var text = txt.Lines.ToArray(); @@ -254,60 +207,55 @@ namespace ShiftOS.WinForms.Applications var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - if (IsInRemoteSystem == true) - { - ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new - { + if (IsInRemoteSystem == true) { + ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new { guid = RemoteGuid, command = text4 })); - } - else - { - if (TerminalBackend.PrefixEnabled) - { + } else { + if (TerminalBackend.PrefixEnabled) { text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } TerminalBackend.LastCommand = text3; TextSent?.Invoke(text4); - if (TerminalBackend.InStory == false) - { - TerminalBackend.InvokeCommand(text3); + if (TerminalBackend.InStory == false) { + if(text3 == "stop theme") { + CurrentCommandParser.parser = null; + }else { + if(CurrentCommandParser.parser == null) { + TerminalBackend.InvokeCommand(text3); + } else { + var result = CurrentCommandParser.parser.ParseCommand(text3); + + if (result.Equals(default(KeyValuePair, Dictionary>))) { + Console.WriteLine("Syntax Error: Syntax Error"); + } else { + TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value); + } + } + } } - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); } } + } catch { } - catch - { - } - } - else if (a.KeyCode == Keys.Back) - { - try - { + } else if (a.KeyCode == Keys.Back) { + try { var tostring3 = txt.Lines[txt.Lines.Length - 1]; var tostringlen = tostring3.Length + 1; var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; var derp = workaround.Length + 1; - if (tostringlen != derp) - { + if (tostringlen != derp) { AppearanceManager.CurrentPosition--; - } - else - { + } else { a.SuppressKeyPress = true; } - } - catch - { + } catch { Debug.WriteLine("Drunky alert in terminal."); } - } - else if (a.KeyCode == Keys.Left) - { + } else if (a.KeyCode == Keys.Left) { var getstring = txt.Lines[txt.Lines.Length - 1]; var stringlen = getstring.Length + 1; var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; @@ -316,28 +264,19 @@ namespace ShiftOS.WinForms.Applications var remstrlen = txt.TextLength - stringlen; var finalnum = selstart - remstrlen; - if (finalnum != headerlen) - { + if (finalnum != headerlen) { AppearanceManager.CurrentPosition--; - } - else - { + } else { a.SuppressKeyPress = true; } - } - //( ͡° ͜ʖ ͡° ) You found the lennyface without looking at the commit message. Message Michael in the #shiftos channel on Discord saying "ladouceur" somewhere in your message if you see this. - else if (a.KeyCode == Keys.Up) - { + } else if (a.KeyCode == Keys.Up) { var tostring3 = txt.Lines[txt.Lines.Length - 1]; if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") Console.Write(TerminalBackend.LastCommand); a.SuppressKeyPress = true; - } - else - { - if (TerminalBackend.InStory) - { + } else { + if (TerminalBackend.InStory) { a.SuppressKeyPress = true; } AppearanceManager.CurrentPosition++; @@ -346,7 +285,7 @@ namespace ShiftOS.WinForms.Applications }; AppearanceManager.ConsoleOut = txt; - + txt.Focus(); txt.Font = LoadedSkin.TerminalFont; @@ -355,17 +294,12 @@ namespace ShiftOS.WinForms.Applications } - private void Terminal_Load(object sender, EventArgs e) - { - ServerManager.MessageReceived += (msg) => - { - if(msg.Name == "trm_handshake_guid") - { + private void Terminal_Load(object sender, EventArgs e) { + ServerManager.MessageReceived += (msg) => { + if (msg.Name == "trm_handshake_guid") { IsInRemoteSystem = true; RemoteGuid = msg.GUID; - } - else if(msg.Name == "trm_handshake_stop") - { + } else if (msg.Name == "trm_handshake_stop") { IsInRemoteSystem = false; RemoteGuid = ""; } @@ -373,21 +307,17 @@ namespace ShiftOS.WinForms.Applications } - private void Terminal_FormClosing(object sender, FormClosingEventArgs e) - { + private void Terminal_FormClosing(object sender, FormClosingEventArgs e) { ti.Stop(); IsInRemoteSystem = false; RemoteGuid = ""; } - public void OnLoad() - { + public void OnLoad() { MakeWidget(rtbterm); - if (SaveSystem.CurrentSave != null) - { - if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) - { + if (SaveSystem.CurrentSave != null) { + if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) { rtbterm.Text = AppearanceManager.LastTerminalText; rtbterm.Select(rtbterm.TextLength, 0); } @@ -398,42 +328,30 @@ namespace ShiftOS.WinForms.Applications } - public void OnSkinLoad() - { - try - { + public void OnSkinLoad() { + try { rtbterm.Font = LoadedSkin.TerminalFont; rtbterm.ForeColor = LoadedSkin.TerminalForeColor; rtbterm.BackColor = LoadedSkin.TerminalBackColor; - } - catch - { + } catch { } } - public bool OnUnload() - { - if (SaveSystem.ShuttingDown == false) - { - if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) - { - if (AppearanceManager.OpenForms.Count <= 1) - { + public bool OnUnload() { + if (SaveSystem.ShuttingDown == false) { + if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) { + if (AppearanceManager.OpenForms.Count <= 1) { Console.WriteLine(""); Console.WriteLine("{WIN_CANTCLOSETERMINAL}"); - try - { + try { Console.WriteLine(""); - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { Console.Write($"{SaveSystem.CurrentSave.Username}@shiftos:~$ "); } - } - catch (Exception ex) - { + } catch (Exception ex) { Console.WriteLine(ex); } return false; @@ -443,15 +361,13 @@ namespace ShiftOS.WinForms.Applications return true; } - public void OnUpgrade() - { + public void OnUpgrade() { } - private void rtbterm_TextChanged(object sender, EventArgs e) - { + private void rtbterm_TextChanged(object sender, EventArgs e) { } - + } } //lol you found this comment i made so i chould push a change to make a point. \ No newline at end of file diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs new file mode 100644 index 0000000..182ff53 --- /dev/null +++ b/ShiftOS_TheReturn/CommandParser.cs @@ -0,0 +1,366 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShiftOS.Engine { + public static class CurrentCommandParser { + public static CommandParser parser; + } + + public class CommandParser { + public IList parts = new List(); + + public void AddPart(CommandFormat part) { + parts.Add(part); + } + + public void ImportPart(IList parts) { + this.parts = parts; + } + + public string Save() { + JArray data = new JArray(); + foreach(CommandFormat part in parts) { + CFValue val = new CFValue(part); + JObject obj = new JObject(); + obj["type"] = new JValue(val.type); + obj["text"] = new JValue(val.text); + data.Add(obj); + } + + return data.ToString(); + } + + public static CommandParser Load(string val) { + CommandParser parser = new CommandParser(); + JArray data = JArray.Parse(val); + + IList values = data.Select(obj => new CFValue ( + (string)obj["type"], + (string)obj["text"] + )).ToList(); + + foreach(CFValue value in values) { + parser.AddPart(value.GetCommandFormat()); + } + + return parser; + } + + public KeyValuePair, Dictionary> ParseCommand(string cdd) { + string command = ""; + string ns = ""; + Dictionary arguments = new Dictionary(); + + string text = cdd; + int position = 0; + + int commandPos; + int firstValuePos = -1; + int lastValuePos = -1; + + string syntaxError = ""; + + for (int ii = 0; ii < parts.Count; ii++) { + CommandFormat part = parts[ii]; + if (part is CommandFormatMarker) { + if (part is CommandFormatCommand) { + commandPos = ii; + } else if (part is CommandFormatValue) { + if (firstValuePos > -1) + lastValuePos = ii; + else + firstValuePos = ii; + } + } + } + + int i = 0; + string currentArgument = ""; + int help = -1; + + while (position < text.Length) { + + if (i >= parts.Count) { + position = text.Length; + command = "+FALSE+"; + i = 0; + } + + CommandFormat part = parts[i]; + string res = part.CheckValidity(text.Substring(position)); + + // ok so: + + // example + // COMMAND text[ --] ARGUMENT VALUE text[ --] ARGUMENT VALUE + // COMMAND text[{] ARGUMENT text[=] VALUE text[, ] ARGUMENT text[=] VALUE text[}] + + if (part is CommandFormatMarker) { + if (part is CommandFormatNamespace) { + ns = res; + help = -1; + }else if (part is CommandFormatCommand) { + command = res; + help = -1; + } else if (part is CommandFormatArgument) { + currentArgument = res; + help = -1; + } else if (part is CommandFormatValue) { + arguments[currentArgument] = string.Join("", res.Split('"')); + + if (i == firstValuePos) + help = lastValuePos; + if (i == lastValuePos) + help = firstValuePos; + } + } + + if (res == "+FALSE+") { + if (help > -1) { + i = help; + if (i >= parts.Count) { + position = text.Length; + command = "+FALSE+"; + } + } else { + position = text.Length; + syntaxError = "Syntax Error"; + command = "+FALSE+"; + } + help = -1; + } else { + position += res.Length; + } + + i++; + } + + if (command == "+FALSE+") { + //lblExampleCommand.Text = "Syntax Error"; + return new KeyValuePair, Dictionary>(); + } else { + /*string argvs = "{"; + + foreach (KeyValuePair entry in arguments) { + argvs += entry.Key + "=" + entry.Value + ", "; + } + + argvs += "}"; + + lblExampleCommand.Text = command + argvs;*/ + return new KeyValuePair, Dictionary> (new KeyValuePair(ns, command), arguments); + } + } + } + + public class CFValue { + public string type { get; set; } + public string text { get; set; } + + public CFValue(string type, string text) { + this.type = type; + this.text = text; + } + + public CFValue(CommandFormat format) { + type = ""; + text = ""; + if(format is CommandFormatText) { + text = ((CommandFormatText) format).str; + if(format is CommandFormatOptionalText) { + type = "optionalText"; + }else if (format is CommandFormatRegex) { + type = "regexText"; + }else { + type = "text"; + } + }else if (format is CommandFormatMarker) { + if (format is CommandFormatNamespace) { + type = "namespace"; + } else if (format is CommandFormatCommand) { + type = "command"; + } else if (format is CommandFormatArgument) { + type = "argument"; + } else if (format is CommandFormatValue) { + type = "value"; + } + } + } + + public CommandFormat GetCommandFormat() { // TODO update with better code + switch (type) { + case "text": + return new CommandFormatText(text); + case "optionalText": + return new CommandFormatOptionalText(text); + case "regexText": + return new CommandFormatRegex(text); + case "namespace": + return new CommandFormatNamespace(); + case "command": + return new CommandFormatCommand(); + case "argument": + return new CommandFormatArgument(); + case "value": + return new CommandFormatValue(); + case "color": + throw new NotImplementedException(); // fix this (make it not a notimplementedexception) + } + return new CommandFormatMarker(); + } + } + + + public interface CommandFormat { + string CheckValidity(string check); + Control Draw(); + } + public class CommandFormatText : CommandFormat { + public string str = ""; + TextBox textBox; + + public CommandFormatText() { + + } + + public CommandFormatText(string str) { + this.str = str; + } + + public virtual string CheckValidity(string check) { + return check.StartsWith(str) ? str : "+FALSE+"; + } + + public Control Draw() { + textBox = new TextBox(); + textBox.TextChanged += new EventHandler(TextChanged); + textBox.Location = new Point(0, 0); + textBox.Text = str; + + return textBox; + } + + void TextChanged(object sender, EventArgs e) { + str = textBox.Text; + } + } + + public class CommandFormatOptionalText : CommandFormatText { + public CommandFormatOptionalText() : base() { + } + public CommandFormatOptionalText(string str) : base(str) { + } + + public override string CheckValidity(string check) { + return check.StartsWith(str) ? str : ""; + } + } + + public class CommandFormatRegex : CommandFormatText { + public CommandFormatRegex() : base() { + } + public CommandFormatRegex(string str) : base(str) { + } + + public override string CheckValidity(string check) { + Match match = (new Regex("^" + str)).Match(check); + return match.Success ? match.Value : "+FALSE+"; + } + } + + public class CommandFormatMarker : CommandFormat { + protected string str; + Button button; + + public CommandFormatMarker() { + } + + public virtual string CheckValidity(string check) { + string res = string.Empty; + string alphanumeric = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; // not using regex for performance reasons + + foreach (char c in check) { + if (alphanumeric.IndexOf(c) > -1) { + res += c; + } else { + break; + } + } + + return res; + } + + public virtual Control Draw() { + button = new Button(); + button.Location = new Point(0, 0); + button.Text = "Marker"; + + return button; + } + } + + public class CommandFormatCommand : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Command"; + return draw; + } + } + + public class CommandFormatNamespace : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Namespace"; + return draw; + } + } + + public class CommandFormatArgument : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Argument"; + return draw; + } + } + + public class CommandFormatValue : CommandFormatMarker { + public override string CheckValidity(string cd) { + string res = string.Empty; + var check = ""; + bool done = false; + + if (cd.StartsWith("\"")) { + check = cd.Substring(1); + + foreach (char c in check) { + if (c != '"') { + res += c; + } else { + done = true; + res = "\"" + res + "\""; + break; + } + } + } else{ + res = base.CheckValidity(cd); + done = true; + } + return done ? res : "+FALSE+"; + } + + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "\"Value\""; + return draw; + } + } +} diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 0ea00e5..779c616 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -305,6 +305,7 @@ namespace ShiftOS.Engine [RequiresArgument("type")] public static bool MultArg(Dictionary args) { + Console.WriteLine("Success! "+args.ToString()); return true; } diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 20ca879..5521f49 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -97,6 +97,7 @@ + diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 8be54d0..fd2524f 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -32,26 +32,21 @@ using System.Threading.Tasks; using Newtonsoft.Json; using static ShiftOS.Engine.SaveSystem; -namespace ShiftOS.Engine -{ - public static class TerminalBackend - { +namespace ShiftOS.Engine { + public static class TerminalBackend { public static event Action CommandProcessed; public static bool Elevated { get; set; } - public static Dictionary GetArgs(ref string text) - { + public static Dictionary GetArgs(ref string text) { bool shouldParse = false; int argStart = 0; - if (text.Contains("{")) - { + if (text.Contains("{")) { shouldParse = true; argStart = text.IndexOf('{'); } - if (shouldParse == false) - { + if (shouldParse == false) { string replacement = Regex.Replace(text, @"\t|\n|\r", ""); text = replacement + "{}"; shouldParse = true; @@ -61,15 +56,47 @@ namespace ShiftOS.Engine string args = text.Substring(argStart, text.Length - argStart); text = text.Remove(argStart, text.Length - argStart).Replace(" ", ""); - return JsonConvert.DeserializeObject>(args); + return JsonConvert.DeserializeObject>(args); } public static string LastCommand = ""; - public static void InvokeCommand(string text, bool isRemote = false) - { - try - { + public static void InvokeCommand(string ns, string command, Dictionary arguments, bool isRemote = false) { + try { + if (string.IsNullOrWhiteSpace(ns)) + return; + + + bool commandWasClient = RunClient(ns, command, arguments, isRemote); + + if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) { + PrefixEnabled = false; + + ServerManager.SendMessage("script", $@"{{ + user: ""{ns}"", + script: ""{command}"", + args: ""{GetSentArgs(arguments)}"" +}}"); + } + + CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments)); + } catch (Exception ex) { + Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now + PrefixEnabled = true; + + } + } + + public static string GetSentArgs(Dictionary argss) { + Dictionary args = new Dictionary(); + foreach (KeyValuePair arg in argss) { + args[arg.Key] = arg.Value; + } + return JsonConvert.SerializeObject(args); + } + + public static void InvokeCommand(string text, bool isRemote = false) { + try { if (string.IsNullOrWhiteSpace(text)) return; @@ -77,19 +104,17 @@ namespace ShiftOS.Engine bool commandWasClient = RunClient(text, args, isRemote); - if (!commandWasClient && !string.IsNullOrWhiteSpace(text)) - { + if (!commandWasClient) { PrefixEnabled = false; + ServerManager.SendMessage("script", $@"{{ user: ""{text.Split('.')[0]}"", script: ""{text.Split('.')[1]}"", - args: ""{JsonConvert.SerializeObject(args)}"" + args: ""{GetSentArgs(args)}"" }}"); } - CommandProcessed?.Invoke(text, JsonConvert.SerializeObject(args)); - } - catch (Exception ex) - { + CommandProcessed?.Invoke(text, GetSentArgs(args)); + } catch (Exception ex) { Console.WriteLine($"Command parse error: {ex.Message}"); PrefixEnabled = true; @@ -104,18 +129,15 @@ namespace ShiftOS.Engine public static event EmptyEventHandler TerminalRequested; - internal static void OpenTerminal() - { + internal static void OpenTerminal() { TerminalRequested?.Invoke(); } - public static bool CanRunRemotely(MethodInfo mth, bool isRemote) - { + public static bool CanRunRemotely(MethodInfo mth, bool isRemote) { if (!isRemote) return true; - foreach(var attr in mth.GetCustomAttributes(false)) - { + foreach (var attr in mth.GetCustomAttributes(false)) { if (attr is RemoteLockAttribute) return false; } @@ -123,60 +145,45 @@ namespace ShiftOS.Engine return true; } - public static bool RunClient(string text, Dictionary args, bool isRemote = false) - { + public static bool RunClient(string ns, string cmd, Dictionary args, bool isRemote = false) { + return RunClient(ns + "." + cmd, args, isRemote); + } + + public static bool RunClient(string text, Dictionary args, bool isRemote = false) { latestCommmand = text; - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - try - { + foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) { + try { var asm = Assembly.LoadFile(asmExec); var types = asm.GetTypes(); - foreach (var type in types) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - if (KernelWatchdog.IsSafe(type)) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (a is Namespace) - { + foreach (var type in types) { + if (Shiftorium.UpgradeAttributesUnlocked(type)) { + if (KernelWatchdog.IsSafe(type)) { + foreach (var a in type.GetCustomAttributes(false)) { + if (a is Namespace) { var ns = a as Namespace; - if (text.Split('.')[0] == ns.name) - { - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (Shiftorium.UpgradeAttributesUnlocked(method)) - { - if (KernelWatchdog.IsSafe(method)) - { - if (CanRunRemotely(method, isRemote)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { + if (text.Split('.')[0] == ns.name) { + foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { + if (Shiftorium.UpgradeAttributesUnlocked(method)) { + if (KernelWatchdog.IsSafe(method)) { + if (CanRunRemotely(method, isRemote)) { + foreach (var ma in method.GetCustomAttributes(false)) { + if (ma is Command) { var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) - { + if (text.Split('.')[1] == cmd.name) { var attr = method.GetCustomAttribute(); - if (attr != null) - { + if (attr != null) { string newcommand = attr.newcommand; - if (attr.warn) - { + if (attr.warn) { Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary() { {"%newcommand", newcommand} })); } - if (newcommand != "") - { + if (newcommand != "") { // redo the entire process running newcommand return RunClient(newcommand, args); @@ -188,13 +195,10 @@ namespace ShiftOS.Engine bool error = false; bool providedusage = false; - foreach (RequiresArgument argument in requiresArgs) - { - if (!args.ContainsKey(argument.argument)) - { + foreach (RequiresArgument argument in requiresArgs) { + if (!args.ContainsKey(argument.argument)) { - if (!providedusage) - { + if (!providedusage) { string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}"; if (usageparse == Localization.Parse(usageparse)) usageparse = ""; @@ -209,14 +213,11 @@ namespace ShiftOS.Engine providedusage = true; } - if (Shiftorium.UpgradeInstalled("help_usage")) - { + if (Shiftorium.UpgradeInstalled("help_usage")) { Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary() { {"%argument", argument.argument} })); - } - else - { + } else { Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}")); } @@ -224,89 +225,69 @@ namespace ShiftOS.Engine } } - if (error) - { + if (error) { throw new Exception("{ERROR_COMMAND_WRONG}"); } - try - { + try { return (bool)method.Invoke(null, new[] { args }); - } - catch (TargetInvocationException e) - { + } catch (TargetInvocationException e) { Console.WriteLine(Localization.Parse("{ERROR_EXCEPTION_THROWN_IN_METHOD}")); Console.WriteLine(e.InnerException.Message); Console.WriteLine(e.InnerException.StackTrace); return true; - } - catch - { + } catch { return (bool)method.Invoke(null, new object[] { }); } } } } - } - else - { + } else { Console.WriteLine(text + " cannot be ran in a remote session"); return true; } } - + } } } } } } - + } } - } - catch { } + } catch { } } return false; } - - static TerminalBackend() - { - ServerMessageReceived onMessageReceived = (msg) => - { - if (msg.Name == "trm_invokecommand") - { + + static TerminalBackend() { + ServerMessageReceived onMessageReceived = (msg) => { + if (msg.Name == "trm_invokecommand") { string text3 = ""; string text4 = msg.Contents; - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } IsForwardingConsoleWrites = true; - if (TerminalBackend.InStory == false) - { + if (TerminalBackend.InStory == false) { TerminalBackend.InvokeCommand(text3, true); } - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); } IsForwardingConsoleWrites = false; - } - else if (msg.Name == "pleasewrite") - { + } else if (msg.Name == "pleasewrite") { Console.Write(msg.Contents); - } - else if(msg.Name == "handshake_from") - { + } else if (msg.Name == "handshake_from") { var a = JsonConvert.DeserializeObject>(msg.Contents); string uName = a["username"] as string; string pass = a["password"] as string; string sys = a["sysname"] as string; string guid = msg.GUID; - if(SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) - { + if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) { ForwardGUID = guid; ServerManager.SendMessage("trm_handshake_accept", $@"{{ guid: ""{ServerManager.thisGuid}"", @@ -326,6 +307,6 @@ namespace ShiftOS.Engine public static bool IsForwardingConsoleWrites { get; internal set; } public static string ForwardGUID { get; internal set; } - + } } -- cgit v1.2.3 From 791290857f6feed7da6b583b8f39cb45698d69e8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Apr 2017 10:03:28 -0400 Subject: Huge optimizations. Windows load A LOT faster, and Shifter has a preview. --- ShiftOS.WinForms/Applications/Shifter.Designer.cs | 467 +++++++++++++++++++--- ShiftOS.WinForms/Applications/Shifter.cs | 245 +++++++++++- ShiftOS.WinForms/Applications/Shifter.resx | 52 +++ ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs | 51 ++- ShiftOS.WinForms/WindowBorder.cs | 75 ++-- ShiftOS.WinForms/WinformsWindowManager.cs | 4 +- ShiftOS_TheReturn/Skinning.cs | 10 +- 7 files changed, 793 insertions(+), 111 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.Designer.cs b/ShiftOS.WinForms/Applications/Shifter.Designer.cs index 44045b5..4520e2a 100644 --- a/ShiftOS.WinForms/Applications/Shifter.Designer.cs +++ b/ShiftOS.WinForms/Applications/Shifter.Designer.cs @@ -52,103 +52,284 @@ namespace ShiftOS.WinForms.Applications /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Shifter)); this.panel1 = new System.Windows.Forms.Panel(); - this.panel4 = new System.Windows.Forms.Panel(); + this.pnlpreview = new System.Windows.Forms.Panel(); + this.pnlwindow = new System.Windows.Forms.Panel(); + this.pnlcontents = new System.Windows.Forms.Panel(); + this.pnltitle = new System.Windows.Forms.Panel(); + this.pnlicon = new System.Windows.Forms.Panel(); + this.pnlminimize = new System.Windows.Forms.Panel(); + this.pnlmaximize = new System.Windows.Forms.Panel(); + this.pnlclose = new System.Windows.Forms.Panel(); + this.pnltitleleft = new System.Windows.Forms.Panel(); + this.pnltitleright = new System.Windows.Forms.Panel(); + this.lbtitletext = new System.Windows.Forms.Label(); + this.pnlbottom = new System.Windows.Forms.Panel(); + this.pnlbottomr = new System.Windows.Forms.Panel(); + this.pnlbottoml = new System.Windows.Forms.Panel(); + this.pnlright = new System.Windows.Forms.Panel(); + this.pnlleft = new System.Windows.Forms.Panel(); + this.pnlsettingsholder = new System.Windows.Forms.Panel(); this.flbody = new System.Windows.Forms.FlowLayoutPanel(); this.flcategory = new System.Windows.Forms.FlowLayoutPanel(); - this.panel3 = new System.Windows.Forms.Panel(); - this.label1 = new System.Windows.Forms.Label(); - this.panel2 = new System.Windows.Forms.Panel(); + this.pnlcategoryholder = new System.Windows.Forms.Panel(); this.flmeta = new System.Windows.Forms.FlowLayoutPanel(); this.btnapply = new System.Windows.Forms.Button(); + this.mspreview = new System.Windows.Forms.MenuStrip(); + this.menuToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuItem1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuItem2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.subitem1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.subitem2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.subitem3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.separatorToolStripMenuItem = new System.Windows.Forms.ToolStripSeparator(); + this.menuItem3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.tspreview = new System.Windows.Forms.ToolStrip(); + this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel(); + this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); + this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); + this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox(); this.panel1.SuspendLayout(); - this.panel4.SuspendLayout(); - this.panel3.SuspendLayout(); - this.panel2.SuspendLayout(); + this.pnlpreview.SuspendLayout(); + this.pnlwindow.SuspendLayout(); + this.pnlcontents.SuspendLayout(); + this.pnltitle.SuspendLayout(); + this.pnlbottom.SuspendLayout(); + this.pnlsettingsholder.SuspendLayout(); + this.pnlcategoryholder.SuspendLayout(); + this.mspreview.SuspendLayout(); + this.tspreview.SuspendLayout(); this.SuspendLayout(); // // panel1 // - this.panel1.Controls.Add(this.panel4); - this.panel1.Controls.Add(this.panel3); - this.panel1.Controls.Add(this.panel2); + this.panel1.Controls.Add(this.pnlpreview); + this.panel1.Controls.Add(this.pnlsettingsholder); + this.panel1.Controls.Add(this.pnlcategoryholder); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(893, 539); this.panel1.TabIndex = 0; // - // panel4 + // pnlpreview // - this.panel4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + this.pnlpreview.Controls.Add(this.pnlwindow); + this.pnlpreview.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlpreview.Location = new System.Drawing.Point(136, 0); + this.pnlpreview.Name = "pnlpreview"; + this.pnlpreview.Size = new System.Drawing.Size(757, 286); + this.pnlpreview.TabIndex = 1; + // + // pnlwindow + // + this.pnlwindow.Controls.Add(this.pnlcontents); + this.pnlwindow.Controls.Add(this.pnltitle); + this.pnlwindow.Controls.Add(this.pnlbottom); + this.pnlwindow.Controls.Add(this.pnlright); + this.pnlwindow.Controls.Add(this.pnlleft); + this.pnlwindow.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlwindow.Location = new System.Drawing.Point(0, 0); + this.pnlwindow.Name = "pnlwindow"; + this.pnlwindow.Size = new System.Drawing.Size(757, 286); + this.pnlwindow.TabIndex = 0; + // + // pnlcontents + // + this.pnlcontents.BackColor = System.Drawing.Color.Black; + this.pnlcontents.Controls.Add(this.tspreview); + this.pnlcontents.Controls.Add(this.mspreview); + this.pnlcontents.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlcontents.ForeColor = System.Drawing.Color.White; + this.pnlcontents.Location = new System.Drawing.Point(2, 30); + this.pnlcontents.Name = "pnlcontents"; + this.pnlcontents.Size = new System.Drawing.Size(753, 254); + this.pnlcontents.TabIndex = 9; + // + // pnltitle + // + this.pnltitle.BackColor = System.Drawing.Color.Black; + this.pnltitle.Controls.Add(this.pnlicon); + this.pnltitle.Controls.Add(this.pnlminimize); + this.pnltitle.Controls.Add(this.pnlmaximize); + this.pnltitle.Controls.Add(this.pnlclose); + this.pnltitle.Controls.Add(this.pnltitleleft); + this.pnltitle.Controls.Add(this.pnltitleright); + this.pnltitle.Controls.Add(this.lbtitletext); + this.pnltitle.Dock = System.Windows.Forms.DockStyle.Top; + this.pnltitle.Location = new System.Drawing.Point(2, 0); + this.pnltitle.Name = "pnltitle"; + this.pnltitle.Size = new System.Drawing.Size(753, 30); + this.pnltitle.TabIndex = 5; + // + // pnlicon + // + this.pnlicon.Location = new System.Drawing.Point(9, -76); + this.pnlicon.Name = "pnlicon"; + this.pnlicon.Size = new System.Drawing.Size(200, 100); + this.pnlicon.TabIndex = 6; + // + // pnlminimize + // + this.pnlminimize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pnlminimize.BackColor = System.Drawing.Color.Green; + this.pnlminimize.Location = new System.Drawing.Point(672, 3); + this.pnlminimize.Name = "pnlminimize"; + this.pnlminimize.Size = new System.Drawing.Size(24, 24); + this.pnlminimize.TabIndex = 3; + // + // pnlmaximize + // + this.pnlmaximize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pnlmaximize.BackColor = System.Drawing.Color.Yellow; + this.pnlmaximize.Location = new System.Drawing.Point(699, 3); + this.pnlmaximize.Name = "pnlmaximize"; + this.pnlmaximize.Size = new System.Drawing.Size(24, 24); + this.pnlmaximize.TabIndex = 2; + // + // pnlclose + // + this.pnlclose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pnlclose.BackColor = System.Drawing.Color.Red; + this.pnlclose.Location = new System.Drawing.Point(726, 3); + this.pnlclose.Name = "pnlclose"; + this.pnlclose.Size = new System.Drawing.Size(24, 24); + this.pnlclose.TabIndex = 1; + // + // pnltitleleft + // + this.pnltitleleft.Dock = System.Windows.Forms.DockStyle.Left; + this.pnltitleleft.Location = new System.Drawing.Point(0, 0); + this.pnltitleleft.Name = "pnltitleleft"; + this.pnltitleleft.Size = new System.Drawing.Size(2, 30); + this.pnltitleleft.TabIndex = 4; + // + // pnltitleright + // + this.pnltitleright.Dock = System.Windows.Forms.DockStyle.Right; + this.pnltitleright.Location = new System.Drawing.Point(751, 0); + this.pnltitleright.Name = "pnltitleright"; + this.pnltitleright.Size = new System.Drawing.Size(2, 30); + this.pnltitleright.TabIndex = 5; + // + // lbtitletext + // + this.lbtitletext.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.panel4.Controls.Add(this.flbody); - this.panel4.Controls.Add(this.flcategory); - this.panel4.Location = new System.Drawing.Point(154, 283); - this.panel4.Name = "panel4"; - this.panel4.Size = new System.Drawing.Size(734, 253); - this.panel4.TabIndex = 2; + this.lbtitletext.AutoSize = true; + this.lbtitletext.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.lbtitletext.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Bold); + this.lbtitletext.ForeColor = System.Drawing.Color.White; + this.lbtitletext.Location = new System.Drawing.Point(75, 9); + this.lbtitletext.Name = "lbtitletext"; + this.lbtitletext.Size = new System.Drawing.Size(77, 14); + this.lbtitletext.TabIndex = 0; + this.lbtitletext.Text = "Title text"; + this.lbtitletext.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.lbtitletext.UseMnemonic = false; + // + // pnlbottom + // + this.pnlbottom.BackColor = System.Drawing.Color.Black; + this.pnlbottom.Controls.Add(this.pnlbottomr); + this.pnlbottom.Controls.Add(this.pnlbottoml); + this.pnlbottom.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlbottom.Location = new System.Drawing.Point(2, 284); + this.pnlbottom.Name = "pnlbottom"; + this.pnlbottom.Size = new System.Drawing.Size(753, 2); + this.pnlbottom.TabIndex = 6; + // + // pnlbottomr + // + this.pnlbottomr.Dock = System.Windows.Forms.DockStyle.Right; + this.pnlbottomr.Location = new System.Drawing.Point(751, 0); + this.pnlbottomr.Name = "pnlbottomr"; + this.pnlbottomr.Size = new System.Drawing.Size(2, 2); + this.pnlbottomr.TabIndex = 3; + // + // pnlbottoml + // + this.pnlbottoml.Dock = System.Windows.Forms.DockStyle.Left; + this.pnlbottoml.Location = new System.Drawing.Point(0, 0); + this.pnlbottoml.Name = "pnlbottoml"; + this.pnlbottoml.Size = new System.Drawing.Size(2, 2); + this.pnlbottoml.TabIndex = 2; + // + // pnlright + // + this.pnlright.BackColor = System.Drawing.Color.Black; + this.pnlright.Dock = System.Windows.Forms.DockStyle.Right; + this.pnlright.Location = new System.Drawing.Point(755, 0); + this.pnlright.Name = "pnlright"; + this.pnlright.Size = new System.Drawing.Size(2, 286); + this.pnlright.TabIndex = 8; + // + // pnlleft + // + this.pnlleft.BackColor = System.Drawing.Color.Black; + this.pnlleft.Dock = System.Windows.Forms.DockStyle.Left; + this.pnlleft.Location = new System.Drawing.Point(0, 0); + this.pnlleft.Name = "pnlleft"; + this.pnlleft.Size = new System.Drawing.Size(2, 286); + this.pnlleft.TabIndex = 7; + // + // pnlsettingsholder + // + this.pnlsettingsholder.Controls.Add(this.flbody); + this.pnlsettingsholder.Controls.Add(this.flcategory); + this.pnlsettingsholder.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlsettingsholder.Location = new System.Drawing.Point(136, 286); + this.pnlsettingsholder.Name = "pnlsettingsholder"; + this.pnlsettingsholder.Padding = new System.Windows.Forms.Padding(10); + this.pnlsettingsholder.Size = new System.Drawing.Size(757, 253); + this.pnlsettingsholder.TabIndex = 2; // // flbody // this.flbody.AutoScroll = true; this.flbody.Dock = System.Windows.Forms.DockStyle.Fill; - this.flbody.Location = new System.Drawing.Point(126, 0); + this.flbody.Location = new System.Drawing.Point(136, 10); this.flbody.Name = "flbody"; - this.flbody.Size = new System.Drawing.Size(608, 253); + this.flbody.Size = new System.Drawing.Size(611, 233); this.flbody.TabIndex = 3; // // flcategory // this.flcategory.Dock = System.Windows.Forms.DockStyle.Left; - this.flcategory.Location = new System.Drawing.Point(0, 0); + this.flcategory.Location = new System.Drawing.Point(10, 10); this.flcategory.Name = "flcategory"; - this.flcategory.Size = new System.Drawing.Size(126, 253); + this.flcategory.Size = new System.Drawing.Size(126, 233); this.flcategory.TabIndex = 2; // - // panel3 - // - this.panel3.Controls.Add(this.label1); - this.panel3.Location = new System.Drawing.Point(155, 12); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(640, 360); - this.panel3.TabIndex = 1; - // - // label1 - // - this.label1.Dock = System.Windows.Forms.DockStyle.Fill; - this.label1.Location = new System.Drawing.Point(0, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(640, 360); - this.label1.TabIndex = 0; - this.label1.Text = "Preview not available."; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // pnlcategoryholder // - // panel2 - // - this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.panel2.Controls.Add(this.flmeta); - this.panel2.Controls.Add(this.btnapply); - this.panel2.Location = new System.Drawing.Point(12, 12); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(136, 511); - this.panel2.TabIndex = 0; + this.pnlcategoryholder.Controls.Add(this.flmeta); + this.pnlcategoryholder.Controls.Add(this.btnapply); + this.pnlcategoryholder.Dock = System.Windows.Forms.DockStyle.Left; + this.pnlcategoryholder.Location = new System.Drawing.Point(0, 0); + this.pnlcategoryholder.Name = "pnlcategoryholder"; + this.pnlcategoryholder.Padding = new System.Windows.Forms.Padding(10); + this.pnlcategoryholder.Size = new System.Drawing.Size(136, 539); + this.pnlcategoryholder.TabIndex = 0; // // flmeta // this.flmeta.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.flmeta.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flmeta.Location = new System.Drawing.Point(4, 4); + this.flmeta.Location = new System.Drawing.Point(14, 14); this.flmeta.Name = "flmeta"; - this.flmeta.Size = new System.Drawing.Size(126, 450); + this.flmeta.Size = new System.Drawing.Size(126, 458); this.flmeta.TabIndex = 1; // // btnapply // this.btnapply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnapply.Location = new System.Drawing.Point(3, 460); + this.btnapply.Location = new System.Drawing.Point(13, 478); this.btnapply.Name = "btnapply"; this.btnapply.Size = new System.Drawing.Size(127, 48); this.btnapply.TabIndex = 0; @@ -156,19 +337,155 @@ namespace ShiftOS.WinForms.Applications this.btnapply.UseVisualStyleBackColor = true; this.btnapply.Click += new System.EventHandler(this.btnapply_Click); // + // mspreview + // + this.mspreview.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuToolStripMenuItem}); + this.mspreview.Location = new System.Drawing.Point(0, 0); + this.mspreview.Name = "mspreview"; + this.mspreview.Size = new System.Drawing.Size(753, 24); + this.mspreview.TabIndex = 0; + this.mspreview.Text = "menuStrip1"; + // + // menuToolStripMenuItem + // + this.menuToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuItem1ToolStripMenuItem, + this.menuItem2ToolStripMenuItem, + this.separatorToolStripMenuItem, + this.menuItem3ToolStripMenuItem}); + this.menuToolStripMenuItem.Name = "menuToolStripMenuItem"; + this.menuToolStripMenuItem.Size = new System.Drawing.Size(50, 20); + this.menuToolStripMenuItem.Text = "Menu"; + // + // menuItem1ToolStripMenuItem + // + this.menuItem1ToolStripMenuItem.Name = "menuItem1ToolStripMenuItem"; + this.menuItem1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.menuItem1ToolStripMenuItem.Text = "Menu Item 1"; + // + // menuItem2ToolStripMenuItem + // + this.menuItem2ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.subitem1ToolStripMenuItem, + this.subitem2ToolStripMenuItem, + this.subitem3ToolStripMenuItem}); + this.menuItem2ToolStripMenuItem.Name = "menuItem2ToolStripMenuItem"; + this.menuItem2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.menuItem2ToolStripMenuItem.Text = "Menu Item 2"; + // + // subitem1ToolStripMenuItem + // + this.subitem1ToolStripMenuItem.Name = "subitem1ToolStripMenuItem"; + this.subitem1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.subitem1ToolStripMenuItem.Text = "Subitem 1"; + // + // subitem2ToolStripMenuItem + // + this.subitem2ToolStripMenuItem.Name = "subitem2ToolStripMenuItem"; + this.subitem2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.subitem2ToolStripMenuItem.Text = "Subitem 2"; + // + // subitem3ToolStripMenuItem + // + this.subitem3ToolStripMenuItem.Name = "subitem3ToolStripMenuItem"; + this.subitem3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.subitem3ToolStripMenuItem.Text = "Subitem 3"; + // + // separatorToolStripMenuItem + // + this.separatorToolStripMenuItem.Name = "separatorToolStripMenuItem"; + this.separatorToolStripMenuItem.Size = new System.Drawing.Size(149, 6); + // + // menuItem3ToolStripMenuItem + // + this.menuItem3ToolStripMenuItem.Name = "menuItem3ToolStripMenuItem"; + this.menuItem3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.menuItem3ToolStripMenuItem.Text = "Menu Item 3"; + // + // tspreview + // + this.tspreview.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripLabel1, + this.toolStripButton2, + this.toolStripButton3, + this.toolStripButton1, + this.toolStripSeparator1, + this.toolStripTextBox1}); + this.tspreview.Location = new System.Drawing.Point(0, 24); + this.tspreview.Name = "tspreview"; + this.tspreview.Size = new System.Drawing.Size(753, 25); + this.tspreview.TabIndex = 1; + this.tspreview.Text = "toolStrip1"; + // + // toolStripLabel1 + // + this.toolStripLabel1.Name = "toolStripLabel1"; + this.toolStripLabel1.Size = new System.Drawing.Size(81, 22); + this.toolStripLabel1.Text = "Toolbar Label:"; + // + // toolStripButton1 + // + this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.toolStripButton1.Enabled = false; + this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); + this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton1.Name = "toolStripButton1"; + this.toolStripButton1.Size = new System.Drawing.Size(56, 22); + this.toolStripButton1.Text = "Disabled"; + // + // toolStripButton2 + // + this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image"))); + this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton2.Name = "toolStripButton2"; + this.toolStripButton2.Size = new System.Drawing.Size(51, 22); + this.toolStripButton2.Text = "Regular"; + // + // toolStripButton3 + // + this.toolStripButton3.Checked = true; + this.toolStripButton3.CheckState = System.Windows.Forms.CheckState.Checked; + this.toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.toolStripButton3.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton3.Image"))); + this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton3.Name = "toolStripButton3"; + this.toolStripButton3.Size = new System.Drawing.Size(57, 22); + this.toolStripButton3.Text = "Checked"; + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25); + // + // toolStripTextBox1 + // + this.toolStripTextBox1.Name = "toolStripTextBox1"; + this.toolStripTextBox1.Size = new System.Drawing.Size(100, 25); + // // Shifter // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.panel1); this.Name = "Shifter"; - this.Text = "{SHIFTER_NAME}"; this.Size = new System.Drawing.Size(893, 539); this.Load += new System.EventHandler(this.Shifter_Load); this.panel1.ResumeLayout(false); - this.panel4.ResumeLayout(false); - this.panel3.ResumeLayout(false); - this.panel2.ResumeLayout(false); + this.pnlpreview.ResumeLayout(false); + this.pnlwindow.ResumeLayout(false); + this.pnlcontents.ResumeLayout(false); + this.pnlcontents.PerformLayout(); + this.pnltitle.ResumeLayout(false); + this.pnltitle.PerformLayout(); + this.pnlbottom.ResumeLayout(false); + this.pnlsettingsholder.ResumeLayout(false); + this.pnlcategoryholder.ResumeLayout(false); + this.mspreview.ResumeLayout(false); + this.mspreview.PerformLayout(); + this.tspreview.ResumeLayout(false); + this.tspreview.PerformLayout(); this.ResumeLayout(false); } @@ -176,13 +493,43 @@ namespace ShiftOS.WinForms.Applications #endregion private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel pnlcategoryholder; private System.Windows.Forms.FlowLayoutPanel flmeta; private System.Windows.Forms.Button btnapply; - private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.Panel pnlsettingsholder; private System.Windows.Forms.FlowLayoutPanel flbody; private System.Windows.Forms.FlowLayoutPanel flcategory; - private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel pnlpreview; + private System.Windows.Forms.Panel pnlwindow; + private System.Windows.Forms.Panel pnlcontents; + private System.Windows.Forms.Panel pnltitle; + private System.Windows.Forms.Panel pnlicon; + private System.Windows.Forms.Panel pnlminimize; + private System.Windows.Forms.Panel pnlmaximize; + private System.Windows.Forms.Panel pnlclose; + private System.Windows.Forms.Panel pnltitleleft; + private System.Windows.Forms.Panel pnltitleright; + private System.Windows.Forms.Label lbtitletext; + private System.Windows.Forms.Panel pnlbottom; + private System.Windows.Forms.Panel pnlbottomr; + private System.Windows.Forms.Panel pnlbottoml; + private System.Windows.Forms.Panel pnlright; + private System.Windows.Forms.Panel pnlleft; + private System.Windows.Forms.MenuStrip mspreview; + private System.Windows.Forms.ToolStripMenuItem menuToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem menuItem1ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem menuItem2ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem subitem1ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem subitem2ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem subitem3ToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator separatorToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem menuItem3ToolStripMenuItem; + private System.Windows.Forms.ToolStrip tspreview; + private System.Windows.Forms.ToolStripLabel toolStripLabel1; + private System.Windows.Forms.ToolStripButton toolStripButton2; + private System.Windows.Forms.ToolStripButton toolStripButton3; + private System.Windows.Forms.ToolStripButton toolStripButton1; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripTextBox toolStripTextBox1; } } \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 02e2d0a..e7ad768 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -47,6 +47,193 @@ namespace ShiftOS.WinForms.Applications PopulateShifter(); } + [ShifterMeta("Windows")] + public void SetupWindowPreview() + { + pnlwindow.BringToFront(); + WBSetup(); + } + + [ShifterMeta("Menus")] + public void SetupMenusPreview() + { + SetupWindowPreview(); + } + + [ShifterMeta("System")] + public void SetupSystemPreview() + { + SetupWindowPreview(); + } + + /// + /// Setup this instance. + /// + public void WBSetup() + { + this.lbtitletext.Text = "Window Preview"; + + if (SaveSystem.CurrentSave != null) + { + this.pnltitle.Visible = Shiftorium.UpgradeInstalled("wm_titlebar"); + this.pnlclose.Visible = Shiftorium.UpgradeInstalled("close_button"); + this.pnlminimize.Visible = Shiftorium.UpgradeInstalled("minimize_button"); + this.pnlmaximize.Visible =Shiftorium.UpgradeInstalled("maximize_button"); + WBSetupSkin(); + } + else + { + this.pnltitle.Visible = false; + this.pnlclose.Visible = false; + this.pnlminimize.Visible = false; + this.pnlmaximize.Visible = false; + + } + } + + public Image GetImage(string id) + { + var type = typeof(ShiftOS.Engine.Skin); + foreach(var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance)) + { + foreach(var attrib in field.GetCustomAttributes(false)) + { + if(attrib is ImageAttribute) + { + var img = attrib as ImageAttribute; + if(img.Name == id) + { + return SkinEngine.ImageFromBinary((byte[])field.GetValue(LoadedSkin)); + } + } + } + } + return null; + } + + public ImageLayout GetImageLayout(string img) + { + if (LoadedSkin.SkinImageLayouts.ContainsKey(img)) + { + return LoadedSkin.SkinImageLayouts[img]; + } + else + { + LoadedSkin.SkinImageLayouts.Add(img, ImageLayout.Tile); + return ImageLayout.Tile; + } + + } + + /// + /// Setups the skin. + /// + /// The skin. + public void WBSetupSkin() + { + this.DoubleBuffered = true; + var renderer = new ShiftOSMenuRenderer(LoadedSkin); + mspreview.Renderer = renderer; + tspreview.Renderer = renderer; + pnltitle.Height = LoadedSkin.TitlebarHeight; + pnltitle.BackColor = LoadedSkin.TitleBackgroundColor; + pnltitle.BackgroundImage = GetImage("titlebar"); + pnltitleleft.Visible = LoadedSkin.ShowTitleCorners; + pnltitleright.Visible = LoadedSkin.ShowTitleCorners; + pnltitleleft.BackColor = LoadedSkin.TitleLeftCornerBackground; + pnltitleright.BackColor = LoadedSkin.TitleRightCornerBackground; + pnltitleleft.Width = LoadedSkin.TitleLeftCornerWidth; + pnltitleright.Width = LoadedSkin.TitleRightCornerWidth; + pnltitleleft.BackgroundImage = GetImage("titleleft"); + pnltitleleft.BackgroundImageLayout = GetImageLayout("titleleft"); + pnltitleright.BackgroundImage = GetImage("titleright"); + pnltitleright.BackgroundImageLayout = GetImageLayout("titleright"); + pnltitle.BackgroundImageLayout = GetImageLayout("titlebar"); //RETARD ALERT. WHY WASN'T THIS THERE WHEN IMAGELAYOUTS WERE FIRST IMPLEMENTED? + + lbtitletext.BackColor = (pnltitle.BackgroundImage != null) ? Color.Transparent : LoadedSkin.TitleBackgroundColor; + lbtitletext.ForeColor = LoadedSkin.TitleTextColor; + lbtitletext.Font = LoadedSkin.TitleFont; + + pnlleft.BackColor = LoadedSkin.BorderLeftBackground; + pnlleft.BackgroundImage = GetImage("leftborder"); + pnlleft.BackgroundImageLayout = GetImageLayout("leftborder"); + pnlleft.Width = LoadedSkin.LeftBorderWidth; + pnlright.BackColor = LoadedSkin.BorderRightBackground; + pnlright.BackgroundImage = GetImage("rightborder"); + pnlright.BackgroundImageLayout = GetImageLayout("rightborder"); + pnlright.Width = LoadedSkin.RightBorderWidth; + + pnlbottom.BackColor = LoadedSkin.BorderBottomBackground; + pnlbottom.BackgroundImage = GetImage("bottomborder"); + pnlbottom.BackgroundImageLayout = GetImageLayout("bottomborder"); + pnlbottom.Height = LoadedSkin.BottomBorderWidth; + + pnlbottomr.BackColor = LoadedSkin.BorderBottomRightBackground; + pnlbottomr.BackgroundImage = GetImage("bottomrborder"); + pnlbottomr.BackgroundImageLayout = GetImageLayout("bottomrborder"); + pnlbottoml.BackColor = LoadedSkin.BorderBottomLeftBackground; + pnlbottoml.BackgroundImage = GetImage("bottomlborder"); + pnlbottoml.BackgroundImageLayout = GetImageLayout("bottomlborder"); + + lbtitletext.ForeColor = LoadedSkin.TitleTextColor; + lbtitletext.Font = LoadedSkin.TitleFont; + pnlclose.BackColor = LoadedSkin.CloseButtonColor; + pnlclose.BackgroundImage = GetImage("closebutton"); + pnlclose.BackgroundImageLayout = GetImageLayout("closebutton"); + pnlminimize.BackColor = LoadedSkin.MinimizeButtonColor; + pnlminimize.BackgroundImage = GetImage("minimizebutton"); + pnlminimize.BackgroundImageLayout = GetImageLayout("minimizebutton"); + pnlmaximize.BackColor = LoadedSkin.MaximizeButtonColor; + pnlmaximize.BackgroundImage = GetImage("maximizebutton"); + pnlmaximize.BackgroundImageLayout = GetImageLayout("maximizebutton"); + + pnlclose.Size = LoadedSkin.CloseButtonSize; + pnlminimize.Size = LoadedSkin.MinimizeButtonSize; + pnlmaximize.Size = LoadedSkin.MaximizeButtonSize; + pnlclose.Location = FromRight(LoadedSkin.CloseButtonFromSide); + pnlminimize.Location = FromRight(LoadedSkin.MinimizeButtonFromSide); + pnlmaximize.Location = FromRight(LoadedSkin.MaximizeButtonFromSide); + pnlclose.Left -= pnlclose.Width; + pnlmaximize.Left -= pnlmaximize.Width; + pnlminimize.Left -= pnlminimize.Width; + + switch (LoadedSkin.TitleTextCentered) + { + case false: + lbtitletext.Location = new Point(16 + LoadedSkin.TitlebarIconFromSide.X + LoadedSkin.TitleTextLeft.X, + LoadedSkin.TitleTextLeft.Y); + break; + default: + lbtitletext.Left = (pnltitle.Width - lbtitletext.Width) / 2; + lbtitletext.Top = LoadedSkin.TitleTextLeft.Y; + break; + } + + if (Shiftorium.UpgradeInstalled("app_icons")) + { + pnlicon.Show(); + pnlicon.Size = new Size(16, 16); + pnlicon.BackColor = Color.Transparent; + pnlicon.BackgroundImageLayout = ImageLayout.Stretch; + pnlicon.Location = LoadedSkin.TitlebarIconFromSide; + } + else + { + pnlicon.Hide(); + } + } + + /// + /// Froms the right. + /// + /// The right. + /// Input. + public Point FromRight(Point input) + { + return new Point(pnltitle.Width - input.X, input.Y); + } + + public int CodepointValue = 0; public List settings = new List(); public Skin LoadedSkin = null; @@ -123,6 +310,21 @@ namespace ShiftOS.WinForms.Applications btn.FlatStyle = FlatStyle.Flat; btn.Click += (o, a) => { + foreach(var mth in this.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)) + { + foreach(var attrib in mth.GetCustomAttributes(false)) + { + if(attrib is ShifterMetaAttribute) + { + var meta = attrib as ShifterMetaAttribute; + if(meta.Meta == btn.Text) + { + mth?.Invoke(this, null); + } + } + } + } + PopulateSubcategories(c); }; @@ -164,6 +366,21 @@ namespace ShiftOS.WinForms.Applications } } + public void InvokeSetup(string cat) + { + foreach(var mth in this.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)) + { + foreach(var attr in mth.GetCustomAttributes(false)) + { + if(attr is ShifterMetaAttribute) + { + if ((attr as ShifterMetaAttribute).Meta == cat) + mth.Invoke(this, null); + } + } + } + } + public void PopulateBody(string cat, string subcat) { flbody.Controls.Clear(); @@ -233,6 +450,7 @@ namespace ShiftOS.WinForms.Applications width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString(); height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString(); } + InvokeSetup(cat); }; width.TextChanged += tc; @@ -247,7 +465,12 @@ namespace ShiftOS.WinForms.Applications labelHeight = str.Height; str.Text = c.Field.GetValue(LoadedSkin).ToString(); flbody.SetFlowBreak(str, true); - str.TextChanged += (o, a) => { c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100; }; + str.TextChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100; + + InvokeSetup(cat); + }; flbody.Controls.Add(str); str.Show(); } @@ -271,6 +494,8 @@ namespace ShiftOS.WinForms.Applications color.BackgroundImageLayout = layout; LoadedSkin.SkinImageLayouts[c.Field.GetImageName()] = layout; CodepointValue += 700; + InvokeSetup(cat); + }))); }; flbody.Controls.Add(color); @@ -316,6 +541,8 @@ namespace ShiftOS.WinForms.Applications width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString(); height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString(); } + InvokeSetup(cat); + }; width.TextChanged += tc; @@ -331,6 +558,8 @@ namespace ShiftOS.WinForms.Applications { c.Field.SetValue(LoadedSkin, check.Checked); CodepointValue += 50; + InvokeSetup(cat); + }; flbody.SetFlowBreak(check, true); @@ -377,6 +606,8 @@ namespace ShiftOS.WinForms.Applications c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); CodepointValue += 100; + InvokeSetup(cat); + }; style.SelectedIndexChanged += (o, a) => @@ -387,6 +618,8 @@ namespace ShiftOS.WinForms.Applications c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); CodepointValue += 50; + InvokeSetup(cat); + }; size.TextChanged += (o, a) => @@ -404,6 +637,8 @@ namespace ShiftOS.WinForms.Applications size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString(); } CodepointValue += 50; + InvokeSetup(cat); + }; flbody.Controls.Add(name); @@ -434,6 +669,8 @@ namespace ShiftOS.WinForms.Applications { color.BackColor = col; CodepointValue += 300; + InvokeSetup(cat); + }))); }; flbody.SetFlowBreak(color, true); @@ -457,6 +694,8 @@ namespace ShiftOS.WinForms.Applications cBox.SelectedIndexChanged += (o, a) => { c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text)); + InvokeSetup(cat); + }; labelHeight = cBox.Height; @@ -482,6 +721,8 @@ namespace ShiftOS.WinForms.Applications { c.Field.SetValue(LoadedSkin, name.SelectedIndex); CodepointValue += 75; + InvokeSetup(cat); + }; labelHeight = name.Height; flbody.Controls.Add(name); @@ -517,6 +758,8 @@ namespace ShiftOS.WinForms.Applications { width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString(); } + InvokeSetup(cat); + }; width.TextChanged += tc; diff --git a/ShiftOS.WinForms/Applications/Shifter.resx b/ShiftOS.WinForms/Applications/Shifter.resx index 1af7de1..f16904f 100644 --- a/ShiftOS.WinForms/Applications/Shifter.resx +++ b/ShiftOS.WinForms/Applications/Shifter.resx @@ -117,4 +117,56 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 127, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + 17, 17 + \ No newline at end of file diff --git a/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs b/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs index 28623ef..a31edd9 100644 --- a/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs +++ b/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs @@ -28,16 +28,16 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; -using static ShiftOS.Engine.SkinEngine; +using ShiftOS.Engine; using System.Windows.Forms; namespace ShiftOS.WinForms.Tools { public class ShiftOSMenuRenderer : ToolStripProfessionalRenderer { - public ShiftOSMenuRenderer() : base(new ShiftOSColorTable()) + public ShiftOSMenuRenderer() : base(new ShiftOSColorTable(ShiftOS.Engine.SkinEngine.LoadedSkin)) { - + } public ShiftOSMenuRenderer(ProfessionalColorTable table) : base(table) @@ -45,6 +45,26 @@ namespace ShiftOS.WinForms.Tools } + public ShiftOSMenuRenderer(Skin skn) : base(new ShiftOSColorTable(skn)) + { + + } + + public Skin LoadedSkin + { + get + { + if(ColorTable is ShiftOSColorTable) + { + return (ColorTable as ShiftOSColorTable).LoadedSkin; + } + else + { + return SkinEngine.LoadedSkin; + } + } + } + protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { if (e.Item.Tag?.ToString() == "applauncherbutton") @@ -99,6 +119,18 @@ namespace ShiftOS.WinForms.Tools public class ShiftOSColorTable : ProfessionalColorTable { + public ShiftOSColorTable(ShiftOS.Engine.Skin skn) + { + LoadedSkin = skn; + } + + public Skin LoadedSkin { get; private set; } + + public Image GetImage(string id) + { + return SkinEngine.GetImage(id); + } + public override Color ButtonSelectedHighlight { get { return LoadedSkin.Menu_ButtonSelectedHighlight; } @@ -327,6 +359,19 @@ namespace ShiftOS.WinForms.Tools public class AppLauncherColorTable : ProfessionalColorTable { + public Image GetImage(string id) + { + return SkinEngine.GetImage(id); + } + + public Skin LoadedSkin + { + get + { + return SkinEngine.LoadedSkin; + } + } + public override Color ButtonSelectedHighlight { get { return LoadedSkin.Menu_ButtonSelectedHighlight; } diff --git a/ShiftOS.WinForms/WindowBorder.cs b/ShiftOS.WinForms/WindowBorder.cs index 4fba470..4babbbd 100644 --- a/ShiftOS.WinForms/WindowBorder.cs +++ b/ShiftOS.WinForms/WindowBorder.cs @@ -129,7 +129,6 @@ namespace ShiftOS.WinForms this.pnlcontents.Controls.Add(this._parentWindow); this._parentWindow.Dock = DockStyle.Fill; - this._parentWindow.Show(); ControlManager.SetupControls(this._parentWindow); ParentWindow.OnSkinLoad(); @@ -139,9 +138,40 @@ namespace ShiftOS.WinForms Setup(); ParentWindow.OnUpgrade(); }; + Setup(); + this._parentWindow.TextChanged += (o, a) => + { + Setup(); + Desktop.ResetPanelButtons(); + + }; + + this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; + this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; - Desktop.ShowWindow(this); + if (!this.IsDialog) + { + Engine.AppearanceManager.OpenForms.Add(this); + } + SaveSystem.GameReady += () => + { + if (Shiftorium.UpgradeInstalled("wm_free_placement")) + { + AppearanceManager.Invoke(new Action(() => + { + this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; + this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; + + })); + } + AppearanceManager.Invoke(new Action(() => + { + Setup(); + })); + }; + + ParentWindow.OnLoad(); } /// @@ -178,46 +208,7 @@ namespace ShiftOS.WinForms public void WindowBorder_Load(object sender, EventArgs e) { this.DoubleBuffered = true; - - this._parentWindow.TextChanged += (o, a) => - { - Setup(); - Desktop.ResetPanelButtons(); - - }; - - this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; - this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; - - if (!this.IsDialog) - { - Engine.AppearanceManager.OpenForms.Add(this); - } - - SaveSystem.GameReady += () => - { - if (Shiftorium.UpgradeInstalled("wm_free_placement")) - { - AppearanceManager.Invoke(new Action(() => - { - this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; - this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; - - })); - } - AppearanceManager.Invoke(new Action(() => - { - Setup(); - })); - }; - - ControlManager.SetupControls(this); - - Setup(); - - var sWin = (IShiftOSWindow)ParentWindow; - - sWin.OnLoad(); + this._parentWindow.Show(); } /// diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs index cfcb6d3..4fcd185 100644 --- a/ShiftOS.WinForms/WinformsWindowManager.cs +++ b/ShiftOS.WinForms/WinformsWindowManager.cs @@ -120,8 +120,7 @@ namespace ShiftOS.WinForms var wb = new WindowBorder(form as UserControl); wb.IsDialog = true; - - wb.Show(); + Desktop.ShowWindow(wb); } public override void SetupWindow(IShiftOSWindow form) @@ -213,6 +212,7 @@ namespace ShiftOS.WinForms wb.FormClosed -= onClose; }; wb.FormClosed += onClose; + Desktop.ShowWindow(wb); SetupWindows(); } diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index 800b107..48b7c0b 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -64,10 +64,14 @@ namespace ShiftOS.Engine { public static class SkinEngine { - public static ImageLayout GetImageLayout(string img) { - if (LoadedSkin.SkinImageLayouts.ContainsKey(img)) { + public static ImageLayout GetImageLayout(string img) + { + if (LoadedSkin.SkinImageLayouts.ContainsKey(img)) + { return LoadedSkin.SkinImageLayouts[img]; - } else { + } + else + { LoadedSkin.SkinImageLayouts.Add(img, ImageLayout.Tile); return ImageLayout.Tile; } -- cgit v1.2.3 From 4d3eb794b532a13a24107e54947022aed841d165 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Apr 2017 10:57:40 -0400 Subject: Make the Shifter greet the user. --- ShiftOS.WinForms/Applications/Shifter.Designer.cs | 40 +++++++++++++++++++++++ ShiftOS.WinForms/Applications/Shifter.cs | 1 + ShiftOS.WinForms/Applications/Shifter.resx | 9 +++++ 3 files changed, 50 insertions(+) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.Designer.cs b/ShiftOS.WinForms/Applications/Shifter.Designer.cs index 4520e2a..f919834 100644 --- a/ShiftOS.WinForms/Applications/Shifter.Designer.cs +++ b/ShiftOS.WinForms/Applications/Shifter.Designer.cs @@ -92,6 +92,9 @@ namespace ShiftOS.WinForms.Applications this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox(); + this.pnlintro = new System.Windows.Forms.Panel(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); this.pnlpreview.SuspendLayout(); this.pnlwindow.SuspendLayout(); @@ -102,6 +105,7 @@ namespace ShiftOS.WinForms.Applications this.pnlcategoryholder.SuspendLayout(); this.mspreview.SuspendLayout(); this.tspreview.SuspendLayout(); + this.pnlintro.SuspendLayout(); this.SuspendLayout(); // // panel1 @@ -117,6 +121,7 @@ namespace ShiftOS.WinForms.Applications // // pnlpreview // + this.pnlpreview.Controls.Add(this.pnlintro); this.pnlpreview.Controls.Add(this.pnlwindow); this.pnlpreview.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlpreview.Location = new System.Drawing.Point(136, 0); @@ -464,6 +469,37 @@ namespace ShiftOS.WinForms.Applications this.toolStripTextBox1.Name = "toolStripTextBox1"; this.toolStripTextBox1.Size = new System.Drawing.Size(100, 25); // + // pnlintro + // + this.pnlintro.Controls.Add(this.label2); + this.pnlintro.Controls.Add(this.label1); + this.pnlintro.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlintro.Location = new System.Drawing.Point(0, 0); + this.pnlintro.Name = "pnlintro"; + this.pnlintro.Size = new System.Drawing.Size(757, 286); + this.pnlintro.TabIndex = 2; + // + // 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(757, 54); + this.label1.TabIndex = 0; + this.label1.Tag = "header2"; + this.label1.Text = "Welcome to the Shifter!"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label2 + // + this.label2.Dock = System.Windows.Forms.DockStyle.Fill; + this.label2.Location = new System.Drawing.Point(0, 54); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(757, 232); + this.label2.TabIndex = 1; + this.label2.Text = resources.GetString("label2.Text"); + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // Shifter // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -486,6 +522,7 @@ namespace ShiftOS.WinForms.Applications this.mspreview.PerformLayout(); this.tspreview.ResumeLayout(false); this.tspreview.PerformLayout(); + this.pnlintro.ResumeLayout(false); this.ResumeLayout(false); } @@ -531,5 +568,8 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.ToolStripButton toolStripButton1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripTextBox toolStripTextBox1; + private System.Windows.Forms.Panel pnlintro; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index e7ad768..e22956f 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -817,6 +817,7 @@ namespace ShiftOS.WinForms.Applications public void OnLoad() { + pnlintro.BringToFront(); } public void OnSkinLoad() diff --git a/ShiftOS.WinForms/Applications/Shifter.resx b/ShiftOS.WinForms/Applications/Shifter.resx index f16904f..9533980 100644 --- a/ShiftOS.WinForms/Applications/Shifter.resx +++ b/ShiftOS.WinForms/Applications/Shifter.resx @@ -117,6 +117,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The Shifter is a brilliant application for ShiftOS that allows you to customize almost every aspect of the user interface. + +To use the Shifter, simply select a category from the left, then a list of sub-categories will show up. Choose a sub-category, then a list of settings will appear. You can modify any one of these settings. A live preview of what you are editing will show, and you can use it to see what your new user experience will look like. + +When you are done, hit Apply Changes to apply your changes! + +You can also earn Codepoints through the Shifter. The more you tweak and customize, the more Codepoints you'll earn! Go nuts! Shift it your way! + 127, 17 -- cgit v1.2.3 From 6ec8e375c4b756bcd323df6babd4a4a74cd75904 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Apr 2017 13:06:13 -0400 Subject: Desktop preview --- ShiftOS.WinForms/Applications/Shifter.Designer.cs | 275 ++++++++++++++++++++++ ShiftOS.WinForms/Applications/Shifter.cs | 158 +++++++++++++ ShiftOS.WinForms/Applications/Shifter.resx | 39 +-- ShiftOS.WinForms/Tools/ControlManager.cs | 2 +- ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs | 14 +- ShiftOS.WinForms/WindowBorder.cs | 2 +- ShiftOS_TheReturn/ServerManager.cs | 12 +- 7 files changed, 478 insertions(+), 24 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.Designer.cs b/ShiftOS.WinForms/Applications/Shifter.Designer.cs index f919834..593f43d 100644 --- a/ShiftOS.WinForms/Applications/Shifter.Designer.cs +++ b/ShiftOS.WinForms/Applications/Shifter.Designer.cs @@ -95,6 +95,29 @@ namespace ShiftOS.WinForms.Applications this.pnlintro = new System.Windows.Forms.Panel(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); + this.pnldesktoppreview = new System.Windows.Forms.Panel(); + this.pnlscreensaver = new System.Windows.Forms.Panel(); + this.pnlssicon = new System.Windows.Forms.Panel(); + this.desktoppanel = new System.Windows.Forms.Panel(); + this.lbtime = new System.Windows.Forms.Label(); + this.panelbuttonholder = new System.Windows.Forms.FlowLayoutPanel(); + this.sysmenuholder = new System.Windows.Forms.Panel(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.apps = new System.Windows.Forms.ToolStripMenuItem(); + this.pnladvancedal = new System.Windows.Forms.Panel(); + this.flapps = new System.Windows.Forms.FlowLayoutPanel(); + this.flcategories = new System.Windows.Forms.FlowLayoutPanel(); + this.pnlalsystemactions = new System.Windows.Forms.Panel(); + this.btnshutdown = new System.Windows.Forms.Button(); + this.pnlstatus = new System.Windows.Forms.Panel(); + this.lbalstatus = new System.Windows.Forms.Label(); + this.item1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.item2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.item3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.item4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.item5ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shutdownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.separatorToolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.panel1.SuspendLayout(); this.pnlpreview.SuspendLayout(); this.pnlwindow.SuspendLayout(); @@ -106,6 +129,14 @@ namespace ShiftOS.WinForms.Applications this.mspreview.SuspendLayout(); this.tspreview.SuspendLayout(); this.pnlintro.SuspendLayout(); + this.pnldesktoppreview.SuspendLayout(); + this.pnlscreensaver.SuspendLayout(); + this.desktoppanel.SuspendLayout(); + this.sysmenuholder.SuspendLayout(); + this.menuStrip1.SuspendLayout(); + this.pnladvancedal.SuspendLayout(); + this.pnlalsystemactions.SuspendLayout(); + this.pnlstatus.SuspendLayout(); this.SuspendLayout(); // // panel1 @@ -121,6 +152,7 @@ namespace ShiftOS.WinForms.Applications // // pnlpreview // + this.pnlpreview.Controls.Add(this.pnldesktoppreview); this.pnlpreview.Controls.Add(this.pnlintro); this.pnlpreview.Controls.Add(this.pnlwindow); this.pnlpreview.Dock = System.Windows.Forms.DockStyle.Fill; @@ -500,6 +532,214 @@ namespace ShiftOS.WinForms.Applications this.label2.Text = resources.GetString("label2.Text"); this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // + // pnldesktoppreview + // + this.pnldesktoppreview.Controls.Add(this.pnlscreensaver); + this.pnldesktoppreview.Controls.Add(this.desktoppanel); + this.pnldesktoppreview.Controls.Add(this.pnladvancedal); + this.pnldesktoppreview.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnldesktoppreview.Location = new System.Drawing.Point(0, 0); + this.pnldesktoppreview.Name = "pnldesktoppreview"; + this.pnldesktoppreview.Size = new System.Drawing.Size(757, 286); + this.pnldesktoppreview.TabIndex = 2; + // + // pnlscreensaver + // + this.pnlscreensaver.Controls.Add(this.pnlssicon); + this.pnlscreensaver.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlscreensaver.Location = new System.Drawing.Point(0, 24); + this.pnlscreensaver.Name = "pnlscreensaver"; + this.pnlscreensaver.Size = new System.Drawing.Size(757, 262); + this.pnlscreensaver.TabIndex = 3; + this.pnlscreensaver.Visible = false; + // + // pnlssicon + // + this.pnlssicon.Location = new System.Drawing.Point(303, 495); + this.pnlssicon.Name = "pnlssicon"; + this.pnlssicon.Size = new System.Drawing.Size(200, 100); + this.pnlssicon.TabIndex = 0; + // + // desktoppanel + // + this.desktoppanel.BackColor = System.Drawing.Color.Green; + this.desktoppanel.Controls.Add(this.lbtime); + this.desktoppanel.Controls.Add(this.panelbuttonholder); + this.desktoppanel.Controls.Add(this.sysmenuholder); + this.desktoppanel.Dock = System.Windows.Forms.DockStyle.Top; + this.desktoppanel.Location = new System.Drawing.Point(0, 0); + this.desktoppanel.Name = "desktoppanel"; + this.desktoppanel.Size = new System.Drawing.Size(757, 24); + this.desktoppanel.TabIndex = 2; + // + // lbtime + // + this.lbtime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbtime.AutoSize = true; + this.lbtime.Location = new System.Drawing.Point(-536, 0); + this.lbtime.Name = "lbtime"; + this.lbtime.Size = new System.Drawing.Size(35, 13); + this.lbtime.TabIndex = 0; + this.lbtime.Text = "label1"; + this.lbtime.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // panelbuttonholder + // + this.panelbuttonholder.AutoSize = true; + this.panelbuttonholder.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.panelbuttonholder.Location = new System.Drawing.Point(107, -77); + this.panelbuttonholder.Name = "panelbuttonholder"; + this.panelbuttonholder.Size = new System.Drawing.Size(0, 0); + this.panelbuttonholder.TabIndex = 2; + // + // sysmenuholder + // + this.sysmenuholder.Controls.Add(this.menuStrip1); + this.sysmenuholder.Location = new System.Drawing.Point(12, 5); + this.sysmenuholder.Name = "sysmenuholder"; + this.sysmenuholder.Size = new System.Drawing.Size(68, 24); + this.sysmenuholder.TabIndex = 1; + // + // menuStrip1 + // + this.menuStrip1.Dock = System.Windows.Forms.DockStyle.Fill; + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.apps}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(0); + this.menuStrip1.Size = new System.Drawing.Size(68, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // apps + // + this.apps.AutoSize = false; + this.apps.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.item1ToolStripMenuItem, + this.item2ToolStripMenuItem, + this.item3ToolStripMenuItem, + this.item4ToolStripMenuItem, + this.item5ToolStripMenuItem, + this.separatorToolStripMenuItem1, + this.shutdownToolStripMenuItem}); + this.apps.Name = "apps"; + this.apps.Padding = new System.Windows.Forms.Padding(0); + this.apps.Size = new System.Drawing.Size(58, 20); + this.apps.Tag = "applauncherbutton"; + this.apps.Text = "ShiftOS"; + // + // pnladvancedal + // + this.pnladvancedal.Controls.Add(this.flapps); + this.pnladvancedal.Controls.Add(this.flcategories); + this.pnladvancedal.Controls.Add(this.pnlalsystemactions); + this.pnladvancedal.Controls.Add(this.pnlstatus); + this.pnladvancedal.Location = new System.Drawing.Point(0, -53); + this.pnladvancedal.Name = "pnladvancedal"; + this.pnladvancedal.Size = new System.Drawing.Size(433, 417); + this.pnladvancedal.TabIndex = 4; + this.pnladvancedal.Visible = false; + // + // flapps + // + this.flapps.Dock = System.Windows.Forms.DockStyle.Fill; + this.flapps.Location = new System.Drawing.Point(221, 58); + this.flapps.Name = "flapps"; + this.flapps.Size = new System.Drawing.Size(212, 328); + this.flapps.TabIndex = 3; + // + // flcategories + // + this.flcategories.Dock = System.Windows.Forms.DockStyle.Left; + this.flcategories.Location = new System.Drawing.Point(0, 58); + this.flcategories.Name = "flcategories"; + this.flcategories.Size = new System.Drawing.Size(221, 328); + this.flcategories.TabIndex = 2; + // + // pnlalsystemactions + // + this.pnlalsystemactions.Controls.Add(this.btnshutdown); + this.pnlalsystemactions.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlalsystemactions.Location = new System.Drawing.Point(0, 386); + this.pnlalsystemactions.Name = "pnlalsystemactions"; + this.pnlalsystemactions.Size = new System.Drawing.Size(433, 31); + this.pnlalsystemactions.TabIndex = 1; + // + // btnshutdown + // + this.btnshutdown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnshutdown.AutoSize = true; + this.btnshutdown.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnshutdown.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnshutdown.Location = new System.Drawing.Point(363, 3); + this.btnshutdown.Name = "btnshutdown"; + this.btnshutdown.Size = new System.Drawing.Size(67, 25); + this.btnshutdown.TabIndex = 0; + this.btnshutdown.Text = "Shutdown"; + this.btnshutdown.UseVisualStyleBackColor = true; + // + // pnlstatus + // + this.pnlstatus.Controls.Add(this.lbalstatus); + this.pnlstatus.Dock = System.Windows.Forms.DockStyle.Top; + this.pnlstatus.Location = new System.Drawing.Point(0, 0); + this.pnlstatus.Name = "pnlstatus"; + this.pnlstatus.Size = new System.Drawing.Size(433, 58); + this.pnlstatus.TabIndex = 0; + // + // lbalstatus + // + this.lbalstatus.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbalstatus.Location = new System.Drawing.Point(0, 0); + this.lbalstatus.Name = "lbalstatus"; + this.lbalstatus.Size = new System.Drawing.Size(433, 58); + this.lbalstatus.TabIndex = 0; + this.lbalstatus.Text = "michael@system\r\n0 Codepoints\r\n0 installed, 0 available"; + this.lbalstatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // item1ToolStripMenuItem + // + this.item1ToolStripMenuItem.Name = "item1ToolStripMenuItem"; + this.item1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.item1ToolStripMenuItem.Text = "Item 1"; + // + // item2ToolStripMenuItem + // + this.item2ToolStripMenuItem.Name = "item2ToolStripMenuItem"; + this.item2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.item2ToolStripMenuItem.Text = "Item 2"; + // + // item3ToolStripMenuItem + // + this.item3ToolStripMenuItem.Name = "item3ToolStripMenuItem"; + this.item3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.item3ToolStripMenuItem.Text = "Item 3"; + // + // item4ToolStripMenuItem + // + this.item4ToolStripMenuItem.Name = "item4ToolStripMenuItem"; + this.item4ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.item4ToolStripMenuItem.Text = "Item 4"; + // + // item5ToolStripMenuItem + // + this.item5ToolStripMenuItem.Name = "item5ToolStripMenuItem"; + this.item5ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.item5ToolStripMenuItem.Text = "Item 5"; + // + // shutdownToolStripMenuItem + // + this.shutdownToolStripMenuItem.Name = "shutdownToolStripMenuItem"; + this.shutdownToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.shutdownToolStripMenuItem.Text = "Shutdown"; + // + // separatorToolStripMenuItem1 + // + this.separatorToolStripMenuItem1.Name = "separatorToolStripMenuItem1"; + this.separatorToolStripMenuItem1.Size = new System.Drawing.Size(149, 6); + // // Shifter // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -523,6 +763,18 @@ namespace ShiftOS.WinForms.Applications this.tspreview.ResumeLayout(false); this.tspreview.PerformLayout(); this.pnlintro.ResumeLayout(false); + this.pnldesktoppreview.ResumeLayout(false); + this.pnlscreensaver.ResumeLayout(false); + this.desktoppanel.ResumeLayout(false); + this.desktoppanel.PerformLayout(); + this.sysmenuholder.ResumeLayout(false); + this.sysmenuholder.PerformLayout(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.pnladvancedal.ResumeLayout(false); + this.pnlalsystemactions.ResumeLayout(false); + this.pnlalsystemactions.PerformLayout(); + this.pnlstatus.ResumeLayout(false); this.ResumeLayout(false); } @@ -571,5 +823,28 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.Panel pnlintro; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel pnldesktoppreview; + private System.Windows.Forms.Panel pnlscreensaver; + private System.Windows.Forms.Panel pnlssicon; + private System.Windows.Forms.Panel desktoppanel; + private System.Windows.Forms.Label lbtime; + private System.Windows.Forms.FlowLayoutPanel panelbuttonholder; + private System.Windows.Forms.Panel sysmenuholder; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem apps; + private System.Windows.Forms.Panel pnladvancedal; + private System.Windows.Forms.FlowLayoutPanel flapps; + private System.Windows.Forms.FlowLayoutPanel flcategories; + private System.Windows.Forms.Panel pnlalsystemactions; + private System.Windows.Forms.Button btnshutdown; + private System.Windows.Forms.Panel pnlstatus; + private System.Windows.Forms.Label lbalstatus; + private System.Windows.Forms.ToolStripMenuItem item1ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem item2ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem item3ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem item4ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem item5ToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator separatorToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem shutdownToolStripMenuItem; } } \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index e22956f..600a9b2 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -47,6 +47,164 @@ namespace ShiftOS.WinForms.Applications PopulateShifter(); } + [ShifterMeta("Desktop")] + public void ResetDesktop() + { + pnldesktoppreview.BringToFront(); + pnldesktoppreview.Tag = "keepbg"; + SetupDesktop(); + } + + /// + /// Populates the panel buttons. + /// + /// The panel buttons. + public void PopulatePanelButtons() + { + if (DesktopFunctions.ShowDefaultElements == true) + { + panelbuttonholder.Controls.Clear(); + if (Shiftorium.IsInitiated == true) + { + if (Shiftorium.UpgradeInstalled("wm_panel_buttons")) + { + + var pnlbtn = new Panel(); + pnlbtn.Margin = new Padding(2, LoadedSkin.PanelButtonFromTop, 0, 0); + pnlbtn.BackColor = LoadedSkin.PanelButtonColor; + pnlbtn.BackgroundImage = GetImage("panelbutton"); + pnlbtn.BackgroundImageLayout = GetImageLayout("panelbutton"); + + var pnlbtntext = new Label(); + pnlbtntext.Text = "Panel Button Text"; + pnlbtntext.AutoSize = true; + pnlbtntext.Location = LoadedSkin.PanelButtonFromLeft; + pnlbtntext.ForeColor = LoadedSkin.PanelButtonTextColor; + pnlbtntext.BackColor = Color.Transparent; + + pnlbtn.BackColor = LoadedSkin.PanelButtonColor; + if (pnlbtn.BackgroundImage != null) + { + pnlbtntext.BackColor = Color.Transparent; + } + pnlbtn.Size = LoadedSkin.PanelButtonSize; + pnlbtn.Tag = "keepbg"; + pnlbtntext.Tag = "keepbg"; + pnlbtn.Controls.Add(pnlbtntext); + this.panelbuttonholder.Controls.Add(pnlbtn); + pnlbtn.Show(); + pnlbtntext.Show(); + + pnlbtntext.Font = LoadedSkin.PanelButtonFont; + + + + + } + } + } + + } + + /// + /// Setups the desktop. + /// + /// The desktop. + public void SetupDesktop() + { + if (DesktopFunctions.ShowDefaultElements == true) + { + desktoppanel.BackColor = Color.Green; + + //upgrades + + if (Shiftorium.IsInitiated == true) + { + desktoppanel.Visible = Shiftorium.UpgradeInstalled("desktop"); + lbtime.Visible = Shiftorium.UpgradeInstalled("desktop_clock_widget"); + + //skinning + lbtime.ForeColor = LoadedSkin.DesktopPanelClockColor; + + panelbuttonholder.Top = 0; + panelbuttonholder.Left = LoadedSkin.PanelButtonHolderFromLeft; + panelbuttonholder.Height = desktoppanel.Height; + panelbuttonholder.BackColor = Color.Transparent; + panelbuttonholder.Margin = new Padding(0, 0, 0, 0); + + sysmenuholder.Visible = Shiftorium.UpgradeInstalled("app_launcher"); + + //The Color Picker can give us transparent colors - which Windows Forms fucking despises when dealing with form backgrounds. + //To compensate, we must recreate the desktop color and make the alpha channel '255'. + pnldesktoppreview.BackColor = Color.FromArgb(LoadedSkin.DesktopColor.R, LoadedSkin.DesktopColor.G, LoadedSkin.DesktopColor.B); + //Not doing this will cause an ArgumentException. + + DitheringEngine.DitherImage(SkinEngine.GetImage("desktopbackground"), new Action((img) => + { + pnldesktoppreview.BackgroundImage = img; + })); + pnldesktoppreview.BackgroundImageLayout = GetImageLayout("desktopbackground"); + desktoppanel.BackColor = LoadedSkin.DesktopPanelColor; + + var pnlimg = GetImage("desktoppanel"); + if (pnlimg != null) + { + var bmp = new Bitmap(pnlimg); + bmp.MakeTransparent(Color.FromArgb(1, 0, 1)); + pnlimg = bmp; + } + + desktoppanel.BackgroundImage = pnlimg; + if (desktoppanel.BackgroundImage != null) + { + desktoppanel.BackColor = Color.Transparent; + } + var appimg = GetImage("applauncher"); + if (appimg != null) + { + var bmp = new Bitmap(appimg); + bmp.MakeTransparent(Color.FromArgb(1, 0, 1)); + appimg = bmp; + } + menuStrip1.BackgroundImage = appimg; + lbtime.ForeColor = LoadedSkin.DesktopPanelClockColor; + lbtime.Font = LoadedSkin.DesktopPanelClockFont; + if (desktoppanel.BackgroundImage == null) + { + lbtime.BackColor = LoadedSkin.DesktopPanelClockBackgroundColor; + } + else + { + lbtime.BackColor = Color.Transparent; + } + apps.Text = LoadedSkin.AppLauncherText; + sysmenuholder.Location = LoadedSkin.AppLauncherFromLeft; + sysmenuholder.Size = LoadedSkin.AppLauncherHolderSize; + apps.Size = sysmenuholder.Size; + menuStrip1.Renderer = new ShiftOSMenuRenderer(new AppLauncherColorTable(LoadedSkin)); + desktoppanel.BackgroundImageLayout = GetImageLayout("desktoppanel"); + desktoppanel.Height = LoadedSkin.DesktopPanelHeight; + if (LoadedSkin.DesktopPanelPosition == 1) + { + desktoppanel.Dock = DockStyle.Bottom; + } + else + { + desktoppanel.Dock = DockStyle.Top; + } + } + } + else + { + desktoppanel.Hide(); + } + + PopulatePanelButtons(); + } + + + + [ShifterMeta("Windows")] public void SetupWindowPreview() { diff --git a/ShiftOS.WinForms/Applications/Shifter.resx b/ShiftOS.WinForms/Applications/Shifter.resx index 9533980..c18f92a 100644 --- a/ShiftOS.WinForms/Applications/Shifter.resx +++ b/ShiftOS.WinForms/Applications/Shifter.resx @@ -117,20 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - The Shifter is a brilliant application for ShiftOS that allows you to customize almost every aspect of the user interface. - -To use the Shifter, simply select a category from the left, then a list of sub-categories will show up. Choose a sub-category, then a list of settings will appear. You can modify any one of these settings. A live preview of what you are editing will show, and you can use it to see what your new user experience will look like. - -When you are done, hit Apply Changes to apply your changes! - -You can also earn Codepoints through the Shifter. The more you tweak and customize, the more Codepoints you'll earn! Go nuts! Shift it your way! - + + 230, 17 + + + 127, 17 + + + 17, 17 + + + 17, 17 + 127, 17 - + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG @@ -145,7 +148,7 @@ You can also earn Codepoints through the Shifter. The more you tweak and customi TgDQASA1MVpwzwAAAABJRU5ErkJggg== - + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG @@ -160,7 +163,7 @@ You can also earn Codepoints through the Shifter. The more you tweak and customi TgDQASA1MVpwzwAAAABJRU5ErkJggg== - + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG @@ -175,7 +178,13 @@ You can also earn Codepoints through the Shifter. The more you tweak and customi TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - 17, 17 - + + The Shifter is a brilliant application for ShiftOS that allows you to customize almost every aspect of the user interface. + +To use the Shifter, simply select a category from the left, then a list of sub-categories will show up. Choose a sub-category, then a list of settings will appear. You can modify any one of these settings. A live preview of what you are editing will show, and you can use it to see what your new user experience will look like. + +When you are done, hit Apply Changes to apply your changes! + +You can also earn Codepoints through the Shifter. The more you tweak and customize, the more Codepoints you'll earn! Go nuts! Shift it your way! + \ No newline at end of file diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index 781e045..1c6f40c 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -277,7 +277,7 @@ namespace ShiftOS.WinForms.Tools { for (int i = 0; i < frm.Controls.Count; i++) { - SetupControls(frm.Controls[i], false); + SetupControls(frm.Controls[i], false); } }; diff --git a/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs b/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs index a31edd9..81e8c89 100644 --- a/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs +++ b/ShiftOS.WinForms/Tools/ShiftOSMenuRenderer.cs @@ -364,14 +364,18 @@ namespace ShiftOS.WinForms.Tools return SkinEngine.GetImage(id); } - public Skin LoadedSkin + public AppLauncherColorTable() { - get - { - return SkinEngine.LoadedSkin; - } + LoadedSkin = SkinEngine.LoadedSkin; + } + + public AppLauncherColorTable(Skin skn) + { + LoadedSkin = skn; } + public Skin LoadedSkin { get; private set; } + public override Color ButtonSelectedHighlight { get { return LoadedSkin.Menu_ButtonSelectedHighlight; } diff --git a/ShiftOS.WinForms/WindowBorder.cs b/ShiftOS.WinForms/WindowBorder.cs index e716803..e809f90 100644 --- a/ShiftOS.WinForms/WindowBorder.cs +++ b/ShiftOS.WinForms/WindowBorder.cs @@ -129,6 +129,7 @@ namespace ShiftOS.WinForms this.pnlcontents.Controls.Add(this._parentWindow); this._parentWindow.Dock = DockStyle.Fill; + this._parentWindow.Show(); ControlManager.SetupControls(this._parentWindow); ParentWindow.OnSkinLoad(); @@ -208,7 +209,6 @@ namespace ShiftOS.WinForms this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; ParentWindow.OnLoad(); - this._parentWindow.Show(); } /// diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 4fce247..d356600 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -34,6 +34,7 @@ using System.Threading; using ShiftOS; using static ShiftOS.Engine.SaveSystem; using Newtonsoft.Json; +using System.Net.Sockets; namespace ShiftOS.Engine { @@ -191,8 +192,15 @@ namespace ShiftOS.Engine } }; - client.Connect(mud_address, port); - + try + { + client.Connect(mud_address, port); + } + catch(SocketException ex) + { + System.Diagnostics.Debug.Print(ex.ToString()); + Initiate(mud_address, port); + } } public static void SendMessage(string name, string contents) -- cgit v1.2.3 From 25f83c8f191c0e451e2fc88b193d158517396f31 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Apr 2017 16:17:44 -0400 Subject: Fix bug with shifter and skin applying --- ShiftOS.WinForms/Applications/Shifter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 600a9b2..05ba638 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -832,7 +832,7 @@ namespace ShiftOS.WinForms.Applications }))); }; flbody.SetFlowBreak(color, true); - + color.Tag = "keepbg"; flbody.Controls.Add(color); color.Show(); } -- cgit v1.2.3 From c18c0fbc325b1c6a0864f88c6e2f4d2889d62e18 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 12 May 2017 20:32:28 -0400 Subject: dithering revamp --- ShiftOS.WinForms/Applications/Shifter.cs | 5 +- ShiftOS.WinForms/Program.cs | 1 + ShiftOS.WinForms/Tools/DitheringEngine.cs | 195 +++++++++++++----------------- ShiftOS.WinForms/WinformsDesktop.cs | 5 +- ShiftOS_TheReturn/Commands.cs | 17 +++ ShiftOS_TheReturn/Skinning.cs | 19 +++ 6 files changed, 123 insertions(+), 119 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 05ba638..edc3703 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -139,10 +139,7 @@ namespace ShiftOS.WinForms.Applications pnldesktoppreview.BackColor = Color.FromArgb(LoadedSkin.DesktopColor.R, LoadedSkin.DesktopColor.G, LoadedSkin.DesktopColor.B); //Not doing this will cause an ArgumentException. - DitheringEngine.DitherImage(SkinEngine.GetImage("desktopbackground"), new Action((img) => - { - pnldesktoppreview.BackgroundImage = img; - })); + pnldesktoppreview.BackgroundImage = SkinEngine.GetImage("desktopbackground"); pnldesktoppreview.BackgroundImageLayout = GetImageLayout("desktopbackground"); desktoppanel.BackColor = LoadedSkin.DesktopPanelColor; diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 256894d..73215d4 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -49,6 +49,7 @@ namespace ShiftOS.WinForms Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //if ANYONE puts code before those two winforms config lines they will be declared a drunky. - Michael + SkinEngine.SetPostProcessor(new DitheringSkinPostProcessor()); SaveSystem.PreDigitalSocietyConnection += () => { Action completed = null; diff --git a/ShiftOS.WinForms/Tools/DitheringEngine.cs b/ShiftOS.WinForms/Tools/DitheringEngine.cs index 8509a0b..f96a45a 100644 --- a/ShiftOS.WinForms/Tools/DitheringEngine.cs +++ b/ShiftOS.WinForms/Tools/DitheringEngine.cs @@ -33,6 +33,7 @@ using System.Drawing; using System.Threading; using ShiftOS.Engine; using System.Runtime.InteropServices; +using System.IO; namespace ShiftOS.WinForms.Tools { @@ -101,7 +102,7 @@ namespace ShiftOS.WinForms.Tools } } - public static void DitherColor(Color source, int width, int height, Action result) + public static Image DitherColor(Color source, int width, int height) { var bmp = new Bitmap(width + 1, height + 1); var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); @@ -115,7 +116,7 @@ namespace ShiftOS.WinForms.Tools } Marshal.Copy(rgb, 0, data.Scan0, rgb.Length); bmp.UnlockBits(data); - DitherImage(bmp, result); + return DitherImage(bmp); } @@ -226,15 +227,8 @@ namespace ShiftOS.WinForms.Tools #endif #if FLOYDSTEINBERG - public static void DitherImage(Image source, Action result) + public static Image DitherImage(Image source) { - if (source == null) - { - result?.Invoke(source); - return; - } - - var bmp = new Bitmap(source.Width, source.Height); var sourceBmp = (Bitmap)source; var sourceLck = sourceBmp.LockBits(new Rectangle(0, 0, sourceBmp.Width, sourceBmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); @@ -267,121 +261,80 @@ namespace ShiftOS.WinForms.Tools bool color_depth_floydsteinberg = Shiftorium.UpgradeInstalled("color_depth_floyd-steinberg_dithering"); bool dithering = Shiftorium.UpgradeInstalled("color_depth_dithering"); - for (int y = 0; y < (destLck.Height); y++) + if (!sixteenBits) { - for (int x = 0; x < (Math.Abs(destLck.Stride)); x += 3) + if (dithering == true) { - int i = getIndexFromXY(x, y, width); - byte red = sourceArr[i]; - byte green = sourceArr[i + 1]; - byte blue = sourceArr[i + 2]; - - Color oldc = Color.FromArgb(red, green, blue); - Color newc; - - if (sixteenBits) + if (false == true) { - newc = GetColor(oldc); + } else { - int gray = ((oldc.R + oldc.G + oldc.B) / 3); - - byte newgray = 0; - - if (dithering && !color_depth_floydsteinberg) - gray += error_r; - - - - if (eightBits) + int error = 0; + for (int i = 0; i < destArr.Length; i += 3) { - newgray = (byte)gray; - error_r = 0; - } - else if(sixBits) - { - newgray = (byte)(linear(gray, 0, 0xFF, 0, 0x3F) * 3); - error_r = newgray - gray; - } - else if (fourBits) - { - newgray = (byte)(linear(gray, 0, 0xFF, 0, 0xF) * 0xF); - error_r = newgray - gray; - } - else if (twoBits) - { - if (gray >= 191) - newgray = 0xFF; - else if (gray >= 127) - newgray = Color.LightGray.R; - else if (gray >= 64) - newgray = Color.DarkGray.R; - else - newgray = 0x00; - error_r = newgray - gray; - } - else - { - if (gray >= 127) - newgray = 0xFF; - else - newgray = 0x00; - error_r = newgray - gray; - } - newc = Color.FromArgb(newgray, newgray, newgray); - } + byte r = sourceArr[i]; + byte g = sourceArr[i + 1]; + byte b = sourceArr[i + 2]; - int nextIndex = getIndexFromXY(x + 3, y, width); - int nextRow = getIndexFromXY(x, y + 1, width); - int nextIndexOnNextRow = getIndexFromXY(x + 3, y + 1, width); - int prevIndexOnNextRow = getIndexFromXY(x - 3, y + 1, width); - - grays[i] = newc.R; - grays[i + 1] = newc.G; - grays[i + 2] = newc.B; - - if (dithering) - { - if (color_depth_floydsteinberg) - { - if (x + 3 < width) + int gray = (((r + g + b) / 3) + error); + int newgray = gray; + if (!eightBits) { - sourceArr[nextIndex] += (byte)((error_r * 7) / 16); - sourceArr[nextIndex + 1] += (byte)((error_r * 7) / 16); - sourceArr[nextIndex + 2] += (byte)((error_r * 7) / 16); - } - if (y + 1 < height) - { - sourceArr[nextRow] += (byte)((error_r) / 16); - sourceArr[nextRow + 1] += (byte)((error_r) / 16); - sourceArr[nextRow + 2] += (byte)((error_r) / 16); - } - if (x + 3 < width && y + 1 < height) - { - sourceArr[nextIndexOnNextRow] += (byte)((error_r * 3) / 16); - sourceArr[nextIndexOnNextRow + 1] += (byte)((error_r * 3) / 16); - sourceArr[nextIndexOnNextRow + 2] += (byte)((error_r * 3) / 16); - + if (sixBits) + { + newgray = gray >> 2; + } + else + { + if (fourBits) + { + newgray = (int)linear(gray, 0, 255, 0, 63) * 4; + } + else + { + if (twoBits) + { + if (gray > 127 + 63) + { + newgray = 255; + } + else if (gray > 127) + newgray = 127 + 63; + else if (gray > 63) + { + newgray = 127; + } + else if (gray > 0) + newgray = 63; + else + newgray = 0; + } + else + { + if (gray > 127) + newgray = 255; + else + newgray = 0; + } + } + } } - if (x - 3 > 0 && y + 1 < height) - { - sourceArr[prevIndexOnNextRow] += (byte)((error_r * 5) / 16); - sourceArr[prevIndexOnNextRow + 1] += (byte)((error_r * 5) / 16); - sourceArr[prevIndexOnNextRow + 2] += (byte)((error_r * 5) / 16); + if (newgray > 255) + newgray = 255; + if (newgray < 0) + newgray = 0; + error = gray - newgray; + destArr[i] = (byte)newgray; + destArr[i+1] = (byte)newgray; + destArr[i+2] = (byte)newgray; - } } } } } - for (int i = 0; i < destArr.Length - 3; i++) - { - destArr[i] = grays[i]; - - } - Marshal.Copy(destArr, 0, destPtr, destBytes); @@ -389,8 +342,7 @@ namespace ShiftOS.WinForms.Tools - Desktop.InvokeOnWorkerThread(new Action(() => { result?.Invoke(bmp); })); - + return bmp; } #endif @@ -399,4 +351,25 @@ namespace ShiftOS.WinForms.Tools return (width * y) + x; } } + + public class DitheringSkinPostProcessor : ISkinPostProcessor + { + public byte[] ProcessImage(byte[] original) + { + try + { + var img = SkinEngine.ImageFromBinary(original); + var dithered = DitheringEngine.DitherImage(img); + using (var mstr = new MemoryStream()) + { + dithered.Save(mstr, System.Drawing.Imaging.ImageFormat.Bmp); + return mstr.ToArray(); + } + } + catch + { + return original; + } + } + } } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 6825f34..4efef1b 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -390,10 +390,7 @@ namespace ShiftOS.WinForms this.BackColor = Color.FromArgb(LoadedSkin.DesktopColor.R, LoadedSkin.DesktopColor.G, LoadedSkin.DesktopColor.B); //Not doing this will cause an ArgumentException. - DitheringEngine.DitherImage(SkinEngine.GetImage("desktopbackground"), new Action((img) => - { - this.BackgroundImage = img; - })); + this.BackgroundImage = SkinEngine.GetImage("desktopbackground"); this.BackgroundImageLayout = GetImageLayout("desktopbackground"); desktoppanel.BackColor = LoadedSkin.DesktopPanelColor; diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index d622bb9..5b7674a 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -233,6 +233,23 @@ namespace ShiftOS.Engine [Namespace("dev")] public static class ShiftOSDevCommands { + [Command("buy")] + public static bool UnlockUpgrade(Dictionary args) + { + string upg = args["id"].ToString(); + try + { + SaveSystem.CurrentSave.Upgrades[upg] = true; + Shiftorium.InvokeUpgradeInstalled(); + SaveSystem.SaveGame(); + } + catch + { + Console.WriteLine("Upgrade not found."); + } + return true; + } + [Command("rock", description = "A little surprise for unstable builds...")] public static bool ThrowASandwichingRock() { diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index b731c4f..548e80f 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -66,6 +66,13 @@ namespace ShiftOS.Engine public static class SkinEngine { + private static ISkinPostProcessor processor = null; + + public static void SetPostProcessor(ISkinPostProcessor _processor) + { + processor = _processor; + } + public static ImageLayout GetImageLayout(string img) { if (LoadedSkin.SkinImageLayouts.ContainsKey(img)) @@ -93,6 +100,8 @@ namespace ShiftOS.Engine if (iattr.Name == img) { byte[] image = (byte[])field.GetValue(LoadedSkin); + if (processor != null) + image = processor.ProcessImage(image); return ImageFromBinary(image); } } @@ -1323,6 +1332,16 @@ namespace ShiftOS.Engine public string Category { get; set; } } + public interface ISkinPostProcessor + { + /// + /// Perform algorithmic operations at the bit level on a ShiftOS skin image. + /// + /// The image, as loaded by the engine, as a 32-bit ARGB byte array. + /// The processed image. + byte[] ProcessImage(byte[] original); + } + public class ShifterMetaAttribute : Attribute { -- cgit v1.2.3 From 6747c63e2c8c5a274846da7200c50a444b725d28 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 20 May 2017 16:09:50 -0400 Subject: Tiny skinning fixes. --- ShiftOS.WinForms/Applications/Shifter.cs | 7 +- ShiftOS.WinForms/Tools/ControlManager.cs | 33 +++- ShiftOS_TheReturn/UserManagementCommands.cs | 238 ++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+), 13 deletions(-) create mode 100644 ShiftOS_TheReturn/UserManagementCommands.cs (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index edc3703..acb64a5 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -814,15 +814,12 @@ namespace ShiftOS.WinForms.Applications ControlManager.SetupControl(color); color.BackColor = ((Color)c.Field.GetValue(LoadedSkin)); - color.BackColorChanged += (o, a) => - { - c.Field.SetValue(LoadedSkin, color.BackColor); - }; color.Click += (o, a) => { - AppearanceManager.SetupDialog(new ColorPicker(color.BackColor, c.Name, new Action((col) => + AppearanceManager.SetupDialog(new ColorPicker((Color)c.Field.GetValue(LoadedSkin), c.Name, new Action((col) => { color.BackColor = col; + c.Field.SetValue(LoadedSkin, col); CodepointValue += 300; InvokeSetup(cat); diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index 4f888ab..fc9567d 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -220,13 +220,22 @@ namespace ShiftOS.WinForms.Tools Desktop.InvokeOnWorkerThread(() => { Button b = ctrl as Button; - b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor; - b.BackgroundImage = SkinEngine.GetImage("buttonidle"); - b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle"); + if (!b.Tag.ToString().ToLower().Contains("keepbg")) + { + b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor; + b.BackgroundImage = SkinEngine.GetImage("buttonidle"); + b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle"); + } b.FlatAppearance.BorderSize = SkinEngine.LoadedSkin.ButtonBorderWidth; - b.FlatAppearance.BorderColor = SkinEngine.LoadedSkin.ButtonForegroundColor; - b.ForeColor = SkinEngine.LoadedSkin.ButtonForegroundColor; - b.Font = SkinEngine.LoadedSkin.ButtonTextFont; + if (!b.Tag.ToString().ToLower().Contains("keepfg")) + { + b.FlatAppearance.BorderColor = SkinEngine.LoadedSkin.ButtonForegroundColor; + b.ForeColor = SkinEngine.LoadedSkin.ButtonForegroundColor; + } + if(!b.Tag.ToString().ToLower().Contains("keepfont")) + b.Font = SkinEngine.LoadedSkin.ButtonTextFont; + + Color orig_bg = b.BackColor; b.MouseEnter += (o, a) => { @@ -236,13 +245,13 @@ namespace ShiftOS.WinForms.Tools }; b.MouseLeave += (o, a) => { - b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor; + b.BackColor = orig_bg; b.BackgroundImage = SkinEngine.GetImage("buttonidle"); b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle"); }; b.MouseUp += (o, a) => { - b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor; + b.BackColor = orig_bg; b.BackgroundImage = SkinEngine.GetImage("buttonidle"); b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle"); }; @@ -257,6 +266,14 @@ namespace ShiftOS.WinForms.Tools }); } + if(ctrl is TextBox) + { + Desktop.InvokeOnWorkerThread(() => + { + (ctrl as TextBox).BorderStyle = BorderStyle.FixedSingle; + }); + } + ctrl.KeyDown += (o, a) => { if (a.Control && a.KeyCode == Keys.T) diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs new file mode 100644 index 0000000..a64c99c --- /dev/null +++ b/ShiftOS_TheReturn/UserManagementCommands.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Objects; + +namespace ShiftOS.Engine +{ + /// + /// Administrative user management terminal commands. + /// + [Namespace("admin")] + [KernelMode] + [RequiresUpgrade("mud_fundamentals")] + public static class AdminUserManagementCommands + { + /// + /// Add a user to the system. + /// + /// Command arguments. + /// Command result. + [Command("add", description = "Add a user to the system.", usage ="name:")] + [RequiresArgument("name")] + public static bool AddUser(Dictionary args) + { + string name = args["name"].ToString(); + if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==name) != null) + { + Console.WriteLine("Error: User already exists."); + return true; + } + + var user = new ClientSave + { + Username = name, + Password = "", + Permissions = UserPermissions.User + }; + SaveSystem.CurrentSave.Users.Add(user); + Console.WriteLine($"Creating new user \"{name}\" with no password and User permissions."); + SaveSystem.SaveGame(); + return true; + } + + /// + /// Remove a user from the system. + /// + /// Command arguments. + /// Command result. + + [Command("remove", description = "Remove a user from the system.", usage = "name:")] + [RequiresArgument("name")] + public static bool RemoveUser(Dictionary args) + { + string name = args["name"].ToString(); + if (SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name) == null) + { + Console.WriteLine("Error: User doesn't exist."); + return true; + } + + var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name); + if(user.Username != SaveSystem.CurrentUser.Username) + { + Console.WriteLine("Error: Cannot remove yourself."); + return true; + } + SaveSystem.CurrentSave.Users.Remove(user); + Console.WriteLine($"Removing user \"{name}\" from system..."); + SaveSystem.SaveGame(); + return true; + } + + + + /// + /// Set access control level for a user. + /// + /// Command arguments. + /// Command result. + + [Command("set_acl")] + [RequiresArgument("user")] + [RequiresArgument("val")] + public static bool SetUserPermission(Dictionary args) + { + int permission = 0; + string username = args["user"].ToString(); + try + { + permission = Convert.ToInt32(args["val"].ToString()); + } + catch + { + Console.WriteLine("Error: Permission value must be an integer."); + return true; + } + + if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==username) == null) + { + Console.WriteLine("Error: User not found."); + return true; + } + + UserPermissions uperm = UserPermissions.Guest; + + switch (permission) + { + case 0: + uperm = UserPermissions.Guest; + break; + case 1: + uperm = UserPermissions.User; + break; + case 2: + uperm = UserPermissions.Admin; + break; + case 3: + uperm = UserPermissions.Root; + break; + default: + Console.WriteLine("Permission value must be between 0 and 4."); + return true; + } + + //Permissions are backwards... oops... + if(uperm < SaveSystem.CurrentUser.Permissions) + { + Console.WriteLine("Error: Cannot set user permissions to values greater than your own!"); + return true; + } + + var oldperm = SaveSystem.Users.FirstOrDefault(x => x.Username == username).Permissions; + if (SaveSystem.CurrentUser.Permissions > oldperm) + { + Console.WriteLine("Error: Can't set the permission of this user. They have more rights than you."); + return true; + } + + SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == username).Permissions = uperm; + Console.WriteLine("User permissions updated."); + return true; + } + + /// + /// List all users in the system. + /// + /// Command arguments. + /// Command result. + + [Command("users", description = "Get a list of all users on the system.")] + public static bool GetUsers() + { + foreach (var u in SaveSystem.CurrentSave.Users) + { + if (u.Username == SaveSystem.CurrentUser.Username) + { + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + } + else + { + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + ConsoleEx.Bold = false; + } + Console.WriteLine(u.Username); + } + return true; + } + } + + /// + /// Non-administrative user management terminal commands. + /// + [Namespace("user")] + [RequiresUpgrade("mud_fundamentals")] + public static class UserManagementCommands + { + /// + /// Log in as another user. + /// + /// Command arguments. + /// Command result. + [Command("login", description = "Log in as another user.")] + [RequiresArgument("user")] + [RequiresArgument("pass")] + public static bool Login(Dictionary args) + { + string user = args["user"].ToString(); + string pass = args["pass"].ToString(); + + var usr = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == user); + if(usr==null) + { + Console.WriteLine("Error: No such user."); + return true; + } + + if (usr.Password != pass) + { + Console.WriteLine("Access denied."); + return true; + } + + SaveSystem.CurrentUser = usr; + Console.WriteLine("Access granted."); + return true; + } + + /// + /// Set the password for the current user. + /// + /// Command arguments. + /// Command result. + [Command("setpass", description ="Allows you to set your password to a new value.", usage ="old:,new:")] + [RequiresArgument("old")] + [RequiresArgument("new")] + public static bool SetPassword(Dictionary args) + { + string old = args["old"].ToString(); + string newpass = args["new"].ToString(); + + if(old == SaveSystem.CurrentUser.Password) + { + SaveSystem.CurrentUser.Password = newpass; + SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == SaveSystem.CurrentUser.Username).Password = newpass; + Console.WriteLine("Password set successfully."); + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Passwords do not match."); + } + return true; + } + } +} -- cgit v1.2.3 From 97e22b35ada5898fdcb2556628f764d927cff913 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 26 May 2017 17:06:38 -0400 Subject: SLIGHT optimizations? --- ShiftOS.WinForms/Applications/Shifter.cs | 679 ++++++++++++----------- ShiftOS.WinForms/Applications/Terminal.cs | 4 + ShiftOS.WinForms/Servers/RemoteTerminalServer.cs | 161 ++++++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 1 + ShiftOS.WinForms/Tools/ControlManager.cs | 13 +- ShiftOS_TheReturn/Localization.cs | 4 - ShiftOS_TheReturn/Server.cs | 40 ++ ShiftOS_TheReturn/ServerManager.cs | 62 +++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + ShiftOS_TheReturn/TerminalBackend.cs | 9 +- 10 files changed, 635 insertions(+), 339 deletions(-) create mode 100644 ShiftOS.WinForms/Servers/RemoteTerminalServer.cs create mode 100644 ShiftOS_TheReturn/Server.cs (limited to 'ShiftOS.WinForms/Applications/Shifter.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index acb64a5..1a59c80 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -31,6 +31,8 @@ using System.Reflection; using System.Windows.Forms; using ShiftOS.Engine; using ShiftOS.WinForms.Tools; +using System.Linq; +using System.Threading; namespace ShiftOS.WinForms.Applications { @@ -540,400 +542,425 @@ namespace ShiftOS.WinForms.Applications { flbody.Controls.Clear(); - List cats = new List(); + IEnumerable cats = this.settings.Where(x => x.SubCategory == subcat && x.Category == cat && x.Field.FlagFullfilled(LoadedSkin)).OrderBy(x=>x.Name); - foreach (var c in this.settings) + new Thread(() => { - if (c.SubCategory == subcat && c.Category == cat) + foreach (var c in cats) { - if (c.Field.FlagFullfilled(LoadedSkin)) + Label lbl = null; + int labelHeight = 0; + Desktop.InvokeOnWorkerThread(() => { - if (!cats.Contains(c)) - { - cats.Add(c); - } - } - } - } - - foreach(var c in cats) - { - var lbl = new Label(); - int labelHeight = 0; - lbl.AutoSize = true; - lbl.Text = c.Name + ":"; - flbody.Controls.Add(lbl); - lbl.TextAlign = ContentAlignment.MiddleLeft; - lbl.Show(); - //Cool - label's in. - if(c.Field.FieldType == typeof(Point)) - { - var width = new TextBox(); - var height = new TextBox(); - labelHeight = width.Height; //irony? - width.Width = 30; - height.Width = width.Width; - width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString(); - height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString(); - flbody.SetFlowBreak(height, true); - ControlManager.SetupControl(width); - ControlManager.SetupControl(height); - - flbody.Controls.Add(width); - width.Show(); - flbody.Controls.Add(height); - height.Show(); - - EventHandler tc = (o, a) => + lbl = new Label(); + lbl.AutoSize = true; + lbl.Text = c.Name + ":"; + flbody.Controls.Add(lbl); + lbl.TextAlign = ContentAlignment.MiddleLeft; + lbl.Show(); + }); + //Cool - label's in. + if (c.Field.FieldType == typeof(Point)) { - try + TextBox width = null; + TextBox height = null; + Desktop.InvokeOnWorkerThread(() => { - int x = Convert.ToInt32(width.Text); - int y = Convert.ToInt32(height.Text); + width = new TextBox(); + height = new TextBox(); + labelHeight = width.Height; //irony? + width.Width = 30; + height.Width = width.Width; + width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString(); + height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString(); + flbody.SetFlowBreak(height, true); + ControlManager.SetupControl(width); + ControlManager.SetupControl(height); - int oldx = ((Point)c.Field.GetValue(this.LoadedSkin)).X; - int oldy = ((Point)c.Field.GetValue(this.LoadedSkin)).Y; + flbody.Controls.Add(width); + width.Show(); + flbody.Controls.Add(height); + height.Show(); - if(x != oldx || y != oldy) + EventHandler tc = (o, a) => { - c.Field.SetValue(LoadedSkin, new Point(x, y)); - CodepointValue += 200; - } - } - catch - { - width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString(); - height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString(); - } - InvokeSetup(cat); - }; + try + { + int x = Convert.ToInt32(width.Text); + int y = Convert.ToInt32(height.Text); - width.TextChanged += tc; - height.TextChanged += tc; + int oldx = ((Point)c.Field.GetValue(this.LoadedSkin)).X; + int oldy = ((Point)c.Field.GetValue(this.LoadedSkin)).Y; - } - else if(c.Field.FieldType == typeof(string)) - { - var str = new TextBox(); - str.Width = 120; - ControlManager.SetupControl(str); - labelHeight = str.Height; - str.Text = c.Field.GetValue(LoadedSkin).ToString(); - flbody.SetFlowBreak(str, true); - str.TextChanged += (o, a) => - { - c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100; + if (x != oldx || y != oldy) + { + c.Field.SetValue(LoadedSkin, new Point(x, y)); + CodepointValue += 200; + } + } + catch + { + width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString(); + height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString(); + } + InvokeSetup(cat); + }; - InvokeSetup(cat); - }; - flbody.Controls.Add(str); - str.Show(); - } - else if(c.Field.FieldType == typeof(byte[])) - { - //We'll assume that this is an image file. - var color = new Button(); - color.Width = 40; - labelHeight = color.Height; - //just so it's flat like the system. - ControlManager.SetupControl(color); - flbody.SetFlowBreak(color, true); - - color.BackgroundImage = SkinEngine.ImageFromBinary((byte[])c.Field.GetValue(this.LoadedSkin)); - color.Click += (o, a) => + width.TextChanged += tc; + height.TextChanged += tc; + }); + } + else if (c.Field.FieldType == typeof(string)) { - AppearanceManager.SetupDialog(new GraphicPicker(color.BackgroundImage, c.Name, GetLayout(c.Field.GetImageName()), new Action((col, gdiImg, layout) => + Desktop.InvokeOnWorkerThread(() => { - c.Field.SetValue(LoadedSkin, col); - color.BackgroundImage = SkinEngine.ImageFromBinary(col); - color.BackgroundImageLayout = layout; - LoadedSkin.SkinImageLayouts[c.Field.GetImageName()] = layout; - CodepointValue += 700; - InvokeSetup(cat); - - }))); - }; - flbody.Controls.Add(color); - color.Show(); - } - else if (c.Field.FieldType == typeof(Size)) - { - var width = new TextBox(); - var height = new TextBox(); - width.Width = 30; - height.Width = width.Width; - labelHeight = width.Height; - flbody.SetFlowBreak(height, true); - - width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString(); - height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString(); - ControlManager.SetupControl(width); - ControlManager.SetupControl(height); - - flbody.Controls.Add(width); - width.Show(); - flbody.Controls.Add(height); - height.Show(); - - EventHandler tc = (o, a) => + var str = new TextBox(); + str.Width = 120; + ControlManager.SetupControl(str); + labelHeight = str.Height; + str.Text = c.Field.GetValue(LoadedSkin).ToString(); + flbody.SetFlowBreak(str, true); + str.TextChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100; + + InvokeSetup(cat); + }; + flbody.Controls.Add(str); + str.Show(); + }); + } + else if (c.Field.FieldType == typeof(byte[])) { - try + Desktop.InvokeOnWorkerThread(() => { - int x = Convert.ToInt32(width.Text); - int y = Convert.ToInt32(height.Text); - - int oldx = ((Size)c.Field.GetValue(this.LoadedSkin)).Width; - int oldy = ((Size)c.Field.GetValue(this.LoadedSkin)).Height; - - if (x != oldx || y != oldy) + //We'll assume that this is an image file. + var color = new Button(); + color.Width = 40; + labelHeight = color.Height; + //just so it's flat like the system. + ControlManager.SetupControl(color); + flbody.SetFlowBreak(color, true); + + color.BackgroundImage = SkinEngine.ImageFromBinary((byte[])c.Field.GetValue(this.LoadedSkin)); + color.Click += (o, a) => { - c.Field.SetValue(LoadedSkin, new Size(x, y)); - CodepointValue += 200; - } - } - catch + AppearanceManager.SetupDialog(new GraphicPicker(color.BackgroundImage, c.Name, GetLayout(c.Field.GetImageName()), new Action((col, gdiImg, layout) => + { + c.Field.SetValue(LoadedSkin, col); + color.BackgroundImage = SkinEngine.ImageFromBinary(col); + color.BackgroundImageLayout = layout; + LoadedSkin.SkinImageLayouts[c.Field.GetImageName()] = layout; + CodepointValue += 700; + InvokeSetup(cat); + + }))); + }; + flbody.Controls.Add(color); + color.Show(); + }); + } + else if (c.Field.FieldType == typeof(Size)) + { + Desktop.InvokeOnWorkerThread(() => { + var width = new TextBox(); + var height = new TextBox(); + width.Width = 30; + height.Width = width.Width; + labelHeight = width.Height; + flbody.SetFlowBreak(height, true); + width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString(); height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString(); - } - InvokeSetup(cat); + ControlManager.SetupControl(width); + ControlManager.SetupControl(height); - }; + flbody.Controls.Add(width); + width.Show(); + flbody.Controls.Add(height); + height.Show(); - width.TextChanged += tc; - height.TextChanged += tc; + EventHandler tc = (o, a) => + { + try + { + int x = Convert.ToInt32(width.Text); + int y = Convert.ToInt32(height.Text); - } - else if(c.Field.FieldType == typeof(bool)) - { - var check = new CheckBox(); - check.Checked = ((bool)c.Field.GetValue(LoadedSkin)); - labelHeight = check.Height; - check.CheckedChanged += (o, a) => - { - c.Field.SetValue(LoadedSkin, check.Checked); - CodepointValue += 50; - InvokeSetup(cat); + int oldx = ((Size)c.Field.GetValue(this.LoadedSkin)).Width; + int oldy = ((Size)c.Field.GetValue(this.LoadedSkin)).Height; - }; - flbody.SetFlowBreak(check, true); + if (x != oldx || y != oldy) + { + c.Field.SetValue(LoadedSkin, new Size(x, y)); + CodepointValue += 200; + } + } + catch + { + width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString(); + height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString(); + } + InvokeSetup(cat); - flbody.Controls.Add(check); - check.Show(); - } - else if(c.Field.FieldType == typeof(Font)) - { - var name = new ComboBox(); - var size = new TextBox(); - var style = new ComboBox(); - - name.Width = 120; - labelHeight = name.Height; - size.Width = 40; - style.Width = 80; - flbody.SetFlowBreak(style, true); - - ControlManager.SetupControl(name); - ControlManager.SetupControl(size); - ControlManager.SetupControl(style); - - //populate the font name box - foreach(var font in FontFamily.Families) - { - name.Items.Add(font.Name); + }; + + width.TextChanged += tc; + height.TextChanged += tc; + }); } - name.Text = ((Font)c.Field.GetValue(LoadedSkin)).Name; + else if (c.Field.FieldType == typeof(bool)) + { + Desktop.InvokeOnWorkerThread(() => + { + var check = new CheckBox(); + check.Checked = ((bool)c.Field.GetValue(LoadedSkin)); + labelHeight = check.Height; + check.CheckedChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, check.Checked); + CodepointValue += 50; + InvokeSetup(cat); - size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString(); + }; + flbody.SetFlowBreak(check, true); - //populate the style box - foreach(var s in (FontStyle[])Enum.GetValues(typeof(FontStyle))) - { - style.Items.Add(s.ToString()); + flbody.Controls.Add(check); + check.Show(); + }); } - style.Text = ((Font)c.Field.GetValue(LoadedSkin)).Style.ToString(); - - name.SelectedIndexChanged += (o, a) => + else if (c.Field.FieldType == typeof(Font)) { - var en = (FontStyle[])Enum.GetValues(typeof(FontStyle)); + Desktop.InvokeOnWorkerThread(() => + { + var name = new ComboBox(); + var size = new TextBox(); + var style = new ComboBox(); + + name.Width = 120; + labelHeight = name.Height; + size.Width = 40; + style.Width = 80; + flbody.SetFlowBreak(style, true); + + ControlManager.SetupControl(name); + ControlManager.SetupControl(size); + ControlManager.SetupControl(style); + + //populate the font name box + foreach (var font in FontFamily.Families) + { + name.Items.Add(font.Name); + } + name.Text = ((Font)c.Field.GetValue(LoadedSkin)).Name; - var f = en[style.SelectedIndex]; + size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString(); - c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); - CodepointValue += 100; - InvokeSetup(cat); + //populate the style box + foreach (var s in (FontStyle[])Enum.GetValues(typeof(FontStyle))) + { + style.Items.Add(s.ToString()); + } + style.Text = ((Font)c.Field.GetValue(LoadedSkin)).Style.ToString(); - }; + name.SelectedIndexChanged += (o, a) => + { + var en = (FontStyle[])Enum.GetValues(typeof(FontStyle)); - style.SelectedIndexChanged += (o, a) => - { - var en = (FontStyle[])Enum.GetValues(typeof(FontStyle)); + var f = en[style.SelectedIndex]; - var f = en[style.SelectedIndex]; + c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); + CodepointValue += 100; + InvokeSetup(cat); - c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); - CodepointValue += 50; - InvokeSetup(cat); + }; - }; + style.SelectedIndexChanged += (o, a) => + { + var en = (FontStyle[])Enum.GetValues(typeof(FontStyle)); - size.TextChanged += (o, a) => - { - try - { - var en = (FontStyle[])Enum.GetValues(typeof(FontStyle)); + var f = en[style.SelectedIndex]; - var f = en[style.SelectedIndex]; + c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); + CodepointValue += 50; + InvokeSetup(cat); - c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); - } - catch - { - size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString(); - } - CodepointValue += 50; - InvokeSetup(cat); + }; - }; + size.TextChanged += (o, a) => + { + try + { + var en = (FontStyle[])Enum.GetValues(typeof(FontStyle)); - flbody.Controls.Add(name); - flbody.Controls.Add(size); - flbody.Controls.Add(style); + var f = en[style.SelectedIndex]; - name.Show(); - size.Show(); - style.Show(); + c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f)); + } + catch + { + size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString(); + } + CodepointValue += 50; + InvokeSetup(cat); - } - else if(c.Field.FieldType == typeof(Color)) - { - var color = new Button(); - color.Width = 40; - labelHeight = color.Height; - //just so it's flat like the system. - ControlManager.SetupControl(color); - - color.BackColor = ((Color)c.Field.GetValue(LoadedSkin)); - color.Click += (o, a) => - { - AppearanceManager.SetupDialog(new ColorPicker((Color)c.Field.GetValue(LoadedSkin), c.Name, new Action((col) => - { - color.BackColor = col; - c.Field.SetValue(LoadedSkin, col); - CodepointValue += 300; - InvokeSetup(cat); - - }))); - }; - flbody.SetFlowBreak(color, true); - color.Tag = "keepbg"; - flbody.Controls.Add(color); - color.Show(); - } - else if(c.Field.FieldType.IsEnum == true) - { - var cBox = new ComboBox(); - cBox.Width = 150; - ControlManager.SetupControl(cBox); + }; + + flbody.Controls.Add(name); + flbody.Controls.Add(size); + flbody.Controls.Add(style); - foreach(var itm in Enum.GetNames(c.Field.FieldType)) + name.Show(); + size.Show(); + style.Show(); + }); + } + else if (c.Field.FieldType == typeof(Color)) { - cBox.Items.Add(itm); + Desktop.InvokeOnWorkerThread(() => + { + var color = new Button(); + color.Width = 40; + labelHeight = color.Height; + //just so it's flat like the system. + ControlManager.SetupControl(color); + + color.BackColor = ((Color)c.Field.GetValue(LoadedSkin)); + color.Click += (o, a) => + { + AppearanceManager.SetupDialog(new ColorPicker((Color)c.Field.GetValue(LoadedSkin), c.Name, new Action((col) => + { + color.BackColor = col; + c.Field.SetValue(LoadedSkin, col); + CodepointValue += 300; + InvokeSetup(cat); + + }))); + }; + flbody.SetFlowBreak(color, true); + color.Tag = "keepbg"; + flbody.Controls.Add(color); + color.Show(); + }); } - - cBox.Text = c.Field.GetValue(LoadedSkin).ToString(); - - cBox.SelectedIndexChanged += (o, a) => + else if (c.Field.FieldType.IsEnum == true) { - c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text)); - InvokeSetup(cat); + Desktop.InvokeOnWorkerThread(() => + { + var cBox = new ComboBox(); + cBox.Width = 150; + ControlManager.SetupControl(cBox); - }; + foreach (var itm in Enum.GetNames(c.Field.FieldType)) + { + cBox.Items.Add(itm); + } - labelHeight = cBox.Height; + cBox.Text = c.Field.GetValue(LoadedSkin).ToString(); - flbody.Controls.Add(cBox); - cBox.Show(); - flbody.SetFlowBreak(cBox, true); - } - else if(c.Field.FieldType == typeof(int)) - { - if (c.Field.HasShifterEnumMask()) - { - var name = new ComboBox(); - name.Width = 120; - ControlManager.SetupControl(name); - string[] items = c.Field.GetShifterEnumMask(); - foreach(var item in items) - { - name.Items.Add(item); - } - name.SelectedIndex = (int)c.Field.GetValue(LoadedSkin); - name.SelectedIndexChanged += (o, a) => - { - c.Field.SetValue(LoadedSkin, name.SelectedIndex); - CodepointValue += 75; - InvokeSetup(cat); + cBox.SelectedIndexChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text)); + InvokeSetup(cat); + + }; - }; - labelHeight = name.Height; - flbody.Controls.Add(name); - name.Show(); - flbody.SetFlowBreak(name, true); + labelHeight = cBox.Height; + flbody.Controls.Add(cBox); + cBox.Show(); + flbody.SetFlowBreak(cBox, true); + }); } - else + else if (c.Field.FieldType == typeof(int)) { - var width = new TextBox(); - width.Width = 30; - width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString(); - ControlManager.SetupControl(width); - labelHeight = width.Height; - flbody.Controls.Add(width); - width.Show(); - - EventHandler tc = (o, a) => + Desktop.InvokeOnWorkerThread(() => { - try + if (c.Field.HasShifterEnumMask()) { - int x = Convert.ToInt32(width.Text); - - int oldx = ((int)c.Field.GetValue(this.LoadedSkin)); - - if (x != oldx) + var name = new ComboBox(); + name.Width = 120; + ControlManager.SetupControl(name); + string[] items = c.Field.GetShifterEnumMask(); + foreach (var item in items) { - c.Field.SetValue(LoadedSkin, x); - CodepointValue += 75; + name.Items.Add(item); } + name.SelectedIndex = (int)c.Field.GetValue(LoadedSkin); + name.SelectedIndexChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, name.SelectedIndex); + CodepointValue += 75; + InvokeSetup(cat); + + }; + labelHeight = name.Height; + flbody.Controls.Add(name); + name.Show(); + flbody.SetFlowBreak(name, true); + } - catch + else { + var width = new TextBox(); + width.Width = 30; width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString(); - } - InvokeSetup(cat); + ControlManager.SetupControl(width); + labelHeight = width.Height; + flbody.Controls.Add(width); + width.Show(); + + EventHandler tc = (o, a) => + { + try + { + int x = Convert.ToInt32(width.Text); + + int oldx = ((int)c.Field.GetValue(this.LoadedSkin)); - }; + if (x != oldx) + { + c.Field.SetValue(LoadedSkin, x); + CodepointValue += 75; + } + } + catch + { + width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString(); + } + InvokeSetup(cat); - width.TextChanged += tc; - flbody.SetFlowBreak(width, true); + }; + width.TextChanged += tc; + flbody.SetFlowBreak(width, true); + + } + }); } - } - lbl.AutoSize = false; - lbl.Width = (int)this.CreateGraphics().MeasureString(lbl.Text, SkinEngine.LoadedSkin.MainFont).Width + 15; - lbl.Height = labelHeight; - lbl.TextAlign = ContentAlignment.MiddleLeft; + Desktop.InvokeOnWorkerThread(() => + { + lbl.AutoSize = false; + lbl.Width = (int)this.CreateGraphics().MeasureString(lbl.Text, SkinEngine.LoadedSkin.MainFont).Width + 15; + lbl.Height = labelHeight; + lbl.TextAlign = ContentAlignment.MiddleLeft; + }); - if (!string.IsNullOrWhiteSpace(c.Description)) - { - var desc = new Label(); - flbody.SetFlowBreak(desc, true); - desc.Text = c.Description; - desc.AutoSize = true; - flbody.Controls.Add(desc); - desc.Show(); + if (!string.IsNullOrWhiteSpace(c.Description)) + { + Desktop.InvokeOnWorkerThread(() => + { + var desc = new Label(); + flbody.SetFlowBreak(desc, true); + desc.Text = c.Description; + desc.AutoSize = true; + flbody.Controls.Add(desc); + desc.Show(); + }); + } } - } + }).Start(); } public ImageLayout GetLayout(string name) diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 664b657..ea24686 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -442,6 +442,10 @@ namespace ShiftOS.WinForms.Applications }).Start(); } + public static string RemoteSystemName { get; set; } + public static string RemoteUser { get; set; } + public static string RemotePass { get; set; } + [Story("first_steps")] public static void FirstSteps() { diff --git a/ShiftOS.WinForms/Servers/RemoteTerminalServer.cs b/ShiftOS.WinForms/Servers/RemoteTerminalServer.cs new file mode 100644 index 0000000..d57e28f --- /dev/null +++ b/ShiftOS.WinForms/Servers/RemoteTerminalServer.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json; +using ShiftOS.Engine; +using ShiftOS.Objects; + +namespace ShiftOS.WinForms.Servers +{ + [Namespace("rts")] + [Server("Remote Terminal Server", 21)] + //[RequiresUpgrade("story_hacker101_breakingthebonds")] //Uncomment when story is implemented. + public class RemoteTerminalServer : Server + { + public void MessageReceived(ServerMessage msg) + { + var rtsMessage = JsonConvert.DeserializeObject(msg.Contents); + if (msg.Name == "disconnected") + { + if (Applications.Terminal.IsInRemoteSystem == true) + { + if (Applications.Terminal.RemoteSystemName == rtsMessage.SenderSystemName) + { + if(Applications.Terminal.RemoteUser == rtsMessage.Username) + if(Applications.Terminal.RemotePass == rtsMessage.Password) + { + Applications.Terminal.IsInRemoteSystem = false; + Applications.Terminal.RemoteSystemName = ""; + Applications.Terminal.RemoteUser = ""; + Applications.Terminal.RemotePass = ""; + TerminalBackend.PrefixEnabled = true; + TerminalBackend.PrintPrompt(); + } + } + } + return; + } + + string currentUserName = SaveSystem.CurrentUser.Username; + + var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == rtsMessage.Username && x.Password == rtsMessage.Password); + + if(user == null) + { + ServerManager.SendMessageToIngameServer(rtsMessage.SenderSystemName, 0, "Access denied.", "The username and password you have provided was denied."); + return; + } + else + { + SaveSystem.CurrentUser = user; + + string cmd = rtsMessage.Namespace + "." + rtsMessage.Command + JsonConvert.SerializeObject(rtsMessage.Arguments); + TerminalBackend.InvokeCommand(cmd, true); + ServerManager.SendMessageToIngameServer(rtsMessage.SenderSystemName, 1, "writeline", TerminalBackend.LastCommandBuffer); + ServerManager.SendMessageToIngameServer(rtsMessage.SenderSystemName, 1, "write", $"{rtsMessage.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + + SaveSystem.CurrentUser = SaveSystem.Users.FirstOrDefault(x => x.Username == currentUserName); + } + } + + [Command("connect")] + [RequiresArgument("sysname")] + [RequiresArgument("username")] + [RequiresArgument("password")] + public static bool Connect(Dictionary args) + { + string sysname = args["sysname"].ToString(); + string username = args["username"].ToString(); + string password = args["password"].ToString(); + + bool connectionFinished = false; + + + new Thread(() => + { + Thread.Sleep(10000); + if (connectionFinished == false) + { + Applications.Terminal.IsInRemoteSystem = false; + Applications.Terminal.RemoteSystemName = ""; + Applications.Terminal.RemoteUser = ""; + Applications.Terminal.RemotePass = ""; + TerminalBackend.PrefixEnabled = true; + Console.WriteLine("[rts] Connection failed, target system did not respond."); + TerminalBackend.PrintPrompt(); + + } + }).Start(); + + ServerMessageReceived smr = null; + smr = (msg) => + { + if (msg.Name == "msgtosys") + { + var m = JsonConvert.DeserializeObject(msg.Contents); + if (m.GUID.Split('|')[2] != ServerManager.thisGuid.ToString()) + { + connectionFinished = true; + ServerManager.MessageReceived -= smr; + } + } + }; + ServerManager.MessageReceived += smr; + ServerManager.SendMessageToIngameServer(sysname, 21, "cmd", JsonConvert.SerializeObject(new RTSMessage + { + SenderSystemName = SaveSystem.CurrentSave.SystemName, + Username = username, + Password = password, + Namespace = "trm", + Command = "clear" + })); + Applications.Terminal.IsInRemoteSystem = true; + Applications.Terminal.RemoteSystemName = sysname; + Applications.Terminal.RemoteUser = username; + Applications.Terminal.RemotePass = password; + TerminalBackend.PrefixEnabled = false; + return true; + } + } + + [Server("Generic port 0", 0)] + public class InfoboxServer : Server + { + public void MessageReceived(ServerMessage msg) + { + Infobox.Show(msg.Name, msg.Contents); + } + } + + [Server("Generic port 1", 1)] + public class ConsoleServer : Server + { + public void MessageReceived(ServerMessage msg) + { + switch (msg.Name) + { + case "write": + Console.Write(msg.Contents); + break; + case "writeline": + Console.WriteLine(msg.Contents); + break; + } + } + } + + public class RTSMessage + { + public string SenderSystemName { get; set; } + + public string Namespace { get; set; } + public string Command { get; set; } + public Dictionary Arguments { get; set; } + + public string Username { get; set; } + public string Password { get; set; } + } +} diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 9675744..da8eafc 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -363,6 +363,7 @@ Resources.resx + UserControl diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index fc9567d..1643b23 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -144,10 +144,7 @@ namespace ShiftOS.WinForms.Tools public static void SetupControl(Control ctrl) { - Desktop.InvokeOnWorkerThread(new Action(() => - { - ctrl.SuspendLayout(); - })); + if (!(ctrl is MenuStrip) && !(ctrl is ToolStrip) && !(ctrl is StatusStrip) && !(ctrl is ContextMenuStrip)) { string tag = ""; @@ -306,7 +303,6 @@ namespace ShiftOS.WinForms.Tools { MakeDoubleBuffered(ctrl); - ctrl.ResumeLayout(); }); ControlSetup?.Invoke(ctrl); } @@ -330,17 +326,18 @@ namespace ShiftOS.WinForms.Tools public static void SetupControls(Control frm, bool runInThread = true) { - SetupControl(frm); frm.Click += (o, a) => { Desktop.HideAppLauncher(); }; ThreadStart ts = () => { - for (int i = 0; i < frm.Controls.Count; i++) + var ctrls = frm.Controls.ToList(); + for (int i = 0; i < ctrls.Count(); i++) { - SetupControls(frm.Controls[i], false); + SetupControls(ctrls[i]); } + SetupControl(frm); }; diff --git a/ShiftOS_TheReturn/Localization.cs b/ShiftOS_TheReturn/Localization.cs index 2c701c9..5d848b0 100644 --- a/ShiftOS_TheReturn/Localization.cs +++ b/ShiftOS_TheReturn/Localization.cs @@ -117,10 +117,6 @@ namespace ShiftOS.Engine } List orphaned = new List(); - if (Utils.FileExists("0:/dev_orphaned_lang.txt")) - { - orphaned = JsonConvert.DeserializeObject>(Utils.ReadAllText("0:/dev_orphaned_lang.txt")); // if this file exists read from it and put in list orphaned - } int start_index = 0; diff --git a/ShiftOS_TheReturn/Server.cs b/ShiftOS_TheReturn/Server.cs new file mode 100644 index 0000000..ddbd15b --- /dev/null +++ b/ShiftOS_TheReturn/Server.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Objects; + +namespace ShiftOS.Engine +{ + public interface Server + { + /// + /// Occurs when someone sends a message to the server. + /// + /// The message from the client. + void MessageReceived(ServerMessage msg); + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] + public class ServerAttribute : Attribute + { + public ServerAttribute(string name, int port) + { + Name = name; + Port = port; + } + + + /// + /// Gets the name of the server. + /// + public string Name { get; } + + /// + /// Gets the port of the server. + /// + public int Port { get; } + + } +} diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 95e86e9..217b9ee 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -36,6 +36,8 @@ using static ShiftOS.Engine.SaveSystem; using Newtonsoft.Json; using System.Net.Sockets; using System.Diagnostics; +using System.IO; +using System.Reflection; namespace ShiftOS.Engine { @@ -104,6 +106,43 @@ Ping: {ServerManager.DigitalSocietyPing} ms /// public static event Action GUIDReceived; + private static void delegateToServer(ServerMessage msg) + { + string[] split = msg.GUID.Split('|'); + bool finished = false; + foreach (var exec in Directory.GetFiles(Environment.CurrentDirectory)) + { + if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll")) + { + try + { + var asm = Assembly.LoadFile(exec); + foreach(var type in asm.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(Server)))) + { + var attrib = type.GetCustomAttributes().FirstOrDefault(x => x is ServerAttribute) as ServerAttribute; + if(attrib != null) + { + if(split[0] == SaveSystem.CurrentSave.SystemName && split[1] == attrib.Port.ToString()) + { + if (Shiftorium.UpgradeAttributesUnlocked(type)) + { + type.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == "MessageReceived")?.Invoke(Activator.CreateInstance(type), null); + finished = true; + } + } + } + } + } + catch { } + } + } + if (finished == false) + { + Forward(split[2], "Error", $"{split[0]}:{split[1]}: connection refused"); + } + } + + private static void ServerManager_MessageReceived(ServerMessage msg) { switch(msg.Name) @@ -119,12 +158,35 @@ Ping: {ServerManager.DigitalSocietyPing} ms })); } break; + case "msgtosys": + try + { + var m = JsonConvert.DeserializeObject(msg.Contents); + if(m.GUID.Split('|')[2] != thisGuid.ToString()) + { + delegateToServer(m); + } + } + catch { } + break; case "getguid_reply": GUIDReceived?.Invoke(msg.Contents); break; } } + public static void SendMessageToIngameServer(string sysname, int port, string title, string contents) + { + var smsg = new ServerMessage + { + Name = title, + GUID = $"{sysname}|{port}|{thisGuid.ToString()}", + Contents = contents + }; + Forward("all", "msgtosys", JsonConvert.SerializeObject(smsg)); + + } + public static void Detach_ServerManager_MessageReceived() { MessageReceived -= new ServerMessageReceived(ServerManager_MessageReceived); diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 8b48023..9d7d696 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -124,6 +124,7 @@ + diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index c8619b5..b18e27c 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -84,6 +84,11 @@ namespace ShiftOS.Engine /// public static string LastCommand = ""; + /// + /// Gets the output of the last command. + /// + public static string LastCommandBuffer { get; private set; } + /// /// Invokes a ShiftOS terminal command. /// @@ -395,8 +400,10 @@ namespace ShiftOS.Engine } string buffer = tw.ToString(); + LastCommandBuffer = buffer; Console.SetOut(new TerminalTextWriter()); - Console.Write(buffer); + if(!isRemote) + Console.Write(buffer); } -- cgit v1.2.3