feat: show keyboard keys or the controller's own buttons in the hint bar
The hint bar always named Xbox buttons, so someone at a keyboard was told to press buttons they did not have, and owners of other pads got the wrong letters. Hints now name an action, and the keys or button icons come from the input used last: keyboard, or an Xbox, PlayStation, Switch or Steam Deck controller. Behind Steam, every pad is Steam's virtual one. remus reads the file Steam names in SteamVirtualGamepadInfo to find the physical controller, matching the slot in the pad's name, as SDL does. Icons are Kenney's Input Prompts (CC0), with the licence beside them.
This commit is contained in:
+10
-27
@@ -42,7 +42,7 @@ export struct Header {
|
||||
round: bool,
|
||||
}
|
||||
|
||||
export struct Hint { key: string, label: string }
|
||||
export struct Hint { icons: [image], label: string }
|
||||
|
||||
export global Theme {
|
||||
in-out property <float> s: 1.0;
|
||||
@@ -556,14 +556,6 @@ component HintBar inherits Rectangle {
|
||||
in property <[Hint]> hints;
|
||||
in property <string> version;
|
||||
|
||||
pure function key-color(k: string) -> color {
|
||||
if (k == "A") { return #3fb950; }
|
||||
if (k == "B") { return #f0605d; }
|
||||
if (k == "X") { return #4d8ff7; }
|
||||
if (k == "Y") { return #e3b341; }
|
||||
return Theme.line;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: 28px * Theme.s;
|
||||
padding-right: 28px * Theme.s;
|
||||
@@ -572,24 +564,15 @@ component HintBar inherits Rectangle {
|
||||
|
||||
for h in root.hints: HorizontalLayout {
|
||||
spacing: 9px * Theme.s;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
min-width: 26px * Theme.s;
|
||||
height: 26px * Theme.s;
|
||||
border-radius: 13px * Theme.s;
|
||||
background: root.key-color(h.key);
|
||||
HorizontalLayout {
|
||||
padding-left: 8px * Theme.s;
|
||||
padding-right: 8px * Theme.s;
|
||||
Text {
|
||||
text: h.key;
|
||||
font-size: 12px * Theme.s;
|
||||
font-weight: 800;
|
||||
color: #ffffff;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 3px * Theme.s;
|
||||
for icon in h.icons: VerticalLayout {
|
||||
alignment: center;
|
||||
Image {
|
||||
source: icon;
|
||||
height: 30px * Theme.s;
|
||||
// Keys such as Space are wider than a button.
|
||||
width: self.height * icon.width / max(1, icon.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user