Fix widget stacking

This commit is contained in:
Michael 2017-04-23 08:06:00 -04:00
parent 1fd16be65f
commit ba0ae29bbb
6 changed files with 446 additions and 94 deletions

View file

@ -45,11 +45,13 @@ using ShiftOS.Engine;
using ShiftOS.Objects;
using ShiftOS.WinForms.Tools;
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<string> ConsoleStack = new Stack<string>();
public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer();
@ -60,72 +62,97 @@ 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;
TerminalBackend.PrintPrompt();
if (Shiftorium.UpgradeInstalled("wm_free_placement"))
if (!Shiftorium.UpgradeInstalled("desktop"))
{
this.ParentForm.Width = 640;
this.ParentForm.Height = 480;
this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2;
this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2;
TerminalBackend.PrefixEnabled = true;
TerminalBackend.InStory = false;
TerminalBackend.PrintPrompt();
if (Shiftorium.UpgradeInstalled("wm_free_placement"))
{
this.ParentForm.Width = 640;
this.ParentForm.Height = 480;
this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2;
this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2;
}
}
else
{
AppearanceManager.Close(this);
}
}));
} catch { }
}
catch { }
};
@ -133,21 +160,32 @@ 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();
}
@ -157,7 +195,8 @@ namespace ShiftOS.WinForms.Applications {
public static event TextSentEventHandler TextSent;
public void ResetAllKeywords() {
public void ResetAllKeywords()
{
string primary = SaveSystem.CurrentSave.Username + " ";
string secondary = "shiftos ";
@ -166,18 +205,27 @@ 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 + " ";
@ -193,14 +241,19 @@ 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();
@ -208,29 +261,44 @@ 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) {
if(text3 == "stop theme") {
if (TerminalBackend.InStory == false)
{
if (text3 == "stop theme")
{
CurrentCommandParser.parser = null;
}else {
if(CurrentCommandParser.parser == null) {
}
else
{
if (CurrentCommandParser.parser == null)
{
TerminalBackend.InvokeCommand(text3);
} else {
}
else
{
var result = CurrentCommandParser.parser.ParseCommand(text3);
if (result.Equals(default(KeyValuePair<KeyValuePair<string, string>, Dictionary<string, string>>))) {
if (result.Equals(default(KeyValuePair<KeyValuePair<string, string>, Dictionary<string, string>>)))
{
Console.WriteLine("Syntax Error: Syntax Error");
} else {
}
else
{
TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value);
}
}
@ -241,23 +309,35 @@ namespace ShiftOS.WinForms.Applications {
TerminalBackend.PrintPrompt();
}
}
} catch {
}
} else if (a.KeyCode == Keys.Back) {
try {
catch
{
}
}
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}:~$ ";
@ -266,19 +346,27 @@ 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;
}
} 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++;
@ -287,7 +375,7 @@ namespace ShiftOS.WinForms.Applications {
};
AppearanceManager.ConsoleOut = txt;
txt.Focus();
txt.Font = LoadedSkin.TerminalFont;
@ -296,12 +384,17 @@ 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 = "";
}
@ -309,17 +402,21 @@ 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.Select(rtbterm.TextLength, 0);
}
TerminalBackend.PrintPrompt();
@ -328,8 +425,10 @@ namespace ShiftOS.WinForms.Applications {
}
public void OnSkinLoad() {
try {
public void OnSkinLoad()
{
try
{
rtbterm.Font = LoadedSkin.TerminalFont;
rtbterm.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC);
rtbterm.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC);
@ -341,19 +440,27 @@ namespace ShiftOS.WinForms.Applications {
}
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;
@ -363,10 +470,12 @@ 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)
{
}

View file

@ -0,0 +1,61 @@
namespace ShiftOS.WinForms.DesktopWidgets
{
partial class CodepointsWidget
{
/// <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()
{
this.lbcodepoints = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lbcodepoints
//
this.lbcodepoints.Cursor = System.Windows.Forms.Cursors.Default;
this.lbcodepoints.Dock = System.Windows.Forms.DockStyle.Fill;
this.lbcodepoints.Location = new System.Drawing.Point(0, 0);
this.lbcodepoints.Name = "lbcodepoints";
this.lbcodepoints.Size = new System.Drawing.Size(274, 57);
this.lbcodepoints.TabIndex = 0;
this.lbcodepoints.Tag = "header3";
this.lbcodepoints.Text = "label1";
this.lbcodepoints.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// CodepointsWidget
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lbcodepoints);
this.Name = "CodepointsWidget";
this.Size = new System.Drawing.Size(274, 57);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label lbcodepoints;
}
}

View file

@ -0,0 +1,53 @@
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.WinForms.Tools;
using ShiftOS.Engine;
namespace ShiftOS.WinForms.DesktopWidgets
{
[DesktopWidget("Codepoints Display", "Show how many Codepoints you have.")]
public partial class CodepointsWidget : UserControl, IDesktopWidget
{
public CodepointsWidget()
{
InitializeComponent();
tmr.Tick += (o, a) =>
{
try
{
lbcodepoints.Text = SaveSystem.CurrentSave.Codepoints.ToString() + " Codepoints";
}
catch { }
};
tmr.Interval = 350;
this.VisibleChanged += (o, a) =>
{
if (this.Visible == false)
tmr.Stop();
};
}
Timer tmr = new Timer();
public void OnSkinLoad()
{
ControlManager.SetupControls(this);
}
public void OnUpgrade()
{
}
public void Setup()
{
tmr.Start();
}
}
}

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

@ -270,6 +270,12 @@
<Compile Include="DesktopWidgets\Clock.Designer.cs">
<DependentUpon>Clock.cs</DependentUpon>
</Compile>
<Compile Include="DesktopWidgets\CodepointsWidget.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="DesktopWidgets\CodepointsWidget.Designer.cs">
<DependentUpon>CodepointsWidget.cs</DependentUpon>
</Compile>
<Compile Include="DesktopWidgets\TerminalWidget.cs">
<SubType>UserControl</SubType>
</Compile>
@ -434,6 +440,9 @@
<EmbeddedResource Include="DesktopWidgets\Clock.resx">
<DependentUpon>Clock.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DesktopWidgets\CodepointsWidget.resx">
<DependentUpon>CodepointsWidget.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DesktopWidgets\TerminalWidget.resx">
<DependentUpon>TerminalWidget.cs</DependentUpon>
</EmbeddedResource>

View file

@ -475,7 +475,7 @@ namespace ShiftOS.WinForms
if (widget.Location.X == -1 && widget.Location.Y == -1)
{
widget.Location = new Point(5, lastHeight);
lastHeight += (widget.Location.Y + widget.Size.Height) + 5;
lastHeight += widget.Size.Height + 5;
}
}
else