summaryrefslogtreecommitdiff
path: root/source/ui/guis/GUI.cs
blob: 6d000700eb07a5da5c2606a084cbaf29df6b21ce (plain)
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
using System.Diagnostics;
using Celesteia.UI;
using Celesteia.UI.Elements;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Celesteia.GUIs {
    public class GUI {
        public GameInstance Game;

        public IContainer Root;

        public GUI(GameInstance Game, Rect rect) {
            this.Game = Game;
            this.Root = new Container(rect);
        }

        public virtual void LoadContent(ContentManager Content) {
            Debug.WriteLine("Loaded GUI.");
        }

        public virtual void Update(GameTime gameTime, out bool clickedAnything) {
            if (!Game.IsActive) {
                clickedAnything = false;
                return;
            }
            
            Root.Update(gameTime, out clickedAnything);
        }

        // Draw all elements.
        public virtual void Draw(GameTime gameTime) {
            
            Game.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointWrap, null, null, null);

            if (UIReferences.GUIEnabled) Root.Draw(Game.SpriteBatch);

            Game.SpriteBatch.End();
        }

        // If the menu is referred to as a boolean, return whether it is non-null (true) or null (false).
        public static implicit operator bool(GUI gui)
        {
            return !object.ReferenceEquals(gui, null);
        }
    }
}