diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 92a86d97..7f56e966 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ add_executable( gui/style.cc gui/widgets.cc app/editor/editor.cc + app/editor/assembly_editor.cc app/editor/overworld_editor.cc app/rom.cc app/core/common.cc diff --git a/src/app/editor/assembly_editor.cc b/src/app/editor/assembly_editor.cc new file mode 100644 index 00000000..f1dcb660 --- /dev/null +++ b/src/app/editor/assembly_editor.cc @@ -0,0 +1,40 @@ +#include "assembly_editor.h" + +namespace yaze { +namespace app { +namespace editor { + +void AssemblyEditor::Update() { + SetEditorText(); + auto cpos = text_editor_.GetCursorPosition(); + ImGui::Begin("ASM Editor", &file_is_loaded_); + ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1, + cpos.mColumn + 1, text_editor_.GetTotalLines(), + text_editor_.IsOverwrite() ? "Ovr" : "Ins", + text_editor_.CanUndo() ? "*" : " ", + text_editor_.GetLanguageDefinition().mName.c_str(), + current_file_.c_str()); + + text_editor_.Render(current_file_.c_str()); + ImGui::End(); +} + +void AssemblyEditor::ChangeActiveFile(const std::string & filename) { + current_file_ = filename; +} + +void AssemblyEditor::SetEditorText() { + if (!file_is_loaded_) { + std::ifstream t(current_file_); + if (t.good()) { + std::string str((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + text_editor_.SetText(str); + } + file_is_loaded_ = true; + } +} + +} // namespace editor +} // namespace app +} // namespace yaze \ No newline at end of file diff --git a/src/app/editor/assembly_editor.h b/src/app/editor/assembly_editor.h new file mode 100644 index 00000000..0572b1bc --- /dev/null +++ b/src/app/editor/assembly_editor.h @@ -0,0 +1,34 @@ +#ifndef YAZE_APP_EDITOR_ASSEMBLY_EDITOR_H +#define YAZE_APP_EDITOR_ASSEMBLY_EDITOR_H + +#include +#include + +#include +#include +#include + +namespace yaze { +namespace app { +namespace editor { + +class AssemblyEditor { + public: + AssemblyEditor() = default; + + void Update(); + void ChangeActiveFile(const std::string &); + + private: + void SetEditorText(); + + std::string current_file_; + bool file_is_loaded_ = false; + TextEditor text_editor_; +}; + +} // namespace editor +} // namespace app +} // namespace yaze + +#endif \ No newline at end of file diff --git a/src/app/editor/editor.cc b/src/app/editor/editor.cc index f1480863..b728e24e 100644 --- a/src/app/editor/editor.cc +++ b/src/app/editor/editor.cc @@ -176,28 +176,8 @@ void Editor::DrawViewMenu() { } if (show_asm_editor) { - static bool asm_is_loaded = false; - auto cpos = asm_editor_.GetCursorPosition(); - static const char *fileToEdit = "assets/bunnyhood.asm"; - if (!asm_is_loaded) { - std::ifstream t(fileToEdit); - if (t.good()) { - std::string str((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - asm_editor_.SetText(str); - } - asm_is_loaded = true; - } - - ImGui::Begin("ASM Editor", &show_asm_editor); - ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1, - cpos.mColumn + 1, asm_editor_.GetTotalLines(), - asm_editor_.IsOverwrite() ? "Ovr" : "Ins", - asm_editor_.CanUndo() ? "*" : " ", - asm_editor_.GetLanguageDefinition().mName.c_str(), fileToEdit); - - asm_editor_.Render(fileToEdit); - ImGui::End(); + assembly_editor_.ChangeActiveFile("assets/bunnyhood.asm"); + assembly_editor_.Update(); } if (show_imgui_style_editor) { @@ -248,8 +228,8 @@ void Editor::DrawGraphicsSheet(int offset) { unsigned int snes_addr = 0; unsigned int pc_addr = 0; snes_addr = (unsigned int)((((rom_.data()[0x4F80 + offset]) << 16) | - ((rom_.data()[0x505F + offset]) << 8) | - ((rom_.data()[0x513E + offset])))); + ((rom_.data()[0x505F + offset]) << 8) | + ((rom_.data()[0x513E + offset])))); pc_addr = core::SnesToPc(snes_addr); std::cout << "Decompressing..." << std::endl; char *decomp = rom_.Decompress(pc_addr); @@ -325,7 +305,7 @@ void Editor::DrawProjectEditor() { ImGui::InvisibleButton( "canvas", canvas_sz, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); - const bool is_active = ImGui::IsItemActive(); // Held + const bool is_active = ImGui::IsItemActive(); // Held const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); // Lock scrolled origin const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x, diff --git a/src/app/editor/editor.h b/src/app/editor/editor.h index cb4c0aaa..4b69b902 100644 --- a/src/app/editor/editor.h +++ b/src/app/editor/editor.h @@ -10,6 +10,7 @@ #include "app/core/constants.h" #include "app/editor/overworld_editor.h" #include "app/gfx/tile.h" +#include "app/editor/assembly_editor.h" #include "app/rom.h" #include "gui/icons.h" #include "gui/input.h" @@ -43,12 +44,13 @@ class Editor { void DrawHUDEditor(); bool is_loaded_ = true; + bool asm_is_loaded = false; - app::rom::ROM rom_; - app::gfx::TilePreset current_set_; + rom::ROM rom_; + gfx::TilePreset current_set_; TextEditor asm_editor_; - TextEditor::LanguageDefinition language_65816_; + AssemblyEditor assembly_editor_; OverworldEditor overworld_editor_; std::shared_ptr sdl_renderer_; std::unordered_map image_cache_;