WHOA LUA STUFF 💃

This commit is contained in:
Michael 2017-02-18 10:37:11 -05:00
parent 30823a0778
commit 9b8d5861a9
17 changed files with 662 additions and 94 deletions

View file

@ -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;
}
}

View file

@ -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<IDesktop> GetAllDesktops()
{
List<IDesktop> dekstops = new List<IDesktop>();
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<ShiftOSConfigFile>(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<string>((script) =>
{
ShiftOSConfigFile conf = new WinForms.ShiftOSConfigFile();
if (Utils.FileExists(Paths.GetPath("conf.sft")))
{
conf = JsonConvert.DeserializeObject<ShiftOSConfigFile>(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
{
}
}
}
}
}

View file

@ -120,4 +120,7 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="menuStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
</root>

View file

@ -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)
{
}
}
}

View file

@ -28,11 +28,32 @@
/// </summary>
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;
}
}

View file

@ -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<Panel>(() =>
{
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<LauncherItem>(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;
}
/// <summary>
/// Kills the window.
/// </summary>
/// <returns>The window.</returns>
/// <param name="border">Border.</param>
public void KillWindow(IWindowBorder border)
{
border.Close();
}
/// <summary>
/// Minimizes the window.
/// </summary>
/// <param name="brdr">Brdr.</param>
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);
}
/// <summary>
/// Maximizes the window.
/// </summary>
/// <returns>The window.</returns>
/// <param name="brdr">Brdr.</param>
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);
}
/// <summary>
/// Restores the window.
/// </summary>
/// <returns>The window.</returns>
/// <param name="brdr">Brdr.</param>
public void RestoreWindow(IWindowBorder brdr)
{
dynamic tag = JsonConvert.DeserializeObject<dynamic>((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();
}
};
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -207,6 +207,7 @@
<Compile Include="FakeSetupScreen.Designer.cs">
<DependentUpon>FakeSetupScreen.cs</DependentUpon>
</Compile>
<Compile Include="GUIFunctions.cs" />
<Compile Include="JobTasks.cs" />
<Compile Include="LuaDesktop.cs">
<SubType>Form</SubType>
@ -221,12 +222,19 @@
<DependentUpon>Oobe.cs</DependentUpon>
</Compile>
<Compile Include="ShiftOSAudioProvider.cs" />
<Compile Include="ShiftOSConfigFile.cs" />
<Compile Include="Tools\ColorPickerDataBackend.cs" />
<Compile Include="Tools\ControlManager.cs" />
<Compile Include="Tools\DitheringEngine.cs" />
<Compile Include="Tools\ShiftOSMenuRenderer.cs" />
<Compile Include="TrailerCommands.cs" />
<Compile Include="WFLanguageProvider.cs" />
<Compile Include="Window.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Window.Designer.cs">
<DependentUpon>Window.cs</DependentUpon>
</Compile>
<Compile Include="WindowBorder.cs">
<SubType>Form</SubType>
</Compile>
@ -305,6 +313,9 @@
<EmbeddedResource Include="FakeSetupScreen.resx">
<DependentUpon>FakeSetupScreen.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LuaDesktop.resx">
<DependentUpon>LuaDesktop.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Oobe.resx">
<DependentUpon>Oobe.cs</DependentUpon>
</EmbeddedResource>

View file

@ -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<string>();
}
public float AudioVolume { get; set; }
public List<string> Desktops { get; set; }
}
}

37
ShiftOS.WinForms/Window.Designer.cs generated Normal file
View file

@ -0,0 +1,37 @@
namespace ShiftOS.WinForms
{
partial class Window
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
/// <summary>

View file

@ -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)

View file

@ -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<IDesktop> desktops = new List<IDesktop>();
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)

View file

@ -57,16 +57,22 @@ namespace ShiftOS.Engine
/// <param name="message">Infobox message</param>
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<string> callback)
{
title = Localization.Parse(title);
message = Localization.Parse(message);
_infobox.PromptText(title, message, callback);
}
public static void PromptYesNo(string title, string message, Action<bool> callback)
{
title = Localization.Parse(title);
message = Localization.Parse(message);
_infobox.PromptYesNo(title, message, callback);
}

View file

@ -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");

View file

@ -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<string, Action<object>>((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<string, dynamic>((objName) =>
{
@ -166,6 +183,21 @@ namespace ShiftOS.Engine.Scripting
{e.Message}");
}
}
/// <summary>
/// Occurs when a Lua event is fired by C#.
/// </summary>
private static event Action<string, object> LuaEvent;
/// <summary>
/// Raises a Lua event with the specified name and caller object.
/// </summary>
/// <param name="eventName">The name of the event. Scripts use this to check what type of event occurred.</param>
/// <param name="caller">The caller of the event. Scripts can use this to check if they should handle this event.</param>
public static void RaiseEvent(string eventName, object caller)
{
LuaEvent?.Invoke(eventName, caller);
}
}
[Exposed("net")]