Add "Load Last ROM" shortcut and streamline ROM asset loading in EditorManager

This commit is contained in:
scawful
2025-03-11 14:04:13 -04:00
parent c8ce2843b1
commit 33de8d2c77
4 changed files with 35 additions and 28 deletions

View File

@@ -39,7 +39,7 @@ struct Project {
return absl::OkStatus();
}
absl::Status Open(const std::string &project_path);
absl::Status Open(const std::string& project_path);
absl::Status Save();
bool project_opened_ = false;
@@ -128,6 +128,14 @@ class RecentFilesManager {
std::vector<std::string> recent_files_;
};
class VersionControlManager {
absl::Status Commit(const std::string& message);
absl::Status Pull();
absl::Status Push();
private:
std::string repository_path_;
};
} // namespace yaze

View File

@@ -102,6 +102,15 @@ void EditorManager::Initialize(const std::string &filename) {
"Find", {ImGuiKey_F, ImGuiMod_Ctrl},
[&]() { status_ = current_editor_->Find(); });
context_.shortcut_manager.RegisterShortcut(
"Load Last ROM", {ImGuiKey_R, ImGuiMod_Ctrl}, [&]() {
manager.Load();
if (!manager.GetRecentFiles().empty()) {
auto front = manager.GetRecentFiles().front();
OpenRomOrProject(front);
}
});
context_.shortcut_manager.RegisterShortcut("F1", ImGuiKey_F1,
[&]() { about_ = true; });
@@ -195,29 +204,10 @@ void EditorManager::Initialize(const std::string &filename) {
}
absl::Status EditorManager::Update() {
ExecuteShortcuts(context_.shortcut_manager);
context_.command_manager.ShowWhichKey();
// If CMD + R is pressed, reload the top result of recent files
if (IsKeyDown(ImGuiKey_R) && GetIO().KeyCtrl) {
static RecentFilesManager manager("recent_files.txt");
manager.Load();
if (!manager.GetRecentFiles().empty()) {
auto front = manager.GetRecentFiles().front();
OpenRomOrProject(front);
}
}
DrawMenuBar();
DrawPopups();
if (rom()->is_loaded() && !rom_assets_loaded_) {
auto &sheet_manager = GraphicsSheetManager::GetInstance();
ASSIGN_OR_RETURN(*sheet_manager.mutable_gfx_sheets(),
LoadAllGraphicsData(*rom()))
RETURN_IF_ERROR(overworld_editor_.LoadGraphics());
rom_assets_loaded_ = true;
}
ExecuteShortcuts(context_.shortcut_manager);
context_.command_manager.ShowWhichKey();
if (!current_rom_) {
DrawHomepage();
@@ -651,6 +641,16 @@ void EditorManager::LoadRom() {
manager.Load();
manager.AddFile(file_name);
manager.Save();
auto load_rom_assets = [&]() -> absl::Status {
auto &sheet_manager = GraphicsSheetManager::GetInstance();
ASSIGN_OR_RETURN(*sheet_manager.mutable_gfx_sheets(),
LoadAllGraphicsData(*rom()))
RETURN_IF_ERROR(overworld_editor_.LoadGraphics());
return absl::OkStatus();
};
if (!load_rom_assets().ok()) {
status_ = load_rom_assets();
}
}
}

View File

@@ -75,8 +75,12 @@ class EditorManager : public SharedRom {
bool about_ = false;
bool rom_info_ = false;
bool backup_rom_ = false;
bool save_new_auto_ = true;
bool save_as_menu_ = false;
bool save_new_auto_ = true;
bool open_rom_help = false;
bool open_manage_project = false;
bool open_supported_features = false;
bool show_emulator_ = false;
bool show_memory_editor_ = false;
bool show_asm_editor_ = false;
@@ -84,10 +88,6 @@ class EditorManager : public SharedRom {
bool show_imgui_demo_ = false;
bool show_palette_editor_ = false;
bool show_resource_label_manager = false;
bool open_supported_features = false;
bool open_rom_help = false;
bool open_manage_project = false;
bool rom_assets_loaded_ = false;
std::string version_ = "";

View File

@@ -537,5 +537,4 @@ void Emulator::RenderCpuInstructionLog(
}
} // namespace emu
} // namespace yaze