aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/MainMenu.cs
blob: e12989cc47dcb3c82bcee63427ede3bd143aa803 (plain) (blame)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
using ShiftOS.Frontend.GUI;
using ShiftOS.Frontend.GraphicsSubsystem;
using Microsoft.Xna.Framework;

namespace ShiftOS.Frontend
{
    public class MainMenu : GUI.Control
    {
        private TextControl _mainTitle = new TextControl();
        private TextControl _menuTitle = new TextControl();
        private Button _campaign = new Button();
        private Button _sandbox = new Button();

        public MainMenu()
        {
            X = 0;
            Y = 0;
            Width = UIManager.Viewport.Width;
            Height = UIManager.Viewport.Height;

            AddControl(_mainTitle);
            AddControl(_menuTitle);
            AddControl(_campaign);
            AddControl(_sandbox);

            _campaign.Text = "Campaign";
            _campaign.Font = new System.Drawing.Font("Lucida Console", 10F);
            _campaign.Width = 200;
            _campaign.Height = 6 + _campaign.Font.Height;
            _campaign.X = 30;

            _sandbox.Text = "Sandbox";
            _sandbox.Width = 200;
            _sandbox.Height = 6 + _campaign.Font.Height;
            _sandbox.Font = _campaign.Font;
            _sandbox.X = 30;

            _mainTitle.X = 30;
            _mainTitle.Y = 30;
            _mainTitle.Font = new System.Drawing.Font("Lucida Console", 48F);
            _mainTitle.AutoSize = true;
            _mainTitle.Text = "ShiftOS";

            _menuTitle.Text = "Main menu";
            _menuTitle.Font = new System.Drawing.Font(_menuTitle.Font.Name, 16F);
            _menuTitle.X = 30;
            _menuTitle.Y = _mainTitle.Y + _mainTitle.Font.Height + 10;

            _campaign.Y = _menuTitle.Y + _menuTitle.Font.Height + 15;
            _sandbox.Y = _campaign.Y + _campaign.Font.Height + 15;
            _campaign.Click += () =>
            {
                SaveSystem.IsSandbox = false;
                SaveSystem.Begin(false);
                Close();
            };
            _sandbox.Click += () =>
            {
                SaveSystem.IsSandbox = true;
                SaveSystem.Begin(false);
                Close();
            };

        }

        private string _tipText = "This is some tip text.";
        private float _tipFade = 0.0f;
        private int _tipTime = 0;



        public void Close()
        {
            UIManager.StopHandling(this);
        }

        private Color _redbg = new Color(180, 0, 0, 255);
        private Color _bluebg = new Color(0, 0, 180, 255);
        private float _bglerp = 0.0f;
        private int _lerpdir = 1;
        private bool _tipVisible = false;
        int rnd = 0;
        private Random _rnd = new Random();

        public string GetRandomString()
        {
            var r = _rnd.Next(0, 10);
            while(r == rnd)
            {
                r = _rnd.Next(0, 10);
            }
            rnd = r;
            switch (r)
            {
                case 0:
                    return "Sentience choppy? Try adjusting sentience quality settings in Options.";
                case 1:
                    return "Want to hear about the latest ShiftOS news and events? Check out the Community menu!";
                case 2:
                    return "Go follow DevX on Twitter! http://twitter.com/MichaelTheShift";
                case 3:
                    return "Ran out of things to do in-game? Visit the modding forums for some extra user-created content or how to make your own ShiftOS-y things!";
                case 4:
                    return "Tip of advice: Never use a GUI toolkit made in the 90s for utility design to develop a game that simulates an operating system with tools that look like they should be made in a GUI toolkit from the 90s for utility design.";
                case 5:
                    return "Skins are a very extensive and neat way to customize your ShiftOS experience. Why not give them a try?";
                case 6:
                    return "We thought of putting some pong stuff here but ShiftOS is already mostly just playing pong if you don't play this update. Ping pung pong pang.";
                case 7:
                    return "Welcome to the Digital Society. Do you wish to continue?";
                case 8:
                    return "Open-source projects are pretty cool, you can use, modify, copy and redistribute the code without worrying too much about what lawyer you're gonna hire to act on your behalf. That's why ShiftOS is one of them. http://github.com/shiftos-game/ShiftOS";
                default:
                    return "We ran out of things to say.";
            }
        }

        protected override void OnLayout(GameTime gameTime)
        {
            if (_lerpdir == 1)
                _bglerp += 0.00075f;
            else
                _bglerp -= 0.00075f;
            if (_bglerp <= 0.0)
                _lerpdir = 1;
            else if (_bglerp >= 1)
                _lerpdir = -1;

            if (_tipVisible == false)
            {


                _tipTime = 0;
                if (_tipFade == 0.0f)
                {
                    _tipText = GetRandomString();
                }
                _tipFade += 0.01f;
                if(_tipFade >= 1.0f)
                {
                    _tipVisible = true;
                }
            }
            else
            {
                _tipTime += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
                if(_tipTime >= 10000)
                {
                    _tipFade -= 0.01f;
                    if(_tipFade <= 0.0f)
                    {
                        _tipVisible = false;
                        _tipText = GetRandomString();
                    }
                }
            }

            Invalidate();
        }

        protected override void OnPaint(GraphicsContext gfx)
        {
            gfx.DrawRectangle(0, 0, Width, Height, Color.Lerp(_redbg, _bluebg, _bglerp));
            gfx.DrawRectangle(0, 0, Width / 4, Height, Color.White * 0.35F);

            var measure = gfx.MeasureString(_tipText, _campaign.Font, (Width / 4) - 30);
            int _height = (Height - (int)measure.Y) - 30;
            gfx.DrawString(_tipText, 30, _height, Color.White * _tipFade, _campaign.Font, (Width / 4) - 30);
        }
    }
}