Add file management to ResourceLabelManager, include in settings
This commit is contained in:
@@ -20,8 +20,18 @@ namespace core {
|
||||
bool ResourceLabelManager::LoadLabels(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
// Create the file if it does not exist
|
||||
std::ofstream create_file(filename);
|
||||
if (!create_file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
create_file.close();
|
||||
file.open(filename);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
filename_ = filename;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
@@ -32,11 +42,35 @@ bool ResourceLabelManager::LoadLabels(const std::string& filename) {
|
||||
labels_[type][key] = value;
|
||||
}
|
||||
}
|
||||
labels_loaded_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResourceLabelManager::DisplayLabels() {
|
||||
if (ImGui::Begin("Resource Labels")) {
|
||||
bool ResourceLabelManager::SaveLabels() {
|
||||
if (!labels_loaded_) {
|
||||
return false;
|
||||
}
|
||||
std::ofstream file(filename_);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
for (const auto& type_pair : labels_) {
|
||||
for (const auto& label_pair : type_pair.second) {
|
||||
file << type_pair.first << "," << label_pair.first << ","
|
||||
<< label_pair.second << std::endl;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResourceLabelManager::DisplayLabels(bool* p_open) {
|
||||
if (!labels_loaded_) {
|
||||
ImGui::Text("No labels loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui::Begin("Resource Labels", p_open)) {
|
||||
for (const auto& type_pair : labels_) {
|
||||
if (ImGui::TreeNode(type_pair.first.c_str())) {
|
||||
for (const auto& label_pair : type_pair.second) {
|
||||
@@ -47,6 +81,14 @@ void ResourceLabelManager::DisplayLabels() {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Button("Update Labels")) {
|
||||
if (SaveLabels()) {
|
||||
ImGui::Text("Labels updated successfully!");
|
||||
} else {
|
||||
ImGui::Text("Failed to update labels.");
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ class ResourceLabelManager {
|
||||
ResourceLabelManager() = default;
|
||||
|
||||
bool LoadLabels(const std::string& filename);
|
||||
void DisplayLabels();
|
||||
bool SaveLabels();
|
||||
void DisplayLabels(bool* p_open);
|
||||
void EditLabel(const std::string& type, const std::string& key,
|
||||
const std::string& newValue);
|
||||
void SelectableLabelWithNameEdit(bool selected, const std::string& type,
|
||||
@@ -36,6 +37,8 @@ class ResourceLabelManager {
|
||||
const std::string& defaultValue);
|
||||
|
||||
private:
|
||||
bool labels_loaded_ = false;
|
||||
std::string filename_;
|
||||
struct ResourceType {
|
||||
std::string key_name;
|
||||
std::string display_description;
|
||||
|
||||
@@ -113,6 +113,7 @@ class RecentFilesManager {
|
||||
} // namespace
|
||||
|
||||
using ImGui::BeginMenu;
|
||||
using ImGui::Checkbox;
|
||||
using ImGui::MenuItem;
|
||||
using ImGui::Text;
|
||||
|
||||
@@ -203,7 +204,7 @@ void MasterEditor::DrawAboutPopup() {
|
||||
if (about_) ImGui::OpenPopup("About");
|
||||
if (ImGui::BeginPopupModal("About", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Yet Another Zelda3 Editor - v0.05");
|
||||
Text("Yet Another Zelda3 Editor - v%d", core::kYazeVersion);
|
||||
Text("Written by: scawful");
|
||||
ImGui::Spacing();
|
||||
Text("Special Thanks: Zarby89, JaredBrian");
|
||||
@@ -321,22 +322,20 @@ void MasterEditor::DrawFileMenu() {
|
||||
MenuItem("Backup ROM", "", &backup_rom_);
|
||||
ImGui::Separator();
|
||||
Text("Experiment Flags");
|
||||
ImGui::Checkbox("Enable Texture Streaming",
|
||||
&mutable_flags()->kLoadTexturesAsStreaming);
|
||||
ImGui::Checkbox("Enable Overworld Sprites",
|
||||
&mutable_flags()->kDrawOverworldSprites);
|
||||
ImGui::Checkbox("Use Bitmap Manager",
|
||||
&mutable_flags()->kUseBitmapManager);
|
||||
ImGui::Checkbox("Log Instructions to Debugger",
|
||||
&mutable_flags()->kLogInstructions);
|
||||
ImGui::Checkbox("Use New ImGui Input",
|
||||
&mutable_flags()->kUseNewImGuiInput);
|
||||
ImGui::Checkbox("Save All Palettes", &mutable_flags()->kSaveAllPalettes);
|
||||
ImGui::Checkbox("Save With Change Queue",
|
||||
&mutable_flags()->kSaveWithChangeQueue);
|
||||
ImGui::Checkbox("Draw Dungeon Room Graphics",
|
||||
&mutable_flags()->kDrawDungeonRoomGraphics);
|
||||
ImGui::Checkbox("Save Dungeon Maps", &mutable_flags()->kSaveDungeonMaps);
|
||||
Checkbox("Enable Texture Streaming",
|
||||
&mutable_flags()->kLoadTexturesAsStreaming);
|
||||
Checkbox("Enable Overworld Sprites",
|
||||
&mutable_flags()->kDrawOverworldSprites);
|
||||
Checkbox("Use Bitmap Manager", &mutable_flags()->kUseBitmapManager);
|
||||
Checkbox("Log Instructions to Debugger",
|
||||
&mutable_flags()->kLogInstructions);
|
||||
Checkbox("Use New ImGui Input", &mutable_flags()->kUseNewImGuiInput);
|
||||
Checkbox("Save All Palettes", &mutable_flags()->kSaveAllPalettes);
|
||||
Checkbox("Save With Change Queue",
|
||||
&mutable_flags()->kSaveWithChangeQueue);
|
||||
Checkbox("Draw Dungeon Room Graphics",
|
||||
&mutable_flags()->kDrawDungeonRoomGraphics);
|
||||
Checkbox("Save Dungeon Maps", &mutable_flags()->kSaveDungeonMaps);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@@ -389,6 +388,7 @@ void MasterEditor::DrawViewMenu() {
|
||||
static bool show_memory_viewer = false;
|
||||
static bool show_palette_editor = false;
|
||||
static bool show_emulator = false;
|
||||
static bool show_resource_label_manager = false;
|
||||
|
||||
if (show_emulator) {
|
||||
ImGui::Begin("Emulator", &show_emulator, ImGuiWindowFlags_MenuBar);
|
||||
@@ -442,12 +442,20 @@ void MasterEditor::DrawViewMenu() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (show_resource_label_manager) {
|
||||
rom()->resource_label()->DisplayLabels(&show_resource_label_manager);
|
||||
}
|
||||
|
||||
if (BeginMenu("View")) {
|
||||
MenuItem("Emulator", nullptr, &show_emulator);
|
||||
MenuItem("HEX Editor", nullptr, &show_memory_editor);
|
||||
MenuItem("ASM Editor", nullptr, &show_asm_editor);
|
||||
MenuItem("Palette Editor", nullptr, &show_palette_editor);
|
||||
MenuItem("Memory Viewer", nullptr, &show_memory_viewer);
|
||||
ImGui::Separator();
|
||||
MenuItem("Resource Label Manager", nullptr, &show_resource_label_manager);
|
||||
ImGui::Separator();
|
||||
MenuItem("Hex Editor", nullptr, &show_memory_editor);
|
||||
MenuItem("Assembly Editor", nullptr, &show_asm_editor);
|
||||
MenuItem("Palette Editor", nullptr, &show_palette_editor);
|
||||
ImGui::Separator();
|
||||
MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
|
||||
MenuItem("ImGui Metrics", nullptr, &show_imgui_metrics);
|
||||
ImGui::EndMenu();
|
||||
|
||||
@@ -347,6 +347,10 @@ absl::Status ROM::LoadFromFile(const absl::string_view& filename,
|
||||
LoadGfxGroups();
|
||||
}
|
||||
|
||||
// Set up the resource labels
|
||||
std::string resource_label_filename = absl::StrFormat("%s.labels", filename);
|
||||
resource_label_manager_.LoadLabels(resource_label_filename);
|
||||
|
||||
// Set is_loaded_ flag and return success
|
||||
is_loaded_ = true;
|
||||
return absl::OkStatus();
|
||||
|
||||
Reference in New Issue
Block a user