[nostalgia] Split studio::Editor into Editor and BaseEditor

This commit is contained in:
2022-04-09 16:20:39 -05:00
parent 56964e197a
commit edf4571ff7
8 changed files with 64 additions and 55 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ ox::Vector<studio::EditorMaker> Module::editors(core::Context *ctx) noexcept {
return {
{
{"ng"},
[ctx](const ox::String &path) -> ox::Result<studio::Editor*> {
[ctx](const ox::String &path) -> ox::Result<studio::BaseEditor*> {
try {
return new TileSheetEditorImGui(ctx, path);
} catch (const ox::Exception &ex) {
@@ -23,7 +23,7 @@ ox::Vector<studio::EditorMaker> Module::editors(core::Context *ctx) noexcept {
},
{
{"npal"},
[ctx](const ox::String &path) -> ox::Result<studio::Editor*> {
[ctx](const ox::String &path) -> ox::Result<studio::BaseEditor*> {
return PaletteEditorImGui::make(ctx, path);
}
}
@@ -21,11 +21,10 @@ ox::Result<PaletteEditorImGui*> PaletteEditorImGui::make(Context *ctx, const ox:
out->m_itemName = out->m_itemPath.substr(lastSlash + 1);
oxRequire(pal, core::readObj<Palette>(out->m_ctx, out->m_itemPath));
out->m_pal = *pal.get();
out->undoStack()->changeTriggered.connect(out.get(), &PaletteEditorImGui::markUnsavedChanges);
return out.release();
}
const ox::String &PaletteEditorImGui::itemName() const {
const ox::String &PaletteEditorImGui::itemName() const noexcept {
return m_itemPath;
}
@@ -33,10 +32,6 @@ const ox::String &PaletteEditorImGui::itemDisplayName() const noexcept {
return m_itemName;
}
studio::UndoStack *PaletteEditorImGui::undoStack() noexcept {
return &m_undoStack;
}
void PaletteEditorImGui::draw(core::Context*) noexcept {
static constexpr auto flags = ImGuiTableFlags_RowBg;
const auto paneSize = ImGui::GetContentRegionAvail();
@@ -50,20 +45,20 @@ void PaletteEditorImGui::draw(core::Context*) noexcept {
{
const auto sz = ImVec2(70, 24);
if (ImGui::Button("Add", sz)) {
m_undoStack.push(new AddColorCommand(&m_pal, 0, m_pal.colors.size()));
undoStack()->push(new AddColorCommand(&m_pal, 0, m_pal.colors.size()));
}
ImGui::SameLine();
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size());
{
if (ImGui::Button("Remove", sz)) {
m_undoStack.push(new RemoveColorCommand(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], m_selectedRow));
undoStack()->push(new RemoveColorCommand(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], m_selectedRow));
m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow);
}
ImGui::SameLine();
ImGui::BeginDisabled(m_selectedRow <= 0);
{
if (ImGui::Button("Move Up", sz)) {
m_undoStack.push(new MoveColorCommand(&m_pal, m_selectedRow, -1));
undoStack()->push(new MoveColorCommand(&m_pal, m_selectedRow, -1));
--m_selectedRow;
}
}
@@ -72,7 +67,7 @@ void PaletteEditorImGui::draw(core::Context*) noexcept {
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size() - 1);
{
if (ImGui::Button("Move Down", sz)) {
m_undoStack.push(new MoveColorCommand(&m_pal, m_selectedRow, 1));
undoStack()->push(new MoveColorCommand(&m_pal, m_selectedRow, 1));
++m_selectedRow;
}
}
@@ -132,7 +127,7 @@ void PaletteEditorImGui::draw(core::Context*) noexcept {
ImGui::InputInt("Blue", &b, 1, 5);
const auto newColor = color16(r, g, b, a);
if (c != newColor) {
m_undoStack.push(new UpdateColorCommand(&m_pal, m_selectedRow, c, newColor));
undoStack()->push(new UpdateColorCommand(&m_pal, m_selectedRow, c, newColor));
}
}
ImGui::EndChild();
@@ -148,9 +143,4 @@ ox::Error PaletteEditorImGui::saveItem() noexcept {
return OxError(0);
}
ox::Error PaletteEditorImGui::markUnsavedChanges(int) noexcept {
setUnsavedChanges(true);
return OxError(0);
}
}
@@ -17,7 +17,6 @@ class PaletteEditorImGui: public studio::Editor {
ox::String m_itemPath;
Palette m_pal;
std::size_t m_selectedRow = 0;
studio::UndoStack m_undoStack;
PaletteEditorImGui() noexcept = default;
@@ -27,19 +26,14 @@ class PaletteEditorImGui: public studio::Editor {
/**
* Returns the name of item being edited.
*/
const ox::String &itemName() const override;
const ox::String &itemName() const noexcept final;
const ox::String &itemDisplayName() const noexcept override;
const ox::String &itemDisplayName() const noexcept final;
void draw(core::Context*) noexcept override;
void draw(core::Context*) noexcept final;
protected:
studio::UndoStack *undoStack() noexcept final;
ox::Error saveItem() noexcept override;
private:
ox::Error markUnsavedChanges(int) noexcept;
ox::Error saveItem() noexcept final;
};
@@ -23,7 +23,7 @@ enum class Tool {
Select,
};
class TileSheetEditorImGui: public studio::Editor {
class TileSheetEditorImGui: public studio::BaseEditor {
private:
class SubSheetEditor {