Skip to content

Commit

Permalink
Add support for button glyph display
Browse files Browse the repository at this point in the history
This adds a function that converts an action (such as interacting
in-game) to the corresponding button text ("ENTER", "E") or button
glyph (PlayStation triangle, Steam Deck Y, etc). This function
currently only gives the existing ENTERs or Es, because I don't know
how best to detect controller usage, or whether the game is running on
a Steam Deck, or what buttons need to be displayed there. Still, it
should now be really easy to adapt the rendering of keyboard keys to
consoles, controllers, or rebound keys.

To identify the actions that currently need to be displayed, this
commit also adds the initial enums for action sets as described by
Ethan in a comment in TerryCavanagh#834 (Jan 18, 2022).
  • Loading branch information
Daaaav committed Mar 17, 2023
1 parent acfa085 commit 0b66ac9
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 46 deletions.
1 change: 1 addition & 0 deletions desktop_version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ endif()
set(VVV_SRC
src/BinaryBlob.cpp
src/BlockV.cpp
src/ButtonGlyphs.cpp
src/CWrappers.cpp
src/Ent.cpp
src/Entity.cpp
Expand Down
9 changes: 6 additions & 3 deletions desktop_version/lang/ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@
<string english="The levels path is:" translation="El camí dels nivells és:" explanation="" max="40"/>
<string english="[ Press ACTION to Start ]" translation="[ Prem Acció per a començar ]" explanation="title screen" max="38*2"/>
<string english="ACTION = Space, Z, or V" translation="Acció = Espai, Z o V" explanation="title screen" max="38*3"/>
<string english="[Press ENTER to return to editor]" translation="[Prem Retorn per a tornar a l’editor]" explanation="`to editor` is sorta redundant" max="40"/>
<string english="[Press ENTER to return to editor]" translation="[Prem Retorn per a tornar a l’editor]" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to return to editor]" translation="" explanation="`to editor` is sorta redundant" max="40"/>
<string english="- Press ACTION to advance text -" translation="- Prem Acció per a avançar el text -" explanation="to dismiss a textbox" max="40"/>
<string english="Press ACTION to continue" translation="Prem Acció per a continuar" explanation="" max="34"/>
<string english="Current Time" translation="Temps actual" explanation="super gravitron, stopwatch time" max="20"/>
Expand All @@ -434,7 +435,8 @@
<string english="All Trophies collected!" translation="Has obtingut tots els trofeus!" explanation="" max="38*2"/>
<string english="New Record!" translation="Nou rècord!" explanation="" max="20"/>
<string english="New Trophy!" translation="Nou trofeu!" explanation="" max="20"/>
<string english="[Press ENTER to stop]" translation="[Prem Retorn per a aturar-lo]" explanation="stop super gravitron" max="40"/>
<string english="[Press ENTER to stop]" translation="[Prem Retorn per a aturar-lo]" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to stop]" translation="" explanation="stop super gravitron" max="40"/>
<string english="SUPER GRAVITRON" translation="SUPERGRAVITRÓ" explanation="" max="20"/>
<string english="SUPER GRAVITRON HIGHSCORE" translation="PUNTUACIÓ MÀXIMA AL SUPERGRAVITRÓ" explanation="" max="38*4"/>
<string english="MAP" translation="MAPA" explanation="in-game menu" max="8"/>
Expand Down Expand Up @@ -637,7 +639,8 @@
<string english="Game Saved" translation="S’ha desat la partida" explanation="" max="30"/>
<string english="Press arrow keys or WASD to move" translation="Prem les tecles de fletxa o WASD per a moure’t" explanation="" max="32*2"/>
<string english="Press ACTION to flip" translation="Prem Acció per a invertir-te" explanation="" max="32*3"/>
<string english="Press ENTER to view map and quicksave" translation="Prem Retorn per a veure el mapa|i desar ràpidament" explanation="" max="32*3"/>
<string english="Press ENTER to view map and quicksave" translation="Prem Retorn per a veure el mapa|i desar ràpidament" explanation="***OUTDATED***" max="32*3"/>
<string english="Press {button} to view map and quicksave" translation="" explanation="" max="32*3"/>
<string english="If you prefer, you can press UP or DOWN instead of ACTION to flip." translation="Si ho prefereixes, pots prémer ↑ o ↓ en lloc d’Acció per a invertir-te." explanation="" max="34*3"/>
<string english="Help! Can anyone hear this message?" translation="Ajuda! Algú sent aquest missatge?" explanation="Violet speaking via Comms Relay" max="25*4"/>
<string english="Verdigris? Are you out there? Are you ok?" translation="Verdet? Ets allà fora? Estàs bé?" explanation="Violet speaking via Comms Relay" max="25*4"/>
Expand Down
9 changes: 6 additions & 3 deletions desktop_version/lang/en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@
<string english="The levels path is:" translation="" explanation="" max="40"/>
<string english="[ Press ACTION to Start ]" translation="" explanation="title screen" max="38*2"/>
<string english="ACTION = Space, Z, or V" translation="" explanation="title screen" max="38*3"/>
<string english="[Press ENTER to return to editor]" translation="" explanation="`to editor` is sorta redundant" max="40"/>
<string english="[Press ENTER to return to editor]" translation="" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to return to editor]" translation="" explanation="`to editor` is sorta redundant" max="40"/>
<string english="- Press ACTION to advance text -" translation="" explanation="to dismiss a textbox" max="40"/>
<string english="Press ACTION to continue" translation="" explanation="" max="34"/>
<string english="Current Time" translation="" explanation="super gravitron, stopwatch time" max="20"/>
Expand All @@ -434,7 +435,8 @@
<string english="All Trophies collected!" translation="" explanation="" max="38*2"/>
<string english="New Record!" translation="" explanation="" max="20"/>
<string english="New Trophy!" translation="" explanation="" max="20"/>
<string english="[Press ENTER to stop]" translation="" explanation="stop super gravitron" max="40"/>
<string english="[Press ENTER to stop]" translation="" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to stop]" translation="" explanation="stop super gravitron" max="40"/>
<string english="SUPER GRAVITRON" translation="" explanation="" max="20"/>
<string english="SUPER GRAVITRON HIGHSCORE" translation="" explanation="" max="38*4"/>
<string english="MAP" translation="" explanation="in-game menu" max="8"/>
Expand Down Expand Up @@ -637,7 +639,8 @@
<string english="Game Saved" translation="" explanation="" max="30"/>
<string english="Press arrow keys or WASD to move" translation="" explanation="" max="32*2"/>
<string english="Press ACTION to flip" translation="" explanation="" max="32*3"/>
<string english="Press ENTER to view map and quicksave" translation="" explanation="" max="32*3"/>
<string english="Press ENTER to view map and quicksave" translation="" explanation="***OUTDATED***" max="32*3"/>
<string english="Press {button} to view map and quicksave" translation="" explanation="" max="32*3"/>
<string english="If you prefer, you can press UP or DOWN instead of ACTION to flip." translation="" explanation="" max="34*3"/>
<string english="Help! Can anyone hear this message?" translation="" explanation="Violet speaking via Comms Relay" max="25*4"/>
<string english="Verdigris? Are you out there? Are you ok?" translation="" explanation="Violet speaking via Comms Relay" max="25*4"/>
Expand Down
3 changes: 2 additions & 1 deletion desktop_version/lang/eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
<string english="All Trophies collected!" translation="Ĉiuj trofeoj kolektiĝis!" explanation="" max="38*2"/>
<string english="New Record!" translation="Nova rekordo!" explanation="" max="20"/>
<string english="New Trophy!" translation="Nova trofeo!" explanation="" max="20"/>
<string english="[Press ENTER to stop]" translation="[Premu ENTER por eliri]" explanation="stop super gravitron" max="40"/>
<string english="[Press ENTER to stop]" translation="[Premu ENTER por eliri]" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to stop]" translation="" explanation="stop super gravitron" max="40"/>
<string english="SUPER GRAVITRON" translation="SUPERGRAVITRONO" explanation="" max="20"/>
<string english="SUPER GRAVITRON HIGHSCORE" translation="ALTPOENTARO DE SUPERGRAVITRONO" explanation="" max="38*4"/>
<string english="MAP" translation="MAPO" explanation="in-game menu" max="8"/>
Expand Down
9 changes: 6 additions & 3 deletions desktop_version/lang/nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@
<string english="The levels path is:" translation="Het levelspad is:" explanation="" max="40"/>
<string english="[ Press ACTION to Start ]" translation="[ Druk op ACTIE om te beginnen ]" explanation="title screen" max="38*2"/>
<string english="ACTION = Space, Z, or V" translation="ACTIE = Spatie, Z, of V" explanation="title screen" max="38*3"/>
<string english="[Press ENTER to return to editor]" translation="[Druk op ENTER om terug te gaan]" explanation="`to editor` is sorta redundant" max="40"/>
<string english="[Press ENTER to return to editor]" translation="[Druk op ENTER om terug te gaan]" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to return to editor]" translation="[Druk op {button} om terug te gaan]" explanation="`to editor` is sorta redundant" max="40"/>
<string english="- Press ACTION to advance text -" translation="- Druk op ACTIE om verder te gaan -" explanation="to dismiss a textbox" max="40"/>
<string english="Press ACTION to continue" translation="Druk op ACTIE om verder te gaan" explanation="" max="34"/>
<string english="Current Time" translation="Huidige tijd" explanation="super gravitron, stopwatch time" max="20"/>
Expand All @@ -434,7 +435,8 @@
<string english="All Trophies collected!" translation="Alle trofeeën behaald!" explanation="" max="38*2"/>
<string english="New Record!" translation="Nieuw record!" explanation="" max="20"/>
<string english="New Trophy!" translation="Nieuwe trofee!" explanation="" max="20"/>
<string english="[Press ENTER to stop]" translation="[Druk op ENTER om te stoppen]" explanation="stop super gravitron" max="40"/>
<string english="[Press ENTER to stop]" translation="[Druk op ENTER om te stoppen]" explanation="***OUTDATED***" max="40"/>
<string english="[Press {button} to stop]" translation="[Druk op {button} om te stoppen]" explanation="stop super gravitron" max="40"/>
<string english="SUPER GRAVITRON" translation="SUPERGRAVITRON" explanation="" max="20"/>
<string english="SUPER GRAVITRON HIGHSCORE" translation="HIGHSCORE SUPERGRAVITRON" explanation="" max="38*4"/>
<string english="MAP" translation="KAART" explanation="in-game menu" max="8"/>
Expand Down Expand Up @@ -637,7 +639,8 @@
<string english="Game Saved" translation="Spel opgeslagen" explanation="" max="30"/>
<string english="Press arrow keys or WASD to move" translation="Druk op de pijltjestoetsen of WASD om te bewegen" explanation="" max="32*2"/>
<string english="Press ACTION to flip" translation="Druk op ACTIE om je zwaartekracht om te keren" explanation="" max="32*3"/>
<string english="Press ENTER to view map and quicksave" translation="Druk op ENTER om de kaart te bekijken en om op te slaan" explanation="" max="32*3"/>
<string english="Press ENTER to view map and quicksave" translation="Druk op ENTER om de kaart te bekijken en om op te slaan" explanation="***OUTDATED***" max="32*3"/>
<string english="Press {button} to view map and quicksave" translation="Druk op {button} om de kaart te bekijken en om op te slaan" explanation="" max="32*3"/>
<string english="If you prefer, you can press UP or DOWN instead of ACTION to flip." translation="Je kunt ook op OMHOOG of OMLAAG drukken in plaats van ACTIE om je zwaartekracht om te keren." explanation="" max="34*3"/>
<string english="Help! Can anyone hear this message?" translation="Help! Kan iemand dit horen?" explanation="Violet speaking via Comms Relay" max="25*4"/>
<string english="Verdigris? Are you out there? Are you ok?" translation="Verdigris? Ben je daar ergens? Ben je in orde?" explanation="Violet speaking via Comms Relay" max="25*4"/>
Expand Down
80 changes: 80 additions & 0 deletions desktop_version/src/ActionSets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* For now, this isn't really a foundation for action sets yet; button glyphs
* just need to be able to identify actions that are printed in text like
* "Press ENTER to teleport". Thus, this currently ONLY contains identifiers
* for the actions that button glyphs are needed for.
*
* Based on this comment:
* https://github.com/TerryCavanagh/VVVVVV/issues/834#issuecomment-1015692161
*/


#ifndef ACTIONSETS_H
#define ACTIONSETS_H


#ifdef __cplusplus
extern "C"
{
#endif


/*----------------------------------------*
* List of all action sets (all "states") *
*----------------------------------------*/
typedef enum
{
//ActionSet_Global,
//ActionSet_Menu,
ActionSet_InGame
//ActionSet_Editor
}
ActionSet;


/*----------------------------------------------------------*
* An enum for each actionset, with the actions in that set *
*----------------------------------------------------------*/
/*
typedef enum
{
Action_Global_Mute,
Action_Global_MuteMusic
}
Action_Global;
*/

typedef enum
{
Action_InGame_Interact,
Action_InGame_Map
}
Action_InGame;

/*
typedef enum
{
//Action_Editor_PrevTool,
//Action_Editor_NextTool
}
Action_Editor;
*/


/*-----------------------------------------*
* A union to represent any actionset enum *
*-----------------------------------------*/
typedef union
{
int intval;
//Action_Global Global;
Action_InGame InGame;
//Action_Editor Editor;
}
Action;


#ifdef __cplusplus
} // extern "C"
#endif

#endif // ACTIONSETS_H
139 changes: 139 additions & 0 deletions desktop_version/src/ButtonGlyphs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "ButtonGlyphs.h"

#include <SDL.h>

#include "Game.h"
#include "Localization.h"
#include "UTF8.h"

extern "C"
{

typedef enum
{
GLYPH_NINTENDO_DECK_A, // Note that for the Deck, the icons are same as Nintendo but the layout is the same as Xbox
GLYPH_NINTENDO_DECK_B,
GLYPH_NINTENDO_DECK_X,
GLYPH_NINTENDO_DECK_Y,
GLYPH_NINTENDO_PLUS,
GLYPH_NINTENDO_MINUS,
GLYPH_NINTENDO_L,
GLYPH_NINTENDO_R,
GLYPH_NINTENDO_ZL,
GLYPH_NINTENDO_ZR,
GLYPH_NINTENDO_XBOX_LSTICK,
GLYPH_NINTENDO_XBOX_RSTICK,
GLYPH_NINTENDO_SL,
GLYPH_NINTENDO_SR,
GLYPH_GENERIC_L,
GLYPH_GENERIC_R,

GLYPH_PLAYSTATION_CIRCLE,
GLYPH_PLAYSTATION_CROSS,
GLYPH_PLAYSTATION_TRIANGLE,
GLYPH_PLAYSTATION_SQUARE,
GLYPH_PLAYSTATION_START,
GLYPH_PLAYSTATION_OPTIONS,
GLYPH_PLAYSTATION_DECK_L1,
GLYPH_PLAYSTATION_DECK_R1,
GLYPH_PLAYSTATION_DECK_L2,
GLYPH_PLAYSTATION_DECK_R2,
GLYPH_PLAYSTATION_DECK_L3,
GLYPH_PLAYSTATION_DECK_R3,
GLYPH_DECK_L4,
GLYPH_DECK_R4,
GLYPH_DECK_L5,
GLYPH_DECK_R5,

GLYPH_XBOX_B,
GLYPH_XBOX_A,
GLYPH_XBOX_Y,
GLYPH_XBOX_X,
GLYPH_XBOX_DECK_VIEW,
GLYPH_XBOX_DECK_MENU,
GLYPH_XBOX_LB,
GLYPH_XBOX_RB,
GLYPH_XBOX_LT,
GLYPH_XBOX_RT,
GLYPH_NINTENDO_GENERIC_ACTIONRIGHT,
GLYPH_NINTENDO_GENERIC_ACTIONDOWN,
GLYPH_NINTENDO_GENERIC_ACTIONUP,
GLYPH_NINTENDO_GENERIC_ACTIONLEFT,
GLYPH_GENERIC_STICK,
GLYPH_GENERIC_UNKNOWN,

GLYPH_TOTAL
}
ButtonGlyphKey;

static char glyph[GLYPH_TOTAL][5];

void BUTTONGLYPHS_init(void)
{
/* Set glyph array to strings for all the button glyph codepoints (U+EBxx) */
for (int i = 0; i < GLYPH_TOTAL; i++)
{
SDL_strlcpy(glyph[i], UTF8_encode(0xEB00+i).bytes, sizeof(glyph[i]));
}
}

bool BUTTONGLYPHS_keyboard_is_available(void)
{
/* Returns true if it makes sense to show button hints that are only available
* on keyboards (like press M to mute), false if we're on a console. */
return true;
}

bool BUTTONGLYPHS_keyboard_is_active(void)
{
/* Returns true if, not only do we have a keyboard available, but it's also the
* active input method. (So, show keyboard keys, if false, show controller glyphs) */
return true;
}

const char* BUTTONGLYPHS_get_wasd_text(void)
{
/* Returns the string to use in Welcome Aboard */
if (BUTTONGLYPHS_keyboard_is_active())
{
return loc::gettext("Press arrow keys or WASD to move");
}
return loc::gettext("Press left/right to move");
}

const char* BUTTONGLYPHS_get_button(const ActionSet actionset, const Action action)
{
/* Given a specific action (like INTERACT in-game),
* return either a (localized) keyboard key string like "ENTER" or "E",
* or a controller button glyph from the table above like glyph[GLYPH_XBOX_Y],
* to fill into strings like "Press {button} to activate terminal". */
switch (actionset)
{
case ActionSet_InGame:
switch (action.InGame)
{
case Action_InGame_Interact:
if (false) // TODO
{
return glyph[GLYPH_PLAYSTATION_TRIANGLE];
}
if (game.separate_interact)
{
return "E";
}
return loc::gettext("ENTER");
case Action_InGame_Map:
if (false) // TODO
{
return glyph[GLYPH_XBOX_DECK_VIEW];
}
return loc::gettext("ENTER");
}
break;
}

SDL_assert(0 && "Trying to get label/glyph for unknown action!");
return glyph[GLYPH_GENERIC_UNKNOWN];
}

} // extern "C"
24 changes: 24 additions & 0 deletions desktop_version/src/ButtonGlyphs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef BUTTONGLYPHS_H
#define BUTTONGLYPHS_H

#include <stdbool.h>

#include "ActionSets.h"

#ifdef __cplusplus
extern "C"
{
#endif

void BUTTONGLYPHS_init(void);

bool BUTTONGLYPHS_keyboard_is_available(void);
bool BUTTONGLYPHS_keyboard_is_active(void);
const char* BUTTONGLYPHS_get_wasd_text(void);
const char* BUTTONGLYPHS_get_button(ActionSet actionset, Action action);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // BUTTONGLYPHS_H
Loading

0 comments on commit 0b66ac9

Please sign in to comment.