From aa1dd8348fdd7d6dbb17440770b12bc42b780484 Mon Sep 17 00:00:00 2001 From: girst Date: Tue, 19 Feb 2019 13:27:58 +0100 Subject: [PATCH] freecell: mouse select for cells/foundation --- README.md | 11 +++++------ sol.c | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8c21e55..6819fda 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,13 @@ General Public License, version 3. Copyright 2019 Tobias Girstmair. For licensing details, see `LICENSE`.
-## TODO +

TODO

### P1 - * TODO FREECELL: t2t() multi card move and accompanying pop_undo() - (also DO_HI and TOP_HI macros) - * TODO FREECELL: non-hjkl/cursor addressing: - - mouse (term2pile() cell encoding, set_mouse(), wait_mouse_up()) - - direct addressing ("select correct cell/found pile") + * TODO FREECELL: don't allow selecting more cards than movable (`DO_HI, TOP_HI, cursor_{up,down}`) + * TODO FREECELL: autodetect possible moves (card selector choice dialog) ### P2 * TODO: suggest moves (`h` => hint) * TODO: cleanup: in `x2y()` functions there is a lot of replication and noise @@ -111,6 +108,8 @@ licensing details, see `LICENSE`. * DONE: `:help` to show keyhelp (/u/Valley6660) * DONE: don't show cursor-highlight when inputting directly or with the mouse (/u/TooEarlyForMe) * DONE: remove sysmlink trickery and just call sol.c explicitly + * DONE FREECELL: t2t() multi card move and accompanying pop_undo() + * DONE: - mouse (term2pile() cell encoding, set_mouse(), wait_mouse_up())
## Notes diff --git a/sol.c b/sol.c index f0d3a98..23154dc 100644 --- a/sol.c +++ b/sol.c @@ -866,6 +866,7 @@ void cursor_to (struct cursor* cursor, int pile) { cursor->opt = 0; } int set_mouse(int pile, int* main, int* opt) { +//TODO: this should set cursor.opt, so card selector choice dialog does not trigger! op.h = 0; if (pile < 0) return 1; *main = pile; @@ -876,7 +877,10 @@ int set_mouse(int pile, int* main, int* opt) { #elif defined SPIDER (void)opt; #elif defined FREECELL - (void)opt; //TODO FREECELL: needs to decode not-yet-decided term2pile STOCK/FOUNDATION encodings + if (pile > TAB_MAX) { + *main = pile-STOCK < NUM_CELLS? STOCK : FOUNDATION; + *opt = (pile-STOCK) % 4; + } #endif return 0; } @@ -960,6 +964,10 @@ from_l: print_table(&active, &inactive); case MOUSE_LEFT: if (set_mouse(term2pile(mouse), from, opt)) return CMD_INVAL; +#ifdef FREECELL + if (!is_tableu(*from)) + inactive.opt = *opt; /* prevents card selector dialog */ +#endif break; /* misc keys: */ case ':': @@ -1231,7 +1239,8 @@ int term2pile(unsigned char *mouse) { if (column < 3) return STOCK; return -1; #elif defined FREECELL - //TODO FREECELL: term2pile cells/foundation (how to encode open cells?) + if (column < NUM_SUITS + NUM_CELLS) return STOCK+column; + return -1; #endif } else if (line > op.s->height) { /* tableu */ if (column <= TAB_MAX) return column; @@ -1248,11 +1257,15 @@ int wait_mouse_up(unsigned char* mouse) { int pile = term2pile(mouse); cur.pile = pile; #ifdef KLONDIKE -//TODO: need something similar from FREECELL if (pile >= FOUNDATION) { cur.pile = FOUNDATION; cur.opt = pile-FOUNDATION; } +#elif defined FREECELL + if (pile > TAB_MAX) { + cur.pile = pile-STOCK < NUM_CELLS? STOCK : FOUNDATION; + cur.opt = (pile-STOCK) % 4; + } #endif /* need to temporarily show the cursor, then revert to last state: */ int old_show_cursor_hi = op.h; //TODO: ARGH! that's awful! -- 2.39.3