From fd168c24b9bc45c4bc6c092d072fef835063918e Mon Sep 17 00:00:00 2001 From: Joshua Langley Date: Sun, 19 Aug 2007 08:34:48 +0000 Subject: v0.0.23 - src/keyboardconfig.cpp, src/keyboardconfig.h - minor cleanup. --- ChangeLog | 6 +++++- src/keyboardconfig.cpp | 36 ++++++++++++++++++++++-------------- src/keyboardconfig.h | 21 ++++----------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 737ff4f9..be4d0e5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2007-08-17 Bjørn Lindeijer +2007-08-19 Joshua Langley + + * src/keyboardconfig.cpp, src/keyboardconfig.h - minor cleanup. + +2007-08-17 Bjørn Lindeijer * tools/adler32.c: Added little program for calculating adler32 checksums of files. diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 73912000..047f576a 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -29,25 +29,33 @@ #include "gui/setup_keyboard.h" -void KeyboardConfig::init() +struct KeyData { - 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"); + const char *configField; + int defaultValue; + const char *caption; +}; - mKey[KEY_ATTACK] = KeyFunction("keyAttack", SDLK_LCTRL, "Attack"); - mKey[KEY_TARGET] = KeyFunction("keyTarget", SDLK_LSHIFT, "Target"); - mKey[KEY_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"); - mKey[KEY_SIT] = KeyFunction("keyBeingSit", SDLK_g, "Sit"); +static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = { + {"keyMoveUp", SDLK_UP, "Move Up"}, + {"keyMoveDown", SDLK_DOWN, "Move Down"}, + {"keyMoveLeft", SDLK_LEFT, "Move Left"}, + {"keyMoveRight", SDLK_RIGHT, "Move Right"}, + {"keyAttack", SDLK_LCTRL, "Attack"}, + {"keyTarget", SDLK_LSHIFT, "Target"}, + {"keyTargetClosest", SDLK_a, "Target Closest"}, + {"keyPickup", SDLK_z, "Pickup"}, + {"keyHideWindows", SDLK_h, "Hide Windows"}, + {"keyBeingSit", SDLK_g, "Sit"} +}; +void KeyboardConfig::init() +{ for (int i = 0; i < KEY_TOTAL; i++) { + mKey[i].configField = keyData[i].configField; + mKey[i].defaultValue = keyData[i].defaultValue; + mKey[i].caption = keyData[i].caption; mKey[i].value = KEY_NO_VALUE; } mNewKeyIndex = KEY_NO_VALUE; diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index 64d80629..1a7d84b9 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -35,19 +35,9 @@ */ struct KeyFunction { - KeyFunction() {} - - KeyFunction(std::string configField, - int defaultValue, - std::string caption): - configField(configField), - caption(caption), - defaultValue(defaultValue) - {} - - std::string configField; /** Field index that is in the config file. */ - std::string caption; /** The caption value for the key function. */ + const char* configField; /** Field index that is in the config file. */ int defaultValue; /** The default key value used. */ + std::string caption; /** The caption value for the key function. */ int value; /** The actual value that is used. */ }; @@ -105,7 +95,7 @@ class KeyboardConfig /** * Get the key caption, providing more meaning to the user. */ - std::string const &getKeyCaption(int index) const + const std::string &getKeyCaption(int index) const { return mKey[index].caption; } /** @@ -150,10 +140,7 @@ class KeyboardConfig /** * 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. + * KEY_TOTAL should always be last (used as a conditional in loops). * The key assignment view gets arranged according to the order of * these values. */ -- cgit v1.2.3-70-g09d2