Add menu bar to tile16 editor

This commit is contained in:
scawful
2024-04-10 09:30:02 -04:00
parent ae8ca72402
commit a6ef95c5dd
2 changed files with 52 additions and 37 deletions

View File

@@ -50,6 +50,7 @@ absl::Status Tile16Editor::Update() {
*tile8_source_canvas_.custom_labels_enabled() = true; *tile8_source_canvas_.custom_labels_enabled() = true;
} }
RETURN_IF_ERROR(DrawMenu());
if (BeginTabBar("Tile16 Editor Tabs")) { if (BeginTabBar("Tile16 Editor Tabs")) {
RETURN_IF_ERROR(DrawTile16Editor()); RETURN_IF_ERROR(DrawTile16Editor());
RETURN_IF_ERROR(UpdateTile16Transfer()); RETURN_IF_ERROR(UpdateTile16Transfer());
@@ -60,10 +61,14 @@ absl::Status Tile16Editor::Update() {
} }
absl::Status Tile16Editor::DrawMenu() { absl::Status Tile16Editor::DrawMenu() {
if (ImGui::BeginMenu("Tile16 Editor")) { if (ImGui::BeginMenuBar()) {
ImGui::Checkbox("Show Collision Types", if (ImGui::BeginMenu("View")) {
tile8_source_canvas_.custom_labels_enabled()); ImGui::Checkbox("Show Collision Types",
ImGui::EndMenu(); tile8_source_canvas_.custom_labels_enabled());
ImGui::EndMenu();
}
ImGui::EndMenuBar();
} }
return absl::OkStatus(); return absl::OkStatus();
@@ -209,8 +214,7 @@ absl::Status Tile16Editor::UpdateTile16Edit() {
tile16_edit_canvas_.DrawOverlay(); tile16_edit_canvas_.DrawOverlay();
} }
ImGui::EndChild(); ImGui::EndChild();
DrawTileEditControls(); RETURN_IF_ERROR(DrawTileEditControls());
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -245,7 +245,8 @@ absl::Status OverworldEditor::DrawToolset() {
if (show_tile16_editor_) { if (show_tile16_editor_) {
// Create a table in ImGui for the Tile16 Editor // Create a table in ImGui for the Tile16 Editor
ImGui::Begin("Tile16 Editor", &show_tile16_editor_); ImGui::Begin("Tile16 Editor", &show_tile16_editor_,
ImGuiWindowFlags_MenuBar);
RETURN_IF_ERROR(tile16_editor_.Update()) RETURN_IF_ERROR(tile16_editor_.Update())
ImGui::End(); ImGui::End();
} }
@@ -346,6 +347,9 @@ void OverworldEditor::RefreshOverworldMap() {
// TODO: Palette throws out of bounds error unexpectedly. // TODO: Palette throws out of bounds error unexpectedly.
absl::Status OverworldEditor::RefreshMapPalette() { absl::Status OverworldEditor::RefreshMapPalette() {
const auto current_map_palette =
overworld_.overworld_map(current_map_)->current_palette();
if (overworld_.overworld_map(current_map_)->is_large_map()) { if (overworld_.overworld_map(current_map_)->is_large_map()) {
// We need to update the map and its siblings if it's a large map // We need to update the map and its siblings if it's a large map
for (int i = 1; i < 4; i++) { for (int i = 1; i < 4; i++) {
@@ -353,14 +357,12 @@ absl::Status OverworldEditor::RefreshMapPalette() {
if (i >= 2) sibling_index += 6; if (i >= 2) sibling_index += 6;
RETURN_IF_ERROR( RETURN_IF_ERROR(
overworld_.mutable_overworld_map(sibling_index)->LoadPalette()); overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
RETURN_IF_ERROR(maps_bmp_[sibling_index].ApplyPalette( RETURN_IF_ERROR(
*overworld_.mutable_overworld_map(sibling_index) maps_bmp_[sibling_index].ApplyPalette(current_map_palette));
->mutable_current_palette()));
} }
} }
RETURN_IF_ERROR(maps_bmp_[current_map_].ApplyPalette(
*overworld_.mutable_overworld_map(current_map_) RETURN_IF_ERROR(maps_bmp_[current_map_].ApplyPalette(current_map_palette));
->mutable_current_palette()));
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -414,6 +416,7 @@ void OverworldEditor::DrawOverworldMapSettings() {
kInputFieldSize)) { kInputFieldSize)) {
RefreshMapProperties(); RefreshMapProperties();
status_ = RefreshMapPalette(); status_ = RefreshMapPalette();
RefreshOverworldMap();
} }
ImGui::EndGroup(); ImGui::EndGroup();
@@ -723,6 +726,7 @@ void OverworldEditor::DrawOverworldCanvas() {
CheckForOverworldEdits(); CheckForOverworldEdits();
if (ImGui::IsItemHovered()) status_ = CheckForCurrentMap(); if (ImGui::IsItemHovered()) status_ = CheckForCurrentMap();
} }
ow_map_canvas_.DrawGrid(); ow_map_canvas_.DrawGrid();
ow_map_canvas_.DrawOverlay(); ow_map_canvas_.DrawOverlay();
ImGui::EndChild(); ImGui::EndChild();
@@ -734,25 +738,30 @@ absl::Status OverworldEditor::DrawTile16Selector() {
gui::BeginChildWithScrollbar("##Tile16SelectorScrollRegion"); gui::BeginChildWithScrollbar("##Tile16SelectorScrollRegion");
blockset_canvas_.DrawBackground(); blockset_canvas_.DrawBackground();
gui::EndNoPadding(); gui::EndNoPadding();
blockset_canvas_.DrawContextMenu(); {
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, /*border_offset=*/2, blockset_canvas_.DrawContextMenu();
map_blockset_loaded_); blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, /*border_offset=*/2,
if (blockset_canvas_.DrawTileSelector(32.0f)) { map_blockset_loaded_);
// Open the tile16 editor to the tile
auto tile_pos = blockset_canvas_.points().front(); if (blockset_canvas_.DrawTileSelector(32.0f)) {
int grid_x = static_cast<int>(tile_pos.x / 32); // Open the tile16 editor to the tile
int grid_y = static_cast<int>(tile_pos.y / 32); auto tile_pos = blockset_canvas_.points().front();
int id = grid_x + grid_y * 8; int grid_x = static_cast<int>(tile_pos.x / 32);
RETURN_IF_ERROR(tile16_editor_.set_tile16(id)); int grid_y = static_cast<int>(tile_pos.y / 32);
show_tile16_editor_ = true; int id = grid_x + grid_y * 8;
RETURN_IF_ERROR(tile16_editor_.set_tile16(id));
show_tile16_editor_ = true;
}
if (ImGui::IsItemClicked() && !blockset_canvas_.points().empty()) {
int x = blockset_canvas_.points().front().x / 32;
int y = blockset_canvas_.points().front().y / 32;
current_tile16_ = x + (y * 8);
}
blockset_canvas_.DrawGrid();
blockset_canvas_.DrawOverlay();
} }
if (ImGui::IsItemClicked() && !blockset_canvas_.points().empty()) {
int x = blockset_canvas_.points().front().x / 32;
int y = blockset_canvas_.points().front().y / 32;
current_tile16_ = x + (y * 8);
}
blockset_canvas_.DrawGrid();
blockset_canvas_.DrawOverlay();
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndGroup(); ImGui::EndGroup();
return absl::OkStatus(); return absl::OkStatus();
@@ -798,12 +807,14 @@ void OverworldEditor::DrawAreaGraphics() {
gui::BeginChildWithScrollbar("##AreaGraphicsScrollRegion"); gui::BeginChildWithScrollbar("##AreaGraphicsScrollRegion");
current_gfx_canvas_.DrawBackground(); current_gfx_canvas_.DrawBackground();
gui::EndPadding(); gui::EndPadding();
current_gfx_canvas_.DrawContextMenu(); {
current_gfx_canvas_.DrawBitmap(current_graphics_set_[current_map_], current_gfx_canvas_.DrawContextMenu();
/*border_offset=*/2, overworld_.is_loaded()); current_gfx_canvas_.DrawBitmap(current_graphics_set_[current_map_],
current_gfx_canvas_.DrawTileSelector(32.0f); /*border_offset=*/2, overworld_.is_loaded());
current_gfx_canvas_.DrawGrid(); current_gfx_canvas_.DrawTileSelector(32.0f);
current_gfx_canvas_.DrawOverlay(); current_gfx_canvas_.DrawGrid();
current_gfx_canvas_.DrawOverlay();
}
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndGroup(); ImGui::EndGroup();
} }