]> git.r.bdr.sh - rbdr/super-polarity/blame_incremental - SuperPolarity/NameChooserWidget.cs
More spaces removed.
[rbdr/super-polarity] / SuperPolarity / NameChooserWidget.cs
... / ...
CommitLineData
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Microsoft.Xna.Framework;
6using Microsoft.Xna.Framework.Graphics;
7
8namespace SuperPolarity
9{
10 class NameChooserWidget : Widget
11 {
12 int CurrentIndex;
13 bool Lock;
14 int LockRate;
15 int CurrentTime;
16
17 public NameChooserWidget(SuperPolarity game, Vector2 position)
18 : base(game, position)
19 {
20 AppendChild(new LetterChooseWidget(game, new Vector2(position.X, position.Y)));
21 AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 32, position.Y)));
22 AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 64, position.Y)));
23 CurrentIndex = 0;
24 Children[CurrentIndex].Activate();
25 LockRate = 300;
26 CurrentTime = 0;
27
28 InputController.Bind("moveX", HandleMovement);
29 }
30
31 public override void Update(GameTime gameTime)
32 {
33 base.Update(gameTime);
34
35 CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds;
36 if (CurrentTime > LockRate)
37 {
38 CurrentTime = 0;
39 Lock = false;
40 }
41
42 foreach (LetterChooseWidget widget in Children)
43 {
44 widget.Update(gameTime);
45 }
46 }
47
48 public void HandleMovement(float value)
49 {
50 if (value > 0.8 && !Lock)
51 {
52 Children[CurrentIndex].Deactivate();
53 CurrentIndex = CurrentIndex + 1;
54
55 if (CurrentIndex > Children.Count - 1)
56 {
57 CurrentIndex = 0;
58 }
59
60 Lock = true;
61 }
62
63 if (value < -0.8 && !Lock)
64 {
65 Children[CurrentIndex].Deactivate();
66 CurrentIndex = CurrentIndex - 1;
67
68 if (CurrentIndex < 0)
69 {
70 CurrentIndex = Children.Count - 1;
71 }
72
73 Lock = true;
74 }
75
76 Children[CurrentIndex].Activate();
77 }
78
79 public string Value()
80 {
81 var name = "";
82
83 foreach (LetterChooseWidget letter in Children)
84 {
85 name = name + letter.Value();
86 }
87
88 return name;
89 }
90
91 public override void Draw(SpriteBatch spriteBatch)
92 {
93 foreach (LetterChooseWidget widget in Children)
94 {
95 widget.Draw(spriteBatch);
96 }
97 }
98 }
99}