Add ScrennManager
This commit is contained in:
parent
efd6596421
commit
011787c7fa
|
@ -10,7 +10,7 @@ namespace Exemple
|
||||||
{
|
{
|
||||||
enum GameState { Menu, Credit }
|
enum GameState { Menu, Credit }
|
||||||
|
|
||||||
GraphicsDeviceManager graphics;
|
ScreenManager screen;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
ResourcesManager resources;
|
ResourcesManager resources;
|
||||||
InputsManager inputs;
|
InputsManager inputs;
|
||||||
|
@ -22,16 +22,7 @@ namespace Exemple
|
||||||
|
|
||||||
public MainGame()
|
public MainGame()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
screen = new ScreenManager(this);
|
||||||
|
|
||||||
Window.AllowUserResizing = true;
|
|
||||||
Window.AllowUserResizing = true;
|
|
||||||
Window.ClientSizeChanged += delegate
|
|
||||||
{
|
|
||||||
graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
|
|
||||||
graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
|
|
||||||
graphics.ApplyChanges();
|
|
||||||
};
|
|
||||||
|
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
|
|
||||||
|
@ -41,13 +32,7 @@ namespace Exemple
|
||||||
|
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
graphics.PreferredBackBufferWidth = 800;
|
screen.Initialize(new Vector(800, 600), false, true, true);
|
||||||
graphics.PreferredBackBufferHeight = 600;
|
|
||||||
graphics.IsFullScreen = false;
|
|
||||||
graphics.ApplyChanges();
|
|
||||||
|
|
||||||
IsMouseVisible = true;
|
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,37 +58,37 @@ namespace Exemple
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
graphics.GraphicsDevice.Clear(Color.DarkGray);
|
screen.Clear(Color.DarkGray);
|
||||||
|
|
||||||
spriteBatch.Begin();
|
spriteBatch.Begin();
|
||||||
ui.Texture(new Rectangle(10, 10, 200, 150), resources.Textures["Background"]);
|
ui.Texture(new Rectangle(10, 10, 200, 150), resources.Textures["Background"]);
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case GameState.Credit:
|
case GameState.Credit:
|
||||||
ui.Box(new Rectangle(200, 100, graphics.PreferredBackBufferWidth - 400, graphics.PreferredBackBufferWidth - 200), new Colors(Color.LightGray, Color.White));
|
ui.Box(new Rectangle(200, 100, screen.size.X - 400, screen.size.X - 200), new Colors(Color.LightGray, Color.White));
|
||||||
ui.Label(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 4), "By Sheychen", new Colors(Color.Red, Color.OrangeRed), null, UIManager.textAlign.centerCenter);
|
ui.Label(new Vector(screen.size.X / 2, screen.size.Y / 4), "By Sheychen", new Colors(Color.Red, Color.OrangeRed), null, UIManager.textAlign.centerCenter);
|
||||||
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2 - 100, 200, 40), "My website"))
|
if (ui.Button(new Rectangle(screen.size.X / 2 - 100, screen.size.Y / 2 - 100, 200, 40), "My website"))
|
||||||
{
|
{
|
||||||
Process.Start("https://sheychen.shost.ca");
|
Process.Start("https://sheychen.shost.ca");
|
||||||
}
|
}
|
||||||
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2 - 50, 200, 40), "Show on GitHub"))
|
if (ui.Button(new Rectangle(screen.size.X / 2 - 100, screen.size.Y / 2 - 50, 200, 40), "Show on GitHub"))
|
||||||
{
|
{
|
||||||
Process.Start("https://github.com/sheychen290/MyMonoGame");
|
Process.Start("https://github.com/sheychen290/MyMonoGame");
|
||||||
}
|
}
|
||||||
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2, 200, 40), "Back"))
|
if (ui.Button(new Rectangle(screen.size.X / 2 - 100, screen.size.Y / 2, 200, 40), "Back"))
|
||||||
{
|
{
|
||||||
state = GameState.Menu;
|
state = GameState.Menu;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GameState.Menu:
|
case GameState.Menu:
|
||||||
ui.Label(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 4), "MyMonoGameAddin", new Colors(Color.Black, Color.Green), resources.Fonts["Title"], UIManager.textAlign.centerCenter);
|
ui.Label(new Vector(screen.size.X / 2, screen.size.Y / 4), "MyMonoGameAddin", new Colors(Color.Black, Color.Green), resources.Fonts["Title"], UIManager.textAlign.centerCenter);
|
||||||
if (ui.TextField(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2), ref Github, new Colors(Color.White, Color.WhiteSmoke, Color.LightGray), null, UIManager.textAlign.centerCenter, "Search on Github"))
|
if (ui.TextField(new Vector(screen.size.X / 2, screen.size.Y / 2), ref Github, new Colors(Color.White, Color.WhiteSmoke, Color.LightGray), null, UIManager.textAlign.centerCenter, "Search on Github"))
|
||||||
{
|
{
|
||||||
Process.Start("https://github.com/search?q=" + Github);
|
Process.Start("https://github.com/search?q=" + Github);
|
||||||
Github = null;
|
Github = null;
|
||||||
}
|
}
|
||||||
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight * 3 / 4 + 50, 200, 40), "About", null, new Colors(Color.Black, Color.Green)))
|
if (ui.Button(new Rectangle(screen.size.X / 2 - 100, screen.size.Y * 3 / 4 + 50, 200, 40), "About", null, new Colors(Color.Black, Color.Green)))
|
||||||
{
|
{
|
||||||
state = GameState.Credit;
|
state = GameState.Credit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<Compile Include="KeyChar.cs" />
|
<Compile Include="KeyChar.cs" />
|
||||||
<Compile Include="Colors.cs" />
|
<Compile Include="Colors.cs" />
|
||||||
<Compile Include="Skin.cs" />
|
<Compile Include="Skin.cs" />
|
||||||
|
<Compile Include="ScreenManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,52 @@
|
||||||
|
using System;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace MyMonoGameAddin
|
||||||
|
{
|
||||||
|
public class ScreenManager
|
||||||
|
{
|
||||||
|
public Vector size = Vector.Zero;
|
||||||
|
public GraphicsDeviceManager graphics;
|
||||||
|
Game _game;
|
||||||
|
|
||||||
|
public ScreenManager(Game game)
|
||||||
|
{
|
||||||
|
_game = game;
|
||||||
|
graphics = new GraphicsDeviceManager(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(Vector buffersize, bool fullScreen, bool resizeing, bool mouse)
|
||||||
|
{
|
||||||
|
size = buffersize;
|
||||||
|
graphics.PreferredBackBufferWidth = size.X;
|
||||||
|
graphics.PreferredBackBufferHeight = size.Y;
|
||||||
|
graphics.IsFullScreen = fullScreen;
|
||||||
|
graphics.ApplyChanges();
|
||||||
|
|
||||||
|
_game.Window.AllowUserResizing = resizeing;
|
||||||
|
if (resizeing)
|
||||||
|
_game.Window.ClientSizeChanged += Window_ClientSizeChanged;
|
||||||
|
|
||||||
|
_game.IsMouseVisible = mouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear(Color color)
|
||||||
|
{
|
||||||
|
graphics.GraphicsDevice.Clear(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowSizeIsBeingChanged = false;
|
||||||
|
void Window_ClientSizeChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
WindowSizeIsBeingChanged = !WindowSizeIsBeingChanged;
|
||||||
|
if (WindowSizeIsBeingChanged)
|
||||||
|
{
|
||||||
|
size.X = _game.Window.ClientBounds.Width;
|
||||||
|
size.Y = _game.Window.ClientBounds.Height;
|
||||||
|
graphics.PreferredBackBufferWidth = size.X;
|
||||||
|
graphics.PreferredBackBufferHeight = size.Y;
|
||||||
|
graphics.ApplyChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue