Merge pull request #25 from andreja6/datamodel-v1.1

Datamodel v1.1
This commit is contained in:
andreja6
2018-10-24 20:50:09 -07:00
committed by GitHub
19 changed files with 324 additions and 75 deletions

View File

@@ -1,7 +1,7 @@
#include "CameraController.h" #include "CameraController.h"
#include "win32Defines.h" #include "win32Defines.h"
#include <iostream> #include <iostream>
#include "PhysicalInstance.h" #include "PartInstance.h"
#include "Demo.h" #include "Demo.h"
#include "AudioPlayer.h" #include "AudioPlayer.h"
@@ -141,7 +141,7 @@ void CameraController::centerCamera(Instance* selection)
} }
else else
{ {
Vector3 partPos = ((PhysicalInstance*)selection)->getPosition()/2; Vector3 partPos = ((PartInstance*)selection)->getPosition()/2;
lookAt(partPos); lookAt(partPos);
focusPosition=partPos; focusPosition=partPos;
zoom=((partPos-frame.translation).magnitude()); zoom=((partPos-frame.translation).magnitude());

View File

@@ -15,6 +15,11 @@ DataModelInstance::DataModelInstance(void)
mousey = 0; mousey = 0;
mouseButton1Down = false; mouseButton1Down = false;
showMessage = false; showMessage = false;
canDelete = false;
winMessage = "You Won!";
loseMessage = "You Lost. Try Again";
timer = 60.0F;
score = 0;
} }
DataModelInstance::~DataModelInstance(void) DataModelInstance::~DataModelInstance(void)
@@ -68,3 +73,59 @@ Instance* DataModelInstance::getGuiRoot()
{ {
return guiRoot; return guiRoot;
} }
char timerTxt[12];
char scoreTxt[12];
std::vector<PROPGRIDITEM> DataModelInstance::getProperties()
{
std::vector<PROPGRIDITEM> 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);
}

View File

@@ -24,4 +24,11 @@ public:
void setMousePos(int x,int y); void setMousePos(int x,int y);
void setMousePos(Vector2 pos); void setMousePos(Vector2 pos);
bool mouseButton1Down; bool mouseButton1Down;
float timer;
int score;
virtual std::vector<PROPGRIDITEM> getProperties();
std::string winMessage;
std::string loseMessage;
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
}; };

6
Enum.h
View File

@@ -6,4 +6,10 @@ namespace Enum
Smooth, Bumps, Welds, Glue Smooth, Bumps, Welds, Glue
}; };
} }
namespace Shape
{
enum Value {
Block, Sphere, Cylinder
};
}
} }

View File

@@ -313,6 +313,10 @@
RelativePath=".\DataModelInstance.cpp" RelativePath=".\DataModelInstance.cpp"
> >
</File> </File>
<File
RelativePath=".\GroupInstance.cpp"
>
</File>
<File <File
RelativePath=".\ImageButtonInstance.cpp" RelativePath=".\ImageButtonInstance.cpp"
> >
@@ -322,7 +326,11 @@
> >
</File> </File>
<File <File
RelativePath=".\PhysicalInstance.cpp" RelativePath=".\PartInstance.cpp"
>
</File>
<File
RelativePath=".\PVInstance.cpp"
> >
</File> </File>
<File <File
@@ -410,6 +418,10 @@
RelativePath=".\DataModelInstance.h" RelativePath=".\DataModelInstance.h"
> >
</File> </File>
<File
RelativePath=".\GroupInstance.h"
>
</File>
<File <File
RelativePath=".\ImageButtonInstance.h" RelativePath=".\ImageButtonInstance.h"
> >
@@ -419,7 +431,11 @@
> >
</File> </File>
<File <File
RelativePath=".\PhysicalInstance.h" RelativePath=".\PartInstance.h"
>
</File>
<File
RelativePath=".\PVInstance.h"
> >
</File> </File>
<File <File

25
GroupInstance.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include "GroupInstance.h"
GroupInstance::GroupInstance(void)
{
PVInstance::PVInstance();
}
GroupInstance::GroupInstance(const GroupInstance &oinst)
{
PVInstance::PVInstance(oinst);
}
GroupInstance::~GroupInstance(void)
{
}
std::vector<PROPGRIDITEM> GroupInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = PVInstance::getProperties();
return properties;
}
void GroupInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
PVInstance::PropUpdate(pItem);
}

13
GroupInstance.h Normal file
View File

@@ -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<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
};

View File

@@ -9,6 +9,7 @@ Instance::Instance(void)
name = "Default Game Instance"; name = "Default Game Instance";
className = "BaseInstance"; className = "BaseInstance";
listicon = 0; listicon = 0;
canDelete = true;
} }
Instance::Instance(const Instance &oinst) Instance::Instance(const Instance &oinst)
@@ -16,6 +17,7 @@ Instance::Instance(const Instance &oinst)
name = oinst.name; name = oinst.name;
className = oinst.className; className = oinst.className;
canDelete = oinst.canDelete;
//setParent(oinst.parent); //setParent(oinst.parent);
} }

View File

@@ -5,6 +5,7 @@
class Instance class Instance
{ {
public: public:
bool canDelete;
Instance(void); Instance(void);
Instance(const Instance&); Instance(const Instance&);
virtual ~Instance(void); virtual ~Instance(void);
@@ -12,7 +13,7 @@ public:
virtual void render(RenderDevice*); virtual void render(RenderDevice*);
std::vector<Instance*> children; // All children. std::vector<Instance*> children; // All children.
std::string getClassName(); std::string getClassName();
virtual Instance* findFirstChild(std::string); Instance* findFirstChild(std::string);
std::vector<Instance* > getChildren(); std::vector<Instance* > getChildren();
std::vector<Instance* > getAllChildren(); std::vector<Instance* > getAllChildren();
void setParent(Instance*); void setParent(Instance*);

25
PVInstance.cpp Normal file
View File

@@ -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<PROPGRIDITEM> PVInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = Instance::getProperties();
return properties;
}
void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
Instance::PropUpdate(pItem);
}

13
PVInstance.h Normal file
View File

@@ -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<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
};

View File

@@ -1,11 +1,11 @@
#include "PhysicalInstance.h" #include "PartInstance.h"
#include "Globals.h" #include "Globals.h"
PhysicalInstance::PhysicalInstance(void) PartInstance::PartInstance(void)
{ {
Instance::Instance(); PVInstance::PVInstance();
name = "Default PhysicalInstance"; name = "Default PartInstance";
className = "Part"; className = "Part";
canCollide = true; canCollide = true;
anchored = true; anchored = true;
@@ -20,13 +20,15 @@ PhysicalInstance::PhysicalInstance(void)
back = Enum::SurfaceType::Smooth; back = Enum::SurfaceType::Smooth;
left = Enum::SurfaceType::Smooth; left = Enum::SurfaceType::Smooth;
bottom = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth;
shape = Enum::Shape::Block;
} }
PhysicalInstance::PhysicalInstance(const PhysicalInstance &oinst) PartInstance::PartInstance(const PartInstance &oinst)
{ {
Instance::Instance(oinst); PVInstance::PVInstance(oinst);
//name = oinst.name; //name = oinst.name;
//className = "Part"; //className = "Part";
name = oinst.name;
canCollide = oinst.canCollide; canCollide = oinst.canCollide;
setParent(oinst.parent); setParent(oinst.parent);
anchored = oinst.anchored; anchored = oinst.anchored;
@@ -41,9 +43,10 @@ PhysicalInstance::PhysicalInstance(const PhysicalInstance &oinst)
back = oinst.back; back = oinst.back;
left = oinst.left; left = oinst.left;
bottom = oinst.bottom; bottom = oinst.bottom;
shape = oinst.shape;
} }
void PhysicalInstance::setSize(Vector3 newSize) void PartInstance::setSize(Vector3 newSize)
{ {
int minsize = 1; int minsize = 1;
int maxsize = 512; int maxsize = 512;
@@ -66,42 +69,52 @@ void PhysicalInstance::setSize(Vector3 newSize)
if(sizez > 512) if(sizez > 512)
sizez = 512; sizez = 512;
if(shape != Enum::Shape::Block)
{
int max = sizex;
if(sizey > max)
max = sizey;
if(sizez > max)
max = sizez;
sizex = sizey = sizez = max;
}
size = Vector3(sizex, sizey, sizez); size = Vector3(sizex, sizey, sizez);
} }
Vector3 PhysicalInstance::getSize() Vector3 PartInstance::getSize()
{ {
return size; return size;
} }
Vector3 PhysicalInstance::getPosition() Vector3 PartInstance::getPosition()
{ {
return position; return position;
} }
void PhysicalInstance::setPosition(Vector3 pos) void PartInstance::setPosition(Vector3 pos)
{ {
position = pos; position = pos;
cFrame = CoordinateFrame(pos); cFrame = CoordinateFrame(pos);
changed = true; changed = true;
} }
CoordinateFrame PhysicalInstance::getCFrame() CoordinateFrame PartInstance::getCFrame()
{ {
return cFrame; return cFrame;
} }
void PhysicalInstance::setCFrame(CoordinateFrame coordinateFrame) void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
{ {
cFrame = coordinateFrame; cFrame = coordinateFrame;
position = coordinateFrame.translation; position = coordinateFrame.translation;
changed = true; 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)); 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) if(changed)
{ {
@@ -132,12 +145,12 @@ Box PhysicalInstance::getBox()
return itemBox; return itemBox;
} }
bool PhysicalInstance::collides(Box box) bool PartInstance::collides(Box box)
{ {
return CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), box); return CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), box);
} }
void PhysicalInstance::render(RenderDevice* rd) void PartInstance::render(RenderDevice* rd)
{ {
if(changed) if(changed)
Box box = getBox(); Box box = getBox();
@@ -211,14 +224,14 @@ void PhysicalInstance::render(RenderDevice* rd)
} }
PhysicalInstance::~PhysicalInstance(void) PartInstance::~PartInstance(void)
{ {
} }
char pto[512]; char pto[512];
char pto2[512]; char pto2[512];
#include <sstream> #include <sstream>
void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
{ {
if(strcmp(item->lpszPropName, "Color3") == 0) if(strcmp(item->lpszPropName, "Color3") == 0)
{ {
@@ -285,7 +298,7 @@ void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item)
else Instance::PropUpdate(item); else Instance::PropUpdate(item);
} }
std::vector<PROPGRIDITEM> PhysicalInstance::getProperties() std::vector<PROPGRIDITEM> PartInstance::getProperties()
{ {
std::vector<PROPGRIDITEM> properties = Instance::getProperties(); std::vector<PROPGRIDITEM> properties = Instance::getProperties();

View File

@@ -1,15 +1,14 @@
#pragma once #pragma once
#include "instance.h" #include "PVInstance.h"
#include "Enum.h" #include "Enum.h"
class PhysicalInstance : class PartInstance : public PVInstance
public Instance
{ {
public: public:
PhysicalInstance(void); PartInstance(void);
PhysicalInstance(const PhysicalInstance &oinst); PartInstance(const PartInstance &oinst);
Instance* clone() const { return new PhysicalInstance(*this); } Instance* clone() const { return new PartInstance(*this); }
~PhysicalInstance(void); ~PartInstance(void);
virtual void render(RenderDevice*); virtual void render(RenderDevice*);
Vector3 velocity; Vector3 velocity;
Enum::SurfaceType::Value top; Enum::SurfaceType::Value top;
@@ -18,6 +17,7 @@ public:
Enum::SurfaceType::Value back; Enum::SurfaceType::Value back;
Enum::SurfaceType::Value left; Enum::SurfaceType::Value left;
Enum::SurfaceType::Value bottom; Enum::SurfaceType::Value bottom;
Enum::Shape::Value shape;
CoordinateFrame cFrame; CoordinateFrame cFrame;
Color3 color; Color3 color;
Vector3 getPosition(); Vector3 getPosition();

View File

@@ -58,6 +58,10 @@ void TextButtonInstance::setAllColorsSame()
textOutlineColorDn = textOutlineColor; textOutlineColorDn = textOutlineColor;
boxColorDn = boxColor; boxColorDn = boxColor;
boxOutlineColorDn = boxOutlineColor; boxOutlineColorDn = boxOutlineColor;
textColorDis = textColor;
textOutlineColorDis = textOutlineColor;
boxColorDis = boxColor;
boxOutlineColorDis = boxOutlineColor;
} }
TextButtonInstance::~TextButtonInstance(void) TextButtonInstance::~TextButtonInstance(void)
@@ -80,7 +84,12 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD
point2 = Vector3(boxEnd.x, boxEnd.y,0); point2 = Vector3(boxEnd.x, boxEnd.y,0);
} }
Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y); 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); Draw::box(Box(point1, point2), rd, boxColorDn, boxOutlineColorDn);
font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn); font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn);

View File

@@ -21,6 +21,10 @@ public:
Color4 textOutlineColorDn; Color4 textOutlineColorDn;
Color4 boxColorDn; Color4 boxColorDn;
Color4 boxOutlineColorDn; Color4 boxOutlineColorDn;
Color4 textColorDis;
Color4 textOutlineColorDis;
Color4 boxColorDis;
Color4 boxOutlineColorDis;
bool centeredWithinBox; bool centeredWithinBox;
std::string title; std::string title;
G3D::GFontRef font; G3D::GFontRef font;

View File

@@ -3,11 +3,10 @@
WorkspaceInstance::WorkspaceInstance(void) WorkspaceInstance::WorkspaceInstance(void)
{ {
Instance::Instance(); GroupInstance::GroupInstance();
name = "Instance"; name = "Workspace";
className = "Level"; className = "Workspace";
timer = 60.0F; canDelete = false;
score = 0;
} }
WorkspaceInstance::~WorkspaceInstance(void) WorkspaceInstance::~WorkspaceInstance(void)

View File

@@ -1,13 +1,10 @@
#pragma once #pragma once
#include "instance.h" #include "GroupInstance.h"
class WorkspaceInstance : class WorkspaceInstance :
public Instance public GroupInstance
{ {
public: public:
float timer;
int score;
WorkspaceInstance(void); WorkspaceInstance(void);
~WorkspaceInstance(void); ~WorkspaceInstance(void);
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

124
main.cpp
View File

@@ -20,7 +20,7 @@
#include <iomanip> #include <iomanip>
#include "Instance.h" #include "Instance.h"
#include "resource.h" #include "resource.h"
#include "PhysicalInstance.h" #include "PartInstance.h"
#include "TextButtonInstance.h" #include "TextButtonInstance.h"
#include "ImageButtonInstance.h" #include "ImageButtonInstance.h"
#include "DataModelInstance.h" #include "DataModelInstance.h"
@@ -68,7 +68,10 @@ static std::string cameraSound = "";
static std::string clickSound = ""; static std::string clickSound = "";
static std::string dingSound = ""; static std::string dingSound = "";
static int cursorid = 0; static int cursorid = 0;
static int cursorOvrid = 0;
static int currentcursorid = 0;
static G3D::TextureRef cursor = NULL; static G3D::TextureRef cursor = NULL;
static G3D::TextureRef cursorOvr = NULL;
static bool running = true; static bool running = true;
static bool mouseMovedBeginMotion = false; static bool mouseMovedBeginMotion = false;
static const int CURSOR = 0; static const int CURSOR = 0;
@@ -192,9 +195,9 @@ std::string Convert (float number){
} }
PhysicalInstance* makePart() PartInstance* makePart()
{ {
PhysicalInstance* part = new PhysicalInstance(); PartInstance* part = new PartInstance();
return part; return part;
} }
@@ -246,7 +249,14 @@ public:
void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) 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); AudioPlayer::playSound(dingSound);
if(button->name == "Duplicate") if(button->name == "Duplicate")
@@ -254,7 +264,7 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
std::vector<Instance*> newinst; std::vector<Instance*> newinst;
for(size_t i = 0; i < g_selectedInstances.size(); i++) 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); Instance* tempinst = g_selectedInstances.at(i);
@@ -283,7 +293,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button)
{ {
Instance* selectedInstance = g_selectedInstances.at(0); Instance* selectedInstance = g_selectedInstances.at(0);
AudioPlayer::playSound(clickSound); AudioPlayer::playSound(clickSound);
if(PhysicalInstance* part = dynamic_cast<PhysicalInstance*>(selectedInstance)) if(PartInstance* part = dynamic_cast<PartInstance*>(selectedInstance))
{ {
if(button->name == "Tilt") if(button->name == "Tilt")
part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90))); part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90)));
@@ -302,7 +312,7 @@ void deleteInstance()
size_t undeletable = 0; size_t undeletable = 0;
while(g_selectedInstances.size() > undeletable) 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")); AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav"));
Instance* selectedInstance = g_selectedInstances.at(0); Instance* selectedInstance = g_selectedInstances.at(0);
@@ -503,7 +513,9 @@ void Demo::initGUI()
button->boxColor = Color4::clear(); button->boxColor = Color4::clear();
button->textSize = 12; button->textSize = 12;
button->title = "Group"; button->title = "Group";
button->setAllColorsSame(); button->name = "Group";
button->setAllColorsSame();
button->textColorDis = Color3(0.8F,0.8F,0.8F);
button->font = fntlighttrek; button->font = fntlighttrek;
button->fontLocationRelativeTo = Vector2(10, 0); button->fontLocationRelativeTo = Vector2(10, 0);
button->setParent(dataModel->getGuiRoot()); button->setParent(dataModel->getGuiRoot());
@@ -517,7 +529,9 @@ void Demo::initGUI()
button->boxColor = Color4::clear(); button->boxColor = Color4::clear();
button->textSize = 12; button->textSize = 12;
button->title = "UnGroup"; button->title = "UnGroup";
button->name = "UnGroup";
button->setAllColorsSame(); button->setAllColorsSame();
button->textColorDis = Color3(0.8F,0.8F,0.8F);
button->font = fntlighttrek; button->font = fntlighttrek;
button->fontLocationRelativeTo = Vector2(10, 0); button->fontLocationRelativeTo = Vector2(10, 0);
button->setParent(dataModel->getGuiRoot()); button->setParent(dataModel->getGuiRoot());
@@ -531,6 +545,7 @@ void Demo::initGUI()
button->textSize = 12; button->textSize = 12;
button->title = "Duplicate"; button->title = "Duplicate";
button->setAllColorsSame(); button->setAllColorsSame();
button->textColorDis = Color3(0.8F,0.8F,0.8F);
button->font = fntlighttrek; button->font = fntlighttrek;
button->fontLocationRelativeTo = Vector2(10, 0); button->fontLocationRelativeTo = Vector2(10, 0);
button->setParent(dataModel->getGuiRoot()); button->setParent(dataModel->getGuiRoot());
@@ -710,7 +725,7 @@ void Demo::onInit() {
initGUI(); initGUI();
PhysicalInstance* test = makePart(); PartInstance* test = makePart();
test->setParent(dataModel->getWorkspace()); test->setParent(dataModel->getWorkspace());
test->color = Color3(0.2F,0.3F,1); test->color = Color3(0.2F,0.3F,1);
test->setSize(Vector3(24,1,24)); test->setSize(Vector3(24,1,24));
@@ -838,14 +853,39 @@ std::vector<Instance*> Demo::getSelection()
} }
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { 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; BaseButtonInstance* button = (BaseButtonInstance*)obj;
if(g_selectedInstances.size() <= 0 || g_selectedInstances.at(0) == dataModel->getWorkspace()) BaseButtonInstance* button2 = (BaseButtonInstance*)obj2;
button->disabled = true; BaseButtonInstance* button3 = (BaseButtonInstance*)obj3;
else BaseButtonInstance* button4 = (BaseButtonInstance*)obj4;
button->disabled = false; 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 +953,14 @@ void Demo::onUserInput(UserInput* ui) {
if (GetHoldKeyState(VK_LBUTTON)) { if (GetHoldKeyState(VK_LBUTTON)) {
if (dragging) { if (dragging) {
PhysicalInstance* part = NULL; PartInstance* part = NULL;
if(g_selectedInstances.size() > 0) 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()); Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren(); std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances.size(); i++) for(size_t i = 0; i < instances.size(); i++)
{ {
if(PhysicalInstance* moveTo = dynamic_cast<PhysicalInstance*>(instances.at(i))) if(PartInstance* moveTo = dynamic_cast<PartInstance*>(instances.at(i)))
{ {
float __time = testRay.intersectionTime(moveTo->getBox()); float __time = testRay.intersectionTime(moveTo->getBox());
float __nearest=std::numeric_limits<float>::infinity(); float __nearest=std::numeric_limits<float>::infinity();
@@ -1162,7 +1202,7 @@ void Demo::onGraphics(RenderDevice* rd) {
{ {
for(size_t i = 0; i < g_selectedInstances.size(); i++) for(size_t i = 0; i < g_selectedInstances.size(); i++)
{ {
if(PhysicalInstance* part = dynamic_cast<PhysicalInstance*>(g_selectedInstances.at(i))) if(PartInstance* part = dynamic_cast<PartInstance*>(g_selectedInstances.at(i)))
{ {
Vector3 size = part->getSize(); Vector3 size = part->getSize();
Vector3 pos = part->getPosition(); Vector3 pos = part->getPosition();
@@ -1197,9 +1237,9 @@ void Demo::onGraphics(RenderDevice* rd) {
//TODO--Move these to their own instance //TODO--Move these to their own instance
std::stringstream stream; std::stringstream stream;
stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer; stream << std::fixed << std::setprecision(1) << dataModel->timer;
fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black()); fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black());
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black()); fntdominant->draw2D(rd, "Score: " + Convert(dataModel->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
//GUI Boxes //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)); 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));
@@ -1225,19 +1265,35 @@ void Demo::onGraphics(RenderDevice* rd) {
glEnable(GL_BLEND);// you enable blending function glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
currentcursorid = cursorid;
for(size_t i = 0; i < instances.size(); i++)
{
if(PartInstance* test = dynamic_cast<PartInstance*>(instances.at(i)))
{
float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox());
//float time = testRay.intersectionTime(test->getBox());
if (time != inf())
{
currentcursorid = cursorOvrid;
break;
}
}
}
glBindTexture( GL_TEXTURE_2D, cursorid); glBindTexture( GL_TEXTURE_2D, currentcursorid);
glBegin( GL_QUADS ); glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glTexCoord2d(0.0,0.0);
glVertex2f(mousepos.x-40, mousepos.y-40); glVertex2f(mousepos.x-64, mousepos.y-64);
glTexCoord2d( 1.0,0.0 ); glTexCoord2d( 1.0,0.0 );
glVertex2f(mousepos.x+40, mousepos.y-40); glVertex2f(mousepos.x+64, mousepos.y-64);
glTexCoord2d(1.0,1.0 ); glTexCoord2d(1.0,1.0 );
glVertex2f(mousepos.x+40, mousepos.y+40 ); glVertex2f(mousepos.x+64, mousepos.y+64 );
glTexCoord2d( 0.0,1.0 ); glTexCoord2d( 0.0,1.0 );
glVertex2f( mousepos.x-40, mousepos.y+40 ); glVertex2f( mousepos.x-64, mousepos.y+64 );
glEnd(); glEnd();
glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D );
@@ -1291,7 +1347,7 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
bool objFound = false; bool objFound = false;
for(size_t i = 0; i < instances.size(); i++) for(size_t i = 0; i < instances.size(); i++)
{ {
if(PhysicalInstance* test = dynamic_cast<PhysicalInstance*>(instances.at(i))) if(PartInstance* test = dynamic_cast<PartInstance*>(instances.at(i)))
{ {
float time = testRay.intersectionTime(test->getBox()); float time = testRay.intersectionTime(test->getBox());
@@ -1330,8 +1386,8 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
{ {
while(g_selectedInstances.size() > 0) while(g_selectedInstances.size() > 0)
g_selectedInstances.erase(g_selectedInstances.begin()); g_selectedInstances.erase(g_selectedInstances.begin());
g_selectedInstances.push_back(dataModel->getWorkspace()); g_selectedInstances.push_back(dataModel);
_propWindow->SetProperties(dataModel->getWorkspace()); _propWindow->SetProperties(dataModel);
} }
} }
@@ -1344,7 +1400,7 @@ void Demo::onMouseLeftUp(int x,int y)
//message = "Dragging = false."; //message = "Dragging = false.";
//messageTime = System::time(); //messageTime = System::time();
std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getAllChildren(); std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getAllChildren();
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren(); //std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances_2D.size(); i++) for(size_t i = 0; i < instances_2D.size(); i++)
{ {
if(BaseButtonInstance* button = dynamic_cast<BaseButtonInstance*>(instances_2D[i])) if(BaseButtonInstance* button = dynamic_cast<BaseButtonInstance*>(instances_2D[i]))
@@ -1545,7 +1601,8 @@ void Demo::run() {
UpdateWindow(_hWndMain); UpdateWindow(_hWndMain);
// Load objects here= // Load objects here=
cursor = Texture::fromFile(GetFileInPath("/content/cursor2.png")); cursor = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png"));
cursorOvr = Texture::fromFile(GetFileInPath("/content/images/DragCursor.png"));
Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png")); Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png"));
Globals::surfaceId = Globals::surface->getOpenGLID(); Globals::surfaceId = Globals::surface->getOpenGLID();
fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt"));
@@ -1555,7 +1612,8 @@ void Demo::run() {
dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav"); dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav");
sky = Sky::create(NULL, ExePath() + "/content/sky/"); sky = Sky::create(NULL, ExePath() + "/content/sky/");
cursorid = cursor->openGLID(); cursorid = cursor->openGLID();
currentcursorid = cursorid;
cursorOvrid = cursorOvr->openGLID();
RealTime now=0, lastTime=0; RealTime now=0, lastTime=0;
double simTimeRate = 1.0f; double simTimeRate = 1.0f;
float fps=30.0f; float fps=30.0f;