From e2dde4412dbf90210f407719622d7061ce327a9b Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Mon, 19 Aug 2019 18:49:23 -0300 Subject: [PATCH] Fix character description text rendering. --- src/m_menu.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index aaae35240..cde73ab9e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7972,14 +7972,84 @@ static void M_DrawSetupChoosePlayerMenu(void) } // Character select pictures - V_DrawScaledPatch(8-xsh, (my+16) - FixedInt(char_scroll), 0, description[char_on].charpic); - if (prev != -1) - V_DrawScaledPatch(8-xsh, (my+16) - FixedInt(char_scroll) - 144, 0, description[prev].charpic); - if (next != -1) - V_DrawScaledPatch(8-xsh, (my+16) - FixedInt(char_scroll) + 144, 0, description[next].charpic); + { + INT32 x = 8 - xsh; + INT32 y = (my+16) - FixedInt(char_scroll); + V_DrawScaledPatch(x, y, 0, description[char_on].charpic); + if (prev != -1) + V_DrawScaledPatch(x, y - 144, 0, description[prev].charpic); + if (next != -1) + V_DrawScaledPatch(x, y + 144, 0, description[next].charpic); + } // Character description - V_DrawString(146+xsh, my + 9, V_RETURN8|V_ALLOWLOWERCASE, char_notes); + // No, I can't use strtok. + // Put two line break characters next to each other to see why. + { + char *text = char_notes; + char *first_token = text; + char *last_token = strchr(text, '\n'); + INT32 x = 146 + xsh; + INT32 y = my + 9; + INT32 flags = V_ALLOWLOWERCASE; + + // No line breaks? + // Draw entire string + if (!last_token) + V_DrawString(x, y, flags, char_notes); + // Split string by the line break character + else + { + char *string = NULL; + INT32 len; + while (true) + { + // There are still lines left do draw + if (last_token) + { + size_t shift = 0; + // Free this line + if (string) + Z_Free(string); + // Find string length, do a malloc... + len = (last_token-first_token)+1; + string = ZZ_Alloc(len); + // Copy the line + strncpy(string, first_token, len-1); + string[len-1] = '\0'; + // Don't leave a line break character + // at the start of the string! + if ((strlen(string) >= 2) && (string[0] == '\n') && (string[1] != '\n')) + shift++; + // Then draw it + V_DrawString(x, y, flags, string+shift); + } + // No line break character was found + else + { + // Don't leave a line break character + // at the start of the string! + if ((strlen(first_token) >= 2) && (first_token[0] == '\n') && (first_token[1] != '\n')) + first_token++; + V_DrawString(x, y, flags, first_token); + break; + } + + // Next line + y += 8; // V_RETURN8 + if ((last_token-text)+1 >= strlen(text)) + last_token = NULL; + else + { + first_token = last_token; + last_token = strchr(first_token+1, '\n'); + } + } + // Free this line + if (string) + Z_Free(string); + } + } // Name tags! {