add zsprite to sprite editor
This commit is contained in:
@@ -63,6 +63,7 @@ class MasterEditor : public SharedRom,
|
||||
active_editors_.push_back(&dungeon_editor_);
|
||||
active_editors_.push_back(&graphics_editor_);
|
||||
active_editors_.push_back(&palette_editor_);
|
||||
active_editors_.push_back(&sprite_editor_);
|
||||
}
|
||||
|
||||
void SetupScreen(std::shared_ptr<SDL_Renderer> renderer,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "sprite_editor.h"
|
||||
|
||||
#include <core/platform/file_dialog.h>
|
||||
#include <editor/sprite/zsprite.h>
|
||||
#include <gui/icons.h>
|
||||
#include <gui/input.h>
|
||||
|
||||
@@ -34,43 +36,41 @@ absl::Status SpriteEditor::Update() {
|
||||
DrawSpritesList();
|
||||
|
||||
TableNextColumn();
|
||||
{
|
||||
static int next_tab_id = 0;
|
||||
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
|
||||
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++;
|
||||
}
|
||||
|
||||
// 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();
|
||||
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();
|
||||
@@ -80,7 +80,7 @@ absl::Status SpriteEditor::Update() {
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
return status_.ok() ? absl::OkStatus() : status_;
|
||||
}
|
||||
|
||||
void SpriteEditor::DrawSpriteCanvas() {
|
||||
@@ -96,7 +96,7 @@ void SpriteEditor::DrawSpriteCanvas() {
|
||||
|
||||
// Draw a table with OAM configuration
|
||||
// X, Y, Tile, Palette, Priority, Flip X, Flip Y
|
||||
if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_None,
|
||||
if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_Resizable,
|
||||
ImVec2(0, 0))) {
|
||||
TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
|
||||
TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
|
||||
@@ -169,6 +169,21 @@ 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(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define YAZE_APP_EDITOR_SPRITE_EDITOR_H
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "app/editor/sprite/zsprite.h"
|
||||
#include "app/editor/utils/editor.h"
|
||||
#include "app/gui/canvas.h"
|
||||
#include "app/rom.h"
|
||||
@@ -70,8 +71,8 @@ class SpriteEditor : public SharedRom, public Editor {
|
||||
|
||||
ImVector<int> active_sprites_; /**< Active sprites. */
|
||||
|
||||
int current_sprite_id_; /**< Current sprite ID. */
|
||||
uint8_t current_sheets_[8]; /**< Array to store the current sheets. */
|
||||
int current_sprite_id_; /**< Current sprite ID. */
|
||||
uint8_t current_sheets_[8] = {0x00, 0x0A, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00};
|
||||
bool sheets_loaded_ =
|
||||
false; /**< Flag indicating whether the sheets are loaded or not. */
|
||||
|
||||
@@ -95,6 +96,10 @@ class SpriteEditor : public SharedRom, public Editor {
|
||||
gui::Canvas graphics_sheet_canvas_{
|
||||
ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
|
||||
gui::CanvasGridSize::k16x16}; /**< Graphics sheet canvas. */
|
||||
|
||||
std::vector<zsprite::ZSprite> custom_sprites_; /**< Sprites. */
|
||||
|
||||
absl::Status status_; /**< Status. */
|
||||
};
|
||||
|
||||
} // namespace editor
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
#ifndef YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
|
||||
#define YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
|
||||
|
||||
#include <gfx/snes_tile.h>
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "app/gfx/snes_tile.h"
|
||||
#include "absl/status/status.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace editor {
|
||||
/**
|
||||
* @brief Namespace for the ZSprite format from Zarby's ZSpriteMaker.
|
||||
*/
|
||||
namespace zsprite {
|
||||
|
||||
struct OamTile {
|
||||
@@ -38,6 +44,7 @@ struct OamTile {
|
||||
};
|
||||
|
||||
struct AnimationGroup {
|
||||
AnimationGroup() = default;
|
||||
AnimationGroup(uint8_t fs, uint8_t fe, uint8_t fsp, std::string fn)
|
||||
: frame_start(fs), frame_end(fe), frame_speed(fsp), frame_name(fn) {}
|
||||
|
||||
@@ -66,10 +73,13 @@ struct SpriteProperty {
|
||||
std::string Text;
|
||||
};
|
||||
|
||||
class ZSprite {
|
||||
struct ZSprite {
|
||||
public:
|
||||
void LoadZSpriteFormat(const std::string& filename) {
|
||||
absl::Status Load(const std::string& filename) {
|
||||
std::ifstream fs(filename, std::ios::binary);
|
||||
if (!fs.is_open()) {
|
||||
return absl::NotFoundError("File not found");
|
||||
}
|
||||
|
||||
std::vector<char> buffer(std::istreambuf_iterator<char>(fs), {});
|
||||
|
||||
@@ -213,9 +223,11 @@ class ZSprite {
|
||||
// UpdateUserRoutines();
|
||||
// userroutinesListbox.SelectedIndex = 0;
|
||||
// RefreshScreen();
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void SaveZSpriteFormat(const std::string& filename) {
|
||||
absl::Status Save(const std::string& filename) {
|
||||
std::ofstream fs(filename, std::ios::binary);
|
||||
if (fs.is_open()) {
|
||||
// Write data to the file
|
||||
@@ -335,9 +347,10 @@ class ZSprite {
|
||||
|
||||
fs.close();
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string sprName;
|
||||
std::vector<AnimationGroup> animations;
|
||||
std::vector<UserRoutine> userRoutines;
|
||||
@@ -377,6 +390,7 @@ class ZSprite {
|
||||
|
||||
} // namespace zsprite
|
||||
} // namespace editor
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
|
||||
Reference in New Issue
Block a user