Skip to content

Commit

Permalink
#123 Implement array property UI, refactor name functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed May 21, 2022
1 parent babbce9 commit 6730f8a
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,40 @@ namespace Skylicht
}
else if (valueProperty->getType() == EPropertyDataType::Object)
{
// sub objects
CObjectSerializable* arrayObject = (CObjectSerializable*)valueProperty;
CSubject<CObjectSerializable*>* subject = new CSubject<CObjectSerializable*>(arrayObject);
CObjectSerializable* object = (CObjectSerializable*)valueProperty;
CSubject<CObjectSerializable*>* subject = new CSubject<CObjectSerializable*>(object);

// header
GUI::CCollapsibleGroup* group = ui->addSubGroup(layout);
group->getHeader()->setLabel(ui->getPrettyName(valueProperty->Name));

GUI::CBoxLayout* layout = ui->createBoxLayout(group);
initDataGUI(arrayObject, layout, ui);

if (object->isArray())
{
CArraySerializable* arrayObject = (CArraySerializable*)object;

if (arrayObject->OnCreateElement != nullptr)
{
// add input to add elements
CSubject<int>* count = new CSubject<int>(arrayObject->getElementCount());
m_subjects.push_back(count);

ui->addNumberTextBox(layout, L"Count", count);

CObserver* observer = new CObserver();
observer->Notify = [&, arrayObject, count, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
// updateData();
}
};
count->addObserver(observer, true);
}
}

// Show child data
initDataGUI(object, layout, ui);

m_subjects.push_back(subject);
}
Expand Down
44 changes: 44 additions & 0 deletions Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,50 @@ namespace Skylicht
boxLayout->endVertical();
}

void CSpaceProperty::addNumberTextBox(GUI::CBoxLayout* boxLayout, const wchar_t* name, CSubject<int>* value)
{
GUI::CLayout* layout = boxLayout->beginVertical();

GUI::CLabel* label = new GUI::CLabel(layout);
label->setPadding(GUI::SMargin(0.0f, 2.0, 0.0f, 0.0f));
label->setString(name);
label->setTextAlignment(GUI::TextRight);

GUI::CNumberInput* input = new GUI::CNumberInput(layout);
input->setNumberType(GUI::ENumberInputType::Integer);
input->alwayFocusTextbox(true);

wchar_t text[32];
swprintf(text, 32, L"%d", value->get());
input->setString(text);

CSpaceProperty::SGroup* group = getGroupByLayout(boxLayout);
if (group != NULL)
{
CObserver* onChange = new CObserver();
onChange->Notify = [me = onChange, target = input](ISubject* subject, IObserver* from)
{
if (from != me)
{
CSubject<std::wstring>* value = (CSubject<std::wstring>*)subject;
target->setString(value->get());
}
};

// when input text change
IObserver* observer = value->addObserver(onChange);
input->OnEnter = [value, input, observer](GUI::CBase* base) {
value->set(input->getValueInt());
value->notify(observer);
};

// hold observer to release later
group->Observer.push_back(observer);
}

boxLayout->endVertical();
}

void CSpaceProperty::addCheckBox(GUI::CBoxLayout* boxLayout, const wchar_t* name, CSubject<bool>* value)
{
GUI::CLayout* layout = boxLayout->beginVertical();
Expand Down
2 changes: 2 additions & 0 deletions Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ namespace Skylicht

void addTextBox(GUI::CBoxLayout* boxLayout, const wchar_t* name, CSubject<std::wstring>* value);

void addNumberTextBox(GUI::CBoxLayout* boxLayout, const wchar_t* name, CSubject<int>* value);

void addCheckBox(GUI::CBoxLayout* boxLayout, const wchar_t* name, CSubject<bool>* value);

void addComboBox(GUI::CBoxLayout* boxLayout, const wchar_t* name, CSubject<std::wstring>* value, const std::vector<std::wstring>& listValue);
Expand Down
34 changes: 32 additions & 2 deletions Projects/Editor/Source/GUI/Controls/CNumberInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Skylicht
m_mouseDownX(0.0f),
m_mouseDownY(0.0f),
m_focusTextbox(false),
m_alwayFocusTextbox(false),
m_value(0.0f),
m_stepValue(1.0f),
m_mousePress(false),
Expand All @@ -58,7 +59,7 @@ namespace Skylicht

void CNumberInput::think()
{
if (m_focusTextbox)
if (m_focusTextbox || m_alwayFocusTextbox)
CTextBox::think();
else
{
Expand All @@ -84,6 +85,9 @@ namespace Skylicht
{
CTextBox::renderUnder();

if (m_alwayFocusTextbox)
return;

if (m_drawTextbox && isHovered() && !m_focusTextbox)
{
CTheme* theme = CTheme::getTheme();
Expand All @@ -98,6 +102,15 @@ namespace Skylicht
// disable default textbox focus
}

void CNumberInput::alwayFocusTextbox(bool b)
{
m_alwayFocusTextbox = b;
if (b)
setCursor(ECursorType::Beam);
else
setCursor(ECursorType::SizeWE);
}

void CNumberInput::onTabableFocus()
{
CTextBox::onKeyboardFocus();
Expand All @@ -124,7 +137,22 @@ namespace Skylicht
{
m_mousePress = down;

if (m_focusTextbox == true)
if (m_alwayFocusTextbox)
{
if (down)
CTextBox::onKeyboardFocus();

CTextBox::onMouseClickLeft(x, y, down);

if (down)
{
onSelectAll(this);
setCursor(ECursorType::Beam);
}
return;
}

if (m_focusTextbox)
{
// default textbox function
CTextBox::onMouseClickLeft(x, y, down);
Expand Down Expand Up @@ -220,6 +248,8 @@ namespace Skylicht
}
else if (c == '\r')
{
if (OnEnter != nullptr)
OnEnter(this);
onLostKeyboardFocus();
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CNumberInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Skylicht
float m_cursorX;
float m_cursorY;

bool m_alwayFocusTextbox;
bool m_focusTextbox;

float m_stepValue;
Expand Down Expand Up @@ -100,6 +101,8 @@ namespace Skylicht
m_numberType = type;
}

void alwayFocusTextbox(bool b);

protected:

void applyTextValue();
Expand Down
2 changes: 1 addition & 1 deletion Projects/Editor/Source/ProjectSettings/CObjectLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Skylicht
for (int i = 0; i < 16; i++)
{
sprintf(name, "%d", i);
addAutoRelease(new CStringProperty(this, name, ""));
autoRelease(new CStringProperty(this, name, ""));
}

setName(0, "Default");
Expand Down
6 changes: 3 additions & 3 deletions Projects/Skylicht/Components/Source/SkyBox/CSkyBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ namespace Skylicht

std::vector<std::string> textureExts = { "tga","png" };

object->addAutoRelease(new CFilePathProperty(object, "texture", m_texture.c_str(), textureExts));
object->addAutoRelease(new CColorProperty(object, "color", m_color));
object->addAutoRelease(new CFloatProperty(object, "intensity", m_intensity, 0.0f, 3.0f));
object->autoRelease(new CFilePathProperty(object, "texture", m_texture.c_str(), textureExts));
object->autoRelease(new CColorProperty(object, "color", m_color));
object->autoRelease(new CFloatProperty(object, "intensity", m_intensity, 0.0f, 3.0f));

return object;
}
Expand Down
6 changes: 3 additions & 3 deletions Projects/Skylicht/Components/Source/SkyDome/CSkyDome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ namespace Skylicht

std::vector<std::string> textureExts = { "tga","png" };

object->addAutoRelease(new CFilePathProperty(object, "texture", m_texture.c_str(), textureExts));
object->addAutoRelease(new CColorProperty(object, "color", m_color));
object->addAutoRelease(new CFloatProperty(object, "intensity", m_intensity, 0.0f, 3.0f));
object->autoRelease(new CFilePathProperty(object, "texture", m_texture.c_str(), textureExts));
object->autoRelease(new CColorProperty(object, "color", m_color));
object->autoRelease(new CFloatProperty(object, "intensity", m_intensity, 0.0f, 3.0f));

return object;
}
Expand Down
20 changes: 10 additions & 10 deletions Projects/Skylicht/Components/Source/SkySun/CSkySun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ namespace Skylicht
CFloatProperty* skyProperty = new CFloatProperty(object, "Intensity", m_skyIntensity, 0.0f);
skyProperty->setUIHeader("Sky");
skyProperty->setUISpace(10.0f);
object->addAutoRelease(skyProperty);
object->autoRelease(skyProperty);

CColorProperty* atmosphericProperty = new CColorProperty(object, "Atmospheric Color", m_atmosphericColor);
atmosphericProperty->setUIHeader("Atmospheric");
object->addAutoRelease(atmosphericProperty);
object->addAutoRelease(new CFloatProperty(object, "Atmospheric Intensity", m_atmosphericIntensity, 0.0f));
object->autoRelease(atmosphericProperty);
object->autoRelease(new CFloatProperty(object, "Atmospheric Intensity", m_atmosphericIntensity, 0.0f));

CColorProperty* sunProperty = new CColorProperty(object, "Sun Color", m_sunColor);
sunProperty->setUIHeader("Sun");
object->addAutoRelease(sunProperty);
object->addAutoRelease(new CFloatProperty(object, "Sun Intensity", m_sunIntensity, 0.0f));
object->addAutoRelease(new CFloatProperty(object, "Sun Size", m_sunSize, 1.0f, 5000.0f));
object->autoRelease(sunProperty);
object->autoRelease(new CFloatProperty(object, "Sun Intensity", m_sunIntensity, 0.0f));
object->autoRelease(new CFloatProperty(object, "Sun Size", m_sunSize, 1.0f, 5000.0f));

CColorProperty* glareProperty = new CColorProperty(object, "Glare1 Color", m_glare1Color);
glareProperty->setUIHeader("Glare");
object->addAutoRelease(glareProperty);
object->addAutoRelease(new CFloatProperty(object, "Glare1 Intensity", m_glare1Intensity, 0.0f));
object->autoRelease(glareProperty);
object->autoRelease(new CFloatProperty(object, "Glare1 Intensity", m_glare1Intensity, 0.0f));

object->addAutoRelease(new CColorProperty(object, "Glare2 Color", m_glare2Color));
object->addAutoRelease(new CFloatProperty(object, "Glare2 Intensity", m_glare2Intensity, 0.0f));
object->autoRelease(new CColorProperty(object, "Glare2 Color", m_glare2Color));
object->autoRelease(new CFloatProperty(object, "Glare2 Intensity", m_glare2Intensity, 0.0f));

return object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace Skylicht
CObjectSerializable* CComponentSystem::createSerializable()
{
CObjectSerializable* object = new CObjectSerializable(getTypeName().c_str());
object->addAutoRelease(new CBoolProperty(object, "enable", isEnable()));
object->autoRelease(new CBoolProperty(object, "enable", isEnable()));
return object;
}

Expand Down
16 changes: 8 additions & 8 deletions Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,16 @@ namespace Skylicht
CObjectSerializable* CGameObject::createSerializable()
{
CObjectSerializable* object = new CObjectSerializable(getTypeName().c_str());
object->addAutoRelease(new CStringProperty(object, "id", getID().c_str()));
object->addAutoRelease(new CStringProperty(object, "name", getNameA()));
object->addAutoRelease(new CBoolProperty(object, "enable", isEnable()));
object->addAutoRelease(new CBoolProperty(object, "visible", isVisible()));
object->addAutoRelease(new CBoolProperty(object, "static", isStatic()));
object->addAutoRelease(new CUIntProperty(object, "culling", getCullingLayer()));
object->autoRelease(new CStringProperty(object, "id", getID().c_str()));
object->autoRelease(new CStringProperty(object, "name", getNameA()));
object->autoRelease(new CBoolProperty(object, "enable", isEnable()));
object->autoRelease(new CBoolProperty(object, "visible", isVisible()));
object->autoRelease(new CBoolProperty(object, "static", isStatic()));
object->autoRelease(new CUIntProperty(object, "culling", getCullingLayer()));

CObjectSerializable* coms = new CObjectSerializable("Components");
object->addProperty(coms);
object->addAutoRelease(coms);
object->autoRelease(coms);

size_t numComponents = m_components.size();
CComponentSystem** components = m_components.data();
Expand All @@ -412,7 +412,7 @@ namespace Skylicht
if (data->Name != "CComponentSystem")
{
coms->addProperty(data);
coms->addAutoRelease(data);
coms->autoRelease(data);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ namespace Skylicht
enumType->addEnumString("Lightmap", EIndirectType::LightmapArray);
enumType->addEnumString("Vertex Color", EIndirectType::VertexColor);
enumType->addEnumString("SH9", EIndirectType::SH9);
object->addAutoRelease(enumType);
object->autoRelease(enumType);

CArraySerializable* textureArray = new CArraySerializable("LMTextures", object);
object->addAutoRelease(textureArray);
object->autoRelease(textureArray);

std::vector<std::string> textureExts = { "tga","png" };
for (u32 i = 0, n = (u32)m_lightmapPaths.size(); i < n; i++)
{
char name[43];
sprintf(name, "%d", i);

textureArray->addAutoRelease(
textureArray->autoRelease(
new CFilePathProperty(
textureArray,
name,
Expand Down
4 changes: 2 additions & 2 deletions Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ namespace Skylicht

CArraySerializable* probes = new CArraySerializable("Probes");
object->addProperty(probes);
object->addAutoRelease(probes);
object->autoRelease(probes);

int numProbes = (int)m_entities.size();
for (int i = 0; i < numProbes; i++)
{
CProbeSerializable* probeData = new CProbeSerializable(probes);
probes->addAutoRelease(probeData);
probes->autoRelease(probeData);

CWorldTransformData* world = (CWorldTransformData*)m_entities[i]->getDataByIndex(CWorldTransformData::DataTypeIndex);
CLightProbeData* light = (CLightProbeData*)m_entities[i]->getDataByIndex(CLightProbeData::DataTypeIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Skylicht
{
sprintf(name, "sh%d", i);
SH[i] = new CVector3Property(this, name);
addAutoRelease(SH[i]);
autoRelease(SH[i]);
}
}

Expand All @@ -53,7 +53,7 @@ namespace Skylicht
{
sprintf(name, "sh%d", i);
SH[i] = new CVector3Property(this, name);
addAutoRelease(SH[i]);
autoRelease(SH[i]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Projects/Skylicht/Engine/Source/Lighting/CLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ namespace Skylicht
CObjectSerializable* CLight::createSerializable()
{
CObjectSerializable* object = CComponentSystem::createSerializable();
object->addAutoRelease(new CUIntProperty(object, "bakeBounce", m_bakeBounce, 4));
object->addAutoRelease(new CBoolProperty(object, "castShadow", m_castShadow));
object->addAutoRelease(new CColorProperty(object, "color", m_color.toSColor()));
object->addAutoRelease(new CFloatProperty(object, "intensity", m_intensity, 0.0f, 10.0f));
object->autoRelease(new CUIntProperty(object, "bakeBounce", m_bakeBounce, 4));
object->autoRelease(new CBoolProperty(object, "castShadow", m_castShadow));
object->autoRelease(new CColorProperty(object, "color", m_color.toSColor()));
object->autoRelease(new CFloatProperty(object, "intensity", m_intensity, 0.0f, 10.0f));
return object;
}

Expand Down
2 changes: 1 addition & 1 deletion Projects/Skylicht/Engine/Source/Lighting/CPointLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace Skylicht
{
CObjectSerializable* object = CLight::createSerializable();

object->addAutoRelease(new CFloatProperty(object, "radius", m_radius, 0.0f));
object->autoRelease(new CFloatProperty(object, "radius", m_radius, 0.0f));
return object;
}

Expand Down
Loading

0 comments on commit 6730f8a

Please sign in to comment.