-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added colorblind mode for LED Math & Conditional Buttons
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Tweaks/TweaksAssembly/Modules/Tweaks/ConditionalButtonsTweak.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
class ConditionalButtonsTweak : ModuleTweak | ||
{ | ||
private readonly Dictionary<string, string> colorblindChars = new Dictionary<string, string>() | ||
{ | ||
{ "pink", "I" }, | ||
{ "orange", "O" }, | ||
{ "purple", "P" }, | ||
{ "white", "W" }, | ||
{ "blue", "B" }, | ||
{ "yellow", "Y" }, | ||
{ "light green", "LG" }, | ||
{ "red", "R" }, | ||
{ "black", "K" }, | ||
{ "dark green", "DG" } | ||
}; | ||
|
||
private readonly List<GameObject> colorblindText = new List<GameObject>(); | ||
|
||
public ConditionalButtonsTweak(BombComponent bombComponent) : base(bombComponent, "conditionalButtons") | ||
{ | ||
if (!ColorblindMode.IsActive("conditionalButtons")) | ||
return; | ||
|
||
UpdateColorblind(); | ||
|
||
foreach (var selectable in bombComponent.GetComponent<KMSelectable>().Children) | ||
{ | ||
var previous = selectable.OnInteract; | ||
selectable.OnInteract = () => { | ||
previous(); | ||
foreach (var text in colorblindText) | ||
text.SetActive(false); | ||
return false; | ||
}; | ||
} | ||
} | ||
|
||
private void UpdateColorblind() | ||
{ | ||
void makeText(GameObject btn, string letter) | ||
{ | ||
var text = new GameObject("ColorblindText"); | ||
text.transform.SetParent(btn.transform, false); | ||
colorblindText.Add(text); | ||
|
||
var mesh = text.AddComponent<TextMesh>(); | ||
mesh.transform.localPosition = new Vector3(0, 0, 0.0051f); | ||
mesh.transform.localEulerAngles = new Vector3(0, 180, 180); | ||
mesh.characterSize = letter.Length == 1 ? 0.0015f : 0.0013f; | ||
mesh.fontSize = 80; | ||
mesh.anchor = TextAnchor.MiddleCenter; | ||
mesh.GetComponent<MeshRenderer>().sharedMaterial.shader = Shader.Find("GUI/KT 3D Text"); | ||
|
||
mesh.text = letter; | ||
mesh.color = (letter == "K" || letter == "DG") ? Color.white : Color.black; | ||
} | ||
|
||
var buttons = bombComponent.GetComponent<KMSelectable>().Children; | ||
for (int i = 0; i < buttons.Length; i++) | ||
makeText(buttons[i].gameObject, colorblindChars[buttons[i].GetComponent<MeshRenderer>().material.name.Replace(" (Instance)", "")]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
class LEDMathTweak : ModuleTweak | ||
{ | ||
private readonly string[] colorblindChars = { "R", "B", "G", "Y" }; | ||
|
||
private readonly List<GameObject> colorblindText = new List<GameObject>(); | ||
|
||
public LEDMathTweak(BombComponent bombComponent) : base(bombComponent, "LEDMathScript") | ||
{ | ||
if (!ColorblindMode.IsActive("lgndLEDMath")) | ||
return; | ||
|
||
UpdateColorblind(); | ||
|
||
bombComponent.OnPass += (_) => { | ||
foreach (var text in colorblindText) | ||
{ | ||
text.SetActive(false); | ||
} | ||
|
||
return false; | ||
}; | ||
} | ||
|
||
private void UpdateColorblind() | ||
{ | ||
void makeText(GameObject led, string letter) | ||
{ | ||
var text = new GameObject("ColorblindText"); | ||
text.transform.SetParent(led.transform, false); | ||
colorblindText.Add(text); | ||
|
||
var mesh = text.AddComponent<TextMesh>(); | ||
mesh.transform.localPosition = new Vector3(0, 0.501f, 0); | ||
mesh.transform.localEulerAngles = new Vector3(90, 0, 0); | ||
mesh.characterSize = 0.08f; | ||
mesh.fontSize = 80; | ||
mesh.anchor = TextAnchor.MiddleCenter; | ||
mesh.GetComponent<MeshRenderer>().sharedMaterial.shader = Shader.Find("GUI/KT 3D Text"); | ||
|
||
mesh.text = letter; | ||
mesh.color = Color.black; | ||
} | ||
|
||
var ledA = component.GetValue<MeshRenderer>("ledA").gameObject; | ||
var ledB = component.GetValue<MeshRenderer>("ledB").gameObject; | ||
var ledOp = component.GetValue<MeshRenderer>("ledOp").gameObject; | ||
makeText(ledA, colorblindChars[component.GetValue<int>("ledAIndex")]); | ||
makeText(ledB, colorblindChars[component.GetValue<int>("ledBIndex")]); | ||
makeText(ledOp, colorblindChars[component.GetValue<int>("ledOpIndex")]); | ||
} | ||
} |