public static IEnumerable <Gizmo> GetGizmosForVerb(this Verb verb, ManagedVerb man = null)
        {
            var props = man?.Props;

            Thing ownerThing = null;

            switch (verb.DirectOwner)
            {
            case ThingWithComps twc when twc.TryGetComp <Comp_VerbGiver>() is Comp_VerbGiver giver:
                ownerThing = twc;

                props = giver.PropsFor(verb);
                break;

            case Thing thing:
                ownerThing = thing;
                break;

            case Comp_VerbGiver comp:
                ownerThing = comp.parent;
                props      = comp.PropsFor(verb);
                break;

            case CompEquippable eq:
                ownerThing = eq.parent;
                break;

            case HediffComp_ExtendedVerbGiver hediffGiver:
                props = hediffGiver.PropsFor(verb);
                break;
            }

            Command gizmo;
            var     command = new Command_VerbTarget {
                verb = verb
            };

            gizmo = command;


            if (ownerThing != null)
            {
                gizmo.defaultDesc = FirstNonEmptyString(props?.description, ownerThing.def.LabelCap + ": " +
                                                        ownerThing
                                                        .def?.description?
                                                        .Truncate(500, __truncateCache)?
                                                        .CapitalizeFirst());
                gizmo.icon = verb.Icon(props, ownerThing, false);
            }
            else if (verb.DirectOwner is HediffComp_VerbGiver hediffGiver)
            {
                var hediff = hediffGiver.parent;
                gizmo.defaultDesc = FirstNonEmptyString(props?.description, hediff.def.LabelCap + ": " +
                                                        hediff.def.description
                                                        .Truncate(500, __truncateCache)
                                                        .CapitalizeFirst());
                gizmo.icon = verb.Icon(props, null, false);
            }

            gizmo.tutorTag     = "VerbTarget";
            gizmo.defaultLabel = verb.Label(props);

            if (verb.Caster.Faction != Faction.OfPlayer)
            {
                gizmo.Disable("CannotOrderNonControlled".Translate());
            }
            else if (verb.CasterIsPawn)
            {
                if (verb.verbProps.violent && verb.CasterPawn.WorkTagIsDisabled(WorkTags.Violent))
                {
                    gizmo.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort,
                                                                    verb.CasterPawn));
                }
                else if (verb.CasterPawn.drafter != null && !verb.CasterPawn.drafter.Drafted &&
                         !(props != null && props.canFireIndependently))
                {
                    gizmo.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort,
                                                           verb.CasterPawn));
                }
                else if (verb.CasterPawn.InMentalState && !(props != null && props.canFireIndependently))
                {
                    gizmo.Disable("CannotOrderNonControlled".Translate());
                }
            }

            yield return(gizmo);


            if (props != null && props.canBeToggled && man != null && verb.caster.Faction == Faction.OfPlayer ||
                verb.CasterIsPawn && verb.CasterPawn.RaceProps.Animal)
            {
                if (props != null && props.separateToggle ||
                    verb.CasterIsPawn && !verb.CasterPawn.RaceProps.Animal)
                {
                    yield return(new Command_ToggleVerbUsage(man));
                }
                else if (!Base.Features.IntegratedToggle)
                {
                    Log.ErrorOnce(
                        "[MVCF] " + (verb.EquipmentSource.LabelShortCap ?? "Hediff verb of " + verb.caster) +
                        " wants an integrated toggle but that feature is not enabled. Using seperate toggle.",
                        verb.GetHashCode());
                    yield return(new Command_ToggleVerbUsage(man));
                }
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <Gizmo> GetGizmosForVerb(this Verb verb, ManagedVerb man = null)
        {
            AdditionalVerbProps props = null;

            Thing ownerThing = null;

            switch (verb.DirectOwner)
            {
            case ThingWithComps twc when twc.TryGetComp <Comp_VerbGiver>() is Comp_VerbGiver giver:
                ownerThing = twc;

                props = giver.PropsFor(verb);
                break;

            case Thing thing:
                ownerThing = thing;
                break;

            case Comp_VerbGiver comp:
                ownerThing = comp.parent;
                props      = comp.PropsFor(verb);
                break;

            case CompEquippable eq:
                ownerThing = eq.parent;
                break;

            case HediffComp_ExtendedVerbGiver hediffGiver:
                props = hediffGiver.PropsFor(verb);
                break;
            }

            var gizmo = new Command_VerbTarget();

            if (ownerThing != null)
            {
                gizmo.defaultDesc = FirstNonEmptyString(props?.description, ownerThing.def.LabelCap + ": " + ownerThing
                                                        .def.description
                                                        .Truncate(500, __truncateCache)
                                                        .CapitalizeFirst());
                gizmo.icon = verb.Icon(null, ownerThing);
            }
            else if (verb.DirectOwner is HediffComp_VerbGiver hediffGiver)
            {
                var hediff = hediffGiver.parent;
                gizmo.defaultDesc = FirstNonEmptyString(props?.description, hediff.def.LabelCap + ": " +
                                                        hediff.def.description
                                                        .Truncate(500, __truncateCache)
                                                        .CapitalizeFirst());
                gizmo.icon = verb.Icon(null, null);
            }

            gizmo.tutorTag     = "VerbTarget";
            gizmo.verb         = verb;
            gizmo.defaultLabel = verb.Label(props);

            if (verb.caster.Faction != Faction.OfPlayer)
            {
                gizmo.Disable("CannotOrderNonControlled".Translate());
            }
            else if (verb.CasterIsPawn)
            {
                if (verb.CasterPawn.WorkTagIsDisabled(WorkTags.Violent))
                {
                    gizmo.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort,
                                                                    verb.CasterPawn));
                }
                else if (!verb.CasterPawn.drafter.Drafted)
                {
                    gizmo.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort,
                                                           verb.CasterPawn));
                }
            }

            yield return(gizmo);

            if (props != null && props.canBeToggled && man != null && verb.caster.Faction == Faction.OfPlayer &&
                props.separateToggle)
            {
                yield return(new Command_ToggleVerbUsage(man));
            }
        }