aboutsummaryrefslogtreecommitdiff
path: root/source/ui/elements/game/controls
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/ui/elements/game/controls
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/ui/elements/game/controls')
-rw-r--r--source/ui/elements/game/controls/ControlTips.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/source/ui/elements/game/controls/ControlTips.cs b/source/ui/elements/game/controls/ControlTips.cs
new file mode 100644
index 0000000..904b3cc
--- /dev/null
+++ b/source/ui/elements/game/controls/ControlTips.cs
@@ -0,0 +1,51 @@
+using System.Collections.Generic;
+using Celesteia.Game.Input;
+using Celesteia.Resources;
+using Celesteia.UI.Properties;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+
+namespace Celesteia.UI.Elements.Game.Controls {
+ public class ControlTips : Container {
+ private TextProperties _properties;
+ private Dictionary<Keys, string> _keyboardControls = new Dictionary<Keys, string>();
+ private List<string> _lines = new List<string>();
+ private List<Label> _labels = new List<Label>();
+
+ public ControlTips(Rect rect) : base(rect) {
+ _properties = new TextProperties()
+ .SetColor(Color.White)
+ .SetFont(ResourceManager.Fonts.DEFAULT)
+ .SetFontSize(12f)
+ .SetTextAlignment(TextAlignment.Left);
+ }
+
+ private int lineHeight = 16;
+ private Rect LineRect(int line) => new Rect(
+ AbsoluteUnit.WithValue(0f),
+ AbsoluteUnit.WithValue(line * lineHeight),
+ new RelativeUnit(1f, GetRect(), RelativeUnit.Orientation.Horizontal),
+ AbsoluteUnit.WithValue(lineHeight)
+ );
+
+ private void UpdateLines() {
+ _labels.Clear();
+
+ foreach (Keys keys in _keyboardControls.Keys) _lines.Add($"[{keys}] {_keyboardControls[keys]}");
+
+ for (int i = 0; i < _lines.Count; i++) {
+ Label label = new Label(LineRect(i - (_lines.Count / 2)))
+ .SetTextProperties(_properties)
+ .SetText(_lines[i]);
+ label.SetParent(this);
+ _labels.Add(label);
+ }
+ }
+
+ public override void Draw(SpriteBatch spriteBatch)
+ {
+ foreach (Label l in _labels) l.Draw(spriteBatch);
+ }
+ }
+} \ No newline at end of file