Skip to content

Commit

Permalink
General fixes
Browse files Browse the repository at this point in the history
- Applied zone data for finding the combinedScene object
- Fixed non-treehouse keys not loading due to some of them lacking a material
  • Loading branch information
developer9998 committed Aug 29, 2023
1 parent ea79ee9 commit 5d713c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
33 changes: 19 additions & 14 deletions ComputerInterface/CustomComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ private async Task ReplaceKeys(GameObject computer)
nameToEnum.Add(key, (EKeyboardKey)Enum.Parse(typeof(EKeyboardKey), enumString));
}

foreach (var button in computer.GetComponentsInChildren<GorillaKeyboardButton>())
foreach (var button in computer.GetComponentsInChildren<GorillaKeyboardButton>(true))
{

if (button.characterString == "up" || button.characterString == "down")
{
button.GetComponentInChildren<MeshRenderer>().material.color = new Color(0.1f, 0.1f, 0.1f);
button.GetComponentInChildren<MeshRenderer>(true).material.color = new Color(0.1f, 0.1f, 0.1f);
button.transform.localPosition -= new Vector3(0, 0.6f, 0);
DestroyImmediate(button.GetComponent<BoxCollider>());
if(FindText(button.gameObject, button.name + "text")?.GetComponent<Text>() is Text arrowBtnText)
Expand Down Expand Up @@ -392,23 +392,21 @@ private CustomKeyboardKey CreateKey(GameObject prefab, string goName, Vector3 of
newKeyText.transform.localPosition += offset;

var customKeyboardKey = newKey.GetComponent<CustomKeyboardKey>();

if (label.IsNullOrWhiteSpace())
{
customKeyboardKey.Init(this, key);
}
else if (color.HasValue)
{
customKeyboardKey.Init(this, key, newKeyText, label, color.Value);
}
else
{
if (color.HasValue)
{
customKeyboardKey.Init(this, key, newKeyText, label, color.Value);
}
else
{
customKeyboardKey.Init(this, key, newKeyText, label);
}
customKeyboardKey.Init(this, key, newKeyText, label);
}
_keys.Add(customKeyboardKey);

_keys.Add(customKeyboardKey);
return customKeyboardKey;
}

Expand Down Expand Up @@ -482,11 +480,18 @@ private void RemoveMonitor(GameObject computer, MonitorLocation monitorIndex)
// Currently, This is broken as the combined mesh has isReadable set to false
// so all the mesh info lives on the GPU, which makes it unaccessabel afaik

// https://github.com/legoandmars/Utilla/blob/457bc612eda8e63b989dcdb219e04e8e7f06393a/Utilla/GamemodeManager.cs#L54
ZoneManagement zoneManager = FindObjectOfType<ZoneManagement>();

// https://github.com/legoandmars/Utilla/blob/457bc612eda8e63b989dcdb219e04e8e7f06393a/Utilla/GamemodeManager.cs#L56
ZoneData FindZoneData(GTZone zone)
=> (ZoneData)AccessTools.Method(typeof(ZoneManagement), "GetZoneData").Invoke(zoneManager, new object[] { zone });

GameObject combinedScene = monitorIndex switch
{
MonitorLocation.Treehouse => GameObject.Find("LocalObjects_Prefab/Forest/Terrain/Uncover ForestCombined/").GetComponentInChildren<MeshRenderer>().gameObject,
MonitorLocation.Mountains => GameObject.Find("Mountain/Mountain Texture Baker/Uncover Mountain Lit/").GetComponentInChildren<MeshRenderer>().gameObject,
MonitorLocation.Beach => GameObject.Find("Beach/Beach Texture Baker - ABOVE WATER/Uncover Beach Lit/").GetComponentInChildren<MeshRenderer>().gameObject,
MonitorLocation.Treehouse => FindZoneData(GTZone.forest).rootGameObjects[1].transform.Find("Terrain/Uncover ForestCombined/").GetComponentInChildren<MeshRenderer>(true).gameObject,
MonitorLocation.Mountains => FindZoneData(GTZone.mountain).rootGameObjects[0].transform.Find("Mountain Texture Baker/Uncover Mountain Lit/").GetComponentInChildren<MeshRenderer>(true).gameObject,
MonitorLocation.Beach => FindZoneData(GTZone.beach).rootGameObjects[0].transform.Find("Beach Texture Baker - ABOVE WATER/Uncover Beach Lit/").GetComponentInChildren<MeshRenderer>(true).gameObject,
_ => null,
};

Expand Down
19 changes: 19 additions & 0 deletions ComputerInterface/CustomKeyboardKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,28 @@ public void Init(CustomComputer computer, EKeyboardKey key, Text keyboardText, s
public void Init(CustomComputer computer, EKeyboardKey key, Text keyboardText, string text, Color buttonColor)
{
Init(computer, key, keyboardText, text);

if (_material == null)
{
_originalColor = buttonColor;

var baseRenderer = GetComponent<Renderer>();
if (baseRenderer.material == null)
{
_material = new Material(Shader.Find("Legacy Shaders/Diffuse"))
{
color = buttonColor
};
goto PrepareColour;
}
baseRenderer.material.color = buttonColor;
goto PrepareColour;
}

_material.color = buttonColor;
_originalColor = buttonColor;

PrepareColour:
Color.RGBToHSV(buttonColor, out float H, out float S, out float _);
_pressedColor = Color.HSVToRGB(H, S, 0.6f);
}
Expand Down

0 comments on commit 5d713c0

Please sign in to comment.