From 11fc7bb36280c27d231753a9b3b3e95210351144 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Wed, 14 Dec 2016 23:04:01 +0700 Subject: [PATCH] Cleaned up console printing code, replaced global displaytext by local vars in Menu --- Source/Game.cpp | 5 ----- Source/Game.hpp | 5 ----- Source/GameDraw.cpp | 21 +++------------------ Source/GameTick.cpp | 4 ---- Source/Menu/Menu.cpp | 30 +++++++++++++++++------------- 5 files changed, 20 insertions(+), 45 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index 76455fb..5da0518 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -112,11 +112,6 @@ int numchallengelevels = 0; bool console = false; std::string consoletext[15] = {}; -std::string displaytext[15] = {}; -float displaytime[15] = {}; -float displayblinkdelay = 0; -bool displayblink = 0; -unsigned displayselected = 0; float consoleblinkdelay = 0; bool consoleblink = 0; unsigned consoleselected = 0; diff --git a/Source/Game.hpp b/Source/Game.hpp index 2a0f874..4829414 100644 --- a/Source/Game.hpp +++ b/Source/Game.hpp @@ -120,11 +120,6 @@ extern int numchallengelevels; extern bool console; extern std::string consoletext[15]; -extern std::string displaytext[15]; -extern float displaytime[15]; -extern float displayblinkdelay; -extern bool displayblink; -extern unsigned displayselected; extern float consoleblinkdelay; extern bool consoleblink; extern unsigned consoleselected; diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 3374fbd..0cc214e 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -1331,19 +1331,6 @@ int Game::DrawGLScene(StereoSide side) glDepthMask(1); } - if (!console) { - displaytime[0] = 0; - glEnable(GL_TEXTURE_2D); - glColor4f(1, 1, 1, 1); - for (unsigned i = 1; i < 15; i++) - if (displaytime[i] < 4) - for (unsigned j = 0; j < displaytext[i].size(); j++) { - glColor4f(1, 1, 1, 4 - displaytime[i]); - string = std::string(1, displaytext[i][j]); - text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight); - } - } - if (difficulty < 2 && !Dialog::inDialog()) { // minimap float mapviewdist = 20000; @@ -1870,11 +1857,9 @@ int Game::DrawGLScene(StereoSide side) if (consoleblink) { text->glPrint(30 + (float)(consoleselected) * 10 - offset * 10, 30, "_", 0, 1, 1024, 768); } - for (unsigned i = 0; i < 15; i++) - for (unsigned j = 0; j < consoletext[i].size(); j++) { - glColor4f(1, 1, 1, 1 - (float)(i) / 16); - text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, std::string(1, consoletext[i][j]), 0, 1, 1024, 768); - } + for (unsigned i = 0; i < 15; i++) { + text->glPrint(30 - offset * 10, 30 + i * 20, consoletext[i], 0, 1, 1024, 768); + } } } diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 1ed3b8a..3b47a60 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -4490,10 +4490,6 @@ void Game::Tick() static XYZ facing, flatfacing; static int target; - for (int i = 0; i < 15; i++) { - displaytime[i] += multiplier; - } - Input::Tick(); if (Input::isKeyPressed(SDL_SCANCODE_F6)) { diff --git a/Source/Menu/Menu.cpp b/Source/Menu/Menu.cpp index 08fffb0..bac46a6 100644 --- a/Source/Menu/Menu.cpp +++ b/Source/Menu/Menu.cpp @@ -49,6 +49,10 @@ extern int leveltheme; extern void toggleFullscreen(); int entername = 0; +std::string newusername = ""; +unsigned newuserselected = 0; +float newuserblinkdelay = 0; +bool newuserblink = false; std::vector Menu::items; @@ -787,8 +791,8 @@ void Menu::Tick() } else { mainmenu = 1; } - displaytext[0].clear(); - displayselected = 0; + newusername.clear(); + newuserselected = 0; entername = 0; } break; @@ -864,10 +868,10 @@ void Menu::Tick() OPENAL_SetFrequency(channels[stream_menutheme]); if (entername) { - inputText(displaytext[0], &displayselected); + inputText(newusername, &newuserselected); if (!waiting) { // the input as finished - if (!displaytext[0].empty()) { // with enter - Account::add(string(displaytext[0])); + if (!newusername.empty()) { // with enter + Account::add(string(newusername)); mainmenu = 8; @@ -875,24 +879,24 @@ void Menu::Tick() fireSound(firestartsound); - displaytext[0].clear(); + newusername.clear(); - displayselected = 0; + newuserselected = 0; } entername = 0; Load(); } - displayblinkdelay -= multiplier; - if (displayblinkdelay <= 0) { - displayblinkdelay = .3; - displayblink = !displayblink; + newuserblinkdelay -= multiplier; + if (newuserblinkdelay <= 0) { + newuserblinkdelay = .3; + newuserblink = !newuserblink; } } if (entername) { - setText(0, displaytext[0], 20, 400, -1, -1); - setText(-2, displayblink ? "_" : "", 20 + displayselected * 10, 400, -1, -1); + setText(0, newusername, 20, 400, -1, -1); + setText(-2, newuserblink ? "_" : "", 20 + newuserselected * 10, 400, -1, -1); } if (oldmainmenu != mainmenu) -- 2.39.2