move sprite_editor to editors/sprite
This commit is contained in:
200
src/app/editor/sprite/sprite_editor.cc
Normal file
200
src/app/editor/sprite/sprite_editor.cc
Normal file
@@ -0,0 +1,200 @@
|
||||
#include "sprite_editor.h"
|
||||
|
||||
#include <gui/icons.h>
|
||||
#include <gui/input.h>
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace editor {
|
||||
|
||||
using ImGui::Button;
|
||||
using ImGui::Separator;
|
||||
using ImGui::TableHeadersRow;
|
||||
using ImGui::TableNextColumn;
|
||||
using ImGui::TableNextRow;
|
||||
using ImGui::TableSetupColumn;
|
||||
using ImGui::Text;
|
||||
|
||||
absl::Status SpriteEditor::Update() {
|
||||
if (rom()->is_loaded() && !sheets_loaded_) {
|
||||
// Load the values for current_sheets_ array
|
||||
sheets_loaded_ = true;
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable,
|
||||
ImVec2(0, 0))) {
|
||||
TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256);
|
||||
TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
|
||||
ImGui::GetContentRegionAvail().x);
|
||||
TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
|
||||
TableHeadersRow();
|
||||
TableNextRow();
|
||||
|
||||
TableNextColumn();
|
||||
DrawSpritesList();
|
||||
|
||||
TableNextColumn();
|
||||
{
|
||||
static int next_tab_id = 0;
|
||||
|
||||
if (ImGui::BeginTabBar("SpriteTabBar", kSpriteTabBarFlags)) {
|
||||
if (ImGui::TabItemButton(ICON_MD_ADD, kSpriteTabBarFlags)) {
|
||||
if (std::find(active_sprites_.begin(), active_sprites_.end(),
|
||||
current_sprite_id_) != active_sprites_.end()) {
|
||||
// Room is already open
|
||||
next_tab_id++;
|
||||
}
|
||||
active_sprites_.push_back(next_tab_id++); // Add new tab
|
||||
}
|
||||
|
||||
// Submit our regular tabs
|
||||
for (int n = 0; n < active_sprites_.Size;) {
|
||||
bool open = true;
|
||||
|
||||
if (active_sprites_[n] > sizeof(core::kSpriteDefaultNames) / 4) {
|
||||
active_sprites_.erase(active_sprites_.Data + n);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem(
|
||||
core::kSpriteDefaultNames[active_sprites_[n]].data(), &open,
|
||||
ImGuiTabItemFlags_None)) {
|
||||
DrawSpriteCanvas();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (!open)
|
||||
active_sprites_.erase(active_sprites_.Data + n);
|
||||
else
|
||||
n++;
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
}
|
||||
|
||||
TableNextColumn();
|
||||
if (sheets_loaded_) {
|
||||
DrawCurrentSheets();
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void SpriteEditor::DrawSpriteCanvas() {
|
||||
static bool flip_x = false;
|
||||
static bool flip_y = false;
|
||||
if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
|
||||
ImGui::GetContentRegionAvail(), true)) {
|
||||
sprite_canvas_.DrawBackground();
|
||||
sprite_canvas_.DrawContextMenu();
|
||||
// sprite_canvas_.DrawBitmap(oam_bitmap_, 2, 2);
|
||||
sprite_canvas_.DrawGrid();
|
||||
sprite_canvas_.DrawOverlay();
|
||||
|
||||
// Draw a table with OAM configuration
|
||||
// X, Y, Tile, Palette, Priority, Flip X, Flip Y
|
||||
if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_None,
|
||||
ImVec2(0, 0))) {
|
||||
TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Tile", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Palette", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Priority", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Flip X", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Flip Y", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableHeadersRow();
|
||||
TableNextRow();
|
||||
|
||||
TableNextColumn();
|
||||
gui::InputHexWord("", &oam_config_.x);
|
||||
|
||||
TableNextColumn();
|
||||
gui::InputHexWord("", &oam_config_.y);
|
||||
|
||||
TableNextColumn();
|
||||
gui::InputHexByte("", &oam_config_.tile);
|
||||
|
||||
TableNextColumn();
|
||||
gui::InputHexByte("", &oam_config_.palette);
|
||||
|
||||
TableNextColumn();
|
||||
gui::InputHexByte("", &oam_config_.priority);
|
||||
|
||||
TableNextColumn();
|
||||
if (ImGui::Checkbox("##XFlip", &flip_x)) {
|
||||
oam_config_.flip_x = flip_x;
|
||||
}
|
||||
|
||||
TableNextColumn();
|
||||
if (ImGui::Checkbox("##YFlip", &flip_y)) {
|
||||
oam_config_.flip_y = flip_y;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
DrawAnimationFrames();
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteEditor::DrawCurrentSheets() {
|
||||
if (ImGui::BeginChild(gui::GetID("sheet_label"),
|
||||
ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
|
||||
ImGuiWindowFlags_NoDecoration)) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
std::string sheet_label = absl::StrFormat("Sheet %d", i);
|
||||
gui::InputHexByte(sheet_label.c_str(), ¤t_sheets_[i]);
|
||||
if (i % 2 == 0) ImGui::SameLine();
|
||||
}
|
||||
|
||||
graphics_sheet_canvas_.DrawBackground();
|
||||
graphics_sheet_canvas_.DrawContextMenu();
|
||||
graphics_sheet_canvas_.DrawTileSelector(32);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
graphics_sheet_canvas_.DrawBitmap(
|
||||
rom()->bitmap_manager()[current_sheets_[i]], 1, (i * 0x40) + 1, 2);
|
||||
}
|
||||
graphics_sheet_canvas_.DrawGrid();
|
||||
graphics_sheet_canvas_.DrawOverlay();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteEditor::DrawSpritesList() {
|
||||
if (ImGui::BeginChild(gui::GetID("##SpritesList"),
|
||||
ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
|
||||
ImGuiWindowFlags_NoDecoration)) {
|
||||
int i = 0;
|
||||
for (const auto each_sprite_name : core::kSpriteDefaultNames) {
|
||||
rom()->resource_label()->SelectableLabelWithNameEdit(
|
||||
current_sprite_id_ == i, "Sprite Names", core::UppercaseHexByte(i),
|
||||
core::kSpriteDefaultNames[i].data());
|
||||
if (ImGui::IsItemClicked()) {
|
||||
current_sprite_id_ = i;
|
||||
if (!active_sprites_.contains(i)) {
|
||||
active_sprites_.push_back(i);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteEditor::DrawAnimationFrames() {
|
||||
if (ImGui::Button("Add Frame")) {
|
||||
// Add a new frame
|
||||
}
|
||||
if (ImGui::Button("Remove Frame")) {
|
||||
// Remove the current frame
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace editor
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
104
src/app/editor/sprite/sprite_editor.h
Normal file
104
src/app/editor/sprite/sprite_editor.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef YAZE_APP_EDITOR_SPRITE_EDITOR_H
|
||||
#define YAZE_APP_EDITOR_SPRITE_EDITOR_H
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "app/editor/utils/editor.h"
|
||||
#include "app/gui/canvas.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace editor {
|
||||
|
||||
constexpr ImGuiTabItemFlags kSpriteTabFlags =
|
||||
ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip;
|
||||
|
||||
constexpr ImGuiTabBarFlags kSpriteTabBarFlags =
|
||||
ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
|
||||
ImGuiTabBarFlags_FittingPolicyResizeDown |
|
||||
ImGuiTabBarFlags_TabListPopupButton;
|
||||
|
||||
constexpr ImGuiTableFlags kSpriteTableFlags =
|
||||
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
|
||||
ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
|
||||
ImGuiTableFlags_BordersV;
|
||||
|
||||
/**
|
||||
* @class SpriteEditor
|
||||
* @brief Allows the user to edit sprites.
|
||||
*
|
||||
* This class provides functionality for updating the sprite editor, drawing the
|
||||
* editor table, drawing the sprite canvas, and drawing the current sheets.
|
||||
*/
|
||||
class SpriteEditor : public SharedRom, public Editor {
|
||||
public:
|
||||
SpriteEditor() { type_ = EditorType::kSprite; }
|
||||
|
||||
/**
|
||||
* @brief Updates the sprite editor.
|
||||
*
|
||||
* @return An absl::Status indicating the success or failure of the update.
|
||||
*/
|
||||
absl::Status Update() override;
|
||||
|
||||
absl::Status Cut() override { return absl::OkStatus(); }
|
||||
absl::Status Copy() override { return absl::OkStatus(); }
|
||||
absl::Status Paste() override { return absl::OkStatus(); }
|
||||
absl::Status Undo() override { return absl::OkStatus(); }
|
||||
absl::Status Redo() override { return absl::OkStatus(); }
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Draws the sprites list.
|
||||
*/
|
||||
void DrawSpritesList();
|
||||
|
||||
/**
|
||||
* @brief Draws the sprite canvas.
|
||||
*/
|
||||
void DrawSpriteCanvas();
|
||||
|
||||
/**
|
||||
* @brief Draws the current sheets.
|
||||
*/
|
||||
void DrawCurrentSheets();
|
||||
|
||||
/**
|
||||
* @brief Draws the animation frames manager.
|
||||
*/
|
||||
void DrawAnimationFrames();
|
||||
|
||||
ImVector<int> active_sprites_; /**< Active sprites. */
|
||||
|
||||
int current_sprite_id_; /**< Current sprite ID. */
|
||||
uint8_t current_sheets_[8]; /**< Array to store the current sheets. */
|
||||
bool sheets_loaded_ =
|
||||
false; /**< Flag indicating whether the sheets are loaded or not. */
|
||||
|
||||
// OAM Configuration
|
||||
struct OAMConfig {
|
||||
uint16_t x; /**< X offset. */
|
||||
uint16_t y; /**< Y offset. */
|
||||
uint8_t tile; /**< Tile number. */
|
||||
uint8_t palette; /**< Palette number. */
|
||||
uint8_t priority; /**< Priority. */
|
||||
bool flip_x; /**< Flip X. */
|
||||
bool flip_y; /**< Flip Y. */
|
||||
};
|
||||
|
||||
OAMConfig oam_config_; /**< OAM configuration. */
|
||||
gui::Bitmap oam_bitmap_; /**< OAM bitmap. */
|
||||
|
||||
gui::Canvas sprite_canvas_{
|
||||
ImVec2(0x200, 0x200), gui::CanvasGridSize::k32x32}; /**< Sprite canvas. */
|
||||
|
||||
gui::Canvas graphics_sheet_canvas_{
|
||||
ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
|
||||
gui::CanvasGridSize::k16x16}; /**< Graphics sheet canvas. */
|
||||
};
|
||||
|
||||
} // namespace editor
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_EDITOR_SPRITE_EDITOR_H
|
||||
Reference in New Issue
Block a user