From dc5d9dee3f3f726d463f5f23f5902d1d0373df93 Mon Sep 17 00:00:00 2001 From: Joshua Langley Date: Tue, 24 Jul 2007 06:39:04 +0000 Subject: keyboard configuration - mainly documentation fixes. http://mantis.themanaworld.org/view.php?id=16 --- ChangeLog | 22 +++++++++--------- The Mana World.dev | 8 +++---- src/game.cpp | 4 +--- src/gui/setup_keyboard.cpp | 20 +++++++---------- src/gui/setup_keyboard.h | 17 +++++++++----- src/keyboardconfig.cpp | 18 ++++++++------- src/keyboardconfig.h | 56 ++++++++++++++++++++++------------------------ src/main.cpp | 3 +-- 8 files changed, 74 insertions(+), 74 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15ba409c..1d6ca15e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,14 +1,14 @@ -2007-07-17 Joshua Langley - - * src/game.cpp: only one key per function. - * src/main.cpp: keyboard configuration included. - * src/gui/button.cpp, src/gui/button.h: default constructor and - init function added. - * src/gui/setup.cpp: keyboard setup tab added. - * src/gui/setup_keyboard.cpp, src/gui/setup_keyboard.h: - Add to project file, it is the keyboard setup tab. - * src/keyboardconfig.cpp, src/keyboardconfig.h: Add to project file, - the main keyboard config operations. +2007-07-17 Joshua Langley + + * src/game.cpp: only one key per function. + * src/main.cpp: keyboard configuration included. + * src/gui/button.cpp, src/gui/button.h: default constructor and + init function added. + * src/gui/setup.cpp: keyboard setup tab added. + * src/gui/setup_keyboard.cpp, src/gui/setup_keyboard.h: + Add to project file, it is the keyboard setup tab. + * src/keyboardconfig.cpp, src/keyboardconfig.h: Add to project file, + the main keyboard config operations. 2007-07-16 Eugenio Favalli diff --git a/The Mana World.dev b/The Mana World.dev index b2fa556a..54026e4c 100644 --- a/The Mana World.dev +++ b/The Mana World.dev @@ -2828,7 +2828,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit278] -FileName=..\tmw_3367_CR0000016\src\keyboardconfig.cpp +FileName=src\keyboardconfig.cpp CompileCpp=1 Folder= Compile=1 @@ -2838,7 +2838,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit279] -FileName=..\tmw_3367_CR0000016\src\keyboardconfig.h +FileName=src\keyboardconfig.h CompileCpp=1 Folder=header Compile=1 @@ -2848,7 +2848,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit280] -FileName=..\tmw_3367_CR0000016\src\gui\setup_keyboard.cpp +FileName=src\gui\setup_keyboard.cpp CompileCpp=1 Folder=gui/source Compile=1 @@ -2858,7 +2858,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit281] -FileName=..\tmw_3367_CR0000016\src\gui\setup_keyboard.h +FileName=src\gui\setup_keyboard.h CompileCpp=1 Folder=gui/header Compile=1 diff --git a/src/game.cpp b/src/game.cpp index eb990e1b..a2ea9af6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -427,7 +427,7 @@ void Game::handleInput() { gcn::Window *requestedWindow = NULL; - if (//setupWindow->isVisible() && + if (setupWindow->isVisible() && keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) { keyboard.setNewKey((int) event.key.keysym.sym); @@ -569,7 +569,6 @@ void Game::handleInput() used = true; } - // Keys pressed together with Alt/Meta // Emotions and some internal gui windows if (event.key.keysym.mod & KMOD_ALT) @@ -668,7 +667,6 @@ void Game::handleInput() { direction |= Being::UP; } - else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || joystick && joystick->isDown()) { diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 6ca149a5..4cb39494 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -29,7 +29,6 @@ #include "../configuration.h" #include "../keyboardconfig.h" -#include "../log.h" #include "../utils/tostring.h" @@ -104,14 +103,13 @@ void Setup_Keyboard::action(const gcn::ActionEvent &event) { keyboard.setEnabled(false); keyboard.setNewKeyIndex(i); - enableButtons(false); + enableSetButtons(false); mKeyLabel[i].setCaption(keyboard.getKeyCaption(i) + ": ?"); } } } - -void Setup_Keyboard::enableButtons(bool bValue) +void Setup_Keyboard::enableSetButtons(bool bValue) { for (int i=0; i < keyboard.KEY_TOTAL; i++) { @@ -121,17 +119,17 @@ void Setup_Keyboard::enableButtons(bool 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(); + 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); + enableSetButtons(true); } void Setup_Keyboard::refreshKeys() @@ -141,5 +139,3 @@ void Setup_Keyboard::refreshKeys() refreshAssignedKey(i); } } - - diff --git a/src/gui/setup_keyboard.h b/src/gui/setup_keyboard.h index 0430b040..115a2b9a 100644 --- a/src/gui/setup_keyboard.h +++ b/src/gui/setup_keyboard.h @@ -35,7 +35,14 @@ class Setup_Keyboard : public SetupTab, public gcn::ActionListener { public: + /** + * Constructor + */ Setup_Keyboard(); + + /** + * Destructor + */ ~Setup_Keyboard(); void apply(); @@ -44,22 +51,22 @@ class Setup_Keyboard : public SetupTab, public gcn::ActionListener void action(const gcn::ActionEvent &event); /** - * easy way to disable/enable all the set buttons. + * Easy way to disable/enable all the set buttons. */ - void enableButtons(bool bValue); + void enableSetButtons(bool bValue); /** - * get an update on the assigned key. + * Get an update on the assigned key. */ void refreshAssignedKey(const int index); /** - * the callback function when a new key has been pressed. + * The callback function when a new key has been pressed. */ void newKeyCallback(const int index); /** - * shorthand method to update all the keys. + * Shorthand method to update all the keys. */ void refreshKeys(); diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 3185a58a..5cce793a 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -28,11 +28,6 @@ #include "gui/setup_keyboard.h" -void KeyboardConfig::destroy() -{ - -} - void KeyboardConfig::init() { mKey[KEY_MOVE_UP] = KeyFunction("keyMoveUp", SDLK_UP, "Move Up"); @@ -44,7 +39,7 @@ void KeyboardConfig::init() 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"); + KeyFunction("keyTargetClosest", SDLK_a, "Target Closest"); mKey[KEY_PICKUP] = KeyFunction("keyPickup", SDLK_z, "Pickup"); mKey[KEY_HIDE_WINDOWS] = KeyFunction("keyHideWindows", SDLK_h, "Hide Windows"); @@ -60,6 +55,13 @@ void KeyboardConfig::init() retrieve(); } +void KeyboardConfig::destroy() +{ + store(); + + delete [] mActiveKeys; +} + void KeyboardConfig::retrieve() { for (int i = 0; i < KEY_TOTAL; i++) @@ -103,7 +105,7 @@ bool KeyboardConfig::hasConflicts() void KeyboardConfig::callbackNewKey() { - mSetupKey->newKeyCallback((const int) mNewKeyIndex); + mSetupKey->newKeyCallback(mNewKeyIndex); } int KeyboardConfig::getKeyIndex(const int keyValue) const @@ -120,7 +122,7 @@ int KeyboardConfig::getKeyIndex(const int keyValue) const bool KeyboardConfig::isKeyActive(int index) { - return mActiveKeys[mKey[index].value]; + return mActiveKeys[ mKey[index].value]; } void KeyboardConfig::refreshActiveKeys() diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index 73e08730..f074e001 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -29,8 +29,6 @@ #include -#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) - /** * Each key represents a key function. Such as 'Move up', 'Attack' etc. */ @@ -43,52 +41,52 @@ struct KeyFunction caption(caption) { } - std::string configField; - std::string caption; - int defaultValue; - int value; + std::string configField; /** Field index that is in the config file. */ + std::string caption; /** The caption value for the key function. */ + int defaultValue; /** The default key value used. */ + int value; /** The actual value that is used. */ }; class KeyboardConfig { public: /** - * initialize the keyboard config. + * Initializes the keyboard config explicitly. */ void init(); /** - * destroy the object by releasing any memory. + * Destroys the keyboard config explicitly. */ void destroy(); /** - * retrieve the key values from config file. + * Retrieve the key values from config file. */ void retrieve(); /** - * store the key values to config file. + * Store the key values to config file. */ void store(); /** - * make the keys their default values. + * Make the keys their default values. */ void makeDefault(); /** - * determines if any key assignments are the same as each other. + * 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. + * Calls a function back so the key re-assignment(s) can be seen. */ void callbackNewKey(); /** - * obtain the value stored in memory. + * Obtain the value stored in memory. */ int getKeyValue(int index) const { @@ -96,7 +94,7 @@ class KeyboardConfig }; /** - * get the index of the new key to be assigned. + * Get the index of the new key to be assigned. */ int getNewKeyIndex() const { @@ -104,7 +102,7 @@ class KeyboardConfig }; /** - * get the enable flag, which will stop the user from doing actions. + * Get the enable flag, which will stop the user from doing actions. */ bool isEnabled() const { @@ -112,7 +110,7 @@ class KeyboardConfig }; /** - * get the key caption, providing more meaning to the user. + * Get the key caption, providing more meaning to the user. */ std::string& getKeyCaption(int index) { @@ -120,12 +118,12 @@ class KeyboardConfig }; /** - * get the key function index by providing the keys value. + * 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. + * Set the enable flag, which will stop the user from doing actions. */ void setEnabled(bool flag) { @@ -133,7 +131,7 @@ class KeyboardConfig }; /** - * set the index of the new key to be assigned. + * Set the index of the new key to be assigned. */ void setNewKeyIndex(int value) { @@ -141,7 +139,7 @@ class KeyboardConfig }; /** - * set the value of the new key. + * Set the value of the new key. */ void setNewKey(int value) { @@ -149,7 +147,7 @@ class KeyboardConfig }; /** - * set a reference to the key setup window. + * Set a reference to the key setup window. */ void setSetupKeyboard(Setup_Keyboard *setupKey) { @@ -157,12 +155,12 @@ class KeyboardConfig }; /** - * checks if the key is active, by providing the key function index. + * 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. + * Takes a snapshot of all the active keys. */ void refreshActiveKeys(); @@ -191,14 +189,14 @@ class KeyboardConfig KEY_TOTAL }; private: - int mNewKeyIndex; /** index of new key to be assigned */ - bool mEnabled; /** flag to determine respond to key input */ + 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 */ + Setup_Keyboard *mSetupKey; /** Reference to setup window */ - KeyFunction mKey[KEY_TOTAL]; /** pointer to all the key data */ + KeyFunction mKey[KEY_TOTAL]; /** Pointer to all the key data */ - Uint8 *mActiveKeys; /** stores a list of all the keys */ + Uint8 *mActiveKeys; /** Stores a list of all the keys */ }; extern KeyboardConfig keyboard; diff --git a/src/main.cpp b/src/main.cpp index e147f760..112c5b6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -328,8 +328,7 @@ void init_engine(const Options &options) /** Clear the engine */ void exit_engine() { - // Store keys and Remove Keyboard configuration. - keyboard.store(); + // Remove Keyboard configuration. keyboard.destroy(); config.write(); -- cgit v1.2.3-70-g09d2