forked from RigsOfRods/rigs-of-rods
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
👼Script: Added enum
keyCodes
and isKeyDown*()
functions.
2 new example scripts. also new script func `setEventStatusSupressed(keyCodes keycode, bool supressed)` Updated and formatted docs. Fixed group formatting in InputEngine.h
Showing
7 changed files
with
670 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// EXAMPLE - querying key states and events | ||
// =================================================== | ||
|
||
string keyEventLog; // keys pressed history | ||
string keyEventSeparator; | ||
int HISTORY_LEN = 100; | ||
|
||
void showKeyState(keyCodes kc, string desc) | ||
{ | ||
// Draw the immediate state | ||
ImGui::Text(desc); ImGui::SameLine(); ImGui::Text(""+inputs.isKeyDownEffective(kc)); | ||
|
||
// remember the keypress event | ||
if (inputs.isKeyDownValueBounce(kc)) { | ||
keyEventLog = desc + keyEventSeparator + keyEventLog; | ||
keyEventSeparator = ", "; | ||
// History len cap | ||
if (keyEventLog.length() > HISTORY_LEN) { keyEventLog.resize(HISTORY_LEN); } | ||
} | ||
} | ||
|
||
void frameStep(float dt) | ||
{ | ||
ImGui::TextDisabled("===[ K E Y S T A T E S : ]==="); | ||
|
||
showKeyState(KC_F1, "F1"); ImGui::SameLine(); ImGui::Dummy(vector2(10, 1)); | ||
showKeyState(KC_F2, "F2"); ImGui::SameLine(); ImGui::Dummy(vector2(10, 1)); | ||
showKeyState(KC_F3, "F3"); ImGui::SameLine(); ImGui::Dummy(vector2(10, 1)); | ||
showKeyState(KC_F4, "F4"); | ||
|
||
ImGui::TextDisabled("===[ K E Y H I S T O R Y : ]==="); | ||
|
||
ImGui::Text(keyEventLog); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// EXAMPLE - how to use | ||
// =================================================== | ||
|
||
void drawInputBtn(inputEvents ev, string caption) | ||
{ | ||
ImGui::Button(caption); | ||
if (ImGui::IsItemActive()) // Is button currently pressed? | ||
{ inputs.setEventSimulatedValue(ev, 1.f); } | ||
else | ||
{ inputs.setEventSimulatedValue(ev, 0.f); } // IMPORTANT! The value is persistent, we must also reset it. | ||
} | ||
|
||
// `frameStep()` runs every frame; `dt` is delta time in seconds. | ||
void frameStep(float dt) | ||
{ | ||
if (@game.getCurrentTruck() == null) | ||
{ | ||
ImGui::TextDisabled("Character controls:"); | ||
drawInputBtn(EV_CHARACTER_FORWARD, " ^ "); | ||
drawInputBtn(EV_CHARACTER_LEFT, "<"); | ||
ImGui::SameLine(); | ||
drawInputBtn(EV_CHARACTER_RIGHT, ">"); | ||
drawInputBtn(EV_CHARACTER_BACKWARDS, " v "); | ||
} | ||
else | ||
{ | ||
ImGui::TextDisabled("Vehicle controls:"); | ||
drawInputBtn(EV_TRUCK_ACCELERATE, " ^ "); | ||
drawInputBtn(EV_TRUCK_STEER_LEFT, "<"); | ||
ImGui::SameLine(); | ||
drawInputBtn(EV_TRUCK_STEER_RIGHT, ">"); | ||
drawInputBtn(EV_TRUCK_BRAKE, " v "); | ||
} | ||
} |
Oops, something went wrong.