Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Ports To Configure Default Button Mappings #724

Merged
merged 10 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion cmake/cvars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ set(CVAR_GAME_OVERLAY_FONT "gOverlayFont" CACHE STRING "")
set(CVAR_MENU_BAR_OPEN "gOpenMenuBar" CACHE STRING "")
set(CVAR_PREFIX_CONTROLLERS "gControllers" CACHE STRING "")
set(CVAR_PREFIX_ADVANCED_RESOLUTION "gAdvancedResolution" CACHE STRING "")

set(LUS_DEFAULT_KB_MAPPING_A KbScancode::LUS_KB_X CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_B KbScancode::LUS_KB_C CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_L KbScancode::LUS_KB_E CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_R KbScancode::LUS_KB_R CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_Z KbScancode::LUS_KB_Z CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_START KbScancode::LUS_KB_SPACE CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_STICKUP KbScancode::LUS_KB_W CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_STICKDOWN KbScancode::LUS_KB_S CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_STICKLEFT KbScancode::LUS_KB_A CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_STICKRIGHT KbScancode::LUS_KB_D CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_CUP KbScancode::LUS_KB_ARROWKEY_UP CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_CDOWN KbScancode::LUS_KB_ARROWKEY_DOWN CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_CLEFT KbScancode::LUS_KB_ARROWKEY_LEFT CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_CRIGHT KbScancode::LUS_KB_ARROWKEY_RIGHT CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_DUP KbScancode::LUS_KB_T CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_DDOWN KbScancode::LUS_KB_G CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_DLEFT KbScancode::LUS_KB_F CACHE STRING "")
set(LUS_DEFAULT_KB_MAPPING_DRIGHT KbScancode::LUS_KB_H CACHE STRING "")

add_compile_definitions(
CVAR_VSYNC_ENABLED="${CVAR_VSYNC_ENABLED}"
CVAR_Z_FIGHTING_MODE="${CVAR_Z_FIGHTING_MODE}"
Expand All @@ -43,4 +63,23 @@ add_compile_definitions(
CVAR_MENU_BAR_OPEN="${CVAR_MENU_BAR_OPEN}"
CVAR_PREFIX_CONTROLLERS="${CVAR_PREFIX_CONTROLLERS}"
CVAR_PREFIX_ADVANCED_RESOLUTION="${CVAR_PREFIX_ADVANCED_RESOLUTION}"
)

MegaMech marked this conversation as resolved.
Show resolved Hide resolved
LUS_DEFAULT_KB_MAPPING_A=${LUS_DEFAULT_KB_MAPPING_A}
LUS_DEFAULT_KB_MAPPING_B=${LUS_DEFAULT_KB_MAPPING_B}
LUS_DEFAULT_KB_MAPPING_L=${LUS_DEFAULT_KB_MAPPING_L}
LUS_DEFAULT_KB_MAPPING_R=${LUS_DEFAULT_KB_MAPPING_R}
LUS_DEFAULT_KB_MAPPING_Z=${LUS_DEFAULT_KB_MAPPING_Z}
LUS_DEFAULT_KB_MAPPING_START=${LUS_DEFAULT_KB_MAPPING_START}
LUS_DEFAULT_KB_MAPPING_STICKUP=${LUS_DEFAULT_KB_MAPPING_STICKUP}
LUS_DEFAULT_KB_MAPPING_STICKDOWN=${LUS_DEFAULT_KB_MAPPING_STICKDOWN}
LUS_DEFAULT_KB_MAPPING_STICKLEFT=${LUS_DEFAULT_KB_MAPPING_STICKLEFT}
LUS_DEFAULT_KB_MAPPING_STICKRIGHT=${LUS_DEFAULT_KB_MAPPING_STICKRIGHT}
LUS_DEFAULT_KB_MAPPING_CUP=${LUS_DEFAULT_KB_MAPPING_CUP}
LUS_DEFAULT_KB_MAPPING_CDOWN=${LUS_DEFAULT_KB_MAPPING_CDOWN}
LUS_DEFAULT_KB_MAPPING_CLEFT=${LUS_DEFAULT_KB_MAPPING_CLEFT}
LUS_DEFAULT_KB_MAPPING_CRIGHT=${LUS_DEFAULT_KB_MAPPING_CRIGHT}
LUS_DEFAULT_KB_MAPPING_DUP=${LUS_DEFAULT_KB_MAPPING_DUP}
LUS_DEFAULT_KB_MAPPING_DDOWN=${LUS_DEFAULT_KB_MAPPING_DDOWN}
LUS_DEFAULT_KB_MAPPING_DLEFT=${LUS_DEFAULT_KB_MAPPING_DLEFT}
LUS_DEFAULT_KB_MAPPING_DRIGHT=${LUS_DEFAULT_KB_MAPPING_DRIGHT}
)
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn
std::vector<std::shared_ptr<ControllerAxisDirectionMapping>>
AxisDirectionMappingFactory::CreateDefaultKeyboardAxisDirectionMappings(uint8_t portIndex, Stick stick) {
std::vector<std::shared_ptr<ControllerAxisDirectionMapping>> mappings = {
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, LEFT, LUS_KB_A),
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, RIGHT, LUS_KB_D),
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, UP, LUS_KB_W),
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, DOWN, LUS_KB_S)
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, LEFT, LUS_DEFAULT_KB_MAPPING_STICKLEFT),
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, RIGHT, LUS_DEFAULT_KB_MAPPING_STICKRIGHT),
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, UP, LUS_DEFAULT_KB_MAPPING_STICKUP),
std::make_shared<KeyboardKeyToAxisDirectionMapping>(portIndex, stick, DOWN, LUS_DEFAULT_KB_MAPPING_STICKDOWN)
};

return mappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,54 +75,60 @@ ButtonMappingFactory::CreateDefaultKeyboardButtonMappings(uint8_t portIndex, CON

switch (bitmask) {
case BTN_A:
mappings.push_back(std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_A, KbScancode::LUS_KB_X));
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_A, LUS_DEFAULT_KB_MAPPING_A));
break;
case BTN_B:
mappings.push_back(std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_B, KbScancode::LUS_KB_C));
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_B, LUS_DEFAULT_KB_MAPPING_B));
break;
case BTN_L:
mappings.push_back(std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_L, KbScancode::LUS_KB_E));
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_L, LUS_DEFAULT_KB_MAPPING_L));
break;
case BTN_R:
mappings.push_back(std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_R, KbScancode::LUS_KB_R));
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_R, LUS_DEFAULT_KB_MAPPING_R));
break;
case BTN_Z:
mappings.push_back(std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_Z, KbScancode::LUS_KB_Z));
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_Z, LUS_DEFAULT_KB_MAPPING_Z));
break;
case BTN_START:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_START, KbScancode::LUS_KB_SPACE));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_START, LUS_DEFAULT_KB_MAPPING_START));
break;
case BTN_CUP:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CUP, KbScancode::LUS_KB_ARROWKEY_UP));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CUP, LUS_DEFAULT_KB_MAPPING_CUP));
break;
case BTN_CDOWN:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CDOWN, KbScancode::LUS_KB_ARROWKEY_DOWN));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CDOWN, LUS_DEFAULT_KB_MAPPING_CDOWN));
break;
case BTN_CLEFT:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CLEFT, KbScancode::LUS_KB_ARROWKEY_LEFT));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CLEFT, LUS_DEFAULT_KB_MAPPING_CLEFT));
break;
case BTN_CRIGHT:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CRIGHT, KbScancode::LUS_KB_ARROWKEY_RIGHT));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_CRIGHT, LUS_DEFAULT_KB_MAPPING_CRIGHT));
break;
case BTN_DUP:
mappings.push_back(std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DUP, KbScancode::LUS_KB_T));
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DUP, LUS_DEFAULT_KB_MAPPING_DUP));
break;
case BTN_DDOWN:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DDOWN, KbScancode::LUS_KB_G));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DDOWN, LUS_DEFAULT_KB_MAPPING_DDOWN));
break;
case BTN_DLEFT:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DLEFT, KbScancode::LUS_KB_F));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DLEFT, LUS_DEFAULT_KB_MAPPING_DLEFT));
break;
case BTN_DRIGHT:
mappings.push_back(
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DRIGHT, KbScancode::LUS_KB_H));
std::make_shared<KeyboardKeyToButtonMapping>(portIndex, BTN_DRIGHT, LUS_DEFAULT_KB_MAPPING_DRIGHT));
break;
}

Expand Down
Loading