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