Example #1
0
        public NeedModel(PawnModel model, NeedDef def) : base(model)
        {
            var need = model.Base.needs?.TryGetNeed(def);

            if (need == null)
            {
                Hidden = true;
                return;
            }

            Label = def.LabelCap;

            Max        = 1f;
            Value      = need.CurLevelPercentage;
            ValueStyle = HudBar.ValueStyle.Percentage;

            if (def == Access.NeedDefOfMood)
            {
                Tooltip    = model.Mind.Tooltip;
                Thresholds = new[] { model.MoodThresholdMinor, model.MoodThresholdMajor, model.MoodThresholdExtreme };
            }
            else
            {
                Tooltip    = null;
                Thresholds = null;
            }
        }
Example #2
0
        public static HudWidgetBase GetWidget(PawnModel model, string id, string defName)
        {
            if (id == "Stat")
            {
                return(GetStatWidget(model, defName));
            }
            if (id == "Record")
            {
                return(GetRecordWidget(model, defName));
            }
            if (id == "Need")
            {
                return(GetNeedWidget(model, defName));
            }
            if (id == "Skill")
            {
                return(GetSkillWidget(model, defName));
            }
            if (id == "Training")
            {
                return(GetTrainingWidget(model, defName));
            }

            var widget = Widgets.TryGetValue(id);

            if (widget == null)
            {
                throw new Mod.Exception($"Invalid HUD Widget, type '{id}' is not recognized");
            }

            return(widget.Invoke(model) ?? HudBlank.GetEmpty);
        }
Example #3
0
        public TimetableModel(PawnModel model)
        {
            try
            {
                Model = model;

                if ((!model.Base.Faction?.IsPlayer ?? true) || model.Base.timetable == null)
                {
                    Hidden = true;
                    return;
                }

                Label = Lang.Get("Model.Selector.TimetableFormat", model.Base.timetable.CurrentAssignment.LabelCap);

                var assignment = model.Base.timetable.CurrentAssignment;
                Color = assignment == TimeAssignmentDefOf.Anything ? (Color?)null : assignment.color;

                OnClick = DrawFloatMenu;
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Example #4
0
        public AreaModel(PawnModel model)
        {
            try
            {
                Model = model;

                if ((!model.Base.Faction?.IsPlayer ?? true) || model.Base.playerSettings == null || (!model.Base.IsColonist && !model.Base.playerSettings.RespectsAllowedArea))
                {
                    Hidden = true;
                    return;
                }

                Label = Lang.Get("Model.Selector.AreaFormat", AreaUtility.AreaAllowedLabel(model.Base));
                Color = model.Base.playerSettings?.EffectiveAreaRestriction?.Color;

                OnClick = DrawFloatMenu;

                OnHover = () => model.Base.playerSettings.EffectiveAreaRestriction?.MarkForDraw();
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Example #5
0
        public SkillModel(PawnModel model, SkillDef def)
        {
            Model = model;
            Def   = def;

            var skill = model.Base.skills?.GetSkill(def);

            if (skill == null)
            {
                Hidden = true;
                return;
            }

            Skill = skill;

            var passionIndicator = new StringBuilder().Insert(0, Lang.Get("Model.Component.Skill.PassionIndicator"), (int)skill.passion).ToString();

            Label = def.LabelCap + passionIndicator;

            var isActive    = model.Base.jobs?.curDriver?.ActiveSkill == def;
            var isSaturated = skill.LearningSaturatedToday;

            Value = skill.TotallyDisabled ? "-" : skill.Level.ToDecimalString(skill.XpProgressPercent.ToPercentageInt());
            Color = skill.TotallyDisabled ? Theme.DisabledColor.Value : isSaturated ? Theme.SkillSaturatedColor.Value : isActive ? Theme.SkillActiveColor.Value : GetSkillColor(skill);

            Tooltip = GetTooltip();

            OnClick = InspectPanePlus.ToggleBioTab;
        }
Example #6
0
        private static HudWidget GetSkillWidget(PawnModel model, string defName)
        {
            var def = DefDatabase <SkillDef> .GetNamed(defName, false);

            if (def != null)
            {
                return((HudWidget)HudValue.FromValueModel(new SkillModel(model, def), Theme.RegularTextStyle) ?? HudBlank.GetEmpty);
            }

            Mod.ErrorOnce($"Invalid HUD Widget, Skill def '{defName}' not found", "InvalidSkillDefName" + defName);
            return(HudBlank.GetEmpty);
        }
Example #7
0
        private static HudWidget GetNeedWidget(PawnModel model, string defName)
        {
            var def = DefDatabase <NeedDef> .GetNamed(defName, false);

            if (def != null)
            {
                return((HudWidget)HudBar.FromModel(new NeedModel(model, def), Theme.RegularTextStyle) ?? HudBlank.GetEmpty);
            }

            Mod.ErrorOnce($"Invalid HUD Widget, Need def '{defName}' not found", "InvalidNeedDefName" + defName);
            return(HudBlank.GetEmpty);
        }
Example #8
0
        public TrainingModel(PawnModel model, TrainableDef def)
        {
            try
            {
                Model = model;

                bool canTrainNow;
                try { canTrainNow = model.Base.RaceProps?.trainability != null && model.Base.training != null && model.Base.training.CanAssignToTrain(def, out var visible).Accepted&& visible; }
                catch (Exception exception)
                {
                    Mod.HandleWarning(exception);
                    canTrainNow = false;
                }

                if (!canTrainNow)
                {
                    Hidden = true;
                    return;
                }

                Label = def.LabelCap;

                var disabled   = !model.Base.training.GetWanted(def);
                var hasLearned = model.Base.training.HasLearned(def);

                var steps = GetSteps(model.Base, def);
                var value = steps + " / " + def.steps;
                Value = hasLearned ? value.Bold() : value;

                Tooltip = model.GetAnimalTooltip(def);

                if (disabled)
                {
                    Color = Theme.DisabledColor.Value;
                }
                else if (hasLearned)
                {
                    Color = Theme.SkillMinorPassionColor.Value;
                }
                else
                {
                    Color = Theme.MainTextColor.Value;
                }

                OnClick = InspectPanePlus.ToggleTrainingTab;
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Example #9
0
        private static HudWidgetBase GetTrainingWidget(PawnModel model, string defName)
        {
            var def = DefDatabase <TrainableDef> .GetNamed(defName, false);

            if (def != null)
            {
                return((HudWidgetBase)HudValue.FromValueModel(new TrainingModel(model, def), Theme.RegularTextStyle) ?? HudBlank.GetEmpty);
            }

            Mod.Warning($"Invalid HUD Widget, Trainable def '{defName}' not found, resetting layout to default");
            RequiredReset();
            return(HudBlank.GetEmpty);
        }
Example #10
0
        private static HudWidget GetNeedWidget(PawnModel model, string defName)
        {
            var def = DefDatabase <NeedDef> .GetNamed(defName, false);

            if (def != null)
            {
                return((HudWidget)HudBar.FromModel(new NeedModel(model, def), Theme.RegularTextStyle) ?? HudBlank.GetEmpty);
            }

            Mod.Warning($"Invalid HUD Widget, Need def '{defName}' not found, resetting layout to default");
            RequiredReset();
            return(HudBlank.GetEmpty);
        }
Example #11
0
        private static HudWidgetBase GetRecordWidget(PawnModel model, string defName)
        {
            var def = DefDatabase <RecordDef> .GetNamed(defName, false);

            if (def != null)
            {
                var text = $"{def.LabelCap}: {(def.type == RecordType.Time ? model.Base.records.GetAsInt(def).ToStringTicksToPeriod() : model.Base.records.GetValue(def).ToString("0.##"))}";
                return((HudWidgetBase)HudValue.FromText(text, null, Theme.RegularTextStyle) ?? HudBlank.GetEmpty);
            }

            Mod.Warning($"Invalid HUD Widget, Record def '{defName}' not found, resetting layout to default");
            RequiredReset();
            return(HudBlank.GetEmpty);
        }
Example #12
0
        public RulesModel(PawnModel model) : base(model)
        {
            if (!Mod_PawnRules.Instance.IsActive || !Mod_PawnRules.CanHaveRules(model.Base))
            {
                Hidden = true;
                return;
            }

            Label   = Lang.Get("Integration.PawnRules.RuleNameFormat", Mod_PawnRules.GetRules(model.Base));
            Tooltip = null;
            Color   = null;

            OnClick = () => Mod_PawnRules.OpenRules(model.Base);
            OnHover = null;
        }
Example #13
0
        public OutfitModel(PawnModel model) : base(model)
        {
            if (!model.IsPlayerFaction || (model.Base.outfits?.CurrentOutfit == null))
            {
                Hidden = true;
                return;
            }

            Label   = Lang.Get("Model.Selector.OutfitFormat", model.Base.outfits?.CurrentOutfit.label);
            Tooltip = null;
            Color   = null;

            OnClick = DrawFloatMenu;
            OnHover = null;
        }
Example #14
0
        public FoodModel(PawnModel model) : base(model)
        {
            if (!model.IsPlayerManaged || (model.Base.foodRestriction == null) || !model.Base.foodRestriction.Configurable)
            {
                Hidden = true;
                return;
            }

            Label   = Lang.Get("Model.Selector.FoodFormat", model.Base.foodRestriction.CurrentFoodRestriction.label);
            Tooltip = null;
            Color   = null;

            OnClick = DrawFloatMenu;
            OnHover = null;
        }
Example #15
0
        public AreaModel(PawnModel model) : base(model)
        {
            if ((!model.Base.Faction?.IsPlayer ?? true) || (model.Base.playerSettings == null) || (!model.Base.IsColonist && !model.Base.playerSettings.RespectsAllowedArea))
            {
                Hidden = true;
                return;
            }

            Label   = Lang.Get("Model.Selector.AreaFormat", AreaUtility.AreaAllowedLabel(model.Base));
            Tooltip = null;
            Color   = model.Base.playerSettings?.EffectiveAreaRestriction?.Color;

            OnClick = DrawFloatMenu;
            OnHover = () => model.Base.playerSettings.EffectiveAreaRestriction?.MarkForDraw();
        }
Example #16
0
        public HealthBarModel(PawnModel model) : base(model)
        {
            if (model.Base.health == null)
            {
                Hidden = true;
                return;
            }

            Label = "Health".Translate();

            Max        = 1f;
            Value      = model.Health.Percent;
            ValueStyle = HudBar.ValueStyle.Percentage;

            Tooltip    = model.Health.Tooltip;
            Thresholds = null;
        }
Example #17
0
        public TimetableModel(PawnModel model) : base(model)
        {
            if ((!model.Base.Faction?.IsPlayer ?? true) || (model.Base.timetable == null))
            {
                Hidden = true;
                return;
            }

            Label   = Lang.Get("Model.Selector.TimetableFormat", model.Base.timetable.CurrentAssignment.LabelCap);
            Tooltip = null;
            var assignment = model.Base.timetable.CurrentAssignment;

            Color = assignment == TimeAssignmentDefOf.Anything ? (Color?)null : assignment.color;

            OnClick = DrawFloatMenu;
            OnHover = null;
        }
Example #18
0
        public SkillModel(PawnModel model, SkillDef def) : base(model)
        {
            Def = def;

            var skill = model.Base.skills?.GetSkill(def);

            if (skill == null)
            {
                Hidden = true;
                return;
            }

            Skill = skill;

            Label = def.LabelCap + new string('+', (int)skill.passion);
            Value = skill.TotallyDisabled ? "-" : skill.Level.ToDecimalString(skill.XpProgressPercent.ToPercentageInt()) + (skill.LearningSaturatedToday ? "*" : null);
            Color = skill.TotallyDisabled ? Theme.DisabledColor.Value : GetSkillPassionColor(skill.passion);
        }
Example #19
0
        private static HudWidgetBase GetStatWidget(PawnModel model, string defName)
        {
            var def = DefDatabase <StatDef> .GetNamed(defName, false);

            if (def != null)
            {
                if (def.Worker?.IsDisabledFor(model.Base) ?? true)
                {
                    return(HudBlank.GetEmpty);
                }
                var text = $"{def.LabelCap}: {def.ValueToString(model.Base.GetStatValue(def))}";
                return((HudWidgetBase)HudValue.FromText(text, null, Theme.RegularTextStyle) ?? HudBlank.GetEmpty);
            }

            Mod.Warning($"Invalid HUD Widget, Stat def '{defName}' not found, resetting layout to default");
            RequiredReset();
            return(HudBlank.GetEmpty);
        }
Example #20
0
        public HealthBarModel(PawnModel model)
        {
            Model = model;

            if (model.Base.health == null)
            {
                Hidden = true;
                return;
            }

            Label = "Health".Translate();

            Max        = 1f;
            Value      = model.Health.Percent;
            ValueStyle = HudBar.ValueStyle.Percentage;

            Tooltip = model.Health.Tooltip;

            OnClick = InspectPanePlus.ToggleHealthTab;
        }
Example #21
0
        public RulesModel(PawnModel model)
        {
            try
            {
                Model = model;

                if (!Mod_PawnRules.Instance.IsActive || !Mod_PawnRules.CanHaveRules(model.Base))
                {
                    Hidden = true;
                    return;
                }

                Label = Lang.Get("Integration.PawnRules.RuleNameFormat", Mod_PawnRules.GetRules(model.Base));

                OnClick = () => Mod_PawnRules.OpenRules(model.Base);
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Example #22
0
        public FoodModel(PawnModel model)
        {
            try
            {
                Model = model;

                if (!model.IsPlayerManaged || model.Base.foodRestriction == null || !model.Base.foodRestriction.Configurable)
                {
                    Hidden = true;
                    return;
                }

                Label = Lang.Get("Model.Selector.FoodFormat", model.Base.foodRestriction.CurrentFoodRestriction?.label);

                OnClick = DrawFloatMenu;
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Example #23
0
        public OutfitModel(PawnModel model)
        {
            try
            {
                Model = model;

                if (!model.IsPlayerFaction || model.Base?.outfits?.CurrentOutfit == null)
                {
                    Hidden = true;
                    return;
                }

                Label = Lang.Get("Model.Selector.OutfitFormat", model.Base.outfits?.CurrentOutfit.label);

                OnClick = DrawFloatMenu;
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Example #24
0
        public NeedModel(PawnModel model, NeedDef def)
        {
            Model = model;

            var need = model.Base.needs?.TryGetNeed(def);

            if (need == null)
            {
                Hidden = true;
                return;
            }

            Label = def.LabelCap;

            Max        = 1f;
            Value      = need.CurLevelPercentage;
            ValueStyle = HudBar.ValueStyle.Percentage;

            if (def == Access.NeedDefOfMood)
            {
                Tooltip    = model.Mind.Tooltip;
                Thresholds = new[] { model.MoodThresholdMinor, model.MoodThresholdMajor, model.MoodThresholdExtreme };
            }
            else if (def == NeedDefOf.Food)
            {
                Tooltip = GetFoodTooltip();
            }
            else if (def == NeedDefOf.Rest)
            {
                Tooltip = GetRestTooltip();
            }
            else if (def == NeedDefOf.Joy)
            {
                Tooltip = GetJoyTooltip();
            }

            OnClick = InspectPanePlus.ToggleNeedsTab;
        }
Example #25
0
        public TrainingModel(PawnModel model, TrainableDef def) : base(model)
        {
            var trainable   = (model.Base.RaceProps?.trainability != null) && (model.Base.training != null);
            var visible     = false;
            var canTrainNow = model.Base.training?.CanAssignToTrain(def, out visible).Accepted ?? false;

            if (!trainable || !visible || !canTrainNow)
            {
                Hidden = true;
                return;
            }

            Label = def.LabelCap;

            var disabled   = !model.Base.training.GetWanted(def);
            var hasLearned = model.Base.training.HasLearned(def);

            var steps = GetSteps(model.Base, def);
            var value = steps + " / " + def.steps;

            Value = hasLearned ? value.Bold() : value;

            Tooltip = model.GetAnimalTooltip(def);

            if (disabled)
            {
                Color = Theme.DisabledColor.Value;
            }
            else if (hasLearned)
            {
                Color = Theme.SkillMinorPassionColor.Value;
            }
            else
            {
                Color = Theme.MainTextColor.Value;
            }
        }
Example #26
0
 protected AttributeModel(PawnModel model) => Model = model;
Example #27
0
 protected SelectorModel(PawnModel model) : base(model)
 {
 }
Example #28
0
 protected BarModel(PawnModel model) : base(model)
 {
 }
Example #29
0
 public MindModel(PawnModel model) => Model = model;
Example #30
0
        public NeedModel(PawnModel model, NeedDef def) : base(model)
        {
            var need = model.Base.needs?.TryGetNeed(def);

            if (need == null)
            {
                Hidden = true;
                return;
            }

            Label = def.LabelCap;

            Max        = 1f;
            Value      = need.CurLevelPercentage;
            ValueStyle = HudBar.ValueStyle.Percentage;

            if (def == Access.NeedDefOfMood)
            {
                Tooltip    = model.Mind.Tooltip;
                Thresholds = new[] { model.MoodThresholdMinor, model.MoodThresholdMajor, model.MoodThresholdExtreme };
            }
            else if (def == NeedDefOf.Food)
            {
                var builder = new StringBuilder();
                if (Model.Base.RaceProps?.foodType != null)
                {
                    builder.AppendLine("Diet".Translate() + ": " + Model.Base.RaceProps.foodType.ToHumanString().CapitalizeFirst());
                    builder.AppendLine();
                }
                BuildStatString(builder, StatDefOf.EatingSpeed);
                BuildStatString(builder, StatDefOf.HungerRateMultiplier);

                Tooltip = builder.Length == 0 ? null : new TipSignal(() => builder.ToStringTrimmed().Size(Theme.RegularTextStyle.ActualSize), GUIPlus.TooltipId);
            }
            else if (def == NeedDefOf.Rest)
            {
                var builder = new StringBuilder();
                BuildStatString(builder, StatDefOf.RestRateMultiplier);

                Tooltip = builder.Length == 0 ? null : new TipSignal(() => builder.ToStringTrimmed().Size(Theme.RegularTextStyle.ActualSize), GUIPlus.TooltipId);
            }
            else if (def == NeedDefOf.Joy)
            {
                var builder = new StringBuilder();
                if (Model.Base.needs?.beauty != null)
                {
                    builder.AppendLine($"{Access.NeedDefOfBeauty.LabelCap}: {Model.Base.needs.beauty.CurLevelPercentage.ToStringPercent()}");
                }
                if (Model.Base.needs?.comfort != null)
                {
                    builder.AppendLine($"{Access.NeedDefOfComfort.LabelCap}: {Model.Base.needs.comfort.CurLevelPercentage.ToStringPercent()}");
                }
                if (Model.Base.needs?.outdoors != null)
                {
                    builder.AppendLine($"{Access.NeedDefOfOutdoors.LabelCap}: {Model.Base.needs.outdoors.CurLevelPercentage.ToStringPercent()}");
                }

                Tooltip = builder.Length == 0 ? null : new TipSignal(() => builder.ToStringTrimmed().Size(Theme.RegularTextStyle.ActualSize), GUIPlus.TooltipId);
            }
            else
            {
                Tooltip    = null;
                Thresholds = null;
            }

            OnClick = InspectPanePlus.ToggleNeedsTab;
        }