Esempio n. 1
0
        public override void DoComponentContents(Rect inRect, Flow flow)
        {
            float lineHeight       = QOLMod.LineHeight(GameFont.Tiny);
            float tripleLineHeight = lineHeight * 4;
            Rect  nextSquare       = new Rect(inRect.x, inRect.y, width, tripleLineHeight);

            Color originalColor = exprColor(flow);
            Color currentColor  = originalColor;

            GUI.DrawTexture(nextSquare, QOLMod.getSolidColorTexture(currentColor));
            Rect rgbLine = new Rect(nextSquare); rgbLine.height = lineHeight;

            currentColor.r = Widgets.HorizontalSlider(rgbLine, currentColor.r, 0, 1f);
            rgbLine.y     += lineHeight;
            currentColor.g = Widgets.HorizontalSlider(rgbLine, currentColor.g, 0, 1f);
            rgbLine.y     += lineHeight;
            currentColor.b = Widgets.HorizontalSlider(rgbLine, currentColor.b, 0, 1f);
            rgbLine.y     += lineHeight;
            currentColor.a = Widgets.HorizontalSlider(rgbLine, currentColor.a, 0, 1f);

            if (!originalColor.IndistinguishableFrom(currentColor))
            {
                onChange(flow, currentColor);
            }
        }
Esempio n. 2
0
 public override float getWidth()
 {
     if (width >= 0)
     {
         return(width);
     }
     return(QOLMod.CalcSize(label, font, TextAnchor.MiddleCenter, false).x + 8f);
 }
Esempio n. 3
0
        public PawnPath findPath(Map map, IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode, ByteGrid avoidGrid, Area allowedArea,
                                 int costsCardinal, int costsDiagonal)
        {
            this.map                 = map;
            this.cellIndices         = this.map.cellIndices;
            this.edificeGrid         = map.edificeGrid;
            this.traverseParms       = traverseParms;
            this.dest                = dest;
            this.peMode              = peMode;
            this.costPerMoveCardinal = costsCardinal;
            this.costPerMoveDiagonal = costsDiagonal;
            this.avoidGrid           = avoidGrid;
            this.allowedArea         = allowedArea;
            this.pathGridArray       = map.pathGrid.pathGrid;
            this.pathGrid            = map.pathGrid;
            this.topGrid             = map.terrainGrid.topGrid;
            this.pawn                = traverseParms.pawn;
            this.drafted             = pawn != null && pawn.Drafted;
            this.blueprintGrid       = map.blueprintGrid.InnerArray;

            //Only colonists and tamed animals should respect restrictions.
            //Drafted pawns move unrestricted.
            //Some job types like firefighting should exclude the restrictions.
            List <string> exceptions = QOLMod.getSettings().pfRestrictionExcemptions;

            if (this.pawn.Faction != null && this.pawn.Faction.IsPlayer && !this.pawn.Drafted && (exceptions == null || pawn.jobs.curJob == null || !exceptions.Contains(pawn.jobs.curJob.def.defName)))
            {
                this.pathfinderDirections = map.GetComponent <MapComponent_PathfinderDirections>();
            }
            else
            {
                this.pathfinderDirections = null;
            }
            this.drawPath          = DebugViewSettings.drawPaths;
            this.mapSizeX          = map.Size.x;
            this.mapSizeZ          = map.Size.z;
            this.dontPassWater     = traverseParms.mode == TraverseMode.NoPassClosedDoorsOrWater || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater;
            this.collidesWithPawns = pawn != null && PawnUtility.ShouldCollideWithPawns(pawn);

            Step step = astar(start);

            if (step == null)
            {
                return(PawnPath.NotFound);
            }

            PawnPath emptyPawnPath = map.pawnPathPool.GetEmptyPawnPath();
            int      costs         = step.costToReachThis;

            while (step != null)
            {
                emptyPawnPath.AddNode(step.current);
                step = step.predecessor;
            }
            emptyPawnPath.SetupFound((float)costs, false);
            return(emptyPawnPath);
        }
Esempio n. 4
0
        public override void DoComponentContents(Rect inRect, Flow flow)
        {
            Text.Font   = font;
            Text.Anchor = anchor;
            bool   wasCapped;
            string labelToRender = label != null?label:labelExpr(flow);
            string labelCapped   = QOLMod.CapString(labelToRender, inRect.width, "...", out wasCapped, font, anchor);

            displayToolTipIfNecessary(inRect, flow, wasCapped ? labelToRender : null);
            Widgets.Label(inRect, labelCapped);
        }
Esempio n. 5
0
 public LabelRenderer(string label, float width = -1f, GameFont font = GameFont.Small, TextAnchor anchor = TextAnchor.MiddleLeft)
 {
     this.label  = label;
     this.font   = font;
     this.width  = width;
     this.anchor = anchor;
     if (this.width < 0)
     {
         this.width = QOLMod.CalcSize(this.label, font, this.anchor, false).x;
     }
     this.labelExpr = null;
 }
Esempio n. 6
0
        public override void DoComponentContents(Rect inRect, Flow flow)
        {
            Text.Font = font;
            bool   wasCapped;
            string labelToRender = label != null?label:exprLabel(flow);
            string labelCapped   = QOLMod.CapString(labelToRender, inRect.width, "...", out wasCapped, font);

            displayToolTipIfNecessary(inRect, flow, wasCapped ? labelToRender : null);
            if (Widgets.ButtonText(inRect, labelCapped))
            {
                onClick(flow);
            }
        }
Esempio n. 7
0
        public override void DoComponentContents(Rect inRect, Flow flow)
        {
            if (exprItems != null)
            {
                items = exprItems(flow);
            }
            if (items == null || items.Count == 0)
            {
                return;
            }

            Rect viewRect = new Rect(inRect);

            viewRect.height = Mathf.Max(lastMeasuredHeight, inRect.height);
            viewRect.width -= QOLMod.VerticalScrollbarWidth();
            Widgets.BeginScrollView(inRect, ref scrollPosition, viewRect);

            beginIteration(flow);

            lastMeasuredHeight = 0;
            Rect cell = new Rect(viewRect);

            foreach (object curItem in items)
            {
                advanceIteration(curItem);

                float rowheight = 0;
                foreach (BaseRenderer cr in childs)
                {
                    rowheight = Math.Max(rowheight, cr.getHeight());
                }
                cell.height = rowheight;
                if (cell.y - scrollPosition.y < inRect.y + inRect.height && cell.y + cell.height - scrollPosition.y > inRect.y)
                {
                    float x = cell.x;
                    foreach (BaseRenderer cr in childs)
                    {
                        cell.width = cr.getWidth();
                        cr.DoComponentContents(cell, flow);
                        cell.x += cell.width;
                    }
                    cell.x = x;
                }
                cell.y             += cell.height;
                lastMeasuredHeight += cell.height;
            }

            endIteration(flow);

            Widgets.EndScrollView();
        }
Esempio n. 8
0
        public override void DoComponentContents(Rect inRect, Flow flow)
        {
            float height = getHeight();

            Rect viewRect = new Rect(0, 0, inRect.width, Mathf.Max(height, inRect.height));

            if (height > inRect.height)
            {
                viewRect.width -= QOLMod.VerticalScrollbarWidth();
            }

            Widgets.BeginScrollView(inRect, ref scrollPosition, viewRect);
            Rect row = new Rect(0, 0, viewRect.width, 0);

            foreach (BaseRenderer cr in childs)
            {
                row.height = cr.getHeight();
                cr.DoComponentContents(row, flow);
                row.y += row.height;
            }
            Widgets.EndScrollView();
        }
Esempio n. 9
0
        static bool Prefix(PathFinder __instance, ref PawnPath __result, IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode = PathEndMode.OnCell)
        {
            //swVanilla = null;
            Pawn pawn = traverseParms.pawn;

            if (pawn != null)
            {
                int algId;
                if (pawn.IsColonist)
                {
                    algId = 1;
                }
                else if (pawn.RaceProps.Animal)
                {
                    if (pawn.Faction != null && pawn.Faction.IsPlayer)
                    {
                        algId = 2;
                    }
                    else
                    {
                        algId = 3;
                    }
                }
                else
                {
                    algId = 4;
                }

                if (QOLMod.hasPFAlgorithm(algId))
                {
                    Map map = (Map)mapField.GetValue(__instance);
                    if (!preSearchChecks(map, start, dest, traverseParms, peMode))
                    {
                        __result = PawnPath.NotFound;
                        return(false);
                    }

                    ByteGrid avoidGrid   = (pawn == null) ? null : pawn.GetAvoidGrid();
                    Area     allowedArea = GetAllowedArea(pawn);
                    int      ticksPerMoveCardinal;
                    int      ticksPerMoveDiagonal;
                    if (pawn != null)
                    {
                        ticksPerMoveCardinal = pawn.TicksPerMoveCardinal;
                        ticksPerMoveDiagonal = pawn.TicksPerMoveDiagonal;
                        //Log.Message("PawnTicksToMove: "+ticksPerMoveCardinal+"/"+ticksPerMoveDiagonal);
                    }
                    else
                    {
                        //we currently do not pathfind for non pawn(e.g. generating maps) but best to leave it as a reminder
                        ticksPerMoveCardinal = 13;
                        ticksPerMoveDiagonal = 18;
                    }

                    __result = QOLMod.doPFAlgorithm(algId, map, start, dest, traverseParms, peMode, avoidGrid, allowedArea, ticksPerMoveCardinal, ticksPerMoveDiagonal);
                    if (__result == null)
                    {
                        return(true);
                    }
                    if (DebugViewSettings.drawPaths)
                    {
                        foreach (IntVec3 pos in __result.NodesReversed)
                        {
                            map.debugDrawer.FlashCell(pos, 0.7f, "finalPath", 100);
                        }
                    }
                    return(false);
                }
            }

            /*if ( pawn != null && pawn.IsColonist ) {
             *      Log.Message("Pathfinding for distance: "+Math.Max(Math.Abs(start.x-dest.Cell.x),Math.Abs(start.z-dest.Cell.z)));
             *      swVanilla = Stopwatch.StartNew();
             * }*/
            return(true);
        }
Esempio n. 10
0
 public override float getHeight()
 {
     return(QOLMod.LineHeight(font));
 }
Esempio n. 11
0
 public override float getHeight()
 {
     return(QOLMod.LineHeight(GameFont.Tiny) * 4);
 }
Esempio n. 12
0
        public override void DoComponentContents(Rect inRect, Flow flow)
        {
            Rect viewRect = new Rect(inRect);

            if (filter != null)
            {
                this.filterExpr = Widgets.TextField(new Rect(inRect.x, inRect.y, 200f, 30f), this.filterExpr);
                viewRect.yMin  += 35f;
            }

            if (dynamicSorter != null)
            {
                items = dynamicSorter(items);
            }

            Rect contentRect = new Rect(0f, 0f, totalOptionsWidth > 0 ? totalOptionsWidth : viewRect.width, viewRect.height - QOLMod.HorizontalScrollbarHeight());

            Widgets.BeginScrollView(viewRect, ref this.scrollPosition, contentRect, true);

            beginIteration(flow);

            Rect  r = new Rect(contentRect.x, contentRect.y, 0, 0);
            float columnStart = r.x, maxColumnWidth = 0;

            foreach (T d in items)
            {
                if (filter == null || filter(filterExpr, d))
                {
                    advanceIteration(d);

                    r.height = 0;
                    foreach (BaseRenderer cr in childs)
                    {
                        r.height = Mathf.Max(r.height, cr.getHeight());
                    }

                    if (r.yMax > contentRect.height)
                    {
                        r.y            = contentRect.yMin;
                        r.x           += maxColumnWidth + horizontalGap;
                        columnStart    = r.x;
                        maxColumnWidth = 0;
                    }

                    foreach (BaseRenderer cr in childs)
                    {
                        r.width = cr.getWidth();
                        cr.DoComponentContents(r, flow);
                        r.x += r.width + childGap;
                    }
                    maxColumnWidth = Mathf.Max(maxColumnWidth, r.x - columnStart - childGap);
                    r.x            = columnStart;
                    r.y           += r.height + verticalGap;
                }
            }
            totalOptionsWidth = columnStart + maxColumnWidth + horizontalGap - contentRect.x;

            endIteration(flow);

            Widgets.EndScrollView();
        }