Skip to content

Commit

Permalink
Clean up sign-related code a bit
Browse files Browse the repository at this point in the history
Also draw search signs with purple text and thread signs with red.
  • Loading branch information
LBPHacker committed Apr 12, 2019
1 parent 59afaec commit 9d92b77
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 228 deletions.
36 changes: 8 additions & 28 deletions src/graphics/RasterDrawMethods.inl
Expand Up @@ -58,34 +58,14 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, String str, int r, int g, int b,
if(!s[1]) break;
switch (s[1])
{
case 'w':
r = g = b = 255;
break;
case 'g':
r = g = b = 192;
break;
case 'o':
r = 255;
g = 216;
b = 32;
break;
case 'r':
r = 255;
g = b = 0;
break;
case 'l':
r = 255;
g = b = 75;
break;
case 'b':
r = g = 0;
b = 255;
break;
case 't':
b = 255;
g = 170;
r = 32;
break;
case 'w': r = 255; g = 255; b = 255; break;
case 'g': r = 192; g = 192; b = 192; break;
case 'o': r = 255; g = 216; b = 32; break;
case 'r': r = 255; g = 0; b = 0; break;
case 'l': r = 255; g = 75; b = 75; break;
case 'b': r = 0; g = 0; b = 255; break;
case 't': b = 255; g = 170; r = 32; break;
case 'u': r = 147; g = 83; b = 211; break;
}
if(invert)
{
Expand Down
30 changes: 12 additions & 18 deletions src/graphics/Renderer.cpp
Expand Up @@ -981,28 +981,21 @@ void Renderer::DrawSigns()
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
glTranslated(0, MENUSIZE, 0);
#endif
for (size_t i = 0; i < signs.size(); i++)
if (signs[i].text.length())
for (auto &currentSign : signs)
{
if (currentSign.text.length())
{
String::value_type type = 0;
String text = signs[i].getText(sim);
sign::splitsign(signs[i].text, &type);
signs[i].pos(text, x, y, w, h);
String text = currentSign.getDisplayText(sim, x, y, w, h);
clearrect(x, y, w+1, h);
drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (!type)
drawtext(x+3, y+3, text, 255, 255, 255, 255);
else if(type == 'b')
drawtext(x+3, y+3, text, 211, 211, 40, 255);
else
drawtext(x+3, y+3, text, 0, 191, 255, 255);

if (signs[i].ju != sign::None)
drawtext(x+3, y+3, text, 255, 255, 255, 255);

if (currentSign.ju != sign::None)
{
int x = signs[i].x;
int y = signs[i].y;
int dx = 1 - signs[i].ju;
int dy = (signs[i].y > 18) ? -1 : 1;
int x = currentSign.x;
int y = currentSign.y;
int dx = 1 - currentSign.ju;
int dy = (currentSign.y > 18) ? -1 : 1;
#ifdef OGLR
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
Expand All @@ -1019,6 +1012,7 @@ void Renderer::DrawSigns()
#endif
}
}
}
#ifdef OGLR
glTranslated(0, -MENUSIZE, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo);
Expand Down
55 changes: 26 additions & 29 deletions src/gui/game/GameController.cpp
Expand Up @@ -311,7 +311,7 @@ int GameController::GetSignAt(int x, int y)
for (int i = sim->signs.size()-1; i >= 0; i--)
{
int signx, signy, signw, signh;
sim->signs[i].pos(sim->signs[i].getText(sim), signx, signy, signw, signh);
sim->signs[i].getDisplayText(sim, signx, signy, signw, signh);
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
return i;
}
Expand All @@ -324,6 +324,11 @@ String GameController::GetSignText(int signID)
return gameModel->GetSimulation()->signs[signID].text;
}

std::pair<int, sign::Type> GameController::GetSignSplit(int signID)
{
return gameModel->GetSimulation()->signs[signID].split();
}

void GameController::PlaceSave(ui::Point position, bool includePressure)
{
bool incPressure = Client::Ref().GetPrefBool("Simulation.LoadPressure", true);
Expand Down Expand Up @@ -640,9 +645,10 @@ bool GameController::MouseDown(int x, int y, unsigned button)
foundSignID = GetSignAt(x, y);
if (foundSignID != -1)
{
sign foundSign = gameModel->GetSimulation()->signs[foundSignID];
if (sign::splitsign(foundSign.text))
if (gameModel->GetSimulation()->signs[foundSignID].split().first)
{
return false;
}
}
}
}
Expand All @@ -665,40 +671,31 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
int foundSignID = GetSignAt(x, y);
if (foundSignID != -1)
{
sign foundSign = gameModel->GetSimulation()->signs[foundSignID];
sign &foundSign = gameModel->GetSimulation()->signs[foundSignID];
String str = foundSign.text;
String::value_type type;
int pos = sign::splitsign(str, &type);
if (pos)
auto si = gameModel->GetSimulation()->signs[foundSignID].split();
if (si.first)
{
ret = false;
if (type == 'c' || type == 't' || type == 's')
switch (si.second)
{
String link = str.Substr(3, pos-3);
switch (type)
{
case 'c':
case sign::Type::Save:
{
int saveID = link.ToNumber<int>(true);
int saveID = str.Substr(3, si.first - 3).ToNumber<int>(true);
if (saveID)
OpenSavePreview(saveID, 0, false);
break;
}
case 't':
{
// buff is already confirmed to be a number by sign::splitsign
Platform::OpenURI(ByteString::Build(SCHEME "powdertoy.co.uk/Discussions/Thread/View.html?Thread=", link.ToUtf8()));
break;
}
case 's':
OpenSearch(link);
break;
}
}
else if (type == 'b')
{
Simulation * sim = gameModel->GetSimulation();
sim->create_part(-1, foundSign.x, foundSign.y, PT_SPRK);
break;
case sign::Type::Thread:
Platform::OpenURI(ByteString::Build(SCHEME "powdertoy.co.uk/Discussions/Thread/View.html?Thread=", str.Substr(3, si.first - 3).ToUtf8()));
break;
case sign::Type::Search:
OpenSearch(str.Substr(3, si.first - 3));
break;
case sign::Type::Button:
gameModel->GetSimulation()->create_part(-1, foundSign.x, foundSign.y, PT_SPRK);
break;
default: break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -59,6 +59,7 @@ class GameController: public ClientListener
GameView * GetView();
int GetSignAt(int x, int y);
String GetSignText(int signID);
std::pair<int, sign::Type> GetSignSplit(int signID);

bool MouseMove(int x, int y, int dx, int dy);
bool MouseDown(int x, int y, unsigned button);
Expand Down
35 changes: 18 additions & 17 deletions src/gui/game/GameView.cpp
Expand Up @@ -1726,24 +1726,25 @@ void GameView::OnTick(float dt)
if (foundSignID != -1)
{
String str = c->GetSignText(foundSignID);
String::value_type type = '\0';
int pos = sign::splitsign(str, &type);
if (type == 'c' || type == 't' || type == 's')
auto si = c->GetSignSplit(foundSignID);

StringBuilder tooltip;
switch (si.second)
{
case sign::Type::Save:
tooltip << "Go to save ID:" << str.Substr(3, si.first - 3);
break;
case sign::Type::Thread:
tooltip << "Open forum thread " << str.Substr(3, si.first - 3) << " in browser";
break;
case sign::Type::Search:
tooltip << "Search for " << str.Substr(3, si.first - 3);
break;
default: break;
}

if (tooltip.Size())
{
String linkSign = str.Substr(3, pos-3);
StringBuilder tooltip;
switch (type)
{
case 'c':
tooltip << "Go to save ID:" << linkSign;
break;
case 't':
tooltip << "Open forum thread " << linkSign << " in browser";
break;
case 's':
tooltip << "Search for " << linkSign;
break;
}
ToolTip(ui::Point(0, Size.Y), tooltip.Build());
}
}
Expand Down
18 changes: 5 additions & 13 deletions src/gui/game/SignTool.cpp
Expand Up @@ -193,23 +193,15 @@ void SignWindow::OnTryExit(ui::Window::ExitMethod method)

void SignWindow::DoDraw()
{
for(std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter)
for (auto &currentSign : sim->signs)
{
sign & currentSign = *iter;
int x, y, w, h, dx, dy;
String::value_type type = 0;
Graphics * g = GetGraphics();
String text = currentSign.getText(sim);
sign::splitsign(currentSign.text, &type);
currentSign.pos(text, x, y, w, h);

String text = currentSign.getDisplayText(sim, x, y, w, h);
g->clearrect(x, y, w+1, h);
g->drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (!type)
g->drawtext(x+3, y+3, text, 255, 255, 255, 255);
else if(type == 'b')
g->drawtext(x+3, y+3, text, 211, 211, 40, 255);
else
g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
g->drawtext(x+3, y+3, text, 255, 255, 255, 255);

if (currentSign.ju != sign::None)
{
Expand Down Expand Up @@ -294,7 +286,7 @@ void SignTool::Click(Simulation * sim, Brush * brush, ui::Point position)
int signX, signY, signW, signH, signIndex = -1;
for (size_t i = 0; i < sim->signs.size(); i++)
{
sim->signs[i].pos(sim->signs[i].getText(sim), signX, signY, signW, signH);
sim->signs[i].getDisplayText(sim, signX, signY, signW, signH);
if (position.X > signX && position.X < signX+signW && position.Y > signY && position.Y < signY+signH)
{
signIndex = i;
Expand Down
15 changes: 6 additions & 9 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -564,10 +564,11 @@ int LuaScriptInterface::simulation_signIndex(lua_State *l)
return lua_pushnil(l), 1;
}

int x, y, w, h;
if (!key.compare("text"))
return lua_pushstring(l, luacon_sim->signs[id].text.ToUtf8().c_str()), 1;
else if (!key.compare("displayText"))
return lua_pushstring(l, luacon_sim->signs[id].getText(luacon_sim).ToUtf8().c_str()), 1;
return lua_pushstring(l, luacon_sim->signs[id].getDisplayText(luacon_sim, x, y, w, h, false).ToUtf8().c_str()), 1;
else if (!key.compare("justification"))
return lua_pushnumber(l, (int)luacon_sim->signs[id].ju), 1;
else if (!key.compare("x"))
Expand All @@ -576,29 +577,25 @@ int LuaScriptInterface::simulation_signIndex(lua_State *l)
return lua_pushnumber(l, luacon_sim->signs[id].y), 1;
else if (!key.compare("screenX"))
{
int x, y, w, h;
luacon_sim->signs[id].pos(luacon_sim->signs[id].getText(luacon_sim), x, y, w, h);
luacon_sim->signs[id].getDisplayText(luacon_sim, x, y, w, h);
lua_pushnumber(l, x);
return 1;
}
else if (!key.compare("screenY"))
{
int x, y, w, h;
luacon_sim->signs[id].pos(luacon_sim->signs[id].getText(luacon_sim), x, y, w, h);
luacon_sim->signs[id].getDisplayText(luacon_sim, x, y, w, h);
lua_pushnumber(l, y);
return 1;
}
else if (!key.compare("width"))
{
int x, y, w, h;
luacon_sim->signs[id].pos(luacon_sim->signs[id].getText(luacon_sim), x, y, w, h);
luacon_sim->signs[id].getDisplayText(luacon_sim, x, y, w, h);
lua_pushnumber(l, w);
return 1;
}
else if (!key.compare("height"))
{
int x, y, w, h;
luacon_sim->signs[id].pos(luacon_sim->signs[id].getText(luacon_sim), x, y, w, h);
luacon_sim->signs[id].getDisplayText(luacon_sim, x, y, w, h);
lua_pushnumber(l, h);
return 1;
}
Expand Down

0 comments on commit 9d92b77

Please sign in to comment.