Fixed keybinds
This commit is contained in:
parent
2c76741c9b
commit
e3af067972
6 changed files with 29 additions and 54 deletions
|
|
@ -847,14 +847,12 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
||||||
if(kPress != SDLK_LSHIFT && kPress != SDLK_RSHIFT && kPress != SDLK_LCTRL && kPress != SDLK_RCTRL &&
|
if(kPress != SDLK_LSHIFT && kPress != SDLK_RSHIFT && kPress != SDLK_LCTRL && kPress != SDLK_RCTRL &&
|
||||||
kPress != SDLK_LGUI && kPress != SDLK_RGUI &&
|
kPress != SDLK_LGUI && kPress != SDLK_RGUI &&
|
||||||
kPress != SDLK_LALT && kPress != SDLK_RALT) {
|
kPress != SDLK_LALT && kPress != SDLK_RALT) {
|
||||||
lastPressedKeybind = {make_generic_key_mod(kMod), kPress};
|
if(main.input_keybind_callback({make_generic_key_mod(kMod), kPress}))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.key != SDLK_LMETA && e.key != SDLK_RMETA &&
|
// e.key != SDLK_LMETA && e.key != SDLK_RMETA &&
|
||||||
|
|
||||||
if(stopKeyInput)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::shared_ptr<RichText::TextBox> textBox = text.textBoxes.empty() ? nullptr : text.textBoxes.front().textBox;
|
std::shared_ptr<RichText::TextBox> textBox = text.textBoxes.empty() ? nullptr : text.textBoxes.front().textBox;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> cursor = text.textBoxes.empty() ? nullptr : text.textBoxes.front().cursor;
|
std::shared_ptr<RichText::TextBox::Cursor> cursor = text.textBoxes.empty() ? nullptr : text.textBoxes.front().cursor;
|
||||||
std::optional<RichText::TextStyleModifier::ModifierMap> modMap = text.textBoxes.empty() ? std::nullopt : shared_ptr_to_opt(text.textBoxes.front().modMap);
|
std::optional<RichText::TextStyleModifier::ModifierMap> modMap = text.textBoxes.empty() ? std::nullopt : shared_ptr_to_opt(text.textBoxes.front().modMap);
|
||||||
|
|
@ -1168,10 +1166,6 @@ void InputManager::backend_key_up_update(const SDL_KeyboardEvent& e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::stop_key_input() {
|
|
||||||
stopKeyInput = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputManager::Mouse::set_pos(const Vector2f& newPos) {
|
void InputManager::Mouse::set_pos(const Vector2f& newPos) {
|
||||||
pos = newPos;
|
pos = newPos;
|
||||||
}
|
}
|
||||||
|
|
@ -1195,10 +1189,6 @@ void InputManager::update() {
|
||||||
void InputManager::frame_reset(const Vector2i& windowSize) {
|
void InputManager::frame_reset(const Vector2i& windowSize) {
|
||||||
cursorIcon = SystemCursorType::DEFAULT;
|
cursorIcon = SystemCursorType::DEFAULT;
|
||||||
|
|
||||||
lastPressedKeybind = std::nullopt;
|
|
||||||
if(stopKeyInput)
|
|
||||||
stopKeyInput--;
|
|
||||||
|
|
||||||
toggleFullscreen = false;
|
toggleFullscreen = false;
|
||||||
hideCursor = false;
|
hideCursor = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -187,9 +187,6 @@ struct InputManager {
|
||||||
SDL_Keymod CTRL_MOD = SDL_KMOD_CTRL;
|
SDL_Keymod CTRL_MOD = SDL_KMOD_CTRL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int stopKeyInput = 0;
|
|
||||||
std::optional<Vector2ui32> lastPressedKeybind;
|
|
||||||
|
|
||||||
enum KeyCodeEnum : unsigned {
|
enum KeyCodeEnum : unsigned {
|
||||||
// Assignable
|
// Assignable
|
||||||
KEY_CAMERA_ROTATE_CLOCKWISE = 0,
|
KEY_CAMERA_ROTATE_CLOCKWISE = 0,
|
||||||
|
|
@ -263,7 +260,6 @@ struct InputManager {
|
||||||
typedef unsigned KeyCode;
|
typedef unsigned KeyCode;
|
||||||
|
|
||||||
bool ctrl_or_meta_held();
|
bool ctrl_or_meta_held();
|
||||||
void stop_key_input();
|
|
||||||
uint32_t make_generic_key_mod(SDL_Keymod m);
|
uint32_t make_generic_key_mod(SDL_Keymod m);
|
||||||
void set_key_up(const SDL_KeyboardEvent& e, KeyCode kCode);
|
void set_key_up(const SDL_KeyboardEvent& e, KeyCode kCode);
|
||||||
void set_key_down(const SDL_KeyboardEvent& e, KeyCode kCode);
|
void set_key_down(const SDL_KeyboardEvent& e, KeyCode kCode);
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,24 @@ sk_sp<SkSurface> MainProgram::create_native_surface(Vector2i resolution, bool is
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainProgram::input_keybind_callback(const Vector2ui32& newKey) {
|
||||||
|
if(keybindWaiting.has_value()) {
|
||||||
|
unsigned v = keybindWaiting.value();
|
||||||
|
|
||||||
|
input.keyAssignments.erase(newKey);
|
||||||
|
auto f = std::find_if(input.keyAssignments.begin(), input.keyAssignments.end(), [&](auto& p) {
|
||||||
|
return p.second == v;
|
||||||
|
});
|
||||||
|
if(f != input.keyAssignments.end())
|
||||||
|
input.keyAssignments.erase(f);
|
||||||
|
input.keyAssignments.emplace(newKey, v);
|
||||||
|
keybindWaiting = std::nullopt;
|
||||||
|
g.gui.set_to_layout();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void MainProgram::input_drop_file_callback(const InputManager::DropCallbackArgs& drop) {
|
void MainProgram::input_drop_file_callback(const InputManager::DropCallbackArgs& drop) {
|
||||||
if(std::filesystem::is_regular_file(drop.data)) {
|
if(std::filesystem::is_regular_file(drop.data)) {
|
||||||
std::filesystem::path droppedFilePath(drop.data);
|
std::filesystem::path droppedFilePath(drop.data);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <SDL3/SDL_render.h>
|
#include <SDL3/SDL_render.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <include/core/SkCanvas.h>
|
#include <include/core/SkCanvas.h>
|
||||||
|
#include "Helpers/Hashes.hpp"
|
||||||
#include "InputManager.hpp"
|
#include "InputManager.hpp"
|
||||||
#include "FontData.hpp"
|
#include "FontData.hpp"
|
||||||
#include "TimePoint.hpp"
|
#include "TimePoint.hpp"
|
||||||
|
|
@ -119,6 +120,9 @@ class MainProgram {
|
||||||
|
|
||||||
GlobalConfig conf;
|
GlobalConfig conf;
|
||||||
|
|
||||||
|
std::optional<unsigned> keybindWaiting;
|
||||||
|
bool input_keybind_callback(const Vector2ui32& newKey);
|
||||||
|
|
||||||
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
||||||
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
||||||
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||||
|
|
|
||||||
|
|
@ -290,22 +290,6 @@ void Toolbar::layout_run() {
|
||||||
colorLeftJustDisabled = false;
|
colorLeftJustDisabled = false;
|
||||||
colorRightJustEnabled = nullptr;
|
colorRightJustEnabled = nullptr;
|
||||||
colorRightJustDisabled = false;
|
colorRightJustDisabled = false;
|
||||||
|
|
||||||
if(!main.world->clientStillConnecting) {
|
|
||||||
//if(io.hoverObstructed && (io.mouse.leftClick || io.mouse.rightClick))
|
|
||||||
// rightClickPopupLocation = std::nullopt;
|
|
||||||
|
|
||||||
//if(rightClickPopupLocation.has_value()) {
|
|
||||||
// if(!main.world->drawProg.right_click_popup_gui(rightClickPopupLocation.value()))
|
|
||||||
// rightClickPopupLocation = std::nullopt;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if(io.hoverObstructed && io.mouse.rightClick) // This runs specifically if the paint popup has the cursor
|
|
||||||
// rightClickPopupLocation = std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!optionsMenuOpen || generalSettingsOptions != GSETTINGS_KEYBINDS)
|
|
||||||
keybindWaiting = std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Toolbar::app_close_requested() {
|
bool Toolbar::app_close_requested() {
|
||||||
|
|
@ -1711,6 +1695,7 @@ void Toolbar::general_settings_inner_gui() {
|
||||||
main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded);
|
main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded);
|
||||||
themeData.selectedThemeIndex = std::nullopt;
|
themeData.selectedThemeIndex = std::nullopt;
|
||||||
generalSettingsOptions = opt;
|
generalSettingsOptions = opt;
|
||||||
|
main.keybindWaiting = std::nullopt;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -1878,23 +1863,6 @@ void Toolbar::general_settings_inner_gui() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GSETTINGS_KEYBINDS: {
|
case GSETTINGS_KEYBINDS: {
|
||||||
if(keybindWaiting.has_value()) {
|
|
||||||
main.input.stop_key_input();
|
|
||||||
if(main.input.lastPressedKeybind) {
|
|
||||||
unsigned v = keybindWaiting.value();
|
|
||||||
|
|
||||||
Vector2ui32 newKey = main.input.lastPressedKeybind.value();
|
|
||||||
main.input.keyAssignments.erase(newKey);
|
|
||||||
auto f = std::find_if(main.input.keyAssignments.begin(), main.input.keyAssignments.end(), [&](auto& p) {
|
|
||||||
return p.second == v;
|
|
||||||
});
|
|
||||||
if(f != main.input.keyAssignments.end())
|
|
||||||
main.input.keyAssignments.erase(f);
|
|
||||||
main.input.keyAssignments.emplace(newKey, v);
|
|
||||||
keybindWaiting = std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
general_scroll_area("keybind entries", [&] {
|
general_scroll_area("keybind entries", [&] {
|
||||||
for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) {
|
for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) {
|
||||||
gui.new_id(i, [&] {
|
gui.new_id(i, [&] {
|
||||||
|
|
@ -1913,10 +1881,10 @@ void Toolbar::general_settings_inner_gui() {
|
||||||
});
|
});
|
||||||
std::string assignedKeystrokeStr = f != main.input.keyAssignments.end() ? main.input.key_assignment_to_str(f->first) : "";
|
std::string assignedKeystrokeStr = f != main.input.keyAssignments.end() ? main.input.key_assignment_to_str(f->first) : "";
|
||||||
text_button(gui, "keybind button", assignedKeystrokeStr, {
|
text_button(gui, "keybind button", assignedKeystrokeStr, {
|
||||||
.isSelected = keybindWaiting.has_value() && keybindWaiting.value() == i,
|
.isSelected = main.keybindWaiting.has_value() && main.keybindWaiting.value() == i,
|
||||||
.wide = true,
|
.wide = true,
|
||||||
.onClick = [&] {
|
.onClick = [&, i] {
|
||||||
keybindWaiting = i;
|
main.keybindWaiting = i;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1953,6 +1921,7 @@ void Toolbar::general_settings_inner_gui() {
|
||||||
main.save_config();
|
main.save_config();
|
||||||
main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded);
|
main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded);
|
||||||
themeData.selectedThemeIndex = std::nullopt;
|
themeData.selectedThemeIndex = std::nullopt;
|
||||||
|
main.keybindWaiting = std::nullopt;
|
||||||
optionsMenuOpen = false;
|
optionsMenuOpen = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,8 +212,6 @@ class Toolbar {
|
||||||
};
|
};
|
||||||
static NativeFilePicker nativeFilePicker;
|
static NativeFilePicker nativeFilePicker;
|
||||||
|
|
||||||
std::optional<unsigned> keybindWaiting;
|
|
||||||
|
|
||||||
std::unique_ptr<skia::textlayout::Paragraph> build_paragraph_from_chat_message(const ChatMessage& message, float alpha);
|
std::unique_ptr<skia::textlayout::Paragraph> build_paragraph_from_chat_message(const ChatMessage& message, float alpha);
|
||||||
|
|
||||||
void load_icons_at(const std::filesystem::path& pathToLoad);
|
void load_icons_at(const std::filesystem::path& pathToLoad);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue