Skip to content

Commit

Permalink
Implement save history for GUI Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Sep 26, 2024
1 parent a1116d0 commit 7130f69
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 40 deletions.
14 changes: 13 additions & 1 deletion Projects/Editor/Source/Editor/GUIEditor/CGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This file is part of the "Skylicht Engine".
#include "CGUIEditor.h"
#include "Editor/CEditor.h"
#include "Editor/Space/GUIDesign/CSpaceGUIDesign.h"
#include "Editor/SpaceController/CGUIDesignController.h"
#include "Selection/CSelection.h"

namespace Skylicht
Expand All @@ -34,7 +35,8 @@ namespace Skylicht
{
CGUIEditor::CGUIEditor() :
m_gui(NULL),
m_guiData(NULL)
m_guiData(NULL),
m_isChanged(false)
{

}
Expand All @@ -46,6 +48,12 @@ namespace Skylicht

void CGUIEditor::closeGUI()
{
if (m_isChanged)
{
// save history
CGUIDesignController::getInstance()->getHistory()->saveModifyHistory(m_gui);
}

if (m_guiData)
delete m_guiData;
m_gui = NULL;
Expand All @@ -55,12 +63,16 @@ namespace Skylicht

void CGUIEditor::initGUI(CGUIElement* gui, CSpaceProperty* ui)
{
m_isChanged = false;
m_gui = gui;
m_guiData = m_gui->createSerializable();
}

void CGUIEditor::onUpdateValue(CObjectSerializable* object)
{
if (object)
m_isChanged = true;

m_gui->loadSerializable(m_guiData);

// notify to update on GUI
Expand Down
2 changes: 2 additions & 0 deletions Projects/Editor/Source/Editor/GUIEditor/CGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace Skylicht
CGUIElement* m_gui;
CObjectSerializable* m_guiData;

bool m_isChanged;

public:
CGUIEditor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This file is part of the "Skylicht Engine".
#include "CGUITransformGizmos.h"
#include "Handles/CGUIHandles.h"
#include "Editor/SpaceController/CSceneController.h"
#include "Editor/SpaceController/CGUIDesignController.h"
#include "Editor/CEditor.h"
#include "Activator/CEditorActivator.h"
#include "Editor/GUIEditor/CGUIEditor.h"
Expand Down Expand Up @@ -134,8 +135,8 @@ namespace Skylicht
handle->end();

// save undo/redo
// if (m_changed)
// saveHistorySelectedObject();
if (m_changed)
saveHistorySelectedObject();
}
}

Expand Down Expand Up @@ -166,8 +167,8 @@ namespace Skylicht
m_selectID = "";

// save undo/redo
// if (m_changed)
// saveHistorySelectedObject();
if (m_changed)
saveHistorySelectedObject();
}
}
}
Expand Down Expand Up @@ -308,5 +309,13 @@ namespace Skylicht
}
}
}

void CGUITransformGizmos::saveHistorySelectedObject()
{
std::vector<CGUIElement*> selectedObject;
getSelectedGUI(selectedObject);

CGUIDesignController::getInstance()->getHistory()->saveModifyHistory(selectedObject);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace Skylicht

void getSelectedGUI(std::vector<CGUIElement*>& guis);

void saveHistorySelectedObject();

protected:

void updateProperty();
Expand Down
20 changes: 10 additions & 10 deletions Projects/Editor/Source/Editor/Gizmos/Transform/CTransformGizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Skylicht
m_rotation(core::quaternion()),
m_scale(core::vector3df(1.0f, 1.0f, 1.0f)),
m_lastType(ETransformGizmo::Translate),
changed(false)
m_changed(false)
{
getSubjectTransformGizmos().addObserver(this);

Expand Down Expand Up @@ -183,7 +183,7 @@ namespace Skylicht
m_parentWorld.makeIdentity();
handle->setWorld(m_parentWorld);
handle->end();
changed = false;
m_changed = false;
m_selectID = "";
return;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace Skylicht
m_position = m_transform->getPosition();
m_rotation = m_transform->getRotationQuaternion();
m_scale = m_transform->getScale();
changed = false;
m_changed = false;

onEnable();
}
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace Skylicht

m_transform->setPosition(newPos);

changed = true;
m_changed = true;
}

if (handle->endCheck())
Expand All @@ -255,7 +255,7 @@ namespace Skylicht
handle->end();

// save undo/redo
if (changed)
if (m_changed)
saveHistorySelectedObject();

m_cacheSelectedObjects.clear();
Expand All @@ -279,7 +279,7 @@ namespace Skylicht
m_rotation.notify(this);

m_transform->setRotation(newRot);
changed = true;
m_changed = true;
}

if (handle->endCheck())
Expand All @@ -288,7 +288,7 @@ namespace Skylicht
handle->end();

// save undo/redo
if (changed)
if (m_changed)
saveHistorySelectedObject();

m_cacheSelectedObjects.clear();
Expand All @@ -306,7 +306,7 @@ namespace Skylicht
m_scale.notify(this);

m_transform->setScale(newScale);
changed = true;
m_changed = true;
}

if (handle->endCheck())
Expand All @@ -315,7 +315,7 @@ namespace Skylicht
handle->end();

// save undo/redo
if (changed)
if (m_changed)
saveHistorySelectedObject();

m_cacheSelectedObjects.clear();
Expand All @@ -325,7 +325,7 @@ namespace Skylicht
{
handle->end();
m_cacheSelectedObjects.clear();
changed = false;
m_changed = false;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Skylicht
CGameObject* m_selectObject;
CTransformEuler* m_transform;

bool changed;
bool m_changed;

CSubject<core::vector3df> m_position;
CSubject<core::quaternion> m_rotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Skylicht
CSubject<float>* Z = new CSubject<float>(v.Z);

CObserver* observer = new CObserver();
observer->Notify = [&, value, X, Y, Z, observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, X, Y, Z, observer](ISubject* subject, IObserver* from)
{
if (from != observer)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace Skylicht
{
CBoolProperty* value = dynamic_cast<CBoolProperty*>(valueProperty);
CSubject<bool>* subject = new CSubject<bool>(value->get());
CObserver* observer = new CObserver([&, value, s = subject](ISubject* subject, IObserver* from)
CObserver* observer = new CObserver([&, object, value, s = subject](ISubject* subject, IObserver* from)
{
value->set(s->get());
onUpdateValue(object);
Expand Down Expand Up @@ -177,7 +177,7 @@ namespace Skylicht
// add slider control on Limit Float
CSubject<float>* subject = new CSubject<float>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace Skylicht
{
CSubject<float>* subject = new CSubject<float>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -260,7 +260,7 @@ namespace Skylicht
CIntProperty* value = dynamic_cast<CIntProperty*>(valueProperty);
CSubject<int>* subject = new CSubject<int>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -311,7 +311,7 @@ namespace Skylicht
CUIntProperty* value = dynamic_cast<CUIntProperty*>(valueProperty);
CSubject<u32>* subject = new CSubject<u32>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -360,7 +360,7 @@ namespace Skylicht
CSubject<std::wstring>* subject = new CSubject<std::wstring>(stringValue);

CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace Skylicht
CColorProperty* value = dynamic_cast<CColorProperty*>(valueProperty);
CSubject<SColor>* subject = new CSubject<SColor>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -426,7 +426,7 @@ namespace Skylicht
CFilePathProperty* value = dynamic_cast<CFilePathProperty*>(valueProperty);
CSubject<std::string>* subject = new CSubject<std::string>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -469,7 +469,7 @@ namespace Skylicht
CFolderPathProperty* value = dynamic_cast<CFolderPathProperty*>(valueProperty);
CSubject<std::string>* subject = new CSubject<std::string>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -535,7 +535,7 @@ namespace Skylicht
if (enumData.Value == currentValue)
dropBox->setLabel(enumName);

item->OnPress = [&, item, enumValue, dropBox, ui](GUI::CBase* base)
item->OnPress = [&, object, item, enumValue, dropBox, ui](GUI::CBase* base)
{
enumValue->setIntValue(item->getTagInt());

Expand Down Expand Up @@ -587,7 +587,7 @@ namespace Skylicht
objectLayout = ui->createBoxLayout(group);

CObserver* observer = new CObserver();
observer->Notify = [&, arrayObject, count, o = observer, objectLayout, group, ui](ISubject* subject, IObserver* from)
observer->Notify = [&, object, arrayObject, count, o = observer, objectLayout, group, ui](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -619,7 +619,7 @@ namespace Skylicht
CImageSourceProperty* value = dynamic_cast<CImageSourceProperty*>(valueProperty);
CSubject<std::string>* subject = new CSubject<std::string>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -783,7 +783,7 @@ namespace Skylicht
objectLayout = ui->createBoxLayout(group);

CObserver* observer = new CObserver();
observer->Notify = [&, arrayObject, count, o = observer, objectLayout, group, ui](ISubject* subject, IObserver* from)
observer->Notify = [&, object, arrayObject, count, o = observer, objectLayout, group, ui](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -815,7 +815,7 @@ namespace Skylicht
CImageSourceProperty* value = dynamic_cast<CImageSourceProperty*>(valueProperty);
CSubject<std::string>* subject = new CSubject<std::string>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down Expand Up @@ -954,7 +954,7 @@ namespace Skylicht
CFrameSourceProperty* value = dynamic_cast<CFrameSourceProperty*>(valueProperty);
CSubject<std::string>* subject = new CSubject<std::string>(value->get());
CObserver* observer = new CObserver();
observer->Notify = [&, value, s = subject, o = observer](ISubject* subject, IObserver* from)
observer->Notify = [&, object, value, s = subject, o = observer](ISubject* subject, IObserver* from)
{
if (from != o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ namespace Skylicht
std::wstring newName = nameHint + L" " + newNode->getNameW();
newNode->setName(newName.c_str());

// add history create
std::vector<CGUIElement*> listObjects;
newNode->getAllChilds(listObjects);
m_history->saveCreateHistory(listObjects);

createGUINode(parent, newNode);
}
}
Expand Down Expand Up @@ -545,11 +550,11 @@ namespace Skylicht
});

CGUIElement* root = m_guiCanvas->getRootElement();
CGUIElement* fullRect = root->getChilds()[0];
CGUIElement* rootCanvas = root->getChilds()[0];

for (CGUIElement* sel : selelectList)
{
if (sel == fullRect)
if (sel == rootCanvas)
continue;

bool addToDeleteList = true;
Expand All @@ -568,6 +573,9 @@ namespace Skylicht
}
}

// add history
m_history->saveDeleteHistory(deleteList);

for (CGUIElement* del : deleteList)
{
del->remove();
Expand Down
Loading

0 comments on commit 7130f69

Please sign in to comment.