Update menus on element change from lua, addresses issue #42
This commit is contained in:
parent
94bb1ad2df
commit
b165619266
@ -543,6 +543,8 @@ int luacon_element_getproperty(char * key, int * format, unsigned int * modified
|
||||
if (strcmp(key, "name")==0){
|
||||
offset = offsetof(Element, Name);
|
||||
*format = 2;
|
||||
if(modified_stuff)
|
||||
*modified_stuff |= LUACON_EL_MODIFIED_MENUS;
|
||||
}
|
||||
else if (strcmp(key, "color")==0){
|
||||
offset = offsetof(Element, Colour);
|
||||
@ -651,6 +653,8 @@ int luacon_element_getproperty(char * key, int * format, unsigned int * modified
|
||||
else if (strcmp(key, "description")==0){
|
||||
offset = offsetof(Element, Description);
|
||||
*format = 2;
|
||||
if(modified_stuff)
|
||||
*modified_stuff |= LUACON_EL_MODIFIED_MENUS;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
@ -761,8 +765,8 @@ int luacon_elementwrite(lua_State* l){
|
||||
}
|
||||
if (modified_stuff)
|
||||
{
|
||||
//if (modified_stuff & LUACON_EL_MODIFIED_MENUS)
|
||||
//luacon_model->notifyMenuListChanged();
|
||||
if (modified_stuff & LUACON_EL_MODIFIED_MENUS)
|
||||
luacon_model->BuildMenus();
|
||||
if (modified_stuff & LUACON_EL_MODIFIED_CANMOVE)
|
||||
luacon_sim->init_can_move();
|
||||
if (modified_stuff & LUACON_EL_MODIFIED_GRAPHICS)
|
||||
|
@ -16,7 +16,7 @@ extern "C"
|
||||
}
|
||||
|
||||
#include "CommandInterface.h"
|
||||
#include "simulation/Simulation.h";
|
||||
#include "simulation/Simulation.h"
|
||||
|
||||
//Because lua only has bindings for C, we're going to have to go outside "outside" the LuaScriptInterface, this means we can only have one instance :(
|
||||
|
||||
|
@ -52,11 +52,84 @@ GameModel::GameModel():
|
||||
|
||||
}
|
||||
|
||||
//Load last user
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
{
|
||||
currentUser = Client::Ref().GetAuthUser();
|
||||
}
|
||||
|
||||
//Set stamp to first stamp in list
|
||||
vector<string> stamps = Client::Ref().GetStamps(0, 1);
|
||||
if(stamps.size()>0)
|
||||
{
|
||||
SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]);
|
||||
if(stampFile && stampFile->GetGameSave())
|
||||
stamp = stampFile->GetGameSave();
|
||||
}
|
||||
|
||||
BuildMenus();
|
||||
|
||||
//Set default decoration colour
|
||||
unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
|
||||
unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255);
|
||||
unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255);
|
||||
unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);
|
||||
|
||||
SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));
|
||||
}
|
||||
|
||||
GameModel::~GameModel()
|
||||
{
|
||||
//Save to config:
|
||||
Client::Ref().SetPref("Renderer.ColourMode", (double)ren->GetColourMode());
|
||||
|
||||
std::vector<unsigned int> displayModes = ren->GetDisplayMode();
|
||||
Client::Ref().SetPref("Renderer.DisplayModes", std::vector<double>(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("Decoration.Red", (int)colour.Red);
|
||||
Client::Ref().SetPref("Decoration.Green", (int)colour.Green);
|
||||
Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue);
|
||||
Client::Ref().SetPref("Decoration.Alpha", (int)colour.Alpha);
|
||||
|
||||
for(int i = 0; i < menuList.size(); i++)
|
||||
{
|
||||
delete menuList[i];
|
||||
}
|
||||
for(int i = 0; i < brushList.size(); i++)
|
||||
{
|
||||
delete brushList[i];
|
||||
}
|
||||
delete sim;
|
||||
delete ren;
|
||||
if(clipboard)
|
||||
delete clipboard;
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
if(currentSave)
|
||||
delete currentSave;
|
||||
//if(activeTools)
|
||||
// delete[] activeTools;
|
||||
}
|
||||
|
||||
void GameModel::BuildMenus()
|
||||
{
|
||||
//Empty current menus
|
||||
for(std::vector<Menu*>::iterator iter = menuList.begin(), end = menuList.end(); iter != end; ++iter)
|
||||
{
|
||||
delete *iter;
|
||||
}
|
||||
menuList.clear();
|
||||
toolList.clear();
|
||||
|
||||
//Create menus
|
||||
for(int i = 0; i < SC_TOTAL; i++)
|
||||
{
|
||||
menuList.push_back(new Menu((const char)sim->msections[i].icon[0], sim->msections[i].name));
|
||||
}
|
||||
|
||||
//Build menus from Simulation elements
|
||||
for(int i = 0; i < PT_NUM; i++)
|
||||
{
|
||||
@ -119,70 +192,15 @@ GameModel::GameModel():
|
||||
//Set default tools
|
||||
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
|
||||
activeTools[1] = menuList[SC_SPECIAL]->GetToolList()[0];
|
||||
activeTools[2] = NULL;
|
||||
|
||||
//Set default menu
|
||||
activeMenu = menuList[SC_POWDERS];
|
||||
toolList = menuList[SC_POWDERS]->GetToolList();
|
||||
|
||||
//Load last user
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
{
|
||||
currentUser = Client::Ref().GetAuthUser();
|
||||
}
|
||||
|
||||
//Set stamp to first stamp in list
|
||||
vector<string> stamps = Client::Ref().GetStamps(0, 1);
|
||||
if(stamps.size()>0)
|
||||
{
|
||||
SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]);
|
||||
if(stampFile && stampFile->GetGameSave())
|
||||
stamp = stampFile->GetGameSave();
|
||||
}
|
||||
|
||||
|
||||
//Set default decoration colour
|
||||
unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
|
||||
unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255);
|
||||
unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255);
|
||||
unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);
|
||||
|
||||
SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));
|
||||
}
|
||||
|
||||
GameModel::~GameModel()
|
||||
{
|
||||
//Save to config:
|
||||
Client::Ref().SetPref("Renderer.ColourMode", (double)ren->GetColourMode());
|
||||
|
||||
std::vector<unsigned int> displayModes = ren->GetDisplayMode();
|
||||
Client::Ref().SetPref("Renderer.DisplayModes", std::vector<double>(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("Decoration.Red", (int)colour.Red);
|
||||
Client::Ref().SetPref("Decoration.Green", (int)colour.Green);
|
||||
Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue);
|
||||
Client::Ref().SetPref("Decoration.Alpha", (int)colour.Alpha);
|
||||
|
||||
for(int i = 0; i < menuList.size(); i++)
|
||||
{
|
||||
delete menuList[i];
|
||||
}
|
||||
for(int i = 0; i < brushList.size(); i++)
|
||||
{
|
||||
delete brushList[i];
|
||||
}
|
||||
delete sim;
|
||||
delete ren;
|
||||
if(clipboard)
|
||||
delete clipboard;
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
if(currentSave)
|
||||
delete currentSave;
|
||||
//if(activeTools)
|
||||
// delete[] activeTools;
|
||||
notifyMenuListChanged();
|
||||
notifyToolListChanged();
|
||||
notifyActiveToolsChanged();
|
||||
}
|
||||
|
||||
void GameModel::SetVote(int direction)
|
||||
|
@ -91,6 +91,8 @@ public:
|
||||
std::string GetToolTip();
|
||||
std::string GetInfoTip();
|
||||
|
||||
void BuildMenus();
|
||||
|
||||
void SetVote(int direction);
|
||||
SaveInfo * GetSave();
|
||||
Brush * GetBrush();
|
||||
|
Loading…
Reference in New Issue
Block a user