From 3701e740a003cbb20dc7331490aaab6b9edc63aa Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 21 Jul 2024 18:52:41 -0400 Subject: [PATCH] add vanilla and custom sprite editor tabs --- src/app/editor/sprite/sprite_editor.cc | 98 +++++++++++++++++++++----- src/app/editor/sprite/sprite_editor.h | 6 ++ 2 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/app/editor/sprite/sprite_editor.cc b/src/app/editor/sprite/sprite_editor.cc index 13254024..03d02e5b 100644 --- a/src/app/editor/sprite/sprite_editor.cc +++ b/src/app/editor/sprite/sprite_editor.cc @@ -9,7 +9,10 @@ namespace yaze { namespace app { namespace editor { +using ImGui::BeginTable; using ImGui::Button; +using ImGui::EndTable; +using ImGui::Selectable; using ImGui::Separator; using ImGui::TableHeadersRow; using ImGui::TableNextColumn; @@ -23,6 +26,22 @@ absl::Status SpriteEditor::Update() { sheets_loaded_ = true; } + if (ImGui::BeginTabBar("##SpriteEditorTabs")) { + if (ImGui::BeginTabItem("Vanilla")) { + DrawVanillaSpriteEditor(); + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Custom")) { + DrawCustomSprites(); + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); + } + + return status_.ok() ? absl::OkStatus() : status_; +} + +void SpriteEditor::DrawVanillaSpriteEditor() { if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable, ImVec2(0, 0))) { TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256); @@ -79,8 +98,6 @@ absl::Status SpriteEditor::Update() { } ImGui::EndTable(); } - - return status_.ok() ? absl::OkStatus() : status_; } void SpriteEditor::DrawSpriteCanvas() { @@ -137,6 +154,8 @@ void SpriteEditor::DrawSpriteCanvas() { DrawAnimationFrames(); + DrawCustomSpritesMetadata(); + ImGui::EndChild(); } } @@ -168,21 +187,6 @@ void SpriteEditor::DrawSpritesList() { if (ImGui::BeginChild(gui::GetID("##SpritesList"), ImVec2(ImGui::GetContentRegionAvail().x, 0), true, ImGuiWindowFlags_NoDecoration)) { - // ZSprite Maker format open file dialog - if (ImGui::Button("Open ZSprite")) { - // Open ZSprite file - std::string file_path = FileDialogWrapper::ShowOpenFileDialog(); - if (!file_path.empty()) { - zsprite::ZSprite zsprite; - status_ = zsprite.Load(file_path); - } - } - - for (const auto custom_sprite : custom_sprites_) { - Text("%s", custom_sprite.sprName.c_str()); - Separator(); - } - int i = 0; for (const auto each_sprite_name : core::kSpriteDefaultNames) { rom()->resource_label()->SelectableLabelWithNameEdit( @@ -209,6 +213,66 @@ void SpriteEditor::DrawAnimationFrames() { } } +void SpriteEditor::DrawCustomSprites() { + if (BeginTable("##CustomSpritesTable", 3, + ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders | + ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable, + ImVec2(0, 0))) { + TableSetupColumn("Metadata", ImGuiTableColumnFlags_WidthFixed, 256); + TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthFixed, 256); + TableSetupColumn("TIlesheets", ImGuiTableColumnFlags_WidthFixed, 256); + + TableHeadersRow(); + TableNextRow(); + TableNextColumn(); + + Separator(); + DrawCustomSpritesMetadata(); + + TableNextColumn(); + DrawSpriteCanvas(); + + TableNextColumn(); + DrawCurrentSheets(); + + EndTable(); + } +} + +void SpriteEditor::DrawCustomSpritesMetadata() { + // ZSprite Maker format open file dialog + if (ImGui::Button("Open ZSprite")) { + // Open ZSprite file + std::string file_path = FileDialogWrapper::ShowOpenFileDialog(); + if (!file_path.empty()) { + zsprite::ZSprite zsprite; + status_ = zsprite.Load(file_path); + if (status_.ok()) { + custom_sprites_.push_back(zsprite); + } + } + } + + for (const auto custom_sprite : custom_sprites_) { + Selectable("%s", custom_sprite.sprName.c_str()); + if (ImGui::IsItemClicked()) { + current_sprite_id_ = 256 + stoi(custom_sprite.property_sprid.Text); + if (!active_sprites_.contains(current_sprite_id_)) { + active_sprites_.push_back(current_sprite_id_); + } + } + Separator(); + } + + for (const auto custom_sprite : custom_sprites_) { + // Draw the custom sprite metadata + Text("Sprite ID: %s", custom_sprite.property_sprid.Text.c_str()); + Text("Sprite Name: %s", custom_sprite.property_sprname.Text.c_str()); + Text("Sprite Palette: %s", custom_sprite.property_palette.Text.c_str()); + Separator(); + } +} + } // namespace editor } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/editor/sprite/sprite_editor.h b/src/app/editor/sprite/sprite_editor.h index 5fd656c8..0cc6e019 100644 --- a/src/app/editor/sprite/sprite_editor.h +++ b/src/app/editor/sprite/sprite_editor.h @@ -50,6 +50,8 @@ class SpriteEditor : public SharedRom, public Editor { absl::Status Find() override { return absl::UnimplementedError("Find"); } private: + void DrawVanillaSpriteEditor(); + /** * @brief Draws the sprites list. */ @@ -65,6 +67,10 @@ class SpriteEditor : public SharedRom, public Editor { */ void DrawCurrentSheets(); + void DrawCustomSprites(); + + void DrawCustomSpritesMetadata(); + /** * @brief Draws the animation frames manager. */