Begin LoadSprites, LoadChests, housekeeping

This commit is contained in:
scawful
2023-06-25 10:08:01 -04:00
parent 7d1dad3975
commit 3ada9988aa
18 changed files with 301 additions and 210 deletions

View File

@@ -14,11 +14,11 @@
#include "app/editor/overworld_editor.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/gui/input.h"
#include "app/gui/widgets.h"
#include "app/rom.h"
namespace yaze {
namespace app {
@@ -54,22 +54,6 @@ bool BeginCentered(const char *name) {
return ImGui::Begin(name, nullptr, flags);
}
void DisplayStatus(absl::Status &status) {
if (BeginCentered("StatusWindow")) {
ImGui::Text("%s", status.ToString().c_str());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(270);
if (ImGui::Button("OK", ImVec2(200, 0))) {
status = absl::OkStatus();
}
ImGui::End();
}
}
} // namespace
void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
@@ -114,7 +98,24 @@ void MasterEditor::DrawFileDialog() {
void MasterEditor::DrawStatusPopup() {
if (!status_.ok()) {
DisplayStatus(status_);
show_status_ = true;
prev_status_ = status_;
}
if (show_status_) {
if (BeginCentered("StatusWindow")) {
ImGui::Text("%s", prev_status_.ToString().c_str());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(270);
if (ImGui::Button("OK", ImVec2(200, 0))) {
show_status_ = false;
}
ImGui::End();
}
}
}
@@ -167,23 +168,13 @@ void MasterEditor::DrawFileMenu() {
".sfc,.smc", ".");
}
MENU_ITEM2("Save", "Ctrl+S") { status_ = rom_.SaveToFile(true); }
MENU_ITEM2("Save", "Ctrl+S") { status_ = rom_.SaveToFile(backup_rom_); }
MENU_ITEM("Save As..") {}
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::MenuItem("Backup ROM", "", &backup_rom_);
ImGui::EndMenu();
}
ImGui::EndMenu();

View File

@@ -52,9 +52,12 @@ class MasterEditor {
bool about_ = false;
bool rom_info_ = false;
bool backup_rom_ = true;
bool show_status_ = false;
std::shared_ptr<SDL_Renderer> sdl_renderer_;
absl::Status status_;
absl::Status prev_status_;
AssemblyEditor assembly_editor_;
DungeonEditor dungeon_editor_;

View File

@@ -13,10 +13,10 @@
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
namespace yaze {
namespace app {
@@ -88,8 +88,8 @@ void OverworldEditor::DrawOverworldMapSettings() {
ImGui::TableSetupColumn(name.data());
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(50.f);
ImGui::InputInt("Current Map", &current_map_);
ImGui::SetNextItemWidth(100.f);
ImGui::Combo("##world", &game_state_, "Part 0\0Part 1\0Part 2\0");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(100.f);
@@ -161,7 +161,25 @@ void OverworldEditor::DrawOverworldMaps() {
yy++;
xx = 0;
}
DrawOverworldEntrances();
}
}
// ----------------------------------------------------------------------------
void OverworldEditor::DrawOverworldSprites() {
for (const auto &sprite : overworld_.Sprites(game_state_)) {
// Get the sprite's bitmap and real X and Y positions
auto id = sprite.id();
const gfx::Bitmap &sprite_bitmap = sprite_previews_[id];
int realX = sprite.GetRealX();
int realY = sprite.GetRealY();
// Draw the sprite's bitmap onto the canvas at its real X and Y positions
ow_map_canvas_.DrawBitmap(sprite_bitmap, realX, realY);
ow_map_canvas_.DrawRect(realX, realY, sprite.Width(), sprite.Height(),
ImVec4(255, 0, 0, 150));
std::string str = absl::StrFormat("%s", sprite.Name());
ow_map_canvas_.DrawText(str, realX - 4, realY - 2);
}
}
@@ -192,6 +210,8 @@ void OverworldEditor::DrawOverworldCanvas() {
ow_map_canvas_.DrawContextMenu();
if (overworld_.isLoaded()) {
DrawOverworldMaps();
DrawOverworldEntrances();
DrawOverworldSprites();
// User has selected a tile they want to draw from the blockset.
if (!blockset_canvas_.Points().empty()) {
int x = blockset_canvas_.Points().front().x / 32;
@@ -358,6 +378,18 @@ absl::Status OverworldEditor::LoadGraphics() {
rom_.RenderBitmap(&(maps_bmp_[i]));
}
// Render the sprites for each Overworld map
// for (int i = 0; i < 3; i++)
// for (auto &sprite : overworld_.Sprites(i)) {
// int width = sprite.Width();
// int height = sprite.Height();
// int depth = 0x40;
// auto spr_gfx = sprite.PreviewGraphics().data();
// sprite_previews_[sprite.id()].Create(width, height, depth, spr_gfx);
// sprite_previews_[sprite.id()].ApplyPalette(palette_);
// rom_.RenderBitmap(&(sprite_previews_[sprite.id()]));
// }
return absl::OkStatus();
}

View File

@@ -14,10 +14,11 @@
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
namespace yaze {
namespace app {
@@ -56,6 +57,7 @@ class OverworldEditor {
void DrawOverworldEntrances();
void DrawOverworldMaps();
void DrawOverworldSprites();
void DrawOverworldEdits();
void DrawOverworldCanvas();
@@ -69,6 +71,7 @@ class OverworldEditor {
int current_map_ = 0;
int current_tile16_ = 0;
int selected_tile_ = 0;
int game_state_ = 0;
char map_gfx_[3] = "";
char map_palette_[3] = "";
char spr_gfx_[3] = "";

View File

@@ -40,6 +40,16 @@ using namespace ImGui;
} // namespace
absl::Status PaletteEditor::Update() {
for (int i = 0; i < kNumPalettes; ++i) {
if (ImGui::TreeNode(kPaletteCategoryNames[i].data())) {
DrawPaletteGroup(i);
ImGui::TreePop();
}
}
return absl::OkStatus();
}
void PaletteEditor::DrawPaletteGroup(int i) {
auto size = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()).size();
auto palettes = rom_.GetPaletteGroup(kPaletteGroupNames[i].data());
@@ -61,7 +71,7 @@ void PaletteEditor::DrawPaletteGroup(int i) {
palette_button_flags))
current_color_ =
ImVec4(palette[n].rgb.x, palette[n].rgb.y, palette[n].rgb.z,
palette[n].rgb.w); // Preserve alpha!
palette[n].rgb.w); // Prese rve alpha!
}
if (ImGui::BeginPopupContextItem(popupId.c_str())) {
@@ -69,11 +79,8 @@ void PaletteEditor::DrawPaletteGroup(int i) {
if (ImGui::ColorEdit4(
"Edit Color", col,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha)) {
// palette[n].rgb.x = current_color_rgba.x;
// palette[n].rgb.y = current_color_rgba.y;
// palette[n].rgb.z = current_color_rgba.z;
// rom_.UpdatePaletteColor(kPaletteGroupNames[groupIndex].data(), j,
// n, palette[n]);
rom_.UpdatePaletteColor(kPaletteGroupNames[i].data(), j, n,
palette[n]);
}
if (Button("Copy as..", ImVec2(-1, 0))) OpenPopup("Copy");
if (BeginPopup("Copy")) {
@@ -100,16 +107,6 @@ void PaletteEditor::DrawPaletteGroup(int i) {
}
}
absl::Status PaletteEditor::Update() {
for (int i = 0; i < kNumPalettes; ++i) {
if (ImGui::TreeNode(kPaletteCategoryNames[i].data())) {
DrawPaletteGroup(i);
ImGui::TreePop();
}
}
return absl::OkStatus();
}
void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
static ImVec4 color = ImVec4(0, 0, 0, 255.f);
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
@@ -150,7 +147,6 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
ImGui::Text("Previous");
if (ImGui::Button("Update Map Palette")) {
}
ImGui::ColorButton(
@@ -165,7 +161,7 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
ImVec2(60, 40)))
color = backup_color;
// List of Colors in Overworld Palette
// List of Colors in Overworld Palette
ImGui::Separator();
ImGui::Text("Palette");
for (int n = 0; n < IM_ARRAYSIZE(saved_palette_); n++) {