Implement dynamic layout support and enhance window management commands in EditorManager
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
#include "app/gui/style.h"
|
#include "app/gui/style.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
|
#include "editor/editor.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||||
|
|
||||||
@@ -71,6 +72,9 @@ absl::Status EditorManager::Update() {
|
|||||||
rom_assets_loaded_ = true;
|
rom_assets_loaded_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dynamic_layout_)
|
||||||
|
RETURN_IF_ERROR(DrawDynamicLayout())
|
||||||
|
else
|
||||||
ManageActiveEditors();
|
ManageActiveEditors();
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
@@ -239,6 +243,13 @@ 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() {
|
void EditorManager::ManageKeyboardShortcuts() {
|
||||||
bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper);
|
bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper);
|
||||||
|
|
||||||
@@ -298,6 +309,80 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
command_manager_.RegisterPrefix("window", 'w', "window management", "");
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
command_manager_.RegisterSubcommand("window", "close", 'd', "close",
|
||||||
|
"close the current editor", [this]() {
|
||||||
|
if (root_layout_.editor != nullptr) {
|
||||||
|
root_layout_.editor = nullptr;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void EditorManager::DrawStatusPopup() {
|
void EditorManager::DrawStatusPopup() {
|
||||||
static absl::Status prev_status;
|
static absl::Status prev_status;
|
||||||
if (!status_.ok()) {
|
if (!status_.ok()) {
|
||||||
@@ -557,6 +642,7 @@ void EditorManager::DrawYazeMenuBar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (BeginMenu("View")) {
|
if (BeginMenu("View")) {
|
||||||
|
MenuItem("Dynamic Layout", nullptr, &dynamic_layout_);
|
||||||
MenuItem("Emulator", nullptr, &show_emulator);
|
MenuItem("Emulator", nullptr, &show_emulator);
|
||||||
Separator();
|
Separator();
|
||||||
MenuItem("Memory Editor", nullptr, &show_memory_editor);
|
MenuItem("Memory Editor", nullptr, &show_memory_editor);
|
||||||
@@ -572,7 +658,6 @@ void EditorManager::DrawYazeMenuBar() {
|
|||||||
|
|
||||||
static bool show_resource_label_manager = false;
|
static bool show_resource_label_manager = false;
|
||||||
if (current_project_.project_opened_) {
|
if (current_project_.project_opened_) {
|
||||||
// Project Menu
|
|
||||||
if (BeginMenu("Project")) {
|
if (BeginMenu("Project")) {
|
||||||
Text("Name: %s", current_project_.name.c_str());
|
Text("Name: %s", current_project_.name.c_str());
|
||||||
Text("ROM: %s", current_project_.rom_filename_.c_str());
|
Text("ROM: %s", current_project_.rom_filename_.c_str());
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void ManageActiveEditors();
|
void ManageActiveEditors();
|
||||||
|
absl::Status DrawDynamicLayout();
|
||||||
|
|
||||||
void ManageKeyboardShortcuts();
|
void ManageKeyboardShortcuts();
|
||||||
|
void InitializeCommands();
|
||||||
|
|
||||||
void DrawStatusPopup();
|
void DrawStatusPopup();
|
||||||
void DrawAboutPopup();
|
void DrawAboutPopup();
|
||||||
@@ -89,20 +92,22 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
bool save_new_auto_ = true;
|
bool save_new_auto_ = true;
|
||||||
bool show_status_ = false;
|
bool show_status_ = false;
|
||||||
bool rom_assets_loaded_ = false;
|
bool rom_assets_loaded_ = false;
|
||||||
|
bool dynamic_layout_ = false;
|
||||||
|
|
||||||
absl::Status status_;
|
absl::Status status_;
|
||||||
|
|
||||||
std::vector<Editor *> active_editors_;
|
|
||||||
|
|
||||||
emu::Emulator emulator_;
|
emu::Emulator emulator_;
|
||||||
|
|
||||||
|
std::vector<Editor *> active_editors_;
|
||||||
|
std::vector<EditorLayoutParams> active_layouts_;
|
||||||
|
|
||||||
Project current_project_;
|
Project current_project_;
|
||||||
CommandManager command_manager_;
|
CommandManager command_manager_;
|
||||||
ConstantManager constant_manager_;
|
ConstantManager constant_manager_;
|
||||||
ExtensionManager extension_manager_;
|
ExtensionManager extension_manager_;
|
||||||
yaze_editor_context editor_context_;
|
|
||||||
|
|
||||||
Editor *current_editor_ = nullptr;
|
Editor *current_editor_ = nullptr;
|
||||||
|
EditorLayoutParams root_layout_;
|
||||||
AssemblyEditor assembly_editor_;
|
AssemblyEditor assembly_editor_;
|
||||||
DungeonEditor dungeon_editor_;
|
DungeonEditor dungeon_editor_;
|
||||||
GraphicsEditor graphics_editor_;
|
GraphicsEditor graphics_editor_;
|
||||||
@@ -114,6 +119,8 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
SettingsEditor settings_editor_;
|
SettingsEditor settings_editor_;
|
||||||
MessageEditor message_editor_;
|
MessageEditor message_editor_;
|
||||||
MemoryEditorWithDiffChecker memory_editor_;
|
MemoryEditorWithDiffChecker memory_editor_;
|
||||||
|
|
||||||
|
yaze_editor_context editor_context_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
Reference in New Issue
Block a user