mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
SDL: Use scancodes for keybindings (#14964)
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> Co-authored-by: sfan5 <sfan5@live.de> Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
parent
e0378737b7
commit
cc65c8bd70
13 changed files with 509 additions and 369 deletions
|
@ -252,8 +252,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
|
|||
if (event.EventType == EET_KEY_INPUT_EVENT && active_key
|
||||
&& event.KeyInput.PressedDown) {
|
||||
|
||||
bool prefer_character = shift_down;
|
||||
KeyPress kp(event.KeyInput, prefer_character);
|
||||
KeyPress kp(event.KeyInput);
|
||||
|
||||
if (event.KeyInput.Key == irr::KEY_DELETE)
|
||||
kp = KeyPress(""); // To erase key settings
|
||||
|
@ -269,7 +268,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
|
|||
|
||||
// Display Key already in use message
|
||||
bool key_in_use = false;
|
||||
if (strcmp(kp.sym(), "") != 0) {
|
||||
if (kp) {
|
||||
for (key_setting *ks : key_settings) {
|
||||
if (ks != active_key && ks->key == kp) {
|
||||
key_in_use = true;
|
||||
|
|
|
@ -147,12 +147,13 @@ bool GUIModalMenu::remapClickOutside(const SEvent &event)
|
|||
if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP &&
|
||||
current.isRelated(last)) {
|
||||
SEvent translated{};
|
||||
translated.EventType = EET_KEY_INPUT_EVENT;
|
||||
translated.KeyInput.Key = KEY_ESCAPE;
|
||||
translated.KeyInput.Control = false;
|
||||
translated.KeyInput.Shift = false;
|
||||
translated.KeyInput.PressedDown = true;
|
||||
translated.KeyInput.Char = 0;
|
||||
translated.EventType = EET_KEY_INPUT_EVENT;
|
||||
translated.KeyInput.Key = KEY_ESCAPE;
|
||||
translated.KeyInput.SystemKeyCode = EscapeKey.getScancode();
|
||||
translated.KeyInput.Control = false;
|
||||
translated.KeyInput.Shift = false;
|
||||
translated.KeyInput.PressedDown = true;
|
||||
translated.KeyInput.Char = 0;
|
||||
OnEvent(translated);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "porting.h"
|
||||
#include "settings.h"
|
||||
#include "client/guiscalingfilter.h"
|
||||
#include "client/keycode.h"
|
||||
#include "client/renderingengine.h"
|
||||
#include "client/texturesource.h"
|
||||
#include "util/numeric.h"
|
||||
|
@ -31,15 +30,16 @@
|
|||
|
||||
TouchControls *g_touchcontrols;
|
||||
|
||||
void TouchControls::emitKeyboardEvent(EKEY_CODE keycode, bool pressed)
|
||||
void TouchControls::emitKeyboardEvent(const KeyPress &key, bool pressed)
|
||||
{
|
||||
SEvent e{};
|
||||
e.EventType = EET_KEY_INPUT_EVENT;
|
||||
e.KeyInput.Key = keycode;
|
||||
e.KeyInput.Control = false;
|
||||
e.KeyInput.Shift = false;
|
||||
e.KeyInput.Char = 0;
|
||||
e.KeyInput.PressedDown = pressed;
|
||||
e.EventType = EET_KEY_INPUT_EVENT;
|
||||
e.KeyInput.Key = key.getKeycode();
|
||||
e.KeyInput.Control = false;
|
||||
e.KeyInput.Shift = false;
|
||||
e.KeyInput.Char = key.getKeychar();
|
||||
e.KeyInput.SystemKeyCode = key.getScancode();
|
||||
e.KeyInput.PressedDown = pressed;
|
||||
m_receiver->OnEvent(e);
|
||||
}
|
||||
|
||||
|
@ -54,10 +54,10 @@ void TouchControls::loadButtonTexture(IGUIImage *gui_button, const std::string &
|
|||
|
||||
void TouchControls::buttonEmitAction(button_info &btn, bool action)
|
||||
{
|
||||
if (btn.keycode == KEY_UNKNOWN)
|
||||
if (!btn.keypress)
|
||||
return;
|
||||
|
||||
emitKeyboardEvent(btn.keycode, action);
|
||||
emitKeyboardEvent(btn.keypress, action);
|
||||
|
||||
if (action) {
|
||||
if (btn.toggleable == button_info::FIRST_TEXTURE) {
|
||||
|
@ -133,12 +133,11 @@ bool TouchControls::buttonsStep(std::vector<button_info> &buttons, float dtime)
|
|||
return has_pointers;
|
||||
}
|
||||
|
||||
static EKEY_CODE id_to_keycode(touch_gui_button_id id)
|
||||
static const KeyPress &id_to_keypress(touch_gui_button_id id)
|
||||
{
|
||||
EKEY_CODE code;
|
||||
// ESC isn't part of the keymap.
|
||||
if (id == exit_id)
|
||||
return KEY_ESCAPE;
|
||||
return EscapeKey;
|
||||
|
||||
std::string key = "";
|
||||
switch (id) {
|
||||
|
@ -197,15 +196,11 @@ static EKEY_CODE id_to_keycode(touch_gui_button_id id)
|
|||
break;
|
||||
}
|
||||
assert(!key.empty());
|
||||
std::string resolved = g_settings->get("keymap_" + key);
|
||||
try {
|
||||
code = keyname_to_keycode(resolved.c_str());
|
||||
} catch (UnknownKeycode &e) {
|
||||
code = KEY_UNKNOWN;
|
||||
warningstream << "TouchControls: Unknown key '" << resolved
|
||||
<< "' for '" << key << "', hiding button." << std::endl;
|
||||
}
|
||||
return code;
|
||||
auto &kp = getKeySetting("keymap_" + key);
|
||||
if (!kp)
|
||||
warningstream << "TouchControls: Unbound or invalid key for"
|
||||
<< key << ", hiding button." << std::endl;
|
||||
return kp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -355,7 +350,7 @@ bool TouchControls::mayAddButton(touch_gui_button_id id)
|
|||
return false;
|
||||
if (id == aux1_id && m_joystick_triggers_aux1)
|
||||
return false;
|
||||
if (id != overflow_id && id_to_keycode(id) == KEY_UNKNOWN)
|
||||
if (id != overflow_id && !id_to_keypress(id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -368,7 +363,7 @@ void TouchControls::addButton(std::vector<button_info> &buttons, touch_gui_butto
|
|||
loadButtonTexture(btn_gui_button, image);
|
||||
|
||||
button_info &btn = buttons.emplace_back();
|
||||
btn.keycode = id_to_keycode(id);
|
||||
btn.keypress = id_to_keypress(id);
|
||||
btn.gui_button = grab_gui_element<IGUIImage>(btn_gui_button);
|
||||
}
|
||||
|
||||
|
@ -634,7 +629,7 @@ void TouchControls::translateEvent(const SEvent &event)
|
|||
void TouchControls::applyJoystickStatus()
|
||||
{
|
||||
if (m_joystick_triggers_aux1) {
|
||||
auto key = id_to_keycode(aux1_id);
|
||||
auto key = id_to_keypress(aux1_id);
|
||||
emitKeyboardEvent(key, false);
|
||||
if (m_joystick_status_aux1)
|
||||
emitKeyboardEvent(key, true);
|
||||
|
@ -741,11 +736,11 @@ void TouchControls::releaseAll()
|
|||
// Release those manually too since the change initiated by
|
||||
// handleReleaseEvent will only be applied later by applyContextControls.
|
||||
if (m_dig_pressed) {
|
||||
emitKeyboardEvent(id_to_keycode(dig_id), false);
|
||||
emitKeyboardEvent(id_to_keypress(dig_id), false);
|
||||
m_dig_pressed = false;
|
||||
}
|
||||
if (m_place_pressed) {
|
||||
emitKeyboardEvent(id_to_keycode(place_id), false);
|
||||
emitKeyboardEvent(id_to_keypress(place_id), false);
|
||||
m_place_pressed = false;
|
||||
}
|
||||
}
|
||||
|
@ -826,20 +821,20 @@ void TouchControls::applyContextControls(const TouchInteractionMode &mode)
|
|||
target_place_pressed |= now < m_place_pressed_until;
|
||||
|
||||
if (target_dig_pressed && !m_dig_pressed) {
|
||||
emitKeyboardEvent(id_to_keycode(dig_id), true);
|
||||
emitKeyboardEvent(id_to_keypress(dig_id), true);
|
||||
m_dig_pressed = true;
|
||||
|
||||
} else if (!target_dig_pressed && m_dig_pressed) {
|
||||
emitKeyboardEvent(id_to_keycode(dig_id), false);
|
||||
emitKeyboardEvent(id_to_keypress(dig_id), false);
|
||||
m_dig_pressed = false;
|
||||
}
|
||||
|
||||
if (target_place_pressed && !m_place_pressed) {
|
||||
emitKeyboardEvent(id_to_keycode(place_id), true);
|
||||
emitKeyboardEvent(id_to_keypress(place_id), true);
|
||||
m_place_pressed = true;
|
||||
|
||||
} else if (!target_place_pressed && m_place_pressed) {
|
||||
emitKeyboardEvent(id_to_keycode(place_id), false);
|
||||
emitKeyboardEvent(id_to_keypress(place_id), false);
|
||||
m_place_pressed = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "itemdef.h"
|
||||
#include "touchscreenlayout.h"
|
||||
#include "util/basic_macros.h"
|
||||
#include "client/keycode.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
|
@ -57,7 +58,7 @@ enum class TapState
|
|||
struct button_info
|
||||
{
|
||||
float repeat_counter;
|
||||
EKEY_CODE keycode;
|
||||
KeyPress keypress;
|
||||
std::vector<size_t> pointer_ids;
|
||||
std::shared_ptr<IGUIImage> gui_button = nullptr;
|
||||
|
||||
|
@ -202,7 +203,7 @@ private:
|
|||
// for its buttons. We only want static image display, not interactivity,
|
||||
// from Irrlicht.
|
||||
|
||||
void emitKeyboardEvent(EKEY_CODE keycode, bool pressed);
|
||||
void emitKeyboardEvent(const KeyPress &keycode, bool pressed);
|
||||
|
||||
void loadButtonTexture(IGUIImage *gui_button, const std::string &path);
|
||||
void buttonEmitAction(button_info &btn, bool action);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue