duplicate improvements, prototype model insertion

This commit is contained in:
KeyboardCombination
2023-04-07 18:46:19 -04:00
parent 20bf032f1e
commit e37ad4879e
4 changed files with 94 additions and 25 deletions

View File

@@ -27,7 +27,9 @@ public:
void clearMessage(); void clearMessage();
bool debugGetOpen(); bool debugGetOpen();
bool getOpen(); bool getOpen();
bool getOpenModel();
bool load(const char* filename,bool clearObjects); bool load(const char* filename,bool clearObjects);
bool loadModel(const char* filename);
bool readXMLFileStream(std::ifstream* file); bool readXMLFileStream(std::ifstream* file);
void drawMessage(RenderDevice*); void drawMessage(RenderDevice*);

View File

@@ -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) bool DataModelInstance::readXMLFileStream(std::ifstream* file)
{ {
file->seekg(0,file->end); file->seekg(0,file->end);
@@ -584,6 +605,30 @@ bool DataModelInstance::getOpen()
} }
return true; 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) void DataModelInstance::setMessage(std::string msg)
{ {
message = msg; message = msg;

View File

@@ -1,72 +1,80 @@
#include <G3DAll.h> #include <G3DAll.h>
#include "Application.h" #include "Application.h"
#include "Globals.h" #include "Globals.h"
#include "AudioPlayer.h"
#include "DataModelV2/SelectionService.h" #include "DataModelV2/SelectionService.h"
#include "Listener/GUDButtonListener.h" #include "Listener/GUDButtonListener.h"
#include "DataModelV2/SoundService.h"
void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
{ {
SelectionService* SelectionSvc = g_dataModel->getSelectionService();
SoundService* SoundSvc = g_dataModel->getSoundService();
bool cont = false; bool cont = false;
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)
{ {
cont = true; cont = true;
break; break;
} }
if(cont)
if (cont)
{ {
if(button->disabled == false){ if(button->disabled == false){
AudioPlayer::playSound(dingSound); SoundSvc->playSound(SoundSvc->findFirstChild("Ping"));
} }
if(button->name == "Duplicate") if(button->name == "Duplicate")
{ {
std::vector<Instance*> newinst; std::vector<Instance*> 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<PartInstance*>(clonedInstance);
Part->setPosition(Part->getPosition() + G3D::Vector3(0, Part->getSize().y, 0));
}
newinst.push_back(clonedInstance);
} }
} }
g_dataModel->getSelectionService()->clearSelection(); SelectionSvc->clearSelection();
g_dataModel->getSelectionService()->addSelected(newinst); SelectionSvc->addSelected(newinst);
} }
else if(button->name == "Group") else if(button->name == "Group")
{ {
if (g_dataModel->getSelectionService()->getSelection().size() > 1){ if (SelectionSvc->getSelection().size() > 1){
GroupInstance * inst = new GroupInstance(); GroupInstance * inst = new GroupInstance();
inst->setParent(g_dataModel->getWorkspace()); 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); SelectionSvc->getSelection()[i]->setParent(inst);
if(PartInstance* part = dynamic_cast<PartInstance*>(g_dataModel->getSelectionService()->getSelection()[i])) if(PartInstance* part = dynamic_cast<PartInstance*>(SelectionSvc->getSelection()[i]))
{ {
inst->primaryPart = part; inst->primaryPart = part;
} }
} }
} }
g_dataModel->getSelectionService()->clearSelection(); SelectionSvc->clearSelection();
g_dataModel->getSelectionService()->addSelected(inst); SelectionSvc->addSelected(inst);
} }
} }
else if(button->name == "UnGroup") else if(button->name == "UnGroup")
{ {
std::vector<Instance*> newinst; std::vector<Instance*> 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(selection->canDelete && selection->getClassName() == "GroupInstance")
{ {
if(GroupInstance* model = dynamic_cast<GroupInstance*>(g_dataModel->getSelectionService()->getSelection()[i])) if(GroupInstance* model = dynamic_cast<GroupInstance*>(SelectionSvc->getSelection()[i]))
{ {
newinst = model->unGroup(); newinst = model->unGroup();
model->setParent(NULL); model->setParent(NULL);
@@ -75,8 +83,8 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
} }
} }
} }
g_dataModel->getSelectionService()->clearSelection(); SelectionSvc->clearSelection();
g_dataModel->getSelectionService()->addSelected(newinst); SelectionSvc->addSelected(newinst);
} }
} }
} }

View File

@@ -49,4 +49,18 @@ void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button)
break; 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;
}
}
} }