1+ using DiskCardGame ;
2+ using HarmonyLib ;
3+ using System ;
4+ using UnityEngine ;
5+ using System . Linq ;
6+ using APIPlugin ;
7+ using System . Collections . Generic ;
8+ using GBC ;
9+ using System . Collections ;
10+
11+ namespace InscryptionAPI . AscensionScreens
12+ {
13+ [ HarmonyPatch ]
14+ public static class AscensionScreenManager
15+ {
16+ internal static List < Type > registeredScreens = new List < Type > ( ) ;
17+
18+ internal static Dictionary < AscensionMenuScreens . Screen , AscensionRunSetupScreenBase > screens ;
19+
20+ internal static AscensionMenuScreens . Screen initialScreen = AscensionMenuScreens . Screen . JournalSummary ;
21+
22+ internal const int CUSTOM_SCREEN_START = 100 ;
23+
24+ private static string challengeScreenHoverText = "START RUN" ;
25+
26+ public static void AdvanceScreenQueue ( bool forward = true )
27+ {
28+
29+ }
30+
31+ public static void RegisterScreen < T > ( ) where T : AscensionRunSetupScreenBase
32+ {
33+ registeredScreens . Add ( typeof ( T ) ) ;
34+ }
35+
36+ private static AscensionScreenSort . Direction GetPreferredDirection ( Type t )
37+ {
38+ AscensionScreenSort sortAttr = Attribute . GetCustomAttribute ( t , typeof ( AscensionScreenSort ) ) as AscensionScreenSort ;
39+ if ( sortAttr == null )
40+ return AscensionScreenSort . Direction . NoPreference ;
41+ else
42+ return sortAttr . preferredDirection ;
43+ }
44+
45+ public static void InitializeAllScreens ( )
46+ {
47+ // Sort the screens
48+ registeredScreens . Sort ( ( a , b ) => ( int ) GetPreferredDirection ( a ) - ( int ) GetPreferredDirection ( b ) ) ;
49+
50+ // Build screens
51+ screens = new Dictionary < AscensionMenuScreens . Screen , AscensionRunSetupScreenBase > ( ) ;
52+
53+ AscensionMenuScreens . Screen previousScreen = AscensionMenuScreens . Screen . SelectChallenges ;
54+ AscensionMenuScreens . Screen currentScreen = ( AscensionMenuScreens . Screen ) CUSTOM_SCREEN_START ;
55+ AscensionMenuScreens . Screen nextScreen = ( AscensionMenuScreens . Screen ) ( CUSTOM_SCREEN_START + 1 ) ;
56+ initialScreen = currentScreen ;
57+ for ( int i = 0 ; i < registeredScreens . Count ; i ++ )
58+ {
59+ Type screenType = registeredScreens [ i ] ;
60+
61+ if ( i == registeredScreens . Count - 1 ) // the last one
62+ nextScreen = AscensionMenuScreens . Screen . SelectChallengesConfirm ;
63+
64+ try
65+ {
66+ AscensionRunSetupScreenBase screen = AscensionRunSetupScreenBase . BuildScreen ( screenType , previousScreen , nextScreen ) ;
67+
68+ screens . Add ( currentScreen , screen ) ;
69+
70+ previousScreen = currentScreen ;
71+ currentScreen = nextScreen ;
72+ nextScreen = ( AscensionMenuScreens . Screen ) ( ( int ) nextScreen + 1 ) ;
73+ } catch ( Exception ex )
74+ {
75+ Plugin . Log . LogError ( ex ) ;
76+ }
77+ }
78+
79+ if ( screens . Count == 0 )
80+ return ;
81+
82+ // Now make another pass through the screens and set the behavior of hovering over the continue and back buttons
83+
84+ previousScreen = AscensionMenuScreens . Screen . SelectChallenges ;
85+ currentScreen = ( AscensionMenuScreens . Screen ) CUSTOM_SCREEN_START ;
86+ nextScreen = ( AscensionMenuScreens . Screen ) ( CUSTOM_SCREEN_START + 1 ) ;
87+
88+ // Set the hover text of the challenge screen to be the title of the first custom screen
89+ challengeScreenHoverText = screens [ currentScreen ] . headerText ;
90+
91+ for ( int i = 0 ; i < screens . Count ; i ++ )
92+ {
93+ AscensionRunSetupScreenBase cur = screens [ currentScreen ] ;
94+
95+ string prevText = screens . ContainsKey ( previousScreen ) ? screens [ previousScreen ] . headerText : "SELECT CHALLENGES" ;
96+ string nextText = screens . ContainsKey ( nextScreen ) ? screens [ nextScreen ] . headerText : "START RUN" ;
97+
98+ Action < MainInputInteractable > prevHoverAction = ( MainInputInteractable i ) => cur . DisplayMessage ( Localization . ToUpper ( Localization . Translate ( prevText ) ) ) ;
99+ Action < MainInputInteractable > nextHoverAction = ( MainInputInteractable i ) => cur . DisplayMessage ( Localization . ToUpper ( Localization . Translate ( nextText ) ) ) ;
100+ Action < MainInputInteractable > unHoverAction = ( MainInputInteractable i ) => cur . ClearMessage ( ) ;
101+
102+ cur . backButton . CursorEntered = ( Action < MainInputInteractable > ) Delegate . Combine ( cur . backButton . CursorEntered , prevHoverAction ) ;
103+ cur . backButton . CursorExited = ( Action < MainInputInteractable > ) Delegate . Combine ( cur . backButton . CursorExited , unHoverAction ) ;
104+ cur . continueButton . CursorEntered = ( Action < MainInputInteractable > ) Delegate . Combine ( cur . continueButton . CursorEntered , nextHoverAction ) ;
105+ cur . continueButton . CursorExited = ( Action < MainInputInteractable > ) Delegate . Combine ( cur . continueButton . CursorExited , unHoverAction ) ;
106+
107+ previousScreen = currentScreen ;
108+ currentScreen = nextScreen ;
109+ nextScreen = ( AscensionMenuScreens . Screen ) ( ( int ) nextScreen + 1 ) ;
110+ }
111+ }
112+
113+ // This patches the confirmation button of the challenge screen to ensure it starts the queue
114+ [ HarmonyPatch ( typeof ( AscensionChallengeScreen ) , "OnContinuePressed" ) ]
115+ [ HarmonyPrefix ]
116+ public static bool TransitionToSideDeckScreen ( ref AscensionChallengeScreen __instance )
117+ {
118+ if ( screens == null || screens . Count == 0 )
119+ return true ; // No custom screens; execute the original method
120+
121+ AscensionMenuScreens . Instance . SwitchToScreen ( initialScreen ) ;
122+ return false ;
123+ }
124+
125+ [ HarmonyPatch ( typeof ( AscensionMenuScreens ) , "ScreenSwitchSequence" ) ]
126+ [ HarmonyPostfix ]
127+ public static IEnumerator SwitchToScreen ( IEnumerator sequenceEvent , AscensionMenuScreens . Screen screen )
128+ {
129+ while ( sequenceEvent . MoveNext ( ) )
130+ yield return sequenceEvent . Current ;
131+
132+ yield return new WaitForSeconds ( 0.05f ) ;
133+
134+ if ( AscensionScreenManager . screens . ContainsKey ( screen ) )
135+ AscensionScreenManager . screens [ screen ] . gameObject . SetActive ( true ) ;
136+
137+ yield break ;
138+ }
139+
140+ [ HarmonyPatch ( typeof ( AscensionMenuScreens ) , "ConfigurePostGameScreens" ) ]
141+ [ HarmonyPostfix ]
142+ public static void InitializeScreensOnStart ( )
143+ {
144+ InitializeAllScreens ( ) ;
145+ }
146+
147+ [ HarmonyPatch ( typeof ( AscensionMenuScreens ) , "DeactivateAllScreens" ) ]
148+ [ HarmonyPostfix ]
149+ public static void DeactivateAllCustomScreens ( )
150+ {
151+ if ( screens != null && screens . Count > 0 )
152+ foreach ( AscensionRunSetupScreenBase screenbase in screens . Values )
153+ if ( screenbase != null && screenbase . gameObject != null )
154+ screenbase . gameObject . SetActive ( false ) ;
155+ }
156+
157+ [ HarmonyPatch ( typeof ( AscensionChallengeScreen ) , "OnContinueCursorEnter" ) ]
158+ [ HarmonyPrefix ]
159+ public static bool HoverTextFirstCustomScreen ( ref AscensionChallengeScreen __instance )
160+ {
161+ string line = Localization . Translate ( challengeScreenHoverText ) ;
162+ __instance . challengeDisplayer . DisplayText ( "" , line , "" , false ) ;
163+ return false ;
164+ }
165+ }
166+ }
0 commit comments