From 9b8d5861a954610713ae66a53d2ac067991d9b68 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 18 Feb 2017 10:37:11 -0500 Subject: WHOA LUA STUFF :dancer: --- ShiftOS.WinForms/LuaDesktop.cs | 158 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 140 insertions(+), 18 deletions(-) (limited to 'ShiftOS.WinForms/LuaDesktop.cs') 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) + public void PopulateAppLauncher(LauncherItem[] items) { - throw new NotImplementedException(); + interpreter.Lua.populateAppLauncher(interpreter.Lua.totable(new List(items))); } - public void MaximizeWindow(IWindowBorder brdr) + public void PopulatePanelButtons() { - throw new NotImplementedException(); + interpreter.Lua.populatePanelButtons(); } - public void MinimizeWindow(IWindowBorder brdr) + 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 PopulateAppLauncher(LauncherItem[] items) + public void ShowWindow(IWindowBorder border) { - + var brdr = border as Form; + focused = border; + brdr.GotFocus += (o, a) => + { + focused = border; + }; + brdr.FormBorderStyle = FormBorderStyle.None; + brdr.Show(); + brdr.TopMost = true; } - public void PopulatePanelButtons() + /// + /// Kills the window. + /// + /// The window. + /// Border. + public void KillWindow(IWindowBorder border) { - throw new NotImplementedException(); + border.Close(); } - public void RestoreWindow(IWindowBorder brdr) + /// + /// 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) { - throw new NotImplementedException(); + 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); + } - public void SetupDesktop() + /// + /// Restores the window. + /// + /// The window. + /// Brdr. + public void RestoreWindow(IWindowBorder brdr) { - throw new NotImplementedException(); + dynamic tag = JsonConvert.DeserializeObject((brdr as WindowBorder).Tag.ToString()); + (brdr as WindowBorder).Location = tag.Location; + (brdr as WindowBorder).Size = tag.Size; + } - public void ShowWindow(IWindowBorder border) + private void LuaDesktop_Load(object sender, EventArgs e) { - throw new NotImplementedException(); + 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(); + } + + }; + } } } -- cgit v1.2.3