From 30557fd528127e894dd9ea22b1ee6c43d38aa9c1 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 9 Jul 2022 18:41:30 -0400 Subject: [PATCH] Improve AssemblyEditor class --- src/app/editor/assembly_editor.cc | 61 +++++++++++++++++++++++++++++-- src/app/editor/assembly_editor.h | 2 + src/app/editor/editor.cc | 44 ++-------------------- src/app/editor/editor.h | 8 +--- 4 files changed, 64 insertions(+), 51 deletions(-) diff --git a/src/app/editor/assembly_editor.cc b/src/app/editor/assembly_editor.cc index f1dcb660..65499ab6 100644 --- a/src/app/editor/assembly_editor.cc +++ b/src/app/editor/assembly_editor.cc @@ -1,13 +1,20 @@ #include "assembly_editor.h" +#include "core/constants.h" + namespace yaze { namespace app { namespace editor { void AssemblyEditor::Update() { - SetEditorText(); auto cpos = text_editor_.GetCursorPosition(); - ImGui::Begin("ASM Editor", &file_is_loaded_); + ImGui::Begin("ASM Editor", &file_is_loaded_, ImGuiWindowFlags_MenuBar); + MENU_BAR() + DrawFileMenu(); + DrawEditMenu(); + END_MENU_BAR() + + SetEditorText(); ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1, cpos.mColumn + 1, text_editor_.GetTotalLines(), text_editor_.IsOverwrite() ? "Ovr" : "Ins", @@ -19,10 +26,56 @@ void AssemblyEditor::Update() { ImGui::End(); } -void AssemblyEditor::ChangeActiveFile(const std::string & filename) { +void AssemblyEditor::ChangeActiveFile(const std::string& filename) { current_file_ = filename; } +void AssemblyEditor::DrawFileMenu() { + if (ImGui::BeginMenu("File")) { + if (ImGui::MenuItem("Open", "Ctrl+O")) { + ImGuiFileDialog::Instance()->OpenDialog( + "ChooseASMFileDlg", "Open ASM file", ".asm,.txt", "."); + } + if (ImGui::MenuItem("Save", "Ctrl+S")) { + // TODO: Implement this + } + ImGui::EndMenu(); + } + + if (ImGuiFileDialog::Instance()->Display("ChooseASMFileDlg")) { + if (ImGuiFileDialog::Instance()->IsOk()) { + ChangeActiveFile(ImGuiFileDialog::Instance()->GetFilePathName()); + } + ImGuiFileDialog::Instance()->Close(); + } +} + +void AssemblyEditor::DrawEditMenu() { + if (ImGui::BeginMenu("Edit")) { + if (ImGui::MenuItem("Undo", "Ctrl+Z")) { + text_editor_.Undo(); + } + if (ImGui::MenuItem("Redo", "Ctrl+Y")) { + text_editor_.Redo(); + } + ImGui::Separator(); + if (ImGui::MenuItem("Cut", "Ctrl+X")) { + text_editor_.Cut(); + } + if (ImGui::MenuItem("Copy", "Ctrl+C")) { + text_editor_.Copy(); + } + if (ImGui::MenuItem("Paste", "Ctrl+V")) { + text_editor_.Paste(); + } + ImGui::Separator(); + if (ImGui::MenuItem("Find", "Ctrl+F")) { + // TODO: Implement this. + } + ImGui::EndMenu(); + } +} + void AssemblyEditor::SetEditorText() { if (!file_is_loaded_) { std::ifstream t(current_file_); @@ -30,8 +83,8 @@ void AssemblyEditor::SetEditorText() { std::string str((std::istreambuf_iterator(t)), std::istreambuf_iterator()); text_editor_.SetText(str); + file_is_loaded_ = true; } - file_is_loaded_ = true; } } diff --git a/src/app/editor/assembly_editor.h b/src/app/editor/assembly_editor.h index 0572b1bc..2a49c6b1 100644 --- a/src/app/editor/assembly_editor.h +++ b/src/app/editor/assembly_editor.h @@ -20,6 +20,8 @@ class AssemblyEditor { void ChangeActiveFile(const std::string &); private: + void DrawFileMenu(); + void DrawEditMenu(); void SetEditorText(); std::string current_file_; diff --git a/src/app/editor/editor.cc b/src/app/editor/editor.cc index b728e24e..3e4c5e3e 100644 --- a/src/app/editor/editor.cc +++ b/src/app/editor/editor.cc @@ -23,13 +23,6 @@ Editor::Editor() { asm_editor_.SetLanguageDefinition(gui::widgets::GetAssemblyLanguageDef()); asm_editor_.SetPalette(TextEditor::GetDarkPalette()); - current_set_.bits_per_pixel_ = 4; - current_set_.pc_tiles_location_ = 0x80000; - current_set_.SNESTilesLocation = 0x0000; - current_set_.length_ = 28672; - current_set_.pc_palette_location_ = 906022; - current_set_.SNESPaletteLocation = 0; - for (int i = 0; i < 8; i++) { current_palette_[i].x = (i * 0.21f); current_palette_[i].y = (i * 0.21f); @@ -68,10 +61,8 @@ void Editor::UpdateScreen() { DrawProjectEditor(); DrawOverworldEditor(); DrawDungeonEditor(); - DrawgfxEditor(); + DrawGraphicsEditor(); DrawSpriteEditor(); - DrawScreenEditor(); - DrawHUDEditor(); END_TAB_BAR() ImGui::End(); @@ -134,7 +125,7 @@ void Editor::DrawEditMenu() const { if (ImGui::MenuItem("Undo", "Ctrl+Z")) { // TODO: Implement this } - if (ImGui::MenuItem("Undo", "Ctrl+Y")) { + if (ImGui::MenuItem("Redo", "Ctrl+Y")) { // TODO: Implement this } ImGui::Separator(); @@ -176,7 +167,6 @@ void Editor::DrawViewMenu() { } if (show_asm_editor) { - assembly_editor_.ChangeActiveFile("assets/bunnyhood.asm"); assembly_editor_.Update(); } @@ -288,7 +278,6 @@ void Editor::DrawProjectEditor() { static ImVector points; static ImVec2 scrolling(0.0f, 0.0f); static bool opt_enable_context_menu = true; - static bool opt_enable_grid = true; ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); auto canvas_sz = ImVec2( 512 + 1, ImGui::GetContentRegionAvail().y + (tilesheet_offset * 256)); @@ -348,21 +337,6 @@ void Editor::DrawProjectEditor() { } } - // Draw the tile grid - if (opt_enable_grid) { - const float GRID_STEP = 32.0f; - for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x; - x += GRID_STEP) - draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y), - ImVec2(canvas_p0.x + x, canvas_p1.y), - IM_COL32(200, 200, 200, 40)); - for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y; - y += GRID_STEP) - draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y), - ImVec2(canvas_p1.x, canvas_p0.y + y), - IM_COL32(200, 200, 200, 40)); - } - draw_list->PopClipRect(); ImGui::EndTable(); @@ -423,7 +397,7 @@ void Editor::DrawDungeonEditor() { } } -void Editor::DrawgfxEditor() { +void Editor::DrawGraphicsEditor() { if (ImGui::BeginTabItem("Graphics")) { ImGui::EndTabItem(); } @@ -435,18 +409,6 @@ void Editor::DrawSpriteEditor() { } } -void Editor::DrawScreenEditor() { - if (ImGui::BeginTabItem("Screens")) { - ImGui::EndTabItem(); - } -} - -void Editor::DrawHUDEditor() { - if (ImGui::BeginTabItem("HUD")) { - ImGui::EndTabItem(); - } -} - } // namespace editor } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/editor/editor.h b/src/app/editor/editor.h index 4b69b902..f61b7f83 100644 --- a/src/app/editor/editor.h +++ b/src/app/editor/editor.h @@ -38,17 +38,13 @@ class Editor { void DrawProjectEditor(); void DrawOverworldEditor(); void DrawDungeonEditor(); - void DrawgfxEditor(); + void DrawGraphicsEditor(); void DrawSpriteEditor(); - void DrawScreenEditor(); - void DrawHUDEditor(); - + bool is_loaded_ = true; bool asm_is_loaded = false; rom::ROM rom_; - gfx::TilePreset current_set_; - TextEditor asm_editor_; AssemblyEditor assembly_editor_; OverworldEditor overworld_editor_;