add selected tile outline for ow editor

This commit is contained in:
scawful
2022-10-07 19:32:24 -05:00
parent 16e1ee389a
commit c7f12e56a2
5 changed files with 71 additions and 82 deletions

View File

@@ -41,6 +41,7 @@ void UpdateSelectedTile16(int selected, gfx::Bitmap &tile16_blockset,
void OverworldEditor::SetupROM(ROM &rom) { rom_ = rom; } void OverworldEditor::SetupROM(ROM &rom) { rom_ = rom; }
absl::Status OverworldEditor::Update() { absl::Status OverworldEditor::Update() {
// Initialize overworld graphics, maps, and palettes
if (rom_.isLoaded() && !all_gfx_loaded_) { if (rom_.isLoaded() && !all_gfx_loaded_) {
LoadGraphics(); LoadGraphics();
all_gfx_loaded_ = true; all_gfx_loaded_ = true;
@@ -196,11 +197,11 @@ void OverworldEditor::DrawOverworldCanvas() {
} }
} }
for (const auto &each : overworld_.Entrances()) { for (const auto &each : overworld_.Entrances()) {
if (each.mapId_ < 64 + (current_world_ * 0x40) && if (each.map_id_ < 64 + (current_world_ * 0x40) &&
each.mapId_ >= (current_world_ * 0x40)) { each.map_id_ >= (current_world_ * 0x40)) {
overworld_map_canvas_.DrawRect(each.x_, each.y_, 16, 16, overworld_map_canvas_.DrawRect(each.x_, each.y_, 16, 16,
ImVec4(210, 24, 210, 150)); ImVec4(210, 24, 210, 150));
std::string str = absl::StrFormat("%#x", each.entranceId_); std::string str = absl::StrFormat("%#x", each.entrance_id_);
overworld_map_canvas_.DrawText(str, each.x_ - 4, each.y_ - 2); overworld_map_canvas_.DrawText(str, each.x_ - 4, each.y_ - 2);
} }
} }
@@ -213,11 +214,11 @@ void OverworldEditor::DrawOverworldCanvas() {
void OverworldEditor::DrawTileSelector() { void OverworldEditor::DrawTileSelector() {
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) { if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
if (ImGui::BeginTabItem("Tile8")) { if (ImGui::BeginTabItem("Area Graphics")) {
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1); ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) { ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawTile8Selector(); DrawAreaGraphics();
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndTabItem(); ImGui::EndTabItem();
@@ -231,11 +232,11 @@ void OverworldEditor::DrawTileSelector() {
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
if (ImGui::BeginTabItem("Area Graphics")) { if (ImGui::BeginTabItem("Tile8")) {
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3); ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) { ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawAreaGraphics(); DrawTile8Selector();
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndTabItem(); ImGui::EndTabItem();
@@ -244,6 +245,19 @@ void OverworldEditor::DrawTileSelector() {
} }
} }
void OverworldEditor::DrawAreaGraphics() {
current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 16 * 64 + 1));
current_gfx_canvas_.DrawContextMenu();
current_gfx_canvas_.DrawTileSelector(32);
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_, 2, overworld_.isLoaded());
current_gfx_canvas_.DrawGrid(32.0f);
current_gfx_canvas_.DrawOverlay();
if (!current_gfx_canvas_.Points().empty()) {
// TODO(scawful): update selected tile by getting position from canvas
}
}
void OverworldEditor::DrawTile16Selector() { void OverworldEditor::DrawTile16Selector() {
blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1)); blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
blockset_canvas_.DrawContextMenu(); blockset_canvas_.DrawContextMenu();
@@ -274,14 +288,6 @@ void OverworldEditor::DrawTile8Selector() {
graphics_bin_canvas_.DrawOverlay(); graphics_bin_canvas_.DrawOverlay();
} }
void OverworldEditor::DrawAreaGraphics() {
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() { void OverworldEditor::LoadGraphics() {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
current_palette_[i].x = (i * 0.21f); current_palette_[i].x = (i * 0.21f);

View File

@@ -258,9 +258,9 @@ void Overworld::LoadEntrances() {
} }
for (int i = 0; i < 0x13; i++) { for (int i = 0; i < 0x13; i++) {
short mapId = (short)((rom_[core::OWHoleArea + (i * 2) + 1] << 8) + auto mapId = (short)((rom_[core::OWHoleArea + (i * 2) + 1] << 8) +
(rom_[core::OWHoleArea + (i * 2)])); (rom_[core::OWHoleArea + (i * 2)]));
short mapPos = (short)((rom_[core::OWHolePos + (i * 2) + 1] << 8) + auto mapPos = (short)((rom_[core::OWHolePos + (i * 2) + 1] << 8) +
(rom_[core::OWHolePos + (i * 2)])); (rom_[core::OWHolePos + (i * 2)]));
uchar entranceId = (rom_[core::OWHoleEntrance + i]); uchar entranceId = (rom_[core::OWHoleEntrance + i]);
int p = (mapPos + 0x400) >> 1; int p = (mapPos + 0x400) >> 1;
@@ -282,8 +282,6 @@ void Overworld::LoadSprites() {
all_sprites_.emplace_back(std::vector<Sprite>()); all_sprites_.emplace_back(std::vector<Sprite>());
} }
// Console.WriteLine(((core::overworldSpritesBegining & 0xFFFF) + (09 <<
// 16)).ToString("X6"));
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if (map_parent_[i] == i) { if (map_parent_[i] == i) {
// Beginning Sprites // Beginning Sprites

View File

@@ -22,53 +22,48 @@ class OverworldEntrance {
public: public:
int x_; int x_;
int y_; int y_;
ushort mapPos; ushort map_pos_;
uchar entranceId_, AreaX, AreaY; uchar entrance_id_;
short mapId_; uchar area_x_;
bool isHole = false; uchar area_y_;
short map_id_;
bool is_hole_ = false;
bool deleted = false; bool deleted = false;
OverworldEntrance(int x, int y, uchar entranceId, short mapId, ushort mapPos, OverworldEntrance(int x, int y, uchar entranceId, short mapId, ushort mapPos,
bool hole) { bool hole)
x_ = x; : x_(x),
y_ = y; y_(y),
entranceId_ = entranceId; map_pos_(mapPos),
mapId_ = mapId; entrance_id_(entranceId),
mapPos = mapPos; map_id_(mapId),
is_hole_(hole) {
int mapX = (map_id_ - ((map_id_ / 8) * 8));
int mapY = (map_id_ / 8);
int mapX = (mapId_ - ((mapId / 8) * 8)); area_x_ = (uchar)((std::abs(x - (mapX * 512)) / 16));
int mapY = (mapId_ / 8); area_y_ = (uchar)((std::abs(y - (mapY * 512)) / 16));
AreaX = (uchar)((std::abs(x - (mapX * 512)) / 16));
AreaY = (uchar)((std::abs(y - (mapY * 512)) / 16));
isHole = hole;
} }
auto Copy() { auto Copy() {
return new OverworldEntrance(x_, y_, entranceId_, mapId_, mapPos, isHole); return new OverworldEntrance(x_, y_, entrance_id_, map_id_, map_pos_,
is_hole_);
} }
void updateMapStuff(short mapId) { void updateMapStuff(short mapId) {
mapId_ = mapId; map_id_ = mapId;
if (mapId_ >= 64) { if (map_id_ >= 64) {
mapId_ -= 64; map_id_ -= 64;
} }
int mapX = (mapId_ - ((mapId_ / 8) * 8)); int mapX = (map_id_ - ((map_id_ / 8) * 8));
int mapY = (mapId_ / 8); int mapY = (map_id_ / 8);
AreaX = (uchar)((std::abs(x_ - (mapX * 512)) / 16)); area_x_ = (uchar)((std::abs(x_ - (mapX * 512)) / 16));
AreaY = (uchar)((std::abs(y_ - (mapY * 512)) / 16)); area_y_ = (uchar)((std::abs(y_ - (mapY * 512)) / 16));
int mx = (mapId_ - ((mapId_ / 8) * 8)); map_pos_ = (ushort)((((area_y_) << 6) | (area_x_ & 0x3F)) << 1);
int my = (mapId_ / 8);
uchar xx = (uchar)((x_ - (mx * 512)) / 16);
uchar yy = (uchar)((y_ - (my * 512)) / 16);
mapPos = (ushort)((((AreaY) << 6) | (AreaX & 0x3F)) << 1);
} }
}; };

View File

@@ -37,19 +37,6 @@ void Canvas::DrawContextMenu() {
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x, const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
io.MousePos.y - origin.y); io.MousePos.y - origin.y);
// Add first and second point
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
ImVec2 draw_tile_outline_pos;
draw_tile_outline_pos.x =
std::round((double)mouse_pos_in_canvas.x / 32) * 32;
draw_tile_outline_pos.y =
std::round((double)mouse_pos_in_canvas.y / 32) * 32;
points_.push_back(draw_tile_outline_pos);
points_.push_back(
ImVec2(draw_tile_outline_pos.x + 32, draw_tile_outline_pos.y + 32));
}
// Pan (we use a zero mouse threshold when there's no context menu) // Pan (we use a zero mouse threshold when there's no context menu)
const float mouse_threshold_for_pan = enable_context_menu_ ? -1.0f : 0.0f; const float mouse_threshold_for_pan = enable_context_menu_ ? -1.0f : 0.0f;
if (is_active && if (is_active &&
@@ -76,24 +63,27 @@ void Canvas::DrawContextMenu() {
} }
} }
void Canvas::DrawTilesFromUser(app::ROM &rom, Bytes &tile, void Canvas::DrawTileSelector(int size) {
app::gfx::SNESPalette &pal) { const ImGuiIO &io = ImGui::GetIO();
ImVec2 draw_tile_outline_pos; const bool is_hovered = ImGui::IsItemHovered(); // Hovered
const ImVec2 origin(canvas_p0_.x + scrolling_.x,
// Add rectangle canvas_p0_.y + scrolling_.y); // Lock scrolled origin
if (is_hovered_ && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
io.MousePos.y - origin.y);
// Add first and second point
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
if (!points_.empty()) {
points_.clear();
}
ImVec2 draw_tile_outline_pos;
draw_tile_outline_pos.x = draw_tile_outline_pos.x =
std::round((double)mouse_pos_in_canvas_.x / 16) * 16; std::floor((double)mouse_pos_in_canvas.x / size) * size;
draw_tile_outline_pos.y = draw_tile_outline_pos.y =
std::round((double)mouse_pos_in_canvas_.y / 16) * 16; std::floor((double)mouse_pos_in_canvas.y / size) * size;
points_.push_back(draw_tile_outline_pos); points_.push_back(draw_tile_outline_pos);
points_.push_back( points_.push_back(
ImVec2(draw_tile_outline_pos.x + 16, draw_tile_outline_pos.y + 16)); ImVec2(draw_tile_outline_pos.x + size, draw_tile_outline_pos.y + size));
changed_tiles_.emplace_back(app::gfx::Bitmap(16, 16, 64, tile.data()));
changed_tiles_.back().ApplyPalette(pal);
rom.RenderBitmap(&(changed_tiles_.back()));
} }
} }

View File

@@ -17,13 +17,12 @@ using app::gfx::Bitmap;
class Canvas { class Canvas {
public: public:
Canvas() = default; Canvas() = default;
Canvas(ImVec2 canvas_size) explicit Canvas(ImVec2 canvas_size)
: custom_canvas_size_(true), canvas_sz_(canvas_size) {} : custom_canvas_size_(true), canvas_sz_(canvas_size) {}
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0)); void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
void DrawContextMenu(); void DrawContextMenu();
void DrawTilesFromUser(app::ROM& rom, Bytes& tile, void DrawTileSelector(int size);
app::gfx::SNESPalette& pal);
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0, void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
bool ready = true); bool ready = true);
void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset); void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset);
@@ -33,6 +32,7 @@ class Canvas {
void DrawGrid(float grid_step = 64.0f); void DrawGrid(float grid_step = 64.0f);
void DrawOverlay(); // last void DrawOverlay(); // last
auto Points() const { return points_; }
auto GetDrawList() const { return draw_list_; } auto GetDrawList() const { return draw_list_; }
auto GetZeroPoint() const { return canvas_p0_; } auto GetZeroPoint() const { return canvas_p0_; }
void SetCanvasSize(ImVec2 canvas_size) { void SetCanvasSize(ImVec2 canvas_size) {