@@ -56,7 +56,7 @@ public static class StackAbilityIcons
5656
5757 private static Sprite GetGBCNumberSprite ( int number )
5858 {
59- var stackGBC = "stack_gbc.png" ;
59+ string stackGBC = "stack_gbc.png" ;
6060 if ( ! PatchPlugin . act2StackIconType . Value )
6161 stackGBC = "stack_gbc_alt.png" ;
6262
@@ -101,13 +101,6 @@ private static Color[] LEFT_BORDER
101101 private static readonly Dictionary < string , Texture2D > patchedTexture = new ( ) ;
102102 private static readonly Dictionary < Ability , Tuple < Vector2Int , int > > patchLocations = new ( ) ;
103103
104- [ HarmonyPatch ( typeof ( CardAbilityIcons ) , "GetDistinctShownAbilities" ) ]
105- [ HarmonyPostfix ]
106- private static void ClearStackableIcons ( ref List < Ability > __result , CardInfo info , List < CardModificationInfo > mods , List < Ability > hiddenAbilities )
107- {
108- __result = __result . Distinct ( ) . ToList ( ) ;
109- }
110-
111104 private static Vector2Int FindMatchingOnesDigit ( Texture2D searchTex , bool normalSize = true )
112105 {
113106 Texture2D onesTexture = normalSize ? NUMBER_TEXTURES [ 1 ] : MEDIUM_NUMBER_TEXTURES [ 1 ] ;
@@ -301,6 +294,18 @@ private static Texture2D PatchTexture(Ability ability, int count)
301294 return newTexture ;
302295 }
303296
297+ [ HarmonyPatch ( typeof ( CardAbilityIcons ) , "GetDistinctShownAbilities" ) ]
298+ [ HarmonyPostfix ]
299+ private static void ClearStackableIcons ( ref List < Ability > __result , CardInfo info , List < CardModificationInfo > mods , List < Ability > hiddenAbilities )
300+ {
301+ int preDistinctCount = __result . Count ;
302+ __result = __result . Distinct ( ) . ToList ( ) ;
303+ if ( PatchPlugin . doubleStackSplit . Value && __result . Count == 1 && preDistinctCount == 2 && AbilitiesUtil . GetInfo ( __result [ 0 ] ) . canStack )
304+ {
305+ __result . Add ( __result [ 0 ] ) ;
306+ }
307+ }
308+
304309 [ HarmonyPatch ( typeof ( AbilityIconInteractable ) , "AssignAbility" ) ]
305310 [ HarmonyPostfix ]
306311 private static void AddIconNumber ( Ability ability , CardInfo info , PlayableCard card , ref AbilityIconInteractable __instance )
@@ -312,12 +317,12 @@ private static void AddIconNumber(Ability ability, CardInfo info, PlayableCard c
312317 // Find all abilities on the card
313318 // Replace all of the textures where it stacks with a texture showing that it stacks
314319 // Okay, go through each ability on the card and see how many instances it has.
315- List < Ability > baseAbilities = new ( info . Abilities ) ;
316320 int ? count = null ;
321+ List < Ability > baseAbilities = new ( info . Abilities ) ;
322+ AbilityInfo ai = AbilityManager . AllAbilityInfos . AbilityByID ( ability ) ;
317323 if ( card != null )
318324 {
319- baseAbilities . AddRange ( AbilitiesUtil . GetAbilitiesFromMods ( card . TemporaryMods ) ) ;
320- AbilityInfo ai = AbilityManager . AllAbilityInfos . AbilityByID ( ability ) ;
325+ baseAbilities . AddRange ( AbilitiesUtil . GetAbilitiesFromMods ( card . TemporaryMods /*.Where(x => !x.fromTotem && (!x.fromCardMerge || PatchPlugin.configMergeOnBottom.Value)).ToList()*/ ) ) ;
321326 if ( ai . GetHideSingleStacks ( ) )
322327 {
323328 for ( int i = 0 ; i < card . Status . hiddenAbilities . Count ( x => x == ability ) ; i ++ )
@@ -333,10 +338,15 @@ private static void AddIconNumber(Ability ability, CardInfo info, PlayableCard c
333338 }
334339
335340 count ??= baseAbilities . Count ( ab => ab == ability ) ;
336- // Debug.Log($"[{AbilitiesUtil.GetInfo(ability).rulebookName}] {count}");
341+ Debug . Log ( $ "[{ AbilitiesUtil . GetInfo ( ability ) . rulebookName } ] { count } { baseAbilities . Count } ") ;
337342
338- if ( count > 1 ) // We need to add an override
339- __instance . SetIcon ( PatchTexture ( ability , ( int ) count ) ) ;
343+ if ( count > 1 ) // we have a stack and need to add an override
344+ {
345+ if ( PatchPlugin . doubleStackSplit . Value && count == 2 && count == baseAbilities . Count )
346+ __instance . SetIcon ( __instance . LoadIcon ( info , ai , card != null && card . OpponentCard ) ) ; //RenderSameSigilTwice(__instance, ai, info, card);
347+ else
348+ __instance . SetIcon ( PatchTexture ( ability , ( int ) count ) ) ;
349+ }
340350 }
341351
342352 [ HarmonyPatch ( typeof ( PixelCardAbilityIcons ) , "DisplayAbilities" , new Type [ ] { typeof ( List < Ability > ) , typeof ( PlayableCard ) } ) ]
@@ -348,30 +358,62 @@ private static bool PatchPixelCardStacks(PixelCardAbilityIcons __instance, List<
348358
349359 public static bool RenderPixelAbilityStacks ( PixelCardAbilityIcons __instance , List < Ability > abilities , PlayableCard card )
350360 {
351- List < Tuple < Ability , int > > grps = abilities . Distinct ( ) . Select ( a => new Tuple < Ability , int > ( a , abilities . Where ( ab => ab == a ) . Count ( ) ) ) . ToList ( ) ;
352361 List < GameObject > abilityIconGroups = __instance . abilityIconGroups ;
353362 if ( abilityIconGroups . Count == 0 )
354363 return false ;
355364
356365 foreach ( GameObject gameObject in abilityIconGroups )
357366 gameObject . gameObject . SetActive ( false ) ;
358367
359- if ( grps . Count > 0 && grps . Count - 1 < abilityIconGroups . Count )
368+ List < Ability > allDisplayableAbilities = new ( abilities ) ;
369+ if ( card != null )
360370 {
371+ allDisplayableAbilities . AddRange ( AbilitiesUtil . GetAbilitiesFromMods ( card . TemporaryMods ) ) ;
372+ }
373+
374+ List < Tuple < Ability , int > > grps = allDisplayableAbilities . Distinct ( ) . Select ( a => new Tuple < Ability , int > ( a , abilities . Where ( ab => ab == a ) . Count ( ) ) ) . ToList ( ) ;
375+
376+ if ( grps . Count > 0 && grps . Count - 1 < abilityIconGroups . Count ) // if there are displayable sigils and there are enough icon groups
377+ {
378+ // if there is only 1 ability and there are two stacks of it, render it twice
379+ if ( PatchPlugin . doubleStackSplit . Value && grps . Count == 1 && grps [ 0 ] . Item2 == 2 )
380+ {
381+ PatchPlugin . Logger . LogDebug ( $ "Displaying { grps [ 0 ] . Item1 } twice") ;
382+ grps [ 0 ] = new Tuple < Ability , int > ( grps [ 0 ] . Item1 , 1 ) ;
383+ grps . Add ( grps [ 0 ] ) ;
384+ }
385+
361386 GameObject iconGroup = abilityIconGroups [ grps . Count - 1 ] ;
362387 iconGroup . gameObject . SetActive ( true ) ;
363388
364- List < SpriteRenderer > componentsInChildren = new ( ) ;
389+ List < SpriteRenderer > abilityRenderers = new ( ) ;
365390 foreach ( Transform child in iconGroup . transform )
366- componentsInChildren . Add ( child . gameObject . GetComponent < SpriteRenderer > ( ) ) ;
391+ abilityRenderers . Add ( child . gameObject . GetComponent < SpriteRenderer > ( ) ) ;
367392
368- componentsInChildren . RemoveAll ( sr => sr == null ) ;
393+ abilityRenderers . RemoveAll ( sr => sr == null ) ;
369394
370- for ( int i = 0 ; i < componentsInChildren . Count ; i ++ )
395+ CardInfo cardInfo = card ? . Info ?? __instance . GetComponentInParent < DiskCardGame . Card > ( ) ? . Info ;
396+ for ( int i = 0 ; i < abilityRenderers . Count ; i ++ )
371397 {
372- SpriteRenderer abilityRenderer = componentsInChildren [ i ] ;
398+ SpriteRenderer abilityRenderer = abilityRenderers [ i ] ;
373399 AbilityInfo abilityInfo = AbilitiesUtil . GetInfo ( grps [ i ] . Item1 ) ;
374- CardInfo cardInfo = card ? . Info ?? __instance . GetComponentInParent < DiskCardGame . Card > ( ) ? . Info ;
400+ int stackCount = grps [ i ] . Item2 ;
401+ if ( card != null )
402+ {
403+ if ( abilityInfo . GetHideSingleStacks ( ) )
404+ {
405+ for ( int j = 0 ; j < card . Status . hiddenAbilities . Count ( x => x == grps [ i ] . Item1 ) ; j ++ )
406+ {
407+ stackCount -- ;
408+ }
409+ }
410+ else if ( card . Status . hiddenAbilities . Contains ( grps [ i ] . Item1 ) )
411+ stackCount -= allDisplayableAbilities . Count ( x => x == grps [ i ] . Item1 ) ;
412+
413+ if ( abilityInfo . IsShieldAbility ( ) )
414+ stackCount = card . GetShieldBehaviour ( grps [ i ] . Item1 ) ? . NumShields ?? 0 ;
415+ }
416+
375417 abilityRenderer . sprite = abilityInfo . activated ? new ( ) : OverridePixelSprite ( abilityInfo , cardInfo , card ) ;
376418 if ( abilityInfo . flipYIfOpponent && card != null && card . OpponentCard )
377419 {
@@ -383,7 +425,8 @@ public static bool RenderPixelAbilityStacks(PixelCardAbilityIcons __instance, Li
383425 else
384426 abilityRenderer . flipY = false ;
385427
386- AddStackCount ( abilityRenderer , grps [ i ] ) ;
428+ PatchPlugin . Logger . LogDebug ( $ "Pixel Stacks: [{ grps [ i ] . Item1 } ] Count: { stackCount } ") ;
429+ AddStackCount ( abilityRenderer , grps [ i ] . Item1 , stackCount ) ;
387430 }
388431 }
389432 __instance . conduitIcon . SetActive ( abilities . Exists ( ( Ability x ) => AbilitiesUtil . GetInfo ( x ) . conduit ) ) ;
@@ -402,14 +445,14 @@ public static bool RenderPixelAbilityStacks(PixelCardAbilityIcons __instance, Li
402445
403446 return false ;
404447 }
405- private static void AddStackCount ( SpriteRenderer abilityRenderer , Tuple < Ability , int > grpsI )
448+ private static void AddStackCount ( SpriteRenderer abilityRenderer , Ability ability , int count )
406449 {
407450 // And now my custom code to add the ability counter if we need to
408451 Transform countTransform = abilityRenderer . transform . Find ( "Count" ) ;
409452
410453 if ( countTransform == null )
411454 {
412- if ( grpsI . Item2 <= 1 )
455+ if ( count <= 1 )
413456 return ;
414457
415458 GameObject counter = new ( ) ;
@@ -428,17 +471,18 @@ private static void AddStackCount(SpriteRenderer abilityRenderer, Tuple<Ability,
428471 countTransform = counter . transform ;
429472 }
430473
431- if ( grpsI . Item2 <= 1 )
474+ if ( count <= 1 )
432475 countTransform . gameObject . SetActive ( false ) ;
433476 else
434477 {
435478 countTransform . gameObject . SetActive ( true ) ;
436- Debug . Log ( $ "countTransform { grpsI . Item2 - 1 } ") ;
437- countTransform . gameObject . GetComponent < SpriteRenderer > ( ) . sprite = GBC_NUMBER_SPRITES [ grpsI . Item2 - 1 ] ;
479+ Debug . Log ( $ "countTransform [ { count - 1 } ] ") ;
480+ countTransform . gameObject . GetComponent < SpriteRenderer > ( ) . sprite = GBC_NUMBER_SPRITES [ count - 1 ] ;
438481 }
439482 }
440483 private static Sprite OverridePixelSprite ( AbilityInfo abilityInfo , CardInfo cardInfo , PlayableCard card )
441484 {
485+ // countdown numbers for evolve and transformer
442486 if ( cardInfo != null && ( abilityInfo . ability == Ability . Evolve || abilityInfo . ability == Ability . Transformer ) )
443487 {
444488 int turnsInPlay = card ? . GetComponentInChildren < Evolve > ( ) ? . numTurnsInPlay ?? 0 ;
@@ -457,7 +501,7 @@ private static Sprite OverridePixelSprite(AbilityInfo abilityInfo, CardInfo card
457501 return TextureHelper . ConvertTexture ( texture , TextureHelper . SpriteType . PixelAbilityIcon ) ;
458502 }
459503
460- if ( card && card . RenderInfo . overriddenAbilityIcons . ContainsKey ( abilityInfo . ability ) )
504+ if ( card != null && card . RenderInfo . overriddenAbilityIcons . ContainsKey ( abilityInfo . ability ) )
461505 {
462506 card . RenderInfo . overriddenAbilityIcons . TryGetValue ( abilityInfo . ability , out Texture texture ) ;
463507
0 commit comments