Files
MonoGame.Extended/Source/Demos/Demo.Features/GameMain.cs
T
Dylan WilsonandGitHub b3a631aff5 Gui dialogs (#410)
* started refactoring for gui windows

* a bit more work on gui windows

* fixed some bugs and broken build stuff

* fixed some bugs in gui controls

* a little code cleanup

* got gui dialogs positioning and experimenting with named styles by type

* apply control styles directly in the constructor of controls

* got everything compiling again

* all gui controls have skinnable constructors

* rework uniform grid desired size calculations

* turns out gui layouts are complicated

* include pdb files in nuget packages

* fixed a bug in find nearest glyph

* custom control styling

* added a range constructor overload that takes one value

* rethinking control desired size behaviour

* made particle emitters more editable at runtime

* moved the auto trigger code to the particle effect instead of the emitters

* tweaks

* changed the particle modifer interface to an abstract base with an optional name

* changed the particle modifer interface to an abstract base with an optional name

* an attempt at creating a gui combo box

* rolled back the nested control experiment

* pretty good (but not perfect) combo boxes

* tweaks

* name property bindings on lists

* removed and cleaned up the hacks from the gui combo box

* minor combo box styling tweaks

* minor bug fix in gui combo box

* experiments with data binding

* fixed a mistake on the texture region service interface

* working on the ability to serialize particles

* finished particle serialization

* more robust range deserialization

* added editor browable attributes

* fixed some broken demos

* made the particle modifiers editable at runtime

* fixed some issues with particle serialization

* fixed some issues with interpolators
2017-07-22 21:22:13 +10:00

139 lines
4.3 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Demo.Features.Demos;
using Demo.Features.Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
using MonoGame.Extended.Gui;
using MonoGame.Extended.ViewportAdapters;
namespace Demo.Features
{
public class PlatformConfig
{
public bool IsFullScreen { get; set; } = true;
}
public class GameMain : Game
{
// ReSharper disable once NotAccessedField.Local
private readonly GraphicsDeviceManager _graphicsDeviceManager;
private readonly FramesPerSecondCounter _fpsCounter = new FramesPerSecondCounter();
private readonly Dictionary<string, DemoBase> _demos;
private DemoBase _currentDemo;
private GuiSystem _guiSystem;
public ViewportAdapter ViewportAdapter { get; private set; }
public GameMain(PlatformConfig config)
{
_graphicsDeviceManager = new GraphicsDeviceManager(this)
{
IsFullScreen = config.IsFullScreen,
SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight
};
Content.RootDirectory = "Content";
IsMouseVisible = false;
Window.AllowUserResizing = true;
_demos = new DemoBase[]
{
new GuiLayoutDemo(this),
new GuiDemo(this),
//new ScreensDemo(this),
new ViewportAdaptersDemo(this),
new TiledMapsDemo(this),
new AnimationsDemo(this),
new SpritesDemo(this),
new BatchingDemo(this),
new TweeningDemo(this),
new InputListenersDemo(this),
new SceneGraphsDemo(this),
new ParticlesDemo(this),
new CameraDemo(this),
new BitmapFontsDemo(this)
}.ToDictionary(d => d.Name);
}
protected override void Initialize()
{
base.Initialize();
// TODO: Allow switching to full-screen mode from the UI
//if (_isFullScreen)
//{
// _graphicsDeviceManager.IsFullScreen = true;
// _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
// _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
// _graphicsDeviceManager.ApplyChanges();
//}
}
protected override void LoadContent()
{
ViewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
var skin = GuiSkin.FromFile(Content, @"Raw/adventure-gui-skin.json");
var guiRenderer = new GuiSpriteBatchRenderer(GraphicsDevice, ViewportAdapter.GetScaleMatrix);
_guiSystem = new GuiSystem(ViewportAdapter, guiRenderer)
{
Screens = { new SelectDemoScreen(skin, _demos, LoadDemo) }
};
//LoadDemo(_demoIndex);
}
private void LoadDemo(string name)
{
IsMouseVisible = true;
_currentDemo?.Unload();
_currentDemo = _demos[name];
_currentDemo.Load();
}
private KeyboardState _previousKeyboardState;
protected override void Update(GameTime gameTime)
{
var keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Keys.Escape) && _previousKeyboardState.IsKeyUp(Keys.Escape))
Back();
_fpsCounter.Update(gameTime);
_guiSystem.Update(gameTime);
_currentDemo?.OnUpdate(gameTime);
_previousKeyboardState = keyboardState;
base.Update(gameTime);
}
public void Back()
{
if (_guiSystem.Screens[0].IsVisible)
Exit();
IsMouseVisible = false;
_guiSystem.Screens[0].Show();
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
_fpsCounter.Draw(gameTime);
Window.Title = $"{_currentDemo?.Name} {_fpsCounter.FramesPerSecond}";
base.Draw(gameTime);
_currentDemo?.OnDraw(gameTime);
_guiSystem.Draw(gameTime);
}
}
}