diff options
| author | Michael <[email protected]> | 2017-07-26 09:59:48 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-07-26 09:59:48 -0400 |
| commit | 74d0790ab3b91d0a46db526f2599d6bf26172377 (patch) | |
| tree | 9dc783b84a8b677c5c7020e0e584964ff9995f83 /ShiftOS.Frontend | |
| parent | c9b183a0e00720905a0da75a7d20770070a4f61d (diff) | |
| download | shiftos_thereturn-74d0790ab3b91d0a46db526f2599d6bf26172377.tar.gz shiftos_thereturn-74d0790ab3b91d0a46db526f2599d6bf26172377.tar.bz2 shiftos_thereturn-74d0790ab3b91d0a46db526f2599d6bf26172377.zip | |
skin loading and fullscreen toggle in options
Diffstat (limited to 'ShiftOS.Frontend')
| -rw-r--r-- | ShiftOS.Frontend/Apps/SkinLoader.cs | 22 | ||||
| -rw-r--r-- | ShiftOS.Frontend/GUI/CheckBox.cs | 57 | ||||
| -rw-r--r-- | ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs | 22 | ||||
| -rw-r--r-- | ShiftOS.Frontend/MainMenu.cs | 57 | ||||
| -rw-r--r-- | ShiftOS.Frontend/ShiftOS.Frontend.csproj | 2 | ||||
| -rw-r--r-- | ShiftOS.Frontend/ShiftOS.cs | 39 |
6 files changed, 168 insertions, 31 deletions
diff --git a/ShiftOS.Frontend/Apps/SkinLoader.cs b/ShiftOS.Frontend/Apps/SkinLoader.cs new file mode 100644 index 0000000..42f7a47 --- /dev/null +++ b/ShiftOS.Frontend/Apps/SkinLoader.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; +using ShiftOS.Objects.ShiftFS; + +namespace ShiftOS.Frontend.Apps +{ + [FileHandler("Skin Loader", ".skn", "")] + public class SkinLoader : IFileHandler + { + public void OpenFile(string file) + { + string skn = Utils.ReadAllText(file); + Utils.WriteAllText(Paths.GetPath("skin.json"), skn); + SkinEngine.LoadSkin(); + + } + } +} diff --git a/ShiftOS.Frontend/GUI/CheckBox.cs b/ShiftOS.Frontend/GUI/CheckBox.cs new file mode 100644 index 0000000..070967a --- /dev/null +++ b/ShiftOS.Frontend/GUI/CheckBox.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Frontend.GraphicsSubsystem; +using ShiftOS.Engine; +using static ShiftOS.Engine.SkinEngine; +namespace ShiftOS.Frontend.GUI +{ + public class CheckBox : GUI.Control + { + public CheckBox() + { + Width = 24; + Height = 24; + Click += () => + { + Checked = !_checked; + }; + } + + private bool _checked = false; + + public bool Checked + { + get + { + return _checked; + } + set + { + if (value == _checked) + return; + _checked = value; + CheckedChanged?.Invoke(); + Invalidate(); + } + } + + protected override void OnPaint(GraphicsContext gfx) + { + gfx.DrawRectangle(0, 0, Width, Height, UIManager.SkinTextures["ControlTextColor"]); + if (_checked) + { + gfx.DrawRectangle(1, 1, Width - 2, Height - 2, UIManager.SkinTextures["ControlTextColor"]); + } + else + { + gfx.DrawRectangle(1, 1, Width - 2, Height - 2, UIManager.SkinTextures["ControlColor"]); + + } + } + + public event Action CheckedChanged; + } +} diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs index 7bb534e..96ef3cb 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -18,6 +18,28 @@ namespace ShiftOS.Frontend.GraphicsSubsystem private static List<GUI.Control> topLevels = new List<GUI.Control>(); public static System.Drawing.Size Viewport { get; set; } public static GUI.Control FocusedControl = null; + private static ShiftOS _game = null; + + public static void Init(ShiftOS sentience) + { + _game = sentience; + } + + public static bool Fullscreen + { + get + { + return _game.graphicsDevice.IsFullScreen; + } + set + { + var uconf = Objects.UserConfig.Get(); + uconf.Fullscreen = value; + System.IO.File.WriteAllText("config.json", Newtonsoft.Json.JsonConvert.SerializeObject(uconf, Newtonsoft.Json.Formatting.Indented)); + _game.graphicsDevice.IsFullScreen = value; + _game.graphicsDevice.ApplyChanges(); + } + } public static void BringToFront(GUI.Control ctrl) { diff --git a/ShiftOS.Frontend/MainMenu.cs b/ShiftOS.Frontend/MainMenu.cs index 59abb06..12fb033 100644 --- a/ShiftOS.Frontend/MainMenu.cs +++ b/ShiftOS.Frontend/MainMenu.cs @@ -22,6 +22,7 @@ namespace ShiftOS.Frontend private Button _resUp = new Button(); private TextControl _resDisplay = new TextControl(); private Button _optionsSave = new Button(); + private CheckBox _fullscreen = new CheckBox(); public MainMenu() { @@ -39,6 +40,7 @@ namespace ShiftOS.Frontend AddControl(_resDown); AddControl(_resDisplay); AddControl(_optionsSave); + AddControl(_fullscreen); _optionsSave.Text = "Save sentience settings"; _optionsSave.Width = (Width / 4) - 60; @@ -63,6 +65,10 @@ namespace ShiftOS.Frontend _sandbox.Font = _campaign.Font; _sandbox.X = 30; + _fullscreen.X = 30; + _fullscreen.Y = _campaign.Y; + + _options.Text = "Options"; _options.Width = 200; _options.Height = 6 + _campaign.Font.Height; @@ -138,22 +144,35 @@ namespace ShiftOS.Frontend } }; + _fullscreen.CheckedChanged += () => + { + UIManager.Fullscreen = _fullscreen.Checked; + }; + _optionsSave.Click += () => { - var uconf = Objects.UserConfig.Get(); - Engine.Infobox.PromptYesNo("Confirm sentience edit", "Performing this operation requires your sentience to be re-established which may cause you to go unconscious. Do you wish to continue?", (sleep) => + if (UIManager.Viewport != _screenResolutions[_resIndex]) { - if (sleep == true) + + Engine.Infobox.PromptYesNo("Confirm sentience edit", "Performing this operation requires your sentience to be re-established which may cause you to go unconscious. Do you wish to continue?", (sleep) => { - var res = _screenResolutions[_resIndex]; - uconf.ScreenWidth = res.Width; - uconf.ScreenHeight = res.Height; - System.IO.File.WriteAllText("config.json", Newtonsoft.Json.JsonConvert.SerializeObject(uconf, Newtonsoft.Json.Formatting.Indented)); - System.Diagnostics.Process.Start("ShiftOS.Frontend.exe"); - Environment.Exit(-1); - } - }); + if (sleep == true) + { + SaveOptions(); + System.Diagnostics.Process.Start("ShiftOS.Frontend.exe"); + Environment.Exit(-1); + } + }); + } + else + { + SaveOptions(); + _menuTitle.Text = "Main Menu"; + _campaign.Visible = true; + _sandbox.Visible = true; + _options.Visible = true; + } }; foreach(var mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.OrderBy(x=>x.Width * x.Height)) @@ -162,6 +181,17 @@ namespace ShiftOS.Frontend if (UIManager.Viewport == _screenResolutions.Last()) _resIndex = _screenResolutions.Count - 1; } + _fullscreen.Y = _sandbox.Y; + } + + public void SaveOptions() + { + var uconf = Objects.UserConfig.Get(); + var res = _screenResolutions[_resIndex]; + uconf.ScreenWidth = res.Width; + uconf.ScreenHeight = res.Height; + System.IO.File.WriteAllText("config.json", Newtonsoft.Json.JsonConvert.SerializeObject(uconf, Newtonsoft.Json.Formatting.Indented)); + } public void ShowOptions() @@ -272,6 +302,11 @@ namespace ShiftOS.Frontend _resUp.Visible = (_menuTitle.Text == "Options" && _resIndex < _screenResolutions.Count - 1); _resDisplay.Visible = _menuTitle.Text == "Options"; _optionsSave.Visible = _resDisplay.Visible; + _fullscreen.Visible = _optionsSave.Visible; + if (_fullscreen.Visible) + { + _fullscreen.Checked = UIManager.Fullscreen; + } Invalidate(); } diff --git a/ShiftOS.Frontend/ShiftOS.Frontend.csproj b/ShiftOS.Frontend/ShiftOS.Frontend.csproj index 8512511..4e739f9 100644 --- a/ShiftOS.Frontend/ShiftOS.Frontend.csproj +++ b/ShiftOS.Frontend/ShiftOS.Frontend.csproj @@ -45,6 +45,7 @@ <Compile Include="Apps\CodeShop.cs" /> <Compile Include="Apps\FileSkimmer.cs" /> <Compile Include="Apps\Pong.cs" /> + <Compile Include="Apps\SkinLoader.cs" /> <Compile Include="Apps\SystemStatus.cs" /> <Compile Include="Apps\Terminal.cs" /> <Compile Include="Apps\TextPad.cs" /> @@ -54,6 +55,7 @@ <Compile Include="GraphicsSubsystem\GraphicsContext.cs" /> <Compile Include="GraphicsSubsystem\UIManager.cs" /> <Compile Include="GUI\Button.cs" /> + <Compile Include="GUI\CheckBox.cs" /> <Compile Include="GUI\Control.cs" /> <Compile Include="GUI\ItemGroup.cs" /> <Compile Include="GUI\ListBox.cs" /> diff --git a/ShiftOS.Frontend/ShiftOS.cs b/ShiftOS.Frontend/ShiftOS.cs index 51c4e78..88f009a 100644 --- a/ShiftOS.Frontend/ShiftOS.cs +++ b/ShiftOS.Frontend/ShiftOS.cs @@ -16,25 +16,25 @@ namespace ShiftOS.Frontend /// </summary> public class ShiftOS : Game { - GraphicsDeviceManager GraphicsDevice; + internal GraphicsDeviceManager graphicsDevice; SpriteBatch spriteBatch; private bool DisplayDebugInfo = false; public ShiftOS() { - GraphicsDevice = new GraphicsDeviceManager(this); + graphicsDevice = new GraphicsDeviceManager(this); var uconf = Objects.UserConfig.Get(); - GraphicsDevice.PreferredBackBufferHeight = uconf.ScreenHeight; - GraphicsDevice.PreferredBackBufferWidth = uconf.ScreenWidth; + graphicsDevice.PreferredBackBufferHeight = uconf.ScreenHeight; + graphicsDevice.PreferredBackBufferWidth = uconf.ScreenWidth; SkinEngine.SkinLoaded += () => { - UIManager.ResetSkinTextures(GraphicsDevice.GraphicsDevice); + UIManager.ResetSkinTextures(GraphicsDevice); UIManager.InvalidateAll(); }; UIManager.Viewport = new System.Drawing.Size( - GraphicsDevice.PreferredBackBufferWidth, - GraphicsDevice.PreferredBackBufferHeight + graphicsDevice.PreferredBackBufferWidth, + graphicsDevice.PreferredBackBufferHeight ); Content.RootDirectory = "Content"; @@ -49,8 +49,8 @@ namespace ShiftOS.Frontend //Fullscreen - GraphicsDevice.IsFullScreen = false; - + graphicsDevice.IsFullScreen = uconf.Fullscreen; + UIManager.Init(this); } private Keys lastKey = Keys.None; @@ -67,7 +67,7 @@ namespace ShiftOS.Frontend OutOfBoxExperience.Init(new MonoGameOOBE()); //Before we do ANYTHING, we've got to initiate the ShiftOS engine. - UIManager.GraphicsDevice = GraphicsDevice.GraphicsDevice; + UIManager.GraphicsDevice = GraphicsDevice; //Let's get localization going. Localization.RegisterProvider(new MonoGameLanguageProvider()); @@ -119,7 +119,7 @@ namespace ShiftOS.Frontend // Create a new SpriteBatch, which can be used to draw textures. this.spriteBatch = new SpriteBatch(base.GraphicsDevice); - UIManager.ResetSkinTextures(GraphicsDevice.GraphicsDevice); + UIManager.ResetSkinTextures(GraphicsDevice); // TODO: use this.Content to load your game content here @@ -128,7 +128,7 @@ namespace ShiftOS.Frontend byte[] rgb = new byte[Math.Abs(_lock.Stride) * _lock.Height]; Marshal.Copy(_lock.Scan0, rgb, 0, rgb.Length); bmp.UnlockBits(_lock); - MouseTexture = new Texture2D(GraphicsDevice.GraphicsDevice, bmp.Width, bmp.Height); + MouseTexture = new Texture2D(GraphicsDevice, bmp.Width, bmp.Height); MouseTexture.SetData<byte>(rgb); rgb = null; } @@ -200,8 +200,7 @@ namespace ShiftOS.Frontend { if (lastKey == Keys.F11) { - GraphicsDevice.IsFullScreen = !GraphicsDevice.IsFullScreen; - GraphicsDevice.ApplyChanges(); + UIManager.Fullscreen = !UIManager.Fullscreen; } else { @@ -269,7 +268,7 @@ namespace ShiftOS.Frontend /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { - UIManager.DrawControlsToTargets(GraphicsDevice.GraphicsDevice, spriteBatch, 0, 0); + UIManager.DrawControlsToTargets(GraphicsDevice, spriteBatch, 0, 0); var rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; @@ -279,7 +278,7 @@ namespace ShiftOS.Frontend SamplerState.LinearClamp, DepthStencilState.Default, rasterizerState); //Draw the desktop BG. - UIManager.DrawBackgroundLayer(GraphicsDevice.GraphicsDevice, spriteBatch, 640, 480); + UIManager.DrawBackgroundLayer(GraphicsDevice, spriteBatch, 640, 480); //The desktop is drawn, now we can draw the UI. UIManager.DrawTArgets(spriteBatch); @@ -297,7 +296,7 @@ namespace ShiftOS.Frontend if (Hacking.CurrentHackable.DoConnectionTimeout) { string str = $"Connection TImeout in {(Hacking.CurrentHackable.MillisecondsCountdown / 1000).ToString("#.##")} seconds."; - var gfx = new GraphicsContext(GraphicsDevice.GraphicsDevice, spriteBatch, 0, 0, UIManager.Viewport.Width, UIManager.Viewport.Height); + var gfx = new GraphicsContext(GraphicsDevice, spriteBatch, 0, 0, UIManager.Viewport.Width, UIManager.Viewport.Height); var measure = gfx.MeasureString(str, SkinEngine.LoadedSkin.HeaderFont); gfx.DrawString(str, 5, (gfx.Height - ((int)measure.Y) - 5), Color.Red, SkinEngine.LoadedSkin.HeaderFont); } @@ -305,7 +304,7 @@ namespace ShiftOS.Frontend if (DisplayDebugInfo) { - var gfxContext = new GraphicsContext(GraphicsDevice.GraphicsDevice, spriteBatch, 0, 0, GraphicsDevice.PreferredBackBufferWidth, GraphicsDevice.PreferredBackBufferHeight); + var gfxContext = new GraphicsContext(GraphicsDevice, spriteBatch, 0, 0, graphicsDevice.PreferredBackBufferWidth, graphicsDevice.PreferredBackBufferHeight); var color = Color.White; double fps = Math.Round(1 / gameTime.ElapsedGameTime.TotalSeconds); if (fps <= 20) @@ -333,8 +332,8 @@ Skin texture caches: {UIManager.SkinTextures.Count} Open windows (excluding dialog boxes): {AppearanceManager.OpenForms.Count} Experimental effects enabled: {UIManager.ExperimentalEffects} -Fullscreen: {GraphicsDevice.IsFullScreen} -Game resolution: {GraphicsDevice.PreferredBackBufferWidth}x{GraphicsDevice.PreferredBackBufferHeight} +Fullscreen: {UIManager.Fullscreen} +Game resolution: {graphicsDevice.PreferredBackBufferWidth}x{graphicsDevice.PreferredBackBufferHeight} Mouse state: X: {LastMouseState.X} |
