From 62208a14a56f63e997afd85a235da9009fa90eca Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 09:45:13 -0700 Subject: [PATCH] Made LevelInstance (DataModel V1.1_01?) --- DataModelInstance.cpp | 63 ++++--------------------------------- DataModelInstance.h | 10 +++--- G3DTest.vcproj | 8 +++++ GroupInstance.cpp | 1 + LevelInstance.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++ LevelInstance.h | 16 ++++++++++ PVInstance.cpp | 1 + main.cpp | 4 +-- 8 files changed, 110 insertions(+), 65 deletions(-) create mode 100644 LevelInstance.cpp create mode 100644 LevelInstance.h diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 087dd23..380ea83 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -9,17 +9,16 @@ DataModelInstance::DataModelInstance(void) Instance::Instance(); workspace = new WorkspaceInstance(); guiRoot = new Instance(); + level = new LevelInstance(); children.push_back(workspace); + children.push_back(level); className = "dataModel"; mousex = 0; mousey = 0; mouseButton1Down = false; showMessage = false; canDelete = false; - winMessage = "You Won!"; - loseMessage = "You Lost. Try Again"; - timer = 60.0F; - score = 0; + } DataModelInstance::~DataModelInstance(void) @@ -74,58 +73,8 @@ Instance* DataModelInstance::getGuiRoot() return guiRoot; } -char timerTxt[12]; -char scoreTxt[12]; -std::vector DataModelInstance::getProperties() + +LevelInstance* DataModelInstance::getLevel() { - std::vector properties = Instance::getProperties(); - - - - properties.push_back(createPGI("Messages", - "WinMessage", - "The message that shows when the player wins.", - (LPARAM)winMessage.c_str(), - PIT_EDIT)); - properties.push_back(createPGI("Messages", - "LoseMessage", - "The message that shows when the player loses.", - (LPARAM)loseMessage.c_str(), - PIT_EDIT)); - - - sprintf(timerTxt, "%g", timer); - sprintf(scoreTxt, "%d", score); - properties.push_back(createPGI("Gameplay", - "InitialTimerValue", - "The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.", - (LPARAM)timerTxt, - PIT_EDIT)); - properties.push_back(createPGI("Gameplay", - "InitialScoreValue", - "The ammount of points the player starts with.", - (LPARAM)scoreTxt, - PIT_EDIT)); - return properties; -} -void DataModelInstance::PropUpdate(LPPROPGRIDITEM &pItem) -{ - if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0) - { - timer = atoi((LPSTR)pItem->lpCurValue); - } - if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0) - { - score = atof((LPSTR)pItem->lpCurValue); - } - if(strcmp(pItem->lpszPropName, "LoseMessage") == 0) - { - loseMessage = (LPSTR)pItem->lpCurValue; - } - if(strcmp(pItem->lpszPropName, "WinMessage") == 0) - { - winMessage = (LPSTR)pItem->lpCurValue; - } - else - Instance::PropUpdate(pItem); + return level; } \ No newline at end of file diff --git a/DataModelInstance.h b/DataModelInstance.h index 879f732..45844dc 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -1,6 +1,7 @@ #pragma once #include "instance.h" #include "WorkspaceInstance.h" +#include "LevelInstance.h" class DataModelInstance : public Instance @@ -13,6 +14,8 @@ public: void drawMessage(RenderDevice*); WorkspaceInstance* getWorkspace(); WorkspaceInstance* workspace; + LevelInstance * level; + LevelInstance * getLevel(); Instance* guiRoot; std::string message; bool showMessage; @@ -25,10 +28,5 @@ public: void setMousePos(Vector2 pos); bool mouseButton1Down; - float timer; - int score; - virtual std::vector getProperties(); - std::string winMessage; - std::string loseMessage; - virtual void PropUpdate(LPPROPGRIDITEM &pItem); + }; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 79a5e2c..5e82c5e 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -325,6 +325,10 @@ RelativePath=".\Instance.cpp" > + + @@ -430,6 +434,10 @@ RelativePath=".\Instance.h" > + + diff --git a/GroupInstance.cpp b/GroupInstance.cpp index 7560448..c8c593b 100644 --- a/GroupInstance.cpp +++ b/GroupInstance.cpp @@ -3,6 +3,7 @@ GroupInstance::GroupInstance(void) { PVInstance::PVInstance(); + className = "GroupInstance"; } GroupInstance::GroupInstance(const GroupInstance &oinst) diff --git a/LevelInstance.cpp b/LevelInstance.cpp new file mode 100644 index 0000000..4bab150 --- /dev/null +++ b/LevelInstance.cpp @@ -0,0 +1,72 @@ +#include "LevelInstance.h" + +LevelInstance::LevelInstance(void) +{ + Instance::Instance(); + name = "Level"; + winMessage = "You Won!"; + loseMessage = "You Lost. Try Again"; + timer = 60.0F; + score = 0; +} + +LevelInstance::~LevelInstance(void) +{ +} + + +char timerTxt[12]; +char scoreTxt[12]; +std::vector LevelInstance::getProperties() +{ + std::vector properties = Instance::getProperties(); + + + + properties.push_back(createPGI("Messages", + "WinMessage", + "The message that shows when the player wins.", + (LPARAM)winMessage.c_str(), + PIT_EDIT)); + properties.push_back(createPGI("Messages", + "LoseMessage", + "The message that shows when the player loses.", + (LPARAM)loseMessage.c_str(), + PIT_EDIT)); + + + sprintf(timerTxt, "%g", timer); + sprintf(scoreTxt, "%d", score); + properties.push_back(createPGI("Gameplay", + "InitialTimerValue", + "The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.", + (LPARAM)timerTxt, + PIT_EDIT)); + properties.push_back(createPGI("Gameplay", + "InitialScoreValue", + "The ammount of points the player starts with.", + (LPARAM)scoreTxt, + PIT_EDIT)); + return properties; +} +void LevelInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0) + { + timer = atoi((LPSTR)pItem->lpCurValue); + } + if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0) + { + score = atof((LPSTR)pItem->lpCurValue); + } + if(strcmp(pItem->lpszPropName, "LoseMessage") == 0) + { + loseMessage = (LPSTR)pItem->lpCurValue; + } + if(strcmp(pItem->lpszPropName, "WinMessage") == 0) + { + winMessage = (LPSTR)pItem->lpCurValue; + } + else + Instance::PropUpdate(pItem); +} \ No newline at end of file diff --git a/LevelInstance.h b/LevelInstance.h new file mode 100644 index 0000000..f29ca78 --- /dev/null +++ b/LevelInstance.h @@ -0,0 +1,16 @@ +#pragma once +#include "instance.h" + +class LevelInstance : + public Instance +{ +public: + LevelInstance(void); + ~LevelInstance(void); + float timer; + int score; + virtual std::vector getProperties(); + std::string winMessage; + std::string loseMessage; + virtual void PropUpdate(LPPROPGRIDITEM &pItem); +}; diff --git a/PVInstance.cpp b/PVInstance.cpp index 8f0332d..271ea50 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -3,6 +3,7 @@ PVInstance::PVInstance(void) { Instance::Instance(); + className = "PVInstance"; } PVInstance::PVInstance(const PVInstance &oinst) diff --git a/main.cpp b/main.cpp index 90b1ef6..7fa68c9 100644 --- a/main.cpp +++ b/main.cpp @@ -1237,9 +1237,9 @@ void Demo::onGraphics(RenderDevice* rd) { //TODO--Move these to their own instance std::stringstream stream; - stream << std::fixed << std::setprecision(1) << dataModel->timer; + stream << std::fixed << std::setprecision(1) << dataModel->getLevel()->timer; fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black()); - fntdominant->draw2D(rd, "Score: " + Convert(dataModel->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black()); + fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getLevel()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black()); //GUI Boxes Draw::box(G3D::Box(Vector3(0,25,0),Vector3(80,355,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));