Added the AssemblyEditor class
This commit is contained in:
@@ -40,6 +40,7 @@ add_executable(
|
|||||||
gui/style.cc
|
gui/style.cc
|
||||||
gui/widgets.cc
|
gui/widgets.cc
|
||||||
app/editor/editor.cc
|
app/editor/editor.cc
|
||||||
|
app/editor/assembly_editor.cc
|
||||||
app/editor/overworld_editor.cc
|
app/editor/overworld_editor.cc
|
||||||
app/rom.cc
|
app/rom.cc
|
||||||
app/core/common.cc
|
app/core/common.cc
|
||||||
|
|||||||
40
src/app/editor/assembly_editor.cc
Normal file
40
src/app/editor/assembly_editor.cc
Normal file
@@ -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<char>(t)),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
|
text_editor_.SetText(str);
|
||||||
|
}
|
||||||
|
file_is_loaded_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace editor
|
||||||
|
} // namespace app
|
||||||
|
} // namespace yaze
|
||||||
34
src/app/editor/assembly_editor.h
Normal file
34
src/app/editor/assembly_editor.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef YAZE_APP_EDITOR_ASSEMBLY_EDITOR_H
|
||||||
|
#define YAZE_APP_EDITOR_ASSEMBLY_EDITOR_H
|
||||||
|
|
||||||
|
#include <ImGuiColorTextEdit/TextEditor.h>
|
||||||
|
#include <ImGuiFileDialog/ImGuiFileDialog.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <istream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -176,28 +176,8 @@ void Editor::DrawViewMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (show_asm_editor) {
|
if (show_asm_editor) {
|
||||||
static bool asm_is_loaded = false;
|
assembly_editor_.ChangeActiveFile("assets/bunnyhood.asm");
|
||||||
auto cpos = asm_editor_.GetCursorPosition();
|
assembly_editor_.Update();
|
||||||
static const char *fileToEdit = "assets/bunnyhood.asm";
|
|
||||||
if (!asm_is_loaded) {
|
|
||||||
std::ifstream t(fileToEdit);
|
|
||||||
if (t.good()) {
|
|
||||||
std::string str((std::istreambuf_iterator<char>(t)),
|
|
||||||
std::istreambuf_iterator<char>());
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_imgui_style_editor) {
|
if (show_imgui_style_editor) {
|
||||||
@@ -248,8 +228,8 @@ void Editor::DrawGraphicsSheet(int offset) {
|
|||||||
unsigned int snes_addr = 0;
|
unsigned int snes_addr = 0;
|
||||||
unsigned int pc_addr = 0;
|
unsigned int pc_addr = 0;
|
||||||
snes_addr = (unsigned int)((((rom_.data()[0x4F80 + offset]) << 16) |
|
snes_addr = (unsigned int)((((rom_.data()[0x4F80 + offset]) << 16) |
|
||||||
((rom_.data()[0x505F + offset]) << 8) |
|
((rom_.data()[0x505F + offset]) << 8) |
|
||||||
((rom_.data()[0x513E + offset]))));
|
((rom_.data()[0x513E + offset]))));
|
||||||
pc_addr = core::SnesToPc(snes_addr);
|
pc_addr = core::SnesToPc(snes_addr);
|
||||||
std::cout << "Decompressing..." << std::endl;
|
std::cout << "Decompressing..." << std::endl;
|
||||||
char *decomp = rom_.Decompress(pc_addr);
|
char *decomp = rom_.Decompress(pc_addr);
|
||||||
@@ -325,7 +305,7 @@ void Editor::DrawProjectEditor() {
|
|||||||
ImGui::InvisibleButton(
|
ImGui::InvisibleButton(
|
||||||
"canvas", canvas_sz,
|
"canvas", canvas_sz,
|
||||||
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
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,
|
const ImVec2 origin(canvas_p0.x + scrolling.x,
|
||||||
canvas_p0.y + scrolling.y); // Lock scrolled origin
|
canvas_p0.y + scrolling.y); // Lock scrolled origin
|
||||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "app/core/constants.h"
|
#include "app/core/constants.h"
|
||||||
#include "app/editor/overworld_editor.h"
|
#include "app/editor/overworld_editor.h"
|
||||||
#include "app/gfx/tile.h"
|
#include "app/gfx/tile.h"
|
||||||
|
#include "app/editor/assembly_editor.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "gui/icons.h"
|
#include "gui/icons.h"
|
||||||
#include "gui/input.h"
|
#include "gui/input.h"
|
||||||
@@ -43,12 +44,13 @@ class Editor {
|
|||||||
void DrawHUDEditor();
|
void DrawHUDEditor();
|
||||||
|
|
||||||
bool is_loaded_ = true;
|
bool is_loaded_ = true;
|
||||||
|
bool asm_is_loaded = false;
|
||||||
|
|
||||||
app::rom::ROM rom_;
|
rom::ROM rom_;
|
||||||
app::gfx::TilePreset current_set_;
|
gfx::TilePreset current_set_;
|
||||||
|
|
||||||
TextEditor asm_editor_;
|
TextEditor asm_editor_;
|
||||||
TextEditor::LanguageDefinition language_65816_;
|
AssemblyEditor assembly_editor_;
|
||||||
OverworldEditor overworld_editor_;
|
OverworldEditor overworld_editor_;
|
||||||
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
||||||
std::unordered_map<uint, SDL_Texture *> image_cache_;
|
std::unordered_map<uint, SDL_Texture *> image_cache_;
|
||||||
|
|||||||
Reference in New Issue
Block a user