void InitControls()
    {
        background = Menu.BackgroundBox();
        AddChild(background);

        logo = Menu.TexturedButton("res://Textures/logo.jpg");
        AddChild(logo);

        newGameButton = Menu.Button(text: "New", onClick: NewGame);
        AddChild(newGameButton);

        if (CareerDb.SaveExists())
        {
            continueGameButton = Menu.Button(text: "Continue", onClick: ContinueGame);
            AddChild(continueGameButton);
        }

        quitButton = Menu.Button(text: "Quit", onClick: Quit);
        AddChild(quitButton);

        settingsButton = (Godot.Button)Menu.Button(text: "Settings", onClick: Settings);
        AddChild(settingsButton);

        Sound.PlayRandomSong(Sound.GetPlaylist(Sound.Playlists.Menu));
    }
Beispiel #2
0
    public static TexturedButton TexturedButton(
        string normalTexturePath = "",
        string selectTexturePath = "",
        Action onClick           = null
        )
    {
        TexturedButton tb = new TexturedButton();

        if (normalTexturePath != "")
        {
            tb.TextureNormal = ResourceLoader.Load(normalTexturePath) as Texture;
        }
        if (selectTexturePath != "")
        {
            Texture t = ResourceLoader.Load(selectTexturePath) as Texture;
            tb.TextureFocused = t;
            tb.TextureHover   = t;
        }
        if (onClick != null)
        {
            tb.SetOnClick(onClick);
        }
        tb.Expand = true;
        return(tb);
    }
    public void InitControls()
    {
        background = Menu.BackgroundBox();
        AddChild(background);

        logo = Menu.TexturedButton("res://Assets/Textures/logo.jpg");
        AddChild(logo);

        newGameButton = Menu.Button(text: "New", onClick: NewGame);
        AddChild(newGameButton);

        quitButton = Menu.Button(text: "Quit", onClick: Quit);
        AddChild(quitButton);

        settingsButton = (Godot.Button)Menu.Button(text: "Settings", onClick: Settings);
        AddChild(settingsButton);

        Sound.PlayRandomSong(Sound.GetPlaylist(Sound.Playlists.Menu));
    }
        private void SetupUserInterface()
        {
            var mainMenuSpriteMap = _spriteMapLoader.GetContent("assets/UI/title_menu_buttons.json");
            var interfaceFont     = _contentChest.Get <SpriteFont>("Fonts/InterfaceFont");
            var inputBoxFont      = _contentChest.Get <SpriteFont>("Fonts/InputBoxFont");

            var portraitTexture = _contentChest.Get <Texture2D>("portrait_background");
            var portraitImage   = new Sprite(portraitTexture);

            var nineSlice = new NineSlice(_menuButtons, new Dictionary <Segment, Rectangle>
            {
                { Segment.TopLeft, new Rectangle(1, 189, 8, 9) },
                { Segment.Top, new Rectangle(10, 189, 1, 9) },
                { Segment.TopRight, new Rectangle(12, 189, 8, 9) },
                { Segment.Right, new Rectangle(12, 199, 8, 1) },
                { Segment.BottomRight, new Rectangle(12, 201, 8, 8) },
                { Segment.Bottom, new Rectangle(10, 201, 1, 8) },
                { Segment.BottomLeft, new Rectangle(1, 201, 8, 8) },
                { Segment.Left, new Rectangle(1, 199, 8, 1) },
                { Segment.Center, new Rectangle(10, 199, 1, 1) }
            });

            var panelWidth = (int)(30 + 200 + 30 + portraitImage.Texture.Width * _buttonScale + 30);

            _panel = new Panel(nineSlice,
                               new Rectangle(
                                   (int)(_viewPortPortManager.ViewPort.Center().X - panelWidth / 2f),
                                   (int)(_viewPortPortManager.ViewPort.Center().Y - (500 + 30 + 22 * _buttonScale) / 2f), panelWidth,
                                   500), _buttonScale);

            // Back Button
            BackButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Back_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Back_On"),
                new Vector2(_panel.BottomLeft().X,
                            _panel.BottomLeft().Y + 10), _buttonScale);

            // Done Button
            var doneOffSprite = mainMenuSpriteMap.CreateSpriteFromRegion("Done_Off");

            DoneButton = new TexturedButton(doneOffSprite,
                                            mainMenuSpriteMap.CreateSpriteFromRegion("Done_On"),
                                            new Vector2(_panel.BottomRight().X - doneOffSprite.Source.Width * _buttonScale,
                                                        _panel.BottomLeft().Y + 10), _buttonScale);

            // Name
            var nameSectionPosition = new Vector2(_panel.Left() + 30,
                                                  _panel.Top() + 30);
            var nameTextBoxTitle = new TextBlock("Name", nameSectionPosition, interfaceFont, Color.White, Color.Black);

            NameTextBox = new TextBox(_contentChest, _keyboardDispatcher,
                                      nameSectionPosition + new Vector2(0, interfaceFont.MeasureString("Name").Y + 10),
                                      inputBoxFont, 200)
            {
                Value = _playerMaker.Name
            };
            NameTextBox.Changed += OnPlayerNameSet;

            // Pronouns
            var pronounSectionPosition = new Vector2(_panel.Left() + 30, NameTextBox.Bounds.Bottom + 10);
            var pronounTextBoxTitle    =
                new TextBlock("Pronouns", pronounSectionPosition, interfaceFont, Color.White, Color.Black);

            PronounDropDown = new DropDownBox(_contentChest, inputBoxFont,
                                              pronounSectionPosition + new Vector2(0, interfaceFont.MeasureString("Pronouns").Y + 10),
                                              _optionsManager.PronounOptions.Pronouns.Select(x =>
                                                                                             $"{x.Subjective}/{x.Objective}").ToArray(), 200);
            PronounDropDown.Hover        += OnPronounSelect;
            PronounDropDown.SelectedIndex = _playerMaker.Pronouns;

            var characterPanel = new Image(portraitImage,
                                           new Vector2(
                                               PronounDropDown.Bounds.Right + 30 +
                                               (_panel.Right() - 30 - (PronounDropDown.Bounds.Right + 30)) / 2f -
                                               portraitImage.Center.X * _buttonScale,
                                               nameTextBoxTitle.Top()), _buttonScale);

            // Character Preview
            var characterPreview = new CharacterPreview(_characterRenderer, characterPanel.Center());

            // Hair
            var hairText = new TextBlock("Hair Style",
                                         new Vector2(PronounDropDown.Left(), PronounDropDown.BottomLeft().Y + 10), interfaceFont, Color.White,
                                         Color.Black);

            PlayerHairDropDown = new DropDownBox(_contentChest, inputBoxFont,
                                                 new Vector2(hairText.Left(), hairText.BottomLeft().Y + 10),
                                                 _hair.Select(x => x.Name).ToArray(), 200);
            PlayerHairDropDown.Hover        += (newIndex) => { characterPreview.Hair = _hair[newIndex]; };
            PlayerHairDropDown.SelectedIndex = _playerMaker.Hair;

            // Head
            var headText = new TextBlock("Head Shape",
                                         PlayerHairDropDown.BottomLeft().Add(0, 10), interfaceFont, Color.White,
                                         Color.Black);
            var horizontalSelector = new HorizontalSelector(headText.BottomLeft().Add(0, 10),
                                                            _heads.Select(x => x.Name).ToArray(), 200,
                                                            mainMenuSpriteMap.CreateSpriteFromRegion("Arrow_Left"),
                                                            mainMenuSpriteMap.CreateSpriteFromRegion("Arrow_Right"),
                                                            interfaceFont, _buttonScale);

            horizontalSelector.SelectionChanged += (newIndex) => { characterPreview.Head = _heads[newIndex]; };
            horizontalSelector.SelectedIndex     = _playerMaker.Head;

            _panel.AddChild(pronounTextBoxTitle);
            _panel.AddChild(nameTextBoxTitle);
            _panel.AddChild(NameTextBox);
            _panel.AddChild(characterPanel);
            _panel.AddChild(BackButton);
            _panel.AddChild(DoneButton);
            _panel.AddChild(hairText);
            _panel.AddChild(headText);
            _panel.AddChild(horizontalSelector);
            _panel.AddChild(characterPreview);

            _panel.AddChild(PlayerHairDropDown);
            _panel.AddChild(PronounDropDown);

            _userInterface.AddWidget(_panel);

            DoneButton.OnClick += () =>
            {
                Console.WriteLine("Saving Settings");
                _playerMaker.SetHair(PlayerHairDropDown.SelectedIndex);
                _playerMaker.SetName(NameTextBox.GetValue());
                _playerMaker.SetPronouns(PronounDropDown.SelectedIndex);
            };
        }
Beispiel #5
0
        void ScienceOnClick(object sender, EventArgs e)
        {
            TexturedButton control = sender as TexturedButton;
            selectedResearch = control;
            string s = control.Tag.ToString();
            switch (s)
            {

                case "Science1":
                    textManager.Text = string.Format(LocalizationData.Science1 + "\n" + LocalizationData.AvailablePoints + ":{1}", playerData.Research["Growth"] + 1, playerData.Points);
                    textManager.Parse();
                    break;
                case "Science2":
                    textManager.Text = string.Format(LocalizationData.Science2 + "\n" + LocalizationData.AvailablePoints + ":{1}", playerData.Research["Speed"] + 1, playerData.Points);
                    textManager.Parse();
                    break;
                case "Science3":
                    textManager.Text = string.Format(LocalizationData.Science3 + "\n" + LocalizationData.AvailablePoints + ":{1}", playerData.Research["Attack"] + 1, playerData.Points);
                    textManager.Parse();
                    break;
                case "Science4":
                    textManager.Text = string.Format(LocalizationData.Science4 + "\n" + LocalizationData.AvailablePoints + ":{1}", playerData.Research["Defense"] + 1, playerData.Points);
                    textManager.Parse();
                    break;
            }
        }
Beispiel #6
0
        void Manager_OnBeginMenuChange(object sender, MenuChangeEventArgs e)
        {
            offsetVelocity = Vector2.Zero;
            if (e.Menu == Manager.Menues["Campaing"])
            {
                selectedEpisode = selectedCampaing.Episodes[0];
                selectedMission = selectedEpisode.Missions[0];
                TutorialMode = selectedCampaing.InternalName == "Tutorial";
                TutorialProgress = 0;
                textManager.Text = selectedCampaing.Name + "\n\n\n" + selectedCampaing.ShortDescription;
                textManager.Parse();

                RCS.PreCache<Texture2D>("Menues/Strategic/Strategy");
                RCS.PreCache<Texture2D>("Menues/Strategic/06");
                RCS.PreCache<Texture2D>("Menues/Strategic/Hex2");
                RCS.PreCache<Texture2D>("Menues/Strategic/Screen");
                RCS.PreCache<Texture2D>("Menues/Strategic/science_screen");

                for (int i = 1; i <= 4; i++)
                {
                    //Load science
                    for (int j = 1; j <= 6; j++)
                    {
                        RCS.PreCache<Texture2D>(string.Format("Science/{0}_{1}", i, j));
                    }
                }
                RCS.PreCache<Texture2D>("Menues/Strategic/selection_tactical");
                textSettings.Width = 310;
                textSettings.Offset = new Vector2(425, 60);
                textManager.Text = selectedCampaing.Name + "\n\n\n" + selectedCampaing.ShortDescription;
                textManager.Parse();
                RCS.PreCache<Texture2D>("Menues/Strategic/06");
                if (SSL == null)
                {
                    SSL = new SpriteSheetLoader();

                    ScienceAnimator.AtStart = new Vector2(462, 8);
                    ScienceAnimator.AtEnd = new Vector2(25, 319);
                    ScienceAnimator.Duration = 1000;

                    ScienceAnimatorReversed.AtEnd = new Vector2(462, 8);
                    ScienceAnimatorReversed.AtStart = new Vector2(25, 319);
                    ScienceAnimatorReversed.Duration = 1000;

                    IAnimator<Vector2> Empty = new SmoothVectorAnimator();
                    Empty.AtStart = Vector2.Zero;
                    Empty.AtEnd = Vector2.Zero;
                    Empty.Duration = 0;
                    IResourceObject<Texture2D> BaseOverlay = RCS.GetObject<Texture2D>("Menues/Base/Base");
                    Menu Three = new Menu(Empty, Empty, BuildMessageBox());
                    Three.OnDraw += CampaignDescriptionOnDraw;
                    Manager.Menues.Add("Base", Three);
                    Three.Controls.Add(new Image() { Texture = BaseOverlay, Position = Vector2.Zero, Depth = 0.48f });
                    Three.Controls.Add(new Image() { Texture = RCS.GetObject<Texture2D>("Menues/Base/bg_ext"), Position = new Vector2(0, 0), Depth = 0.6f });
                    Three.Controls.Add(new AdControl(adManager) { Position = new Vector2(252, 415), Scale = 1, Depth = 0 });
                    HybridButton LeftBase = new HybridButton(RCS.GetObject<Texture2D>("Menues/LeftButton"), RCS.GetObject<Texture2D>("Menues/LeftButton"), new Vector2(43, 444));
                    LeftBase.Origin = new Vector2(0, 62);
                    LeftBase.NextMenu = "%Back%";
                    LeftBase.CanOffset = false;
                    LeftBase.Depth = 0.01f;
                    LeftBase.Font = Font;
                    LeftBase.HoverColor = new Color(50, 238, 50);
                    LeftBase.UseSound = true;
                    LeftBase.Sound = MenuItemSelected.CreateInstance();
                    LeftBase.TextPosition = -LeftBase.Origin + new Vector2(50, 23);
                    LeftBase.Text = LocalizationData.Back;
                    HybridButton RightBase = new HybridButton(RCS.GetObject<Texture2D>("Menues/RightButton"), RCS.GetObject<Texture2D>("Menues/RightButton"), new Vector2(757, 444));
                    RightBase.Origin = new Vector2(172, 62);
                    RightBase.CanOffset = false;
                    RightBase.Depth = 0.01f;
                    RightBase.HoverColor = new Color(50, 238, 50);
                    RightBase.UseSound = true;
                    RightBase.Sound = MenuItemSelected.CreateInstance();
                    RightBase.NextMenu = "Strategic";
                    RightBase.Font = Font;
                    RightBase.TextPosition = -RightBase.Origin + new Vector2(60, 23);
                    RightBase.Text = LocalizationData.Select;
                    Three.Controls.Add(LeftBase);
                    Three.Controls.Add(RightBase);

                    EpilogueMenu eMenu = new EpilogueMenu();
                    Manager.Menues.Add("Epilogue", eMenu);

                }

            }
            else if (e.Menu == Manager.Menues["Strategic"])
            {
                if (TutorialMode)
                {
                    if (TutorialProgress == 0)
                    {
                        e.Menu.MessageBox.Text = LocalizationData.Tutorial0;
                        e.Menu.MessageBox.Show(true);
                        e.Menu.MessageBox.OnClosed += new Action(MessageBox_OnClosed);
                        TutorialProgress++;
                    }
                }
                if (GalaxyImage == null)
                    GalaxyImage = new Image() { Texture = RCS.GetObject<Texture2D>("Menues/Strategic/06"), CanOffset = true, Depth = 0.9f };

                ScienceDNA = RCS.GetObject<Texture2D>("Menues/Strategic/science_screen");
                textManager.Settings.Width = 200;
                textManager.Settings.Offset = new Vector2(545, 50);
                textManager.Text = "";
                textManager.Parse();

                e.Menu.Controls.Clear();
                e.Menu.Controls.Add(new AdControl(adManager) { Position = new Vector2(252, 415), Scale = 1, Depth = 0 });
                HybridButton LeftStrategic = new HybridButton(RCS.GetObject<Texture2D>("Menues/LeftButton"), RCS.GetObject<Texture2D>("Menues/LeftButton"), new Vector2(43, 444));
                LeftStrategic.Origin = new Vector2(0, 62);
                LeftStrategic.NextMenu = "%Back%";
                LeftStrategic.UseSound = true;
                LeftStrategic.HoverColor = new Color(50, 238, 50);
                LeftStrategic.Sound = MenuItemSelected.CreateInstance();
                LeftStrategic.CanOffset = false;
                LeftStrategic.Depth = 0.01f;
                LeftStrategic.Font = Font;
                LeftStrategic.TextPosition = -LeftStrategic.Origin + new Vector2(50, 23);
                LeftStrategic.Text = LocalizationData.Back;
                HybridButton RightStrategic = new HybridButton(RCS.GetObject<Texture2D>("Menues/RightButton"), RCS.GetObject<Texture2D>("Menues/RightButton"), new Vector2(757, 444));
                RightStrategic.Origin = new Vector2(172, 62);
                RightStrategic.NextMenu = "Mission";
                RightStrategic.CanOffset = false;
                RightStrategic.UseSound = true;
                RightStrategic.HoverColor = new Color(50, 238, 50);
                RightStrategic.Sound = MenuItemSelected.CreateInstance();
                RightStrategic.Depth = 0.01f;
                RightStrategic.Font = Font;
                RightStrategic.TextPosition = -RightStrategic.Origin + new Vector2(60, 23);
                RightStrategic.Text = LocalizationData.Select;

                e.Menu.Controls.Add(new Image() { Texture = RCS.GetObject<Texture2D>("Menues/Strategic/Strategy"), Position = Vector2.Zero, Depth = 0.1f });
                e.Menu.Controls.Add(new Image() { Texture = RCS.GetObject<Texture2D>("Menues/Strategic/Screen"), Position = Vector2.Zero, Depth = 0.7f });
                e.Menu.Controls.Add(GalaxyImage);
                e.Menu.Controls.Add(LeftStrategic);
                e.Menu.Controls.Add(RightStrategic);

                int TextureNumber = playerData.Research["Growth"] + 1;
                if (TextureNumber >= 6)
                {
                    TextureNumber = 6;
                }
                TexturedButton Science1 = new TexturedButton(RCS.GetObject<Texture2D>(string.Format("Science/1_{0}", TextureNumber)), RCS.GetObject<Texture2D>(string.Format("Science/1_{0}", TextureNumber)), new Vector2(100, 10) - new Vector2(37, 319));
                TextureNumber = playerData.Research["Speed"] + 1;
                if (TextureNumber >= 6)
                {
                    TextureNumber = 6;
                }
                TexturedButton Science2 = new TexturedButton(RCS.GetObject<Texture2D>(string.Format("Science/2_{0}", TextureNumber)), RCS.GetObject<Texture2D>(string.Format("Science/2_{0}", TextureNumber)), new Vector2(100 + 164, 10) - new Vector2(37, 319));
                TextureNumber = playerData.Research["Attack"] + 1;
                if (TextureNumber >= 6)
                {
                    TextureNumber = 6;
                }
                TexturedButton Science3 = new TexturedButton(RCS.GetObject<Texture2D>(string.Format("Science/3_{0}", TextureNumber)), RCS.GetObject<Texture2D>(string.Format("Science/3_{0}", TextureNumber)), new Vector2(100, 10 + 164) - new Vector2(37, 319));
                TextureNumber = playerData.Research["Defense"] + 1;
                if (TextureNumber >= 6)
                {
                    TextureNumber = 6;
                }
                TexturedButton Science4 = new TexturedButton(RCS.GetObject<Texture2D>(string.Format("Science/4_{0}", TextureNumber)), RCS.GetObject<Texture2D>(string.Format("Science/1_{0}", TextureNumber)), new Vector2(100 + 164, 10 + 164) - new Vector2(37, 319));

                Science1.Visible = Science1.Enabled = true;
                Science1.Scale = 0.640625f;
                Science2.Visible = Science2.Enabled = true;
                Science2.Scale = 0.640625f;
                Science3.Visible = Science3.Enabled = true;
                Science3.Scale = 0.640625f;
                Science4.Visible = Science4.Enabled = true;
                Science4.Scale = 0.640625f;
                Science1.Tag = "Science1";
                Science2.Tag = "Science2";
                Science3.Tag = "Science3";
                Science4.Tag = "Science4";
                Science1.OnClick += ScienceOnClick;
                Science2.OnClick += ScienceOnClick;
                Science3.OnClick += ScienceOnClick;
                Science4.OnClick += ScienceOnClick;
                Science1.UseSound = true;
                Science2.UseSound = true;
                Science3.UseSound = true;
                Science4.UseSound = true;
                Science1.Sound = MenuItemSelected.CreateInstance();
                Science2.Sound = MenuItemSelected.CreateInstance();
                Science3.Sound = MenuItemSelected.CreateInstance();
                Science4.Sound = MenuItemSelected.CreateInstance();
                e.Menu.Controls.Add(Science1);
                e.Menu.Controls.Add(Science2);
                e.Menu.Controls.Add(Science3);
                e.Menu.Controls.Add(Science4);
                int tC = 4;
                Control[] controls = (from c in e.Menu.Controls where CheckScienceTag(c.Tag) select c).ToArray();
                foreach (Control control in controls)
                {
                    Image image = new Image();
                    image.CanOffset = false;
                    image.Position = (control as TexturedButton).Position;
                    image.Enabled = true;
                    image.Visible = true;
                    image.Scale = 1f;
                    image.Depth = 0.72f;
                    image.Color = Color.White;
                    image.Tag = "Science" + (tC.ToString());
                    tC++;
                    image.Texture = RCS.GetObject<Texture2D>("Science/science_icon_bg");
                    e.Menu.Controls.Add(image);
                }
                EpisodeProgressCounter = 0;
                HexControl hexControl = new HexControl(RCS.GetObject<Texture2D>("Menues/Strategic/Hex2"), factory.GetHexFill(410, new Vector2(512, 512)));
                hexControl.Depth = 0.8f;
                foreach (Episode episode in selectedCampaing.Episodes)
                {
                    if (EpisodeProgressCounter < playerData.GetProgress(selectedCampaing.InternalName))
                    {
                        selectedEpisode = episode;
                        selectedMission = selectedEpisode.Missions[0];
                        hexControl[episode.Position].Color = Color.Yellow * 0.7f;
                        EpisodeProgressCounter += episode.Missions.Count;
                    }
                    else
                    {
                        hexControl[episode.Position].Color = Color.White * 0.8f;
                    }

                    if (EpisodeProgressCounter < playerData.GetProgress(selectedCampaing.InternalName))
                    {
                        hexControl[episode.Position].Color = new Color(53, 234, 28) * 0.7f;
                        foreach (int cell in episode.Cells)
                            hexControl[cell].Color = new Color(53, 234, 28) * 0.7f;
                    }
                    hexControl[episode.Position].Tag = episode;
                    hexControl[episode.Position].OnClick += new Action<Cell>(hexControl_OnClick);
                }
                textManager.Text = selectedEpisode.Name + "\n\n\n\n\n" + selectedEpisode.Description;
                textManager.Parse();
                e.Menu.Controls.Add(hexControl);
                /*
                foreach (Episode episode in selectedCampaing.Episodes)
                {
                    AnimatedButton animated = new AnimatedButton(SSL.DescriptorList["StrategicEpisodeSelection"]);
                    animated.Position = episode.Position;
                    animated.Origin = new Vector2(32, 32);
                    if (EpisodeProgressCounter < playerData.GetProgress(selectedCampaing.InternalName))
                    {
                        animated.Enabled = true;
                        EpisodeProgressCounter += episode.Missions.Count;
                    }
                    else
                    {
                        animated.Enabled = false;
                    }

                    animated.CanOffset = true;
                    animated.Depth = 0.8f;
                    animated.Color = animated.Enabled ? Color.Khaki : Color.Gray;
                    animated.Tag = episode;
                    animated.OnClick += new EventHandler(animated_OnClick);
                    e.Menu.Controls.Add(animated);

                }
                */
                EpisodeProgressCounter = 0;
                foreach (Episode ep in selectedCampaing.Episodes)
                {
                    if (ep != selectedEpisode)
                        EpisodeProgressCounter += ep.Missions.Count;
                    else
                        break;
                }

                e.Menu.InitializeControls();
            }
            else if (e.Menu == Manager.Menues["Mission"])
            {
                if (TutorialMode)
                    if (TutorialProgress == 4)
                    {
                        e.Menu.MessageBox.Text = LocalizationData.Tutorial4;
                        e.Menu.MessageBox.Show(true);
                        TutorialProgress++;
                    }
                MissionOffset = Vector2.Zero;
                textManager.Settings.Width = 200;
                textManager.Settings.Offset = new Vector2(545, 50);

                e.Menu.Controls.Clear();
                e.Menu.Controls.Add(new AdControl(adManager) { Position = new Vector2(252, 415), Scale = 1, Depth = 0 });
                HybridButton LeftMission = new HybridButton(RCS.GetObject<Texture2D>("Menues/LeftButton"), RCS.GetObject<Texture2D>("Menues/LeftButton"), new Vector2(43, 444));
                LeftMission.Origin = new Vector2(0, 62);
                LeftMission.NextMenu = "%Back%";
                LeftMission.CanOffset = false;
                LeftMission.Depth = 0.01f;
                LeftMission.HoverColor = new Color(50, 238, 50);
                LeftMission.UseSound = true;
                LeftMission.Sound = MenuItemSelected.CreateInstance();
                LeftMission.Font = Font;
                LeftMission.TextPosition = -LeftMission.Origin + new Vector2(50, 23);
                LeftMission.Text = LocalizationData.Back;
                HybridButton RightMission = new HybridButton(RCS.GetObject<Texture2D>("Menues/RightButton"), RCS.GetObject<Texture2D>("Menues/RightButton"), new Vector2(757, 444));
                RightMission.Origin = new Vector2(172, 62);
                RightMission.CanOffset = false;
                RightMission.Depth = 0.01f;
                RightMission.HoverColor = new Color(50, 238, 50);
                RightMission.Font = Font;
                RightMission.UseSound = true;
                RightMission.Sound = MenuItemSelected.CreateInstance();
                RightMission.TextPosition = -RightMission.Origin + new Vector2(60, 23);
                RightMission.Text = LocalizationData.Play;
                RightMission.OnClick += new EventHandler(RightMission_OnClick);

                e.Menu.Controls.Add(LeftMission);
                e.Menu.Controls.Add(RightMission);
                e.Menu.Controls.Add(new Image() { Texture = RCS.GetObject<Texture2D>("Menues/Strategic/Strategy"), Position = Vector2.Zero, Depth = 0.1f });
                e.Menu.Controls.Add(new Image() { Texture = RCS.GetObject<Texture2D>("Menues/Strategic/Screen"), Position = Vector2.Zero, Depth = 0.7f });
                e.Menu.Controls.Add(PopupMB);

                int Counter = EpisodeProgressCounter;
                if (EpisodeProgressCounter == playerData.GetProgress(selectedCampaing.InternalName) - 1)
                {
                    if (!String.IsNullOrWhiteSpace(selectedEpisode.EpisodePopup))
                    {
                        PopupTextManager.Text = selectedEpisode.EpisodePopup;
                        PopupTextManager.Parse();
                        PopupMB.Show(true);
                    }
                }
                foreach (Mission mission in selectedEpisode.Missions)
                {
                    Vector2 Position = Vector2.Zero;
                    if (Counter - EpisodeProgressCounter == 0 || Counter - EpisodeProgressCounter == selectedEpisode.Missions.Count - 1)
                    {
                        Position = new Vector2(150 + (Counter - EpisodeProgressCounter) * 256, 240);
                    }
                    else
                    {
                        bool Even = (Counter - EpisodeProgressCounter - 1) % 2 == 0;
                        if (Even)
                        {
                            Position = new Vector2(150 + (Counter - EpisodeProgressCounter) * 256, 140);
                        }
                        else
                        {
                            Position = new Vector2(150 + (Counter - EpisodeProgressCounter) * 256, 340);
                        }
                    }
                    Position.Y -= 30;
                    TexturedButton tb = new TexturedButton(RCS.GetObject<Texture2D>("Menues/Strategic/selection_tactical"), RCS.GetObject<Texture2D>("Menues/Strategic/selection_tactical"), Position);
                    tb.CanOffset = true;
                    tb.Scale = 0.5f;
                    tb.Origin = new Vector2(128, 128);
                    tb.Color = Counter < playerData.GetProgress(selectedCampaing.InternalName) ? Color.White : Color.Black;
                    if (tb.Color == Color.White)
                        selectedMission=mission;
                    tb.Depth = 0.8f;
                    tb.Enabled = Counter < playerData.GetProgress(selectedCampaing.InternalName) ? true : false;
                    tb.Tag = mission;
                    tb.OnClick += new EventHandler(tb_OnClick);
                    e.Menu.Controls.Add(tb);
                    Counter++;

                }
                (from control in e.Menu.Controls where control.Tag == selectedMission select control).First().Color = Color.Gray;
                textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                textManager.Parse();
                e.Menu.InitializeControls();
            }
        }
Beispiel #7
0
        void fOnUpdateEnd(GameTime gameTime)
        {
            #region Menu
            if (GameState == GameState.Menu)
            {
                if (Manager.SelectedMenu == "Mission" && Manager.State == MenuState.Sustain)
                {
                    offsetVelocity *= 0.95f;
                    MissionOffset = Vector2.Clamp(MissionOffset + offsetVelocity, new Vector2(-(Manager.Menues["Mission"].Controls.Count - 3) * 240 + 400, 0), new Vector2(0, 0));
                    foreach (Control control in Manager.Menues["Mission"].Controls)
                    {
                        TexturedButton ab = control as TexturedButton;
                        if (ab != null)
                        {
                            ab.Offset = MissionOffset;
                        }
                    }
                }
                else if (Manager.SelectedMenu == "Strategic" && Manager.State == MenuState.Sustain)
                {
                    if (!ScienceVisible)
                    {
                        if (!textManager.Text.StartsWith(selectedEpisode.Name))
                        {
                            textManager.Text = selectedEpisode.Name + "\n\n\n\n\n" + selectedEpisode.Description;
                            textManager.Parse();
                        }
                        offsetVelocity *= 0.95f;
                        float Multiplier = (float)gameTime.ElapsedGameTime.TotalMilliseconds / (1000f / 30);
                        GalaxyImage.Offset = Vector2.Clamp(GalaxyImage.Offset + offsetVelocity * Multiplier, new Vector2(-224 - 310, -480), new Vector2(0, 0));
                        foreach (Control control in Manager.Menues["Strategic"].Controls)
                        {
                            HexControl ab = control as HexControl;
                            if (ab != null)
                            {
                                ab.Offset = GalaxyImage.Offset;
                            }
                        }
                    }
                    else
                        offsetVelocity = Vector2.Zero;
                    if (!Draging && ScienceAnimator.State == AnimatorState.Stoped && ScienceAnimatorReversed.State == AnimatorState.Stoped)
                    {
                        if (ScienceState == ScienceState.Forward)
                        {
                            if (Vector2.Distance(SciencePosition, new Vector2(462, 8)) > 100)
                            {
                                ScienceAnimator.AtStart = SciencePosition;
                                ScienceAnimator.Reset();
                                ScienceAnimator.Start();
                                ScienceLock = true;

                                if (TutorialMode)
                                {
                                    if (TutorialProgress == 3)
                                    {
                                        Manager.Menues["Strategic"].MessageBox.Text = LocalizationData.Tutorial3;
                                        Manager.Menues["Strategic"].MessageBox.Show(true);
                                        TutorialProgress++;
                                    }
                                }
                            }
                        }
                        else if (ScienceState == ScienceState.Reversed)
                        {
                            if (Vector2.Distance(SciencePosition, new Vector2(462, 8)) < 460)
                            {
                                ScienceAnimatorReversed.AtStart = SciencePosition;
                                ScienceAnimatorReversed.Reset();
                                ScienceAnimatorReversed.Start();
                            }
                        }
                    }
                    ScienceAnimator.Update(gameTime);
                    ScienceAnimatorReversed.Update(gameTime);
                    if (!Draging)
                    {
                        if (ScienceState == ScienceState.Forward)
                        {
                            SciencePosition = ScienceAnimator.Value;
                            if (ScienceAnimator.State == AnimatorState.Started && Vector2.Distance(SciencePosition, new Vector2(462, 8)) > 520)
                            {
                                ScienceAnimator.AtStart = new Vector2(462, 8);
                                ScienceState = ScienceState.Reversed;
                                ScienceAnimatorReversed.Reset();
                            }
                        }
                        else
                        {
                            SciencePosition = ScienceAnimatorReversed.Value;
                            if (ScienceAnimatorReversed.State == AnimatorState.Started && Vector2.Distance(SciencePosition, new Vector2(462, 8)) < 10)
                            {
                                ScienceAnimatorReversed.AtStart = new Vector2(25, 319);
                                ScienceLock = false;
                                ScienceState = ScienceState.Forward;
                                ScienceAnimator.Reset();
                            }
                            else if (ScienceAnimatorReversed.State == AnimatorState.Started)
                            {
                                ScienceVisible = false;
                            }
                            else if (ScienceAnimatorReversed.State == AnimatorState.Stoped)
                            {
                                ScienceVisible = true;
                            }
                        }
                    }
                    foreach (Control control in Manager.Menues["Strategic"].Controls.Where(c => CheckScienceTag(c.Tag)))
                    {
                        if (!(control is Image))
                            control.Depth = 0.71f;
                        control.CanOffset = true;
                        control.Offset = SciencePosition;
                    }
                    if (ScienceVisible)
                    {
                        foreach (Control control in Manager.Menues["Strategic"].Controls)
                        {
                            if (control is HybridButton)
                            {
                                HybridButton hb = control as HybridButton;
                                if (hb.Text == LocalizationData.Select)
                                {
                                    selectedResearch = null;
                                    hb.NextMenu = "";
                                    hb.OnClick += new EventHandler(hb_OnClick);
                                    hb.Text = LocalizationData.Research;
                                    break;
                                }
                            }
                        }
                        foreach (Control control in Manager.Menues["Strategic"].Controls)
                        {
                            if (control is HybridButton)
                            {
                                HybridButton hb = control as HybridButton;
                                if (hb.Text == LocalizationData.Back)
                                {
                                    hb.NextMenu = "";
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Control control in Manager.Menues["Strategic"].Controls)
                        {
                            if (control is HybridButton)
                            {
                                HybridButton hb = control as HybridButton;
                                if (hb.Text == LocalizationData.Research)
                                {
                                    hb.OnClick -= hb_OnClick;
                                    hb.NextMenu = "Mission";
                                    hb.Text = LocalizationData.Select;
                                    break;
                                }
                            }
                        }
                        foreach (Control control in Manager.Menues["Strategic"].Controls)
                        {
                            if (control is HybridButton)
                            {
                                HybridButton hb = control as HybridButton;
                                if (hb.Text == LocalizationData.Back)
                                {
                                    hb.NextMenu = "%Back%";
                                    break;
                                }
                            }
                        }
                    }
                    if (SciencePosition.X < 27)
                        SciencePosition.X = 27;
                    else if (SciencePosition.X > 462)
                        SciencePosition.X = 462;
                    if (SciencePosition.Y < 8)
                        SciencePosition.Y = 8;
                    else if (SciencePosition.Y > 319)
                        SciencePosition.Y = 319;

                    ScienceRectangle.Width = 512 - (int)SciencePosition.X;
                    ScienceRectangle.Height = (int)SciencePosition.Y - 8 + 103;
                    ScienceRectangle.Y = 305 - ((int)SciencePosition.Y - 8);
                }
            }
            #endregion
            #region SinglePlayer
            else if (GameState == GameState.Singleplayer)
            {
                cameraVelocity *= 0.95f;
                camera.Position += cameraVelocity;
                Vector2 cameraWorldMin = Vector2.Transform(Vector2.Zero, Matrix.Invert(camera.Transforms));
                Vector2 cameraSize = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height) / camera.Zoom;
                Vector2 limitWorldMin = new Vector2(0, 0);
                Vector2 limitWorldMax = new Vector2(Width, Height);
                Vector2 positionOffset = camera.Position - cameraWorldMin;
                camera.Position = Vector2.Clamp(cameraWorldMin, limitWorldMin, limitWorldMax - cameraSize) + positionOffset;
                if (!InternalPause)
                {
                    GameTimeSpent += gameTime.ElapsedGameTime;
                    foreach (Planet p in GameManager.State.Planets)
                    {
                        if (GameSelectedPlanets.Contains(p))
                            p.SelectionRotation += 0.05f;
                        else
                            p.SelectionRotation = 0;
                    }
                    GameManager.Update();
                    AI.ProcessTurn(GameManager, gameTime);
                    if (GameManager.GameEnd())
                    {
                        OnGameEnd();
                    }
                }

            }
            #endregion
            else if(GameState==GameState.Multiplayer)
            {

                Multiplayer.Update(gameTime);
            }
        }
Beispiel #8
0
        private void SetupUserInterface()
        {
            var mainMenuSpriteMap = _spriteMapLoader.GetContent("assets/UI/title_menu_buttons.json");

            _buttonScale = 3f;
            var font = _contentChest.Get <SpriteFont>("Fonts/TitleFont");

            // Main Menu Heading
            var signTopSprite = mainMenuSpriteMap.CreateSpriteFromRegion("Title_Button_Heading");

            SignTopImage = _userInterface.AddWidget(new Image(signTopSprite,
                                                              new Vector2(_viewPortManager.ViewPort.Center().X - signTopSprite.Source.Width * _buttonScale / 2f,
                                                                          _viewPortManager.ViewPort.Center().Y - _viewPortManager.ViewPort.Height / 6f), _buttonScale));

            // Title Text
            TitleTextBlock = new TextBlock(Title,
                                           new Vector2(_viewPortManager.ViewPort.Center().X - font.MeasureString(Title).X / 2,
                                                       SignTopImage.Bounds.Top -
                                                       font.MeasureString(Title).Y), font, Color.Black, null);

            // News Section
            var newsPanelSprite   = mainMenuSpriteMap.CreateSpriteFromRegion("Main_Menu_Empty");
            var newsPanelPosition = new Vector2(SignTopImage.Bounds.Right - newsPanelSprite.Source.Width * _buttonScale,
                                                SignTopImage.Bounds.Bottom);

            NewsPanelImage = SignTopImage.AddChild(new Image(newsPanelSprite,
                                                             newsPanelPosition, _buttonScale));
            ScrollBox = new ScrollBox(_contentChest,
                                      "{line} Welcome to Project Sanctuary! {line} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue finibus maximus. Maecenas rhoncus malesuada eros vitae tincidunt. Nam suscipit, justo ac gravida rhoncus, ante neque auctor urna, a egestas dui odio eget ante. Aenean nec eros nisi. Nam bibendum viverra tincidunt. Phasellus elementum urna nibh, ac egestas nibh pellentesque vitae. Nulla in mollis nisl. Vivamus nec mauris rutrum magna sollicitudin venenatis et a enim. Phasellus quis mi ex. {line} ",
                                      NewsPanelImage.Bounds.Add(5 * _buttonScale, 14 * _buttonScale, -11 * _buttonScale, -20 * _buttonScale));

            // New Game Button
            var newButtonPosition = new Vector2(SignTopImage.Bounds.Left,
                                                SignTopImage.Bounds.Bottom);

            NewGameButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("New_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("New_On"),
                newButtonPosition, _buttonScale);
            NewGameButton.OnClick += () => { };

            // Load Game Button
            LoadGameButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Load_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Load_On"),
                newButtonPosition + new Vector2(0, NewGameButton.Height * _buttonScale), _buttonScale);
            LoadGameButton.OnClick += () => { };

            // Exit Game Button
            ExitGameButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Exit_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Exit_On"),
                newButtonPosition + new Vector2(0,
                                                NewGameButton.Height * _buttonScale + LoadGameButton.Height * _buttonScale),
                _buttonScale);
            ExitGameButton.OnClick += () => Console.WriteLine("Closing Game...");

            var settingsSprite = mainMenuSpriteMap.CreateSpriteFromRegion("Settings_On");
            var settingsButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Settings_Off"), settingsSprite,
                new Vector2(_viewPortManager.ViewPort.Width - settingsSprite.Source.Width * _buttonScale - 10,
                            _viewPortManager.ViewPort.Height - settingsSprite.Source.Height * _buttonScale - 10), _buttonScale);

            // Add all elements to the parent.
            SignTopImage.AddChild(TitleTextBlock);
            SignTopImage.AddChild(ScrollBox);
            SignTopImage.AddChild(NewGameButton as IWidget);
            SignTopImage.AddChild(LoadGameButton as IWidget);
            SignTopImage.AddChild(ExitGameButton as IWidget);
            SignTopImage.AddChild(settingsButton);

            _userInterface.AddWidget(SignTopImage);
        }