Exemple #1
0
        /// <summary>
        /// Draw stuff names and info icon buttons as headers for stat table.
        /// </summary>
        /// <param name="startRect"> Rect for drawing stats. </param>
        /// <param name="start"> Start index from which <paramref name="pairListToDraw"/> should begin to read. </param>
        /// <param name="end"> End index which is one greater than the index at which <paramref name="pairListToDraw"/> should stop reading. </param>
        /// <param name="pairListToDraw"> A working set of <see cref="TSPWQuality"/>. </param>
        private static void DrawStatTableHeader(Rect startRect, int start, int end, List <TSPWQuality> pairListToDraw)
        {
            Text.Anchor   = TextAnchor.MiddleCenter;
            Text.WordWrap = false;
            for (int i = start; i < pairListToDraw.Count && i < end; i++)
            {
                TSPWQuality pair       = pairListToDraw[i];
                Rect        buttonRect = startRect.ReplaceWidth(GenUI.SmallIconSize);
                if (Widgets.ButtonImage(buttonRect, TexResource.Info))
                {
                    Thing thing = pair.MakeThingWithoutID();
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }

                Rect labelRect = startRect.ReplacexMin(buttonRect.xMax + GenUI.GapTiny);

                string text = pair.stuff != null?pair.stuff.LabelAsStuff.CapitalizeFirst().ColorizeByQuality(pair.Quality) : pair.thing.LabelCap.ToString();

                labelRect.width -= GenUI.GapTiny;
                if (text.StripTags().GetWidthCached() > labelRect.width)
                {
                    Text.Anchor = TextAnchor.MiddleLeft;
                }

                Widgets.Label(labelRect, text);
                startRect = startRect.ReplaceX(startRect.xMax);
            }

            Text.Anchor   = TextAnchor.UpperLeft;
            Text.WordWrap = true;
        }
Exemple #2
0
        private static void DrawStatRows(List <StatDef> stats, List <TSPWQuality> pairs, Rect startRect, int from, int to,
                                         out float rollingY, List <List <StatDrawInfo> > listHolder = null,
                                         bool specialStats = false)
        {
            float startX = startRect.x;

            for (int i = 0; i < stats.Count; i++)
            {
                List <StatDrawInfo> statInfoList = new List <StatDrawInfo>();
                if (!specialStats)
                {
                    statInfoList = new List <StatDrawInfo>();

                    // Retrieve stat value and create a view model, StatDrawInfo, for drawing.
                    for (int j = from; j < to && j < pairs.Count; j++)
                    {
                        TSPWQuality  pair        = pairs[j];
                        StatDrawInfo drawInfo    = new StatDrawInfo();
                        Thing        tempThing   = pair.MakeThingWithoutID();
                        StatRequest  statRequest = StatRequest.For(tempThing);
                        if ((stats[i].Worker.ShouldShowFor(statRequest) && !stats[i].Worker.IsDisabledFor(tempThing)) || stats[i] == StatDefOf.MaxHitPoints || stats[i] == StatDefOf.MeleeWeapon_CooldownMultiplier)
                        {
                            drawInfo.StatRequest = statRequest;
                            drawInfo.Value       = GetCachedValue(_statCache, () => stats[i].Worker.GetValue(drawInfo.StatRequest), pair, stats[i]);
                            drawInfo.Tip         = GetCachedValue(_statTipCache, () => stats[i].Worker.GetExplanationFull(drawInfo.StatRequest, stats[i].toStringNumberSense, drawInfo.Value), pair, stats[i]);
                        }
                        else
                        {
                            drawInfo.Value = -1;
                            drawInfo.Tip   = string.Empty;
                        }

                        statInfoList.Add(drawInfo);
                    }

                    if (statInfoList.Count > 1)
                    {
                        // Highlight highest stat value.
                        List <StatDrawInfo> orderedList = statInfoList.OrderByDescending(t => t.Value).ToList();
                        foreach (StatDrawInfo statDrawInfo in orderedList)
                        {
                            if (statDrawInfo.Value == orderedList[0].Value)
                            {
                                statDrawInfo.Color = Color.green;
                            }
                        }
                    }
                }
                else
                {
                    statInfoList = listHolder[i];
                }

#pragma warning disable SA1118 // Parameter should not span multiple lines

                // Draw stat for each stuff choice.
                Text.Anchor = TextAnchor.MiddleCenter;
                foreach (StatDrawInfo info in statInfoList)
                {
                    GUI.color = info.Color;
                    Widgets.Label(
                        startRect,
                        specialStats
                        ? info.ValueString
                        : info.Value == -1
                            ? "-"
                            : stats[i].Worker.ValueToString(info.Value, true, stats[i].toStringNumberSense));
                    Widgets.DrawHighlightIfMouseover(startRect);
                    Text.Anchor = TextAnchor.MiddleLeft;
                    TooltipHandler.TipRegion(startRect, info.Tip);
                    Text.Anchor = TextAnchor.MiddleCenter;
                    startRect   = startRect.ReplaceX(startRect.xMax);
                }
#pragma warning restore SA1118 // Parameter should not span multiple lines

                startRect = new Rect(startX, startRect.yMax, startRect.width, startRect.height);
            }

            rollingY    = startRect.y;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }