Refactor tools

This commit is contained in:
mniip 2023-04-05 14:11:37 +02:00
parent 7f84887f6d
commit 132e3508cf
21 changed files with 474 additions and 547 deletions

Binary file not shown.

View File

@ -12,122 +12,107 @@
constexpr auto VIDXRES = WINDOWW; constexpr auto VIDXRES = WINDOWW;
// constexpr auto VIDYRES = WINDOWH; // not actually used anywhere // constexpr auto VIDYRES = WINDOWH; // not actually used anywhere
VideoBuffer * Renderer::WallIcon(int wallID, int width, int height) std::unique_ptr<VideoBuffer> Renderer::WallIcon(int wallID, Vec2<int> size)
{ {
static std::vector<wall_type> Renderer_wtypes = LoadWalls(); auto wtypes = LoadWalls();
int i, j; if (wallID < 0 || wallID >= int(wtypes.size()))
int wt = wallID; return nullptr;
if (wt<0 || wt>=(int)Renderer_wtypes.size()) wall_type const &wtype = wtypes[wallID];
return 0;
wall_type *wtypes = Renderer_wtypes.data(); RGB<uint8_t> primary = RGB<uint8_t>::Unpack(wtype.colour);
pixel pc = wtypes[wt].colour; RGB<uint8_t> secondary = RGB<uint8_t>::Unpack(wtype.eglow);
pixel gc = wtypes[wt].eglow;
VideoBuffer * newTexture = new VideoBuffer(width, height); auto texture = std::make_unique<VideoBuffer>(size);
if (wtypes[wt].drawstyle==1) switch (wtype.drawstyle)
{ {
for (j=0; j<height; j+=2) case 1:
for (i=(j>>1)&1; i<width; i+=2) // #.#.
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); // ....
} // .#.#
else if (wtypes[wt].drawstyle==2) // ....
{ for (auto pos : size.OriginRect())
for (j=0; j<height; j+=2) if (~pos.Y & ~(pos.X ^ (pos.Y >> 1)) & 1)
for (i=0; i<width; i+=2) texture->DrawPixel(pos, primary);
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); break;
} case 2:
else if (wtypes[wt].drawstyle==3) // #.#.
{ // ....
for (j=0; j<height; j++) // #.#.
for (i=0; i<width; i++) // ....
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); for (auto pos : size.OriginRect())
} if (~pos.Y & ~pos.X & 1)
else if (wtypes[wt].drawstyle==4) texture->DrawPixel(pos, primary);
{ break;
for (j=0; j<height; j++) case 3:
for (i=0; i<width; i++) // ####
if(i%CELL == j%CELL) // ####
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); // ####
else if (i%CELL == (j%CELL)+1 || (i%CELL == 0 && j%CELL == CELL-1)) // ####
newTexture->SetPixel(i, j, PIXR(gc), PIXG(gc), PIXB(gc), 255); for (auto pos : size.OriginRect())
texture->DrawPixel(pos, primary);
break;
case 4:
// #+.#
// .#+.
// +.#+
// #+.#
for (auto pos : size.OriginRect())
if (((pos.X - pos.Y) % CELL + CELL) % CELL == 0)
texture->DrawPixel(pos, primary);
else if (((pos.X - pos.Y) % CELL + CELL) % CELL == 1)
texture->DrawPixel(pos, secondary);
else else
newTexture->SetPixel(i, j, 0x20, 0x20, 0x20, 255); texture->DrawPixel(pos, 0x202020_rgb);
break;
} }
// special rendering for some walls switch (wallID)
if (wt==WL_EWALL)
{ {
for (j=0; j<height; j++) case WL_EWALL:
{ // ##### .......
for (i=0; i<(width/4)+j; i++) // #.#.#. ...#.#
{ // ####### .....
if (!(i&j&1)) // #.#.#.#. .#.#
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); for (auto pos : size.OriginRect())
} if ((pos.X < size.X / 4 + pos.Y) != (pos.X & pos.Y & 1))
for (; i<width; i++) texture->DrawPixel(pos, primary);
{ break;
if (i&j&1) case WL_WALLELEC:
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); // #+#+
} // ++++
} // #+#+
} // ++++
else if (wt==WL_WALLELEC) for (auto pos : size.OriginRect())
{ if (~pos.Y & ~pos.X & 1)
for (j=0; j<height; j++) texture->DrawPixel(pos, primary);
for (i=0; i<width; i++)
{
if (!(j%2) && !(i%2))
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255);
else else
newTexture->SetPixel(i, j, 0x80, 0x80, 0x80, 255); texture->DrawPixel(pos, 0x808080_rgb);
} break;
} case WL_EHOLE:
else if (wt==WL_EHOLE || wt==WL_STASIS) case WL_STASIS:
{ // ..... #######
for (j=0; j<height; j++) // .#.#.# ###.#.
{ // ....... #####
for (i=0; i<(width/4)+j; i++) // .#.#.#.# #.#.
{ for (auto pos : size.OriginRect())
if (i&j&1) if ((pos.X < size.X / 4 + pos.Y) == (pos.X & pos.Y & 1))
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); texture->DrawPixel(pos, primary);
} break;
for (; i<width; i++) case WL_ERASE:
{ // #.#.#. ######
if (!(i&j&1)) // ...... ######
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); // .#.#.# ######
} // ...... ######
} for (auto pos : size.OriginRect())
} if ((pos.X < size.X / 2) ? ~pos.Y & ~(pos.X ^ (pos.Y >> 1)) & 1 : true)
else if (wt == WL_ERASE) texture->DrawPixel(pos, primary);
{ texture->BlendChar(size / 2 - Vec2(4, 2), 0xE06C, 0xFF0000_rgb .WithAlpha(0xFF));
for (j=0; j<height; j+=2) break;
{ case WL_ERASEALL:
for (i=1+(1&(j>>1)); i<width/2; i+=2)
{
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255);
}
}
for (j=0; j<height; j++)
{
for (i=width/2; i<width; i++)
{
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255);
}
}
for (j=3; j<(width-4)/2; j++)
{
newTexture->SetPixel(j+6, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(j+7, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(-j+19, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(-j+20, j, 0xFF, 0, 0, 255);
}
}
else if (wt == WL_ERASEALL)
{
for (int j = 0; j < height; j++)
{ {
int r = 100, g = 150, b = 50; int r = 100, g = 150, b = 50;
int rd = 1, gd = -1, bd = -1; int rd = 1, gd = -1, bd = -1;
for (int i = 0; i < width; i++) for (int x = 0; x < size.X; x++)
{ {
r += 15 * rd; r += 15 * rd;
g += 15 * gd; g += 15 * gd;
@ -141,39 +126,19 @@ VideoBuffer * Renderer::WallIcon(int wallID, int width, int height)
int rc = std::min(150, std::max(0, r)); int rc = std::min(150, std::max(0, r));
int gc = std::min(200, std::max(0, g)); int gc = std::min(200, std::max(0, g));
int bc = std::min(200, std::max(0, b)); int bc = std::min(200, std::max(0, b));
newTexture->SetPixel(i, j, rc, gc, bc, 255); texture->DrawLine(Vec2(x, 0), Vec2(x, size.Y - 1), RGB<uint8_t>(rc, gc, bc));
} }
texture->BlendChar(size / 2 - Vec2(10, 2), 0xE06C, 0xFF0000_rgb .WithAlpha(0xFF));
texture->BlendChar(size / 2 - Vec2(-1, 2), 0xE06C, 0xFF0000_rgb .WithAlpha(0xFF));
} }
for (int j = 3; j < (width-4)/2; j++) break;
{ case WL_STREAM:
newTexture->SetPixel(j+0, j, 0xFF, 0, 0, 255); texture->DrawRect(size.OriginRect(), 0xA0A0A0_rgb);
newTexture->SetPixel(j+1, j, 0xFF, 0, 0, 255); texture->AddChar(Vec2(4, 2), 0xE00D, 0xFFFFFF_rgb .WithAlpha(0xFF));
newTexture->SetPixel(-j+13, j, 0xFF, 0, 0, 255); texture->AddChar(Vec2(8, 2), 0xE06D, 0xFFFFFF_rgb .WithAlpha(0xFF));
newTexture->SetPixel(-j+14, j, 0xFF, 0, 0, 255); break;
newTexture->SetPixel(j+11, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(j+12, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(-j+24, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(-j+25, j, 0xFF, 0, 0, 255);
} }
} return texture;
else if(wt == WL_STREAM)
{
for (j=0; j<height; j++)
{
for (i=0; i<width; i++)
{
pc = i==0||i==width-1||j==0||j==height-1 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255);
}
}
newTexture->AddCharacter(4, 2, 0xE00D, 255, 255, 255, 255);
for (i=width/3; i<width; i++)
{
newTexture->SetPixel(i, 7+(int)(3.9f*cos(i*0.3f)), 255, 255, 255, 255);
}
}
return newTexture;
} }
void Renderer::DrawSigns() void Renderer::DrawSigns()

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array> #include <array>
#include <memory>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include "Graphics.h" #include "Graphics.h"
@ -142,7 +143,7 @@ public:
int GetGridSize() { return gridSize; } int GetGridSize() { return gridSize; }
void SetGridSize(int value) { gridSize = value; } void SetGridSize(int value) { gridSize = value; }
static VideoBuffer * WallIcon(int wallID, int width, int height); static std::unique_ptr<VideoBuffer> WallIcon(int wallID, Vec2<int> size);
Renderer(Simulation * sim); Renderer(Simulation * sim);
~Renderer(); ~Renderer();

View File

@ -127,9 +127,9 @@ void ElementSearchActivity::searchTools(String query)
for (int toolIndex = 0; toolIndex < (int)tools.size(); ++toolIndex) for (int toolIndex = 0; toolIndex < (int)tools.size(); ++toolIndex)
{ {
int favouritePriority = favs.find(tools[toolIndex]->GetIdentifier()) != favs.end() ? 0 : 1; int favouritePriority = favs.find(tools[toolIndex]->Identifier) != favs.end() ? 0 : 1;
pushIfMatches(tools[toolIndex]->GetName().ToLower(), toolIndex, favouritePriority, 0); pushIfMatches(tools[toolIndex]->Name.ToLower(), toolIndex, favouritePriority, 0);
pushIfMatches(tools[toolIndex]->GetDescription().ToLower(), toolIndex, favouritePriority, 1); pushIfMatches(tools[toolIndex]->Description.ToLower(), toolIndex, favouritePriority, 1);
auto it = menudescriptionLower.find(tools[toolIndex]); auto it = menudescriptionLower.find(tools[toolIndex]);
if (it != menudescriptionLower.end()) if (it != menudescriptionLower.end())
{ {
@ -149,16 +149,16 @@ void ElementSearchActivity::searchTools(String query)
if(!firstResult) if(!firstResult)
firstResult = tool; firstResult = tool;
VideoBuffer * tempTexture = tool->GetTexture(26, 14); std::unique_ptr<VideoBuffer> tempTexture = tool->GetTexture(Vec2(26, 14));
ToolButton * tempButton; ToolButton * tempButton;
if(tempTexture) if(tempTexture)
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->GetIdentifier(), tool->GetDescription()); tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->Identifier, tool->Description);
else else
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName(), tool->GetIdentifier(), tool->GetDescription()); tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->Name, tool->Identifier, tool->Description);
tempButton->Appearance.SetTexture(tempTexture); tempButton->Appearance.SetTexture(tempTexture.get());
tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue); tempButton->Appearance.BackgroundInactive = tool->Colour.WithAlpha(0xFF);
tempButton->SetActionCallback({ [this, tempButton, tool] { tempButton->SetActionCallback({ [this, tempButton, tool] {
if (tempButton->GetSelectionState() >= 0 && tempButton->GetSelectionState() <= 2) if (tempButton->GetSelectionState() >= 0 && tempButton->GetSelectionState() <= 2)
SetActiveTool(tempButton->GetSelectionState(), tool); SetActiveTool(tempButton->GetSelectionState(), tool);
@ -196,11 +196,11 @@ void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
{ {
if (ctrlPressed && shiftPressed && !altPressed) if (ctrlPressed && shiftPressed && !altPressed)
{ {
Favorite::Ref().AddFavorite(tool->GetIdentifier()); Favorite::Ref().AddFavorite(tool->Identifier);
gameController->RebuildFavoritesMenu(); gameController->RebuildFavoritesMenu();
} }
else if (ctrlPressed && altPressed && !shiftPressed && else if (ctrlPressed && altPressed && !shiftPressed &&
tool->GetIdentifier().Contains("DEFAULT_PT_")) tool->Identifier.BeginsWith("DEFAULT_PT_"))
{ {
gameController->SetActiveTool(3, tool); gameController->SetActiveTool(3, tool);
} }

View File

@ -5,84 +5,60 @@
#include "simulation/SimulationData.h" #include "simulation/SimulationData.h"
#include "simulation/Simulation.h" #include "simulation/Simulation.h"
VideoBuffer *DecorationTool::GetIcon(int toolID, int width, int height) std::unique_ptr<VideoBuffer> DecorationTool::GetIcon(int ToolID, Vec2<int> size)
{ {
VideoBuffer * newTexture = new VideoBuffer(width, height); auto texture = std::make_unique<VideoBuffer>(size);
for (int y=0; y<height; y++)
{ if (ToolID == DECO_SMUDGE)
for (int x=0; x<width; x++) for (auto pos : size.OriginRect())
{ texture->DrawPixel(pos, RGB<uint8_t>(0, 0xFF - 5 * pos.X, 5 * pos.X));
//if (toolID == DECO_LIGH) else if (ToolID == DECO_DRAW || ToolID == DECO_CLEAR)
// vid_buf[WINDOWW*(y+j)+(x+i)] = PIXRGB(PIXR(pc)-10*j, PIXG(pc)-10*j, PIXB(pc)-10*j); texture->BlendFilledRect(size.OriginRect(), Colour);
//else if (toolID == DECO_DARK)
// vid_buf[WINDOWW*(y+j)+(x+i)] = PIXRGB(PIXR(pc)+10*j, PIXG(pc)+10*j, PIXB(pc)+10*j);
if (toolID == DECO_SMUDGE)
newTexture->SetPixel(x, y, 0, 255-5*x, 5*x, 255);
else if (toolID == DECO_DRAW || toolID == DECO_CLEAR)
newTexture->SetPixel(x, y, Red, Green, Blue, Alpha);
else else
newTexture->SetPixel(x, y, 50, 50, 50, 255); texture->DrawFilledRect(size.OriginRect(), 0x323232_rgb);
}
}
if (toolID == DECO_CLEAR)
{
int reverseRed = (Red+127)%256;
int reverseGreen = (Green+127)%256;
int reverseBlue = (Blue+127)%256;
for (int y=4; y<12; y++)
{
newTexture->SetPixel(y+5, y-1, reverseRed, reverseGreen, reverseBlue, 255);
newTexture->SetPixel(y+6, y-1, reverseRed, reverseGreen, reverseBlue, 255);
newTexture->SetPixel(20-y, y-1, reverseRed, reverseGreen, reverseBlue, 255);
newTexture->SetPixel(21-y, y-1, reverseRed, reverseGreen, reverseBlue, 255);
}
}
else if (toolID == DECO_ADD)
newTexture->AddCharacter(11, 4, '+', Red, Green, Blue, 255);
else if (toolID == DECO_SUBTRACT)
newTexture->AddCharacter(11, 4, '-', Red, Green, Blue, 255);
else if (toolID == DECO_MULTIPLY)
newTexture->AddCharacter(11, 3, 'x', Red, Green, Blue, 255);
else if (toolID == DECO_DIVIDE)
newTexture->AddCharacter(11, 4, '/', Red, Green, Blue, 255);
return newTexture;
}
DecorationTool::DecorationTool(Renderer *ren_, int decoMode, String name, String description, int r, int g, int b, ByteString identifier): if (ToolID == DECO_CLEAR)
Tool(decoMode, name, description, r, g, b, identifier),
Red(0),
Green(0),
Blue(0),
Alpha(0),
ren(ren_)
{ {
auto reverse = RGB<uint8_t>(Colour.Red + 127, Colour.Green + 127, Colour.Blue + 127).WithAlpha(0xFF);
texture->BlendChar(size / 2 - Vec2(4, 2), 0xE06C, reverse);
} }
else
DecorationTool::~DecorationTool()
{ {
auto colour = Colour.NoAlpha().WithAlpha(0xFF);
if (ToolID == DECO_ADD)
texture->AddChar(Vec2(11, 4), '+', colour);
else if (ToolID == DECO_SUBTRACT)
texture->AddChar(Vec2(11, 4), '-', colour);
else if (ToolID == DECO_MULTIPLY)
texture->AddChar(Vec2(11, 3), 'x', colour);
else if (ToolID == DECO_DIVIDE)
texture->AddChar(Vec2(11, 4), '/', colour);
}
return texture;
} }
void DecorationTool::Draw(Simulation * sim, Brush const &brush, ui::Point position) void DecorationTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
{ {
sim->ApplyDecorationPoint(position.X, position.Y, Red, Green, Blue, Alpha, toolID, brush); sim->ApplyDecorationPoint(position.X, position.Y, Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha, ToolID, brush);
} }
void DecorationTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) void DecorationTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging)
{ {
sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, Red, Green, Blue, Alpha, toolID, brush); sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha, ToolID, brush);
} }
void DecorationTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) void DecorationTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2)
{ {
sim->ApplyDecorationBox(position1.X, position1.Y, position2.X, position2.Y, Red, Green, Blue, Alpha, toolID); sim->ApplyDecorationBox(position1.X, position1.Y, position2.X, position2.Y, Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha, ToolID);
} }
void DecorationTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) void DecorationTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position)
{ {
pixel loc = ren->vid[position.X+position.Y*WINDOWW]; pixel loc = ren.vid[position.X+position.Y*WINDOWW];
if (toolID == DECO_CLEAR) if (ToolID == DECO_CLEAR)
sim->ApplyDecorationFill(ren, position.X, position.Y, 0, 0, 0, 0, PIXR(loc), PIXG(loc), PIXB(loc)); // TODO: this is actually const-correct
sim->ApplyDecorationFill(const_cast<Renderer *>(&ren), position.X, position.Y, 0, 0, 0, 0, PIXR(loc), PIXG(loc), PIXB(loc));
else else
sim->ApplyDecorationFill(ren, position.X, position.Y, Red, Green, Blue, Alpha, PIXR(loc), PIXG(loc), PIXB(loc)); sim->ApplyDecorationFill(const_cast<Renderer *>(&ren), position.X, position.Y, Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha, PIXR(loc), PIXG(loc), PIXB(loc));
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <memory>
#include "Tool.h" #include "Tool.h"
#include "graphics/Graphics.h" #include "graphics/Graphics.h"
@ -6,16 +7,20 @@ class Renderer;
class DecorationTool: public Tool class DecorationTool: public Tool
{ {
public: public:
unsigned char Red; RGBA<uint8_t> Colour;
unsigned char Green; Renderer const &ren;
unsigned char Blue;
unsigned char Alpha;
Renderer *ren;
VideoBuffer * GetIcon(int toolID, int width, int height); std::unique_ptr<VideoBuffer> GetIcon(int toolID, Vec2<int> size);
DecorationTool(Renderer const &ren, int decoMode, String name, String description, RGB<uint8_t> colour, ByteString identifier):
Tool(decoMode, name, description, colour, identifier),
Colour(0x000000_rgb .WithAlpha(0x00)),
ren(ren)
{}
virtual ~DecorationTool()
{}
DecorationTool(Renderer *ren_, int decoMode, String name, String description, int r, int g, int b, ByteString identifier);
virtual ~DecorationTool();
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override; void Draw(Simulation * sim, Brush const &brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) override; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) override;
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override; void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;

View File

@ -19,28 +19,36 @@
class GOLWindow: public ui::Window class GOLWindow: public ui::Window
{ {
void UpdateGradient();
public:
ui::Colour highColour, lowColour; ui::Colour highColour, lowColour;
ui::Button *highColourButton, *lowColourButton; ui::Button *highColourButton, *lowColourButton;
ui::Textbox *nameField, *ruleField; ui::Textbox *nameField, *ruleField;
GameModel * gameModel; GameModel &gameModel;
Simulation *sim; Simulation *sim;
int toolSelection; int toolSelection;
GOLWindow(GameModel *gameModel, Simulation *sim, int toolSelection, int rule, int colour1, int colour2);
void Validate(); void updateGradient();
void validate();
public:
GOLWindow(GameModel &gameModel, Simulation *sim, int toolSelection, int rule, RGB<uint8_t> colour1, RGB<uint8_t> colour2);
virtual ~GOLWindow()
{}
void OnDraw() override; void OnDraw() override;
void OnTryExit(ExitMethod method) override; void OnTryExit(ExitMethod method) override;
virtual ~GOLWindow() {}
}; };
GOLWindow::GOLWindow(GameModel * gameModel_, Simulation *sim_, int toolSelection, int rule, int colour1, int colour2): GOLWindow::GOLWindow(GameModel &gameModel_, Simulation *sim_, int toolSelection, int rule, RGB<uint8_t> colour1, RGB<uint8_t> colour2):
ui::Window(ui::Point(-1, -1), ui::Point(200, 108)), ui::Window(ui::Point(-1, -1), ui::Point(200, 108)),
highColour(colour1.WithAlpha(0xFF)),
lowColour(colour2.WithAlpha(0xFF)),
gameModel(gameModel_), gameModel(gameModel_),
sim(sim_), sim(sim_),
toolSelection(toolSelection) toolSelection(toolSelection)
{ {
highColour.Alpha = 255;
lowColour.Alpha = 255;
ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit custom GOL type"); ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit custom GOL type");
messageLabel->SetTextColour(style::Colour::InformationTitle); messageLabel->SetTextColour(style::Colour::InformationTitle);
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
@ -55,7 +63,7 @@ toolSelection(toolSelection)
if (nameField->GetText().length() && ruleField->GetText().length()) if (nameField->GetText().length() && ruleField->GetText().length())
{ {
CloseActiveWindow(); CloseActiveWindow();
Validate(); validate();
SelfDestruct(); SelfDestruct();
} }
} }); } });
@ -79,7 +87,7 @@ toolSelection(toolSelection)
highColourButton->SetActionCallback({ [this] { highColourButton->SetActionCallback({ [this] {
new ColourPickerActivity(highColour, [this](ui::Colour colour) { new ColourPickerActivity(highColour, [this](ui::Colour colour) {
highColour = colour; highColour = colour;
UpdateGradient(); updateGradient();
}); });
} }); } });
AddComponent(highColourButton); AddComponent(highColourButton);
@ -88,7 +96,7 @@ toolSelection(toolSelection)
lowColourButton->SetActionCallback({ [this] { lowColourButton->SetActionCallback({ [this] {
new ColourPickerActivity(lowColour, [this](ui::Colour colour) { new ColourPickerActivity(lowColour, [this](ui::Colour colour) {
lowColour = colour; lowColour = colour;
UpdateGradient(); updateGradient();
}); });
} }); } });
AddComponent(lowColourButton); AddComponent(lowColourButton);
@ -97,12 +105,6 @@ toolSelection(toolSelection)
{ {
ruleField->SetText(SerialiseGOLRule(rule)); ruleField->SetText(SerialiseGOLRule(rule));
nameField->SetText(""); nameField->SetText("");
highColour.Red = PIXR(colour1);
highColour.Green = PIXG(colour1);
highColour.Blue = PIXB(colour1);
lowColour.Red = PIXR(colour2);
lowColour.Green = PIXG(colour2);
lowColour.Blue = PIXB(colour2);
} }
else else
{ {
@ -112,18 +114,18 @@ toolSelection(toolSelection)
highColour.Red = RNG::Ref().between(0x80, 0xFF); highColour.Red = RNG::Ref().between(0x80, 0xFF);
highColour.Green = RNG::Ref().between(0x80, 0xFF); highColour.Green = RNG::Ref().between(0x80, 0xFF);
highColour.Blue = RNG::Ref().between(0x80, 0xFF); highColour.Blue = RNG::Ref().between(0x80, 0xFF);
highColour.Alpha = 0xFF;
lowColour.Red = RNG::Ref().between(0x00, 0x7F); lowColour.Red = RNG::Ref().between(0x00, 0x7F);
lowColour.Green = RNG::Ref().between(0x00, 0x7F); lowColour.Green = RNG::Ref().between(0x00, 0x7F);
lowColour.Blue = RNG::Ref().between(0x00, 0x7F); lowColour.Blue = RNG::Ref().between(0x00, 0x7F);
lowColour.Alpha = 0xFF;
} }
highColour.Alpha = 255; updateGradient();
lowColour.Alpha = 255;
UpdateGradient();
MakeActiveWindow(); MakeActiveWindow();
} }
void GOLWindow::UpdateGradient() void GOLWindow::updateGradient()
{ {
highColourButton->Appearance.BackgroundInactive = highColour; highColourButton->Appearance.BackgroundInactive = highColour;
highColourButton->Appearance.BackgroundHover = highColour; highColourButton->Appearance.BackgroundHover = highColour;
@ -131,7 +133,7 @@ void GOLWindow::UpdateGradient()
lowColourButton->Appearance.BackgroundHover = lowColour; lowColourButton->Appearance.BackgroundHover = lowColour;
} }
void GOLWindow::Validate() void GOLWindow::validate()
{ {
auto nameString = nameField->GetText(); auto nameString = nameField->GetText();
auto ruleString = ruleField->GetText(); auto ruleString = ruleField->GetText();
@ -169,8 +171,8 @@ void GOLWindow::Validate()
return; return;
} }
gameModel->SelectNextIdentifier = "DEFAULT_PT_LIFECUST_" + nameString.ToAscii(); gameModel.SelectNextIdentifier = "DEFAULT_PT_LIFECUST_" + nameString.ToAscii();
gameModel->SelectNextTool = toolSelection; gameModel.SelectNextTool = toolSelection;
} }
void GOLWindow::OnTryExit(ExitMethod method) void GOLWindow::OnTryExit(ExitMethod method)
@ -200,7 +202,7 @@ void GOLWindow::OnDraw()
} }
} }
void GOLTool::OpenWindow(Simulation *sim, int toolSelection, int rule, int colour1, int colour2) void GOLTool::OpenWindow(Simulation *sim, int toolSelection, int rule, RGB<uint8_t> colour1, RGB<uint8_t> colour2)
{ {
new GOLWindow(gameModel, sim, toolSelection, rule, colour1, colour2); new GOLWindow(gameModel, sim, toolSelection, rule, colour1, colour2);
} }

View File

@ -360,7 +360,7 @@ void GameController::DrawRect(int toolSelection, ui::Point point1, ui::Point poi
Brush &cBrush = gameModel->GetBrush(); Brush &cBrush = gameModel->GetBrush();
if (!activeTool) if (!activeTool)
return; return;
activeTool->SetStrength(1.0f); activeTool->Strength = 1.0f;
activeTool->DrawRect(sim, cBrush, point1, point2); activeTool->DrawRect(sim, cBrush, point1, point2);
} }
@ -372,7 +372,7 @@ void GameController::DrawLine(int toolSelection, ui::Point point1, ui::Point poi
Brush &cBrush = gameModel->GetBrush(); Brush &cBrush = gameModel->GetBrush();
if (!activeTool) if (!activeTool)
return; return;
activeTool->SetStrength(1.0f); activeTool->Strength = 1.0f;
activeTool->DrawLine(sim, cBrush, point1, point2); activeTool->DrawLine(sim, cBrush, point1, point2);
} }
@ -384,7 +384,7 @@ void GameController::DrawFill(int toolSelection, ui::Point point)
Brush &cBrush = gameModel->GetBrush(); Brush &cBrush = gameModel->GetBrush();
if (!activeTool) if (!activeTool)
return; return;
activeTool->SetStrength(1.0f); activeTool->Strength = 1.0f;
activeTool->DrawFill(sim, cBrush, point); activeTool->DrawFill(sim, cBrush, point);
} }
@ -399,7 +399,7 @@ void GameController::DrawPoints(int toolSelection, ui::Point oldPos, ui::Point n
return; return;
} }
activeTool->SetStrength(gameModel->GetToolStrength()); activeTool->Strength = gameModel->GetToolStrength();
if (!held) if (!held)
activeTool->Draw(sim, cBrush, newPos); activeTool->Draw(sim, cBrush, newPos);
else else
@ -503,7 +503,7 @@ bool GameController::MouseDown(int x, int y, unsigned button)
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)->Identifier != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
{ {
foundSignID = GetSignAt(x, y); foundSignID = GetSignAt(x, y);
if (foundSignID != -1) if (foundSignID != -1)
@ -528,7 +528,7 @@ bool GameController::MouseUp(int x, int y, unsigned button, MouseupReason reason
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)->Identifier != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
{ {
int foundSignID = GetSignAt(x, y); int foundSignID = GetSignAt(x, y);
if (foundSignID != -1) if (foundSignID != -1)
@ -872,9 +872,9 @@ void GameController::Update()
{ {
int rightSelected = PT_DUST; int rightSelected = PT_DUST;
Tool * activeTool = gameModel->GetActiveTool(1); Tool * activeTool = gameModel->GetActiveTool(1);
if (activeTool->GetIdentifier().BeginsWith("DEFAULT_PT_")) if (activeTool->Identifier.BeginsWith("DEFAULT_PT_"))
{ {
int sr = activeTool->GetToolID(); int sr = activeTool->ToolID;
if (sr && sim->IsElementOrNone(sr)) if (sr && sim->IsElementOrNone(sr))
rightSelected = sr; rightSelected = sr;
} }
@ -1069,16 +1069,16 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool)
gameModel->SetActiveTool(toolSelection, tool); gameModel->SetActiveTool(toolSelection, tool);
gameModel->GetRenderer()->gravityZonesEnabled = false; gameModel->GetRenderer()->gravityZonesEnabled = false;
if (toolSelection == 3) if (toolSelection == 3)
gameModel->GetSimulation()->replaceModeSelected = tool->GetToolID(); gameModel->GetSimulation()->replaceModeSelected = tool->ToolID;
gameModel->SetLastTool(tool); gameModel->SetLastTool(tool);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
if(gameModel->GetActiveTool(i) == gameModel->GetMenuList().at(SC_WALL)->GetToolList().at(WL_GRAV)) if(gameModel->GetActiveTool(i) == gameModel->GetMenuList().at(SC_WALL)->GetToolList().at(WL_GRAV))
gameModel->GetRenderer()->gravityZonesEnabled = true; gameModel->GetRenderer()->gravityZonesEnabled = true;
} }
if(tool->GetIdentifier() == "DEFAULT_UI_PROPERTY") if(tool->Identifier == "DEFAULT_UI_PROPERTY")
((PropertyTool *)tool)->OpenWindow(gameModel->GetSimulation()); ((PropertyTool *)tool)->OpenWindow(gameModel->GetSimulation());
if(tool->GetIdentifier() == "DEFAULT_UI_ADDLIFE") if(tool->Identifier == "DEFAULT_UI_ADDLIFE")
{ {
((GOLTool *)tool)->OpenWindow(gameModel->GetSimulation(), toolSelection); ((GOLTool *)tool)->OpenWindow(gameModel->GetSimulation(), toolSelection);
} }

View File

@ -231,13 +231,13 @@ void GameModel::BuildMenus()
ByteString activeToolIdentifiers[4]; ByteString activeToolIdentifiers[4];
if(regularToolset[0]) if(regularToolset[0])
activeToolIdentifiers[0] = regularToolset[0]->GetIdentifier(); activeToolIdentifiers[0] = regularToolset[0]->Identifier;
if(regularToolset[1]) if(regularToolset[1])
activeToolIdentifiers[1] = regularToolset[1]->GetIdentifier(); activeToolIdentifiers[1] = regularToolset[1]->Identifier;
if(regularToolset[2]) if(regularToolset[2])
activeToolIdentifiers[2] = regularToolset[2]->GetIdentifier(); activeToolIdentifiers[2] = regularToolset[2]->Identifier;
if(regularToolset[3]) if(regularToolset[3])
activeToolIdentifiers[3] = regularToolset[3]->GetIdentifier(); activeToolIdentifiers[3] = regularToolset[3]->Identifier;
//Empty current menus //Empty current menus
for (size_t i = 0; i < menuList.size(); i++) for (size_t i = 0; i < menuList.size(); i++)
@ -270,19 +270,19 @@ void GameModel::BuildMenus()
Tool * tempTool; Tool * tempTool;
if(i == PT_LIGH) if(i == PT_LIGH)
{ {
tempTool = new Element_LIGH_Tool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator); tempTool = new Element_LIGH_Tool(i, sim->elements[i].Name, sim->elements[i].Description, RGB<uint8_t>::Unpack(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator);
} }
else if(i == PT_TESC) else if(i == PT_TESC)
{ {
tempTool = new Element_TESC_Tool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator); tempTool = new Element_TESC_Tool(i, sim->elements[i].Name, sim->elements[i].Description, RGB<uint8_t>::Unpack(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator);
} }
else if(i == PT_STKM || i == PT_FIGH || i == PT_STKM2) else if(i == PT_STKM || i == PT_FIGH || i == PT_STKM2)
{ {
tempTool = new PlopTool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator); tempTool = new PlopTool(i, sim->elements[i].Name, sim->elements[i].Description, RGB<uint8_t>::Unpack(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator);
} }
else else
{ {
tempTool = new ElementTool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator); tempTool = new ElementTool(i, sim->elements[i].Name, sim->elements[i].Description, RGB<uint8_t>::Unpack(sim->elements[i].Colour), sim->elements[i].Identifier, sim->elements[i].IconGenerator);
} }
if (sim->elements[i].MenuSection >= 0 && sim->elements[i].MenuSection < SC_TOTAL && sim->elements[i].MenuVisible) if (sim->elements[i].MenuSection >= 0 && sim->elements[i].MenuSection < SC_TOTAL && sim->elements[i].MenuVisible)
@ -300,7 +300,7 @@ void GameModel::BuildMenus()
//Build menu for GOL types //Build menu for GOL types
for(int i = 0; i < NGOL; i++) for(int i = 0; i < NGOL; i++)
{ {
Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), builtinGol[i].name, builtinGol[i].description, PIXR(builtinGol[i].colour), PIXG(builtinGol[i].colour), PIXB(builtinGol[i].colour), "DEFAULT_PT_LIFE_"+builtinGol[i].name.ToAscii()); Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), builtinGol[i].name, builtinGol[i].description, RGB<uint8_t>::Unpack(builtinGol[i].colour), "DEFAULT_PT_LIFE_"+builtinGol[i].name.ToAscii());
menuList[SC_LIFE]->AddTool(tempTool); menuList[SC_LIFE]->AddTool(tempTool);
} }
{ {
@ -353,7 +353,7 @@ void GameModel::BuildMenus()
} }
for (auto &gd : newCustomGol) for (auto &gd : newCustomGol)
{ {
Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(gd.rule), gd.nameString, "Custom GOL type: " + gd.ruleString, PIXR(gd.colour1), PIXG(gd.colour1), PIXB(gd.colour1), "DEFAULT_PT_LIFECUST_"+gd.nameString.ToAscii(), NULL); Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(gd.rule), gd.nameString, "Custom GOL type: " + gd.ruleString, RGB<uint8_t>::Unpack(gd.colour1), "DEFAULT_PT_LIFECUST_"+gd.nameString.ToAscii(), NULL);
menuList[SC_LIFE]->AddTool(tempTool); menuList[SC_LIFE]->AddTool(tempTool);
} }
sim->SetCustomGOL(newCustomGol); sim->SetCustomGOL(newCustomGol);
@ -362,7 +362,7 @@ void GameModel::BuildMenus()
//Build other menus from wall data //Build other menus from wall data
for(int i = 0; i < UI_WALLCOUNT; i++) for(int i = 0; i < UI_WALLCOUNT; i++)
{ {
Tool * tempTool = new WallTool(i, "", sim->wtypes[i].descs, PIXR(sim->wtypes[i].colour), PIXG(sim->wtypes[i].colour), PIXB(sim->wtypes[i].colour), sim->wtypes[i].identifier, sim->wtypes[i].textureGen); Tool * tempTool = new WallTool(i, sim->wtypes[i].descs, RGB<uint8_t>::Unpack(sim->wtypes[i].colour), sim->wtypes[i].identifier, sim->wtypes[i].textureGen);
menuList[SC_WALL]->AddTool(tempTool); menuList[SC_WALL]->AddTool(tempTool);
//sim->wtypes[i] //sim->wtypes[i]
} }
@ -374,28 +374,26 @@ void GameModel::BuildMenus()
i, i,
sim->tools[i].Name, sim->tools[i].Name,
sim->tools[i].Description, sim->tools[i].Description,
PIXR(sim->tools[i].Colour), RGB<uint8_t>::Unpack(sim->tools[i].Colour),
PIXG(sim->tools[i].Colour),
PIXB(sim->tools[i].Colour),
sim->tools[i].Identifier sim->tools[i].Identifier
); );
menuList[SC_TOOL]->AddTool(tempTool); menuList[SC_TOOL]->AddTool(tempTool);
} }
//Add special sign and prop tools //Add special sign and prop tools
menuList[SC_TOOL]->AddTool(new WindTool(0, "WIND", "Creates air movement.", 64, 64, 64, "DEFAULT_UI_WIND")); menuList[SC_TOOL]->AddTool(new WindTool());
menuList[SC_TOOL]->AddTool(new PropertyTool(this)); menuList[SC_TOOL]->AddTool(new PropertyTool(*this));
menuList[SC_TOOL]->AddTool(new SignTool(this)); menuList[SC_TOOL]->AddTool(new SignTool(*this));
menuList[SC_TOOL]->AddTool(new SampleTool(this)); menuList[SC_TOOL]->AddTool(new SampleTool(*this));
menuList[SC_LIFE]->AddTool(new GOLTool(this)); menuList[SC_LIFE]->AddTool(new GOLTool(*this));
//Add decoration tools to menu //Add decoration tools to menu
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_ADD, "ADD", "Colour blending: Add.", 0, 0, 0, "DEFAULT_DECOR_ADD")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_ADD, "ADD", "Colour blending: Add.", 0x000000_rgb, "DEFAULT_DECOR_ADD"));
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_SUBTRACT, "SUB", "Colour blending: Subtract.", 0, 0, 0, "DEFAULT_DECOR_SUB")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_SUBTRACT, "SUB", "Colour blending: Subtract.", 0x000000_rgb, "DEFAULT_DECOR_SUB"));
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_MULTIPLY, "MUL", "Colour blending: Multiply.", 0, 0, 0, "DEFAULT_DECOR_MUL")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_MULTIPLY, "MUL", "Colour blending: Multiply.", 0x000000_rgb, "DEFAULT_DECOR_MUL"));
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_DIVIDE, "DIV", "Colour blending: Divide." , 0, 0, 0, "DEFAULT_DECOR_DIV")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_DIVIDE, "DIV", "Colour blending: Divide." , 0x000000_rgb, "DEFAULT_DECOR_DIV"));
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_SMUDGE, "SMDG", "Smudge tool, blends surrounding deco together.", 0, 0, 0, "DEFAULT_DECOR_SMDG")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_SMUDGE, "SMDG", "Smudge tool, blends surrounding deco together.", 0x000000_rgb, "DEFAULT_DECOR_SMDG"));
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_CLEAR, "CLR", "Erase any set decoration.", 0, 0, 0, "DEFAULT_DECOR_CLR")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_CLEAR, "CLR", "Erase any set decoration.", 0x000000_rgb, "DEFAULT_DECOR_CLR"));
menuList[SC_DECO]->AddTool(new DecorationTool(ren, DECO_DRAW, "SET", "Draw decoration (No blending).", 0, 0, 0, "DEFAULT_DECOR_SET")); menuList[SC_DECO]->AddTool(new DecorationTool(*ren, DECO_DRAW, "SET", "Draw decoration (No blending).", 0x000000_rgb, "DEFAULT_DECOR_SET"));
SetColourSelectorColour(colour); // update tool colors SetColourSelectorColour(colour); // update tool colors
decoToolset[0] = GetToolFromIdentifier("DEFAULT_DECOR_SET"); decoToolset[0] = GetToolFromIdentifier("DEFAULT_DECOR_SET");
decoToolset[1] = GetToolFromIdentifier("DEFAULT_DECOR_CLR"); decoToolset[1] = GetToolFromIdentifier("DEFAULT_DECOR_CLR");
@ -499,7 +497,7 @@ Tool *GameModel::GetToolFromIdentifier(ByteString const &identifier)
{ {
for (auto *tool : menu->GetToolList()) for (auto *tool : menu->GetToolList())
{ {
if (identifier == tool->GetIdentifier()) if (identifier == tool->Identifier)
{ {
return tool; return tool;
} }
@ -507,7 +505,7 @@ Tool *GameModel::GetToolFromIdentifier(ByteString const &identifier)
} }
for (auto *extra : extraElementTools) for (auto *extra : extraElementTools)
{ {
if (identifier == extra->GetIdentifier()) if (identifier == extra->Identifier)
{ {
return extra; return extra;
} }
@ -904,7 +902,7 @@ Tool * GameModel::GetElementTool(int elementID)
{ {
for(std::vector<Tool*>::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter) for(std::vector<Tool*>::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter)
{ {
if((*iter)->GetToolID() == elementID) if((*iter)->ToolID == elementID)
return *iter; return *iter;
} }
return NULL; return NULL;
@ -1208,13 +1206,8 @@ void GameModel::SetColourSelectorColour(ui::Colour colour_)
colour = colour_; colour = colour_;
std::vector<Tool*> tools = GetMenuList()[SC_DECO]->GetToolList(); std::vector<Tool*> tools = GetMenuList()[SC_DECO]->GetToolList();
for (size_t i = 0; i < tools.size(); i++) for (auto tool : tools)
{ static_cast<DecorationTool *>(tool)->Colour = colour;
((DecorationTool*)tools[i])->Red = colour.Red;
((DecorationTool*)tools[i])->Green = colour.Green;
((DecorationTool*)tools[i])->Blue = colour.Blue;
((DecorationTool*)tools[i])->Alpha = colour.Alpha;
}
notifyColourSelectorColourChanged(); notifyColourSelectorColourChanged();
} }

View File

@ -518,15 +518,15 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender)
toolButtons[i]->SetSelectionState(-1); toolButtons[i]->SetSelectionState(-1);
} }
decoBrush = sender->GetActiveTool(0)->GetIdentifier().BeginsWith("DEFAULT_DECOR_"); decoBrush = sender->GetActiveTool(0)->Identifier.BeginsWith("DEFAULT_DECOR_");
if (sender->GetRenderer()->findingElement) if (sender->GetRenderer()->findingElement)
{ {
Tool *active = sender->GetActiveTool(0); Tool *active = sender->GetActiveTool(0);
if (!active->GetIdentifier().Contains("_PT_")) if (!active->Identifier.Contains("_PT_"))
ren->findingElement = 0; ren->findingElement = 0;
else else
ren->findingElement = sender->GetActiveTool(0)->GetToolID(); ren->findingElement = sender->GetActiveTool(0)->ToolID;
} }
} }
@ -534,8 +534,8 @@ void GameView::NotifyLastToolChanged(GameModel * sender)
{ {
if (sender->GetLastTool()) if (sender->GetLastTool())
{ {
wallBrush = sender->GetLastTool()->GetBlocky(); wallBrush = sender->GetLastTool()->Blocky;
toolBrush = sender->GetLastTool()->GetIdentifier().BeginsWith("DEFAULT_TOOL_"); toolBrush = sender->GetLastTool()->Identifier.BeginsWith("DEFAULT_TOOL_");
} }
} }
@ -563,17 +563,17 @@ void GameView::NotifyToolListChanged(GameModel * sender)
for (size_t i = 0; i < toolList.size(); i++) for (size_t i = 0; i < toolList.size(); i++)
{ {
auto *tool = toolList[i]; auto *tool = toolList[i];
VideoBuffer * tempTexture = tool->GetTexture(26, 14); auto tempTexture = tool->GetTexture(Vec2(26, 14));
ToolButton * tempButton; ToolButton * tempButton;
//get decotool texture manually, since it changes depending on it's own color //get decotool texture manually, since it changes depending on it's own color
if (sender->GetActiveMenu() == SC_DECO) if (sender->GetActiveMenu() == SC_DECO)
tempTexture = ((DecorationTool*)tool)->GetIcon(tool->GetToolID(), 26, 14); tempTexture = ((DecorationTool*)tool)->GetIcon(tool->ToolID, Vec2(26, 14));
if (tempTexture) if (tempTexture)
tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", tool->GetIdentifier(), tool->GetDescription()); tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", tool->Identifier, tool->Description);
else else
tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), tool->GetName(), tool->GetIdentifier(), tool->GetDescription()); tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), tool->Name, tool->Identifier, tool->Description);
tempButton->clipRectX = 1; tempButton->clipRectX = 1;
tempButton->clipRectY = YRES + 1; tempButton->clipRectY = YRES + 1;
@ -589,19 +589,19 @@ void GameView::NotifyToolListChanged(GameModel * sender)
{ {
if (tempButton->GetSelectionState() == 0) if (tempButton->GetSelectionState() == 0)
{ {
if (Favorite::Ref().IsFavorite(tool->GetIdentifier())) if (Favorite::Ref().IsFavorite(tool->Identifier))
{ {
Favorite::Ref().RemoveFavorite(tool->GetIdentifier()); Favorite::Ref().RemoveFavorite(tool->Identifier);
} }
else else
{ {
Favorite::Ref().AddFavorite(tool->GetIdentifier()); Favorite::Ref().AddFavorite(tool->Identifier);
} }
c->RebuildFavoritesMenu(); c->RebuildFavoritesMenu();
} }
else if (tempButton->GetSelectionState() == 1) else if (tempButton->GetSelectionState() == 1)
{ {
auto identifier = tool->GetIdentifier(); auto identifier = tool->Identifier;
if (Favorite::Ref().IsFavorite(identifier)) if (Favorite::Ref().IsFavorite(identifier))
{ {
Favorite::Ref().RemoveFavorite(identifier); Favorite::Ref().RemoveFavorite(identifier);
@ -620,7 +620,7 @@ void GameView::NotifyToolListChanged(GameModel * sender)
{ {
if (CtrlBehaviour() && AltBehaviour() && !ShiftBehaviour()) if (CtrlBehaviour() && AltBehaviour() && !ShiftBehaviour())
{ {
if (tool->GetIdentifier().Contains("_PT_")) if (tool->Identifier.Contains("_PT_"))
{ {
tempButton->SetSelectionState(3); tempButton->SetSelectionState(3);
} }
@ -631,10 +631,9 @@ void GameView::NotifyToolListChanged(GameModel * sender)
} }
} }); } });
tempButton->Appearance.SetTexture(tempTexture); tempButton->Appearance.SetTexture(tempTexture.get());
delete tempTexture;
tempButton->Appearance.BackgroundInactive = ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue); tempButton->Appearance.BackgroundInactive = toolList[i]->Colour.WithAlpha(0xFF);
if(sender->GetActiveTool(0) == toolList[i]) if(sender->GetActiveTool(0) == toolList[i])
{ {
@ -1156,8 +1155,8 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
return; return;
Tool *lastTool = c->GetActiveTool(toolIndex); Tool *lastTool = c->GetActiveTool(toolIndex);
c->SetLastTool(lastTool); c->SetLastTool(lastTool);
windTool = lastTool->GetIdentifier() == "DEFAULT_UI_WIND"; windTool = lastTool->Identifier == "DEFAULT_UI_WIND";
decoBrush = lastTool->GetIdentifier().BeginsWith("DEFAULT_DECOR_"); decoBrush = lastTool->Identifier.BeginsWith("DEFAULT_DECOR_");
UpdateDrawMode(); UpdateDrawMode();
@ -1435,10 +1434,10 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
if (ctrl) if (ctrl)
{ {
Tool *active = c->GetActiveTool(0); Tool *active = c->GetActiveTool(0);
if (!active->GetIdentifier().Contains("_PT_") || (ren->findingElement == active->GetToolID())) if (!active->Identifier.Contains("_PT_") || (ren->findingElement == active->ToolID))
ren->findingElement = 0; ren->findingElement = 0;
else else
ren->findingElement = active->GetToolID(); ren->findingElement = active->ToolID;
} }
else else
c->FrameStep(); c->FrameStep();

View File

@ -139,11 +139,11 @@ void PropertyWindow::SetProperty(bool warn)
v = sim->GetParticleType(value.ToUtf8()); v = sim->GetParticleType(value.ToUtf8());
if (v == -1) if (v == -1)
{ {
for (auto *elementTool : tool->gameModel->GetMenuList()[SC_LIFE]->GetToolList()) for (auto *elementTool : tool->gameModel.GetMenuList()[SC_LIFE]->GetToolList())
{ {
if (elementTool && elementTool->GetName() == value) if (elementTool && elementTool->Name == value)
{ {
v = ID(elementTool->GetToolID()); v = ID(elementTool->ToolID);
break; break;
} }
} }
@ -199,7 +199,7 @@ void PropertyWindow::SetProperty(bool warn)
case StructProperty::Float: case StructProperty::Float:
{ {
if (properties[property->GetOption().second].Name == "temp") if (properties[property->GetOption().second].Name == "temp")
tool->propValue.Float = format::StringToTemperature(value, tool->gameModel->GetTemperatureScale()); tool->propValue.Float = format::StringToTemperature(value, tool->gameModel.GetTemperatureScale());
else else
tool->propValue.Float = value.ToNumber<float>(); tool->propValue.Float = value.ToNumber<float>();
} }

View File

@ -11,30 +11,21 @@
#include "Menu.h" #include "Menu.h"
VideoBuffer * SampleTool::GetIcon(int toolID, int width, int height) std::unique_ptr<VideoBuffer> SampleTool::GetIcon(int toolID, Vec2<int> size)
{ {
VideoBuffer * newTexture = new VideoBuffer(width, height); auto texture = std::make_unique<VideoBuffer>(size);
for (int y=0; y<height; y++) texture->DrawRect(size.OriginRect(), 0xA0A0A0_rgb);
{ texture->BlendChar((size / 2) - Vec2(5, 5), 0xE066, 0xFFFFFF_rgb .WithAlpha(0xFF));
for (int x=0; x<width; x++) texture->BlendChar((size / 2) - Vec2(5, 5), 0xE06B, 0x64B4FF_rgb .WithAlpha(0xFF));
{ return texture;
pixel pc = x==0||x==width-1||y==0||y==height-1 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
newTexture->SetPixel(x, y, PIXR(pc), PIXG(pc), PIXB(pc), 255);
}
}
newTexture->AddCharacter((width/2)-5, (height/2)-5, 0xE066, 255, 255, 255, 255);
newTexture->BlendPixel(10, 9, 100, 180, 255, 255);
newTexture->BlendPixel(11, 8, 100, 180, 255, 255);
newTexture->BlendPixel(12, 7, 100, 180, 255, 255);
return newTexture;
} }
void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position) void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
{ {
if(gameModel->GetColourSelectorVisibility()) if(gameModel.GetColourSelectorVisibility())
{ {
pixel colour = gameModel->GetRenderer()->sampleColor; pixel colour = gameModel.GetRenderer()->sampleColor;
gameModel->SetColourSelectorColour(ui::Colour(PIXR(colour), PIXG(colour), PIXB(colour), 255)); gameModel.SetColourSelectorColour(RGB<uint8_t>::Unpack(colour).WithAlpha(0xFF));
} }
else else
{ {
@ -52,25 +43,24 @@ void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
if (part->type == PT_LIFE) if (part->type == PT_LIFE)
{ {
bool found = false; bool found = false;
for (auto *elementTool : gameModel->GetMenuList()[SC_LIFE]->GetToolList()) for (auto *elementTool : gameModel.GetMenuList()[SC_LIFE]->GetToolList())
{ {
if (elementTool && ID(elementTool->GetToolID()) == part->ctype) if (elementTool && ID(elementTool->ToolID) == part->ctype)
{ {
gameModel->SetActiveTool(0, elementTool); gameModel.SetActiveTool(0, elementTool);
found = true; found = true;
break; break;
} }
} }
if (!found) if (!found)
{ {
((GOLTool *)(gameModel->GetToolFromIdentifier("DEFAULT_UI_ADDLIFE")))->OpenWindow(gameModel->GetSimulation(), 0, part->ctype, part->dcolour, part->tmp); static_cast<GOLTool *>(gameModel.GetToolFromIdentifier("DEFAULT_UI_ADDLIFE"))->OpenWindow(gameModel.GetSimulation(), 0, part->ctype, RGB<uint8_t>::Unpack(part->dcolour & 0xFFFFFF), RGB<uint8_t>::Unpack(part->tmp & 0xFFFFFF));
} }
} }
else else
{ {
Tool * elementTool = gameModel->GetElementTool(part->type); if (auto elementTool = gameModel.GetElementTool(part->type))
if(elementTool) gameModel.SetActiveTool(0, elementTool);
gameModel->SetActiveTool(0, elementTool);
} }
} }
} }

View File

@ -197,7 +197,7 @@ void SignWindow::DoMouseMove(int x, int y, int dx, int dy) {
ui::Window::DoMouseMove(x, y, dx, dy); ui::Window::DoMouseMove(x, y, dx, dy);
else else
{ {
ui::Point pos = tool->gameModel->AdjustZoomCoords(ui::Point(x, y)); ui::Point pos = tool->gameModel.AdjustZoomCoords(ui::Point(x, y));
if(pos.X < XRES && pos.Y < YRES) if(pos.X < XRES && pos.Y < YRES)
{ {
movingSign->x = pos.X; movingSign->x = pos.X;
@ -226,20 +226,13 @@ void SignWindow::OnDraw()
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
} }
VideoBuffer * SignTool::GetIcon(int toolID, int width, int height) std::unique_ptr<VideoBuffer> SignTool::GetIcon(int toolID, Vec2<int> size)
{ {
VideoBuffer * newTexture = new VideoBuffer(width, height); auto texture = std::make_unique<VideoBuffer>(size);
for (int y=0; y<height; y++) texture->DrawRect(size.OriginRect(), 0xA0A0A0_rgb);
{ texture->BlendChar((size / 2) - Vec2(5, 5), 0xE021, 0x204080_rgb .WithAlpha(0xFF));
for (int x=0; x<width; x++) texture->BlendChar((size / 2) - Vec2(5, 5), 0xE020, 0xFFFFFF_rgb .WithAlpha(0xFF));
{ return texture;
pixel pc = x==0||x==width-1||y==0||y==height-1 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
newTexture->SetPixel(x, y, PIXR(pc), PIXG(pc), PIXB(pc), 255);
}
}
newTexture->AddCharacter((width/2)-5, (height/2)-5, 0xE021, 32, 64, 128, 255);
newTexture->BlendCharacter((width/2)-5, (height/2)-5, 0xE020, 255, 255, 255, 255);
return newTexture;
} }
void SignTool::Click(Simulation * sim, Brush const &brush, ui::Point position) void SignTool::Click(Simulation * sim, Brush const &brush, ui::Point position)

View File

@ -1,92 +1,56 @@
#include "Tool.h" #include "Tool.h"
#include "graphics/Graphics.h"
#include "gui/game/Brush.h" #include "gui/game/Brush.h"
#include "simulation/Simulation.h" #include "simulation/Simulation.h"
#include "simulation/SimulationData.h" #include "simulation/SimulationData.h"
#include "simulation/ElementClasses.h" #include "simulation/ElementClasses.h"
Tool::Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)): std::unique_ptr<VideoBuffer> Tool::GetTexture(Vec2<int> size)
textureGen(textureGen),
toolID(id),
toolName(name),
toolDescription(description),
strength(1.0f),
blocky(false),
identifier(identifier),
colRed(r),
colGreen(g),
colBlue(b)
{ {
return textureGen ? textureGen(ToolID, size) : nullptr;
} }
VideoBuffer * Tool::GetTexture(int width, int height)
{
if(textureGen)
{
return textureGen(toolID, width, height);
}
return NULL;
}
void Tool::SetTextureGen(VideoBuffer * (*textureGen)(int, int, int))
{
this->textureGen = textureGen;
}
ByteString Tool::GetIdentifier() { return identifier; }
String Tool::GetName() { return toolName; }
String Tool::GetDescription() { return toolDescription; }
Tool::~Tool() {}
void Tool::Click(Simulation * sim, Brush const &brush, ui::Point position) { } void Tool::Click(Simulation * sim, Brush const &brush, ui::Point position) { }
void Tool::Draw(Simulation * sim, Brush const &brush, ui::Point position) { void Tool::Draw(Simulation * sim, Brush const &brush, ui::Point position) {
sim->ToolBrush(position.X, position.Y, toolID, brush, strength); sim->ToolBrush(position.X, position.Y, ToolID, brush, Strength);
} }
void Tool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) { void Tool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) {
sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush, strength); sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, ToolID, brush, Strength);
} }
void Tool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) { void Tool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) {
sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, strength); sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, ToolID, Strength);
} }
void Tool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) {} void Tool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) {}
ElementTool::ElementTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
}
ElementTool::~ElementTool() {}
void ElementTool::Draw(Simulation * sim, Brush const &brush, ui::Point position){ void ElementTool::Draw(Simulation * sim, Brush const &brush, ui::Point position){
sim->CreateParts(position.X, position.Y, toolID, brush); sim->CreateParts(position.X, position.Y, ToolID, brush);
} }
void ElementTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) { void ElementTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) {
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, ToolID, brush);
} }
void ElementTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) { void ElementTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) {
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID); sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, ToolID);
} }
void ElementTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) { void ElementTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) {
sim->FloodParts(position.X, position.Y, toolID, -1); sim->FloodParts(position.X, position.Y, ToolID, -1);
} }
WallTool::WallTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
blocky = true;
}
WallTool::~WallTool() {}
void WallTool::Draw(Simulation * sim, Brush const &brush, ui::Point position) { void WallTool::Draw(Simulation * sim, Brush const &brush, ui::Point position) {
sim->CreateWalls(position.X, position.Y, 1, 1, toolID, &brush); sim->CreateWalls(position.X, position.Y, 1, 1, ToolID, &brush);
} }
void WallTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) { void WallTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) {
int wallX = position1.X/CELL; int wallX = position1.X/CELL;
int wallY = position1.Y/CELL; int wallY = position1.Y/CELL;
if(dragging == false && toolID == WL_FAN && sim->bmap[wallY][wallX]==WL_FAN) if(dragging == false && ToolID == WL_FAN && sim->bmap[wallY][wallX]==WL_FAN)
{ {
float newFanVelX = (position2.X-position1.X)*0.005f; float newFanVelX = (position2.X-position1.X)*0.005f;
newFanVelX *= strength; newFanVelX *= Strength;
float newFanVelY = (position2.Y-position1.Y)*0.005f; float newFanVelY = (position2.Y-position1.Y)*0.005f;
newFanVelY *= strength; newFanVelY *= Strength;
sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, WL_FAN); sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, WL_FAN);
for (int j = 0; j < YCELLS; j++) for (int j = 0; j < YCELLS; j++)
for (int i = 0; i < XCELLS; i++) for (int i = 0; i < XCELLS; i++)
@ -99,26 +63,21 @@ void WallTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position
} }
else else
{ {
sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, &brush); sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, ToolID, &brush);
} }
} }
void WallTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) { void WallTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) {
sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID); sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, ToolID);
} }
void WallTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) { void WallTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) {
if (toolID != WL_STREAM) if (ToolID != WL_STREAM)
sim->FloodWalls(position.X, position.Y, toolID, -1); sim->FloodWalls(position.X, position.Y, ToolID, -1);
}
WindTool::WindTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
} }
void WindTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging) void WindTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging)
{ {
float strength = dragging?0.01f:0.002f; float strength = dragging?0.01f:0.002f;
strength *= this->strength; strength *= this->Strength;
for (ui::Point off : brush) for (ui::Point off : brush)
{ {
@ -141,15 +100,15 @@ void Element_LIGH_Tool::DrawLine(Simulation * sim, Brush const &brush, ui::Point
void Element_TESC_Tool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) { void Element_TESC_Tool::DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) {
int radiusInfo = brush.GetRadius().X*4+brush.GetRadius().Y*4+7; int radiusInfo = brush.GetRadius().X*4+brush.GetRadius().Y*4+7;
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID | PMAPID(radiusInfo)); sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, ToolID | PMAPID(radiusInfo));
} }
void Element_TESC_Tool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) { void Element_TESC_Tool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) {
int radiusInfo = brush.GetRadius().X*4+brush.GetRadius().Y*4+7; int radiusInfo = brush.GetRadius().X*4+brush.GetRadius().Y*4+7;
sim->FloodParts(position.X, position.Y, toolID | PMAPID(radiusInfo), -1); sim->FloodParts(position.X, position.Y, ToolID | PMAPID(radiusInfo), -1);
} }
void PlopTool::Click(Simulation * sim, Brush const &brush, ui::Point position) void PlopTool::Click(Simulation * sim, Brush const &brush, ui::Point position)
{ {
sim->create_part(-2, position.X, position.Y, TYP(toolID), ID(toolID)); sim->create_part(-2, position.X, position.Y, TYP(ToolID), ID(ToolID));
} }

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
#include <memory>
#include "common/String.h" #include "common/String.h"
#include "common/Vec2.h"
#include "graphics/Pixel.h"
#include "gui/interface/Point.h" #include "gui/interface/Point.h"
#include "simulation/StructProperty.h" #include "simulation/StructProperty.h"
@ -9,28 +12,34 @@ class VideoBuffer;
class Tool class Tool
{ {
protected: private:
VideoBuffer * (*textureGen)(int, int, int); std::unique_ptr<VideoBuffer> (*const textureGen)(int, Vec2<int>);
int toolID;
String toolName;
String toolDescription;
float strength;
bool blocky;
ByteString identifier;
public:
int colRed, colGreen, colBlue;
Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL); public:
int GetToolID() { return toolID; } int const ToolID;
String GetName(); String const Name;
String GetDescription(); String const Description;
ByteString GetIdentifier(); ByteString const Identifier;
int GetBlocky() { return blocky; } RGB<uint8_t> const Colour;
void SetStrength(float value) { strength = value; } bool const Blocky;
float GetStrength() { return strength; } float Strength = 1.0f;
VideoBuffer * GetTexture(int width, int height);
void SetTextureGen(VideoBuffer * (*textureGen)(int, int, int)); Tool(int id, String name, String description,
virtual ~Tool(); RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL, bool blocky = false
):
textureGen(textureGen),
ToolID(id),
Name(name),
Description(description),
Identifier(identifier),
Colour(colour),
Blocky(blocky)
{}
virtual ~Tool()
{}
std::unique_ptr<VideoBuffer> GetTexture(Vec2<int>);
virtual void Click(Simulation * sim, Brush const &brush, ui::Point position); virtual void Click(Simulation * sim, Brush const &brush, ui::Point position);
virtual void Draw(Simulation * sim, Brush const &brush, ui::Point position); virtual void Draw(Simulation * sim, Brush const &brush, ui::Point position);
virtual void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false); virtual void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false);
@ -42,15 +51,22 @@ class GameModel;
class SignTool: public Tool class SignTool: public Tool
{ {
GameModel &gameModel;
friend class SignWindow;
public: public:
GameModel * gameModel; SignTool(GameModel &model):
SignTool(GameModel *model): Tool(0, "SIGN", "Sign. Displays text. Click on a sign to edit it or anywhere else to place a new one.",
Tool(0, "SIGN", "Sign. Displays text. Click on a sign to edit it or anywhere else to place a new one.", 0, 0, 0, "DEFAULT_UI_SIGN", SignTool::GetIcon), 0x000000_rgb, "DEFAULT_UI_SIGN", SignTool::GetIcon
),
gameModel(model) gameModel(model)
{ {}
}
static VideoBuffer * GetIcon(int toolID, int width, int height); virtual ~SignTool()
virtual ~SignTool() {} {}
static std::unique_ptr<VideoBuffer> GetIcon(int toolID, Vec2<int> size);
void Click(Simulation * sim, Brush const &brush, ui::Point position) override; void Click(Simulation * sim, Brush const &brush, ui::Point position) override;
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { } void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { }
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override { } void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override { }
@ -60,14 +76,17 @@ public:
class SampleTool: public Tool class SampleTool: public Tool
{ {
GameModel * gameModel; GameModel &gameModel;
public: public:
SampleTool(GameModel *model): SampleTool(GameModel &model):
Tool(0, "SMPL", "Sample an element on the screen.", 0, 0, 0, "DEFAULT_UI_SAMPLE", SampleTool::GetIcon), Tool(0, "SMPL", "Sample an element on the screen.",
0x000000_rgb, "DEFAULT_UI_SAMPLE", SampleTool::GetIcon
),
gameModel(model) gameModel(model)
{ {}
}
static VideoBuffer * GetIcon(int toolID, int width, int height); static std::unique_ptr<VideoBuffer> GetIcon(int toolID, Vec2<int> size);
virtual ~SampleTool() {} virtual ~SampleTool() {}
void Click(Simulation * sim, Brush const &brush, ui::Point position) override { } void Click(Simulation * sim, Brush const &brush, ui::Point position) override { }
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override; void Draw(Simulation * sim, Brush const &brush, ui::Point position) override;
@ -78,21 +97,27 @@ public:
class PropertyTool: public Tool class PropertyTool: public Tool
{ {
public: GameModel &gameModel;
GameModel * gameModel;
PropertyTool(GameModel *model):
Tool(0, "PROP", "Property Drawing Tool. Use to alter the properties of elements in the field.", 0xfe, 0xa9, 0x00, "DEFAULT_UI_PROPERTY", NULL),
gameModel(model)
{
}
StructProperty::PropertyType propType; StructProperty::PropertyType propType;
PropertyValue propValue; PropertyValue propValue;
bool changeType; bool changeType;
size_t propOffset; size_t propOffset;
bool validProperty; bool validProperty;
friend class PropertyWindow;
public:
PropertyTool(GameModel &model):
Tool(0, "PROP", "Property Drawing Tool. Use to alter the properties of elements in the field.",
0xFEA900_rgb, "DEFAULT_UI_PROPERTY", NULL
),
gameModel(model)
{}
virtual ~PropertyTool()
{}
void OpenWindow(Simulation *sim); void OpenWindow(Simulation *sim);
virtual ~PropertyTool() {}
virtual void SetProperty(Simulation *sim, ui::Point position); virtual void SetProperty(Simulation *sim, ui::Point position);
void Click(Simulation * sim, Brush const &brush, ui::Point position) override { } void Click(Simulation * sim, Brush const &brush, ui::Point position) override { }
void Draw(Simulation *sim, Brush const &brush, ui::Point position) override; void Draw(Simulation *sim, Brush const &brush, ui::Point position) override;
@ -103,15 +128,19 @@ public:
class GOLTool: public Tool class GOLTool: public Tool
{ {
GameModel &gameModel;
public: public:
GameModel * gameModel; GOLTool(GameModel &gameModel):
GOLTool(GameModel * gameModel): Tool(0, "CUST", "Add a new custom GOL type. (Use ctrl+shift+rightclick to remove them)",
Tool(0, "CUST", "Add a new custom GOL type. (Use ctrl+shift+rightclick to remove them)", 0xfe, 0xa9, 0x00, "DEFAULT_UI_ADDLIFE", NULL), 0xFEA900_rgb, "DEFAULT_UI_ADDLIFE", NULL
),
gameModel(gameModel) gameModel(gameModel)
{ {}
}
void OpenWindow(Simulation *sim, int toolSelection, int rule = 0, int colour1 = 0, int colour2 = 0); virtual ~GOLTool()
virtual ~GOLTool() {} {}
void OpenWindow(Simulation *sim, int toolSelection, int rule = 0, RGB<uint8_t> colour1 = 0x000000_rgb, RGB<uint8_t> colour2 = 0x000000_rgb);
void Click(Simulation * sim, Brush const &brush, ui::Point position) override { } void Click(Simulation * sim, Brush const &brush, ui::Point position) override { }
void Draw(Simulation *sim, Brush const &brush, ui::Point position) override { }; void Draw(Simulation *sim, Brush const &brush, ui::Point position) override { };
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override { }; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override { };
@ -123,8 +152,14 @@ public:
class ElementTool: public Tool class ElementTool: public Tool
{ {
public: public:
ElementTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL); ElementTool(int id, String name, String description,
virtual ~ElementTool(); RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
Tool(id, name, description, colour, identifier, textureGen)
{}
virtual ~ElementTool()
{}
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override; void Draw(Simulation * sim, Brush const &brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override; void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;
@ -134,10 +169,14 @@ public:
class Element_LIGH_Tool: public ElementTool class Element_LIGH_Tool: public ElementTool
{ {
public: public:
Element_LIGH_Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL): Element_LIGH_Tool(int id, String name, String description,
ElementTool(id, name, description, r, g, b, identifier, textureGen) RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
ElementTool(id, name, description, colour, identifier, textureGen)
{} {}
virtual ~Element_LIGH_Tool() { }
virtual ~Element_LIGH_Tool()
{}
void Click(Simulation * sim, Brush const &brush, ui::Point position) override { } void Click(Simulation * sim, Brush const &brush, ui::Point position) override { }
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override { } void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override { }
@ -147,10 +186,14 @@ public:
class Element_TESC_Tool: public ElementTool class Element_TESC_Tool: public ElementTool
{ {
public: public:
Element_TESC_Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL): Element_TESC_Tool(int id, String name, String description,
ElementTool(id, name, description, r, g, b, identifier, textureGen) RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
ElementTool(id, name, description, colour, identifier, textureGen)
{} {}
virtual ~Element_TESC_Tool() {}
virtual ~Element_TESC_Tool()
{}
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override; void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;
void DrawFill(Simulation * sim, Brush const &brush, ui::Point position) override; void DrawFill(Simulation * sim, Brush const &brush, ui::Point position) override;
}; };
@ -158,10 +201,14 @@ public:
class PlopTool: public ElementTool class PlopTool: public ElementTool
{ {
public: public:
PlopTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL): PlopTool(int id, String name, String description,
ElementTool(id, name, description, r, g, b, identifier, textureGen) RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
ElementTool(id, name, description, colour, identifier, textureGen)
{} {}
virtual ~PlopTool() { }
virtual ~PlopTool()
{}
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { } void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { }
void Click(Simulation * sim, Brush const &brush, ui::Point position) override; void Click(Simulation * sim, Brush const &brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override { } void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override { }
@ -172,8 +219,15 @@ public:
class WallTool: public Tool class WallTool: public Tool
{ {
public: public:
WallTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL); WallTool(int id, String description,
virtual ~WallTool(); RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
Tool(id, "", description, colour, identifier, textureGen, true)
{
}
virtual ~WallTool()
{}
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override; void Draw(Simulation * sim, Brush const &brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override; void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;
@ -183,8 +237,14 @@ public:
class WindTool: public Tool class WindTool: public Tool
{ {
public: public:
WindTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL); WindTool():
virtual ~WindTool() { } Tool(0, "WIND", "Creates air movement.",
0x404040_rgb, "DEFAULT_UI_WIND")
{}
virtual ~WindTool()
{}
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { } void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { }
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override { } void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override { }

View File

@ -10,20 +10,21 @@ namespace ui
VerticalAlign(AlignMiddle), VerticalAlign(AlignMiddle),
HorizontalAlign(AlignCentre), HorizontalAlign(AlignCentre),
BackgroundHover(20, 20, 20), BackgroundHover(0x141414_rgb .WithAlpha(0xFF)),
BackgroundInactive(0, 0, 0), BackgroundInactive(0x000000_rgb .WithAlpha(0xFF)),
BackgroundActive(255, 255, 255), BackgroundActive(0xFFFFFF_rgb .WithAlpha(0xFF)),
BackgroundDisabled(10, 10, 10), BackgroundDisabled(0x0A0A0A_rgb .WithAlpha(0xFF)),
TextHover(255, 255, 255), TextHover(0xFFFFFF_rgb .WithAlpha(0xFF)),
TextInactive(255, 255, 255), TextInactive(0xFFFFFF_rgb .WithAlpha(0xFF)),
TextActive(0, 0, 0), TextActive(0x000000_rgb .WithAlpha(0xFF)),
TextDisabled(100, 100, 100), TextDisabled(0x646464_rgb .WithAlpha(0xFF)),
BorderHover(255, 255, 255), BorderHover(0xFFFFFF_rgb .WithAlpha(0xFF)),
BorderInactive(200, 200, 200), BorderInactive(0xC8C8C8_rgb .WithAlpha(0xFF)),
BorderActive(235, 235, 235), BorderActive(0xEBEBEB_rgb .WithAlpha(0xFF)),
BorderDisabled(100, 100, 100), BorderFavorite(0xFFFF00_rgb .WithAlpha(0xFF)),
BorderDisabled(0x646464_rgb .WithAlpha(0xFF)),
Margin(1, 4), Margin(1, 4),
Border(1), Border(1),

View File

@ -1,21 +1,8 @@
#pragma once #pragma once
#include "graphics/Pixel.h"
namespace ui namespace ui
{ {
class Colour using Colour = RGBA<uint8_t>;
{
public:
unsigned char Red, Green, Blue, Alpha;
Colour(unsigned char red, unsigned char green, unsigned char blue):
Red(red), Green(green), Blue(blue), Alpha(255)
{
}
Colour(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha):
Red(red), Green(green), Blue(blue), Alpha(alpha)
{
}
Colour()
{
}
};
} }

View File

@ -481,13 +481,13 @@ int LuaScriptInterface::tpt_index(lua_State *l)
else if (byteStringEqualsLiteral(key, "mousey")) else if (byteStringEqualsLiteral(key, "mousey"))
return lua_pushnumber(l, c->GetView()->GetMousePosition().Y), 1; return lua_pushnumber(l, c->GetView()->GetMousePosition().Y), 1;
else if (byteStringEqualsLiteral(key, "selectedl")) else if (byteStringEqualsLiteral(key, "selectedl"))
return tpt_lua_pushByteString(l, m->GetActiveTool(0)->GetIdentifier()), 1; return tpt_lua_pushByteString(l, m->GetActiveTool(0)->Identifier), 1;
else if (byteStringEqualsLiteral(key, "selectedr")) else if (byteStringEqualsLiteral(key, "selectedr"))
return tpt_lua_pushByteString(l, m->GetActiveTool(1)->GetIdentifier()), 1; return tpt_lua_pushByteString(l, m->GetActiveTool(1)->Identifier), 1;
else if (byteStringEqualsLiteral(key, "selecteda")) else if (byteStringEqualsLiteral(key, "selecteda"))
return tpt_lua_pushByteString(l, m->GetActiveTool(2)->GetIdentifier()), 1; return tpt_lua_pushByteString(l, m->GetActiveTool(2)->Identifier), 1;
else if (byteStringEqualsLiteral(key, "selectedreplace")) else if (byteStringEqualsLiteral(key, "selectedreplace"))
return tpt_lua_pushByteString(l, m->GetActiveTool(3)->GetIdentifier()), 1; return tpt_lua_pushByteString(l, m->GetActiveTool(3)->Identifier), 1;
else if (byteStringEqualsLiteral(key, "brushx")) else if (byteStringEqualsLiteral(key, "brushx"))
return lua_pushnumber(l, m->GetBrush().GetRadius().X), 1; return lua_pushnumber(l, m->GetBrush().GetRadius().X), 1;
else if (byteStringEqualsLiteral(key, "brushy")) else if (byteStringEqualsLiteral(key, "brushy"))
@ -1468,7 +1468,7 @@ int LuaScriptInterface::simulation_createParts(lua_State * l)
int y = luaL_optint(l,2,-1); int y = luaL_optint(l,2,-1);
int rx = luaL_optint(l,3,5); int rx = luaL_optint(l,3,5);
int ry = luaL_optint(l,4,5); int ry = luaL_optint(l,4,5);
int c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID()); int c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->ToolID);
int brushID = luaL_optint(l,6,CIRCLE_BRUSH); int brushID = luaL_optint(l,6,CIRCLE_BRUSH);
int flags = luaL_optint(l,7,luacon_sim->replaceModeFlags); int flags = luaL_optint(l,7,luacon_sim->replaceModeFlags);
@ -1491,7 +1491,7 @@ int LuaScriptInterface::simulation_createLine(lua_State * l)
int y2 = luaL_optint(l,4,-1); int y2 = luaL_optint(l,4,-1);
int rx = luaL_optint(l,5,5); int rx = luaL_optint(l,5,5);
int ry = luaL_optint(l,6,5); int ry = luaL_optint(l,6,5);
int c = luaL_optint(l,7,luacon_model->GetActiveTool(0)->GetToolID()); int c = luaL_optint(l,7,luacon_model->GetActiveTool(0)->ToolID);
int brushID = luaL_optint(l,8,CIRCLE_BRUSH); int brushID = luaL_optint(l,8,CIRCLE_BRUSH);
int flags = luaL_optint(l,9,luacon_sim->replaceModeFlags); int flags = luaL_optint(l,9,luacon_sim->replaceModeFlags);
@ -1511,7 +1511,7 @@ int LuaScriptInterface::simulation_createBox(lua_State * l)
int y1 = luaL_optint(l,2,-1); int y1 = luaL_optint(l,2,-1);
int x2 = luaL_optint(l,3,-1); int x2 = luaL_optint(l,3,-1);
int y2 = luaL_optint(l,4,-1); int y2 = luaL_optint(l,4,-1);
int c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID()); int c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->ToolID);
int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags); int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags);
luacon_sim->CreateBox(x1, y1, x2, y2, c, flags); luacon_sim->CreateBox(x1, y1, x2, y2, c, flags);
@ -1522,7 +1522,7 @@ int LuaScriptInterface::simulation_floodParts(lua_State * l)
{ {
int x = luaL_optint(l,1,-1); int x = luaL_optint(l,1,-1);
int y = luaL_optint(l,2,-1); int y = luaL_optint(l,2,-1);
int c = luaL_optint(l,3,luacon_model->GetActiveTool(0)->GetToolID()); int c = luaL_optint(l,3,luacon_model->GetActiveTool(0)->ToolID);
int cm = luaL_optint(l,4,-1); int cm = luaL_optint(l,4,-1);
int flags = luaL_optint(l,5,luacon_sim->replaceModeFlags); int flags = luaL_optint(l,5,luacon_sim->replaceModeFlags);
@ -1662,10 +1662,10 @@ int LuaScriptInterface::simulation_toolLine(lua_State * l)
if (tool == (int)luacon_sim->tools.size()) if (tool == (int)luacon_sim->tools.size())
{ {
Tool *windTool = luacon_model->GetToolFromIdentifier("DEFAULT_UI_WIND"); Tool *windTool = luacon_model->GetToolFromIdentifier("DEFAULT_UI_WIND");
float oldStrength = windTool->GetStrength(); float oldStrength = windTool->Strength;
windTool->SetStrength(strength); windTool->Strength = strength;
windTool->DrawLine(luacon_sim, *newBrush, ui::Point(x1, y1), ui::Point(x2, y2)); windTool->DrawLine(luacon_sim, *newBrush, ui::Point(x1, y1), ui::Point(x2, y2));
windTool->SetStrength(oldStrength); windTool->Strength = oldStrength;
} }
else else
luacon_sim->ToolLine(x1, y1, x2, y2, tool, *newBrush, strength); luacon_sim->ToolLine(x1, y1, x2, y2, tool, *newBrush, strength);

View File

@ -1,4 +1,6 @@
#pragma once #pragma once
#include <memory>
#include "common/Vec2.h"
#include "graphics/Pixel.h" #include "graphics/Pixel.h"
#include "ElementDefs.h" #include "ElementDefs.h"
#include "Particle.h" #include "Particle.h"
@ -58,7 +60,7 @@ public:
bool (*CtypeDraw) (CTYPEDRAW_FUNC_ARGS); bool (*CtypeDraw) (CTYPEDRAW_FUNC_ARGS);
VideoBuffer * (*IconGenerator)(int, int, int); std::unique_ptr<VideoBuffer> (*IconGenerator)(int, Vec2<int>);
Particle DefaultProperties; Particle DefaultProperties;

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <memory>
#include "common/String.h" #include "common/String.h"
#include "common/Vec2.h"
#include "graphics/Pixel.h" #include "graphics/Pixel.h"
class VideoBuffer; class VideoBuffer;
@ -8,7 +10,7 @@ struct wall_type
pixel colour; pixel colour;
pixel eglow; // if emap set, add this to fire glow pixel eglow; // if emap set, add this to fire glow
int drawstyle; int drawstyle;
VideoBuffer * (*textureGen)(int, int, int); std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>);
String name; String name;
ByteString identifier; ByteString identifier;
String descs; String descs;

View File

@ -1,6 +1,6 @@
#include "simulation/ElementCommon.h" #include "simulation/ElementCommon.h"
static VideoBuffer *iconGen(int wallID, int width, int height); static std::unique_ptr<VideoBuffer> iconGen(int wallID, Vec2<int> size);
void Element::Element_NONE() void Element::Element_NONE()
{ {
@ -45,17 +45,9 @@ void Element::Element_NONE()
IconGenerator = &iconGen; IconGenerator = &iconGen;
} }
static VideoBuffer *iconGen(int wallID, int width, int height) static std::unique_ptr<VideoBuffer> iconGen(int wallID, Vec2<int> size)
{ {
VideoBuffer * newTexture = new VideoBuffer(width, height); auto texture = std::make_unique<VideoBuffer>(size);
texture->BlendChar(size / 2 - Vec2(4, 2), 0xE06C, 0xFF0000_rgb .WithAlpha(0xFF));
for (int j=3; j<(width-4)/2; j++) return texture;
{
newTexture->SetPixel(j+6, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(j+7, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(-j+19, j, 0xFF, 0, 0, 255);
newTexture->SetPixel(-j+20, j, 0xFF, 0, 0, 255);
}
return newTexture;
} }