Skip to content
Permalink
Browse files

Make Simulation.IncludePressure pref node accessible from OptionsView

Also remove ugly and messy behaviour depending on whether
shift is being held while copying or stamping.
  • Loading branch information...
LBPHacker committed Jul 9, 2019
1 parent 5391fc3 commit a407aba087a98bc7635e8d707dc555324cf80832
@@ -97,7 +97,7 @@ int main(int argc, char *argv[])

if (gameSave)
{
sim->Load(gameSave);
sim->Load(gameSave, true);

//Render save
ren->decorations_enable = true;
@@ -366,17 +366,13 @@ std::pair<int, sign::Type> GameController::GetSignSplit(int signID)
return gameModel->GetSimulation()->signs[signID].split();
}

void GameController::PlaceSave(ui::Point position, bool includePressure)
void GameController::PlaceSave(ui::Point position)
{
bool incPressure = Client::Ref().GetPrefBool("Simulation.LoadPressure", true);
if (!incPressure)
includePressure = !includePressure;

GameSave *placeSave = gameModel->GetPlaceSave();
if (placeSave)
{
HistorySnapshot();
if (!gameModel->GetSimulation()->Load(position.X, position.Y, placeSave, includePressure))
if (!gameModel->GetSimulation()->Load(placeSave, Client::Ref().GetPrefBool("Simulation.LoadPressure", true), position.X, position.Y))
{
gameModel->SetPaused(placeSave->paused | gameModel->GetPaused());
Client::Ref().MergeStampAuthorInfo(placeSave->authors);
@@ -612,13 +608,9 @@ void GameController::ToolClick(int toolSelection, ui::Point point)
activeTool->Click(sim, cBrush, point);
}

ByteString GameController::StampRegion(ui::Point point1, ui::Point point2, bool includePressure)
ByteString GameController::StampRegion(ui::Point point1, ui::Point point2)
{
bool incPressure = Client::Ref().GetPrefBool("Simulation.IncludePressure", true);
if (!incPressure)
includePressure = !includePressure;

GameSave * newSave = gameModel->GetSimulation()->Save(point1.X, point1.Y, point2.X, point2.Y, includePressure);
GameSave * newSave = gameModel->GetSimulation()->Save(gameModel->GetIncludePressure(), point1.X, point1.Y, point2.X, point2.Y);
if(newSave)
{
newSave->paused = gameModel->GetPaused();
@@ -635,13 +627,9 @@ ByteString GameController::StampRegion(ui::Point point1, ui::Point point2, bool
}
}

void GameController::CopyRegion(ui::Point point1, ui::Point point2, bool includePressure)
void GameController::CopyRegion(ui::Point point1, ui::Point point2)
{
bool incPressure = Client::Ref().GetPrefBool("Simulation.IncludePressure", true);
if (!incPressure)
includePressure = !includePressure;

GameSave * newSave = gameModel->GetSimulation()->Save(point1.X, point1.Y, point2.X, point2.Y, includePressure);
GameSave * newSave = gameModel->GetSimulation()->Save(gameModel->GetIncludePressure(), point1.X, point1.Y, point2.X, point2.Y);
if(newSave)
{
Json::Value clipboardInfo;
@@ -656,9 +644,9 @@ void GameController::CopyRegion(ui::Point point1, ui::Point point2, bool include
}
}

void GameController::CutRegion(ui::Point point1, ui::Point point2, bool includePressure)
void GameController::CutRegion(ui::Point point1, ui::Point point2)
{
CopyRegion(point1, point2, includePressure);
CopyRegion(point1, point2);
gameModel->GetSimulation()->clear_area(point1.X, point1.Y, point2.X-point1.X, point2.Y-point1.Y);
}

@@ -1271,7 +1259,7 @@ void GameController::OpenSearch(String searchText)
void GameController::OpenLocalSaveWindow(bool asCurrent)
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure());
if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
@@ -1490,7 +1478,7 @@ void GameController::OpenSaveWindow()
if(gameModel->GetUser().UserID)
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure());
if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
@@ -1537,7 +1525,7 @@ void GameController::SaveAsCurrent()
if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName())
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure());
if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
@@ -1785,4 +1773,4 @@ void GameController::RunUpdater()
bool GameController::GetMouseClickRequired()
{
return gameModel->GetMouseClickRequired();
}
}
@@ -97,9 +97,9 @@ class GameController: public ClientListener
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);
void DrawFill(int toolSelection, ui::Point point);
ByteString StampRegion(ui::Point point1, ui::Point point2, bool includePressure);
void CopyRegion(ui::Point point1, ui::Point point2, bool includePressure);
void CutRegion(ui::Point point1, ui::Point point2, bool includePressure);
ByteString StampRegion(ui::Point point1, ui::Point point2);
void CopyRegion(ui::Point point1, ui::Point point2);
void CutRegion(ui::Point point1, ui::Point point2);
void Update();
void SetPaused(bool pauseState);
void SetPaused();
@@ -141,7 +141,7 @@ class GameController: public ClientListener
void OpenStamps();
void OpenElementSearch();
void OpenColourPicker();
void PlaceSave(ui::Point position, bool includePressure);
void PlaceSave(ui::Point position);
void ClearSim();
void ReloadSim();
void Vote(int direction);
@@ -155,6 +155,7 @@ GameModel::GameModel():
undoHistoryLimit = 200;

mouseClickRequired = Client::Ref().GetPrefBool("MouseClickRequired", false);
includePressure = Client::Ref().GetPrefBool("Simulation.IncludePressure", true);
}

GameModel::~GameModel()
@@ -185,6 +186,7 @@ GameModel::~GameModel()
Client::Ref().SetPref("Simulation.UndoHistoryLimit", undoHistoryLimit);

Client::Ref().SetPref("MouseClickRequired", mouseClickRequired);
Client::Ref().SetPref("Simulation.IncludePressure", includePressure);

Favorite::Ref().SaveFavoritesToPrefs();

@@ -662,7 +664,7 @@ void GameModel::SetSave(SaveInfo * newSave)
sim->grav->stop_grav_async();
sim->clear_sim();
ren->ClearAccumulation();
if (!sim->Load(saveData))
if (!sim->Load(saveData, GetIncludePressure()))
{
// This save was created before logging existed
// Add in the correct info
@@ -727,7 +729,7 @@ void GameModel::SetSaveFile(SaveFile * newSave)
}
sim->clear_sim();
ren->ClearAccumulation();
if (!sim->Load(saveData))
if (!sim->Load(saveData, GetIncludePressure()))
{
Client::Ref().OverwriteAuthorInfo(saveData->authors);
}
@@ -1307,4 +1309,14 @@ bool GameModel::GetMouseClickRequired()
void GameModel::SetMouseClickRequired(bool mouseClickRequired_)
{
mouseClickRequired = mouseClickRequired_;
}
}

bool GameModel::GetIncludePressure()
{
return includePressure;
}

void GameModel::SetIncludePressure(bool includePressure_)
{
includePressure = includePressure_;
}
@@ -68,6 +68,7 @@ class GameModel
unsigned int historyPosition;
unsigned int undoHistoryLimit;
bool mouseClickRequired;
bool includePressure;

size_t activeColourPreset;
std::vector<ui::Colour> colourPresets;
@@ -204,7 +205,9 @@ class GameModel
GameSave * GetClipboard();
GameSave * GetPlaceSave();
bool GetMouseClickRequired();
void SetMouseClickRequired(bool mouseClickRequired_);
void SetMouseClickRequired(bool mouseClickRequired);
bool GetIncludePressure();
void SetIncludePressure(bool includePressure);

std::vector<Notification*> GetNotifications();
void AddNotification(Notification * notification);
@@ -1274,7 +1274,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
if (thumbY+(placeSaveThumb->Height) >= YRES)
thumbY = YRES-placeSaveThumb->Height;

c->PlaceSave(ui::Point(thumbX, thumbY), !shiftBehaviour);
c->PlaceSave(ui::Point(thumbX, thumbY));
}
}
else
@@ -1284,11 +1284,11 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
int x1 = (selectPoint2.X<selectPoint1.X) ? selectPoint2.X : selectPoint1.X;
int y1 = (selectPoint2.Y<selectPoint1.Y) ? selectPoint2.Y : selectPoint1.Y;
if (selectMode ==SelectCopy)
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2), !shiftBehaviour);
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2));
else if (selectMode == SelectCut)
c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2), !shiftBehaviour);
c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2));
else if (selectMode == SelectStamp)
c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2), !shiftBehaviour);
c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2));
}
}
selectMode = SelectNone;
@@ -97,6 +97,11 @@ void OptionsController::SetMouseClickrequired(bool mouseClickRequired)
model->SetMouseClickRequired(mouseClickRequired);
}

void OptionsController::SetIncludePressure(bool includePressure)
{
model->SetIncludePressure(includePressure);
}

void OptionsController::Exit()
{
view->CloseActiveWindow();
@@ -29,6 +29,7 @@ class OptionsController
void SetFastQuit(bool fastquit);
void SetShowAvatars(bool showAvatars);
void SetMouseClickrequired(bool mouseClickRequired);
void SetIncludePressure(bool includePressure);

void Exit();
OptionsView * GetView();
@@ -192,6 +192,18 @@ void OptionsModel::SetMouseClickRequired(bool mouseClickRequired)
notifySettingsChanged();
}

bool OptionsModel::GetIncludePressure()
{
return Client::Ref().GetPrefBool("Simulation.IncludePressure", true);
}

void OptionsModel::SetIncludePressure(bool includePressure)
{
Client::Ref().SetPref("Simulation.IncludePressure", includePressure);
gModel->SetIncludePressure(includePressure);
notifySettingsChanged();
}

void OptionsModel::notifySettingsChanged()
{
for (size_t i = 0; i < observers.size(); i++)
@@ -45,6 +45,8 @@ class OptionsModel
void SetFastQuit(bool fastquit);
bool GetMouseClickRequired();
void SetMouseClickRequired(bool mouseClickRequired);
bool GetIncludePressure();
void SetIncludePressure(bool includePressure);
virtual ~OptionsModel();
};

@@ -397,6 +397,26 @@ OptionsView::OptionsView():
scrollPanel->AddChild(tempLabel);
scrollPanel->AddChild(mouseClickRequired);

class IncludePressureAction: public ui::CheckboxAction
{
OptionsView * v;
public:
IncludePressureAction(OptionsView * v_){ v = v_; }
void ActionCallback(ui::Checkbox * sender) override {
v->c->SetIncludePressure(sender->GetChecked());
}
};
currentY+=20;
includePressure = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Include Pressure", "");
autowidth(includePressure);
includePressure->SetActionCallback(new IncludePressureAction(this));
tempLabel = new ui::Label(ui::Point(includePressure->Position.X+Graphics::textwidth(includePressure->GetText())+20, currentY), ui::Point(1, 16), "\bg- When saving, loading, stamping, etc.");
autowidth(tempLabel);
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
scrollPanel->AddChild(tempLabel);
scrollPanel->AddChild(includePressure);

class DataFolderAction: public ui::ButtonAction
{
public:
@@ -466,6 +486,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
fastquit->SetChecked(sender->GetFastQuit());
showAvatars->SetChecked(sender->GetShowAvatars());
mouseClickRequired->SetChecked(sender->GetMouseClickRequired());
includePressure->SetChecked(sender->GetIncludePressure());
}

void OptionsView::AttachController(OptionsController * c_)
@@ -31,6 +31,7 @@ class OptionsView: public ui::Window
ui::Checkbox * fastquit;
ui::Checkbox * showAvatars;
ui::Checkbox * mouseClickRequired;
ui::Checkbox * includePressure;
ui::ScrollPanel * scrollPanel;
public:
OptionsView();
@@ -1654,8 +1654,7 @@ int LuaScriptInterface::simulation_saveStamp(lua_State * l)
int y = luaL_optint(l,2,0);
int w = luaL_optint(l,3,XRES-1);
int h = luaL_optint(l,4,YRES-1);
int includePressure = luaL_optint(l,5,1);
ByteString name = luacon_controller->StampRegion(ui::Point(x, y), ui::Point(x+w, y+h), includePressure);
ByteString name = luacon_controller->StampRegion(ui::Point(x, y), ui::Point(x+w, y+h));
lua_pushstring(l, name.c_str());
return 1;
}
@@ -1666,7 +1665,6 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l)
SaveFile * tempfile = NULL;
int x = luaL_optint(l,2,0);
int y = luaL_optint(l,3,0);
int includePressure = luaL_optint(l,4,1);
if (lua_isstring(l, 1)) //Load from 10 char name, or full filename
{
const char * filename = luaL_optstring(l, 1, "");
@@ -1683,7 +1681,7 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l)

if (tempfile)
{
if (!luacon_sim->Load(x, y, tempfile->GetGameSave(), includePressure))
if (!luacon_sim->Load(tempfile->GetGameSave(), luacon_model->GetIncludePressure(), x, y))
{
//luacon_sim->sys_pause = (tempfile->GetGameSave()->paused | luacon_model->GetPaused())?1:0;
lua_pushinteger(l, 1);
@@ -46,7 +46,7 @@ VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
g->Clear();
sim->clear_sim();

if(!sim->Load(save))
if(!sim->Load(save, true))
{
ren->decorations_enable = true;
ren->blackDecorations = !decorations;
@@ -37,10 +37,10 @@

int Simulation::Load(GameSave * save, bool includePressure)
{
return Load(0, 0, save, includePressure);
return Load(save, includePressure, 0, 0);
}

int Simulation::Load(int fullX, int fullY, GameSave * save, bool includePressure)
int Simulation::Load(GameSave * save, bool includePressure, int fullX, int fullY)
{
int x, y, r;

@@ -325,10 +325,10 @@ int Simulation::Load(int fullX, int fullY, GameSave * save, bool includePressure

GameSave * Simulation::Save(bool includePressure)
{
return Save(0, 0, XRES-1, YRES-1, includePressure);
return Save(includePressure, 0, 0, XRES-1, YRES-1);
}

GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2, bool includePressure)
GameSave * Simulation::Save(bool includePressure, int fullX, int fullY, int fullX2, int fullY2)
{
int blockX, blockY, blockX2, blockY2, blockW, blockH;
//Normalise incoming coords
@@ -114,10 +114,10 @@ class Simulation
int sandcolour;
int sandcolour_frame;

int Load(GameSave * save, bool includePressure = true);
int Load(int x, int y, GameSave * save, bool includePressure = true);
GameSave * Save(bool includePressure = true);
GameSave * Save(int x1, int y1, int x2, int y2, bool includePressure = true);
int Load(GameSave * save, bool includePressure);
int Load(GameSave * save, bool includePressure, int x, int y);
GameSave * Save(bool includePressure);
GameSave * Save(bool includePressure, int x1, int y1, int x2, int y2);
void SaveSimOptions(GameSave * gameSave);
SimulationSample GetSample(int x, int y);

0 comments on commit a407aba

Please sign in to comment.
You can’t perform that action at this time.