00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "configuration.h"
00023 #include "keyboardconfig.h"
00024 #include "log.h"
00025
00026 #include "gui/sdlinput.h"
00027 #include "gui/setup_keyboard.h"
00028
00029 #include "utils/gettext.h"
00030 #include "utils/strprintf.h"
00031
00032 struct KeyData
00033 {
00034 const char *configField;
00035 int defaultValue;
00036 std::string caption;
00037 };
00038
00039
00040 static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = {
00041 {"keyMoveUp", SDLK_UP, _("Move Up")},
00042 {"keyMoveDown", SDLK_DOWN, _("Move Down")},
00043 {"keyMoveLeft", SDLK_LEFT, _("Move Left")},
00044 {"keyMoveRight", SDLK_RIGHT, _("Move Right")},
00045 {"keyAttack", SDLK_LCTRL, _("Attack")},
00046 {"keySmilie", SDLK_LALT, _("Smilie")},
00047 {"keyTalk", SDLK_t, _("Talk")},
00048 {"keyTarget", SDLK_LSHIFT, _("Stop Attack")},
00049 {"keyTargetClosest", SDLK_a, _("Target Closest")},
00050 {"keyTargetNPC", SDLK_n, _("Target NPC")},
00051 {"keyTargetPlayer", SDLK_q, _("Target Player")},
00052 {"keyPickup", SDLK_z, _("Pickup")},
00053 {"keyHideWindows", SDLK_h, _("Hide Windows")},
00054 {"keyBeingSit", SDLK_s, _("Sit")},
00055 {"keyScreenshot", SDLK_p, _("Screenshot")},
00056 {"keyTrade", SDLK_r, _("Enable/Disable Trading")},
00057 {"keyPathfind", SDLK_f, _("Find Path to Mouse")},
00058 {"keyShortcut1", SDLK_1, strprintf(_("Item Shortcut %d"), 1)},
00059 {"keyShortcut2", SDLK_2, strprintf(_("Item Shortcut %d"), 2)},
00060 {"keyShortcut3", SDLK_3, strprintf(_("Item Shortcut %d"), 3)},
00061 {"keyShortcut4", SDLK_4, strprintf(_("Item Shortcut %d"), 4)},
00062 {"keyShortcut5", SDLK_5, strprintf(_("Item Shortcut %d"), 5)},
00063 {"keyShortcut6", SDLK_6, strprintf(_("Item Shortcut %d"), 6)},
00064 {"keyShortcut7", SDLK_7, strprintf(_("Item Shortcut %d"), 7)},
00065 {"keyShortcut8", SDLK_8, strprintf(_("Item Shortcut %d"), 8)},
00066 {"keyShortcut9", SDLK_9, strprintf(_("Item Shortcut %d"), 9)},
00067 {"keyShortcut10", SDLK_0, strprintf(_("Item Shortcut %d"), 10)},
00068 {"keyShortcut11", SDLK_MINUS, strprintf(_("Item Shortcut %d"), 11)},
00069 {"keyShortcut12", SDLK_EQUALS, strprintf(_("Item Shortcut %d"), 12)},
00070 {"keyWindowHelp", SDLK_F1, _("Help Window")},
00071 {"keyWindowStatus", SDLK_F2, _("Status Window")},
00072 {"keyWindowInventory", SDLK_F3, _("Inventory Window")},
00073 {"keyWindowEquipment", SDLK_F4, _("Equipment WIndow")},
00074 {"keyWindowSkill", SDLK_F5, _("Skill Window")},
00075 {"keyWindowMinimap", SDLK_F6, _("Minimap Window")},
00076 {"keyWindowChat", SDLK_F7, _("Chat Window")},
00077 {"keyWindowShortcut", SDLK_F8, _("Item Shortcut Window")},
00078 {"keyWindowSetup", SDLK_F9, _("Setup Window")},
00079 {"keyWindowDebug", SDLK_F10, _("Debug Window")},
00080 {"keyWindowEmote", SDLK_F11, _("Emote Window")},
00081 {"keyWindowEmoteBar", SDLK_F12, _("Emote Shortcut Window")},
00082 {"keyEmoteShortcut1", SDLK_1, strprintf(_("Emote Shortcut %d"), 1)},
00083 {"keyEmoteShortcut2", SDLK_2, strprintf(_("Emote Shortcut %d"), 2)},
00084 {"keyEmoteShortcut3", SDLK_3, strprintf(_("Emote Shortcut %d"), 3)},
00085 {"keyEmoteShortcut4", SDLK_4, strprintf(_("Emote Shortcut %d"), 4)},
00086 {"keyEmoteShortcut5", SDLK_5, strprintf(_("Emote Shortcut %d"), 5)},
00087 {"keyEmoteShortcut6", SDLK_6, strprintf(_("Emote Shortcut %d"), 6)},
00088 {"keyEmoteShortcut7", SDLK_7, strprintf(_("Emote Shortcut %d"), 7)},
00089 {"keyEmoteShortcut8", SDLK_8, strprintf(_("Emote Shortcut %d"), 8)},
00090 {"keyEmoteShortcut9", SDLK_9, strprintf(_("Emote Shortcut %d"), 9)},
00091 {"keyEmoteShortcut10", SDLK_0, strprintf(_("Emote Shortcut %d"), 10)},
00092 {"keyEmoteShortcut11", SDLK_MINUS, strprintf(_("Emote Shortcut %d"), 11)},
00093 {"keyEmoteShortcut12", SDLK_EQUALS, strprintf(_("Emote Shortcut %d"), 12)},
00094 {"keyChat", SDLK_RETURN, _("Toggle Chat")},
00095 {"keyChatScrollUp", SDLK_PAGEUP, _("Scroll Chat Up")},
00096 {"keyChatScrollDown", SDLK_PAGEDOWN, _("Scroll Chat Down")},
00097 {"keyChatPrevTab", SDLK_LEFTBRACKET, _("Previous Chat Tab")},
00098 {"keyChatNextTab", SDLK_RIGHTBRACKET, _("Next Chat Tab")},
00099 {"keyOK", SDLK_RETURN, _("Select OK")},
00100 {"keyQuit", SDLK_ESCAPE, _("Quit")},
00101 {"keyIgnoreInput1", SDLK_LSUPER, _("Ignore input 1")},
00102 {"keyIgnoreInput2", SDLK_RSUPER, _("Ignore input 2")}
00103 };
00104
00105 void KeyboardConfig::init()
00106 {
00107 for (int i = 0; i < KEY_TOTAL; i++)
00108 {
00109 mKey[i].configField = keyData[i].configField;
00110 mKey[i].defaultValue = keyData[i].defaultValue;
00111 mKey[i].caption = keyData[i].caption;
00112 mKey[i].value = KEY_NO_VALUE;
00113 }
00114 mNewKeyIndex = KEY_NO_VALUE;
00115 mEnabled = true;
00116
00117 retrieve();
00118 }
00119
00120 void KeyboardConfig::retrieve()
00121 {
00122 for (int i = 0; i < KEY_TOTAL; i++)
00123 {
00124 mKey[i].value = (int) config.getValue(
00125 mKey[i].configField, mKey[i].defaultValue);
00126 }
00127 }
00128
00129 void KeyboardConfig::store()
00130 {
00131 for (int i = 0; i < KEY_TOTAL; i++)
00132 {
00133 config.setValue(mKey[i].configField, mKey[i].value);
00134 }
00135 }
00136
00137 void KeyboardConfig::makeDefault()
00138 {
00139 for (int i = 0; i < KEY_TOTAL; i++)
00140 {
00141 mKey[i].value = mKey[i].defaultValue;
00142 }
00143 }
00144
00145 bool KeyboardConfig::hasConflicts()
00146 {
00147 int i, j;
00152 for (i = 0; i < KEY_TOTAL; i++)
00153 {
00154 for (j = i, j++; j < KEY_TOTAL; j++)
00155 {
00156
00157 if (!((((i >= KEY_SHORTCUT_1) && (i <= KEY_SHORTCUT_12)) &&
00158 ((j >= KEY_EMOTE_1) && (j <= KEY_EMOTE_12))) ||
00159 ((i == KEY_TOGGLE_CHAT) && (j == KEY_OK))) &&
00160 (mKey[i].value == mKey[j].value)
00161 )
00162 {
00163 return true;
00164 }
00165 }
00166 }
00167 return false;
00168 }
00169
00170 void KeyboardConfig::callbackNewKey()
00171 {
00172 mSetupKey->newKeyCallback(mNewKeyIndex);
00173 }
00174
00175 int KeyboardConfig::getKeyIndex(int keyValue) const
00176 {
00177 for (int i = 0; i < KEY_TOTAL; i++)
00178 {
00179 if (keyValue == mKey[i].value)
00180 {
00181 return i;
00182 }
00183 }
00184 return KEY_NO_VALUE;
00185 }
00186
00187
00188 int KeyboardConfig::getKeyEmoteOffset(int keyValue) const
00189 {
00190 for (int i = KEY_EMOTE_1; i <= KEY_EMOTE_12; i++)
00191 {
00192 if (keyValue == mKey[i].value)
00193 {
00194 return 1 + i - KEY_EMOTE_1;
00195 }
00196 }
00197 return 0;
00198 }
00199
00200 bool KeyboardConfig::isKeyActive(int index)
00201 {
00202 if (!mActiveKeys) return false;
00203 return mActiveKeys[mKey[index].value];
00204 }
00205
00206 void KeyboardConfig::refreshActiveKeys()
00207 {
00208 mActiveKeys = SDL_GetKeyState(NULL);
00209 }