+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-
-namespace SuperPolarity
-{
- class NameChooserWidget : Widget
- {
- int CurrentIndex;
- bool Lock;
- int LockRate;
- int CurrentTime;
-
- public NameChooserWidget(SuperPolarity game, Vector2 position)
- : base(game, position)
- {
- AppendChild(new LetterChooseWidget(game, new Vector2(position.X, position.Y)));
- AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 32, position.Y)));
- AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 64, position.Y)));
- CurrentIndex = 0;
- Children[CurrentIndex].Activate();
- LockRate = 300;
- CurrentTime = 0;
-
- InputController.Bind("moveX", HandleMovement);
- }
-
- public override void Update(GameTime gameTime)
- {
- base.Update(gameTime);
-
- CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds;
- if (CurrentTime > LockRate)
- {
- CurrentTime = 0;
- Lock = false;
- }
-
- foreach (LetterChooseWidget widget in Children)
- {
- widget.Update(gameTime);
- }
- }
-
- public void HandleMovement(float value)
- {
- if (value > 0.8 && !Lock)
- {
- Children[CurrentIndex].Deactivate();
- CurrentIndex = CurrentIndex + 1;
-
- if (CurrentIndex > Children.Count - 1)
- {
- CurrentIndex = 0;
- }
-
- Lock = true;
- }
-
- if (value < -0.8 && !Lock)
- {
- Children[CurrentIndex].Deactivate();
- CurrentIndex = CurrentIndex - 1;
-
- if (CurrentIndex < 0)
- {
- CurrentIndex = Children.Count - 1;
- }
-
- Lock = true;
- }
-
- Children[CurrentIndex].Activate();
- }
-
- public string Value()
- {
- var name = "";
-
- foreach (LetterChooseWidget letter in Children)
- {
- name = name + letter.Value();
- }
-
- return name;
- }
-
- public override void Draw(SpriteBatch spriteBatch)
- {
- foreach (LetterChooseWidget widget in Children)
- {
- widget.Draw(spriteBatch);
- }
- }
- }
-}