Add RefreshOverworldMap, RefreshMapPalette, RefreshMapProperties
This commit is contained in:
@@ -348,30 +348,142 @@ void OverworldEditor::DrawOverworldProperties() {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void OverworldEditor::RefreshChildMap(int map_index) {
|
||||||
|
overworld_.mutable_overworld_map(map_index)->LoadAreaGraphics();
|
||||||
|
status_ = overworld_.mutable_overworld_map(map_index)->BuildTileset();
|
||||||
|
PRINT_IF_ERROR(status_);
|
||||||
|
status_ = overworld_.mutable_overworld_map(map_index)->BuildTiles16Gfx(
|
||||||
|
overworld_.tiles16().size());
|
||||||
|
PRINT_IF_ERROR(status_);
|
||||||
|
OWBlockset blockset;
|
||||||
|
if (current_world_ == 0) {
|
||||||
|
blockset = overworld_.map_tiles().light_world;
|
||||||
|
} else if (current_world_ == 1) {
|
||||||
|
blockset = overworld_.map_tiles().dark_world;
|
||||||
|
} else {
|
||||||
|
blockset = overworld_.map_tiles().special_world;
|
||||||
|
}
|
||||||
|
maps_bmp_[map_index].set_data(
|
||||||
|
overworld_.mutable_overworld_map(map_index)->BitmapData());
|
||||||
|
status_ = overworld_.mutable_overworld_map(map_index)->BuildBitmap(blockset);
|
||||||
|
PRINT_IF_ERROR(status_);
|
||||||
|
rom()->UpdateBitmap(&maps_bmp_[map_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverworldEditor::RefreshOverworldMap() {
|
||||||
|
std::vector<std::future<void>> futures;
|
||||||
|
|
||||||
|
auto refresh_map_async = [this](int map_index) {
|
||||||
|
RefreshChildMap(map_index);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (overworld_.overworld_map(current_map_)->IsLargeMap()) {
|
||||||
|
// We need to update the map and its siblings if it's a large map
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
int sibling_index = overworld_.overworld_map(current_map_)->Parent() + i;
|
||||||
|
if (i >= 2) {
|
||||||
|
sibling_index += 6;
|
||||||
|
}
|
||||||
|
futures.push_back(
|
||||||
|
std::async(std::launch::async, refresh_map_async, sibling_index));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
futures.push_back(
|
||||||
|
std::async(std::launch::async, refresh_map_async, current_map_));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &each : futures) {
|
||||||
|
each.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Palette throws out of bounds error unexpectedly.
|
||||||
|
void OverworldEditor::RefreshMapPalette() {
|
||||||
|
std::vector<std::future<void>> futures;
|
||||||
|
|
||||||
|
auto refresh_palette_async = [this](int map_index) {
|
||||||
|
overworld_.mutable_overworld_map(map_index)->LoadPalette();
|
||||||
|
maps_bmp_[map_index].ApplyPalette(
|
||||||
|
*overworld_.mutable_overworld_map(map_index)
|
||||||
|
->mutable_current_palette());
|
||||||
|
rom()->UpdateBitmap(&maps_bmp_[map_index]);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (overworld_.overworld_map(current_map_)->IsLargeMap()) {
|
||||||
|
// We need to update the map and its siblings if it's a large map
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
int sibling_index = overworld_.overworld_map(current_map_)->Parent() + i;
|
||||||
|
if (i >= 2) {
|
||||||
|
sibling_index += 6;
|
||||||
|
}
|
||||||
|
futures.push_back(
|
||||||
|
std::async(std::launch::async, refresh_palette_async, sibling_index));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
futures.push_back(
|
||||||
|
std::async(std::launch::async, refresh_palette_async, current_map_));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &each : futures) {
|
||||||
|
each.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverworldEditor::RefreshMapProperties() {
|
||||||
|
auto ¤t_ow_map = *overworld_.mutable_overworld_map(current_map_);
|
||||||
|
if (current_ow_map.IsLargeMap()) {
|
||||||
|
// We need to copy the properties from the parent map to the children
|
||||||
|
for (int i = 1; i < 4; i++) {
|
||||||
|
int sibling_index = current_ow_map.Parent() + i;
|
||||||
|
if (i >= 2) {
|
||||||
|
sibling_index += 6;
|
||||||
|
}
|
||||||
|
auto &map = *overworld_.mutable_overworld_map(sibling_index);
|
||||||
|
map.set_area_graphics(current_ow_map.area_graphics());
|
||||||
|
map.set_area_palette(current_ow_map.area_palette());
|
||||||
|
map.set_sprite_graphics(game_state_,
|
||||||
|
current_ow_map.sprite_graphics(game_state_));
|
||||||
|
map.set_sprite_palette(game_state_,
|
||||||
|
current_ow_map.sprite_palette(game_state_));
|
||||||
|
map.set_message_id(current_ow_map.message_id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OverworldEditor::DrawOverworldMapSettings() {
|
void OverworldEditor::DrawOverworldMapSettings() {
|
||||||
if (BeginTable(kOWMapTable.data(), 7, kOWMapFlags, ImVec2(0, 0), -1)) {
|
if (BeginTable(kOWMapTable.data(), 8, kOWMapFlags, ImVec2(0, 0), -1)) {
|
||||||
for (const auto &name : {"##1stCol", "##gfxCol", "##palCol", "##sprgfxCol",
|
for (const auto &name :
|
||||||
"##sprpalCol", "##msgidCol", "##2ndCol"})
|
{"##mapIdCol", "##1stCol", "##gfxCol", "##palCol", "##sprgfxCol",
|
||||||
|
"##sprpalCol", "##msgidCol", "##2ndCol"})
|
||||||
ImGui::TableSetupColumn(name);
|
ImGui::TableSetupColumn(name);
|
||||||
|
|
||||||
|
TableNextColumn();
|
||||||
|
ImGui::Text("Map ID: %#x", current_map_);
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
ImGui::SetNextItemWidth(120.f);
|
ImGui::SetNextItemWidth(120.f);
|
||||||
ImGui::Combo("##world", ¤t_world_, kWorldList.data(), 3);
|
ImGui::Combo("##world", ¤t_world_, kWorldList.data(), 3);
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
gui::InputHexByte(
|
if (gui::InputHexByte("Gfx",
|
||||||
"Gfx",
|
overworld_.mutable_overworld_map(current_map_)
|
||||||
overworld_.mutable_overworld_map(current_map_)->mutable_area_graphics(),
|
->mutable_area_graphics(),
|
||||||
kInputFieldSize);
|
kInputFieldSize)) {
|
||||||
|
RefreshMapProperties();
|
||||||
|
RefreshOverworldMap();
|
||||||
|
}
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
gui::InputHexByte(
|
if (gui::InputHexByte("Palette",
|
||||||
"Palette",
|
overworld_.mutable_overworld_map(current_map_)
|
||||||
overworld_.mutable_overworld_map(current_map_)->mutable_area_palette(),
|
->mutable_area_palette(),
|
||||||
kInputFieldSize);
|
kInputFieldSize)) {
|
||||||
|
RefreshMapProperties();
|
||||||
|
RefreshMapPalette();
|
||||||
|
}
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ class OverworldEditor : public Editor,
|
|||||||
absl::Status DrawToolset();
|
absl::Status DrawToolset();
|
||||||
void DrawOverworldMapSettings();
|
void DrawOverworldMapSettings();
|
||||||
|
|
||||||
|
void RefreshChildMap(int i);
|
||||||
|
void RefreshOverworldMap();
|
||||||
|
void RefreshMapPalette();
|
||||||
|
void RefreshMapProperties();
|
||||||
|
|
||||||
void DrawOverworldProperties();
|
void DrawOverworldProperties();
|
||||||
|
|
||||||
void DrawOverworldEntrances(ImVec2 canvas_p, ImVec2 scrolling);
|
void DrawOverworldEntrances(ImVec2 canvas_p, ImVec2 scrolling);
|
||||||
|
|||||||
Reference in New Issue
Block a user