public override void UpdateHoverElements(List <KSelectable> hoverObjects)
    {
        HoverTextScreen instance        = HoverTextScreen.Instance;
        HoverTextDrawer hoverTextDrawer = instance.BeginDrawing();

        hoverTextDrawer.BeginShadowBar(false);
        ActionName = ((!((UnityEngine.Object)currentDef != (UnityEngine.Object)null) || !currentDef.DragBuild) ? UI.TOOLS.BUILD.TOOLACTION : UI.TOOLS.BUILD.TOOLACTION_DRAG);
        if ((UnityEngine.Object)currentDef != (UnityEngine.Object)null && currentDef.Name != null)
        {
            ToolName = string.Format(UI.TOOLS.BUILD.NAME, currentDef.Name);
        }
        DrawTitle(instance, hoverTextDrawer);
        DrawInstructions(instance, hoverTextDrawer);
        int cell       = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos()));
        int min_height = 26;
        int width      = 8;

        if ((UnityEngine.Object)currentDef != (UnityEngine.Object)null)
        {
            Orientation orientation = Orientation.Neutral;
            if ((UnityEngine.Object)PlayerController.Instance.ActiveTool != (UnityEngine.Object)null)
            {
                Type type = PlayerController.Instance.ActiveTool.GetType();
                if (typeof(BuildTool).IsAssignableFrom(type) || typeof(BaseUtilityBuildTool).IsAssignableFrom(type))
                {
                    if ((UnityEngine.Object)currentDef.BuildingComplete.GetComponent <Rotatable>() != (UnityEngine.Object)null)
                    {
                        hoverTextDrawer.NewLine(min_height);
                        hoverTextDrawer.AddIndent(width);
                        string text = UI.TOOLTIPS.HELP_ROTATE_KEY.ToString();
                        text = text.Replace("{Key}", GameUtil.GetActionString(Action.RotateBuilding));
                        hoverTextDrawer.DrawText(text, Styles_Instruction.Standard);
                    }
                    orientation = BuildTool.Instance.GetBuildingOrientation;
                    string  fail_reason = "Unknown reason";
                    Vector3 pos         = Grid.CellToPosCCC(cell, Grid.SceneLayer.Building);
                    if (!currentDef.IsValidPlaceLocation(BuildTool.Instance.visualizer, pos, orientation, out fail_reason))
                    {
                        hoverTextDrawer.NewLine(min_height);
                        hoverTextDrawer.AddIndent(width);
                        hoverTextDrawer.DrawText(fail_reason, HoverTextStyleSettings[1]);
                    }
                    RoomTracker component = currentDef.BuildingComplete.GetComponent <RoomTracker>();
                    if ((UnityEngine.Object)component != (UnityEngine.Object)null && !component.SufficientBuildLocation(cell))
                    {
                        hoverTextDrawer.NewLine(min_height);
                        hoverTextDrawer.AddIndent(width);
                        hoverTextDrawer.DrawText(UI.TOOLTIPS.HELP_REQUIRES_ROOM, HoverTextStyleSettings[1]);
                    }
                }
            }
            hoverTextDrawer.NewLine(min_height);
            hoverTextDrawer.AddIndent(width);
            hoverTextDrawer.DrawText(ResourceRemainingDisplayScreen.instance.GetString(), Styles_BodyText.Standard);
            hoverTextDrawer.EndShadowBar();
            HashedString mode = SimDebugView.Instance.GetMode();
            if (mode == OverlayModes.Logic.ID && hoverObjects != null)
            {
                SelectToolHoverTextCard component2 = SelectTool.Instance.GetComponent <SelectToolHoverTextCard>();
                foreach (KSelectable hoverObject in hoverObjects)
                {
                    LogicPorts component3 = hoverObject.GetComponent <LogicPorts>();
                    if ((UnityEngine.Object)component3 != (UnityEngine.Object)null && component3.TryGetPortAtCell(cell, out LogicPorts.Port port, out bool isInput))
                    {
                        bool flag = component3.IsPortConnected(port.id);
                        hoverTextDrawer.BeginShadowBar(false);
                        int num;
                        if (isInput)
                        {
                            string replacement = (!port.displayCustomName) ? UI.LOGIC_PORTS.PORT_INPUT_DEFAULT_NAME.text : port.description;
                            num = component3.GetInputValue(port.id);
                            hoverTextDrawer.DrawText(UI.TOOLS.GENERIC.LOGIC_INPUT_HOVER_FMT.Replace("{Port}", replacement).Replace("{Name}", hoverObject.GetProperName().ToUpper()), component2.Styles_Title.Standard);
                        }
                        else
                        {
                            string replacement2 = (!port.displayCustomName) ? UI.LOGIC_PORTS.PORT_OUTPUT_DEFAULT_NAME.text : port.description;
                            num = component3.GetOutputValue(port.id);
                            hoverTextDrawer.DrawText(UI.TOOLS.GENERIC.LOGIC_OUTPUT_HOVER_FMT.Replace("{Port}", replacement2).Replace("{Name}", hoverObject.GetProperName().ToUpper()), component2.Styles_Title.Standard);
                        }
                        hoverTextDrawer.NewLine(26);
                        TextStyleSetting textStyleSetting = (!flag) ? component2.Styles_LogicActive.Standard : ((num != 1) ? component2.Styles_LogicSignalInactive : component2.Styles_LogicActive.Selected);
                        hoverTextDrawer.DrawIcon((num != 1 || !flag) ? component2.iconDash : component2.iconActiveAutomationPort, textStyleSetting.textColor, 18, 2);
                        hoverTextDrawer.DrawText(port.activeDescription, textStyleSetting);
                        hoverTextDrawer.NewLine(26);
                        TextStyleSetting textStyleSetting2 = (!flag) ? component2.Styles_LogicStandby.Standard : ((num != 0) ? component2.Styles_LogicSignalInactive : component2.Styles_LogicStandby.Selected);
                        hoverTextDrawer.DrawIcon((num != 0 || !flag) ? component2.iconDash : component2.iconActiveAutomationPort, textStyleSetting2.textColor, 18, 2);
                        hoverTextDrawer.DrawText(port.inactiveDescription, textStyleSetting2);
                        hoverTextDrawer.EndShadowBar();
                    }
                    LogicGate component4 = hoverObject.GetComponent <LogicGate>();
                    if ((UnityEngine.Object)component4 != (UnityEngine.Object)null && component4.TryGetPortAtCell(cell, out LogicGateBase.PortId port2))
                    {
                        int  portValue     = component4.GetPortValue(port2);
                        bool portConnected = component4.GetPortConnected(port2);
                        LogicGate.LogicGateDescriptions.Description portDescription = component4.GetPortDescription(port2);
                        hoverTextDrawer.BeginShadowBar(false);
                        if (port2 == LogicGateBase.PortId.Output)
                        {
                            hoverTextDrawer.DrawText(UI.TOOLS.GENERIC.LOGIC_MULTI_OUTPUT_HOVER_FMT.Replace("{Port}", portDescription.name).Replace("{Name}", hoverObject.GetProperName().ToUpper()), component2.Styles_Title.Standard);
                        }
                        else
                        {
                            hoverTextDrawer.DrawText(UI.TOOLS.GENERIC.LOGIC_MULTI_INPUT_HOVER_FMT.Replace("{Port}", portDescription.name).Replace("{Name}", hoverObject.GetProperName().ToUpper()), component2.Styles_Title.Standard);
                        }
                        hoverTextDrawer.NewLine(26);
                        TextStyleSetting textStyleSetting3 = (!portConnected) ? component2.Styles_LogicActive.Standard : ((portValue != 1) ? component2.Styles_LogicSignalInactive : component2.Styles_LogicActive.Selected);
                        hoverTextDrawer.DrawIcon((portValue != 1 || !portConnected) ? component2.iconDash : component2.iconActiveAutomationPort, textStyleSetting3.textColor, 18, 2);
                        hoverTextDrawer.DrawText(portDescription.active, textStyleSetting3);
                        hoverTextDrawer.NewLine(26);
                        TextStyleSetting textStyleSetting4 = (!portConnected) ? component2.Styles_LogicStandby.Standard : ((portValue != 0) ? component2.Styles_LogicSignalInactive : component2.Styles_LogicStandby.Selected);
                        hoverTextDrawer.DrawIcon((portValue != 0 || !portConnected) ? component2.iconDash : component2.iconActiveAutomationPort, textStyleSetting4.textColor, 18, 2);
                        hoverTextDrawer.DrawText(portDescription.inactive, textStyleSetting4);
                        hoverTextDrawer.EndShadowBar();
                    }
                }
            }
            else if (mode == OverlayModes.Power.ID)
            {
                CircuitManager circuitManager = Game.Instance.circuitManager;
                ushort         circuitID      = circuitManager.GetCircuitID(cell);
                if (circuitID != 65535)
                {
                    hoverTextDrawer.BeginShadowBar(false);
                    float wattsNeededWhenActive = circuitManager.GetWattsNeededWhenActive(circuitID);
                    wattsNeededWhenActive += currentDef.EnergyConsumptionWhenActive;
                    float maxSafeWattageForCircuit = circuitManager.GetMaxSafeWattageForCircuit(circuitID);
                    Color color = (!(wattsNeededWhenActive >= maxSafeWattageForCircuit)) ? Color.white : Color.red;
                    hoverTextDrawer.AddIndent(width);
                    hoverTextDrawer.DrawText(string.Format(UI.DETAILTABS.ENERGYGENERATOR.POTENTIAL_WATTAGE_CONSUMED, GameUtil.GetFormattedWattage(wattsNeededWhenActive, GameUtil.WattageFormatterUnit.Automatic)), Styles_BodyText.Standard, color, true);
                    hoverTextDrawer.EndShadowBar();
                }
            }
        }
        hoverTextDrawer.EndDrawing();
    }
 private void Refresh()
 {
     if (!((Object)selectedTarget == (Object)null))
     {
         foreach (KeyValuePair <string, GameObject> overviewLabel in overviewLabels)
         {
             overviewLabel.Value.SetActive(false);
         }
         foreach (KeyValuePair <string, GameObject> generatorsLabel in generatorsLabels)
         {
             generatorsLabel.Value.SetActive(false);
         }
         foreach (KeyValuePair <string, GameObject> consumersLabel in consumersLabels)
         {
             consumersLabel.Value.SetActive(false);
         }
         foreach (KeyValuePair <string, GameObject> batteriesLabel in batteriesLabels)
         {
             batteriesLabel.Value.SetActive(false);
         }
         CircuitManager circuitManager = Game.Instance.circuitManager;
         ushort         num            = ushort.MaxValue;
         EnergyConsumer component      = selectedTarget.GetComponent <EnergyConsumer>();
         if ((Object)component != (Object)null)
         {
             num = component.CircuitID;
         }
         else
         {
             Generator component2 = selectedTarget.GetComponent <Generator>();
             if ((Object)component2 != (Object)null)
             {
                 num = component2.CircuitID;
             }
         }
         if (num == 65535)
         {
             int cell = Grid.PosToCell(selectedTarget.transform.GetPosition());
             num = circuitManager.GetCircuitID(cell);
         }
         if (num != 65535)
         {
             overviewPanel.SetActive(true);
             generatorsPanel.SetActive(true);
             consumersPanel.SetActive(true);
             batteriesPanel.SetActive(true);
             float      joulesAvailableOnCircuit = circuitManager.GetJoulesAvailableOnCircuit(num);
             GameObject gameObject = AddOrGetLabel(overviewLabels, overviewPanel, "joulesAvailable");
             gameObject.GetComponent <LocText>().text    = string.Format(UI.DETAILTABS.ENERGYGENERATOR.AVAILABLE_JOULES, GameUtil.GetFormattedJoules(joulesAvailableOnCircuit, "F1", GameUtil.TimeSlice.None));
             gameObject.GetComponent <ToolTip>().toolTip = UI.DETAILTABS.ENERGYGENERATOR.AVAILABLE_JOULES_TOOLTIP;
             gameObject.SetActive(true);
             float wattsGeneratedByCircuit          = circuitManager.GetWattsGeneratedByCircuit(num);
             float potentialWattsGeneratedByCircuit = circuitManager.GetPotentialWattsGeneratedByCircuit(num);
             gameObject = AddOrGetLabel(overviewLabels, overviewPanel, "wattageGenerated");
             string text = null;
             text = ((wattsGeneratedByCircuit != potentialWattsGeneratedByCircuit) ? $"{GameUtil.GetFormattedWattage(wattsGeneratedByCircuit, GameUtil.WattageFormatterUnit.Automatic)} / {GameUtil.GetFormattedWattage(potentialWattsGeneratedByCircuit, GameUtil.WattageFormatterUnit.Automatic)}" : GameUtil.GetFormattedWattage(wattsGeneratedByCircuit, GameUtil.WattageFormatterUnit.Automatic));
             gameObject.GetComponent <LocText>().text    = string.Format(UI.DETAILTABS.ENERGYGENERATOR.WATTAGE_GENERATED, text);
             gameObject.GetComponent <ToolTip>().toolTip = UI.DETAILTABS.ENERGYGENERATOR.WATTAGE_GENERATED_TOOLTIP;
             gameObject.SetActive(true);
             gameObject = AddOrGetLabel(overviewLabels, overviewPanel, "wattageConsumed");
             gameObject.GetComponent <LocText>().text    = string.Format(UI.DETAILTABS.ENERGYGENERATOR.WATTAGE_CONSUMED, GameUtil.GetFormattedWattage(circuitManager.GetWattsUsedByCircuit(num), GameUtil.WattageFormatterUnit.Automatic));
             gameObject.GetComponent <ToolTip>().toolTip = UI.DETAILTABS.ENERGYGENERATOR.WATTAGE_CONSUMED_TOOLTIP;
             gameObject.SetActive(true);
             gameObject = AddOrGetLabel(overviewLabels, overviewPanel, "potentialWattageConsumed");
             gameObject.GetComponent <LocText>().text    = string.Format(UI.DETAILTABS.ENERGYGENERATOR.POTENTIAL_WATTAGE_CONSUMED, GameUtil.GetFormattedWattage(circuitManager.GetWattsNeededWhenActive(num), GameUtil.WattageFormatterUnit.Automatic));
             gameObject.GetComponent <ToolTip>().toolTip = UI.DETAILTABS.ENERGYGENERATOR.POTENTIAL_WATTAGE_CONSUMED_TOOLTIP;
             gameObject.SetActive(true);
             gameObject = AddOrGetLabel(overviewLabels, overviewPanel, "maxSafeWattage");
             gameObject.GetComponent <LocText>().text    = string.Format(UI.DETAILTABS.ENERGYGENERATOR.MAX_SAFE_WATTAGE, GameUtil.GetFormattedWattage(circuitManager.GetMaxSafeWattageForCircuit(num), GameUtil.WattageFormatterUnit.Automatic));
             gameObject.GetComponent <ToolTip>().toolTip = UI.DETAILTABS.ENERGYGENERATOR.MAX_SAFE_WATTAGE_TOOLTIP;
             gameObject.SetActive(true);
             ReadOnlyCollection <Generator>       generatorsOnCircuit = circuitManager.GetGeneratorsOnCircuit(num);
             ReadOnlyCollection <IEnergyConsumer> consumersOnCircuit  = circuitManager.GetConsumersOnCircuit(num);
             List <Battery> batteriesOnCircuit = circuitManager.GetBatteriesOnCircuit(num);
             ReadOnlyCollection <Battery> transformersOnCircuit = circuitManager.GetTransformersOnCircuit(num);
             if (generatorsOnCircuit.Count > 0)
             {
                 foreach (Generator item in generatorsOnCircuit)
                 {
                     if ((Object)item != (Object)null && (Object)item.GetComponent <Battery>() == (Object)null)
                     {
                         gameObject = AddOrGetLabel(generatorsLabels, generatorsPanel, item.gameObject.GetInstanceID().ToString());
                         Operational component3 = item.GetComponent <Operational>();
                         if (component3.IsActive)
                         {
                             gameObject.GetComponent <LocText>().text = $"{item.GetComponent<KSelectable>().entityName}: {GameUtil.GetFormattedWattage(item.WattageRating, GameUtil.WattageFormatterUnit.Automatic)}";
                         }
                         else
                         {
                             gameObject.GetComponent <LocText>().text = $"{item.GetComponent<KSelectable>().entityName}: {GameUtil.GetFormattedWattage(0f, GameUtil.WattageFormatterUnit.Automatic)} / {GameUtil.GetFormattedWattage(item.WattageRating, GameUtil.WattageFormatterUnit.Automatic)}";
                         }
                         gameObject.SetActive(true);
                         gameObject.GetComponent <LocText>().fontStyle = (((Object)item.gameObject == (Object)selectedTarget) ? FontStyles.Bold : FontStyles.Normal);
                     }
                 }
             }
             else
             {
                 gameObject = AddOrGetLabel(generatorsLabels, generatorsPanel, "nogenerators");
                 gameObject.GetComponent <LocText>().text = UI.DETAILTABS.ENERGYGENERATOR.NOGENERATORS;
                 gameObject.SetActive(true);
             }
             if (consumersOnCircuit.Count > 0 || transformersOnCircuit.Count > 0)
             {
                 foreach (IEnergyConsumer item2 in consumersOnCircuit)
                 {
                     AddConsumerInfo(item2, gameObject);
                 }
                 foreach (Battery item3 in transformersOnCircuit)
                 {
                     AddConsumerInfo(item3, gameObject);
                 }
             }
             else
             {
                 gameObject = AddOrGetLabel(consumersLabels, consumersPanel, "noconsumers");
                 gameObject.GetComponent <LocText>().text = UI.DETAILTABS.ENERGYGENERATOR.NOCONSUMERS;
                 gameObject.SetActive(true);
             }
             if (batteriesOnCircuit.Count > 0)
             {
                 foreach (Battery item4 in batteriesOnCircuit)
                 {
                     if ((Object)item4 != (Object)null)
                     {
                         gameObject = AddOrGetLabel(batteriesLabels, batteriesPanel, item4.gameObject.GetInstanceID().ToString());
                         gameObject.GetComponent <LocText>().text = string.Format("{0}: {1}", item4.GetComponent <KSelectable>().entityName, GameUtil.GetFormattedJoules(item4.JoulesAvailable, "F1", GameUtil.TimeSlice.None));
                         gameObject.SetActive(true);
                         gameObject.GetComponent <LocText>().fontStyle = (((Object)item4.gameObject == (Object)selectedTarget) ? FontStyles.Bold : FontStyles.Normal);
                     }
                 }
             }
             else
             {
                 gameObject = AddOrGetLabel(batteriesLabels, batteriesPanel, "nobatteries");
                 gameObject.GetComponent <LocText>().text = UI.DETAILTABS.ENERGYGENERATOR.NOBATTERIES;
                 gameObject.SetActive(true);
             }
         }
         else
         {
             overviewPanel.SetActive(true);
             generatorsPanel.SetActive(false);
             consumersPanel.SetActive(false);
             batteriesPanel.SetActive(false);
             GameObject gameObject2 = AddOrGetLabel(overviewLabels, overviewPanel, "nocircuit");
             gameObject2.GetComponent <LocText>().text = UI.DETAILTABS.ENERGYGENERATOR.DISCONNECTED;
             gameObject2.SetActive(true);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Updates the circuit summary information.
        /// </summary>
        /// <param name="manager">The circuit manager to query.</param>
        /// <param name="circuitID">The circuit to look up.</param>
        private void RefreshSummary(CircuitManager manager, ushort circuitID)
        {
            var text = CACHED_BUILDER;

            // Available
            text.Clear().Append(ENERGYGENERATOR.AVAILABLE_JOULES).Replace("{0}", GameUtil.
                                                                          GetFormattedJoules(manager.GetJoulesAvailableOnCircuit(circuitID)));
            joulesAvailable.text.SetText(text);
            // Generated
            float generated = GetWattageGenerated(manager, circuitID, out float potential);

            text.Clear();
            if (Mathf.Approximately(generated, potential))
            {
                FormatStringPatches.GetFormattedWattage(text, generated);
            }
            else
            {
                FormatStringPatches.GetFormattedWattage(text, generated);
                text.Append(" / ");
                FormatStringPatches.GetFormattedWattage(text, potential);
            }
            string ratio = text.ToString();

            text.Clear().Append(ENERGYGENERATOR.WATTAGE_GENERATED).Replace("{0}", ratio);
            wattageGenerated.text.SetText(text);
            // Consumed
            text.Clear().Append(ENERGYGENERATOR.WATTAGE_CONSUMED).Replace("{0}",
                                                                          GameUtil.GetFormattedWattage(manager.GetWattsUsedByCircuit(circuitID)));
            wattageConsumed.text.SetText(text);
            // Max consumed
            text.Clear().Append(ENERGYGENERATOR.POTENTIAL_WATTAGE_CONSUMED).Replace("{0}",
                                                                                    GameUtil.GetFormattedWattage(GetWattsNeededWhenActive(manager, circuitID)));
            potentialWattageConsumed.text.SetText(text);
            // Max safe
            text.Clear().Append(ENERGYGENERATOR.MAX_SAFE_WATTAGE).Replace("{0}",
                                                                          GameUtil.GetFormattedWattage(manager.GetMaxSafeWattageForCircuit(circuitID)));
            maxSafeWattage.text.SetText(text);
        }