regexless gameModel

This commit is contained in:
mniip 2013-08-22 16:52:14 +04:00
parent 95c01bcf0a
commit 4e9fe8b8e7
2 changed files with 40 additions and 15 deletions

View File

@ -571,19 +571,30 @@ bool GameController::MouseUp(int x, int y, unsigned button)
(*iter).pos((*iter).getText(sim), signx, signy, signw, signh);
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
{
if (sregexp((*iter).text.c_str(), "^{[ct]:[0-9]*|.*}$")==0)
int match=0;
const char* str=(*iter).text.c_str();
const char* e;
if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9')
{
const char* p=str+4;
while (*p>='0' && *p<='9')
p++;
e=p;
if (*p=='|')
{
while (*p)
p++;
if (p[-1]=='}')
{
match=1;
}
}
}
if (match)
{
const char * signText = (*iter).text.c_str();
char buff[256];
int sldr;
memset(buff, 0, sizeof(buff));
for (sldr=3; signText[sldr] != '|'; sldr++)
buff[sldr-3] = signText[sldr];
buff[sldr-3] = '\0';
strcpy(buff, str+3);
buff[e-str-3]=0;
int tempSaveID = format::StringToNumber<int>(std::string(buff));
if (tempSaveID)
{

View File

@ -177,16 +177,30 @@ void SignWindow::DoDraw()
for(std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter)
{
sign & currentSign = *iter;
int x, y, w, h, dx, dy;
int x, y, w, h, dx, dy, match=0;
Graphics * g = ui::Engine::Ref().g;
std::string text = currentSign.getText(sim);
const char* str = currentSign.text.c_str();
currentSign.pos(text, x, y, w, h);
g->clearrect(x, y, w+1, h);
g->drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (sregexp(currentSign.text.c_str(), "^{[ct]:[0-9]*|.*}$"))
g->drawtext(x+3, y+3, text, 255, 255, 255, 255);
else
if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9')
{
const char* p=str+4;
while (*p>='0' && *p<='9')
p++;
if (*p=='|')
{
while (*p)
p++;
if (p[-1]=='}')
match=1;
}
}
if (match)
g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
else
g->drawtext(x+3, y+3, text, 255, 255, 255, 255);
x = currentSign.x;
y = currentSign.y;