/// <summary>
        /// Title screen constructor.
        /// </summary>
        public SaveScreen(GameMain parent)
        {
            List <Base.GameState> allStates = GameStateManager.LoadData();
            int i = 0;

            _window = Rectangle.Empty;
            _parent = parent;

            _list = new ComponentList();
            _list.ComponentHeight = 80;

            if (allStates.Count < 5)
            {
                _list.AddComponent(new Button("New Save", new SelectDelegate(() =>
                {
                    GameStateManager.SaveData(-1);
                    _parent.ChangeState(GameState.Playing);
                })));
            }
            foreach (Base.GameState state in allStates)
            {
                _list.AddComponent(new SaveDataButton("saveButton" + (i++), state, new SelectDelegate(() =>
                {
                    GameStateManager.SaveDataOverwriting(state);
                    _parent.ChangeState(GameState.Playing);
                })));
            }

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.Playing);
            })));
        }
Exemple #2
0
        private void FindIgnoreComponents()
        {
            var ignore = _type.GetCustomAttribute <Ignore>();

            if (ignore != null)
            {
                for (var i = 0; i < ignore.Types.Length; i++)
                {
                    if (!_components.IsValid(_fields[i].DeclaringType))
                    {
                        IsValid = false;
                        return;
                    }

                    var componentType = _components.AddComponent(_fields[i].DeclaringType);
                    if (!_allComponents.Add(componentType))
                    {
                        IsValid = false;
                        return;
                    }

                    _ignoreComponents.Add(componentType);
                }
            }
        }
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public LoadScreen(GameMain parent)
        {
            _window = Rectangle.Empty;
            _parent = parent;
            int x = 0;

            _list = new ComponentList();
            _list.ComponentHeight = 80;

            foreach (Base.GameState state in GameStateManager.LoadData())
            {
                //TODO: Create specific component.
                _list.AddComponent(new SaveDataButton("saveButton" + (x++), state, new SelectDelegate(() =>
                {
                    GameStateManager.SelectSaveData(state);
                    _parent.ChangeState(GameState.LoadingGame);
                })));
            }

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));
        }
 private void OnEnable()
 {
     if (TargetList != null && SubjectComponent != null)
     {
         TargetList.AddComponent(SubjectComponent);
     }
 }
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public OptionsScreen(GameMain parent)
        {
            _list = new ComponentList();

            SelectionBox resolution = new SelectionBox("Resolution");

            resolution.AddOption("800x600");
            resolution.AddOption("1280x720");
            resolution.AddOption("1920x1080");
            resolution.SelectOption(OptionsManager.CurrentOptions.ResolutionWidth + "x" + OptionsManager.CurrentOptions.ResolutionHeight);
            _list.AddComponent(resolution);

            SelectionBox fullscreen = new SelectionBox("Fullscreen");

            fullscreen.AddOption("On");
            fullscreen.AddOption("Off");
            fullscreen.SelectOption(OptionsManager.CurrentOptions.Fullscreen ? "On" : "Off");
            _list.AddComponent(fullscreen);

            SelectionBox inverted = new SelectionBox("Inverted Aim");

            inverted.AddOption("On");
            inverted.AddOption("Off");
            inverted.SelectOption(OptionsManager.CurrentOptions.InvertAim ? "On" : "Off");
            _list.AddComponent(inverted);

            _list.ValueChanged += new ValueChangeDelegate(() =>
            {
                string res = _list.GetValue("Resolution");
                string ful = _list.GetValue("Fullscreen");
                string aim = _list.GetValue("Inverted Aim");

                OptionsManager.CurrentOptions.ResolutionWidth  = Convert.ToInt32(res.Split('x')[0]);
                OptionsManager.CurrentOptions.ResolutionHeight = Convert.ToInt32(res.Split('x')[1]);
                OptionsManager.CurrentOptions.Fullscreen       = (ful == "On");
                OptionsManager.CurrentOptions.InvertAim        = (aim == "On");
            });

            _list.AddComponent(new Button("Delete All Save Data", new SelectDelegate(() =>
            {
                GameStateManager.DeleteAllSaves();
            })));

            _list.AddComponent(new Button("Save", new SelectDelegate(() =>
            {
                OptionsManager.SaveOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));

            _window = Rectangle.Empty;

            _parent = parent;
        }
Exemple #6
0
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public IntroScreen(GameMain parent)
        {
            _font = GameContent.LoadContent <SpriteFont>("fonts/DefaultFont");

            _parent = parent;

            _input = new Input();

            _credits = new List <string>();
            _credits.Add("A long time ago, an distant kingdom lived in peace");
            _credits.Add("thanks to a magic crown. The peace was kept until ");
            _credits.Add("one day, when a Evil Wizard stole the crown.");
            _credits.Add("The Prince couldn't let the worst happen,");
            _credits.Add("and saved the day, killing the villain.");
            _credits.Add("");
            _credits.Add("Two hundred years have passed since then.");
            _credits.Add("A group of cultists stole the crown and");
            _credits.Add("captured the king, so they could");
            _credits.Add("get enough power to ressurrect the wizard.");
            _credits.Add("");
            _credits.Add("Now, all of the kingdom's hopes rest on");
            _credits.Add("the shoulders of the king's bodyguard.");
            _credits.Add("He needs to get the sacred weapons to");
            _credits.Add("destroy the evil cult, saving the king,");
            _credits.Add("the kingdom and the crown.");
            _credits.Add("");
            _credits.Add("But first... he would need a sword.");

            _titleList = new ComponentList();
            _titleList.AddComponent(new Label("Diogo Muller & João Vitor present..."));
            _titleList.Position = new Rectangle(20, 20, parent.Window.ClientBounds.Width - 40, parent.Window.ClientBounds.Height - 40);

            _list = new ScrollingList();

            _list.ComponentHeight = 50;

            foreach (string st in _credits)
            {
                _list.AddComponent(new Label(st));
            }

            _list.Position = new Rectangle(20, 20, parent.Window.ClientBounds.Width - 40, parent.Window.ClientBounds.Height - 40);
            _list.ResetPosition();

            _showningTime = ShowTime;
            _fadingTime   = FadeTime;
        }
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public TitleScreen(GameMain parent)
        {
            _logo = GameContent.LoadContent <Texture2D>("images/title.png");

            _list = new ComponentList();

            _list.ComponentHeight = 50;

            _list.AddComponent(new Button("New Game", () => _parent.ChangeState(GameState.NewGame)));
            _list.AddComponent(new Button("Load Game", () => _parent.ChangeState(GameState.LoadGame)));
            _list.AddComponent(new Button("Demo Mode", () => _parent.ChangeState(GameState.DemoMode)));
            _list.AddComponent(new Button("Options", () => _parent.ChangeState(GameState.Options)));
            _list.AddComponent(new Button("How to Play", () => _parent.ChangeState(GameState.HowToPlay)));
            _list.AddComponent(new Button("Credits", () => _parent.ChangeState(GameState.Credits)));
            _list.AddComponent(new Button("Quit Game", () => _parent.ChangeState(GameState.Quiting)));

            _window = Rectangle.Empty;

            _parent = parent;
        }
Exemple #8
0
 public void AddComponenet(Component component)
 {
     List.AddComponent(component);
 }
        public TitleScreen(string background, int width, int height)
        {
            #region Title Screen Assets initialization

            _bounds     = new Rectangle(0, 0, width, height);
            _background = GameContent.LoadContent <Texture2D>(background);
            _logo       = GameContent.LoadContent <Texture2D>("Images/Logo");
            _font       = GameContent.LoadContent <SpriteFont>("Fonts/SmallFont");

            Vector2 bg_center     = new Vector2(_logo.Width / 2.0f, _logo.Height / 2.0f);
            Vector2 screen_center = new Vector2(width / 2.0f, height / 2.0f);
            _titlePosition = new Rectangle((int)(screen_center.X - bg_center.X),
                                           (int)(screen_center.Y * 0.5 - bg_center.Y),
                                           (int)(_logo.Width),
                                           (int)(_logo.Height));

            _startMessage = "Press START or ENTER to start the game";
            Vector2 startSize = _font.MeasureString(_startMessage);
            _startOrigin   = new Vector2(startSize.X / 2, startSize.Y / 2);
            _startPosition = new Vector2(screen_center.X, screen_center.Y * 1.7f);

            _transparency     = 0.9f;
            _transparencyDiff = 0.001f;

            #endregion Title Screen Assets initialization

            #region Options Initialization

            _options = new ComponentList();

            SelectionBox controller = new SelectionBox("Use Keyboard?");
            controller.AddOption("Yes");
            controller.AddOption("No");
            controller.SelectOption(GameMain.UseKeyboard ? "Yes" : "No");
            _options.AddComponent(controller);

            SelectionBox players = new SelectionBox("Players");
            players.AddOption("2");
            players.AddOption("3");
            players.AddOption("4");

            /*players.AddOption("5");
            *  players.AddOption("6");
            *  players.AddOption("7");
            *  players.AddOption("8");*/
            players.SelectOption(GameMain.PlayerCount.ToString());
            _options.AddComponent(players);

            _options.ValueChanged += () =>
            {
                string useKeyboard  = _options.GetValue("Use Keyboard?");
                string playersCount = _options.GetValue("Players");

                GameMain.UseKeyboard = (useKeyboard == "Yes");
                GameMain.PlayerCount = int.Parse(playersCount.Replace('*', '\0'));

                if (GameMain.PlayerCount > 2)
                {
                    _options.GetComponent <Button>("Search For Game").Visible = false;
                    _options.GetComponent <Button>("Host Game").Visible       = false;
                }
                else
                {
                    _options.GetComponent <Button>("Search For Game").Visible = true;
                    _options.GetComponent <Button>("Host Game").Visible       = true;
                }
            };

            _options.AddComponent(new Button("Play Local", () =>
            {
                _showOptions = false;
                GameMain.ChangeState(GameState.PlayingLocal);
            }));

            _options.AddComponent(new Button("Search For Game", () =>
            {
                // TODO: Add network logic.
                _showOptions = false;
                GameMain.ChangeState(GameState.SearchingGame);
            }));

            _options.AddComponent(new Button("Host Game", () =>
            {
                if (GameMain.CurrentState != GameState.TitleScreen)
                {
                    return;
                }

                // TODO: Add network logic.
                _showOptions = false;
                GameMain.ChangeState(GameState.CreatingHost);
            }));

            _options.Position = new Rectangle(30, 200, width - 60, height - 220);
            _showOptions      = false;
            #endregion Options Initialization

            _firstKeyUp = false;
        }