1+ using System . IO ;
2+ using Steamworks ;
3+ using UnityEngine ;
4+ using ButtonStyle = SteamInputFixMod . ModConfig . StyleConfig . ButtonStyle ;
5+
6+ namespace SteamInputFixMod
7+ {
8+ internal abstract class ButtonStyleHandler
9+ {
10+ private static ButtonStyleHandler _currentHandler ;
11+
12+ public abstract Sprite GetSprite ( string actionString , bool isPauseAction ) ;
13+
14+ public static ButtonStyleHandler Get ( )
15+ {
16+ return _currentHandler ;
17+ }
18+
19+ public static void OnPreferredStyleChanged ( object newPreferredStyle )
20+ {
21+ var style = ( ButtonStyle ) newPreferredStyle ;
22+ switch ( style )
23+ {
24+ case ButtonStyle . SlimeRancher :
25+ _currentHandler = new SlimeRancherButtonStyleHandler ( ) ;
26+ break ;
27+ case ButtonStyle . Steam :
28+ _currentHandler = new SteamButtonStyleHandler ( ) ;
29+ break ;
30+ }
31+ }
32+
33+ public EControllerActionOrigin ReassignOriginIfNeeded ( EControllerActionOrigin oldOrigin )
34+ {
35+ switch ( oldOrigin )
36+ {
37+ // Nintendo Switch
38+ case EControllerActionOrigin . k_EControllerActionOrigin_Switch_A :
39+ return EControllerActionOrigin . k_EControllerActionOrigin_Switch_B ;
40+
41+ case EControllerActionOrigin . k_EControllerActionOrigin_Switch_B :
42+ return EControllerActionOrigin . k_EControllerActionOrigin_Switch_A ;
43+
44+ case EControllerActionOrigin . k_EControllerActionOrigin_Switch_X :
45+ return EControllerActionOrigin . k_EControllerActionOrigin_Switch_Y ;
46+
47+ case EControllerActionOrigin . k_EControllerActionOrigin_Switch_Y :
48+ return EControllerActionOrigin . k_EControllerActionOrigin_Switch_X ;
49+
50+ default :
51+ return oldOrigin ;
52+ }
53+ }
54+
55+ public Sprite LoadNewSprite ( string FilePath , float PixelsPerUnit = 100.0f ,
56+ SpriteMeshType spriteType = SpriteMeshType . Tight )
57+ {
58+ // Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference
59+
60+ var SpriteTexture = LoadTexture ( FilePath ) ;
61+ var NewSprite = Sprite . Create ( SpriteTexture , new Rect ( 0 , 0 , SpriteTexture . width , SpriteTexture . height ) ,
62+ new Vector2 ( 0 , 0 ) , PixelsPerUnit , 0 , spriteType ) ;
63+
64+ return NewSprite ;
65+ }
66+
67+ public Sprite ConvertTextureToSprite ( Texture2D texture , float PixelsPerUnit = 100.0f ,
68+ SpriteMeshType spriteType = SpriteMeshType . Tight )
69+ {
70+ // Converts a Texture2D to a sprite, assign this texture to a new sprite and return its reference
71+
72+ var NewSprite = Sprite . Create ( texture , new Rect ( 0 , 0 , texture . width , texture . height ) , new Vector2 ( 0 , 0 ) ,
73+ PixelsPerUnit , 0 , spriteType ) ;
74+
75+ return NewSprite ;
76+ }
77+
78+ public Texture2D LoadTexture ( string FilePath )
79+ {
80+ // Load a PNG or JPG file from disk to a Texture2D
81+ // Returns null if load fails
82+
83+ Texture2D Tex2D ;
84+ byte [ ] FileData ;
85+
86+ if ( File . Exists ( FilePath ) )
87+ {
88+ FileData = File . ReadAllBytes ( FilePath ) ;
89+ Tex2D = new Texture2D ( 2 , 2 ) ; // Create new "empty" texture
90+ if ( Tex2D . LoadImage ( FileData ) ) // Load the imagedata into the texture (size is set automatically)
91+ return Tex2D ; // If data = readable -> return texture
92+ }
93+
94+ return null ; // Return null if load failed
95+ }
96+ }
97+ }
0 commit comments