This repository has been archived by the owner on Dec 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShooterInterface.cs
220 lines (159 loc) · 5.89 KB
/
ShooterInterface.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Fusion.Core.Mathematics;
using Fusion.Drivers.Graphics;
using Fusion.Engine.Input;
using Fusion.Engine.Graphics;
using Fusion.Core;
using Fusion.Core.Configuration;
using Fusion.Engine.Tools;
using Fusion;
using Fusion.Engine.Client;
using Fusion.Engine.Common;
using Fusion.Engine.Server;
namespace ShooterDemo {
class ShooterInterface : Fusion.Engine.Common.UserInterface {
DiscTexture background;
SpriteLayer uiLayer;
SpriteFont headerFont;
SpriteFont textFont;
SpriteFont titleFont;
/// <summary>
/// Creates instance of ShooterDemoUserInterface
/// </summary>
/// <param name="engine"></param>
public ShooterInterface ( Game game )
: base( game )
{
ShowMenu = true;
}
/// <summary>
/// Called after the ShooterDemoUserInterface is created,
/// </summary>
public override void Initialize ()
{
uiLayer = new SpriteLayer(Game.RenderSystem, 1024);
// add console sprite layer to master view layer :
Game.RenderSystem.SpriteLayers.Add( uiLayer );
LoadContent();
Game.Reloading += (s,e) => LoadContent();
Game.GameClient.ClientStateChanged += GameClient_ClientStateChanged;
}
void GameClient_ClientStateChanged ( object sender, GameClient.ClientEventArgs e )
{
Game.Console.Hide();
}
void LoadContent ()
{
background = Game.Content.Load<DiscTexture>(@"ui\background");
headerFont = Game.Content.Load<SpriteFont>(@"fonts\headerFont");
titleFont = Game.Content.Load<SpriteFont>(@"fonts\titleFont");
textFont = Game.Content.Load<SpriteFont>(@"fonts\textFont");
}
/// <summary>
/// Overloaded. Immediately releases the unmanaged resources used by this object.
/// </summary>
protected override void Dispose ( bool disposing )
{
if (disposing) {
SafeDispose( ref uiLayer );
}
base.Dispose( disposing );
}
float dofFactor = 0;
/// <summary>
/// Called when the game has determined that UI logic needs to be processed.
/// </summary>
/// <param name="gameTime"></param>
public override void Update ( GameTime gameTime )
{
// update console :
Game.Console.Update( gameTime );
uiLayer.Clear();
var clientState = Game.GameClient.ClientState;
dofFactor = MathUtil.Lerp( (float)dofFactor, Game.Keyboard.IsKeyDown(Keys.Q) ? 1.0f : 0.0f, 0.1f );
Game.RenderSystem.RenderWorld.DofSettings.PlaneInFocus = 7;
Game.RenderSystem.RenderWorld.DofSettings.FocalLength = 0.1f;
Game.RenderSystem.RenderWorld.DofSettings.Enabled = dofFactor > 0.01f;
Game.RenderSystem.RenderWorld.DofSettings.Aperture = dofFactor * 20;
switch (clientState) {
case ClientState.StandBy : DrawStandByScreen(); break;
case ClientState.Connecting : DrawLoadingScreen("Connecting..."); break;
case ClientState.Loading : DrawLoadingScreen("Loading..."); break;
case ClientState.Awaiting : DrawLoadingScreen("Awaiting snapshot..."); break;
case ClientState.Disconnected : DrawLoadingScreen("Disconnected."); break;
case ClientState.Active : break;
}
if (ShowMenu) {
Game.Keyboard.ScanKeyboard = false;
Game.Mouse.IsMouseCentered = false;
Game.Mouse.IsMouseClipped = false;
Game.Mouse.IsMouseHidden = false;
} else {
if (!Game.Console.IsShown) {
Game.Keyboard.ScanKeyboard = true;
Game.Mouse.IsMouseCentered = true;
Game.Mouse.IsMouseClipped = true;
Game.Mouse.IsMouseHidden = true;
} else {
Game.Keyboard.ScanKeyboard = false;
Game.Mouse.IsMouseCentered = false;
Game.Mouse.IsMouseClipped = false;
Game.Mouse.IsMouseHidden = false;
}
}
}
/// <summary>
/// Draw loading screen
/// </summary>
/// <param name="message"></param>
void DrawLoadingScreen ( string message )
{
var vp = Game.RenderSystem.DisplayBounds;
uiLayer.Draw( background, 0,0, vp.Width, vp.Height, Color.White );
uiLayer.Draw( null, 0,vp.Height/4, vp.Width, vp.Height/2, new Color(0,0,0,192) );
var h = textFont.LineHeight;
//titleFont.DrawString( uiLayer, message, 100,vp.Height/2 - h*2, new Color(242,242,242) );
textFont.DrawString( uiLayer, message, 100,vp.Height/2 - h, new Color(220,20,60) );
}
/// <summary>
/// Draws stand-by screen
/// </summary>
void DrawStandByScreen ()
{
var vp = Game.RenderSystem.DisplayBounds;
uiLayer.Draw( background, 0,0, vp.Width, vp.Height, Color.White );
uiLayer.Draw( null, 0,vp.Height/4, vp.Width, vp.Height/2, new Color(0,0,0,192) );
var h = textFont.LineHeight;
//titleFont.DrawString( uiLayer, "SHOOTER DEMO", 100,vp.Height/2 - h*2, new Color(242,242,242) );
titleFont.DrawString( uiLayer, "HEROES OF THE SHOOTER AGE", 100,vp.Height/2 - h*2, new Color(242,242,242) );
textFont.DrawString( uiLayer, "Fusion Engine Test Project", 100,vp.Height/2 - h, new Color(220,20,60) );
textFont.DrawString( uiLayer, "Press [~] to open console:", 100,vp.Height/2 + h, new Color(242,242,242) );
textFont.DrawString( uiLayer, " - Enter \"map base1\" to start the game.", 100,vp.Height/2 + h*2, new Color(242,242,242) );
textFont.DrawString( uiLayer, " - Enter \"killserver\" to stop the game.", 100,vp.Height/2 + h*3, new Color(242,242,242) );
textFont.DrawString( uiLayer, " - Enter \"connect <IP:port>\" to connect to the remote game.", 100,vp.Height/2 + h*4, new Color(242,242,242) );
}
public bool ShowMenu {
get; set;
}
/// <summary>
/// Called when user closes game window using Close button or Alt+F4.
/// </summary>
public override void RequestToExit ()
{
Game.Exit();
}
/// <summary>
/// Called when discovery respone arrives.
/// </summary>
/// <param name="endPoint"></param>
/// <param name="serverInfo"></param>
public override void DiscoveryResponse ( System.Net.IPEndPoint endPoint, string serverInfo )
{
Log.Message( "DISCOVERY : {0} - {1}", endPoint.ToString(), serverInfo );
}
}
}