aboutsummaryrefslogtreecommitdiff
path: root/src/utility.h
Commit message (Expand)AuthorAge
* Collected and moved existing camera infrastructure from game.cpp to camera.cp...Kahrl2011-09-08
* Fix byte count in serialization of "F1000"Perttu Ahola2011-08-22
* Let Settings accept a const char* directlyGiuseppe Bilotta2011-08-13
* Always return from non-void functionsGiuseppe Bilotta2011-08-08
* mapgen stuffPerttu Ahola2011-06-25
* Reduced the CPU usage of the sent block selector algorithmPerttu Ahola2011-05-31
* player passwords and privileges in world/auth.txtPerttu Ahola2011-05-29
* Added the ability to change your password (via pause menu)Ciaran Gultnieks2011-05-22
* Preliminary "active block" stuff + set up test code to grow grass.Perttu Ahola2011-05-22
* Cleaned networking code a bit (had this one on the to-do list for like 4 mont...Perttu Ahola2011-05-21
* All textures are are now searched first from the directory specified by the t...Perttu Ahola2011-05-21
* put the wstring stoi too in the ignore-on-vc2010 #ifPerttu Ahola2011-05-19
* (hopefully) fixed stoi/stof compile problems on vc2010Perttu Ahola2011-05-18
* Improved server commands and added player permissions.Ciaran Gultnieks2011-05-16
* Fixed a temporary solution of server shutting down to an assert(0) when a too...Perttu Ahola2011-05-03
* made proper skyboxes for dawn/evening and nightPerttu Ahola2011-04-29
* Removed IrrlichtWrapperPerttu Ahola2011-04-22
* Some work-in-progress in hp and mobs and a frightening amount of random fixes.Perttu Ahola2011-04-21
* Fixed some problems with crafting and inventoryPerttu Ahola2011-04-11
* fixed warnings reported by cppcheckPerttu Ahola2011-04-11
* fixed the object update interval thingyPerttu Ahola2011-04-10
* better support for old mapsPerttu Ahola2011-04-10
* implemented rats in new system to verify that it worksPerttu Ahola2011-04-10
* new object systemPerttu Ahola2011-04-10
* Made a proper queued thread to client for handling some block mesh updates. A...Perttu Ahola2011-04-04
* Modified block mesh generation to have clearer input and output. Instead of b...Perttu Ahola2011-04-03
* commit before some radical changesPerttu Ahola2011-04-02
* A third try on terrain generation. No trees yet.Perttu Ahola2011-02-28
* mainly work on object scripting apiPerttu Ahola2011-02-23
* removed an old commentPerttu Ahola2011-02-23
* Fixed insufficient error handling in narrow_to_wide, which caused a crash if ...Perttu Ahola2011-02-23
* preliminary lua scripting framework for objectsPerttu Ahola2011-02-21
* Temporary commit; lots of test code and stuffPerttu Ahola2011-02-21
* Ctrl+C handling on POSIX, some commands for server and other tweakingPerttu Ahola2011-02-15
* hopefully a fix for the majority of the windows 7 problems - thanks to zerochenPerttu Ahola2011-02-12
* more stuff...Perttu Ahola2011-02-11
* fully working i guessPerttu Ahola2011-02-11
* new texture stuff quite workingPerttu Ahola2011-02-11
* bug-fixin'Perttu Ahola2011-02-08
* mapgen tweakingPerttu Ahola2011-02-06
* mapgen stuffPerttu Ahola2011-02-05
* all kinds of tweaking and fixingPerttu Ahola2011-02-04
* some generation-time mud flow tweakingPerttu Ahola2011-02-03
* This map generator is starting to look pretty good now... also, disabled load...Perttu Ahola2011-02-01
* partly working chunk-based map generator (doesn't save properly, spawn is pre...Perttu Ahola2011-02-01
* map generation framework under development... not quite operational at this p...Perttu Ahola2011-01-30
* Commented out some debug output of class SettingsPerttu Ahola2011-01-29
* Now texture handling is fast. Also now players are saved on disk.Perttu Ahola2011-01-28
* backing up some stuffPerttu Ahola2011-01-26
* Reworked texture, material, mineral and whatever handlingPerttu Ahola2011-01-26
href='#n451'>451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
/*
 Minetest-c55
 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();
	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;
}