Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Config Tool #589

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a0c4ea3
add config tool for dray
krawthekrow Jul 8, 2018
e97a05e
config tool: clean up warnings
krawthekrow Jul 8, 2018
515f52c
config tool: add cray
krawthekrow Jul 8, 2018
9e33952
config tool: move filt modes to element file
krawthekrow Jul 8, 2018
afdba24
config tool: add filt
krawthekrow Jul 8, 2018
e2f9f90
config tool: add ldtc and dtec
krawthekrow Jul 8, 2018
448fb5c
config tool: add conv
krawthekrow Jul 8, 2018
cb7ad58
config tool: correct off-by-one error in bounds checking
krawthekrow Jul 8, 2018
6dd36de
config tool: use correct default for diagonal check
krawthekrow Jul 8, 2018
f7f7b06
config tool: fix diagonal detection
krawthekrow Jul 8, 2018
21fed8a
config tool: calculate config property only once per frame
krawthekrow Jul 8, 2018
3642bd5
config tool: minor improvements
krawthekrow Jul 8, 2018
89bf560
config tool: don't mutate sample
krawthekrow Jul 8, 2018
692371b
config tool: put config tool in a separate toolset
krawthekrow Jul 14, 2018
5abe4be
config tool: make lines slightly translucent
krawthekrow Jul 14, 2018
59afa1c
config tool: bind middle click to sample
krawthekrow Jul 14, 2018
bdb7fa6
config tool: clean up config tool finding
krawthekrow Jul 14, 2018
7e10ffd
config tool: force selection to bind to left click
krawthekrow Jul 14, 2018
7b751ab
config tool: don't show brush
krawthekrow Jul 14, 2018
806595e
config tool: draw dtec box even when not configuring
krawthekrow Jul 20, 2018
1ceeae2
config tool: formatting improvements
krawthekrow Jul 20, 2018
6e58686
config tool: bind right click to clear tool when not configuring
krawthekrow Jul 21, 2018
22dae0d
config tool: remove need to get simiulation from controller
krawthekrow Jul 21, 2018
87910bd
config tool: use correct brush size when clearing in config mode
krawthekrow Jul 21, 2018
416b04b
config tool: remove cancel option from filt mode select menu
krawthekrow Jul 22, 2018
9907797
config tool: fix indentation in hud code
krawthekrow Jul 22, 2018
5e6de3f
config tool: handle photon map
krawthekrow Aug 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
448 changes: 448 additions & 0 deletions src/gui/game/ConfigTool.cpp

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/gui/game/GameController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,13 +1155,26 @@ void GameController::ActiveToolChanged(int toolSelection, Tool *tool)
commandInterface->OnActiveToolChanged(toolSelection, tool);
}

ConfigTool * GameController::GetActiveConfigTool()
{
Tool * t = GetActiveTool(0);
if(t->GetIdentifier() == "DEFAULT_UI_CONFIG")
return (ConfigTool*)t;
else return NULL;
}

Tool * GameController::GetActiveTool(int selection)
{
return gameModel->GetActiveTool(selection);
}

void GameController::SetActiveTool(int toolSelection, Tool * tool)
{
if(tool->GetIdentifier() == "DEFAULT_UI_CONFIG")
{
((ConfigTool *)tool)->Reset();
toolSelection = 0;
}
if (gameModel->GetActiveMenu() == SC_DECO && toolSelection == 2)
toolSelection = 0;
gameModel->SetActiveTool(toolSelection, tool);
Expand Down Expand Up @@ -1191,6 +1204,14 @@ void GameController::SetLastTool(Tool * tool)
gameModel->SetLastTool(tool);
}

void GameController::ToggleConfigTool()
{
if (GetActiveConfigTool())
gameModel->ResetToolset();
else
SetActiveTool(0, "DEFAULT_UI_CONFIG");
}

int GameController::GetReplaceModeFlags()
{
return gameModel->GetSimulation()->replaceModeFlags;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/game/GameController.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ class GameController: public ClientListener
std::vector<Menu*> GetMenuList();
int GetNumMenus(bool onlyEnabled);
void RebuildFavoritesMenu();
ConfigTool * GetActiveConfigTool();
Tool * GetActiveTool(int selection);
void SetActiveTool(int toolSelection, Tool * tool);
void SetActiveTool(int toolSelection, ByteString identifier);
void SetLastTool(Tool * tool);
void ToggleConfigTool();
int GetReplaceModeFlags();
void SetReplaceModeFlags(int flags);
void ActiveToolChanged(int toolSelection, Tool *tool);
Expand Down
21 changes: 20 additions & 1 deletion src/gui/game/GameModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GameModel::GameModel():
activeTools = regularToolset;

std::fill(decoToolset, decoToolset+4, (Tool*)NULL);
std::fill(configToolset, configToolset+4, (Tool*)NULL);
std::fill(regularToolset, regularToolset+4, (Tool*)NULL);

//Default render prefs
Expand Down Expand Up @@ -327,6 +328,7 @@ void GameModel::BuildMenus()
//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());
menuList[SC_TOOL]->AddTool(new ConfigTool(this));
menuList[SC_TOOL]->AddTool(new SignTool(this));
menuList[SC_TOOL]->AddTool(new SampleTool(this));

Expand All @@ -343,6 +345,13 @@ void GameModel::BuildMenus()
decoToolset[1] = GetToolFromIdentifier("DEFAULT_DECOR_CLR");
decoToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE");
decoToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE");
ConfigTool *configTool = (ConfigTool*)GetToolFromIdentifier("DEFAULT_UI_CONFIG");
configTool->SetClearTool(GetToolFromIdentifier("DEFAULT_PT_NONE"));
configToolset[0] = configTool;
configToolset[1] = &configTool->releaseTool;
// Reserved for more complex configuration
configToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE");
configToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE");

//Set default tools
regularToolset[0] = GetToolFromIdentifier("DEFAULT_PT_DUST");
Expand Down Expand Up @@ -557,7 +566,7 @@ void GameModel::SetActiveMenu(int menuID)
notifyActiveToolsChanged();
}
}
else
else if(activeTools != configToolset)
{
if(activeTools != regularToolset)
{
Expand Down Expand Up @@ -600,10 +609,20 @@ Tool * GameModel::GetActiveTool(int selection)

void GameModel::SetActiveTool(int selection, Tool * tool)
{
if (tool->GetIdentifier() == "DEFAULT_UI_CONFIG")
activeTools = configToolset;
else if (activeTools == configToolset)
activeTools = regularToolset;
activeTools[selection] = tool;
notifyActiveToolsChanged();
}

void GameModel::ResetToolset()
{
activeTools = regularToolset;
notifyActiveToolsChanged();
}

vector<QuickOption*> GameModel::GetQuickOptions()
{
return quickOptions;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/game/GameModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GameModel
Tool ** activeTools;
Tool * decoToolset[4];
Tool * regularToolset[4];
Tool * configToolset[4];
User currentUser;
float toolStrength;
std::deque<Snapshot*> history;
Expand Down Expand Up @@ -145,6 +146,7 @@ class GameModel

Tool * GetActiveTool(int selection);
void SetActiveTool(int selection, Tool * tool);
void ResetToolset();
void SetToolStrength(float value);
float GetToolStrength();
Tool * GetLastTool();
Expand Down
123 changes: 89 additions & 34 deletions src/gui/game/GameView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,10 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)";
buttonTipShow = 120;
}
else
{
c->ToggleConfigTool();
}
break;
case 'x':
if(ctrl)
Expand Down Expand Up @@ -2097,6 +2101,9 @@ void GameView::SetSaveButtonTooltips()

void GameView::OnDraw()
{
ConfigTool * configTool = c->GetActiveConfigTool();
if(configTool)
configTool->CalculatePreview(sample.PositionX, sample.PositionY, sample.particle);
Graphics * g = GetGraphics();
if (ren)
{
Expand Down Expand Up @@ -2158,6 +2165,10 @@ void GameView::OnDraw()
ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y-finalBrushRadius.Y+1, finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-2);
ren->xor_line(finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y-finalBrushRadius.Y+1, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-2);
}
else if(configTool)
{
configTool->DrawHUD(ren);
}
else
{
activeBrush->RenderPoint(ren, finalCurrentMouse);
Expand Down Expand Up @@ -2284,65 +2295,107 @@ void GameView::OnDraw()
StringBuilder sampleInfo;
sampleInfo << Format::Precision(2);

int type = sample.particle.type;
bool isConfiguring = configTool && configTool->IsConfiguring();
Particle samplePart = isConfiguring ?
configTool->GetPart() : sample.particle;

int type = samplePart.type;
if (type)
{
int ctype = sample.particle.ctype;
int ctype = samplePart.ctype;

if (type == PT_PHOT || type == PT_BIZR || type == PT_BIZRG || type == PT_BIZRS || type == PT_FILT || type == PT_BRAY || type == PT_C5)
wavelengthGfx = (ctype&0x3FFFFFFF);

if (showDebug)
if (showDebug || configTool)
{
String lbrace = String::Build("["),
rbrace = String::Build("]"),
noneString = String::Build("");
if (type == PT_LAVA && c->IsValidElement(ctype))
sampleInfo << "Molten " << c->ElementResolve(ctype, -1).FromAscii();
else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype))
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]).FromAscii();
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)samplePart.pavg[1]).FromAscii();
else if (type == PT_LIFE)
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
else if (type == PT_FILT)
{
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
String filtModes[] = {"set colour", "AND", "OR", "subtract colour", "red shift", "blue shift", "no effect", "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"};
if (sample.particle.tmp>=0 && sample.particle.tmp<=11)
sampleInfo << " (" << filtModes[sample.particle.tmp] << ")";
else
sampleInfo << " (unknown mode)";
}
else
{
bool isConfigurable = configTool &&
(configTool->IsConfiguring() ||
ConfigTool::IsConfigurableType(type));
if (isConfigurable)
sampleInfo << lbrace;
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
if (wavelengthGfx)
sampleInfo << " (" << ctype << ")";
// Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2
else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV)
sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)).FromAscii() << ")";
else if (c->IsValidElement(ctype))
sampleInfo << " (" << c->ElementResolve(ctype, -1).FromAscii() << ")";
if (type == PT_FILT)
{
if (samplePart.tmp>=0 && samplePart.tmp<Element_FILT::NUM_MODES)
sampleInfo << " (" << Element_FILT::MODES[samplePart.tmp] << ")";
else
sampleInfo << " (unknown mode)";
}
else
sampleInfo << " ()";
{
if (wavelengthGfx)
sampleInfo << " (" << ctype << ")";
// Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2
else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV)
sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)).FromAscii() << ")";
else if (c->IsValidElement(ctype))
sampleInfo << " (" << c->ElementResolve(ctype, -1).FromAscii() << ")";
else
sampleInfo << " ()";
}
if (isConfigurable)
sampleInfo << rbrace;
}
sampleInfo << ", Temp: " << (sample.particle.temp - 273.15f) << " C";
sampleInfo << ", Life: " << sample.particle.life;
if (sample.particle.type != PT_RFRG && sample.particle.type != PT_RFGL)
bool isConfiguringTemp = configTool &&
configTool->IsConfiguringTemp();
bool isConfiguringLife = configTool &&
configTool->IsConfiguringLife();
bool isConfiguringTmp = configTool &&
configTool->IsConfiguringTmp();
bool isConfiguringTmp2 = configTool &&
configTool->IsConfiguringTmp2();
sampleInfo << ", " <<
(isConfiguringTemp ? lbrace : noneString) <<
"Temp" <<
(isConfiguringTemp ? rbrace : noneString) <<
": " << (samplePart.temp - 273.15f) << " C";
sampleInfo << ", " <<
(isConfiguringLife ? lbrace : noneString) <<
"Life" <<
(isConfiguringLife ? rbrace : noneString) <<
": " << samplePart.life;
if (samplePart.type != PT_RFRG && samplePart.type != PT_RFGL)
{
if (sample.particle.type == PT_CONV)
sampleInfo << ", " <<
(isConfiguringTmp ? lbrace : noneString) <<
"Tmp" <<
(isConfiguringTmp ? rbrace : noneString) <<
": ";
if (samplePart.type == PT_CONV)
{
String elemName = c->ElementResolve(
TYP(sample.particle.tmp),
ID(sample.particle.tmp)).FromAscii();
TYP(samplePart.tmp),
ID(samplePart.tmp)).FromAscii();
if (elemName == "")
sampleInfo << ", Tmp: " << sample.particle.tmp;
sampleInfo << samplePart.tmp;
else
sampleInfo << ", Tmp: " << elemName;
sampleInfo << elemName;
}
else
sampleInfo << ", Tmp: " << sample.particle.tmp;
sampleInfo << samplePart.tmp;
}

// only elements that use .tmp2 show it in the debug HUD
if (type == PT_CRAY || type == PT_DRAY || type == PT_EXOT || type == PT_LIGH || type == PT_SOAP || type == PT_TRON || type == PT_VIBR || type == PT_VIRS || type == PT_WARP || type == PT_LCRY || type == PT_CBNW || type == PT_TSNS || type == PT_DTEC || type == PT_LSNS || type == PT_PSTN || type == PT_LDTC)
sampleInfo << ", Tmp2: " << sample.particle.tmp2;
if (type == PT_CRAY || type == PT_DRAY || type == PT_EXOT || type == PT_LIGH || type == PT_SOAP || type == PT_TRON || type == PT_VIBR || type == PT_VIRS || type == PT_WARP || type == PT_LCRY || type == PT_CBNW || type == PT_TSNS || type == PT_DTEC || type == PT_LSNS || type == PT_PSTN)
{
sampleInfo << ", " <<
(isConfiguringTmp2 ? lbrace : noneString) <<
"Tmp2" <<
(isConfiguringTmp2 ? rbrace : noneString) <<
": " << samplePart.tmp2;
}

sampleInfo << ", Pressure: " << sample.AirPressure;
}
Expand All @@ -2351,12 +2404,12 @@ void GameView::OnDraw()
if (type == PT_LAVA && c->IsValidElement(ctype))
sampleInfo << "Molten " << c->ElementResolve(ctype, -1).FromAscii();
else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype))
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]).FromAscii();
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)samplePart.pavg[1]).FromAscii();
else if (type == PT_LIFE)
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
else
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
sampleInfo << ", Temp: " << sample.particle.temp - 273.15f << " C";
sampleInfo << ", Temp: " << samplePart.temp - 273.15f << " C";
sampleInfo << ", Pressure: " << sample.AirPressure;
}
}
Expand Down Expand Up @@ -2450,6 +2503,8 @@ void GameView::OnDraw()
else
fpsInfo << " Parts: " << sample.NumParts;
}
if (configTool)
fpsInfo << " [CONFIG TOOL]";
if (c->GetReplaceModeFlags()&REPLACE_MODE)
fpsInfo << " [REPLACE MODE]";
if (c->GetReplaceModeFlags()&SPECIFIC_DELETE)
Expand Down