[nostalgia/core/studio] Fix palette selection reversion on undo of palette change

This commit is contained in:
Gary Talent 2023-12-09 12:56:23 -06:00
parent 65a179e314
commit 115941a787
4 changed files with 21 additions and 12 deletions

View File

@ -47,20 +47,11 @@ TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringVi
m_tileSheetEditor(m_ctx, m_itemPath) { m_tileSheetEditor(m_ctx, m_itemPath) {
const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1); m_itemName = m_itemPath.substr(lastSlash + 1);
// init palette idx oxIgnoreError(setPaletteSelection());
const auto &palPath = model()->palPath();
auto sctx = applicationData<studio::StudioContext>(m_ctx);
const auto &palList = sctx->project->fileList(core::FileExt_npal);
for (std::size_t i = 0; const auto &pal : palList) {
if (palPath == pal) {
m_selectedPaletteIdx = i;
break;
}
++i;
}
// connect signal/slots // connect signal/slots
undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges); undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges);
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet); m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
model()->paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
} }
ox::String const&TileSheetEditorImGui::itemName() const noexcept { ox::String const&TileSheetEditorImGui::itemName() const noexcept {
@ -401,6 +392,20 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name,
return model()->updateSubsheet(model()->activeSubSheetIdx(), name, cols, rows); return model()->updateSubsheet(model()->activeSubSheetIdx(), name, cols, rows);
} }
ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
const auto &palPath = model()->palPath();
auto sctx = applicationData<studio::StudioContext>(m_ctx);
const auto &palList = sctx->project->fileList(core::FileExt_npal);
for (std::size_t i = 0; const auto &pal : palList) {
if (palPath == pal) {
m_selectedPaletteIdx = i;
break;
}
++i;
}
return {};
}
ox::Error TileSheetEditorImGui::markUnsavedChanges(const studio::UndoCommand*) noexcept { ox::Error TileSheetEditorImGui::markUnsavedChanges(const studio::UndoCommand*) noexcept {
setUnsavedChanges(true); setUnsavedChanges(true);
return {}; return {};

View File

@ -106,6 +106,8 @@ class TileSheetEditorImGui: public studio::BaseEditor {
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept; ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
ox::Error setPaletteSelection() noexcept;
// slots // slots
private: private:
ox::Error markUnsavedChanges(const studio::UndoCommand*) noexcept; ox::Error markUnsavedChanges(const studio::UndoCommand*) noexcept;

View File

@ -753,7 +753,8 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(const studio::UndoCommand *cmd)
m_updated = true; m_updated = true;
const auto cmdId = cmd->commandId(); const auto cmdId = cmd->commandId();
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) { if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
oxReturnError(readObj<Palette>(keelCtx(m_ctx), ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal)); oxReturnError(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).moveTo(&m_pal));
paletteChanged.emit();
} }
auto tsCmd = dynamic_cast<const TileSheetCommand*>(cmd); auto tsCmd = dynamic_cast<const TileSheetCommand*>(cmd);
auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx()); auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx());

View File

@ -20,6 +20,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
public: public:
ox::Signal<ox::Error(const TileSheet::SubSheetIdx&)> activeSubsheetChanged; ox::Signal<ox::Error(const TileSheet::SubSheetIdx&)> activeSubsheetChanged;
ox::Signal<ox::Error()> paletteChanged;
private: private:
static const Palette s_defaultPalette; static const Palette s_defaultPalette;