improved key handling: shift+5 works now, and better key assignments in crystal rug

This commit is contained in:
Zeno Rogue 2018-12-06 11:43:10 +01:00
parent 58d584eed2
commit 9b21b9c5a0
4 changed files with 39 additions and 22 deletions

View File

@ -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--;
}

View File

@ -836,6 +836,11 @@ void next_home_orientation() {
init_rotation();
}
void flip_z() {
for(int i=0; i<MAXDIM; i++)
crug_rotation[i][2] *= -1;
}
hyperpoint coord_to_flat(ldcoord co) {
hyperpoint res = hpxyz(0, 0, 0);
co = co - rug_center;

View File

@ -2487,6 +2487,9 @@ extern function <bool(SDL_Event &ev)> 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);

28
rug.cpp
View File

@ -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;
}