From 9b8d5861a954610713ae66a53d2ac067991d9b68 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 18 Feb 2017 10:37:11 -0500 Subject: [PATCH] WHOA LUA STUFF :dancer: --- .../ExperienceShifter.Designer.cs | 83 ++++++--- .../Applications/ExperienceShifter.cs | 51 ++++- .../Applications/ExperienceShifter.resx | 3 + ShiftOS.WinForms/GUIFunctions.cs | 85 +++++++++ ShiftOS.WinForms/LuaDesktop.Designer.cs | 23 ++- ShiftOS.WinForms/LuaDesktop.cs | 174 +++++++++++++++--- ShiftOS.WinForms/LuaDesktop.resx | 120 ++++++++++++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 11 ++ ShiftOS.WinForms/ShiftOSConfigFile.cs | 20 ++ ShiftOS.WinForms/Window.Designer.cs | 37 ++++ ShiftOS.WinForms/Window.cs | 44 +++++ ShiftOS.WinForms/WinformsDesktop.cs | 23 ++- ShiftOS_TheReturn/AudioManager.cs | 6 +- ShiftOS_TheReturn/Desktop.cs | 35 +--- ShiftOS_TheReturn/Infobox.cs | 6 + ShiftOS_TheReturn/Paths.cs | 3 + ShiftOS_TheReturn/Scripting.cs | 32 ++++ 17 files changed, 662 insertions(+), 94 deletions(-) create mode 100644 ShiftOS.WinForms/GUIFunctions.cs create mode 100644 ShiftOS.WinForms/LuaDesktop.resx create mode 100644 ShiftOS.WinForms/ShiftOSConfigFile.cs create mode 100644 ShiftOS.WinForms/Window.Designer.cs create mode 100644 ShiftOS.WinForms/Window.cs diff --git a/ShiftOS.WinForms/Applications/ExperienceShifter.Designer.cs b/ShiftOS.WinForms/Applications/ExperienceShifter.Designer.cs index 9a0d54c..02cb01b 100644 --- a/ShiftOS.WinForms/Applications/ExperienceShifter.Designer.cs +++ b/ShiftOS.WinForms/Applications/ExperienceShifter.Designer.cs @@ -32,16 +32,19 @@ this.desktopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.appLauncherToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pnldesktop = new System.Windows.Forms.Panel(); + this.lbdesktops = new System.Windows.Forms.ListBox(); this.gpdesktopsettings = new System.Windows.Forms.GroupBox(); this.label2 = new System.Windows.Forms.Label(); this.pnlapplauncher = new System.Windows.Forms.Panel(); - this.label1 = new System.Windows.Forms.Label(); - this.lbdesktops = new System.Windows.Forms.ListBox(); - this.gpalsettings = new System.Windows.Forms.GroupBox(); this.lblaunchers = new System.Windows.Forms.ListBox(); + this.gpalsettings = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.menuStrip2 = new System.Windows.Forms.MenuStrip(); + this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.pnldesktop.SuspendLayout(); this.pnlapplauncher.SuspendLayout(); + this.menuStrip2.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 @@ -71,6 +74,7 @@ // // pnldesktop // + this.pnldesktop.Controls.Add(this.menuStrip2); this.pnldesktop.Controls.Add(this.lbdesktops); this.pnldesktop.Controls.Add(this.gpdesktopsettings); this.pnldesktop.Controls.Add(this.label2); @@ -80,6 +84,16 @@ this.pnldesktop.Size = new System.Drawing.Size(582, 407); this.pnldesktop.TabIndex = 1; // + // lbdesktops + // + this.lbdesktops.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbdesktops.FormattingEnabled = true; + this.lbdesktops.Location = new System.Drawing.Point(0, 23); + this.lbdesktops.Name = "lbdesktops"; + this.lbdesktops.Size = new System.Drawing.Size(582, 239); + this.lbdesktops.TabIndex = 0; + this.lbdesktops.SelectedIndexChanged += new System.EventHandler(this.lbdesktops_SelectedIndexChanged); + // // gpdesktopsettings // this.gpdesktopsettings.Dock = System.Windows.Forms.DockStyle.Bottom; @@ -113,6 +127,25 @@ this.pnlapplauncher.Size = new System.Drawing.Size(582, 407); this.pnlapplauncher.TabIndex = 0; // + // lblaunchers + // + this.lblaunchers.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblaunchers.FormattingEnabled = true; + this.lblaunchers.Location = new System.Drawing.Point(0, 23); + this.lblaunchers.Name = "lblaunchers"; + this.lblaunchers.Size = new System.Drawing.Size(582, 239); + this.lblaunchers.TabIndex = 4; + // + // gpalsettings + // + this.gpalsettings.Dock = System.Windows.Forms.DockStyle.Bottom; + this.gpalsettings.Location = new System.Drawing.Point(0, 262); + this.gpalsettings.Name = "gpalsettings"; + this.gpalsettings.Size = new System.Drawing.Size(582, 145); + this.gpalsettings.TabIndex = 3; + this.gpalsettings.TabStop = false; + this.gpalsettings.Text = "Settings for this environment"; + // // label1 // this.label1.AutoSize = true; @@ -125,40 +158,30 @@ this.label1.Tag = "header2"; this.label1.Text = "App Launcher"; // - // lbdesktops + // menuStrip2 // - this.lbdesktops.Dock = System.Windows.Forms.DockStyle.Fill; - this.lbdesktops.FormattingEnabled = true; - this.lbdesktops.Location = new System.Drawing.Point(0, 23); - this.lbdesktops.Name = "lbdesktops"; - this.lbdesktops.Size = new System.Drawing.Size(582, 239); - this.lbdesktops.TabIndex = 0; + this.menuStrip2.Dock = System.Windows.Forms.DockStyle.Bottom; + this.menuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addToolStripMenuItem}); + this.menuStrip2.Location = new System.Drawing.Point(0, 238); + this.menuStrip2.Name = "menuStrip2"; + this.menuStrip2.Size = new System.Drawing.Size(582, 24); + this.menuStrip2.TabIndex = 0; + this.menuStrip2.Text = "menuStrip2"; // - // gpalsettings + // addToolStripMenuItem // - this.gpalsettings.Dock = System.Windows.Forms.DockStyle.Bottom; - this.gpalsettings.Location = new System.Drawing.Point(0, 262); - this.gpalsettings.Name = "gpalsettings"; - this.gpalsettings.Size = new System.Drawing.Size(582, 145); - this.gpalsettings.TabIndex = 3; - this.gpalsettings.TabStop = false; - this.gpalsettings.Text = "Settings for this environment"; - // - // lblaunchers - // - this.lblaunchers.Dock = System.Windows.Forms.DockStyle.Fill; - this.lblaunchers.FormattingEnabled = true; - this.lblaunchers.Location = new System.Drawing.Point(0, 23); - this.lblaunchers.Name = "lblaunchers"; - this.lblaunchers.Size = new System.Drawing.Size(582, 239); - this.lblaunchers.TabIndex = 4; + this.addToolStripMenuItem.Name = "addToolStripMenuItem"; + this.addToolStripMenuItem.Size = new System.Drawing.Size(41, 20); + this.addToolStripMenuItem.Text = "Add"; + this.addToolStripMenuItem.Click += new System.EventHandler(this.addToolStripMenuItem_Click); // // ExperienceShifter // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.pnlapplauncher); this.Controls.Add(this.pnldesktop); + this.Controls.Add(this.pnlapplauncher); this.Controls.Add(this.menuStrip1); this.Name = "ExperienceShifter"; this.Size = new System.Drawing.Size(582, 431); @@ -168,6 +191,8 @@ this.pnldesktop.PerformLayout(); this.pnlapplauncher.ResumeLayout(false); this.pnlapplauncher.PerformLayout(); + this.menuStrip2.ResumeLayout(false); + this.menuStrip2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -186,5 +211,7 @@ private System.Windows.Forms.ListBox lbdesktops; private System.Windows.Forms.ListBox lblaunchers; private System.Windows.Forms.GroupBox gpalsettings; + private System.Windows.Forms.MenuStrip menuStrip2; + private System.Windows.Forms.ToolStripMenuItem addToolStripMenuItem; } } diff --git a/ShiftOS.WinForms/Applications/ExperienceShifter.cs b/ShiftOS.WinForms/Applications/ExperienceShifter.cs index 2623b88..281b723 100644 --- a/ShiftOS.WinForms/Applications/ExperienceShifter.cs +++ b/ShiftOS.WinForms/Applications/ExperienceShifter.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; +using ShiftOS.Objects.ShiftFS; +using Newtonsoft.Json; namespace ShiftOS.WinForms.Applications { @@ -42,12 +44,27 @@ namespace ShiftOS.WinForms.Applications public void PopulateDesktops() { lbdesktops.Items.Clear(); - foreach(var desk in Desktop.GetAllDesktops()) + foreach(var desk in GetAllDesktops()) { lbdesktops.Items.Add(desk.DesktopName); } } + public List GetAllDesktops() + { + List dekstops = new List(); + dekstops.Add(new WinformsDesktop()); + if (!Utils.FileExists(Paths.GetPath("conf.sft"))) + Utils.WriteAllText(Paths.GetPath("conf.sft"), JsonConvert.SerializeObject(new ShiftOSConfigFile(), Formatting.Indented)); + + foreach(var script in JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.GetPath("conf.sft"))).Desktops) + { + if(Utils.FileExists(script)) + dekstops.Add(new LuaDesktop(script)); + } + return dekstops; + } + public void PopulateLaunchers() { lblaunchers.Items.Clear(); @@ -83,5 +100,37 @@ namespace ShiftOS.WinForms.Applications currentUI = "applauncher"; SetupUI(); } + + private void addToolStripMenuItem_Click(object sender, EventArgs e) + { + FileSkimmerBackend.GetFile(new[] { ".lua" }, FileOpenerStyle.Open, new Action((script) => + { + ShiftOSConfigFile conf = new WinForms.ShiftOSConfigFile(); + if (Utils.FileExists(Paths.GetPath("conf.sft"))) + { + conf = JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.GetPath("conf.sft"))); + } + conf.Desktops.Add(script); + Utils.WriteAllText(Paths.GetPath("conf.sft"), JsonConvert.SerializeObject(conf, Formatting.Indented)); + })); + } + + private void lbdesktops_SelectedIndexChanged(object sender, EventArgs e) + { + foreach(var desk in GetAllDesktops()) + { + try + { + if(desk.DesktopName == lbdesktops.SelectedItem.ToString()) + { + Desktop.Init(desk, true); + } + } + catch + { + + } + } + } } } diff --git a/ShiftOS.WinForms/Applications/ExperienceShifter.resx b/ShiftOS.WinForms/Applications/ExperienceShifter.resx index d5494e3..2d404e0 100644 --- a/ShiftOS.WinForms/Applications/ExperienceShifter.resx +++ b/ShiftOS.WinForms/Applications/ExperienceShifter.resx @@ -120,4 +120,7 @@ 17, 17 + + 132, 17 + \ No newline at end of file diff --git a/ShiftOS.WinForms/GUIFunctions.cs b/ShiftOS.WinForms/GUIFunctions.cs new file mode 100644 index 0000000..edccea9 --- /dev/null +++ b/ShiftOS.WinForms/GUIFunctions.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine.Scripting; +using System.Drawing; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms +{ + [Exposed("gui")] + public class GUIFunctions + { + public dynamic color(int r, int g, int b) + { + return Color.FromArgb(r, g, b); + } + + public dynamic color(string name) + { + return Color.FromName(name); + } + + public dynamic point(int x, int y) + { + return new Point(x, y); + } + + public dynamic size(int w, int h) + { + return new Size(w, h); + } + + public dynamic font(string name, float size, bool bold, bool italic, bool strikethrough, bool underline) + { + FontStyle fs = FontStyle.Regular; + if (bold) + fs = fs | FontStyle.Bold; + if (italic) + fs = fs | FontStyle.Italic; + if (underline) + fs = fs | FontStyle.Underline; + if (strikethrough) + fs = fs | FontStyle.Strikeout; + + return new Font(name, size, fs); + } + + public dynamic createWindow(string name, dynamic size) + { + var win = new Window(); + win.Size = size; + AppearanceManager.SetupWindow(win); + return win; + } + } + + [Exposed("clr")] + public class CommonLanguageRuntimeInterop + { + public dynamic construct(Type type, dynamic[] ctorParams) + { + return Activator.CreateInstance(type, ctorParams); + } + + public dynamic typeOf(string typeName) + { + return Type.GetType(typeName); + } + + public void throwException(string message) + { + throw new UserException(message); + } + } + + public class UserException : Exception + { + public UserException(string message) :base("User threw exception using clr:throwException().\r\n\r\n" + message) + { + + } + } +} diff --git a/ShiftOS.WinForms/LuaDesktop.Designer.cs b/ShiftOS.WinForms/LuaDesktop.Designer.cs index 10681f3..7c77f0e 100644 --- a/ShiftOS.WinForms/LuaDesktop.Designer.cs +++ b/ShiftOS.WinForms/LuaDesktop.Designer.cs @@ -28,11 +28,32 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.pnlcanvas = new System.Windows.Forms.Panel(); + this.SuspendLayout(); + // + // pnlcanvas + // + this.pnlcanvas.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlcanvas.Location = new System.Drawing.Point(0, 0); + this.pnlcanvas.Name = "pnlcanvas"; + this.pnlcanvas.Size = new System.Drawing.Size(284, 261); + this.pnlcanvas.TabIndex = 0; + // + // LuaDesktop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 261); + this.Controls.Add(this.pnlcanvas); + this.Name = "LuaDesktop"; this.Text = "LuaDesktop"; + this.Load += new System.EventHandler(this.LuaDesktop_Load); + this.ResumeLayout(false); + } #endregion + + private System.Windows.Forms.Panel pnlcanvas; } } \ No newline at end of file diff --git a/ShiftOS.WinForms/LuaDesktop.cs b/ShiftOS.WinForms/LuaDesktop.cs index 445a571..8fd5244 100644 --- a/ShiftOS.WinForms/LuaDesktop.cs +++ b/ShiftOS.WinForms/LuaDesktop.cs @@ -7,17 +7,35 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; - +using Newtonsoft.Json; using ShiftOS.Engine; using ShiftOS.Engine.Scripting; +using ShiftOS.Objects.ShiftFS; +using static ShiftOS.Engine.SkinEngine; + namespace ShiftOS.WinForms { public partial class LuaDesktop : Form, IDesktop { - public LuaDesktop() + public LuaDesktop(string script) { InitializeComponent(); + interpreter = new LuaInterpreter(); + interpreter.Lua.getCanvas = new Func(() => + { + return this.pnlcanvas; + }); + if (Utils.FileExists(script)) + { + interpreter.ExecuteFile(script); + } + else + { + Desktop.Init(new WinformsDesktop(), true); + Infobox.Show("Script not found.", "Couldn't find a ShiftOS script to handle the desktop environment."); + this.Close(); + } } private LuaInterpreter interpreter = null; @@ -39,6 +57,8 @@ namespace ShiftOS.WinForms } } + private IWindowBorder focused = null; + public Size GetSize() { return this.Size; @@ -49,44 +69,146 @@ namespace ShiftOS.WinForms this.Invoke(act); } - public void KillWindow(IWindowBorder border) - { - throw new NotImplementedException(); - } - - public void MaximizeWindow(IWindowBorder brdr) - { - throw new NotImplementedException(); - } - - public void MinimizeWindow(IWindowBorder brdr) - { - throw new NotImplementedException(); - } - public void PopulateAppLauncher(LauncherItem[] items) { - + interpreter.Lua.populateAppLauncher(interpreter.Lua.totable(new List(items))); } public void PopulatePanelButtons() { - throw new NotImplementedException(); - } - - public void RestoreWindow(IWindowBorder brdr) - { - throw new NotImplementedException(); + interpreter.Lua.populatePanelButtons(); } public void SetupDesktop() { - throw new NotImplementedException(); + try + { + interpreter.Lua.setupDesktop(); + } + catch (Exception ex) + { + Infobox.Show("Desktop setup error", "The desktop environment threw an exception: \r\n\r\n\r\n" + ex.Message); + Desktop.Init(new WinformsDesktop(), true); + this.Close(); + } } public void ShowWindow(IWindowBorder border) { - throw new NotImplementedException(); + var brdr = border as Form; + focused = border; + brdr.GotFocus += (o, a) => + { + focused = border; + }; + brdr.FormBorderStyle = FormBorderStyle.None; + brdr.Show(); + brdr.TopMost = true; + } + + /// + /// Kills the window. + /// + /// The window. + /// Border. + public void KillWindow(IWindowBorder border) + { + border.Close(); + } + + /// + /// Minimizes the window. + /// + /// Brdr. + public void MinimizeWindow(IWindowBorder brdr) + { + var loc = (brdr as WindowBorder).Location; + var sz = (brdr as WindowBorder).Size; + (brdr as WindowBorder).Tag = JsonConvert.SerializeObject(new + { + Size = sz, + Location = loc + }); + (brdr as WindowBorder).Location = new Point(this.GetSize().Width * 2, this.GetSize().Height * 2); + } + + /// + /// Maximizes the window. + /// + /// The window. + /// Brdr. + public void MaximizeWindow(IWindowBorder brdr) + { + int startY = (LoadedSkin.DesktopPanelPosition == 1) ? 0 : LoadedSkin.DesktopPanelHeight; + int h = this.GetSize().Height - LoadedSkin.DesktopPanelHeight; + var loc = (brdr as WindowBorder).Location; + var sz = (brdr as WindowBorder).Size; + (brdr as WindowBorder).Tag = JsonConvert.SerializeObject(new + { + Size = sz, + Location = loc + }); + (brdr as WindowBorder).Location = new Point(0, startY); + (brdr as WindowBorder).Size = new Size(this.GetSize().Width, h); + + } + + /// + /// Restores the window. + /// + /// The window. + /// Brdr. + public void RestoreWindow(IWindowBorder brdr) + { + dynamic tag = JsonConvert.DeserializeObject((brdr as WindowBorder).Tag.ToString()); + (brdr as WindowBorder).Location = tag.Location; + (brdr as WindowBorder).Size = tag.Size; + + } + + private void LuaDesktop_Load(object sender, EventArgs e) + { + this.LocationChanged += (o, a) => + { + if (this.Left != 0) + this.Left = 0; + if (this.Top != 0) + this.Top = 0; + }; + + this.SizeChanged += (o, a) => + { + if(this.DisplayRectangle != Screen.PrimaryScreen.Bounds) + { + this.WindowState = FormWindowState.Maximized; + } + }; + + interpreter.Lua.onLoadDesktop(); + SetupDesktop(); + SaveSystem.GameReady += () => + { + InvokeOnWorkerThread(new Action(() => + { + SetupDesktop(); + })); + }; + SkinEngine.SkinLoaded += () => + { + if(this.Visible == true) + { + SetupDesktop(); + } + }; + Shiftorium.Installed += () => + { + if (this.Visible == true) + { + SetupDesktop(); + } + + }; + } } } diff --git a/ShiftOS.WinForms/LuaDesktop.resx b/ShiftOS.WinForms/LuaDesktop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/LuaDesktop.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/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index f63dcd2..d2260cf 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -207,6 +207,7 @@ FakeSetupScreen.cs + Form @@ -221,12 +222,19 @@ Oobe.cs + + + UserControl + + + Window.cs + Form @@ -305,6 +313,9 @@ FakeSetupScreen.cs + + LuaDesktop.cs + Oobe.cs diff --git a/ShiftOS.WinForms/ShiftOSConfigFile.cs b/ShiftOS.WinForms/ShiftOSConfigFile.cs new file mode 100644 index 0000000..60a9a41 --- /dev/null +++ b/ShiftOS.WinForms/ShiftOSConfigFile.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.WinForms +{ + public class ShiftOSConfigFile + { + public ShiftOSConfigFile() + { + AudioVolume = 0.5F; + Desktops = new List(); + } + + public float AudioVolume { get; set; } + public List Desktops { get; set; } + } +} diff --git a/ShiftOS.WinForms/Window.Designer.cs b/ShiftOS.WinForms/Window.Designer.cs new file mode 100644 index 0000000..520f614 --- /dev/null +++ b/ShiftOS.WinForms/Window.Designer.cs @@ -0,0 +1,37 @@ +namespace ShiftOS.WinForms +{ + partial class Window + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/ShiftOS.WinForms/Window.cs b/ShiftOS.WinForms/Window.cs new file mode 100644 index 0000000..9295820 --- /dev/null +++ b/ShiftOS.WinForms/Window.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using ShiftOS.Engine.Scripting; + + +namespace ShiftOS.WinForms +{ + public partial class Window : UserControl, IShiftOSWindow + { + public Window() + { + InitializeComponent(); + } + + public void OnLoad() + { + LuaInterpreter.RaiseEvent("on_window_load", this); + } + + public void OnSkinLoad() + { + LuaInterpreter.RaiseEvent("on_window_skin_load", this); + } + + public bool OnUnload() + { + LuaInterpreter.RaiseEvent("on_window_unload", this); + return true; + } + + public void OnUpgrade() + { + LuaInterpreter.RaiseEvent("on_window_upgrade", this); + } + } +} diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index c2bbe5c..0ea150c 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -75,8 +75,16 @@ namespace ShiftOS.WinForms } }; - SaveSystem.GameReady += () => this.Invoke(new Action(() => SetupDesktop())); - Shiftorium.Installed += () => this.Invoke(new Action(() => SetupDesktop())); + SaveSystem.GameReady += () => + { + if(this.Visible == true) + this.Invoke(new Action(() => SetupDesktop())); + }; + Shiftorium.Installed += () => + { + if(this.Visible == true) + this.Invoke(new Action(() => SetupDesktop())); + }; var time = new Timer(); time.Interval = 100; this.KeyDown += (o, a) => @@ -112,16 +120,7 @@ namespace ShiftOS.WinForms time.Start(); this.DoubleBuffered = true; - SetCursors(this); - } - - public void SetCursors(Control ctrl) - { - ControlManager.SetupControl(ctrl); - foreach(Control child in ctrl.Controls) - { - SetCursors(child); - } + } /// diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 1ea4575..db3ddc9 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -1,4 +1,6 @@ -using System; +#define NOSOUND + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -18,6 +20,7 @@ namespace ShiftOS.Engine public static void Init(IAudioProvider _p) { +#if !NOSOUND _provider = _p; AppearanceManager.OnExit += () => { @@ -59,6 +62,7 @@ namespace ShiftOS.Engine }); t.IsBackground = true; t.Start(); +#endif } public static void SetVolume(float volume) diff --git a/ShiftOS_TheReturn/Desktop.cs b/ShiftOS_TheReturn/Desktop.cs index d30e3c3..86d2099 100644 --- a/ShiftOS_TheReturn/Desktop.cs +++ b/ShiftOS_TheReturn/Desktop.cs @@ -85,45 +85,30 @@ namespace ShiftOS.Engine void RestoreWindow(IWindowBorder brdr); void InvokeOnWorkerThread(Action act); Size GetSize(); + + void Show(); + void Close(); } public static class Desktop { private static IDesktop _desktop = null; - public static IDesktop[] GetAllDesktops() - { - List desktops = new List(); - foreach(var exe in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if(exe.EndsWith(".exe") || exe.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(exe); - foreach(var type in asm.GetTypes()) - { - if (type.GetInterfaces().Contains(typeof(IDesktop))) - { - desktops.Add(Activator.CreateInstance(type) as IDesktop); - } - } - } - catch { } - } - } - return desktops.ToArray(); - } - public static Size Size { get { return _desktop.GetSize(); } } - public static void Init(IDesktop desk) + public static void Init(IDesktop desk, bool show = false) { + IDesktop deskToClose = null; + if (_desktop != null) + deskToClose = _desktop; _desktop = desk; + if (show == true) + _desktop.Show(); + deskToClose?.Close(); } public static void MinimizeWindow(IWindowBorder brdr) diff --git a/ShiftOS_TheReturn/Infobox.cs b/ShiftOS_TheReturn/Infobox.cs index 8854b88..3e8fa30 100644 --- a/ShiftOS_TheReturn/Infobox.cs +++ b/ShiftOS_TheReturn/Infobox.cs @@ -57,16 +57,22 @@ namespace ShiftOS.Engine /// Infobox message public static void Show(string title, string message) { + title = Localization.Parse(title); + message = Localization.Parse(message); _infobox.Open(title, message); } public static void PromptText(string title, string message, Action callback) { + title = Localization.Parse(title); + message = Localization.Parse(message); _infobox.PromptText(title, message, callback); } public static void PromptYesNo(string title, string message, Action callback) { + title = Localization.Parse(title); + message = Localization.Parse(message); _infobox.PromptYesNo(title, message, callback); } diff --git a/ShiftOS_TheReturn/Paths.cs b/ShiftOS_TheReturn/Paths.cs index aeca13d..7408bef 100644 --- a/ShiftOS_TheReturn/Paths.cs +++ b/ShiftOS_TheReturn/Paths.cs @@ -60,6 +60,9 @@ namespace ShiftOS.Engine AddPath("data", "save.json"); AddPath("data", "user.dat"); AddPath("data", "skin"); + AddPath("system", "programs"); + AddPath("system", "kernel.sft"); + AddPath("system", "conf.sft"); AddPath("skin", "current"); AddPath("current", "skin.json"); AddPath("current", "images"); diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index e699939..c934fc6 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -45,6 +45,15 @@ namespace ShiftOS.Engine.Scripting public LuaInterpreter() { + Lua(@"function totable(clrlist) + local t = {} + local it = clrlist:GetEnumerator() + while it:MoveNext() do + t[#t+1] = it.Current + end + return t +end"); + SetupAPIs(); Application.ApplicationExit += (o, a) => { @@ -55,6 +64,14 @@ namespace ShiftOS.Engine.Scripting public void SetupAPIs() { + Lua.registerEvent = new Action>((eventName, callback) => + { + LuaEvent += (e, s) => + { + if(e == eventName) + callback?.Invoke(s); + }; + }); //This temporary proxy() method will be used by the API prober. Lua.proxy = new Func((objName) => { @@ -166,6 +183,21 @@ namespace ShiftOS.Engine.Scripting {e.Message}"); } } + + /// + /// Occurs when a Lua event is fired by C#. + /// + private static event Action LuaEvent; + + /// + /// Raises a Lua event with the specified name and caller object. + /// + /// The name of the event. Scripts use this to check what type of event occurred. + /// The caller of the event. Scripts can use this to check if they should handle this event. + public static void RaiseEvent(string eventName, object caller) + { + LuaEvent?.Invoke(eventName, caller); + } } [Exposed("net")]