Skip to content

Commit

Permalink
Make element names a String (unicode support)
Browse files Browse the repository at this point in the history
This won't be used by official elements, but mods or lua scripts could and do use unicode
  • Loading branch information
jacob1 committed Mar 12, 2019
1 parent 45b391d commit 2e17b84
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/gui/elementsearch/ElementSearchActivity.cpp
Expand Up @@ -104,15 +104,15 @@ void ElementSearchActivity::searchTools(String query)
ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
ui::Point current = ui::Point(0, 0);

ByteString queryLower = query.ToUtf8().ToLower();
String queryLower = query.ToLower();

std::vector<Tool *> matches;
std::vector<Tool *> frontmatches;
std::vector<Tool *> exactmatches;

for(std::vector<Tool*>::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter)
{
ByteString nameLower = (*iter)->GetName().ToLower();
String nameLower = (*iter)->GetName().ToLower();
if(nameLower == queryLower)
exactmatches.push_back(*iter);
else if(nameLower.BeginsWith(queryLower))
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/DecorationTool.h
Expand Up @@ -58,7 +58,7 @@ class DecorationTool: public Tool
return newTexture;
}

DecorationTool(Renderer *ren_, int decoMode, ByteString name, String description, int r, int g, int b, ByteString identifier):
DecorationTool(Renderer *ren_, int decoMode, String name, String description, int r, int g, int b, ByteString identifier):
Tool(decoMode, name, description, r, g, b, identifier),
Red(0),
Green(0),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameController.cpp
Expand Up @@ -1566,7 +1566,7 @@ void GameController::ReloadSim()
}
}

ByteString GameController::ElementResolve(int type, int ctype)
String GameController::ElementResolve(int type, int ctype)
{
if(gameModel && gameModel->GetSimulation())
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameController.h
Expand Up @@ -147,7 +147,7 @@ class GameController: public ClientListener
bool MouseInZoom(ui::Point position);
ui::Point PointTranslate(ui::Point point);
ui::Point NormaliseBlockCoord(ui::Point point);
ByteString ElementResolve(int type, int ctype);
String ElementResolve(int type, int ctype);
bool IsValidElement(int type);
String WallName(int type);
int Record(bool record);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameModel.cpp
Expand Up @@ -305,7 +305,7 @@ void GameModel::BuildMenus()
//Build menu for GOL types
for(int i = 0; i < NGOL; i++)
{
Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), sim->gmenu[i].name, sim->gmenu[i].description, PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+sim->gmenu[i].name);
Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), sim->gmenu[i].name, sim->gmenu[i].description, PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+sim->gmenu[i].name.ToAscii());
menuList[SC_LIFE]->AddTool(tempTool);
}

Expand Down
26 changes: 13 additions & 13 deletions src/gui/game/GameView.cpp
Expand Up @@ -1472,7 +1472,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
case SDL_SCANCODE_F5:
c->ReloadSim();
break;
case 'a':
case SDL_SCANCODE_A:
if ((Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator
|| Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin) && ctrl)
{
Expand Down Expand Up @@ -2284,14 +2284,14 @@ void GameView::OnDraw()
if (showDebug)
{
if (type == PT_LAVA && c->IsValidElement(ctype))
sampleInfo << "Molten " << c->ElementResolve(ctype, -1).FromAscii();
sampleInfo << "Molten " << c->ElementResolve(ctype, -1);
else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype))
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]).FromAscii();
sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]);
else if (type == PT_LIFE)
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
sampleInfo << c->ElementResolve(type, ctype);
else if (type == PT_FILT)
{
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
sampleInfo << c->ElementResolve(type, ctype);
String filtModes[] = {"set colour", "AND", "OR", "subtract colour", "red shift", "blue shift", "no effect", "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"};
if (sample.particle.tmp>=0 && sample.particle.tmp<=11)
sampleInfo << " (" << filtModes[sample.particle.tmp] << ")";
Expand All @@ -2300,14 +2300,14 @@ void GameView::OnDraw()
}
else
{
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
sampleInfo << c->ElementResolve(type, ctype);
if (wavelengthGfx)
sampleInfo << " (" << ctype << ")";
// Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2
else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV)
sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)).FromAscii() << ")";
sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)) << ")";
else if (c->IsValidElement(ctype))
sampleInfo << " (" << c->ElementResolve(ctype, -1).FromAscii() << ")";
sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")";
else
sampleInfo << " ()";
}
Expand All @@ -2319,7 +2319,7 @@ void GameView::OnDraw()
{
String elemName = c->ElementResolve(
TYP(sample.particle.tmp),
ID(sample.particle.tmp)).FromAscii();
ID(sample.particle.tmp));
if (elemName == "")
sampleInfo << ", Tmp: " << sample.particle.tmp;
else
Expand All @@ -2338,13 +2338,13 @@ void GameView::OnDraw()
else
{
if (type == PT_LAVA && c->IsValidElement(ctype))
sampleInfo << "Molten " << c->ElementResolve(ctype, -1).FromAscii();
sampleInfo << "Molten " << c->ElementResolve(ctype, -1);
else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype))
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]).FromAscii();
sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]);
else if (type == PT_LIFE)
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
sampleInfo << c->ElementResolve(type, ctype);
else
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
sampleInfo << c->ElementResolve(type, ctype);
sampleInfo << ", Temp: " << sample.particle.temp - 273.15f << " C";
sampleInfo << ", Pressure: " << sample.AirPressure;
}
Expand Down
10 changes: 5 additions & 5 deletions src/gui/game/Tool.cpp
Expand Up @@ -6,7 +6,7 @@

using namespace std;

Tool::Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool::Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
textureGen(textureGen),
toolID(id),
toolName(name),
Expand All @@ -33,7 +33,7 @@ void Tool::SetTextureGen(VideoBuffer * (*textureGen)(int, int, int))
this->textureGen = textureGen;
}
ByteString Tool::GetIdentifier() { return identifier; }
ByteString Tool::GetName() { return toolName; }
String Tool::GetName() { return toolName; }
String Tool::GetDescription() { return toolDescription; }
Tool::~Tool() {}

Expand All @@ -50,7 +50,7 @@ void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Po
void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}


ElementTool::ElementTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
ElementTool::ElementTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
}
Expand All @@ -69,7 +69,7 @@ void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position)
}


WallTool::WallTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
WallTool::WallTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
blocky = true;
Expand Down Expand Up @@ -110,7 +110,7 @@ void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
sim->FloodWalls(position.X, position.Y, toolID, -1);
}

WindTool::WindTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
WindTool::WindTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
}
Expand Down
18 changes: 9 additions & 9 deletions src/gui/game/Tool.h
Expand Up @@ -16,17 +16,17 @@ class Tool
protected:
VideoBuffer * (*textureGen)(int, int, int);
int toolID;
ByteString toolName;
String toolName;
String toolDescription;
float strength;
bool blocky;
ByteString identifier;
public:
int colRed, colGreen, colBlue;

Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
int GetToolID() { return toolID; }
ByteString GetName();
String GetName();
String GetDescription();
ByteString GetIdentifier();
int GetBlocky() { return blocky; }
Expand Down Expand Up @@ -105,7 +105,7 @@ class PropertyTool: public Tool
class ElementTool: public Tool
{
public:
ElementTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
ElementTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~ElementTool();
void Draw(Simulation * sim, Brush * brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
Expand All @@ -116,7 +116,7 @@ class ElementTool: public Tool
class Element_LIGH_Tool: public ElementTool
{
public:
Element_LIGH_Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
Element_LIGH_Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~Element_LIGH_Tool() { }
Expand All @@ -129,7 +129,7 @@ class Element_LIGH_Tool: public ElementTool
class Element_TESC_Tool: public ElementTool
{
public:
Element_TESC_Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
Element_TESC_Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~Element_TESC_Tool() {}
Expand All @@ -140,7 +140,7 @@ class Element_TESC_Tool: public ElementTool
class PlopTool: public ElementTool
{
public:
PlopTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
PlopTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~PlopTool() { }
Expand All @@ -154,7 +154,7 @@ class PlopTool: public ElementTool
class WallTool: public Tool
{
public:
WallTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
WallTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~WallTool();
void Draw(Simulation * sim, Brush * brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
Expand All @@ -165,7 +165,7 @@ class WallTool: public Tool
class WindTool: public Tool
{
public:
WindTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
WindTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~WindTool() { }
void Draw(Simulation * sim, Brush * brush, ui::Point position) override { }
void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/game/ToolButton.cpp
Expand Up @@ -4,8 +4,8 @@
#include "gui/interface/Mouse.h"
#include "Favorite.h"

ToolButton::ToolButton(ui::Point position, ui::Point size, ByteString text_, ByteString toolIdentifier, String toolTip):
ui::Button(position, size, text_.FromAscii(), toolTip),
ToolButton::ToolButton(ui::Point position, ui::Point size, String text, ByteString toolIdentifier, String toolTip):
ui::Button(position, size, text, toolTip),
toolIdentifier(toolIdentifier)
{
SetSelectionState(-1);
Expand Down Expand Up @@ -72,11 +72,11 @@ void ToolButton::Draw(const ui::Point& screenPos)

if (totalColour<544)
{
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText.c_str(), 255, 255, 255, 255);
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText, 255, 255, 255, 255);
}
else
{
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText.c_str(), 0, 0, 0, 255);
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText, 0, 0, 0, 255);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/ToolButton.h
Expand Up @@ -8,7 +8,7 @@ class ToolButton: public ui::Button
int currentSelection;
ByteString toolIdentifier;
public:
ToolButton(ui::Point position, ui::Point size, ByteString text_, ByteString toolIdentifier, String toolTip = String());
ToolButton(ui::Point position, ui::Point size, String text, ByteString toolIdentifier, String toolTip = String());
void OnMouseUnclick(int x, int y, unsigned int button) override;
void OnMouseUp(int x, int y, unsigned int button) override;
void OnMouseClick(int x, int y, unsigned int button) override;
Expand Down
2 changes: 1 addition & 1 deletion src/lua/LegacyLuaAPI.cpp
Expand Up @@ -276,7 +276,7 @@ int luatpt_getelement(lua_State *l)
t = luaL_optint(l, 1, 1);
if (t<0 || t>=PT_NUM)
return luaL_error(l, "Unrecognised element number '%d'", t);
lua_pushstring(l, luacon_sim->elements[t].Name.c_str());
lua_pushstring(l, luacon_sim->elements[t].Name.ToUtf8().c_str());
}
else
{
Expand Down
9 changes: 4 additions & 5 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -290,7 +290,7 @@ tpt.partsdata = nil");
lua_setfield(l, currentElementMeta, "__index");
lua_setmetatable(l, currentElement);

lua_setfield(l, tptElements, luacon_sim->elements[i].Name.ToLower().c_str());
lua_setfield(l, tptElements, luacon_sim->elements[i].Name.ToUtf8().ToLower().c_str());
}
lua_setfield(l, tptProperties, "el");

Expand All @@ -310,7 +310,7 @@ tpt.partsdata = nil");
lua_setfield(l, currentElementMeta, "__index");
lua_setmetatable(l, currentElement);

lua_setfield(l, tptElementTransitions, luacon_sim->elements[i].Name.ToLower().c_str());
lua_setfield(l, tptElementTransitions, luacon_sim->elements[i].Name.ToUtf8().ToLower().c_str());
}
lua_setfield(l, tptProperties, "eltransition");

Expand Down Expand Up @@ -2428,12 +2428,11 @@ void LuaScriptInterface::initElementsAPI()
{
lua_pushinteger(l, i);
lua_setfield(l, -2, luacon_sim->elements[i].Identifier.c_str());
char realIdentifier[20];
sprintf(realIdentifier, "DEFAULT_PT_%s", luacon_sim->elements[i].Name.c_str());
ByteString realIdentifier = ByteString::Build("DEFAULT_PT_", luacon_sim->elements[i].Name.ToUtf8());
if (i != 0 && i != PT_NBHL && i != PT_NWHL && luacon_sim->elements[i].Identifier != realIdentifier)
{
lua_pushinteger(l, i);
lua_setfield(l, -2, realIdentifier);
lua_setfield(l, -2, realIdentifier.c_str());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/GOLMenu.h
Expand Up @@ -3,7 +3,7 @@

struct gol_menu
{
ByteString name;
String name;
pixel colour;
int goltype;
String description;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/Simulation.cpp
Expand Up @@ -4912,7 +4912,7 @@ int Simulation::GetParticleType(ByteString type)
return PT_NONE;
for (int i = 1; i < PT_NUM; i++)
{
if (!strcasecmp(txt, elements[i].Name.c_str()) && elements[i].Name.size() && elements[i].Enabled)
if (!strcasecmp(txt, elements[i].Name.ToUtf8().c_str()) && elements[i].Name.size() && elements[i].Enabled)
{
return i;
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/Element.cpp
Expand Up @@ -51,7 +51,7 @@ Element::Element():
std::vector<StructProperty> Element::GetProperties()
{
std::vector<StructProperty> properties;
properties.push_back(StructProperty("Name", StructProperty::BString, offsetof(Element, Name)));
properties.push_back(StructProperty("Name", StructProperty::String, offsetof(Element, Name)));
properties.push_back(StructProperty("Colour", StructProperty::Colour, offsetof(Element, Colour)));
properties.push_back(StructProperty("Color", StructProperty::Colour, offsetof(Element, Colour)));
properties.push_back(StructProperty("MenuVisible", StructProperty::Integer, offsetof(Element, MenuVisible)));
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/Element.h
Expand Up @@ -14,7 +14,7 @@ class Element
{
public:
ByteString Identifier;
ByteString Name;
String Name;
pixel Colour;
int MenuVisible;
int MenuSection;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/simtools/SimTool.h
Expand Up @@ -11,7 +11,7 @@ class SimTool
{
public:
ByteString Identifier;
ByteString Name;
String Name;
pixel Colour;
String Description;

Expand Down

0 comments on commit 2e17b84

Please sign in to comment.