diff options
author | Franklin Wei <git@fwei.tk> | 2017-10-23 17:19:29 -0400 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-10-23 17:19:29 -0400 |
commit | ef1306764e6443d67612542654f252b376c5993e (patch) | |
tree | 5f064178c1f9a23695b1b52b8bd487434be9006e /apps/plugins/puzzles/src/pegs.c | |
parent | 7a8c9daf7ef5a8b38d4c4f6625ff2d9d8eb1aa0a (diff) | |
download | rockbox-ef1306764e6443d67612542654f252b376c5993e.tar.gz rockbox-ef1306764e6443d67612542654f252b376c5993e.zip |
puzzles: resync with upstream
There have been some improvements with regard to small screen sizes,
which will be nice to have.
Change-Id: I30c740514156258d2818fde325c1a751500f7611
Diffstat (limited to 'apps/plugins/puzzles/src/pegs.c')
-rw-r--r-- | apps/plugins/puzzles/src/pegs.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/apps/plugins/puzzles/src/pegs.c b/apps/plugins/puzzles/src/pegs.c index 8286851954..565ba9417f 100644 --- a/apps/plugins/puzzles/src/pegs.c +++ b/apps/plugins/puzzles/src/pegs.c | |||
@@ -149,24 +149,20 @@ static config_item *game_configure(const game_params *params) | |||
149 | ret[0].name = "Width"; | 149 | ret[0].name = "Width"; |
150 | ret[0].type = C_STRING; | 150 | ret[0].type = C_STRING; |
151 | sprintf(buf, "%d", params->w); | 151 | sprintf(buf, "%d", params->w); |
152 | ret[0].sval = dupstr(buf); | 152 | ret[0].u.string.sval = dupstr(buf); |
153 | ret[0].ival = 0; | ||
154 | 153 | ||
155 | ret[1].name = "Height"; | 154 | ret[1].name = "Height"; |
156 | ret[1].type = C_STRING; | 155 | ret[1].type = C_STRING; |
157 | sprintf(buf, "%d", params->h); | 156 | sprintf(buf, "%d", params->h); |
158 | ret[1].sval = dupstr(buf); | 157 | ret[1].u.string.sval = dupstr(buf); |
159 | ret[1].ival = 0; | ||
160 | 158 | ||
161 | ret[2].name = "Board type"; | 159 | ret[2].name = "Board type"; |
162 | ret[2].type = C_CHOICES; | 160 | ret[2].type = C_CHOICES; |
163 | ret[2].sval = TYPECONFIG; | 161 | ret[2].u.choices.choicenames = TYPECONFIG; |
164 | ret[2].ival = params->type; | 162 | ret[2].u.choices.selected = params->type; |
165 | 163 | ||
166 | ret[3].name = NULL; | 164 | ret[3].name = NULL; |
167 | ret[3].type = C_END; | 165 | ret[3].type = C_END; |
168 | ret[3].sval = NULL; | ||
169 | ret[3].ival = 0; | ||
170 | 166 | ||
171 | return ret; | 167 | return ret; |
172 | } | 168 | } |
@@ -175,14 +171,14 @@ static game_params *custom_params(const config_item *cfg) | |||
175 | { | 171 | { |
176 | game_params *ret = snew(game_params); | 172 | game_params *ret = snew(game_params); |
177 | 173 | ||
178 | ret->w = atoi(cfg[0].sval); | 174 | ret->w = atoi(cfg[0].u.string.sval); |
179 | ret->h = atoi(cfg[1].sval); | 175 | ret->h = atoi(cfg[1].u.string.sval); |
180 | ret->type = cfg[2].ival; | 176 | ret->type = cfg[2].u.choices.selected; |
181 | 177 | ||
182 | return ret; | 178 | return ret; |
183 | } | 179 | } |
184 | 180 | ||
185 | static char *validate_params(const game_params *params, int full) | 181 | static const char *validate_params(const game_params *params, int full) |
186 | { | 182 | { |
187 | if (full && (params->w <= 3 || params->h <= 3)) | 183 | if (full && (params->w <= 3 || params->h <= 3)) |
188 | return "Width and height must both be greater than three"; | 184 | return "Width and height must both be greater than three"; |
@@ -660,7 +656,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, | |||
660 | return ret; | 656 | return ret; |
661 | } | 657 | } |
662 | 658 | ||
663 | static char *validate_desc(const game_params *params, const char *desc) | 659 | static const char *validate_desc(const game_params *params, const char *desc) |
664 | { | 660 | { |
665 | int len = params->w * params->h; | 661 | int len = params->w * params->h; |
666 | 662 | ||
@@ -711,7 +707,7 @@ static void free_game(game_state *state) | |||
711 | } | 707 | } |
712 | 708 | ||
713 | static char *solve_game(const game_state *state, const game_state *currstate, | 709 | static char *solve_game(const game_state *state, const game_state *currstate, |
714 | const char *aux, char **error) | 710 | const char *aux, const char **error) |
715 | { | 711 | { |
716 | return NULL; | 712 | return NULL; |
717 | } | 713 | } |
@@ -848,7 +844,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
848 | ui->dx = x; | 844 | ui->dx = x; |
849 | ui->dy = y; | 845 | ui->dy = y; |
850 | ui->cur_visible = ui->cur_jumping = 0; | 846 | ui->cur_visible = ui->cur_jumping = 0; |
851 | return ""; /* ui modified */ | 847 | return UI_UPDATE; |
852 | } | 848 | } |
853 | } else if (button == LEFT_DRAG && ui->dragging) { | 849 | } else if (button == LEFT_DRAG && ui->dragging) { |
854 | /* | 850 | /* |
@@ -856,7 +852,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
856 | */ | 852 | */ |
857 | ui->dx = x; | 853 | ui->dx = x; |
858 | ui->dy = y; | 854 | ui->dy = y; |
859 | return ""; /* ui modified */ | 855 | return UI_UPDATE; |
860 | } else if (button == LEFT_RELEASE && ui->dragging) { | 856 | } else if (button == LEFT_RELEASE && ui->dragging) { |
861 | int tx, ty, dx, dy; | 857 | int tx, ty, dx, dy; |
862 | 858 | ||
@@ -868,18 +864,18 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
868 | tx = FROMCOORD(x); | 864 | tx = FROMCOORD(x); |
869 | ty = FROMCOORD(y); | 865 | ty = FROMCOORD(y); |
870 | if (tx < 0 || tx >= w || ty < 0 || ty >= h) | 866 | if (tx < 0 || tx >= w || ty < 0 || ty >= h) |
871 | return ""; /* target out of range */ | 867 | return UI_UPDATE; /* target out of range */ |
872 | dx = tx - ui->sx; | 868 | dx = tx - ui->sx; |
873 | dy = ty - ui->sy; | 869 | dy = ty - ui->sy; |
874 | if (max(abs(dx),abs(dy)) != 2 || min(abs(dx),abs(dy)) != 0) | 870 | if (max(abs(dx),abs(dy)) != 2 || min(abs(dx),abs(dy)) != 0) |
875 | return ""; /* move length was wrong */ | 871 | return UI_UPDATE; /* move length was wrong */ |
876 | dx /= 2; | 872 | dx /= 2; |
877 | dy /= 2; | 873 | dy /= 2; |
878 | 874 | ||
879 | if (state->grid[ty*w+tx] != GRID_HOLE || | 875 | if (state->grid[ty*w+tx] != GRID_HOLE || |
880 | state->grid[(ty-dy)*w+(tx-dx)] != GRID_PEG || | 876 | state->grid[(ty-dy)*w+(tx-dx)] != GRID_PEG || |
881 | state->grid[ui->sy*w+ui->sx] != GRID_PEG) | 877 | state->grid[ui->sy*w+ui->sx] != GRID_PEG) |
882 | return ""; /* grid contents were invalid */ | 878 | return UI_UPDATE; /* grid contents were invalid */ |
883 | 879 | ||
884 | /* | 880 | /* |
885 | * We have a valid move. Encode it simply as source and | 881 | * We have a valid move. Encode it simply as source and |
@@ -899,7 +895,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
899 | ui->cur_x = cx; | 895 | ui->cur_x = cx; |
900 | ui->cur_y = cy; | 896 | ui->cur_y = cy; |
901 | } | 897 | } |
902 | return ""; | 898 | return UI_UPDATE; |
903 | } else { | 899 | } else { |
904 | int dx, dy, mx, my, jx, jy; | 900 | int dx, dy, mx, my, jx, jy; |
905 | 901 | ||
@@ -922,21 +918,21 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
922 | ui->cur_x = jx; ui->cur_y = jy; | 918 | ui->cur_x = jx; ui->cur_y = jy; |
923 | return dupstr(buf); | 919 | return dupstr(buf); |
924 | } | 920 | } |
925 | return ""; | 921 | return UI_UPDATE; |
926 | } | 922 | } |
927 | } else if (IS_CURSOR_SELECT(button)) { | 923 | } else if (IS_CURSOR_SELECT(button)) { |
928 | if (!ui->cur_visible) { | 924 | if (!ui->cur_visible) { |
929 | ui->cur_visible = 1; | 925 | ui->cur_visible = 1; |
930 | return ""; | 926 | return UI_UPDATE; |
931 | } | 927 | } |
932 | if (ui->cur_jumping) { | 928 | if (ui->cur_jumping) { |
933 | ui->cur_jumping = 0; | 929 | ui->cur_jumping = 0; |
934 | return ""; | 930 | return UI_UPDATE; |
935 | } | 931 | } |
936 | if (state->grid[ui->cur_y*w+ui->cur_x] == GRID_PEG) { | 932 | if (state->grid[ui->cur_y*w+ui->cur_x] == GRID_PEG) { |
937 | /* cursor is on peg: next arrow-move wil jump. */ | 933 | /* cursor is on peg: next arrow-move wil jump. */ |
938 | ui->cur_jumping = 1; | 934 | ui->cur_jumping = 1; |
939 | return ""; | 935 | return UI_UPDATE; |
940 | } | 936 | } |
941 | return NULL; | 937 | return NULL; |
942 | } | 938 | } |