88
99namespace ModReloader . Common . Configs . ConfigElements ;
1010
11- public class PlayerIndexSliderElement : IntOptionElement
11+ public class PlayerIndexSliderElement : IntPathOptionElement
1212{
1313 protected override int GetCount ( )
1414 {
@@ -23,7 +23,7 @@ protected override string ResolveName(int index)
2323 if ( clamped < 0 ) clamped = 0 ;
2424 if ( clamped > Main . PlayerList . Count - 1 ) clamped = Main . PlayerList . Count - 1 ;
2525 var file = Main . PlayerList [ clamped ] ;
26- if ( file != null && file . Player != null && ! string . IsNullOrWhiteSpace ( file . Player . name ) )
26+ if ( file != null && file . Player != null && ! string . IsNullOrWhiteSpace ( file . Player . name ) )
2727 return file . Player . name ;
2828 if ( file != null && ! string . IsNullOrWhiteSpace ( file . Name ) ) return file . Name ;
2929 return "Player " + clamped ;
@@ -36,43 +36,57 @@ public override void Draw(SpriteBatch sb)
3636 // Player instance
3737 int playerIndex = - 1 ;
3838 object raw = MemberInfo . GetValue ( Item ) ;
39- if ( raw is int i )
40- playerIndex = i ;
39+ if ( raw is string path )
40+ {
41+ playerIndex = PathToID ( path ) ;
42+ }
4143
4244 if ( playerIndex < 0 )
43- return ;
45+ playerIndex = 0 ;
4446
45- if ( playerIndex != - 1 )
46- {
47- // Player
48- var player = Main . PlayerList [ playerIndex ] . Player ;
49- string name = player . name ;
50-
51- // Measure width
52- var font = FontAssets . ItemStack . Value ;
53- var width = font . MeasureString ( name ) . X ;
54-
55- // Dims
56- var dims = GetDimensions ( ) ;
57- var rect = dims . ToRectangle ( ) ;
58- var namePos = new Vector2 ( rect . X + dims . Width - 200 - width , rect . Y + 7 ) ;
59-
60- ChatManager . DrawColorCodedStringWithShadow ( sb , font ,
61- name , namePos , Color . White , 0f , Vector2 . Zero , Vector2 . One ) ;
62-
63- // Player head pos
64- Vector2 headPos = new ( namePos . X - 20 , namePos . Y + 5 ) ;
65-
66- // Draw player head
67- PlayerHeadFlipHook . shouldFlipHeadDraw = player . direction == - 1 ;
68- Main . MapPlayerRenderer . DrawPlayerHead (
69- Main . Camera ,
70- player ,
71- headPos ,
72- scale : 0.8f ,
73- borderColor : Color . White
74- ) ;
75- PlayerHeadFlipHook . shouldFlipHeadDraw = false ;
76- }
47+
48+ // Dims
49+ var dims = GetDimensions ( ) ;
50+ var rect = dims . ToRectangle ( ) ;
51+ var pos = new Vector2 ( rect . X + dims . Width - 200 , rect . Y + 12 ) ;
52+ // Player
53+ var player = Main . PlayerList [ playerIndex ] . Player ;
54+ string name = player . name ;
55+
56+ // Measure width
57+ var font = FontAssets . ItemStack . Value ;
58+ var width = font . MeasureString ( name ) . X ;
59+ var namePos = new Vector2 ( rect . X + dims . Width - 200 - width , rect . Y + 7 ) ;
60+
61+ ChatManager . DrawColorCodedStringWithShadow ( sb , font ,
62+ name , namePos , Color . White , 0f , Vector2 . Zero , Vector2 . One ) ;
63+
64+ // Player head pos
65+ Vector2 headPos = new ( namePos . X - 20 , namePos . Y + 5 ) ;
66+
67+ // Draw player head
68+ PlayerHeadFlipHook . shouldFlipHeadDraw = player . direction == - 1 ;
69+ Main . MapPlayerRenderer . DrawPlayerHead (
70+ Main . Camera ,
71+ player ,
72+ headPos ,
73+ scale : 0.8f ,
74+ borderColor : Color . White
75+ ) ;
76+ PlayerHeadFlipHook . shouldFlipHeadDraw = false ;
77+
78+
79+ }
80+
81+ protected override string IDToPath ( int index )
82+ {
83+ return Utilities . FindPlayer ( index ) . Path ;
84+ }
85+
86+ protected override int PathToID ( string path )
87+ {
88+ return Utilities . FindPlayerId ( path ) ;
89+
90+
7791 }
7892}
0 commit comments