コード例 #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;
                ThingWithComps door  = (ThingWithComps)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);
        }
コード例 #2
0
ファイル: LockGizmo.cs プロジェクト: StoneNimRod/Locks
 private void SetOwnersFloatMenu(Building_Door door)
 {
     if (door != parent)
     {
         LockUtility.GetData(door).WantedState.owners.Clear();
         LockUtility.GetData(door).WantedState.owners.AddRange(LockUtility.GetData(parent).WantedState.owners);
     }
     LockUtility.UpdateLockDesignation(door);
 }
コード例 #3
0
 public void UpdateOwners()
 {
     foreach (Building_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door && 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);
 }
コード例 #4
0
ファイル: LockGizmo.cs プロジェクト: JonnyNova/Locks
        public LockGizmo(Building_Door 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;
        }
コード例 #5
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_Door door = (Building_Door)t;

            if (!LockUtility.GetData(door).CanChangeLocks(pawn))
            {
                JobFailReason.Is("Locks_FailOnWrongUser".Translate(pawn));
                return(null);
            }
            return(new Job(LockUtility.JobDef, t));
        }
コード例 #6
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_Door door = (Building_Door)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));
        }
コード例 #7
0
ファイル: LockGizmo.cs プロジェクト: JonnyNova/Locks
 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);
     }
 }
コード例 #8
0
ファイル: CompLock.cs プロジェクト: StoneNimRod/Locks
        public override string CompInspectStringExtra()
        {
            string text = "Locks_StatePrefix".Translate() + " ";

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

            return(text);
        }
コード例 #9
0
ファイル: LockGizmo.cs プロジェクト: JonnyNova/Locks
        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));
            }
        }
コード例 #10
0
ファイル: LockGizmo.cs プロジェクト: StoneNimRod/Locks
        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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                {
                    InvertLockFloatMenu(door, value);
                }
            })
                         ));
            if (LockUtility.GetData(parent).WantedState.IsVisible(nameof(LockState.mode)))
            {
                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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        InvertVisitorFloatMenu(door, value);
                    }
                })
                             ));
            }
            if (LockUtility.GetData(parent).WantedState.IsVisible(nameof(LockState.petDoor)))
            {
                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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        InvertPetDoorFloatMenu(door, value);
                    }
                })
                             ));
            }
            if (LockUtility.GetData(parent).WantedState.IsVisible(nameof(LockState.owners)))
            {
                list.Add(new FloatMenuOption(
                             "Locks_SetOwners".Translate(),
                             new Action(() =>
                {
                    Find.WindowStack.Add(new Dialog_AssignBuildingOwner(LockUtility.GetData(parent).CompAssignableToPawn));
                    foreach (Building_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        SetOwnersFloatMenu(door);
                    }
                })
                             ));
            }
            if (LockUtility.GetData(parent).WantedState.Private)
            {
                list.Add(new FloatMenuOption(
                             "Locks_ClearOwners".Translate(),
                             new Action(() =>
                {
                    foreach (Building_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        ClearOwnersFloatMenu(door);
                    }
                })
                             ));
            }
            return(list);
        }
コード例 #11
0
 private void ClearOwnersFloatMenu(ThingWithComps door)
 {
     LockUtility.GetData(door).WantedState.owners.Clear();
     LockUtility.UpdateLockDesignation(door);
 }
コード例 #12
0
ファイル: LockGizmo.cs プロジェクト: StoneNimRod/Locks
 private void InvertPetDoorFloatMenu(Building_Door door, bool value)
 {
     LockUtility.GetData(door).WantedState.petDoor = value;
     LockUtility.UpdateLockDesignation(door);
 }
コード例 #13
0
ファイル: LockGizmo.cs プロジェクト: StoneNimRod/Locks
 private void InvertVisitorFloatMenu(Building_Door door, LockMode value)
 {
     LockUtility.GetData(door).WantedState.mode = value;
     LockUtility.UpdateLockDesignation(door);
 }
コード例 #14
0
ファイル: LockGizmo.cs プロジェクト: StoneNimRod/Locks
 private void InvertLockDesignation()
 {
     SoundDefOf.Click.PlayOneShotOnCamera(null);
     LockUtility.GetData(parent).WantedState.locked = !LockUtility.GetData(parent).WantedState.locked;
     LockUtility.UpdateLockDesignation(parent);
 }
コード例 #15
0
 public override void PostExposeData()
 {
     LockUtility.GetData(this.parent).ExposeData();
 }
コード例 #16
0
ファイル: LockGizmo.cs プロジェクト: JonnyNova/Locks
        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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                {
                    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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                {
                    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_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
                    {
                        LockUtility.GetData(door).WantedState.owners.Clear();
                        LockUtility.UpdateLockDesignation(door);
                    }
                })
                             ));
            }
            return(list);
        }
コード例 #17
0
ファイル: LockGizmo.cs プロジェクト: StoneNimRod/Locks
 private void ClearOwnersFloatMenu(Building_Door door)
 {
     LockUtility.GetData(door).WantedState.owners.Clear();
     LockUtility.UpdateLockDesignation(door);
 }
コード例 #18
0
 private void InvertPensDoorFloatMenu(ThingWithComps door, bool value)
 {
     LockUtility.GetData(door).WantedState.pensDoor = value;
     LockUtility.UpdateLockDesignation(door);
 }