From 80262de6f860d9aead05ffa42bdb245c0c888b37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Verschelde?= Date: Sat, 28 Jan 2017 13:12:21 +0100 Subject: [PATCH] Dialogs: Fix long lines overflowing the box I just reduced their scale factor from 1.5 to 1.4, which seems to work fine. Also took the opportunity to cleanup the string management while I was trying to understand what the code does. Fixes #86. --- Source/GameDraw.cpp | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 73e4dde..676727d 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -664,6 +664,7 @@ int Game::DrawGLScene(StereoSide side) } } + /* Drowing dialogs */ if (Dialog::inDialog() && !mainmenu) { glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); @@ -713,41 +714,23 @@ int Game::DrawGLScene(StereoSide side) starty = screenheight * 1 / 5 - screenheight / 16; } - // FIXME - What is that char[] building for? - char tempname[264]; - int tempnum = 0; - for (int i = 0; i < 264; i++) { - tempname[i] = '\0'; - } - - for (unsigned i = 0; i < Dialog::currentScene().name.size(); i++) { - tempname[tempnum] = Dialog::currentScene().name[i]; - if (tempname[tempnum] == '#' || tempname[tempnum] == '\0') { - tempname[tempnum] = '\0'; - } else { - tempnum++; - } - } - - string = std::string(tempname) + ": "; + /* Get speaker name, and remove potential '#' chars hardcoded in it. */ + string = Dialog::currentScene().name + ": "; + string.erase(std::remove(string.begin(), string.end(), '#'), string.end()); + /* Print speaker name in dialog box. */ if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) { - text->glPrintOutlined(0.7, 0.7, 0.7, tutorialopac, startx - 2 * 7.6 * string.size() * screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutlined(0.7, 0.7, 0.7, tutorialopac, startx - 2 * 7.6 * string.size() * screenwidth / 1024, starty, string, 1, 1.4 * screenwidth / 1024, screenwidth, screenheight); } else { glColor4f(0, 0, 0, tutorialopac); - text->glPrintOutline(startx - 2 * 7.6 * string.size() * screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); - } - - tempnum = 0; - for (unsigned i = 0; i < Dialog::currentScene().text.size() + 1; i++) { - tempname[tempnum] = Dialog::currentScene().text[i]; - if (Dialog::currentScene().text[i] != '#') { - tempnum++; - } + text->glPrintOutline(startx - 2 * 7.6 * string.size() * screenwidth / 1024 - 4, starty - 4, string, 1, 1.4 * 1.25 * screenwidth / 1024, screenwidth, screenheight); } - string = tempname; + /* Get dialog text, and remove potential '#' chars hardcoded in it.' */ + string = Dialog::currentScene().text; + string.erase(std::remove(string.begin(), string.end(), '#'), string.end()); + /* Print dialog text in dialog box. */ int lastline = 0; int line = 0; bool done = false; @@ -755,10 +738,10 @@ int Game::DrawGLScene(StereoSide side) while (!done) { if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') { if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) { - text->glPrintOutlined(1, 1, 1, tutorialopac, startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); + text->glPrintOutlined(1, 1, 1, tutorialopac, startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.4 * screenwidth / 1024, screenwidth, screenheight, lastline, i); } else { glColor4f(0, 0, 0, tutorialopac); - text->glPrint(startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); + text->glPrint(startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.4 * screenwidth / 1024, screenwidth, screenheight, lastline, i); } lastline = i + 1; line++; -- 2.39.2