Skip to content

Commit

Permalink
[US] Improve uncensor blacklist interface - search, scroll, etc. (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco authored Apr 30, 2024
1 parent eea6600 commit 6a40091
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/UncensorSelector.Core/Core.UncensorSelector.SettingsGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class SettingsGUI<T> : ISettingsGUI where T : IUncensorData
private bool _visible;
private readonly List<Entry> AllValues;
private Rect GUIRect;
private Vector2 ScrollPosition;
private string SearchText = string.Empty;
private readonly bool Initialized;

private int LastScreenHeight = -1;
Expand All @@ -34,7 +36,7 @@ public class SettingsGUI<T> : ISettingsGUI where T : IUncensorData

private ConfigEntry<string> Setting;

internal SettingsGUI(IDictionary<string, T> uncensors, byte sex, string part, bool studio=false)
internal SettingsGUI(IDictionary<string, T> uncensors, byte sex, string part, bool studio = false)
{
WindowID = $"{GUID}.{nameof(SettingsGUI<T>)}.{sex}.{part}".GetHashCode();
//Deal with duplicate display names (it happens)
Expand Down Expand Up @@ -92,7 +94,7 @@ private void UpdateRects()

var width = Math.Min(300f, Screen.width / 4f);

var height = Math.Min(Screen.height * 0.9f, (valueCountChanged || GUIRect.height < 60) ? (AllValues.Count + 4) * 22f : GUIRect.height);
var height = Math.Min(Screen.height * 0.9f, (valueCountChanged || GUIRect.height < 60) ? (AllValues.Count + 6) * 22f : GUIRect.height);
GUIRect = new Rect(
// make sure it's not off screen and try not to overlap settings GUI
Screen.width > 1600 ? Screen.width * 0.75f - width * 0.5f : Screen.width - width,
Expand All @@ -107,12 +109,37 @@ private void UpdateRects()

private void DoSettingsGUI(int id)
{
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUILayout.Label("Select uncensors to exclude from random selection");
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
GUILayout.Label("Select uncensors to *exclude* from random selection");
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
GUILayout.Label("Search: ", GUILayout.ExpandWidth(false));
SearchText = GUILayout.TextField(SearchText, GUILayout.ExpandWidth(true));
var isSearch = !string.IsNullOrEmpty(SearchText);
if (GUILayout.Button("Clear", GUILayout.ExpandWidth(false))) SearchText = string.Empty;
if (GUILayout.Button("Toggle all", GUILayout.ExpandWidth(false)))
{
foreach (var value in AllValues)
{
if (isSearch && !value.Name.Contains(SearchText))
continue;

if (SelectedGUIDS.Contains(value.GUID))
SelectedGUIDS.Remove(value.GUID);
else
SelectedGUIDS.Add(value.GUID);
}
}
GUILayout.EndHorizontal();

ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, false, false);
var any = false;
foreach (var value in AllValues)
{
if (isSearch && !value.Name.Contains(SearchText))
continue;

GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
{
GUI.changed = false;
Expand All @@ -132,7 +159,15 @@ private void DoSettingsGUI(int id)
}
}
GUILayout.EndHorizontal();
any = true;
}
if (!any)
{
GUILayout.FlexibleSpace();
GUILayout.Label(isSearch ? "No search results! Clear your search string to see all available uncensors." : "No uncensors were found! Install uncensors by putting their .zipmod files inside of your mods folder.", GUILayout.ExpandWidth(true));
}
GUILayout.FlexibleSpace();
GUILayout.EndScrollView();

GUI.changed = false;

Expand Down

0 comments on commit 6a40091

Please sign in to comment.