mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-13 11:54:04 +02:00
Element menu
This commit is contained in:
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@ OBJS := $(patsubst src/%.cpp,build/obj/%.o,$(SOURCES))
|
|||||||
FOLDERS :=
|
FOLDERS :=
|
||||||
|
|
||||||
CFLAGS := -w -Isrc/ -Idata/
|
CFLAGS := -w -Isrc/ -Idata/
|
||||||
OFLAGS := -fkeep-inline-functions #-O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2
|
OFLAGS := -fkeep-inline-functions -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2
|
||||||
|
|
||||||
CPPC := g++
|
CPPC := g++
|
||||||
CPPC_WIN := i686-w64-mingw32-gcc
|
CPPC_WIN := i686-w64-mingw32-gcc
|
||||||
|
@@ -88,7 +88,7 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
|
|||||||
|
|
||||||
void GameController::Tick()
|
void GameController::Tick()
|
||||||
{
|
{
|
||||||
//gameModel->GetSimulation()->update_particles();
|
gameModel->GetSimulation()->update_particles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::SetPaused(bool pauseState)
|
void GameController::SetPaused(bool pauseState)
|
||||||
@@ -96,11 +96,21 @@ void GameController::SetPaused(bool pauseState)
|
|||||||
gameModel->SetPaused(pauseState);
|
gameModel->SetPaused(pauseState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::SetPaused()
|
||||||
|
{
|
||||||
|
gameModel->SetPaused(!gameModel->GetPaused());
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::SetActiveMenu(Menu * menu)
|
void GameController::SetActiveMenu(Menu * menu)
|
||||||
{
|
{
|
||||||
gameModel->SetActiveMenu(menu);
|
gameModel->SetActiveMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::SetActiveTool(Tool * tool)
|
||||||
|
{
|
||||||
|
gameModel->SetActiveTool(tool);
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::OpenSearch()
|
void GameController::OpenSearch()
|
||||||
{
|
{
|
||||||
search = new SearchController();
|
search = new SearchController();
|
||||||
|
@@ -28,7 +28,9 @@ public:
|
|||||||
void DrawPoints(queue<ui::Point*> & pointQueue);
|
void DrawPoints(queue<ui::Point*> & pointQueue);
|
||||||
void Tick();
|
void Tick();
|
||||||
void SetPaused(bool pauseState);
|
void SetPaused(bool pauseState);
|
||||||
|
void SetPaused();
|
||||||
void SetActiveMenu(Menu * menu);
|
void SetActiveMenu(Menu * menu);
|
||||||
|
void SetActiveTool(Tool * tool);
|
||||||
void OpenSearch();
|
void OpenSearch();
|
||||||
void OpenLogin();
|
void OpenLogin();
|
||||||
void OpenTags();
|
void OpenTags();
|
||||||
|
@@ -26,7 +26,7 @@ GameModel::GameModel():
|
|||||||
{
|
{
|
||||||
if(sim->ptypes[i].menusection < 12)
|
if(sim->ptypes[i].menusection < 12)
|
||||||
{
|
{
|
||||||
Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, 0, 0, 0);
|
Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, PIXR(sim->ptypes[i].pcolors), PIXG(sim->ptypes[i].pcolors), PIXB(sim->ptypes[i].pcolors));
|
||||||
menuList[sim->ptypes[i].menusection]->AddTool(tempTool);
|
menuList[sim->ptypes[i].menusection]->AddTool(tempTool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,6 +96,7 @@ Tool * GameModel::GetActiveTool()
|
|||||||
void GameModel::SetActiveTool(Tool * tool)
|
void GameModel::SetActiveTool(Tool * tool)
|
||||||
{
|
{
|
||||||
activeTool = tool;
|
activeTool = tool;
|
||||||
|
notifyActiveToolChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Menu*> GameModel::GetMenuList()
|
vector<Menu*> GameModel::GetMenuList()
|
||||||
@@ -195,3 +196,11 @@ void GameModel::notifyToolListChanged()
|
|||||||
observers[i]->NotifyToolListChanged(this);
|
observers[i]->NotifyToolListChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameModel::notifyActiveToolChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifyActiveToolChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -36,6 +36,7 @@ private:
|
|||||||
void notifyBrushChanged();
|
void notifyBrushChanged();
|
||||||
void notifyMenuListChanged();
|
void notifyMenuListChanged();
|
||||||
void notifyToolListChanged();
|
void notifyToolListChanged();
|
||||||
|
void notifyActiveToolChanged();
|
||||||
public:
|
public:
|
||||||
GameModel();
|
GameModel();
|
||||||
~GameModel();
|
~GameModel();
|
||||||
|
@@ -187,6 +187,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GameView::ToolAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
GameView * v;
|
||||||
|
public:
|
||||||
|
Tool * tool;
|
||||||
|
ToolAction(GameView * _v, Tool * tool_) { v = _v; tool = tool_; }
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->SetActiveTool(tool);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void GameView::NotifyMenuListChanged(GameModel * sender)
|
void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
int currentY = YRES+MENUSIZE-36;
|
int currentY = YRES+MENUSIZE-36;
|
||||||
@@ -216,8 +228,24 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::NotifyActiveToolChanged(GameModel * sender)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < toolButtons.size(); i++)
|
||||||
|
{
|
||||||
|
if(((ToolAction*)toolButtons[i]->GetActionCallback())->tool==sender->GetActiveTool())
|
||||||
|
{
|
||||||
|
toolButtons[i]->SetToggleState(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toolButtons[i]->SetToggleState(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::NotifyToolListChanged(GameModel * sender)
|
void GameView::NotifyToolListChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
|
int currentX = XRES+BARSIZE-56;
|
||||||
for(int i = 0; i < menuButtons.size(); i++)
|
for(int i = 0; i < menuButtons.size(); i++)
|
||||||
{
|
{
|
||||||
if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu())
|
if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu())
|
||||||
@@ -229,6 +257,25 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
|||||||
menuButtons[i]->SetToggleState(false);
|
menuButtons[i]->SetToggleState(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(int i = 0; i < toolButtons.size(); i++)
|
||||||
|
{
|
||||||
|
RemoveComponent(toolButtons[i]);
|
||||||
|
delete toolButtons[i];
|
||||||
|
}
|
||||||
|
toolButtons.clear();
|
||||||
|
vector<Tool*> toolList = sender->GetToolList();
|
||||||
|
for(int i = 0; i < toolList.size(); i++)
|
||||||
|
{
|
||||||
|
ui::Button * tempButton = new ui::Button(ui::Point(currentX, YRES), ui::Point(32, 16), toolList[i]->GetName());
|
||||||
|
currentX -= 36;
|
||||||
|
tempButton->SetTogglable(true);
|
||||||
|
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
|
||||||
|
tempButton->SetBackgroundColour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue);
|
||||||
|
tempButton->SetAlignment(AlignCentre, AlignBottom);
|
||||||
|
AddComponent(tempButton);
|
||||||
|
toolButtons.push_back(tempButton);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::NotifyRendererChanged(GameModel * sender)
|
void GameView::NotifyRendererChanged(GameModel * sender)
|
||||||
@@ -313,6 +360,15 @@ void GameView::OnMouseWheel(int x, int y, int d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
switch(key)
|
||||||
|
{
|
||||||
|
case ' ':
|
||||||
|
c->SetPaused();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::OnTick(float dt)
|
void GameView::OnTick(float dt)
|
||||||
{
|
{
|
||||||
if(!pointQueue.empty())
|
if(!pointQueue.empty())
|
||||||
@@ -327,6 +383,8 @@ void GameView::OnDraw()
|
|||||||
if(ren)
|
if(ren)
|
||||||
{
|
{
|
||||||
ren->render_parts();
|
ren->render_parts();
|
||||||
|
ren->render_fire();
|
||||||
|
ren->render_signs();
|
||||||
}
|
}
|
||||||
if(activeBrush)
|
if(activeBrush)
|
||||||
{
|
{
|
||||||
|
@@ -46,15 +46,18 @@ public:
|
|||||||
void NotifyBrushChanged(GameModel * sender);
|
void NotifyBrushChanged(GameModel * sender);
|
||||||
void NotifyMenuListChanged(GameModel * sender);
|
void NotifyMenuListChanged(GameModel * sender);
|
||||||
void NotifyToolListChanged(GameModel * sender);
|
void NotifyToolListChanged(GameModel * sender);
|
||||||
|
void NotifyActiveToolChanged(GameModel * sender);
|
||||||
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
virtual void OnMouseUp(int x, int y, unsigned button);
|
virtual void OnMouseUp(int x, int y, unsigned button);
|
||||||
virtual void OnMouseWheel(int x, int y, int d);
|
virtual void OnMouseWheel(int x, int y, int d);
|
||||||
|
virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
||||||
//virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {}
|
//virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {}
|
||||||
//virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {}
|
//virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {}
|
||||||
virtual void OnTick(float dt);
|
virtual void OnTick(float dt);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
class MenuAction;
|
class MenuAction;
|
||||||
|
class ToolAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GAMEVIEW_H
|
#endif // GAMEVIEW_H
|
||||||
|
@@ -15,10 +15,10 @@ using namespace std;
|
|||||||
class Tool
|
class Tool
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
int toolID, colRed, colBlue, colGreen;
|
int toolID;
|
||||||
string toolName;
|
string toolName;
|
||||||
public:
|
public:
|
||||||
Tool(int id, string name, int r, int b, int g):
|
Tool(int id, string name, int r, int g, int b):
|
||||||
toolID(id),
|
toolID(id),
|
||||||
toolName(name),
|
toolName(name),
|
||||||
colRed(r),
|
colRed(r),
|
||||||
@@ -26,16 +26,18 @@ public:
|
|||||||
colBlue(b)
|
colBlue(b)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
string GetName() { return toolName; }
|
||||||
virtual ~Tool() {}
|
virtual ~Tool() {}
|
||||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}
|
||||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
|
virtual void 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 DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
|
||||||
|
int colRed, colBlue, colGreen;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ElementTool: public Tool
|
class ElementTool: public Tool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ElementTool(int id, string name, int r, int b, int g):
|
ElementTool(int id, string name, int r, int g, int b):
|
||||||
Tool(id, name, r, g, b)
|
Tool(id, name, r, g, b)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,10 @@ Button::Button(Window* parent_state, std::string buttonText):
|
|||||||
textPosition(ui::Point(0, 0)),
|
textPosition(ui::Point(0, 0)),
|
||||||
textVAlign(AlignMiddle),
|
textVAlign(AlignMiddle),
|
||||||
textHAlign(AlignCentre),
|
textHAlign(AlignCentre),
|
||||||
Enabled(true)
|
Enabled(true),
|
||||||
|
colr(0),
|
||||||
|
colg(0),
|
||||||
|
colb(0)
|
||||||
{
|
{
|
||||||
TextPosition();
|
TextPosition();
|
||||||
}
|
}
|
||||||
@@ -42,7 +45,10 @@ Button::Button(Point position, Point size, std::string buttonText):
|
|||||||
textPosition(ui::Point(0, 0)),
|
textPosition(ui::Point(0, 0)),
|
||||||
textVAlign(AlignMiddle),
|
textVAlign(AlignMiddle),
|
||||||
textHAlign(AlignCentre),
|
textHAlign(AlignCentre),
|
||||||
Enabled(true)
|
Enabled(true),
|
||||||
|
colr(0),
|
||||||
|
colg(0),
|
||||||
|
colb(0)
|
||||||
{
|
{
|
||||||
TextPosition();
|
TextPosition();
|
||||||
}
|
}
|
||||||
@@ -58,7 +64,10 @@ Button::Button(std::string buttonText):
|
|||||||
textPosition(ui::Point(0, 0)),
|
textPosition(ui::Point(0, 0)),
|
||||||
textVAlign(AlignMiddle),
|
textVAlign(AlignMiddle),
|
||||||
textHAlign(AlignCentre),
|
textHAlign(AlignCentre),
|
||||||
Enabled(true)
|
Enabled(true),
|
||||||
|
colr(0),
|
||||||
|
colg(0),
|
||||||
|
colb(0)
|
||||||
{
|
{
|
||||||
TextPosition();
|
TextPosition();
|
||||||
}
|
}
|
||||||
@@ -135,6 +144,8 @@ void Button::Draw(const Point& screenPos)
|
|||||||
{
|
{
|
||||||
if(isMouseInside)
|
if(isMouseInside)
|
||||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
|
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
|
||||||
|
else
|
||||||
|
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, colr, colg, colb, 255);
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,9 @@ public:
|
|||||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||||
VerticalAlignment GetVAlignment() { return textVAlign; }
|
VerticalAlignment GetVAlignment() { return textVAlign; }
|
||||||
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
||||||
|
void SetBackgroundColour(int colr, int colg, int colb) { this->colr = colr; this->colg = colg; this->colb = colb; }
|
||||||
protected:
|
protected:
|
||||||
|
int colr, colg, colb;
|
||||||
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
|
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
|
||||||
ButtonAction * actionCallback;
|
ButtonAction * actionCallback;
|
||||||
ui::Point textPosition;
|
ui::Point textPosition;
|
||||||
|
Reference in New Issue
Block a user