From 4c6e053e819e29a0baae3a6b4c5d636ff3c45bae Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 29 Mar 2020 19:00:02 -0500 Subject: [PATCH] [nostalgia/core/studio] Make TileSheetEditor reload when the current palette is updated --- src/nostalgia/core/studio/tilesheeteditor.cpp | 9 +++++++++ src/nostalgia/core/studio/tilesheeteditor.hpp | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index cf63d179..a0744677 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -294,6 +294,10 @@ void SheetData::load(const studio::Context *ctx, QString ngPath, QString palPath updatePixels(ng.get()); } +void SheetData::reload(const studio::Context *ctx) { + load(ctx, m_tilesheetPath, m_currentPalettePath); +} + void SheetData::save(const studio::Context *ctx, QString ngPath) const { auto ng = toNostalgiaGraphic(); ctx->project->writeObj(ngPath, ng.get()); @@ -512,6 +516,11 @@ QWidget *TileSheetEditor::setupColorPicker(QWidget *parent) { m_colorPicker.palette->addItem(name); } }); + m_ctx->project->subscribe(studio::ProjectEvent::FileUpdated, m_colorPicker.palette, [this](QString path) { + if (path == m_sheetData.palettePath()) { + m_sheetData.reload(m_ctx); + } + }); m_ctx->project->subscribe(studio::ProjectEvent::FileDeleted, m_colorPicker.palette, [this](QString path) { if (path.startsWith(PaletteDir) && path.endsWith(FileExt_npal)) { auto name = paletteName(path); diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index 355bb08e..70365faf 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -61,6 +61,8 @@ class SheetData: public QObject { void load(const studio::Context *ctx, QString ngPath, QString palPath = ""); + void reload(const studio::Context *ctx); + void save(const studio::Context *ctx, QString ngPath) const; void setPalette(const NostalgiaPalette *pal); @@ -129,7 +131,7 @@ class TileSheetEditor: public studio::Editor { virtual ~TileSheetEditor(); - QString itemName() override; + QString itemName() const override; void exportFile() override;