mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Introduce a new game backend function (there seem to have been a lot
of these recently) whose job is to update a game_ui to be consistent with a new game_state. This is called by midend.c in every situation where the current game_state changes _other_ than as a result of make_move (Undo, Redo, Restart, Solve). The introduction of this function allows a game_ui to contain information about selections or highlights within a game_state which simply wouldn't make sense when transferred to another game_state. In particular, I've used it to fix a subtle bug in Solo whereby, although you couldn't right-click to pencil-mode highlight a filled square, you could _get_ a pencil-mode highlight in a filled square if you used Undo and Redo. (Undo to before the square was filled, right-click to highlight it, then Redo. Alternatively, left-click and clear the square, right-click to highlight it, then Undo.) [originally from svn r5912]
This commit is contained in:
16
midend.c
16
midend.c
@ -228,6 +228,10 @@ void midend_new_game(midend_data *me)
|
||||
static int midend_undo(midend_data *me)
|
||||
{
|
||||
if (me->statepos > 1) {
|
||||
if (me->ui)
|
||||
me->ourgame->changed_state(me->ui,
|
||||
me->states[me->statepos-1].state,
|
||||
me->states[me->statepos-2].state);
|
||||
me->statepos--;
|
||||
me->dir = -1;
|
||||
return 1;
|
||||
@ -238,6 +242,10 @@ static int midend_undo(midend_data *me)
|
||||
static int midend_redo(midend_data *me)
|
||||
{
|
||||
if (me->statepos < me->nstates) {
|
||||
if (me->ui)
|
||||
me->ourgame->changed_state(me->ui,
|
||||
me->states[me->statepos-1].state,
|
||||
me->states[me->statepos].state);
|
||||
me->statepos++;
|
||||
me->dir = +1;
|
||||
return 1;
|
||||
@ -308,6 +316,10 @@ void midend_restart_game(midend_data *me)
|
||||
me->states[me->nstates].state = s;
|
||||
me->states[me->nstates].special = TRUE; /* we just restarted */
|
||||
me->statepos = ++me->nstates;
|
||||
if (me->ui)
|
||||
me->ourgame->changed_state(me->ui,
|
||||
me->states[me->statepos-2].state,
|
||||
me->states[me->statepos-1].state);
|
||||
me->anim_time = 0.0;
|
||||
midend_finish_move(me);
|
||||
midend_redraw(me);
|
||||
@ -936,6 +948,10 @@ char *midend_solve(midend_data *me)
|
||||
me->states[me->nstates].state = s;
|
||||
me->states[me->nstates].special = TRUE; /* created using solve */
|
||||
me->statepos = ++me->nstates;
|
||||
if (me->ui)
|
||||
me->ourgame->changed_state(me->ui,
|
||||
me->states[me->statepos-2].state,
|
||||
me->states[me->statepos-1].state);
|
||||
me->anim_time = 0.0;
|
||||
midend_finish_move(me);
|
||||
midend_redraw(me);
|
||||
|
Reference in New Issue
Block a user