private void LogicCard(HoverTextDrawer hoverTextDrawer, List <KSelectable> hoverObjects)
        {
            foreach (KSelectable kselectable2 in hoverObjects)
            {
                LogicPorts ports      = kselectable2.GetComponent <LogicPorts>();
                string     properName = kselectable2.GetProperName().ToUpper();

                if (ports != null)
                {
                    LogicPorts.Port port;
                    bool            portIsInput;
                    if (ports.TryGetPortAtCell(cellPos, out port, out portIsInput))
                    {
                        LogicCardPort(hoverTextDrawer, properName, ports, port, portIsInput);
                    }
                }

                LogicGate            gates = kselectable2.GetComponent <LogicGate>();
                LogicGateBase.PortId portId;
                if (gates != null && gates.TryGetPortAtCell(cellPos, out portId))
                {
                    LogicCardGate(hoverTextDrawer, properName, gates, portId);
                }
            }
        }
Exemple #2
0
    private LogicCircuitNetwork GetNetwork()
    {
        LogicPorts          component           = GetComponent <LogicPorts>();
        int                 portCell            = component.GetPortCell(PORT_ID);
        LogicCircuitManager logicCircuitManager = Game.Instance.logicCircuitManager;

        return(logicCircuitManager.GetNetworkForCell(portCell));
    }
Exemple #3
0
 protected override void OnSpawn()
 {
     base.OnSpawn();
     ports = gameObject.GetComponent <LogicPorts>();
     Subscribe(-1697596308, new Action <object>(UpdateLogicCircuitCB));
     Subscribe(-592767678, new Action <object>(UpdateLogicCircuitCB));
     Subscribe((int)GameHashes.CopySettings, new Action <object>(OnCopySettings));
     UpdateLogicAndActiveState();
 }
        private static void CheckAndDrop(StorageLockerSmart storageLocker, LogicPorts ports)
        {
            if (ports.GetInputValue(DropPortID) == 1)
            {
                var filteredStorage = FilteredStorageGetter.Invoke(storageLocker);
                var storage         = StorageGetter.Invoke(filteredStorage);

                storage.DropAll();
            }
        }
        /// <summary>
        /// Only sends the logic signal update if the new value has changed from the last
        /// value.
        /// </summary>
        /// <param name="ports">The logic port object to which to send the signal.</param>
        /// <param name="portID">The logic port ID to update.</param>
        /// <param name="newValue">The new value of the port.</param>
        /// <param name="lastValue">The previous value of the activated flag.</param>
        private static void SendSignalIf(LogicPorts ports, HashedString portID, int newValue,
                                         bool lastValue)
        {
            int lastIntValue = lastValue ? 1 : 0;

            if (newValue != lastIntValue)
            {
                ports.SendSignal(portID, newValue);
            }
        }
 public Instance(Gantry master, bool manual_start_state)
     : base(master)
 {
     manual_on   = manual_start_state;
     operational = GetComponent <Operational>();
     logic       = GetComponent <LogicPorts>();
     Subscribe(-592767678, OnOperationalChanged);
     Subscribe(-801688580, OnLogicValueChanged);
     base.smi.sm.should_extend.Set(true, base.smi);
 }
            public static void Postfix(StorageLockerSmart __instance, LogicPorts ___ports)
            {
                __instance.Subscribe(Convert.ToInt32(GameHashes.LogicEvent), logicValueChanged =>
                {
                    var changed = (LogicValueChanged)logicValueChanged;

                    if (changed.portID == DropPortID && changed.newValue == 1)
                    {
                        CheckAndDrop(__instance, ___ports);
                    }
                });
            }
        public void SendSignal()
        {
            LogicPorts presencePort = this.gameObject.GetComponent <LogicPorts>();

            if (presencePort == null)
            {
                return;
            }
            if (currentState.HasValue && this.PortName != null && presencePort.IsPortConnected(this.PortName))
            {
                presencePort.SendSignal(this.PortName, currentState.Value == true ? 1 : 0);
            }
        }
Exemple #9
0
 protected override void OnSpawn()
 {
     base.OnSpawn();
     this.filteredStorage.FilterChanged();
     this.ports = this.gameObject.GetComponent <LogicPorts>();
     this.meter = new MeterController((KAnimControllerBase)this.GetComponent <KBatchedAnimController>(), "meter_target", "meter", Meter.Offset.Infront, Grid.SceneLayer.NoLayer, new string[2]
     {
         "meter_fill",
         "meter_OL"
     });
     //this.Subscribe<LiquidReservoirSmart>((int)GameHashes.OnStorageChange, OnStorageChangeDelegate);
     this.OnStorageChange((object)null);
 }
Exemple #10
0
    public void Sim1000ms(float dt)
    {
        Spacecraft spacecraftFromLaunchConditionManager = SpacecraftManager.instance.GetSpacecraftFromLaunchConditionManager(this);

        if (spacecraftFromLaunchConditionManager != null)
        {
            SpaceDestination spacecraftDestination = SpacecraftManager.instance.GetSpacecraftDestination(spacecraftFromLaunchConditionManager.id);
            LogicPorts       component             = base.gameObject.GetComponent <LogicPorts>();
            if (component.GetInputValue(triggerPort) == 1 && spacecraftDestination != null && spacecraftDestination.id != -1)
            {
                Launch(spacecraftDestination);
            }
        }
    }
        public override void DoPostConfigureComplete(GameObject go)
        {
            GeneratedBuildings.MakeBuildingAlwaysOperational(go);
            LogicPorts logicPorts = go.AddOrGet <LogicPorts>();

            logicPorts.inputPortInfo  = null;
            logicPorts.outputPortInfo = new LogicPorts.Port[1]
            {
                OUTPUT_PORT
            };
            LogicScheduleSensor logicScheduleSensor = go.AddOrGet <LogicScheduleSensor>();

            logicScheduleSensor.manuallyControlled = false;
        }
Exemple #12
0
    public void Sim4000ms(float dt)
    {
        bool       flag      = CheckReadyToLaunch();
        LogicPorts component = base.gameObject.GetComponent <LogicPorts>();

        if (flag)
        {
            Spacecraft spacecraftFromLaunchConditionManager = SpacecraftManager.instance.GetSpacecraftFromLaunchConditionManager(this);
            if (spacecraftFromLaunchConditionManager.state == Spacecraft.MissionState.Grounded || spacecraftFromLaunchConditionManager.state == Spacecraft.MissionState.Launching)
            {
                component.SendSignal(statusPort, 1);
            }
            else
            {
                component.SendSignal(statusPort, 0);
            }
            KSelectable component2 = GetComponent <KSelectable>();
            foreach (RocketModule rocketModule in rocketModules)
            {
                foreach (RocketFlightCondition flightCondition in rocketModule.flightConditions)
                {
                    if (!flightCondition.EvaluateFlightCondition())
                    {
                        if (!conditionStatuses.ContainsKey(flightCondition))
                        {
                            StatusItem failureStatusItem = flightCondition.GetFailureStatusItem();
                            conditionStatuses[flightCondition] = component2.AddStatusItem(failureStatusItem, flightCondition);
                        }
                    }
                    else if (conditionStatuses.ContainsKey(flightCondition))
                    {
                        component2.RemoveStatusItem(conditionStatuses[flightCondition], false);
                        conditionStatuses.Remove(flightCondition);
                    }
                }
            }
        }
        else
        {
            ClearFlightStatuses();
            component.SendSignal(statusPort, 0);
        }
    }
        public void Sim200ms(float dt)
        {
            if (sender == null || receiver == null)
            {
                return;
            }

            if (senderPorts == null)
            {
                senderPorts = sender.GetComponent <LogicPorts>();
            }
            if (receiverPorts == null)
            {
                receiverPorts = receiver.GetComponent <LogicPorts>();
            }

            int signal = senderPorts.GetInputValue(WarpBridgeData.InId);

            receiverPorts.SendSignal(WarpBridgeData.OutId, signal);
        }
Exemple #14
0
    public List <Descriptor> GetDescriptors(BuildingDef def)
    {
        List <Descriptor> list      = new List <Descriptor>();
        LogicPorts        component = def.BuildingComplete.GetComponent <LogicPorts>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            if (component.inputPortInfo != null && component.inputPortInfo.Length > 0)
            {
                Descriptor item = new Descriptor(UI.LOGIC_PORTS.INPUT_PORTS, UI.LOGIC_PORTS.INPUT_PORTS_TOOLTIP, Descriptor.DescriptorType.Effect, false);
                list.Add(item);
                Port[] array = component.inputPortInfo;
                for (int i = 0; i < array.Length; i++)
                {
                    Port   port    = array[i];
                    string tooltip = string.Format(UI.LOGIC_PORTS.INPUT_PORT_TOOLTIP, port.activeDescription, port.inactiveDescription);
                    item = new Descriptor(port.description, tooltip, Descriptor.DescriptorType.Effect, false);
                    item.IncreaseIndent();
                    list.Add(item);
                }
            }
            if (component.outputPortInfo != null && component.outputPortInfo.Length > 0)
            {
                Descriptor item2 = new Descriptor(UI.LOGIC_PORTS.OUTPUT_PORTS, UI.LOGIC_PORTS.INPUT_PORTS_TOOLTIP, Descriptor.DescriptorType.Effect, false);
                list.Add(item2);
                Port[] array2 = component.outputPortInfo;
                for (int j = 0; j < array2.Length; j++)
                {
                    Port   port2    = array2[j];
                    string tooltip2 = string.Format(UI.LOGIC_PORTS.OUTPUT_PORT_TOOLTIP, port2.activeDescription, port2.inactiveDescription);
                    item2 = new Descriptor(port2.description, tooltip2, Descriptor.DescriptorType.Effect, false);
                    item2.IncreaseIndent();
                    list.Add(item2);
                }
            }
        }
        return(list);
    }
        public void ScanEther()
        {
            EnergyConsumer consumer    = this.gameObject.GetComponent <EnergyConsumer>();
            Operational    operational = this.gameObject.GetComponent <Operational>();

            if (consumer == null || operational == null)
            {
                return;
            }

            int signal = 0;

            if (consumer.IsPowered && operational.IsOperational)
            {
                signal = RadioEther.Instance.GetSignal();
            }

            LogicPorts ports = this.gameObject.GetComponent <LogicPorts>();

            if (ports != null)
            {
                ports.SendSignal(RadioTowerConfig.ReceiverRadioPortId, signal);
            }
        }
        public int GetSignal()
        {
            int signal = 0;

            foreach (GameObject sender in senders)
            {
                if (sender == null)
                {
                    AddVanished(sender);
                }
                else
                {
                    EnergyConsumer consumer = sender.GetComponent <EnergyConsumer>();
                    LogicPorts     ports    = sender.GetComponent <LogicPorts>();
                    RadioTower     tower    = sender.GetComponent <RadioTower>();
                    if (consumer != null && ports != null && tower != null && consumer.IsPowered && tower.CheckSunExposition())
                    {
                        signal |= ports.GetInputValue(RadioTowerConfig.SnederRadioPortId);
                    }
                }
            }
            ClearVanished();
            return(signal);
        }
 public static void Postfix(StorageLockerSmart __instance, LogicPorts ___ports)
 {
     CheckAndDrop(__instance, ___ports);
 }
    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 LogicCardPort(HoverTextDrawer hoverTextDrawer, string properName, LogicPorts ports, LogicPorts.Port port, bool isInput)
        {
            hoverTextDrawer.BeginShadowBar(false);

            LocString defaultName;
            int       portState;
            string    fmt;

            if (isInput)
            {
                defaultName = UI.LOGIC_PORTS.PORT_INPUT_DEFAULT_NAME;
                portState   = ports.GetInputValue(port.id);
                fmt         = UI.TOOLS.GENERIC.LOGIC_INPUT_HOVER_FMT;
            }
            else
            {
                defaultName = UI.LOGIC_PORTS.PORT_OUTPUT_DEFAULT_NAME;
                portState   = ports.GetOutputValue(port.id);
                fmt         = UI.TOOLS.GENERIC.LOGIC_OUTPUT_HOVER_FMT;
            }
            string desc = port.displayCustomName ? port.description : defaultName.text;

            hoverTextDrawer.DrawText(fmt.Replace("{Port}", desc.ToUpper()).Replace("{Name}", properName), __this.Styles_BodyText.Standard);
            hoverTextDrawer.NewLine(26);

            bool             portConnected = ports.IsPortConnected(port.id);
            TextStyleSetting textStyleSetting;

            if (portConnected)
            {
                textStyleSetting = ((portState == 1) ? __this.Styles_LogicActive.Selected : __this.Styles_LogicSignalInactive);
            }
            else
            {
                textStyleSetting = __this.Styles_LogicActive.Standard;
            }
            hoverTextDrawer.DrawIcon((portState == 1 && portConnected) ? __this.iconActiveAutomationPort : __this.iconDash, textStyleSetting.textColor, 18, 2);
            hoverTextDrawer.DrawText(port.activeDescription, textStyleSetting);
            hoverTextDrawer.NewLine(26);

            TextStyleSetting textStyleSetting2;

            if (portConnected)
            {
                textStyleSetting2 = ((portState == 0) ? __this.Styles_LogicStandby.Selected : __this.Styles_LogicSignalInactive);
            }
            else
            {
                textStyleSetting2 = __this.Styles_LogicStandby.Standard;
            }
            hoverTextDrawer.DrawIcon((portState == 0 && portConnected) ? __this.iconActiveAutomationPort : __this.iconDash, textStyleSetting2.textColor, 18, 2);
            hoverTextDrawer.DrawText(port.inactiveDescription, textStyleSetting2);
            hoverTextDrawer.EndShadowBar();
        }
    private void RefreshDetails()
    {
        detailsPanel.SetActive(true);
        detailsPanel.GetComponent <CollapsibleDetailContentPanel>().HeaderLabel.text = UI.DETAILTABS.DETAILS.GROUPNAME_DETAILS;
        PrimaryElement      component  = selectedTarget.GetComponent <PrimaryElement>();
        CellSelectionObject component2 = selectedTarget.GetComponent <CellSelectionObject>();
        float   mass;
        float   temperature;
        Element element;
        byte    diseaseIdx;
        int     diseaseCount;

        if ((Object)component != (Object)null)
        {
            mass         = component.Mass;
            temperature  = component.Temperature;
            element      = component.Element;
            diseaseIdx   = component.DiseaseIdx;
            diseaseCount = component.DiseaseCount;
        }
        else
        {
            if (!((Object)component2 != (Object)null))
            {
                return;
            }
            mass         = component2.Mass;
            temperature  = component2.temperature;
            element      = component2.element;
            diseaseIdx   = component2.diseaseIdx;
            diseaseCount = component2.diseaseCount;
        }
        bool             flag = element.id == SimHashes.Vacuum || element.id == SimHashes.Void;
        float            specificHeatCapacity = element.specificHeatCapacity;
        float            highTemp             = element.highTemp;
        float            lowTemp    = element.lowTemp;
        BuildingComplete component3 = selectedTarget.GetComponent <BuildingComplete>();
        float            num        = (!((Object)component3 != (Object)null)) ? (-1f) : component3.creationTime;
        LogicPorts       component4 = selectedTarget.GetComponent <LogicPorts>();
        EnergyConsumer   component5 = selectedTarget.GetComponent <EnergyConsumer>();
        Operational      component6 = selectedTarget.GetComponent <Operational>();
        Battery          component7 = selectedTarget.GetComponent <Battery>();
        float            num2;
        float            num3;
        float            num4;

        if ((Object)component6 != (Object)null && ((Object)component4 != (Object)null || (Object)component5 != (Object)null || (Object)component7 != (Object)null))
        {
            num2 = component6.GetUptimeForTimeSpan(10f);
            num3 = component6.GetUptimeForTimeSpan(600f);
            num4 = component6.GetUptimeForTimeSpan(6000f);
        }
        else
        {
            num2 = -1f;
            num3 = -1f;
            num4 = -1f;
        }
        drawer.NewLabel(drawer.Format(UI.ELEMENTAL.PRIMARYELEMENT.NAME, element.name)).Tooltip(drawer.Format(UI.ELEMENTAL.PRIMARYELEMENT.TOOLTIP, element.name)).NewLabel(drawer.Format(UI.ELEMENTAL.MASS.NAME, GameUtil.GetFormattedMass(mass, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}")))
        .Tooltip(drawer.Format(UI.ELEMENTAL.MASS.TOOLTIP, GameUtil.GetFormattedMass(mass, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}")));
        if (num > 0f)
        {
            drawer.NewLabel(drawer.Format(UI.ELEMENTAL.AGE.NAME, Util.FormatTwoDecimalPlace((GameClock.Instance.GetTime() - num) / 600f))).Tooltip(drawer.Format(UI.ELEMENTAL.AGE.TOOLTIP, Util.FormatTwoDecimalPlace((GameClock.Instance.GetTime() - num) / 600f)));
        }
        else
        {
            drawer.NewLabel(drawer.Format(UI.ELEMENTAL.AGE.NAME, UI.ELEMENTAL.AGE.UNKNOWN)).Tooltip(UI.ELEMENTAL.AGE.UNKNOWN_TOOLTIP);
        }
        if (num2 >= 0f)
        {
            string text = UI.ELEMENTAL.UPTIME.NAME;
            text = text.Replace("{0}", GameUtil.GetFormattedTime(10f));
            text = text.Replace("{1}", GameUtil.GetFormattedTime(600f));
            text = text.Replace("{2}", GameUtil.GetFormattedTime(6000f));
            text = text.Replace("{3}", GameUtil.GetFormattedPercent(num2 * 100f, GameUtil.TimeSlice.None));
            text = text.Replace("{4}", GameUtil.GetFormattedPercent(num3 * 100f, GameUtil.TimeSlice.None));
            text = text.Replace("{5}", GameUtil.GetFormattedPercent(num4 * 100f, GameUtil.TimeSlice.None));
            drawer.NewLabel(text);
        }
        if (!flag)
        {
            bool     flag2      = false;
            float    num5       = element.thermalConductivity;
            Building component8 = selectedTarget.GetComponent <Building>();
            if ((Object)component8 != (Object)null)
            {
                num5 *= component8.Def.ThermalConductivity;
                flag2 = (component8.Def.ThermalConductivity < 1f);
            }
            string temperatureUnitSuffix = GameUtil.GetTemperatureUnitSuffix();
            float  shc   = specificHeatCapacity * 1f;
            string text2 = string.Format(UI.ELEMENTAL.SHC.NAME, GameUtil.GetDisplaySHC(shc).ToString("0.000"));
            string text3 = UI.ELEMENTAL.SHC.TOOLTIP;
            text3 = text3.Replace("{SPECIFIC_HEAT_CAPACITY}", text2 + GameUtil.GetSHCSuffix());
            text3 = text3.Replace("{TEMPERATURE_UNIT}", temperatureUnitSuffix);
            string text4 = string.Format(UI.ELEMENTAL.THERMALCONDUCTIVITY.NAME, GameUtil.GetDisplayThermalConductivity(num5).ToString("0.000"));
            string text5 = UI.ELEMENTAL.THERMALCONDUCTIVITY.TOOLTIP;
            text5 = text5.Replace("{THERMAL_CONDUCTIVITY}", text4 + GameUtil.GetThermalConductivitySuffix());
            text5 = text5.Replace("{TEMPERATURE_UNIT}", temperatureUnitSuffix);
            drawer.NewLabel(drawer.Format(UI.ELEMENTAL.TEMPERATURE.NAME, GameUtil.GetFormattedTemperature(temperature, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false))).Tooltip(drawer.Format(UI.ELEMENTAL.TEMPERATURE.TOOLTIP, GameUtil.GetFormattedTemperature(temperature, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false))).NewLabel(drawer.Format(UI.ELEMENTAL.DISEASE.NAME, GameUtil.GetFormattedDisease(diseaseIdx, diseaseCount, false)))
            .Tooltip(drawer.Format(UI.ELEMENTAL.DISEASE.TOOLTIP, GameUtil.GetFormattedDisease(diseaseIdx, diseaseCount, true)))
            .NewLabel(text2)
            .Tooltip(text3)
            .NewLabel(text4)
            .Tooltip(text5);
            if (flag2)
            {
                drawer.NewLabel(UI.GAMEOBJECTEFFECTS.INSULATED.NAME).Tooltip(UI.GAMEOBJECTEFFECTS.INSULATED.TOOLTIP);
            }
        }
        if (element.IsSolid)
        {
            drawer.NewLabel(drawer.Format(UI.ELEMENTAL.MELTINGPOINT.NAME, GameUtil.GetFormattedTemperature(highTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false))).Tooltip(drawer.Format(UI.ELEMENTAL.MELTINGPOINT.TOOLTIP, GameUtil.GetFormattedTemperature(highTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)));
            ElementChunk component9 = selectedTarget.GetComponent <ElementChunk>();
            if ((Object)component9 != (Object)null)
            {
                AttributeModifier attributeModifier = component.Element.attributeModifiers.Find((AttributeModifier m) => m.AttributeId == Db.Get().BuildingAttributes.OverheatTemperature.Id);
                if (attributeModifier != null)
                {
                    drawer.NewLabel(drawer.Format(UI.ELEMENTAL.OVERHEATPOINT.NAME, attributeModifier.GetFormattedString(selectedTarget.gameObject))).Tooltip(drawer.Format(UI.ELEMENTAL.OVERHEATPOINT.TOOLTIP, attributeModifier.GetFormattedString(selectedTarget.gameObject)));
                }
            }
        }
        else if (element.IsLiquid)
        {
            drawer.NewLabel(drawer.Format(UI.ELEMENTAL.FREEZEPOINT.NAME, GameUtil.GetFormattedTemperature(lowTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false))).Tooltip(drawer.Format(UI.ELEMENTAL.FREEZEPOINT.TOOLTIP, GameUtil.GetFormattedTemperature(lowTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false))).NewLabel(drawer.Format(UI.ELEMENTAL.VAPOURIZATIONPOINT.NAME, GameUtil.GetFormattedTemperature(highTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)))
            .Tooltip(drawer.Format(UI.ELEMENTAL.VAPOURIZATIONPOINT.TOOLTIP, GameUtil.GetFormattedTemperature(highTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)));
        }
        else if (!flag)
        {
            drawer.NewLabel(drawer.Format(UI.ELEMENTAL.DEWPOINT.NAME, GameUtil.GetFormattedTemperature(lowTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false))).Tooltip(drawer.Format(UI.ELEMENTAL.DEWPOINT.TOOLTIP, GameUtil.GetFormattedTemperature(lowTemp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)));
        }
        Attributes attributes = selectedTarget.GetAttributes();

        if (attributes != null)
        {
            for (int i = 0; i < attributes.Count; i++)
            {
                AttributeInstance attributeInstance = attributes.AttributeTable[i];
                if (attributeInstance.Attribute.ShowInUI == Attribute.Display.Details || attributeInstance.Attribute.ShowInUI == Attribute.Display.Expectation)
                {
                    drawer.NewLabel(attributeInstance.modifier.Name + ": " + attributeInstance.GetFormattedValue()).Tooltip(attributeInstance.GetAttributeValueTooltip());
                }
            }
        }
        List <Descriptor> detailDescriptors = GameUtil.GetDetailDescriptors(GameUtil.GetAllDescriptors(selectedTarget, false));

        for (int j = 0; j < detailDescriptors.Count; j++)
        {
            Descriptor descriptor = detailDescriptors[j];
            drawer.NewLabel(descriptor.text).Tooltip(descriptor.tooltipText);
        }
    }
        private void UpdateLogicCircuit()
        {
            LogicPorts component = GetComponent <LogicPorts>();

            component?.SendSignal(LogicSwitch.PORT_ID, switchedOn ? 1 : 0);
        }
    private bool CheckForConnection(int cell, string defName, string soundName, ref BuildingCellVisualizer outBcv, bool fireEvents = true)
    {
        outBcv = null;
        DebugUtil.Assert(defName != null, "defName was null");
        Building building = GetBuilding(cell);

        if (!(bool)building)
        {
            return(false);
        }
        DebugUtil.Assert(building.gameObject, "targetBuilding.gameObject was null");
        int num  = -1;
        int num2 = -1;
        int num3 = -1;

        if (defName.Contains("LogicWire"))
        {
            LogicPorts component = building.gameObject.GetComponent <LogicPorts>();
            if ((Object)component != (Object)null)
            {
                if (component.inputPorts != null)
                {
                    foreach (ILogicUIElement inputPort in component.inputPorts)
                    {
                        DebugUtil.Assert(inputPort != null, "input port was null");
                        if (inputPort.GetLogicUICell() == cell)
                        {
                            num = cell;
                            break;
                        }
                    }
                }
                if (num == -1 && component.outputPorts != null)
                {
                    foreach (ILogicUIElement outputPort in component.outputPorts)
                    {
                        DebugUtil.Assert(outputPort != null, "output port was null");
                        if (outputPort.GetLogicUICell() == cell)
                        {
                            num2 = cell;
                            break;
                        }
                    }
                }
            }
        }
        else if (defName.Contains("Wire"))
        {
            num  = building.GetPowerInputCell();
            num2 = building.GetPowerOutputCell();
        }
        else if (defName.Contains("Liquid"))
        {
            if (building.Def.InputConduitType == ConduitType.Liquid)
            {
                num = building.GetUtilityInputCell();
            }
            if (building.Def.OutputConduitType == ConduitType.Liquid)
            {
                num2 = building.GetUtilityOutputCell();
            }
            ElementFilter component2 = building.GetComponent <ElementFilter>();
            if ((Object)component2 != (Object)null)
            {
                DebugUtil.Assert(component2.portInfo != null, "elementFilter.portInfo was null A");
                if (component2.portInfo.conduitType == ConduitType.Liquid)
                {
                    num3 = component2.GetFilteredCell();
                }
            }
        }
        else if (defName.Contains("Gas"))
        {
            if (building.Def.InputConduitType == ConduitType.Gas)
            {
                num = building.GetUtilityInputCell();
            }
            if (building.Def.OutputConduitType == ConduitType.Gas)
            {
                num2 = building.GetUtilityOutputCell();
            }
            ElementFilter component3 = building.GetComponent <ElementFilter>();
            if ((Object)component3 != (Object)null)
            {
                DebugUtil.Assert(component3.portInfo != null, "elementFilter.portInfo was null B");
                if (component3.portInfo.conduitType == ConduitType.Gas)
                {
                    num3 = component3.GetFilteredCell();
                }
            }
        }
        if (cell == num || cell == num2 || cell == num3)
        {
            BuildingCellVisualizer buildingCellVisualizer = outBcv = building.gameObject.GetComponent <BuildingCellVisualizer>();
            if (((Object)buildingCellVisualizer != (Object)null) ? true : false)
            {
                if (fireEvents)
                {
                    buildingCellVisualizer.ConnectedEvent(cell);
                    string sound = GlobalAssets.GetSound(soundName, false);
                    if (sound != null)
                    {
                        KMonoBehaviour.PlaySound(sound);
                    }
                }
                return(true);
            }
        }
        outBcv = null;
        return(false);
    }
Exemple #23
0
 public static IEnumerable <int> GetLogicCells(this LogicPorts logicPorts)
 {
     return((logicPorts.inputPorts ?? new List <ILogicUIElement>())
            .Concat(logicPorts.outputPorts ?? new List <ILogicUIElement>())
            .Select(x => x.GetLogicUICell()));
 }