From 9b21b9c5a0066e9e4541d5f4be1b702a7c89f084 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 6 Dec 2018 11:43:10 +0100 Subject: [PATCH] improved key handling: shift+5 works now, and better key assignments in crystal rug --- control.cpp | 24 ++++++++++++++---------- crystal.cpp | 5 +++++ hyper.h | 4 ++++ rug.cpp | 28 ++++++++++++++++------------ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/control.cpp b/control.cpp index b54c2b69..680f0bdb 100644 --- a/control.cpp +++ b/control.cpp @@ -345,9 +345,9 @@ void handleKeyNormal(int sym, int uni) { } #endif - if(uni == sym && DEFAULTNOR(sym)) { + if(DEFAULTNOR(sym)) { gmodekeys(sym, uni); - if(sym == 'm' && canmove && (centerover == cwt ? mouseover : centerover.at)) + if(uni == 'm' && canmove && (centerover == cwt ? mouseover : centerover.at)) performMarkCommand(mouseover); } @@ -827,18 +827,22 @@ void displayabutton(int px, int py, string s, int col) { } #endif +bool numberkey(int sym, int uni, char number) { + return uni == number && !(sym >= SDLK_KP0 && sym <= SDLK_KP9); + } + void gmodekeys(int sym, int uni) { #if CAP_RUG if(rug::rugged) rug::handlekeys(sym, uni); #endif - if(uni == '1' && !rug::rugged) { vid.alpha = 999; vid.scale = 998; vid.xposition = vid.yposition = 0; } - if(uni == '2' && !rug::rugged) { vid.alpha = 1; vid.scale = 0.4; vid.xposition = vid.yposition = 0; } - if(uni == '3' && !rug::rugged) { vid.alpha = 1; vid.scale = 1; vid.xposition = vid.yposition = 0; } - if(uni == '4' && !rug::rugged) { vid.alpha = 0; vid.scale = 1; vid.xposition = vid.yposition = 0; } - if(uni == '5') { vid.wallmode += 60 + (shiftmul > 0 ? 1 : -1); vid.wallmode %= 6; } - if(uni == '6') vid.grid = !vid.grid; - if(uni == '7') { vid.darkhepta = !vid.darkhepta; } - if(uni == '%' && sym == '5') { + if(numberkey(sym, uni, '1') && !rug::rugged) { vid.alpha = 999; vid.scale = 998; vid.xposition = vid.yposition = 0; } + if(numberkey(sym, uni, '2') && !rug::rugged) { vid.alpha = 1; vid.scale = 0.4; vid.xposition = vid.yposition = 0; } + if(numberkey(sym, uni, '3') && !rug::rugged) { vid.alpha = 1; vid.scale = 1; vid.xposition = vid.yposition = 0; } + if(numberkey(sym, uni, '4') && !rug::rugged) { vid.alpha = 0; vid.scale = 1; vid.xposition = vid.yposition = 0; } + if(numberkey(sym, uni, '5')) { vid.wallmode += 60 + (shiftmul > 0 ? 1 : -1); vid.wallmode %= 6; } + if(numberkey(sym, uni, '6')) vid.grid = !vid.grid; + if(numberkey(sym, uni, '7')) { vid.darkhepta = !vid.darkhepta; } + if(uni == '%') { if(vid.wallmode == 0) vid.wallmode = 6; vid.wallmode--; } diff --git a/crystal.cpp b/crystal.cpp index f6c4fd6e..269f4714 100644 --- a/crystal.cpp +++ b/crystal.cpp @@ -836,6 +836,11 @@ void next_home_orientation() { init_rotation(); } +void flip_z() { + for(int i=0; i joyhandler; #endif void gmodekeys(int sym, int uni); +// check for a plain number key +bool numberkey(int sym, int uni, char number); + void switchGL(); void switchFullscreen(); extern int cmode; @@ -4157,6 +4160,7 @@ namespace crystal { void apply_rotation(const transmatrix t); void switch_z_coordinate(); void next_home_orientation(); + void flip_z(); void set_land(cell *c); int dist_alt(cell *c); int dist_relative(cell *c); diff --git a/rug.cpp b/rug.cpp index b486890d..6f5dcafb 100644 --- a/rug.cpp +++ b/rug.cpp @@ -1485,7 +1485,7 @@ void move_forward(ld distance) { #define CAP_HOLDKEYS CAP_SDL // && !ISWEB) bool handlekeys(int sym, int uni) { - if(uni == '1') { + if(numberkey(sym, uni, '1')) { ld bdist = 1e12; if(finger_center) finger_center = NULL; @@ -1499,35 +1499,39 @@ bool handlekeys(int sym, int uni) { if(renderonce) renderlate+=10; return true; } - else if(uni == '2') { + else if(numberkey(sym, uni, '2')) { if(in_crystal()) crystal::switch_z_coordinate(); else apply_rotation(rotmatrix(M_PI, 0, 2)); return true; } - else if(uni == '3') { + else if(numberkey(sym, uni, '3')) { if(in_crystal()) - crystal::next_home_orientation(); + crystal::flip_z(); else apply_rotation(rotmatrix(M_PI/2, 0, 2)); return true; } + else if(sym == SDLK_HOME && in_crystal()) { + crystal::next_home_orientation(); + return true; + } #if !CAP_HOLDKEYS - else if(uni == SDLK_PAGEUP || uni == '[') { + else if(sym == SDLK_PAGEUP || uni == '[') { move_forward(.1); return true; } - else if(uni == SDLK_PAGEDOWN || uni == ']') { + else if(sym == SDLK_PAGEDOWN || uni == ']') { move_forward(-.1); return true; } - else if(uni == SDLK_HOME) { apply_rotation(rotmatrix(.1, 0, 1)); return true; } - else if(uni == SDLK_END) { apply_rotation(rotmatrix(.1, 1, 0)); return true; } - else if(uni == SDLK_DOWN) { apply_rotation(rotmatrix(.1, 2, 1)); return true; } - else if(uni == SDLK_UP) { apply_rotation(rotmatrix(.1, 1, 2)); return true; } - else if(uni == SDLK_LEFT) { apply_rotation(rotmatrix(.1, 2, 0)); return true; } - else if(uni == SDLK_RIGHT) { apply_rotation(rotmatrix(.1, 0, 2)); return true; } + else if(sym == SDLK_HOME) { apply_rotation(rotmatrix(.1, 0, 1)); return true; } + else if(sym == SDLK_END) { apply_rotation(rotmatrix(.1, 1, 0)); return true; } + else if(sym == SDLK_DOWN) { apply_rotation(rotmatrix(.1, 2, 1)); return true; } + else if(sym == SDLK_UP) { apply_rotation(rotmatrix(.1, 1, 2)); return true; } + else if(sym == SDLK_LEFT) { apply_rotation(rotmatrix(.1, 2, 0)); return true; } + else if(sym == SDLK_RIGHT) { apply_rotation(rotmatrix(.1, 0, 2)); return true; } #endif else return false; }