mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Some patches from James H:
- reinstate the initialisation of ds->w and ds->h in guess.c, which I'd accidentally removed during game_size() refactoring - reorganise Net's interpret_move() so that my uncommitted patch for drag-based UI (which he uses on the Palm port) will apply more easily - the interpret_move() changes make it easy to have a single move type which rotates a tile by 180 degrees, so this is now provided via the `F' key (but there's no spare button available to provide it via the mouse). [originally from svn r6070]
This commit is contained in:
8
guess.c
8
guess.c
@ -835,7 +835,7 @@ static void game_compute_size(game_params *params, int tilesize,
|
|||||||
static void game_set_size(game_drawstate *ds, game_params *params,
|
static void game_set_size(game_drawstate *ds, game_params *params,
|
||||||
int tilesize)
|
int tilesize)
|
||||||
{
|
{
|
||||||
int colh, guessh, x, y;
|
int colh, guessh;
|
||||||
|
|
||||||
ds->pegsz = tilesize;
|
ds->pegsz = tilesize;
|
||||||
|
|
||||||
@ -850,12 +850,12 @@ static void game_set_size(game_drawstate *ds, game_params *params,
|
|||||||
guessh = ((ds->pegsz + ds->gapsz) * params->nguesses); /* guesses */
|
guessh = ((ds->pegsz + ds->gapsz) * params->nguesses); /* guesses */
|
||||||
guessh += ds->gapsz + ds->pegsz; /* solution */
|
guessh += ds->gapsz + ds->pegsz; /* solution */
|
||||||
|
|
||||||
game_compute_size(params, tilesize, &x, &y);
|
game_compute_size(params, tilesize, &ds->w, &ds->h);
|
||||||
ds->colx = ds->border;
|
ds->colx = ds->border;
|
||||||
ds->coly = (y - colh) / 2;
|
ds->coly = (ds->h - colh) / 2;
|
||||||
|
|
||||||
ds->guessx = ds->solnx = ds->border + ds->pegsz * 2; /* border + colours */
|
ds->guessx = ds->solnx = ds->border + ds->pegsz * 2; /* border + colours */
|
||||||
ds->guessy = (y - guessh) / 2;
|
ds->guessy = (ds->h - guessh) / 2;
|
||||||
ds->solny = ds->guessy + ((ds->pegsz + ds->gapsz) * params->nguesses) + ds->gapsz;
|
ds->solny = ds->guessy + ((ds->pegsz + ds->gapsz) * params->nguesses) + ds->gapsz;
|
||||||
|
|
||||||
assert(ds->pegsz > 0);
|
assert(ds->pegsz > 0);
|
||||||
|
81
net.c
81
net.c
@ -1881,11 +1881,16 @@ static char *interpret_move(game_state *state, game_ui *ui,
|
|||||||
game_drawstate *ds, int x, int y, int button)
|
game_drawstate *ds, int x, int y, int button)
|
||||||
{
|
{
|
||||||
char *nullret;
|
char *nullret;
|
||||||
int tx, ty;
|
int tx = -1, ty = -1, dir = 0;
|
||||||
int shift = button & MOD_SHFT, ctrl = button & MOD_CTRL;
|
int shift = button & MOD_SHFT, ctrl = button & MOD_CTRL;
|
||||||
|
enum {
|
||||||
|
NONE, ROTATE_LEFT, ROTATE_180, ROTATE_RIGHT, TOGGLE_LOCK, JUMBLE,
|
||||||
|
MOVE_ORIGIN, MOVE_SOURCE, MOVE_ORIGIN_AND_SOURCE, MOVE_CURSOR
|
||||||
|
} action;
|
||||||
|
|
||||||
button &= ~MOD_MASK;
|
button &= ~MOD_MASK;
|
||||||
nullret = NULL;
|
nullret = NULL;
|
||||||
|
action = NONE;
|
||||||
|
|
||||||
if (button == LEFT_BUTTON ||
|
if (button == LEFT_BUTTON ||
|
||||||
button == MIDDLE_BUTTON ||
|
button == MIDDLE_BUTTON ||
|
||||||
@ -1913,9 +1918,11 @@ static char *interpret_move(game_state *state, game_ui *ui,
|
|||||||
if (x % TILE_SIZE >= TILE_SIZE - TILE_BORDER ||
|
if (x % TILE_SIZE >= TILE_SIZE - TILE_BORDER ||
|
||||||
y % TILE_SIZE >= TILE_SIZE - TILE_BORDER)
|
y % TILE_SIZE >= TILE_SIZE - TILE_BORDER)
|
||||||
return nullret;
|
return nullret;
|
||||||
|
|
||||||
|
action = button == LEFT_BUTTON ? ROTATE_LEFT :
|
||||||
|
button == RIGHT_BUTTON ? ROTATE_RIGHT : TOGGLE_LOCK;
|
||||||
} else if (button == CURSOR_UP || button == CURSOR_DOWN ||
|
} else if (button == CURSOR_UP || button == CURSOR_DOWN ||
|
||||||
button == CURSOR_RIGHT || button == CURSOR_LEFT) {
|
button == CURSOR_RIGHT || button == CURSOR_LEFT) {
|
||||||
int dir;
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case CURSOR_UP: dir = U; break;
|
case CURSOR_UP: dir = U; break;
|
||||||
case CURSOR_DOWN: dir = D; break;
|
case CURSOR_DOWN: dir = D; break;
|
||||||
@ -1923,44 +1930,28 @@ static char *interpret_move(game_state *state, game_ui *ui,
|
|||||||
case CURSOR_RIGHT: dir = R; break;
|
case CURSOR_RIGHT: dir = R; break;
|
||||||
default: return nullret;
|
default: return nullret;
|
||||||
}
|
}
|
||||||
if (shift) {
|
if (shift && ctrl) action = MOVE_ORIGIN_AND_SOURCE;
|
||||||
/*
|
else if (shift) action = MOVE_ORIGIN;
|
||||||
* Move origin.
|
else if (ctrl) action = MOVE_SOURCE;
|
||||||
*/
|
else action = MOVE_CURSOR;
|
||||||
if (state->wrapping) {
|
|
||||||
OFFSET(ui->org_x, ui->org_y, ui->org_x, ui->org_y, dir, state);
|
|
||||||
} else return nullret; /* disallowed for non-wrapping grids */
|
|
||||||
}
|
|
||||||
if (ctrl) {
|
|
||||||
/*
|
|
||||||
* Change source tile.
|
|
||||||
*/
|
|
||||||
OFFSET(ui->cx, ui->cy, ui->cx, ui->cy, dir, state);
|
|
||||||
}
|
|
||||||
if (!shift && !ctrl) {
|
|
||||||
/*
|
|
||||||
* Move keyboard cursor.
|
|
||||||
*/
|
|
||||||
OFFSET(ui->cur_x, ui->cur_y, ui->cur_x, ui->cur_y, dir, state);
|
|
||||||
ui->cur_visible = TRUE;
|
|
||||||
}
|
|
||||||
return ""; /* UI activity has occurred */
|
|
||||||
} else if (button == 'a' || button == 's' || button == 'd' ||
|
} else if (button == 'a' || button == 's' || button == 'd' ||
|
||||||
button == 'A' || button == 'S' || button == 'D' ||
|
button == 'A' || button == 'S' || button == 'D' ||
|
||||||
|
button == 'f' || button == 'F' ||
|
||||||
button == CURSOR_SELECT) {
|
button == CURSOR_SELECT) {
|
||||||
tx = ui->cur_x;
|
tx = ui->cur_x;
|
||||||
ty = ui->cur_y;
|
ty = ui->cur_y;
|
||||||
if (button == 'a' || button == 'A' || button == CURSOR_SELECT)
|
if (button == 'a' || button == 'A' || button == CURSOR_SELECT)
|
||||||
button = LEFT_BUTTON;
|
action = ROTATE_LEFT;
|
||||||
else if (button == 's' || button == 'S')
|
else if (button == 's' || button == 'S')
|
||||||
button = MIDDLE_BUTTON;
|
action = TOGGLE_LOCK;
|
||||||
else if (button == 'd' || button == 'D')
|
else if (button == 'd' || button == 'D')
|
||||||
button = RIGHT_BUTTON;
|
action = ROTATE_RIGHT;
|
||||||
|
else if (button == 'f' || button == 'F')
|
||||||
|
action = ROTATE_180;
|
||||||
ui->cur_visible = TRUE;
|
ui->cur_visible = TRUE;
|
||||||
} else if (button == 'j' || button == 'J') {
|
} else if (button == 'j' || button == 'J') {
|
||||||
/* XXX should we have some mouse control for this? */
|
/* XXX should we have some mouse control for this? */
|
||||||
button = 'J'; /* canonify */
|
action = JUMBLE;
|
||||||
tx = ty = -1; /* shut gcc up :( */
|
|
||||||
} else
|
} else
|
||||||
return nullret;
|
return nullret;
|
||||||
|
|
||||||
@ -1974,11 +1965,12 @@ static char *interpret_move(game_state *state, game_ui *ui,
|
|||||||
* accident. If they change their mind, another middle click
|
* accident. If they change their mind, another middle click
|
||||||
* unlocks it.)
|
* unlocks it.)
|
||||||
*/
|
*/
|
||||||
if (button == MIDDLE_BUTTON) {
|
if (action == TOGGLE_LOCK) {
|
||||||
char buf[80];
|
char buf[80];
|
||||||
sprintf(buf, "L%d,%d", tx, ty);
|
sprintf(buf, "L%d,%d", tx, ty);
|
||||||
return dupstr(buf);
|
return dupstr(buf);
|
||||||
} else if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
|
} else if (action == ROTATE_LEFT || action == ROTATE_RIGHT ||
|
||||||
|
action == ROTATE_180) {
|
||||||
char buf[80];
|
char buf[80];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1992,9 +1984,10 @@ static char *interpret_move(game_state *state, game_ui *ui,
|
|||||||
* Otherwise, turn the tile one way or the other. Left button
|
* Otherwise, turn the tile one way or the other. Left button
|
||||||
* turns anticlockwise; right button turns clockwise.
|
* turns anticlockwise; right button turns clockwise.
|
||||||
*/
|
*/
|
||||||
sprintf(buf, "%c%d,%d", (button == LEFT_BUTTON ? 'A' : 'C'), tx, ty);
|
sprintf(buf, "%c%d,%d", (int)(action == ROTATE_LEFT ? 'A' :
|
||||||
|
action == ROTATE_RIGHT ? 'C' : 'F'), tx, ty);
|
||||||
return dupstr(buf);
|
return dupstr(buf);
|
||||||
} else if (button == 'J') {
|
} else if (action == JUMBLE) {
|
||||||
/*
|
/*
|
||||||
* Jumble all unlocked tiles to random orientations.
|
* Jumble all unlocked tiles to random orientations.
|
||||||
*/
|
*/
|
||||||
@ -2027,6 +2020,22 @@ static char *interpret_move(game_state *state, game_ui *ui,
|
|||||||
ret = sresize(ret, p - ret, char);
|
ret = sresize(ret, p - ret, char);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
} else if (action == MOVE_ORIGIN || action == MOVE_SOURCE ||
|
||||||
|
action == MOVE_ORIGIN_AND_SOURCE || action == MOVE_CURSOR) {
|
||||||
|
assert(dir != 0);
|
||||||
|
if (action == MOVE_ORIGIN || action == MOVE_ORIGIN_AND_SOURCE) {
|
||||||
|
if (state->wrapping) {
|
||||||
|
OFFSET(ui->org_x, ui->org_y, ui->org_x, ui->org_y, dir, state);
|
||||||
|
} else return nullret; /* disallowed for non-wrapping grids */
|
||||||
|
}
|
||||||
|
if (action == MOVE_SOURCE || action == MOVE_ORIGIN_AND_SOURCE) {
|
||||||
|
OFFSET(ui->cx, ui->cy, ui->cx, ui->cy, dir, state);
|
||||||
|
}
|
||||||
|
if (action == MOVE_CURSOR) {
|
||||||
|
OFFSET(ui->cur_x, ui->cur_y, ui->cur_x, ui->cur_y, dir, state);
|
||||||
|
ui->cur_visible = TRUE;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2066,10 +2075,8 @@ static game_state *execute_move(game_state *from, char *move)
|
|||||||
ret->last_rotate_dir = +1;
|
ret->last_rotate_dir = +1;
|
||||||
} else if (move[0] == 'F') {
|
} else if (move[0] == 'F') {
|
||||||
tile(ret, tx, ty) = F(orig);
|
tile(ret, tx, ty) = F(orig);
|
||||||
if (!noanim) {
|
if (!noanim)
|
||||||
free_game(ret);
|
ret->last_rotate_dir = +2; /* + for sake of argument */
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else if (move[0] == 'C') {
|
} else if (move[0] == 'C') {
|
||||||
tile(ret, tx, ty) = C(orig);
|
tile(ret, tx, ty) = C(orig);
|
||||||
if (!noanim)
|
if (!noanim)
|
||||||
|
@ -330,6 +330,8 @@ controls are:
|
|||||||
|
|
||||||
\dt \e{Rotate tile clockwise}: right mouse button, \q{D} key
|
\dt \e{Rotate tile clockwise}: right mouse button, \q{D} key
|
||||||
|
|
||||||
|
\dt \e{Rotate tile by 180 degrees}: \q{F} key
|
||||||
|
|
||||||
\dt \e{Lock (or unlock) tile}: middle mouse button, shift-click, \q{S} key
|
\dt \e{Lock (or unlock) tile}: middle mouse button, shift-click, \q{S} key
|
||||||
|
|
||||||
\dd You can lock a tile once you're sure of its orientation. You can
|
\dd You can lock a tile once you're sure of its orientation. You can
|
||||||
|
Reference in New Issue
Block a user