Wall Edge option, fixes #70
This commit is contained in:
parent
30f8049efc
commit
4ce22e4e77
@ -1692,6 +1692,34 @@ int Client::GetPrefInteger(std::string property, int defaultValue)
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
unsigned int Client::GetPrefUInteger(std::string property, unsigned int defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::stringstream defHexInt;
|
||||
defHexInt << std::hex << defaultValue;
|
||||
|
||||
std::string hexString = GetPrefString(property, defHexInt.str());
|
||||
unsigned int finalValue = defaultValue;
|
||||
|
||||
std::stringstream hexInt;
|
||||
hexInt << hexString;
|
||||
|
||||
hexInt >> std::hex >> finalValue;
|
||||
|
||||
return finalValue;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
catch(exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
vector<string> Client::GetPrefStringArray(std::string property)
|
||||
{
|
||||
try
|
||||
@ -1780,6 +1808,40 @@ vector<int> Client::GetPrefIntegerArray(std::string property)
|
||||
return vector<int>();
|
||||
}
|
||||
|
||||
vector<unsigned int> Client::GetPrefUIntegerArray(std::string property)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::Array value = GetPref(property);
|
||||
vector<unsigned int> intArray;
|
||||
for(json::Array::iterator iter = value.Begin(); iter != value.End(); ++iter)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::String cValue = *iter;
|
||||
unsigned int finalValue = 0;
|
||||
|
||||
std::string hexString = cValue.Value();
|
||||
std::stringstream hexInt;
|
||||
hexInt << std::hex << hexString;
|
||||
hexInt >> finalValue;
|
||||
|
||||
intArray.push_back(finalValue);
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return intArray;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
return vector<unsigned int>();
|
||||
}
|
||||
|
||||
vector<bool> Client::GetPrefBoolArray(std::string property)
|
||||
{
|
||||
try
|
||||
@ -1841,6 +1903,14 @@ void Client::SetPref(std::string property, int value)
|
||||
SetPref(property, intValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, unsigned int value)
|
||||
{
|
||||
std::stringstream hexInt;
|
||||
hexInt << std::hex << value;
|
||||
json::UnknownElement intValue = json::String(hexInt.str());
|
||||
SetPref(property, intValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, vector<string> value)
|
||||
{
|
||||
json::Array newArray;
|
||||
@ -1888,6 +1958,20 @@ void Client::SetPref(std::string property, vector<int> value)
|
||||
SetPref(property, newArrayValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, vector<unsigned int> value)
|
||||
{
|
||||
json::Array newArray;
|
||||
for(vector<unsigned int>::iterator iter = value.begin(); iter != value.end(); ++iter)
|
||||
{
|
||||
std::stringstream hexInt;
|
||||
hexInt << std::hex << *iter;
|
||||
|
||||
newArray.Insert(json::String(hexInt.str()));
|
||||
}
|
||||
json::UnknownElement newArrayValue = newArray;
|
||||
SetPref(property, newArrayValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, bool value)
|
||||
{
|
||||
json::UnknownElement boolValue = json::Boolean(value);
|
||||
|
@ -133,18 +133,22 @@ public:
|
||||
std::string GetPrefString(std::string property, std::string defaultValue);
|
||||
double GetPrefNumber(std::string property, double defaultValue);
|
||||
int GetPrefInteger(std::string property, int defaultValue);
|
||||
unsigned int GetPrefUInteger(std::string property, unsigned int defaultValue);
|
||||
vector<string> GetPrefStringArray(std::string property);
|
||||
vector<double> GetPrefNumberArray(std::string property);
|
||||
vector<int> GetPrefIntegerArray(std::string property);
|
||||
vector<unsigned int> GetPrefUIntegerArray(std::string property);
|
||||
vector<bool> GetPrefBoolArray(std::string property);
|
||||
bool GetPrefBool(std::string property, bool defaultValue);
|
||||
|
||||
void SetPref(std::string property, std::string value);
|
||||
void SetPref(std::string property, double value);
|
||||
void SetPref(std::string property, int value);
|
||||
void SetPref(std::string property, unsigned int value);
|
||||
void SetPref(std::string property, vector<string> value);
|
||||
void SetPref(std::string property, vector<double> value);
|
||||
void SetPref(std::string property, vector<int> value);
|
||||
void SetPref(std::string property, vector<unsigned int> value);
|
||||
void SetPref(std::string property, vector<bool> value);
|
||||
void SetPref(std::string property, bool value);
|
||||
|
||||
|
@ -33,16 +33,16 @@ GameModel::GameModel():
|
||||
//Load config into renderer
|
||||
try
|
||||
{
|
||||
ren->SetColourMode(Client::Ref().GetPrefNumber("Renderer.ColourMode", 0));
|
||||
ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0));
|
||||
|
||||
vector<double> tempArray = Client::Ref().GetPrefNumberArray("Renderer.DisplayModes");
|
||||
vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes");
|
||||
if(tempArray.size())
|
||||
{
|
||||
std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end());
|
||||
ren->SetDisplayMode(displayModes);
|
||||
}
|
||||
|
||||
tempArray = Client::Ref().GetPrefNumberArray("Renderer.RenderModes");
|
||||
tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes");
|
||||
if(tempArray.size())
|
||||
{
|
||||
std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end());
|
||||
@ -54,6 +54,9 @@ GameModel::GameModel():
|
||||
|
||||
}
|
||||
|
||||
//Load config into simulation
|
||||
sim->SetEdgeMode(Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0));
|
||||
|
||||
//Load last user
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
{
|
||||
@ -84,13 +87,15 @@ GameModel::GameModel():
|
||||
GameModel::~GameModel()
|
||||
{
|
||||
//Save to config:
|
||||
Client::Ref().SetPref("Renderer.ColourMode", (double)ren->GetColourMode());
|
||||
Client::Ref().SetPref("Renderer.ColourMode", ren->GetColourMode());
|
||||
|
||||
std::vector<unsigned int> displayModes = ren->GetDisplayMode();
|
||||
Client::Ref().SetPref("Renderer.DisplayModes", std::vector<double>(displayModes.begin(), displayModes.end()));
|
||||
Client::Ref().SetPref("Renderer.DisplayModes", std::vector<unsigned int>(displayModes.begin(), displayModes.end()));
|
||||
|
||||
std::vector<unsigned int> renderModes = ren->GetRenderMode();
|
||||
Client::Ref().SetPref("Renderer.RenderModes", std::vector<double>(renderModes.begin(), renderModes.end()));
|
||||
Client::Ref().SetPref("Renderer.RenderModes", std::vector<unsigned int>(renderModes.begin(), renderModes.end()));
|
||||
|
||||
Client::Ref().SetPref("Simulation.EdgeMode", sim->edgeMode);
|
||||
|
||||
Client::Ref().SetPref("Decoration.Red", (int)colour.Red);
|
||||
Client::Ref().SetPref("Decoration.Green", (int)colour.Green);
|
||||
|
@ -46,6 +46,10 @@ void OptionsController::SetAirMode(int airMode)
|
||||
{
|
||||
model->SetAirMode(airMode);
|
||||
}
|
||||
void OptionsController::SetEdgeMode(int airMode)
|
||||
{
|
||||
model->SetEdgeMode(airMode);
|
||||
}
|
||||
|
||||
OptionsView * OptionsController::GetView()
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
void SetWaterEqualisation(bool state);
|
||||
void SetGravityMode(int gravityMode);
|
||||
void SetAirMode(int airMode);
|
||||
void SetEdgeMode(int airMode);
|
||||
void Exit();
|
||||
OptionsView * GetView();
|
||||
virtual ~OptionsController();
|
||||
|
@ -75,6 +75,16 @@ void OptionsModel::SetAirMode(int airMode)
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
int OptionsModel::GetEdgeMode()
|
||||
{
|
||||
return sim->edgeMode;
|
||||
}
|
||||
void OptionsModel::SetEdgeMode(int edgeMode)
|
||||
{
|
||||
sim->SetEdgeMode(edgeMode);
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
int OptionsModel::GetGravityMode()
|
||||
{
|
||||
return sim->gravityMode;
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
void SetWaterEqualisation(bool state);
|
||||
int GetAirMode();
|
||||
void SetAirMode(int airMode);
|
||||
int GetEdgeMode();
|
||||
void SetEdgeMode(int edgeMode);
|
||||
int GetGravityMode();
|
||||
void SetGravityMode(int gravityMode);
|
||||
virtual ~OptionsModel();
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "interface/DropDown.h"
|
||||
|
||||
OptionsView::OptionsView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(300, 206)){
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(300, 226)){
|
||||
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options");
|
||||
tempLabel->SetTextColour(style::Colour::InformationTitle);
|
||||
@ -118,6 +118,24 @@ OptionsView::OptionsView():
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class EdgeModeChanged: public ui::DropDownAction
|
||||
{
|
||||
OptionsView * v;
|
||||
public:
|
||||
EdgeModeChanged(OptionsView * v): v(v) { }
|
||||
virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option) { v->c->SetEdgeMode(option.second); }
|
||||
};
|
||||
|
||||
edgeMode = new ui::DropDown(ui::Point(Size.X-88, 186), ui::Point(80, 16));
|
||||
AddComponent(edgeMode);
|
||||
edgeMode->AddOption(std::pair<std::string, int>("Void", 0));
|
||||
edgeMode->AddOption(std::pair<std::string, int>("Solid", 1));
|
||||
edgeMode->SetActionCallback(new EdgeModeChanged(this));
|
||||
|
||||
tempLabel = new ui::Label(ui::Point(8, 186), ui::Point(Size.X-96, 16), "Edge Mode");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
|
||||
class CloseAction: public ui::ButtonAction
|
||||
{
|
||||
@ -145,6 +163,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
|
||||
waterEqualisation->SetChecked(sender->GetWaterEqualisation());
|
||||
airMode->SetOption(sender->GetAirMode());
|
||||
gravityMode->SetOption(sender->GetGravityMode());
|
||||
edgeMode->SetOption(sender->GetEdgeMode());
|
||||
}
|
||||
|
||||
void OptionsView::AttachController(OptionsController * c_)
|
||||
|
@ -24,6 +24,7 @@ class OptionsView: public ui::Window {
|
||||
ui::Checkbox * waterEqualisation;
|
||||
ui::DropDown * airMode;
|
||||
ui::DropDown * gravityMode;
|
||||
ui::DropDown * edgeMode;
|
||||
public:
|
||||
OptionsView();
|
||||
void NotifySettingsChanged(OptionsModel * sender);
|
||||
|
@ -750,6 +750,41 @@ int Simulation::create_part_add_props(int p, int x, int y, int tv, int rx, int r
|
||||
return p;
|
||||
}
|
||||
|
||||
void Simulation::SetEdgeMode(int newEdgeMode)
|
||||
{
|
||||
edgeMode = newEdgeMode;
|
||||
switch(edgeMode)
|
||||
{
|
||||
case 0:
|
||||
for(int i = 0; i<(XRES/CELL); i++)
|
||||
{
|
||||
bmap[0][i] = 0;
|
||||
bmap[YRES/CELL-1][i] = 0;
|
||||
}
|
||||
for(int i = 1; i<((YRES/CELL)-1); i++)
|
||||
{
|
||||
bmap[i][0] = 0;
|
||||
bmap[i][XRES/CELL-1] = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int i;
|
||||
for(i=0; i<(XRES/CELL); i++)
|
||||
{
|
||||
bmap[0][i] = WL_WALL;
|
||||
bmap[YRES/CELL-1][i] = WL_WALL;
|
||||
}
|
||||
for(i=1; i<((YRES/CELL)-1); i++)
|
||||
{
|
||||
bmap[i][0] = WL_WALL;
|
||||
bmap[i][XRES/CELL-1] = WL_WALL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
SetEdgeMode(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, int colA_, int mode)
|
||||
{
|
||||
int rp;
|
||||
@ -1801,6 +1836,7 @@ void Simulation::clear_sim(void)
|
||||
grav->Clear();
|
||||
if(air)
|
||||
air->Clear();
|
||||
SetEdgeMode(edgeMode);
|
||||
}
|
||||
void Simulation::init_can_move()
|
||||
{
|
||||
|
@ -102,6 +102,7 @@ public:
|
||||
int photons[YRES][XRES];
|
||||
int pmap_count[YRES][XRES];
|
||||
//
|
||||
int edgeMode;
|
||||
int gravityMode;
|
||||
//int airMode;
|
||||
int legacy_enable;
|
||||
@ -156,6 +157,8 @@ public:
|
||||
void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert);
|
||||
void clear_area(int area_x, int area_y, int area_w, int area_h);
|
||||
|
||||
void SetEdgeMode(int newEdgeMode);
|
||||
|
||||
int Tool(int x, int y, int tool, float strength);
|
||||
int ToolBrush(int x, int y, int tool, Brush * cBrush);
|
||||
void ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush);
|
||||
|
Reference in New Issue
Block a user