From 71532a23200b246f63ed1e0dc3d563bd1184b593 Mon Sep 17 00:00:00 2001 From: Joshua Langley Date: Mon, 16 Jul 2007 15:23:34 +0000 Subject: --- src/game.cpp | 148 +++++++++++++++++--------------- src/gui/button.cpp | 20 +++-- src/gui/button.h | 3 + src/gui/setup.cpp | 11 ++- src/gui/setup_keyboard.cpp | 145 +++++++++++++++++++++++++++++++ src/gui/setup_keyboard.h | 74 ++++++++++++++++ src/keyboardconfig.cpp | 129 ++++++++++++++++++++++++++++ src/keyboardconfig.h | 208 +++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 10 +++ 9 files changed, 671 insertions(+), 77 deletions(-) create mode 100644 src/gui/setup_keyboard.cpp create mode 100644 src/gui/setup_keyboard.h create mode 100644 src/keyboardconfig.cpp create mode 100644 src/keyboardconfig.h (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 54474b1c..eb990e1b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -37,6 +37,7 @@ #include "flooritemmanager.h" #include "graphics.h" #include "joystick.h" +#include "keyboardconfig.h" #include "localplayer.h" #include "log.h" #include "npc.h" @@ -426,6 +427,14 @@ void Game::handleInput() { gcn::Window *requestedWindow = NULL; + if (//setupWindow->isVisible() && + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + { + keyboard.setNewKey((int) event.key.keysym.sym); + keyboard.callbackNewKey(); + keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + return; + } switch (event.key.keysym.sym) { case SDLK_F1: @@ -484,54 +493,7 @@ void Game::handleInput() used = true; } break; - - // Hide certain windows - case SDLK_h: - if (!chatWindow->isFocused()) - { - statusWindow->setVisible(false); - inventoryWindow->setVisible(false); - skillDialog->setVisible(false); - setupWindow->setVisible(false); - equipmentWindow->setVisible(false); - helpWindow->setVisible(false); - debugWindow->setVisible(false); - } - break; - - // Picking up items on the floor - case SDLK_g: - case SDLK_z: - if (!chatWindow->isFocused()) - { - FloorItem *item = floorItemManager->findByCoordinates( - player_node->mX, player_node->mY); - - // If none below the player, try the tile in front of - // the player - if (!item) { - Uint16 x = player_node->mX; - Uint16 y = player_node->mY; - if (player_node->getDirection() & Being::UP) - y--; - if (player_node->getDirection() & Being::DOWN) - y++; - if (player_node->getDirection() & Being::LEFT) - x--; - if (player_node->getDirection() & Being::RIGHT) - x++; - - item = floorItemManager->findByCoordinates(x, y); - } - - if (item) - player_node->pickUp(item); - - used = true; - } - break; - - // Quitting confirmation dialog + // Quitting confirmation dialog case SDLK_ESCAPE: if (!exitConfirm) { exitConfirm = new ConfirmDialog( @@ -545,6 +507,58 @@ void Game::handleInput() break; } + if (keyboard.isEnabled() && !chatWindow->isFocused()) + { + switch (keyboard.getKeyIndex(event.key.keysym.sym)) { + case KeyboardConfig::KEY_PICKUP: + { + FloorItem *item = floorItemManager->findByCoordinates( + player_node->mX, player_node->mY); + + // If none below the player, try the tile in front of + // the player + if (!item) { + Uint16 x = player_node->mX; + Uint16 y = player_node->mY; + if (player_node->getDirection() & Being::UP) + y--; + if (player_node->getDirection() & Being::DOWN) + y++; + if (player_node->getDirection() & Being::LEFT) + x--; + if (player_node->getDirection() & Being::RIGHT) + x++; + + item = floorItemManager->findByCoordinates(x, y); + } + + if (item) + player_node->pickUp(item); + + used = true; + } + break; + case KeyboardConfig::KEY_SIT: + // Player sit action + player_node->toggleSit(); + used = true; + break; + case KeyboardConfig::KEY_HIDE_WINDOWS: + // Hide certain windows + if (!chatWindow->isFocused()) + { + statusWindow->setVisible(false); + inventoryWindow->setVisible(false); + skillDialog->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + } + break; + } + } + if (requestedWindow) { requestedWindow->setVisible(!requestedWindow->isVisible()); @@ -555,18 +569,13 @@ void Game::handleInput() used = true; } + // Keys pressed together with Alt/Meta // Emotions and some internal gui windows if (event.key.keysym.mod & KMOD_ALT) { switch (event.key.keysym.sym) { - case SDLK_s: - // Player sit action - player_node->toggleSit(); - used = true; - break; - case SDLK_p: // Screenshot (picture, hence the p) { @@ -636,41 +645,42 @@ void Game::handleInput() } } // End while - + // If the user is configuring the keys then don't respond. + if (!keyboard.isEnabled()) + { + return; + } // Moving player around if (player_node->mAction != Being::DEAD && current_npc == 0 && !chatWindow->isFocused()) { // Get the state of the keyboard keys - Uint8* keys; - keys = SDL_GetKeyState(NULL); + keyboard.refreshActiveKeys(); Uint16 x = player_node->mX; Uint16 y = player_node->mY; unsigned char direction = 0; // Translate pressed keys to movement and direction - if (keys[SDLK_UP] || keys[SDLK_KP8] || - keys[SDLK_KP7] || keys[SDLK_KP9] || + if ( keyboard.isKeyActive(keyboard.KEY_MOVE_UP) || joystick && joystick->isUp()) { direction |= Being::UP; } - else if (keys[SDLK_DOWN] || keys[SDLK_KP2] || - keys[SDLK_KP1] || keys[SDLK_KP3] || + + else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || joystick && joystick->isDown()) { direction |= Being::DOWN; } - if (keys[SDLK_LEFT] || keys[SDLK_KP4] || - keys[SDLK_KP1] || keys[SDLK_KP7] || + + if ( keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT) || joystick && joystick->isLeft()) { direction |= Being::LEFT; } - else if (keys[SDLK_RIGHT] || keys[SDLK_KP6] || - keys[SDLK_KP3] || keys[SDLK_KP9] || + else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT) || joystick && joystick->isRight()) { direction |= Being::RIGHT; @@ -679,12 +689,11 @@ void Game::handleInput() player_node->setWalkingDir(direction); // Attacking monsters - if (keys[SDLK_LCTRL] || keys[SDLK_RCTRL] || + if ( keyboard.isKeyActive(keyboard.KEY_ATTACK) || joystick && joystick->buttonPressed(0)) { Being *target = NULL; - bool newTarget = keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]; - + bool newTarget = keyboard.isKeyActive(keyboard.KEY_TARGET); // A set target has highest priority if (newTarget || !player_node->getTarget()) { @@ -711,7 +720,8 @@ void Game::handleInput() } // Target the nearest monster if 'a' pressed - if (keys[SDLK_a]) + if ( keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) ) + //if (keys[SDLK_a]) { Being *target = beingManager->findNearestLivingBeing(x, y, 20, Being::MONSTER); diff --git a/src/gui/button.cpp b/src/gui/button.cpp index e607b66a..a9212e83 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -37,10 +37,25 @@ ImageRect Button::button[4]; int Button::mInstances = 0; +Button::Button(): + mIsLogged(false) +{ + init(); +} + Button::Button(const std::string& caption, const std::string &actionEventId, gcn::ActionListener *listener): gcn::Button(caption), mIsLogged(false) +{ + init(); + setActionEventId(actionEventId); + if (listener) { + addActionListener(listener); + } +} + +void Button::init() { setBorderSize(0); @@ -72,12 +87,7 @@ Button::Button(const std::string& caption, const std::string &actionEventId, btn[mode]->decRef(); } } - mInstances++; - setActionEventId(actionEventId); - if (listener) { - addActionListener(listener); - } } Button::~Button() diff --git a/src/gui/button.h b/src/gui/button.h index eb73e311..68831d5a 100644 --- a/src/gui/button.h +++ b/src/gui/button.h @@ -37,6 +37,7 @@ class ImageRect; */ class Button : public gcn::Button { public: + Button(); /** * Constructor, sets the caption of the button to the given string. */ @@ -60,6 +61,8 @@ class Button : public gcn::Button { { mIsLogged = enable; } private: + void init(); + static ImageRect button[4]; /**< Button state graphics */ static int mInstances; /**< Number of button instances */ bool mIsLogged; /**< Makes the button appear pressed all the time */ diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 3add3a18..b936f688 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -27,6 +27,7 @@ #include "setup_audio.h" #include "setup_joystick.h" #include "setup_video.h" +#include "setup_keyboard.h" #include "tabbedcontainer.h" #include "../utils/dtor.h" @@ -42,8 +43,8 @@ extern Window *skillDialog; Setup::Setup(): Window("Setup") { - int width = 230; - int height = 245; + int width = 260; + int height = 305; setContentSize(width, height); const char *buttonNames[] = { @@ -58,7 +59,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 205)); + panel->setDimension(gcn::Rectangle(5, 5, 250, 265)); panel->setOpaque(false); SetupTab *tab; @@ -75,6 +76,10 @@ Setup::Setup(): panel->addTab(tab, "Joystick"); mTabs.push_back(tab); + tab = new Setup_Keyboard(); + panel->addTab(tab, "Keyboard"); + mTabs.push_back(tab); + add(panel); setLocationRelativeTo(getParent()); diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp new file mode 100644 index 00000000..6ca149a5 --- /dev/null +++ b/src/gui/setup_keyboard.cpp @@ -0,0 +1,145 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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 + * any later version. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "setup_keyboard.h" + +#include + +#include "button.h" +#include "ok_dialog.h" + +#include "../configuration.h" +#include "../keyboardconfig.h" +#include "../log.h" + +#include "../utils/tostring.h" + +#include + +Setup_Keyboard::Setup_Keyboard() +{ + setOpaque(false); + + keyboard.setSetupKeyboard(this); + + mKeyLabel = new gcn::Label[keyboard.KEY_TOTAL]; + mKeyButton = new Button[keyboard.KEY_TOTAL]; + + for (int i=0; i < keyboard.KEY_TOTAL; i++) + { + refreshAssignedKey(i); + mKeyLabel[i].setPosition(10, 10+(i*20)); + add(&mKeyLabel[i]); + + mKeyButton[i].setCaption("Set"); + mKeyButton[i].adjustSize(); + mKeyButton[i].addActionListener(this); + mKeyButton[i].setActionEventId("sk"+toString(i)); + mKeyButton[i].setPosition(150,5+(i*20)); + add(&mKeyButton[i]); + } + mMakeDefaultButton = new Button("Default", "makeDefault", this); + mMakeDefaultButton->setPosition(200, 5); + mMakeDefaultButton->addActionListener(this); + add(mMakeDefaultButton); +} + +Setup_Keyboard::~Setup_Keyboard() +{ + delete [] mKeyLabel; + delete [] mKeyButton; + delete mMakeDefaultButton; +} + +void Setup_Keyboard::apply() +{ + if (keyboard.hasConflicts()) + { + new OkDialog("Key Conflict(s) Detected.", + "One or more key conflicts has been detected. " + "Resolve them immediately, " + "or gameplay might result in unpredictable behaviour"); + } + keyboard.setEnabled(true); + keyboard.store(); +} + +void Setup_Keyboard::cancel() +{ + keyboard.retrieve(); + keyboard.setEnabled(true); + refreshKeys(); +} + +void Setup_Keyboard::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "makeDefault") + { + keyboard.makeDefault(); + refreshKeys(); + return; + } + for (int i=0; i < keyboard.KEY_TOTAL; i++) + { + if (event.getId() == "sk"+toString(i)) + { + keyboard.setEnabled(false); + keyboard.setNewKeyIndex(i); + enableButtons(false); + mKeyLabel[i].setCaption(keyboard.getKeyCaption(i) + ": ?"); + } + } +} + + +void Setup_Keyboard::enableButtons(bool bValue) +{ + for (int i=0; i < keyboard.KEY_TOTAL; i++) + { + mKeyButton[i].setEnabled(bValue); + } +} + +void Setup_Keyboard::refreshAssignedKey(const int index) +{ + char *temp = SDL_GetKeyName( + (SDLKey) keyboard.getKeyValue(index)); + mKeyLabel[index].setCaption( + keyboard.getKeyCaption(index) + ": " + toString(temp)); + mKeyLabel[index].adjustSize(); +} + +void Setup_Keyboard::newKeyCallback(const int index) +{ + refreshAssignedKey(index); + enableButtons(true); +} + +void Setup_Keyboard::refreshKeys() +{ + for(int i=0; i < keyboard.KEY_TOTAL; i++) + { + refreshAssignedKey(i); + } +} + + diff --git a/src/gui/setup_keyboard.h b/src/gui/setup_keyboard.h new file mode 100644 index 00000000..0430b040 --- /dev/null +++ b/src/gui/setup_keyboard.h @@ -0,0 +1,74 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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 + * any later version. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_GUI_SETUP_KEYBOARD_H +#define _TMW_GUI_SETUP_KEYBOARD_H + +#include "setuptab.h" +#include "button.h" +#include "../guichanfwd.h" + +#include + + +#include + +class Setup_Keyboard : public SetupTab, public gcn::ActionListener +{ + public: + Setup_Keyboard(); + ~Setup_Keyboard(); + + void apply(); + void cancel(); + + void action(const gcn::ActionEvent &event); + + /** + * easy way to disable/enable all the set buttons. + */ + void enableButtons(bool bValue); + + /** + * get an update on the assigned key. + */ + void refreshAssignedKey(const int index); + + /** + * the callback function when a new key has been pressed. + */ + void newKeyCallback(const int index); + + /** + * shorthand method to update all the keys. + */ + void refreshKeys(); + + private: + gcn::Label *mKeyLabel; + + Button *mKeyButton; + + gcn::Button *mMakeDefaultButton; +}; + +#endif diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp new file mode 100644 index 00000000..3185a58a --- /dev/null +++ b/src/keyboardconfig.cpp @@ -0,0 +1,129 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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 + * any later version. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "keyboardconfig.h" +#include "configuration.h" +#include "log.h" + +#include + +#include "gui/setup_keyboard.h" + +void KeyboardConfig::destroy() +{ + +} + +void KeyboardConfig::init() +{ + mKey[KEY_MOVE_UP] = KeyFunction("keyMoveUp", SDLK_UP, "Move Up"); + mKey[KEY_MOVE_DOWN] = KeyFunction("keyMoveDown", SDLK_DOWN, "Move Down"); + mKey[KEY_MOVE_LEFT] = KeyFunction("keyMoveLeft", SDLK_LEFT, "Move Left"); + mKey[KEY_MOVE_RIGHT] = + KeyFunction("keyMoveRight", SDLK_RIGHT, "Move Right"); + + mKey[KEY_ATTACK] = KeyFunction("keyAttack", SDLK_LCTRL, "Attack"); + mKey[KEY_TARGET] = KeyFunction("keyTarget", SDLK_LSHIFT, "Target"); + mKey[KEY_TARGET_CLOSEST] = + KeyFunction("mKeyTargetClosest", SDLK_a, "Target Closest"); + mKey[KEY_PICKUP] = KeyFunction("keyPickup", SDLK_z, "Pickup"); + mKey[KEY_HIDE_WINDOWS] = + KeyFunction("keyHideWindows", SDLK_h, "Hide Windows"); + mKey[KEY_SIT] = KeyFunction("keyBeingSit", SDLK_g, "Sit"); + + for (int i = 0; i < KEY_TOTAL; i++) + { + mKey[i].value = KEY_NO_VALUE; + } + mNewKeyIndex = KEY_NO_VALUE; + mEnabled = true; + + retrieve(); +} + +void KeyboardConfig::retrieve() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + mKey[i].value = (int) config.getValue( + mKey[i].configField, mKey[i].defaultValue); + } +} + +void KeyboardConfig::store() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + config.setValue(mKey[i].configField, mKey[i].value); + } +} + +void KeyboardConfig::makeDefault() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + mKey[i].value = mKey[i].defaultValue; + } +} + +bool KeyboardConfig::hasConflicts() +{ + int i, j; + for (i = 0; i < KEY_TOTAL; i++) + { + for (j = 0; j < KEY_TOTAL; j++) + { + if (i != j && mKey[i].value == mKey[j].value) + { + return true; + } + } + } + return false; +} + +void KeyboardConfig::callbackNewKey() +{ + mSetupKey->newKeyCallback((const int) mNewKeyIndex); +} + +int KeyboardConfig::getKeyIndex(const int keyValue) const +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + if(keyValue == mKey[i].value) + { + return i; + } + } + return KEY_NO_VALUE; +} + +bool KeyboardConfig::isKeyActive(int index) +{ + return mActiveKeys[mKey[index].value]; +} + +void KeyboardConfig::refreshActiveKeys() +{ + mActiveKeys = SDL_GetKeyState(NULL); +} diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h new file mode 100644 index 00000000..73e08730 --- /dev/null +++ b/src/keyboardconfig.h @@ -0,0 +1,208 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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 + * any later version. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_KEYBOARDCONFIG_H +#define _TMW_KEYBOARDCONFIG_H + +#include + +#include "gui/setup_keyboard.h" + +#include + +#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) + +/** + * Each key represents a key function. Such as 'Move up', 'Attack' etc. + */ +struct KeyFunction +{ + KeyFunction(){} + KeyFunction(std::string configField, int defaultValue, std::string caption): + configField(configField), + defaultValue(defaultValue), + caption(caption) + { } + + std::string configField; + std::string caption; + int defaultValue; + int value; +}; + +class KeyboardConfig +{ + public: + /** + * initialize the keyboard config. + */ + void init(); + + /** + * destroy the object by releasing any memory. + */ + void destroy(); + + /** + * retrieve the key values from config file. + */ + void retrieve(); + + /** + * store the key values to config file. + */ + void store(); + + /** + * make the keys their default values. + */ + void makeDefault(); + + /** + * determines if any key assignments are the same as each other. + */ + bool hasConflicts(); + + /** + * calls a function back so the key re-assignment(s) can be seen. + */ + void callbackNewKey(); + + /** + * obtain the value stored in memory. + */ + int getKeyValue(int index) const + { + return mKey[index].value; + }; + + /** + * get the index of the new key to be assigned. + */ + int getNewKeyIndex() const + { + return mNewKeyIndex; + }; + + /** + * get the enable flag, which will stop the user from doing actions. + */ + bool isEnabled() const + { + return mEnabled; + }; + + /** + * get the key caption, providing more meaning to the user. + */ + std::string& getKeyCaption(int index) + { + return mKey[index].caption; + }; + + /** + * get the key function index by providing the keys value. + */ + int getKeyIndex(int keyValue) const; + + /** + * set the enable flag, which will stop the user from doing actions. + */ + void setEnabled(bool flag) + { + mEnabled = flag; + }; + + /** + * set the index of the new key to be assigned. + */ + void setNewKeyIndex(int value) + { + mNewKeyIndex = value; + }; + + /** + * set the value of the new key. + */ + void setNewKey(int value) + { + mKey[mNewKeyIndex].value = value; + }; + + /** + * set a reference to the key setup window. + */ + void setSetupKeyboard(Setup_Keyboard *setupKey) + { + mSetupKey = setupKey; + }; + + /** + * checks if the key is active, by providing the key function index. + */ + bool isKeyActive(const int index); + + /** + * takes a snapshot of all the active keys. + */ + void refreshActiveKeys(); + + /** + * All the key functions. + * KEY_NO_VALUE is used in initialization, and should be unchanged. + * KEY_MIN and KEY_TOTAL should always be first and last respectively, + * the bare used in control loops. + * The third element (after KEY_NO_VALUE and KEY_MIN), + * should always equal KEY_MIN. + * The key assignment view gets arranged according to the order of + * these values. + */ + enum KeyAction { + KEY_NO_VALUE = -1, + KEY_MOVE_UP, + KEY_MOVE_DOWN, + KEY_MOVE_LEFT, + KEY_MOVE_RIGHT, + KEY_ATTACK, + KEY_TARGET, + KEY_TARGET_CLOSEST, + KEY_PICKUP, + KEY_SIT, + KEY_HIDE_WINDOWS, + KEY_TOTAL + }; + private: + int mNewKeyIndex; /** index of new key to be assigned */ + bool mEnabled; /** flag to determine respond to key input */ + + Setup_Keyboard *mSetupKey; /** reference to setup window */ + + KeyFunction mKey[KEY_TOTAL]; /** pointer to all the key data */ + + Uint8 *mActiveKeys; /** stores a list of all the keys */ + +}; +extern KeyboardConfig keyboard; + +#endif + + diff --git a/src/main.cpp b/src/main.cpp index 1a6aea4c..e147f760 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,7 @@ #endif #include "configuration.h" +#include "keyboardconfig.h" #include "game.h" #include "graphics.h" #include "lockedarray.h" @@ -103,6 +104,7 @@ Music *bgm; Configuration config; /**< XML file configuration reader */ Logger *logger; /**< Log object */ +KeyboardConfig keyboard; /** * A structure holding the values of various options that can be passed from @@ -318,12 +320,20 @@ void init_engine(const Options &options) errorMessage = err; logger->log("Warning: %s", err); } + + //Initialize keyboard + keyboard.init(); } /** Clear the engine */ void exit_engine() { + // Store keys and Remove Keyboard configuration. + keyboard.store(); + keyboard.destroy(); + config.write(); + delete gui; delete graphics; -- cgit v1.2.3-70-g09d2