Add short name handling for ROMs in Rom class; update EditorManager to use short names in the ROM selector for improved UI clarity.

This commit is contained in:
scawful
2025-04-16 17:33:48 -04:00
parent 75d7ba9382
commit 00d30efbf1
4 changed files with 107 additions and 38 deletions

View File

@@ -49,18 +49,18 @@ std::string GetEditorName(EditorType type) {
return kEditorNames[static_cast<int>(type)]; return kEditorNames[static_cast<int>(type)];
} }
void DrawRomSelector(EditorManager &editor_manager) { } // namespace
const auto &roms = editor_manager.GetRoms();
const Rom *current_rom = editor_manager.GetCurrentRom(); void EditorManager::DrawRomSelector() {
absl::Status status; absl::Status status;
SameLine((GetWindowWidth() / 2) - 100); SameLine((GetWindowWidth() / 2) - 100);
if (current_rom && current_rom->is_loaded()) { if (current_rom_ && current_rom_->is_loaded()) {
SetNextItemWidth(GetWindowWidth() / 4); SetNextItemWidth(GetWindowWidth() / 6);
if (BeginCombo("##ROMSelector", current_rom->filename().c_str())) { if (BeginCombo("##ROMSelector", current_rom_->short_name().c_str())) {
for (const auto &rom : roms) { for (const auto &rom : roms_) {
if (MenuItem(rom->filename().c_str())) { if (MenuItem(rom->short_name().c_str())) {
status = editor_manager.SetCurrentRom(rom.get()); status = SetCurrentRom(rom.get());
} }
} }
EndCombo(); EndCombo();
@@ -74,7 +74,16 @@ void DrawRomSelector(EditorManager &editor_manager) {
} }
} }
} // namespace constexpr const char *kOverworldEditorName = ICON_MD_LAYERS " Overworld Editor";
constexpr const char *kGraphicsEditorName = ICON_MD_PHOTO " Graphics Editor";
constexpr const char *kPaletteEditorName = ICON_MD_PALETTE " Palette Editor";
constexpr const char *kScreenEditorName = ICON_MD_SCREENSHOT " Screen Editor";
constexpr const char *kSpriteEditorName = ICON_MD_SMART_TOY " Sprite Editor";
constexpr const char *kMessageEditorName = ICON_MD_MESSAGE " Message Editor";
constexpr const char *kSettingsEditorName = ICON_MD_SETTINGS " Settings Editor";
constexpr const char *kAssemblyEditorName = ICON_MD_CODE " Assembly Editor";
constexpr const char *kDungeonEditorName = ICON_MD_CASTLE " Dungeon Editor";
constexpr const char *kMusicEditorName = ICON_MD_MUSIC_NOTE " Music Editor";
void EditorManager::Initialize(const std::string &filename) { void EditorManager::Initialize(const std::string &filename) {
// Create a blank editor set // Create a blank editor set
@@ -144,8 +153,9 @@ void EditorManager::Initialize(const std::string &filename) {
recent_files.emplace_back("No Recent Files", "", nullptr); recent_files.emplace_back("No Recent Files", "", nullptr);
} else { } else {
for (const auto &filePath : manager.GetRecentFiles()) { for (const auto &filePath : manager.GetRecentFiles()) {
recent_files.emplace_back( recent_files.emplace_back(filePath, "", [filePath, this]() {
filePath, "", [filePath, this]() { status_ = OpenRomOrProject(filePath); }); status_ = OpenRomOrProject(filePath);
});
} }
} }
@@ -227,34 +237,33 @@ void EditorManager::Initialize(const std::string &filename) {
{ {
{absl::StrCat(ICON_MD_HOME, " Home"), "", {absl::StrCat(ICON_MD_HOME, " Home"), "",
[&]() { show_homepage_ = true; }}, [&]() { show_homepage_ = true; }},
{absl::StrCat(ICON_MD_CODE, " Assembly Editor"), "", {kAssemblyEditorName, "", [&]() { show_asm_editor_ = true; },
[&]() { show_asm_editor_ = true; },
[&]() { return show_asm_editor_; }}, [&]() { return show_asm_editor_; }},
{absl::StrCat(ICON_MD_CASTLE, " Dungeon Editor"), "", {kDungeonEditorName, "",
[&]() { current_editor_set_->dungeon_editor_.set_active(true); }, [&]() { current_editor_set_->dungeon_editor_.set_active(true); },
[&]() { return *current_editor_set_->dungeon_editor_.active(); }}, [&]() { return *current_editor_set_->dungeon_editor_.active(); }},
{absl::StrCat(ICON_MD_PHOTO, " Graphics Editor"), "", {kGraphicsEditorName, "",
[&]() { current_editor_set_->graphics_editor_.set_active(true); }, [&]() { current_editor_set_->graphics_editor_.set_active(true); },
[&]() { return *current_editor_set_->graphics_editor_.active(); }}, [&]() { return *current_editor_set_->graphics_editor_.active(); }},
{absl::StrCat(ICON_MD_MUSIC_NOTE, " Music Editor"), "", {kMusicEditorName, "",
[&]() { current_editor_set_->music_editor_.set_active(true); }, [&]() { current_editor_set_->music_editor_.set_active(true); },
[&]() { return *current_editor_set_->music_editor_.active(); }}, [&]() { return *current_editor_set_->music_editor_.active(); }},
{absl::StrCat(ICON_MD_LAYERS, " Overworld Editor"), "", {kOverworldEditorName, "",
[&]() { current_editor_set_->overworld_editor_.set_active(true); }, [&]() { current_editor_set_->overworld_editor_.set_active(true); },
[&]() { return *current_editor_set_->overworld_editor_.active(); }}, [&]() { return *current_editor_set_->overworld_editor_.active(); }},
{absl::StrCat(ICON_MD_PALETTE, " Palette Editor"), "", {kPaletteEditorName, "",
[&]() { current_editor_set_->palette_editor_.set_active(true); }, [&]() { current_editor_set_->palette_editor_.set_active(true); },
[&]() { return *current_editor_set_->palette_editor_.active(); }}, [&]() { return *current_editor_set_->palette_editor_.active(); }},
{absl::StrCat(ICON_MD_SCREENSHOT, " Screen Editor"), "", {kScreenEditorName, "",
[&]() { current_editor_set_->screen_editor_.set_active(true); }, [&]() { current_editor_set_->screen_editor_.set_active(true); },
[&]() { return *current_editor_set_->screen_editor_.active(); }}, [&]() { return *current_editor_set_->screen_editor_.active(); }},
{absl::StrCat(ICON_MD_SMART_TOY, " Sprite Editor"), "", {kSpriteEditorName, "",
[&]() { current_editor_set_->sprite_editor_.set_active(true); }, [&]() { current_editor_set_->sprite_editor_.set_active(true); },
[&]() { return *current_editor_set_->sprite_editor_.active(); }}, [&]() { return *current_editor_set_->sprite_editor_.active(); }},
{absl::StrCat(ICON_MD_MESSAGE, " Message Editor"), "", {kMessageEditorName, "",
[&]() { current_editor_set_->message_editor_.set_active(true); }, [&]() { current_editor_set_->message_editor_.set_active(true); },
[&]() { return *current_editor_set_->message_editor_.active(); }}, [&]() { return *current_editor_set_->message_editor_.active(); }},
{absl::StrCat(ICON_MD_SETTINGS, " Settings Editor"), "", {kSettingsEditorName, "",
[&]() { current_editor_set_->settings_editor_.set_active(true); }, [&]() { current_editor_set_->settings_editor_.set_active(true); },
[&]() { return *current_editor_set_->settings_editor_.active(); }}, [&]() { return *current_editor_set_->settings_editor_.active(); }},
{gui::kSeparator, "", nullptr, []() { return true; }}, {gui::kSeparator, "", nullptr, []() { return true; }},
@@ -301,6 +310,17 @@ absl::Status EditorManager::Update() {
if (current_editor_set_) { if (current_editor_set_) {
for (auto editor : current_editor_set_->active_editors_) { for (auto editor : current_editor_set_->active_editors_) {
if (*editor->active()) { if (*editor->active()) {
if (editor->type() == EditorType::kOverworld) {
auto &overworld_editor = static_cast<OverworldEditor &>(*editor);
if (overworld_editor.jump_to_tab() != -1) {
current_editor_set_->dungeon_editor_.set_active(true);
// Set the dungeon editor to the jump to tab
current_editor_set_->dungeon_editor_.add_room(
overworld_editor.jump_to_tab());
overworld_editor.jump_to_tab_ = -1;
}
}
if (ImGui::Begin(GetEditorName(editor->type()).c_str(), if (ImGui::Begin(GetEditorName(editor->type()).c_str(),
editor->active())) { editor->active())) {
current_editor_ = editor; current_editor_ = editor;
@@ -337,20 +357,57 @@ void EditorManager::DrawHomepage() {
"The editor is still in development, so please report any bugs or issues " "The editor is still in development, so please report any bugs or issues "
"you encounter."); "you encounter.");
if (current_rom_) { if (!current_rom_) {
TextWrapped("Current ROM: %s", current_rom_->filename().c_str());
} else {
TextWrapped("No ROM loaded."); TextWrapped("No ROM loaded.");
if (gui::ClickableText("Open a ROM")) { if (gui::ClickableText("Open a ROM")) {
status_ = LoadRom(); status_ = LoadRom();
} }
} // Checkbox for loading a ROM with custom overworld flag.
} Checkbox("Load custom overworld features",
&core::FeatureFlags::get().overworld.kLoadCustomOverworld);
void EditorManager::DrawPopups() { // Recent Files list
// This function is now handled by the PopupManager TextWrapped("Recent Files");
// We'll keep it as a placeholder in case we need to add more popup-related static RecentFilesManager manager("recent_files.txt");
// functionality manager.Load();
for (const auto &file : manager.GetRecentFiles()) {
if (gui::ClickableText(file.c_str())) {
status_ = OpenRomOrProject(file);
}
}
return;
}
TextWrapped("Current ROM: %s", current_rom_->filename().c_str());
// Quick buttons for opening editors
if (Button(kOverworldEditorName)) {
current_editor_set_->overworld_editor_.set_active(true);
}
ImGui::SameLine();
if (Button(kDungeonEditorName)) {
current_editor_set_->dungeon_editor_.set_active(true);
}
ImGui::SameLine();
if (Button(kGraphicsEditorName)) {
current_editor_set_->graphics_editor_.set_active(true);
}
ImGui::SameLine();
if (Button(kPaletteEditorName)) {
current_editor_set_->palette_editor_.set_active(true);
}
ImGui::SameLine();
if (Button(kScreenEditorName)) {
current_editor_set_->screen_editor_.set_active(true);
}
ImGui::SameLine();
if (Button(kSpriteEditorName)) {
current_editor_set_->sprite_editor_.set_active(true);
}
ImGui::SameLine();
if (Button(kMessageEditorName)) {
current_editor_set_->message_editor_.set_active(true);
}
} }
void EditorManager::DrawMenuBar() { void EditorManager::DrawMenuBar() {
@@ -360,7 +417,7 @@ void EditorManager::DrawMenuBar() {
if (BeginMenuBar()) { if (BeginMenuBar()) {
gui::DrawMenu(gui::kMainMenu); gui::DrawMenu(gui::kMainMenu);
DrawRomSelector(*this); DrawRomSelector();
SameLine(GetWindowWidth() - GetStyle().ItemSpacing.x - SameLine(GetWindowWidth() - GetStyle().ItemSpacing.x -
CalcTextSize(ICON_MD_DISPLAY_SETTINGS).x - 110); CalcTextSize(ICON_MD_DISPLAY_SETTINGS).x - 110);
@@ -609,11 +666,12 @@ absl::Status EditorManager::SetCurrentRom(Rom *rom) {
editor_sets_[rom] = std::move(editor_set); editor_sets_[rom] = std::move(editor_set);
current_rom_ = rom; current_rom_ = rom;
SharedRom::set_rom(rom);
RETURN_IF_ERROR(LoadAssets()); RETURN_IF_ERROR(LoadAssets());
} else { } else {
current_editor_set_ = it->second.get(); current_editor_set_ = it->second.get();
current_rom_ = rom; current_rom_ = rom;
SharedRom::set_rom(rom); SharedRom::set_rom(current_rom_);
} }
return absl::OkStatus(); return absl::OkStatus();

View File

@@ -60,13 +60,12 @@ class EditorManager {
auto version() const { return version_; } auto version() const { return version_; }
absl::Status SetCurrentRom(Rom* rom); absl::Status SetCurrentRom(Rom* rom);
auto GetRoms() -> std::vector<std::unique_ptr<Rom>>& { return roms_; }
auto GetCurrentRom() -> Rom* { return current_rom_; } auto GetCurrentRom() -> Rom* { return current_rom_; }
auto GetCurrentEditorSet() -> EditorSet* { return current_editor_set_; } auto GetCurrentEditorSet() -> EditorSet* { return current_editor_set_; }
private: private:
void DrawHomepage(); void DrawHomepage();
void DrawPopups(); void DrawRomSelector();
absl::Status LoadRom(); absl::Status LoadRom();
absl::Status LoadAssets(); absl::Status LoadAssets();
@@ -94,7 +93,7 @@ class EditorManager {
absl::Status status_; absl::Status status_;
emu::Emulator emulator_; emu::Emulator emulator_;
std::vector<std::unique_ptr<Rom>> roms_; std::vector<std::shared_ptr<Rom>> roms_;
std::unordered_map<Rom*, std::unique_ptr<EditorSet>> editor_sets_; std::unordered_map<Rom*, std::unique_ptr<EditorSet>> editor_sets_;
Rom* current_rom_ = nullptr; Rom* current_rom_ = nullptr;
EditorSet* current_editor_set_ = nullptr; EditorSet* current_editor_set_ = nullptr;

View File

@@ -176,6 +176,8 @@ absl::Status Rom::LoadFromFile(const std::string &filename, bool z3_load) {
} }
std::string full_filename = std::filesystem::absolute(filename).string(); std::string full_filename = std::filesystem::absolute(filename).string();
filename_ = full_filename; filename_ = full_filename;
// Get the short name of the ROM
short_name_ = filename_.substr(filename_.find_last_of("/\\") + 1);
std::ifstream file(filename_, std::ios::binary); std::ifstream file(filename_, std::ios::binary);
if (!file.is_open()) { if (!file.is_open()) {

View File

@@ -168,7 +168,7 @@ class Rom {
auto vector() const { return rom_data_; } auto vector() const { return rom_data_; }
auto filename() const { return filename_; } auto filename() const { return filename_; }
auto set_filename(std::string name) { filename_ = name; } auto set_filename(std::string name) { filename_ = name; }
auto short_name() const { return short_name_; }
std::vector<uint8_t> graphics_buffer() const { return graphics_buffer_; } std::vector<uint8_t> graphics_buffer() const { return graphics_buffer_; }
auto mutable_graphics_buffer() { return &graphics_buffer_; } auto mutable_graphics_buffer() { return &graphics_buffer_; }
auto palette_group() const { return palette_groups_; } auto palette_group() const { return palette_groups_; }
@@ -248,6 +248,9 @@ class Rom {
// Filename of the ROM // Filename of the ROM
std::string filename_ = ""; std::string filename_ = "";
// Short name of the ROM
std::string short_name_ = "";
// Full contiguous rom space // Full contiguous rom space
std::vector<uint8_t> rom_data_; std::vector<uint8_t> rom_data_;
@@ -386,6 +389,13 @@ class SharedRom {
return rom; return rom;
} }
static void set_rom(Rom* rom) {
if (!shared_rom_) {
shared_rom_ = std::make_shared<Rom>();
}
shared_rom_ = std::shared_ptr<Rom>(rom);
}
// private: // private:
static std::shared_ptr<Rom> shared_rom_; static std::shared_ptr<Rom> shared_rom_;
}; };