wip shifter and infobox prison

This commit is contained in:
Michael 2017-08-06 20:03:10 -04:00
parent 97a5a97370
commit 0af9c84029
5 changed files with 414 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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" />