From fe5f7480888186473400f40003eb683e6db9fdaf Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Mon, 6 Jul 2020 01:39:31 -0400 Subject: [PATCH] gui2/unit_create: Address issue with variation+gender previews Instead of generating the unit preview from the gender variation attached to the unit type variation, we need to generate it from the unit type variation attached to the gender variation. I know this sounds really crazy, but it matches the behaviour in unit::advance_to(): // Adjust the new type for gender and variation. const unit_type& new_type = u_type.get_gender_unit_type(gender_).get_variation(variation_); This behaviour is also relied upon by at least one pre-existing add-on (After the Storm Episode 3, Demon Shapeshifter unit type). Without this patch, the preview display doesn't reflect gender variations at all when a non-default variation is selected. As a side-note, the fix also makes the logic in unit_create::update_displayed_type() simpler since we don't need to verify if the variation exists at all -- if it doesn't we just get the parent unit type back. --- src/gui/dialogs/unit_create.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/gui/dialogs/unit_create.cpp b/src/gui/dialogs/unit_create.cpp index 10cfb9e6dd4..2b8b8c4a48e 100644 --- a/src/gui/dialogs/unit_create.cpp +++ b/src/gui/dialogs/unit_create.cpp @@ -199,11 +199,9 @@ void unit_create::update_displayed_type() const const unit_type* ut = &units_[selected_row]->get_gender_unit_type(gender_); if(!variation_.empty()) { - const auto& variations = units_[selected_row]->variation_types(); - auto vi = variations.find(variation_); - if(vi != variations.end()) { - ut = &vi->second.get_gender_unit_type(gender_); - } + // This effectively translates to `ut = ut` if somehow variation_ does + // not refer to a variation that the unit type supports. + ut = &ut->get_variation(variation_); } find_widget(w, "unit_details", false).set_displayed_type(*ut);