@@ -62,6 +62,7 @@ public class ConfigurationManager : BaseUnityPlugin
6262 private List < PluginSettingsData > _filteredSetings = new List < PluginSettingsData > ( ) ;
6363
6464 internal Rect SettingWindowRect { get ; private set ; }
65+ private bool _windowWasMoved ;
6566 private Rect _screenRect ;
6667 private Vector2 _settingWindowScrollPos ;
6768 private int _tipsHeight ;
@@ -254,6 +255,8 @@ private void CalculateWindowRect()
254255
255256 LeftColumnWidth = Mathf . RoundToInt ( SettingWindowRect . width / 2.5f ) ;
256257 RightColumnWidth = ( int ) SettingWindowRect . width - LeftColumnWidth - 115 ;
258+
259+ _windowWasMoved = false ;
257260 }
258261
259262 private void OnGUI ( )
@@ -262,15 +265,25 @@ private void OnGUI()
262265 {
263266 SetUnlockCursor ( 0 , true ) ;
264267
265- if ( GUI . Button ( _screenRect , string . Empty , GUI . skin . box ) &&
266- ! SettingWindowRect . Contains ( UnityInput . Current . mousePosition ) )
267- DisplayingWindow = false ;
268+ // If the window hasn't been moved by the user yet, block the whole screen and use a solid background to make the window easier to see
269+ if ( ! _windowWasMoved )
270+ {
271+ if ( GUI . Button ( _screenRect , string . Empty , GUI . skin . box ) &&
272+ ! SettingWindowRect . Contains ( UnityInput . Current . mousePosition ) )
273+ DisplayingWindow = false ;
268274
269- GUI . Box ( SettingWindowRect , GUIContent . none , new GUIStyle { normal = new GUIStyleState { background = WindowBackground } } ) ;
275+ GUI . Box ( SettingWindowRect , GUIContent . none , new GUIStyle { normal = new GUIStyleState { background = WindowBackground } } ) ;
276+ }
270277
271- GUILayout . Window ( WindowId , SettingWindowRect , SettingsWindow , "Plugin / mod settings" ) ;
278+ var newRect = GUILayout . Window ( WindowId , SettingWindowRect , SettingsWindow , "Plugin / mod settings" ) ;
272279
273- if ( ! SettingFieldDrawer . SettingKeyboardShortcut )
280+ if ( newRect != SettingWindowRect )
281+ {
282+ _windowWasMoved = true ;
283+ SettingWindowRect = newRect ;
284+ }
285+
286+ if ( ! SettingFieldDrawer . SettingKeyboardShortcut && ( ! _windowWasMoved || SettingWindowRect . Contains ( UnityInput . Current . mousePosition ) ) )
274287 UnityInput . Current . ResetInputAxes ( ) ;
275288 }
276289 }
@@ -373,6 +386,8 @@ private void SettingsWindow(int id)
373386
374387 if ( ! SettingFieldDrawer . DrawCurrentDropdown ( ) )
375388 DrawTooltip ( SettingWindowRect ) ;
389+
390+ GUI . DragWindow ( ) ;
376391 }
377392
378393 private void DrawTips ( )
@@ -386,98 +401,86 @@ private void DrawTips()
386401
387402 private void DrawWindowHeader ( )
388403 {
389- GUILayout . BeginHorizontal ( ) ;
404+ GUILayout . BeginHorizontal ( GUI . skin . box ) ;
390405 {
391- GUILayout . BeginHorizontal ( GUI . skin . box ) ;
406+ GUI . enabled = SearchString == string . Empty ;
407+
408+ var newVal = GUILayout . Toggle ( _showSettings . Value , "Normal settings" ) ;
409+ if ( _showSettings . Value != newVal )
392410 {
393- GUILayout . Label ( "Show: " ) ;
411+ _showSettings . Value = newVal ;
412+ BuildFilteredSettingList ( ) ;
413+ }
394414
395- GUI . enabled = SearchString == string . Empty ;
415+ newVal = GUILayout . Toggle ( _showKeybinds . Value , "Keyboard shortcuts" ) ;
416+ if ( _showKeybinds . Value != newVal )
417+ {
418+ _showKeybinds . Value = newVal ;
419+ BuildFilteredSettingList ( ) ;
420+ }
396421
397- var newVal = GUILayout . Toggle ( _showSettings . Value , "Normal settings" ) ;
398- if ( _showSettings . Value != newVal )
399- {
400- _showSettings . Value = newVal ;
401- BuildFilteredSettingList ( ) ;
402- }
422+ var origColor = GUI . color ;
423+ GUI . color = _advancedSettingColor ;
424+ newVal = GUILayout . Toggle ( _showAdvanced . Value , "Advanced settings" ) ;
425+ if ( _showAdvanced . Value != newVal )
426+ {
427+ _showAdvanced . Value = newVal ;
428+ BuildFilteredSettingList ( ) ;
429+ }
430+ GUI . color = origColor ;
403431
404- newVal = GUILayout . Toggle ( _showKeybinds . Value , "Keyboard shortcuts" ) ;
405- if ( _showKeybinds . Value != newVal )
406- {
407- _showKeybinds . Value = newVal ;
408- BuildFilteredSettingList ( ) ;
409- }
432+ GUI . enabled = true ;
410433
411- var origColor = GUI . color ;
412- GUI . color = _advancedSettingColor ;
413- newVal = GUILayout . Toggle ( _showAdvanced . Value , "Advanced settings" ) ;
414- if ( _showAdvanced . Value != newVal )
415- {
416- _showAdvanced . Value = newVal ;
417- BuildFilteredSettingList ( ) ;
418- }
419- GUI . color = origColor ;
434+ GUILayout . Space ( 8 ) ;
420435
421- GUI . enabled = true ;
436+ newVal = GUILayout . Toggle ( _showDebug , "Debug info" ) ;
437+ if ( _showDebug != newVal )
438+ {
439+ _showDebug = newVal ;
440+ BuildSettingList ( ) ;
422441 }
423- GUILayout . EndHorizontal ( ) ;
424442
425- GUILayout . BeginHorizontal ( GUI . skin . box , GUILayout . ExpandWidth ( false ) ) ;
443+ if ( GUILayout . Button ( "Open Log" ) )
426444 {
427- if ( GUILayout . Button ( "Close" ) )
428- {
429- DisplayingWindow = false ;
430- }
445+ try { Utils . OpenLog ( ) ; }
446+ catch ( SystemException ex ) { Logger . Log ( LogLevel . Message | LogLevel . Error , ex . Message ) ; }
447+ }
448+
449+ GUILayout . Space ( 8 ) ;
450+
451+ if ( GUILayout . Button ( "Close" ) )
452+ {
453+ DisplayingWindow = false ;
431454 }
432- GUILayout . EndHorizontal ( ) ;
433455 }
434456 GUILayout . EndHorizontal ( ) ;
435457
436- GUILayout . BeginHorizontal ( ) ;
458+ GUILayout . BeginHorizontal ( GUI . skin . box ) ;
437459 {
438- GUILayout . BeginHorizontal ( GUI . skin . box ) ;
439- {
440- GUILayout . Label ( "Search: " , GUILayout . ExpandWidth ( false ) ) ;
460+ GUILayout . Label ( "Search: " , GUILayout . ExpandWidth ( false ) ) ;
441461
442- GUI . SetNextControlName ( SearchBoxName ) ;
443- SearchString = GUILayout . TextField ( SearchString , GUILayout . ExpandWidth ( true ) , GUILayout . MinWidth ( 250 ) ) ;
462+ GUI . SetNextControlName ( SearchBoxName ) ;
463+ SearchString = GUILayout . TextField ( SearchString , GUILayout . ExpandWidth ( true ) ) ;
444464
445- if ( _focusSearchBox )
446- {
447- GUI . FocusWindow ( WindowId ) ;
448- GUI . FocusControl ( SearchBoxName ) ;
449- _focusSearchBox = false ;
450- }
451-
452- if ( GUILayout . Button ( "Clear" , GUILayout . ExpandWidth ( false ) ) )
453- SearchString = string . Empty ;
465+ if ( _focusSearchBox )
466+ {
467+ GUI . FocusWindow ( WindowId ) ;
468+ GUI . FocusControl ( SearchBoxName ) ;
469+ _focusSearchBox = false ;
454470 }
455- GUILayout . EndHorizontal ( ) ;
456471
457- GUILayout . BeginHorizontal ( GUI . skin . box , GUILayout . ExpandWidth ( false ) ) ;
458- {
459- if ( GUILayout . Button ( _pluginConfigCollapsedDefault . Value ? "Expand All" : "Collapse All" ) )
460- {
461- var newValue = ! _pluginConfigCollapsedDefault . Value ;
462- _pluginConfigCollapsedDefault . Value = newValue ;
463- foreach ( var plugin in _filteredSetings )
464- plugin . Collapsed = newValue ;
465- }
472+ if ( GUILayout . Button ( "Clear" , GUILayout . ExpandWidth ( false ) ) )
473+ SearchString = string . Empty ;
466474
467- var newVal = GUILayout . Toggle ( _showDebug , "Debug mode" ) ;
468- if ( _showDebug != newVal )
469- {
470- _showDebug = newVal ;
471- BuildSettingList ( ) ;
472- }
475+ GUILayout . Space ( 8 ) ;
473476
474- if ( GUILayout . Button ( "Open Log" ) )
475- {
476- try { Utils . OpenLog ( ) ; }
477- catch ( SystemException ex ) { Logger . Log ( LogLevel . Message | LogLevel . Error , ex . Message ) ; }
478- }
477+ if ( GUILayout . Button ( _pluginConfigCollapsedDefault . Value ? "Expand All" : "Collapse All" , GUILayout . ExpandWidth ( false ) ) )
478+ {
479+ var newValue = ! _pluginConfigCollapsedDefault . Value ;
480+ _pluginConfigCollapsedDefault . Value = newValue ;
481+ foreach ( var plugin in _filteredSetings )
482+ plugin . Collapsed = newValue ;
479483 }
480- GUILayout . EndHorizontal ( ) ;
481484 }
482485 GUILayout . EndHorizontal ( ) ;
483486 }
0 commit comments