Merge branch 'feature_sparksigns' into develop

This commit is contained in:
Simon Robertshaw 2013-10-29 19:43:02 +00:00
commit f2e28ee667
7 changed files with 95 additions and 43 deletions

View File

@ -622,21 +622,34 @@ void membwand(void * destv, void * srcv, size_t destsize, size_t srcsize)
} }
} }
int splitsign(const char* str) int splitsign(const char* str, char * type)
{ {
int match=0,r; int match=0,r;
if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9') if (str[0]=='{' && (str[1]=='c' || str[1]=='t' || str[1]=='b'))
{ {
const char* p=str+4; const char* p=str+2;
while (*p>='0' && *p<='9') if(str[1] != 'b') {
p++; if(str[2]==':' && str[3]>='0' && str[3]<='9')
{
p=str+4;
while (*p>='0' && *p<='9')
p++;
}
else
return 0;
}
if (*p=='|') if (*p=='|')
{ {
r=p-str; r=p-str;
while (*p) while (*p)
p++; p++;
if (p[-1]=='}') if (p[-1]=='}')
{
if(type)
*type = str[1];
return r; return r;
}
} }
} }
return 0; return 0;

View File

@ -86,7 +86,7 @@ void OpenURI(std::string uri);
void membwand(void * dest, void * src, size_t destsize, size_t srcsize); void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
int splitsign(const char* str); int splitsign(const char* str, char * type = NULL);
// a b // a b
// c d // c d

View File

@ -923,14 +923,18 @@ void Renderer::DrawSigns()
for (i=0; i < signs.size(); i++) for (i=0; i < signs.size(); i++)
if (signs[i].text.length()) if (signs[i].text.length())
{ {
char type = 0;
std::string text = signs[i].getText(sim); std::string text = signs[i].getText(sim);
splitsign(signs[i].text.c_str(), &type);
signs[i].pos(text, x, y, w, h); signs[i].pos(text, x, y, w, h);
clearrect(x, y, w+1, h); clearrect(x, y, w+1, h);
drawrect(x, y, w+1, h, 192, 192, 192, 255); drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (splitsign(signs[i].text.c_str())) if (!type)
drawtext(x+3, y+3, text, 0, 191, 255, 255);
else
drawtext(x+3, y+3, text, 255, 255, 255, 255); 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);
x = signs[i].x; x = signs[i].x;
y = signs[i].y; y = signs[i].y;

View File

@ -253,6 +253,18 @@ GameView * GameController::GetView()
return gameView; return gameView;
} }
sign * GameController::GetSignAt(int x, int y){
Simulation * sim = gameModel->GetSimulation();
for (std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter)
{
int signx, signy, signw, signh;
(*iter).pos((*iter).getText(sim), signx, signy, signw, signh);
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
return &(*iter);
}
return NULL;
}
void GameController::PlaceSave(ui::Point position) void GameController::PlaceSave(ui::Point position)
{ {
if(gameModel->GetPlaceSave()) if(gameModel->GetPlaceSave())
@ -550,7 +562,18 @@ bool GameController::BrushChanged(int brushType, int rx, int ry)
bool GameController::MouseDown(int x, int y, unsigned button) bool GameController::MouseDown(int x, int y, unsigned button)
{ {
return commandInterface->OnMouseDown(x, y, button); bool ret = commandInterface->OnMouseDown(x, y, button);
ui::Point point = PointTranslate(ui::Point(x, y));
x = point.X;
y = point.Y;
if(ret && y<YRES && x<XRES)
if (gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
{
sign * foundSign = GetSignAt(x, y);
if(foundSign && splitsign(foundSign->text.c_str()))
return false;
}
return ret;
} }
bool GameController::MouseUp(int x, int y, unsigned button) bool GameController::MouseUp(int x, int y, unsigned button)
@ -563,17 +586,15 @@ bool GameController::MouseUp(int x, int y, unsigned button)
{ {
if (gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking if (gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
{ {
Simulation * sim = gameModel->GetSimulation(); sign * foundSign = GetSignAt(x, y);
for (std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter) if(foundSign) {
{ const char* str=foundSign->text.c_str();
int signx, signy, signw, signh; char type;
(*iter).pos((*iter).getText(sim), signx, signy, signw, signh); int pos=splitsign(str, &type);
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh) if (pos)
{ {
const char* str=(*iter).text.c_str(); ret = false;
int pos=splitsign(str); if(type == 'c' || type == 't') {
if (pos)
{
char buff[256]; char buff[256];
strcpy(buff, str+3); strcpy(buff, str+3);
buff[pos]=0; buff[pos]=0;
@ -589,7 +610,9 @@ bool GameController::MouseUp(int x, int y, unsigned button)
OpenURI(url); OpenURI(url);
} }
} }
break; } else if(type == 'b') {
Simulation * sim = gameModel->GetSimulation();
sim->create_part(-1, foundSign->x, foundSign->y, PT_SPRK);
} }
} }
} }

View File

@ -56,6 +56,7 @@ public:
GameController(); GameController();
~GameController(); ~GameController();
GameView * GetView(); GameView * GetView();
sign * GetSignAt(int x, int y);
bool BrushChanged(int brushType, int rx, int ry); bool BrushChanged(int brushType, int rx, int ry);
bool MouseMove(int x, int y, int dx, int dy); bool MouseMove(int x, int y, int dx, int dy);

View File

@ -178,15 +178,19 @@ void SignWindow::DoDraw()
{ {
sign & currentSign = *iter; sign & currentSign = *iter;
int x, y, w, h, dx, dy; int x, y, w, h, dx, dy;
char type = 0;
Graphics * g = ui::Engine::Ref().g; Graphics * g = ui::Engine::Ref().g;
std::string text = currentSign.getText(sim); std::string text = currentSign.getText(sim);
splitsign(currentSign.text.c_str(), &type);
currentSign.pos(text, x, y, w, h); currentSign.pos(text, x, y, w, h);
g->clearrect(x, y, w+1, h); g->clearrect(x, y, w+1, h);
g->drawrect(x, y, w+1, h, 192, 192, 192, 255); g->drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (splitsign(currentSign.text.c_str())) if (!type)
g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
else
g->drawtext(x+3, y+3, text, 255, 255, 255, 255); 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);
x = currentSign.x; x = currentSign.x;
y = currentSign.y; y = currentSign.y;

View File

@ -17,30 +17,37 @@ std::string sign::getText(Simulation *sim)
char signText[256]; char signText[256];
sprintf(signText, "%s", text.substr(0, 255).c_str()); sprintf(signText, "%s", text.substr(0, 255).c_str());
if (!strcmp(signText,"{p}")) if(signText[0] && signText[0] == '{')
{ {
float pressure = 0.0f; if (!strcmp(signText,"{p}"))
if (x>=0 && x<XRES && y>=0 && y<YRES) {
pressure = sim->pv[y/CELL][x/CELL]; float pressure = 0.0f;
sprintf(buff, "Pressure: %3.2f", pressure); //...pressure if (x>=0 && x<XRES && y>=0 && y<YRES)
} pressure = sim->pv[y/CELL][x/CELL];
else if (!strcmp(signText,"{t}")) sprintf(buff, "Pressure: %3.2f", pressure); //...pressure
{ }
if (x>=0 && x<XRES && y>=0 && y<YRES && sim->pmap[y][x]) else if (!strcmp(signText,"{t}"))
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[y][x]>>8].temp-273.15); //...temperature {
if (x>=0 && x<XRES && y>=0 && y<YRES && sim->pmap[y][x])
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[y][x]>>8].temp-273.15); //...temperature
else
sprintf(buff, "Temp: 0.00"); //...temperature
}
else else
sprintf(buff, "Temp: 0.00"); //...temperature {
int pos=splitsign(signText);
if (pos)
{
strcpy(buff, signText+pos+1);
buff[strlen(signText)-pos-2]=0;
}
else
strcpy(buff, signText);
}
} }
else else
{ {
int pos=splitsign(signText); strcpy(buff, signText);
if (pos)
{
strcpy(buff, signText+pos+1);
buff[strlen(signText)-pos-2]=0;
}
else
strcpy(buff, signText);
} }
return std::string(buff); return std::string(buff);