mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-12 19:34:01 +02:00
Begining menu, tool
This commit is contained in:
@@ -50,8 +50,19 @@ void GameController::AdjustBrushSize(int direction)
|
|||||||
void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
|
void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
|
||||||
{
|
{
|
||||||
Simulation * sim = gameModel->GetSimulation();
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
int activeElement = gameModel->GetActiveElement();
|
Tool * activeTool = gameModel->GetActiveTool();
|
||||||
Brush * cBrush = gameModel->GetBrush();
|
Brush * cBrush = gameModel->GetBrush();
|
||||||
|
if(!activeTool || !cBrush)
|
||||||
|
{
|
||||||
|
if(!pointQueue.empty())
|
||||||
|
{
|
||||||
|
while(!pointQueue.empty())
|
||||||
|
{
|
||||||
|
delete pointQueue.front();
|
||||||
|
pointQueue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!pointQueue.empty())
|
if(!pointQueue.empty())
|
||||||
{
|
{
|
||||||
ui::Point * sPoint = NULL;
|
ui::Point * sPoint = NULL;
|
||||||
@@ -61,12 +72,12 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
|
|||||||
pointQueue.pop();
|
pointQueue.pop();
|
||||||
if(sPoint)
|
if(sPoint)
|
||||||
{
|
{
|
||||||
sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0, cBrush);
|
activeTool->DrawLine(sim, cBrush, *fPoint, *sPoint);
|
||||||
delete sPoint;
|
delete sPoint;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0, cBrush);
|
activeTool->Draw(sim, cBrush, *fPoint);
|
||||||
}
|
}
|
||||||
sPoint = fPoint;
|
sPoint = fPoint;
|
||||||
}
|
}
|
||||||
@@ -85,6 +96,11 @@ void GameController::SetPaused(bool pauseState)
|
|||||||
gameModel->SetPaused(pauseState);
|
gameModel->SetPaused(pauseState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::SetActiveMenu(Menu * menu)
|
||||||
|
{
|
||||||
|
gameModel->SetActiveMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::OpenSearch()
|
void GameController::OpenSearch()
|
||||||
{
|
{
|
||||||
search = new SearchController();
|
search = new SearchController();
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "simulation/Simulation.h"
|
#include "simulation/Simulation.h"
|
||||||
#include "search/SearchController.h"
|
#include "search/SearchController.h"
|
||||||
|
#include "Menu.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ 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 SetActiveMenu(Menu * menu);
|
||||||
void OpenSearch();
|
void OpenSearch();
|
||||||
void OpenLogin();
|
void OpenLogin();
|
||||||
void OpenTags();
|
void OpenTags();
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
#include "Brush.h"
|
#include "Brush.h"
|
||||||
|
|
||||||
GameModel::GameModel():
|
GameModel::GameModel():
|
||||||
activeElement(1),
|
activeTool(NULL),
|
||||||
sim(NULL),
|
sim(NULL),
|
||||||
ren(NULL),
|
ren(NULL),
|
||||||
currentSave(NULL),
|
currentSave(NULL),
|
||||||
@@ -15,10 +15,35 @@ GameModel::GameModel():
|
|||||||
{
|
{
|
||||||
sim = new Simulation();
|
sim = new Simulation();
|
||||||
ren = new Renderer(ui::Engine::Ref().g, sim);
|
ren = new Renderer(ui::Engine::Ref().g, sim);
|
||||||
|
|
||||||
|
menuList.clear();
|
||||||
|
for(int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
menuList.push_back(new Menu('q', "Simon"));
|
||||||
|
}
|
||||||
|
//Build menus from Simulation elements
|
||||||
|
for(int i = 0; i < PT_NUM; i++)
|
||||||
|
{
|
||||||
|
if(sim->ptypes[i].menusection < 12)
|
||||||
|
{
|
||||||
|
Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, 0, 0, 0);
|
||||||
|
menuList[sim->ptypes[i].menusection]->AddTool(tempTool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activeTool = new ElementTool(1, "TURD", 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameModel::~GameModel()
|
GameModel::~GameModel()
|
||||||
{
|
{
|
||||||
|
for(int i = 0; i < menuList.size(); i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; i < menuList[i]->GetToolList().size(); i++)
|
||||||
|
{
|
||||||
|
delete menuList[i]->GetToolList()[j];
|
||||||
|
}
|
||||||
|
delete menuList[i];
|
||||||
|
}
|
||||||
delete sim;
|
delete sim;
|
||||||
delete ren;
|
delete ren;
|
||||||
}
|
}
|
||||||
@@ -36,22 +61,53 @@ void GameModel::AddObserver(GameView * observer){
|
|||||||
observer->NotifyPausedChanged(this);
|
observer->NotifyPausedChanged(this);
|
||||||
observer->NotifySaveChanged(this);
|
observer->NotifySaveChanged(this);
|
||||||
observer->NotifyBrushChanged(this);
|
observer->NotifyBrushChanged(this);
|
||||||
|
observer->NotifyMenuListChanged(this);
|
||||||
|
observer->NotifyToolListChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameModel::GetActiveElement()
|
void GameModel::SetActiveMenu(Menu * menu)
|
||||||
{
|
{
|
||||||
return activeElement;
|
for(int i = 0; i < menuList.size(); i++)
|
||||||
|
{
|
||||||
|
if(menuList[i]==menu)
|
||||||
|
{
|
||||||
|
activeMenu = menu;
|
||||||
|
toolList = menu->GetToolList();
|
||||||
|
notifyToolListChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameModel::SetActiveElement(int element)
|
vector<Tool*> GameModel::GetToolList()
|
||||||
{
|
{
|
||||||
activeElement = element;
|
return toolList;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu * GameModel::GetActiveMenu()
|
||||||
|
{
|
||||||
|
return activeMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tool * GameModel::GetActiveTool()
|
||||||
|
{
|
||||||
|
return activeTool;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameModel::SetActiveTool(Tool * tool)
|
||||||
|
{
|
||||||
|
activeTool = tool;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Menu*> GameModel::GetMenuList()
|
||||||
|
{
|
||||||
|
return menuList;
|
||||||
}
|
}
|
||||||
|
|
||||||
Save * GameModel::GetSave()
|
Save * GameModel::GetSave()
|
||||||
{
|
{
|
||||||
return currentSave;
|
return currentSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameModel::SetSave(Save * newSave)
|
void GameModel::SetSave(Save * newSave)
|
||||||
{
|
{
|
||||||
currentSave = newSave;
|
currentSave = newSave;
|
||||||
@@ -123,3 +179,19 @@ void GameModel::notifyBrushChanged()
|
|||||||
observers[i]->NotifyBrushChanged(this);
|
observers[i]->NotifyBrushChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameModel::notifyMenuListChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifyMenuListChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameModel::notifyToolListChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifyToolListChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -8,6 +8,9 @@
|
|||||||
#include "GameView.h"
|
#include "GameView.h"
|
||||||
#include "Brush.h"
|
#include "Brush.h"
|
||||||
|
|
||||||
|
#include "Tool.h"
|
||||||
|
#include "Menu.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class GameView;
|
class GameView;
|
||||||
@@ -18,16 +21,21 @@ class GameModel
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
vector<GameView*> observers;
|
vector<GameView*> observers;
|
||||||
|
vector<Tool*> toolList;
|
||||||
|
vector<Menu*> menuList;
|
||||||
|
Menu * activeMenu;
|
||||||
Brush * currentBrush;
|
Brush * currentBrush;
|
||||||
Save * currentSave;
|
Save * currentSave;
|
||||||
Simulation * sim;
|
Simulation * sim;
|
||||||
Renderer * ren;
|
Renderer * ren;
|
||||||
int activeElement;
|
Tool * activeTool;
|
||||||
void notifyRendererChanged();
|
void notifyRendererChanged();
|
||||||
void notifySimulationChanged();
|
void notifySimulationChanged();
|
||||||
void notifyPausedChanged();
|
void notifyPausedChanged();
|
||||||
void notifySaveChanged();
|
void notifySaveChanged();
|
||||||
void notifyBrushChanged();
|
void notifyBrushChanged();
|
||||||
|
void notifyMenuListChanged();
|
||||||
|
void notifyToolListChanged();
|
||||||
public:
|
public:
|
||||||
GameModel();
|
GameModel();
|
||||||
~GameModel();
|
~GameModel();
|
||||||
@@ -35,11 +43,15 @@ public:
|
|||||||
Brush * GetBrush();
|
Brush * GetBrush();
|
||||||
void SetSave(Save * newSave);
|
void SetSave(Save * newSave);
|
||||||
void AddObserver(GameView * observer);
|
void AddObserver(GameView * observer);
|
||||||
int GetActiveElement();
|
Tool * GetActiveTool();
|
||||||
void SetActiveElement(int element);
|
void SetActiveTool(Tool * tool);
|
||||||
bool GetPaused();
|
bool GetPaused();
|
||||||
void SetPaused(bool pauseState);
|
void SetPaused(bool pauseState);
|
||||||
void ClearSimulation();
|
void ClearSimulation();
|
||||||
|
vector<Menu*> GetMenuList();
|
||||||
|
vector<Tool*> GetToolList();
|
||||||
|
void SetActiveMenu(Menu * menu);
|
||||||
|
Menu * GetActiveMenu();
|
||||||
|
|
||||||
Simulation * GetSimulation();
|
Simulation * GetSimulation();
|
||||||
Renderer * GetRenderer();
|
Renderer * GetRenderer();
|
||||||
|
@@ -175,6 +175,62 @@ GameView::GameView():
|
|||||||
AddComponent(pauseButton);
|
AddComponent(pauseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GameView::MenuAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
GameView * v;
|
||||||
|
public:
|
||||||
|
Menu * menu;
|
||||||
|
MenuAction(GameView * _v, Menu * menu_) { v = _v; menu = menu_; }
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->SetActiveMenu(menu);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||||
|
{
|
||||||
|
int currentY = YRES+MENUSIZE-36;
|
||||||
|
for(int i = 0; i < menuButtons.size(); i++)
|
||||||
|
{
|
||||||
|
RemoveComponent(menuButtons[i]);
|
||||||
|
delete menuButtons[i];
|
||||||
|
}
|
||||||
|
menuButtons.clear();
|
||||||
|
for(int i = 0; i < toolButtons.size(); i++)
|
||||||
|
{
|
||||||
|
RemoveComponent(toolButtons[i]);
|
||||||
|
delete toolButtons[i];
|
||||||
|
}
|
||||||
|
toolButtons.clear();
|
||||||
|
vector<Menu*> menuList = sender->GetMenuList();
|
||||||
|
for(int i = 0; i < menuList.size(); i++)
|
||||||
|
{
|
||||||
|
std::string tempString = "";
|
||||||
|
tempString += menuList[i]->GetIcon();
|
||||||
|
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-18, currentY), ui::Point(16, 16), tempString);
|
||||||
|
tempButton->SetTogglable(true);
|
||||||
|
tempButton->SetActionCallback(new MenuAction(this, menuList[i]));
|
||||||
|
currentY-=18;
|
||||||
|
AddComponent(tempButton);
|
||||||
|
menuButtons.push_back(tempButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::NotifyToolListChanged(GameModel * sender)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < menuButtons.size(); i++)
|
||||||
|
{
|
||||||
|
if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu())
|
||||||
|
{
|
||||||
|
menuButtons[i]->SetToggleState(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menuButtons[i]->SetToggleState(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::NotifyRendererChanged(GameModel * sender)
|
void GameView::NotifyRendererChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
ren = sender->GetRenderer();
|
ren = sender->GetRenderer();
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#ifndef GAMEVIEW_H
|
#ifndef GAMEVIEW_H
|
||||||
#define GAMEVIEW_H
|
#define GAMEVIEW_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
#include "GameModel.h"
|
#include "GameModel.h"
|
||||||
@@ -22,6 +23,8 @@ private:
|
|||||||
Renderer * ren;
|
Renderer * ren;
|
||||||
Brush * activeBrush;
|
Brush * activeBrush;
|
||||||
//UI Elements
|
//UI Elements
|
||||||
|
vector<ui::Button*> menuButtons;
|
||||||
|
vector<ui::Button*> toolButtons;
|
||||||
ui::Button * searchButton;
|
ui::Button * searchButton;
|
||||||
ui::Button * reloadButton;
|
ui::Button * reloadButton;
|
||||||
ui::Button * saveSimulationButton;
|
ui::Button * saveSimulationButton;
|
||||||
@@ -41,6 +44,8 @@ public:
|
|||||||
void NotifyPausedChanged(GameModel * sender);
|
void NotifyPausedChanged(GameModel * sender);
|
||||||
void NotifySaveChanged(GameModel * sender);
|
void NotifySaveChanged(GameModel * sender);
|
||||||
void NotifyBrushChanged(GameModel * sender);
|
void NotifyBrushChanged(GameModel * sender);
|
||||||
|
void NotifyMenuListChanged(GameModel * sender);
|
||||||
|
void NotifyToolListChanged(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);
|
||||||
@@ -49,6 +54,7 @@ public:
|
|||||||
//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;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GAMEVIEW_H
|
#endif // GAMEVIEW_H
|
||||||
|
49
src/game/Menu.h
Normal file
49
src/game/Menu.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Menu.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 22, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MENU_H_
|
||||||
|
#define MENU_H_
|
||||||
|
|
||||||
|
#include "Tool.h"
|
||||||
|
|
||||||
|
class Menu
|
||||||
|
{
|
||||||
|
char icon;
|
||||||
|
string description;
|
||||||
|
vector<Tool*> tools;
|
||||||
|
public:
|
||||||
|
Menu(char icon_, string description_):
|
||||||
|
icon(icon_),
|
||||||
|
description(description_),
|
||||||
|
tools(vector<Tool*>())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Tool*> GetToolList()
|
||||||
|
{
|
||||||
|
return tools;
|
||||||
|
}
|
||||||
|
|
||||||
|
char GetIcon()
|
||||||
|
{
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetDescription()
|
||||||
|
{
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddTool(Tool * tool_)
|
||||||
|
{
|
||||||
|
tools.push_back(tool_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* MENU_H_ */
|
53
src/game/Tool.h
Normal file
53
src/game/Tool.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Tool.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 22, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOOL_H_
|
||||||
|
#define TOOL_H_
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Tool
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
int toolID, colRed, colBlue, colGreen;
|
||||||
|
string toolName;
|
||||||
|
public:
|
||||||
|
Tool(int id, string name, int r, int b, int g):
|
||||||
|
toolID(id),
|
||||||
|
toolName(name),
|
||||||
|
colRed(r),
|
||||||
|
colGreen(g),
|
||||||
|
colBlue(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~Tool() {}
|
||||||
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}
|
||||||
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
|
||||||
|
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ElementTool: public Tool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ElementTool(int id, string name, int r, int b, int g):
|
||||||
|
Tool(id, name, r, g, b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~ElementTool() {}
|
||||||
|
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){
|
||||||
|
sim->create_parts(position.X, position.Y, 1, 1, toolID, 0, brush);
|
||||||
|
}
|
||||||
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
std::cout << position1.X << toolID << brush << std::endl;
|
||||||
|
sim->create_line(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) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* TOOL_H_ */
|
@@ -53,6 +53,7 @@ public:
|
|||||||
inline bool GetToggleState();
|
inline bool GetToggleState();
|
||||||
inline void SetToggleState(bool state);
|
inline void SetToggleState(bool state);
|
||||||
void SetActionCallback(ButtonAction * action);
|
void SetActionCallback(ButtonAction * action);
|
||||||
|
ButtonAction * GetActionCallback() { return actionCallback; }
|
||||||
void TextPosition();
|
void TextPosition();
|
||||||
void SetText(std::string buttonText);
|
void SetText(std::string buttonText);
|
||||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||||
|
Reference in New Issue
Block a user