コード例 #1
0
        public static void CalculateScoreForSpecialStats(Apparel ap, StatPriority statPriority, Pawn thisPawn,
                                                         float apStat, ref float score)
        {
            var current     = thisPawn.GetStatValue(statPriority.Stat);
            var goal        = statPriority.Weight;
            var defaultStat = thisPawn.def.GetStatValueAbstract(statPriority.Stat);

            if (thisPawn.story != null)
            {
                foreach (var trait in thisPawn.story.traits.allTraits)
                {
                    defaultStat += trait.OffsetOfStat(statPriority.Stat);
                }

                foreach (var trait in thisPawn.story.traits.allTraits)
                {
                    defaultStat *= trait.MultiplierOfStat(statPriority.Stat);
                }
            }

            if (ap.Wearer == thisPawn)
            {
                current -= apStat;
            }
            else
            {
                foreach (var worn in thisPawn.apparel.WornApparel)
                {
                    if (ApparelUtility.CanWearTogether(worn.def, ap.def, thisPawn.RaceProps.body))
                    {
                        continue;
                    }

                    var stat1 = worn.GetStatValue(statPriority.Stat);
                    var stat2 = worn.GetEquippedStatValue(thisPawn, statPriority.Stat);
                    DoApparelScoreRaw_PawnStatsHandlers(worn, statPriority.Stat, out var stat3);
                    current -= stat1 + stat2 + stat3;
                }
            }

            if (!(Math.Abs(current - goal) > 0.01f))
            {
                return;
            }

            var need = 1f - Mathf.InverseLerp(defaultStat, goal, current);

            score += Mathf.InverseLerp(current, goal, current + apStat) * need;
        }
コード例 #2
0
        public static void CalculateScoreForSpecialStats(Apparel ap, StatPriority statPriority, Pawn thisPawn, float apStat, ref float score)
        {
            float current     = thisPawn.GetStatValue(statPriority.Stat);
            float goal        = statPriority.Weight;
            float defaultStat = thisPawn.def.GetStatValueAbstract(statPriority.Stat);

            if (thisPawn.story != null)
            {
                for (int k = 0; k < thisPawn.story.traits.allTraits.Count; k++)
                {
                    defaultStat += thisPawn.story.traits.allTraits[k].OffsetOfStat(statPriority.Stat);
                }

                for (int n = 0; n < thisPawn.story.traits.allTraits.Count; n++)
                {
                    defaultStat *= thisPawn.story.traits.allTraits[n].MultiplierOfStat(statPriority.Stat);
                }
            }

            if (ap.Wearer == thisPawn)
            {
                current -= apStat;
            }
            else
            {
                foreach (Apparel worn in thisPawn.apparel.WornApparel)
                {
                    if (!ApparelUtility.CanWearTogether(worn.def, ap.def, thisPawn.RaceProps.body))
                    {
                        float stat1 = worn.GetStatValue(statPriority.Stat);
                        float stat2 = worn.GetEquippedStatValue(thisPawn, statPriority.Stat);
                        DoApparelScoreRaw_PawnStatsHandlers(worn, statPriority.Stat, out float stat3);
                        current -= stat1 + stat2 + stat3;
                    }
                }
            }

            if (Math.Abs(current - goal) > 0.01f)
            {
                float need = 1f - Mathf.InverseLerp(defaultStat, goal, current);
                score += Mathf.InverseLerp(current, goal, current + apStat) * need;
            }
        }
コード例 #3
0
        public static void DrawStatRow(ref Vector2 cur, float width, StatPriority stat, Pawn pawn, out bool stop_ui)
        {
            // sent a signal if the statlist has changed
            stop_ui = false;

            // set up rects
            Rect labelRect  = new Rect(cur.x, cur.y, (width - 24) / 2f, 30f);
            Rect sliderRect = new Rect(labelRect.xMax + 4f, cur.y + 5f, labelRect.width, 25f);
            Rect buttonRect = new Rect(sliderRect.xMax + 4f, cur.y + 3f, 16f, 16f);

            // draw label
            Text.Font = Text.CalcHeight(stat.Stat.LabelCap, labelRect.width) > labelRect.height
                ? GameFont.Tiny
                : GameFont.Small;
            Widgets.Label(labelRect, stat.Stat.LabelCap);
            Text.Font = GameFont.Small;

            // draw button
            // if manually added, delete the priority
            string buttonTooltip = String.Empty;

            if (stat.Assignment == StatAssignment.Manual)
            {
                buttonTooltip = "StatPriorityDelete".Translate(stat.Stat.LabelCap);
                if (Widgets.ImageButton(buttonRect, ITab_Pawn_Outfitter.deleteButton))
                {
                    stat.Delete(pawn);
                    stop_ui = true;
                }
            }
            // if overridden auto assignment, reset to auto
            if (stat.Assignment == StatAssignment.Override)
            {
                buttonTooltip = "StatPriorityReset".Translate(stat.Stat.LabelCap);
                if (Widgets.ImageButton(buttonRect, ITab_Pawn_Outfitter.resetButton))
                {
                    stat.Reset(pawn);
                    stop_ui = true;
                }
            }

            // draw line behind slider
            GUI.color = new Color(.3f, .3f, .3f);
            for (int y = (int)cur.y; y < cur.y + 30; y += 5)
            {
                Widgets.DrawLineVertical((sliderRect.xMin + sliderRect.xMax) / 2f, y, 3f);
            }

            // draw slider
            GUI.color = stat.Assignment == StatAssignment.Automatic ? Color.grey : Color.white;
            float weight = GUI.HorizontalSlider(sliderRect, stat.Weight, -10f, 10f);

            if (Mathf.Abs(weight - stat.Weight) > 1e-4)
            {
                stat.Weight = weight;
                if (stat.Assignment == StatAssignment.Automatic)
                {
                    stat.Assignment = StatAssignment.Override;
                }
            }
            GUI.color = Color.white;

            // tooltips
            TooltipHandler.TipRegion(labelRect, stat.Stat.LabelCap + "\n\n" + stat.Stat.description);
            if (buttonTooltip != String.Empty)
            {
                TooltipHandler.TipRegion(buttonRect, buttonTooltip);
            }
            TooltipHandler.TipRegion(sliderRect, stat.Weight.ToStringByStyle(ToStringStyle.FloatTwo));

            // advance row
            cur.y += 30f;
        }
コード例 #4
0
        private void DrawStatRow(
            ref Vector2 cur,
            float width,
            [NotNull] StatPriority statPriority,
            Pawn pawn,
            out bool stopUI)
        {
            // sent a signal if the statlist has changed
            stopUI = false;

            // set up rects
            Rect labelRect  = new Rect(cur.x, cur.y, (width - 24) / 2f, 30f);
            Rect sliderRect = new Rect(labelRect.xMax + 4f, cur.y + 5f, labelRect.width, 25f);
            Rect buttonRect = new Rect(sliderRect.xMax + 4f, cur.y + 3f, 16f, 16f);

            // draw label
            Text.Font = Text.CalcHeight(statPriority.Stat.LabelCap, labelRect.width) > labelRect.height
                            ? GameFont.Tiny
                            : GameFont.Small;
            switch (statPriority.Assignment)
            {
            case StatAssignment.Automatic:
                GUI.color = Color.grey;
                break;

            case StatAssignment.Individual:
                GUI.color = Color.cyan;
                break;

            case StatAssignment.Manual:
                GUI.color = Color.white;
                break;

            case StatAssignment.Override:
                GUI.color = new Color(0.75f, 0.69f, 0.33f);
                break;

            default:
                GUI.color = Color.white;
                break;
            }
            // if (!ApparelStatsHelper.AllStatDefsModifiedByAnyApparel.Contains(statPriority.Stat))
            // {
            //     GUI.color *= new Color(0.8f, 0.8f, 0.8f);
            // }

            Widgets.Label(labelRect, statPriority.Stat.LabelCap);
            Text.Font = GameFont.Small;

            // draw button
            // if manually added, delete the priority
            string buttonTooltip = string.Empty;

            if (statPriority.Assignment == StatAssignment.Manual)
            {
                buttonTooltip = "StatPriorityDelete".Translate(statPriority.Stat.LabelCap);
                if (Widgets.ButtonImage(buttonRect, OutfitterTextures.DeleteButton))
                {
                    statPriority.Delete(pawn);
                    stopUI = true;
                }
            }

            // if overridden auto assignment, reset to auto
            if (statPriority.Assignment == StatAssignment.Override)
            {
                buttonTooltip = "StatPriorityReset".Translate(statPriority.Stat.LabelCap);
                if (Widgets.ButtonImage(buttonRect, OutfitterTextures.ResetButton))
                {
                    statPriority.Reset(pawn);
                    stopUI = true;
                }
            }

            // draw line behind slider
            GUI.color = new Color(.3f, .3f, .3f);
            for (int y = (int)cur.y; y < cur.y + 30; y += 5)
            {
                Widgets.DrawLineVertical((sliderRect.xMin + sliderRect.xMax) / 2f, y, 3f);
            }

            // draw slider
            switch (statPriority.Assignment)
            {
            case StatAssignment.Automatic:
                GUI.color = Color.grey;
                break;

            case StatAssignment.Individual:
                GUI.color = Color.cyan;
                break;

            case StatAssignment.Manual:
                GUI.color = Color.white;
                break;

            case StatAssignment.Override:
                GUI.color = new Color(0.75f, 0.69f, 0.33f);
                break;

            default:
                GUI.color = Color.white;
                break;
            }

            float weight = GUI.HorizontalSlider(
                sliderRect,
                statPriority.Weight,
                ApparelStatCache.SpecialStats.Contains(statPriority.Stat)
                                                    ? 0.01f
                                                    : -ApparelStatCache.MaxValue,
                ApparelStatCache.MaxValue);

            if (Mathf.Abs(weight - statPriority.Weight) > 1e-4)
            {
                statPriority.Weight = weight;
                if (statPriority.Assignment == StatAssignment.Automatic ||
                    statPriority.Assignment == StatAssignment.Individual)
                {
                    statPriority.Assignment = StatAssignment.Override;
                }
            }

            if (GUI.changed)
            {
                pawn.GetApparelStatCache().RawScoreDict.Clear();
            }

            GUI.color = Color.white;

            // tooltips
            TooltipHandler.TipRegion(labelRect, statPriority.Stat.LabelCap + "\n\n" + statPriority.Stat.description);
            if (buttonTooltip != string.Empty)
            {
                TooltipHandler.TipRegion(buttonRect, buttonTooltip);
            }

            TooltipHandler.TipRegion(sliderRect, statPriority.Weight.ToStringByStyle(ToStringStyle.FloatTwo));

            // advance row
            cur.y += 30f;
        }