Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Add RuntimeProvider method for setting Selectable.colors
Browse files Browse the repository at this point in the history
  • Loading branch information
sinai-dev committed Apr 10, 2021
1 parent e0fd682 commit a5a07a0
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 100 deletions.
35 changes: 29 additions & 6 deletions src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,22 @@ public static int GetRootCount(int handle)
.Invoke(handle);
}

internal static bool triedToGetProperties;
internal static bool triedToGetColorBlockProps;
internal static PropertyInfo _normalColorProp;
internal static PropertyInfo _highlightColorProp;
internal static PropertyInfo _pressedColorProp;

public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null)
{
var colors = selectable.colors;

colors.colorMultiplier = 1;

object boxed = (object)colors;

if (!triedToGetProperties)
if (!triedToGetColorBlockProps)
{
triedToGetProperties = true;
triedToGetColorBlockProps = true;

if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor") is PropertyInfo norm && norm.CanWrite)
_normalColorProp = norm;
Expand Down Expand Up @@ -209,11 +211,32 @@ public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null
fi.SetValue(boxed, (Color)pressed);
}
}
catch { }
catch (Exception ex)
{
ExplorerCore.Log(ex);
}

colors = (ColorBlock)boxed;

return colors;
SetColorBlock(selectable, colors);
}

public override void SetColorBlock(Selectable selectable, ColorBlock _colorBlock)
{
try
{
selectable = selectable.TryCast<Selectable>();

ReflectionUtility.GetPropertyInfo(typeof(Selectable), "m_Colors")
.SetValue(selectable, _colorBlock, null);

ReflectionUtility.GetMethodInfo(typeof(Selectable), "OnSetProperty", new Type[0])
.Invoke(selectable, new object[0]);
}
catch (Exception ex)
{
ExplorerCore.Log(ex);
}
}

public override void FindSingleton(string[] possibleNames, Type type, BF flags, List<object> instances)
Expand Down
11 changes: 9 additions & 2 deletions src/Core/Runtime/Mono/MonoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public override int GetRootCount(Scene scene)
return scene.rootCount;
}

public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null)
{
var colors = selectable.colors;

if (normal != null)
colors.normalColor = (Color)normal;

Expand All @@ -97,7 +99,12 @@ public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null
if (pressed != null)
colors.pressedColor = (Color)pressed;

return colors;
SetColorBlock(selectable, colors);
}

public override void SetColorBlock(Selectable selectable, ColorBlock colors)
{
selectable.colors = colors;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Runtime/RuntimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public static void Init() =>

public abstract int GetRootCount(Scene scene);

public abstract ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null);
public abstract void SetColorBlock(Selectable selectable, ColorBlock colors);

public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null);

public virtual void FindSingleton(string[] s_instanceNames, Type type, BindingFlags flags, List<object> instances)
{
Expand Down
19 changes: 8 additions & 11 deletions src/UI/CacheObject/CacheMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,13 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
default, new Color(1, 1, 1, 0));
UIFactory.SetLayoutElement(evalGroupObj, minHeight: 25, flexibleHeight: 0, flexibleWidth: 5000);

var colors = new ColorBlock();
colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f),
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));

var evalButton = UIFactory.CreateButton(evalGroupObj,
"EvalButton",
$"Evaluate ({ParamCount})",
null,
colors);
null);

RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f),
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));

UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0);

Expand All @@ -345,7 +343,7 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
argsHolder.SetActive(true);
m_isEvaluating = true;
evalText.text = "Evaluate";
evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.3f, 0.6f, 0.3f));
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.3f, 0.6f, 0.3f));
cancelButton.gameObject.SetActive(true);
}
Expand All @@ -365,18 +363,17 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
m_isEvaluating = false;
evalText.text = $"Evaluate ({ParamCount})";
evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.4f, 0.4f, 0.4f));
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f));
});
}
else if (this is CacheMethod)
{
// simple method evaluate button

var colors = new ColorBlock();
colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f),
var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); });
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f),
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));

var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); }, colors);
UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0);
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/UI/Inspectors/GameObjects/ChildList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,13 @@ internal void AddChildListButton()
s_childListToggles.Add(toggle);
toggle.onValueChanged.AddListener((bool val) => { OnToggleClicked(thisIndex, val); });

ColorBlock mainColors = new ColorBlock();
mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.07f, 0.07f, 0.07f),
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));

var mainBtn = UIFactory.CreateButton(btnGroupObj,
"MainButton",
"",
() => { OnChildListObjectClicked(thisIndex); },
mainColors);
() => { OnChildListObjectClicked(thisIndex); });

RuntimeProvider.Instance.SetColorBlock(mainBtn, new Color(0.07f, 0.07f, 0.07f),
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));

UIFactory.SetLayoutElement(mainBtn.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 25, flexibleWidth: 9999);

Expand Down
10 changes: 4 additions & 6 deletions src/UI/Inspectors/GameObjects/ComponentList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,13 @@ internal void AddCompListButton()

// Main component button

ColorBlock mainColors = new ColorBlock();
mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.07f, 0.07f, 0.07f),
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));

var mainBtn = UIFactory.CreateButton(groupObj,
"MainButton",
"",
() => { OnCompListObjectClicked(thisIndex); },
mainColors);
() => { OnCompListObjectClicked(thisIndex); });

RuntimeProvider.Instance.SetColorBlock(mainBtn, new Color(0.07f, 0.07f, 0.07f),
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));

UIFactory.SetLayoutElement(mainBtn.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 25, flexibleWidth: 999);

Expand Down
2 changes: 1 addition & 1 deletion src/UI/Inspectors/GameObjects/GameObjectControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ internal GameObject ConstructEditorRow(GameObject parent, ControlEditor editor,
var sliderObj = UIFactory.CreateSlider(rowObject, "VectorSlider", out Slider slider);
UIFactory.SetLayoutElement(sliderObj, minHeight: 20, flexibleHeight: 0, minWidth: 200, flexibleWidth: 9000);
sliderObj.transform.Find("Fill Area").gameObject.SetActive(false);
slider.colors = RuntimeProvider.Instance.SetColorBlock(slider.colors, new Color(0.65f, 0.65f, 0.65f));
RuntimeProvider.Instance.SetColorBlock(slider, new Color(0.65f, 0.65f, 0.65f));
slider.minValue = -2;
slider.maxValue = 2;
slider.value = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/UI/Inspectors/InspectorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public void UnsetInspectorTab()
public void OnSetInspectorTab(InspectorBase inspector)
{
Color activeColor = new Color(0, 0.25f, 0, 1);
inspector.m_tabButton.colors = RuntimeProvider.Instance.SetColorBlock(inspector.m_tabButton.colors, activeColor, activeColor);
RuntimeProvider.Instance.SetColorBlock(inspector.m_tabButton, activeColor, activeColor);
}

public void OnUnsetInspectorTab()
{
m_activeInspector.m_tabButton.colors = RuntimeProvider.Instance.SetColorBlock(m_activeInspector.m_tabButton.colors,
RuntimeProvider.Instance.SetColorBlock(m_activeInspector.m_tabButton,
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.1f, 0.3f, 0.1f, 1));
}

Expand Down
8 changes: 4 additions & 4 deletions src/UI/Inspectors/Reflection/InstanceInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public InstanceInspector(object target) : base(target) { }
internal void OnScopeFilterClicked(MemberScopes type, Button button)
{
if (m_lastActiveScopeButton)
m_lastActiveScopeButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton.colors, new Color(0.2f, 0.2f, 0.2f));
RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton, new Color(0.2f, 0.2f, 0.2f));

m_scopeFilter = type;
m_lastActiveScopeButton = button;

m_lastActiveScopeButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton.colors, new Color(0.2f, 0.6f, 0.2f));
RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton, new Color(0.2f, 0.6f, 0.2f));

FilterMembers(null, true);
m_sliderScroller.m_slider.value = 1f;
Expand Down Expand Up @@ -240,11 +240,11 @@ private void AddFilterButton(GameObject parent, MemberScopes type, bool setEnabl

btn.onClick.AddListener(() => { OnScopeFilterClicked(type, btn); });

btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, highlighted: new Color(0.3f, 0.7f, 0.3f));
RuntimeProvider.Instance.SetColorBlock(btn, highlighted: new Color(0.3f, 0.7f, 0.3f));

if (setEnabled)
{
btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, new Color(0.2f, 0.6f, 0.2f));
RuntimeProvider.Instance.SetColorBlock(btn, new Color(0.2f, 0.6f, 0.2f));
m_scopeFilter = type;
m_lastActiveScopeButton = btn;
}
Expand Down
8 changes: 4 additions & 4 deletions src/UI/Inspectors/Reflection/ReflectionInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ public override void Update()
internal void OnMemberFilterClicked(MemberTypes type, Button button)
{
if (m_lastActiveMemButton)
m_lastActiveMemButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton.colors, new Color(0.2f, 0.2f, 0.2f));
RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.2f, 0.2f));

m_memberFilter = type;
m_lastActiveMemButton = button;

m_lastActiveMemButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton.colors, new Color(0.2f, 0.6f, 0.2f));
RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.6f, 0.2f));

FilterMembers(null, true);
m_sliderScroller.m_slider.value = 1f;
Expand Down Expand Up @@ -461,11 +461,11 @@ private void AddFilterButton(GameObject parent, MemberTypes type, bool setEnable
UIFactory.SetLayoutElement(btn.gameObject, minHeight: 25, minWidth: 70);
btn.onClick.AddListener(() => { OnMemberFilterClicked(type, btn); });

btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, highlighted: new Color(0.3f, 0.7f, 0.3f));
RuntimeProvider.Instance.SetColorBlock(btn, highlighted: new Color(0.3f, 0.7f, 0.3f));

if (setEnabled)
{
btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, new Color(0.2f, 0.6f, 0.2f));
RuntimeProvider.Instance.SetColorBlock(btn, new Color(0.2f, 0.6f, 0.2f));
m_memberFilter = type;
m_lastActiveMemButton = btn;
}
Expand Down
6 changes: 2 additions & 4 deletions src/UI/Main/CSConsole/AutoCompleter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,10 @@ private static void ConstructUI()
mainGroup.childForceExpandHeight = false;
mainGroup.childForceExpandWidth = true;

ColorBlock btnColors = new ColorBlock();
RuntimeProvider.Instance.SetColorBlock(btnColors, new Color(0, 0, 0, 0), highlighted: new Color(0.2f, 0.2f, 0.2f, 1.0f));

for (int i = 0; i < MAX_LABELS; i++)
{
var btn = UIFactory.CreateButton(content, "AutoCompleteButton", "", null, btnColors);
var btn = UIFactory.CreateButton(content, "AutoCompleteButton", "", null);
RuntimeProvider.Instance.SetColorBlock(btn, new Color(0, 0, 0, 0), highlighted: new Color(0.2f, 0.2f, 0.2f, 1.0f));

var nav = btn.navigation;
nav.mode = Navigation.Mode.Vertical;
Expand Down
20 changes: 8 additions & 12 deletions src/UI/Main/Home/SceneExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,13 @@ private void AddObjectListButton()
m_shortListToggles.Add(toggle);
toggle.onValueChanged.AddListener((bool val) => { OnToggleClicked(thisIndex, val); });

ColorBlock mainColors = new ColorBlock();
mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.1f, 0.1f, 0.1f),
new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f));

var mainButton = UIFactory.CreateButton(btnGroupObj,
"MainButton",
"",
() => { SceneListObjectClicked(thisIndex); },
mainColors);
() => { SceneListObjectClicked(thisIndex); });

RuntimeProvider.Instance.SetColorBlock(mainButton, new Color(0.1f, 0.1f, 0.1f),
new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f));

UIFactory.SetLayoutElement(mainButton.gameObject, minHeight: 25, minWidth: 230);

Expand All @@ -539,15 +537,13 @@ private void AddObjectListButton()
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
m_shortListTexts.Add(mainText);

ColorBlock inspectColors = new ColorBlock();
inspectColors = RuntimeProvider.Instance.SetColorBlock(inspectColors, new Color(0.15f, 0.15f, 0.15f),
new Color(0.2f, 0.2f, 0.2f), new Color(0.1f, 0.1f, 0.1f));

var inspectButton = UIFactory.CreateButton(btnGroupObj,
"InspectButton",
"Inspect",
() => { InspectorManager.Instance.Inspect(m_shortList[thisIndex]); },
inspectColors);
() => { InspectorManager.Instance.Inspect(m_shortList[thisIndex]); });

RuntimeProvider.Instance.SetColorBlock(inspectButton, new Color(0.15f, 0.15f, 0.15f),
new Color(0.2f, 0.2f, 0.2f), new Color(0.1f, 0.1f, 0.1f));

UIFactory.SetLayoutElement(inspectButton.gameObject, minWidth: 60, minHeight: 25);
}
Expand Down
22 changes: 9 additions & 13 deletions src/UI/Main/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ public void SetPage(BaseMenuPage page)

internal void SetButtonActiveColors(Button button)
{
button.colors = RuntimeProvider.Instance.SetColorBlock(button.colors, m_navButtonSelected);
RuntimeProvider.Instance.SetColorBlock(button, m_navButtonSelected);
}

internal void SetButtonInactiveColors(Button button)
{
button.colors = RuntimeProvider.Instance.SetColorBlock(button.colors, m_navButtonNormal);
RuntimeProvider.Instance.SetColorBlock(button, m_navButtonNormal);
}

#region UI Construction
Expand Down Expand Up @@ -184,15 +184,13 @@ private void ConstructTitleBar(GameObject content)

// Hide button

ColorBlock colorBlock = new ColorBlock();
colorBlock = RuntimeProvider.Instance.SetColorBlock(colorBlock, new Color(65f / 255f, 23f / 255f, 23f / 255f),
new Color(35f / 255f, 10f / 255f, 10f / 255f), new Color(156f / 255f, 0f, 0f));

var hideButton = UIFactory.CreateButton(titleBar,
"HideButton",
$"Hide ({ConfigManager.Main_Menu_Toggle.Value})",
() => { UIManager.ShowMenu = false; },
colorBlock);
() => { UIManager.ShowMenu = false; });

RuntimeProvider.Instance.SetColorBlock(hideButton, new Color(65f / 255f, 23f / 255f, 23f / 255f),
new Color(35f / 255f, 10f / 255f, 10f / 255f), new Color(156f / 255f, 0f, 0f));

UIFactory.SetLayoutElement(hideButton.gameObject, minWidth: 90, flexibleWidth: 0);

Expand All @@ -213,16 +211,14 @@ private void ConstructNavbar(GameObject content)
GameObject navbarObj = UIFactory.CreateHorizontalGroup(content, "MainNavBar", true, true, true, true, 5);
UIFactory.SetLayoutElement(navbarObj, minHeight: 25, flexibleHeight: 0);

ColorBlock colorBlock = new ColorBlock();
colorBlock = RuntimeProvider.Instance.SetColorBlock(colorBlock, m_navButtonNormal, m_navButtonHighlight, m_navButtonSelected);

foreach (var page in Pages)
{
Button btn = UIFactory.CreateButton(navbarObj,
$"Button_{page.Name}",
page.Name,
() => { SetPage(page); },
colorBlock);
() => { SetPage(page); });

RuntimeProvider.Instance.SetColorBlock(btn, m_navButtonNormal, m_navButtonHighlight, m_navButtonSelected);

page.RefNavbarButton = btn;
}
Expand Down
Loading

0 comments on commit a5a07a0

Please sign in to comment.