11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
6- using Epic . OnlineServices . Presence ;
72using HarmonyLib ;
8- using TheOtherRoles . Utilities ;
3+ using Hazel ;
94using TMPro ;
105using UnityEngine ;
11- using static UnityEngine . UI . Button ;
126using UnityEngine . Events ;
13- using Hazel ;
7+ using static UnityEngine . UI . Button ;
148
15- namespace TheOtherRoles . CustomGameModes {
16- [ HarmonyPatch ]
17- class GameModePatches {
18- /*
19- Creates a button in the info pane in the lobby to cycle through the game modes of TOR.
20- */
21- [ HarmonyPatch ( typeof ( LobbyInfoPane ) , nameof ( LobbyInfoPane . Update ) ) ]
22- class LobbyInfoPanePatch {
9+ namespace TheOtherRoles . CustomGameModes ;
2310
24- private static GameObject gameModeButton = null ;
25- public static void Postfix ( LobbyInfoPane __instance ) {
26- if ( gameModeButton != null || ! AmongUsClient . Instance . AmHost ) { return ; }
11+ [ HarmonyPatch ]
12+ internal class GameModePatches
13+ {
14+ /*
15+ Creates a button in the info pane in the lobby to cycle through the game modes of TOR.
16+ */
17+ [ HarmonyPatch ( typeof ( LobbyInfoPane ) , nameof ( LobbyInfoPane . Update ) ) ]
18+ private class LobbyInfoPanePatch
19+ {
20+ private static GameObject gameModeButton ;
2721
28- var template = GameObject . Find ( "PRIVATE BUTTON" ) ;
29- var GameModeText = GameObject . Find ( "GameModeText" ) ;
30- if ( template == null || GameModeText == null ) { return ; }
31- gameModeButton = GameObject . Instantiate ( template , template . transform . parent ) ; //, GameModeText.transform);
32- gameModeButton . transform . localPosition = template . transform . localPosition + new Vector3 ( 0f , 0.65f , - 2f ) ;
33- gameModeButton . name = "TOR GameModeButton" ;
22+ public static void Postfix ( LobbyInfoPane __instance )
23+ {
24+ if ( gameModeButton != null || ! AmongUsClient . Instance . AmHost ) return ;
3425
35- var pButton = gameModeButton . GetComponent < PassiveButton > ( ) ;
36- pButton . buttonText . text = GameModeText . GetComponent < TextMeshPro > ( ) . text ;
37- pButton . OnClick . RemoveAllListeners ( ) ;
38- pButton . OnClick = new ButtonClickedEvent ( ) ;
39- __instance . StartCoroutine ( Effects . Lerp ( 0.1f , new Action < float > ( p => { pButton . buttonText . text = Helpers . cs ( Color . yellow , GameModeText . GetComponent < TextMeshPro > ( ) . text ) ; } ) ) ) ;
40- gameModeButton . transform . GetChild ( 1 ) . GetComponent < SpriteRenderer > ( ) . color = new Color ( 0.1f , 0.1f , 0.1f ) ;
41- gameModeButton . transform . GetChild ( 2 ) . GetComponent < SpriteRenderer > ( ) . color = new Color ( 0f , 0f , 0f ) ;
42- pButton . OnClick . AddListener ( ( Action ) ( ( ) =>
43- {
44- TORMapOptions . gameMode = ( CustomGamemodes ) ( ( int ) ( TORMapOptions . gameMode + 1 ) % Enum . GetNames ( typeof ( CustomGamemodes ) ) . Length ) ;
45- __instance . StartCoroutine ( Effects . Lerp ( 0.1f , new Action < float > ( p => { pButton . buttonText . text = Helpers . cs ( Color . yellow , GameModeText . GetComponent < TextMeshPro > ( ) . text ) ; } ) ) ) ;
46- MessageWriter writer = AmongUsClient . Instance . StartRpcImmediately ( PlayerControl . LocalPlayer . NetId , ( byte ) CustomRPC . ShareGamemode , Hazel . SendOption . Reliable , - 1 ) ;
47- writer . Write ( ( byte ) TORMapOptions . gameMode ) ;
48- AmongUsClient . Instance . FinishRpcImmediately ( writer ) ;
49- RPCProcedure . shareGamemode ( ( byte ) TORMapOptions . gameMode ) ;
50- } ) ) ;
51- pButton . OnMouseOut = new UnityEvent ( ) ;
52- pButton . OnMouseOver = new UnityEvent ( ) ;
53- pButton . OnMouseOver . AddListener ( ( Action ) ( ( ) => {
54- gameModeButton . transform . GetChild ( 1 ) . gameObject . SetActive ( true ) ;
55- gameModeButton . transform . GetChild ( 2 ) . gameObject . SetActive ( false ) ;
56- } ) ) ;
57- pButton . OnMouseOut . AddListener ( ( Action ) ( ( ) => {
58- gameModeButton . transform . GetChild ( 1 ) . gameObject . SetActive ( false ) ;
59- gameModeButton . transform . GetChild ( 2 ) . gameObject . SetActive ( true ) ;
60- } ) ) ;
26+ var template = GameObject . Find ( "PRIVATE BUTTON" ) ;
27+ var GameModeText = GameObject . Find ( "GameModeText" ) ;
28+ if ( template == null || GameModeText == null ) return ;
29+ gameModeButton = GameObject . Instantiate ( template , template . transform . parent ) ; //, GameModeText.transform);
30+ gameModeButton . transform . localPosition = template . transform . localPosition + new Vector3 ( 0f , 0.65f , - 2f ) ;
31+ gameModeButton . name = "TOR GameModeButton" ;
6132
62- }
33+ var pButton = gameModeButton . GetComponent < PassiveButton > ( ) ;
34+ pButton . buttonText . text = GameModeText . GetComponent < TextMeshPro > ( ) . text ;
35+ pButton . OnClick . RemoveAllListeners ( ) ;
36+ pButton . OnClick = new ButtonClickedEvent ( ) ;
37+ __instance . StartCoroutine ( Effects . Lerp ( 0.1f ,
38+ new Action < float > ( p =>
39+ {
40+ pButton . buttonText . text =
41+ Helpers . cs ( Color . yellow , GameModeText . GetComponent < TextMeshPro > ( ) . text ) ;
42+ } ) ) ) ;
43+ gameModeButton . transform . GetChild ( 1 ) . GetComponent < SpriteRenderer > ( ) . color = new Color ( 0.1f , 0.1f , 0.1f ) ;
44+ gameModeButton . transform . GetChild ( 2 ) . GetComponent < SpriteRenderer > ( ) . color = new Color ( 0f , 0f , 0f ) ;
45+ pButton . OnClick . AddListener ( ( Action ) ( ( ) =>
46+ {
47+ TORMapOptions . gameMode =
48+ ( CustomGamemodes ) ( ( int ) ( TORMapOptions . gameMode + 1 ) %
49+ Enum . GetNames ( typeof ( CustomGamemodes ) ) . Length ) ;
50+ __instance . StartCoroutine ( Effects . Lerp ( 0.1f ,
51+ new Action < float > ( p =>
52+ {
53+ pButton . buttonText . text =
54+ Helpers . cs ( Color . yellow , GameModeText . GetComponent < TextMeshPro > ( ) . text ) ;
55+ } ) ) ) ;
56+ var writer = AmongUsClient . Instance . StartRpcImmediately ( PlayerControl . LocalPlayer . NetId ,
57+ ( byte ) CustomRPC . ShareGamemode , SendOption . Reliable ) ;
58+ writer . Write ( ( byte ) TORMapOptions . gameMode ) ;
59+ AmongUsClient . Instance . FinishRpcImmediately ( writer ) ;
60+ RPCProcedure . shareGamemode ( ( byte ) TORMapOptions . gameMode ) ;
61+ } ) ) ;
62+ pButton . OnMouseOut = new UnityEvent ( ) ;
63+ pButton . OnMouseOver = new UnityEvent ( ) ;
64+ pButton . OnMouseOver . AddListener ( ( Action ) ( ( ) =>
65+ {
66+ gameModeButton . transform . GetChild ( 1 ) . gameObject . SetActive ( true ) ;
67+ gameModeButton . transform . GetChild ( 2 ) . gameObject . SetActive ( false ) ;
68+ } ) ) ;
69+ pButton . OnMouseOut . AddListener ( ( Action ) ( ( ) =>
70+ {
71+ gameModeButton . transform . GetChild ( 1 ) . gameObject . SetActive ( false ) ;
72+ gameModeButton . transform . GetChild ( 2 ) . gameObject . SetActive ( true ) ;
73+ } ) ) ;
6374 }
6475 }
65- }
76+ }
0 commit comments