Example #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(delegate
            {
                Designation designation = Map.designationManager.DesignationOn(TargetThingA, LockUtility.DesDef);
                return(designation == null);
            });
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(15).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                Building_DoorExpanded door = (Building_DoorExpanded)actor.CurJob.targetA.Thing;
                this.FailOn(() => !LockUtility.GetData(door).CanChangeLocks(actor));
                LockUtility.GetData(door).CurrentState.CopyFrom(LockUtility.GetData(door).WantedState);
                SoundDefOf.FlickSwitch.PlayOneShot(new TargetInfo(door.Position, door.Map, false));
                door.Map.reachability.ClearCache();
                //actor.records.Increment(RecordDefOf.SwitchesFlicked);
                Designation designation = Map.designationManager.DesignationOn(door, LockUtility.DesDef);
                if (designation != null)
                {
                    designation.Delete();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil);
        }
Example #2
0
 public void UpdateOwners()
 {
     foreach (Building_DoorExpanded door in Find.Selector.SelectedObjects.Where(o => o is Building_DoorExpanded && o != parent))
     {
         LockUtility.GetData(door).WantedState.owners.Clear();
         LockUtility.GetData(door).WantedState.owners.AddRange(LockUtility.GetData(parent).WantedState.owners);
         LockUtility.UpdateLockDesignation(door);
     }
     LockUtility.UpdateLockDesignation(parent);
 }
Example #3
0
        public LockGizmo(Building_DoorExpanded door)
        {
            parent       = door;
            defaultLabel = "Locks_Label".Translate();
            defaultDesc  = "Locks_Description".Translate();
            lockTexture  = ContentFinder <Texture2D> .Get("lock", false);

            unlockTexture = ContentFinder <Texture2D> .Get("unlock", false);

            isActive = () => LockUtility.GetData(parent).WantedState.locked;
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_DoorExpanded door = (Building_DoorExpanded)t;

            if (!LockUtility.GetData(door).CanChangeLocks(pawn))
            {
                JobFailReason.Is("Locks_FailOnWrongUser".Translate(pawn));
                return(null);
            }
            return(new Job(LockUtility.JobDef, t));
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_DoorExpanded door = (Building_DoorExpanded)t;

            if (!LockUtility.GetData(door).CanChangeLocks(pawn))
            {
                JobFailReason.Is("Locks_FailOnWrongUser".Translate(pawn));
                return(false);
            }
            return(pawn.Map.designationManager.DesignationOn(t, LockUtility.DesDef) != null && pawn.CanReserveAndReach(t, PathEndMode.Touch, pawn.NormalMaxDanger(), 1, -1, null, forced));
        }
Example #6
0
 public override void ProcessInput(Event ev)
 {
     if (ev.button == 0)
     {
         SoundDefOf.Click.PlayOneShotOnCamera(null);
         LockUtility.GetData(parent).WantedState.locked = !LockUtility.GetData(parent).WantedState.locked;
         LockUtility.UpdateLockDesignation(parent);
     }
     else if (ev.button == 1)
     {
         SoundDefOf.Click.PlayOneShotOnCamera(null);
         var floatMenu = new FloatMenu(GetMenuOptions());
         Find.WindowStack.Add(floatMenu);
     }
 }
Example #7
0
        public override string CompInspectStringExtra()
        {
            string text = "Locks_StatePrefix".Translate() + " ";

            if (LockUtility.GetData((Building_DoorExpanded)this.parent).CurrentState.locked)
            {
                text += "Locks_StateLocked".Translate();
            }
            else
            {
                text += "Locks_StateUnlocked".Translate();
            }
            if (LockUtility.GetData((Building_DoorExpanded)this.parent).NeedChange)
            {
                text += $" ({"Locks_StateChanging".Translate()})";
            }

            return(text);
        }
Example #8
0
        public List <FloatMenuOption> GetMenuOptions()
        {
            var list = new List <FloatMenuOption>();

            list.Add(new FloatMenuOption(
                         LockUtility.GetData(parent).WantedState.locked ?
                         "Locks_UnlockToggle".Translate() :
                         "Locks_LockToggle".Translate(),
                         new Action(() =>
            {
                bool value = !LockUtility.GetData(parent).WantedState.locked;
                foreach (Building_DoorExpanded door in Find.Selector.SelectedObjects.Where(o => o is Building_DoorExpanded))
                {
                    LockUtility.GetData(door).WantedState.locked = value;
                    LockUtility.UpdateLockDesignation(door);
                }
            })
                         ));
            if (!LockUtility.GetData(parent).WantedState.Private)
            {
                list.Add(new FloatMenuOption(
                             LockUtility.GetData(parent).WantedState.mode == LockMode.Allies ?
                             "Locks_ForbidVisitors".Translate() :
                             "Locks_AllowVisitors".Translate(),
                             new Action(() =>
                {
                    LockMode value;
                    if (LockUtility.GetData(parent).WantedState.mode == LockMode.Allies)
                    {
                        value = LockMode.Colony;
                    }
                    else
                    {
                        value = LockMode.Allies;
                    }
                    foreach (Building_DoorExpanded door in Find.Selector.SelectedObjects.Where(o => o is Building_DoorExpanded))
                    {
                        LockUtility.GetData(door).WantedState.mode = value;
                        LockUtility.UpdateLockDesignation(door);
                    }
                })
                             ));
            }
            if (LockUtility.GetData(parent).WantedState.Private)
            {
                list.Add(new FloatMenuOption(
                             LockUtility.GetData(parent).WantedState.petDoor ?
                             "Locks_RemovePetDoor".Translate() :
                             "Locks_AddPetDoor".Translate(),
                             new Action(() =>
                {
                    bool value = !LockUtility.GetData(parent).WantedState.petDoor;
                    foreach (Building_DoorExpanded door in Find.Selector.SelectedObjects.Where(o => o is Building_DoorExpanded))
                    {
                        LockUtility.GetData(door).WantedState.petDoor = value;
                        LockUtility.UpdateLockDesignation(door);
                    }
                })
                             ));
            }
            list.Add(new FloatMenuOption(
                         "CommandBedSetOwnerLabel".Translate(),
                         new Action(() =>
            {
                Find.WindowStack.Add(new Dialog_AssignBuildingOwner(LockUtility.GetData(parent)));
                foreach (Building_DoorExpanded door in Find.Selector.SelectedObjects.Where(o => o is Building_DoorExpanded))
                {
                    if (door != parent)
                    {
                        LockUtility.GetData(door).WantedState.owners.Clear();
                        LockUtility.GetData(door).WantedState.owners.AddRange(LockUtility.GetData(parent).WantedState.owners);
                    }
                    LockUtility.UpdateLockDesignation(door);
                }
            })
                         ));
            if (LockUtility.GetData(parent).WantedState.Private)
            {
                list.Add(new FloatMenuOption(
                             "Locks_ClearOwners".Translate(),
                             new Action(() =>
                {
                    foreach (Building_DoorExpanded door in Find.Selector.SelectedObjects.Where(o => o is Building_DoorExpanded))
                    {
                        LockUtility.GetData(door).WantedState.owners.Clear();
                        LockUtility.UpdateLockDesignation(door);
                    }
                })
                             ));
            }
            return(list);
        }
Example #9
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Rect rect = new Rect(topLeft.x, topLeft.y, this.GetWidth(maxWidth), 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag      = true;
                GUI.color = GenUI.MouseoverColor;
            }
            Texture2D badTex = LockUtility.GetData(parent).WantedState.locked ? lockTexture : unlockTexture;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }
            GUI.DrawTexture(rect, BGTex);
            GUI.DrawTexture(rect, badTex);
            MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            bool    flag2   = false;
            KeyCode keyCode = (this.hotKey != null) ? hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect, false))
            {
                flag2 = true;
            }
            string labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = string.Concat(new string[]
                    {
                        text,
                        "\n\n",
                        "DisabledCommand".Translate(),
                        ": ",
                        disabledReason
                    });
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, HighlightTag);
            }
            if (flag2)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(TutorTagSelect);
                return(result);
            }
            else
            {
                if (flag)
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                return(new GizmoResult(GizmoState.Clear, null));
            }
        }