@@ -18,14 +18,15 @@ namespace Intersect.Client.Interface.Game.Admin;
1818
1919public partial class AdminWindow : WindowControl
2020{
21- private readonly TextBox _textboxName ;
21+ private readonly Checkbox _checkboxChronological ;
2222 private readonly ComboBox _dropdownAccess ;
23- private BanMuteBox ? _banOrMuteWindow ;
2423 private readonly ComboBox _dropdownSprite ;
25- public ImagePanel _spritePanel ;
2624 private readonly ComboBox _dropdownFace ;
27- public ImagePanel _facePanel ;
28- private readonly Checkbox _checkboxChronological ;
25+ private readonly ImagePanel _facePanel ;
26+ private readonly ImagePanel _spritePanel ;
27+ private readonly TextBox _textboxName ;
28+
29+ private BanMuteBox ? _banOrMuteWindow ;
2930 private TreeControl ? _mapList ;
3031
3132 public AdminWindow ( Base gameCanvas ) : base (
@@ -35,7 +36,7 @@ public AdminWindow(Base gameCanvas) : base(
3536 nameof ( AdminWindow )
3637 )
3738 {
38- DisableResizing ( ) ;
39+ IsResizable = false ;
3940 MinimumSize = new Point ( 320 , 320 ) ;
4041 Margin = Margin . Zero ;
4142 Padding = Padding . Zero ;
@@ -53,25 +54,16 @@ public AdminWindow(Base gameCanvas) : base(
5354 {
5455 Text = Strings . Admin . Access ,
5556 } ;
56- _dropdownAccess = new ComboBox ( this , "DropdownAccess" ) ;
57+ _dropdownAccess = new ComboBox ( this , name : nameof ( _dropdownAccess ) ) ;
5758 _ = _dropdownAccess . AddItem ( Strings . Admin . Access0 , userData : "None" ) ;
5859 _ = _dropdownAccess . AddItem ( Strings . Admin . Access1 , userData : "Moderator" ) ;
5960 _ = _dropdownAccess . AddItem ( Strings . Admin . Access2 , userData : "Admin" ) ;
61+
6062 var buttonSetPower = new Button ( this , "ButtonSetPower" )
6163 {
6264 Text = Strings . Admin . SetPower ,
6365 } ;
64- buttonSetPower . Clicked += ( s , e ) =>
65- {
66- if ( _textboxName . Text . Trim ( ) . Length > 0 )
67- {
68- var power = _dropdownAccess . SelectedItem . UserData . ToString ( ) ;
69- if ( ! string . IsNullOrEmpty ( power ) && power . Trim ( ) . Length > 0 )
70- {
71- PacketSender . SendAdminAction ( new SetAccessAction ( _textboxName . Text , power ) ) ;
72- }
73- }
74- } ;
66+ buttonSetPower . Clicked += OnButtonSetPowerOnClicked ;
7567
7668 #region Quick Admin Actions
7769
@@ -80,9 +72,9 @@ public AdminWindow(Base gameCanvas) : base(
8072 {
8173 Text = Strings . Admin . Warp2Me ,
8274 } ;
83- buttonWarpToMe . Clicked += ( s , e ) =>
75+ buttonWarpToMe . Clicked += ( _ , _ ) =>
8476 {
85- if ( _textboxName . Text . Trim ( ) . Length > 0 )
77+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
8678 {
8779 PacketSender . SendAdminAction ( new WarpToMeAction ( _textboxName . Text ) ) ;
8880 }
@@ -93,9 +85,9 @@ public AdminWindow(Base gameCanvas) : base(
9385 {
9486 Text = Strings . Admin . WarpMe2 ,
9587 } ;
96- buttonWarpMeTo . Clicked += ( s , e ) =>
88+ buttonWarpMeTo . Clicked += ( _ , _ ) =>
9789 {
98- if ( _textboxName . Text . Trim ( ) . Length > 0 )
90+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
9991 {
10092 PacketSender . SendAdminAction ( new WarpMeToAction ( _textboxName . Text ) ) ;
10193 }
@@ -106,7 +98,7 @@ public AdminWindow(Base gameCanvas) : base(
10698 {
10799 Text = Strings . Admin . OverworldReturn ,
108100 } ;
109- buttonOverworldReturn . Clicked += ( s , e ) =>
101+ buttonOverworldReturn . Clicked += ( _ , _ ) =>
110102 {
111103 if ( ! string . IsNullOrEmpty ( _textboxName . Text ) )
112104 {
@@ -119,9 +111,9 @@ public AdminWindow(Base gameCanvas) : base(
119111 {
120112 Text = Strings . Admin . Kick ,
121113 } ;
122- buttonKick . Clicked += ( s , e ) =>
114+ buttonKick . Clicked += ( _ , _ ) =>
123115 {
124- if ( _textboxName . Text . Trim ( ) . Length > 0 )
116+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
125117 {
126118 PacketSender . SendAdminAction ( new KickAction ( _textboxName . Text ) ) ;
127119 }
@@ -132,9 +124,9 @@ public AdminWindow(Base gameCanvas) : base(
132124 {
133125 Text = Strings . Admin . Kill ,
134126 } ;
135- buttonKill . Clicked += ( s , e ) =>
127+ buttonKill . Clicked += ( _ , _ ) =>
136128 {
137- if ( _textboxName . Text . Trim ( ) . Length > 0 )
129+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
138130 {
139131 PacketSender . SendAdminAction ( new KillAction ( _textboxName . Text ) ) ;
140132 }
@@ -153,13 +145,13 @@ public AdminWindow(Base gameCanvas) : base(
153145 } ;
154146 buttonUnban . Clicked += ( s , e ) =>
155147 {
156- if ( _textboxName . Text . Trim ( ) . Length > 0 )
148+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
157149 {
158150 _ = new InputBox (
159151 Strings . Admin . UnbanCaption . ToString ( _textboxName . Text ) ,
160152 Strings . Admin . UnbanPrompt . ToString ( _textboxName . Text ) ,
161153 InputBox . InputType . YesNo ,
162- ( s , e ) => PacketSender . SendAdminAction ( new UnbanAction ( _textboxName . Text ) )
154+ ( _ , _ ) => PacketSender . SendAdminAction ( new UnbanAction ( _textboxName . Text ) )
163155 ) ;
164156 }
165157 } ;
@@ -177,13 +169,13 @@ public AdminWindow(Base gameCanvas) : base(
177169 } ;
178170 buttonUnmute . Clicked += ( s , e ) =>
179171 {
180- if ( _textboxName . Text . Trim ( ) . Length > 0 )
172+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
181173 {
182174 _ = new InputBox (
183175 Strings . Admin . UnmuteCaption . ToString ( _textboxName . Text ) ,
184176 Strings . Admin . UnmutePrompt . ToString ( _textboxName . Text ) ,
185177 InputBox . InputType . YesNo ,
186- ( s , e ) => PacketSender . SendAdminAction ( new UnmuteAction ( _textboxName . Text ) )
178+ ( _ , _ ) => PacketSender . SendAdminAction ( new UnmuteAction ( _textboxName . Text ) )
187179 ) ;
188180 }
189181 } ;
@@ -212,9 +204,9 @@ public AdminWindow(Base gameCanvas) : base(
212204 {
213205 Text = Strings . Admin . SetSprite ,
214206 } ;
215- buttonSetSprite . Clicked += ( s , e ) =>
207+ buttonSetSprite . Clicked += ( _ , _ ) =>
216208 {
217- if ( _textboxName . Text . Trim ( ) . Length > 0 )
209+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
218210 {
219211 PacketSender . SendAdminAction ( new SetSpriteAction ( _textboxName . Text , _dropdownSprite . Text ) ) ;
220212 }
@@ -243,9 +235,9 @@ public AdminWindow(Base gameCanvas) : base(
243235 {
244236 Text = Strings . Admin . SetFace ,
245237 } ;
246- buttonSetFace . Clicked += ( s , e ) =>
238+ buttonSetFace . Clicked += ( _ , _ ) =>
247239 {
248- if ( _textboxName . Text . Trim ( ) . Length > 0 )
240+ if ( _textboxName . Text ? . Trim ( ) . Length > 0 )
249241 {
250242 PacketSender . SendAdminAction ( new SetFaceAction ( _textboxName . Text , _dropdownFace . Text ) ) ;
251243 }
@@ -263,16 +255,33 @@ public AdminWindow(Base gameCanvas) : base(
263255 } ;
264256 _checkboxChronological = new Checkbox ( this , "CheckboxChronological" ) ;
265257 _checkboxChronological . SetToolTipText ( Strings . Admin . ChronologicalTip ) ;
266- _checkboxChronological . CheckChanged += ( s , e ) => UpdateMapList ( ) ;
258+ _checkboxChronological . CheckChanged += ( _ , _ ) => UpdateMapList ( ) ;
267259 _ = new Label ( this , "LabelChronological" )
268260 {
269261 Text = Strings . Admin . Chronological ,
270262 } ;
271263
272- LoadJsonUi ( UI . InGame , Graphics . Renderer ? . GetResolutionString ( ) , true ) ;
264+ LoadJsonUi ( UI . InGame , Graphics . Renderer ? . GetResolutionString ( ) , saveOutput : true ) ;
273265 UpdateMapList ( ) ;
274266 }
275267
268+ private void OnButtonSetPowerOnClicked ( Base @base , MouseButtonState mouseButtonState )
269+ {
270+ var name = _textboxName . Text ? . Trim ( ) ;
271+ if ( name is null or { Length : < 1 } )
272+ {
273+ return ;
274+ }
275+
276+ var power = _dropdownAccess . SelectedItem ? . UserData . ToString ( ) ? . Trim ( ) ;
277+ if ( power is null or { Length : < 1 } )
278+ {
279+ return ;
280+ }
281+
282+ PacketSender . SendAdminAction ( new SetAccessAction ( name , power ) ) ;
283+ }
284+
276285 public void SetName ( string name )
277286 {
278287 _textboxName . Text = name ;
@@ -290,7 +299,7 @@ private void UpdateMapList()
290299 Width = Width - 8 ,
291300 Height = mapListHeight ,
292301 MaximumSize = new Point ( 4096 , 999999 ) ,
293- Font = Current ? . GetFont ( "sourcesansproblack" , 10 ) ,
302+ Font = Current . GetFont ( "sourcesansproblack" , 10 ) ,
294303 TextColorOverride = Color . White ,
295304 } ;
296305 _mapList . SelectionChanged += MapList_SelectionChanged ;
@@ -343,7 +352,7 @@ private void banButton_Clicked(Base sender, MouseButtonState arguments)
343352 return ;
344353 }
345354
346- var name = _textboxName . Text . Trim ( ) ;
355+ var name = _textboxName . Text ? . Trim ( ) ;
347356 if ( string . Equals ( name , Globals . Me ? . Name , StringComparison . CurrentCultureIgnoreCase ) )
348357 {
349358 return ;
@@ -352,7 +361,7 @@ private void banButton_Clicked(Base sender, MouseButtonState arguments)
352361 _banOrMuteWindow = new BanMuteBox (
353362 Strings . Admin . BanCaption . ToString ( name ) ,
354363 Strings . Admin . BanPrompt . ToString ( _textboxName . Text ) ,
355- ( s , e ) =>
364+ ( _ , _ ) =>
356365 {
357366 PacketSender . SendAdminAction (
358367 new BanAction (
@@ -375,7 +384,7 @@ private void muteButton_Clicked(Base sender, MouseButtonState arguments)
375384 return ;
376385 }
377386
378- var name = _textboxName . Text . Trim ( ) ;
387+ var name = _textboxName . Text ? . Trim ( ) ;
379388 if ( string . Equals ( name , Globals . Me ? . Name , StringComparison . CurrentCultureIgnoreCase ) )
380389 {
381390 return ;
@@ -384,7 +393,7 @@ private void muteButton_Clicked(Base sender, MouseButtonState arguments)
384393 _banOrMuteWindow = new BanMuteBox (
385394 Strings . Admin . MuteCaption . ToString ( name ) ,
386395 Strings . Admin . MutePrompt . ToString ( _textboxName . Text ) ,
387- ( s , e ) =>
396+ ( _ , _ ) =>
388397 {
389398 PacketSender . SendAdminAction (
390399 new MuteAction (
@@ -402,15 +411,20 @@ private void muteButton_Clicked(Base sender, MouseButtonState arguments)
402411
403412 private void _dropdownSprite_ItemSelected ( Base sender , ItemSelectedEventArgs arguments )
404413 {
405- _spritePanel . Texture = Globals . ContentManager . GetTexture ( TextureType . Entity , _dropdownSprite . Text ) ;
414+ if ( _dropdownSprite . Text is not { } spriteName )
415+ {
416+ return ;
417+ }
406418
407- if ( _spritePanel . Texture == null )
419+ var spriteTexture = Globals . ContentManager . GetTexture ( TextureType . Entity , spriteName ) ;
420+
421+ if ( spriteTexture == null )
408422 {
409423 return ;
410424 }
411425
412- var textFrameWidth = _spritePanel . Texture . Width / Options . Instance . Sprites . NormalFrames ;
413- var textFrameHeight = _spritePanel . Texture . Height / Options . Instance . Sprites . Directions ;
426+ var textFrameWidth = spriteTexture . Width / Options . Instance . Sprites . NormalFrames ;
427+ var textFrameHeight = spriteTexture . Height / Options . Instance . Sprites . Directions ;
414428 _spritePanel . SetTextureRect (
415429 0 ,
416430 0 ,
@@ -423,15 +437,21 @@ private void _dropdownSprite_ItemSelected(Base sender, ItemSelectedEventArgs arg
423437
424438 private void _dropdownFace_ItemSelected ( Base sender , ItemSelectedEventArgs arguments )
425439 {
426- _facePanel . Texture = Globals . ContentManager . GetTexture ( TextureType . Face , _dropdownFace . Text ) ;
440+ if ( _dropdownFace . Text is not { } faceName )
441+ {
442+ return ;
443+ }
444+
445+ var faceTexture = Globals . ContentManager . GetTexture ( TextureType . Face , faceName ) ;
446+ _facePanel . Texture = faceTexture ;
427447
428- if ( _facePanel . Texture == null )
448+ if ( faceTexture == null )
429449 {
430450 return ;
431451 }
432452
433- var textFrameWidth = _facePanel . Texture . Width ;
434- var textFrameHeight = _facePanel . Texture . Height ;
453+ var textFrameWidth = faceTexture . Width ;
454+ var textFrameHeight = faceTexture . Height ;
435455 _facePanel . SetTextureRect (
436456 0 ,
437457 0 ,
@@ -448,7 +468,7 @@ private void MapList_SelectionChanged(Base sender, EventArgs arguments)
448468 {
449469 ApplicationContext . Context . Value ? . Logger . LogDebug (
450470 "MapList selection triggered by a sender of type {SenderType} instead of a {TreeNodeType}" ,
451- sender ? . GetType ( ) . GetName ( qualified : true ) ?? "null" ,
471+ sender . GetType ( ) . GetName ( qualified : true ) ,
452472 typeof ( TreeNode ) . GetName ( qualified : true )
453473 ) ;
454474 return ;
0 commit comments