bitmap optimization, sprites, inventory, tiles

This commit is contained in:
Justin Scofield
2022-09-12 21:17:41 -05:00
parent d6081e9add
commit 56ef315028
21 changed files with 1692 additions and 155 deletions

View File

@@ -101,46 +101,21 @@ absl::Status OverworldEditor::DrawToolset() {
for (const auto &name : kToolsetColumnNames)
ImGui::TableSetupColumn(name.data());
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_UNDO);
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_REDO);
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);
// Entrances
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_DOOR_FRONT);
// Exits
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_DOOR_BACK);
// Items
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_GRASS);
// Sprites
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_PEST_CONTROL_RODENT);
// Transports
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_ADD_LOCATION);
// Music
ImGui::TableNextColumn();
ImGui::Button(ICON_MD_MUSIC_NOTE);
// Separator
ImGui::TableNextColumn();
ImGui::Text(ICON_MD_MORE_VERT);
// Music
ImGui::TableNextColumn();
BUTTON_COLUMN(ICON_MD_UNDO) // Undo
BUTTON_COLUMN(ICON_MD_REDO) // Redo
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
BUTTON_COLUMN(ICON_MD_ZOOM_OUT) // Zoom Out
BUTTON_COLUMN(ICON_MD_ZOOM_IN) // Zoom In
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
BUTTON_COLUMN(ICON_MD_DRAW); // Draw Tile
BUTTON_COLUMN(ICON_MD_DOOR_FRONT) // Entrances
BUTTON_COLUMN(ICON_MD_DOOR_BACK) // Exits
BUTTON_COLUMN(ICON_MD_GRASS) // Items
BUTTON_COLUMN(ICON_MD_PEST_CONTROL_RODENT) // Sprites
BUTTON_COLUMN(ICON_MD_ADD_LOCATION) // Transports
BUTTON_COLUMN(ICON_MD_MUSIC_NOTE) // Music
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
ImGui::TableNextColumn(); // Palette
palette_editor_.DisplayPalette(palette_, overworld_.isLoaded());
ImGui::EndTable();
@@ -223,9 +198,10 @@ void OverworldEditor::DrawOverworldCanvas() {
for (const auto &each : overworld_.Entrances()) {
if (each.mapId_ < 64 + (current_world_ * 0x40) &&
each.mapId_ >= (current_world_ * 0x40)) {
overworld_map_canvas_.DrawOutline(each.x_, each.y_, 16, 16);
overworld_map_canvas_.DrawRect(each.x_, each.y_, 16, 16,
ImVec4(210, 24, 210, 150));
std::string str = absl::StrFormat("%#x", each.entranceId_);
overworld_map_canvas_.DrawText(str, each.x_ - 2, each.y_ - 14);
overworld_map_canvas_.DrawText(str, each.x_ - 4, each.y_ - 2);
}
}
}
@@ -271,9 +247,7 @@ void OverworldEditor::DrawTileSelector() {
void OverworldEditor::DrawTile16Selector() {
blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
blockset_canvas_.DrawContextMenu();
if (map_blockset_loaded_) {
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 2);
}
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 2, map_blockset_loaded_);
blockset_canvas_.DrawGrid(32.0f);
blockset_canvas_.DrawOverlay();
}
@@ -301,13 +275,11 @@ void OverworldEditor::DrawTile8Selector() {
}
void OverworldEditor::DrawAreaGraphics() {
if (overworld_.isLoaded()) {
current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 16 * 64 + 1));
current_gfx_canvas_.DrawContextMenu();
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_);
current_gfx_canvas_.DrawGrid(32.0f);
current_gfx_canvas_.DrawOverlay();
}
current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 16 * 64 + 1));
current_gfx_canvas_.DrawContextMenu();
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_, 2, overworld_.isLoaded());
current_gfx_canvas_.DrawGrid(32.0f);
current_gfx_canvas_.DrawOverlay();
}
void OverworldEditor::LoadGraphics() {

View File

@@ -84,20 +84,21 @@ class OverworldEditor {
ImGuiTableFlags_Resizable |
ImGuiTableFlags_SizingStretchSame;
Bytes selected_tile_data_;
std::unordered_map<int, gfx::Bitmap> graphics_bin_;
std::unordered_map<int, gfx::Bitmap> current_graphics_set_;
std::unordered_map<int, gfx::Bitmap> maps_bmp_;
std::unordered_map<int, gfx::Bitmap> sprite_previews_;
ROM rom_;
zelda3::Overworld overworld_;
PaletteEditor palette_editor_;
zelda3::Overworld overworld_;
gfx::SNESPalette palette_;
gfx::Bitmap tile16_blockset_bmp_;
gfx::Bitmap current_gfx_bmp_;
gfx::Bitmap all_gfx_bmp;
gfx::Bitmap selected_tile_bmp_;
Bytes selected_tile_data_;
gui::Canvas overworld_map_canvas_;
gui::Canvas current_gfx_canvas_;

View File

@@ -41,8 +41,7 @@ absl::Status PaletteEditor::Update() {
return absl::OkStatus();
}
absl::Status PaletteEditor::DisplayPalette(gfx::SNESPalette& palette,
bool loaded) {
void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
static ImVec4 color = ImVec4(0, 0, 0, 255.f);
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
ImGuiColorEditFlags_NoDragDrop |
@@ -122,7 +121,6 @@ absl::Status PaletteEditor::DisplayPalette(gfx::SNESPalette& palette,
ImGui::EndGroup();
ImGui::EndPopup();
}
return absl::OkStatus();
}
} // namespace editor

View File

@@ -26,7 +26,7 @@ static constexpr absl::string_view kPaletteGroupNames[] = {
class PaletteEditor {
public:
absl::Status Update();
absl::Status DisplayPalette(gfx::SNESPalette& palette, bool loaded);
void DisplayPalette(gfx::SNESPalette& palette, bool loaded);
auto SetupROM(ROM& rom) { rom_ = rom; }

View File

@@ -27,13 +27,12 @@ ScreenEditor::ScreenEditor() { screen_canvas_.SetCanvasSize(ImVec2(512, 512)); }
void ScreenEditor::Update() {
TAB_BAR("##TabBar")
DrawMosaicEditor();
DrawInventoryMenuEditor();
DrawTitleScreenEditor();
DrawNamingScreenEditor();
DrawOverworldMapEditor();
DrawDungeonMapsEditor();
DrawGameMenuEditor();
DrawHUDEditor();
DrawMosaicEditor();
END_TAB_BAR()
}
@@ -60,6 +59,61 @@ void ScreenEditor::DrawWorldGrid(int world, int h, int w) {
}
}
void ScreenEditor::DrawInventoryMenuEditor() {
TAB_ITEM("Inventory Menu")
static bool create = false;
if (!create) {
PRINT_IF_ERROR(rom_.LoadAllGraphicsData())
all_gfx_ = rom_.GetGraphicsBuffer();
inventory_.Create(all_gfx_);
create = true;
}
if (ImGui::BeginTable("InventoryScreen", 2, ImGuiTableFlags_Resizable)) {
ImGui::TableSetupColumn("Canvas");
ImGui::TableSetupColumn("Tiles");
ImGui::TableHeadersRow();
ImGui::TableNextColumn();
screen_canvas_.DrawBackground();
screen_canvas_.DrawContextMenu();
screen_canvas_.DrawBitmap(inventory_.Bitmap(), 2, create);
screen_canvas_.DrawGrid();
screen_canvas_.DrawOverlay();
ImGui::TableNextColumn();
tilesheet_canvas_.DrawBackground(ImVec2(128 * 2 + 2, 192 * 2 + 2));
tilesheet_canvas_.DrawContextMenu();
tilesheet_canvas_.DrawBitmap(inventory_.Tilesheet(), 2, create);
tilesheet_canvas_.DrawGrid();
tilesheet_canvas_.DrawOverlay();
ImGui::EndTable();
}
ImGui::SameLine();
END_TAB_ITEM()
}
void ScreenEditor::DrawTitleScreenEditor() {
TAB_ITEM("Title Screen")
END_TAB_ITEM()
}
void ScreenEditor::DrawNamingScreenEditor() {
TAB_ITEM("Naming Screen")
END_TAB_ITEM()
}
void ScreenEditor::DrawOverworldMapEditor() {
TAB_ITEM("Overworld Map")
END_TAB_ITEM()
}
void ScreenEditor::DrawDungeonMapsEditor() {
TAB_ITEM("Dungeon Maps")
END_TAB_ITEM()
}
void ScreenEditor::DrawMosaicEditor() {
TAB_ITEM("Mosaic Transitions")
@@ -94,39 +148,6 @@ void ScreenEditor::DrawMosaicEditor() {
END_TAB_ITEM()
}
void ScreenEditor::DrawTitleScreenEditor() {
TAB_ITEM("Title Screen")
END_TAB_ITEM()
}
void ScreenEditor::DrawNamingScreenEditor() {
TAB_ITEM("Naming Screen")
END_TAB_ITEM()
}
void ScreenEditor::DrawOverworldMapEditor() {
TAB_ITEM("Overworld Map")
END_TAB_ITEM()
}
void ScreenEditor::DrawDungeonMapsEditor() {
TAB_ITEM("Dungeon Maps")
END_TAB_ITEM()
}
void ScreenEditor::DrawGameMenuEditor() {
TAB_ITEM("Game Menu")
END_TAB_ITEM()
}
void ScreenEditor::DrawHUDEditor() {
TAB_ITEM("Heads-up Display")
END_TAB_ITEM()
}
void ScreenEditor::DrawCanvas() {
screen_canvas_.DrawBackground();
screen_canvas_.DrawContextMenu();
screen_canvas_.DrawGrid();
screen_canvas_.DrawOverlay();
}
void ScreenEditor::DrawToolset() {
static bool show_bg1 = true;
static bool show_bg2 = true;

View File

@@ -10,7 +10,7 @@
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/screen.h"
#include "app/zelda3/inventory.h"
#include "gui/canvas.h"
namespace yaze {
@@ -24,7 +24,10 @@ static int overworldCustomMosaicArray = 0x1301F0;
class ScreenEditor {
public:
ScreenEditor();
void SetupROM(ROM &rom) { rom_ = rom; }
void SetupROM(ROM &rom) {
rom_ = rom;
inventory_.SetupROM(rom_);
}
void Update();
private:
@@ -33,19 +36,19 @@ class ScreenEditor {
void DrawNamingScreenEditor();
void DrawOverworldMapEditor();
void DrawDungeonMapsEditor();
void DrawGameMenuEditor();
void DrawHUDEditor();
void DrawInventoryMenuEditor();
void DrawCanvas();
void DrawToolset();
void DrawWorldGrid(int world, int h = 8, int w = 8);
char mosaic_tiles_[core::kNumOverworldMaps];
ROM rom_;
Bytes all_gfx_;
zelda3::Inventory inventory_;
snes_asm::Script mosaic_script_;
zelda3::Screen current_screen_;
gui::Canvas screen_canvas_;
gui::Canvas tilesheet_canvas_;
};
} // namespace editor