diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-01-27 16:41:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-27 16:41:22 +0300 |
commit | 3f0292bc97dec0c1c6a3c8997fb55012c4135480 (patch) | |
tree | e2c9706547008dca57742dbce19dfbf787366519 /src/gui/outfitwindow.cpp | |
parent | e70e4c56f86a33b7a1ce50c6e99eed02d0d1be14 (diff) | |
download | plus-3f0292bc97dec0c1c6a3c8997fb55012c4135480.tar.gz plus-3f0292bc97dec0c1c6a3c8997fb55012c4135480.tar.bz2 plus-3f0292bc97dec0c1c6a3c8997fb55012c4135480.tar.xz plus-3f0292bc97dec0c1c6a3c8997fb55012c4135480.zip |
Cleanup outfits keys handling.
Diffstat (limited to 'src/gui/outfitwindow.cpp')
-rw-r--r-- | src/gui/outfitwindow.cpp | 379 |
1 files changed, 18 insertions, 361 deletions
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 74e8dbe46..20b2bac27 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -491,375 +491,32 @@ void OutfitWindow::unequipNotInOutfit(int outfit) } } +static const SDLKey numsTbl[] = +{ + SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, + SDLK_0, SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_INSERT, SDLK_HOME, + SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i, SDLK_o, + SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_BACKSLASH, SDLK_a, + SDLK_s, SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, + SDLK_SEMICOLON, SDLK_QUOTE, SDLK_z, SDLK_x, SDLK_c, SDLK_v, SDLK_b, SDLK_n, + SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH +}; + int OutfitWindow::keyToNumber(SDLKey key) const { - int outfitNum = -1; - switch (key) + for (int f = 0; f < sizeof(numsTbl) / sizeof(SDLKey); f ++) { - case SDLK_1: - case SDLK_2: - case SDLK_3: - case SDLK_4: - case SDLK_5: - case SDLK_6: - case SDLK_7: - case SDLK_8: - case SDLK_9: - outfitNum = key - SDLK_1; - break; - - case SDLK_0: - outfitNum = 9; - break; - - case SDLK_MINUS: - outfitNum = 10; - break; - - case SDLK_EQUALS: - outfitNum = 11; - break; - - case SDLK_BACKSPACE: - outfitNum = 12; - break; - - case SDLK_INSERT: - outfitNum = 13; - break; - - case SDLK_HOME: - outfitNum = 14; - break; - - case SDLK_q: - outfitNum = 15; - break; - - case SDLK_w: - outfitNum = 16; - break; - - case SDLK_e: - outfitNum = 17; - break; - - case SDLK_r: - outfitNum = 18; - break; - - case SDLK_t: - outfitNum = 19; - break; - - case SDLK_y: - outfitNum = 20; - break; - - case SDLK_u: - outfitNum = 21; - break; - - case SDLK_i: - outfitNum = 22; - break; - - case SDLK_o: - outfitNum = 23; - break; - - case SDLK_p: - outfitNum = 24; - break; - - case SDLK_LEFTBRACKET: - outfitNum = 25; - break; - - case SDLK_RIGHTBRACKET: - outfitNum = 26; - break; - - case SDLK_BACKSLASH: - outfitNum = 27; - break; - - case SDLK_a: - outfitNum = 28; - break; - - case SDLK_s: - outfitNum = 29; - break; - - case SDLK_d: - outfitNum = 30; - break; - - case SDLK_f: - outfitNum = 31; - break; - - case SDLK_g: - outfitNum = 32; - break; - - case SDLK_h: - outfitNum = 33; - break; - - case SDLK_j: - outfitNum = 34; - break; - - case SDLK_k: - outfitNum = 35; - break; - - case SDLK_l: - outfitNum = 36; - break; - - case SDLK_SEMICOLON: - outfitNum = 37; - break; - - case SDLK_QUOTE: - outfitNum = 38; - break; - - case SDLK_z: - outfitNum = 39; - break; - - - case SDLK_x: - outfitNum = 40; - break; - - case SDLK_c: - outfitNum = 41; - break; - - case SDLK_v: - outfitNum = 42; - break; - - case SDLK_b: - outfitNum = 43; - break; - - case SDLK_n: - outfitNum = 44; - break; - - case SDLK_m: - outfitNum = 45; - break; - - case SDLK_COMMA: - outfitNum = 46; - break; - - case SDLK_PERIOD: - outfitNum = 47; - break; - - case SDLK_SLASH: - outfitNum = 48; - break; - - default: - break; + if (numsTbl[f] == key) + return f; } - - return outfitNum; + return -1; } SDLKey OutfitWindow::numberToKey(int number) const { - SDLKey key = SDLK_UNKNOWN; - switch (number) - { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - key = static_cast<SDLKey>( - static_cast<unsigned int>(SDLK_1) + number); - break; - - case 9: - key = SDLK_0; - break; - - case 10: - key = SDLK_MINUS; - break; - - case 11: - key = SDLK_EQUALS; - break; - - case 12: - key = SDLK_BACKSPACE; - break; - - case 13: - key = SDLK_INSERT; - break; - - case 14: - key = SDLK_HOME; - break; - - case 15: - key = SDLK_q; - break; - - case 16: - key = SDLK_w; - break; - - case 17: - key = SDLK_e; - break; - - case 18: - key = SDLK_r; - break; - - case 19: - key = SDLK_t; - break; - - case 20: - key = SDLK_y; - break; - - case 21: - key = SDLK_u; - break; - - case 22: - key = SDLK_i; - break; - - case 23: - key = SDLK_o; - break; - - case 24: - key = SDLK_p; - break; - - case 25: - key = SDLK_LEFTBRACKET; - break; - - case 26: - key = SDLK_RIGHTBRACKET; - break; - - case 27: - key = SDLK_BACKSLASH; - break; - - case 28: - key = SDLK_a; - break; - - case 29: - key = SDLK_s; - break; - - case 30: - key = SDLK_d; - break; - - case 31: - key = SDLK_f; - break; - - case 32: - key = SDLK_g; - break; - - case 33: - key = SDLK_h; - break; - - case 34: - key = SDLK_j; - break; - - case 35: - key = SDLK_k; - break; - - case 36: - key = SDLK_l; - break; - - case 37: - key = SDLK_SEMICOLON; - break; - - case 38: - key = SDLK_QUOTE; - break; - - case 39: - key = SDLK_z; - break; - - - case 40: - key = SDLK_x; - break; - - case 41: - key = SDLK_c; - break; - - case 42: - key = SDLK_v; - break; - - case 43: - key = SDLK_b; - break; - - case 44: - key = SDLK_n; - break; - - case 45: - key = SDLK_m; - break; - - case 46: - key = SDLK_COMMA; - break; - - case 47: - key = SDLK_PERIOD; - break; - - case 48: - key = SDLK_SLASH; - break; - - default: - break; - } - - return key; + if (number < 0 || number >= sizeof(numsTbl) / sizeof(SDLKey)) + return SDLK_UNKNOWN; + return numsTbl[number]; } std::string OutfitWindow::keyName(int number) |