Пример #1
0
 public void SetPriority(WorkTypeDef w, int priority)
 {
     this.ConfirmInitializedDebug();
     if (priority != 0 && this.pawn.story.WorkTypeIsDisabled(w))
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to change priority on disabled worktype ",
             w,
             " for pawn ",
             this.pawn
         }));
         return;
     }
     if (priority < 0 || priority > 4)
     {
         Log.Message("Trying to set work to invalid priority " + priority);
     }
     this.priorities[w] = priority;
     if (priority == 0)
     {
         this.pawn.mindState.Notify_WorkPriorityDisabled(w);
     }
     this.workGiversDirty = true;
 }
Пример #2
0
        private void SetAsBuilder(Pawn p)
        {
            var data         = Data;
            var customParams = CustomParams;

            p.mindState.duty        = new PawnDuty(DutyDefOf.Build, data.siegeCenter, -1f);
            p.mindState.duty.radius = data.baseRadius;
            int minLevel = Mathf.Max(customParams.coverDef.constructionSkillPrerequisite, customParams.maxArtilleryConstructionSkill);

            p.skills.GetSkill(SkillDefOf.Construction).EnsureMinLevelWithMargin(minLevel);
            p.workSettings.EnableAndInitialize();
            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                WorkTypeDef workTypeDef = allDefsListForReading[i];
                if (workTypeDef == WorkTypeDefOf.Construction)
                {
                    p.workSettings.SetPriority(workTypeDef, 1);
                }
                else
                {
                    p.workSettings.Disable(workTypeDef);
                }
            }
        }
 protected override bool CanDoNext()
 {
     if (!base.CanDoNext())
     {
         return(false);
     }
     if (TutorSystem.TutorialMode)
     {
         WorkTypeDef workTypeDef = StartingPawnUtility.RequiredWorkTypesDisabledForEveryone().FirstOrDefault();
         if (workTypeDef != null)
         {
             Messages.Message("RequiredWorkTypeDisabledForEveryone".Translate() + ": " + workTypeDef.gerundLabel.CapitalizeFirst() + ".", MessageTypeDefOf.RejectInput, historical: false);
             return(false);
         }
     }
     foreach (Pawn startingAndOptionalPawn in Find.GameInitData.startingAndOptionalPawns)
     {
         if (!startingAndOptionalPawn.Name.IsValid)
         {
             Messages.Message("EveryoneNeedsValidName".Translate(), MessageTypeDefOf.RejectInput, historical: false);
             return(false);
         }
     }
     PortraitsCache.Clear();
     return(true);
 }
Пример #4
0
        public static bool AnyoneCanDoBasicWorks()
        {
            if (ModdedMapInitParams.colonists.Count == 0)
            {
                return(false);
            }
            WorkTypeDef[] array = new WorkTypeDef[]
            {
                WorkTypeDefOf.Hauling,
                WorkTypeDefOf.Construction,
                WorkTypeDefOf.Mining,
                WorkTypeDefOf.Mining
            };
            WorkTypeDef[] array2 = array;
            WorkTypeDef   wt;

            for (int i = 0; i < array2.Length; i++)
            {
                wt = array2[i];
                if (!ModdedMapInitParams.colonists.Any((Pawn col) => !col.story.WorkTypeIsDisabled(wt)))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #5
0
        public static int GetPriority(this Pawn pawn, WorkTypeDef worktype, int hour)
        {
            if (hour < 0)
            {
                hour = GenLocalDate.HourOfDay(pawn);
            }

            // get priorities for all workgivers in worktype
            var priorities = worktype.WorkGivers()
                             .Select(wg => GetPriority(pawn, wg, hour))
                             .Where(p => p > 0);

            // if there are no active priorities, return zero
            if (!priorities.Any())
            {
                return(0);
            }

            // otherwise, return the lowest number (highest priority).
            if (Find.PlaySettings.useWorkPriorities)
            {
                return(priorities.Min());
            }

            // or, in simple mode, just 3.
            return(3);
        }
Пример #6
0
        protected void DecrementJobPriority(WorkTypeDef work, bool toggle)
        {
            bool min = Pawns.All(p => (p.workSettings.GetPriority(work) == 0 || (p.story == null || p.story.WorkTypeIsDisabled(work))));

            foreach (Pawn p in Pawns)
            {
                if (!(p.story == null || p.story.WorkTypeIsDisabled(work)))
                {
                    int cur = p.workSettings.GetPriority(work);
                    if (!toggle && cur > 0 && cur < 4)
                    {
                        p.workSettings.SetPriority(work, cur + 1);
                    }
                    if (cur == 4 || (toggle && cur == 1))
                    {
                        p.workSettings.SetPriority(work, 0);
                        if (toggle)
                        {
                            SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
                        }
                    }
                    if (min && toggle)
                    {
                        p.workSettings.SetPriority(work, 3);
                        SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                    }
                }
            }
        }
Пример #7
0
        protected void IncrementJobPriority(WorkTypeDef work, bool toggle)
        {
            int  start = toggle ? 3 : 4;
            bool max   = Pawns.All(p => (p.workSettings.GetPriority(work) == 1 || (p.story == null || p.story.WorkTypeIsDisabled(work))));

            foreach (Pawn t in Pawns)
            {
                if (!(t.story == null || t.story.WorkTypeIsDisabled(work)))
                {
                    int cur = t.workSettings.GetPriority(work);
                    if (cur > 1)
                    {
                        t.workSettings.SetPriority(work, cur - 1);
                    }
                    if (cur == 0)
                    {
                        if (toggle)
                        {
                            SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                        }
                        t.workSettings.SetPriority(work, start);
                    }
                    if (toggle && max)
                    {
                        SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
                        t.workSettings.SetPriority(work, 0);
                    }
                }
            }
        }
Пример #8
0
 public static bool AnyoneCanDoBasicWorks()
 {
     if (ModdedMapInitParams.colonists.Count == 0)
     {
         return false;
     }
     WorkTypeDef[] array = new WorkTypeDef[]
     {
         WorkTypeDefOf.Hauling,
         WorkTypeDefOf.Construction,
         WorkTypeDefOf.Mining,
         WorkTypeDefOf.Mining
     };
     WorkTypeDef[] array2 = array;
     WorkTypeDef wt;
     for (int i = 0; i < array2.Length; i++)
     {
         wt = array2[i];
         if (!ModdedMapInitParams.colonists.Any((Pawn col) => !col.story.WorkTypeIsDisabled(wt)))
         {
             return false;
         }
     }
     return true;
 }
Пример #9
0
        public bool IsDisabled(WorkTags combinedDisabledWorkTags, IEnumerable <WorkTypeDef> disabledWorkTypes)
        {
            if ((combinedDisabledWorkTags & disablingWorkTags) != 0)
            {
                return(true);
            }
            if (neverDisabledBasedOnWorkTypes)
            {
                return(false);
            }
            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;
            bool flag = false;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                WorkTypeDef workTypeDef = allDefsListForReading[i];
                for (int j = 0; j < workTypeDef.relevantSkills.Count; j++)
                {
                    if (workTypeDef.relevantSkills[j] == this)
                    {
                        if (!disabledWorkTypes.Contains(workTypeDef))
                        {
                            return(false);
                        }
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
            return(true);
        }
        public List <WorkGiver> GetWorkGivers(bool emergency)
        {
            if (emergency && workGiversEmergencyCache != null)
            {
                return(workGiversEmergencyCache);
            }
            if (!emergency && workGiversNonEmergencyCache != null)
            {
                return(workGiversNonEmergencyCache);
            }

            List <WorkTypeDef> wtsByPrio             = new List <WorkTypeDef>();
            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;
            int num = 999;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                WorkTypeDef workTypeDef = allDefsListForReading[i];
                int         priority    = GetPriority(workTypeDef);
                if (priority > 0)
                {
                    if (priority < num)
                    {
                        if (workTypeDef.workGiversByPriority.Any((WorkGiverDef wg) => wg.emergency == emergency))
                        {
                            num = priority;
                        }
                    }
                    wtsByPrio.Add(workTypeDef);
                }
            }
            wtsByPrio.InsertionSort(delegate(WorkTypeDef a, WorkTypeDef b)
            {
                float value = (float)(a.naturalPriority + (4 - this.GetPriority(a)) * 100000);
                return(((float)(b.naturalPriority + (4 - this.GetPriority(b)) * 100000)).CompareTo(value));
            });
            List <WorkGiver> workGivers = new List <WorkGiver>();

            for (int j = 0; j < wtsByPrio.Count; j++)
            {
                WorkTypeDef workTypeDef2 = wtsByPrio[j];
                for (int k = 0; k < workTypeDef2.workGiversByPriority.Count; k++)
                {
                    WorkGiver worker = workTypeDef2.workGiversByPriority[k].Worker;
                    workGivers.Add(worker);
                }
            }

            // Fill cache
            if (emergency)
            {
                workGiversEmergencyCache = workGivers;
            }
            else
            {
                workGiversNonEmergencyCache = workGivers;
            }

            return(workGivers);
        }
Пример #11
0
        public static string SpecificWorkListString(this WorkTypeDef def)
        {
            string tip;

            if (workListCache.TryGetValue(def, out tip))
            {
                return(tip);
            }

            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < def.workGiversByPriority.Count; i++)
            {
                stringBuilder.Append(def.workGiversByPriority[i].LabelCap);
                if (def.workGiversByPriority[i].emergency)
                {
                    stringBuilder.Append(" (" + "EmergencyWorkMarker".Translate() + ")");
                }
                if (i < def.workGiversByPriority.Count - 1)
                {
                    stringBuilder.AppendLine();
                }
            }

            tip = stringBuilder.ToString();
            workListCache.Add(def, tip);
            return(tip);
        }
Пример #12
0
        public void Notify_WorkTypeDisabled(WorkTypeDef wType)
        {
            bool flag = pawn.WorkTypeIsDisabled(wType);

            try
            {
                if (curJob != null && curJob.workGiverDef != null && curJob.workGiverDef.workType == wType && (flag || !curJob.playerForced))
                {
                    tmpJobsToDequeue.Add(curJob);
                }
                foreach (QueuedJob item in jobQueue)
                {
                    if (item.job.workGiverDef != null && item.job.workGiverDef.workType == wType && (flag || !item.job.playerForced))
                    {
                        tmpJobsToDequeue.Add(item.job);
                    }
                }
                foreach (Job item2 in tmpJobsToDequeue)
                {
                    EndCurrentOrQueuedJob(item2, JobCondition.InterruptForced);
                }
            }
            finally
            {
                tmpJobsToDequeue.Clear();
            }
        }
Пример #13
0
        private IEnumerable <PawnColumnDef> GenerateImpliedDefs()
        {
            PawnTableDef workTable = DefDatabase <PawnTableDef> .GetNamed("MD3_DroidWork");

            bool moveWorkTypeLabelDown2 = false;

            using (IEnumerator <WorkTypeDef> enumerator2 = (from d in WorkTypeDefsUtility.WorkTypeDefsInPriorityOrder
                                                            where d.visible
                                                            select d).Reverse().GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    WorkTypeDef def = enumerator2.Current;
                    moveWorkTypeLabelDown2 = !moveWorkTypeLabelDown2;
                    PawnColumnDef d2 = new PawnColumnDef
                    {
                        defName  = "DroidWorkPriority_" + def.defName,
                        workType = def,
                        moveWorkTypeLabelDown = moveWorkTypeLabelDown2,
                        workerClass           = typeof(PawnColumnWorker_DroidWorkPriority),
                        sortable       = true,
                        modContentPack = def.modContentPack
                    };
                    workTable.columns.Insert(workTable.columns.FindIndex((PawnColumnDef x) => x.Worker is PawnColumnWorker_CopyPasteWorkPriorities) + 1, d2);
                    yield return(d2);
                }
            }
        }
Пример #14
0
 // due to other mods' worktypes, our worktype priority may start at zero. This should fix that.
 public static void EnsureAllColonistsHaveWorkTypeEnabled(WorkTypeDef def, Map map)
 {
     try {
         var activatedPawns = new HashSet <Pawn>();
         if (map?.mapPawns == null)
         {
             return;
         }
         foreach (var pawn in map.mapPawns.PawnsInFaction(Faction.OfPlayer).Concat(map.mapPawns.PrisonersOfColony))
         {
             var priorityList = GetWorkPriorityListForPawn(pawn);
             if (priorityList != null && priorityList.Count > 0)
             {
                 var curValue = priorityList[def.index];
                 if (curValue == DisabledWorkPriority)
                 {
                     var adjustedValue = GetWorkTypePriorityForPawn(def, pawn);
                     if (adjustedValue != curValue)
                     {
                         priorityList[def.index] = adjustedValue;
                         activatedPawns.Add(pawn);
                     }
                 }
             }
         }
         if (activatedPawns.Count > 0)
         {
             AllowToolController.Logger.Message("Adjusted work type priority of {0} to default for pawns: {1}", def.defName, activatedPawns.Join(", ", true));
         }
     } catch (Exception e) {
         AllowToolController.Logger.Error("Exception while adjusting work type priority in colonist pawns: " + e);
     }
 }
Пример #15
0
        protected override bool Satisfied(Pawn me)
        {
            if (_def == null)
            {
                _def = DefDatabase <WorkTypeDef> .GetNamedSilentFail(workTypeDef);
            }

            if (_def == null)
            {
                return(false);
            }

            if (me?.workSettings == null || !me.workSettings.WorkIsActive(_def))
            {
                return(false);
            }

            if (me.Drafted)
            {
                return(false);
            }

            if (makeAgro)
            {
                if (me.playerSettings == null)
                {
                    me.playerSettings = new Pawn_PlayerSettings(me);
                }
                me.playerSettings.hostilityResponse = HostilityResponseMode.Attack;
            }

            return(true);
        }
Пример #16
0
        public override void PostClose()
        {
            base.PostClose();

            this.sortingDef   = null;
            this.sortingOrder = SortOrder.Undefined;
        }
        // EdB: Copied from MapInitData.AnyoneCanDoBasicWork() and changed from a static to an instance method.
        public bool AnyoneCanDoBasicWorks()
        {
            if (colonists.Count == 0)
            {
                return(false);
            }
            WorkTypeDef[] array = new WorkTypeDef[] {
                WorkTypeDefOf.Hauling,
                WorkTypeDefOf.Construction,
                WorkTypeDefOf.Mining,
                WorkTypeDefOf.Growing,
                WorkTypeDefOf.Cleaning,
                WorkTypeDefOf.PlantCutting,
                WorkTypeDefOf.Repair
            };
            WorkTypeDef[] array2 = array;
            WorkTypeDef   wt;

            for (int i = 0; i < array2.Length; i++)
            {
                wt = array2[i];
                if (!Colonists.Any((Pawn col) => !col.story.WorkTypeIsDisabled(wt)))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #18
0
        //Small helper function to create each Checkbox as i cant pass variable directly
        private bool CheckboxHelper(Rect rect, Listing_Standard list, bool variable, WorkTypeDef def)
        {
            rect = list.GetRect(30f); //That seems to affect the text possition
            bool lstatus = variable;

            Widgets.CheckboxLabeled(rect, def.labelShort, ref lstatus);
            Rect rect2 = rect;

            string labeltext = "ITab_DroneStation_averageskill".Translate();

            rect2.x = 400 - (10 * labeltext.Length);
            if (def.relevantSkills.Count > 0)
            {
                int medSkill = 0;
                foreach (SkillRecord skill in droneStation.DroneSeetings_skillDefs)
                {
                    if (def.relevantSkills.Contains(skill.def))
                    {
                        medSkill += skill.levelInt;
                    }
                }
                rect2.y += 5;

                medSkill = medSkill / def.relevantSkills.Count;

                Widgets.Label(rect2, labeltext + medSkill);
            }
            else
            {
                Widgets.Label(rect2, "-");
            }

            return(lstatus);
        }
Пример #19
0
 public void SetPawnWorkTypeEnabled([NotNull] Pawn pawn, [NotNull] WorkTypeDef workType, bool enabled)
 {
     if (pawn == null)
     {
         throw new ArgumentNullException(nameof(pawn));
     }
     if (workType == null)
     {
         throw new ArgumentNullException(nameof(workType));
     }
     if (_disabledPawnWorkTypes == null)
     {
         _disabledPawnWorkTypes = new List <PawnWorkType>();
     }
     if (enabled)
     {
         _disabledPawnWorkTypes.RemoveAll(pwt => pwt.Pawn == pawn && pwt.WorkType == workType);
     }
     else
     {
         if (!_disabledPawnWorkTypes.Any(pwt => pwt.Pawn == pawn && pwt.WorkType == workType))
         {
             _disabledPawnWorkTypes.Add(new PawnWorkType {
                 Pawn = pawn, WorkType = workType
             });
         }
     }
 }
Пример #20
0
        public static void IncrementPriority(this WorkTypeDef worktype, List <Pawn> pawns, int hour = -1, List <int> hours = null, bool playSound = true)
        {
            // bail out on bad input
            if (pawns.NullOrEmpty())
            {
                return;
            }

            // get default hour if not specified, we're assuming all pawns are on the same map/tile
            if (hour < 0)
            {
                hour = GenLocalDate.HourOfDay(pawns.FirstOrDefault());
            }

            // play sounds
            if (Settings.playSounds && playSound && pawns.Any(p => p.GetPriority(worktype, hour) > 0))
            {
                SoundDefOf.AmountDecrement.PlayOneShotOnCamera();
            }

            // increase priorities that are > 0 only (no wrapping around once we're at min priority
            foreach (Pawn pawn in pawns.Where(p => p.GetPriority(worktype, hour) > 0).DistinctTrackers())
            {
                IncrementPriority(worktype, pawn, hour, hours, false);
            }
        }
Пример #21
0
        public bool IsDisabled(WorkTags combinedDisabledWorkTags, IEnumerable <WorkTypeDef> disabledWorkTypes)
        {
            bool result;

            if ((combinedDisabledWorkTags & this.disablingWorkTags) != WorkTags.None)
            {
                result = true;
            }
            else
            {
                List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;
                bool flag = false;
                for (int i = 0; i < allDefsListForReading.Count; i++)
                {
                    WorkTypeDef workTypeDef = allDefsListForReading[i];
                    for (int j = 0; j < workTypeDef.relevantSkills.Count; j++)
                    {
                        if (workTypeDef.relevantSkills[j] == this)
                        {
                            if (!disabledWorkTypes.Contains(workTypeDef))
                            {
                                return(false);
                            }
                            flag = true;
                        }
                    }
                }
                result = flag;
            }
            return(result);
        }
Пример #22
0
 public Priority(Pawn pawn, WorkTypeDef workTypeDef, YouDoYou_Settings settings, bool freePawn)
 {
     this.pawn              = pawn;
     this.workTypeDef       = workTypeDef;
     this.adjustmentStrings = new List <string> {
     };
     this.mapComp           = pawn.Map.GetComponent <YouDoYou_MapComponent>();
     this.worldComp         = Find.World.GetComponent <YouDoYou_WorldComponent>();
     if (freePawn)
     {
         this.set(0.2f, "YouDoYouPriorityGlobalDefault".Translate()).compute();
     }
     else
     {
         int p = pawn.workSettings.GetPriority(workTypeDef);
         if (p == 0)
         {
             this.set(0.0f, "YouDoYouPriorityNoFreeWill".Translate());
         }
         else
         {
             this.set((100f - onePriorityWidth * (p - 1)) / 100f, "YouDoYouPriorityNoFreeWill".Translate());
         }
     }
 }
        static void Prefix(Pawn_WorkSettings __instance, WorkTypeDef w, ref int priority)
        {
            __instance.Pawn().SetPriority(w, priority, null);

            // TODO: find a more elegant way to stop RW complaining about bad priorities.
            priority = Mathf.Min(priority, 4);
        }
Пример #24
0
        private void SetAsBuilder(Pawn p)
        {
            LordToilData_Siege data = this.Data;

            p.mindState.duty        = new PawnDuty(DutyDefOf.Build, data.siegeCenter, -1f);
            p.mindState.duty.radius = data.baseRadius;
            int minLevel = Mathf.Max(ThingDefOf.Sandbags.constructionSkillPrerequisite, ThingDefOf.Turret_Mortar.constructionSkillPrerequisite);

            p.skills.GetSkill(SkillDefOf.Construction).EnsureMinLevelWithMargin(minLevel);
            p.workSettings.EnableAndInitialize();
            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                WorkTypeDef workTypeDef = allDefsListForReading[i];
                if (workTypeDef == WorkTypeDefOf.Construction)
                {
                    p.workSettings.SetPriority(workTypeDef, 1);
                }
                else
                {
                    p.workSettings.Disable(workTypeDef);
                }
            }
        }
        static Pawn Postfix(Pawn __result, Bill_ProductionWithUft __instance, UnfinishedThing __state)
        {
            if (__result == null && __state != null)
            {
                Pawn creator = __state.Creator;
                if (creator == null || creator.Downed || creator.Destroyed || !creator.Spawned)
                {
                    return(__result);
                }
                Thing thing = __instance.billStack.billGiver as Thing;
                if (thing != null)
                {
                    WorkTypeDef         workTypeDef           = null;
                    List <WorkGiverDef> allDefsListForReading = DefDatabase <WorkGiverDef> .AllDefsListForReading;
                    for (int i = 0; i < allDefsListForReading.Count; i++)
                    {
                        if (allDefsListForReading[i].fixedBillGiverDefs != null && allDefsListForReading[i].fixedBillGiverDefs.Contains(thing.def))
                        {
                            workTypeDef = allDefsListForReading[i].workType;
                            break;
                        }
                    }
                    if (workTypeDef != null && !creator.workSettings.WorkIsActive(workTypeDef))
                    {
                        return(__result);
                    }
                }
                Traverse.Create(__instance).Field("boundUftInt").SetValue(__state);
                DebugLogger.debug($"Returning creator {creator.LabelShort}, value override");
                return(creator);
            }

            return(__result);
        }
Пример #26
0
 public new void SetPriority(WorkTypeDef w, int priority)
 {
     //this.ConfirmInitializedDebug();
     //if (priority != 0 && this.pawn.story.WorkTypeIsDisabled(w))
     //{
     //    Log.Error(string.Concat(new object[]
     //    {
     //        "Tried to change priority on disabled worktype ",
     //        w,
     //        " for pawn ",
     //        this.pawn2
     //    }));
     //    return;
     //}
     //if (priority < 0 || priority > 4)
     //{
     //    Log.Message("Trying to set work to invalid priority " + priority);
     //}
     this.prioritiesReflected[w] = priority;
     //if (priority == 0)
     //{
     //    this.pawn2.mindState.Notify_WorkPriorityDisabled(w);
     //}
     //this.workGiversDirty = true;
 }
Пример #27
0
                static void Postfix(Pawn __instance, WorkTypeDef w, ref bool __result)
                {
                    // __result = true means the work is disabled and to check further now.
                    if (__result && LoadedModManager.GetMod <RoyaltyTweaksMod>().GetSettings <RoyaltyTweaksSettings>().willWorkPassionSkills &&
                        __instance.royalty != null &&
                        __instance.royalty.MostSeniorTitle != null &&
                        __instance.royalty.MostSeniorTitle.def != null &&
                        __instance.royalty.MostSeniorTitle.def.seniority > 100)
                    {
                        var skills = w.relevantSkills;

                        if (LoadedModManager.GetMod <RoyaltyTweaksMod>().GetSettings <RoyaltyTweaksSettings>().willWorkOnlyMajorPassionSkills)
                        {
                            // Work only major passion skills
                            if (__instance.skills.skills.Any(a => a.passion == Passion.Major && skills.Contains(a.def)))
                            {
                                __result = false;
                            }
                        }
                        else
                        {
                            // Work all passion skills.
                            if (__instance.skills.skills.Any(a => a.passion != Passion.None && skills.Contains(a.def)))
                            {
                                __result = false;
                            }
                        }
                    }
                }
Пример #28
0
 private static Job GetVehicle(Pawn pawn, Job job, WorkTypeDef worktag)
 {
     if (!ToolsForHaulUtility.IsDriver(pawn))
     {
         if (ToolsForHaulUtility.Cart.Count > 0 || ToolsForHaulUtility.CartTurret.Count > 0)
         {
             Thing vehicle = RightTools.GetRightVehicle(pawn, worktag);
             if (vehicle != null)
             {
                 job = new Job(HaulJobDefOf.Mount)
                 {
                     targetA = vehicle,
                 };
             }
         }
     }
     else
     {
         if (!ToolsForHaulUtility.IsDriverOfThisVehicle(pawn, RightTools.GetRightVehicle(pawn, worktag)))
         {
             job = ToolsForHaulUtility.DismountInBase(pawn, MapComponent_ToolsForHaul.currentVehicle[pawn]);
         }
     }
     return(job);
 }
Пример #29
0
        public static int GetVanillaPriority(this Pawn pawn, WorkTypeDef worktype)
        {
            //public override float GetPriority(Pawn pawn)
            if (pawn.workSettings == null || !pawn.workSettings.EverWork)
            {
                return(0);
            }

            if (prioritiesFieldInfo == null)
            {
                prioritiesFieldInfo = typeof(Pawn_WorkSettings).GetField("priorities", AccessTools.all);
                if (prioritiesFieldInfo == null)
                {
                    throw new NullReferenceException("priorities field not found");
                }
            }

            int priority;

            try
            {
                priority = (prioritiesFieldInfo.GetValue(pawn.workSettings) as DefMap <WorkTypeDef, int>)[worktype];
            }
            catch (ArgumentOutOfRangeException)
            {
                priority = 0;
                Logger.Message($"Priority requested for a workgiver that did not yet exist for {pawn.Name.ToStringShort}. Did you add mods in an existing game?");
            }
            catch (TargetException) {
                priority = 0;
                Logger.Message($"Priority requested for a pawn that did not have worksettings ({pawn.Name.ToStringShort})");
            }
            return(priority);
        }
Пример #30
0
        public static TipSignal TipForPawnWorker(Pawn p, WorkTypeDef wDef)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(wDef.gerundLabel);
            if (p.story.WorkTypeIsDisabled(wDef))
            {
                stringBuilder.Append("CannotDoThisWork".Translate(p.NameStringShort));
            }
            else
            {
                string text = string.Empty;
                if (wDef.relevantSkills.Count == 0)
                {
                    text = "NoneBrackets".Translate();
                }
                else
                {
                    foreach (SkillDef current in wDef.relevantSkills)
                    {
                        text = text + current.skillLabel + ", ";
                    }
                    text = text.Substring(0, text.Length - 2);
                }
                stringBuilder.AppendLine("RelevantSkills".Translate(text, p.skills.AverageOfRelevantSkillsFor(wDef).ToString(), 20));
                stringBuilder.AppendLine();
                stringBuilder.Append(wDef.description);
            }
            return(stringBuilder.ToString());
        }
Пример #31
0
        private static void LoadPriorities(List <Saveable_WorkTypeDef> saveableDefs)
        {
            // warning
            if (saveableDefs == null || saveableDefs.Count == 0)
            {
                Log.Warning("Loading priorities from a null / empty list.");
                return;
            }

            // Load the stored stuff, if any, into the game.
            foreach (Saveable_WorkTypeDef workType in saveableDefs)
            {
                WorkTypeDef workTypeDef = DefDatabase <WorkTypeDef> .GetNamedSilentFail(workType.defName);

                workTypeDef.naturalPriority = workType.priority;

                foreach (Saveable_WorkGiverDef workGiver in workType.workGivers)
                {
                    DefDatabase <WorkGiverDef> .GetNamedSilentFail(workGiver.defName).priorityInType = workGiver.priority;
                }

                // sort the cache correctly an notify pawns of changed priorities, which also notifies them of the worktype priority changes.
                // normalization of workTypes is handled in the dialog, and is irrelevant outside of the dialog.
                Dialog_Priority.RebuildWorkGiverDefsList(workTypeDef);
            }
        }
 public static void ForcePriority( this Pawn_WorkSettings p, WorkTypeDef w, int priority )
 {
     p.ConfirmInitializedDebug();
     if(
         ( priority < 0 )||
         ( priority > 4 )
     )
     {
         Log.Message( "Trying to set work to invalid priority " + (object) priority );
     }
     var priorities = p.Priorities();
     priorities[ w ] = priority;
     if( priority == 0 )
     {
         p.Pawn().mindState.Notify_WorkPriorityDisabled( w );
     }
     p.WorkGiversDirtySet( true );
 }
Пример #33
0
 public static void DrawWorkBoxBackground( Rect rect, Pawn p, WorkTypeDef workDef )
 {
     float num = p.skills.AverageOfRelevantSkillsFor( workDef );
     Texture2D texture2D1;
     Texture2D texture2D2;
     float a;
     var foo = p.workSettings.GetPriority( workDef );
     if( (double) num <= 14.0 )
     {
         texture2D1 = WidgetsWork.WorkBoxBGTex_Bad;
         texture2D2 = WidgetsWork.WorkBoxBGTex_Mid;
         a = num / 14f;
     }
     else
     {
         texture2D1 = WidgetsWork.WorkBoxBGTex_Mid;
         texture2D2 = WidgetsWork.WorkBoxBGTex_Excellent;
         a = (float) ( ( (double) num - 14.0 ) / 6.0 );
     }
     GUI.DrawTexture( rect, (Texture) texture2D1 );
     GUI.color = new Color( GUI.color.r, GUI.color.g, GUI.color.b, a );
     GUI.DrawTexture( rect, (Texture) texture2D2 );
     Passion passion = p.skills.MaxPassionOfRelevantSkillsFor( workDef );
     if( passion > Passion.None )
     {
         GUI.color = new Color( 1f, 1f, 1f, 0.4f );
         Rect position = rect;
         position.xMin = rect.center.x;
         position.yMin = rect.center.y;
         if( passion == Passion.Minor )
             GUI.DrawTexture( position, (Texture) WidgetsWork.PassionWorkboxMinorIcon );
         else if( passion == Passion.Major )
             GUI.DrawTexture( position, (Texture) WidgetsWork.PassionWorkboxMajorIcon );
     }
     GUI.color = Color.white;
 }
Пример #34
0
        private void Up( WorkTypeDef workType, WorkGiverDef workGiver )
        {
            // up, so increase priority
            // we actually switch priorities with the next highest
            WorkGiverDef next = workType.workGiversByPriority.OrderBy(wgd => wgd.priorityInType).First(wgd => wgd.priorityInType > workGiver.priorityInType);

            // bumping by one works because we normalized priorities.
            workGiver.priorityInType += 1;
            next.priorityInType -= 1;
            
            // rebuild the list to ensure everything stays normalized and is displayed correctly.
            RebuildWorkGiverDefsList( workType);
            
        }
Пример #35
0
        private void Down( WorkTypeDef workType, WorkGiverDef workGiver )
        {
            // down, so decrease priority
            // we actually switch priorities with the next highest
            // workGivers come pre-sorted in descending order
            WorkGiverDef next = workType.workGiversByPriority.First(wgd => wgd.priorityInType < workGiver.priorityInType);

            // bumping by one works because we normalized priorities.
            workGiver.priorityInType -= 1;
            next.priorityInType += 1;
            
            // rebuild the list to ensure everything stays normalized and is displayed correctly.
            RebuildWorkGiverDefsList( workType );
            
        }
 public void SetPriority( WorkTypeDef worktype, int priority )
 {
     for ( int hour = 0; hour < GenDate.HoursPerDay; hour++ )
         SetPriority( worktype, priority, hour );
 }
 private static void DrawWorkBoxBackground( Rect rect, Pawn p, WorkTypeDef workDef )
 {
     if( _DrawWorkBoxBackground == null )
     {
         _DrawWorkBoxBackground = typeof( WidgetsWork ).GetMethod( "DrawWorkBoxBackground", BindingFlags.Static | BindingFlags.NonPublic );
     }
     _DrawWorkBoxBackground.Invoke( null, new object[ ] { rect, p, workDef } );
 }
Пример #38
0
        public bool DrawEntry( ref Vector2 cur, Rect view, bool selected, WorkTypeDef workType, WorkGiverDef workGiver = null)
        {
            // set some convenience variables
            float   width       = view.width - cur.x - _margin;
            float   height      = _entryHeight;
            string  label;
            string  tooltip     = string.Empty;

            // indent with the margin
            cur.x += _margin;

            // set label / tooltip
            if (workGiver == null)
            {
                label = workType.labelShort;
            }
            else 
            {
                label = workGiver.verb.CapitalizeFirst();
                // very naive camelcase splitter, should help make things a tad more friendly, added sentence casing.
                // http://stackoverflow.com/questions/773303/splitting-camelcase 
                tooltip = System.Text.RegularExpressions.Regex.Replace( workGiver.defName, "([A-Z])", " $1", System.Text.RegularExpressions.RegexOptions.Compiled ).Trim().ToLower().CapitalizeFirst();
            }

            // decrease text size if label grows too big (probably will never happen).
            if( Text.CalcHeight( label, width ) > _entryHeight )
            {
                Text.Font = GameFont.Tiny;
                float height2 = Text.CalcHeight(label, width);
                height = Mathf.Max( height, height2 );
            }

            // draw the label
            Text.Anchor = TextAnchor.MiddleLeft;
            Rect labelRect = new Rect(cur.x, cur.y, width, height);
            Widgets.Label( labelRect, label );
            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font = GameFont.Small;
            
            // set buttonRect for highlighting
            Rect buttonRect = new Rect(view.xMin, cur.y, view.width, height);

            Widgets.DrawHighlightIfMouseover(buttonRect);

            // highlight if selected
            if(selected)
            {
                Widgets.DrawHighlightSelected( buttonRect );
            }

            // set a tooltip, since workgivers do not necessarily have unique labels
            if( tooltip != string.Empty )
            {
                TooltipHandler.TipRegion( buttonRect, tooltip );
            }

            // draw a line at the bottom to separate entries
            cur.y += height;
            GUI.color = Color.grey;
            Widgets.DrawLineHorizontal( view.xMin, cur.y, view.width );
            GUI.color = Color.white;

            // reset cur.x
            cur.x -= _margin;

            // return click for selecting stuff.
            return Widgets.InvisibleButton(buttonRect);

        }
        private void CreatePartiallyScheduledTip( WorkTypeDef worktype )
        {
            string tip = "FluffyTabs.XIsScheduledForY".Translate( pawn.Name.ToStringShort, worktype.labelShort );

            int start = -1;

            for ( int hour = 0; hour < GenDate.HoursPerDay; hour++ )
            {
                // start condition
                if ( GetPriority( worktype, hour ) > 0 && start < 0 )
                    start = hour;

                // stop condition
                if ( GetPriority( worktype, hour ) == 0 && start >= 0 )
                {
                    tip += start.FormatHour() + " - " + hour.FormatHour() + "\n";

                    // reset start
                    start = -1;
                }
            }

            // final check for x till midnight
            if ( start > 0 )
            {
                tip += start.FormatHour() + " - " + 0.FormatHour() + "\n";
            }

            // add or replace tip cache
            if ( !_partiallyScheduledTipCache.ContainsKey( worktype ) )
                _partiallyScheduledTipCache.Add( worktype, tip );
            else
                _partiallyScheduledTipCache[worktype] = tip;
        }
        private void Bottom( WorkTypeDef workType )
        {
            // set to top, i.e. 0
            workType.naturalPriority = 0;

            // rebuild def list (also notifies work tab and pawns of change)
            RebuildWorkTypeDefsList();
        }
Пример #41
0
        public override void DoWindowContents( Rect inRect )
        {
            // Close if work tab closed
            if( Find.WindowStack.WindowOfType<MainTabWindow_Work>() == null )
            {
                Find.WindowStack.TryRemove( this );
            }

            float areaHeight = (inRect.height - 50f - _margin)/2f;

            // the space reserved on the UI
            Rect headerRect = new Rect(inRect.xMin, _margin, inRect.width, 50f - _margin);
            Rect workTypeListRect = new Rect(inRect.xMin, 50f, inRect.width, areaHeight);
            Rect workGiverListRect = new Rect(inRect.xMin, workTypeListRect.yMax + _margin, inRect.width, areaHeight);

            // leave room for buttons
            workGiverListRect.width -= _buttonSize.x + _margin;
            workTypeListRect.width -= _buttonSize.x + _margin;

            // button areas
            Rect workTypeSortRect = new Rect(workTypeListRect.xMax + _margin, workTypeListRect.yMin, _buttonSize.x, areaHeight);
            Rect workGiverSortRect = new Rect(workGiverListRect.xMax + _margin, workGiverListRect.yMin, _buttonSize.x, areaHeight);
            Rect resetRect = new Rect(inRect.width - 27f, 13f - _margin / 2, 24f, 24f);

            // draw backgrounds
            Widgets.DrawMenuSection( workTypeListRect );
            Widgets.DrawMenuSection( workGiverListRect );

            // leave a tiny margin around the scrollbar if necessary
            if (_workTypeListHeight > workTypeListRect.height)
            {
                workTypeListRect.xMax -= 2f;
            }
            if( _workGiverListHeight > workGiverListRect.height )
            {
                workGiverListRect.xMax -= 2f;
            }

            // the canvas for the (scrollable) lists
            Rect workTypeListContent = new Rect(workTypeListRect.AtZero());
            Rect workGiverListContent = new Rect(workGiverListRect.AtZero());

            // set height to calculated height after first (every) pass.
            workTypeListContent.height = _workTypeListHeight;
            workGiverListContent.height = _workGiverListHeight;

            // leave room for scrollbar if necessary.
            workTypeListContent.width -= _workTypeListHeight > workTypeListRect.height ? 16f : 0f;
            workGiverListContent.width -= _workGiverListHeight > workGiverListRect.height ? 16f : 0f;
            
            // header
            Text.Font = GameFont.Medium;
            Widgets.Label(headerRect, "Fluffy.WorkPrioritiesDetails".Translate() );
            Text.Font = GameFont.Small;

            // reset button
            TooltipHandler.TipRegion(resetRect, "Fluffy.ResetPriorities".Translate());
            if (Widgets.ImageButton(resetRect, ResetButton))
            {
                MapComponent_Priorities.ResetPriorities();
                RebuildWorkTypeDefsList();
            }

            // worktype lister
            GUI.BeginGroup( workTypeListRect );
            Widgets.BeginScrollView( workTypeListRect.AtZero(), ref _workTypeScrollPosition, workTypeListContent );

            // keep track of position
            Vector2 cur = Vector2.zero;

            // draw the listings
            foreach (WorkTypeDef workType in WorkTypeDefs)
            {
                // move with selected when reordering
                if (_workTypeMoved && workType == _selectedWorkTypeDef)
                {
                    _workTypeScrollPosition.y = cur.y - 2 * _entryHeight;
                    _workTypeMoved = false;
                }
                if (DrawEntry(ref cur, workTypeListContent, workType == _selectedWorkTypeDef, workType))
                {
                    _selectedWorkTypeDef = workType;
                    _selectedWorkGiverDef = null;
                }
            }

            // set the actual height after having drawn everything
            _workTypeListHeight = cur.y;

            Widgets.EndScrollView();
            GUI.EndGroup();
            
            // draw buttons
            DrawSortButtons( workTypeSortRect, _selectedWorkTypeDef != null, _selectedWorkTypeDef );
            

            // START WORKGIVERS
            if( _selectedWorkTypeDef != null)
            {
                // workgiver lister
                GUI.BeginGroup( workGiverListRect );
                Widgets.BeginScrollView( workGiverListRect.AtZero(), ref _workGiverScrollPosition, workGiverListContent );

                // keep track of position
                cur = Vector2.zero;

                // draw the listings
                foreach( WorkGiverDef workGiver in _selectedWorkTypeDef.workGiversByPriority )
                {
                    // move with selected when reordering
                    if( _workGiverMoved && workGiver == _selectedWorkGiverDef )
                    {
                        _workGiverScrollPosition.y = cur.y - 2 * _entryHeight;
                        _workGiverMoved = false;
                    }
                    if( DrawEntry( ref cur, workGiverListContent, workGiver == _selectedWorkGiverDef, _selectedWorkTypeDef, workGiver ) )
                    {
                        _selectedWorkGiverDef = workGiver;
                    }
                }

                _workGiverListHeight = cur.y;

                Widgets.EndScrollView();
                GUI.EndGroup();

                // draw buttons
                DrawSortButtons( workGiverSortRect, _selectedWorkGiverDef != null, _selectedWorkTypeDef, _selectedWorkGiverDef );
            }
        }
        private void Up( WorkTypeDef workType )
        {
            // up, so increase priority
            // we actually switch priorities with the next highest
            WorkTypeDef next =
                DefDatabase<WorkTypeDef>.AllDefs.OrderBy( wtd => wtd.naturalPriority )
                    .First( wtd => wtd.naturalPriority > workType.naturalPriority );

            // bumping by one works because we normalized priorities.
            workType.naturalPriority += 1;
            next.naturalPriority -= 1;

            // rebuild def list (also notifies work tab and pawns of change)
            RebuildWorkTypeDefsList();
        }
        private void Top( WorkTypeDef workType )
        {
            // set to top, i.e. count + 1
            workType.naturalPriority = WorkTypeDefs.Count + 1;

            // rebuild def list (also notifies work tab and pawns of change)
            RebuildWorkTypeDefsList();
        }
Пример #44
0
 public static TipSignal TipForPawnWorker( Pawn p, WorkTypeDef wDef )
 {
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.AppendLine( wDef.gerundLabel );
     if( p.story.WorkTypeIsDisabled( wDef ) )
     {
         stringBuilder.Append( "CannotDoThisWork".Translate( p.NameStringShort ) );
     }
     else
     {
         string text = string.Empty;
         if( wDef.relevantSkills.Count == 0 )
         {
             text = "NoneBrackets".Translate();
         }
         else
         {
             foreach( SkillDef current in wDef.relevantSkills )
             {
                 text = text + current.skillLabel + ", ";
             }
             text = text.Substring( 0, text.Length - 2 );
         }
         stringBuilder.AppendLine( "RelevantSkills".Translate( text, p.skills.AverageOfRelevantSkillsFor( wDef ).ToString(), 20 ) );
         stringBuilder.AppendLine();
         stringBuilder.Append( wDef.description );
     }
     return stringBuilder.ToString();
 }
Пример #45
0
 private static void DrawWorkBoxBackground( Rect rect, Pawn p, WorkTypeDef workDef )
 {
     float num = p.skills.AverageOfRelevantSkillsFor(workDef);
     Texture2D image;
     Texture2D image2;
     float a;
     if( num <= 14f )
     {
         image = WorkBoxBGTex_Bad;
         image2 = WorkBoxBGTex_Mid;
         a = num / 14f;
     }
     else
     {
         image = WorkBoxBGTex_Mid;
         image2 = WorkBoxBGTex_Excellent;
         a = ( num - 14f ) / 6f;
     }
     GUI.DrawTexture( rect, image );
     GUI.color = new Color( 1f, 1f, 1f, a );
     GUI.DrawTexture( rect, image2 );
     Passion passion = p.skills.MaxPassionOfRelevantSkillsFor(workDef);
     if( passion > Passion.None )
     {
         GUI.color = new Color( 1f, 1f, 1f, 0.4f );
         Rect position = rect;
         position.xMin = rect.center.x;
         position.yMin = rect.center.y;
         if( passion == Passion.Minor )
         {
             GUI.DrawTexture( position, PassionWorkboxMinorIcon );
         }
         else if( passion == Passion.Major )
         {
             GUI.DrawTexture( position, PassionWorkboxMajorIcon );
         }
     }
     GUI.color = Color.white;
 }
Пример #46
0
 public static void DrawWorkBoxFor( Vector2 topLeft, Pawn p, WorkTypeDef wType )
 {
     if( p.story == null || p.story.WorkTypeIsDisabled( wType ) )
     {
         return;
     }
     Rect rect = new Rect(topLeft.x, topLeft.y, 25f, 25f);
     DrawWorkBoxBackground( rect, p, wType );
     if( Find.PlaySettings.useWorkPriorities )
     {
         int priority = p.workSettings.GetPriority(wType);
         string label;
         if( priority > 0 )
         {
             label = priority.ToString();
         }
         else
         {
             label = string.Empty;
         }
         Text.Anchor = TextAnchor.MiddleCenter;
         GUI.color = ColorOfPriority( priority );
         Rect rect2 = rect.ContractedBy(-3f);
         Widgets.Label( rect2, label );
         GUI.color = Color.white;
         Text.Anchor = TextAnchor.UpperLeft;
         if( Event.current.type == EventType.MouseDown && Mouse.IsOver( rect ) )
         {
             if( Event.current.button == 0 )
             {
                 int num = p.workSettings.GetPriority(wType) - 1;
                 if( num < 0 )
                 {
                     num = 4;
                 }
                 p.workSettings.SetPriority( wType, num );
                 SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
             }
             if( Event.current.button == 1 )
             {
                 int num2 = p.workSettings.GetPriority(wType) + 1;
                 if( num2 > 4 )
                 {
                     num2 = 0;
                 }
                 p.workSettings.SetPriority( wType, num2 );
                 SoundDefOf.AmountDecrement.PlayOneShotOnCamera();
             }
             Event.current.Use();
         }
     }
     else
     {
         int priority2 = p.workSettings.GetPriority(wType);
         if( priority2 > 0 )
         {
             GUI.DrawTexture( rect, WorkBoxCheckTex );
         }
         if( Mouse.IsOver( rect ) )
         {
             // catch clicks
             // for some reason down & up get called 4 times, make sure 
             if( Input.GetMouseButtonDown( 0 ) && _mouseDownOn.First == null )
             {
                 _mouseDownOn = new Pair<Pawn, WorkTypeDef>( p, wType );
                 _priority = p.workSettings.GetPriority( wType );
                 _clickLenth = 0;
             }
             if( Input.GetMouseButtonUp( 0 ) )
             {
                 if( p == _mouseDownOn.First && wType == _mouseDownOn.Second )
                 {
                     if( _priority < 1 )
                     {
                         p.workSettings.SetPriority( wType, 3 );
                         SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                     }
                     else
                     {
                         p.workSettings.SetPriority( wType, 0 );
                         SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                     }
                 }
                 // for some reason mouseDown & mouseUp get registered 4 times
                 // set the tracker to null to avoid further down calls and immediate resets
                 _mouseDownOn = new Pair<Pawn, WorkTypeDef>(null, null);
                 _priority = -1;
                 _clickLenth = 0;
             }
             // catch drags
             if( Input.GetMouseButton( 0 ) )
             {
                 // if this is the cell that a click originated in, delay dragging action until threshold is reached.
                 if( p == _mouseDownOn.First && wType == _mouseDownOn.Second )
                 {
                     if (_clickLenth++ < _clickThreshold)
                     {
                         return;
                     }
                 }
                 
                 // Log.Message(p.workSettings.GetPriority(wType).ToString());
                 // Priority of 'active' is 1 when manual is disabled, even if set to 3
                 if( p.workSettings.GetPriority( wType ) < 1 )
                 {
                     p.workSettings.SetPriority( wType, 3 );
                     SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                 }
             }
             else if( Input.GetMouseButton( 1 ) )
             {
                 if( p.workSettings.GetPriority( wType ) > 0 )
                 {
                     p.workSettings.SetPriority( wType, 0 );
                     SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
                 }
             }
         }
     }
 }
Пример #47
0
 private void Top( WorkTypeDef workType, WorkGiverDef workGiver )
 {
     // set to top, i.e. count + 1
     workGiver.priorityInType = workType.workGiversByPriority.Count + 1;
     
     // rebuild the list to ensure everything stays normalized and is displayed correctly.
     RebuildWorkGiverDefsList( workType );
     
 }
        public bool DrawEntry( ref Vector2 cur, Rect view, bool selected, WorkTypeDef worktype, WorkGiverDef workgiver = null )
        {
            // set some convenience variables
            float width = view.width - cur.x - _margin;
            float height = _entryHeight;
            string label;
            string tooltip = string.Empty;

            // indent with the margin
            cur.x += _margin;

            // set label / tooltip
            if ( workgiver == null )
            {
                label = worktype.labelShort;
            }
            else
            {
                label = Settings.WorkgiverLabels[workgiver];
                tooltip = Settings.WorkgiverDescriptions[workgiver];
            }

            // decrease text size if label grows too big (probably will never happen).
            if ( Text.CalcHeight( label, width ) > _entryHeight )
            {
                Text.Font = GameFont.Tiny;
                float height2 = Text.CalcHeight( label, width );
                height = Mathf.Max( height, height2 );
            }

            // draw the label
            Text.Anchor = TextAnchor.MiddleLeft;
            Rect labelRect = new Rect( cur.x, cur.y, width, height );
            Widgets.Label( labelRect, label );
            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font = GameFont.Small;

            // set buttonRect for highlighting
            Rect buttonRect = new Rect( view.xMin, cur.y, view.width, height );

            Verse.Widgets.DrawHighlightIfMouseover( buttonRect );

            // highlight if selected
            if ( selected )
            {
                Verse.Widgets.DrawHighlightSelected( buttonRect );
            }

            // set a tooltip, since workgivers do not necessarily have unique labels
            if ( tooltip != string.Empty )
            {
                TooltipHandler.TipRegion( buttonRect, tooltip );
            }

            // draw a line at the bottom to separate entries
            cur.y += height;
            GUI.color = Color.grey;
            Verse.Widgets.DrawLineHorizontal( view.xMin, cur.y, view.width );
            GUI.color = Color.white;

            // reset cur.x
            cur.x -= _margin;

            // return click for selecting stuff.
            return Verse.Widgets.InvisibleButton( buttonRect );
        }
Пример #49
0
 private void Bottom( WorkTypeDef workType, WorkGiverDef workGiver )
 {
     // set to bottom, i.e. 0
     workGiver.priorityInType = 0;
     
     // rebuild the list to ensure everything stays normalized and is displayed correctly.
     RebuildWorkGiverDefsList( workType );
     
 }
Пример #50
0
 public bool Contains(WorkTypeDef def)
 {
     return AllWorkTypes.Contains(def);
 }
Пример #51
0
        public void DrawSortButtons(Rect rect, bool active, WorkTypeDef workType, WorkGiverDef workGiver = null)
        {
            bool top = false, bottom = false, isWorkType = false;

            // no workType, should not be possible, but catch it nonetheless
            if (workType == null)
            {
                active = false;
            }

            // is this a workGiver, or a workType?
            if (workGiver == null)
            {
                isWorkType = true;
            }
            
            // for worktypes
            if( isWorkType )
            {
                int index = WorkTypeDefs.IndexOf(workType);
                int count = WorkTypeDefs.Count;
                if( index == 0 ) top = true;
                if( index == count - 1 ) bottom = true;
            }
            else 
            // for workgivers
            {
                int index = workType.workGiversByPriority.IndexOf(workGiver);
                int count = workType.workGiversByPriority.Count;
                if( index == 0 ) top = true;
                if( index == count - 1 ) bottom = true;
            }

            GUI.BeginGroup(rect);
            Rect buttonRect = new Rect(0f, 0f, _buttonSize.x, _buttonSize.y);
            Rect topRect = buttonRect;
            Rect upRect = buttonRect;
            upRect.y = _buttonSize.y + _margin;
            Rect downRect = buttonRect;
            downRect.y = rect.height - _buttonSize.y * 2 - _margin;
            Rect bottomRect = buttonRect;
            bottomRect.y = rect.height - _buttonSize.y;
            
            if (active && !top)
            {
                if (Widgets.ImageButton(topRect, TopArrow))
                {
                    if (isWorkType)
                    {
                        Top(workType);
                    }
                    else
                    {
                        Top(workType, workGiver);
                    }
                }
                if ( Widgets.ImageButton( upRect, UpArrow ) )
                {
                    if( isWorkType )
                    {
                        Up( workType );
                    }
                    else
                    {
                        Up( workType, workGiver );
                    }
                }
            }
            else
            {
                GUI.color = Color.grey;
                //Widgets.DrawBox( topRect );
                //Widgets.DrawBox( upRect );
                GUI.DrawTexture(topRect, TopArrow);
                GUI.DrawTexture(upRect, UpArrow);
                GUI.color = Color.white;
            }

            if (active && !bottom)
            {
                if( Widgets.ImageButton( downRect, DownArrow ) )
                {
                    if( isWorkType )
                    {
                        Down( workType );
                    }
                    else
                    {
                        Down( workType, workGiver );
                    }
                }
                if ( Widgets.ImageButton( bottomRect, BottomArrow ) )
                {
                    if( isWorkType )
                    {
                        Bottom( workType );
                    }
                    else
                    {
                        Bottom( workType, workGiver );
                    }
                }
            }
            else
            {
                GUI.color = Color.grey;
                //Widgets.DrawBox( downRect );
                //Widgets.DrawBox( bottomRect );
                GUI.DrawTexture( downRect, DownArrow);
                GUI.DrawTexture( bottomRect, BottomArrow );
                GUI.color = Color.white;
            }
            GUI.EndGroup();
        }
Пример #52
0
        private void Down(WorkTypeDef workType)
        {
            // down, so decrease priority
            // we actually switch priorities with the next lowest
            WorkTypeDef next =
                DefDatabase<WorkTypeDef>.AllDefs.OrderByDescending(wtd => wtd.naturalPriority)
                    .First(wtd => wtd.naturalPriority < workType.naturalPriority);

            // bumping by one works because we normalized priorities.
            workType.naturalPriority -= 1;
            next.naturalPriority += 1;

            // rebuild the list to ensure everything stays normalized and is displayed correctly.
            RebuildWorkTypeDefsList();
        }
Пример #53
0
        public static void RebuildWorkGiverDefsList(WorkTypeDef workType)
        {
            // first reset the list, since core uses a cache
            // normalization is irrelevant for order
            workType.workGiversByPriority = workType.workGiversByPriority.OrderByDescending(wg => wg.priorityInType).ToList();

            // normalize
            int max = workType.workGiversByPriority.Count;

            for (int i = 0, j = max; i < max; i++, j--)
            {
                workType.workGiversByPriority[i].priorityInType = j;
            }

            // notify drawer to change scrollPosition
            _workGiverMoved = true;
            
            // notify all pawns to recache their internal priorities
            NotifyPrioritiesChanged();
        }
Пример #54
0
        private void Top(WorkTypeDef workType)
        {
            // set to top, i.e. count + 1
            workType.naturalPriority = WorkTypeDefs.Count + 1;

            // rebuild the list to ensure everything stays normalized and is displayed correctly.
            RebuildWorkTypeDefsList();
        }
 public void SetPriority( WorkTypeDef worktype, int priority, List<int> hours )
 {
     foreach ( int hour in hours )
         SetPriority( worktype, priority, hour );
 }
Пример #56
0
        private void Bottom(WorkTypeDef workType)
        {
            // set to top, i.e. 0
            workType.naturalPriority = 0;

            // rebuild the list to ensure everything stays normalized and is displayed correctly.
            RebuildWorkTypeDefsList();
        }
        private static void DrawWorkBoxFor( Vector2 topLeft, Pawn p, WorkTypeDef wType, bool incapableBecauseOfCapacities )
        {
            if(
                ( !p.IsSlaveOfColony() ) ||
                ( p.workSettings == null ) ||
                ( !p.workSettings.EverWork )
            )
            {
                return;
            }
            var rect = new Rect( topLeft.x, topLeft.y, 25f, 25f );
            if( incapableBecauseOfCapacities )
            {
                GUI.color = new Color( 1f, 0.3f, 0.3f );
                DrawWorkBoxBackground( rect, p, wType );
                GUI.color = Color.white;
            }
            else
            {
                DrawWorkBoxBackground( rect, p, wType );
            }
            if( Find.PlaySettings.useWorkPriorities )
            {
                var priority1 = p.workSettings.GetPriority( wType );
                var label = priority1 <= 0 ? string.Empty : priority1.ToString();

                Text.Anchor = TextAnchor.MiddleCenter;

                GUI.color = ColorOfPriority( priority1 );
                Widgets.Label( rect.ContractedBy( -3f ), label );
                GUI.color = Color.white;

                Text.Anchor = TextAnchor.UpperLeft;

                if(
                    ( Event.current.type != EventType.MouseDown ) ||
                    ( !Mouse.IsOver( rect ) )
                )
                {
                    return;
                }

                if( Event.current.button == 0 )
                {
                    int priority2 = p.workSettings.GetPriority( wType ) - 1;
                    if( priority2 < 0 )
                    {
                        priority2 = 4;
                    }
                    p.workSettings.ForcePriority( wType, priority2 );
                    SoundStarter.PlayOneShotOnCamera( SoundDefOf.AmountIncrement );
                }
                if( Event.current.button == 1 )
                {
                    int priority2 = p.workSettings.GetPriority( wType ) + 1;
                    if( priority2 > 4 )
                    {
                        priority2 = 0;
                    }
                    p.workSettings.ForcePriority( wType, priority2 );
                    SoundStarter.PlayOneShotOnCamera( SoundDefOf.AmountDecrement );
                }
                Event.current.Use();
            }
            else
            {
                if( p.workSettings.GetPriority( wType ) > 0 )
                {
                    GUI.DrawTexture( rect, (Texture) WidgetsWork.WorkBoxCheckTex );
                }
                if( !Widgets.ButtonInvisible( rect ) )
                {
                    return;
                }
                if( p.workSettings.GetPriority( wType ) > 0 )
                {
                    p.workSettings.ForcePriority( wType, 0 );
                    SoundStarter.PlayOneShotOnCamera( SoundDefOf.CheckboxTurnedOff );
                }
                else
                {
                    p.workSettings.ForcePriority( wType, 3 );
                    SoundStarter.PlayOneShotOnCamera( SoundDefOf.CheckboxTurnedOn );
                }
            }
        }
 private bool IsIncapableOfWholeWorkType( Pawn p, WorkTypeDef work )
 {
     for( int index1 = 0; index1 < work.workGiversByPriority.Count; ++index1 )
     {
         for( int index2 = 0; index2 < work.workGiversByPriority[ index1 ].requiredCapacities.Count; ++index2 )
         {
             var activity = work.workGiversByPriority[ index1 ].requiredCapacities[ index2 ];
             if( !p.health.capacities.CapableOf( activity ) )
             {
                 //Log.Message( string.Format( "Pawn {0} - false on {1}", p.NameStringShort, activity.label ) );
                 return false;
             }
         }
     }
     return true;
 }
Пример #59
0
 public Saveable_WorkTypeDef(WorkTypeDef def)
 {
     defName = def.defName;
     priority = def.naturalPriority;
     workGivers = def.workGiversByPriority.Select(wg => new Saveable_WorkGiverDef(wg)).ToList();
 }
 private static string SpecificWorkListString( WorkTypeDef def )
 {
     var stringBuilder = new StringBuilder();
     for( int index = 0; index < def.workGiversByPriority.Count; ++index )
     {
         stringBuilder.Append( def.workGiversByPriority[ index ].LabelCap );
         if( def.workGiversByPriority[ index ].emergency )
         {
             stringBuilder.Append( " (" + Data.Strings.EmergencyWorkMarker.Translate() + ")" );
         }
         if( index < def.workGiversByPriority.Count - 1 )
         {
             stringBuilder.AppendLine();
         }
     }
     return stringBuilder.ToString();
 }