Skip to content

Commit

Permalink
gui2/unit_create: Address issue with variation+gender previews
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irydacea committed Jul 9, 2020
1 parent c8a31df commit fe5f748
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/gui/dialogs/unit_create.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit fe5f748

Please sign in to comment.