Refactor tab handling in Dungeon and Graphics editors for improved readability

This commit is contained in:
scawful
2024-11-13 09:42:54 -05:00
parent 12309f460e
commit e3ed705336
6 changed files with 64 additions and 57 deletions

View File

@@ -1,11 +1,6 @@
#ifndef YAZE_APP_CORE_CONSTANTS_H #ifndef YAZE_APP_CORE_CONSTANTS_H
#define YAZE_APP_CORE_CONSTANTS_H #define YAZE_APP_CORE_CONSTANTS_H
#define TAB_BAR(w) if (ImGui::BeginTabBar(w)) {
#define END_TAB_BAR() \
ImGui::EndTabBar(); \
}
#define TAB_ITEM(w) if (ImGui::BeginTabItem(w)) { #define TAB_ITEM(w) if (ImGui::BeginTabItem(w)) {
#define END_TAB_ITEM() \ #define END_TAB_ITEM() \
ImGui::EndTabItem(); \ ImGui::EndTabItem(); \

View File

@@ -49,21 +49,22 @@ absl::Status DungeonEditor::Update() {
refresh_graphics_ = false; refresh_graphics_ = false;
} }
TAB_BAR("##DungeonEditorTabBar") if (ImGui::BeginTabBar("##DungeonEditorTabBar")) {
TAB_ITEM("Room Editor") TAB_ITEM("Room Editor")
status_ = UpdateDungeonRoomView(); status_ = UpdateDungeonRoomView();
END_TAB_ITEM() END_TAB_ITEM()
TAB_ITEM("Usage Statistics") TAB_ITEM("Usage Statistics")
if (is_loaded_) { if (is_loaded_) {
static bool calc_stats = false; static bool calc_stats = false;
if (!calc_stats) { if (!calc_stats) {
CalculateUsageStats(); CalculateUsageStats();
calc_stats = true; calc_stats = true;
}
DrawUsageStats();
} }
DrawUsageStats(); END_TAB_ITEM()
ImGui::EndTabBar();
} }
END_TAB_ITEM()
END_TAB_BAR()
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -194,14 +195,15 @@ absl::Status DungeonEditor::UpdateDungeonRoomView() {
TableNextRow(); TableNextRow();
TableNextColumn(); TableNextColumn();
TAB_BAR("##DungeonRoomTabBar"); if (ImGui::BeginTabBar("##DungeonRoomTabBar")) {
TAB_ITEM("Rooms"); TAB_ITEM("Rooms");
DrawRoomSelector(); DrawRoomSelector();
END_TAB_ITEM(); END_TAB_ITEM();
TAB_ITEM("Entrances"); TAB_ITEM("Entrances");
DrawEntranceSelector(); DrawEntranceSelector();
END_TAB_ITEM(); END_TAB_ITEM();
END_TAB_BAR(); ImGui::EndTabBar();
}
TableNextColumn(); TableNextColumn();
DrawDungeonTabView(); DrawDungeonTabView();

View File

@@ -34,25 +34,11 @@ using ImGui::InputText;
using ImGui::SameLine; using ImGui::SameLine;
using ImGui::TableNextColumn; using ImGui::TableNextColumn;
static constexpr absl::string_view kGfxToolsetColumnNames[] = {
"#memoryEditor",
"##separator_gfx1",
};
constexpr ImGuiTableFlags kGfxEditTableFlags = constexpr ImGuiTableFlags kGfxEditTableFlags =
ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable |
ImGuiTableFlags_SizingFixedFit; ImGuiTableFlags_SizingFixedFit;
constexpr ImGuiTabBarFlags kGfxEditTabBarFlags =
ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
ImGuiTabBarFlags_FittingPolicyResizeDown |
ImGuiTabBarFlags_TabListPopupButton;
constexpr ImGuiTableFlags kGfxEditFlags = ImGuiTableFlags_Reorderable |
ImGuiTableFlags_Resizable |
ImGuiTableFlags_SizingStretchSame;
absl::Status GraphicsEditor::Update() { absl::Status GraphicsEditor::Update() {
if (ImGui::BeginTabBar("##TabBar")) { if (ImGui::BeginTabBar("##TabBar")) {
status_ = UpdateGfxEdit(); status_ = UpdateGfxEdit();
@@ -260,6 +246,10 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
absl::Status GraphicsEditor::UpdateGfxTabView() { absl::Status GraphicsEditor::UpdateGfxTabView() {
static int next_tab_id = 0; static int next_tab_id = 0;
constexpr ImGuiTabBarFlags kGfxEditTabBarFlags =
ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
ImGuiTabBarFlags_FittingPolicyResizeDown |
ImGuiTabBarFlags_TabListPopupButton;
if (ImGui::BeginTabBar("##GfxEditTabBar", kGfxEditTabBarFlags)) { if (ImGui::BeginTabBar("##GfxEditTabBar", kGfxEditTabBarFlags)) {
if (ImGui::TabItemButton(ICON_MD_ADD, ImGuiTabItemFlags_Trailing | if (ImGui::TabItemButton(ICON_MD_ADD, ImGuiTabItemFlags_Trailing |
@@ -439,6 +429,10 @@ absl::Status GraphicsEditor::UpdateScadView() {
ImGui::End(); ImGui::End();
} }
constexpr ImGuiTableFlags kGfxEditFlags = ImGuiTableFlags_Reorderable |
ImGuiTableFlags_Resizable |
ImGuiTableFlags_SizingStretchSame;
BEGIN_TABLE("#gfxEditTable", 4, kGfxEditFlags) BEGIN_TABLE("#gfxEditTable", 4, kGfxEditFlags)
SETUP_COLUMN("File Import (BIN, CGX, ROM)") SETUP_COLUMN("File Import (BIN, CGX, ROM)")
SETUP_COLUMN("Palette (COL)") SETUP_COLUMN("Palette (COL)")
@@ -490,6 +484,11 @@ absl::Status GraphicsEditor::UpdateScadView() {
} }
absl::Status GraphicsEditor::DrawToolset() { absl::Status GraphicsEditor::DrawToolset() {
static constexpr absl::string_view kGfxToolsetColumnNames[] = {
"#memoryEditor",
"##separator_gfx1",
};
if (ImGui::BeginTable("GraphicsToolset", 2, ImGuiTableFlags_SizingFixedFit, if (ImGui::BeginTable("GraphicsToolset", 2, ImGuiTableFlags_SizingFixedFit,
ImVec2(0, 0))) { ImVec2(0, 0))) {
for (const auto& name : kGfxToolsetColumnNames) for (const auto& name : kGfxToolsetColumnNames)

View File

@@ -26,17 +26,19 @@ using core::Renderer;
constexpr uint32_t kRedPen = 0xFF0000FF; constexpr uint32_t kRedPen = 0xFF0000FF;
absl::Status ScreenEditor::Update() { absl::Status ScreenEditor::Update() {
TAB_BAR("##TabBar") if (ImGui::BeginTabBar("##ScreenEditorTabBar")) {
TAB_ITEM("Dungeon Maps") if (ImGui::BeginTabItem("Dungeon Maps")) {
if (rom()->is_loaded()) { if (rom()->is_loaded()) {
DrawDungeonMapsEditor(); DrawDungeonMapsEditor();
}
ImGui::EndTabItem();
}
DrawInventoryMenuEditor();
DrawOverworldMapEditor();
DrawTitleScreenEditor();
DrawNamingScreenEditor();
ImGui::EndTabBar();
} }
END_TAB_ITEM()
DrawInventoryMenuEditor();
DrawOverworldMapEditor();
DrawTitleScreenEditor();
DrawNamingScreenEditor();
END_TAB_BAR()
return status_; return status_;
} }
@@ -483,6 +485,7 @@ void ScreenEditor::DrawDungeonMapsEditor() {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
tilemap_canvas_.DrawBackground(ImVec2(128 * 2 + 2, (192 * 2) + 4)); tilemap_canvas_.DrawBackground(ImVec2(128 * 2 + 2, (192 * 2) + 4));
tilemap_canvas_.DrawContextMenu(); tilemap_canvas_.DrawContextMenu();
tilemap_canvas_.DrawTileSelector(8.f);
tilemap_canvas_.DrawBitmapTable(sheets_); tilemap_canvas_.DrawBitmapTable(sheets_);
tilemap_canvas_.DrawGrid(); tilemap_canvas_.DrawGrid();
tilemap_canvas_.DrawOverlay(); tilemap_canvas_.DrawOverlay();
@@ -524,16 +527,21 @@ void ScreenEditor::LoadBinaryGfx() {
} }
void ScreenEditor::DrawTitleScreenEditor() { void ScreenEditor::DrawTitleScreenEditor() {
TAB_ITEM("Title Screen") if (ImGui::BeginTabItem("Title Screen")) {
END_TAB_ITEM() ImGui::EndTabItem();
}
} }
void ScreenEditor::DrawNamingScreenEditor() { void ScreenEditor::DrawNamingScreenEditor() {
TAB_ITEM("Naming Screen") if (ImGui::BeginTabItem("Naming Screen")) {
END_TAB_ITEM() ImGui::EndTabItem();
}
} }
void ScreenEditor::DrawOverworldMapEditor() { void ScreenEditor::DrawOverworldMapEditor() {
TAB_ITEM("Overworld Map") if (ImGui::BeginTabItem("Overworld Map")) {
END_TAB_ITEM() ImGui::EndTabItem();
}
} }
void ScreenEditor::DrawToolset() { void ScreenEditor::DrawToolset() {

View File

@@ -52,6 +52,7 @@ struct FlagsMenu : public core::ExperimentFlags {
&mutable_flags()->kLogInstructions); &mutable_flags()->kLogInstructions);
Checkbox("Save All Palettes", &mutable_flags()->kSaveAllPalettes); Checkbox("Save All Palettes", &mutable_flags()->kSaveAllPalettes);
Checkbox("Save Gfx Groups", &mutable_flags()->kSaveGfxGroups); Checkbox("Save Gfx Groups", &mutable_flags()->kSaveGfxGroups);
Checkbox("Save Graphics Sheets", &mutable_flags()->kSaveGraphicsSheet);
Checkbox("Use New ImGui Input", &mutable_flags()->kUseNewImGuiInput); Checkbox("Use New ImGui Input", &mutable_flags()->kUseNewImGuiInput);
} }
}; };

View File

@@ -150,7 +150,9 @@ absl::Status Rom::SaveAllGraphicsData() {
auto sheet_data = graphics_sheets_[i].vector(); auto sheet_data = graphics_sheets_[i].vector();
final_data = gfx::ConvertBpp(sheet_data, from_bpp, to_bpp); final_data = gfx::ConvertBpp(sheet_data, from_bpp, to_bpp);
if (compressed) { if (compressed) {
final_data = gfx::lc_lz2::CompressV2(final_data); ASSIGN_OR_RETURN(
final_data,
gfx::lc_lz2::CompressV2(final_data.data(), 0, final_data.size()));
} }
auto offset = auto offset =
GetGraphicsAddress(data(), i, version_constants().kOverworldGfxPtr1, GetGraphicsAddress(data(), i, version_constants().kOverworldGfxPtr1,