Ejemplo n.º 1
0
 // public NeededWarmth neededWarmth;
 private ApparelStatCache([NotNull] SaveablePawn saveablePawn)
 {
     _pawn             = saveablePawn.Pawn;
     _pawnSave         = _pawn.GetSaveablePawn();
     Cache             = new List <StatPriority>();
     _lastStatUpdate   = -5000;
     _lastTempUpdate   = -5000;
     _lastWeightUpdate = -5000;
 }
 // public NeededWarmth neededWarmth;
 public ApparelStatCache([NotNull] SaveablePawn saveablePawn)
 {
     this._pawn             = saveablePawn.Pawn;
     this._pawnSave         = this._pawn.GetSaveablePawn();
     this.Cache             = new List <StatPriority>();
     this._lastStatUpdate   = -5000;
     this._lastTempUpdate   = -5000;
     this._lastWeightUpdate = -5000;
 }
Ejemplo n.º 3
0
        public static SaveablePawn GetSaveablePawn(this Pawn pawn)
        {
            GameComponent_Outfitter outfitter = Current.Game.GetComponent<GameComponent_Outfitter>();
            foreach (SaveablePawn c in outfitter.PawnCache.Where(c => c.Pawn == pawn))
            {
                return c;
            }

            SaveablePawn n = new SaveablePawn { Pawn = pawn };
            outfitter.PawnCache.Add(n);
            return n;

            // if (!PawnApparelStatCaches.ContainsKey(pawn))
            // {
            // PawnApparelStatCaches.Add(pawn, new StatCache(pawn));
            // }
            // return PawnApparelStatCaches[pawn];
        }
Ejemplo n.º 4
0
        public void Reset(Pawn pawn)
        {
            Dictionary <StatDef, float> stats     = pawn.GetWeightedApparelStats();
            Dictionary <StatDef, float> indiStats = pawn.GetWeightedApparelIndividualStats();

            if (stats.ContainsKey(this.Stat))
            {
                this.Weight     = stats[this.Stat];
                this.Assignment = StatAssignment.Automatic;
            }

            if (indiStats.ContainsKey(this.Stat))
            {
                this.Weight     = indiStats[this.Stat];
                this.Assignment = StatAssignment.Individual;
            }

            SaveablePawn pawnSave = pawn.GetSaveablePawn();

            pawnSave.Stats.RemoveAll(i => i.Stat == this.Stat);
        }
        private void DrawTemperatureStats([NotNull] SaveablePawn pawnSave, ref Vector2 cur, Rect canvas)
        {
            // header
            Rect tempHeaderRect = new Rect(cur.x, cur.y, canvas.width, 30f);

            cur.y      += 30f;
            Text.Anchor = TextAnchor.LowerLeft;
            Widgets.Label(tempHeaderRect, "PreferedTemperature".Translate());
            Text.Anchor = TextAnchor.UpperLeft;

            // line
            GUI.color = Color.grey;
            Widgets.DrawLineHorizontal(cur.x, cur.y, canvas.width);
            GUI.color = Color.white;

            // some padding
            cur.y += Margin;

            // temperature slider
            // SaveablePawn pawnStatCache = MapComponent_Outfitter.Get.GetSaveablePawn(SelPawn);
            ApparelStatCache pawnStatCache = this.SelPawnForGear.GetApparelStatCache();
            FloatRange       targetTemps   = pawnStatCache.TargetTemperatures;
            FloatRange       minMaxTemps   = ApparelStatsHelper.MinMaxTemperatureRange;
            Rect             sliderRect    = new Rect(cur.x, cur.y, canvas.width - 20f, 40f);
            Rect             tempResetRect = new Rect(sliderRect.xMax + 4f, cur.y + Margin, 16f, 16f);

            cur.y += 40f;                          // includes padding

            // current temperature settings
            GUI.color = pawnSave.TargetTemperaturesOverride ? Color.white : Color.grey;
            Widgets_FloatRange.FloatRange(
                sliderRect,
                123123123,
                ref targetTemps,
                minMaxTemps,
                ToStringStyle.Temperature);
            GUI.color = Color.white;

            if (Math.Abs(targetTemps.min - pawnStatCache.TargetTemperatures.min) > 1e-4 ||
                Math.Abs(targetTemps.max - pawnStatCache.TargetTemperatures.max) > 1e-4)
            {
                pawnStatCache.TargetTemperatures = targetTemps;
            }

            if (pawnSave.TargetTemperaturesOverride)
            {
                if (Widgets.ButtonImage(tempResetRect, OutfitterTextures.ResetButton))
                {
                    pawnSave.TargetTemperaturesOverride = false;

                    // var saveablePawn = MapComponent_Outfitter.Get.GetSaveablePawn(SelPawn);
                    // saveablePawn.targetTemperaturesOverride = false;
                    pawnStatCache.UpdateTemperatureIfNecessary(true);
                }

                TooltipHandler.TipRegion(tempResetRect, "TemperatureRangeReset".Translate());
            }

            Text.Font = GameFont.Small;
            this.TryDrawComfyTemperatureRange(ref cur.y, canvas.width);
        }
        protected override void FillTab()
        {
            SaveablePawn pawnSave = this.SelPawnForGear.GetSaveablePawn();

            // Outfit + Status button
            Rect rectStatus = new Rect(20f, 15f, 380f, ButtonHeight);

            Rect outfitRect = new Rect(rectStatus.x, rectStatus.y, 392f / 3 - Margin, ButtonHeight);

            Rect outfitEditRect = new Rect(outfitRect.xMax + Margin, outfitRect.y, outfitRect.width, ButtonHeight);

            Rect outfitJobRect = new Rect(outfitEditRect.xMax + Margin, outfitRect.y, outfitRect.width, ButtonHeight);

            // select outfit
            if (Widgets.ButtonText(outfitRect, this.SelPawnForGear.outfits.CurrentOutfit.label))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();

                foreach (Outfit current in Current.Game.outfitDatabase.AllOutfits)
                {
                    Outfit localOut = current;
                    options.Add(
                        new FloatMenuOption(
                            localOut.label,
                            delegate { this.SelPawnForGear.outfits.CurrentOutfit = localOut; }));
                }

                FloatMenu window = new FloatMenu(options, "SelectOutfit".Translate());

                Find.WindowStack.Add(window);
            }

            // edit outfit
            if (Widgets.ButtonText(
                    outfitEditRect,
                    "OutfitterEditOutfit".Translate() + " " + this.SelPawnForGear.outfits.CurrentOutfit.label + " ..."))
            {
                Find.WindowStack.Add(new Dialog_ManageOutfits(this.SelPawnForGear.outfits.CurrentOutfit));
            }

            // job outfit
            if (Widgets.ButtonText(
                    outfitJobRect,
                    pawnSave.MainJob == MainJob.Anything
                                       ? "MainJob".Translate()
                                       : "PreferedGear".Translate() + " " + pawnSave.MainJob.ToString()
                    .Replace("00", " - ")
                    .Replace("_", " ")))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (MainJob mainJob in Enum.GetValues(typeof(MainJob)))
                {
                    options.Add(
                        new FloatMenuOption(
                            mainJob.ToString().Replace("00", " - ").Replace("_", " "),
                            delegate
                    {
                        pawnSave.MainJob         = mainJob;
                        pawnSave.ForceStatUpdate = true;

                        this.SelPawnForGear.mindState.Notify_OutfitChanged();

                        if (this.SelPawnForGear.jobs.curJob != null &&
                            this.SelPawnForGear.jobs.IsCurrentJobPlayerInterruptible())
                        {
                            this.SelPawnForGear.jobs.EndCurrentJob(JobCondition
                                                                   .InterruptForced);
                        }
                    }));
                }

                FloatMenu window = new FloatMenu(options, "MainJob".Translate());

                Find.WindowStack.Add(window);
            }

            // Status checkboxes
            Rect rectCheckboxes = new Rect(rectStatus.x, rectStatus.yMax + Margin, rectStatus.width, 72f);
            Rect check1         = new Rect(rectCheckboxes.x, rectCheckboxes.y, rectCheckboxes.width, 24f);
            Rect check2         = new Rect(rectCheckboxes.x, check1.yMax, rectCheckboxes.width, 24f);
            Rect check3         = new Rect(rectCheckboxes.x, check2.yMax, rectCheckboxes.width, 24f);

            bool pawnSaveAddWorkStats       = pawnSave.AddWorkStats;
            bool pawnSaveAddIndividualStats = pawnSave.AddIndividualStats;
            bool pawnSaveAddPersonalStats   = pawnSave.AddPersonalStats;

            Widgets.CheckboxLabeled(check1, "AddWorkStats".Translate(), ref pawnSaveAddWorkStats);
            Widgets.CheckboxLabeled(check2, "AddIndividualStats".Translate(), ref pawnSaveAddIndividualStats);
            Widgets.CheckboxLabeled(check3, "AddPersonalStats".Translate(), ref pawnSaveAddPersonalStats);

            if (GUI.changed)
            {
                pawnSave.AddWorkStats       = pawnSaveAddWorkStats;
                pawnSave.AddIndividualStats = pawnSaveAddIndividualStats;
                pawnSave.AddPersonalStats   = pawnSaveAddPersonalStats;
                pawnSave.ForceStatUpdate    = true;
            }

            // main canvas
            Rect canvas = new Rect(20f, rectCheckboxes.yMax, 392f, this.size.y - rectCheckboxes.yMax - 20f);

            GUI.BeginGroup(canvas);
            Vector2 cur = Vector2.zero;

            this.DrawTemperatureStats(pawnSave, ref cur, canvas);
            cur.y += Margin;
            this.DrawApparelStats(cur, canvas);

            GUI.EndGroup();

            this.DrawApparelList();

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