[olympic/studio,nostalgia] Change Editor item name to item path, make
TileSheetEditorImGui inherit from Editor
This commit is contained in:
parent
960889749d
commit
819e93bb1c
@ -18,7 +18,7 @@ namespace nostalgia::core {
|
|||||||
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path):
|
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path):
|
||||||
Editor(path),
|
Editor(path),
|
||||||
m_ctx(ctx),
|
m_ctx(ctx),
|
||||||
m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(itemName())).unwrapThrow()) {
|
m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteEditorImGui::draw(turbine::Context&) noexcept {
|
void PaletteEditorImGui::draw(turbine::Context&) noexcept {
|
||||||
@ -131,7 +131,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept {
|
|||||||
|
|
||||||
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
return sctx->project->writeObj(itemName(), m_pal);
|
return sctx->project->writeObj(itemPath(), m_pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,9 @@ ox::Error toPngFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path):
|
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path):
|
||||||
|
Editor(path),
|
||||||
m_ctx(ctx),
|
m_ctx(ctx),
|
||||||
m_itemPath(path),
|
m_tileSheetEditor(m_ctx, path, *undoStack()) {
|
||||||
m_tileSheetEditor(m_ctx, m_itemPath) {
|
|
||||||
const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
|
|
||||||
m_itemName = m_itemPath.substr(lastSlash + 1);
|
|
||||||
oxIgnoreError(setPaletteSelection());
|
oxIgnoreError(setPaletteSelection());
|
||||||
// connect signal/slots
|
// connect signal/slots
|
||||||
undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges);
|
undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges);
|
||||||
@ -54,14 +52,6 @@ TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringVi
|
|||||||
model()->paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
|
model()->paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::CStringView TileSheetEditorImGui::itemName() const noexcept {
|
|
||||||
return m_itemPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
ox::CStringView TileSheetEditorImGui::itemDisplayName() const noexcept {
|
|
||||||
return m_itemName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheetEditorImGui::exportFile() {
|
void TileSheetEditorImGui::exportFile() {
|
||||||
exportSubhseetToPng();
|
exportSubhseetToPng();
|
||||||
}
|
}
|
||||||
@ -231,10 +221,6 @@ void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet *subsheet, T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
studio::UndoStack *TileSheetEditorImGui::undoStack() noexcept {
|
|
||||||
return model()->undoStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::Vec2 TileSheetEditorImGui::clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept {
|
ox::Vec2 TileSheetEditorImGui::clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept {
|
||||||
clickPos.x -= winPos.x + 10;
|
clickPos.x -= winPos.x + 10;
|
||||||
|
@ -23,7 +23,7 @@ enum class Tool {
|
|||||||
Select,
|
Select,
|
||||||
};
|
};
|
||||||
|
|
||||||
class TileSheetEditorImGui: public studio::BaseEditor {
|
class TileSheetEditorImGui: public studio::Editor {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class SubSheetEditor {
|
class SubSheetEditor {
|
||||||
@ -46,8 +46,6 @@ class TileSheetEditorImGui: public studio::BaseEditor {
|
|||||||
turbine::Context &m_ctx;
|
turbine::Context &m_ctx;
|
||||||
ox::Vector<ox::String> m_paletteList;
|
ox::Vector<ox::String> m_paletteList;
|
||||||
SubSheetEditor m_subsheetEditor;
|
SubSheetEditor m_subsheetEditor;
|
||||||
ox::String m_itemPath;
|
|
||||||
ox::String m_itemName;
|
|
||||||
glutils::FrameBuffer m_framebuffer;
|
glutils::FrameBuffer m_framebuffer;
|
||||||
TileSheetEditorView m_tileSheetEditor;
|
TileSheetEditorView m_tileSheetEditor;
|
||||||
float m_palViewWidth = 300;
|
float m_palViewWidth = 300;
|
||||||
@ -59,10 +57,6 @@ class TileSheetEditorImGui: public studio::BaseEditor {
|
|||||||
|
|
||||||
~TileSheetEditorImGui() override = default;
|
~TileSheetEditorImGui() override = default;
|
||||||
|
|
||||||
ox::CStringView itemName() const noexcept override;
|
|
||||||
|
|
||||||
ox::CStringView itemDisplayName() const noexcept override;
|
|
||||||
|
|
||||||
void exportFile() override;
|
void exportFile() override;
|
||||||
|
|
||||||
void cut() override;
|
void cut() override;
|
||||||
@ -77,8 +71,6 @@ class TileSheetEditorImGui: public studio::BaseEditor {
|
|||||||
|
|
||||||
void drawSubsheetSelector(TileSheet::SubSheet*, TileSheet::SubSheetIdx *path);
|
void drawSubsheetSelector(TileSheet::SubSheet*, TileSheet::SubSheetIdx *path);
|
||||||
|
|
||||||
studio::UndoStack *undoStack() noexcept final;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static ox::Vec2 clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept;
|
static ox::Vec2 clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept;
|
||||||
|
|
||||||
|
@ -29,12 +29,13 @@ const Palette TileSheetEditorModel::s_defaultPalette = {
|
|||||||
.colors = ox::Vector<Color16>(128),
|
.colors = ox::Vector<Color16>(128),
|
||||||
};
|
};
|
||||||
|
|
||||||
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path):
|
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
|
||||||
m_ctx(ctx),
|
m_ctx(ctx),
|
||||||
m_path(path),
|
m_path(path),
|
||||||
m_img(*readObj<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()),
|
m_img(*readObj<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()),
|
||||||
// ignore failure to load palette
|
// ignore failure to load palette
|
||||||
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value) {
|
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value),
|
||||||
|
m_undoStack(undoStack) {
|
||||||
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
||||||
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
TileSheet m_img;
|
TileSheet m_img;
|
||||||
TileSheet::SubSheetIdx m_activeSubsSheetIdx;
|
TileSheet::SubSheetIdx m_activeSubsSheetIdx;
|
||||||
keel::AssetRef<Palette> m_pal;
|
keel::AssetRef<Palette> m_pal;
|
||||||
studio::UndoStack m_undoStack;
|
studio::UndoStack &m_undoStack;
|
||||||
class DrawCommand *m_ongoingDrawCommand = nullptr;
|
class DrawCommand *m_ongoingDrawCommand = nullptr;
|
||||||
bool m_updated = false;
|
bool m_updated = false;
|
||||||
bool m_selectionOngoing = false;
|
bool m_selectionOngoing = false;
|
||||||
@ -37,7 +37,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
|
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TileSheetEditorModel(turbine::Context &ctx, ox::StringView path);
|
TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack);
|
||||||
|
|
||||||
~TileSheetEditorModel() override = default;
|
~TileSheetEditorModel() override = default;
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path):
|
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
|
||||||
m_model(ctx, path),
|
m_model(ctx, path, undoStack),
|
||||||
m_pixelsDrawer(&m_model) {
|
m_pixelsDrawer(&m_model) {
|
||||||
// build shaders
|
// build shaders
|
||||||
oxThrowError(m_pixelsDrawer.buildShader());
|
oxThrowError(m_pixelsDrawer.buildShader());
|
||||||
|
@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler {
|
|||||||
std::size_t m_palIdx = 0;
|
std::size_t m_palIdx = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TileSheetEditorView(turbine::Context &ctx, ox::StringView path);
|
TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack);
|
||||||
|
|
||||||
~TileSheetEditorView() override = default;
|
~TileSheetEditorView() override = default;
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ void SceneEditorImGui::onActivated() noexcept {
|
|||||||
|
|
||||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
oxReturnError(sctx->project->writeObj(itemName(), m_editor.scene()));
|
oxReturnError(sctx->project->writeObj(itemPath(), m_editor.scene()));
|
||||||
oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemName(), m_editor.scene()));
|
oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemPath(), m_editor.scene()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ void StudioUI::drawTabs() noexcept {
|
|||||||
if (m_activeEditor != e.get()) {
|
if (m_activeEditor != e.get()) {
|
||||||
m_activeEditor = e.get();
|
m_activeEditor = e.get();
|
||||||
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
|
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
|
||||||
config->activeTabItemName = m_activeEditor->itemName();
|
config->activeTabItemName = m_activeEditor->itemPath();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (m_activeEditorUpdatePending == e.get()) {
|
if (m_activeEditorUpdatePending == e.get()) {
|
||||||
@ -326,7 +326,7 @@ ox::Error StudioUI::openFile(ox::CRStringView path) noexcept {
|
|||||||
ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept {
|
ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept {
|
||||||
if (m_openFiles.contains(path)) {
|
if (m_openFiles.contains(path)) {
|
||||||
for (auto &e : m_editors) {
|
for (auto &e : m_editors) {
|
||||||
if (makeActiveTab && e->itemName() == path) {
|
if (makeActiveTab && e->itemPath() == path) {
|
||||||
m_activeEditor = e.get();
|
m_activeEditor = e.get();
|
||||||
m_activeEditorUpdatePending = e.get();
|
m_activeEditorUpdatePending = e.get();
|
||||||
break;
|
break;
|
||||||
|
@ -32,7 +32,7 @@ class BaseEditor: public Widget {
|
|||||||
* Returns the name of item being edited.
|
* Returns the name of item being edited.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual ox::CStringView itemName() const noexcept = 0;
|
virtual ox::CStringView itemPath() const noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual ox::CStringView itemDisplayName() const noexcept;
|
virtual ox::CStringView itemDisplayName() const noexcept;
|
||||||
@ -98,11 +98,7 @@ class BaseEditor: public Widget {
|
|||||||
* Returns the undo stack holding changes to the item being edited.
|
* Returns the undo stack holding changes to the item being edited.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual UndoStack *undoStack() noexcept {
|
virtual UndoStack *undoStack() noexcept;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ox::StringView pathToItemName(ox::CRStringView path) noexcept;
|
|
||||||
|
|
||||||
void setRequiresConstantRefresh(bool value) noexcept;
|
void setRequiresConstantRefresh(bool value) noexcept;
|
||||||
|
|
||||||
@ -127,15 +123,16 @@ class Editor: public studio::BaseEditor {
|
|||||||
Editor(ox::StringView itemPath) noexcept;
|
Editor(ox::StringView itemPath) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::CStringView itemName() const noexcept final;
|
ox::CStringView itemPath() const noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::CStringView itemDisplayName() const noexcept final;
|
ox::CStringView itemDisplayName() const noexcept final;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
UndoStack *undoStack() noexcept final;
|
UndoStack *undoStack() noexcept final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ox::Error markUnsavedChanges(const UndoCommand*) noexcept;
|
ox::Error markUnsavedChanges(UndoCommand const*) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
ox::CStringView BaseEditor::itemDisplayName() const noexcept {
|
ox::CStringView BaseEditor::itemDisplayName() const noexcept {
|
||||||
return itemName();
|
return itemPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditor::cut() {
|
void BaseEditor::cut() {
|
||||||
@ -37,7 +37,7 @@ bool BaseEditor::requiresConstantRefresh() const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditor::close() const {
|
void BaseEditor::close() const {
|
||||||
this->closed.emit(itemName());
|
this->closed.emit(itemPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditor::save() noexcept {
|
void BaseEditor::save() noexcept {
|
||||||
@ -46,9 +46,9 @@ void BaseEditor::save() noexcept {
|
|||||||
setUnsavedChanges(false);
|
setUnsavedChanges(false);
|
||||||
} else {
|
} else {
|
||||||
if constexpr(ox::defines::Debug) {
|
if constexpr(ox::defines::Debug) {
|
||||||
oxErrorf("Could not save file {}: {} ({}:{})", itemName(), toStr(err), err.file, err.line);
|
oxErrorf("Could not save file {}: {} ({}:{})", itemPath(), toStr(err), err.file, err.line);
|
||||||
} else {
|
} else {
|
||||||
oxErrorf("Could not save file {}: {}", itemName(), toStr(err));
|
oxErrorf("Could not save file {}: {}", itemPath(), toStr(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,9 +102,8 @@ ox::Error BaseEditor::saveItem() noexcept {
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::StringView BaseEditor::pathToItemName(ox::CRStringView path) noexcept {
|
UndoStack *BaseEditor::undoStack() noexcept {
|
||||||
const auto lastSlash = std::find(path.rbegin(), path.rend(), '/').offset();
|
return nullptr;
|
||||||
return substr(path, lastSlash + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditor::setRequiresConstantRefresh(bool value) noexcept {
|
void BaseEditor::setRequiresConstantRefresh(bool value) noexcept {
|
||||||
@ -119,7 +118,7 @@ Editor::Editor(ox::StringView itemPath) noexcept:
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::CStringView Editor::itemName() const noexcept {
|
ox::CStringView Editor::itemPath() const noexcept {
|
||||||
return m_itemPath;
|
return m_itemPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user