OverrideUnitFocusUI

Tracking Issue: #257

Tags: compatibility, events

This focus change allows mods to change the focus UI that the vanilla game uses to display Templar Focus. This effectively creates different types of Focus, even though the game does not know about this. For example, you can create a custom soldier class with its own type of focus, tracked with a UnitValue. This imposes a few limitations on the system:

  • A given unit only ever has a single "type" of focus. The rules for different focus types are expected to be so different from one another to make any conflicts a painful experience for modders and players. In particular, it means that this function should NOT be used to make any changes to the Templar Focus, as tempting as it may be.
  • This also includes an Effect of the name TemplarFocus or an Effect Class of the type XComGameState_Effect_TemplarFocus.

In order to add your custom focus types, there are two changes in XComGame you can use:

  • A new event hook for UIUnitFlag and UITacticalHUD_SoldierInfo: Documentation for that particular hook is directly below.
  • A change in X2AbilityCost_Focus: You may subclass that particular class and override all functions declared there (CanAfford, ApplyCost, PreviewFocusCost). This can be used to preview a cost for custom skills that consume focus. Again, make sure to not mix and match custom subclasses with the base class for any abilities.

OverrideUnitFocusUI event

Param Value
EventID OverrideUnitFocusUI
EventData XComLWTuple
EventSource XComGameState_Unit
NewGameState none

Tuple contents

Index Name Type Direction
0 bVisible bool inout
1 currentFocus int inout
2 maxFoxus int inout
3 color string inout
4 iconPath string inout
5 tooltipText string inout
6 focusLabel string inout

Listener template

static function EventListenerReturn OnOverrideUnitFocusUI(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackObject)
{
    local XComGameState_Unit SourceUnit;
    local XComLWTuple Tuple;
    local bool bVisible;
    local int currentFocus;
    local int maxFoxus;
    local string color;
    local string iconPath;
    local string tooltipText;
    local string focusLabel;

    SourceUnit = XComGameState_Unit(EventSource);
    Tuple = XComLWTuple(EventData);

    bVisible = Tuple.Data[0].b;
    currentFocus = Tuple.Data[1].i;
    maxFoxus = Tuple.Data[2].i;
    color = Tuple.Data[3].s;
    iconPath = Tuple.Data[4].s;
    tooltipText = Tuple.Data[5].s;
    focusLabel = Tuple.Data[6].s;

    // Your code here

    Tuple.Data[0].b = bVisible;
    Tuple.Data[1].i = currentFocus;
    Tuple.Data[2].i = maxFoxus;
    Tuple.Data[3].s = color;
    Tuple.Data[4].s = iconPath;
    Tuple.Data[5].s = tooltipText;
    Tuple.Data[6].s = focusLabel;

    return ELR_NoInterrupt;
}

Note that if bVisible == false, the rest will be ignored and will not have valid data in it.

Compatibility

If you override UIUnitFlag, your code may undo the HL's changes that support this feature in the UI. See the tracking issue for code samples.

Source code references