mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-06 05:48:06 +03:00
Gakuen KING: highlight grid selection cursor without a mouse pointer
Some environments have no mouse, or cannot confine the pointer to the grid, leaving keyboard-only players with no visible cursor. Redraw the grid with a frame on the item under the cursor whenever an arrow key moves it.
This commit is contained in:
+45
-16
@@ -1242,6 +1242,41 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Holds the frameless grid, which erases the highlight when it moves.
|
||||
static constexpr int GRID_BACKUP_SCREEN = 2;
|
||||
|
||||
void draw_grid_base(int cg_page, bool wide, int cols, int cell_w, int nr_items) {
|
||||
load_cg_to_work_screen(cg_page);
|
||||
for (int i = 0; i < nr_items; i++) {
|
||||
if (grid_item_state[i] != 0)
|
||||
continue;
|
||||
int sx = GRID_X + (i % cols) * cell_w;
|
||||
int sy = (wide ? 8 : 7) + (i / cols) * 32;
|
||||
ags->box_fill(WORK_SCREEN, sx, sy, sx + cell_w - 1, sy + (wide ? 31 : 32), 0);
|
||||
}
|
||||
ags->copy_screen(WORK_SCREEN, GRID_BACKUP_SCREEN, GRID_COPY_X1, 0,
|
||||
GRID_COPY_X2, GRID_COPY_Y2, GRID_COPY_X1, 0);
|
||||
}
|
||||
|
||||
void restore_grid_base() {
|
||||
ags->copy_screen(GRID_BACKUP_SCREEN, WORK_SCREEN, GRID_COPY_X1, 0,
|
||||
GRID_COPY_X2, GRID_COPY_Y2, GRID_COPY_X1, 0);
|
||||
}
|
||||
|
||||
void draw_grid_frame(int item, bool wide, int cols, int cell_w) {
|
||||
int sx = GRID_X + (item % cols) * cell_w;
|
||||
int sy = (wide ? 8 : 7) + (item / cols) * 32;
|
||||
int ex = sx + cell_w - 1;
|
||||
int ey = sy + (wide ? 31 : 32);
|
||||
for (int n = 0; n < 3; n++)
|
||||
ags->box_line(WORK_SCREEN, sx + n, sy + n, ex - n, ey - n, 15);
|
||||
}
|
||||
|
||||
void show_grid() {
|
||||
ags->copy_screen(WORK_SCREEN, 0, GRID_COPY_X1, 0, GRID_COPY_X2, GRID_COPY_Y2,
|
||||
GRID_COPY_X1, 0);
|
||||
}
|
||||
|
||||
uint16_t run_grid_selection(int layout, int cg_page) {
|
||||
const bool wide = (layout == 2);
|
||||
const int cols = wide ? 2 : 7;
|
||||
@@ -1249,24 +1284,12 @@ private:
|
||||
const int cell_w = wide ? 112 : 32;
|
||||
const int nr_items = wide ? 18 : NR_GRID_ITEMS;
|
||||
|
||||
load_cg_to_work_screen(cg_page);
|
||||
draw_grid_base(cg_page, wide, cols, cell_w, nr_items);
|
||||
for (int i = 0; i < nr_items; i++) {
|
||||
uint8_t state = grid_item_state[i];
|
||||
if (state & 0xfd)
|
||||
continue; // only states 0 and 2 draw anything
|
||||
int sx = GRID_X + (i % cols) * cell_w;
|
||||
int sy = (wide ? 8 : 7) + (i / cols) * 32;
|
||||
int ex = sx + cell_w - 1;
|
||||
int ey = sy + (wide ? 31 : 32);
|
||||
if (state == 0) {
|
||||
ags->box_fill(WORK_SCREEN, sx, sy, ex, ey, 0);
|
||||
} else {
|
||||
for (int n = 0; n < 3; n++)
|
||||
ags->box_line(WORK_SCREEN, sx + n, sy + n, ex - n, ey - n, 15);
|
||||
}
|
||||
if (grid_item_state[i] == 2)
|
||||
draw_grid_frame(i, wide, cols, cell_w);
|
||||
}
|
||||
ags->copy_screen(WORK_SCREEN, 0, GRID_COPY_X1, 0, GRID_COPY_X2, GRID_COPY_Y2,
|
||||
GRID_COPY_X1, 0);
|
||||
show_grid();
|
||||
|
||||
int& cx = grid_cursor_x[wide ? 1 : 0];
|
||||
int& cy = grid_cursor_y[wide ? 1 : 0];
|
||||
@@ -1283,6 +1306,12 @@ private:
|
||||
if (key & 2 && cy < (wide ? 247 : 248)) cy += 32;
|
||||
if (key & 4 && cx >= (wide ? 544 : 424)) cx -= cell_w;
|
||||
if (key & 8 && cx < (wide ? 433 : 553)) cx += cell_w;
|
||||
int col = (cx - (wide ? 432 : 392)) / cell_w;
|
||||
int row = (cy - (wide ? 22 : 23)) / 32;
|
||||
restore_grid_base();
|
||||
draw_grid_frame(std::min(row * cols + col, nr_items - 1),
|
||||
wide, cols, cell_w);
|
||||
show_grid();
|
||||
set_cursor(cx, cy);
|
||||
wait_key_release(0x0f);
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user