From 70fba67b6ecf9f446a133dc68cfdd0bf5441458c Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 09:55:49 -0700 Subject: [PATCH] Made instances call parent function on properties, Deselecting everything opens Datamodel in the property grid Instances now call the parent method after setting/getting properties, Made delete no longer delete workspace --- Instance.cpp | 2 +- PhysicalInstance.cpp | 18 ++++-------------- main.cpp | 33 ++++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Instance.cpp b/Instance.cpp index 6cf2fea..0620779 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -45,7 +45,7 @@ void Instance::PropUpdate(LPPROPGRIDITEM &item) { if(strcmp(item->lpszPropName, "Name") == 0) { - name = item->lpCurValue; + name = (LPSTR)item->lpCurValue; } } diff --git a/PhysicalInstance.cpp b/PhysicalInstance.cpp index 43b5837..6e1963d 100644 --- a/PhysicalInstance.cpp +++ b/PhysicalInstance.cpp @@ -218,11 +218,7 @@ char pto2[512]; void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) { - if(strcmp(item->lpszPropName, "Name") == 0) - { - name = (LPTSTR)item->lpCurValue; - } - else if(strcmp(item->lpszPropName, "Color3") == 0) + if(strcmp(item->lpszPropName, "Color3") == 0) { color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F); } @@ -283,20 +279,14 @@ void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) setSize(size); } } + + else Instance::PropUpdate(item); } std::vector PhysicalInstance::getProperties() { - std::vector properties; + std::vector properties = Instance::getProperties(); - - properties.push_back(createPGI( - "Properties", - "Name", - "The name of this instance", - (LPARAM)name.c_str(), - PIT_EDIT - )); properties.push_back(createPGI( "Properties", diff --git a/main.cpp b/main.cpp index f080c7d..4d06d0e 100644 --- a/main.cpp +++ b/main.cpp @@ -295,18 +295,27 @@ void deleteInstance() { if(g_selectedInstances.size() > 0) { - while(g_selectedInstances.size() > 0) + int undeletable = 0; + while(g_selectedInstances.size() > undeletable) { - Instance* selectedInstance = g_selectedInstances.at(0); - if(selectedInstance->getParent() != NULL) - selectedInstance->getParent()->removeChild(selectedInstance); - delete selectedInstance; - selectedInstance = NULL; - g_selectedInstances.erase(g_selectedInstances.begin()); - AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); + if(g_selectedInstances.at(0) != dataModel && g_selectedInstances.at(0) != dataModel->getWorkspace()) + { + AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); + Instance* selectedInstance = g_selectedInstances.at(0); + if(selectedInstance->getParent() != NULL) + selectedInstance->getParent()->removeChild(selectedInstance); + delete selectedInstance; + selectedInstance = NULL; + g_selectedInstances.erase(g_selectedInstances.begin()); + } + else + { + undeletable++; + } } } - usableApp->_propWindow->ClearProperties(); + if(g_selectedInstances.size() == 0) + usableApp->_propWindow->ClearProperties(); } @@ -829,7 +838,7 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { if(obj != NULL) { ImageButtonInstance* button = (ImageButtonInstance*)obj; - if(g_selectedInstances.size() <= 0) + if(g_selectedInstances.size() <= 0 || g_selectedInstances.at(0) == dataModel->getWorkspace()) button->disabled = true; else button->disabled = false; @@ -1308,7 +1317,9 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y) { while(g_selectedInstances.size() > 0) g_selectedInstances.erase(g_selectedInstances.begin()); - _propWindow->ClearProperties(); + g_selectedInstances.push_back(dataModel->getWorkspace()); + _propWindow->SetProperties(dataModel->getWorkspace()); + } } }