- [NEW] Menú de redefinició de tecles acabat

- [NEW] Les tecles es guarden al arxiu de config
This commit is contained in:
2024-07-09 09:41:53 +02:00
parent 4d91e86178
commit b6e9310a38
4 changed files with 72 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 627 B

After

Width:  |  Height:  |  Size: 649 B

View File

@@ -45,7 +45,10 @@ namespace config
void defineKey(const int which, const int key) void defineKey(const int which, const int key)
{ {
static const char* nomtecles[6] = {"keyup", "keydown", "keyleft", "keyright", "keyjump", "keypick"};
keys[which] = key; keys[which] = key;
char tmp[5];
file::setConfigValue(nomtecles[which], SDL_itoa(key, tmp, 10));
} }
const int getKey(const int which) const int getKey(const int which)

View File

@@ -8,7 +8,27 @@ namespace modules
{ {
namespace menu_tecles namespace menu_tecles
{ {
enum states { STATE_SELECTING, STATE_REDEFINING };
const char *nom_tecles[] = {"?", "?", "?", "?", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
"RETURN", "ESC", "BORRAR", "TAB", "ESPAI", "'", "j", "[", "]", "l", "?", "m", "k", "\\", ",", ".", "-", "BLOQMAYS", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
"PRNTSCR", "SCRLOCK", "PAUSE", "INSERT", "INICI", "REPAG", "SUPR", "FIN", "AVPAG", "CUR-DRETA", "CUR-ESQ", "CUR-AVALL", "CUR-AMUNT",
"NUM-LOCK", "NUM-DIV", "NUM-MUL", "NUM-MENYS", "NUM-SUM", "NUM-INTRO", "NUM-1", "NUM-2", "NUM-3", "NUM-4", "NUM-5", "NUM-6", "NUM-7", "NUM-8", "NUM-9", "NUM-0", "NUM-PUNT", "<", "MENU",
// 101 << -- >> 224 (if num>101 then num-=122)
"LCTRL", "LMAYUS", "LALT", "LGUI", "RCTRL", "RMAYUS", "RALT", "RGUI" };
int selected_option = MENU_TECLES_AMUNT; int selected_option = MENU_TECLES_AMUNT;
states state = STATE_SELECTING;
const char *getKeyName(const uint8_t key)
{
if (key-122>110) return nom_tecles[0];
if (key>101)
return nom_tecles[key-122];
else
return nom_tecles[key];
}
void init() void init()
{ {
@@ -16,6 +36,8 @@ namespace modules
} }
int loop() int loop()
{
if (state == STATE_SELECTING)
{ {
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return MENU_TECLES_TORNAR; return MENU_TECLES_TORNAR;
@@ -30,7 +52,17 @@ namespace modules
input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) {
//if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic(); //if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic();
//if (selected_option==MENU_AUDIO_SO) config::toggleSound(); //if (selected_option==MENU_AUDIO_SO) config::toggleSound();
if (selected_option==MENU_TECLES_TORNAR) return MENU_TECLES_TORNAR; if (selected_option==MENU_TECLES_TORNAR)
return MENU_TECLES_TORNAR;
else
state = STATE_REDEFINING;
}
} else {
const uint8_t key = input::getKeyPressed();
if (key != SDL_SCANCODE_UNKNOWN) {
if (key != SDL_SCANCODE_ESCAPE) config::defineKey(selected_option, key);
state = STATE_SELECTING;
}
} }
draw::cls(2); draw::cls(2);
@@ -44,14 +76,15 @@ namespace modules
for (int i=0; i<6; ++i) for (int i=0; i<6; ++i)
{ {
const bool selected = (i==selected_option); const bool selected = (i==selected_option);
draw::print2(selected?"fg":"de", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); draw::print2(selected?"fg":"de", 8, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
draw::print2(textos[i], 18, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); draw::print2(textos[i], 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
if (!selected || state == STATE_SELECTING) draw::print2(getKeyName(config::getKey(i)), 23, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
pos += selected?3:2; pos += selected?3:2;
} }
const bool selected = (selected_option==MENU_TECLES_TORNAR); const bool selected = (selected_option==MENU_TECLES_TORNAR);
draw::print2(selected?"fg":"de", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); draw::print2(selected?"fg":"de", 8, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
draw::print2("TORNAR", 18, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); draw::print2("TORNAR", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE);

View File

@@ -44,6 +44,13 @@ void loadConfig()
std::string txt_fullscreen = file::getConfigValue("fullscreen"); std::string txt_fullscreen = file::getConfigValue("fullscreen");
if (txt_fullscreen=="yes") fullscreen = true; if (txt_fullscreen=="yes") fullscreen = true;
static const char* nomtecles[6] = {"keyup", "keydown", "keyleft", "keyright", "keyjump", "keypick"};
for (int i=0; i<6; ++i)
{
const int value = SDL_atoi( file::getConfigValue(nomtecles[i]).c_str() );
if (value != 0) config::defineKey(i, value);
}
} }
void game::init() void game::init()