mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-26 09:24:28 +02:00
Element search
This commit is contained in:
192
src/elementsearch/ElementSearchActivity.cpp
Normal file
192
src/elementsearch/ElementSearchActivity.cpp
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* ElementSearchActivity.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jun 24, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include "ElementSearchActivity.h"
|
||||||
|
#include "interface/Textbox.h"
|
||||||
|
#include "interface/Label.h"
|
||||||
|
#include "game/Tool.h"
|
||||||
|
#include "Style.h"
|
||||||
|
#include "game/GameModel.h"
|
||||||
|
|
||||||
|
class ElementSearchActivity::ToolAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
ElementSearchActivity * a;
|
||||||
|
public:
|
||||||
|
Tool * tool;
|
||||||
|
ToolAction(ElementSearchActivity * a, Tool * tool) : a(a), tool(tool) { }
|
||||||
|
void ActionCallback(ui::Button * sender_)
|
||||||
|
{
|
||||||
|
ToolButton *sender = (ToolButton*)sender_;
|
||||||
|
if(sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 2)
|
||||||
|
a->SetActiveTool(sender->GetSelectionState(), tool);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ElementSearchActivity::ElementSearchActivity(GameModel * gameModel, std::vector<Tool*> tools) :
|
||||||
|
Window(ui::Point(-1, -1), ui::Point(236, 302)),
|
||||||
|
gameModel(gameModel),
|
||||||
|
tools(tools),
|
||||||
|
firstResult(NULL)
|
||||||
|
{
|
||||||
|
ui::Label * title = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), "Element Search");
|
||||||
|
title->SetTextColour(style::Colour::InformationTitle);
|
||||||
|
title->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
|
AddComponent(title);
|
||||||
|
|
||||||
|
class SearchAction : public ui::TextboxAction
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
ElementSearchActivity * a;
|
||||||
|
public:
|
||||||
|
SearchAction(ElementSearchActivity * a) : a(a) {}
|
||||||
|
virtual void TextChangedCallback(ui::Textbox * sender) {
|
||||||
|
a->searchTools(sender->GetText());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
searchField = new ui::Textbox(ui::Point(8, 23), ui::Point(Size.X-16, 17), "");
|
||||||
|
searchField->SetActionCallback(new SearchAction(this));
|
||||||
|
searchField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
|
AddComponent(searchField);
|
||||||
|
FocusComponent(searchField);
|
||||||
|
|
||||||
|
class CloseAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
ElementSearchActivity * a;
|
||||||
|
public:
|
||||||
|
CloseAction(ElementSearchActivity * a) : a(a) { }
|
||||||
|
void ActionCallback(ui::Button * sender_)
|
||||||
|
{
|
||||||
|
a->Exit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class OKAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
ElementSearchActivity * a;
|
||||||
|
public:
|
||||||
|
OKAction(ElementSearchActivity * a) : a(a) { }
|
||||||
|
void ActionCallback(ui::Button * sender_)
|
||||||
|
{
|
||||||
|
if(a->GetFirstResult())
|
||||||
|
a->SetActiveTool(0, a->GetFirstResult());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ui::Button * closeButton = new ui::Button(ui::Point(0, Size.Y-15), ui::Point((Size.X/2)+1, 15), "Close");
|
||||||
|
closeButton->SetActionCallback(new CloseAction(this));
|
||||||
|
ui::Button * okButton = new ui::Button(ui::Point(Size.X/2, Size.Y-15), ui::Point(Size.X/2, 15), "OK");
|
||||||
|
okButton->SetActionCallback(new OKAction(this));
|
||||||
|
|
||||||
|
AddComponent(okButton);
|
||||||
|
AddComponent(closeButton);
|
||||||
|
|
||||||
|
searchTools("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementSearchActivity::searchTools(std::string query)
|
||||||
|
{
|
||||||
|
firstResult = NULL;
|
||||||
|
for(std::vector<ToolButton*>::iterator iter = toolButtons.begin(), end = toolButtons.end(); iter != end; ++iter) {
|
||||||
|
delete *iter;
|
||||||
|
RemoveComponent(*iter);
|
||||||
|
}
|
||||||
|
toolButtons.clear();
|
||||||
|
|
||||||
|
ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
|
||||||
|
ui::Point current = ui::Point(0, 0);
|
||||||
|
|
||||||
|
std::string queryLower = std::string(query);
|
||||||
|
std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
for(std::vector<Tool*>::iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter) {
|
||||||
|
std::string nameLower = std::string((*iter)->GetName());
|
||||||
|
std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
if(strstr(nameLower.c_str(), queryLower.c_str())!=0)
|
||||||
|
{
|
||||||
|
Tool * tool = *iter;
|
||||||
|
|
||||||
|
if(!firstResult)
|
||||||
|
firstResult = tool;
|
||||||
|
|
||||||
|
ToolButton * tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName());
|
||||||
|
tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue);
|
||||||
|
tempButton->SetActionCallback(new ToolAction(this, tool));
|
||||||
|
|
||||||
|
if(gameModel->GetActiveTool(0) == tool)
|
||||||
|
{
|
||||||
|
tempButton->SetSelectionState(0); //Primary
|
||||||
|
}
|
||||||
|
else if(gameModel->GetActiveTool(1) == tool)
|
||||||
|
{
|
||||||
|
tempButton->SetSelectionState(1); //Secondary
|
||||||
|
}
|
||||||
|
else if(gameModel->GetActiveTool(2) == tool)
|
||||||
|
{
|
||||||
|
tempButton->SetSelectionState(2); //Tertiary
|
||||||
|
}
|
||||||
|
|
||||||
|
toolButtons.push_back(tempButton);
|
||||||
|
AddComponent(tempButton);
|
||||||
|
|
||||||
|
current.X += 31;
|
||||||
|
|
||||||
|
if(current.X + 30 > searchField->Size.X) {
|
||||||
|
current.X = 0;
|
||||||
|
current.Y += 19;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current.Y + viewPosition.Y + 18 > Size.Y-23)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
|
||||||
|
{
|
||||||
|
gameModel->SetActiveTool(selectionState, tool);
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementSearchActivity::Exit()
|
||||||
|
{
|
||||||
|
if(ui::Engine::Ref().GetWindow() == this)
|
||||||
|
{
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
}
|
||||||
|
SelfDestruct();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementSearchActivity::OnDraw()
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
|
||||||
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||||
|
|
||||||
|
g->drawrect(Position.X+searchField->Position.X, Position.Y+searchField->Position.Y+searchField->Size.Y+8, searchField->Size.X, Size.Y-(searchField->Position.Y+searchField->Size.Y+8)-23, 255, 255, 255, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
if(key == KEY_ENTER || key == KEY_RETURN)
|
||||||
|
{
|
||||||
|
if(firstResult)
|
||||||
|
gameModel->SetActiveTool(0, firstResult);
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
|
if(key == KEY_ESCAPE)
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ElementSearchActivity::~ElementSearchActivity() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
39
src/elementsearch/ElementSearchActivity.h
Normal file
39
src/elementsearch/ElementSearchActivity.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* ElementSearchActivity.h
|
||||||
|
*
|
||||||
|
* Created on: Jun 24, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ELEMENTSEARCHACTIVITY_H_
|
||||||
|
#define ELEMENTSEARCHACTIVITY_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "interface/Window.h"
|
||||||
|
#include "interface/Textbox.h"
|
||||||
|
#include "game/ToolButton.h"
|
||||||
|
|
||||||
|
class Tool;
|
||||||
|
|
||||||
|
class GameModel;
|
||||||
|
|
||||||
|
class ElementSearchActivity: public ui::Window {
|
||||||
|
Tool * firstResult;
|
||||||
|
GameModel * gameModel;
|
||||||
|
std::vector<Tool*> tools;
|
||||||
|
ui::Textbox * searchField;
|
||||||
|
std::vector<ToolButton*> toolButtons;
|
||||||
|
void searchTools(std::string query);
|
||||||
|
public:
|
||||||
|
class ToolAction;
|
||||||
|
Tool * GetFirstResult() { return firstResult; }
|
||||||
|
ElementSearchActivity(GameModel * gameModel, std::vector<Tool*> tools);
|
||||||
|
void Exit();
|
||||||
|
void SetActiveTool(int selectionState, Tool * tool);
|
||||||
|
virtual ~ElementSearchActivity();
|
||||||
|
virtual void OnDraw();
|
||||||
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ELEMENTSEARCHACTIVITY_H_ */
|
@@ -13,6 +13,7 @@
|
|||||||
#include "dialogues/ConfirmPrompt.h"
|
#include "dialogues/ConfirmPrompt.h"
|
||||||
#include "GameModelException.h"
|
#include "GameModelException.h"
|
||||||
#include "simulation/Air.h"
|
#include "simulation/Air.h"
|
||||||
|
#include "elementsearch/ElementSearchActivity.h"
|
||||||
#include "update/UpdateActivity.h"
|
#include "update/UpdateActivity.h"
|
||||||
#include "Notification.h"
|
#include "Notification.h"
|
||||||
|
|
||||||
@@ -513,6 +514,21 @@ void GameController::OpenLogin()
|
|||||||
ui::Engine::Ref().ShowWindow(loginWindow->GetView());
|
ui::Engine::Ref().ShowWindow(loginWindow->GetView());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::OpenElementSearch()
|
||||||
|
{
|
||||||
|
vector<Tool*> toolList;
|
||||||
|
vector<Menu*> menuList = gameModel->GetMenuList();
|
||||||
|
for(std::vector<Menu*>::iterator iter = menuList.begin(), end = menuList.end(); iter!=end; ++iter) {
|
||||||
|
if(!(*iter))
|
||||||
|
continue;
|
||||||
|
vector<Tool*> menuToolList = (*iter)->GetToolList();
|
||||||
|
if(!menuToolList.size())
|
||||||
|
continue;
|
||||||
|
toolList.insert(toolList.end(), menuToolList.begin(), menuToolList.end());
|
||||||
|
}
|
||||||
|
ui::Engine::Ref().ShowWindow(new ElementSearchActivity(gameModel, toolList));
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::OpenTags()
|
void GameController::OpenTags()
|
||||||
{
|
{
|
||||||
if(gameModel->GetUser().ID)
|
if(gameModel->GetUser().ID)
|
||||||
|
@@ -90,6 +90,7 @@ public:
|
|||||||
void OpenRenderOptions();
|
void OpenRenderOptions();
|
||||||
void OpenSaveWindow();
|
void OpenSaveWindow();
|
||||||
void OpenStamps();
|
void OpenStamps();
|
||||||
|
void OpenElementSearch();
|
||||||
void PlaceSave(ui::Point position);
|
void PlaceSave(ui::Point position);
|
||||||
void ClearSim();
|
void ClearSim();
|
||||||
void ReloadSim();
|
void ReloadSim();
|
||||||
|
@@ -238,6 +238,21 @@ GameView::GameView():
|
|||||||
colourBSlider->SetActionCallback(colC);
|
colourBSlider->SetActionCallback(colC);
|
||||||
colourASlider = new ui::Slider(ui::Point(275, Size.Y-39), ui::Point(50, 14), 255);
|
colourASlider = new ui::Slider(ui::Point(275, Size.Y-39), ui::Point(50, 14), 255);
|
||||||
colourASlider->SetActionCallback(colC);
|
colourASlider->SetActionCallback(colC);
|
||||||
|
|
||||||
|
class ElementSearchAction : public ui::ButtonAction
|
||||||
|
{
|
||||||
|
GameView * v;
|
||||||
|
public:
|
||||||
|
ElementSearchAction(GameView * _v) { v = _v; }
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->OpenElementSearch();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, YRES+MENUSIZE-32), ui::Point(15, 15), "");
|
||||||
|
tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
|
||||||
|
tempButton->SetActionCallback(new ElementSearchAction(this));
|
||||||
|
AddComponent(tempButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
class GameView::MenuAction: public ui::ButtonAction
|
class GameView::MenuAction: public ui::ButtonAction
|
||||||
@@ -272,7 +287,7 @@ public:
|
|||||||
|
|
||||||
void GameView::NotifyMenuListChanged(GameModel * sender)
|
void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
int currentY = YRES+MENUSIZE-16-(sender->GetMenuList().size()*16);
|
int currentY = YRES+MENUSIZE-48;//-(sender->GetMenuList().size()*16);
|
||||||
for(int i = 0; i < menuButtons.size(); i++)
|
for(int i = 0; i < menuButtons.size(); i++)
|
||||||
{
|
{
|
||||||
RemoveComponent(menuButtons[i]);
|
RemoveComponent(menuButtons[i]);
|
||||||
@@ -286,15 +301,16 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
|
|||||||
}
|
}
|
||||||
toolButtons.clear();
|
toolButtons.clear();
|
||||||
vector<Menu*> menuList = sender->GetMenuList();
|
vector<Menu*> menuList = sender->GetMenuList();
|
||||||
for(int i = 0; i < menuList.size(); i++)
|
for(vector<Menu*>::reverse_iterator iter = menuList.rbegin(), end = menuList.rend(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
std::string tempString = "";
|
std::string tempString = "";
|
||||||
tempString += menuList[i]->GetIcon();
|
Menu * item = *iter;
|
||||||
|
tempString += item->GetIcon();
|
||||||
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), tempString);
|
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), tempString);
|
||||||
tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
|
tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
|
||||||
tempButton->SetTogglable(true);
|
tempButton->SetTogglable(true);
|
||||||
tempButton->SetActionCallback(new MenuAction(this, menuList[i]));
|
tempButton->SetActionCallback(new MenuAction(this, item));
|
||||||
currentY+=16;
|
currentY-=16;
|
||||||
AddComponent(tempButton);
|
AddComponent(tempButton);
|
||||||
menuButtons.push_back(tempButton);
|
menuButtons.push_back(tempButton);
|
||||||
}
|
}
|
||||||
|
94
src/game/Tool.cpp
Normal file
94
src/game/Tool.cpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Tool.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jun 24, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "Tool.h"
|
||||||
|
|
||||||
|
#include "simulation/Simulation.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Tool::Tool(int id, string name, int r, int g, int b):
|
||||||
|
toolID(id),
|
||||||
|
toolName(name),
|
||||||
|
colRed(r),
|
||||||
|
colGreen(g),
|
||||||
|
colBlue(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
string Tool::GetName() { return toolName; }
|
||||||
|
Tool::~Tool() {}
|
||||||
|
void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||||
|
void Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) {
|
||||||
|
sim->ToolBrush(position.X, position.Y, toolID, brush);
|
||||||
|
}
|
||||||
|
void Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
|
||||||
|
}
|
||||||
|
void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
|
||||||
|
}
|
||||||
|
void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {};
|
||||||
|
|
||||||
|
ElementTool::ElementTool(int id, string name, int r, int g, int b):
|
||||||
|
Tool(id, name, r, g, b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
ElementTool::~ElementTool() {}
|
||||||
|
void ElementTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
|
||||||
|
sim->CreateParts(position.X, position.Y, toolID, brush);
|
||||||
|
}
|
||||||
|
void ElementTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
|
||||||
|
}
|
||||||
|
void ElementTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
|
||||||
|
}
|
||||||
|
void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
||||||
|
sim->FloodParts(position.X, position.Y, toolID, -1, -1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WallTool::WallTool(int id, string name, int r, int g, int b):
|
||||||
|
Tool(id, name, r, g, b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
WallTool::~WallTool() {}
|
||||||
|
void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
|
||||||
|
sim->CreateWalls(position.X, position.Y, 1, 1, toolID, 0, brush);
|
||||||
|
}
|
||||||
|
void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush);
|
||||||
|
}
|
||||||
|
void WallTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
|
||||||
|
}
|
||||||
|
void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
||||||
|
sim->FloodWalls(position.X, position.Y, toolID, -1, -1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GolTool::GolTool(int id, string name, int r, int g, int b):
|
||||||
|
Tool(id, name, r, g, b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
GolTool::~GolTool() {}
|
||||||
|
void GolTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
|
||||||
|
sim->CreateParts(position.X, position.Y, PT_LIFE|(toolID<<8), brush);
|
||||||
|
}
|
||||||
|
void GolTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), brush);
|
||||||
|
}
|
||||||
|
void GolTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), 0);
|
||||||
|
}
|
||||||
|
void GolTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
||||||
|
sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
103
src/game/Tool.h
103
src/game/Tool.h
@@ -12,33 +12,25 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#include "interface/Point.h"
|
||||||
|
|
||||||
|
class Simulation;
|
||||||
|
class Brush;
|
||||||
|
|
||||||
class Tool
|
class Tool
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
int toolID;
|
int toolID;
|
||||||
string toolName;
|
string toolName;
|
||||||
public:
|
public:
|
||||||
Tool(int id, string name, int r, int g, int b):
|
Tool(int id, string name, int r, int g, int b);
|
||||||
toolID(id),
|
string GetName();
|
||||||
toolName(name),
|
virtual ~Tool();
|
||||||
colRed(r),
|
virtual void Click(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
colGreen(g),
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
colBlue(b)
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
{
|
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
}
|
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
string GetName() { return toolName; }
|
|
||||||
virtual ~Tool() {}
|
|
||||||
virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { }
|
|
||||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {
|
|
||||||
sim->ToolBrush(position.X, position.Y, toolID, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) {};
|
|
||||||
int colRed, colBlue, colGreen;
|
int colRed, colBlue, colGreen;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,67 +67,34 @@ public:
|
|||||||
class ElementTool: public Tool
|
class ElementTool: public Tool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ElementTool(int id, string name, int r, int g, int b):
|
ElementTool(int id, string name, int r, int g, int b);
|
||||||
Tool(id, name, r, g, b)
|
virtual ~ElementTool();
|
||||||
{
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
}
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
virtual ~ElementTool() {}
|
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){
|
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
sim->CreateParts(position.X, position.Y, toolID, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
|
|
||||||
}
|
|
||||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
|
||||||
sim->FloodParts(position.X, position.Y, toolID, -1, -1, 0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WallTool: public Tool
|
class WallTool: public Tool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WallTool(int id, string name, int r, int g, int b):
|
WallTool(int id, string name, int r, int g, int b);
|
||||||
Tool(id, name, r, g, b)
|
virtual ~WallTool();
|
||||||
{
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
}
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
virtual ~WallTool() {}
|
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){
|
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
sim->CreateWalls(position.X, position.Y, 1, 1, toolID, 0, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush);
|
|
||||||
}
|
|
||||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
|
|
||||||
}
|
|
||||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
|
||||||
sim->FloodWalls(position.X, position.Y, toolID, -1, -1, 0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class GolTool: public Tool
|
class GolTool: public Tool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GolTool(int id, string name, int r, int g, int b):
|
GolTool(int id, string name, int r, int g, int b);
|
||||||
Tool(id, name, r, g, b)
|
virtual ~GolTool();
|
||||||
{
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
}
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
virtual ~GolTool() {}
|
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
|
||||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){
|
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
|
||||||
sim->CreateParts(position.X, position.Y, PT_LIFE|(toolID<<8), brush);
|
|
||||||
}
|
|
||||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), brush);
|
|
||||||
}
|
|
||||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
|
||||||
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), 0);
|
|
||||||
}
|
|
||||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
|
||||||
sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TOOL_H_ */
|
#endif /* TOOL_H_ */
|
||||||
|
Reference in New Issue
Block a user