/// <summary> /// The Login Screen is the first screen you see when the app starts /// </summary> public LoginScreen() : base("Login") { //Inherits our login background ScreenManager.AddScreen(new BackgroundScreen()); Settings.UserSetting Settings = GameManager.UserSettings; ButtonEntry play = new ButtonEntry("Play", true); ButtonEntry options = new ButtonEntry("Options", true); ButtonEntry exit = new ButtonEntry("Exit", true); play.Selected += PlaySelected; options.Selected += OptionsSelected; exit.Selected += OnCancel; ButtonEntries.Add(play); ButtonEntries.Add(options); ButtonEntries.Add(exit); CheckBox = new CheckBoxEntry(); CheckBox.Text = "Remember Password"; CheckBox.TextPosition = CheckBoxEntry.TextLocation.Right; CheckBoxEntries.Add(CheckBox); username = new BoxEntry((!String.IsNullOrEmpty(Settings.Username) ? Settings.Username : "******")); if (Settings.PasswordSave && !String.IsNullOrEmpty(Settings.Password)) { //Because our password is already hashed, //lets just make an object show "*" string str = ""; for (int i = 0; i < Settings.PassLength; i++) { str += "*"; } password = new BoxEntry(str); } else { password = new BoxEntry("Password"); } username.Selected += UserSelected; password.Selected += PassSelected; username.InputEnabled = true; password.InputEnabled = true; password.ScrambleInput = true; BoxEntries.Add(username); BoxEntries.Add(password); //Dont draw the login title DrawTitle = false; }
/// <summary> /// Draws the menu /// </summary> public override void Draw(GameTime gameTime) { Vector2 position = Position; //Makes the menu slide into place during transition //Using math.Pow, it makes the movement slow down near the end float offset = (float)Math.Pow(TransPosition, 2); bool StateOn = false; if (ScreenState == Screens.ScreenState.On) { position.X -= offset * 256; StateOn = true; } else { position.X += offset * 512; } ScreenManager.SpriteBatch.Begin(); //Draws each button entry //Makes each entry slide horizontally into place //using a position modifier //State on = right to left //State off = left to right for (int i = 0; i < _buttonEntries.Count; i++) { ButtonEntry entry = _buttonEntries[i]; bool selected = IsActive && (i == _selectedButton); entry.Draw(this, position, selected, gameTime); //Make sure to set our button spacing, //otherwise itll stack on top of eachother position.Y += entry.GetHeight(this); } //Draws each box entry //Makes each entry slide horizontally into place //using a position modifier //State on = left to right //State off = right to left for (int i = 0; i < _boxEntries.Count; i++) { BoxEntry box = _boxEntries[i]; bool select = IsActive && (i == _selectedBox); Vector2 newPos = Vector2.Zero; if (StateOn) { newPos.X += offset * 256; } else { newPos.X -= offset * 512; } box.Draw(this, newPos, select, gameTime); } //Draws each checkbox entry //Internally in each entry, we fade in for (int i = 0; i < _checkboxEntries.Count; i++) { CheckBoxEntry check = _checkboxEntries[i]; bool select = IsActive && (i == _selectedCheckBox); check.Draw(this, position, select, gameTime); } //Draws the menu title if (DrawTitle) { Viewport viewport = GameManager.Device.Viewport; Vector2 titlePos = new Vector2(viewport.Width / 2, viewport.Height / 25); Vector2 titleOrigin = ScreenManager.Font.MeasureString(_title) / 2; Color color = new Color(192, 192, 192, Alpha); float scale = 1.25f; titlePos.Y -= offset * 100; ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, _title, titlePos, color, 0, titleOrigin, scale, SpriteEffects.None, 0); } ScreenManager.SpriteBatch.End(); }
/// <summary> /// Notifies classes that a box entry has been chosen /// </summary> protected virtual void OnSelectBox(int index) { _boxEntries[_selectedBox].OnSelect(); LastBoxClicked = _boxEntries[_selectedBox]; }