-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathGameScreen.cs
105 lines (86 loc) · 3.15 KB
/
GameScreen.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
using System;
using Microsoft.Xna.Framework;
namespace Hacknet
{
public abstract class GameScreen
{
private bool otherScreenHasFocus;
public bool IsPopup { get; protected set; }
public TimeSpan TransitionOnTime { get; protected set; } = TimeSpan.Zero;
public TimeSpan TransitionOffTime { get; protected set; } = TimeSpan.Zero;
public float TransitionPosition { get; protected set; } = 1f;
public byte TransitionAlpha
{
get { return (byte) (byte.MaxValue - TransitionPosition*(double) byte.MaxValue); }
}
public ScreenState ScreenState { get; protected set; }
public bool IsExiting { get; protected internal set; }
public bool IsActive
{
get
{
if (otherScreenHasFocus)
return false;
if (ScreenState != ScreenState.TransitionOn)
return ScreenState == ScreenState.Active;
return true;
}
}
public ScreenManager ScreenManager { get; internal set; }
public PlayerIndex? ControllingPlayer { get; internal set; }
public virtual void LoadContent()
{
}
public virtual void UnloadContent()
{
}
public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
{
this.otherScreenHasFocus = otherScreenHasFocus;
if (IsExiting)
{
ScreenState = ScreenState.TransitionOff;
if (UpdateTransition(gameTime, TransitionOffTime, 1))
return;
ScreenManager.RemoveScreen(this);
}
else if (coveredByOtherScreen)
{
if (UpdateTransition(gameTime, TransitionOffTime, 1))
ScreenState = ScreenState.TransitionOff;
else
ScreenState = ScreenState.Hidden;
}
else if (UpdateTransition(gameTime, TransitionOnTime, -1))
ScreenState = ScreenState.TransitionOn;
else
ScreenState = ScreenState.Active;
}
private bool UpdateTransition(GameTime gameTime, TimeSpan time, int direction)
{
TransitionPosition += (!(time == TimeSpan.Zero)
? (float) (gameTime.ElapsedGameTime.TotalMilliseconds/time.TotalMilliseconds)
: 1f)*direction;
if ((direction >= 0 || TransitionPosition > 0.0) && (direction <= 0 || TransitionPosition < 1.0))
return true;
TransitionPosition = MathHelper.Clamp(TransitionPosition, 0.0f, 1f);
return false;
}
public virtual void HandleInput(InputState input)
{
}
public virtual void Draw(GameTime gameTime)
{
}
public void ExitScreen()
{
if (TransitionOffTime == TimeSpan.Zero)
ScreenManager.RemoveScreen(this);
else
IsExiting = true;
}
public virtual void inputMethodChanged(bool usingGamePad)
{
}
}
}