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.
This commit is contained in:
Iris Morelle 2020-07-06 01:39:31 -04:00
parent c8a31df035
commit fe5f748088

View File

@ -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<unit_preview_pane>(w, "unit_details", false).set_displayed_type(*ut);