Esempio n. 1
0
        private static bool Prefix(SelectToolHoverTextCard __instance, List <KSelectable> hoverObjects)
        {
            new SelectToolHoverTextCardOverride(__instance).UpdateHoverElements(hoverObjects);

            // 全ての処理を奪う。他にやりようがない…
            return(false);
        }
Esempio n. 2
0
 public void Select(KSelectable new_selected, bool skipSound = false)
 {
     if (!((Object)new_selected == (Object)previousSelection))
     {
         previousSelection = new_selected;
         if ((Object)selected != (Object)null)
         {
             selected.Unselect();
         }
         GameObject gameObject = null;
         if ((Object)new_selected != (Object)null)
         {
             SelectToolHoverTextCard component = GetComponent <SelectToolHoverTextCard>();
             if ((Object)component != (Object)null)
             {
                 int currentSelectedSelectableIndex     = component.currentSelectedSelectableIndex;
                 int recentNumberOfDisplayedSelectables = component.recentNumberOfDisplayedSelectables;
                 if (recentNumberOfDisplayedSelectables != 0)
                 {
                     currentSelectedSelectableIndex = (currentSelectedSelectableIndex + 1) % recentNumberOfDisplayedSelectables;
                     if (!skipSound)
                     {
                         if (recentNumberOfDisplayedSelectables == 1)
                         {
                             KFMOD.PlayOneShot(GlobalAssets.GetSound("Select_empty", false));
                         }
                         else
                         {
                             EventInstance instance = KFMOD.BeginOneShot(GlobalAssets.GetSound("Select_full", false), Vector3.zero);
                             instance.setParameterValue("selection", (float)currentSelectedSelectableIndex);
                             SoundEvent.EndOneShot(instance);
                         }
                         playedSoundThisFrame = true;
                     }
                 }
             }
             if ((Object)new_selected == (Object)hover)
             {
                 ClearHover();
             }
             new_selected.Select();
             gameObject = new_selected.gameObject;
             selectMarker.SetTargetTransform(gameObject.transform);
             selectMarker.gameObject.SetActive(!new_selected.DisableSelectMarker);
         }
         else if ((Object)selectMarker != (Object)null)
         {
             selectMarker.gameObject.SetActive(false);
         }
         selected = new_selected;
         Game.Instance.Trigger(-1503271301, gameObject);
     }
 }
Esempio n. 3
0
 public static void Postfix(SelectToolHoverTextCard __instance, List <KSelectable> hoverObjects)
 {
     foreach (KSelectable selectable in hoverObjects)
     {
         Notepad pad = selectable.gameObject.GetComponent <Notepad>();
         if (pad != null)
         {
             HoverTextScreen instance = HoverTextScreen.Instance;
             HoverTextDrawer hover    = instance.BeginDrawing();
             hover.BeginShadowBar();
             hover.DrawIcon(Assets.GetSprite("icon_category_furniture"), 20);
             hover.DrawText(pad.activateText, __instance.ToolTitleTextStyle);
             hover.EndShadowBar();
             hover.EndDrawing();
         }
     }
 }
Esempio n. 4
0
        private static void DrawUnreachableCard(SelectToolHoverTextCard instance, List <KSelectable> overlayValidHoverObjects)
        {
            if (overlayValidHoverObjects.Count > 0)
            {
                StatusItem unreachable = Db.Get().MiscStatusItems.PickupableUnreachable;

                if (overlayValidHoverObjects.Any(x => x.HasStatusItem(unreachable)))
                {
                    HoverTextDrawer drawer = HoverTextScreen.Instance.drawer;

                    drawer.BeginShadowBar();
                    drawer.DrawIcon(unreachable.sprite.sprite, instance.Styles_BodyText.Standard.textColor, 18, -6);
                    drawer.AddIndent(8);
                    drawer.DrawText(unreachable.Name.ToUpper(), instance.Styles_Title.Standard);
                    drawer.EndShadowBar();
                }
            }
        }
            private static void DrawerHelper(SelectToolHoverTextCard inst, int cell, HoverTextDrawer drawer)
            {
                // Cell position info
                drawer.BeginShadowBar();
                var pos = Grid.CellToPos(cell);

                drawer.DrawText("POSITION", inst.Styles_Title.Standard);
                drawer.NewLine();
                drawer.DrawText($"({pos.x}, {pos.y})", inst.Styles_BodyText.Standard);
                drawer.NewLine();
                drawer.DrawText($"Cell {cell}", inst.Styles_BodyText.Standard);
                drawer.EndShadowBar();

                // Counts
                drawer.BeginShadowBar();
                drawer.DrawText("COUNT", inst.Styles_Title.Standard);
                drawer.NewLine();
                var p     = Grid.Objects[cell, (int)ObjectLayer.Pickupables];
                var count = 0;

                while (p != null && p.GetComponent <Pickupable>() is Pickupable p2)
                {
                    ++count;
                    p = p2.objectLayerListItem?.nextItem?.gameObject;
                }

                drawer.DrawText($"Pickupables: {count}", inst.Styles_BodyText.Standard);
                drawer.EndShadowBar();

                // Element info
                drawer.BeginShadowBar();
                var element = Grid.Element[cell];

                drawer.DrawText("ELEMENT", inst.Styles_Title.Standard);
                drawer.NewLine();
                drawer.DrawText($"Name: {element.name}", inst.Styles_BodyText.Standard);
                drawer.NewLine();
                var hardnessStr = GameUtil.GetHardnessString(element);

                if (hardnessStr == ELEMENTS.HARDNESS.NA)
                {
                    hardnessStr = "Not Solid";
                }

                drawer.DrawText($"Hardness: {hardnessStr}", inst.Styles_BodyText.Standard);

                // element.HasTransitionDown doesn't exist :c
                if (element.lowTempTransitionTarget != 0 && element.lowTempTransitionTarget != SimHashes.Unobtanium &&
                    element.lowTempTransition != null && element.lowTempTransition != element)
                {
                    drawer.NewLine();
                    drawer.DrawText(
                        $"Transition down to {element.lowTempTransition.name} at {Math.Round(GameUtil.GetTemperatureConvertedFromKelvin(element.lowTemp, GameUtil.temperatureUnit), 2)}{GameUtil.GetTemperatureUnitSuffix()}",
                        inst.Styles_BodyText.Standard
                        );
                }

                if (element.HasTransitionUp)
                {
                    drawer.NewLine();
                    drawer.DrawText(
                        $"Transition up to {element.highTempTransition.name} at {Math.Round(GameUtil.GetTemperatureConvertedFromKelvin(element.highTemp, GameUtil.temperatureUnit), 2)}{GameUtil.GetTemperatureUnitSuffix()}",
                        inst.Styles_BodyText.Standard
                        );
                }

                drawer.NewLine();
                drawer.DrawText(
                    $"Specific Heat Capacity: {GameUtil.GetFormattedSHC(element.specificHeatCapacity)}",
                    inst.Styles_BodyText.Standard
                    );

                drawer.NewLine();
                drawer.DrawText(
                    $"Thermal Conductivity: {GameUtil.GetThermalConductivityString(element)}",
                    inst.Styles_BodyText.Standard
                    );

                drawer.EndShadowBar();
            }
 internal SelectToolHoverTextCardOverride(SelectToolHoverTextCard instance)
 {
     this.__this             = instance;
     this.__private_accessor = new SelectToolHoverTextCardAccessor(instance);
 }
    public void ShowHoverTextOnHoveredItem(KSelectable hover_obj, HoverTextDrawer drawer, SelectToolHoverTextCard hover_text_card)
    {
        bool flag = false;

        foreach (Chore.Precondition.Context succeededContext in preconditionSnapshot.succeededContexts)
        {
            Chore.Precondition.Context current = succeededContext;
            if (current.chore.showAvailabilityInHoverText && !current.chore.target.isNull && !((UnityEngine.Object)current.chore.target.gameObject != (UnityEngine.Object)hover_obj.gameObject))
            {
                if (!flag)
                {
                    drawer.NewLine(26);
                    drawer.DrawText(DUPLICANTS.CHORES.PRECONDITIONS.HEADER.ToString().Replace("{Selected}", this.GetProperName()), hover_text_card.Styles_BodyText.Standard);
                    flag = true;
                }
                ShowHoverTextOnHoveredItem(current, hover_obj, drawer, hover_text_card);
            }
        }
        foreach (Chore.Precondition.Context failedContext in preconditionSnapshot.failedContexts)
        {
            Chore.Precondition.Context current2 = failedContext;
            if (current2.chore.showAvailabilityInHoverText && !current2.chore.target.isNull && !((UnityEngine.Object)current2.chore.target.gameObject != (UnityEngine.Object)hover_obj.gameObject))
            {
                if (!flag)
                {
                    drawer.NewLine(26);
                    drawer.DrawText(DUPLICANTS.CHORES.PRECONDITIONS.HEADER.ToString().Replace("{Selected}", this.GetProperName()), hover_text_card.Styles_BodyText.Standard);
                    flag = true;
                }
                ShowHoverTextOnHoveredItem(current2, hover_obj, drawer, hover_text_card);
            }
        }
    }
 public void ShowHoverTextOnHoveredItem(Chore.Precondition.Context context, KSelectable hover_obj, HoverTextDrawer drawer, SelectToolHoverTextCard hover_text_card)
 {
     if (!context.chore.target.isNull && !((UnityEngine.Object)context.chore.target.gameObject != (UnityEngine.Object)hover_obj.gameObject))
     {
         drawer.NewLine(26);
         drawer.AddIndent(36);
         drawer.DrawText(context.chore.choreType.Name, hover_text_card.Styles_BodyText.Standard);
         if (!context.IsSuccess())
         {
             Chore.PreconditionInstance preconditionInstance = context.chore.GetPreconditions()[context.failedPreconditionId];
             string text = preconditionInstance.description;
             if (string.IsNullOrEmpty(text))
             {
                 text = preconditionInstance.id;
             }
             if ((UnityEngine.Object)context.chore.driver != (UnityEngine.Object)null)
             {
                 text = text.Replace("{Assignee}", context.chore.driver.GetProperName());
             }
             text = text.Replace("{Selected}", this.GetProperName());
             drawer.DrawText(" (" + text + ")", hover_text_card.Styles_BodyText.Standard);
         }
     }
 }
    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();
    }
Esempio n. 10
0
 public SelectToolHoverTextCardAccessor(SelectToolHoverTextCard original)
 {
     this.original = original;
 }