allow longer signs, add 'None' justification where the pointer line isn't drawn

signs have a longer width limit and hard 45 character limit from the textbox and when loading saves
This commit is contained in:
jacob1 2015-08-29 18:56:38 -04:00
parent 4cc753edc1
commit 5caf8bc8e1
6 changed files with 47 additions and 39 deletions

View File

@ -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) 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) 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; x = 254;
memcpy(tempSignText, d+p, x); memcpy(tempSignText, d+p, x);
tempSignText[x] = 0; 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); tempSigns.push_back(tempSign);
p += x; p += x;
} }

View File

@ -951,6 +951,8 @@ void Renderer::DrawSigns()
else else
drawtext(x+3, y+3, text, 0, 191, 255, 255); drawtext(x+3, y+3, text, 0, 191, 255, 255);
if (signs[i].ju != sign::None)
{
int x = signs[i].x; int x = signs[i].x;
int y = signs[i].y; int y = signs[i].y;
int dx = 1 - signs[i].ju; int dx = 1 - signs[i].ju;
@ -968,6 +970,7 @@ void Renderer::DrawSigns()
x += dx; x += dx;
y += dy; y += dy;
} }
}
#endif #endif
} }
#ifdef OGLR #ifdef OGLR

View File

@ -99,7 +99,7 @@ public:
}; };
SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_): 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_), tool(tool_),
movingSign(NULL), movingSign(NULL),
signMoving(false), 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)); justification = new ui::DropDown(ui::Point(52, 48), ui::Point(50, 16));
AddComponent(justification); AddComponent(justification);
justification->AddOption(std::pair<std::string, int>("\x9D Left", (int)sign::Left)); 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>("\x9F Right", (int)sign::Right));
justification->AddOption(std::pair<std::string, int>(" None", (int)sign::None));
justification->SetOption(1); justification->SetOption(1);
justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 17), "", "[message]"); textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 17), "", "[message]");
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
textField->SetLimit(45);
textField->SetActionCallback(new SignTextAction(this)); textField->SetActionCallback(new SignTextAction(this));
AddComponent(textField); AddComponent(textField);
FocusComponent(textField); FocusComponent(textField);
@ -193,6 +195,8 @@ void SignWindow::DoDraw()
else else
g->drawtext(x+3, y+3, text, 0, 191, 255, 255); g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
if (currentSign.ju != sign::None)
{
x = currentSign.x; x = currentSign.x;
y = currentSign.y; y = currentSign.y;
dx = 1 - currentSign.ju; dx = 1 - currentSign.ju;
@ -210,6 +214,7 @@ void SignWindow::DoDraw()
x+=dx; x+=dx;
y+=dy; y+=dy;
} }
}
#endif #endif
} }
if(!signMoving) if(!signMoving)

View File

@ -209,7 +209,7 @@ void Textbox::pasteIntoSelection()
else else
newText = ""; 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 pLimit = regionWidth - Graphics::textwidth((char*)backingText.c_str());
int cIndex = Graphics::CharIndexAtPosition((char *)newText.c_str(), pLimit, 0); 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 -= 13;
regionWidth -= Appearance.Margin.Left; regionWidth -= Appearance.Margin.Left;
regionWidth -= Appearance.Margin.Right; 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()) if (cursor == (int)backingText.length())
{ {

View File

@ -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; w = Graphics::textwidth(signText.c_str()) + 5;
h = 15; h = 15;
x0 = (ju == 2) ? x - w : x0 = (ju == Right) ? x - w :
(ju == 1) ? x - w/2 : x; (ju == Left) ? x : x - w/2;
y0 = (y > 18) ? y - 18 : y + 4; y0 = (y > 18) ? y - 18 : y + 4;
} }

View File

@ -8,7 +8,7 @@ class Simulation;
class sign class sign
{ {
public: 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_); sign(std::string text_, int x_, int y_, Justification justification_);
int x, y; int x, y;
Justification ju; Justification ju;