Tweak replace mode and specific delete mode (fixes #631)

This commit is contained in:
Tamás Bálint Misius 2019-03-30 19:46:58 +01:00
parent 4cf0fe5aab
commit 47f898ca5a
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
4 changed files with 91 additions and 35 deletions

View File

@ -1206,6 +1206,22 @@ int GameController::GetReplaceModeFlags()
void GameController::SetReplaceModeFlags(int flags)
{
int old_flags = gameModel->GetSimulation()->replaceModeFlags;
if (!(old_flags & REPLACE_MODE) && (flags & REPLACE_MODE))
{
// if replace mode has just been enabled, disable specific delete
flags &= ~SPECIFIC_DELETE;
}
if (!(old_flags & SPECIFIC_DELETE) && (flags & SPECIFIC_DELETE))
{
// if specific delete has just been enabled, disable replace mode
flags &= ~REPLACE_MODE;
}
if ((flags & SPECIFIC_DELETE) && (flags & REPLACE_MODE))
{
// if both have just been enabled, arbitrarily disable one of them
flags &= ~SPECIFIC_DELETE;
}
gameModel->GetSimulation()->replaceModeFlags = flags;
}

View File

@ -559,8 +559,12 @@ public:
else
{
if (v->CtrlBehaviour() && v->AltBehaviour() && !v->ShiftBehaviour())
if (tool->GetIdentifier().BeginsWith("DEFAULT_PT_"))
{
if (tool->GetIdentifier().Contains("_PT_"))
{
sender->SetSelectionState(3);
}
}
if (sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3)
v->c->SetActiveTool(sender->GetSelectionState(), tool);

View File

@ -2581,8 +2581,18 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
group = ByteString(lua_tostring(l, 1)).ToUpper();
id = ByteString(lua_tostring(l, 2)).ToUpper();
if(group == "DEFAULT")
return luaL_error(l, "You cannot create elements in the 'default' group.");
if (id.Contains("_"))
{
return luaL_error(l, "The element name may not contain '_'.");
}
if (group.Contains("_"))
{
return luaL_error(l, "The group name may not contain '_'.");
}
if (group == "DEFAULT")
{
return luaL_error(l, "You cannot create elements in the 'DEFAULT' group.");
}
identifier = group + "_PT_" + id;

View File

@ -1601,38 +1601,6 @@ int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags)
return !created;
}
int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
//delete
if (c == 0 && !(flags&REPLACE_MODE))
delete_part(x, y);
//specific delete
else if ((flags&SPECIFIC_DELETE) && !(flags&REPLACE_MODE))
{
if (!replaceModeSelected || TYP(pmap[y][x]) == replaceModeSelected || TYP(photons[y][x]) == replaceModeSelected)
delete_part(x, y);
}
//replace mode
else if (flags&REPLACE_MODE)
{
if (x<0 || y<0 || x>=XRES || y>=YRES)
return 0;
if (replaceModeSelected && TYP(pmap[y][x]) != replaceModeSelected && TYP(photons[y][x]) != replaceModeSelected)
return 0;
if ((pmap[y][x]))
{
delete_part(x, y);
if (c!=0)
create_part(-2, x, y, TYP(c), ID(c));
}
}
//normal draw
else
if (create_part(-2, x, y, TYP(c), ID(c)) == -1)
return 1;
return 0;
}
void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrush, int flags)
{
int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y;
@ -1686,6 +1654,64 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrus
}
}
int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
if (x < 0 || y < 0 || x >= XRES || y >= YRES)
{
return 0;
}
if (flags & REPLACE_MODE)
{
// if replace whatever and there's something to replace
// or replace X and there's a non-energy particle on top with type X
// or replace X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
if (c)
{
part_change_type(photons[y][x] ? ID(photons[y][x]) : ID(pmap[y][x]), x, y, TYP(c));
}
else
{
delete_part(x, y);
}
}
return 0;
}
else if (!c)
{
delete_part(x, y);
return 0;
}
else if (flags & SPECIFIC_DELETE)
{
// if delete whatever and there's something to delete
// or delete X and there's a non-energy particle on top with type X
// or delete X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
delete_part(x, y);
}
return 0;
}
else
{
if (create_part(-2, x, y, TYP(c), ID(c)) == -1)
{
return 1;
}
return 0;
}
// I'm sure at least one compiler exists that would complain if this wasn't here
return 0;
}
//Now simply creates a 0 pixel radius line without all the complicated flags / other checks
void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c)
{