Merge pull request #44356 from EricEzaM/PR/fix-input-event-string-conversions

Fixed mistakes in InputEvent as_text and to_string implementations.
This commit is contained in:
Rémi Verschelde 2020-12-14 07:30:59 +01:00 committed by GitHub
commit b006fafad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -213,7 +213,7 @@ String InputEventWithModifiers::as_text() const {
if (!mod_names.empty()) {
return String("+").join(mod_names);
} else {
return "None";
return "";
}
}
@ -369,11 +369,19 @@ String InputEventKey::to_string() {
String p = is_pressed() ? "true" : "false";
String e = is_echo() ? "true" : "false";
String kc = "";
String physical = "false";
if (keycode == 0) {
return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", itos(physical_keycode) + " " + keycode_get_string(physical_keycode), InputEventWithModifiers::as_text(), "true", p, e);
kc = itos(physical_keycode) + " " + keycode_get_string(physical_keycode);
physical = "true";
} else {
return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", itos(keycode) + " " + keycode_get_string(keycode), InputEventWithModifiers::as_text(), "false", p, e);
kc = itos(keycode) + " " + keycode_get_string(keycode);
}
String mods = InputEventWithModifiers::as_text();
mods = mods == "" ? TTR("None") : mods;
return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", kc, mods, physical, p, e);
}
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
@ -633,7 +641,12 @@ String InputEventMouseButton::to_string() {
break;
}
return vformat("InputEventMouseButton: button_index=%s pressed=%s position=(%s) button_mask=%s doubleclick=%s", button_index, p, String(get_position()), itos(get_button_mask()), d);
String mods = InputEventWithModifiers::as_text();
mods = mods == "" ? TTR("None") : mods;
// Work around the fact vformat can only take 5 substitutions but 6 need to be passed.
String index_and_mods = vformat("button_index=%s mods=%s", button_index, mods);
return vformat("InputEventMouseButton: %s pressed=%s position=(%s) button_mask=%s doubleclick=%s", index_and_mods, p, String(get_position()), itos(get_button_mask()), d);
}
void InputEventMouseButton::_bind_methods() {