diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 57ed1d944..7b98fa3ce 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -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) diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index 40151098c..3d6f0b9af 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -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 :( diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index b2f7d700f..7c2ddeb1e 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -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 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 displayModes = ren->GetDisplayMode(); + Client::Ref().SetPref("Renderer.DisplayModes", std::vector(displayModes.begin(), displayModes.end())); + + std::vector renderModes = ren->GetRenderMode(); + Client::Ref().SetPref("Renderer.RenderModes", std::vector(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::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 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 displayModes = ren->GetDisplayMode(); - Client::Ref().SetPref("Renderer.DisplayModes", std::vector(displayModes.begin(), displayModes.end())); - - std::vector renderModes = ren->GetRenderMode(); - Client::Ref().SetPref("Renderer.RenderModes", std::vector(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) diff --git a/src/game/GameModel.h b/src/game/GameModel.h index afe1960aa..2c8636a97 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -91,6 +91,8 @@ public: std::string GetToolTip(); std::string GetInfoTip(); + void BuildMenus(); + void SetVote(int direction); SaveInfo * GetSave(); Brush * GetBrush();