1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Microsoft.Xna.Framework; |
---|
4 | using Microsoft.Xna.Framework.Content; |
---|
5 | using Microsoft.Xna.Framework.Graphics; |
---|
6 | |
---|
7 | namespace Fera_Proelia |
---|
8 | { |
---|
9 | public class ScreenManager : DrawableGameComponent |
---|
10 | { |
---|
11 | List<GameScreen> screens = new List<GameScreen>(); |
---|
12 | List<GameScreen> screensToUpdate = new List<GameScreen>(); |
---|
13 | |
---|
14 | SpriteBatch spriteBatch; |
---|
15 | |
---|
16 | bool isInitialized; |
---|
17 | |
---|
18 | public SpriteBatch SpriteBatch { get { return spriteBatch; } } |
---|
19 | |
---|
20 | public ScreenManager(Game game) |
---|
21 | : base(game) |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | public override void Initialize() |
---|
26 | { |
---|
27 | base.Initialize(); |
---|
28 | isInitialized = true; |
---|
29 | } |
---|
30 | |
---|
31 | protected override void LoadContent() |
---|
32 | { |
---|
33 | ContentManager content = Game.Content; |
---|
34 | spriteBatch = new SpriteBatch(GraphicsDevice); |
---|
35 | |
---|
36 | foreach (GameScreen screen in screens) |
---|
37 | { |
---|
38 | screen.LoadContent(); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | protected override void UnloadContent() |
---|
43 | { |
---|
44 | foreach (GameScreen screen in screens) |
---|
45 | { |
---|
46 | screen.UnloadContent(); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | public override void Update(GameTime gameTime) |
---|
51 | { |
---|
52 | screensToUpdate.Clear(); |
---|
53 | foreach (GameScreen screen in screens) |
---|
54 | screensToUpdate.Add(screen); |
---|
55 | |
---|
56 | bool otherScreenHasFocus = !Game.IsActive; |
---|
57 | |
---|
58 | while (screensToUpdate.Count > 0) |
---|
59 | { |
---|
60 | GameScreen screen = screensToUpdate[screensToUpdate.Count - 1]; |
---|
61 | screensToUpdate.RemoveAt(screensToUpdate.Count - 1); |
---|
62 | |
---|
63 | screen.Update(gameTime, otherScreenHasFocus); |
---|
64 | } |
---|
65 | |
---|
66 | base.Update(gameTime); |
---|
67 | } |
---|
68 | |
---|
69 | public override void Draw(GameTime gameTime) |
---|
70 | { |
---|
71 | foreach (GameScreen screen in screens) |
---|
72 | { |
---|
73 | screen.Draw(gameTime); |
---|
74 | } |
---|
75 | base.Draw(gameTime); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|