mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-07-31 13:40:12 +02:00
some changes to sign handling (attempt to fix crash that I can't reproduce)
This commit is contained in:
@@ -128,7 +128,7 @@ public:
|
|||||||
|
|
||||||
GameController::GameController():
|
GameController::GameController():
|
||||||
firstTick(true),
|
firstTick(true),
|
||||||
foundSign(NULL),
|
foundSignID(-1),
|
||||||
activePreview(NULL),
|
activePreview(NULL),
|
||||||
search(NULL),
|
search(NULL),
|
||||||
renderOptions(NULL),
|
renderOptions(NULL),
|
||||||
@@ -308,17 +308,23 @@ GameView * GameController::GetView()
|
|||||||
return gameView;
|
return gameView;
|
||||||
}
|
}
|
||||||
|
|
||||||
sign * GameController::GetSignAt(int x, int y)
|
int GameController::GetSignAt(int x, int y)
|
||||||
{
|
{
|
||||||
Simulation * sim = gameModel->GetSimulation();
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
for (std::vector<sign>::reverse_iterator iter = sim->signs.rbegin(), end = sim->signs.rend(); iter != end; ++iter)
|
for (int i = sim->signs.size()-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
int signx, signy, signw, signh;
|
int signx, signy, signw, signh;
|
||||||
(*iter).pos((*iter).getText(sim), signx, signy, signw, signh);
|
sim->signs[i].pos(sim->signs[i].getText(sim), signx, signy, signw, signh);
|
||||||
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
|
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
|
||||||
return &(*iter);
|
return i;
|
||||||
}
|
}
|
||||||
return NULL;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assumed to already be a valid sign
|
||||||
|
std::string GameController::GetSignText(int signID)
|
||||||
|
{
|
||||||
|
return gameModel->GetSimulation()->signs[signID].text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::PlaceSave(ui::Point position)
|
void GameController::PlaceSave(ui::Point position)
|
||||||
@@ -619,9 +625,13 @@ bool GameController::MouseDown(int x, int y, unsigned button)
|
|||||||
y = point.Y;
|
y = point.Y;
|
||||||
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
||||||
{
|
{
|
||||||
foundSign = GetSignAt(x, y);
|
foundSignID = GetSignAt(x, y);
|
||||||
if(foundSign && sign::splitsign(foundSign->text.c_str()))
|
if (foundSignID != -1)
|
||||||
return false;
|
{
|
||||||
|
sign foundSign = gameModel->GetSimulation()->signs[foundSignID];
|
||||||
|
if (sign::splitsign(foundSign.text.c_str()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -632,17 +642,18 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
|
|||||||
bool ret = commandInterface->OnMouseUp(x, y, button, type);
|
bool ret = commandInterface->OnMouseUp(x, y, button, type);
|
||||||
if (type)
|
if (type)
|
||||||
return ret;
|
return ret;
|
||||||
if (ret && foundSign && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
if (ret && foundSignID != -1 && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
||||||
{
|
{
|
||||||
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
|
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
|
||||||
x = point.X;
|
x = point.X;
|
||||||
y = point.Y;
|
y = point.Y;
|
||||||
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
||||||
{
|
{
|
||||||
sign * foundSign = GetSignAt(x, y);
|
int foundSignID = GetSignAt(x, y);
|
||||||
if (foundSign)
|
if (foundSignID != -1)
|
||||||
{
|
{
|
||||||
const char* str = foundSign->text.c_str();
|
sign foundSign = gameModel->GetSimulation()->signs[foundSignID];
|
||||||
|
const char* str = foundSign.text.c_str();
|
||||||
char type;
|
char type;
|
||||||
int pos = sign::splitsign(str, &type);
|
int pos = sign::splitsign(str, &type);
|
||||||
if (pos)
|
if (pos)
|
||||||
@@ -678,13 +689,13 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
|
|||||||
else if (type == 'b')
|
else if (type == 'b')
|
||||||
{
|
{
|
||||||
Simulation * sim = gameModel->GetSimulation();
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
sim->create_part(-1, foundSign->x, foundSign->y, PT_SPRK);
|
sim->create_part(-1, foundSign.x, foundSign.y, PT_SPRK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foundSign = NULL;
|
foundSignID = -1;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ class GameController: public ClientListener
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool firstTick;
|
bool firstTick;
|
||||||
sign * foundSign;
|
int foundSignID;
|
||||||
|
|
||||||
PreviewController * activePreview;
|
PreviewController * activePreview;
|
||||||
GameView * gameView;
|
GameView * gameView;
|
||||||
@@ -57,7 +57,8 @@ public:
|
|||||||
GameController();
|
GameController();
|
||||||
~GameController();
|
~GameController();
|
||||||
GameView * GetView();
|
GameView * GetView();
|
||||||
sign * GetSignAt(int x, int y);
|
int GetSignAt(int x, int y);
|
||||||
|
std::string GetSignText(int signID);
|
||||||
|
|
||||||
bool MouseMove(int x, int y, int dx, int dy);
|
bool MouseMove(int x, int y, int dx, int dy);
|
||||||
bool MouseDown(int x, int y, unsigned button);
|
bool MouseDown(int x, int y, unsigned button);
|
||||||
|
@@ -1731,10 +1731,10 @@ void GameView::OnTick(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sign * foundSign = c->GetSignAt(mousePosition.X, mousePosition.Y);
|
int foundSignID = c->GetSignAt(mousePosition.X, mousePosition.Y);
|
||||||
if (foundSign)
|
if (foundSignID != -1)
|
||||||
{
|
{
|
||||||
const char* str = foundSign->text.c_str();
|
const char* str = c->GetSignText(foundSignID).c_str();;
|
||||||
char type = '\0';
|
char type = '\0';
|
||||||
int pos = sign::splitsign(str, &type);
|
int pos = sign::splitsign(str, &type);
|
||||||
if (type == 'c' || type == 't' || type == 's')
|
if (type == 'c' || type == 't' || type == 's')
|
||||||
|
Reference in New Issue
Block a user