mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 14:28:30 +01:00
Sample tool, fixes #122
This commit is contained in:
parent
be42cec498
commit
6500923aa5
14
data/font.h
14
data/font.h
@ -232,9 +232,9 @@ char font_data[] = {
|
||||
0x0A, 0x00, 0x00, 0xC0, 0x00, 0x00, 0xFF, 0x86, 0xC0, 0x00, 0x2C, 0x40, 0xFE, 0x0B, 0xE4, 0xBF, 0x0C, 0xC0, 0xF2, 0x6F, 0x08, 0x0C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0A, 0x00, 0x05, 0x00, 0xF4, 0x01, 0xC0, 0x30, 0x00, 0x0D, 0x07, 0xF0, 0xF0, 0x40, 0x5F, 0x1F, 0xFC, 0xFA, 0xD3, 0xFF, 0x7F, 0xFF, 0xF0, 0xDF, 0xFF, 0x7F,
|
||||
0x0C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1E, 0x00, 0x80, 0x07, 0x00, 0xE0, 0x01, 0x00, 0x78, 0x60, 0x00, 0x24, 0x98, 0x01, 0x80, 0x42, 0x06, 0x00, 0x00, 0x19, 0x00, 0x00, 0x04,
|
||||
0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x00, 0xC3, 0x00, 0x30, 0x0D, 0x00, 0xFD, 0x01, 0x00, 0x74, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x0A, 0x00, 0x00, 0x40, 0x7F, 0x00, 0x5C, 0x0D, 0xC0, 0xC1, 0x00, 0x1C, 0x0C, 0x40, 0xFF, 0x01, 0x00, 0x74, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0A, 0x00, 0x00, 0x01, 0x00, 0x68, 0x00, 0xA2, 0x02, 0x80, 0x0A, 0x00, 0x25, 0x00, 0x44, 0x08, 0x10, 0x01, 0x40, 0x04, 0x00, 0x14, 0x00, 0x10, 0x00, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x03, 0x08, 0x00, 0x00,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
@ -289,10 +289,10 @@ short font_ptrs[] = {
|
||||
0x0D7A, 0x0D94, 0x0DAE, 0x0DC8, 0x0DE2, 0x0DFC, 0x0E16, 0x0E30,
|
||||
0x0E48, 0x0E62, 0x0E7C, 0x0E96, 0x0EB0, 0x0ECA, 0x0EE4, 0x0EFE,
|
||||
0x0F18, 0x0F26, 0x0F3B, 0x0F53, 0x0F6D, 0x0F87, 0x0FA1, 0x0FBB,
|
||||
0x0FD5, 0x0FF2, 0x100C, 0x1026, 0x1040, 0x105F, 0x1079, 0x1089,
|
||||
0x1099, 0x10A9, 0x10B9, 0x10C9, 0x10D7, 0x10E7, 0x10F7, 0x1107,
|
||||
0x1117, 0x1127, 0x1137, 0x1147, 0x1157, 0x1167, 0x1177, 0x1187,
|
||||
0x1197, 0x11A7, 0x11B7, 0x11C7, 0x11D7, 0x11E7, 0x11F7, 0x1207,
|
||||
0x0FD5, 0x0FF2, 0x100C, 0x1026, 0x1040, 0x105F, 0x1079, 0x1093,
|
||||
0x10A3, 0x10B3, 0x10C3, 0x10D3, 0x10E1, 0x10F1, 0x1101, 0x1111,
|
||||
0x1121, 0x1131, 0x1141, 0x1151, 0x1161, 0x1171, 0x1181, 0x1191,
|
||||
0x11A1, 0x11B1, 0x11C1, 0x11D1, 0x11E1, 0x11F1, 0x1201, 0x1211,
|
||||
};
|
||||
#else
|
||||
extern char font_data[];
|
||||
|
@ -109,6 +109,10 @@ GameModel::~GameModel()
|
||||
{
|
||||
delete menuList[i];
|
||||
}
|
||||
for(std::vector<Tool*>::iterator iter = extraElementTools.begin(), end = extraElementTools.end(); iter != end; ++iter)
|
||||
{
|
||||
delete *iter;
|
||||
}
|
||||
for(int i = 0; i < brushList.size(); i++)
|
||||
{
|
||||
delete brushList[i];
|
||||
@ -163,6 +167,13 @@ void GameModel::BuildMenus()
|
||||
menuList.clear();
|
||||
toolList.clear();
|
||||
|
||||
for(std::vector<Tool*>::iterator iter = extraElementTools.begin(), end = extraElementTools.end(); iter != end; ++iter)
|
||||
{
|
||||
delete *iter;
|
||||
}
|
||||
extraElementTools.clear();
|
||||
elementTools.clear();
|
||||
|
||||
//Create menus
|
||||
for(int i = 0; i < SC_TOTAL; i++)
|
||||
{
|
||||
@ -172,7 +183,7 @@ void GameModel::BuildMenus()
|
||||
//Build menus from Simulation elements
|
||||
for(int i = 0; i < PT_NUM; i++)
|
||||
{
|
||||
if(sim->elements[i].MenuSection < 12 && sim->elements[i].Enabled && sim->elements[i].MenuVisible)
|
||||
if(sim->elements[i].Enabled)
|
||||
{
|
||||
Tool * tempTool;
|
||||
if(i == PT_LIGH)
|
||||
@ -191,8 +202,17 @@ void GameModel::BuildMenus()
|
||||
{
|
||||
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].IconGenerator);
|
||||
}
|
||||
|
||||
if(sim->elements[i].MenuSection < 12 && sim->elements[i].MenuVisible)
|
||||
{
|
||||
menuList[sim->elements[i].MenuSection]->AddTool(tempTool);
|
||||
}
|
||||
else
|
||||
{
|
||||
extraElementTools.push_back(tempTool);
|
||||
}
|
||||
elementTools.push_back(tempTool);
|
||||
}
|
||||
}
|
||||
|
||||
//Build menu for GOL types
|
||||
@ -211,6 +231,7 @@ void GameModel::BuildMenus()
|
||||
}
|
||||
|
||||
//Add special sign and prop tools
|
||||
menuList[SC_TOOL]->AddTool(new SampleTool(this));
|
||||
menuList[SC_TOOL]->AddTool(new SignTool());
|
||||
menuList[SC_TOOL]->AddTool(new PropertyTool());
|
||||
menuList[SC_TOOL]->AddTool(new WindTool(0, "WIND", "Create air movement", 64, 64, 64));
|
||||
@ -240,7 +261,7 @@ void GameModel::BuildMenus()
|
||||
//Set default tools
|
||||
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
|
||||
activeTools[1] = menuList[SC_SPECIAL]->GetToolList()[0];
|
||||
activeTools[2] = NULL;
|
||||
activeTools[2] = menuList[SC_TOOL]->GetToolList()[0];
|
||||
lastTool = activeTools[0];
|
||||
|
||||
//Set default menu
|
||||
@ -347,6 +368,17 @@ Menu * GameModel::GetActiveMenu()
|
||||
return activeMenu;
|
||||
}
|
||||
|
||||
Tool * GameModel::GetElementTool(int elementID)
|
||||
{
|
||||
std::cout << elementID << std::endl;
|
||||
for(std::vector<Tool*>::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter)
|
||||
{
|
||||
if((*iter)->GetToolID() == elementID)
|
||||
return *iter;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Tool * GameModel::GetActiveTool(int selection)
|
||||
{
|
||||
return activeTools[selection];
|
||||
|
@ -43,6 +43,12 @@ private:
|
||||
deque<string> consoleLog;
|
||||
vector<GameView*> observers;
|
||||
vector<Tool*> toolList;
|
||||
|
||||
//All tools that are associated with elements
|
||||
vector<Tool*> elementTools;
|
||||
//Tools that are present in elementTools, but don't have an associated menu and need to be freed manually
|
||||
vector<Tool*> extraElementTools;
|
||||
|
||||
vector<Menu*> menuList;
|
||||
vector<QuickOption*> quickOptions;
|
||||
Menu * activeMenu;
|
||||
@ -118,8 +124,13 @@ public:
|
||||
void SetSave(SaveInfo * newSave);
|
||||
void SetSaveFile(SaveFile * newSave);
|
||||
void AddObserver(GameView * observer);
|
||||
|
||||
//Get an element tool from an element ID
|
||||
Tool * GetElementTool(int elementID);
|
||||
|
||||
Tool * GetActiveTool(int selection);
|
||||
void SetActiveTool(int selection, Tool * tool);
|
||||
|
||||
bool GetPaused();
|
||||
void SetPaused(bool pauseState);
|
||||
bool GetDecoration();
|
||||
|
36
src/game/SampleTool.cpp
Normal file
36
src/game/SampleTool.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include "graphics/Graphics.h"
|
||||
#include "Tool.h"
|
||||
#include "GameModel.h"
|
||||
|
||||
VideoBuffer * SampleTool::GetIcon(int toolID, int width, int height)
|
||||
{
|
||||
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->SetCharacter((width/2)-5, (height/2)-5, 0xE6, 255, 255, 255, 255);
|
||||
newTexture->BlendCharacter((width/2)-5, (height/2)-5, 0xE7, 100, 180, 255, 255);
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
void SampleTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
|
||||
{
|
||||
int particleType = 0;
|
||||
if(sim->pmap[position.Y][position.X])
|
||||
particleType = sim->parts[sim->pmap[position.Y][position.X]>>8].type;
|
||||
else if(sim->photons[position.Y][position.X])
|
||||
particleType = sim->parts[sim->photons[position.Y][position.X]>>8].type;
|
||||
|
||||
if(particleType)
|
||||
{
|
||||
Tool * elementTool = gameModel->GetElementTool(particleType);
|
||||
if(elementTool)
|
||||
gameModel->SetActiveTool(0, elementTool);
|
||||
}
|
||||
}
|
@ -269,7 +269,7 @@ VideoBuffer * SignTool::GetIcon(int toolID, int width, int height)
|
||||
}
|
||||
}
|
||||
newTexture->SetCharacter((width/2)-5, (height/2)-5, 0xA1, 32, 64, 128, 255);
|
||||
newTexture->SetCharacter((width/2)-5, (height/2)-5, 0xA0, 255, 255, 255, 255);
|
||||
newTexture->BlendCharacter((width/2)-5, (height/2)-5, 0xA0, 255, 255, 255, 255);
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ protected:
|
||||
int resolution;
|
||||
public:
|
||||
Tool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
int GetToolID() { return toolID; }
|
||||
string GetName();
|
||||
string GetDescription();
|
||||
int GetResolution() { return resolution; }
|
||||
@ -61,6 +62,26 @@ public:
|
||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||
};
|
||||
|
||||
class GameModel;
|
||||
|
||||
class SampleTool: public Tool
|
||||
{
|
||||
GameModel * gameModel;
|
||||
public:
|
||||
SampleTool(GameModel * model):
|
||||
Tool(0, "SMPL", "Sample an element on the screen", 0, 0, 0, SampleTool::GetIcon),
|
||||
gameModel(model)
|
||||
{
|
||||
}
|
||||
static VideoBuffer * GetIcon(int toolID, int width, int height);
|
||||
virtual ~SampleTool() {}
|
||||
virtual void Click(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, bool dragging = false) { }
|
||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
|
||||
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||
};
|
||||
|
||||
class PropertyTool: public Tool
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user