galaxies: Use the same code for handling all dropped arrows

The keyboard code was prone to adding null items to the undo history,
and was also unreadable.  Rather than fix it, I've replaced it with a
jump to the mouse drop handling, lightly enhanced to reject drops on
things that aren't tiles.
This commit is contained in:
Ben Harris
2022-12-07 18:43:34 +00:00
parent 09f2052fbf
commit 0b036c9e79

View File

@ -353,6 +353,8 @@ static bool ok_to_add_assoc_with_opposite_internal(
int *colors; int *colors;
bool toret; bool toret;
if (tile->type != s_tile)
return false;
if (tile->flags & F_DOT) if (tile->flags & F_DOT)
return false; return false;
if (opposite == NULL) if (opposite == NULL)
@ -2645,14 +2647,14 @@ static char *interpret_move(const game_state *state, game_ui *ui,
ui->dy = y; ui->dy = y;
return UI_UPDATE; return UI_UPDATE;
} else if (button == RIGHT_RELEASE && ui->dragging) { } else if (button == RIGHT_RELEASE && ui->dragging) {
ui->dragging = false;
/* /*
* Drags are always targeted at a single square. * Drags are always targeted at a single square.
*/ */
px = 2*FROMCOORD(x+TILE_SIZE) - 1; px = 2*FROMCOORD(x+TILE_SIZE) - 1;
py = 2*FROMCOORD(y+TILE_SIZE) - 1; py = 2*FROMCOORD(y+TILE_SIZE) - 1;
dropped: /* We arrive here from the end of a keyboard drag. */
ui->dragging = false;
/* /*
* Dragging an arrow on to the same square it started from * Dragging an arrow on to the same square it started from
* is a null move; just update the ui and finish. * is a null move; just update the ui and finish.
@ -2710,18 +2712,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
} }
sp = &SPACE(state, ui->cur_x, ui->cur_y); sp = &SPACE(state, ui->cur_x, ui->cur_y);
if (ui->dragging) { if (ui->dragging) {
ui->dragging = false; px = ui->cur_x; py = ui->cur_y;
goto dropped;
if ((ui->srcx != ui->dotx || ui->srcy != ui->doty) &&
SPACE(state, ui->srcx, ui->srcy).flags & F_TILE_ASSOC) {
sprintf(buf, "%sU%d,%d", sep, ui->srcx, ui->srcy);
sep = ";";
}
if (sp->type == s_tile && !(sp->flags & F_DOT) && !(sp->flags & F_TILE_ASSOC)) {
sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d",
sep, ui->cur_x, ui->cur_y, ui->dotx, ui->doty);
}
return dupstr(buf);
} else if (sp->flags & F_DOT) { } else if (sp->flags & F_DOT) {
ui->dragging = true; ui->dragging = true;
ui->dx = SCOORD(ui->cur_x); ui->dx = SCOORD(ui->cur_x);