Exemplo n.º 1
0
        //It's very weird way of substituting this as original WorkGivers..But idk
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced)
        {
            if (originalDef == null)
            {
                originalDef = def;
            }

            WorkGiverDef failDef = null;

            foreach (var wgiver in CheckList)
            {
                var res = wgiver.JobOnThing(pawn, t, forced);

                if (res != null)
                {
                    def = wgiver.def;
                    return(res);
                }
                else
                {
                    failDef = wgiver.def;
                }
            }

            def = failDef;

            return(null);
        }
Exemplo n.º 2
0
 public void Clear()
 {
     def                            = null;
     targetA                        = LocalTargetInfo.Invalid;
     targetB                        = LocalTargetInfo.Invalid;
     targetC                        = LocalTargetInfo.Invalid;
     targetQueueA                   = null;
     targetQueueB                   = null;
     count                          = -1;
     countQueue                     = null;
     loadID                         = -1;
     startTick                      = -1;
     expiryInterval                 = -1;
     checkOverrideOnExpire          = false;
     playerForced                   = false;
     placedThings                   = null;
     maxNumMeleeAttacks             = int.MaxValue;
     maxNumStaticAttacks            = int.MaxValue;
     locomotionUrgency              = LocomotionUrgency.Jog;
     haulMode                       = HaulMode.Undefined;
     bill                           = null;
     commTarget                     = null;
     plantDefToSow                  = null;
     verbToUse                      = null;
     haulOpportunisticDuplicates    = false;
     exitMapOnArrival               = false;
     failIfCantJoinOrCreateCaravan  = false;
     killIncappedTarget             = false;
     ignoreForbidden                = false;
     ignoreDesignations             = false;
     canBash                        = false;
     canUseRangedWeapon             = true;
     haulDroppedApparel             = false;
     restUntilHealed                = false;
     ignoreJoyTimeAssignment        = false;
     doUntilGatheringEnded          = false;
     overeat                        = false;
     attackDoorIfTargetLost         = false;
     takeExtraIngestibles           = 0;
     expireRequiresEnemiesNearby    = false;
     lord                           = null;
     collideWithPawns               = false;
     forceSleep                     = false;
     interaction                    = null;
     endIfCantShootTargetFromCurPos = false;
     endIfCantShootInMelee          = false;
     checkEncumbrance               = false;
     followRadius                   = 0f;
     endAfterTendedOnce             = false;
     quest                          = null;
     mote                           = null;
     jobGiverThinkTree              = null;
     jobGiver                       = null;
     workGiverDef                   = null;
     if (cachedDriver != null)
     {
         cachedDriver.job = null;
     }
     cachedDriver = null;
 }
Exemplo n.º 3
0
 private static WorkGiverDef CreateLocalWorkGiverDef(WorkGiverDef def, int priorityAdj)
 {
     return(new WorkGiverDef
     {
         giverClass = typeof(WorkGiver_LocalZoneWrapper),
         defName = "LGF_Local" + def.defName,
         label = "LGF_Local".Translate().CapitalizeFirst() + " " + def.label,
         workType = def.workType,
         priorityInType = def.priorityInType + priorityAdj,
         verb = def.verb,
         gerund = def.gerund,
         emergency = def.emergency,
         requiredCapacities = new List <PawnCapacityDef>(def.requiredCapacities),
         directOrderable = def.directOrderable,
         scanCells = def.scanCells,
         scanThings = def.scanThings,
         tagToGive = def.tagToGive,
         modExtensions = new List <DefModExtension>(1)
         {
             new DefModExt_LocalZoneWrapping
             {
                 defToWrap = def
             }
         }
     });
 }
Exemplo n.º 4
0
 public static bool CheckWorkGiver(ThingDef pawn, WorkGiverDef workGiver)
 {
     if (pawn is RaceAddonThingDef thingDef)
     {
         var set = thingDef.raceAddonSettings.workGiverRestrictionSetting;
         if (WorkGiverRestrictions.Contains(workGiver))
         {
             return(set.raceSpecifics.Contains(workGiver));
         }
         else
         {
             if (set.allAllow)
             {
                 return(!set.allAllow_Exceptions.Contains(workGiver));
             }
             else
             {
                 return(set.allAllow_Exceptions.Contains(workGiver));
             }
         }
     }
     else
     {
         return(!WorkGiverRestrictions.Contains(workGiver));
     }
 }
Exemplo n.º 5
0
        public static void IncrementPriority(this WorkGiverDef workgiver, List <Pawn> pawns, int hour,
                                             List <int> hours, 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.Get().playSounds&& playSound && pawns.Any(p => p.GetPriority(workgiver, 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(workgiver, hour) > 0).DistinctTrackers())
            {
                IncrementPriority(workgiver, pawn, hour, hours, false);
            }
        }
 static void Prefix(ref WorkGiverDef workgiver)
 {
     if (workgiver is MicroWorkGiverDef)
     {
         workgiver = (workgiver as MicroWorkGiverDef).workGiverDef;
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public bool TimeScheduled(WorkGiverDef workgiver)
 {
     if (!_timeScheduledWorkGiver.ContainsKey(workgiver))
     {
         Recache(workgiver);
     }
     return(_timeScheduledWorkGiver[workgiver]);
 }
Exemplo n.º 10
0
 private static bool WorkGiversRelated(WorkGiverDef current, WorkGiverDef next)
 {
     if (next == WorkGiverDefOf.Repair)
     {
         return(current == WorkGiverDefOf.Repair);
     }
     return(true);
 }
Exemplo n.º 11
0
 public string TimeScheduledTip(WorkGiverDef workgiver)
 {
     if (!_timeScheduledWorkGiverTip.ContainsKey(workgiver))
     {
         Recache(workgiver);
     }
     return(_timeScheduledWorkGiverTip[workgiver]);
 }
Exemplo n.º 12
0
 public SavedJob(Job job)
 {
     def                            = job.def;
     targetA                        = job.targetA;
     targetB                        = job.targetB;
     targetC                        = job.targetC;
     targetQueueA                   = job.targetQueueA;
     targetQueueB                   = job.targetQueueB;
     count                          = job.count;
     countQueue                     = job.countQueue;
     startTick                      = job.startTick;
     expiryInterval                 = job.expiryInterval;
     checkOverrideOnExpire          = job.checkOverrideOnExpire;
     playerForced                   = job.playerForced;
     placedThings                   = job.placedThings;
     maxNumMeleeAttacks             = job.maxNumMeleeAttacks;
     maxNumStaticAttacks            = job.maxNumStaticAttacks;
     locomotionUrgency              = job.locomotionUrgency;
     haulMode                       = job.haulMode;
     bill                           = job.bill;
     commTarget                     = job.commTarget;
     plantDefToSow                  = job.plantDefToSow;
     verbToUse                      = job.verbToUse;
     haulOpportunisticDuplicates    = job.haulOpportunisticDuplicates;
     exitMapOnArrival               = job.exitMapOnArrival;
     failIfCantJoinOrCreateCaravan  = job.failIfCantJoinOrCreateCaravan;
     killIncappedTarget             = job.killIncappedTarget;
     ignoreForbidden                = job.ignoreForbidden;
     ignoreDesignations             = job.ignoreDesignations;
     canBash                        = job.canBash;
     canUseRangedWeapon             = job.canUseRangedWeapon;
     haulDroppedApparel             = job.haulDroppedApparel;
     restUntilHealed                = job.restUntilHealed;
     ignoreJoyTimeAssignment        = job.ignoreJoyTimeAssignment;
     doUntilGatheringEnded          = job.doUntilGatheringEnded;
     overeat                        = job.overeat;
     attackDoorIfTargetLost         = job.attackDoorIfTargetLost;
     takeExtraIngestibles           = job.takeExtraIngestibles;
     expireRequiresEnemiesNearby    = job.expireRequiresEnemiesNearby;
     lord                           = job.lord;
     collideWithPawns               = job.collideWithPawns;
     forceSleep                     = job.forceSleep;
     interaction                    = job.interaction;
     endIfCantShootTargetFromCurPos = job.endIfCantShootTargetFromCurPos;
     endIfCantShootInMelee          = job.endIfCantShootInMelee;
     checkEncumbrance               = job.checkEncumbrance;
     followRadius                   = job.followRadius;
     endAfterTendedOnce             = job.endAfterTendedOnce;
     quest                          = job.quest;
     mote                           = job.mote;
     reactingToMeleeThreat          = job.reactingToMeleeThreat;
     wasOnMeditationTimeAssignment  = job.wasOnMeditationTimeAssignment;
     psyfocusTargetLast             = job.psyfocusTargetLast;
     //jobGiverThinkTree = job.jobGiverThinkTree;
     //jobGiver = job.jobGiver;
     workGiverDef = job.workGiverDef;
     ability      = job.ability;
 }
Exemplo n.º 13
0
        public void Recache(WorkGiverDef workgiver)
        {
            // recache workgiver stuff
            var priorities = pawn.GetPriorities(workgiver);

            _everScheduledWorkGiver[workgiver]    = priorities.Any(p => p > 0);
            _timeScheduledWorkGiver[workgiver]    = priorities.Distinct().Count() > 1;
            _timeScheduledWorkGiverTip[workgiver] = DrawUtilities.TimeScheduledTip(pawn, priorities, workgiver.label);
        }
Exemplo n.º 14
0
        public static int GetPriority(this Pawn pawn, WorkGiverDef workgiver, int hour)
        {
            if (hour < 0)
            {
                hour = GenLocalDate.HourOfDay(pawn);
            }

            return(PriorityManager.Get[pawn].GetPriority(workgiver, hour));
        }
Exemplo n.º 15
0
        public static void SetPriority(this Pawn pawn, WorkGiverDef workgiver, int priority, int hour, bool recache = true)
        {
            if (hour < 0)
            {
                hour = GenLocalDate.HourOfDay(pawn);
            }

            PriorityManager.Get[pawn].SetPriority(workgiver, priority, hour, recache);
        }
Exemplo n.º 16
0
        public static void SetPriority(this Pawn pawn, WorkGiverDef workgiver, int priority, List <int> hours)
        {
            foreach (int hour in (hours ?? WholeDay))
            {
                SetPriority(pawn, workgiver, priority, hour, false);
            }

            PriorityManager.Get[pawn].InvalidateCache(workgiver);
        }
Exemplo n.º 17
0
 public static bool AllowedToDo(this Pawn pawn, WorkGiverDef workgiver)
 {
     if (pawn?.story == null)
     {
         return(true);
     }
     return(!pawn.story.WorkTypeIsDisabled(workgiver.workType) &&
            (pawn.story.CombinedDisabledWorkTags & workgiver.workTags) == WorkTags.None &&
            (pawn.story.CombinedDisabledWorkTags & workgiver.workType.workTags) == WorkTags.None);
 }
Exemplo n.º 18
0
 public WorkPriority(PriorityTracker parent, WorkGiverDef workgiver) : this( parent )
 {
     this.workgiver  = workgiver;
     this.priorities = new int[GenDate.HoursPerDay];
     var priority = parent.Pawn?.GetVanillaPriority(workgiver.workType) ?? 0;
     for (int hour = 0; hour < GenDate.HoursPerDay; hour++)
     {
         priorities[hour] = priority;
     }
 }
Exemplo n.º 19
0
        static Utilities()
        {
            Text.Font          = GameFont.Tiny;
            TinyTextLineHeight = Text.LineHeight;
            Text.Font          = GameFont.Small;    //Reset

            //Modify vanilla translations for better tooltip building
            DingoUtils.CachedStrings["ClickToSortByThisColumn"] = "\n\n" + "ClickToSortByThisColumn".Translate();
            DingoUtils.CachedStrings["RelevantSkills"]          = "\n\n" + "RelevantSkills".Translate();
            DingoUtils.CachedStrings["ClickToJumpTo"]           = "ClickToJumpTo".Translate() + "\n\n";

            DraggableOutlineTexture = DingoUtils.GetHQTexture("DraggableOutline");
            WorkButtonTexture       = DingoUtils.GetHQTexture("Cog");
            SortingDescendingIcon   = DingoUtils.GetHQTexture("SortingDescending");
            SortingAscendingIcon    = DingoUtils.GetHQTexture("Sorting");
            PassionMinorIcon        = DingoUtils.GetHQTexture("PassionMinor");
            PassionMajorIcon        = DingoUtils.GetHQTexture("PassionMajor");
            IncapableWorkerX        = DingoUtils.GetHQTexture("IncapableWorkerX");

            foreach (WorkTypeDef def in WorkTypeDefsUtility.WorkTypeDefsInPriorityOrder)
            {
                HashSet <PawnCapacityDef> allRequiredCapacities = new HashSet <PawnCapacityDef>();

                for (int i = 0; i < def.workGiversByPriority.Count; i++)
                {
                    WorkGiverDef workGiver = def.workGiversByPriority[i];

                    for (int j = 0; j < workGiver.requiredCapacities.Count; j++)
                    {
                        allRequiredCapacities.Add(workGiver.requiredCapacities[j]);
                    }
                }

                Texture2D enabledTex   = DingoUtils.GetHQTexture(def.defName, "Work");
                Texture2D disabledTex  = DingoUtils.GetHQTexture(def.defName, "Work_Disabled");
                Texture2D greyscaleTex = DingoUtils.GetHQTexture(def.defName, "Work_Greyscale");

                WorkDefAttributes[def] = new WorkTypeInfo(enabledTex, disabledTex, greyscaleTex, allRequiredCapacities);

                //Cache "relevant skills:" string
                if (def.relevantSkills.Count > 0)
                {
                    string relevantSkills = "";

                    for (int k = 0; k < def.relevantSkills.Count; k++)
                    {
                        relevantSkills += def.relevantSkills[k].skillLabel + ", ";
                    }

                    DingoUtils.CachedStrings[def] = relevantSkills.Substring(0, relevantSkills.Length - 2);
                }
            }

            Controller.GetPrimaries = new PrimarySurface();
        }
Exemplo n.º 20
0
        public static void ChangePriority(this Pawn pawn, WorkGiverDef workgiver, int diff, int hour, bool recache = true)
        {
            if (hour < 0)
            {
                hour = GenLocalDate.HourOfDay(pawn);
            }

            int priority = pawn.GetPriority(workgiver, hour) + diff;

            SetPriority(pawn, workgiver, priority, hour, recache);
        }
Exemplo n.º 21
0
        public void InvalidateCache(WorkGiverDef workgiver, bool bubble = true)
        {
            _everScheduledWorkGiver.Remove(workgiver);
            _timeScheduledWorkGiver.Remove(workgiver);
            _timeScheduledWorkGiverTip.Remove(workgiver);

            if (bubble)
            {
                InvalidateCache(workgiver.workType, false);
            }
        }
Exemplo n.º 22
0
        public static void SetPriority(this Pawn pawn, WorkGiverDef workgiver, int priority, int hour, bool recache = true)
        {
            if (hour < 0)
            {
                hour = GenLocalDate.HourOfDay(pawn);
            }

            Logger.Trace($"Setting {pawn.LabelShort}'s {workgiver.defName} priority for {hour} to {priority}");

            PriorityManager.Get[pawn].SetPriority(workgiver, priority, hour, recache);
        }
Exemplo n.º 23
0
        public WorkPriorityTracker(Pawn pawn, WorkGiverDef workgiver)
        {
            this.pawn       = pawn;
            this.workgiver  = workgiver;
            this.priorities = new int[GenDate.HoursPerDay];
            var priority = pawn.GetVanillaPriority(workgiver.workType);

            for (int hour = 0; hour < GenDate.HoursPerDay; hour++)
            {
                priorities[hour] = priority;
            }
        }
Exemplo n.º 24
0
 public WorkPriorityTracker this[WorkGiverDef workgiver]
 {
     get
     {
         if (!priorities.ContainsKey(workgiver))
         {
             Logger.Debug($"requested {workgiver.defName} priorities for {pawn.LabelShort}, which did not yet exist.");
             priorities.Add(workgiver, new WorkPriorityTracker(pawn, workgiver));
         }
         return(priorities[workgiver]);
     }
     set => priorities[workgiver] = value;
Exemplo n.º 25
0
 public virtual WorkPriority this[WorkGiverDef workgiver]
 {
     get
     {
         if (!priorities.ContainsKey(workgiver))
         {
             Logger.Debug($"requested {workgiver.defName} priorities for {Pawn?.LabelShort ?? "<no pawn>"}, which did not yet exist.");
             priorities.Add(workgiver, new WorkPriority(this, workgiver));
         }
         return(priorities[workgiver]);
     }
     set => priorities[workgiver] = value;
Exemplo n.º 26
0
        public WorkGiver_Warden()
            : base()
        {
            CriticalJobDefs = new List<JobDef>()
            {
                DefDatabase<JobDef>.GetNamedSilentFail("EscortPrisonerToBed"),
                DefDatabase<JobDef>.GetNamedSilentFail("TakeWoundedPrisonerToBed")
            };

            HaulWaterWorkGiverDef = DefDatabase<WorkGiverDef>.GetNamed("Dehydration_HaulWater");
            WaterPatientWorkGiverDef = DefDatabase<WorkGiverDef>.GetNamed("Dehydration_DoctorWater");
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        protected virtual void DrawWorkGiverBoxFor(Rect box, Pawn pawn, WorkGiverDef workgiver, bool incapable)
        {
            List <SkillDef> skillsNeeded = workgiver.workType.relevantSkills;
            float           averageSkill = pawn.skills.AverageOfRelevantSkillsFor(workgiver.workType);

            Passion passion = Passion.None;

            if (skillsNeeded.Count > 0)
            {
                passion = pawn.skills.GetSkill(workgiver.workType.relevantSkills[0]).passion;
            }

            Color red   = new Color(1f, 0f, 0f);
            Color green = new Color(0f, 1f, 0f);
            Color blue  = new Color(0f, 0f, 1f);
            Color black = new Color(0f, 0f, 0f);

            Color passionColor;

            if (passion == Passion.None)
            {
                passionColor = red;
            }
            else if (passion == Passion.Minor)
            {
                passionColor = blue;
            }
            else
            {
                passionColor = green;
            }

            GUI.color = Color.Lerp(black + (passionColor * 0.2f), passionColor, averageSkill / 20);
            // draw background
            //GUI.color = incapable ? new Color( 1f, .3f, .3f ) : Color.white;

            DrawUtilities.DrawWorkBoxBackground(box, pawn, workgiver.workType);
            GUI.color = Color.white;

            // draw extras
            var tracker = PriorityManager.Get[pawn];

            if (tracker.TimeScheduled(workgiver))
            {
                DrawUtilities.DrawTimeScheduled(box);
            }

            // draw priorities / checks
            DrawUtilities.DrawPriority(box, pawn.GetPriority(workgiver, VisibleHour), true);
        }
        static bool Postfix(bool __result, Pawn pawn, Thing t, bool forced)
        {
            if (pawn.Faction != Faction.OfPlayer && !pawn.IsPrisonerOfColony)
            {
                return(false);
            }

            WorkGiverDef workGiverDef = DefDatabase <WorkGiverDef> .GetNamed("CleanFilth");

            return(t is Filth filth && filth.Map.areaManager.Home[filth.Position] &&
                   pawn.CanReserve(t, 1, -1, null, forced) &&
                   filth.TicksSinceThickened >= MinTicksSinceThickened &&
                   PrisonLaborUtility.canWorkHere(filth.Position, pawn, workGiverDef.workType));
        }
Exemplo n.º 30
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);
        }
Exemplo n.º 31
0
        public void Recache(WorkGiverDef workgiver, bool bubble = true)
        {
            // recache workgiver stuff
            var priorities = pawn.GetPriorities(workgiver);

            _everScheduledWorkGiver[workgiver]    = priorities.Any(p => p > 0);
            _timeScheduledWorkGiver[workgiver]    = priorities.Distinct().Count() > 1;
            _timeScheduledWorkGiverTip[workgiver] = WorkUtilities.TimeScheduledTip(pawn, priorities, workgiver.label);

            // also recache worktype
            if (bubble)
            {
                Recache(workgiver.workType, false);
            }
        }
Exemplo n.º 32
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 = 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 );
        }
 public WorkGiver_ShootingRange(WorkGiverDef giverDef)
     : base(giverDef)
 {
 }
Exemplo n.º 34
0
        private void HandleWorkColumnInteractions( WorkGiverDef workgiver, Rect canvas )
        {
            if ( Mouse.IsOver( canvas ) )
            {
                // sorting
                if ( Event.current.type == EventType.MouseUp && Event.current.button == 0 && !Event.current.shift )
                    SortBy( SortMode.WorkType, workgiver.workType );

                // whole column in-/de-crement
                if ( Event.current.shift )
                {
                    if ( ( Event.current.type == EventType.MouseUp && Event.current.button == 0 ) || ( NumericMode && Event.current.type == EventType.ScrollWheel && Event.current.delta.y < 0f ) )
                    {
                        workgiver.IncrementPriorities( pawns, !NumericMode, SchedulerMode, FocusedHours );
                        Event.current.Use();
                    }
                    if ( ( Event.current.type == EventType.MouseUp && Event.current.button == 1 ) || ( NumericMode && Event.current.type == EventType.ScrollWheel && Event.current.delta.y > 0f ) )
                    {
                        workgiver.DecrementPriorities( pawns, !NumericMode, SchedulerMode, FocusedHours );
                        Event.current.Use();
                    }
                }
            }
        }
Exemplo n.º 35
0
        private void DrawWorkHeader( WorkGiverDef workgiver, Vector2 offset, float width, float height, int i )
        {
            // create rect
            Rect rect = new Rect( offset.x + width * i, offset.y, width, height );

            // handle interactions
            HandleWorkColumnInteractions( workgiver, rect );
            Widgets.DrawBackground( rect, Settings.WorktypeColors[workgiver.workType], Settings.WorkgiverColorOpacity );
            Verse.Widgets.DrawHighlightIfMouseover( rect );
            TooltipHandler.TipRegion( rect, "FluffyTabs.WorkgiverHeaderTip".Translate(
                Settings.WorkgiverLabels[workgiver],
                LabelUp,
                LabelDown,
                workgiver.workType.gerundLabel.ToLower(),
                Settings.WorkgiverDescriptions[workgiver] ) );

            // draw rotated label
            var oldWW = Text.WordWrap;
            Text.WordWrap = false;
            Widgets.LabelVertical(
                rect,
                // add space to give a tad of margin
                " " + Settings.WorkgiverLabels[workgiver],
                Color.white,
                GameFont.Small,
                TextAnchor.MiddleLeft );
            Text.WordWrap = oldWW;
        }
Exemplo n.º 36
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();
        }
Exemplo n.º 37
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);

        }
Exemplo n.º 38
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 );
     
 }
Exemplo n.º 39
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 );
            }
        }
Exemplo n.º 40
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 );
     
 }
Exemplo n.º 41
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 );
            
        }
Exemplo n.º 42
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);
            
        }
 public Saveable_WorkGiverDef( WorkGiverDef def )
 {
     defName = def.defName;
     priority = def.priorityInType;
 }
 public WorkGiver_AgaveTank(WorkGiverDef giverDef)
     : base(giverDef)
 {
 }