refactor editor template
This commit is contained in:
@@ -87,7 +87,7 @@ Editor::Editor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Editor::~Editor() {
|
Editor::~Editor() {
|
||||||
for (auto &each : imagesCache) {
|
for (auto &each : image_cache_) {
|
||||||
SDL_DestroyTexture(each.second);
|
SDL_DestroyTexture(each.second);
|
||||||
}
|
}
|
||||||
rom_.Close();
|
rom_.Close();
|
||||||
@@ -125,9 +125,7 @@ void Editor::UpdateScreen() {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::Shutdown() {
|
void Editor::Shutdown() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Editor::DrawYazeMenu() {
|
void Editor::DrawYazeMenu() {
|
||||||
MENU_BAR()
|
MENU_BAR()
|
||||||
@@ -142,7 +140,7 @@ void Editor::DrawYazeMenu() {
|
|||||||
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||||
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||||
rom_.LoadFromFile(filePathName);
|
rom_.LoadFromFile(filePathName);
|
||||||
rom_data_ = (void *)rom_.GetRawData();
|
rom_data_ = (void *)rom_.data();
|
||||||
overworld_editor_.SetupROM(rom_);
|
overworld_editor_.SetupROM(rom_);
|
||||||
}
|
}
|
||||||
ImGuiFileDialog::Instance()->Close();
|
ImGuiFileDialog::Instance()->Close();
|
||||||
@@ -299,10 +297,9 @@ void Editor::DrawGraphicsSheet(int offset) {
|
|||||||
|
|
||||||
unsigned int snesAddr = 0;
|
unsigned int snesAddr = 0;
|
||||||
unsigned int pcAddr = 0;
|
unsigned int pcAddr = 0;
|
||||||
snesAddr =
|
snesAddr = (unsigned int)((((uchar)(rom_.data()[0x4F80 + offset]) << 16) |
|
||||||
(unsigned int)((((uchar)(rom_.GetRawData()[0x4F80 + offset]) << 16) |
|
((uchar)(rom_.data()[0x505F + offset]) << 8) |
|
||||||
((uchar)(rom_.GetRawData()[0x505F + offset]) << 8) |
|
((uchar)(rom_.data()[0x513E + offset]))));
|
||||||
((uchar)(rom_.GetRawData()[0x513E + offset]))));
|
|
||||||
pcAddr = rom_.SnesToPc(snesAddr);
|
pcAddr = rom_.SnesToPc(snesAddr);
|
||||||
std::cout << "Decompressing..." << std::endl;
|
std::cout << "Decompressing..." << std::endl;
|
||||||
char *decomp = rom_.Decompress(pcAddr);
|
char *decomp = rom_.Decompress(pcAddr);
|
||||||
@@ -313,7 +310,7 @@ void Editor::DrawGraphicsSheet(int offset) {
|
|||||||
std::cout << "Creating texture from surface..." << std::endl;
|
std::cout << "Creating texture from surface..." << std::endl;
|
||||||
SDL_Texture *sheet_texture = nullptr;
|
SDL_Texture *sheet_texture = nullptr;
|
||||||
sheet_texture = SDL_CreateTextureFromSurface(sdl_renderer_.get(), surface);
|
sheet_texture = SDL_CreateTextureFromSurface(sdl_renderer_.get(), surface);
|
||||||
imagesCache[offset] = sheet_texture;
|
image_cache_[offset] = sheet_texture;
|
||||||
if (sheet_texture == nullptr) {
|
if (sheet_texture == nullptr) {
|
||||||
std::cout << "Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -412,13 +409,13 @@ void Editor::DrawProjectEditor() {
|
|||||||
|
|
||||||
// Draw the tilesheets loaded from the ROM
|
// Draw the tilesheets loaded from the ROM
|
||||||
if (loaded_image) {
|
if (loaded_image) {
|
||||||
for (const auto &[key, value] : imagesCache) {
|
for (const auto &[key, value] : image_cache_) {
|
||||||
int offset = 128 * (key + 1);
|
int offset = 128 * (key + 1);
|
||||||
int top_left_y = canvas_p0.y + 2;
|
int top_left_y = canvas_p0.y + 2;
|
||||||
if (key >= 1) {
|
if (key >= 1) {
|
||||||
top_left_y = canvas_p0.y + 128 * key;
|
top_left_y = canvas_p0.y + 128 * key;
|
||||||
}
|
}
|
||||||
draw_list->AddImage((void *)(SDL_Texture *)value,
|
draw_list->AddImage((void *)value,
|
||||||
ImVec2(canvas_p0.x + 2, top_left_y),
|
ImVec2(canvas_p0.x + 2, top_left_y),
|
||||||
ImVec2(canvas_p0.x + 512, canvas_p0.y + offset));
|
ImVec2(canvas_p0.x + 512, canvas_p0.y + offset));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Editor {
|
|||||||
TextEditor asm_editor_;
|
TextEditor asm_editor_;
|
||||||
TextEditor::LanguageDefinition language_65816_;
|
TextEditor::LanguageDefinition language_65816_;
|
||||||
OverworldEditor overworld_editor_;
|
OverworldEditor overworld_editor_;
|
||||||
std::unordered_map<uint, SDL_Texture *> imagesCache;
|
std::unordered_map<uint, SDL_Texture *> image_cache_;
|
||||||
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
||||||
|
|
||||||
ImVec4 current_palette_[8];
|
ImVec4 current_palette_[8];
|
||||||
|
|||||||
@@ -35,11 +35,9 @@ namespace editor {
|
|||||||
void OverworldEditor::SetupROM(app::rom::ROM &rom) { rom_ = rom; }
|
void OverworldEditor::SetupROM(app::rom::ROM &rom) { rom_ = rom; }
|
||||||
|
|
||||||
void OverworldEditor::Update() {
|
void OverworldEditor::Update() {
|
||||||
if (rom_.isLoaded()) {
|
if (rom_.isLoaded() && !all_gfx_loaded_) {
|
||||||
if (!all_gfx_loaded_) {
|
LoadGraphics();
|
||||||
LoadGraphics();
|
all_gfx_loaded_ = true;
|
||||||
all_gfx_loaded_ = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_changelist_) {
|
if (show_changelist_) {
|
||||||
@@ -142,8 +140,7 @@ void OverworldEditor::DrawToolset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OverworldEditor::DrawOverworldMapSettings() {
|
void OverworldEditor::DrawOverworldMapSettings() {
|
||||||
if (ImGui::BeginTable("#mapSettings", 7, ow_map_settings_flags, ImVec2(0, 0),
|
if (ImGui::BeginTable("#mapSettings", 7, ow_map_flags, ImVec2(0, 0), -1)) {
|
||||||
-1)) {
|
|
||||||
ImGui::TableSetupColumn("##1stCol");
|
ImGui::TableSetupColumn("##1stCol");
|
||||||
ImGui::TableSetupColumn("##gfxCol");
|
ImGui::TableSetupColumn("##gfxCol");
|
||||||
ImGui::TableSetupColumn("##palCol");
|
ImGui::TableSetupColumn("##palCol");
|
||||||
@@ -202,8 +199,7 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
static bool adding_line = false;
|
static bool adding_line = false;
|
||||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
||||||
ImVec2 canvas_sz = ImGui::GetContentRegionAvail();
|
ImVec2 canvas_sz = ImGui::GetContentRegionAvail();
|
||||||
ImVec2 canvas_p1 =
|
auto canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
|
||||||
|
|
||||||
// Draw border and background color
|
// Draw border and background color
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
@@ -249,10 +245,10 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
if (ImGui::BeginPopup("context")) {
|
if (ImGui::BeginPopup("context")) {
|
||||||
if (adding_line) points.resize(points.size() - 2);
|
if (adding_line) points.resize(points.size() - 2);
|
||||||
adding_line = false;
|
adding_line = false;
|
||||||
if (ImGui::MenuItem("Remove one", NULL, false, points.Size > 0)) {
|
if (ImGui::MenuItem("Remove one", nullptr, false, points.Size > 0)) {
|
||||||
points.resize(points.size() - 2);
|
points.resize(points.size() - 2);
|
||||||
}
|
}
|
||||||
if (ImGui::MenuItem("Remove all", NULL, false, points.Size > 0)) {
|
if (ImGui::MenuItem("Remove all", nullptr, false, points.Size > 0)) {
|
||||||
points.clear();
|
points.clear();
|
||||||
}
|
}
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
@@ -286,7 +282,6 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
void OverworldEditor::DrawTileSelector() {
|
void OverworldEditor::DrawTileSelector() {
|
||||||
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
|
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
|
||||||
if (ImGui::BeginTabItem("Tile16")) {
|
if (ImGui::BeginTabItem("Tile16")) {
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
|
||||||
bool child_is_visible =
|
bool child_is_visible =
|
||||||
ImGui::BeginChild("#Tile16Child", ImGui::GetContentRegionAvail(),
|
ImGui::BeginChild("#Tile16Child", ImGui::GetContentRegionAvail(),
|
||||||
true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||||
@@ -296,7 +291,6 @@ void OverworldEditor::DrawTileSelector() {
|
|||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
}
|
}
|
||||||
if (ImGui::BeginTabItem("Tile8")) {
|
if (ImGui::BeginTabItem("Tile8")) {
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
|
||||||
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
|
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
|
||||||
bool child_is_visible =
|
bool child_is_visible =
|
||||||
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||||
@@ -304,9 +298,6 @@ void OverworldEditor::DrawTileSelector() {
|
|||||||
if (child_is_visible) {
|
if (child_is_visible) {
|
||||||
DrawTile8Selector();
|
DrawTile8Selector();
|
||||||
}
|
}
|
||||||
float scroll_x = ImGui::GetScrollX();
|
|
||||||
float scroll_max_x = ImGui::GetScrollMaxX();
|
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
}
|
}
|
||||||
@@ -318,9 +309,8 @@ void OverworldEditor::DrawTileSelector() {
|
|||||||
void OverworldEditor::DrawTile16Selector() {
|
void OverworldEditor::DrawTile16Selector() {
|
||||||
static ImVec2 scrolling(0.0f, 0.0f);
|
static ImVec2 scrolling(0.0f, 0.0f);
|
||||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
||||||
ImVec2 canvas_sz = ImVec2(256 + 1, kNumSheetsToLoad * 64 + 1);
|
auto canvas_sz = ImVec2(256 + 1, kNumSheetsToLoad * 64 + 1);
|
||||||
ImVec2 canvas_p1 =
|
auto canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
|
||||||
|
|
||||||
// Draw border and background color
|
// Draw border and background color
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
@@ -332,8 +322,6 @@ void OverworldEditor::DrawTile16Selector() {
|
|||||||
ImGui::InvisibleButton(
|
ImGui::InvisibleButton(
|
||||||
"Tile16SelectorCanvas", canvas_sz,
|
"Tile16SelectorCanvas", canvas_sz,
|
||||||
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
||||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
|
||||||
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,
|
||||||
@@ -350,7 +338,7 @@ void OverworldEditor::DrawTile16Selector() {
|
|||||||
|
|
||||||
if (map_blockset_loaded_) {
|
if (map_blockset_loaded_) {
|
||||||
draw_list->AddImage(
|
draw_list->AddImage(
|
||||||
(void *)(SDL_Texture *)mapblockset16Bitmap.GetTexture(),
|
(void *)mapblockset16Bitmap.GetTexture(),
|
||||||
ImVec2(canvas_p0.x + 2, canvas_p0.y + 2),
|
ImVec2(canvas_p0.x + 2, canvas_p0.y + 2),
|
||||||
ImVec2(canvas_p0.x + (mapblockset16Bitmap.GetWidth() * 2),
|
ImVec2(canvas_p0.x + (mapblockset16Bitmap.GetWidth() * 2),
|
||||||
canvas_p0.y + (mapblockset16Bitmap.GetHeight() * 2)));
|
canvas_p0.y + (mapblockset16Bitmap.GetHeight() * 2)));
|
||||||
@@ -378,9 +366,8 @@ void OverworldEditor::DrawTile16Selector() {
|
|||||||
void OverworldEditor::DrawTile8Selector() {
|
void OverworldEditor::DrawTile8Selector() {
|
||||||
static ImVec2 scrolling(0.0f, 0.0f);
|
static ImVec2 scrolling(0.0f, 0.0f);
|
||||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
||||||
ImVec2 canvas_sz = ImVec2(256 + 1, kNumSheetsToLoad * 64 + 1);
|
auto canvas_sz = ImVec2(256 + 1, kNumSheetsToLoad * 64 + 1);
|
||||||
ImVec2 canvas_p1 =
|
auto canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
|
||||||
|
|
||||||
// Draw border and background color
|
// Draw border and background color
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
@@ -392,8 +379,6 @@ void OverworldEditor::DrawTile8Selector() {
|
|||||||
ImGui::InvisibleButton(
|
ImGui::InvisibleButton(
|
||||||
"Tile8SelectorCanvas", canvas_sz,
|
"Tile8SelectorCanvas", canvas_sz,
|
||||||
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
||||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
|
||||||
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,
|
||||||
@@ -414,7 +399,7 @@ void OverworldEditor::DrawTile8Selector() {
|
|||||||
if (key >= 1) {
|
if (key >= 1) {
|
||||||
top_left_y = canvas_p0.y + 64 * key;
|
top_left_y = canvas_p0.y + 64 * key;
|
||||||
}
|
}
|
||||||
draw_list->AddImage((void *)(SDL_Texture *)value,
|
draw_list->AddImage((void *)value,
|
||||||
ImVec2(canvas_p0.x + 2, top_left_y),
|
ImVec2(canvas_p0.x + 2, top_left_y),
|
||||||
ImVec2(canvas_p0.x + 256, canvas_p0.y + offset));
|
ImVec2(canvas_p0.x + 256, canvas_p0.y + offset));
|
||||||
}
|
}
|
||||||
@@ -481,9 +466,6 @@ void OverworldEditor::LoadBlockset() {
|
|||||||
tile16_blockset_bmp_.Create(128, 8192, 8, tile16_blockset_ptr_);
|
tile16_blockset_bmp_.Create(128, 8192, 8, tile16_blockset_ptr_);
|
||||||
tile16_blockset_bmp_.CreateTexture(rom_.Renderer());
|
tile16_blockset_bmp_.CreateTexture(rom_.Renderer());
|
||||||
map_blockset_loaded_ = true;
|
map_blockset_loaded_ = true;
|
||||||
|
|
||||||
// mapblockset16Bitmap.Create(128, 8192, 8, overworld_.GetMapBlockset16Ptr());
|
|
||||||
// mapblockset16Bitmap.CreateTexture(rom_.Renderer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverworldEditor::LoadGraphics() {
|
void OverworldEditor::LoadGraphics() {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class OverworldEditor {
|
|||||||
constexpr static float kInputFieldSize = 30.f;
|
constexpr static float kInputFieldSize = 30.f;
|
||||||
|
|
||||||
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
||||||
ImGuiTableFlags ow_map_settings_flags = ImGuiTableFlags_Borders;
|
ImGuiTableFlags ow_map_flags = ImGuiTableFlags_Borders;
|
||||||
ImGuiTableFlags ow_edit_flags = ImGuiTableFlags_Reorderable |
|
ImGuiTableFlags ow_edit_flags = ImGuiTableFlags_Reorderable |
|
||||||
ImGuiTableFlags_Resizable |
|
ImGuiTableFlags_Resizable |
|
||||||
ImGuiTableFlags_SizingStretchSame;
|
ImGuiTableFlags_SizingStretchSame;
|
||||||
|
|||||||
Reference in New Issue
Block a user