diff --git a/src/include/DataModelV2/DataModelInstance.h b/src/include/DataModelV2/DataModelInstance.h index aceaf86..aba257d 100644 --- a/src/include/DataModelV2/DataModelInstance.h +++ b/src/include/DataModelV2/DataModelInstance.h @@ -27,7 +27,9 @@ public: void clearMessage(); bool debugGetOpen(); bool getOpen(); + bool getOpenModel(); bool load(const char* filename,bool clearObjects); + bool loadModel(const char* filename); bool readXMLFileStream(std::ifstream* file); void drawMessage(RenderDevice*); diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index 79f0c84..0b0d7c6 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -515,6 +515,27 @@ bool DataModelInstance::load(const char* filename, bool clearObjects) } } +bool DataModelInstance::loadModel(const char* filename) +{ + ifstream levelFile(filename,ios::binary); + if (levelFile) + { + readXMLFileStream(&levelFile); + + //resetEngine(); + selectionService->clearSelection(); + selectionService->addSelected(this); + return true; + } + else + { + std::stringstream msg; + msg << "Failed to load file:" << std::endl << filename << std::endl << strerror(errno); + MessageBoxStr(msg.str()); + return false; + } +} + bool DataModelInstance::readXMLFileStream(std::ifstream* file) { file->seekg(0,file->end); @@ -584,6 +605,30 @@ bool DataModelInstance::getOpen() } return true; } + +bool DataModelInstance::getOpenModel() +{ + _modY=0; + OPENFILENAME of; + ZeroMemory( &of , sizeof( of)); + of.lStructSize = sizeof(OPENFILENAME); + of.lpstrFilter = "Roblox Files\0*.rbxm;*.rbxl\0\0"; + char szFile[512]; + of.lpstrFile = szFile ; + of.lpstrFile[0]='\0'; + of.nMaxFile=500; + of.lpstrTitle="Hello"; + of.Flags = OFN_FILEMUSTEXIST; + ShowCursor(TRUE); + BOOL file = GetOpenFileName(&of); + if (file) + { + _loadedFileName = of.lpstrFile; + loadModel(of.lpstrFile); + } + return true; +} + void DataModelInstance::setMessage(std::string msg) { message = msg; diff --git a/src/source/Listener/GUDButtonListener.cpp b/src/source/Listener/GUDButtonListener.cpp index 176384d..c689967 100644 --- a/src/source/Listener/GUDButtonListener.cpp +++ b/src/source/Listener/GUDButtonListener.cpp @@ -1,72 +1,80 @@ #include #include "Application.h" #include "Globals.h" -#include "AudioPlayer.h" #include "DataModelV2/SelectionService.h" #include "Listener/GUDButtonListener.h" +#include "DataModelV2/SoundService.h" void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) { + SelectionService* SelectionSvc = g_dataModel->getSelectionService(); + SoundService* SoundSvc = g_dataModel->getSoundService(); + bool cont = false; - for(size_t i = 0; i < g_dataModel->getSelectionService()->getSelection().size(); i++) - if(g_dataModel->getSelectionService()->getSelection()[i]->canDelete) + for(size_t i = 0; i < SelectionSvc->getSelection().size(); i++) + if(SelectionSvc->getSelection()[i]->canDelete) { cont = true; break; } - if(cont) + + if (cont) { - if(button->disabled == false){ - AudioPlayer::playSound(dingSound); + SoundSvc->playSound(SoundSvc->findFirstChild("Ping")); } if(button->name == "Duplicate") { std::vector newinst; - for(size_t i = 0; i < g_dataModel->getSelectionService()->getSelection().size(); i++) + for(size_t i = 0; i < SelectionSvc->getSelection().size(); i++) { - if(g_dataModel->getSelectionService()->getSelection()[i]->canDelete) + if(SelectionSvc->getSelection()[i]->canDelete) { - Instance* tempinst = g_dataModel->getSelectionService()->getSelection()[i]; + Instance* tempinst = SelectionSvc->getSelection()[i]; - Instance* clonedInstance = g_dataModel->getSelectionService()->getSelection()[i]->clone(); + Instance* clonedInstance = SelectionSvc->getSelection()[i]->clone(); - newinst.push_back(tempinst); + if (clonedInstance->getClassName() == "PVInstance"){ + PartInstance* Part = dynamic_cast(clonedInstance); + Part->setPosition(Part->getPosition() + G3D::Vector3(0, Part->getSize().y, 0)); + } + + newinst.push_back(clonedInstance); } } - g_dataModel->getSelectionService()->clearSelection(); - g_dataModel->getSelectionService()->addSelected(newinst); + SelectionSvc->clearSelection(); + SelectionSvc->addSelected(newinst); } else if(button->name == "Group") { - if (g_dataModel->getSelectionService()->getSelection().size() > 1){ + if (SelectionSvc->getSelection().size() > 1){ GroupInstance * inst = new GroupInstance(); inst->setParent(g_dataModel->getWorkspace()); - for(size_t i = 0; i < g_dataModel->getSelectionService()->getSelection().size(); i++) + for(size_t i = 0; i < SelectionSvc->getSelection().size(); i++) { - if(g_dataModel->getSelectionService()->getSelection()[i]->canDelete) + if(SelectionSvc->getSelection()[i]->canDelete) { - g_dataModel->getSelectionService()->getSelection()[i]->setParent(inst); - if(PartInstance* part = dynamic_cast(g_dataModel->getSelectionService()->getSelection()[i])) + SelectionSvc->getSelection()[i]->setParent(inst); + if(PartInstance* part = dynamic_cast(SelectionSvc->getSelection()[i])) { inst->primaryPart = part; } } } - g_dataModel->getSelectionService()->clearSelection(); - g_dataModel->getSelectionService()->addSelected(inst); + SelectionSvc->clearSelection(); + SelectionSvc->addSelected(inst); } } else if(button->name == "UnGroup") { std::vector newinst; - for(size_t i = 0; i < g_dataModel->getSelectionService()->getSelection().size(); i++) + for(size_t i = 0; i < SelectionSvc->getSelection().size(); i++) { - Instance* selection = g_dataModel->getSelectionService()->getSelection()[i]; + Instance* selection = SelectionSvc->getSelection()[i]; if(selection->canDelete && selection->getClassName() == "GroupInstance") { - if(GroupInstance* model = dynamic_cast(g_dataModel->getSelectionService()->getSelection()[i])) + if(GroupInstance* model = dynamic_cast(SelectionSvc->getSelection()[i])) { newinst = model->unGroup(); model->setParent(NULL); @@ -75,8 +83,8 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) } } } - g_dataModel->getSelectionService()->clearSelection(); - g_dataModel->getSelectionService()->addSelected(newinst); + SelectionSvc->clearSelection(); + SelectionSvc->addSelected(newinst); } } } \ No newline at end of file diff --git a/src/source/Listener/MenuButtonListener.cpp b/src/source/Listener/MenuButtonListener.cpp index fbd6d67..9994f7e 100644 --- a/src/source/Listener/MenuButtonListener.cpp +++ b/src/source/Listener/MenuButtonListener.cpp @@ -49,4 +49,18 @@ void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button) break; } } + else if (button->name == "insert"){ + HMENU mainmenu = CreatePopupMenu(); + AppendMenu(mainmenu, MF_STRING, 104, "Model..."); + + POINT p; + GetCursorPos(&p); + int menuClick = TrackPopupMenu(mainmenu, TPM_LEFTBUTTON | TPM_RETURNCMD, p.x, p.y, 0, Globals::mainHwnd, 0); + switch (menuClick) + { + case 104: + g_dataModel->getOpenModel(); + break; + } + } } \ No newline at end of file