1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-02 19:13:31 +02:00

Remove hardcoded textbox colours

We have a custom textbox colour system, why not use it? This also moves
the map of colours from CustomLevels to Script.
This commit is contained in:
AllyTally 2023-03-18 18:48:20 -03:00 committed by Misa Elizabeth Kai
parent c3e251fea9
commit bd34af32de
5 changed files with 40 additions and 164 deletions

View File

@ -2,7 +2,7 @@
#include <SDL_stdinc.h>
#include "CustomLevels.h"
#include "Script.h"
#include "Font.h"
blockclass::blockclass(void)
@ -48,80 +48,9 @@ void blockclass::rectset(const int xi, const int yi, const int wi, const int hi)
void blockclass::setblockcolour(const char* col)
{
#ifndef NO_CUSTOM_LEVELS
if (cl.customcolours.count(col) != 0)
{
r = cl.customcolours[col].r;
g = cl.customcolours[col].g;
b = cl.customcolours[col].b;
}
else // Turn the if into an else if so we don't run the default colour processing
#endif
if (SDL_strcmp(col, "cyan") == 0)
{
r = 164;
g = 164;
b = 255;
}
else if (SDL_strcmp(col, "red") == 0)
{
r = 255;
g = 60;
b = 60;
}
else if (SDL_strcmp(col, "green") == 0)
{
r = 144;
g = 255;
b = 144;
}
else if (SDL_strcmp(col, "yellow") == 0)
{
r = 255;
g = 255;
b = 134;
}
else if (SDL_strcmp(col, "blue") == 0)
{
r = 95;
g = 95;
b = 255;
}
else if (SDL_strcmp(col, "purple") == 0)
{
r = 255;
g = 134;
b = 255;
}
else if (SDL_strcmp(col, "white") == 0)
{
r = 244;
g = 244;
b = 244;
}
else if (SDL_strcmp(col, "gray") == 0)
{
r = 174;
g = 174;
b = 174;
}
else if (SDL_strcmp(col, "orange") == 0)
{
r = 255;
g = 130;
b = 20;
}
else if (SDL_strcmp(col, "transparent") == 0)
{
r = 0;
g = 0;
b = 0;
}
else
{
//use a gray
r = 174;
g = 174;
b = 174;
}
bool exists = ::script.textbox_colours.count(col) != 0;
r = ::script.textbox_colours[exists ? col : "gray"].r;
g = ::script.textbox_colours[exists ? col : "gray"].g;
b = ::script.textbox_colours[exists ? col : "gray"].b;
}

View File

@ -387,7 +387,8 @@ void customlevelclass::reset(void)
onewaycol_override = false;
customcolours.clear();
script.textbox_colours.clear();
script.add_default_colours();
map.specialroomnames.clear();
}
@ -1309,7 +1310,7 @@ next:
colour.g = g;
colour.b = b;
customcolours[name] = colour;
script.textbox_colours[name] = colour;
}
}
}

View File

@ -170,8 +170,6 @@ public:
SDL_Color getonewaycol(int rx, int ry);
SDL_Color getonewaycol(void);
bool onewaycol_override;
std::map<std::string, SDL_Color> customcolours;
};
std::string translate_title(const std::string& title, bool* is_gettext);

View File

@ -43,6 +43,8 @@ scriptclass::scriptclass(void)
r = 0;
textx = 0;
texty = 0;
textbox_colours.clear();
add_default_colours();
textflipme = false;
textcentertext = false;
textpad_left = 0;
@ -53,6 +55,20 @@ scriptclass::scriptclass(void)
textlarge = false;
}
void scriptclass::add_default_colours(void)
{
textbox_colours["cyan"] = graphics.getRGB(164, 164, 255);
textbox_colours["red"] = graphics.getRGB(255, 60, 60);
textbox_colours["green"] = graphics.getRGB(144, 255, 144);
textbox_colours["yellow"] = graphics.getRGB(255, 255, 134);
textbox_colours["blue"] = graphics.getRGB(95, 95, 255);
textbox_colours["purple"] = graphics.getRGB(255, 134, 255);
textbox_colours["white"] = graphics.getRGB(244, 244, 244);
textbox_colours["gray"] = graphics.getRGB(174, 174, 174);
textbox_colours["orange"] = graphics.getRGB(255, 130, 20);
textbox_colours["transparent"] = graphics.getRGB(0, 0, 0);
}
void scriptclass::clearcustom(void)
{
customscripts.clear();
@ -452,91 +468,18 @@ void scriptclass::run(void)
}
else if (words[0] == "text")
{
//oh boy
//first word is the colour.
#ifndef NO_CUSTOM_LEVELS
if (cl.customcolours.count(words[1]) != 0)
// oh boy
// first word is the colour.
if (textbox_colours.count(words[1]) == 0)
{
r = cl.customcolours[words[1]].r;
g = cl.customcolours[words[1]].g;
b = cl.customcolours[words[1]].b;
}
else // Turn the if into an else if so we don't run the default colour processing
#endif
if (words[1] == "cyan")
{
r = 164;
g = 164;
b = 255;
}
else if (words[1] == "player")
{
r = 164;
g = 164;
b = 255;
}
else if (words[1] == "red")
{
r = 255;
g = 60;
b = 60;
}
else if (words[1] == "green")
{
r = 144;
g = 255;
b = 144;
}
else if (words[1] == "yellow")
{
r = 255;
g = 255;
b = 134;
}
else if (words[1] == "blue")
{
r = 95;
g = 95;
b = 255;
}
else if (words[1] == "purple")
{
r = 255;
g = 134;
b = 255;
}
else if (words[1] == "white")
{
r = 244;
g = 244;
b = 244;
}
else if (words[1] == "gray")
{
r = 174;
g = 174;
b = 174;
}
else if (words[1] == "orange")
{
r = 255;
g = 130;
b = 20;
}
else if (words[1] == "transparent")
{
r = 0;
g = 0;
b = 0;
}
else
{
//use a gray
r = 174;
g = 174;
b = 174;
// No colour named this, use gray
words[1] = "gray";
}
r = textbox_colours[words[1]].r;
g = textbox_colours[words[1]].g;
b = textbox_colours[words[1]].b;
//next are the x,y coordinates
textx = ss_toi(words[2]);
texty = ss_toi(words[3]);

View File

@ -1,6 +1,7 @@
#ifndef SCRIPT_H
#define SCRIPT_H
#include <map>
#include <string>
#include <vector>
@ -8,6 +9,7 @@
#define filllines(lines) commands.insert(commands.end(), lines, lines + SDL_arraysize(lines))
#define TEXT_COLOUR(a) script.textbox_colours[a]
struct Script
{
@ -76,6 +78,8 @@ public:
commands.push_back(t);
}
void add_default_colours(void);
void clearcustom(void);
void tokenize(const std::string& t);
@ -101,7 +105,8 @@ public:
int scriptdelay;
bool running;
//Textbox stuff
// Textbox stuff
std::map<std::string, SDL_Color> textbox_colours;
int textx;
int texty;
int r,g,b;