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; }
absl::Status OverworldEditor::Update() {
// Initialize overworld graphics, maps, and palettes
if (rom_.isLoaded() && !all_gfx_loaded_) {
LoadGraphics();
all_gfx_loaded_ = true;
@@ -196,11 +197,11 @@ void OverworldEditor::DrawOverworldCanvas() {
}
}
for (const auto &each : overworld_.Entrances()) {
if (each.mapId_ < 64 + (current_world_ * 0x40) &&
each.mapId_ >= (current_world_ * 0x40)) {
if (each.map_id_ < 64 + (current_world_ * 0x40) &&
each.map_id_ >= (current_world_ * 0x40)) {
overworld_map_canvas_.DrawRect(each.x_, each.y_, 16, 16,
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);
}
}
@@ -213,11 +214,11 @@ void OverworldEditor::DrawOverworldCanvas() {
void OverworldEditor::DrawTileSelector() {
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
if (ImGui::BeginTabItem("Tile8")) {
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
if (ImGui::BeginTabItem("Area Graphics")) {
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawTile8Selector();
DrawAreaGraphics();
}
ImGui::EndChild();
ImGui::EndTabItem();
@@ -231,11 +232,11 @@ void OverworldEditor::DrawTileSelector() {
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Area Graphics")) {
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
if (ImGui::BeginTabItem("Tile8")) {
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawAreaGraphics();
DrawTile8Selector();
}
ImGui::EndChild();
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() {
blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
blockset_canvas_.DrawContextMenu();
@@ -274,14 +288,6 @@ void OverworldEditor::DrawTile8Selector() {
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() {
for (int i = 0; i < 8; i++) {
current_palette_[i].x = (i * 0.21f);

View File

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

View File

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

View File

@@ -37,19 +37,6 @@ void Canvas::DrawContextMenu() {
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)) {
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)
const float mouse_threshold_for_pan = enable_context_menu_ ? -1.0f : 0.0f;
if (is_active &&
@@ -76,24 +63,27 @@ void Canvas::DrawContextMenu() {
}
}
void Canvas::DrawTilesFromUser(app::ROM &rom, Bytes &tile,
app::gfx::SNESPalette &pal) {
ImVec2 draw_tile_outline_pos;
// Add rectangle
if (is_hovered_ && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
void Canvas::DrawTileSelector(int size) {
const ImGuiIO &io = ImGui::GetIO();
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
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 && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
if (!points_.empty()) {
points_.clear();
}
ImVec2 draw_tile_outline_pos;
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 =
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(
ImVec2(draw_tile_outline_pos.x + 16, draw_tile_outline_pos.y + 16));
changed_tiles_.emplace_back(app::gfx::Bitmap(16, 16, 64, tile.data()));
changed_tiles_.back().ApplyPalette(pal);
rom.RenderBitmap(&(changed_tiles_.back()));
ImVec2(draw_tile_outline_pos.x + size, draw_tile_outline_pos.y + size));
}
}

View File

@@ -17,13 +17,12 @@ using app::gfx::Bitmap;
class Canvas {
public:
Canvas() = default;
Canvas(ImVec2 canvas_size)
explicit Canvas(ImVec2 canvas_size)
: custom_canvas_size_(true), canvas_sz_(canvas_size) {}
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
void DrawContextMenu();
void DrawTilesFromUser(app::ROM& rom, Bytes& tile,
app::gfx::SNESPalette& pal);
void DrawTileSelector(int size);
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
bool ready = true);
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 DrawOverlay(); // last
auto Points() const { return points_; }
auto GetDrawList() const { return draw_list_; }
auto GetZeroPoint() const { return canvas_p0_; }
void SetCanvasSize(ImVec2 canvas_size) {