Пример #1
0
        /// <summary>
        /// Constructor for the menu UI
        /// </summary>
        /// <param name="game"></param>
        public MenuUI(Game game) : base(game)
        {
            orbis        = (Orbis)game;
            stateManager = StateManager.GetInstance();
            SpriteFont font = _contentManager.GetFont("DebugFont");

            // Background for the menu
            AddChild(menuBackground = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(Color.LightGray), new Rectangle(0, 0, 1, 1)))
            {
                Size             = new Point(_game.Window.ClientBounds.Width, _game.Window.ClientBounds.Height),
                AnchorPosition   = AnchorPosition.TopLeft,
                RelativePosition = new Point(0, 0),
                LayerDepth       = 1,
            });

            // The orbis logo
            AddChild(orbisLogo = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetTexture("UI/Orbis-Icon"), new Rectangle(0, 0, 1520, 1520)))
            {
                Size             = new Point(_game.Window.ClientBounds.Width / 4, _game.Window.ClientBounds.Width / 4),
                AnchorPosition   = AnchorPosition.Center,
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 8, -(_game.Window.ClientBounds.Height / 2) + 50),
                LayerDepth       = 0.5f
            });

            // Button to open the popup menu
            AddChild(openPopupButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Start"), new Rectangle(0, 0, 228, 64)))
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(_game.Window.ClientBounds.Width / 6, _game.Window.ClientBounds.Height / 12),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 12, -_game.Window.ClientBounds.Height / 8 + 100),
                LayerDepth       = 0.5f,
                Focused          = true
            });

            // Button for settings menu
            AddChild(settingsMenu = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Settings"), new Rectangle(0, 0, 228, 64)))
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(_game.Window.ClientBounds.Width / 6, _game.Window.ClientBounds.Height / 12),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 12, 0 + 100),
                LayerDepth       = 0.5f,
                Focused          = true
            });

            // Button for exiting the game
            AddChild(quitButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Quit"), new Rectangle(0, 0, 228, 64)))
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(_game.Window.ClientBounds.Width / 6, _game.Window.ClientBounds.Height / 12),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 12, _game.Window.ClientBounds.Height / 8 + 100),
                LayerDepth       = 0.5f,
                Focused          = true
            });

            // Background for the popup menu
            AddChild(popupBackground = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(Color.DarkGray), new Rectangle(0, 0, 1, 1)))
            {
                Size             = new Point(_game.Window.ClientBounds.Width / 3, _game.Window.ClientBounds.Height / 3 + 20),
                AnchorPosition   = AnchorPosition.Center,
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 6, -(_game.Window.ClientBounds.Height / 3 + 20) / 2),
                LayerDepth       = 0.4f,
                Visible          = false
            });

            // Text for the popup window
            AddChild(text = new RelativeText(popupBackground, font)
            {
                AnchorPosition   = AnchorPosition.TopLeft,
                RelativePosition = new Point(10, 10),
                Text             = "Generate a world based on the following settings:\r\n\r\nSeed:\r\n\r\nCivilization count:\r\n\r\nMap radius:\r\n\r\nMonths to simulate:",
                Visible          = false
            });

            // Get the length and height of text
            int textLength = (int)Math.Ceiling(font.MeasureString("Civilization count: ").X);
            int textHeight = (int)Math.Ceiling(font.MeasureString("A").Y);
            // Get the width of the max amount of input
            int fieldWidth = (int)Math.Ceiling(font.MeasureString("99999999").X);

            // Add the seed input field
            AddChild(seed = new InputNumberField(popupBackground)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                Size             = new Point(fieldWidth + 2, font.LineSpacing + 2),
                RelativePosition = new Point(-20 - fieldWidth + 2, 43),
                MaxDigits        = 8,
                Visible          = false,
                LayerDepth       = 0.03F
            });
            // Add the civ number input field
            AddChild(civs = new InputNumberField(popupBackground)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                Size             = new Point(fieldWidth + 2, font.LineSpacing + 2),
                RelativePosition = new Point(-20 - fieldWidth + 2, 83),
                MaxDigits        = 8,
                Visible          = false,
                LayerDepth       = 0.03F
            });
            // Add the radius input field
            AddChild(radius = new InputNumberField(popupBackground)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                Size             = new Point(fieldWidth + 2, font.LineSpacing + 2),
                RelativePosition = new Point(-20 - fieldWidth + 2, 123),
                MaxDigits        = 8,
                Visible          = false,
                LayerDepth       = 0.03F
            });
            // Add the ticks input field
            AddChild(ticks = new InputNumberField(popupBackground)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                Size             = new Point(fieldWidth + 2, font.LineSpacing + 2),
                RelativePosition = new Point(-20 - fieldWidth + 2, 163),
                MaxDigits        = 8,
                Visible          = false,
                LayerDepth       = 0.03F
            });

            // Add text input events to the input fields
            game.Window.TextInput += seed.Window_TextInput;
            game.Window.TextInput += civs.Window_TextInput;
            game.Window.TextInput += radius.Window_TextInput;
            game.Window.TextInput += ticks.Window_TextInput;

            // Add startbutton to the popup menu
            AddChild(startButton = new Button(popupBackground, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Start"), new Rectangle(0, 0, 228, 64)))
            {
                AnchorPosition   = AnchorPosition.BottomRight,
                Size             = new Point(_game.Window.ClientBounds.Width / 8, _game.Window.ClientBounds.Height / 16),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 8 - 10, -_game.Window.ClientBounds.Height / 16 - 10),
                LayerDepth       = 0.3f,
                Focused          = false,
                Visible          = false
            });

            // Add startbutton to the popup menu
            AddChild(closeButton = new Button(popupBackground, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Back"), new Rectangle(0, 0, 228, 64)))
            {
                AnchorPosition   = AnchorPosition.BottomLeft,
                Size             = new Point(_game.Window.ClientBounds.Width / 8, _game.Window.ClientBounds.Height / 16),
                RelativePosition = new Point(10, -_game.Window.ClientBounds.Height / 16 - 10),
                LayerDepth       = 0.3f,
                Focused          = false,
                Visible          = false
            });

            // Add button click listeners
            startButton.Click     += StartButton_Click;
            settingsMenu.Click    += SettingsButton_Click;
            quitButton.Click      += QuitButton_Click;
            openPopupButton.Click += PopupButton_Click;

            closeButton.Click += CloseButton_Click;
        }
Пример #2
0
        public GameUI(Game game) : base(game)
        {
            orbis       = (Orbis)game;
            logger      = Logger.GetInstance();
            logExporter = new LogExporter();

            play  = new SpriteDefinition(_contentManager.GetTexture("UI/Button_Play"), new Rectangle(0, 0, 96, 64));
            pause = new SpriteDefinition(_contentManager.GetTexture("UI/Button_Pause"), new Rectangle(0, 0, 96, 64));

            AddChild(playButton = new Button(this, play)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(-(RIGHT_UI_WIDTH - 96) / 2 - 96, -10),
                Size             = new Point(96, 64),
                LayerDepth       = 0,
                Focused          = true
            });

            AddChild(nextButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Next"), new Rectangle(0, 0, 70, 64)))
            {
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(-(RIGHT_UI_WIDTH - playButton.Size.X) / 2, -10),
                Size             = new Point(70, 64),
                LayerDepth       = 0,
                Focused          = true
            });

            AddChild(exportButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Export"), new Rectangle(0, 0, 70, 64)))
            {
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(-(RIGHT_UI_WIDTH - playButton.Size.X) / 2 - playButton.Size.X - 70, -10),
                Size             = new Point(70, 64),
                LayerDepth       = 0,
                Focused          = true
            });

            playButton.Click   += PlayButton_Click;
            nextButton.Click   += NextButton_Click;
            exportButton.Click += ExportButton_Click;

            // Progress bar
            AddChild(progressBar = new ProgressBar(this)
            {
                AnchorPosition   = AnchorPosition.BottomLeft,
                RelativePosition = new Point(20, -70),
                Size             = new Point(_game.Window.ClientBounds.Width - RIGHT_UI_WIDTH - 40, 50),
                LayerDepth       = 0
            });

            // Background for progressbar
            AddChild(backgroundProgressBar = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(UI_COLOR), new Rectangle(0, 0, 1, 1)))
            {
                Size             = new Point(_game.Window.ClientBounds.Width - RIGHT_UI_WIDTH, BOTTOM_UI_HEIGHT),
                AnchorPosition   = AnchorPosition.BottomLeft,
                RelativePosition = new Point(0, -BOTTOM_UI_HEIGHT),
                LayerDepth       = 1
            });

            // Background for UI
            AddChild(background = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(UI_COLOR), new Rectangle(0, 0, 1, 1)))
            {
                Size             = new Point(RIGHT_UI_WIDTH, _game.Window.ClientBounds.Height),
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(-RIGHT_UI_WIDTH, 0),
                LayerDepth       = 1
            });

            // Background for UI
            AddChild(cellInfoBackground = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(UI_COLOR), new Rectangle(0, 0, 1, 1)))
            {
                Size             = new Point(RIGHT_UI_WIDTH, 300),
                AnchorPosition   = AnchorPosition.BottomRight,
                RelativePosition = new Point(-RIGHT_UI_WIDTH * 2 - 10, -BOTTOM_UI_HEIGHT - 310),
                LayerDepth       = 0.0000001f,
                Visible          = false
            });

            AddChild(text = new RelativeText(this, _contentManager.GetFont("DebugFont"))
            {
                Text             = "",
                AnchorPosition   = AnchorPosition.BottomRight,
                RelativePosition = new Point(-RIGHT_UI_WIDTH * 2, -BOTTOM_UI_HEIGHT - 300),
                LayerDepth       = 0,
                Visible          = false
            });

            // Scene panel
            var sceneSize = new Point(_game.Window.ClientBounds.Width - RIGHT_UI_WIDTH, _game.Window.ClientBounds.Height - BOTTOM_UI_HEIGHT);

            AddChild(scene = new RelativeTexture(this, new SpriteDefinition(
                                                     new RenderTarget2D(orbis.GraphicsDevice, sceneSize.X, sceneSize.Y),
                                                     new Rectangle(0, 0, sceneSize.X, sceneSize.Y)))
            {
                Size             = sceneSize,
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(0, 0),
                LayerDepth       = 0.5f
            });
            // Scene panel itself is invisible, we just use it for size and texture storage
            scene.Visible = false;

            AddChild(civPanel = new CivPanel(this, orbis.Scene.Civilizations)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(-RIGHT_UI_WIDTH, 64),
                Size             = new Point(RIGHT_UI_WIDTH, game.Window.ClientBounds.Height - 64),
                LayerDepth       = 0.99F
            });

            screenResized = true;
        }
Пример #3
0
        public SettingsUI(Game game) : base(game)
        {
            orbis = (Orbis)game;
            SpriteFont font = _contentManager.GetFont("DebugFont");

            // Background for UI
            AddChild(background = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(BACKGROUND_COLOR), new Rectangle(0, 0, 1, 1)))
            {
                Size             = new Point(_game.Window.ClientBounds.Width, _game.Window.ClientBounds.Height),
                AnchorPosition   = AnchorPosition.TopLeft,
                RelativePosition = new Point(0, 0),
                LayerDepth       = 1
            });

            string checkBoxTexture = AudioManager.IsEnabled() ? "UI/Checkbox_Checked" : "UI/Checkbox_Unchecked";

            AddChild(audioCheckbox = new Button(this, new SpriteDefinition(_contentManager.GetTexture(checkBoxTexture), new Rectangle(0, 0, 16, 16)))
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(_game.Window.ClientBounds.Width / 50, _game.Window.ClientBounds.Height / 30),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 16, 60),
                LayerDepth       = 0.3f,
            });

            AddChild(audioCheckboxText = new RelativeText(audioCheckbox, font)
            {
                AnchorPosition   = AnchorPosition.Center,
                RelativePosition = new Point(40, -9),
                Text             = "Music Enabled",
                LayerDepth       = 0.3f,
            });

            AddChild(backButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Back"), new Rectangle(0, 0, 228, 64)))
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(_game.Window.ClientBounds.Width / 8, _game.Window.ClientBounds.Height / 16),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 16, (int)(_game.Window.ClientBounds.Width / 7.5)),
                LayerDepth       = 0.3f,
            });

            // Get the length and height of text
            int textLength = (int)Math.Ceiling(font.MeasureString("Civilization count: ").X);
            int textHeight = (int)Math.Ceiling(font.MeasureString("A").Y);
            // Get the width of the max amount of input
            int fieldWidth = (int)Math.Ceiling(font.MeasureString("99999999").X);

            // Add the seed input field

            AddChild(fog = new InputNumberField(this)
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(fieldWidth + 2, font.LineSpacing + 2),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 16, 0),
                MaxDigits        = 4,
                Visible          = true,
                LayerDepth       = 0.03F
            });

            AddChild(new RelativeText(fog, font)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(16, 3),
                Text             = "Fog/Render Distance",
                LayerDepth       = 0.3f,
            });

            AddChild(decorationDensity = new InputNumberField(this)
            {
                AnchorPosition   = AnchorPosition.Center,
                Size             = new Point(fieldWidth + 2, font.LineSpacing + 2),
                RelativePosition = new Point(-_game.Window.ClientBounds.Width / 16, 30),
                MaxDigits        = 3,
                Visible          = true,
                LayerDepth       = 0.03F
            });

            AddChild(new RelativeText(decorationDensity, font)
            {
                AnchorPosition   = AnchorPosition.TopRight,
                RelativePosition = new Point(16, 3),
                Text             = "Vegetation density (%)",
                LayerDepth       = 0.3f,
            });


            // Add button click listeners
            game.Window.TextInput += fog.Window_TextInput;
            game.Window.TextInput += decorationDensity.Window_TextInput;

            audioCheckbox.Click += AudioCheckbox_Click;
            backButton.Click    += BackButton_Click;
        }