From 4989356d6797335b44060ae94c9af34404773506 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 7 Mar 2017 17:33:39 -0800 Subject: [PATCH] Very early version of FormatEditor --- .../Applications/FormatEditor.Designer.cs | 210 +++++++++++ ShiftOS.WinForms/Applications/FormatEditor.cs | 343 ++++++++++++++++++ .../Applications/FormatEditor.resx | 120 ++++++ ShiftOS.WinForms/Applications/ShiftSweeper.cs | 9 +- ShiftOS.WinForms/Resources/Shiftorium.txt | 30 ++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 + ShiftOS_TheReturn/AudioManager.cs | 2 +- 7 files changed, 718 insertions(+), 5 deletions(-) create mode 100644 ShiftOS.WinForms/Applications/FormatEditor.Designer.cs create mode 100644 ShiftOS.WinForms/Applications/FormatEditor.cs create mode 100644 ShiftOS.WinForms/Applications/FormatEditor.resx diff --git a/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs new file mode 100644 index 0000000..2f628f1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs @@ -0,0 +1,210 @@ +/* + * MIT License + * + * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +namespace ShiftOS.WinForms.Applications +{ + partial class FormatEditor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panelEditor = new System.Windows.Forms.Panel(); + this.btnAddText = new System.Windows.Forms.Button(); + this.btnAddOptionalText = new System.Windows.Forms.Button(); + this.btnAddRegexText = new System.Windows.Forms.Button(); + this.btnAddCommand = new System.Windows.Forms.Button(); + this.lblExampleCommand = new System.Windows.Forms.Label(); + 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.SuspendLayout(); + // + // panelEditor + // + this.panelEditor.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panelEditor.AutoScroll = true; + this.panelEditor.Location = new System.Drawing.Point(4, 4); + this.panelEditor.Name = "panelEditor"; + this.panelEditor.Size = new System.Drawing.Size(589, 46); + this.panelEditor.TabIndex = 1; + // + // btnAddText + // + this.btnAddText.Location = new System.Drawing.Point(4, 56); + this.btnAddText.Name = "btnAddText"; + this.btnAddText.Size = new System.Drawing.Size(75, 23); + this.btnAddText.TabIndex = 2; + this.btnAddText.Text = "Add Text"; + this.btnAddText.UseVisualStyleBackColor = true; + this.btnAddText.Click += new System.EventHandler(this.btnAddText_Click); + // + // btnAddOptionalText + // + this.btnAddOptionalText.Location = new System.Drawing.Point(85, 56); + this.btnAddOptionalText.Name = "btnAddOptionalText"; + this.btnAddOptionalText.Size = new System.Drawing.Size(107, 23); + this.btnAddOptionalText.TabIndex = 3; + this.btnAddOptionalText.Text = "Add Optional Text"; + this.btnAddOptionalText.UseVisualStyleBackColor = true; + this.btnAddOptionalText.Click += new System.EventHandler(this.btnAddOptionalText_Click); + // + // btnAddRegexText + // + this.btnAddRegexText.Location = new System.Drawing.Point(198, 56); + this.btnAddRegexText.Name = "btnAddRegexText"; + this.btnAddRegexText.Size = new System.Drawing.Size(107, 23); + this.btnAddRegexText.TabIndex = 4; + this.btnAddRegexText.Text = "Add Regex Text"; + this.btnAddRegexText.UseVisualStyleBackColor = true; + this.btnAddRegexText.Click += new System.EventHandler(this.btnAddRegexText_Click); + // + // btnAddCommand + // + this.btnAddCommand.Location = new System.Drawing.Point(4, 85); + this.btnAddCommand.Name = "btnAddCommand"; + this.btnAddCommand.Size = new System.Drawing.Size(75, 23); + this.btnAddCommand.TabIndex = 5; + this.btnAddCommand.Text = "+ Command"; + this.btnAddCommand.UseVisualStyleBackColor = true; + this.btnAddCommand.Click += new System.EventHandler(this.btnAddCommand_Click); + // + // lblExampleCommand + // + this.lblExampleCommand.AutoSize = true; + this.lblExampleCommand.Location = new System.Drawing.Point(4, 115); + this.lblExampleCommand.Name = "lblExampleCommand"; + this.lblExampleCommand.Size = new System.Drawing.Size(290, 13); + this.lblExampleCommand.TabIndex = 8; + this.lblExampleCommand.Text = "Create a command and an example usage will show up here"; + // + // btnAddColor + // + this.btnAddColor.Location = new System.Drawing.Point(311, 56); + this.btnAddColor.Name = "btnAddColor"; + this.btnAddColor.Size = new System.Drawing.Size(64, 23); + this.btnAddColor.TabIndex = 9; + this.btnAddColor.Text = "Add Color"; + this.btnAddColor.UseVisualStyleBackColor = true; + this.btnAddColor.Click += new System.EventHandler(this.btnAddColor_Click); + // + // richTextBox1 + // + this.richTextBox1.Location = new System.Drawing.Point(7, 132); + this.richTextBox1.Multiline = false; + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(476, 23); + this.richTextBox1.TabIndex = 10; + this.richTextBox1.Text = ""; + this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); + // + // btnTest + // + this.btnTest.Location = new System.Drawing.Point(490, 132); + this.btnTest.Name = "btnTest"; + this.btnTest.Size = new System.Drawing.Size(47, 23); + this.btnTest.TabIndex = 11; + this.btnTest.Text = "Test"; + this.btnTest.UseVisualStyleBackColor = true; + this.btnTest.Click += new System.EventHandler(this.btnTest_Click); + // + // button1 + // + 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; + // + // button2 + // + 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; + // + // 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.btnTest); + this.Controls.Add(this.richTextBox1); + this.Controls.Add(this.btnAddColor); + this.Controls.Add(this.lblExampleCommand); + this.Controls.Add(this.btnAddText); + this.Controls.Add(this.btnAddOptionalText); + this.Controls.Add(this.btnAddRegexText); + this.Controls.Add(this.btnAddCommand); + this.Controls.Add(this.panelEditor); + this.Name = "FormatEditor"; + this.Size = new System.Drawing.Size(596, 426); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Panel panelEditor; + private System.Windows.Forms.Button btnAddText; + private System.Windows.Forms.Button btnAddOptionalText; + private System.Windows.Forms.Button btnAddRegexText; + private System.Windows.Forms.Button btnAddCommand; + private System.Windows.Forms.Label lblExampleCommand; + 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; + } +} diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs new file mode 100644 index 0000000..ef44b47 --- /dev/null +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -0,0 +1,343 @@ +/* + * MIT License + * + * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Applications { + [Launcher("FormatEditor", true, "al_format_editor", "Games")] + [RequiresUpgrade("format_editor")] + [WinOpen("formateditor")] + [DefaultIcon("iconFormatEditor")] + + public partial class FormatEditor : UserControl, IShiftOSWindow { + + IList parts = new List(); + IList editorBoxes = new List(); + + string commandMode = "command"; + int avcount = 0; + + public FormatEditor() { + InitializeComponent(); + } + + public void OnLoad() { + OnUpgrade(); + } + + public void OnSkinLoad() { } + + public bool OnUnload() { return true; } + + public void OnUpgrade() { + btnAddOptionalText.Visible = ShiftoriumFrontend.UpgradeInstalled("format_editor_optional_text"); + btnAddRegexText.Visible = ShiftoriumFrontend.UpgradeInstalled("format_editor_regex"); + btnAddColor.Visible = ShiftoriumFrontend.UpgradeInstalled("format_editor_syntax_highlighting"); + } + + private void addPart(CommandFormat part) { + parts.Add(part); + Panel container = new Panel(); + + Control drawnPart = part.Draw(); + container.Size = drawnPart.Size; + container.Controls.Add(drawnPart); + + int woffset = 0; + if (editorBoxes.Count > 0) { + woffset = editorBoxes.Last().Width + editorBoxes.Last().Location.X; + } else { + woffset = 0; + } + + container.Location = new Point(woffset, 0); + editorBoxes.Add(container); + panelEditor.Controls.Add(container); + } + + private void btnAddText_Click(object sender, EventArgs e) { + addPart(new CommandFormatText()); + } + + private void btnAddOptionalText_Click(object sender, EventArgs e) { + addPart(new CommandFormatOptionalText()); + } + + private void btnAddRegexText_Click(object sender, EventArgs e) { + + } + + private void btnAddColor_Click(object sender, EventArgs e) { + + } + + private void btnAddCommand_Click(object sender, EventArgs e) { + switch (commandMode) { + case "command": + addPart(new CommandFormatCommand()); + commandMode = "argument"; + btnAddCommand.Text = "+ Argument"; + break; + case "argument": + addPart(new CommandFormatArgument()); + commandMode = "value"; + btnAddCommand.Text = "+ \"Value\""; + break; + case "value": + addPart(new CommandFormatValue()); + avcount++; + if (avcount >= 2) { + commandMode = ""; + btnAddCommand.Text = ""; + btnAddCommand.Enabled = false; + }else { + commandMode = "argument"; + btnAddCommand.Text = "+ Argument"; + } + break; + } + } + + 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; + } + } + + 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+") { + lblExampleCommand.Text = "Syntax Error"; + } else { + string argvs = "{"; + + foreach (KeyValuePair entry in arguments) { + argvs += entry.Key + "=" + entry.Value + ", "; + } + + argvs += "}"; + + lblExampleCommand.Text = command + 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; + } + } + + class CommandFormatArgument : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Argument"; + return draw; + } + } + + 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; + } + } + + return done ? "\""+res : "+FALSE+"; + } + + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "\"Value\""; + return draw; + } + } +} diff --git a/ShiftOS.WinForms/Applications/FormatEditor.resx b/ShiftOS.WinForms/Applications/FormatEditor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/FormatEditor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 69db034..b13880f 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -87,15 +87,14 @@ namespace ShiftOS.WinForms.Applications { } public void OnLoad() { - buttonEasy.Visible = true; - buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); - buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); + OnUpgrade(); ticking.Interval = 1000; ticking.Tick += Ticking_Tick; } public void OnSkinLoad() { + } public bool OnUnload() { @@ -103,7 +102,9 @@ namespace ShiftOS.WinForms.Applications { } public void OnUpgrade() { - + buttonEasy.Visible = true; + buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); + buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); } public void startGame(int w, int h, int b) { diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 841a24e..8e09d6e 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -251,6 +251,36 @@ Description: "Add a launcher item for the MUD cracker.", Dependencies: "mud_cracker;app_launcher" }, + { + Name: "Format Editor", + Cost: 6000, + Description: "Allows you to change the format of commands.", + Dependencies: "shifter;name_changer" + }, + { + Name: "Format Editor Optional Text", + Cost: 150, + Description: "Allows you to add an optional text to commands", + Dependencies: "format_editor" + }, + { + Name: "Format Editor Regex", + Cost: 150, + Description: "Allows you to customize your commands with regexes.", + Dependencies: "format_editor_optional_text" + }, + { + Name: "Format Editor Syntax Highligting", + Cost: 150, + Description: "Allows you to give color to commands as the user types them.", + Dependencies: "format_editor_regex" + }, + { + Name: "AL Format Editor", + Cost: 150, + Description: "Add a launcher item for the Format Editor.", + Dependencies: "format_editor;app_launcher" + }, { Name: "Textpad", Cost: 2500, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 7d4f0d3..8afa76e 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -178,6 +178,12 @@ ShiftoriumFrontend.cs + + UserControl + + + FormatEditor.cs + UserControl @@ -334,6 +340,9 @@ ShiftoriumFrontend.cs + + FormatEditor.cs + ShiftSweeper.cs diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index a548cf6..7f6f5e9 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -69,7 +69,7 @@ namespace ShiftOS.Engine { int track = rnd.Next(0, _provider.Count); byte[] mp3 = _provider.GetTrack(track); - System.IO.File.WriteAllBytes("temp.mp3", mp3); + System.IO.File.WriteAllBytes("temp.mp3", mp3); _reader = new AudioFileReader("temp.mp3"); _out = new WaveOut(); _out.Init(_reader);