/
EmptyKeysUI.cs
132 lines (100 loc) · 4.26 KB
/
EmptyKeysUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using EmptyKeys.UserInterface;
using EmptyKeys.UserInterface.Debug;
using EmptyKeys.UserInterface.Generated;
using EmptyKeys.UserInterface.Input;
using EmptyKeys.UserInterface.Media;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PokeD.SCON.UILibrary;
namespace PokeD.SCON
{
public class EmptyKeysUI : Game
{
public static Point DefaultResolution => new Point(1024, 768);
GraphicsDeviceManager Graphics { get; }
BasicUI BasicUI { get; set; }
BasicUIViewModel ViewModel { get; set; }
DebugViewModel DebugViewMode { get; set; }
SCONClient SCONClient { get; set; }
public EmptyKeysUI(Action<Game> platformCode, bool fullscreen = false)
{
Graphics = new GraphicsDeviceManager(this);
Graphics.PreparingDeviceSettings += Graphics_PreparingDeviceSettings;
Graphics.DeviceCreated += Graphics_DeviceCreated;
Graphics.IsFullScreen = fullscreen;
Graphics.ApplyChanges();
Content.RootDirectory = "Content";
platformCode?.Invoke(this);
}
private void Graphics_DeviceCreated(object sender, EventArgs e)
{
var Engine = new MonoGameEngine(GraphicsDevice, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight);
}
private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
Graphics.PreferredBackBufferWidth = DefaultResolution.X;
Graphics.PreferredBackBufferHeight = DefaultResolution.Y;
//Graphics.GraphicsProfile = GraphicsProfile.HiDef;
Graphics.SynchronizeWithVerticalRetrace = true;
//Graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
}
public void OnResize(object sender, EventArgs e)
{
if (Graphics.GraphicsDevice.Viewport.Width < DefaultResolution.X || Graphics.GraphicsDevice.Viewport.Height < DefaultResolution.Y)
{
Resize(DefaultResolution);
return;
}
BasicUI?.Resize(Graphics.GraphicsDevice.Viewport.Width, Graphics.GraphicsDevice.Viewport.Height);
}
public void Resize(Point size)
{
if (size.X < DefaultResolution.X || size.Y < DefaultResolution.Y)
return;
Graphics.PreferredBackBufferWidth = size.X;
Graphics.PreferredBackBufferHeight = size.Y;
Graphics.ApplyChanges();
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
IsMouseVisible = true;
FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(Content.Load<SpriteFont>("Segoe_UI_10_Regular"));
BasicUI = new BasicUI(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight);
ViewModel = new BasicUIViewModel();
BasicUI.DataContext = ViewModel;
DebugViewMode = new DebugViewModel(BasicUI);
FontManager.Instance.LoadFonts(Content);
ImageManager.Instance.LoadImages(Content);
SoundManager.Instance.LoadSounds(Content);
BasicUI.InputBindings.Add(new KeyBinding(new RelayCommand(o => Exit()), KeyCode.Escape, ModifierKeys.None));
SCONClient = new SCONClient(ViewModel);
base.LoadContent();
}
protected override void UnloadContent()
{
base.UnloadContent();
SCONClient.Dispose();
}
protected override void Update(GameTime gameTime)
{
SCONClient.Update();
DebugViewMode.Update();
BasicUI.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
ViewModel.Update(gameTime.ElapsedGameTime.TotalMilliseconds);
BasicUI.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
BasicUI.Draw(gameTime.ElapsedGameTime.TotalMilliseconds);
DebugViewMode.Draw();
base.Draw(gameTime);
}
}
}