private static void Postfix(Dictionary <int, MultiToggle> ___toggles_by_int, ILogicRibbonBitSelector ___target) { foreach ((var idx, var toggle) in ___toggles_by_int) { toggle.enabled = idx < ___target.GetBitDepth(); toggle.gameObject.SetActive(toggle.enabled); if (toggle.enabled) { bool active = ___target.IsBitActive(idx); string title; if (___target is Building.ILogicBundledBitSelector) { var target = (Building.ILogicBundledBitSelector)___target; var bundleIdx = idx * target.BundleSize + 1; title = String.Format(target.BundleTitle, bundleIdx, bundleIdx + target.BundleSize - 1); } else { title = String.Format(STRINGS.UI.UISIDESCREENS.LOGICBITSELECTORSIDESCREEN.BIT, idx + 1); } toggle.GetComponent <HierarchyReferences>().GetReference <LocText>("bitName").SetText(title); } } }
/// <summary> /// Applied before RenderEveryTick runs. /// </summary> internal static bool Prefix(LogicBitSelectorSideScreen __instance, Color ___activeColor, Color ___inactiveColor, ILogicRibbonBitSelector ___target) { if (__instance != null && __instance.isActiveAndEnabled && ___target != null) { foreach (var pair in __instance.toggles_by_int) { int bit = pair.Key; bool active = ___target.IsBitActive(bit), update = bit >= lastValues. Count; if (!update) { // If in range, see if bit changed update = active != lastValues[bit]; if (update) { lastValues[bit] = active; } } if (update) { UpdateBit(pair.Value, active, ___activeColor, ___inactiveColor); } } } return(false); }
/// <summary> /// Applied after OnSpawn runs. /// </summary> internal static void Postfix(LogicBitSelectorSideScreen __instance, Color ___activeColor, Color ___inactiveColor, ILogicRibbonBitSelector ___target) { if (__instance != null) { UPDATE_IO_DISPLAY.Invoke(__instance); } ForceUpdate(__instance, ___activeColor, ___inactiveColor, ___target); }
/// <summary> /// Updates all bits of the logic bit selector side screen. /// </summary> private static void ForceUpdate(LogicBitSelectorSideScreen instance, Color activeColor, Color inactiveColor, ILogicRibbonBitSelector target) { lastValues.Clear(); foreach (var pair in instance.toggles_by_int) { int bit = pair.Key; bool active = target.IsBitActive(bit); while (lastValues.Count <= bit) { lastValues.Add(false); } lastValues[bit] = active; UpdateBit(pair.Value, active, activeColor, inactiveColor); } }
private static void Postfix(int bit, Dictionary <int, MultiToggle> ___toggles_by_int, ILogicRibbonBitSelector ___target, Color ___activeColor, Color ___inactiveColor) { var toggle = ___toggles_by_int[bit]; toggle.enabled = bit < ___target.GetBitDepth(); if (toggle.enabled) { bool active = ___target.IsBitActive(bit); string state; Color color; if (___target is Building.ILogicBundledBitSelector) { var target = (Building.ILogicBundledBitSelector)___target; var activeBits = target.GetBitsAtSelection(bit); state = target.GetBundleState(activeBits); color = active ? activeBits == target.BundleMask ? ___activeColor : Color.yellow : ___inactiveColor; } else { state = active ? STRINGS.UI.UISIDESCREENS.LOGICBITSELECTORSIDESCREEN.STATE_ACTIVE : STRINGS.UI.UISIDESCREENS.LOGICBITSELECTORSIDESCREEN.STATE_INACTIVE; color = active ? ___activeColor : ___inactiveColor; } toggle.GetComponent <HierarchyReferences>().GetReference <LocText>("stateText").SetText(state); toggle.GetComponent <HierarchyReferences>().GetReference <KImage>("stateIcon").color = color; } }
/// <summary> /// Applied after RefreshToggles runs. /// </summary> internal static void Postfix(LogicBitSelectorSideScreen __instance, Color ___activeColor, Color ___inactiveColor, ILogicRibbonBitSelector ___target) { ForceUpdate(__instance, ___activeColor, ___inactiveColor, ___target); }