enum e_remap_keys{
REMAP_KEYS_NONE = 0,
REMAP_KEYS_SHIFT = 0x1,
REMAP_KEYS_CTRL = 0x2,
REMAP_KEYS_CTRL_SHIFT = REMAP_KEYS_SHIFT | REMAP_KEYS_CTRL,
REMAP_KEYS_COUNT = 4,
};
struct remapped {
const sys_u64* _events;
sys_u64 _event_count;
const struct msg_WINDOWMSG_KB_VIRTUAL* _msg;
};
struct key_remapper {
WC_INLINE void init() {
for ( sys_u8 i = 0; i < REMAP_KEYS_COUNT; i++ ) {
_virtual_key_remap[i].resize( VIRTUAL_N_KEYS );
}
}
WC_INLINE remapped virtual_key_remap( const struct msg_WINDOWMSG_KB_VIRTUAL* msg ) {
sys_u64 modifier_keys = REMAP_KEYS_NONE;
remapped ret = {};
if ( window_is_virtual_key_down( VIRTUAL_LSHIFT ) ||
window_is_virtual_key_down( VIRTUAL_RSHIFT ) ) {
modifier_keys |= REMAP_KEYS_SHIFT;
}
if ( window_is_virtual_key_down( VIRTUAL_LCONTROL ) ||
window_is_virtual_key_down( VIRTUAL_RCONTROL ) ) {
modifier_keys |= REMAP_KEYS_CTRL;
}
ret._event_count += _virtual_key_remap[modifier_keys][msg->_key].size();
ret._events = _virtual_key_remap[modifier_keys][msg->_key].begin();
ret._msg = msg;
return ret;
}
static enum e_remap_keys calc_modifier_keys( const char*& in ) {
sys_u64 ret = 0;
if ( sys_strbegin( in, "CTRL_" ) ) {
ret |= REMAP_KEYS_CTRL;
in += sys_strlen( "CTRL_" );
}
if ( sys_strbegin( in, "SHIFT_" ) ) {
ret |= REMAP_KEYS_SHIFT;
in += sys_strlen( "SHIFT_" );
}
return static_cast<e_remap_keys>( ret );
}
static sys_u64 write_string( const sys_u64 compound, char* buf, sys_u64 buf_size ) {
return write_string( static_cast<window_virtual_key>( static_cast<sys_u32>( compound ) ),
static_cast<e_remap_keys>( compound >> 32 ),
buf,
buf_size );
}
static sys_u64 write_string( const window_virtual_key key, const e_remap_keys mod, char* buf, sys_u64 buf_size ) {
sys_u64 written = 0;
if ( mod & REMAP_KEYS_CTRL ) {
written += sys_snprintf( buf + written, buf_size - written, "CTRL_" );
}
if ( mod & REMAP_KEYS_SHIFT ) {
written += sys_snprintf( buf + written, buf_size - written, "SHIFT_" );
}
written += sys_snprintf( buf + written, buf_size - written, window_virtual_key_strings[key] );
return written;
}
static sys_u64 to_compound( const window_virtual_key key, const e_remap_keys mod ) {
return sys_u64( key ) | ( sys_u64( mod ) << 32 );
}
array<warpcore::hybrid_array<sys_u64, 4>> _virtual_key_remap[REMAP_KEYS_COUNT];
struct remappable_key_info {
const char* _localization_str;
wc_tag _event_tag;
const char* _command_option_name;
};
static const remappable_key_info remapped_keys[] = {
{ "OPTION_KEY_PAUSE", GAME_INPUT_SPEED_PAUSE, "gamemedia-key-pause", },
{ "OPTION_KEY_SPEED1", GAME_INPUT_SPEED_PLAY, "gamemedia-key-speed1", },
{ "OPTION_KEY_SPEED2", GAME_INPUT_SPEED_FAST, "gamemedia-key-speed2", },
{ "OPTION_KEY_SPEED3", GAME_INPUT_SPEED_FASTER, "gamemedia-key-speed3", },
{ "OPTION_COMMAND_CANCEL", GAME_INPUT_COMMAND_CANCEL, "gamemedia-key-command-cancel", },
{ "OPTION_COMMAND_MINE", GAME_INPUT_COMMAND_MINE, "gamemedia-key-command-mine", },
{ "OPTION_COMMAND_PLACE_TILE", GAME_INPUT_COMMAND_PLACE_TILE, "gamemedia-key-command-place-tile", },
{ "OPTION_COMMAND_BUILD_INFRASTRUCTURE", GAME_INPUT_COMMAND_BUILD_INFRASTRUCTURE, "gamemedia-key-command-infrastructure",},
{ "OPTION_COMMAND_BUILD_ROOM", GAME_INPUT_COMMAND_BUILD_ROOM, "gamemedia-key-command-room", },
{ "OPTION_COMMAND_DESTROY", GAME_INPUT_COMMAND_DESTROY, "gamemedia-key-command-destroy", },
{ "OPTION_COMMAND_MOVE_TO", GAME_INPUT_COMMAND_MOVE_TO, "gamemedia-key-command-move-to", },
{ "OPTION_COMMAND_ATTACK", GAME_INPUT_COMMAND_ATTACK, "gamemedia-key-command-attack", },
{ "OPTION_COMMAND_SET_PRIO", GAME_INPUT_COMMAND_SET_PRIO, "gamemedia-key-command-set-prio", },
{ "OPTION_WINDOW_DWARFELOPEDIA", GAME_INPUT_WINDOW_DWARFELOPEDIA, "gamemedia-key-dwarfelopedia", },
{ "OPTION_WINDOW_OVERWORLD", GAME_INPUT_WINDOW_OVERWORLD, "gamemedia-key-overworld", },
{ "OPTION_WINDOW_RESEARCH", GAME_INPUT_WINDOW_RESEARCH, "gamemedia-key-research", },
{ "OPTION_WINDOW_LOGBOOK", GAME_INPUT_WINDOW_LOGBOOK, "gamemedia-key-logbook", },
{ "OPTION_WINDOW_LEDGER", GAME_INPUT_WINDOW_LEDGER, "gamemedia-key-ledger", },
{ "OPTION_WINDOW_JOBBROKER", GAME_INPUT_WINDOW_JOB_BROKER, "gamemedia-key-jobbroker", },
{ "OPTION_WINDOW_RECRUITMENT", GAME_INPUT_WINDOW_RECRUITMENT, "gamemedia-key-recruitment", },
{ "OPTION_CAMERA_UP_0", GAME_INPUT_CAMERA_UP_0, "gamemedia-key-camera-up-0", },
{ "OPTION_CAMERA_UP_1", GAME_INPUT_CAMERA_UP_1, "gamemedia-key-camera-up-1", },
{ "OPTION_CAMERA_DOWN_0", GAME_INPUT_CAMERA_DOWN_0, "gamemedia-key-camera-down-0", },
{ "OPTION_CAMERA_DOWN_1", GAME_INPUT_CAMERA_DOWN_1, "gamemedia-key-camera-down-1", },
{ "OPTION_CAMERA_LEFT_0", GAME_INPUT_CAMERA_LEFT_0, "gamemedia-key-camera-left-0", },
{ "OPTION_CAMERA_LEFT_1", GAME_INPUT_CAMERA_LEFT_1, "gamemedia-key-camera-left-1", },
{ "OPTION_CAMERA_RIGHT_0", GAME_INPUT_CAMERA_RIGHT_0, "gamemedia-key-camera-right-0", },
{ "OPTION_CAMERA_RIGHT_1", GAME_INPUT_CAMERA_RIGHT_1, "gamemedia-key-camera-right-1", },
{ "OPTION_SCREENSHOT", GAME_INPUT_SCREENSHOT, "gamemedia-key-screenshot", },
{ "OPTION_SCREENSHOT_WORLD", GAME_INPUT_SCREENSHOT_WORLD, "gamemedia-key-screenshot-world", },
{ "OPTION_SCREENSHOT_UI", GAME_INPUT_SCREENSHOT_UI, "gamemedia-key-screenshot-ui", },
};
static void
init_key_remapper( key_remapper& kr, const localization_manager& lm ) {
kr.init();
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_ESCAPE].push( GAME_INPUT_CANCEL_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_ESCAPE].push( GAME_INPUT_SPAWN_PAUSE_MENU_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_TAB].push( GAME_INPUT_SELECT_NEXT_HASH );
kr._virtual_key_remap[REMAP_KEYS_SHIFT][VIRTUAL_TAB].push( GAME_INPUT_SELECT_PREV_HASH );
kr._virtual_key_remap[REMAP_KEYS_CTRL][VIRTUAL_TAB].push( GAME_INPUT_SELECT_NEXT_IMPORTANT_HASH );
kr._virtual_key_remap[REMAP_KEYS_CTRL_SHIFT][VIRTUAL_TAB].push(
GAME_INPUT_SELECT_PREV_IMPORTANT_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_ENTER].push( GAME_INPUT_OK_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_PAD_ENTER].push( GAME_INPUT_OK_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_SPACEBAR].push( GAME_INPUT_SPEED_PAUSE_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_1].push( GAME_INPUT_SPEED_PLAY_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_2].push( GAME_INPUT_SPEED_FAST_HASH );
kr._virtual_key_remap[REMAP_KEYS_NONE][VIRTUAL_3].push( GAME_INPUT_SPEED_FASTER_HASH );
//...