Fix Vector3 Property, enum work

This commit is contained in:
Vulpovile
2022-10-25 07:25:58 -07:00
parent 78f135732e
commit fc9e953554
15 changed files with 276 additions and 2 deletions

View File

@@ -266,6 +266,10 @@
RelativePath=".\src\source\CameraController.cpp"
>
</File>
<File
RelativePath=".\src\source\PropertiesV2\Color3Property.cpp"
>
</File>
<File
RelativePath=".\src\source\ErrorFunctions.cpp"
>
@@ -310,6 +314,10 @@
RelativePath=".\src\source\TextureHandler.cpp"
>
</File>
<File
RelativePath=".\src\source\PropertiesV2\Vector3Property.cpp"
>
</File>
<File
RelativePath=".\src\source\WindowFunctions.cpp"
>
@@ -715,6 +723,10 @@
RelativePath=".\src\include\ax.h"
>
</File>
<File
RelativePath=".\src\include\Enum\B3DEnum.h"
>
</File>
<File
RelativePath=".\src\include\BrowserCallHandler.h"
>
@@ -723,6 +735,10 @@
RelativePath=".\src\include\CameraController.h"
>
</File>
<File
RelativePath=".\src\include\PropertiesV2\Color3Property.h"
>
</File>
<File
RelativePath=".\src\include\Enum.h"
>
@@ -779,6 +795,10 @@
RelativePath=".\src\include\ToolEnum.h"
>
</File>
<File
RelativePath=".\src\include\PropertiesV2\Vector3Property.h"
>
</File>
<File
RelativePath=".\src\include\versioning.h"
>

View File

@@ -2,6 +2,7 @@
#include <G3DAll.h>
#include "propertyGrid.h"
#include "PropertiesV2/StringProperty.h"
#include "PropertiesV2/BoolProperty.h"
#include "map"
class Instance

View File

@@ -13,10 +13,13 @@ public:
virtual void postRender(RenderDevice* rd);
virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
virtual std::vector<Property*> collectProperties();
bool nameShown;
bool controllerFlagShown;
Enum::Controller::Value controller;
virtual void makeJoints();
virtual void setNameShown(bool nameShown);
virtual void setControllerFlagShown(bool controllerFlagShown);
protected:
CoordinateFrame cFrame;
static G3D::Color3 getControllerColor(int controller)

View File

@@ -1,6 +1,8 @@
#pragma once
#include "PVInstance.h"
#include "Enum.h"
#include "PropertiesV2/Color3Property.h"
#include "PropertiesV2/Vector3Property.h"
#define _USE_MATH_DEFINES
#include <cmath>
@@ -59,6 +61,7 @@ public:
//Setters
void setParent(Instance* parent);
void setPosition(Vector3);
void setColor(Color3 color);
void setVelocity(Vector3);
void setRotVelocity(Vector3);
void setCFrame(CoordinateFrame);
@@ -83,6 +86,7 @@ public:
//Properties
virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
virtual std::vector<Property *> collectProperties();
private:
bool anchored;
Vector3 position;

View File

@@ -1,4 +1,6 @@
#pragma once
#include <string>
#include <map>
namespace Enum
{
@@ -7,6 +9,30 @@ namespace Enum
enum Value {
Smooth = 0, Bumps = 1, Hinge = 2, Motor = 3, StepperMotor = 4, Spawn = 5
};
static std::pair<std::string, Value> map_data[] = {
std::make_pair("Smooth", Smooth),
std::make_pair("Bumps", Bumps),
std::make_pair("Hinge", Hinge),
std::make_pair("Motor", Motor),
std::make_pair("StepperMotor", StepperMotor),
std::make_pair("Spawn", Spawn)
};
static std::map<std::string, Value> nameMap(map_data,
map_data + sizeof map_data / sizeof map_data[0]);
static Value getByName(std::string name) {
if(nameMap.find(name) != nameMap.end()){
return nameMap[name];
}
return Smooth;
}
static std::string getName(Value value) {
for (std::map<std::string, Value>::iterator it = nameMap.begin(); it != nameMap.end(); ++it)
if (it->second == value)
return it->first;
return "";
}
}
namespace Shape
{

View File

@@ -0,0 +1,24 @@
#pragma once
namespace Enum
{
class B3DEnum {
public:
B3DEnum(int id, std::string name)
{
this->id = id;
this->name = name;
}
const int getId() {
return id;
}
const std::string getName() {
return name;
}
virtual B3DEnum getByName(std::string name);
virtual B3DEnum getById(int id);
private:
int id;
std::string name;
}
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "Property.h"
class Color3Property : public Property
{
public:
typedef void (Instance::*instanceSetter)(Color3);
~Color3Property(void){};
Color3Property(LPSTR name, LPSTR desc, LPSTR catalog, Color3 value, Instance * owner, instanceSetter setterFunc)
:Property(name, desc, catalog, &_value, owner)
{
this->_value = value;
this->setterFunc = setterFunc;
}
const void setValue(Color3 val){
(_owner->*setterFunc)(val);
_value = val;
}
PROPGRIDITEM getPropGridItem();
void setProperty(LPPROPGRIDITEM &pItem);
private:
Color3 _value;
instanceSetter setterFunc;
};

View File

@@ -24,6 +24,9 @@ public:
const void* getValue() {
return _value;
}
const LPSTR getName() {
return _name;
}
virtual PROPGRIDITEM getPropGridItem();
virtual void setProperty(LPPROPGRIDITEM &pItem);
protected:

View File

@@ -0,0 +1,26 @@
#pragma once
#include "Property.h"
#include <sstream>
class Vector3Property : public Property
{
public:
typedef void (Instance::*instanceSetter)(Vector3);
~Vector3Property(void){};
Vector3Property(LPSTR name, LPSTR desc, LPSTR catalog, Vector3 value, Instance * owner, instanceSetter setterFunc)
:Property(name, desc, catalog, &_value, owner)
{
this->_value = value;
this->setterFunc = setterFunc;
}
const void setValue(Vector3 val){
(_owner->*setterFunc)(val);
_value = val;
}
PROPGRIDITEM getPropGridItem();
void setProperty(LPPROPGRIDITEM &pItem);
private:
Vector3 _value;
std::string stringRep;
instanceSetter setterFunc;
};

View File

@@ -15,4 +15,5 @@ private:
HWND _explorerComboBox;
void _resize();
void clearExplorer();
void deleteProperties();
};

View File

@@ -63,6 +63,33 @@ static Enum::Controller::Value strEnum(TCHAR * tval)
}
std::vector<Property *> PVInstance::collectProperties()
{
std::vector<Property *> properties = Instance::collectProperties();
properties.push_back(new BoolProperty(
"NameShown",
"This chooses whether the item name is shown",
"Item",
nameShown,
this,
(BoolProperty::instanceSetter)&PVInstance::setNameShown));
properties.push_back(new BoolProperty(
"ControllerFlagShown",
"This chooses whether the item's ControllerFlag is shown",
"Item",
controllerFlagShown,
this,
(BoolProperty::instanceSetter)&PVInstance::setControllerFlagShown));
return properties;
}
void PVInstance::setNameShown(bool nameShown){
this->nameShown = nameShown;
}
void PVInstance::setControllerFlagShown(bool controllerFlagShown){
this->controllerFlagShown = controllerFlagShown;
}
std::vector<PROPGRIDITEM> PVInstance::getProperties()
{

View File

@@ -674,6 +674,49 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
else PVInstance::PropUpdate(item);
}
void PartInstance::setColor(Color3 color)
{
this->color = color;
changed = true;
}
std::vector<Property *> PartInstance::collectProperties()
{
std::vector<Property *> properties = PVInstance::collectProperties();
properties.push_back(new Color3Property(
"Color3",
"The color of the selected part",
"Properties",
color,
this,
(Color3Property::instanceSetter)&PartInstance::setColor));
properties.push_back(new BoolProperty(
"Anchored",
"Whether the block can move or not",
"Item",
anchored,
this,
(BoolProperty::instanceSetter)&PartInstance::setAnchored));
properties.push_back(new Vector3Property(
"Offset",
"The position of the object in the workspace",
"Item",
position,
this,
(Vector3Property::instanceSetter)&PartInstance::setPosition));
properties.push_back(new Vector3Property(
"Size",
"The size of the object in the workspace",
"Item",
size,
this,
(Vector3Property::instanceSetter)&PartInstance::setSize));
return properties;
}
// This needs to be changed, buffer size of 12 is way too small
// Crash occurs if you put a huge number in
char changeTimerTxt[12];

View File

@@ -0,0 +1,21 @@
#include "PropertiesV2/Color3Property.h"
PROPGRIDITEM Color3Property::getPropGridItem(){
PROPGRIDITEM pItem;
PropGrid_ItemInit(pItem);
pItem.lpszCatalog=_catalog;
pItem.lpszPropName=_name;
pItem.lpszPropDesc=_desc;
pItem.lpCurValue=RGB((_value.r*255),(_value.g*255),(_value.b*255));
pItem.iItemType=PIT_COLOR;
return pItem;
}
void Color3Property::setProperty(LPPROPGRIDITEM &pItem){
setValue(Color3(
GetRValue(pItem->lpCurValue)/255.0F,
GetGValue(pItem->lpCurValue)/255.0F,
GetBValue(pItem->lpCurValue)/255.0F
));
}

View File

@@ -0,0 +1,33 @@
#include "PropertiesV2/Vector3Property.h"
PROPGRIDITEM Vector3Property::getPropGridItem(){
std::stringstream s;
s << _value.x << ", " << _value.y << ", " << _value.z;
stringRep = s.str();
PROPGRIDITEM pItem;
PropGrid_ItemInit(pItem);
pItem.lpszCatalog=_catalog;
pItem.lpszPropName=_name;
pItem.lpszPropDesc=_desc;
pItem.lpCurValue=(LPARAM)stringRep.c_str();
pItem.iItemType=PIT_EDIT;
return pItem;
}
void Vector3Property::setProperty(LPPROPGRIDITEM &pItem){
std::string str = (LPTSTR)pItem->lpCurValue;
std::vector<float> vect;
std::stringstream ss(str);
float i;
while (ss >> i)
{
vect.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
if(vect.size() == 3)
{
setValue(Vector3(vect.at(0),vect.at(1),vect.at(2)));
}
}

View File

@@ -186,8 +186,15 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LPNMHDR pnm = (LPNMHDR)lParam;
LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm;
LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex);
selectedInstance->PropUpdate(item);
//propWind->UpdateSelected(selectedInstance);
for(size_t i = 0; i < prop.size(); i++)
{
if(strcmp(item->lpszPropName, prop[i]->getName()) == 0)
{
prop[i]->setProperty(item);
}
}
//selectedInstance->PropUpdate(item);
propWind->UpdateSelected(g_dataModel->getSelectionService()->getSelection());
}
}
break;
@@ -342,6 +349,7 @@ void PropertyWindow::_resize()
void PropertyWindow::UpdateSelected(std::vector<Instance *> instances)
{
deleteProperties();
if(instances.size() <= 0)
{
ClearProperties();
@@ -371,6 +379,16 @@ void PropertyWindow::UpdateSelected(std::vector<Instance *> instances)
void PropertyWindow::ClearProperties()
{
deleteProperties();
clearExplorer();
PropGrid_ResetContent(_propGrid);
}
void PropertyWindow::deleteProperties()
{
while(prop.size() > 0) {
Property * toDelete = prop.back();
prop.pop_back();
delete toDelete;
}
}