fix(stations): the race requirement comes first in the build panel
The race took the first free row after the materials and the crafting station. Each of those rows now moves one to the right and the race takes row 0: it decides whether the rest matters at all.
This commit is contained in:
parent
ce21036373
commit
7647b66aa0
1 changed files with 37 additions and 5 deletions
|
|
@ -77,8 +77,9 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The race in the build panel's requirement row, in the first slot after the materials and
|
||||
/// the crafting station - the slots Hud.SetupPieceInfo has just filled or switched off.
|
||||
/// The race in the build panel's requirement row, FIRST: the race decides whether the rest
|
||||
/// matters at all. Hud.SetupPieceInfo has just filled one row per material and one for the
|
||||
/// crafting station; each of those is moved one row to the right, and the race takes row 0.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
|
||||
public static class RaceStation_PieceInfo_Patch
|
||||
|
|
@ -100,10 +101,13 @@ namespace RacesOfValheim
|
|||
string[] races = For(piece);
|
||||
if (races == null || races.Length == 0 || __instance.m_requirementItems == null) return;
|
||||
|
||||
int slot = piece.m_resources.Length + (piece.m_craftingStation != null ? 1 : 0);
|
||||
if (slot >= __instance.m_requirementItems.Length) return;
|
||||
GameObject[] rows = __instance.m_requirementItems;
|
||||
int used = piece.m_resources.Length + (piece.m_craftingStation != null ? 1 : 0);
|
||||
if (used >= rows.Length) return;
|
||||
|
||||
GameObject row = __instance.m_requirementItems[slot];
|
||||
for (int i = used; i > 0; i--) CopyRow(rows[i - 1], rows[i]);
|
||||
|
||||
GameObject row = rows[0];
|
||||
Image icon = row.transform.Find("res_icon")?.GetComponent<Image>();
|
||||
TMP_Text name = row.transform.Find("res_name")?.GetComponent<TMP_Text>();
|
||||
TMP_Text amount = row.transform.Find("res_amount")?.GetComponent<TMP_Text>();
|
||||
|
|
@ -126,6 +130,34 @@ namespace RacesOfValheim
|
|||
// Vanilla's blink for a missing crafting station, on the name since there is no number.
|
||||
name.color = ok || Mathf.Sin(Time.time * 10f) <= 0f ? Color.white : Color.red;
|
||||
}
|
||||
|
||||
/// <summary>Everything SetupRequirement and the station row write, from one row to the next.</summary>
|
||||
private static void CopyRow(GameObject from, GameObject to)
|
||||
{
|
||||
to.SetActive(from.activeSelf);
|
||||
foreach (string child in new[] { "res_icon", "res_name", "res_amount" })
|
||||
{
|
||||
Transform a = from.transform.Find(child);
|
||||
Transform b = to.transform.Find(child);
|
||||
if (a == null || b == null) continue;
|
||||
b.gameObject.SetActive(a.gameObject.activeSelf);
|
||||
}
|
||||
|
||||
Image fromIcon = from.transform.Find("res_icon")?.GetComponent<Image>();
|
||||
Image toIcon = to.transform.Find("res_icon")?.GetComponent<Image>();
|
||||
if (fromIcon != null && toIcon != null) { toIcon.sprite = fromIcon.sprite; toIcon.color = fromIcon.color; }
|
||||
|
||||
foreach (string child in new[] { "res_name", "res_amount" })
|
||||
{
|
||||
TMP_Text a = from.transform.Find(child)?.GetComponent<TMP_Text>();
|
||||
TMP_Text b = to.transform.Find(child)?.GetComponent<TMP_Text>();
|
||||
if (a != null && b != null) { b.text = a.text; b.color = a.color; }
|
||||
}
|
||||
|
||||
UITooltip fromTip = from.GetComponent<UITooltip>();
|
||||
UITooltip toTip = to.GetComponent<UITooltip>();
|
||||
if (fromTip != null && toTip != null) toTip.m_text = fromTip.m_text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue