added new submenu for key assignment

configwriting/saving isn't complete and will break your config if you use fancy keys
This commit is contained in:
teddydestodes 2011-06-01 19:44:07 +02:00
parent 9b6b4b65f8
commit 6434f64ab4
8 changed files with 913 additions and 103 deletions

View File

@ -100,6 +100,7 @@ set(minetest_SRCS
clientobject.cpp
guiFurnaceMenu.cpp
guiMainMenu.cpp
guiKeyChangeMenu.cpp
guiMessageMenu.cpp
guiTextInputMenu.cpp
guiInventoryMenu.cpp

598
src/guiKeyChangeMenu.cpp Normal file
View File

@ -0,0 +1,598 @@
/*
Minetest-delta
Copyright (C) 2010-11 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2011 Ciaran Gultnieks <ciaran@ciarang.com>
Copyright (C) 2011 teddydestodes <derkomtur@schattengang.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "guiKeyChangeMenu.h"
#include "debug.h"
#include "serialization.h"
#include "keycode.h"
#include "main.h"
#include <string>
GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
GUIModalMenu(env, parent, id, menumgr)
{
activeKey = -1;
init_keys();
}
GUIKeyChangeMenu::~GUIKeyChangeMenu()
{
removeChildren();
}
void GUIKeyChangeMenu::removeChildren()
{
const core::list<gui::IGUIElement*> &children = getChildren();
core::list<gui::IGUIElement*> children_copy;
for (core::list<gui::IGUIElement*>::ConstIterator i = children.begin(); i
!= children.end(); i++)
{
children_copy.push_back(*i);
}
for (core::list<gui::IGUIElement*>::Iterator i = children_copy.begin(); i
!= children_copy.end(); i++)
{
(*i)->remove();
}
}
void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
{
/*
Remove stuff
*/
removeChildren();
/*
Calculate new sizes and positions
*/
v2s32 size(620, 430);
core::rect < s32 > rect(screensize.X / 2 - size.X / 2,
screensize.Y / 2 - size.Y / 2, screensize.X / 2 + size.X / 2,
screensize.Y / 2 + size.Y / 2);
DesiredRect = rect;
recalculateAbsolutePosition(false);
v2s32 topleft(0, 0);
{
core::rect < s32 > rect(0, 0, 125, 20);
rect += topleft + v2s32(25, 3);
const wchar_t *text = L"KEYBINDINGS";
//gui::IGUIStaticText *t =
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
v2s32 offset(25, 40);
// buttons
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Forward";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->forward = Environment->addButton(rect, this,
GUI_ID_KEY_FORWARD_BUTTON,
narrow_to_wide(KeyNames[key_forward]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Backward";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->backward = Environment->addButton(rect, this,
GUI_ID_KEY_BACKWARD_BUTTON,
narrow_to_wide(KeyNames[key_backward]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Left";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->left = Environment->addButton(rect, this, GUI_ID_KEY_LEFT_BUTTON,
narrow_to_wide(KeyNames[key_left]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Right";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->right = Environment->addButton(rect, this,
GUI_ID_KEY_RIGHT_BUTTON,
narrow_to_wide(KeyNames[key_right]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Use";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->use = Environment->addButton(rect, this, GUI_ID_KEY_USE_BUTTON,
narrow_to_wide(KeyNames[key_use]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Sneak";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->sneak = Environment->addButton(rect, this,
GUI_ID_KEY_SNEAK_BUTTON,
narrow_to_wide(KeyNames[key_sneak]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Jump";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->jump = Environment->addButton(rect, this, GUI_ID_KEY_JUMP_BUTTON,
narrow_to_wide(KeyNames[key_jump]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Inventory";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->inventory = Environment->addButton(rect, this,
GUI_ID_KEY_INVENTORY_BUTTON,
narrow_to_wide(KeyNames[key_inventory]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Chat";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->chat = Environment->addButton(rect, this, GUI_ID_KEY_CHAT_BUTTON,
narrow_to_wide(KeyNames[key_chat]).c_str());
}
//next col
offset = v2s32(250, 40);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Toggle fly";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->fly = Environment->addButton(rect, this, GUI_ID_KEY_FLY_BUTTON,
narrow_to_wide(KeyNames[key_fly]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Toggle fast";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->fast = Environment->addButton(rect, this, GUI_ID_KEY_FAST_BUTTON,
narrow_to_wide(KeyNames[key_fast]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Range select";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->range = Environment->addButton(rect, this,
GUI_ID_KEY_RANGE_BUTTON,
narrow_to_wide(KeyNames[key_range]).c_str());
}
offset += v2s32(0, 25);
{
core::rect < s32 > rect(0, 0, 100, 20);
rect += topleft + v2s32(offset.X, offset.Y);
const wchar_t *text = L"Print stacks";
Environment->addStaticText(text, rect, false, true, this, -1);
//t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
this->dump = Environment->addButton(rect, this, GUI_ID_KEY_DUMP_BUTTON,
narrow_to_wide(KeyNames[key_dump]).c_str());
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(size.X - 100 - 20, size.Y - 40);
Environment->addButton(rect, this, GUI_ID_BACK_BUTTON, L"Save");
}
{
core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(size.X - 100 - 20 - 100 - 20, size.Y - 40);
Environment->addButton(rect, this, GUI_ID_ABORT_BUTTON, L"Cancel");
}
}
void GUIKeyChangeMenu::drawMenu()
{
gui::IGUISkin* skin = Environment->getSkin();
if (!skin)
return;
video::IVideoDriver* driver = Environment->getVideoDriver();
video::SColor bgcolor(140, 0, 0, 0);
{
core::rect < s32 > rect(0, 0, 620, 620);
rect += AbsoluteRect.UpperLeftCorner;
driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
}
gui::IGUIElement::draw();
}
bool GUIKeyChangeMenu::acceptInput()
{
g_settings.set("keymap_forward", keycode_to_keyname(key_forward));
g_settings.set("keymap_backward", keycode_to_keyname(key_backward));
g_settings.set("keymap_left", keycode_to_keyname(key_left));
g_settings.set("keymap_right", keycode_to_keyname(key_right));
g_settings.set("keymap_jump", keycode_to_keyname(key_jump));
g_settings.set("keymap_sneak", keycode_to_keyname(key_sneak));
g_settings.set("keymap_inventory", keycode_to_keyname(key_inventory));
g_settings.set("keymap_chat", keycode_to_keyname(key_chat));
g_settings.set("keymap_rangeselect", keycode_to_keyname(key_range));
g_settings.set("keymap_freemove", keycode_to_keyname(key_fly));
g_settings.set("keymap_fastmove", keycode_to_keyname(key_fast));
g_settings.set("keymap_special1", keycode_to_keyname(key_use));
g_settings.set("keymap_print_debug_stacks", keycode_to_keyname(key_dump));
//clearKeyCache(); Y U NO SCOPE?!
return true;
}
void GUIKeyChangeMenu::init_keys()
{
key_forward = getKeySetting("keymap_forward");
key_backward = getKeySetting("keymap_backward");
key_left = getKeySetting("keymap_left");
key_right = getKeySetting("keymap_right");
key_jump = getKeySetting("keymap_jump");
key_sneak = getKeySetting("keymap_sneak");
key_inventory = getKeySetting("keymap_inventory");
key_chat = getKeySetting("keymap_chat");
key_range = getKeySetting("keymap_rangeselect");
key_fly = getKeySetting("keymap_freemove");
key_fast = getKeySetting("keymap_fastmove");
key_use = getKeySetting("keymap_special1");
key_dump = getKeySetting("keymap_print_debug_stacks");
}
bool GUIKeyChangeMenu::resetMenu()
{
if (activeKey >= 0)
{
switch (activeKey)
{
case GUI_ID_KEY_FORWARD_BUTTON:
this->forward->setText(
narrow_to_wide(KeyNames[key_forward]).c_str());
break;
case GUI_ID_KEY_BACKWARD_BUTTON:
this->backward->setText(
narrow_to_wide(KeyNames[key_backward]).c_str());
break;
case GUI_ID_KEY_LEFT_BUTTON:
this->left->setText(narrow_to_wide(KeyNames[key_left]).c_str());
break;
case GUI_ID_KEY_RIGHT_BUTTON:
this->right->setText(narrow_to_wide(KeyNames[key_right]).c_str());
break;
case GUI_ID_KEY_JUMP_BUTTON:
this->jump->setText(narrow_to_wide(KeyNames[key_jump]).c_str());
break;
case GUI_ID_KEY_SNEAK_BUTTON:
this->sneak->setText(narrow_to_wide(KeyNames[key_sneak]).c_str());
break;
case GUI_ID_KEY_INVENTORY_BUTTON:
this->inventory->setText(
narrow_to_wide(KeyNames[key_inventory]).c_str());
break;
case GUI_ID_KEY_CHAT_BUTTON:
this->chat->setText(narrow_to_wide(KeyNames[key_chat]).c_str());
break;
case GUI_ID_KEY_RANGE_BUTTON:
this->range->setText(narrow_to_wide(KeyNames[key_range]).c_str());
break;
case GUI_ID_KEY_FLY_BUTTON:
this->fly->setText(narrow_to_wide(KeyNames[key_fly]).c_str());
break;
case GUI_ID_KEY_FAST_BUTTON:
this->fast->setText(narrow_to_wide(KeyNames[key_fast]).c_str());
break;
case GUI_ID_KEY_USE_BUTTON:
this->use->setText(narrow_to_wide(KeyNames[key_use]).c_str());
break;
case GUI_ID_KEY_DUMP_BUTTON:
this->dump->setText(narrow_to_wide(KeyNames[key_dump]).c_str());
break;
}
activeKey = -1;
return false;
}
return true;
}
bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT && activeKey >= 0
&& event.KeyInput.PressedDown)
{
if (activeKey == GUI_ID_KEY_FORWARD_BUTTON)
{
this->forward->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_forward = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_BACKWARD_BUTTON)
{
this->backward->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_backward = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_LEFT_BUTTON)
{
this->left->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_left = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_RIGHT_BUTTON)
{
this->right->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_right = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_JUMP_BUTTON)
{
this->jump->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_jump = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_SNEAK_BUTTON)
{
this->sneak->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_sneak = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_INVENTORY_BUTTON)
{
this->inventory->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_inventory = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_CHAT_BUTTON)
{
this->chat->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_chat = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_RANGE_BUTTON)
{
this->range->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_range = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_FLY_BUTTON)
{
this->fly->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_fly = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_FAST_BUTTON)
{
this->fast->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_fast = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_USE_BUTTON)
{
this->use->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_use = event.KeyInput.Key;
}
else if (activeKey == GUI_ID_KEY_DUMP_BUTTON)
{
this->dump->setText(
narrow_to_wide(KeyNames[event.KeyInput.Key]).c_str());
this->key_dump = event.KeyInput.Key;
}
activeKey = -1;
return true;
}
if (event.EventType == EET_GUI_EVENT)
{
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
&& isVisible())
{
if (!canTakeFocus(event.GUIEvent.Element))
{
dstream << "GUIMainMenu: Not allowing focus change."
<< std::endl;
// Returning true disables focus change
return true;
}
}
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
{
switch (event.GUIEvent.Caller->getID())
{
case GUI_ID_BACK_BUTTON: //back
acceptInput();
quitMenu();
return true;
case GUI_ID_ABORT_BUTTON: //abort
quitMenu();
return true;
case GUI_ID_KEY_FORWARD_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->forward->setText(L"press Key");
break;
case GUI_ID_KEY_BACKWARD_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->backward->setText(L"press Key");
break;
case GUI_ID_KEY_LEFT_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->left->setText(L"press Key");
break;
case GUI_ID_KEY_RIGHT_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->right->setText(L"press Key");
break;
case GUI_ID_KEY_USE_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->use->setText(L"press Key");
break;
case GUI_ID_KEY_FLY_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->fly->setText(L"press Key");
break;
case GUI_ID_KEY_FAST_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->fast->setText(L"press Key");
break;
case GUI_ID_KEY_JUMP_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->jump->setText(L"press Key");
break;
case GUI_ID_KEY_CHAT_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->chat->setText(L"press Key");
break;
case GUI_ID_KEY_SNEAK_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->sneak->setText(L"press Key");
break;
case GUI_ID_KEY_INVENTORY_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->inventory->setText(L"press Key");
break;
case GUI_ID_KEY_DUMP_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->dump->setText(L"press Key");
break;
case GUI_ID_KEY_RANGE_BUTTON:
resetMenu();
activeKey = event.GUIEvent.Caller->getID();
this->range->setText(L"press Key");
break;
}
//Buttons
}
}
return Parent ? Parent->OnEvent(event) : false;
}

133
src/guiKeyChangeMenu.h Normal file
View File

@ -0,0 +1,133 @@
/*
Minetest-delta
Copyright (C) 2010-11 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2011 Ciaran Gultnieks <ciaran@ciarang.com>
Copyright (C) 2011 teddydestodes <derkomtur@schattengang.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GUIKEYCHANGEMENU_HEADER
#define GUIKEYCHANGEMENU_HEADER
#include "common_irrlicht.h"
#include "utility.h"
#include "modalMenu.h"
#include "client.h"
#include <string>
static const char *KeyNames[] =
{ "-", "Left Button", "Right Button", "Cancel", "Middle Button", "X Button 1",
"X Button 2", "-", "Back", "Tab", "-", "-", "Clear", "Return", "-",
"-", "Shift", "Control", "Menu", "Pause", "Capital", "Kana", "-",
"Junja", "Final", "Kanji", "-", "Escape", "Convert", "Nonconvert",
"Accept", "Mode Change", "Space", "Priot", "Next", "End", "Home",
"Left", "Up", "Right", "Down", "Select", "Print", "Execute",
"Snapshot", "Insert", "Delete", "Help", "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "-", "-", "-", "-", "-", "-", "-", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Left Windows",
"Right Windows", "Apps", "-", "Sleep", "Numpad 0", "Numpad 1",
"Numpad 2", "Numpad 3", "Numpad 4", "Numpad 5", "Numpad 6", "Numpad 7",
"Numpad 8", "Numpad 9", "Numpad *", "Numpad +", "Numpad /", "Numpad -",
"Numpad .", "Numpad /", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
"F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18",
"F19", "F20", "F21", "F22", "F23", "F24", "-", "-", "-", "-", "-", "-",
"-", "-", "Num Lock", "Scroll Lock", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "Left Shift", "Right Shight",
"Left Control", "Right Control", "Left Menu", "Right Menu", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "Plus", "Comma", "Minus", "Period", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "Attn", "CrSel",
"ExSel", "Erase OEF", "Play", "Zoom", "PA1", "OEM Clear", "-" };
enum
{
GUI_ID_BACK_BUTTON = 101, GUI_ID_ABORT_BUTTON, GUI_ID_SCROLL_BAR,
//buttons
GUI_ID_KEY_FORWARD_BUTTON,
GUI_ID_KEY_BACKWARD_BUTTON,
GUI_ID_KEY_LEFT_BUTTON,
GUI_ID_KEY_RIGHT_BUTTON,
GUI_ID_KEY_USE_BUTTON,
GUI_ID_KEY_FLY_BUTTON,
GUI_ID_KEY_FAST_BUTTON,
GUI_ID_KEY_JUMP_BUTTON,
GUI_ID_KEY_CHAT_BUTTON,
GUI_ID_KEY_SNEAK_BUTTON,
GUI_ID_KEY_INVENTORY_BUTTON,
GUI_ID_KEY_DUMP_BUTTON,
GUI_ID_KEY_RANGE_BUTTON
};
class GUIKeyChangeMenu: public GUIModalMenu
{
public:
GUIKeyChangeMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent,
s32 id, IMenuManager *menumgr);
~GUIKeyChangeMenu();
void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);
void drawMenu();
bool acceptInput();
bool OnEvent(const SEvent& event);
private:
void init_keys();
bool resetMenu();
gui::IGUIButton *forward;
gui::IGUIButton *backward;
gui::IGUIButton *left;
gui::IGUIButton *right;
gui::IGUIButton *use;
gui::IGUIButton *sneak;
gui::IGUIButton *jump;
gui::IGUIButton *inventory;
gui::IGUIButton *fly;
gui::IGUIButton *fast;
gui::IGUIButton *range;
gui::IGUIButton *dump;
gui::IGUIButton *chat;
u32 activeKey;
u32 key_forward;
u32 key_backward;
u32 key_left;
u32 key_right;
u32 key_use;
u32 key_sneak;
u32 key_jump;
u32 key_inventory;
u32 key_fly;
u32 key_fast;
u32 key_range;
u32 key_chat;
u32 key_dump;
};
#endif

View File

@ -18,10 +18,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "guiMainMenu.h"
#include "guiKeyChangeMenu.h"
#include "debug.h"
#include "serialization.h"
#include <string>
GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
@ -34,6 +37,10 @@ GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
m_gamecallback(gamecallback)
{
assert(m_data);
this->env = env;
this->parent = parent;
this->id = id;
this->menumgr = menumgr;
}
GUIMainMenu::~GUIMainMenu()
@ -70,35 +77,35 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
// Client options
{
gui::IGUIElement *e = getElementFromId(258);
gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
if(e != NULL)
text_name = e->getText();
else
text_name = m_data->name;
}
{
gui::IGUIElement *e = getElementFromId(256);
gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
if(e != NULL)
text_address = e->getText();
else
text_address = m_data->address;
}
{
gui::IGUIElement *e = getElementFromId(257);
gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
if(e != NULL)
text_port = e->getText();
else
text_port = m_data->port;
}
{
gui::IGUIElement *e = getElementFromId(263);
gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
else
fancy_trees = m_data->fancy_trees;
}
{
gui::IGUIElement *e = getElementFromId(262);
gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
else
@ -107,14 +114,14 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
// Server options
{
gui::IGUIElement *e = getElementFromId(259);
gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
else
creative_mode = m_data->creative_mode;
}
{
gui::IGUIElement *e = getElementFromId(261);
gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
else
@ -175,7 +182,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
core::rect<s32> rect(0, 0, 230, 30);
rect += topleft_client + v2s32(160, 50);
gui::IGUIElement *e =
Environment->addEditBox(text_name.c_str(), rect, true, this, 258);
Environment->addEditBox(text_name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
if(text_name == L"")
Environment->setFocus(e);
}
@ -198,7 +205,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
core::rect<s32> rect(0, 0, 230, 30);
rect += topleft_client + v2s32(160, 100);
gui::IGUIElement *e =
Environment->addEditBox(text_address.c_str(), rect, true, this, 256);
Environment->addEditBox(text_address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT);
if(text_name != L"")
Environment->setFocus(e);
}
@ -206,7 +213,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
core::rect<s32> rect(0, 0, 120, 30);
//rect += topleft_client + v2s32(160+250+20, 125);
rect += topleft_client + v2s32(size_client.X-60-100, 100);
Environment->addEditBox(text_port.c_str(), rect, true, this, 257);
Environment->addEditBox(text_port.c_str(), rect, true, this, GUI_ID_PORT_INPUT);
}
{
core::rect<s32> rect(0, 0, 400, 20);
@ -217,13 +224,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
{
core::rect<s32> rect(0, 0, 250, 30);
rect += topleft_client + v2s32(35, 150);
Environment->addCheckBox(fancy_trees, rect, this, 263,
Environment->addCheckBox(fancy_trees, rect, this, GUI_ID_FANCYTREE_CB,
L"Fancy trees");
}
{
core::rect<s32> rect(0, 0, 250, 30);
rect += topleft_client + v2s32(35, 150+30);
Environment->addCheckBox(smooth_lighting, rect, this, 262,
Environment->addCheckBox(smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB,
L"Smooth Lighting");
}
// Start game button
@ -231,9 +238,16 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
core::rect<s32> rect(0, 0, 180, 30);
//rect += topleft_client + v2s32(size_client.X/2-180/2, 225-30/2);
rect += topleft_client + v2s32(size_client.X-180-40, 150+25);
Environment->addButton(rect, this, 257, L"Start Game / Connect");
Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, L"Start Game / Connect");
}
// Key change button
{
core::rect<s32> rect(0, 0, 100, 30);
//rect += topleft_client + v2s32(size_client.X/2-180/2, 225-30/2);
rect += topleft_client + v2s32(size_client.X-180-40-100-20, 150+25);
Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON, L"Change keys");
}
/*
Server section
*/
@ -254,19 +268,19 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
{
core::rect<s32> rect(0, 0, 250, 30);
rect += topleft_server + v2s32(35, 30);
Environment->addCheckBox(creative_mode, rect, this, 259, L"Creative Mode");
Environment->addCheckBox(creative_mode, rect, this, GUI_ID_CREATIVE_CB, L"Creative Mode");
}
{
core::rect<s32> rect(0, 0, 250, 30);
rect += topleft_server + v2s32(35, 60);
Environment->addCheckBox(enable_damage, rect, this, 261, L"Enable Damage");
Environment->addCheckBox(enable_damage, rect, this, GUI_ID_DAMAGE_CB, L"Enable Damage");
}
// Map delete button
{
core::rect<s32> rect(0, 0, 130, 30);
//rect += topleft_server + v2s32(size_server.X-40-130, 100+25);
rect += topleft_server + v2s32(40, 100+25);
Environment->addButton(rect, this, 260, L"Delete map");
Environment->addButton(rect, this, GUI_ID_DELETE_MAP_BUTTON, L"Delete map");
}
}
@ -300,7 +314,7 @@ void GUIMainMenu::drawMenu()
void GUIMainMenu::acceptInput()
{
{
gui::IGUIElement *e = getElementFromId(258);
gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
if(e != NULL)
m_data->name = e->getText();
}
@ -310,32 +324,32 @@ void GUIMainMenu::acceptInput()
m_data->password = e->getText();
}
{
gui::IGUIElement *e = getElementFromId(256);
gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
if(e != NULL)
m_data->address = e->getText();
}
{
gui::IGUIElement *e = getElementFromId(257);
gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
if(e != NULL)
m_data->port = e->getText();
}
{
gui::IGUIElement *e = getElementFromId(259);
gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
}
{
gui::IGUIElement *e = getElementFromId(261);
gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
}
{
gui::IGUIElement *e = getElementFromId(262);
gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
}
{
gui::IGUIElement *e = getElementFromId(263);
gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
}
@ -377,11 +391,16 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
{
switch(event.GUIEvent.Caller->getID())
{
case 257: // Start game
case GUI_ID_JOIN_GAME_BUTTON: // Start game
acceptInput();
quitMenu();
return true;
case 260: // Delete map
case GUI_ID_CHANGE_KEYS_BUTTON: {
GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
kmenu->drop();
return true;
}
case GUI_ID_DELETE_MAP_BUTTON: // Delete map
// Don't accept input data, just set deletion request
m_data->delete_map = true;
m_accepted = true;
@ -393,7 +412,7 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
{
switch(event.GUIEvent.Caller->getID())
{
case 256: case 257: case 258: case 264:
case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
acceptInput();
quitMenu();
return true;

View File

@ -1,21 +1,21 @@
/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GUIMAINMENU_HEADER
#define GUIMAINMENU_HEADER
@ -27,21 +27,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// For IGameCallback
#include "guiPauseMenu.h"
enum
{
GUI_ID_QUIT_BUTTON = 101,
GUI_ID_NAME_INPUT,
GUI_ID_ADDRESS_INPUT,
GUI_ID_PORT_INPUT,
GUI_ID_FANCYTREE_CB,
GUI_ID_SMOOTH_LIGHTING_CB,
GUI_ID_DAMAGE_CB,
GUI_ID_CREATIVE_CB,
GUI_ID_JOIN_GAME_BUTTON,
GUI_ID_CHANGE_KEYS_BUTTON,
GUI_ID_DELETE_MAP_BUTTON
};
struct MainMenuData
{
MainMenuData():
MainMenuData() :
// Client opts
fancy_trees(false),
smooth_lighting(false),
// Server opts
creative_mode(false),
enable_damage(false),
// Actions
delete_map(false)
{}
fancy_trees(false), smooth_lighting(false),
// Server opts
creative_mode(false), enable_damage(false),
// Actions
delete_map(false)
{
}
// These are in the native format of the gui elements
// Client options
std::wstring address;
std::wstring port;
@ -56,20 +70,23 @@ struct MainMenuData
bool delete_map;
};
class GUIMainMenu : public GUIModalMenu
class GUIMainMenu: public GUIModalMenu
{
public:
GUIMainMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
MainMenuData *data,
GUIMainMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, MainMenuData *data,
IGameCallback *gamecallback);
~GUIMainMenu();
gui::IGUIEnvironment* env;
gui::IGUIElement* parent;
s32 id;
IMenuManager *menumgr;
void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);
void drawMenu();
@ -82,7 +99,7 @@ public:
}
bool OnEvent(const SEvent& event);
private:
MainMenuData *m_data;
bool m_accepted;

View File

@ -1,21 +1,21 @@
/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GUIMESSAGEMENU_HEADER
#define GUIMESSAGEMENU_HEADER
@ -25,19 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "utility.h"
#include <string>
class GUIMessageMenu : public GUIModalMenu
class GUIMessageMenu: public GUIModalMenu
{
public:
GUIMessageMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
std::wstring message_text);
GUIMessageMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, std::wstring message_text);
~GUIMessageMenu();
void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);
void drawMenu();
@ -45,13 +43,13 @@ public:
bool OnEvent(const SEvent& event);
/*
true = ok'd
*/
true = ok'd
*/
bool getStatus()
{
return m_status;
}
private:
std::wstring m_message_text;
bool m_status;

View File

@ -1,25 +1,24 @@
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "keycode.h"
#include "main.h" // For g_settings
#define CHECKKEY(x){if(strcmp(name, #x)==0) return irr::x;}
irr::EKEY_CODE keyname_to_keycode(const char *name)
@ -171,9 +170,48 @@ irr::EKEY_CODE keyname_to_keycode(const char *name)
return irr::KEY_KEY_CODES_COUNT;
}
static const char *KeyNames[] =
{ "-", "KEY_LBUTTON", "KEY_RBUTTON", "Cancel", "Middle Button", "X Button 1",
"X Button 2", "-", "Back", "Tab", "-", "-", "Clear", "Return", "-",
"-", "KEY_SHIFT", "Control", "Menu", "Pause", "Capital", "Kana", "-",
"Junja", "Final", "Kanji", "-", "Escape", "Convert", "Nonconvert",
"Accept", "Mode Change", "KEY_SPACE", "Priot", "Next", "KEY_END",
"KEY_HOME", "Left", "Up", "Right", "Down", "Select", "KEY_PRINT",
"Execute", "Snapshot", "Insert", "Delete", "Help", "KEY_KEY_0",
"KEY_KEY_1", "KEY_KEY_2", "KEY_KEY_3", "KEY_KEY_4", "KEY_KEY_5",
"KEY_KEY_6", "KEY_KEY_7", "KEY_KEY_8", "KEY_KEY_9", "-", "-", "-", "-",
"-", "-", "-", "KEY_KEY_A", "KEY_KEY_B", "KEY_KEY_C", "KEY_KEY_D",
"KEY_KEY_E", "KEY_KEY_F", "KEY_KEY_G", "KEY_KEY_H", "KEY_KEY_I",
"KEY_KEY_J", "KEY_KEY_K", "KEY_KEY_L", "KEY_KEY_M", "KEY_KEY_N",
"KEY_KEY_O", "KEY_KEY_P", "KEY_KEY_Q", "KEY_KEY_R", "KEY_KEY_S",
"KEY_KEY_T", "KEY_KEY_U", "KEY_KEY_V", "KEY_KEY_W", "KEY_KEY_X",
"KEY_KEY_Y", "KEY_KEY_Z", "Left Windows", "Right Windows", "Apps", "-",
"Sleep", "KEY_NUMPAD0", "KEY_NUMPAD1", "KEY_NUMPAD2", "KEY_NUMPAD3",
"KEY_NUMPAD4", "KEY_NUMPAD5", "KEY_NUMPAD6", "KEY_NUMPAD7",
"KEY_NUMPAD8", "KEY_NUMPAD9", "Numpad *", "Numpad +", "Numpad /",
"Numpad -", "Numpad .", "Numpad /", "KEY_F1", "KEY_F2", "KEY_F3",
"KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", "KEY_F9", "KEY_F10",
"KEY_F11", "KEY_F12", "KEY_F13", "KEY_F14", "KEY_F15", "KEY_F16",
"KEY_F17", "KEY_F18", "KEY_F19", "KEY_F20", "KEY_F21", "KEY_F22",
"KEY_F23", "KEY_F24", "-", "-", "-", "-", "-", "-", "-", "-",
"Num Lock", "Scroll Lock", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "KEY_LSHIFT", "KEY_RSHIFT", "Left Control",
"Right Control", "Left Menu", "Right Menu", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "Plus", "Comma", "Minus", "Period", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "Attn", "CrSel", "ExSel",
"Erase OEF", "Play", "Zoom", "PA1", "OEM Clear", "-" };
std::string keycode_to_keyname(s32 keycode)
{
return KeyNames[keycode];
}
/*
Key config
*/
Key config
*/
// A simple cache for quicker lookup
core::map<std::string, irr::EKEY_CODE> g_key_setting_cache;
@ -182,11 +220,15 @@ irr::EKEY_CODE getKeySetting(const char *settingname)
{
core::map<std::string, irr::EKEY_CODE>::Node *n;
n = g_key_setting_cache.find(settingname);
if(n)
if (n)
return n->getValue();
irr::EKEY_CODE c = keyname_to_keycode(g_settings.get(settingname).c_str());
g_key_setting_cache.insert(settingname, c);
return c;
}
void clearKeyCache()
{
g_key_setting_cache.clear();
}

View File

@ -21,11 +21,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define KEYCODE_HEADER
#include "common_irrlicht.h"
#include <string>
irr::EKEY_CODE keyname_to_keycode(const char *name);
// Key configuration getter
irr::EKEY_CODE getKeySetting(const char *settingname);
std::string keycode_to_keyname(s32 keycode);
void clearCache();
#endif