aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-08-06 20:03:10 -0400
committerMichael <[email protected]>2017-08-06 20:03:10 -0400
commit0af9c840293bff1a0ad699fdd9f3a549294feef9 (patch)
treee3375faf95fa454c602a988dd9de1513f5f39354
parent97a5a97370bc8f4d721791457d551c6bd2b0b67c (diff)
downloadshiftos_thereturn-0af9c840293bff1a0ad699fdd9f3a549294feef9.tar.gz
shiftos_thereturn-0af9c840293bff1a0ad699fdd9f3a549294feef9.tar.bz2
shiftos_thereturn-0af9c840293bff1a0ad699fdd9f3a549294feef9.zip
wip shifter and infobox prison
-rw-r--r--ShiftOS.Frontend/Apps/Shifter.cs162
-rw-r--r--ShiftOS.Frontend/Apps/SkinLoader.cs209
-rw-r--r--ShiftOS.Frontend/Commands.cs35
-rw-r--r--ShiftOS.Frontend/GUI/Control.cs10
-rw-r--r--ShiftOS.Frontend/ShiftOS.Frontend.csproj1
5 files changed, 414 insertions, 3 deletions
diff --git a/ShiftOS.Frontend/Apps/Shifter.cs b/ShiftOS.Frontend/Apps/Shifter.cs
new file mode 100644
index 0000000..0572ed5
--- /dev/null
+++ b/ShiftOS.Frontend/Apps/Shifter.cs
@@ -0,0 +1,162 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework;
+using Newtonsoft.Json;
+using ShiftOS.Engine;
+using ShiftOS.Frontend.GUI;
+
+namespace ShiftOS.Frontend.Apps
+{
+ [WinOpen("shifter")]
+ [DefaultTitle("Shifter")]
+ [Launcher("Shifter", false, null, "Customization")]
+ public class Shifter : Control, IShiftOSWindow
+ {
+ private const int metaWidth = 150;
+ private Button _apply = null;
+ private List<Button> _meta = new List<Button>();
+ private Skin _skin = null;
+ private string _metaCurrent = "";
+ private string _catCurrent = "";
+ private List<Button> _catList = new List<Button>();
+
+ public Shifter()
+ {
+ _apply = new GUI.Button();
+
+ AddControl(_apply);
+ _apply.Width = metaWidth;
+ _apply.Height = 50;
+ _skin = JsonConvert.DeserializeObject<Skin>(JsonConvert.SerializeObject(SkinEngine.LoadedSkin));
+ }
+
+ protected override void OnLayout(GameTime gameTime)
+ {
+ base.OnLayout(gameTime);
+ _apply.X = 10;
+ _apply.Y = Height - _apply.Height - 10;
+ _apply.Text = "Apply Changes";
+
+ int metay = 10;
+ foreach(var btn in _meta)
+ {
+ btn.X = 10;
+ btn.Y = metay;
+ btn.Height = 25;
+ btn.Width = metaWidth;
+ metay += btn.Height + 10;
+ }
+
+ int catY = Height - 10;
+ foreach(var btn in _catList)
+ {
+ btn.Width = metaWidth;
+ btn.Height = 25;
+ catY -= btn.Height;
+ btn.Y = catY;
+ catY -= 10;
+ btn.X = 20 + metaWidth;
+ }
+ }
+
+ public void ResetMetaListing()
+ {
+ var type = _skin.GetType();
+ List<string> metanames = new List<string>();
+ foreach (var field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
+ {
+ var meta = field.GetCustomAttributes(false).FirstOrDefault(x => x is ShifterMetaAttribute) as ShifterMetaAttribute;
+ if(meta != null)
+ {
+ if (!metanames.Contains(meta.Meta))
+ metanames.Add(meta.Meta);
+ }
+ }
+ while(_meta.Count > 0)
+ {
+ RemoveControl(_meta[0]);
+ ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; //IT'S THE SEMICOLON PARTYFEST
+ //that's actually valid C#
+ //like, VS isn't fucking freaking out
+ //wtf
+ //Microsoft, you're drunk.
+ _meta.RemoveAt(0);
+
+ }
+ foreach (var meta in metanames)
+ {
+ var button = new Button();
+ button.Click += () =>
+ {
+ _metaCurrent = meta;
+ ResetCategoryListing();
+ };
+ button.Text = Localization.Parse(meta);
+ AddControl(button);
+ _meta.Add(button);
+ }
+ }
+
+ public void ResetCategoryListing()
+ {
+ while(_catList.Count > 0)
+ {
+ RemoveControl(_catList[0]);
+ _catList.RemoveAt(0);
+ }
+ List<string> catnames = new List<string>();
+ var type = _skin.GetType();
+ foreach (var field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
+ {
+ var meta = field.GetCustomAttributes(false).FirstOrDefault(x => x is ShifterMetaAttribute) as ShifterMetaAttribute;
+ if (meta != null)
+ {
+ if(meta.Meta == _metaCurrent)
+ {
+ var cat = field.GetCustomAttributes(false).FirstOrDefault(x => x is ShifterCategoryAttribute) as ShifterCategoryAttribute;
+ if(cat != null)
+ {
+ if (!catnames.Contains(cat.Category))
+ catnames.Add(cat.Category);
+ }
+ }
+ }
+ }
+
+ foreach (var meta in catnames)
+ {
+ var button = new Button();
+ button.Click += () =>
+ {
+ _catCurrent = meta;
+ //ResetValueEditor();
+ };
+ button.Text = Localization.Parse(meta);
+ AddControl(button);
+ _catList.Add(button);
+ }
+
+ }
+
+ public void OnLoad()
+ {
+ ResetMetaListing();
+ }
+
+ public void OnSkinLoad()
+ {
+ }
+
+ public bool OnUnload()
+ {
+ return true;
+ }
+
+ public void OnUpgrade()
+ {
+ }
+ }
+}
diff --git a/ShiftOS.Frontend/Apps/SkinLoader.cs b/ShiftOS.Frontend/Apps/SkinLoader.cs
index ebd693f..8711d92 100644
--- a/ShiftOS.Frontend/Apps/SkinLoader.cs
+++ b/ShiftOS.Frontend/Apps/SkinLoader.cs
@@ -29,6 +29,210 @@ namespace ShiftOS.Frontend.Apps
private Button _apply = null;
private Dictionary<string, Texture2D> SkinTextures = new Dictionary<string, Texture2D>();
+ public void PaintWindow(GraphicsContext gfx)
+ {
+ int titleheight = _skin.TitlebarHeight;
+ int leftborderwidth = _skin.LeftBorderWidth;
+ int rightborderwidth = _skin.RightBorderWidth;
+ int bottomborderwidth = _skin.BottomBorderWidth;
+
+ var titlebarcolor = SkinTextures["TitleBackgroundColor"];
+ var titlefont = _skin.TitleFont;
+ var titletextcolor = _skin.TitleTextColor;
+ var titletextleft = _skin.TitleTextLeft;
+ bool titletextcentered = _skin.TitleTextCentered;
+
+ var drawcorners = _skin.ShowTitleCorners;
+ int titlebarleft = _previewxstart;
+ int titlebarwidth = _previewxwidth;
+ if (drawcorners)
+ {
+ //set titleleft to the first corner width
+ titlebarleft += _skin.TitleLeftCornerWidth;
+ titlebarwidth -= _skin.TitleLeftCornerWidth;
+ titlebarwidth -= _skin.TitleRightCornerWidth;
+
+
+ //Let's get the left and right images.
+ //and the colors
+ var leftcolor = SkinTextures["TitleLeftCornerBackground"];
+ var rightcolor = SkinTextures["TitleRightCornerBackground"];
+ //and the widths
+ var leftwidth = _skin.TitleLeftCornerWidth;
+ var rightwidth = _skin.TitleRightCornerWidth;
+
+ //draw left corner
+ if (SkinTextures.ContainsKey("titleleft"))
+ {
+ gfx.DrawRectangle(_previewxstart, _windowystart, leftwidth, titleheight, SkinTextures["titleleft"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(_previewxstart, _windowystart, leftwidth, titleheight, leftcolor);
+ }
+
+ //draw right corner
+ if (SkinTextures.ContainsKey("titleright"))
+ {
+ gfx.DrawRectangle(titlebarleft + titlebarwidth, _windowystart, rightwidth, titleheight, SkinTextures["titleright"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(titlebarleft + titlebarwidth, _windowystart, rightwidth, titleheight, rightcolor);
+ }
+ }
+
+ if (!SkinTextures.ContainsKey("titlebar"))
+ {
+ //draw the title bg
+ gfx.DrawRectangle(titlebarleft, _windowystart, titlebarwidth, titleheight, titlebarcolor);
+
+ }
+ else
+ {
+ gfx.DrawRectangle(titlebarleft, _windowystart, titlebarwidth, titleheight, SkinTextures["titlebar"]);
+ }
+ //Now we draw the title text.
+ var textMeasure = gfx.MeasureString("Program window", titlefont);
+ Vector2 textloc;
+ if (titletextcentered)
+ textloc = new Vector2((titlebarwidth - textMeasure.X) / 2,
+ _windowystart + titletextleft.Y);
+ else
+ textloc = new Vector2(titlebarleft + titletextleft.X, _windowystart + titletextleft.Y);
+
+ gfx.DrawString("Program window", (int)textloc.X, (int)textloc.Y, titletextcolor.ToMonoColor(), titlefont);
+
+ var tbuttonpos = _skin.TitleButtonPosition;
+
+ //Draw close button
+ var closebuttonsize = _skin.CloseButtonSize;
+ var closebuttonright = _skin.CloseButtonFromSide;
+ if (_skin.TitleButtonPosition == 0)
+ closebuttonright = new System.Drawing.Point(_previewxstart + (_previewxwidth - closebuttonsize.Width - closebuttonright.X), _windowystart + closebuttonright.Y);
+ else
+ closebuttonright = new System.Drawing.Point(_previewxstart + closebuttonright.X, _windowystart + closebuttonright.Y);
+ if (!SkinTextures.ContainsKey("closebutton"))
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, SkinTextures["CloseButtonColor"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, SkinTextures["closebutton"]);
+ }
+
+ //Draw maximize button
+ closebuttonsize = _skin.MaximizeButtonSize;
+ closebuttonright = _skin.MaximizeButtonFromSide;
+ if (_skin.TitleButtonPosition == 0)
+ closebuttonright = new System.Drawing.Point(_previewxstart + (_previewxwidth - closebuttonsize.Width - closebuttonright.X), _windowystart + closebuttonright.Y);
+ else
+ closebuttonright = new System.Drawing.Point(_previewxstart + closebuttonright.X, _windowystart + closebuttonright.Y);
+
+ if (!SkinTextures.ContainsKey("maximizebutton"))
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, SkinTextures["MaximizeButtonColor"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, SkinTextures["maximizebutton"]);
+ }
+
+ //Draw minimize button
+ closebuttonsize = _skin.MinimizeButtonSize;
+ closebuttonright = _skin.MinimizeButtonFromSide;
+ if (_skin.TitleButtonPosition == 0)
+ closebuttonright = new System.Drawing.Point(_previewxstart + (_previewxwidth - closebuttonsize.Width - closebuttonright.X), _windowystart + closebuttonright.Y);
+ else
+ closebuttonright = new System.Drawing.Point(_previewxstart + closebuttonright.X, _windowystart + closebuttonright.Y);
+ if (!SkinTextures.ContainsKey("minimizebutton"))
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, SkinTextures["MinimizeButtonColor"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, SkinTextures["minimizebutton"]);
+ }
+
+
+
+ //Some variables we'll need...
+ int bottomlocy = _windowystart + (_previewheight - _skin.BottomBorderWidth);
+ int bottomlocx = _previewxstart + leftborderwidth;
+ int bottomwidth = _previewxwidth - bottomlocx - rightborderwidth;
+ int brightlocx = _previewxstart + (_previewxwidth - rightborderwidth);
+
+ var borderleftcolor = (ContainsFocusedControl || IsFocusedControl) ? SkinTextures["BorderLeftBackground"] : SkinTextures["BorderInactiveLeftBackground"];
+ var borderrightcolor = (ContainsFocusedControl || IsFocusedControl) ? SkinTextures["BorderRightBackground"] : SkinTextures["BorderInactiveRightBackground"];
+ var borderbottomcolor = (ContainsFocusedControl || IsFocusedControl) ? SkinTextures["BorderBottomBackground"] : SkinTextures["BorderInactiveBottomBackground"];
+ var borderbleftcolor = (ContainsFocusedControl || IsFocusedControl) ? SkinTextures["BorderBottomLeftBackground"] : SkinTextures["BorderInactiveBottomLeftBackground"];
+ var borderbrightcolor = (ContainsFocusedControl || IsFocusedControl) ? SkinTextures["BorderBottomRightBackground"] : SkinTextures["BorderInactiveBottomRightBackground"];
+
+
+ //draw border corners
+ //BOTTOM LEFT
+ if (!SkinTextures.ContainsKey("bottomlborder"))
+ {
+ gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, borderbleftcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, SkinTextures["bottomlborder"]);
+ }
+
+ //BOTTOM RIGHT
+ if (!SkinTextures.ContainsKey("bottomrborder"))
+ {
+ gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, borderbrightcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, SkinTextures["bottomrborder"]);
+ }
+
+ //BOTTOM
+ if (!SkinTextures.ContainsKey("bottomborder"))
+ {
+ gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, borderbottomcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, SkinTextures["bottomborder"]);
+ }
+
+ //LEFT
+ if (!SkinTextures.ContainsKey("leftborder"))
+ {
+ gfx.DrawRectangle(_previewxstart, _windowystart + titleheight, leftborderwidth, _previewheight - titleheight - bottomborderwidth, borderleftcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(_previewxstart, _windowystart + titleheight, leftborderwidth, _previewheight - titleheight - bottomborderwidth, SkinTextures["leftborder"]);
+ }
+
+ //RIGHT
+ if (!SkinTextures.ContainsKey("rightborder"))
+ {
+ gfx.DrawRectangle(brightlocx, _windowystart + titleheight, rightborderwidth, _previewheight - titleheight - bottomborderwidth, borderrightcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(brightlocx, _windowystart + titleheight, rightborderwidth, _previewheight - titleheight - bottomborderwidth, SkinTextures["rightborder"]);
+ }
+
+
+
+ gfx.DrawRectangle(_previewxstart + leftborderwidth, _windowystart + titleheight, _previewxwidth - leftborderwidth - rightborderwidth, _previewheight - titleheight - bottomborderwidth, SkinTextures["ControlColor"]);
+ //So here's what we're gonna do now.
+ //Now that we have a titlebar and window borders...
+ //We're going to composite the hosted window
+ //and draw it to the remaining area.
+
+ //Painting of the canvas is done by the Paint() method.
+
+ }
+
+
public SkinLoader()
{
_close = new GUI.Button();
@@ -369,9 +573,8 @@ namespace ShiftOS.Frontend.Apps
//Now we actually paint the ui
PaintDesktop(gfx);
- //Paint the window rect
- gfx.DrawRectangle(_previewxstart, _windowystart, _previewxwidth, _previewheight, Color.Red);
-
+ //The desktop's painted, now time for the window.
+ PaintWindow(gfx);
}
}
}
diff --git a/ShiftOS.Frontend/Commands.cs b/ShiftOS.Frontend/Commands.cs
index 29d8409..10003c4 100644
--- a/ShiftOS.Frontend/Commands.cs
+++ b/ShiftOS.Frontend/Commands.cs
@@ -48,6 +48,41 @@ namespace ShiftOS.Frontend
{
public static class FrontendDebugCommands
{
+ [Command("infobox_prison")]
+ [ShellConstraint("shiftos_debug> ")]
+ public static void InfoboxPrison()
+ {
+ var ibox = new InfoboxMessage("Infobox Prison", "You are now sentenced to life in Infobox Prison.");
+ ibox.ShowPrompt(() =>
+ {
+ InfoboxPrison();
+ InfoboxPrison();
+ });
+ var t = new Thread(() =>
+ {
+ var parent = ibox.Parent;
+ int xvel = 3;
+ int yvel = 3;
+ while (parent.Visible)
+ {
+ if (parent.X + parent.Width >= UIManager.Viewport.Width)
+ xvel = -xvel;
+ if (parent.X <= 0)
+ xvel = -xvel;
+ if (parent.Y <= 0)
+ yvel = -yvel;
+ if (parent.Y + parent.Height >= UIManager.Viewport.Height)
+ yvel = -yvel;
+ parent.X += xvel;
+ parent.Y += yvel;
+ Thread.Sleep(50);
+ }
+ InfoboxPrison();
+ InfoboxPrison();
+ });
+ t.Start();
+ }
+
[Command("set_ui_tint")]
[RequiresArgument("color")]
[ShellConstraint("shiftos_debug> ")]
diff --git a/ShiftOS.Frontend/GUI/Control.cs b/ShiftOS.Frontend/GUI/Control.cs
index 6941b7b..43f7931 100644
--- a/ShiftOS.Frontend/GUI/Control.cs
+++ b/ShiftOS.Frontend/GUI/Control.cs
@@ -369,6 +369,16 @@ namespace ShiftOS.Frontend.GUI
Invalidate();
}
+ public void RemoveControl(Control ctrl)
+ {
+ if(_children.Contains(ctrl))
+ {
+ _children.Remove(ctrl);
+ ctrl._parent = null;
+ Invalidate();
+ }
+ }
+
public Point PointToLocal(int x, int y)
{
return new GUI.Point(x - _x, y - _y);
diff --git a/ShiftOS.Frontend/ShiftOS.Frontend.csproj b/ShiftOS.Frontend/ShiftOS.Frontend.csproj
index fdb47d6..1bad909 100644
--- a/ShiftOS.Frontend/ShiftOS.Frontend.csproj
+++ b/ShiftOS.Frontend/ShiftOS.Frontend.csproj
@@ -48,6 +48,7 @@
<Compile Include="Apps\Installer.cs" />
<Compile Include="Apps\Network.cs" />
<Compile Include="Apps\Pong.cs" />
+ <Compile Include="Apps\Shifter.cs" />
<Compile Include="Apps\SkinLoader.cs" />
<Compile Include="Apps\SystemStatus.cs" />
<Compile Include="Apps\Terminal.cs" />