forked from CodingMadeEasy/MonogameRPG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenManager.cs
113 lines (100 loc) · 3.31 KB
/
ScreenManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace YoutubeRPG
{
public class ScreenManager
{
private static ScreenManager instance;
[XmlIgnore]
public Vector2 Dimensions { private set; get; }
[XmlIgnore]
public ContentManager Content { private set; get; }
XmlManager<GameScreen> xmlGameScreenManager;
GameScreen currentScreen, newScreen;
[XmlIgnore]
public GraphicsDevice GraphicsDevice;
[XmlIgnore]
public SpriteBatch SpriteBatch;
public Image Image;
[XmlIgnore]
public bool IsTransitioning { get; private set; }
public static ScreenManager Instance
{
get
{
if (instance == null)
{
XmlManager<ScreenManager> xml = new XmlManager<ScreenManager>();
instance = xml.Load("Load/ScreenManager.xml");
}
return instance;
}
}
public void ChangeScreens(string screenName)
{
newScreen = (GameScreen)Activator.CreateInstance(Type.GetType("YoutubeRPG." + screenName));
Image.IsActive = true;
Image.FadeEffect.Increase = true;
Image.Alpha = 0.0f;
IsTransitioning = true;
}
void Transition(GameTime gameTime)
{
if (IsTransitioning)
{
Image.Update(gameTime);
if (Image.Alpha == 1.0f)
{
currentScreen.UnloadContent();
currentScreen = newScreen;
xmlGameScreenManager.Type = currentScreen.Type;
if (File.Exists(currentScreen.XmlPath))
currentScreen = xmlGameScreenManager.Load(currentScreen.XmlPath);
currentScreen.LoadContent();
}
else if (Image.Alpha == 0.0f)
{
Image.IsActive = false;
IsTransitioning = false;
}
}
}
public ScreenManager()
{
Dimensions = new Vector2(640, 480);
currentScreen = new SplashScreen();
xmlGameScreenManager = new XmlManager<GameScreen>();
xmlGameScreenManager.Type = currentScreen.Type;
currentScreen = xmlGameScreenManager.Load("Load/SplashScreen.xml");
}
public void LoadContent(ContentManager Content)
{
this.Content = new ContentManager(Content.ServiceProvider, "Content");
currentScreen.LoadContent();
Image.LoadContent();
}
public void UnloadContent()
{
currentScreen.UnloadContent();
Image.UnloadContent();
}
public void Update(GameTime gameTime)
{
currentScreen.Update(gameTime);
Transition(gameTime);
}
public void Draw(SpriteBatch spriteBatch)
{
currentScreen.Draw(spriteBatch);
if (IsTransitioning)
Image.Draw(spriteBatch);
}
}
}