mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-15 03:39:56 +01:00
Stupid git
This commit is contained in:
parent
7128188048
commit
724c99102e
@ -474,15 +474,17 @@ void Renderer::DrawWalls()
|
||||
|
||||
void Renderer::get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
|
||||
{
|
||||
sign *signs = sim->signs;
|
||||
std::vector<sign> signs = sim->signs;
|
||||
//Changing width if sign have special content
|
||||
if (strcmp(signs[i].text, "{p}")==0)
|
||||
if (signs[i].text == "{p}")
|
||||
{
|
||||
*w = Graphics::textwidth("Pressure: -000.00");
|
||||
|
||||
if (strcmp(signs[i].text, "{t}")==0)
|
||||
}
|
||||
else if (signs[i].text == "{t}")
|
||||
{
|
||||
*w = Graphics::textwidth("Temp: 0000.00");
|
||||
|
||||
if (sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
|
||||
}
|
||||
else if (sregexp(signs[i].text.c_str(), "^{c:[0-9]*|.*}$")==0)
|
||||
{
|
||||
int sldr, startm;
|
||||
char buff[256];
|
||||
@ -498,10 +500,10 @@ void Renderer::get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
|
||||
}
|
||||
*w = Graphics::textwidth(buff) + 5;
|
||||
}
|
||||
|
||||
//Ususal width
|
||||
if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
|
||||
*w = Graphics::textwidth(signs[i].text) + 5;
|
||||
else
|
||||
{
|
||||
*w = Graphics::textwidth(signs[i].text.c_str()) + 5;
|
||||
}
|
||||
*h = 14;
|
||||
*x0 = (signs[i].ju == 2) ? signs[i].x - *w :
|
||||
(signs[i].ju == 1) ? signs[i].x - *w/2 : signs[i].x;
|
||||
@ -511,13 +513,13 @@ void Renderer::get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
|
||||
void Renderer::DrawSigns()
|
||||
{
|
||||
int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq;
|
||||
sign *signs = sim->signs;
|
||||
std::vector<sign> signs = sim->signs;
|
||||
#ifdef OGLR
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
|
||||
glTranslated(0, MENUSIZE, 0);
|
||||
#endif
|
||||
for (i=0; i<MAXSIGNS; i++)
|
||||
if (signs[i].text[0])
|
||||
for (i=0; i < signs.size(); i++)
|
||||
if (signs[i].text.length())
|
||||
{
|
||||
char buff[256]; //Buffer
|
||||
get_sign_pos(i, &x, &y, &w, &h);
|
||||
@ -525,7 +527,7 @@ void Renderer::DrawSigns()
|
||||
g->drawrect(x, y, w, h, 192, 192, 192, 255);
|
||||
|
||||
//Displaying special information
|
||||
if (strcmp(signs[i].text, "{p}")==0)
|
||||
if (signs[i].text == "{p}")
|
||||
{
|
||||
float pressure = 0.0f;
|
||||
if (signs[i].x>=0 && signs[i].x<XRES && signs[i].y>=0 && signs[i].y<YRES)
|
||||
@ -533,7 +535,7 @@ void Renderer::DrawSigns()
|
||||
sprintf(buff, "Pressure: %3.2f", pressure); //...pressure
|
||||
g->drawtext(x+3, y+3, buff, 255, 255, 255, 255);
|
||||
}
|
||||
if (strcmp(signs[i].text, "{t}")==0)
|
||||
else if (signs[i].text == "{t}")
|
||||
{
|
||||
if (signs[i].x>=0 && signs[i].x<XRES && signs[i].y>=0 && signs[i].y<YRES && sim->pmap[signs[i].y][signs[i].x])
|
||||
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[signs[i].y][signs[i].x]>>8].temp-273.15); //...temperature
|
||||
@ -541,8 +543,7 @@ void Renderer::DrawSigns()
|
||||
sprintf(buff, "Temp: 0.00"); //...temperature
|
||||
g->drawtext(x+3, y+3, buff, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
if (sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
|
||||
else if (sregexp(signs[i].text.c_str(), "^{c:[0-9]*|.*}$")==0)
|
||||
{
|
||||
int sldr, startm;
|
||||
memset(buff, 0, sizeof(buff));
|
||||
@ -556,11 +557,11 @@ void Renderer::DrawSigns()
|
||||
}
|
||||
g->drawtext(x+3, y+3, buff, 0, 191, 255, 255);
|
||||
}
|
||||
|
||||
//Usual text
|
||||
if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
|
||||
else
|
||||
{
|
||||
g->drawtext(x+3, y+3, signs[i].text, 255, 255, 255, 255);
|
||||
|
||||
}
|
||||
|
||||
x = signs[i].x;
|
||||
y = signs[i].y;
|
||||
dx = 1 - signs[i].ju;
|
||||
|
@ -18,7 +18,8 @@ public:
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
prompt->callback->TextCallback(result, prompt->textField->GetText());
|
||||
if(prompt->callback)
|
||||
prompt->callback->TextCallback(result, prompt->textField->GetText());
|
||||
prompt->SelfDestruct(); //TODO: Fix component disposal
|
||||
}
|
||||
};
|
||||
|
@ -93,6 +93,10 @@ GameModel::GameModel():
|
||||
//sim->wtypes[i]
|
||||
}
|
||||
|
||||
//Add special sign and prop tools
|
||||
menuList[SC_TOOL]->AddTool(new SignTool());
|
||||
menuList[SC_TOOL]->AddTool(new PropertyTool());
|
||||
|
||||
//Build menu for simtools
|
||||
for(int i = 0; i < sim->tools.size(); i++)
|
||||
{
|
||||
@ -109,8 +113,8 @@ GameModel::GameModel():
|
||||
menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSet, "SET", 0, 0, 0));
|
||||
|
||||
//Set default brush palette
|
||||
brushList.push_back(new Brush(ui::Point(4, 4)));
|
||||
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
|
||||
brushList.push_back(new Brush(ui::Point(4, 4)));
|
||||
|
||||
//Set default tools
|
||||
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
|
||||
|
@ -1,9 +1,81 @@
|
||||
//
|
||||
// SignTool.cpp
|
||||
// PowderToypp
|
||||
//
|
||||
// Created by Simon Robertshaw on 12/05/2012.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "simulation/Simulation.h"
|
||||
#include "Tool.h"
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Button.h"
|
||||
#include "interface/Label.h"
|
||||
#include "interface/Textbox.h"
|
||||
|
||||
class SignWindow: public ui::Window
|
||||
{
|
||||
public:
|
||||
ui::Textbox * textField;
|
||||
SignTool * tool;
|
||||
Simulation * sim;
|
||||
int signID;
|
||||
ui::Point signPosition;
|
||||
SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_);
|
||||
virtual void OnDraw();
|
||||
virtual ~SignWindow() {}
|
||||
};
|
||||
|
||||
class OkayAction: public ui::ButtonAction
|
||||
{
|
||||
public:
|
||||
SignWindow * prompt;
|
||||
OkayAction(SignWindow * prompt_) { prompt = prompt_; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
prompt->SelfDestruct();
|
||||
|
||||
if(prompt->signID==-1 && prompt->textField->GetText().length())
|
||||
{
|
||||
prompt->sim->signs.push_back(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, sign::Left));
|
||||
}
|
||||
else
|
||||
{
|
||||
prompt->sim->signs[prompt->signID] = sign(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, sign::Left));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_):
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 75)),
|
||||
tool(tool_),
|
||||
signID(signID_),
|
||||
sim(sim_),
|
||||
signPosition(position_)
|
||||
{
|
||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), "New sign");
|
||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||
AddComponent(messageLabel);
|
||||
|
||||
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "OK");
|
||||
okayButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
okayButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||
okayButton->SetActionCallback(new OkayAction(this));
|
||||
AddComponent(okayButton);
|
||||
|
||||
textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
|
||||
textField->SetAlignment(AlignLeft, AlignBottom);
|
||||
AddComponent(textField);
|
||||
|
||||
ui::Engine::Ref().ShowWindow(this);
|
||||
}
|
||||
void SignWindow::OnDraw()
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
|
||||
g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
|
||||
}
|
||||
|
||||
void SignTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
|
||||
{
|
||||
if(!opened) //Ensure the dialogue can only be shown one at a time.
|
||||
{
|
||||
opened = true;
|
||||
new SignWindow(this, sim, -1, position);
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ protected:
|
||||
string toolName;
|
||||
public:
|
||||
Tool(int id, string name, int r, int g, int b):
|
||||
toolID(id),
|
||||
toolName(name),
|
||||
colRed(r),
|
||||
colGreen(g),
|
||||
colBlue(b)
|
||||
toolID(id),
|
||||
toolName(name),
|
||||
colRed(r),
|
||||
colGreen(g),
|
||||
colBlue(b)
|
||||
{
|
||||
}
|
||||
string GetName() { return toolName; }
|
||||
@ -41,6 +41,38 @@ public:
|
||||
int colRed, colBlue, colGreen;
|
||||
};
|
||||
|
||||
class SignTool: public Tool
|
||||
{
|
||||
public:
|
||||
SignTool():
|
||||
Tool(0, "SIGN", 0, 0, 0),
|
||||
opened(false)
|
||||
{
|
||||
}
|
||||
virtual ~SignTool() {}
|
||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
|
||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
|
||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||
void SetClosed() { opened = false; }
|
||||
protected:
|
||||
bool opened;
|
||||
};
|
||||
|
||||
class PropertyTool: public Tool
|
||||
{
|
||||
public:
|
||||
PropertyTool():
|
||||
Tool(0, "PROP", 0, 0, 0)
|
||||
{
|
||||
}
|
||||
virtual ~PropertyTool() {}
|
||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {};
|
||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
|
||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
|
||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||
};
|
||||
|
||||
class ElementTool: public Tool
|
||||
{
|
||||
public:
|
||||
|
@ -86,6 +86,10 @@ int SaveLoader::PSVLoad(unsigned char * data, int dataLength, Simulation * sim,
|
||||
int nf=0, new_format = 0, ttv = 0;
|
||||
Particle *parts = sim->parts;
|
||||
int *fp = (int *)malloc(NPART*sizeof(int));
|
||||
|
||||
std::vector<sign> tempSigns;
|
||||
char tempSignText[255];
|
||||
sign tempSign("", 0, 0, sign::Left);
|
||||
|
||||
//New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures
|
||||
//This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error
|
||||
@ -665,31 +669,32 @@ int SaveLoader::PSVLoad(unsigned char * data, int dataLength, Simulation * sim,
|
||||
{
|
||||
if (p+6 > dataLength)
|
||||
goto corrupt;
|
||||
for (k=0; k<MAXSIGNS; k++)
|
||||
if (!sim->signs[k].text[0])
|
||||
break;
|
||||
x = d[p++];
|
||||
x |= ((unsigned)d[p++])<<8;
|
||||
if (k<MAXSIGNS)
|
||||
sim->signs[k].x = x+x0;
|
||||
tempSign.x = x+x0;
|
||||
x = d[p++];
|
||||
x |= ((unsigned)d[p++])<<8;
|
||||
if (k<MAXSIGNS)
|
||||
sim->signs[k].y = x+y0;
|
||||
tempSign.y = x+y0;
|
||||
x = d[p++];
|
||||
if (k<MAXSIGNS)
|
||||
sim->signs[k].ju = x;
|
||||
tempSign.ju = (sign::Justification)x;
|
||||
x = d[p++];
|
||||
if (p+x > dataLength)
|
||||
goto corrupt;
|
||||
if (k<MAXSIGNS)
|
||||
{
|
||||
memcpy(sim->signs[k].text, d+p, x);
|
||||
sim->signs[k].text[x] = 0;
|
||||
//clean_text(signs[k].text, 158-14 /* Current max sign length */); //TODO: Text cleanup for signs
|
||||
}
|
||||
goto corrupt;
|
||||
if(x>254)
|
||||
x = 254;
|
||||
memcpy(tempSignText, d+p, x);
|
||||
tempSignText[x] = 0;
|
||||
tempSign.text = tempSignText;
|
||||
tempSigns.push_back(tempSign);
|
||||
p += x;
|
||||
}
|
||||
|
||||
for (i = 0; i < tempSigns.size(); i++)
|
||||
{
|
||||
if(i == MAXSIGNS)
|
||||
break;
|
||||
sim->signs.push_back(tempSigns[i]);
|
||||
}
|
||||
|
||||
version1:
|
||||
if (m) free(m);
|
||||
@ -868,14 +873,14 @@ unsigned char * SaveLoader::PSVBuild(int & dataLength, Simulation * sim, int ori
|
||||
}
|
||||
|
||||
j = 0;
|
||||
for (i=0; i<MAXSIGNS; i++)
|
||||
if (sim->signs[i].text[0] &&
|
||||
for (i=0; i<sim->signs.size(); i++)
|
||||
if (sim->signs[i].text.length() &&
|
||||
sim->signs[i].x>=x0 && sim->signs[i].x<x0+w &&
|
||||
sim->signs[i].y>=y0 && sim->signs[i].y<y0+h)
|
||||
j++;
|
||||
d[p++] = j;
|
||||
for (i=0; i<MAXSIGNS; i++)
|
||||
if (sim->signs[i].text[0] &&
|
||||
for (i=0; i<sim->signs.size(); i++)
|
||||
if (sim->signs[i].text.length() &&
|
||||
sim->signs[i].x>=x0 && sim->signs[i].x<x0+w &&
|
||||
sim->signs[i].y>=y0 && sim->signs[i].y<y0+h)
|
||||
{
|
||||
@ -884,9 +889,9 @@ unsigned char * SaveLoader::PSVBuild(int & dataLength, Simulation * sim, int ori
|
||||
d[p++] = (sim->signs[i].y-y0);
|
||||
d[p++] = (sim->signs[i].y-y0)>>8;
|
||||
d[p++] = sim->signs[i].ju;
|
||||
x = strlen(sim->signs[i].text);
|
||||
x = sim->signs[i].text.length();
|
||||
d[p++] = x;
|
||||
memcpy(d+p, sim->signs[i].text, x);
|
||||
memcpy(d+p, sim->signs[i].text.c_str(), x);
|
||||
p+=x;
|
||||
}
|
||||
|
||||
|
@ -1347,8 +1347,7 @@ void Simulation::create_arc(int sx, int sy, int dx, int dy, int midpoints, int v
|
||||
void Simulation::clear_sim(void)
|
||||
{
|
||||
int i, x, y;
|
||||
if(signs)
|
||||
memset(signs, 0, sizeof(sign)*MAXSIGNS);
|
||||
signs.clear();
|
||||
memset(bmap, 0, sizeof(bmap));
|
||||
memset(emap, 0, sizeof(emap));
|
||||
memset(parts, 0, sizeof(Particle)*NPART);
|
||||
@ -3806,7 +3805,6 @@ void Simulation::update_particles()//doesn't update the particles themselves, bu
|
||||
|
||||
Simulation::~Simulation()
|
||||
{
|
||||
free(signs);
|
||||
delete grav;
|
||||
delete air;
|
||||
}
|
||||
@ -3844,9 +3842,6 @@ Simulation::Simulation():
|
||||
pv = air->pv;
|
||||
hv = air->hv;
|
||||
|
||||
//Clear signs
|
||||
signs = (sign*)calloc(MAXSIGNS, sizeof(sign));
|
||||
|
||||
int menuCount;
|
||||
menu_section * msectionsT = LoadMenus(menuCount);
|
||||
memcpy(msections, msectionsT, menuCount * sizeof(menu_section));
|
||||
|
@ -113,8 +113,17 @@ typedef struct menu_section menu_section;
|
||||
|
||||
struct sign
|
||||
{
|
||||
int x,y,ju;
|
||||
char text[256];
|
||||
public:
|
||||
enum Justification { Left = 0, Centre = 1, Right = 2 };
|
||||
sign(std::string text_, int x_, int y_, Justification justification_):
|
||||
text(text_),
|
||||
x(x_),
|
||||
y(y_),
|
||||
ju(justification_)
|
||||
{}
|
||||
int x, y;
|
||||
Justification ju;
|
||||
std::string text;
|
||||
};
|
||||
typedef struct sign sign;
|
||||
|
||||
@ -139,6 +148,7 @@ public:
|
||||
Gravity * grav;
|
||||
Air * air;
|
||||
|
||||
vector<sign> signs;
|
||||
Element * elements;
|
||||
vector<SimTool*> tools;
|
||||
unsigned int * platent;
|
||||
@ -165,7 +175,6 @@ public:
|
||||
int NUM_PARTS;
|
||||
int elementCount[PT_NUM];
|
||||
int ISWIRE;
|
||||
sign * signs;
|
||||
//Gol sim
|
||||
int CGOL;
|
||||
int ISGOL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user