From f3786a8e3f79c5b9d74149d8ea8726244bd63479 Mon Sep 17 00:00:00 2001 From: Ally Date: Wed, 13 Oct 2021 19:38:51 -0300 Subject: [PATCH] Add `setactivityposition(x,y)`, add new textbox color `transparent` (#847) * Add `setactivityposition(x,y)`, add new textbox color `transparent` This commit adds a new internal command as a part of the visual activity zone changes I've been making. This one allows the user to reposition the activity zone to anywhere on the screen. In addition, this commit adds the textbox color `transparent`, which just sets r, g and b to 0. rgb(0, 0, 0) normally creates the color black, however in VVVVVV textboxes, it makes the background of them invisible, and makes the text the off-white color which the game uses elsewhere. * add new variables to hardreset * Fix unwanted text centering; offset position by 16, 4 It makes sense for `setactivityposition(0, 0)` to place the activity zone in the default position, so the x has been offset by 16, and the y has been offset by 4. Text was being automatically centered, meaning any activity zone which wasn't centered had misplaced text. This has been fixed by calculating the center manually, and offsetting it by the passed value. --- desktop_version/src/BlockV.cpp | 9 +++++++++ desktop_version/src/BlockV.h | 1 + desktop_version/src/Entity.cpp | 15 +++++++++++++++ desktop_version/src/Entity.h | 2 ++ desktop_version/src/Game.cpp | 2 ++ desktop_version/src/Game.h | 2 +- desktop_version/src/Logic.cpp | 2 ++ desktop_version/src/Render.cpp | 13 +++++++++++-- desktop_version/src/Script.cpp | 13 +++++++++++++ 9 files changed, 56 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/BlockV.cpp b/desktop_version/src/BlockV.cpp index 4ce525a2..43f240a1 100644 --- a/desktop_version/src/BlockV.cpp +++ b/desktop_version/src/BlockV.cpp @@ -25,6 +25,9 @@ void blockclass::clear(void) g = 0; b = 0; + activity_x = 0; + activity_y = 0; + /* std::strings get initialized automatically, but this is */ /* in case this function gets called again after construction */ script.clear(); @@ -95,6 +98,12 @@ void blockclass::setblockcolour(const char* col) g = 130; b = 20; } + else if (SDL_strcmp(col, "transparent") == 0) + { + r = 0; + g = 0; + b = 0; + } else { //use a gray diff --git a/desktop_version/src/BlockV.h b/desktop_version/src/BlockV.h index 8fa52bb0..3c4c3151 100644 --- a/desktop_version/src/BlockV.h +++ b/desktop_version/src/BlockV.h @@ -21,6 +21,7 @@ public: int xp, yp, wp, hp; std::string script, prompt; int r, g, b; + int activity_x, activity_y; }; #endif /* BLOCKV_H */ diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index fba49cb1..501257d2 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -71,6 +71,8 @@ void entityclass::init(void) customenemy = 0; customwarpmode = false; customwarpmodevon = false; customwarpmodehon = false; customactivitycolour = ""; + customactivitypositionx = -1; + customactivitypositiony = -1; customactivitytext = ""; trophytext = 0; oldtrophytext = 0; @@ -1082,6 +1084,19 @@ void entityclass::createblock( int t, int xp, int yp, int w, int h, int trig /*= customactivitycolour = ""; } + if (customactivitypositionx != -1) + { + block.activity_x = customactivitypositionx; + block.activity_y = customactivitypositiony; + customactivitypositionx = -1; + customactivitypositiony = -1; + } + else + { + block.activity_x = 0; + block.activity_y = 0; + } + if (!reuse) { blocks.push_back(block); diff --git a/desktop_version/src/Entity.h b/desktop_version/src/Entity.h index 3c9839b2..29d92e78 100644 --- a/desktop_version/src/Entity.h +++ b/desktop_version/src/Entity.h @@ -205,6 +205,8 @@ public: bool customcrewmoods[Game::numcrew]; std::string customactivitycolour; std::string customactivitytext; + int customactivitypositionx; + int customactivitypositiony; }; #ifndef OBJ_DEFINITION diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 81fa565b..325c0cff 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -218,6 +218,8 @@ void Game::init(void) activity_r = 0; activity_g = 0; activity_b = 0; + activity_x = 0; + activity_y = 0; creditposition = 0; oldcreditposition = 0; bestgamedeaths = -1; diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 7ea392dd..514e30d0 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -389,7 +389,7 @@ public: bool activetele; int readytotele; int oldreadytotele; - int activity_r, activity_g, activity_b; + int activity_r, activity_g, activity_b, activity_x, activity_y; std::string activity_lastprompt; std::string telesummary, quicksummary, customquicksummary; diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index 00358146..c6c8597e 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -1414,6 +1414,8 @@ void gamelogic(void) game.activity_r = obj.blocks[game.activeactivity].r; game.activity_g = obj.blocks[game.activeactivity].g; game.activity_b = obj.blocks[game.activeactivity].b; + game.activity_x = obj.blocks[game.activeactivity].activity_x; + game.activity_y = obj.blocks[game.activeactivity].activity_y; } game.oldreadytotele = game.readytotele; diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 1b4d8370..65c48c4a 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -1985,8 +1985,17 @@ void gamerender(void) game.activity_lastprompt.c_str() ); - graphics.drawtextbox(16, 4, 36, 3, game.activity_r*act_alpha, game.activity_g*act_alpha, game.activity_b*act_alpha); - graphics.Print(5, 12, final_string, game.activity_r*act_alpha, game.activity_g*act_alpha, game.activity_b*act_alpha, true); + int centered_x = ((160 ) - ((graphics.len(final_string)) / 2)); + + if (game.activity_r == 0 && game.activity_g == 0 && game.activity_b == 0) + { + graphics.bprint(centered_x + game.activity_x, game.activity_y + 12, final_string, 196*act_alpha, 196*act_alpha, (255 - help.glow)*act_alpha); + } + else + { + graphics.drawtextbox(game.activity_x + 16, game.activity_y + 4, 36, 3, game.activity_r*act_alpha, game.activity_g*act_alpha, game.activity_b*act_alpha); + graphics.Print(centered_x + game.activity_x, game.activity_y + 12, final_string, game.activity_r*act_alpha, game.activity_g*act_alpha, game.activity_b*act_alpha); + } } if (obj.trophytext > 0 || obj.oldtrophytext > 0) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 8e3d22f1..83f95bf6 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -468,6 +468,12 @@ void scriptclass::run(void) g = 130; b = 20; } + else if (words[1] == "transparent") + { + r = 0; + g = 0; + b = 0; + } else { //use a gray @@ -1629,6 +1635,11 @@ void scriptclass::run(void) obj.customactivitytext = commands[position]; } } + else if (words[0] == "setactivityposition") + { + obj.customactivitypositionx = ss_toi(words[1]); + obj.customactivitypositiony = ss_toi(words[2]); + } else if (words[0] == "createrescuedcrew") { //special for final level cutscene @@ -3274,6 +3285,8 @@ void scriptclass::hardreset(void) obj.customactivitycolour = ""; obj.customactivitytext = ""; + obj.customactivitypositionx = -1; + obj.customactivitypositiony = -1; } void scriptclass::loadcustom(const std::string& t)