diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ce6df54a..b01889b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ set( YAZE_APP_CORE_SRC app/core/common.cc app/core/controller.cc + app/core/labeling.cc ) set( diff --git a/src/app/core/labeling.cc b/src/app/core/labeling.cc new file mode 100644 index 00000000..439b8ddd --- /dev/null +++ b/src/app/core/labeling.cc @@ -0,0 +1,97 @@ +#include "app/core/labeling.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "app/core/common.h" +#include "app/core/constants.h" + +namespace yaze { +namespace app { +namespace core { + +bool ResourceLabelManager::LoadLabels(const std::string& filename) { + std::ifstream file(filename); + if (!file.is_open()) { + return false; + } + + std::string line; + while (std::getline(file, line)) { + std::istringstream iss(line); + std::string type, key, value; + if (std::getline(iss, type, ',') && std::getline(iss, key, ',') && + std::getline(iss, value)) { + labels_[type][key] = value; + } + } + return true; +} + +void ResourceLabelManager::DisplayLabels() { + if (ImGui::Begin("Resource Labels")) { + for (const auto& type_pair : labels_) { + if (ImGui::TreeNode(type_pair.first.c_str())) { + for (const auto& label_pair : type_pair.second) { + std::string label_id = type_pair.first + "_" + label_pair.first; + ImGui::Text("%s: %s", label_pair.first.c_str(), + label_pair.second.c_str()); + } + ImGui::TreePop(); + } + } + } + ImGui::End(); +} + +void ResourceLabelManager::EditLabel(const std::string& type, + const std::string& key, + const std::string& newValue) { + labels_[type][key] = newValue; +} + +void ResourceLabelManager::SelectableLabelWithNameEdit( + bool selected, const std::string& type, const std::string& key, + const std::string& defaultValue) { + std::string label = CreateOrGetLabel(type, key, defaultValue); + ImGui::Selectable(label.c_str(), selected, + ImGuiSelectableFlags_AllowDoubleClick); + std::string label_id = type + "_" + key; + if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { + ImGui::OpenPopup(label_id.c_str()); + } + + if (ImGui::BeginPopupContextItem(label_id.c_str())) { + char* new_label = labels_[type][key].data(); + if (ImGui::InputText("##Label", new_label, labels_[type][key].size() + 1, + ImGuiInputTextFlags_EnterReturnsTrue)) { + labels_[type][key] = new_label; + } + ImGui::EndPopup(); + } + + // ImGui::PopID(); +} + +std::string ResourceLabelManager::CreateOrGetLabel( + const std::string& type, const std::string& key, + const std::string& defaultValue) { + if (labels_.find(type) == labels_.end()) { + labels_[type] = std::unordered_map(); + } + if (labels_[type].find(key) == labels_[type].end()) { + labels_[type][key] = defaultValue; + } + return labels_[type][key]; +} + +} // namespace core +} // namespace app +} // namespace yaze diff --git a/src/app/core/labeling.h b/src/app/core/labeling.h new file mode 100644 index 00000000..1eaabeaf --- /dev/null +++ b/src/app/core/labeling.h @@ -0,0 +1,52 @@ +#ifndef YAZE_APP_CORE_LABELING_H_ +#define YAZE_APP_CORE_LABELING_H_ + +#include +#include +#include +#include +#include +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "app/core/common.h" +#include "app/core/constants.h" + +namespace yaze { +namespace app { +namespace core { + +// Default types +static constexpr absl::string_view kDefaultTypes[] = { + "Dungeon Names", "Dungeon Room Names", "Overworld Map Names"}; + +class ResourceLabelManager { + public: + ResourceLabelManager() = default; + + bool LoadLabels(const std::string& filename); + void DisplayLabels(); + void EditLabel(const std::string& type, const std::string& key, + const std::string& newValue); + void SelectableLabelWithNameEdit(bool selected, const std::string& type, + const std::string& key, + const std::string& defaultValue); + std::string CreateOrGetLabel(const std::string& type, const std::string& key, + const std::string& defaultValue); + + private: + struct ResourceType { + std::string key_name; + std::string display_description; + }; + + std::unordered_map> + labels_; +}; + +} // namespace core +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_CORE_LABELING_H_ \ No newline at end of file diff --git a/src/app/editor/dungeon_editor.cc b/src/app/editor/dungeon_editor.cc index 4e1bc360..f43cd945 100644 --- a/src/app/editor/dungeon_editor.cc +++ b/src/app/editor/dungeon_editor.cc @@ -3,6 +3,7 @@ #include #include "app/core/common.h" +#include "app/core/labeling.h" #include "app/gfx/snes_palette.h" #include "app/gui/canvas.h" #include "app/gui/icons.h" @@ -279,8 +280,11 @@ void DungeonEditor::DrawRoomSelector() { ImGuiWindowFlags_AlwaysVerticalScrollbar)) { int i = 0; for (const auto each_room_name : zelda3::dungeon::kRoomNames) { - ImGui::Selectable(each_room_name.data(), current_room_id_ == i, - ImGuiSelectableFlags_AllowDoubleClick); + // ImGui::Selectable(each_room_name.data(), current_room_id_ == i, + // ImGuiSelectableFlags_AllowDoubleClick); + rom()->resource_label()->SelectableLabelWithNameEdit( + current_room_id_ == i, "Dungeon Room Names", each_room_name.data(), + zelda3::dungeon::kRoomNames[i].data()); if (ImGui::IsItemClicked()) { active_rooms_.push_back(i); } diff --git a/src/app/editor/dungeon_editor.h b/src/app/editor/dungeon_editor.h index d7712395..12c876c4 100644 --- a/src/app/editor/dungeon_editor.h +++ b/src/app/editor/dungeon_editor.h @@ -5,6 +5,7 @@ #include "app/core/common.h" #include "app/core/editor.h" +#include "app/core/labeling.h" #include "app/editor/modules/gfx_group_editor.h" #include "app/editor/modules/palette_editor.h" #include "app/gui/canvas.h" @@ -109,7 +110,6 @@ class DungeonEditor : public Editor, std::vector room_size_pointers_; - // Add member variables to track the selected set uint16_t selected_blockset_ = 0xFFFF; // 0xFFFF indicates no selection uint16_t selected_spriteset_ = 0xFFFF; uint16_t selected_palette_ = 0xFFFF; diff --git a/src/app/rom.h b/src/app/rom.h index 086b8a11..75faccae 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -31,7 +31,8 @@ #include "absl/strings/string_view.h" // for string_view #include "app/core/common.h" #include "app/core/constants.h" // for Bytes, uchar, armorPalettes -#include "app/gfx/bitmap.h" // for Bitmap, BitmapTable +#include "app/core/labeling.h" +#include "app/gfx/bitmap.h" // for Bitmap, BitmapTable #include "app/gfx/compression.h" #include "app/gfx/snes_palette.h" // for PaletteGroup, SNESColor #include "app/gfx/snes_tile.h" @@ -559,6 +560,8 @@ class ROM : public core::ExperimentFlags { return false; } + auto resource_label() { return &resource_label_manager_; } + private: long size_ = 0; bool is_loaded_ = false; @@ -575,6 +578,7 @@ class ROM : public core::ExperimentFlags { gfx::BitmapTable link_graphics_; gfx::SNESPalette link_palette_; PaletteGroupMap palette_groups_; + core::ResourceLabelManager resource_label_manager_; std::stack> changes_; std::shared_ptr renderer_; diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 15f43dfc..87a5f340 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -5,6 +5,7 @@ add_executable( cli/command_handler.cc app/rom.cc app/core/common.cc + app/core/labeling.cc app/gui/pipeline.cc ${YAZE_APP_EMU_SRC} ${YAZE_APP_GFX_SRC} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3664e35f..e4cceaa8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,6 +36,7 @@ add_executable( ../src/app/gfx/snes_palette.cc ../src/app/gfx/compression.cc ../src/app/core/common.cc + ../src/app/core/labeling.cc # ${ASAR_STATIC_SRC} )