Permalink
Browse files

allow longer signs, add 'None' justification where the pointer line i…

…sn't drawn

signs have a longer width limit and hard 45 character limit from the textbox and when loading saves
  • Loading branch information...
jacob1 committed Aug 29, 2015
1 parent 4cc753e commit 5caf8bc8e18633660b86a28fde6b148e3e4326e1
@@ -517,7 +517,7 @@ void GameSave::readOPS(char * data, int dataLength)
{
if(strcmp(bson_iterator_key(&signiter), "text")==0 && bson_iterator_type(&signiter)==BSON_STRING)
{
tempSign.text = format::CleanString(bson_iterator_string(&signiter), true, true, true).substr(0, 255);
tempSign.text = format::CleanString(bson_iterator_string(&signiter), true, true, true).substr(0, 45);
}
else if(strcmp(bson_iterator_key(&signiter), "justification")==0 && bson_iterator_type(&signiter)==BSON_INT)
{
@@ -1713,7 +1713,7 @@ void GameSave::readPSv(char * data, int dataLength)
x = 254;
memcpy(tempSignText, d+p, x);
tempSignText[x] = 0;
tempSign.text = format::CleanString(tempSignText, true, true, true);
tempSign.text = format::CleanString(tempSignText, true, true, true).substr(0, 45);
tempSigns.push_back(tempSign);
p += x;
}
@@ -951,22 +951,25 @@ void Renderer::DrawSigns()
else
drawtext(x+3, y+3, text, 0, 191, 255, 255);
int x = signs[i].x;
int y = signs[i].y;
int dx = 1 - signs[i].ju;
int dy = (signs[i].y > 18) ? -1 : 1;
if (signs[i].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;
#ifdef OGLR
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2i(x, y);
glVertex2i(x+(dx*4), y+(dy*4));
glEnd();
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2i(x, y);
glVertex2i(x+(dx*4), y+(dy*4));
glEnd();
#else
for (int j = 0; j < 4; j++)
{
blendpixel(x, y, 192, 192, 192, 255);
x += dx;
y += dy;
for (int j = 0; j < 4; j++)
{
blendpixel(x, y, 192, 192, 192, 255);
x += dx;
y += dy;
}
}
#endif
}
@@ -99,7 +99,7 @@ class SignWindow: public ui::Window
};
SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_):
ui::Window(ui::Point(-1, -1), ui::Point(200, 87)),
ui::Window(ui::Point(-1, -1), ui::Point(250, 87)),
tool(tool_),
movingSign(NULL),
signMoving(false),
@@ -129,14 +129,16 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
justification = new ui::DropDown(ui::Point(52, 48), ui::Point(50, 16));
AddComponent(justification);
justification->AddOption(std::pair<std::string, int>("\x9D Left", (int)sign::Left));
justification->AddOption(std::pair<std::string, int>("\x9E Centre", (int)sign::Centre));
justification->AddOption(std::pair<std::string, int>("\x9E Middle", (int)sign::Middle));
justification->AddOption(std::pair<std::string, int>("\x9F Right", (int)sign::Right));
justification->AddOption(std::pair<std::string, int>(" None", (int)sign::None));
justification->SetOption(1);
justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 17), "", "[message]");
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
textField->SetLimit(45);
textField->SetActionCallback(new SignTextAction(this));
AddComponent(textField);
FocusComponent(textField);
@@ -193,22 +195,25 @@ void SignWindow::DoDraw()
else
g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
x = currentSign.x;
y = currentSign.y;
dx = 1 - currentSign.ju;
dy = (currentSign.y > 18) ? -1 : 1;
if (currentSign.ju != sign::None)
{
x = currentSign.x;
y = currentSign.y;
dx = 1 - currentSign.ju;
dy = (currentSign.y > 18) ? -1 : 1;
#ifdef OGLR
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2i(x, y);
glVertex2i(x+(dx*4), y+(dy*4));
glEnd();
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2i(x, y);
glVertex2i(x+(dx*4), y+(dy*4));
glEnd();
#else
for (int j=0; j<4; j++)
{
g->blendpixel(x, y, 192, 192, 192, 255);
x+=dx;
y+=dy;
for (int j=0; j<4; j++)
{
g->blendpixel(x, y, 192, 192, 192, 255);
x+=dx;
y+=dy;
}
}
#endif
}
@@ -209,7 +209,7 @@ void Textbox::pasteIntoSelection()
else
newText = "";
}
else if (!multiline && Graphics::textwidth((char*)std::string(backingText+newText).c_str()) > regionWidth)
if (!multiline && Graphics::textwidth((char*)std::string(backingText+newText).c_str()) > regionWidth)
{
int pLimit = regionWidth - Graphics::textwidth((char*)backingText.c_str());
int cIndex = Graphics::CharIndexAtPosition((char *)newText.c_str(), pLimit, 0);
@@ -413,7 +413,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
regionWidth -= 13;
regionWidth -= Appearance.Margin.Left;
regionWidth -= Appearance.Margin.Right;
if ((limit==std::string::npos || backingText.length() < limit) && (Graphics::textwidth((char*)std::string(backingText+char(character)).c_str()) <= regionWidth || multiline || limit!=std::string::npos))
if ((limit==std::string::npos || backingText.length() < limit) && (Graphics::textwidth((char*)std::string(backingText+char(character)).c_str()) <= regionWidth || multiline))
{
if (cursor == (int)backingText.length())
{
@@ -56,8 +56,8 @@ void sign::pos(std::string signText, int & x0, int & y0, int & w, int & h)
{
w = Graphics::textwidth(signText.c_str()) + 5;
h = 15;
x0 = (ju == 2) ? x - w :
(ju == 1) ? x - w/2 : x;
x0 = (ju == Right) ? x - w :
(ju == Left) ? x : x - w/2;
y0 = (y > 18) ? y - 18 : y + 4;
}
@@ -8,7 +8,7 @@ class Simulation;
class sign
{
public:
enum Justification { Left = 0, Centre = 1, Right = 2 };
enum Justification { Left = 0, Middle = 1, Right = 2, None = 3 };
sign(std::string text_, int x_, int y_, Justification justification_);
int x, y;
Justification ju;

0 comments on commit 5caf8bc

Please sign in to comment.