X2CommunityCore / X2WOTCCommunityHighlander

https://steamcommunity.com/workshop/filedetails/?id=1134256495
MIT License
60 stars 68 forks source link

ShowPromotionUI casts to subclasses of UIArmory_Promotion #1356

Closed Tedster59 closed 1 month ago

Tedster59 commented 2 months ago

XComHQPresentationLayer contains the following function:

  function ShowPromotionUI(StateObjectReference UnitRef, optional bool bInstantTransition)
  {
    local UIArmory_Promotion PromotionUI;
    local XComGameState_Unit UnitState;

    UnitState = XComGameState_Unit(`XCOMHISTORY.GetGameStateForObjectID(UnitRef.ObjectID));

    // Start Issue #600: Replaced class literals with the local variables
    if (UnitState.IsResistanceHero() || ScreenStack.IsInStack(class'UIFacility_TrainingCenter'))
        PromotionUI = UIArmory_PromotionHero(ScreenStack.Push(
            Spawn(TriggerOverridePromotionUIClass(eCHLPST_Hero), self), Get3DMovie()));
    else if (UnitState.GetSoldierClassTemplateName() == 'PsiOperative')
        PromotionUI = UIArmory_PromotionPsiOp(ScreenStack.Push(
            Spawn(TriggerOverridePromotionUIClass(eCHLPST_PsiOp), self), Get3DMovie()));
    else
        PromotionUI = UIArmory_Promotion(ScreenStack.Push(
            Spawn(TriggerOverridePromotionUIClass(eCHLPST_Standard), self), Get3DMovie()));
    // End Issue #600

    PromotionUI.InitPromotion(UnitRef, bInstantTransition);
  }

While we fire an override event to allow mods to change the promotion UI, it is then casted back into UIArmory_PromotionHero, UIArmory_PromotionPsiOp, or UIArmory_Promotion depending on the type of unit. This means that changing the screen type for Psi Ops or Hero units will cause issues if the screen is not a subclass of the class being casted.

For example, trying to allow Psi Operatives to use Community Promotion Screen causes the screen to not initialize because it is being casted to UIArmory_PromotionPsiOp

image

Proposed fix: Change all these casts to the basic UIArmory_Promotion class instead. Tested and working for Psi Operative.

image-1