Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class X2EventListener_JediClass extends X2EventListener;
  2.  
  3. static function array<X2DataTemplate> CreateTemplates()
  4. {
  5.     local array<X2DataTemplate> Templates;
  6.  
  7.     Templates.AddItem(CreateListenerTemplate_OnOverrideUnitFocusUI());
  8.  
  9.     return Templates;
  10. }
  11.  
  12.  
  13. static function CHEventListenerTemplate CreateListenerTemplate_OnOverrideUnitFocusUI()
  14. {
  15.     local CHEventListenerTemplate Template;
  16.  
  17.     `CREATE_X2TEMPLATE(class'CHEventListenerTemplate', Template, 'JediClassOverrideUnitFocusUI');
  18.  
  19.     Template.RegisterInTactical = true;
  20.     Template.RegisterInStrategy = false;
  21.  
  22.     Template.AddCHEvent('OverrideUnitFocusUI', OnOverrideUnitFocusUI, ELD_Immediate);
  23.     `log("Register Event OverrideUnitFocusUI",, 'X2JediClassWOTC');
  24.  
  25.     return Template;
  26. }
  27.  
  28. static function EventListenerReturn OnOverrideUnitFocusUI(Object EventData, Object EventSource, XComGameState GameState, Name Event, Object CallbackData)
  29. {
  30.     local XComLWTuple Tuple;
  31.     local XComGameState_Unit UnitState;
  32.     local UnitValue CurrentForce, MaxForce;
  33.     local int Alignment, ColorInt;
  34.     local string BarColor;
  35.  
  36.     Tuple = XComLWTuple(EventData);
  37.     UnitState = XComGameState_Unit(EventSource);
  38.  
  39.     if (UnitState == none)
  40.     {
  41.         return ELR_NoInterrupt;
  42.     }
  43.  
  44.     if (!UnitState.GetUnitValue(class'X2Effect_JediForcePool_ByRank'.default.MaxForceName, MaxForce)) // GetUnitValue returns false if the unit did not already have the value
  45.     {
  46.         return ELR_NoInterrupt;
  47.     }
  48.    
  49.     UnitState.GetUnitValue(class'X2Effect_JediForcePool_ByRank'.default.CurrentForceName, CurrentForce);
  50.  
  51.     // GetLightSideModifier returns max(LightSidePoints, 0) so I can't use one number to set both colors
  52.     // GetDarkSideModifier returns dark side as a positive number, so make sure to abs(Alignment) before multiplying for blue
  53.     // 0x000000 is black, so we need to start with 0xFFFFFF and then subtract from the colors we don't want
  54.     // Start at full white and reduce by an amount equal to Alignment * 10
  55.     Alignment = class'JediClassHelper'.static.GetDarkSideModifier(UnitState);
  56.     ColorInt = Min(int(Abs(float(Alignment)) * 10), 255);
  57.     BarColor = Right(ToHex(255 - ColorInt), 2);
  58.  
  59.     if (Alignment > 0)
  60.         BarColor = "0xFF" $ BarColor $ BarColor; // if Alignment is positive, it's dark side points, so reduce non-red colors
  61.     else
  62.         BarColor = "0x" $ BarColor $ "FFFF"; // if Alignment is negative, it's light side points, so reduce red
  63.  
  64.     Tuple.Data[0].b = true; // bVisible
  65.     Tuple.Data[1].i = int(CurrentForce.fValue); // currentFocus
  66.     Tuple.Data[2].i = int(MaxForce.fValue); // maxFocus
  67.     Tuple.Data[3].s = BarColor; // color
  68.     Tuple.Data[4].s = "img:///JediClassUI.UIJediClass"; // iconPath
  69.     Tuple.Data[5].s = class'X2Effect_JediForcePool_ByRank'.default.ForceDescription; // tooltipText
  70.     Tuple.Data[6].s = class'X2Effect_JediForcePool_ByRank'.default.ForceLabel; // focusLabel
  71.  
  72.     return ELR_NoInterrupt;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement