namespace housekeeping
This commit is contained in:
525
src/gui/editor/editor.cc
Normal file
525
src/gui/editor/editor.cc
Normal file
@@ -0,0 +1,525 @@
|
||||
#include "editor.h"
|
||||
|
||||
#include <ImGuiColorTextEdit/TextEditor.h>
|
||||
#include <ImGuiFileDialog/ImGuiFileDialog.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_memory_editor.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include "core/constants.h"
|
||||
#include "gfx/palette.h"
|
||||
#include "gfx/tile.h"
|
||||
#include "gui/editor/overworld_editor.h"
|
||||
#include "gui/icons.h"
|
||||
#include "gui/input.h"
|
||||
#include "rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Editor {
|
||||
|
||||
using namespace core;
|
||||
|
||||
Editor::Editor() {
|
||||
for (auto &k : core::Constants::kKeywords)
|
||||
language_65816_.mKeywords.emplace(k);
|
||||
|
||||
for (auto &k : core::Constants::kIdentifiers) {
|
||||
TextEditor::Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
language_65816_.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[ \\t]*#[ \\t]*[a-zA-Z_]+", TextEditor::PaletteIndex::Preprocessor));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"L?\\\"(\\\\.|[^\\\"])*\\\"", TextEditor::PaletteIndex::String));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"\\'\\\\?[^\\']\\'", TextEditor::PaletteIndex::CharLiteral));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",
|
||||
TextEditor::PaletteIndex::Number));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[+-]?[0-9]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"0[0-7]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?",
|
||||
TextEditor::PaletteIndex::Number));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[a-zA-Z_][a-zA-Z0-9_]*", TextEditor::PaletteIndex::Identifier));
|
||||
language_65816_.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[\\[\\]\\{\\}\\!\\%\\^\\&\\*\\(\\)\\-\\+\\=\\~\\|\\<\\>\\?\\/"
|
||||
"\\;\\,\\.]",
|
||||
TextEditor::PaletteIndex::Punctuation));
|
||||
|
||||
language_65816_.mCommentStart = "/*";
|
||||
language_65816_.mCommentEnd = "*/";
|
||||
language_65816_.mSingleLineComment = ";";
|
||||
|
||||
language_65816_.mCaseSensitive = false;
|
||||
language_65816_.mAutoIndentation = true;
|
||||
|
||||
language_65816_.mName = "65816";
|
||||
asm_editor_.SetLanguageDefinition(language_65816_);
|
||||
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);
|
||||
current_palette_[i].z = (i * 0.21f);
|
||||
current_palette_[i].w = 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
Editor::~Editor() {
|
||||
for (auto &each : imagesCache) {
|
||||
SDL_DestroyTexture(each.second);
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
|
||||
sdl_renderer_ = renderer;
|
||||
rom_.SetupRenderer(renderer);
|
||||
}
|
||||
|
||||
void Editor::UpdateScreen() {
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
ImGui::NewFrame();
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y);
|
||||
ImGui::SetNextWindowSize(dimensions, ImGuiCond_Always);
|
||||
|
||||
if (!ImGui::Begin("##YazeMain", nullptr, main_editor_flags_)) {
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
DrawYazeMenu();
|
||||
|
||||
TAB_BAR("##TabBar")
|
||||
DrawProjectEditor();
|
||||
DrawOverworldEditor();
|
||||
DrawDungeonEditor();
|
||||
DrawgfxEditor();
|
||||
DrawSpriteEditor();
|
||||
DrawScreenEditor();
|
||||
DrawHUDEditor();
|
||||
END_TAB_BAR()
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void Editor::DrawYazeMenu() {
|
||||
MENU_BAR()
|
||||
DrawFileMenu();
|
||||
DrawEditMenu();
|
||||
DrawViewMenu();
|
||||
DrawHelpMenu();
|
||||
END_MENU_BAR()
|
||||
|
||||
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) {
|
||||
if (ImGuiFileDialog::Instance()->IsOk()) {
|
||||
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||
rom_.LoadFromFile(filePathName);
|
||||
rom_data_ = (void *)rom_.GetRawData();
|
||||
overworld_editor_.SetupROM(rom_);
|
||||
}
|
||||
ImGuiFileDialog::Instance()->Close();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawFileMenu() const {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Open", "Ctrl+O")) {
|
||||
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM",
|
||||
".sfc,.smc", ".");
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
if (ImGui::MenuItem("Save As..")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
// TODO: Make these options matter
|
||||
if (ImGui::BeginMenu("Options")) {
|
||||
static bool enabled = true;
|
||||
ImGui::MenuItem("Enabled", "", &enabled);
|
||||
ImGui::BeginChild("child", ImVec2(0, 60), true);
|
||||
for (int i = 0; i < 10; i++) ImGui::Text("Scrolling Text %d", i);
|
||||
ImGui::EndChild();
|
||||
static float f = 0.5f;
|
||||
static int n = 0;
|
||||
ImGui::SliderFloat("Value", &f, 0.0f, 1.0f);
|
||||
ImGui::InputFloat("Input", &f, 0.1f);
|
||||
ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0");
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawEditMenu() const {
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
if (ImGui::MenuItem("Undo", "Ctrl+Z")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
if (ImGui::MenuItem("Undo", "Ctrl+Y")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Cut", "Ctrl+X")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
if (ImGui::MenuItem("Copy", "Ctrl+C")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
if (ImGui::MenuItem("Paste", "Ctrl+V")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Find", "Ctrl+F")) {
|
||||
// TODO: Implement this
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawViewMenu() {
|
||||
static bool show_imgui_metrics = false;
|
||||
static bool show_imgui_style_editor = false;
|
||||
static bool show_memory_editor = false;
|
||||
static bool show_asm_editor = false;
|
||||
static bool show_imgui_demo = false;
|
||||
|
||||
if (show_imgui_metrics) {
|
||||
ImGui::ShowMetricsWindow(&show_imgui_metrics);
|
||||
}
|
||||
|
||||
if (show_memory_editor) {
|
||||
static MemoryEditor mem_edit;
|
||||
mem_edit.DrawWindow("Memory Editor", rom_data_, rom_.getSize());
|
||||
}
|
||||
|
||||
if (show_imgui_demo) {
|
||||
ImGui::ShowDemoWindow();
|
||||
}
|
||||
|
||||
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<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) {
|
||||
ImGui::Begin("Style Editor (ImGui)", &show_imgui_style_editor);
|
||||
ImGui::ShowStyleEditor();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("View")) {
|
||||
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
|
||||
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor);
|
||||
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
|
||||
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginMenu("GUI Tools")) {
|
||||
ImGui::MenuItem("Metrics (ImGui)", nullptr, &show_imgui_metrics);
|
||||
ImGui::MenuItem("Style Editor (ImGui)", nullptr,
|
||||
&show_imgui_style_editor);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawHelpMenu() const {
|
||||
if (ImGui::BeginMenu("Help")) {
|
||||
if (ImGui::MenuItem("About")) {
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawgfxSheet(int offset) {
|
||||
SDL_Surface *surface =
|
||||
SDL_CreateRGBSurfaceWithFormat(0, 128, 32, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
std::cout << "Drawing surface" << std::endl;
|
||||
uchar *sheet_buffer = nullptr;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
std::cout << "Red value: " << current_palette_[i].x << std::endl;
|
||||
std::cout << "Green value: " << current_palette_[i].y << std::endl;
|
||||
std::cout << "Blue value: " << current_palette_[i].z << std::endl;
|
||||
surface->format->palette->colors[i].r = current_palette_[i].x * 255;
|
||||
surface->format->palette->colors[i].g = current_palette_[i].y * 255;
|
||||
surface->format->palette->colors[i].b = current_palette_[i].z * 255;
|
||||
}
|
||||
|
||||
unsigned int snesAddr = 0;
|
||||
unsigned int pcAddr = 0;
|
||||
snesAddr =
|
||||
(unsigned int)((((uchar)(rom_.GetRawData()[0x4F80 + offset]) << 16) |
|
||||
((uchar)(rom_.GetRawData()[0x505F + offset]) << 8) |
|
||||
((uchar)(rom_.GetRawData()[0x513E + offset]))));
|
||||
pcAddr = rom_.SnesToPc(snesAddr);
|
||||
std::cout << "Decompressing..." << std::endl;
|
||||
char *decomp = rom_.Decompress(pcAddr);
|
||||
std::cout << "Converting to 8bpp sheet..." << std::endl;
|
||||
sheet_buffer = rom_.SNES3bppTo8bppSheet((uchar *)decomp);
|
||||
std::cout << "Assigning pixel data..." << std::endl;
|
||||
surface->pixels = sheet_buffer;
|
||||
std::cout << "Creating texture from surface..." << std::endl;
|
||||
SDL_Texture *sheet_texture = nullptr;
|
||||
sheet_texture = SDL_CreateTextureFromSurface(sdl_renderer_.get(), surface);
|
||||
imagesCache[offset] = sheet_texture;
|
||||
if (sheet_texture == nullptr) {
|
||||
std::cout << "Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawProjectEditor() {
|
||||
if (ImGui::BeginTabItem("Project")) {
|
||||
if (ImGui::BeginTable(
|
||||
"##projectTable", 2,
|
||||
ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable)) {
|
||||
ImGui::TableSetupColumn("##inputs", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("##outputs");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Title: %s", rom_.getTitle());
|
||||
ImGui::Text("Version: %d", rom_.getVersion());
|
||||
ImGui::Text("ROM Size: %ld", rom_.getSize());
|
||||
ImGui::Separator();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
static bool loaded_image = false;
|
||||
static int tilesheet_offset = 0;
|
||||
ImGui::Text("Palette:");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
std::string id = "##PaletteColor" + std::to_string(i);
|
||||
ImGui::SameLine();
|
||||
ImGui::ColorEdit4(id.c_str(), (float *)¤t_palette_[i].x,
|
||||
ImGuiColorEditFlags_NoInputs |
|
||||
ImGuiColorEditFlags_DisplayRGB |
|
||||
ImGuiColorEditFlags_DisplayHex);
|
||||
}
|
||||
ImGui::SetNextItemWidth(100.f);
|
||||
ImGui::InputInt("Tilesheet Offset", &tilesheet_offset);
|
||||
BASIC_BUTTON("Retrieve gfx") {
|
||||
if (rom_.isLoaded()) {
|
||||
DrawgfxSheet(tilesheet_offset);
|
||||
loaded_image = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
static ImVector<ImVec2> 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();
|
||||
// ImVec2 canvas_sz = ImGui::GetContentRegionAvail();
|
||||
ImVec2 canvas_sz = ImVec2(
|
||||
512 + 1, ImGui::GetContentRegionAvail().y + (tilesheet_offset * 256));
|
||||
ImVec2 canvas_p1 =
|
||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||
|
||||
// Draw border and background color
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
|
||||
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
|
||||
|
||||
// This will catch our interactions
|
||||
ImGui::InvisibleButton(
|
||||
"canvas", canvas_sz,
|
||||
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,
|
||||
canvas_p0.y + scrolling.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
// Pan (we use a zero mouse threshold when there's no context menu)
|
||||
const float mouse_threshold_for_pan =
|
||||
opt_enable_context_menu ? -1.0f : 0.0f;
|
||||
if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right,
|
||||
mouse_threshold_for_pan)) {
|
||||
scrolling.x += io.MouseDelta.x;
|
||||
scrolling.y += io.MouseDelta.y;
|
||||
}
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
if (opt_enable_context_menu && drag_delta.x == 0.0f &&
|
||||
drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupOnItemClick("context",
|
||||
ImGuiPopupFlags_MouseButtonRight);
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
ImGui::MenuItem("Placeholder");
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Draw grid around the canvas
|
||||
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
|
||||
|
||||
// Draw the tilesheets loaded from the ROM
|
||||
if (loaded_image) {
|
||||
for (const auto &[key, value] : imagesCache) {
|
||||
int offset = 128 * (key + 1);
|
||||
int top_left_y = canvas_p0.y + 2;
|
||||
if (key >= 1) {
|
||||
top_left_y = canvas_p0.y + 128 * key;
|
||||
}
|
||||
draw_list->AddImage((void *)(SDL_Texture *)value,
|
||||
ImVec2(canvas_p0.x + 2, top_left_y),
|
||||
ImVec2(canvas_p0.x + 512, canvas_p0.y + offset));
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawOverworldEditor() {
|
||||
if (ImGui::BeginTabItem("Overworld")) {
|
||||
overworld_editor_.Update();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawDungeonEditor() {
|
||||
if (ImGui::BeginTabItem("Dungeon")) {
|
||||
if (ImGui::BeginTable("DWToolset", 9, toolset_table_flags_, ImVec2(0, 0))) {
|
||||
ImGui::TableSetupColumn("#undoTool");
|
||||
ImGui::TableSetupColumn("#redoTool");
|
||||
ImGui::TableSetupColumn("#history");
|
||||
ImGui::TableSetupColumn("#separator");
|
||||
ImGui::TableSetupColumn("#bg1Tool");
|
||||
ImGui::TableSetupColumn("#bg2Tool");
|
||||
ImGui::TableSetupColumn("#bg3Tool");
|
||||
ImGui::TableSetupColumn("#itemTool");
|
||||
ImGui::TableSetupColumn("#spriteTool");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_UNDO);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_REDO);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_MANAGE_HISTORY);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text(ICON_MD_MORE_VERT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_FILTER_1);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_FILTER_2);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_FILTER_3);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_GRASS);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_PEST_CONTROL_RODENT);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawgfxEditor() {
|
||||
if (ImGui::BeginTabItem("gfx")) {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawSpriteEditor() {
|
||||
if (ImGui::BeginTabItem("Sprites")) {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawScreenEditor() {
|
||||
if (ImGui::BeginTabItem("Screens")) {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::DrawHUDEditor() {
|
||||
if (ImGui::BeginTabItem("HUD")) {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
74
src/gui/editor/editor.h
Normal file
74
src/gui/editor/editor.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef YAZE_APPLICATION_VIEW_EDITOR_H
|
||||
#define YAZE_APPLICATION_VIEW_EDITOR_H
|
||||
|
||||
#include <ImGuiColorTextEdit/TextEditor.h>
|
||||
#include <ImGuiFileDialog/ImGuiFileDialog.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_memory_editor.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include "core/constants.h"
|
||||
#include "gfx/tile.h"
|
||||
#include "gui/editor/overworld_editor.h"
|
||||
#include "gui/icons.h"
|
||||
#include "gui/input.h"
|
||||
#include "rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Editor {
|
||||
|
||||
class Editor {
|
||||
public:
|
||||
Editor();
|
||||
~Editor();
|
||||
void SetupScreen(std::shared_ptr<SDL_Renderer> renderer);
|
||||
void UpdateScreen();
|
||||
|
||||
private:
|
||||
void DrawYazeMenu();
|
||||
void DrawFileMenu() const;
|
||||
void DrawEditMenu() const;
|
||||
void DrawViewMenu();
|
||||
void DrawHelpMenu() const;
|
||||
|
||||
void DrawgfxSheet(int offset = 0);
|
||||
|
||||
void DrawProjectEditor();
|
||||
void DrawOverworldEditor();
|
||||
void DrawDungeonEditor();
|
||||
void DrawgfxEditor();
|
||||
void DrawSpriteEditor();
|
||||
void DrawScreenEditor();
|
||||
void DrawHUDEditor();
|
||||
|
||||
void *rom_data_;
|
||||
bool is_loaded_ = true;
|
||||
|
||||
std::vector<tile8> tiles_;
|
||||
std::vector<std::vector<tile8>> arranged_tiles_;
|
||||
std::unordered_map<unsigned int, std::shared_ptr<SDL_Texture>> texture_cache_;
|
||||
std::unordered_map<unsigned int, SDL_Texture *> imagesCache;
|
||||
|
||||
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
||||
|
||||
Data::ROM rom_;
|
||||
TextEditor asm_editor_;
|
||||
TextEditor::LanguageDefinition language_65816_;
|
||||
OverworldEditor overworld_editor_;
|
||||
|
||||
ImVec4 current_palette_[8];
|
||||
gfx::TilePreset current_set_;
|
||||
|
||||
ImGuiWindowFlags main_editor_flags_ =
|
||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar |
|
||||
ImGuiWindowFlags_NoTitleBar;
|
||||
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APPLICATION_VIEW_EDITOR_H
|
||||
382
src/gui/editor/overworld_editor.cc
Normal file
382
src/gui/editor/overworld_editor.cc
Normal file
@@ -0,0 +1,382 @@
|
||||
#include "overworld_editor.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "gfx/bitmap.h"
|
||||
#include "gfx/tile.h"
|
||||
#include "gui/icons.h"
|
||||
|
||||
|
||||
// first step would be to decompress all gfx data from the game
|
||||
// (in alttp that's easy they're all located in the same location all the
|
||||
// same sheet size 128x32) have a code that convert PC address to SNES and
|
||||
// vice-versa
|
||||
|
||||
// 1) find the gfx pointers (you could use ZS constant file)
|
||||
// 2) decompress all the gfx with your lz2 decompressor
|
||||
// 3) convert the 3bpp snes data into PC 4bpp (probably the hardest part)
|
||||
// 4) get the tiles32 data
|
||||
// 5) get the tiles16 data
|
||||
// 6) get the map32 data (they must be decompressed as well with a lz2
|
||||
// variant not the same as gfx compression but pretty similar) 7) get the
|
||||
// gfx data of the map yeah i forgot that one and load 4bpp in a pseudo vram
|
||||
// and use that to render tiles on screen 8) try to render the tiles on the
|
||||
// bitmap in black & white to start 9) get the palettes data and try to find
|
||||
// how they're loaded in the game that's a big puzzle to solve then 9 you'll
|
||||
// have an overworld map viewer, in less than few hours if are able to
|
||||
// understand the data quickly
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Editor {
|
||||
|
||||
void OverworldEditor::SetupROM(Data::ROM &rom) { rom_ = rom; }
|
||||
|
||||
void OverworldEditor::Update() {
|
||||
if (rom_.isLoaded()) {
|
||||
if (!all_gfx_loaded_) {
|
||||
Loadgfx();
|
||||
// overworld_.Load(rom_);
|
||||
all_gfx_loaded_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (show_changelist_) {
|
||||
DrawChangelist();
|
||||
}
|
||||
|
||||
DrawToolset();
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginTable("#owEditTable", 2, ow_edit_flags, ImVec2(0, 0))) {
|
||||
ImGui::TableSetupColumn("#overworldCanvas",
|
||||
ImGuiTableColumnFlags_WidthStretch,
|
||||
ImGui::GetContentRegionAvail().x);
|
||||
ImGui::TableSetupColumn("#tileSelector");
|
||||
ImGui::TableNextColumn();
|
||||
DrawOverworldCanvas();
|
||||
ImGui::TableNextColumn();
|
||||
DrawTileSelector();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawToolset() {
|
||||
if (ImGui::BeginTable("Toolset", 14, toolset_table_flags, ImVec2(0, 0))) {
|
||||
ImGui::TableSetupColumn("#undoTool");
|
||||
ImGui::TableSetupColumn("#redoTool");
|
||||
ImGui::TableSetupColumn("#drawTool");
|
||||
ImGui::TableSetupColumn("#separator2");
|
||||
ImGui::TableSetupColumn("#zoomOutTool");
|
||||
ImGui::TableSetupColumn("#zoomInTool");
|
||||
ImGui::TableSetupColumn("#separator");
|
||||
ImGui::TableSetupColumn("#history");
|
||||
ImGui::TableSetupColumn("#entranceTool");
|
||||
ImGui::TableSetupColumn("#exitTool");
|
||||
ImGui::TableSetupColumn("#itemTool");
|
||||
ImGui::TableSetupColumn("#spriteTool");
|
||||
ImGui::TableSetupColumn("#transportTool");
|
||||
ImGui::TableSetupColumn("#musicTool");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_UNDO);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_REDO);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button(ICON_MD_MANAGE_HISTORY)) {
|
||||
if (!show_changelist_)
|
||||
show_changelist_ = true;
|
||||
else
|
||||
show_changelist_ = false;
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text(ICON_MD_MORE_VERT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_ZOOM_OUT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_ZOOM_IN);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text(ICON_MD_MORE_VERT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_DRAW);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_DOOR_FRONT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_DOOR_BACK);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_GRASS);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_PEST_CONTROL_RODENT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_ADD_LOCATION);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_MUSIC_NOTE);
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawOverworldMapSettings() {
|
||||
if (ImGui::BeginTable("#mapSettings", 7, ow_map_settings_flags, ImVec2(0, 0),
|
||||
-1)) {
|
||||
ImGui::TableSetupColumn("##1stCol");
|
||||
ImGui::TableSetupColumn("##gfxCol");
|
||||
ImGui::TableSetupColumn("##palCol");
|
||||
ImGui::TableSetupColumn("##sprgfxCol");
|
||||
ImGui::TableSetupColumn("##sprpalCol");
|
||||
ImGui::TableSetupColumn("##msgidCol");
|
||||
ImGui::TableSetupColumn("##2ndCol");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::SetNextItemWidth(100.f);
|
||||
ImGui::Combo("##world", ¤t_world_,
|
||||
"Light World\0Dark World\0Extra World\0");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("GFX");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(kInputFieldSize);
|
||||
ImGui::InputText("##mapGFX", map_gfx_, kByteSize);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Palette");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(kInputFieldSize);
|
||||
ImGui::InputText("##mapPal", map_palette_, kByteSize);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Spr GFX");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(kInputFieldSize);
|
||||
ImGui::InputText("##sprGFX", spr_gfx_, kByteSize);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Spr Palette");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(kInputFieldSize);
|
||||
ImGui::InputText("##sprPal", spr_palette_, kByteSize);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Msg ID");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(50.f);
|
||||
ImGui::InputText("##msgid", spr_palette_, kMessageIdSize);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Checkbox("Show grid", &opt_enable_grid);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawOverworldCanvas() {
|
||||
DrawOverworldMapSettings();
|
||||
ImGui::Separator();
|
||||
static ImVector<ImVec2> points;
|
||||
static ImVec2 scrolling(0.0f, 0.0f);
|
||||
static bool opt_enable_context_menu = true;
|
||||
static bool adding_line = false;
|
||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
||||
ImVec2 canvas_sz = ImGui::GetContentRegionAvail();
|
||||
ImVec2 canvas_p1 =
|
||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||
|
||||
// Draw border and background color
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
|
||||
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
|
||||
|
||||
// This will catch our interactions
|
||||
ImGui::InvisibleButton(
|
||||
"canvas", canvas_sz,
|
||||
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,
|
||||
canvas_p0.y + scrolling.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
// Add first and second point
|
||||
if (is_hovered && !adding_line &&
|
||||
ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
adding_line = true;
|
||||
}
|
||||
if (adding_line) {
|
||||
points.back() = mouse_pos_in_canvas;
|
||||
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) adding_line = false;
|
||||
}
|
||||
|
||||
// Pan (we use a zero mouse threshold when there's no context menu)
|
||||
const float mouse_threshold_for_pan = opt_enable_context_menu ? -1.0f : 0.0f;
|
||||
if (is_active &&
|
||||
ImGui::IsMouseDragging(ImGuiMouseButton_Right, mouse_threshold_for_pan)) {
|
||||
scrolling.x += io.MouseDelta.x;
|
||||
scrolling.y += io.MouseDelta.y;
|
||||
}
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
if (opt_enable_context_menu && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
if (adding_line) points.resize(points.size() - 2);
|
||||
adding_line = false;
|
||||
if (ImGui::MenuItem("Remove one", NULL, false, points.Size > 0)) {
|
||||
points.resize(points.size() - 2);
|
||||
}
|
||||
if (ImGui::MenuItem("Remove all", NULL, false, points.Size > 0)) {
|
||||
points.clear();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Draw grid + all lines in the canvas
|
||||
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
|
||||
if (opt_enable_grid) {
|
||||
const float GRID_STEP = 64.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));
|
||||
}
|
||||
|
||||
for (int n = 0; n < points.Size; n += 2)
|
||||
draw_list->AddLine(
|
||||
ImVec2(origin.x + points[n].x, origin.y + points[n].y),
|
||||
ImVec2(origin.x + points[n + 1].x, origin.y + points[n + 1].y),
|
||||
IM_COL32(255, 255, 0, 255), 2.0f);
|
||||
|
||||
draw_list->PopClipRect();
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawTileSelector() {
|
||||
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
|
||||
if (ImGui::BeginTabItem("Tile8")) {
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
|
||||
bool child_is_visible =
|
||||
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
if (child_is_visible) // Avoid calling SetScrollHereY when running with
|
||||
// culled items
|
||||
{
|
||||
DrawTile8Selector();
|
||||
}
|
||||
float scroll_x = ImGui::GetScrollX();
|
||||
float scroll_max_x = ImGui::GetScrollMaxX();
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Tile16")) {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawTile8Selector() {
|
||||
static ImVec2 scrolling(0.0f, 0.0f);
|
||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
||||
ImVec2 canvas_sz = ImVec2(256 + 1, kNumSheetsToLoad * 64);
|
||||
ImVec2 canvas_p1 =
|
||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||
|
||||
// Draw border and background color
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
|
||||
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
|
||||
|
||||
// This will catch our interactions
|
||||
ImGui::InvisibleButton(
|
||||
"Tile8SelectorCanvas", canvas_sz,
|
||||
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,
|
||||
canvas_p0.y + scrolling.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
if (drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (all_gfx_loaded_) {
|
||||
for (const auto &[key, value] : all_texture_sheet_) {
|
||||
int offset = 64 * (key + 1);
|
||||
int top_left_y = canvas_p0.y + 2;
|
||||
if (key >= 1) {
|
||||
top_left_y = canvas_p0.y + 64 * key;
|
||||
}
|
||||
draw_list->AddImage((void *)(SDL_Texture *)value,
|
||||
ImVec2(canvas_p0.x + 2, top_left_y),
|
||||
ImVec2(canvas_p0.x + 256, canvas_p0.y + offset));
|
||||
}
|
||||
}
|
||||
|
||||
// Draw grid + all lines in the canvas
|
||||
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
|
||||
if (opt_enable_grid) {
|
||||
const float GRID_STEP = 16.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();
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawChangelist() {
|
||||
if (!ImGui::Begin("Changelist")) {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::Text("Test");
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void OverworldEditor::Loadgfx() {
|
||||
for (int i = 0; i < kNumSheetsToLoad; i++) {
|
||||
all_texture_sheet_[i] = rom_.DrawgfxSheet(i);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
79
src/gui/editor/overworld_editor.h
Normal file
79
src/gui/editor/overworld_editor.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef YAZE_APPLICATION_EDITOR_OVERWORLDEDITOR_H
|
||||
#define YAZE_APPLICATION_EDITOR_OVERWORLDEDITOR_H
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include "zelda3/overworld.h"
|
||||
#include "gfx/palette.h"
|
||||
#include "gfx/tile.h"
|
||||
#include "gui/icons.h"
|
||||
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Editor {
|
||||
|
||||
static constexpr unsigned int k4BPP = 4;
|
||||
|
||||
class OverworldEditor {
|
||||
public:
|
||||
void SetupROM(Data::ROM &rom);
|
||||
void Update();
|
||||
|
||||
private:
|
||||
void DrawToolset();
|
||||
void DrawOverworldMapSettings();
|
||||
void DrawOverworldCanvas();
|
||||
void DrawTileSelector();
|
||||
void DrawTile8Selector();
|
||||
void DrawChangelist();
|
||||
|
||||
void Loadgfx();
|
||||
|
||||
Data::ROM rom_;
|
||||
Data::Overworld overworld_;
|
||||
gfx::Bitmap allgfxBitmap;
|
||||
gfx::SNESPalette palette_;
|
||||
gfx::TilePreset current_set_;
|
||||
std::unordered_map<unsigned int, SDL_Texture *> all_texture_sheet_;
|
||||
|
||||
SDL_Texture *gfx_texture = nullptr;
|
||||
|
||||
int allgfx_width = 0;
|
||||
int allgfx_height = 0;
|
||||
|
||||
uchar *allGfx16Ptr = new uchar[(128 * 7136) / 2];
|
||||
|
||||
float canvas_table_ratio = 30.f;
|
||||
|
||||
char map_gfx_[3] = "";
|
||||
char map_palette_[3] = "";
|
||||
char spr_gfx_[3] = "";
|
||||
char spr_palette_[3] = "";
|
||||
char message_id_[5] = "";
|
||||
|
||||
int current_world_ = 0;
|
||||
|
||||
bool isLoaded = false;
|
||||
bool doneLoaded = false;
|
||||
bool opt_enable_grid = true;
|
||||
bool show_changelist_ = false;
|
||||
bool all_gfx_loaded_ = false;
|
||||
|
||||
constexpr static int kByteSize = 3;
|
||||
constexpr static int kMessageIdSize = 5;
|
||||
constexpr static float kInputFieldSize = 30.f;
|
||||
constexpr static int kNumSheetsToLoad = 50;
|
||||
constexpr static int kTile8DisplayHeight = 64;
|
||||
|
||||
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
||||
ImGuiTableFlags ow_map_settings_flags = ImGuiTableFlags_Borders;
|
||||
ImGuiTableFlags ow_edit_flags = ImGuiTableFlags_Reorderable |
|
||||
ImGuiTableFlags_Resizable |
|
||||
ImGuiTableFlags_SizingStretchSame;
|
||||
};
|
||||
} // namespace Editor
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,7 @@
|
||||
// for use with https://github.com/google/material-design-icons/blob/master/font/MaterialIcons-Regular.ttf
|
||||
#pragma once
|
||||
|
||||
#define FONT_ICON_FILE_NAME_MD "assets/Fonts/MaterialIcons-Regular.ttf"
|
||||
#define FONT_ICON_FILE_NAME_MD "assets/font/MaterialIcons-Regular.ttf"
|
||||
|
||||
#define ICON_MIN_MD 0xe000
|
||||
#define ICON_MAX_MD 0x10fffd
|
||||
|
||||
Reference in New Issue
Block a user