Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion ConfigurationManager.Shared/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ public class ConfigurationManager : BaseUnityPlugin
private bool _focusSearchBox;
private string _searchString = string.Empty;

/// <summary>
/// Skin to draw the settings window with, for example to match the look of the game. Null (the default) keeps the default look.
/// The window, its controls and tooltips are drawn with this skin, and its window style draws the window background.
/// The dimmed backdrop behind a window that has not been moved yet keeps the default skin.
/// Plugin and category headers use the custom styles named <see cref="PluginHeaderStyleName"/> and <see cref="CategoryHeaderStyleName"/>
/// if the skin has them.
/// </summary>
public GUISkin WindowSkin { get; set; }

/// <summary>
/// Name of the custom style in <see cref="WindowSkin"/> used for plugin headers, if present.
/// </summary>
public const string PluginHeaderStyleName = "ConfigurationManager.PluginHeader";

/// <summary>
/// Name of the custom style in <see cref="WindowSkin"/> used for category headers, if present.
/// </summary>
public const string CategoryHeaderStyleName = "ConfigurationManager.CategoryHeader";

/// <summary>
/// Event fired every time the manager window is shown or hidden.
/// </summary>
Expand Down Expand Up @@ -309,10 +328,15 @@ private void OnGUI()
if (GUI.Button(_screenRect, string.Empty, GUI.skin.box) && !SettingWindowRect.Contains(mousePosition))
DisplayingWindow = false;

ImguiUtils.DrawWindowBackground(SettingWindowRect);
// A custom skin draws the window background with its own window style
if (WindowSkin == null)
ImguiUtils.DrawWindowBackground(SettingWindowRect);
}

var defaultSkin = GUI.skin;
if (WindowSkin != null) GUI.skin = WindowSkin;
var newRect = GUILayout.Window(WindowId, SettingWindowRect, (GUI.WindowFunction)SettingsWindow, "Plugin / mod settings");
GUI.skin = defaultSkin;

if (newRect != SettingWindowRect)
{
Expand Down
43 changes: 26 additions & 17 deletions ConfigurationManager.Shared/SettingFieldDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,41 @@ public static void DrawCenteredLabel(string text, params GUILayoutOption[] optio
GUILayout.EndHorizontal();
}

private static GUIStyle _categoryHeaderSkin;
public static void DrawCategoryHeader(string text)
/// <summary>
/// Header style of the current skin: its custom style with the given name if it has one, otherwise a centered copy of its label.
/// Rebuilt only when the skin changes, so the default look builds it once as before.
/// </summary>
private static GUIStyle GetHeaderStyle(string customStyleName, int fontSize, ref GUIStyle style, ref GUISkin styleSkin)
{
if (_categoryHeaderSkin == null)
var skin = GUI.skin;
if (style == null || styleSkin != skin)
{
_categoryHeaderSkin = GUI.skin.label.CreateCopy();
_categoryHeaderSkin.alignment = TextAnchor.UpperCenter;
_categoryHeaderSkin.wordWrap = true;
_categoryHeaderSkin.stretchWidth = true;
_categoryHeaderSkin.fontSize = 14;
style = skin.FindStyle(customStyleName);
if (style == null)
{
style = skin.label.CreateCopy();
style.alignment = TextAnchor.UpperCenter;
style.wordWrap = true;
style.stretchWidth = true;
style.fontSize = fontSize;
}
styleSkin = skin;
}
return style;
}

GUILayout.Label(text, _categoryHeaderSkin);
private static GUIStyle _categoryHeaderSkin;
private static GUISkin _categoryHeaderSkinFor;
public static void DrawCategoryHeader(string text)
{
GUILayout.Label(text, GetHeaderStyle(ConfigurationManager.CategoryHeaderStyleName, 14, ref _categoryHeaderSkin, ref _categoryHeaderSkinFor));
}

private static GUIStyle _pluginHeaderSkin;
private static GUISkin _pluginHeaderSkinFor;
public static bool DrawPluginHeader(GUIContent content, bool isCollapsed)
{
if (_pluginHeaderSkin == null)
{
_pluginHeaderSkin = GUI.skin.label.CreateCopy();
_pluginHeaderSkin.alignment = TextAnchor.UpperCenter;
_pluginHeaderSkin.wordWrap = true;
_pluginHeaderSkin.stretchWidth = true;
_pluginHeaderSkin.fontSize = 15;
}
GetHeaderStyle(ConfigurationManager.PluginHeaderStyleName, 15, ref _pluginHeaderSkin, ref _pluginHeaderSkinFor);

if (isCollapsed) content.text += "\n...";
return GUILayout.Button(content, _pluginHeaderSkin, GUILayout.ExpandWidth(true));
Expand Down