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

View File

@ -1,5 +1,6 @@
#pragma once
#include <array>
#include <memory>
#include <mutex>
#include <vector>
#include "Graphics.h"
@ -142,7 +143,7 @@ public:
int GetGridSize() { return gridSize; }
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();

View File

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

View File

@ -5,84 +5,60 @@
#include "simulation/SimulationData.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);
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
//if (toolID == DECO_LIGH)
// vid_buf[WINDOWW*(y+j)+(x+i)] = PIXRGB(PIXR(pc)-10*j, PIXG(pc)-10*j, PIXB(pc)-10*j);
//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
newTexture->SetPixel(x, y, 50, 50, 50, 255);
}
}
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;
}
auto texture = std::make_unique<VideoBuffer>(size);
DecorationTool::DecorationTool(Renderer *ren_, int decoMode, String name, String description, int r, int g, int b, ByteString identifier):
Tool(decoMode, name, description, r, g, b, identifier),
Red(0),
Green(0),
Blue(0),
Alpha(0),
ren(ren_)
{
}
if (ToolID == DECO_SMUDGE)
for (auto pos : size.OriginRect())
texture->DrawPixel(pos, RGB<uint8_t>(0, 0xFF - 5 * pos.X, 5 * pos.X));
else if (ToolID == DECO_DRAW || ToolID == DECO_CLEAR)
texture->BlendFilledRect(size.OriginRect(), Colour);
else
texture->DrawFilledRect(size.OriginRect(), 0x323232_rgb);
DecorationTool::~DecorationTool()
{
if (ToolID == DECO_CLEAR)
{
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
{
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)
{
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)
{
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)
{
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)
{
pixel loc = ren->vid[position.X+position.Y*WINDOWW];
if (toolID == DECO_CLEAR)
sim->ApplyDecorationFill(ren, position.X, position.Y, 0, 0, 0, 0, PIXR(loc), PIXG(loc), PIXB(loc));
pixel loc = ren.vid[position.X+position.Y*WINDOWW];
if (ToolID == DECO_CLEAR)
// 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
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
#include <memory>
#include "Tool.h"
#include "graphics/Graphics.h"
@ -6,16 +7,20 @@ class Renderer;
class DecorationTool: public Tool
{
public:
unsigned char Red;
unsigned char Green;
unsigned char Blue;
unsigned char Alpha;
Renderer *ren;
RGBA<uint8_t> Colour;
Renderer const &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 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;

View File

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

View File

@ -360,7 +360,7 @@ void GameController::DrawRect(int toolSelection, ui::Point point1, ui::Point poi
Brush &cBrush = gameModel->GetBrush();
if (!activeTool)
return;
activeTool->SetStrength(1.0f);
activeTool->Strength = 1.0f;
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();
if (!activeTool)
return;
activeTool->SetStrength(1.0f);
activeTool->Strength = 1.0f;
activeTool->DrawLine(sim, cBrush, point1, point2);
}
@ -384,7 +384,7 @@ void GameController::DrawFill(int toolSelection, ui::Point point)
Brush &cBrush = gameModel->GetBrush();
if (!activeTool)
return;
activeTool->SetStrength(1.0f);
activeTool->Strength = 1.0f;
activeTool->DrawFill(sim, cBrush, point);
}
@ -399,7 +399,7 @@ void GameController::DrawPoints(int toolSelection, ui::Point oldPos, ui::Point n
return;
}
activeTool->SetStrength(gameModel->GetToolStrength());
activeTool->Strength = gameModel->GetToolStrength();
if (!held)
activeTool->Draw(sim, cBrush, newPos);
else
@ -503,7 +503,7 @@ bool GameController::MouseDown(int x, int y, unsigned button)
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
x = point.X;
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);
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));
x = point.X;
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);
if (foundSignID != -1)
@ -872,9 +872,9 @@ void GameController::Update()
{
int rightSelected = PT_DUST;
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))
rightSelected = sr;
}
@ -1069,16 +1069,16 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool)
gameModel->SetActiveTool(toolSelection, tool);
gameModel->GetRenderer()->gravityZonesEnabled = false;
if (toolSelection == 3)
gameModel->GetSimulation()->replaceModeSelected = tool->GetToolID();
gameModel->GetSimulation()->replaceModeSelected = tool->ToolID;
gameModel->SetLastTool(tool);
for(int i = 0; i < 3; i++)
{
if(gameModel->GetActiveTool(i) == gameModel->GetMenuList().at(SC_WALL)->GetToolList().at(WL_GRAV))
gameModel->GetRenderer()->gravityZonesEnabled = true;
}
if(tool->GetIdentifier() == "DEFAULT_UI_PROPERTY")
if(tool->Identifier == "DEFAULT_UI_PROPERTY")
((PropertyTool *)tool)->OpenWindow(gameModel->GetSimulation());
if(tool->GetIdentifier() == "DEFAULT_UI_ADDLIFE")
if(tool->Identifier == "DEFAULT_UI_ADDLIFE")
{
((GOLTool *)tool)->OpenWindow(gameModel->GetSimulation(), toolSelection);
}

View File

@ -231,13 +231,13 @@ void GameModel::BuildMenus()
ByteString activeToolIdentifiers[4];
if(regularToolset[0])
activeToolIdentifiers[0] = regularToolset[0]->GetIdentifier();
activeToolIdentifiers[0] = regularToolset[0]->Identifier;
if(regularToolset[1])
activeToolIdentifiers[1] = regularToolset[1]->GetIdentifier();
activeToolIdentifiers[1] = regularToolset[1]->Identifier;
if(regularToolset[2])
activeToolIdentifiers[2] = regularToolset[2]->GetIdentifier();
activeToolIdentifiers[2] = regularToolset[2]->Identifier;
if(regularToolset[3])
activeToolIdentifiers[3] = regularToolset[3]->GetIdentifier();
activeToolIdentifiers[3] = regularToolset[3]->Identifier;
//Empty current menus
for (size_t i = 0; i < menuList.size(); i++)
@ -270,19 +270,19 @@ void GameModel::BuildMenus()
Tool * tempTool;
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)
{
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)
{
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
{
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)
@ -300,7 +300,7 @@ void GameModel::BuildMenus()
//Build menu for GOL types
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);
}
{
@ -353,7 +353,7 @@ void GameModel::BuildMenus()
}
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);
}
sim->SetCustomGOL(newCustomGol);
@ -362,7 +362,7 @@ void GameModel::BuildMenus()
//Build other menus from wall data
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);
//sim->wtypes[i]
}
@ -374,28 +374,26 @@ void GameModel::BuildMenus()
i,
sim->tools[i].Name,
sim->tools[i].Description,
PIXR(sim->tools[i].Colour),
PIXG(sim->tools[i].Colour),
PIXB(sim->tools[i].Colour),
RGB<uint8_t>::Unpack(sim->tools[i].Colour),
sim->tools[i].Identifier
);
menuList[SC_TOOL]->AddTool(tempTool);
}
//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 PropertyTool(this));
menuList[SC_TOOL]->AddTool(new SignTool(this));
menuList[SC_TOOL]->AddTool(new SampleTool(this));
menuList[SC_LIFE]->AddTool(new GOLTool(this));
menuList[SC_TOOL]->AddTool(new WindTool());
menuList[SC_TOOL]->AddTool(new PropertyTool(*this));
menuList[SC_TOOL]->AddTool(new SignTool(*this));
menuList[SC_TOOL]->AddTool(new SampleTool(*this));
menuList[SC_LIFE]->AddTool(new GOLTool(*this));
//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_SUBTRACT, "SUB", "Colour blending: Subtract.", 0, 0, 0, "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_DIVIDE, "DIV", "Colour blending: Divide." , 0, 0, 0, "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_CLEAR, "CLR", "Erase any set decoration.", 0, 0, 0, "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_ADD, "ADD", "Colour blending: Add.", 0x000000_rgb, "DEFAULT_DECOR_ADD"));
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.", 0x000000_rgb, "DEFAULT_DECOR_MUL"));
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.", 0x000000_rgb, "DEFAULT_DECOR_SMDG"));
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).", 0x000000_rgb, "DEFAULT_DECOR_SET"));
SetColourSelectorColour(colour); // update tool colors
decoToolset[0] = GetToolFromIdentifier("DEFAULT_DECOR_SET");
decoToolset[1] = GetToolFromIdentifier("DEFAULT_DECOR_CLR");
@ -499,7 +497,7 @@ Tool *GameModel::GetToolFromIdentifier(ByteString const &identifier)
{
for (auto *tool : menu->GetToolList())
{
if (identifier == tool->GetIdentifier())
if (identifier == tool->Identifier)
{
return tool;
}
@ -507,7 +505,7 @@ Tool *GameModel::GetToolFromIdentifier(ByteString const &identifier)
}
for (auto *extra : extraElementTools)
{
if (identifier == extra->GetIdentifier())
if (identifier == extra->Identifier)
{
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)
{
if((*iter)->GetToolID() == elementID)
if((*iter)->ToolID == elementID)
return *iter;
}
return NULL;
@ -1208,13 +1206,8 @@ void GameModel::SetColourSelectorColour(ui::Colour colour_)
colour = colour_;
std::vector<Tool*> tools = GetMenuList()[SC_DECO]->GetToolList();
for (size_t i = 0; i < tools.size(); i++)
{
((DecorationTool*)tools[i])->Red = colour.Red;
((DecorationTool*)tools[i])->Green = colour.Green;
((DecorationTool*)tools[i])->Blue = colour.Blue;
((DecorationTool*)tools[i])->Alpha = colour.Alpha;
}
for (auto tool : tools)
static_cast<DecorationTool *>(tool)->Colour = colour;
notifyColourSelectorColourChanged();
}

View File

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

View File

@ -139,11 +139,11 @@ void PropertyWindow::SetProperty(bool warn)
v = sim->GetParticleType(value.ToUtf8());
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;
}
}
@ -199,7 +199,7 @@ void PropertyWindow::SetProperty(bool warn)
case StructProperty::Float:
{
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
tool->propValue.Float = value.ToNumber<float>();
}

View File

@ -11,30 +11,21 @@
#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);
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
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;
auto texture = std::make_unique<VideoBuffer>(size);
texture->DrawRect(size.OriginRect(), 0xA0A0A0_rgb);
texture->BlendChar((size / 2) - Vec2(5, 5), 0xE066, 0xFFFFFF_rgb .WithAlpha(0xFF));
texture->BlendChar((size / 2) - Vec2(5, 5), 0xE06B, 0x64B4FF_rgb .WithAlpha(0xFF));
return texture;
}
void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
{
if(gameModel->GetColourSelectorVisibility())
if(gameModel.GetColourSelectorVisibility())
{
pixel colour = gameModel->GetRenderer()->sampleColor;
gameModel->SetColourSelectorColour(ui::Colour(PIXR(colour), PIXG(colour), PIXB(colour), 255));
pixel colour = gameModel.GetRenderer()->sampleColor;
gameModel.SetColourSelectorColour(RGB<uint8_t>::Unpack(colour).WithAlpha(0xFF));
}
else
{
@ -52,25 +43,24 @@ void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
if (part->type == PT_LIFE)
{
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;
break;
}
}
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
{
Tool * elementTool = gameModel->GetElementTool(part->type);
if(elementTool)
gameModel->SetActiveTool(0, elementTool);
if (auto elementTool = gameModel.GetElementTool(part->type))
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);
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)
{
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);
}
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);
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
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;
auto texture = std::make_unique<VideoBuffer>(size);
texture->DrawRect(size.OriginRect(), 0xA0A0A0_rgb);
texture->BlendChar((size / 2) - Vec2(5, 5), 0xE021, 0x204080_rgb .WithAlpha(0xFF));
texture->BlendChar((size / 2) - Vec2(5, 5), 0xE020, 0xFFFFFF_rgb .WithAlpha(0xFF));
return texture;
}
void SignTool::Click(Simulation * sim, Brush const &brush, ui::Point position)

View File

@ -1,92 +1,56 @@
#include "Tool.h"
#include "graphics/Graphics.h"
#include "gui/game/Brush.h"
#include "simulation/Simulation.h"
#include "simulation/SimulationData.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)):
textureGen(textureGen),
toolID(id),
toolName(name),
toolDescription(description),
strength(1.0f),
blocky(false),
identifier(identifier),
colRed(r),
colGreen(g),
colBlue(b)
std::unique_ptr<VideoBuffer> Tool::GetTexture(Vec2<int> size)
{
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::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) {
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) {
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) {}
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){
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) {
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) {
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) {
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) {
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) {
int wallX = position1.X/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;
newFanVelX *= strength;
newFanVelX *= Strength;
float newFanVelY = (position2.Y-position1.Y)*0.005f;
newFanVelY *= strength;
newFanVelY *= Strength;
sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, WL_FAN);
for (int j = 0; j < YCELLS; j++)
for (int i = 0; i < XCELLS; i++)
@ -99,26 +63,21 @@ void WallTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position
}
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) {
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) {
if (toolID != WL_STREAM)
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)
{
if (ToolID != WL_STREAM)
sim->FloodWalls(position.X, position.Y, ToolID, -1);
}
void WindTool::DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging)
{
float strength = dragging?0.01f:0.002f;
strength *= this->strength;
strength *= this->Strength;
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) {
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) {
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)
{
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
#include <memory>
#include "common/String.h"
#include "common/Vec2.h"
#include "graphics/Pixel.h"
#include "gui/interface/Point.h"
#include "simulation/StructProperty.h"
@ -9,28 +12,34 @@ class VideoBuffer;
class Tool
{
protected:
VideoBuffer * (*textureGen)(int, int, int);
int toolID;
String toolName;
String toolDescription;
float strength;
bool blocky;
ByteString identifier;
public:
int colRed, colGreen, colBlue;
private:
std::unique_ptr<VideoBuffer> (*const textureGen)(int, Vec2<int>);
Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
int GetToolID() { return toolID; }
String GetName();
String GetDescription();
ByteString GetIdentifier();
int GetBlocky() { return blocky; }
void SetStrength(float value) { strength = value; }
float GetStrength() { return strength; }
VideoBuffer * GetTexture(int width, int height);
void SetTextureGen(VideoBuffer * (*textureGen)(int, int, int));
virtual ~Tool();
public:
int const ToolID;
String const Name;
String const Description;
ByteString const Identifier;
RGB<uint8_t> const Colour;
bool const Blocky;
float Strength = 1.0f;
Tool(int id, String name, String description,
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 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);
@ -42,15 +51,22 @@ class GameModel;
class SignTool: public Tool
{
GameModel &gameModel;
friend class SignWindow;
public:
GameModel * gameModel;
SignTool(GameModel *model):
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),
gameModel(model)
{
}
static VideoBuffer * GetIcon(int toolID, int width, int height);
virtual ~SignTool() {}
SignTool(GameModel &model):
Tool(0, "SIGN", "Sign. Displays text. Click on a sign to edit it or anywhere else to place a new one.",
0x000000_rgb, "DEFAULT_UI_SIGN", SignTool::GetIcon
),
gameModel(model)
{}
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 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 { }
@ -60,14 +76,17 @@ public:
class SampleTool: public Tool
{
GameModel * gameModel;
GameModel &gameModel;
public:
SampleTool(GameModel *model):
Tool(0, "SMPL", "Sample an element on the screen.", 0, 0, 0, "DEFAULT_UI_SAMPLE", SampleTool::GetIcon),
gameModel(model)
{
}
static VideoBuffer * GetIcon(int toolID, int width, int height);
SampleTool(GameModel &model):
Tool(0, "SMPL", "Sample an element on the screen.",
0x000000_rgb, "DEFAULT_UI_SAMPLE", SampleTool::GetIcon
),
gameModel(model)
{}
static std::unique_ptr<VideoBuffer> GetIcon(int toolID, Vec2<int> size);
virtual ~SampleTool() {}
void Click(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
{
public:
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)
{
}
GameModel &gameModel;
StructProperty::PropertyType propType;
PropertyValue propValue;
bool changeType;
size_t propOffset;
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);
virtual ~PropertyTool() {}
virtual void SetProperty(Simulation *sim, ui::Point position);
void Click(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
{
GameModel &gameModel;
public:
GameModel * gameModel;
GOLTool(GameModel * gameModel):
Tool(0, "CUST", "Add a new custom GOL type. (Use ctrl+shift+rightclick to remove them)", 0xfe, 0xa9, 0x00, "DEFAULT_UI_ADDLIFE", NULL),
gameModel(gameModel)
{
}
void OpenWindow(Simulation *sim, int toolSelection, int rule = 0, int colour1 = 0, int colour2 = 0);
virtual ~GOLTool() {}
GOLTool(GameModel &gameModel):
Tool(0, "CUST", "Add a new custom GOL type. (Use ctrl+shift+rightclick to remove them)",
0xFEA900_rgb, "DEFAULT_UI_ADDLIFE", NULL
),
gameModel(gameModel)
{}
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 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 { };
@ -123,8 +152,14 @@ public:
class ElementTool: public Tool
{
public:
ElementTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~ElementTool();
ElementTool(int id, String name, String description,
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 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;
@ -134,10 +169,14 @@ public:
class Element_LIGH_Tool: public ElementTool
{
public:
Element_LIGH_Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~Element_LIGH_Tool() { }
Element_LIGH_Tool(int id, String name, String description,
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()
{}
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 DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override { }
@ -147,10 +186,14 @@ public:
class Element_TESC_Tool: public ElementTool
{
public:
Element_TESC_Tool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~Element_TESC_Tool() {}
Element_TESC_Tool(int id, String name, String description,
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()
{}
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;
};
@ -158,10 +201,14 @@ public:
class PlopTool: public ElementTool
{
public:
PlopTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~PlopTool() { }
PlopTool(int id, String name, String description,
RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
ElementTool(id, name, description, colour, identifier, textureGen)
{}
virtual ~PlopTool()
{}
void Draw(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 { }
@ -172,8 +219,15 @@ public:
class WallTool: public Tool
{
public:
WallTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~WallTool();
WallTool(int id, String description,
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 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;
@ -183,8 +237,14 @@ public:
class WindTool: public Tool
{
public:
WindTool(int id, String name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~WindTool() { }
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 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 { }

View File

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

View File

@ -1,21 +1,8 @@
#pragma once
#include "graphics/Pixel.h"
namespace ui
{
class Colour
{
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()
{
}
};
using Colour = RGBA<uint8_t>;
}

View File

@ -481,13 +481,13 @@ int LuaScriptInterface::tpt_index(lua_State *l)
else if (byteStringEqualsLiteral(key, "mousey"))
return lua_pushnumber(l, c->GetView()->GetMousePosition().Y), 1;
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"))
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"))
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"))
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"))
return lua_pushnumber(l, m->GetBrush().GetRadius().X), 1;
else if (byteStringEqualsLiteral(key, "brushy"))
@ -1468,7 +1468,7 @@ int LuaScriptInterface::simulation_createParts(lua_State * l)
int y = luaL_optint(l,2,-1);
int rx = luaL_optint(l,3,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 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 rx = luaL_optint(l,5,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 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 x2 = luaL_optint(l,3,-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);
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 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 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())
{
Tool *windTool = luacon_model->GetToolFromIdentifier("DEFAULT_UI_WIND");
float oldStrength = windTool->GetStrength();
windTool->SetStrength(strength);
float oldStrength = windTool->Strength;
windTool->Strength = strength;
windTool->DrawLine(luacon_sim, *newBrush, ui::Point(x1, y1), ui::Point(x2, y2));
windTool->SetStrength(oldStrength);
windTool->Strength = oldStrength;
}
else
luacon_sim->ToolLine(x1, y1, x2, y2, tool, *newBrush, strength);

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#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()
{
@ -45,17 +45,9 @@ void Element::Element_NONE()
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);
for (int 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);
}
return newTexture;
auto texture = std::make_unique<VideoBuffer>(size);
texture->BlendChar(size / 2 - Vec2(4, 2), 0xE06C, 0xFF0000_rgb .WithAlpha(0xFF));
return texture;
}