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