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