Skip to content

Commit

Permalink
adapt guiKeyChangeMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
y5nw committed Jul 20, 2024
1 parent 21d33a9 commit ce94c62
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/client/keycode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ const std::string KeyPress::sym() const

const std::string KeyPress::name() const
{
if (m_name.empty())
if (m_name.empty() && !has_modifier())
return "";
std::string ret;
if (valid_kcode(Key))
ret = lookup_keykey(Key).LangName;
else
else if (Char != L'\0')
ret = lookup_keychar(Char).LangName;
if (!ret.empty())
ret = strgettext(ret);
Expand Down
10 changes: 10 additions & 0 deletions src/client/keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class KeyPress
|| (Char == o.Char && Key == o.Key);
}

bool has_modifier() const
{
return shift || control;
}

bool valid_base() const
{
return valid_kcode(Key) || Char > 0;
}

int matches(const KeyPress &p) const;

const std::string sym() const;
Expand Down
24 changes: 6 additions & 18 deletions src/gui/guiKeyChangeMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,20 @@ bool GUIKeyChangeMenu::resetMenu()
}
bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT && active_key
&& event.KeyInput.PressedDown) {
if (event.EventType == EET_KEY_INPUT_EVENT && active_key) {
if (!event.KeyInput.PressedDown) {
active_key = nullptr;
return true;
}

bool prefer_character = shift_down;
bool prefer_character = false;
KeyPress kp(event.KeyInput, prefer_character);

if (event.KeyInput.Key == irr::KEY_DELETE)
kp = KeyPress(""); // To erase key settings
else if (event.KeyInput.Key == irr::KEY_ESCAPE)
kp = active_key->key; // Cancel

bool shift_went_down = false;
if(!shift_down &&
(event.KeyInput.Key == irr::KEY_SHIFT ||
event.KeyInput.Key == irr::KEY_LSHIFT ||
event.KeyInput.Key == irr::KEY_RSHIFT))
shift_went_down = true;

// Display Key already in use message
bool key_in_use = false;
if (!kp.sym().empty()) {
Expand Down Expand Up @@ -309,13 +305,6 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
active_key->key = kp;
active_key->button->setText(utf8_to_wide(kp.name()).c_str());

// Allow characters made with shift
if (shift_went_down){
shift_down = true;
return false;
}

active_key = nullptr;
return true;
}
} else if (event.EventType == EET_KEY_INPUT_EVENT && !active_key
Expand Down Expand Up @@ -356,7 +345,6 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
}
FATAL_ERROR_IF(!active_key, "Key setting not found");

shift_down = false;
active_key->button->setText(wstrgettext("press key").c_str());
break;
}
Expand Down
2 changes: 0 additions & 2 deletions src/gui/guiKeyChangeMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class GUIKeyChangeMenu : public GUIModalMenu

void add_key(int id, std::wstring button_name, const std::string &setting_name);

bool shift_down = false;

key_setting *active_key = nullptr;
gui::IGUIStaticText *key_used_text = nullptr;
std::vector<key_setting *> key_settings;
Expand Down

0 comments on commit ce94c62

Please sign in to comment.