- if (button != LEFT_BUTTON && button != RIGHT_BUTTON)
- return NULL;
-
- cx = FROMCOORD(x);
- cy = FROMCOORD(y);
- if (cx == -1 && cy >= 0 && cy < from->h)
- n = from->w, dx = +1, dy = 0;
- else if (cx == from->w && cy >= 0 && cy < from->h)
- n = from->w, dx = -1, dy = 0;
- else if (cy == -1 && cx >= 0 && cx < from->w)
- n = from->h, dy = +1, dx = 0;
- else if (cy == from->h && cx >= 0 && cx < from->w)
- n = from->h, dy = -1, dx = 0;
+static void decode_ui(game_ui *ui, const char *encoding)
+{
+}
+
+static void game_changed_state(game_ui *ui, const game_state *oldstate,
+ const game_state *newstate)
+{
+}
+
+struct game_drawstate {
+ int started;
+ int w, h, bgcolour;
+ int *tiles;
+ int tilesize;
+ int cur_x, cur_y;
+};
+
+static char *interpret_move(const game_state *state, game_ui *ui,
+ const game_drawstate *ds,
+ int x, int y, int button)
+{
+ int cx = -1, cy = -1, dx, dy;
+ char buf[80];
+ int shift = button & MOD_SHFT, control = button & MOD_CTRL,
+ pad = button & MOD_NUM_KEYPAD;
+
+ button &= ~MOD_MASK;
+
+ if (IS_CURSOR_MOVE(button) || pad) {
+ if (!ui->cur_visible) {
+ ui->cur_visible = 1;
+ return "";
+ }
+
+ if (control || shift || ui->cur_mode) {
+ int x = ui->cur_x, y = ui->cur_y, xwrap = x, ywrap = y;
+ if (x < 0 || x >= state->w || y < 0 || y >= state->h)
+ return NULL;
+ move_cursor(button | pad, &x, &y,
+ state->w, state->h, FALSE);
+ move_cursor(button | pad, &xwrap, &ywrap,
+ state->w, state->h, TRUE);
+
+ if (x != xwrap) {
+ sprintf(buf, "R%d,%c1", y, x ? '+' : '-');
+ } else if (y != ywrap) {
+ sprintf(buf, "C%d,%c1", x, y ? '+' : '-');
+ } else if (x == ui->cur_x)
+ sprintf(buf, "C%d,%d", x, y - ui->cur_y);
+ else
+ sprintf(buf, "R%d,%d", y, x - ui->cur_x);
+
+ if (control || (!shift && ui->cur_mode == lock_tile)) {
+ ui->cur_x = xwrap;
+ ui->cur_y = ywrap;
+ }
+
+ return dupstr(buf);
+ } else {
+ int x = ui->cur_x + 1, y = ui->cur_y + 1;
+
+ move_cursor(button | pad, &x, &y,
+ state->w + 2, state->h + 2, FALSE);
+
+ if (x == 0 && y == 0) {
+ int t = ui->cur_x;
+ ui->cur_x = ui->cur_y;
+ ui->cur_y = t;
+ } else if (x == 0 && y == state->h + 1) {
+ int t = ui->cur_x;
+ ui->cur_x = (state->h - 1) - ui->cur_y;
+ ui->cur_y = (state->h - 1) - t;
+ } else if (x == state->w + 1 && y == 0) {
+ int t = ui->cur_x;
+ ui->cur_x = (state->w - 1) - ui->cur_y;
+ ui->cur_y = (state->w - 1) - t;
+ } else if (x == state->w + 1 && y == state->h + 1) {
+ int t = ui->cur_x;
+ ui->cur_x = state->w - state->h + ui->cur_y;
+ ui->cur_y = state->h - state->w + t;
+ } else {
+ ui->cur_x = x - 1;
+ ui->cur_y = y - 1;
+ }
+
+ ui->cur_visible = 1;
+ return "";
+ }
+ }
+
+ if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
+ cx = FROMCOORD(x);
+ cy = FROMCOORD(y);
+ ui->cur_visible = 0;
+ } else if (IS_CURSOR_SELECT(button)) {
+ if (ui->cur_visible) {
+ if (ui->cur_x == -1 || ui->cur_x == state->w ||
+ ui->cur_y == -1 || ui->cur_y == state->h) {
+ cx = ui->cur_x;
+ cy = ui->cur_y;
+ } else {
+ const enum cursor_mode m = (button == CURSOR_SELECT2 ?
+ lock_position : lock_tile);
+ ui->cur_mode = (ui->cur_mode == m ? unlocked : m);
+ return "";
+ }
+ } else {
+ ui->cur_visible = 1;
+ return "";
+ }
+ } else {
+ return NULL;
+ }
+
+ if (cx == -1 && cy >= 0 && cy < state->h)
+ dx = -1, dy = 0;
+ else if (cx == state->w && cy >= 0 && cy < state->h)
+ dx = +1, dy = 0;
+ else if (cy == -1 && cx >= 0 && cx < state->w)
+ dy = -1, dx = 0;
+ else if (cy == state->h && cx >= 0 && cx < state->w)
+ dy = +1, dx = 0;