mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Fix GUIKeyChangeMenu so that '/' can be inserted on a finnish keyboard
This commit is contained in:
parent
3e7957512b
commit
5194505407
@ -60,6 +60,7 @@ GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
|
|||||||
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
|
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
|
||||||
GUIModalMenu(env, parent, id, menumgr)
|
GUIModalMenu(env, parent, id, menumgr)
|
||||||
{
|
{
|
||||||
|
shift_down = false;
|
||||||
activeKey = -1;
|
activeKey = -1;
|
||||||
this->key_used_text = NULL;
|
this->key_used_text = NULL;
|
||||||
init_keys();
|
init_keys();
|
||||||
@ -204,7 +205,15 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
|
|||||||
&& event.KeyInput.PressedDown)
|
&& event.KeyInput.PressedDown)
|
||||||
{
|
{
|
||||||
changeCtype("");
|
changeCtype("");
|
||||||
KeyPress kp(event.KeyInput);
|
bool prefer_character = shift_down;
|
||||||
|
KeyPress kp(event.KeyInput, prefer_character);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
// Remove Key already in use message
|
// Remove Key already in use message
|
||||||
if(this->key_used_text)
|
if(this->key_used_text)
|
||||||
@ -240,8 +249,14 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
|
|||||||
this->key_used.push_back(kp);
|
this->key_used.push_back(kp);
|
||||||
|
|
||||||
changeCtype("C");
|
changeCtype("C");
|
||||||
activeKey = -1;
|
// Allow characters made with shift
|
||||||
return true;
|
if(shift_went_down){
|
||||||
|
shift_down = true;
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
activeKey = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.EventType == EET_GUI_EVENT)
|
if (event.EventType == EET_GUI_EVENT)
|
||||||
@ -287,6 +302,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
|
|||||||
assert(k);
|
assert(k);
|
||||||
|
|
||||||
resetMenu();
|
resetMenu();
|
||||||
|
shift_down = false;
|
||||||
activeKey = event.GUIEvent.Caller->getID();
|
activeKey = event.GUIEvent.Caller->getID();
|
||||||
k->button->setText(wgettext("press key"));
|
k->button->setText(wgettext("press key"));
|
||||||
this->key_used.erase(std::remove(this->key_used.begin(),
|
this->key_used.erase(std::remove(this->key_used.begin(),
|
||||||
|
@ -66,6 +66,8 @@ private:
|
|||||||
|
|
||||||
void add_key(int id, std::string setting_name, std::string button_name);
|
void add_key(int id, std::string setting_name, std::string button_name);
|
||||||
|
|
||||||
|
bool shift_down;
|
||||||
|
|
||||||
s32 activeKey;
|
s32 activeKey;
|
||||||
|
|
||||||
std::vector<KeyPress> key_used;
|
std::vector<KeyPress> key_used;
|
||||||
|
@ -288,16 +288,27 @@ KeyPress::KeyPress(const char *name)
|
|||||||
m_name = name[0];
|
m_name = name[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyPress::KeyPress(const irr::SEvent::SKeyInput &in)
|
KeyPress::KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character)
|
||||||
{
|
{
|
||||||
Key = in.Key;
|
Key = in.Key;
|
||||||
Char = in.Char;
|
Char = in.Char;
|
||||||
|
|
||||||
|
if(prefer_character){
|
||||||
|
m_name.resize(MB_CUR_MAX+1, '\0');
|
||||||
|
int written = wctomb(&m_name[0], Char);
|
||||||
|
if(written > 0){
|
||||||
|
infostream<<"KeyPress: Preferring character for "<<m_name<<std::endl;
|
||||||
|
Key = irr::KEY_KEY_CODES_COUNT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (valid_kcode(Key)) {
|
if (valid_kcode(Key)) {
|
||||||
m_name = KeyNames[Key];
|
m_name = KeyNames[Key];
|
||||||
} else {
|
} else {
|
||||||
m_name.resize(MB_CUR_MAX+1, '\0');
|
m_name.resize(MB_CUR_MAX+1, '\0');
|
||||||
int written = wctomb(&m_name[0], Char);
|
int written = wctomb(&m_name[0], Char);
|
||||||
if(written >= 0){
|
if(written < 0){
|
||||||
std::string hexstr = hex_encode((const char*)&Char, sizeof(Char));
|
std::string hexstr = hex_encode((const char*)&Char, sizeof(Char));
|
||||||
errorstream<<"KeyPress: Unexpected multibyte character "<<hexstr<<std::endl;
|
errorstream<<"KeyPress: Unexpected multibyte character "<<hexstr<<std::endl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
KeyPress();
|
KeyPress();
|
||||||
KeyPress(const char *name);
|
KeyPress(const char *name);
|
||||||
|
|
||||||
KeyPress(const irr::SEvent::SKeyInput &in);
|
KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character=false);
|
||||||
|
|
||||||
bool operator==(const KeyPress &o) const
|
bool operator==(const KeyPress &o) const
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user