Remove dynamic layout code
This commit is contained in:
@@ -1,51 +1,7 @@
|
||||
#include "editor.h"
|
||||
|
||||
#include "app/core/constants.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
|
||||
absl::Status DrawEditor(EditorLayoutParams *params) {
|
||||
if (params->editor == nullptr) {
|
||||
return absl::InternalError("Editor is not initialized");
|
||||
}
|
||||
|
||||
// Draw the editors based on h_split and v_split in a recursive manner
|
||||
if (params->v_split) {
|
||||
ImGui::BeginTable("##VerticalSplitTable", 2);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (params->left)
|
||||
RETURN_IF_ERROR(DrawEditor(params->left));
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (params->right)
|
||||
RETURN_IF_ERROR(DrawEditor(params->right));
|
||||
|
||||
ImGui::EndTable();
|
||||
} else if (params->h_split) {
|
||||
ImGui::BeginTable("##HorizontalSplitTable", 1);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (params->top)
|
||||
RETURN_IF_ERROR(DrawEditor(params->top));
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (params->bottom)
|
||||
RETURN_IF_ERROR(DrawEditor(params->bottom));
|
||||
|
||||
ImGui::EndTable();
|
||||
} else {
|
||||
// No split, just draw the single editor
|
||||
ImGui::Text("%s Editor",
|
||||
kEditorNames[static_cast<int>(params->editor->type())]);
|
||||
RETURN_IF_ERROR(params->editor->Update());
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace editor
|
||||
|
||||
} // namespace yaze
|
||||
|
||||
@@ -73,30 +73,6 @@ class Editor {
|
||||
EditorContext context_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Dynamic Editor Layout Parameters
|
||||
*/
|
||||
typedef struct EditorLayoutParams {
|
||||
bool v_split;
|
||||
bool h_split;
|
||||
int v_split_pos;
|
||||
int h_split_pos;
|
||||
Editor *editor = nullptr;
|
||||
EditorLayoutParams *left = nullptr;
|
||||
EditorLayoutParams *right = nullptr;
|
||||
EditorLayoutParams *top = nullptr;
|
||||
EditorLayoutParams *bottom = nullptr;
|
||||
|
||||
EditorLayoutParams() {
|
||||
v_split = false;
|
||||
h_split = false;
|
||||
v_split_pos = 0;
|
||||
h_split_pos = 0;
|
||||
}
|
||||
} EditorLayoutParams;
|
||||
|
||||
absl::Status DrawEditor(EditorLayoutParams *params);
|
||||
|
||||
} // namespace editor
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -65,16 +65,11 @@ absl::Status EditorManager::Update() {
|
||||
DrawInfoPopup();
|
||||
|
||||
if (rom()->is_loaded() && !rom_assets_loaded_) {
|
||||
// Load all of the graphics data from the game.
|
||||
RETURN_IF_ERROR(rom()->LoadAllGraphicsData())
|
||||
// Initialize overworld graphics, maps, and palettes
|
||||
RETURN_IF_ERROR(overworld_editor_.LoadGraphics());
|
||||
rom_assets_loaded_ = true;
|
||||
}
|
||||
|
||||
if (dynamic_layout_)
|
||||
RETURN_IF_ERROR(DrawDynamicLayout())
|
||||
else
|
||||
ManageActiveEditors();
|
||||
|
||||
return absl::OkStatus();
|
||||
@@ -83,7 +78,8 @@ absl::Status EditorManager::Update() {
|
||||
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 (show_add_editor)
|
||||
OpenPopup("AddEditor");
|
||||
|
||||
if (BeginPopup("AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
if (MenuItem("Overworld", nullptr, false,
|
||||
@@ -243,12 +239,6 @@ void EditorManager::ManageActiveEditors() {
|
||||
}
|
||||
}
|
||||
|
||||
absl::Status EditorManager::DrawDynamicLayout() {
|
||||
// Dynamic layout for multiple editors to be open at once
|
||||
// Allows for tiling and resizing of editors using ImGui
|
||||
return DrawEditor(&root_layout_);
|
||||
}
|
||||
|
||||
void EditorManager::ManageKeyboardShortcuts() {
|
||||
bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper);
|
||||
|
||||
@@ -309,78 +299,8 @@ void EditorManager::ManageKeyboardShortcuts() {
|
||||
}
|
||||
|
||||
void EditorManager::InitializeCommands() {
|
||||
if (root_layout_.editor == nullptr) {
|
||||
root_layout_.editor = &overworld_editor_;
|
||||
}
|
||||
|
||||
// New editor popup for window management commands
|
||||
static EditorLayoutParams new_layout;
|
||||
if (ImGui::BeginPopup("NewEditor")) {
|
||||
ImGui::Text("New Editor");
|
||||
ImGui::Separator();
|
||||
if (ImGui::Button("Overworld")) {
|
||||
new_layout.editor = &overworld_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Dungeon")) {
|
||||
new_layout.editor = &dungeon_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Graphics")) {
|
||||
new_layout.editor = &graphics_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Music")) {
|
||||
new_layout.editor = &music_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Palette")) {
|
||||
new_layout.editor = &palette_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Screen")) {
|
||||
new_layout.editor = &screen_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Sprite")) {
|
||||
new_layout.editor = &sprite_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Code")) {
|
||||
new_layout.editor = &assembly_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Settings")) {
|
||||
new_layout.editor = &settings_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button("Message")) {
|
||||
new_layout.editor = &message_editor_;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
editor_context_.command_manager.RegisterPrefix("window", 'w',
|
||||
"window management", "");
|
||||
editor_context_.command_manager.RegisterSubcommand(
|
||||
"window", "vsplit", '/', "vertical split",
|
||||
"split windows vertically and place editor in new window", [this]() {
|
||||
ImGui::OpenPopup("NewEditor");
|
||||
root_layout_.v_split = true;
|
||||
});
|
||||
editor_context_.command_manager.RegisterSubcommand(
|
||||
"window", "hsplit", '-', "horizontal split",
|
||||
"split windows horizontally and place editor in new window", [this]() {
|
||||
ImGui::OpenPopup("NewEditor");
|
||||
root_layout_.h_split = true;
|
||||
});
|
||||
editor_context_.command_manager.RegisterSubcommand(
|
||||
"window", "close", 'd', "close", "close the current editor", [this]() {
|
||||
if (root_layout_.editor != nullptr) {
|
||||
root_layout_.editor = nullptr;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void EditorManager::DrawStatusPopup() {
|
||||
@@ -412,7 +332,8 @@ void EditorManager::DrawStatusPopup() {
|
||||
}
|
||||
|
||||
void EditorManager::DrawAboutPopup() {
|
||||
if (about_) OpenPopup("About");
|
||||
if (about_)
|
||||
OpenPopup("About");
|
||||
if (BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Yet Another Zelda3 Editor - v%s", core::kYazeVersion.data());
|
||||
Text("Written by: scawful");
|
||||
@@ -429,7 +350,8 @@ void EditorManager::DrawAboutPopup() {
|
||||
}
|
||||
|
||||
void EditorManager::DrawInfoPopup() {
|
||||
if (rom_info_) OpenPopup("ROM Information");
|
||||
if (rom_info_)
|
||||
OpenPopup("ROM Information");
|
||||
if (BeginPopupModal("ROM Information", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Title: %s", rom()->title().c_str());
|
||||
@@ -624,10 +546,14 @@ void EditorManager::DrawYazeMenuBar() {
|
||||
static bool show_palette_editor = false;
|
||||
static bool show_emulator = false;
|
||||
|
||||
if (show_imgui_demo) ShowDemoWindow();
|
||||
if (show_imgui_metrics) ShowMetricsWindow(&show_imgui_metrics);
|
||||
if (show_memory_editor) memory_editor_.Update(show_memory_editor);
|
||||
if (show_asm_editor) assembly_editor_.Update(show_asm_editor);
|
||||
if (show_imgui_demo)
|
||||
ShowDemoWindow();
|
||||
if (show_imgui_metrics)
|
||||
ShowMetricsWindow(&show_imgui_metrics);
|
||||
if (show_memory_editor)
|
||||
memory_editor_.Update(show_memory_editor);
|
||||
if (show_asm_editor)
|
||||
assembly_editor_.Update(show_asm_editor);
|
||||
|
||||
if (show_emulator) {
|
||||
Begin("Emulator", &show_emulator, ImGuiWindowFlags_MenuBar);
|
||||
@@ -642,7 +568,6 @@ void EditorManager::DrawYazeMenuBar() {
|
||||
}
|
||||
|
||||
if (BeginMenu("View")) {
|
||||
MenuItem("Dynamic Layout", nullptr, &dynamic_layout_);
|
||||
MenuItem("Emulator", nullptr, &show_emulator);
|
||||
Separator();
|
||||
MenuItem("Memory Editor", nullptr, &show_memory_editor);
|
||||
@@ -673,15 +598,20 @@ void EditorManager::DrawYazeMenuBar() {
|
||||
static bool open_supported_features = false;
|
||||
static bool open_manage_project = false;
|
||||
if (BeginMenu("Help")) {
|
||||
if (MenuItem("How to open a ROM")) open_rom_help = true;
|
||||
if (MenuItem("Supported Features")) open_supported_features = true;
|
||||
if (MenuItem("How to manage a project")) open_manage_project = true;
|
||||
if (MenuItem("How to open a ROM"))
|
||||
open_rom_help = true;
|
||||
if (MenuItem("Supported Features"))
|
||||
open_supported_features = true;
|
||||
if (MenuItem("How to manage a project"))
|
||||
open_manage_project = true;
|
||||
|
||||
if (MenuItem("About", "F1")) about_ = true;
|
||||
if (MenuItem("About", "F1"))
|
||||
about_ = true;
|
||||
EndMenu();
|
||||
}
|
||||
|
||||
if (open_supported_features) OpenPopup("Supported Features");
|
||||
if (open_supported_features)
|
||||
OpenPopup("Supported Features");
|
||||
if (BeginPopupModal("Supported Features", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Overworld");
|
||||
@@ -714,7 +644,8 @@ void EditorManager::DrawYazeMenuBar() {
|
||||
EndPopup();
|
||||
}
|
||||
|
||||
if (open_rom_help) OpenPopup("Open a ROM");
|
||||
if (open_rom_help)
|
||||
OpenPopup("Open a ROM");
|
||||
if (BeginPopupModal("Open a ROM", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("File -> Open");
|
||||
@@ -731,7 +662,8 @@ void EditorManager::DrawYazeMenuBar() {
|
||||
EndPopup();
|
||||
}
|
||||
|
||||
if (open_manage_project) OpenPopup("Manage Project");
|
||||
if (open_manage_project)
|
||||
OpenPopup("Manage Project");
|
||||
if (BeginPopupModal("Manage Project", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Project Menu");
|
||||
|
||||
@@ -55,8 +55,6 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
||||
|
||||
private:
|
||||
void ManageActiveEditors();
|
||||
absl::Status DrawDynamicLayout();
|
||||
|
||||
void ManageKeyboardShortcuts();
|
||||
void InitializeCommands();
|
||||
|
||||
@@ -80,16 +78,10 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
||||
bool save_new_auto_ = true;
|
||||
bool show_status_ = false;
|
||||
bool rom_assets_loaded_ = false;
|
||||
bool dynamic_layout_ = false;
|
||||
|
||||
absl::Status status_;
|
||||
|
||||
emu::Emulator emulator_;
|
||||
|
||||
std::vector<Editor *> active_editors_;
|
||||
std::vector<EditorLayoutParams> active_layouts_;
|
||||
|
||||
EditorLayoutParams root_layout_;
|
||||
|
||||
Project current_project_;
|
||||
EditorContext editor_context_;
|
||||
|
||||
Reference in New Issue
Block a user