diff --git a/CameraController.cpp b/CameraController.cpp index 567f089..909ed9a 100644 --- a/CameraController.cpp +++ b/CameraController.cpp @@ -1,7 +1,7 @@ #include "CameraController.h" #include "win32Defines.h" #include -#include "PhysicalInstance.h" +#include "PartInstance.h" #include "Demo.h" #include "AudioPlayer.h" @@ -141,7 +141,7 @@ void CameraController::centerCamera(Instance* selection) } else { - Vector3 partPos = ((PhysicalInstance*)selection)->getPosition()/2; + Vector3 partPos = ((PartInstance*)selection)->getPosition()/2; lookAt(partPos); focusPosition=partPos; zoom=((partPos-frame.translation).magnitude()); diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 4cba7db..8d8ba72 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -15,6 +15,7 @@ DataModelInstance::DataModelInstance(void) mousey = 0; mouseButton1Down = false; showMessage = false; + canDelete = false; } DataModelInstance::~DataModelInstance(void) diff --git a/G3DTest.vcproj b/G3DTest.vcproj index f234481..79a5e2c 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -313,6 +313,10 @@ RelativePath=".\DataModelInstance.cpp" > + + @@ -322,7 +326,11 @@ > + + + + @@ -419,7 +431,11 @@ > + + GroupInstance::getProperties() +{ + std::vector properties = PVInstance::getProperties(); + return properties; +} +void GroupInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + PVInstance::PropUpdate(pItem); +} diff --git a/GroupInstance.h b/GroupInstance.h new file mode 100644 index 0000000..98d63e3 --- /dev/null +++ b/GroupInstance.h @@ -0,0 +1,13 @@ +#pragma once +#include "PVInstance.h" + +class GroupInstance : + public PVInstance +{ +public: + GroupInstance(void); + ~GroupInstance(void); + GroupInstance(const GroupInstance &oinst); + virtual std::vector getProperties(); + virtual void PropUpdate(LPPROPGRIDITEM &pItem); +}; diff --git a/Instance.cpp b/Instance.cpp index 7cc363d..1a9dbb0 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -9,6 +9,7 @@ Instance::Instance(void) name = "Default Game Instance"; className = "BaseInstance"; listicon = 0; + canDelete = true; } Instance::Instance(const Instance &oinst) @@ -16,6 +17,7 @@ Instance::Instance(const Instance &oinst) name = oinst.name; className = oinst.className; + canDelete = oinst.canDelete; //setParent(oinst.parent); } diff --git a/Instance.h b/Instance.h index 07231a1..2af6866 100644 --- a/Instance.h +++ b/Instance.h @@ -5,6 +5,7 @@ class Instance { public: + bool canDelete; Instance(void); Instance(const Instance&); virtual ~Instance(void); @@ -12,7 +13,7 @@ public: virtual void render(RenderDevice*); std::vector children; // All children. std::string getClassName(); - virtual Instance* findFirstChild(std::string); + Instance* findFirstChild(std::string); std::vector getChildren(); std::vector getAllChildren(); void setParent(Instance*); diff --git a/PVInstance.cpp b/PVInstance.cpp new file mode 100644 index 0000000..8f0332d --- /dev/null +++ b/PVInstance.cpp @@ -0,0 +1,25 @@ +#include "PVInstance.h" + +PVInstance::PVInstance(void) +{ + Instance::Instance(); +} + +PVInstance::PVInstance(const PVInstance &oinst) +{ + Instance::Instance(oinst); +} + +PVInstance::~PVInstance(void) +{ +} + +std::vector PVInstance::getProperties() +{ + std::vector properties = Instance::getProperties(); + return properties; +} +void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + Instance::PropUpdate(pItem); +} diff --git a/PVInstance.h b/PVInstance.h new file mode 100644 index 0000000..99f2233 --- /dev/null +++ b/PVInstance.h @@ -0,0 +1,13 @@ +#pragma once +#include "instance.h" + +class PVInstance : + public Instance +{ +public: + PVInstance(void); + ~PVInstance(void); + PVInstance(const PVInstance &oinst); + virtual std::vector getProperties(); + virtual void PropUpdate(LPPROPGRIDITEM &pItem); +}; diff --git a/PhysicalInstance.cpp b/PartInstance.cpp similarity index 88% rename from PhysicalInstance.cpp rename to PartInstance.cpp index c8734f3..7c1f2e1 100644 --- a/PhysicalInstance.cpp +++ b/PartInstance.cpp @@ -1,11 +1,11 @@ -#include "PhysicalInstance.h" +#include "PartInstance.h" #include "Globals.h" -PhysicalInstance::PhysicalInstance(void) +PartInstance::PartInstance(void) { - Instance::Instance(); - name = "Default PhysicalInstance"; + PVInstance::PVInstance(); + name = "Default PartInstance"; className = "Part"; canCollide = true; anchored = true; @@ -22,11 +22,12 @@ PhysicalInstance::PhysicalInstance(void) bottom = Enum::SurfaceType::Smooth; } -PhysicalInstance::PhysicalInstance(const PhysicalInstance &oinst) +PartInstance::PartInstance(const PartInstance &oinst) { - Instance::Instance(oinst); + PVInstance::PVInstance(oinst); //name = oinst.name; //className = "Part"; + name = oinst.name; canCollide = oinst.canCollide; setParent(oinst.parent); anchored = oinst.anchored; @@ -43,7 +44,7 @@ PhysicalInstance::PhysicalInstance(const PhysicalInstance &oinst) bottom = oinst.bottom; } -void PhysicalInstance::setSize(Vector3 newSize) +void PartInstance::setSize(Vector3 newSize) { int minsize = 1; int maxsize = 512; @@ -71,37 +72,37 @@ void PhysicalInstance::setSize(Vector3 newSize) } -Vector3 PhysicalInstance::getSize() +Vector3 PartInstance::getSize() { return size; } -Vector3 PhysicalInstance::getPosition() +Vector3 PartInstance::getPosition() { return position; } -void PhysicalInstance::setPosition(Vector3 pos) +void PartInstance::setPosition(Vector3 pos) { position = pos; cFrame = CoordinateFrame(pos); changed = true; } -CoordinateFrame PhysicalInstance::getCFrame() +CoordinateFrame PartInstance::getCFrame() { return cFrame; } -void PhysicalInstance::setCFrame(CoordinateFrame coordinateFrame) +void PartInstance::setCFrame(CoordinateFrame coordinateFrame) { cFrame = coordinateFrame; position = coordinateFrame.translation; changed = true; } -CoordinateFrame PhysicalInstance::getCFrameRenderBased() +CoordinateFrame PartInstance::getCFrameRenderBased() { return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x/2, getCFrame().translation.y/2, getCFrame().translation.z/2)); } -Box PhysicalInstance::getBox() +Box PartInstance::getBox() { if(changed) { @@ -132,12 +133,12 @@ Box PhysicalInstance::getBox() return itemBox; } -bool PhysicalInstance::collides(Box box) +bool PartInstance::collides(Box box) { return CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), box); } -void PhysicalInstance::render(RenderDevice* rd) +void PartInstance::render(RenderDevice* rd) { if(changed) Box box = getBox(); @@ -211,14 +212,14 @@ void PhysicalInstance::render(RenderDevice* rd) } -PhysicalInstance::~PhysicalInstance(void) +PartInstance::~PartInstance(void) { } char pto[512]; char pto2[512]; #include -void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) +void PartInstance::PropUpdate(LPPROPGRIDITEM &item) { if(strcmp(item->lpszPropName, "Color3") == 0) { @@ -285,7 +286,7 @@ void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) else Instance::PropUpdate(item); } -std::vector PhysicalInstance::getProperties() +std::vector PartInstance::getProperties() { std::vector properties = Instance::getProperties(); diff --git a/PhysicalInstance.h b/PartInstance.h similarity index 78% rename from PhysicalInstance.h rename to PartInstance.h index 70d89b2..ccdbd45 100644 --- a/PhysicalInstance.h +++ b/PartInstance.h @@ -1,15 +1,14 @@ #pragma once -#include "instance.h" +#include "PVInstance.h" #include "Enum.h" -class PhysicalInstance : - public Instance +class PartInstance : public PVInstance { public: - PhysicalInstance(void); - PhysicalInstance(const PhysicalInstance &oinst); - Instance* clone() const { return new PhysicalInstance(*this); } - ~PhysicalInstance(void); + PartInstance(void); + PartInstance(const PartInstance &oinst); + Instance* clone() const { return new PartInstance(*this); } + ~PartInstance(void); virtual void render(RenderDevice*); Vector3 velocity; Enum::SurfaceType::Value top; diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index 6c8cfd1..5a9b472 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -58,6 +58,10 @@ void TextButtonInstance::setAllColorsSame() textOutlineColorDn = textOutlineColor; boxColorDn = boxColor; boxOutlineColorDn = boxOutlineColor; + textColorDis = textColor; + textOutlineColorDis = textOutlineColor; + boxColorDis = boxColor; + boxOutlineColorDis = boxOutlineColor; } TextButtonInstance::~TextButtonInstance(void) @@ -80,7 +84,12 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD point2 = Vector3(boxEnd.x, boxEnd.y,0); } Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y); - if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown) + if(disabled) + { + Draw::box(Box(point1, point2), rd, boxColorDis, boxOutlineColorDis); + font->draw2D(rd, title, RelativeTo, textSize, textColorDis, textOutlineColorDis); + } + else if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown) { Draw::box(Box(point1, point2), rd, boxColorDn, boxOutlineColorDn); font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn); diff --git a/TextButtonInstance.h b/TextButtonInstance.h index 2f8823c..cc53f7f 100644 --- a/TextButtonInstance.h +++ b/TextButtonInstance.h @@ -21,6 +21,10 @@ public: Color4 textOutlineColorDn; Color4 boxColorDn; Color4 boxOutlineColorDn; + Color4 textColorDis; + Color4 textOutlineColorDis; + Color4 boxColorDis; + Color4 boxOutlineColorDis; bool centeredWithinBox; std::string title; G3D::GFontRef font; diff --git a/WorkspaceInstance.cpp b/WorkspaceInstance.cpp index 2f4d463..8c62729 100644 --- a/WorkspaceInstance.cpp +++ b/WorkspaceInstance.cpp @@ -3,11 +3,12 @@ WorkspaceInstance::WorkspaceInstance(void) { - Instance::Instance(); + GroupInstance::GroupInstance(); name = "Instance"; className = "Level"; timer = 60.0F; score = 0; + canDelete = false; } WorkspaceInstance::~WorkspaceInstance(void) diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h index 26a5bc4..1dc0517 100644 --- a/WorkspaceInstance.h +++ b/WorkspaceInstance.h @@ -1,13 +1,12 @@ #pragma once -#include "instance.h" +#include "GroupInstance.h" class WorkspaceInstance : - public Instance + public GroupInstance { public: float timer; int score; WorkspaceInstance(void); ~WorkspaceInstance(void); - }; diff --git a/main.cpp b/main.cpp index e07b3ee..c808215 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,7 @@ #include #include "Instance.h" #include "resource.h" -#include "PhysicalInstance.h" +#include "PartInstance.h" #include "TextButtonInstance.h" #include "ImageButtonInstance.h" #include "DataModelInstance.h" @@ -192,9 +192,9 @@ std::string Convert (float number){ } -PhysicalInstance* makePart() +PartInstance* makePart() { - PhysicalInstance* part = new PhysicalInstance(); + PartInstance* part = new PartInstance(); return part; } @@ -246,7 +246,14 @@ public: void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) { - if(g_selectedInstances.size() > 0) + bool cont = false; + for(size_t i = 0; i < g_selectedInstances.size(); i++) + if(g_selectedInstances.at(i)->canDelete) + { + cont = true; + break; + } + if(cont) { AudioPlayer::playSound(dingSound); if(button->name == "Duplicate") @@ -254,7 +261,7 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) std::vector newinst; for(size_t i = 0; i < g_selectedInstances.size(); i++) { - if(g_selectedInstances.at(i) != dataModel->getWorkspace()) + if(g_selectedInstances.at(i)->canDelete) { Instance* tempinst = g_selectedInstances.at(i); @@ -283,7 +290,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button) { Instance* selectedInstance = g_selectedInstances.at(0); AudioPlayer::playSound(clickSound); - if(PhysicalInstance* part = dynamic_cast(selectedInstance)) + if(PartInstance* part = dynamic_cast(selectedInstance)) { if(button->name == "Tilt") part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90))); @@ -302,7 +309,7 @@ void deleteInstance() size_t undeletable = 0; while(g_selectedInstances.size() > undeletable) { - if(g_selectedInstances.at(0) != dataModel && g_selectedInstances.at(0) != dataModel->getWorkspace()) + if(g_selectedInstances.at(0)->canDelete) { AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); Instance* selectedInstance = g_selectedInstances.at(0); @@ -503,7 +510,9 @@ void Demo::initGUI() button->boxColor = Color4::clear(); button->textSize = 12; button->title = "Group"; - button->setAllColorsSame(); + button->name = "Group"; + button->setAllColorsSame(); + button->textColorDis = Color3(0.8F,0.8F,0.8F); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); button->setParent(dataModel->getGuiRoot()); @@ -517,7 +526,9 @@ void Demo::initGUI() button->boxColor = Color4::clear(); button->textSize = 12; button->title = "UnGroup"; + button->name = "UnGroup"; button->setAllColorsSame(); + button->textColorDis = Color3(0.8F,0.8F,0.8F); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); button->setParent(dataModel->getGuiRoot()); @@ -531,6 +542,7 @@ void Demo::initGUI() button->textSize = 12; button->title = "Duplicate"; button->setAllColorsSame(); + button->textColorDis = Color3(0.8F,0.8F,0.8F); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); button->setParent(dataModel->getGuiRoot()); @@ -710,7 +722,7 @@ void Demo::onInit() { initGUI(); - PhysicalInstance* test = makePart(); + PartInstance* test = makePart(); test->setParent(dataModel->getWorkspace()); test->color = Color3(0.2F,0.3F,1); test->setSize(Vector3(24,1,24)); @@ -838,14 +850,39 @@ std::vector Demo::getSelection() } void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - Instance* obj = dataModel->getGuiRoot()->findFirstChild("Delete"); - if(obj != NULL) + + + Instance * obj6 = dataModel->getGuiRoot()->findFirstChild("Delete"); + Instance * obj = dataModel->getGuiRoot()->findFirstChild("Duplicate"); + Instance * obj2 = dataModel->getGuiRoot()->findFirstChild("Group"); + Instance * obj3 = dataModel->getGuiRoot()->findFirstChild("UnGroup"); + Instance * obj4 = dataModel->getGuiRoot()->findFirstChild("Rotate"); + Instance * obj5 = dataModel->getGuiRoot()->findFirstChild("Tilt"); + if(obj != NULL && obj2 != NULL && obj3 != NULL && obj4 !=NULL && obj5 != NULL && obj6 != NULL) { - ImageButtonInstance* button = (ImageButtonInstance*)obj; - if(g_selectedInstances.size() <= 0 || g_selectedInstances.at(0) == dataModel->getWorkspace()) - button->disabled = true; - else - button->disabled = false; + BaseButtonInstance* button = (BaseButtonInstance*)obj; + BaseButtonInstance* button2 = (BaseButtonInstance*)obj2; + BaseButtonInstance* button3 = (BaseButtonInstance*)obj3; + BaseButtonInstance* button4 = (BaseButtonInstance*)obj4; + BaseButtonInstance* button5 = (BaseButtonInstance*)obj5; + BaseButtonInstance* button6 = (BaseButtonInstance*)obj6; + button->disabled = true; + button2->disabled = true; + button3->disabled = true; + button4->disabled = true; + button5->disabled = true; + button6->disabled = true; + for(size_t i = 0; i < g_selectedInstances.size(); i++) + if(g_selectedInstances.at(i)->canDelete) + { + button->disabled = false; + button2->disabled = false; + button3->disabled = false; + button4->disabled = false; + button5->disabled = false; + button6->disabled = false; + break; + } } @@ -913,14 +950,14 @@ void Demo::onUserInput(UserInput* ui) { if (GetHoldKeyState(VK_LBUTTON)) { if (dragging) { - PhysicalInstance* part = NULL; + PartInstance* part = NULL; if(g_selectedInstances.size() > 0) - part = (PhysicalInstance*) g_selectedInstances.at(0); + part = (PartInstance*) g_selectedInstances.at(0); Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()); std::vector instances = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { - if(PhysicalInstance* moveTo = dynamic_cast(instances.at(i))) + if(PartInstance* moveTo = dynamic_cast(instances.at(i))) { float __time = testRay.intersectionTime(moveTo->getBox()); float __nearest=std::numeric_limits::infinity(); @@ -1162,7 +1199,7 @@ void Demo::onGraphics(RenderDevice* rd) { { for(size_t i = 0; i < g_selectedInstances.size(); i++) { - if(PhysicalInstance* part = dynamic_cast(g_selectedInstances.at(i))) + if(PartInstance* part = dynamic_cast(g_selectedInstances.at(i))) { Vector3 size = part->getSize(); Vector3 pos = part->getPosition(); @@ -1291,7 +1328,7 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y) bool objFound = false; for(size_t i = 0; i < instances.size(); i++) { - if(PhysicalInstance* test = dynamic_cast(instances.at(i))) + if(PartInstance* test = dynamic_cast(instances.at(i))) { float time = testRay.intersectionTime(test->getBox());