Skip to content

Commit

Permalink
Allow drag moving the window to let the window stay open while playing
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Mar 8, 2023
1 parent 0bcd570 commit eb4fd75
Showing 1 changed file with 79 additions and 76 deletions.
155 changes: 79 additions & 76 deletions ConfigurationManager/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ConfigurationManager : BaseUnityPlugin
private List<PluginSettingsData> _filteredSetings = new List<PluginSettingsData>();

internal Rect SettingWindowRect { get; private set; }
private bool _windowWasMoved;
private Rect _screenRect;
private Vector2 _settingWindowScrollPos;
private int _tipsHeight;
Expand Down Expand Up @@ -254,6 +255,8 @@ private void CalculateWindowRect()

LeftColumnWidth = Mathf.RoundToInt(SettingWindowRect.width / 2.5f);
RightColumnWidth = (int)SettingWindowRect.width - LeftColumnWidth - 115;

_windowWasMoved = false;
}

private void OnGUI()
Expand All @@ -262,15 +265,25 @@ private void OnGUI()
{
SetUnlockCursor(0, true);

if (GUI.Button(_screenRect, string.Empty, GUI.skin.box) &&
!SettingWindowRect.Contains(UnityInput.Current.mousePosition))
DisplayingWindow = false;
// 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
if (!_windowWasMoved)
{
if (GUI.Button(_screenRect, string.Empty, GUI.skin.box) &&
!SettingWindowRect.Contains(UnityInput.Current.mousePosition))
DisplayingWindow = false;

GUI.Box(SettingWindowRect, GUIContent.none, new GUIStyle { normal = new GUIStyleState { background = WindowBackground } });
GUI.Box(SettingWindowRect, GUIContent.none, new GUIStyle { normal = new GUIStyleState { background = WindowBackground } });
}

GUILayout.Window(WindowId, SettingWindowRect, SettingsWindow, "Plugin / mod settings");
var newRect = GUILayout.Window(WindowId, SettingWindowRect, SettingsWindow, "Plugin / mod settings");

if (!SettingFieldDrawer.SettingKeyboardShortcut)
if (newRect != SettingWindowRect)
{
_windowWasMoved = true;
SettingWindowRect = newRect;
}

if (!SettingFieldDrawer.SettingKeyboardShortcut && (!_windowWasMoved || SettingWindowRect.Contains(UnityInput.Current.mousePosition)))
UnityInput.Current.ResetInputAxes();
}
}
Expand Down Expand Up @@ -373,6 +386,8 @@ private void SettingsWindow(int id)

if (!SettingFieldDrawer.DrawCurrentDropdown())
DrawTooltip(SettingWindowRect);

GUI.DragWindow();
}

private void DrawTips()
Expand All @@ -386,98 +401,86 @@ private void DrawTips()

private void DrawWindowHeader()
{
GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box);
{
GUILayout.BeginHorizontal(GUI.skin.box);
GUI.enabled = SearchString == string.Empty;

var newVal = GUILayout.Toggle(_showSettings.Value, "Normal settings");
if (_showSettings.Value != newVal)
{
GUILayout.Label("Show: ");
_showSettings.Value = newVal;
BuildFilteredSettingList();
}

GUI.enabled = SearchString == string.Empty;
newVal = GUILayout.Toggle(_showKeybinds.Value, "Keyboard shortcuts");
if (_showKeybinds.Value != newVal)
{
_showKeybinds.Value = newVal;
BuildFilteredSettingList();
}

var newVal = GUILayout.Toggle(_showSettings.Value, "Normal settings");
if (_showSettings.Value != newVal)
{
_showSettings.Value = newVal;
BuildFilteredSettingList();
}
var origColor = GUI.color;
GUI.color = _advancedSettingColor;
newVal = GUILayout.Toggle(_showAdvanced.Value, "Advanced settings");
if (_showAdvanced.Value != newVal)
{
_showAdvanced.Value = newVal;
BuildFilteredSettingList();
}
GUI.color = origColor;

newVal = GUILayout.Toggle(_showKeybinds.Value, "Keyboard shortcuts");
if (_showKeybinds.Value != newVal)
{
_showKeybinds.Value = newVal;
BuildFilteredSettingList();
}
GUI.enabled = true;

var origColor = GUI.color;
GUI.color = _advancedSettingColor;
newVal = GUILayout.Toggle(_showAdvanced.Value, "Advanced settings");
if (_showAdvanced.Value != newVal)
{
_showAdvanced.Value = newVal;
BuildFilteredSettingList();
}
GUI.color = origColor;
GUILayout.Space(8);

GUI.enabled = true;
newVal = GUILayout.Toggle(_showDebug, "Debug info");
if (_showDebug != newVal)
{
_showDebug = newVal;
BuildSettingList();
}
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(false));
if (GUILayout.Button("Open Log"))
{
if (GUILayout.Button("Close"))
{
DisplayingWindow = false;
}
try { Utils.OpenLog(); }
catch (SystemException ex) { Logger.Log(LogLevel.Message | LogLevel.Error, ex.Message); }
}

GUILayout.Space(8);

if (GUILayout.Button("Close"))
{
DisplayingWindow = false;
}
GUILayout.EndHorizontal();
}
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box);
{
GUILayout.BeginHorizontal(GUI.skin.box);
{
GUILayout.Label("Search: ", GUILayout.ExpandWidth(false));
GUILayout.Label("Search: ", GUILayout.ExpandWidth(false));

GUI.SetNextControlName(SearchBoxName);
SearchString = GUILayout.TextField(SearchString, GUILayout.ExpandWidth(true), GUILayout.MinWidth(250));
GUI.SetNextControlName(SearchBoxName);
SearchString = GUILayout.TextField(SearchString, GUILayout.ExpandWidth(true));

if (_focusSearchBox)
{
GUI.FocusWindow(WindowId);
GUI.FocusControl(SearchBoxName);
_focusSearchBox = false;
}

if (GUILayout.Button("Clear", GUILayout.ExpandWidth(false)))
SearchString = string.Empty;
if (_focusSearchBox)
{
GUI.FocusWindow(WindowId);
GUI.FocusControl(SearchBoxName);
_focusSearchBox = false;
}
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(false));
{
if (GUILayout.Button(_pluginConfigCollapsedDefault.Value ? "Expand All" : "Collapse All"))
{
var newValue = !_pluginConfigCollapsedDefault.Value;
_pluginConfigCollapsedDefault.Value = newValue;
foreach (var plugin in _filteredSetings)
plugin.Collapsed = newValue;
}
if (GUILayout.Button("Clear", GUILayout.ExpandWidth(false)))
SearchString = string.Empty;

var newVal = GUILayout.Toggle(_showDebug, "Debug mode");
if (_showDebug != newVal)
{
_showDebug = newVal;
BuildSettingList();
}
GUILayout.Space(8);

if (GUILayout.Button("Open Log"))
{
try { Utils.OpenLog(); }
catch (SystemException ex) { Logger.Log(LogLevel.Message | LogLevel.Error, ex.Message); }
}
if (GUILayout.Button(_pluginConfigCollapsedDefault.Value ? "Expand All" : "Collapse All", GUILayout.ExpandWidth(false)))
{
var newValue = !_pluginConfigCollapsedDefault.Value;
_pluginConfigCollapsedDefault.Value = newValue;
foreach (var plugin in _filteredSetings)
plugin.Collapsed = newValue;
}
GUILayout.EndHorizontal();
}
GUILayout.EndHorizontal();
}
Expand Down

0 comments on commit eb4fd75

Please sign in to comment.
  翻译: