Refactor EditorManager and integrate PopupManager for improved popup handling
This commit is contained in:
@@ -279,169 +279,6 @@ absl::Status EditorManager::Update() {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void EditorManager::ManageActiveEditors() {
|
||||
// Show popup pane to select an editor to add
|
||||
static bool show_add_editor = false;
|
||||
if (show_add_editor) OpenPopup("AddEditor");
|
||||
|
||||
if (BeginPopup("AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
if (MenuItem("Overworld", nullptr, false,
|
||||
!IsEditorActive(&overworld_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&overworld_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Dungeon", nullptr, false,
|
||||
!IsEditorActive(&dungeon_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&dungeon_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Graphics", nullptr, false,
|
||||
!IsEditorActive(&graphics_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&graphics_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Music", nullptr, false,
|
||||
!IsEditorActive(&music_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&music_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Palette", nullptr, false,
|
||||
!IsEditorActive(&palette_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&palette_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Screen", nullptr, false,
|
||||
!IsEditorActive(&screen_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&screen_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Sprite", nullptr, false,
|
||||
!IsEditorActive(&sprite_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&sprite_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Code", nullptr, false,
|
||||
!IsEditorActive(&assembly_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&assembly_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Message", nullptr, false,
|
||||
!IsEditorActive(&message_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&message_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
if (MenuItem("Settings", nullptr, false,
|
||||
!IsEditorActive(&settings_editor_, active_editors_))) {
|
||||
active_editors_.push_back(&settings_editor_);
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
EndPopup();
|
||||
}
|
||||
|
||||
if (!IsPopupOpen("AddEditor")) {
|
||||
show_add_editor = false;
|
||||
}
|
||||
|
||||
if (BeginTabBar("##TabBar", ImGuiTabBarFlags_Reorderable |
|
||||
ImGuiTabBarFlags_AutoSelectNewTabs)) {
|
||||
for (auto editor : active_editors_) {
|
||||
bool open = true;
|
||||
switch (editor->type()) {
|
||||
case EditorType::kOverworld:
|
||||
if (overworld_editor_.jump_to_tab() == -1) {
|
||||
if (BeginTabItem("Overworld", &open)) {
|
||||
current_editor_ = &overworld_editor_;
|
||||
status_ = overworld_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EditorType::kDungeon:
|
||||
if (BeginTabItem("Dungeon", &open)) {
|
||||
current_editor_ = &dungeon_editor_;
|
||||
status_ = dungeon_editor_.Update();
|
||||
if (overworld_editor_.jump_to_tab() != -1) {
|
||||
dungeon_editor_.add_room(overworld_editor_.jump_to_tab());
|
||||
overworld_editor_.jump_to_tab_ = -1;
|
||||
}
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kGraphics:
|
||||
if (BeginTabItem("Graphics", &open)) {
|
||||
current_editor_ = &graphics_editor_;
|
||||
status_ = graphics_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kMusic:
|
||||
if (BeginTabItem("Music", &open)) {
|
||||
current_editor_ = &music_editor_;
|
||||
|
||||
status_ = music_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kPalette:
|
||||
if (BeginTabItem("Palette", &open)) {
|
||||
current_editor_ = &palette_editor_;
|
||||
status_ = palette_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kScreen:
|
||||
if (BeginTabItem("Screen", &open)) {
|
||||
current_editor_ = &screen_editor_;
|
||||
status_ = screen_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kSprite:
|
||||
if (BeginTabItem("Sprite", &open)) {
|
||||
current_editor_ = &sprite_editor_;
|
||||
status_ = sprite_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kAssembly:
|
||||
if (BeginTabItem("Code", &open)) {
|
||||
current_editor_ = &assembly_editor_;
|
||||
assembly_editor_.UpdateCodeView();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kSettings:
|
||||
if (BeginTabItem("Settings", &open)) {
|
||||
current_editor_ = &settings_editor_;
|
||||
status_ = settings_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
case EditorType::kMessage:
|
||||
if (BeginTabItem("Message", &open)) {
|
||||
current_editor_ = &message_editor_;
|
||||
status_ = message_editor_.Update();
|
||||
EndTabItem();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!open) {
|
||||
active_editors_.erase(
|
||||
std::remove(active_editors_.begin(), active_editors_.end(), editor),
|
||||
active_editors_.end());
|
||||
}
|
||||
}
|
||||
|
||||
if (TabItemButton(ICON_MD_ADD, ImGuiTabItemFlags_Trailing)) {
|
||||
show_add_editor = true;
|
||||
}
|
||||
|
||||
EndTabBar();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorManager::DrawHomepage() {
|
||||
TextWrapped("Welcome to the Yet Another Zelda3 Editor (yaze)!");
|
||||
TextWrapped(
|
||||
@@ -457,61 +294,9 @@ void EditorManager::DrawHomepage() {
|
||||
}
|
||||
|
||||
void EditorManager::DrawPopups() {
|
||||
static bool show_status_ = false;
|
||||
static absl::Status prev_status;
|
||||
if (!status_.ok()) {
|
||||
show_status_ = true;
|
||||
prev_status = status_;
|
||||
}
|
||||
|
||||
if (show_status_ && (BeginCentered("StatusWindow"))) {
|
||||
Text("%s", ICON_MD_ERROR);
|
||||
Text("%s", prev_status.ToString().c_str());
|
||||
Spacing();
|
||||
NextColumn();
|
||||
Columns(1);
|
||||
Separator();
|
||||
NewLine();
|
||||
SameLine(128);
|
||||
if (Button("OK", gui::kDefaultModalSize) || IsKeyPressed(ImGuiKey_Space)) {
|
||||
show_status_ = false;
|
||||
status_ = absl::OkStatus();
|
||||
}
|
||||
SameLine();
|
||||
if (Button(ICON_MD_CONTENT_COPY, ImVec2(50, 0))) {
|
||||
SetClipboardText(prev_status.ToString().c_str());
|
||||
}
|
||||
End();
|
||||
}
|
||||
|
||||
if (about_) OpenPopup("About");
|
||||
if (BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Yet Another Zelda3 Editor - v%s", version_.c_str());
|
||||
Text("Written by: scawful");
|
||||
Spacing();
|
||||
Text("Special Thanks: Zarby89, JaredBrian");
|
||||
Separator();
|
||||
|
||||
if (Button("Close", gui::kDefaultModalSize)) {
|
||||
about_ = false;
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
EndPopup();
|
||||
}
|
||||
|
||||
if (rom_info_) OpenPopup("ROM Information");
|
||||
if (BeginPopupModal("ROM Information", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Title: %s", rom()->title().c_str());
|
||||
Text("ROM Size: %s", util::HexLongLong(rom()->size()).c_str());
|
||||
|
||||
if (Button("Close", gui::kDefaultModalSize) ||
|
||||
IsKeyPressed(ImGuiKey_Escape)) {
|
||||
rom_info_ = false;
|
||||
CloseCurrentPopup();
|
||||
}
|
||||
EndPopup();
|
||||
}
|
||||
// This function is now handled by the PopupManager
|
||||
// We'll keep it as a placeholder in case we need to add more popup-related
|
||||
// functionality
|
||||
}
|
||||
|
||||
void EditorManager::DrawMenuBar() {
|
||||
|
||||
Reference in New Issue
Block a user