add sprites list and tab bar to sprite editor
This commit is contained in:
@@ -20,15 +20,57 @@ absl::Status SpriteEditor::Update() {
|
|||||||
sheets_loaded_ = true;
|
sheets_loaded_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::BeginTable("##SpriteCanvasTable", 2, ImGuiTableFlags_Resizable,
|
if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable,
|
||||||
ImVec2(0, 0))) {
|
ImVec2(0, 0))) {
|
||||||
|
TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256);
|
||||||
TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
|
TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
|
||||||
ImGui::GetContentRegionAvail().x);
|
ImGui::GetContentRegionAvail().x);
|
||||||
TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
|
TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
|
||||||
TableHeadersRow();
|
TableHeadersRow();
|
||||||
TableNextRow();
|
TableNextRow();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
DrawSpriteCanvas();
|
DrawSpritesList();
|
||||||
|
|
||||||
|
TableNextColumn();
|
||||||
|
{
|
||||||
|
static int next_tab_id = 0;
|
||||||
|
|
||||||
|
if (ImGui::BeginTabBar("SpriteTabBar", kSpriteTabBarFlags)) {
|
||||||
|
if (ImGui::TabItemButton("+", 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();
|
TableNextColumn();
|
||||||
if (sheets_loaded_) {
|
if (sheets_loaded_) {
|
||||||
@@ -41,14 +83,16 @@ absl::Status SpriteEditor::Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpriteEditor::DrawSpriteCanvas() {
|
void SpriteEditor::DrawSpriteCanvas() {
|
||||||
|
static bool flip_x = false;
|
||||||
|
static bool flip_y = false;
|
||||||
if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
|
if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
|
||||||
ImGui::GetContentRegionAvail(), true,
|
ImGui::GetContentRegionAvail(), true,
|
||||||
ImGuiWindowFlags_AlwaysVerticalScrollbar |
|
ImGuiWindowFlags_AlwaysVerticalScrollbar |
|
||||||
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) {
|
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) {
|
||||||
sprite_canvas_.DrawBackground(ImVec2(0x200, 0x200));
|
sprite_canvas_.DrawBackground();
|
||||||
sprite_canvas_.DrawContextMenu();
|
sprite_canvas_.DrawContextMenu();
|
||||||
// sprite_canvas_.DrawBitmap(oam_bitmap_, 2, 2);
|
// sprite_canvas_.DrawBitmap(oam_bitmap_, 2, 2);
|
||||||
sprite_canvas_.DrawGrid(8.0f);
|
sprite_canvas_.DrawGrid();
|
||||||
sprite_canvas_.DrawOverlay();
|
sprite_canvas_.DrawOverlay();
|
||||||
|
|
||||||
// Draw a table with OAM configuration
|
// Draw a table with OAM configuration
|
||||||
@@ -81,10 +125,14 @@ void SpriteEditor::DrawSpriteCanvas() {
|
|||||||
gui::InputHexByte("", &oam_config_.priority);
|
gui::InputHexByte("", &oam_config_.priority);
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
ImGui::Checkbox("", &oam_config_.flip_x);
|
if (ImGui::Checkbox("##XFlip", &flip_x)) {
|
||||||
|
oam_config_.flip_x = flip_x;
|
||||||
|
}
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
ImGui::Checkbox("", &oam_config_.flip_y);
|
if (ImGui::Checkbox("##YFlip", &flip_y)) {
|
||||||
|
oam_config_.flip_y = flip_y;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
@@ -94,24 +142,46 @@ void SpriteEditor::DrawSpriteCanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpriteEditor::DrawCurrentSheets() {
|
void SpriteEditor::DrawCurrentSheets() {
|
||||||
for (int i = 0; i < 8; i++) {
|
if (ImGui::BeginChild(gui::GetID("sheet_label"),
|
||||||
// ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
|
||||||
// ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
ImGuiWindowFlags_NoDecoration)) {
|
||||||
// std::string sheet_label = absl::StrFormat("Sheet %d", i);
|
for (int i = 0; i < 8; i++) {
|
||||||
// gui::InputHexByte(sheet_label.c_str(), ¤t_sheets_[i]);
|
std::string sheet_label = absl::StrFormat("Sheet %d", i);
|
||||||
if (ImGui::BeginChild(gui::GetID("sheet_label"),
|
gui::InputHexByte(sheet_label.c_str(), ¤t_sheets_[i]);
|
||||||
ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
|
if (i % 2 == 0) ImGui::SameLine();
|
||||||
ImGuiWindowFlags_NoDecoration)) {
|
|
||||||
static gui::Canvas graphics_sheet_canvas;
|
|
||||||
graphics_sheet_canvas.DrawBackground(ImVec2(0x80 * 2, 0x20 * 2));
|
|
||||||
// ImGui::PopStyleVar(2);
|
|
||||||
graphics_sheet_canvas.DrawContextMenu();
|
|
||||||
graphics_sheet_canvas.DrawBitmap(
|
|
||||||
*rom()->bitmap_manager()[current_sheets_[i]], 2, 2, 2);
|
|
||||||
graphics_sheet_canvas.DrawGrid(64.0f);
|
|
||||||
graphics_sheet_canvas.DrawOverlay();
|
|
||||||
ImGui::EndChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,21 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace editor {
|
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
|
* @class SpriteEditor
|
||||||
* @brief Allows the user to edit sprites.
|
* @brief Allows the user to edit sprites.
|
||||||
@@ -26,6 +41,11 @@ class SpriteEditor : public SharedRom {
|
|||||||
absl::Status Update();
|
absl::Status Update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Draws the sprites list.
|
||||||
|
*/
|
||||||
|
void DrawSpritesList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Draws the sprite canvas.
|
* @brief Draws the sprite canvas.
|
||||||
*/
|
*/
|
||||||
@@ -36,6 +56,9 @@ class SpriteEditor : public SharedRom {
|
|||||||
*/
|
*/
|
||||||
void DrawCurrentSheets();
|
void DrawCurrentSheets();
|
||||||
|
|
||||||
|
ImVector<int> active_sprites_; /**< Active sprites. */
|
||||||
|
|
||||||
|
int current_sprite_id_; /**< Current sprite ID. */
|
||||||
uint8_t current_sheets_[8]; /**< Array to store the current sheets. */
|
uint8_t current_sheets_[8]; /**< Array to store the current sheets. */
|
||||||
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. */
|
||||||
@@ -51,11 +74,15 @@ class SpriteEditor : public SharedRom {
|
|||||||
bool flip_y; /**< Flip Y. */
|
bool flip_y; /**< Flip Y. */
|
||||||
};
|
};
|
||||||
|
|
||||||
OAMConfig oam_config_; /**< OAM configuration. */
|
OAMConfig oam_config_; /**< OAM configuration. */
|
||||||
gui::Bitmap oam_bitmap_; /**< OAM bitmap. */
|
gui::Bitmap oam_bitmap_; /**< OAM bitmap. */
|
||||||
|
|
||||||
gui::Canvas sprite_canvas_{
|
gui::Canvas sprite_canvas_{
|
||||||
ImVec2(0x200, 0x200), gui::CanvasGridSize::k32x32}; /**< 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 editor
|
||||||
|
|||||||
Reference in New Issue
Block a user