16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

Improve the keymapper

The keymapper, available as one of the options in the starting menu when the EXE is run without a scenery specified, has undergone a few changes:
- Key descriptions are now parsed the way Starter does and are displayed in the window. They are also no longer consumed when saving to a file.
- Unbound keys are now also displayed as well. Not all of them though; some entries won't exist if they are not specified in the eu07_input-keyboard.ini file.
- You can now unbind a key by pressing F10.

The Parser has got a new boolean option: `skipComments`, true by default to leave current behavior unchanged. When set to false, comments will be parsed as ordinary tokens.
This commit is contained in:
jakubg1
2024-03-03 03:00:47 +01:00
parent 9259708d4c
commit 84980a4484
7 changed files with 222 additions and 183 deletions

View File

@@ -24,265 +24,265 @@ void
driverkeyboard_input::default_bindings() { driverkeyboard_input::default_bindings() {
m_bindingsetups = { m_bindingsetups = {
{ user_command::aidriverenable, GLFW_KEY_Q | keymodifier::shift }, { user_command::aidriverenable, {GLFW_KEY_Q | keymodifier::shift, ""} },
{ user_command::aidriverdisable, GLFW_KEY_Q }, { user_command::aidriverdisable, {GLFW_KEY_Q, ""} },
// jointcontrollerset, // jointcontrollerset,
{ user_command::mastercontrollerincrease, GLFW_KEY_KP_ADD }, { user_command::mastercontrollerincrease, {GLFW_KEY_KP_ADD, ""} },
{ user_command::mastercontrollerincreasefast, GLFW_KEY_KP_ADD | keymodifier::shift }, { user_command::mastercontrollerincreasefast, {GLFW_KEY_KP_ADD | keymodifier::shift, ""} },
{ user_command::mastercontrollerdecrease, GLFW_KEY_KP_SUBTRACT }, { user_command::mastercontrollerdecrease, {GLFW_KEY_KP_SUBTRACT, ""} },
{ user_command::mastercontrollerdecreasefast, GLFW_KEY_KP_SUBTRACT | keymodifier::shift }, { user_command::mastercontrollerdecreasefast, {GLFW_KEY_KP_SUBTRACT | keymodifier::shift, ""} },
// mastercontrollerset, // mastercontrollerset,
{ user_command::secondcontrollerincrease, GLFW_KEY_KP_DIVIDE }, { user_command::secondcontrollerincrease, {GLFW_KEY_KP_DIVIDE, ""} },
{ user_command::secondcontrollerincreasefast, GLFW_KEY_KP_DIVIDE | keymodifier::shift }, { user_command::secondcontrollerincreasefast, {GLFW_KEY_KP_DIVIDE | keymodifier::shift, ""} },
{ user_command::secondcontrollerdecrease, GLFW_KEY_KP_MULTIPLY }, { user_command::secondcontrollerdecrease, {GLFW_KEY_KP_MULTIPLY, ""} },
{ user_command::secondcontrollerdecreasefast, GLFW_KEY_KP_MULTIPLY | keymodifier::shift }, { user_command::secondcontrollerdecreasefast, {GLFW_KEY_KP_MULTIPLY | keymodifier::shift, ""} },
// secondcontrollerset, // secondcontrollerset,
{ user_command::mucurrentindicatorothersourceactivate, GLFW_KEY_Z | keymodifier::shift }, { user_command::mucurrentindicatorothersourceactivate, {GLFW_KEY_Z | keymodifier::shift, ""} },
{ user_command::independentbrakeincrease, GLFW_KEY_KP_1 }, { user_command::independentbrakeincrease, {GLFW_KEY_KP_1, ""} },
{ user_command::independentbrakeincreasefast, GLFW_KEY_KP_1 | keymodifier::shift }, { user_command::independentbrakeincreasefast, {GLFW_KEY_KP_1 | keymodifier::shift, ""} },
{ user_command::independentbrakedecrease, GLFW_KEY_KP_7 }, { user_command::independentbrakedecrease, {GLFW_KEY_KP_7, ""} },
{ user_command::independentbrakedecreasefast, GLFW_KEY_KP_7 | keymodifier::shift }, { user_command::independentbrakedecreasefast, {GLFW_KEY_KP_7 | keymodifier::shift, ""} },
// independentbrakeset, // independentbrakeset,
{ user_command::independentbrakebailoff, GLFW_KEY_KP_4 }, { user_command::independentbrakebailoff, {GLFW_KEY_KP_4, ""} },
// universalbrakebutton1, // universalbrakebutton1,
// universalbrakebutton2, // universalbrakebutton2,
// universalbrakebutton3, // universalbrakebutton3,
{ user_command::trainbrakeincrease, GLFW_KEY_KP_3 }, { user_command::trainbrakeincrease, {GLFW_KEY_KP_3, ""} },
{ user_command::trainbrakedecrease, GLFW_KEY_KP_9 }, { user_command::trainbrakedecrease, {GLFW_KEY_KP_9, ""} },
// trainbrakeset, // trainbrakeset,
{ user_command::trainbrakecharging, GLFW_KEY_KP_DECIMAL }, { user_command::trainbrakecharging, {GLFW_KEY_KP_DECIMAL, ""} },
{ user_command::trainbrakerelease, GLFW_KEY_KP_6 }, { user_command::trainbrakerelease, {GLFW_KEY_KP_6, ""} },
{ user_command::trainbrakefirstservice, GLFW_KEY_KP_8 }, { user_command::trainbrakefirstservice, {GLFW_KEY_KP_8, ""} },
{ user_command::trainbrakeservice, GLFW_KEY_KP_5 }, { user_command::trainbrakeservice, {GLFW_KEY_KP_5, ""} },
{ user_command::trainbrakefullservice, GLFW_KEY_KP_2 }, { user_command::trainbrakefullservice, {GLFW_KEY_KP_2, ""} },
{ user_command::trainbrakehandleoff, GLFW_KEY_KP_5 | keymodifier::control }, { user_command::trainbrakehandleoff, {GLFW_KEY_KP_5 | keymodifier::control, ""} },
{ user_command::trainbrakeemergency, GLFW_KEY_KP_0 }, { user_command::trainbrakeemergency, {GLFW_KEY_KP_0, ""} },
{ user_command::trainbrakebasepressureincrease, GLFW_KEY_KP_3 | keymodifier::control }, { user_command::trainbrakebasepressureincrease, {GLFW_KEY_KP_3 | keymodifier::control, ""} },
{ user_command::trainbrakebasepressuredecrease, GLFW_KEY_KP_9 | keymodifier::control }, { user_command::trainbrakebasepressuredecrease, {GLFW_KEY_KP_9 | keymodifier::control, ""} },
{ user_command::trainbrakebasepressurereset, GLFW_KEY_KP_6 | keymodifier::control }, { user_command::trainbrakebasepressurereset, {GLFW_KEY_KP_6 | keymodifier::control, ""} },
{ user_command::trainbrakeoperationtoggle, GLFW_KEY_KP_4 | keymodifier::control }, { user_command::trainbrakeoperationtoggle, {GLFW_KEY_KP_4 | keymodifier::control, ""} },
{ user_command::manualbrakeincrease, GLFW_KEY_KP_1 | keymodifier::control }, { user_command::manualbrakeincrease, {GLFW_KEY_KP_1 | keymodifier::control, ""} },
{ user_command::manualbrakedecrease, GLFW_KEY_KP_7 | keymodifier::control }, { user_command::manualbrakedecrease, {GLFW_KEY_KP_7 | keymodifier::control, ""} },
{ user_command::alarmchaintoggle, GLFW_KEY_B | keymodifier::shift | keymodifier::control }, { user_command::alarmchaintoggle, {GLFW_KEY_B | keymodifier::shift | keymodifier::control, ""} },
// alarmchainenable, // alarmchainenable,
// alarmchaindisable, // alarmchaindisable,
{ user_command::wheelspinbrakeactivate, GLFW_KEY_KP_ENTER }, { user_command::wheelspinbrakeactivate, {GLFW_KEY_KP_ENTER, ""} },
{ user_command::sandboxactivate, GLFW_KEY_S | keymodifier::shift }, { user_command::sandboxactivate, {GLFW_KEY_S | keymodifier::shift, ""} },
// autosandboxtoggle, // autosandboxtoggle,
// autosandboxactivate, // autosandboxactivate,
// autosandboxdeactivate, // autosandboxdeactivate,
{ user_command::reverserincrease, GLFW_KEY_D }, { user_command::reverserincrease, {GLFW_KEY_D, ""} },
{ user_command::reverserdecrease, GLFW_KEY_R }, { user_command::reverserdecrease, {GLFW_KEY_R, ""} },
// reverserforwardhigh, // reverserforwardhigh,
// reverserforward, // reverserforward,
// reverserneutral, // reverserneutral,
// reverserbackward, // reverserbackward,
{ user_command::waterpumpbreakertoggle, GLFW_KEY_W | keymodifier::control }, { user_command::waterpumpbreakertoggle, {GLFW_KEY_W | keymodifier::control, ""} },
// waterpumpbreakerclose, // waterpumpbreakerclose,
// waterpumpbreakeropen, // waterpumpbreakeropen,
{ user_command::waterpumptoggle, GLFW_KEY_W }, { user_command::waterpumptoggle, {GLFW_KEY_W, ""} },
// waterpumpenable, // waterpumpenable,
// waterpumpdisable, // waterpumpdisable,
{ user_command::waterheaterbreakertoggle, GLFW_KEY_W | keymodifier::control | keymodifier::shift }, { user_command::waterheaterbreakertoggle, {GLFW_KEY_W | keymodifier::control | keymodifier::shift, ""} },
// waterheaterbreakerclose, // waterheaterbreakerclose,
// waterheaterbreakeropen, // waterheaterbreakeropen,
{ user_command::waterheatertoggle, GLFW_KEY_W | keymodifier::shift }, { user_command::waterheatertoggle, {GLFW_KEY_W | keymodifier::shift, ""} },
// waterheaterenable, // waterheaterenable,
// waterheaterdisable, // waterheaterdisable,
{ user_command::watercircuitslinktoggle, GLFW_KEY_H | keymodifier::shift }, { user_command::watercircuitslinktoggle, {GLFW_KEY_H | keymodifier::shift, ""} },
// watercircuitslinkenable, // watercircuitslinkenable,
// watercircuitslinkdisable, // watercircuitslinkdisable,
{ user_command::fuelpumptoggle, GLFW_KEY_F }, { user_command::fuelpumptoggle, {GLFW_KEY_F, ""} },
// fuelpumpenable, // fuelpumpenable,
// fuelpumpdisable, // fuelpumpdisable,
{ user_command::oilpumptoggle, GLFW_KEY_F | keymodifier::shift }, { user_command::oilpumptoggle, {GLFW_KEY_F | keymodifier::shift, ""} },
// oilpumpenable, // oilpumpenable,
// oilpumpdisable, // oilpumpdisable,
{ user_command::linebreakertoggle, GLFW_KEY_M }, { user_command::linebreakertoggle, {GLFW_KEY_M, ""} },
// linebreakeropen, // linebreakeropen,
// linebreakerclose, // linebreakerclose,
{ user_command::convertertoggle, GLFW_KEY_X }, { user_command::convertertoggle, {GLFW_KEY_X, ""} },
// converterenable, // converterenable,
// converterdisable, // converterdisable,
{ user_command::convertertogglelocal, GLFW_KEY_X | keymodifier::shift }, { user_command::convertertogglelocal, {GLFW_KEY_X | keymodifier::shift, ""} },
{ user_command::converteroverloadrelayreset, GLFW_KEY_N | keymodifier::control }, { user_command::converteroverloadrelayreset, {GLFW_KEY_N | keymodifier::control, ""} },
{ user_command::compressortoggle, GLFW_KEY_C }, { user_command::compressortoggle, {GLFW_KEY_C, ""} },
// compressorenable, // compressorenable,
// compressordisable, // compressordisable,
{ user_command::compressortogglelocal, GLFW_KEY_C | keymodifier::shift }, { user_command::compressortogglelocal, {GLFW_KEY_C | keymodifier::shift, ""} },
// compressorpresetactivatenext, // compressorpresetactivatenext,
// compressorpresetactivateprevious, // compressorpresetactivateprevious,
// compressorpresetactivatedefault, // compressorpresetactivatedefault,
{ user_command::motoroverloadrelaythresholdtoggle, GLFW_KEY_F | keymodifier::control }, { user_command::motoroverloadrelaythresholdtoggle, {GLFW_KEY_F | keymodifier::control, ""} },
// motoroverloadrelaythresholdsetlow, // motoroverloadrelaythresholdsetlow,
// motoroverloadrelaythresholdsethigh, // motoroverloadrelaythresholdsethigh,
{ user_command::motoroverloadrelayreset, GLFW_KEY_N }, { user_command::motoroverloadrelayreset, {GLFW_KEY_N, ""} },
// universalrelayreset1, // universalrelayreset1,
// universalrelayreset2, // universalrelayreset2,
// universalrelayreset3, // universalrelayreset3,
{ user_command::notchingrelaytoggle, GLFW_KEY_G }, { user_command::notchingrelaytoggle, {GLFW_KEY_G, ""} },
{ user_command::epbrakecontroltoggle, GLFW_KEY_Z | keymodifier::control }, { user_command::epbrakecontroltoggle, {GLFW_KEY_Z | keymodifier::control, ""} },
{ user_command::trainbrakeoperationmodeincrease, GLFW_KEY_KP_2 | keymodifier::control }, { user_command::trainbrakeoperationmodeincrease, {GLFW_KEY_KP_2 | keymodifier::control, ""} },
{ user_command::trainbrakeoperationmodedecrease, GLFW_KEY_KP_8 | keymodifier::control }, { user_command::trainbrakeoperationmodedecrease, {GLFW_KEY_KP_8 | keymodifier::control, ""} },
{ user_command::brakeactingspeedincrease, GLFW_KEY_B | keymodifier::shift }, { user_command::brakeactingspeedincrease, {GLFW_KEY_B | keymodifier::shift, ""} },
{ user_command::brakeactingspeeddecrease, GLFW_KEY_B }, { user_command::brakeactingspeeddecrease, {GLFW_KEY_B, ""} },
// brakeactingspeedsetcargo, // brakeactingspeedsetcargo,
// brakeactingspeedsetpassenger, // brakeactingspeedsetpassenger,
// brakeactingspeedsetrapid, // brakeactingspeedsetrapid,
{ user_command::brakeloadcompensationincrease, GLFW_KEY_H | keymodifier::shift | keymodifier::control }, { user_command::brakeloadcompensationincrease, {GLFW_KEY_H | keymodifier::shift | keymodifier::control, ""} },
{ user_command::brakeloadcompensationdecrease, GLFW_KEY_H | keymodifier::control }, { user_command::brakeloadcompensationdecrease, {GLFW_KEY_H | keymodifier::control, ""} },
{ user_command::mubrakingindicatortoggle, GLFW_KEY_L | keymodifier::shift }, { user_command::mubrakingindicatortoggle, {GLFW_KEY_L | keymodifier::shift, ""} },
{ user_command::alerteracknowledge, GLFW_KEY_SPACE }, { user_command::alerteracknowledge, {GLFW_KEY_SPACE, ""} },
{ user_command::hornlowactivate, GLFW_KEY_A }, { user_command::hornlowactivate, {GLFW_KEY_A, ""} },
{ user_command::hornhighactivate, GLFW_KEY_S }, { user_command::hornhighactivate, {GLFW_KEY_S, ""} },
{ user_command::whistleactivate, GLFW_KEY_Z }, { user_command::whistleactivate, {GLFW_KEY_Z, ""} },
{ user_command::radiotoggle, GLFW_KEY_R | keymodifier::control }, { user_command::radiotoggle, {GLFW_KEY_R | keymodifier::control, ""} },
// radioenable // radioenable
// radiodisable // radiodisable
{ user_command::radiochannelincrease, GLFW_KEY_EQUAL }, { user_command::radiochannelincrease, {GLFW_KEY_EQUAL, ""} },
{ user_command::radiochanneldecrease, GLFW_KEY_MINUS }, { user_command::radiochanneldecrease, {GLFW_KEY_MINUS, ""} },
// radiochannelset // radiochannelset
{ user_command::radiostopsend, GLFW_KEY_PAUSE | keymodifier::shift | keymodifier::control }, { user_command::radiostopsend, {GLFW_KEY_PAUSE | keymodifier::shift | keymodifier::control, ""} },
// radiostopenable // radiostopenable
// radiostopdisable // radiostopdisable
{ user_command::radiostoptest, GLFW_KEY_R | keymodifier::shift | keymodifier::control }, { user_command::radiostoptest, {GLFW_KEY_R | keymodifier::shift | keymodifier::control, ""} },
{ user_command::radiocall3send, GLFW_KEY_BACKSPACE }, { user_command::radiocall3send, {GLFW_KEY_BACKSPACE, ""} },
// radiovolumeincrease, // radiovolumeincrease,
// radiovolumedecrease, // radiovolumedecrease,
// radiovolumeset, // radiovolumeset,
{ user_command::cabchangeforward, GLFW_KEY_HOME }, { user_command::cabchangeforward, {GLFW_KEY_HOME, ""} },
{ user_command::cabchangebackward, GLFW_KEY_END }, { user_command::cabchangebackward, {GLFW_KEY_END, ""} },
// viewturn, // viewturn,
// movehorizontal, // movehorizontal,
// movehorizontalfast, // movehorizontalfast,
// movevertical, // movevertical,
// moveverticalfast, // moveverticalfast,
{ user_command::moveleft, GLFW_KEY_LEFT }, { user_command::moveleft, {GLFW_KEY_LEFT, "Move left"} },
{ user_command::moveright, GLFW_KEY_RIGHT }, { user_command::moveright, {GLFW_KEY_RIGHT, "Move right"} },
{ user_command::moveforward, GLFW_KEY_UP }, { user_command::moveforward, {GLFW_KEY_UP, "Move forwards"} },
{ user_command::moveback, GLFW_KEY_DOWN }, { user_command::moveback, {GLFW_KEY_DOWN, "Move backwards"} },
{ user_command::moveup, GLFW_KEY_PAGE_UP }, { user_command::moveup, {GLFW_KEY_PAGE_UP, "Move up"} },
{ user_command::movedown, GLFW_KEY_PAGE_DOWN }, { user_command::movedown, {GLFW_KEY_PAGE_DOWN, "Move down"} },
{ user_command::nearestcarcouplingincrease, GLFW_KEY_INSERT }, { user_command::nearestcarcouplingincrease, {GLFW_KEY_INSERT, ""} },
{ user_command::nearestcarcouplingdisconnect, GLFW_KEY_DELETE }, { user_command::nearestcarcouplingdisconnect, {GLFW_KEY_DELETE, ""} },
{ user_command::nearestcarcoupleradapterattach, GLFW_KEY_INSERT | keymodifier::control }, { user_command::nearestcarcoupleradapterattach, {GLFW_KEY_INSERT | keymodifier::control, ""} },
{ user_command::nearestcarcoupleradapterremove, GLFW_KEY_DELETE | keymodifier::control }, { user_command::nearestcarcoupleradapterremove, {GLFW_KEY_DELETE | keymodifier::control, ""} },
{ user_command::occupiedcarcouplingdisconnect, GLFW_KEY_DELETE | keymodifier::shift }, { user_command::occupiedcarcouplingdisconnect, {GLFW_KEY_DELETE | keymodifier::shift, ""} },
{ user_command::doortoggleleft, GLFW_KEY_COMMA }, { user_command::doortoggleleft, {GLFW_KEY_COMMA, ""} },
{ user_command::doortoggleright, GLFW_KEY_PERIOD }, { user_command::doortoggleright, {GLFW_KEY_PERIOD, ""} },
{ user_command::doorpermitleft, GLFW_KEY_COMMA | keymodifier::shift }, { user_command::doorpermitleft, {GLFW_KEY_COMMA | keymodifier::shift, ""} },
{ user_command::doorpermitright, GLFW_KEY_PERIOD | keymodifier::shift }, { user_command::doorpermitright, {GLFW_KEY_PERIOD | keymodifier::shift, ""} },
{ user_command::doorpermitpresetactivatenext, GLFW_KEY_PERIOD | keymodifier::shift | keymodifier::control }, { user_command::doorpermitpresetactivatenext, {GLFW_KEY_PERIOD | keymodifier::shift | keymodifier::control, ""} },
{ user_command::doorpermitpresetactivateprevious, GLFW_KEY_COMMA | keymodifier::shift | keymodifier::control }, { user_command::doorpermitpresetactivateprevious, {GLFW_KEY_COMMA | keymodifier::shift | keymodifier::control, ""} },
// dooropenleft, // dooropenleft,
// dooropenright, // dooropenright,
{ user_command::dooropenall, GLFW_KEY_SLASH | keymodifier::shift }, { user_command::dooropenall, {GLFW_KEY_SLASH | keymodifier::shift, ""} },
// doorcloseleft, // doorcloseleft,
// doorcloseright, // doorcloseright,
{ user_command::doorcloseall, GLFW_KEY_SLASH | keymodifier::control }, { user_command::doorcloseall, {GLFW_KEY_SLASH | keymodifier::control, ""} },
// doorsteptoggle, // doorsteptoggle,
{ user_command::doormodetoggle, GLFW_KEY_SLASH | keymodifier::shift | keymodifier::control }, { user_command::doormodetoggle, {GLFW_KEY_SLASH | keymodifier::shift | keymodifier::control, ""} },
// mirrorstoggle, // mirrorstoggle,
{ user_command::departureannounce, GLFW_KEY_SLASH }, { user_command::departureannounce, {GLFW_KEY_SLASH, ""} },
{ user_command::doorlocktoggle, GLFW_KEY_S | keymodifier::control }, { user_command::doorlocktoggle, {GLFW_KEY_S | keymodifier::control, ""} },
{ user_command::pantographcompressorvalvetoggle, GLFW_KEY_V | keymodifier::control }, { user_command::pantographcompressorvalvetoggle, {GLFW_KEY_V | keymodifier::control, ""} },
// pantographcompressorvalveenable, // pantographcompressorvalveenable,
// pantographcompressorvalvedisable, // pantographcompressorvalvedisable,
{ user_command::pantographcompressoractivate, GLFW_KEY_V | keymodifier::shift }, { user_command::pantographcompressoractivate, {GLFW_KEY_V | keymodifier::shift, ""} },
{ user_command::pantographtogglefront, GLFW_KEY_P }, { user_command::pantographtogglefront, {GLFW_KEY_P, ""} },
{ user_command::pantographtogglerear, GLFW_KEY_O }, { user_command::pantographtogglerear, {GLFW_KEY_O, ""} },
// pantographraisefront, // pantographraisefront,
// pantographraiserear, // pantographraiserear,
// pantographlowerfront, // pantographlowerfront,
// pantographlowerrear, // pantographlowerrear,
{ user_command::pantographlowerall, GLFW_KEY_P | keymodifier::control }, { user_command::pantographlowerall, {GLFW_KEY_P | keymodifier::control, ""} },
{ user_command::pantographselectnext, GLFW_KEY_P | keymodifier::shift }, { user_command::pantographselectnext, {GLFW_KEY_P | keymodifier::shift, ""} },
{ user_command::pantographselectprevious, GLFW_KEY_O | keymodifier::shift }, { user_command::pantographselectprevious, {GLFW_KEY_O | keymodifier::shift, ""} },
{ user_command::pantographtoggleselected, GLFW_KEY_O | keymodifier::shift | keymodifier::control }, { user_command::pantographtoggleselected, {GLFW_KEY_O | keymodifier::shift | keymodifier::control, ""} },
// pantographraiseselected, // pantographraiseselected,
// pantographlowerselected, // pantographlowerselected,
// pantographvalvesupdate, // pantographvalvesupdate,
// pantographvalvesoff, // pantographvalvesoff,
{ user_command::heatingtoggle, GLFW_KEY_H }, { user_command::heatingtoggle, {GLFW_KEY_H, ""} },
// heatingenable, // heatingenable,
// heatingdisable, // heatingdisable,
{ user_command::lightspresetactivatenext, GLFW_KEY_T | keymodifier::shift }, { user_command::lightspresetactivatenext, {GLFW_KEY_T | keymodifier::shift, ""} },
{ user_command::lightspresetactivateprevious, GLFW_KEY_T }, { user_command::lightspresetactivateprevious, {GLFW_KEY_T, ""} },
{ user_command::headlighttoggleleft, GLFW_KEY_Y }, { user_command::headlighttoggleleft, {GLFW_KEY_Y, ""} },
// headlightenableleft, // headlightenableleft,
// headlightdisableleft, // headlightdisableleft,
{ user_command::headlighttoggleright, GLFW_KEY_I }, { user_command::headlighttoggleright, {GLFW_KEY_I, ""} },
// headlightenableright, // headlightenableright,
// headlightdisableright, // headlightdisableright,
{ user_command::headlighttoggleupper, GLFW_KEY_U }, { user_command::headlighttoggleupper, {GLFW_KEY_U, ""} },
// headlightenableupper, // headlightenableupper,
// headlightdisableupper, // headlightdisableupper,
{ user_command::redmarkertoggleleft, GLFW_KEY_Y | keymodifier::shift }, { user_command::redmarkertoggleleft, {GLFW_KEY_Y | keymodifier::shift, ""} },
// redmarkerenableleft, // redmarkerenableleft,
// redmarkerdisableleft, // redmarkerdisableleft,
{ user_command::redmarkertoggleright, GLFW_KEY_I | keymodifier::shift }, { user_command::redmarkertoggleright, {GLFW_KEY_I | keymodifier::shift, ""} },
// redmarkerenableright, // redmarkerenableright,
// redmarkerdisableright, // redmarkerdisableright,
{ user_command::headlighttogglerearleft, GLFW_KEY_Y | keymodifier::control }, { user_command::headlighttogglerearleft, {GLFW_KEY_Y | keymodifier::control, ""} },
// headlightenablerearleft // headlightenablerearleft
// headlightdisablerearleft // headlightdisablerearleft
{ user_command::headlighttogglerearright, GLFW_KEY_I | keymodifier::control }, { user_command::headlighttogglerearright, {GLFW_KEY_I | keymodifier::control, ""} },
// headlightenablerearright // headlightenablerearright
// headlightdisablerearright // headlightdisablerearright
{ user_command::headlighttogglerearupper, GLFW_KEY_U | keymodifier::control }, { user_command::headlighttogglerearupper, {GLFW_KEY_U | keymodifier::control, ""} },
// headlightenablerearupper // headlightenablerearupper
// headlightdisablerearupper // headlightdisablerearupper
{ user_command::redmarkertogglerearleft, GLFW_KEY_Y | keymodifier::control | keymodifier::shift }, { user_command::redmarkertogglerearleft, {GLFW_KEY_Y | keymodifier::control | keymodifier::shift, ""} },
// redmarkerenablerearleft // redmarkerenablerearleft
// redmarkerdisablerearleft // redmarkerdisablerearleft
{ user_command::redmarkertogglerearright, GLFW_KEY_I | keymodifier::control | keymodifier::shift }, { user_command::redmarkertogglerearright, {GLFW_KEY_I | keymodifier::control | keymodifier::shift, ""} },
// redmarkerenablerearright // redmarkerenablerearright
// redmarkerdisablerearright // redmarkerdisablerearright
{ user_command::redmarkerstoggle, GLFW_KEY_E | keymodifier::shift }, { user_command::redmarkerstoggle, {GLFW_KEY_E | keymodifier::shift, ""} },
{ user_command::endsignalstoggle, GLFW_KEY_E }, { user_command::endsignalstoggle, {GLFW_KEY_E, ""} },
{ user_command::headlightsdimtoggle, GLFW_KEY_L | keymodifier::control }, { user_command::headlightsdimtoggle, {GLFW_KEY_L | keymodifier::control, ""} },
// headlightsdimenable, // headlightsdimenable,
// headlightsdimdisable, // headlightsdimdisable,
{ user_command::motorconnectorsopen, GLFW_KEY_L }, { user_command::motorconnectorsopen, {GLFW_KEY_L, ""} },
// motorconnectorsclose, // motorconnectorsclose,
{ user_command::motordisconnect, GLFW_KEY_E | keymodifier::control }, { user_command::motordisconnect, {GLFW_KEY_E | keymodifier::control, ""} },
{ user_command::interiorlighttoggle, GLFW_KEY_APOSTROPHE }, { user_command::interiorlighttoggle, {GLFW_KEY_APOSTROPHE, ""} },
// interiorlightenable, // interiorlightenable,
// interiorlightdisable, // interiorlightdisable,
{ user_command::interiorlightdimtoggle, GLFW_KEY_APOSTROPHE | keymodifier::control }, { user_command::interiorlightdimtoggle, {GLFW_KEY_APOSTROPHE | keymodifier::control, ""} },
// interiorlightdimenable, // interiorlightdimenable,
// interiorlightdimdisable, // interiorlightdimdisable,
// compartmentlightstoggle, // compartmentlightstoggle,
// compartmentlightsenable, // compartmentlightsenable,
// compartmentlightsdisable, // compartmentlightsdisable,
{ user_command::instrumentlighttoggle, GLFW_KEY_SEMICOLON }, { user_command::instrumentlighttoggle, {GLFW_KEY_SEMICOLON, ""} },
// instrumentlightenable, // instrumentlightenable,
// instrumentlightdisable, // instrumentlightdisable,
{ user_command::dashboardlighttoggle, GLFW_KEY_SEMICOLON | keymodifier::shift }, { user_command::dashboardlighttoggle, {GLFW_KEY_SEMICOLON | keymodifier::shift, ""} },
// dashboardlightenable // dashboardlightenable
// dashboardlightdisable // dashboardlightdisable
{ user_command::timetablelighttoggle, GLFW_KEY_APOSTROPHE | keymodifier::shift }, { user_command::timetablelighttoggle, {GLFW_KEY_APOSTROPHE | keymodifier::shift, ""} },
// timetablelightenable // timetablelightenable
// timetablelightdisable // timetablelightdisable
{ user_command::generictoggle0, GLFW_KEY_0 }, { user_command::generictoggle0, {GLFW_KEY_0, ""} },
{ user_command::generictoggle1, GLFW_KEY_1 }, { user_command::generictoggle1, {GLFW_KEY_1, ""} },
{ user_command::generictoggle2, GLFW_KEY_2 }, { user_command::generictoggle2, {GLFW_KEY_2, ""} },
{ user_command::generictoggle3, GLFW_KEY_3 }, { user_command::generictoggle3, {GLFW_KEY_3, ""} },
{ user_command::generictoggle4, GLFW_KEY_4 }, { user_command::generictoggle4, {GLFW_KEY_4, ""} },
{ user_command::generictoggle5, GLFW_KEY_5 }, { user_command::generictoggle5, {GLFW_KEY_5, ""} },
{ user_command::generictoggle6, GLFW_KEY_6 }, { user_command::generictoggle6, {GLFW_KEY_6, ""} },
{ user_command::generictoggle7, GLFW_KEY_7 }, { user_command::generictoggle7, {GLFW_KEY_7, ""} },
{ user_command::generictoggle8, GLFW_KEY_8 }, { user_command::generictoggle8, {GLFW_KEY_8, ""} },
{ user_command::generictoggle9, GLFW_KEY_9 }, { user_command::generictoggle9, {GLFW_KEY_9, ""} },
{ user_command::batterytoggle, GLFW_KEY_J }, { user_command::batterytoggle, {GLFW_KEY_J, ""} },
// batteryenable, // batteryenable,
// batterydisable, // batterydisable,
// cabactivationtoggle, // cabactivationtoggle,
// cabactivationenable, // cabactivationenable,
// cabactivationdisable, // cabactivationdisable,
{ user_command::motorblowerstogglefront, GLFW_KEY_N | keymodifier::shift }, { user_command::motorblowerstogglefront, {GLFW_KEY_N | keymodifier::shift, ""} },
{ user_command::motorblowerstogglerear, GLFW_KEY_M | keymodifier::shift }, { user_command::motorblowerstogglerear, {GLFW_KEY_M | keymodifier::shift, ""} },
{ user_command::motorblowersdisableall, GLFW_KEY_M | keymodifier::control }, { user_command::motorblowersdisableall, {GLFW_KEY_M | keymodifier::control, ""} },
// coolingfanstoggle, // coolingfanstoggle,
// tempomattoggle, // tempomattoggle,
// springbraketoggle, // springbraketoggle,
@@ -308,14 +308,14 @@ driverkeyboard_input::default_bindings() {
// speedcontrolbutton8, // speedcontrolbutton8,
// speedcontrolbutton9, // speedcontrolbutton9,
// admin_timejump, // admin_timejump,
{ user_command::timejumplarge, GLFW_KEY_F1 | keymodifier::control }, { user_command::timejumplarge, {GLFW_KEY_F1 | keymodifier::control, "Big time jump (Debug Mode only)"} },
{ user_command::timejumpsmall, GLFW_KEY_F1 | keymodifier::shift }, { user_command::timejumpsmall, {GLFW_KEY_F1 | keymodifier::shift, "Small time jump (Debug Mode only)"} },
// admin_vehiclemove, // admin_vehiclemove,
{ user_command::vehiclemoveforwards, GLFW_KEY_LEFT_BRACKET | keymodifier::control }, { user_command::vehiclemoveforwards, {GLFW_KEY_LEFT_BRACKET | keymodifier::control, "Move the train forwards (Debug Mode only)"} },
{ user_command::vehiclemovebackwards, GLFW_KEY_RIGHT_BRACKET | keymodifier::control }, { user_command::vehiclemovebackwards, {GLFW_KEY_RIGHT_BRACKET | keymodifier::control, "Move the train backwards (Debug Mode only)"} },
{ user_command::vehicleboost, GLFW_KEY_TAB | keymodifier::control }, { user_command::vehicleboost, {GLFW_KEY_TAB | keymodifier::control, "Boost the train (Debug Mode only)"} },
{ user_command::debugtoggle, GLFW_KEY_F12 | keymodifier::control | keymodifier::shift }, { user_command::debugtoggle, {GLFW_KEY_F12 | keymodifier::control | keymodifier::shift, "Toggle Debug Mode"} },
{ user_command::pausetoggle, GLFW_KEY_ESCAPE } { user_command::pausetoggle, {GLFW_KEY_ESCAPE, "Pause the game"} }
}; };
} }

View File

@@ -25,12 +25,12 @@ void
editorkeyboard_input::default_bindings() { editorkeyboard_input::default_bindings() {
m_bindingsetups = { m_bindingsetups = {
{ user_command::moveleft, GLFW_KEY_LEFT }, { user_command::moveleft, {GLFW_KEY_LEFT, "Move left"} },
{ user_command::moveright, GLFW_KEY_RIGHT }, { user_command::moveright, {GLFW_KEY_RIGHT, "Move right"} },
{ user_command::moveforward, GLFW_KEY_UP }, { user_command::moveforward, {GLFW_KEY_UP, "Move forwards"} },
{ user_command::moveback, GLFW_KEY_DOWN }, { user_command::moveback, {GLFW_KEY_DOWN, "Move backwards"} },
{ user_command::moveup, GLFW_KEY_PAGE_UP }, { user_command::moveup, {GLFW_KEY_PAGE_UP, "Move up"} },
{ user_command::movedown, GLFW_KEY_PAGE_DOWN }, { user_command::movedown, {GLFW_KEY_PAGE_DOWN, "Move down"} },
}; };
} }

View File

@@ -122,6 +122,7 @@ bool
keyboard_input::recall_bindings() { keyboard_input::recall_bindings() {
cParser bindingparser( "eu07_input-keyboard.ini", cParser::buffer_FILE ); cParser bindingparser( "eu07_input-keyboard.ini", cParser::buffer_FILE );
bindingparser.skipComments = false;
if( false == bindingparser.ok() ) { if( false == bindingparser.ok() ) {
return false; return false;
} }
@@ -147,6 +148,7 @@ keyboard_input::recall_bindings() {
std::string bindingentry; std::string bindingentry;
bindingparser >> bindingentry; bindingparser >> bindingentry;
cParser entryparser( bindingentry ); cParser entryparser( bindingentry );
entryparser.skipComments = false;
if( true == entryparser.getTokens( 1, true, "\n\r\t " ) ) { if( true == entryparser.getTokens( 1, true, "\n\r\t " ) ) {
std::string commandname; std::string commandname;
@@ -158,15 +160,31 @@ keyboard_input::recall_bindings() {
WriteLog( "Keyboard binding defined for unknown command, \"" + commandname + "\"" ); WriteLog( "Keyboard binding defined for unknown command, \"" + commandname + "\"" );
} }
else { else {
int binding{ 0 }; int keycode = 0;
std::string description = "";
bool descriptionStarted = false;
while( entryparser.getTokens( 1, true, "\n\r\t " ) ) { while( entryparser.getTokens( 1, true, "\n\r\t " ) ) {
std::string bindingkeyname; std::string bindingkeyname;
entryparser >> bindingkeyname; entryparser >> bindingkeyname;
if( bindingkeyname == "shift" ) { binding |= keymodifier::shift; } // Parse command description, starting with "//".
else if( bindingkeyname == "ctrl" ) { binding |= keymodifier::control; } // TODO: At some point, rewind this and add translation keys instead for multilingual support.
else if( bindingkeyname == "none" ) { binding = 0; } // This can't be done now as by default this would destroy all command descriptions,
// which are used by Starter.
// Do this when szczawik's Starter becomes deprecated or implements command descriptions in some other way.
WriteLog("got: \"" + bindingkeyname + "\"");
if (descriptionStarted) {
if (description.size() > 0) {
description += " ";
}
description += bindingkeyname;
} else if (bindingkeyname == "//") {
descriptionStarted = true;
} else {
if( bindingkeyname == "shift" ) { keycode |= keymodifier::shift; }
else if( bindingkeyname == "ctrl" ) { keycode |= keymodifier::control; }
else if( bindingkeyname == "none" ) { keycode = 0; }
else { else {
// regular key, convert it to glfw key code // regular key, convert it to glfw key code
auto const keylookup = nametokeymap.find( bindingkeyname ); auto const keylookup = nametokeymap.find( bindingkeyname );
@@ -177,17 +195,17 @@ keyboard_input::recall_bindings() {
else { else {
// replace any existing binding, preserve modifiers // replace any existing binding, preserve modifiers
// (protection from cases where there's more than one key listed in the entry) // (protection from cases where there's more than one key listed in the entry)
binding = keylookup->second | ( binding & 0xffff0000 ); keycode = keylookup->second | ( keycode & 0xffff0000 );
}
} }
} }
if( ( binding & 0xffff ) != 0 ) { std::tuple<int, std::string> binding{keycode, description};
m_bindingsetups.insert_or_assign(lookup->second, binding); m_bindingsetups.insert_or_assign(lookup->second, binding);
} }
} }
} }
} }
}
return true; return true;
} }
@@ -202,20 +220,25 @@ void keyboard_input::dump_bindings()
return; return;
} }
for (const std::pair<user_command, int> &binding : m_bindingsetups) { for (const std::pair<user_command, std::tuple<int, std::string>> &binding : m_bindingsetups) {
stream << simulation::Commands_descriptions[static_cast<std::size_t>(binding.first)].name << ' '; stream << simulation::Commands_descriptions[static_cast<std::size_t>(binding.first)].name << ' ';
auto it = keytonamemap.find(binding.second & 0xFFFF); int keycode = std::get<int>(binding.second);
auto it = keytonamemap.find(keycode & 0xFFFF);
if (it != keytonamemap.end()) { if (it != keytonamemap.end()) {
if (binding.second & keymodifier::control) if (keycode & keymodifier::control)
stream << "ctrl "; stream << "ctrl ";
if (binding.second & keymodifier::shift) if (keycode & keymodifier::shift)
stream << "shift "; stream << "shift ";
stream << it->second << "\r\n"; stream << it->second;
} else { } else {
stream << "none\r\n"; stream << "none";
} }
std::string description = std::get<std::string>(binding.second);
if (description.size() > 0)
stream << " // " << description << "\r\n";
} }
} }
@@ -295,7 +318,7 @@ keyboard_input::bind() {
for( auto const &bindingsetup : m_bindingsetups ) { for( auto const &bindingsetup : m_bindingsetups ) {
m_bindings[ bindingsetup.second ] = bindingsetup.first; m_bindings[ std::get<int>(bindingsetup.second) ] = bindingsetup.first;
} }
// cache movement key bindings // cache movement key bindings

View File

@@ -31,7 +31,7 @@ class keyboard_input {
public: public:
// types // types
using bindingsetup_sequence = std::map<user_command, int>; using bindingsetup_sequence = std::map<user_command, std::tuple<int, std::string>>;
enum keymodifier : int { enum keymodifier : int {

View File

@@ -21,8 +21,15 @@ bool ui::keymapper_panel::key(int key)
key |= keyboard_input::keymodifier::shift; key |= keyboard_input::keymodifier::shift;
if (Global.ctrlState) if (Global.ctrlState)
key |= keyboard_input::keymodifier::control; key |= keyboard_input::keymodifier::control;
// F10 unbinds the key.
if (it->second.compare("f10") == 0)
key = 0;
keyboard.bindings().insert_or_assign(bind_active, key); // Replace the binding with a new key.
auto it2 = keyboard.bindings().find(bind_active);
if (it2 != keyboard.bindings().end()) {
it2->second = std::tuple<int, std::string>(key, std::get<std::string>(it2->second));
}
bind_active = user_command::none; bind_active = user_command::none;
keyboard.bind(); keyboard.bind();
@@ -45,18 +52,26 @@ void ui::keymapper_panel::render()
if (ImGui::Button(STR_C("Save"))) if (ImGui::Button(STR_C("Save")))
keyboard.dump_bindings(); keyboard.dump_bindings();
for (const std::pair<user_command, int> &binding : keyboard.bindings()) { for (const std::pair<user_command, std::tuple<int, std::string>> &binding : keyboard.bindings()) {
// Binding ID
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
ImGui::Text(simulation::Commands_descriptions[static_cast<std::size_t>(binding.first)].name.c_str()); ImGui::Text(simulation::Commands_descriptions[static_cast<std::size_t>(binding.first)].name.c_str());
// Binding description
std::string description = std::get<std::string>(binding.second);
ImGui::SameLine(260);
ImGui::Text((description.size() > 0 ? description : "(No description)").c_str());
// Binding key button
int keycode = std::get<int>(binding.second);
std::string label; std::string label;
if (binding.second & keyboard_input::keymodifier::control) if (keycode & keyboard_input::keymodifier::control)
label += "ctrl + "; label += "ctrl + ";
if (binding.second & keyboard_input::keymodifier::shift) if (keycode & keyboard_input::keymodifier::shift)
label += "shift + "; label += "shift + ";
auto it = keyboard.keytonamemap.find(binding.second & 0xFFFF); auto it = keyboard.keytonamemap.find(keycode & 0xFFFF);
if (it != keyboard.keytonamemap.end()) if (it != keyboard.keytonamemap.end())
label += it->second; label += it->second;
@@ -64,7 +79,7 @@ void ui::keymapper_panel::render()
bool styles_pushed = false; bool styles_pushed = false;
if (bind_active == binding.first) { if (bind_active == binding.first) {
label = "?"; label = "Press key (F10 to unbind)";
ImVec4 active_col = ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive); ImVec4 active_col = ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive);
ImGui::PushStyleColor(ImGuiCol_Button, active_col); ImGui::PushStyleColor(ImGuiCol_Button, active_col);
styles_pushed = true; styles_pushed = true;

View File

@@ -202,7 +202,7 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
token += c; token += c;
if( findQuotes( token ) ) // do glue together words enclosed in quotes if( findQuotes( token ) ) // do glue together words enclosed in quotes
continue; continue;
if( trimComments( token ) ) // don't glue together words separated with comment if( skipComments && trimComments( token ) ) // don't glue together words separated with comment
break; break;
} }
if( c == '\n' ) { if( c == '\n' ) {

View File

@@ -92,6 +92,7 @@ class cParser //: public std::stringstream
int LineMain() const; int LineMain() const;
bool expandIncludes = true; bool expandIncludes = true;
bool allowRandomIncludes = false; bool allowRandomIncludes = false;
bool skipComments = true;
private: private:
// methods: // methods: