Skip to content

Commit

Permalink
Traktor: Fixed re-creating UiKit preview when a dependent resource ha…
Browse files Browse the repository at this point in the history
…s been reloaded.
  • Loading branch information
apistol78 committed Oct 9, 2023
1 parent 0eb46b2 commit a114700
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions code/Resource/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ class Proxy
m_tag = (intptr_t)getResource();
}

/*! Un-consume change; useful for forcing a consume again. */
void unconsume()
{
m_tag = 0;
}

operator bool () const
{
return getResource() != nullptr;
Expand Down
7 changes: 7 additions & 0 deletions code/UiKit/Editor/PreviewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ void PreviewControl::setScaffolding(const Scaffolding* scaffolding)
m_scaffoldingClass.clear();
}

void PreviewControl::invalidateScaffolding(const Guid& eventId)
{
// This will cause the tag in the proxy to be zero so the scaffolding will get re-created.
if (m_scaffolding != nullptr && (Guid)m_scaffolding->getScaffoldingClass() != eventId)
m_scaffoldingClass.unconsume();
}

void PreviewControl::setDebugWires(bool debugWires)
{
m_debugWires = debugWires;
Expand Down
2 changes: 2 additions & 0 deletions code/UiKit/Editor/PreviewControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class PreviewControl : public ui::Widget

void setScaffolding(const Scaffolding* scaffolding);

void invalidateScaffolding(const Guid& eventId);

void setDebugWires(bool debugWires);

bool getDebugWires() const { return m_debugWires; }
Expand Down
9 changes: 8 additions & 1 deletion code/UiKit/Editor/PreviewEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ bool PreviewEditor::handleCommand(const ui::Command& command)
void PreviewEditor::handleDatabaseEvent(db::Database* database, const Guid& eventId)
{
if (m_resourceManager && database == m_editor->getOutputDatabase())
m_resourceManager->reload(eventId, false);
{
if (m_resourceManager->reload(eventId, false))
{
// Content in resource manager was reloaded; in case it's not the main scaffolding script
// we need to invalidate it manually so the scaffolding is re-created properly.
m_previewControl->invalidateScaffolding(eventId);
}
}
}

void PreviewEditor::eventPreviewSize(ui::SizeEvent* event)
Expand Down

0 comments on commit a114700

Please sign in to comment.