Made properties "dynamically update", no longer simply says NO when object makes no sense

This commit is contained in:
andreja6
2018-10-25 15:43:45 -07:00
parent 5dd6ae7d9c
commit 7b4abe3efe
5 changed files with 58 additions and 14 deletions

View File

@@ -31,17 +31,50 @@ DataModelInstance::~DataModelInstance(void)
void DataModelInstance::setMessage(std::string msg) void DataModelInstance::setMessage(std::string msg)
{ {
message = msg; message = msg;
isBrickCount = false;
showMessage = true; showMessage = true;
} }
void DataModelInstance::clearMessage() void DataModelInstance::clearMessage()
{ {
showMessage = false; showMessage = false;
isBrickCount = false;
message = ""; message = "";
} }
void DataModelInstance::setMessageBrickCount()
{
isBrickCount = true;
showMessage = true;
}
void DataModelInstance::drawMessage(RenderDevice* rd) void DataModelInstance::drawMessage(RenderDevice* rd)
{ {
if(isBrickCount)
{
int brickCount = 0;
int instCount = 0;
std::vector<Instance*> inst = getAllChildren();
for(size_t i = 0; i < inst.size(); i++)
{
if(PartInstance* moveTo = dynamic_cast<PartInstance*>(inst.at(i)))
{
brickCount++;
}
else
{
instCount++;
}
}
char brkc[12];
sprintf(brkc, "%d", brickCount);
char instc[12];
sprintf(instc, "%d", instCount);
message = "Bricks: ";
message += brkc;
message += " Snaps: ";
message += instc;
}
if(showMessage && !font.isNull()) if(showMessage && !font.isNull())
{ {
int x = rd->getWidth()/2; int x = rd->getWidth()/2;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "WorkspaceInstance.h" #include "WorkspaceInstance.h"
#include "LevelInstance.h" #include "LevelInstance.h"
#include "PartInstance.h"
class DataModelInstance : class DataModelInstance :
public Instance public Instance
@@ -9,6 +10,7 @@ public:
DataModelInstance(void); DataModelInstance(void);
~DataModelInstance(void); ~DataModelInstance(void);
void setMessage(std::string); void setMessage(std::string);
void setMessageBrickCount();
void clearMessage(); void clearMessage();
void drawMessage(RenderDevice*); void drawMessage(RenderDevice*);
WorkspaceInstance* getWorkspace(); WorkspaceInstance* getWorkspace();
@@ -26,6 +28,7 @@ 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;
private:
bool isBrickCount;
}; };

View File

@@ -152,6 +152,7 @@ bool PartInstance::collides(Box box)
void PartInstance::render(RenderDevice* rd) void PartInstance::render(RenderDevice* rd)
{ {
if(changed) if(changed)
Box box = getBox(); Box box = getBox();
@@ -257,7 +258,6 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what"); sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what");
LPCSTR str = LPCSTR(pto); LPCSTR str = LPCSTR(pto);
item->lpCurValue = (LPARAM)str; item->lpCurValue = (LPARAM)str;
MessageBox(NULL, "NO","NO", MB_OK);
} }
else else
{ {
@@ -286,7 +286,6 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what"); sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what");
LPCSTR str = LPCSTR(pto); LPCSTR str = LPCSTR(pto);
item->lpCurValue = (LPARAM)str; item->lpCurValue = (LPARAM)str;
MessageBox(NULL, "NO","NO", MB_OK);
} }
else else
{ {

View File

@@ -164,6 +164,7 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm; LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm;
LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex); LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex);
selectedInstance->PropUpdate(item); selectedInstance->PropUpdate(item);
propWind->SetProperties(selectedInstance);
} }
} }
break; break;

View File

@@ -786,7 +786,7 @@ void Demo::onInit() {
test->setSize(Vector3(4,1,2)); test->setSize(Vector3(4,1,2));
test->setPosition(Vector3(-2,5,0)); test->setPosition(Vector3(-2,5,0));
//dataModel->setMessageBrickCount();
test = makePart(); test = makePart();
@@ -851,7 +851,7 @@ std::vector<Instance*> Demo::getSelection()
return g_selectedInstances; return g_selectedInstances;
} }
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
if(!running) if(running)
{ {
std::vector <Instance* > objects = dataModel->getWorkspace()->getAllChildren(); std::vector <Instance* > objects = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < objects.size(); i++) for(size_t i = 0; i < objects.size(); i++)
@@ -1182,6 +1182,8 @@ void Demo::onGraphics(RenderDevice* rd) {
} }
} }
if(Globals::useMousePoint) if(Globals::useMousePoint)
{ {
mousepos = Globals::mousepoint; mousepos = Globals::mousepoint;
@@ -1208,10 +1210,25 @@ void Demo::onGraphics(RenderDevice* rd) {
renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
renderDevice->setAmbientLightColor(lighting.ambient); renderDevice->setAmbientLightColor(lighting.ambient);
Vector3 gamepoint = Vector3(0, 5, 0);
Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 50 && distance > -50)
{
if(distance < 0)
distance = distance*-1;
fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
}
rd->beforePrimitive(); rd->beforePrimitive();
dataModel->getWorkspace()->render(rd); dataModel->getWorkspace()->render(rd);
rd->afterPrimitive(); rd->afterPrimitive();
if(g_selectedInstances.size() > 0) if(g_selectedInstances.size() > 0)
{ {
for(size_t i = 0; i < g_selectedInstances.size(); i++) for(size_t i = 0; i < g_selectedInstances.size(); i++)
@@ -1226,16 +1243,7 @@ void Demo::onGraphics(RenderDevice* rd) {
} }
//Vector3 gamepoint = Vector3(0, 5, 0);
//Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
//float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
//if(distance < 50 && distance > -50)
//{
// if(distance < 0)
// distance = distance*-1;
// fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
//}
renderDevice->disableLighting(); renderDevice->disableLighting();