Example #1
0
        // Prefix patch:
        // diverts original method, copying functionality except for walls
        static bool Prefix(DesignationDragger __instance)
        {
            if (Find.DesignatorManager.SelectedDesignator.DraggableDimensions == 1)
            {
                // get ref to starting cell
                var startCell = (IntVec3)AccessTools.Field(typeof(DesignationDragger), "startDragCell").GetValue(__instance);
                var mouseCell = UI.MouseCell();

                // get ref to private list once
                var dragCells = (List <IntVec3>)AccessTools.Field(typeof(DesignationDragger), "dragCells").GetValue(__instance);
                dragCells.Clear();

                // get ref to failure reason
                var failReason = AccessTools.Field(typeof(DesignationDragger), "failureReasonInt");

                foreach (var cell in startCell.CellsInLineTo(mouseCell))
                {
                    // try to add cells to list
                    var _failReason = TryAddDragCellWithFailReason(cell, dragCells);

                    failReason.SetValue(__instance, _failReason);
                }

                // disable original function
                return(false);
            }

            // defaulting to original function
            return(true);
        }
Example #2
0
        public override void DrawMouseAttachments()
        {
            base.DrawMouseAttachments();
            if (ArchitectCategoryTab.InfoRect.Contains(UI.MousePositionOnUIInverted))
            {
                return;
            }
            DesignationDragger dragger = Find.DesignatorManager.Dragger;
            int     num    = ((!dragger.Dragging) ? 1 : dragger.DragCells.Count());
            float   num2   = 0f;
            Vector2 vector = Event.current.mousePosition + DragPriceDrawOffset;
            List <ThingDefCountClass> list = entDef.CostListAdjusted(stuffDef);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                float y = vector.y + num2;
                Widgets.ThingIcon(new Rect(vector.x, y, 27f, 27f), thingDefCountClass.thingDef);
                Rect   rect = new Rect(vector.x + 29f, y, 999f, 29f);
                int    num3 = num * thingDefCountClass.count;
                string text = num3.ToString();
                if (base.Map.resourceCounter.GetCount(thingDefCountClass.thingDef) < num3)
                {
                    GUI.color = Color.red;
                    text     += " (" + "NotEnoughStoredLower".Translate() + ")";
                }
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(rect, text);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
                num2       += 29f;
            }
        }
Example #3
0
        public override void DesignateMultiCell(IEnumerable <IntVec3> cells)
        {
            if (cells != null)
            {
                DesignationDragger dragger = Find.DesignatorManager.Dragger;
                FieldInfo          fi = typeof(DesignationDragger).GetField("startDragCell", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                IntVec3            startDragCell = (IntVec3)fi.GetValue(dragger);
                int minX = int.MaxValue, minZ = int.MaxValue, maxX = int.MinValue, maxZ = int.MinValue;
                foreach (IntVec3 v in cells)
                {
                    minX = Math.Min(minX, v.x);
                    minZ = Math.Min(minZ, v.z);
                    maxX = Math.Max(maxX, v.x);
                    maxZ = Math.Max(maxZ, v.z);
                }
                //whichever abs delta is larger determines if it is horizontal or vertical movement.
                bool horizontalMovement = (maxX - minX) > (maxZ - minZ);
                //based on which end the start cell matches we know the direction of the movement. we also dont want the last cell in the drag since it is used only as an indicator for the direction.
                List <IntVec3> cellsCopy = new List <IntVec3>(cells);
                if (horizontalMovement)
                {
                    if (startDragCell.x == minX)
                    {
                        directions = new [] { Direction8Way.East };
                        cellsCopy.RemoveAll(v => v.x == maxX);
                    }
                    else
                    {
                        directions = new [] { Direction8Way.West };
                        cellsCopy.RemoveAll(v => v.x == minX);
                    }
                }
                else
                {
                    if (startDragCell.z == minZ)
                    {
                        directions = new [] { Direction8Way.North };
                        cellsCopy.RemoveAll(v => v.z == maxZ);
                    }
                    else
                    {
                        directions = new [] { Direction8Way.South };
                        cellsCopy.RemoveAll(v => v.z == minZ);
                    }
                }
                cells = cellsCopy;
            }

            base.DesignateMultiCell(cells);
        }
        public static void DrawBridgeCost(Designator_Build designator, Vector2 drawPos, float curY, ThingDef stuff)
        {
            DesignationDragger dragger  = Find.DesignatorManager.Dragger;
            int bridgeCount             = 0;
            IEnumerable <IntVec3> cells = dragger.Dragging ? dragger.DragCells :
                                          GenAdj.OccupiedRect(UI.MouseCell(), designator.PlacingRot(), designator.PlacingDef.Size).Cells;

            foreach (IntVec3 dragPos in cells)
            {
                if (PlaceBridges.NeedsBridge(designator.PlacingDef, dragPos, designator.Map, stuff))
                {
                    bridgeCount++;
                }
            }

            if (bridgeCount == 0)
            {
                return;
            }

            //could just say wood here, this is still assuming it costs only one thing.
            ThingDefCountClass bridgeCost = TerrainDefOf.Bridge.costList.First();

            Widgets.ThingIcon(new Rect(drawPos.x, drawPos.y + curY, 27f, 27f), bridgeCost.thingDef);

            int totalCost = bridgeCost.count * bridgeCount;

            string label = $"{totalCost} ({TerrainDefOf.Bridge.LabelCap})";

            //This doesn't account for normal building cost + under bridge cost, but what can you do
            if (designator.Map.resourceCounter.GetCount(bridgeCost.thingDef) < totalCost)
            {
                GUI.color = Color.red;
                label     = label + " (" + "NotEnoughStoredLower".Translate() + ")";
            }
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(new Rect(drawPos.x + 29f, drawPos.y + curY, 999f, 29f), label);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }
Example #5
0
        public static void Prefix(DesignationDragger __instance)
        {
            if (!DesignatorShapes.ShowControls)
            {
                return;
            }
            if (__instance == null)
            {
                return;
            }
            if (Time.frameCount == (int)__instance.GetInstanceField <object>("lastUpdateFrame"))
            {
                return;
            }

            if (DesignatorShapes.CurrentTool == null)
            {
                return;
            }
            __instance.SetInstanceField("lastUpdateFrame", Time.frameCount);
            __instance.DragCells.Clear();
            __instance.SetInstanceField <string>("failureReasonInt", null);

            var start     = (IntVec3)__instance.GetInstanceField <object>("startDragCell");
            var sizeOrEnd = DesignatorShapes.CurrentTool.useSizeInputs ? ShapeControls.InputVec : UI.MouseCell();

            var points = DesignatorShapes.CurrentTool?.DrawMethod(start, sizeOrEnd);

            foreach (var vec in points)
            {
                if (vec == null)
                {
                    continue;
                }
                __instance.InvokeMethod("TryAddDragCell", vec);
            }
        }
Example #6
0
 public static bool Prefix(DesignationDragger __instance)
 {
     return(__instance.Dragging);
 }
        //protected override void DrawPlaceMouseAttachments(float curX, ref float curY)
        public static void Postfix(Designator_Build __instance, float curX, ref float curY)
        {
            List <TerrainDef> neededBridges = new List <TerrainDef>();

            ThingDef              stuff   = __instance.StuffDef;
            DesignationDragger    dragger = Find.DesignatorManager.Dragger;
            IEnumerable <IntVec3> cells   = dragger.Dragging ? dragger.DragCells :
                                            GenAdj.OccupiedRect(UI.MouseCell(), __instance.PlacingRot(), __instance.PlacingDef.Size).Cells;

            foreach (IntVec3 dragPos in cells)
            {
                if (PlaceBridges.GetNeededBridge(__instance.PlacingDef, dragPos, __instance.Map, stuff) is TerrainDef tdef)
                {
                    neededBridges.Add(tdef);
                }
            }

            if (neededBridges.Count == 0)
            {
                return;
            }

            Dictionary <ThingDef, int> bridgeTotalCost = new Dictionary <ThingDef, int>();
            float work = 0;

            foreach (TerrainDef bridgeDef in neededBridges)
            {
                work += bridgeDef.GetStatValueAbstract(StatDefOf.WorkToBuild);
                if (bridgeDef.costList != null)
                {
                    foreach (ThingDefCountClass bridgeCost in bridgeDef.costList)
                    {
                        bridgeTotalCost.TryGetValue(bridgeCost.thingDef, out int costCount);
                        bridgeTotalCost[bridgeCost.thingDef] = costCount + bridgeCost.count;
                    }
                }
            }

            if (bridgeTotalCost.Count == 0)
            {
                string label = $"{StatDefOf.WorkToBuild.LabelCap}: {work.ToStringWorkAmount()} ({TerrainDefOf.Bridge.LabelCap})";                 //Not bridgeCostDef.LabelCap

                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(new Rect(curX + 29f, curY, 999f, 29f), label);                 //private const float DragPriceDrawNumberX
                curY       += 29f;
                Text.Anchor = TextAnchor.UpperLeft;
            }

            foreach (var(bridgeCostDef, bridgeCostCount) in bridgeTotalCost.Select(x => (x.Key, x.Value)))
            {
                Widgets.ThingIcon(new Rect(curX, curY, 27f, 27f), bridgeCostDef);

                string label = $"{bridgeCostCount} ({TerrainDefOf.Bridge.LabelCap})";                 //Not bridgeCostDef.LabelCap
                //This doesn't account for normal building cost + under bridge cost, but what can you do
                if (__instance.Map.resourceCounter.GetCount(bridgeCostDef) < bridgeCostCount)
                {
                    GUI.color = Color.red;
                    label     = label + " (" + "NotEnoughStoredLower".Translate() + ")";
                }
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(new Rect(curX + 29f, curY, 999f, 29f), label);                 //private const float DragPriceDrawNumberX
                curY       += 29f;
                Text.Anchor = TextAnchor.UpperLeft;
            }
            GUI.color = Color.white;
        }
        public static void DrawDesignationCorners(DesignationDragger DD)
        {
            // IntVec3 beg = DD.startDragCell;
            IntVec3 beg = DesignationDragger_startDragCell_Getter(DD);

            // DD.TryAddDragCell(beg);
            DesignationDragger_TryAddDragCell_Action(DD, beg);

            IntVec3 end = UI.MouseCell();

            if (beg == end)
            {
                initialDragAxis = -1;
                return;
            }
            if (initialDragAxis == -1)
            {
                if (end.x != beg.x)
                {
                    initialDragAxis = 0;
                }
                else if (end.z != beg.z)
                {
                    initialDragAxis = 2;
                }
            }

            IntVec3    cur           = beg;
            bool       drawRectangle = false;
            Designator selDes        = Find.DesignatorManager.SelectedDesignator;

            if (selDes is Designator_Build des)
            {
                if (des.PlacingDef is ThingDef def)
                {
                    drawRectangle =
                        (
                            (def.passability == Traversability.Impassable) &&
                            (def.category == ThingCategory.Building)
                        );
                }
            }
            void drawSegment(ref int curCoord, int endCoord)
            {
                while (curCoord != endCoord)
                {
                    curCoord += Math.Sign(endCoord - curCoord);
                    // DD.TryAddDragCell(cur);
                    DesignationDragger_TryAddDragCell_Action(DD, cur);
                }
            }

            if (drawRectangle)
            {
                drawSegment(ref cur.x, end.x);
                if (end.z != beg.z)
                {
                    drawSegment(ref cur.z, end.z);
                    if (end.x != beg.x)
                    {
                        drawSegment(ref cur.x, beg.x);
                        drawSegment(ref cur.z, beg.z + (cur.z > beg.z ? 1 : -1)); // don't draw beg again
                    }
                }
            }
            else
            {
                if (initialDragAxis == 0)
                {
                    drawSegment(ref cur.x, end.x);
                    drawSegment(ref cur.z, end.z);
                }
                else
                {
                    drawSegment(ref cur.z, end.z);
                    drawSegment(ref cur.x, end.x);
                }
            }
        }