From 2f1db66e78975f265bd7e3f9064398928090130f Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 20 Aug 2023 07:23:07 -0400 Subject: [PATCH 1/4] Fix drawing of final color --- src/m_menu.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 3451b90d6..ff9d04c53 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -12183,21 +12183,36 @@ colordraw: { for (i = 0; i < 16; i++) { - if (skincolors[mc->color].accessible && !stoprow) + if (skincolors[mc->color].accessible) { M_DrawColorRamp(x + i*w, y + j*16, w, 1, skincolors[mc->color]); - if (mc->color == setupm_fakecolor->color) // store current color position - { - cx = x + i*w; - cy = y + j*16; - } + + if (mc == setupm_fakecolor) // store current color position + { + cx = x + i*w; + cy = y + j*16; + } } - mc = mc->next; - while (!skincolors[mc->color].accessible && !stoprow) // Find accessible color after this one + + if (stoprow) + { + break; + } + + // Find accessible color after this one + do { mc = mc->next; - if (mc == menucolortail) stoprow = true; - } + if (mc == menucolortail) + { + stoprow = true; + } + } while (!skincolors[mc->color].accessible && !stoprow); + } + + if (stoprow) + { + break; } } From 4d1e6df2d7c7e0c62d76e32ace11cd6b05af602e Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 20 Aug 2023 11:28:39 -0400 Subject: [PATCH 2/4] Fix color grid input bugs There's still some slight awkwardness trying to wrap downwards into uneven row grids, but this is significantly better and this already took up way more time than I wanted it to. --- src/m_menu.c | 205 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 190 insertions(+), 15 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index ff9d04c53..653152451 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -12054,6 +12054,136 @@ static INT32 setupm_fakeskin; static menucolor_t *setupm_fakecolor; static boolean colorgrid; +#define COLOR_GRID_ROW_SIZE (16) + +static UINT16 M_GetColorGridIndex(UINT16 color) +{ + menucolor_t *look; + UINT16 i = 0; + + if (!skincolors[color].accessible) + { + return 0; + } + + for (look = menucolorhead; ; i++, look = look->next) + { + while (!skincolors[look->color].accessible) // skip inaccessible colors + { + if (look == menucolortail) + { + return 0; + } + + look = look->next; + } + + if (look->color == color) + { + return i; + } + + if (look == menucolortail) + { + return 0; + } + } +} + +static INT32 M_GridIndexToX(UINT16 index) +{ + return (index % COLOR_GRID_ROW_SIZE); +} + +static INT32 M_GridIndexToY(UINT16 index) +{ + return (index / COLOR_GRID_ROW_SIZE); +} + +static UINT16 M_ColorGridLen(void) +{ + menucolor_t *look; + UINT16 i = 0; + + for (look = menucolorhead; ; i++) + { + do + { + if (look == menucolortail) + { + return i; + } + + look = look->next; + } + while (!skincolors[look->color].accessible); // skip inaccessible colors + } +} + +static UINT16 M_GridPosToGridIndex(INT32 x, INT32 y) +{ + const UINT16 grid_len = M_ColorGridLen(); + const UINT16 grid_height = ((grid_len - 1) / COLOR_GRID_ROW_SIZE) + 1; + const UINT16 last_row_len = COLOR_GRID_ROW_SIZE - ((grid_height * COLOR_GRID_ROW_SIZE) - grid_len); + + UINT16 row_len = COLOR_GRID_ROW_SIZE; + UINT16 new_index = 0; + + while (y < 0) + { + y += grid_height; + } + y = (y % grid_height); + + if (y >= grid_height-1 && last_row_len > 0) + { + row_len = last_row_len; + } + + while (x < 0) + { + x += row_len; + } + x = (x % row_len); + + new_index = (y * COLOR_GRID_ROW_SIZE) + x; + if (new_index >= grid_len) + { + new_index = grid_len - 1; + } + + return new_index; +} + +static menucolor_t *M_GridIndexToMenuColor(UINT16 index) +{ + menucolor_t *look = menucolorhead; + UINT16 i = 0; + + for (look = menucolorhead; ; i++, look = look->next) + { + while (!skincolors[look->color].accessible) // skip inaccessible colors + { + if (look == menucolortail) + { + return menucolorhead; + } + + look = look->next; + } + + if (i == index) + { + return look; + } + + if (look == menucolortail) + { + return menucolorhead; + } + } +} + static void M_DrawSetupMultiPlayerMenu(void) { INT32 x, y, cursory = 0, flags = 0; @@ -12333,15 +12463,16 @@ static void M_HandleSetupMultiPlayer(INT32 choice) case KEY_DOWNARROW: case KEY_UPARROW: { - UINT8 i; if (itemOn == 2 && colorgrid) { - for (i = 0; i < 16; i++) - { - setupm_fakecolor = (choice == KEY_UPARROW) ? setupm_fakecolor->prev : setupm_fakecolor->next; - while (!skincolors[setupm_fakecolor->color].accessible) // skip inaccessible colors - setupm_fakecolor = (choice == KEY_UPARROW) ? setupm_fakecolor->prev : setupm_fakecolor->next; - } + UINT16 index = M_GetColorGridIndex(setupm_fakecolor->color); + INT32 x = M_GridIndexToX(index); + INT32 y = M_GridIndexToY(index); + + y += (choice == KEY_UPARROW) ? -1 : 1; + + index = M_GridPosToGridIndex(x, y); + setupm_fakecolor = M_GridIndexToMenuColor(index); } else if (choice == KEY_UPARROW) M_PrevOpt(); @@ -12368,8 +12499,23 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else if (itemOn == 2) // player color { + if (colorgrid) + { + UINT16 index = M_GetColorGridIndex(setupm_fakecolor->color); + INT32 x = M_GridIndexToX(index); + INT32 y = M_GridIndexToY(index); + + x--; + + index = M_GridPosToGridIndex(x, y); + setupm_fakecolor = M_GridIndexToMenuColor(index); + } + else + { + setupm_fakecolor = setupm_fakecolor->prev; + } + S_StartSound(NULL,sfx_menu1); // Tails - setupm_fakecolor = setupm_fakecolor->prev; } break; @@ -12408,8 +12554,23 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else if (itemOn == 2) // player color { + if (colorgrid) + { + UINT16 index = M_GetColorGridIndex(setupm_fakecolor->color); + INT32 x = M_GridIndexToX(index); + INT32 y = M_GridIndexToY(index); + + x++; + + index = M_GridPosToGridIndex(x, y); + setupm_fakecolor = M_GridIndexToMenuColor(index); + } + else + { + setupm_fakecolor = setupm_fakecolor->next; + } + S_StartSound(NULL,sfx_menu1); // Tails - setupm_fakecolor = setupm_fakecolor->next; } break; @@ -12419,13 +12580,28 @@ static void M_HandleSetupMultiPlayer(INT32 choice) UINT8 i; if (itemOn == 2) // player color { - S_StartSound(NULL,sfx_menu1); - for (i = 0; i < (colorgrid ? 64 : 13); i++) // or (282-charw)/(2*indexwidth) + if (colorgrid) { - setupm_fakecolor = (choice == KEY_PGUP) ? setupm_fakecolor->prev : setupm_fakecolor->next; - while (!skincolors[setupm_fakecolor->color].accessible) // skip inaccessible colors - setupm_fakecolor = (choice == KEY_PGUP) ? setupm_fakecolor->prev : setupm_fakecolor->next; + UINT16 index = M_GetColorGridIndex(setupm_fakecolor->color); + INT32 x = M_GridIndexToX(index); + INT32 y = M_GridIndexToY(index); + + y += (choice == KEY_UPARROW) ? -4 : 4; + + index = M_GridPosToGridIndex(x, y); + setupm_fakecolor = M_GridIndexToMenuColor(index); } + else + { + for (i = 0; i < 13; i++) // or (282-charw)/(2*indexwidth) + { + setupm_fakecolor = (choice == KEY_PGUP) ? setupm_fakecolor->prev : setupm_fakecolor->next; + while (!skincolors[setupm_fakecolor->color].accessible) // skip inaccessible colors + setupm_fakecolor = (choice == KEY_PGUP) ? setupm_fakecolor->prev : setupm_fakecolor->next; + } + } + + S_StartSound(NULL, sfx_menu1); // Tails } } break; @@ -12455,7 +12631,6 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } } break; - break; case KEY_DEL: if (itemOn == 0 && (l = strlen(setupm_name))!=0) From 9c8dd5475111d2b66f1a9a1d18836e9f14703ecb Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 20 Aug 2023 11:56:55 -0400 Subject: [PATCH 3/4] Fix color grid not extending to the very bottom --- src/m_menu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 653152451..6a694b8e3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -12302,16 +12302,23 @@ colordraw: boolean stoprow = false; menucolor_t *mc; // Last accessed color + const UINT16 grid_len = M_ColorGridLen(); + const UINT16 grid_end_y = M_GridIndexToY(grid_len - 1); + + INT32 grid_select = M_GetColorGridIndex(setupm_fakecolor->color); + INT32 grid_select_y = M_GridIndexToY(grid_select); + x = 132; y = 66; - pos = min(max(0, 16*((M_GetColorIndex(setupm_fakecolor->color)-1)/16) - 64), 16*(M_GetColorIndex(menucolortail->color)/16-1) - 128); - mc = M_GetColorFromIndex(pos); + + pos = M_GridPosToGridIndex(0, max(0, min(grid_select_y - 3, grid_end_y - 7))); + mc = M_GridIndexToMenuColor(pos); // Draw grid V_DrawFill(x-2, y-2, 132, 132, 159); for (j = 0; j < 8; j++) { - for (i = 0; i < 16; i++) + for (i = 0; i < COLOR_GRID_ROW_SIZE; i++) { if (skincolors[mc->color].accessible) { From 40c37ce4c2997dbb3487dcda00b9dfc11d30c895 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 20 Aug 2023 12:05:58 -0400 Subject: [PATCH 4/4] Revert left/right movement --- src/m_menu.c | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 6a694b8e3..c49442141 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -12506,22 +12506,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else if (itemOn == 2) // player color { - if (colorgrid) - { - UINT16 index = M_GetColorGridIndex(setupm_fakecolor->color); - INT32 x = M_GridIndexToX(index); - INT32 y = M_GridIndexToY(index); - - x--; - - index = M_GridPosToGridIndex(x, y); - setupm_fakecolor = M_GridIndexToMenuColor(index); - } - else - { - setupm_fakecolor = setupm_fakecolor->prev; - } - + setupm_fakecolor = setupm_fakecolor->prev; S_StartSound(NULL,sfx_menu1); // Tails } break; @@ -12561,22 +12546,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else if (itemOn == 2) // player color { - if (colorgrid) - { - UINT16 index = M_GetColorGridIndex(setupm_fakecolor->color); - INT32 x = M_GridIndexToX(index); - INT32 y = M_GridIndexToY(index); - - x++; - - index = M_GridPosToGridIndex(x, y); - setupm_fakecolor = M_GridIndexToMenuColor(index); - } - else - { - setupm_fakecolor = setupm_fakecolor->next; - } - + setupm_fakecolor = setupm_fakecolor->next; S_StartSound(NULL,sfx_menu1); // Tails } break;