Esempio n. 1
0
        public static Command BuildCopyCommand(BuildableDef buildable, ThingDef stuff)
        {
            Designator_Build des = BuildCopyCommandUtility.FindAllowedDesignator(buildable, true);

            if (des == null)
            {
                return(null);
            }
            Command_Action command_Action = new Command_Action();

            command_Action.action = delegate
            {
                SoundDefOf.SelectDesignator.PlayOneShotOnCamera(null);
                des.SetStuffDef(stuff);
                Find.DesignatorManager.Select(des);
            };
            command_Action.defaultLabel    = "CommandBuildCopy".Translate();
            command_Action.defaultDesc     = "CommandBuildCopyDesc".Translate();
            command_Action.icon            = des.icon;
            command_Action.iconProportions = des.iconProportions;
            command_Action.iconDrawScale   = des.iconDrawScale;
            command_Action.iconTexCoords   = des.iconTexCoords;
            if (stuff != null)
            {
                command_Action.defaultIconColor = stuff.stuffProps.color;
            }
            else
            {
                command_Action.defaultIconColor = buildable.IconDrawColor;
            }
            command_Action.hotKey = KeyBindingDefOf.Misc11;
            return(command_Action);
        }
        public static IEnumerable <Command> BuildFacilityCommands(BuildableDef building)
        {
            ThingDef thingDef = building as ThingDef;

            if (thingDef == null)
            {
                yield break;
            }
            CompProperties_AffectedByFacilities affectedByFacilities = thingDef.GetCompProperties <CompProperties_AffectedByFacilities>();

            if (affectedByFacilities == null)
            {
                yield break;
            }
            for (int i = 0; i < affectedByFacilities.linkableFacilities.Count; i++)
            {
                ThingDef         facility = affectedByFacilities.linkableFacilities[i];
                Designator_Build des      = BuildCopyCommandUtility.FindAllowedDesignator(facility, true);
                if (des != null)
                {
                    yield return(des);
                }
            }
            yield break;
        }
        public static IEnumerable <Command> BuildFacilityCommands(BuildableDef building)
        {
            ThingDef thingDef = building as ThingDef;

            if (thingDef != null)
            {
                CompProperties_AffectedByFacilities affectedByFacilities = thingDef.GetCompProperties <CompProperties_AffectedByFacilities>();
                if (affectedByFacilities != null)
                {
                    int i = 0;
                    Designator_Build des;
                    while (true)
                    {
                        if (i >= affectedByFacilities.linkableFacilities.Count)
                        {
                            yield break;
                        }
                        ThingDef facility = affectedByFacilities.linkableFacilities[i];
                        des = BuildCopyCommandUtility.FindAllowedDesignator(facility);
                        if (des != null)
                        {
                            break;
                        }
                        i++;
                    }
                    yield return((Command)des);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
        }
Esempio n. 4
0
 private void PlaceAllBlueprints(ThingDef preferredStuffIfNone)
 {
     foreach (SketchEntity entity in sketch.Entities)
     {
         SketchBuildable sketchBuildable = entity as SketchBuildable;
         if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
         {
             SketchThing   sketchThing;
             SketchTerrain sketchTerrain;
             if ((sketchThing = (entity as SketchThing)) != null && sketchThing.def.MadeFromStuff && sketchThing.stuff == null && preferredStuffIfNone != null && preferredStuffIfNone.stuffProps.CanMake(sketchThing.def))
             {
                 sketchThing.stuff = preferredStuffIfNone;
                 entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint);
                 sketchThing.stuff = null;
             }
             else if ((sketchTerrain = (entity as SketchTerrain)) != null && sketchTerrain.stuffForComparingSimilar == null && preferredStuffIfNone != null)
             {
                 sketchTerrain.stuffForComparingSimilar = preferredStuffIfNone;
                 entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint);
                 sketchTerrain.stuffForComparingSimilar = null;
             }
             else
             {
                 entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint);
             }
         }
     }
 }
Esempio n. 5
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            if (!AllDone)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandCancelMonumentMarker".Translate();
                command_Action.defaultDesc  = "CommandCancelMonumentMarkerDesc".Translate();
                command_Action.icon         = CancelCommandTex;
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmCancelMonumentMarker".Translate(), delegate
                    {
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentCancelled", this.Named("SUBJECT"));
                        RemovePossiblyRelatedBlueprints();
                        this.Uninstall();
                    }, destructive: true));
                };
                yield return(command_Action);
            }
            bool flag = false;

            foreach (SketchEntity entity in sketch.Entities)
            {
                SketchBuildable sketchBuildable = entity as SketchBuildable;
                if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandPlaceBlueprints".Translate();
                command_Action2.defaultDesc  = "CommandPlaceBlueprintsDesc".Translate();
                command_Action2.icon         = PlaceBlueprintsCommandTex;
                MonumentMarker monumentMarker = default(MonumentMarker);
                ThingDef       stuffLocal     = default(ThingDef);
                command_Action2.action = delegate
                {
                    IEnumerable <ThingDef> enumerable = AllowedStuffs();
                    if (!enumerable.Any())
                    {
                        PlaceAllBlueprints(null);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else if (enumerable.Count() == 1)
                    {
                        PlaceAllBlueprints(enumerable.First());
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        List <FloatMenuOption> list = new List <FloatMenuOption>();
                        bool flag4 = false;
                        foreach (ThingDef item in enumerable)
                        {
                            if (base.Map.listerThings.ThingsOfDef(item).Count > 0)
                            {
                                flag4 = true;
                                break;
                            }
                        }
                        foreach (ThingDef item2 in enumerable)
                        {
                            monumentMarker = this;
                            if (!flag4 || base.Map.listerThings.ThingsOfDef(item2).Count != 0)
                            {
                                stuffLocal = item2;
                                list.Add(new FloatMenuOption(stuffLocal.LabelCap, delegate
                                {
                                    monumentMarker.PlaceAllBlueprints(stuffLocal);
                                }, item2));
                            }
                        }
                        Find.WindowStack.Add(new FloatMenu(list));
                    }
                };
                yield return(command_Action2);
            }
            foreach (Gizmo questRelatedGizmo in QuestUtility.GetQuestRelatedGizmos(this))
            {
                yield return(questRelatedGizmo);
            }
            if (Prefs.DevMode)
            {
                bool flag2 = false;
                foreach (SketchEntity entity2 in sketch.Entities)
                {
                    if (!entity2.IsSameSpawned(entity2.pos + base.Position, base.Map) && !entity2.IsSpawningBlocked(entity2.pos + base.Position, base.Map))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (flag2)
                {
                    Command_Action command_Action3 = new Command_Action();
                    command_Action3.defaultLabel = "Dev: Build all";
                    command_Action3.action       = delegate
                    {
                        DebugBuildAll();
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    };
                    yield return(command_Action3);
                }
            }
            tmpUniqueBuildableDefs.Clear();
            foreach (SketchEntity entity3 in sketch.Entities)
            {
                SketchBuildable sketchBuildable2 = entity3 as SketchBuildable;
                if (sketchBuildable2 != null && !entity3.IsSameSpawnedOrBlueprintOrFrame(entity3.pos + base.Position, base.Map) && tmpUniqueBuildableDefs.Add(new Pair <BuildableDef, ThingDef>(sketchBuildable2.Buildable, sketchBuildable2.Stuff)))
                {
                    SketchTerrain sketchTerrain;
                    if ((sketchTerrain = (sketchBuildable2 as SketchTerrain)) != null && sketchTerrain.treatSimilarAsSame)
                    {
                        TerrainDef terrain = sketchBuildable2.Buildable as TerrainDef;
                        if (terrain.designatorDropdown != null)
                        {
                            Designator designator = BuildCopyCommandUtility.FindAllowedDesignatorRoot(sketchBuildable2.Buildable);
                            if (designator != null)
                            {
                                yield return(designator);
                            }
                        }
                        else
                        {
                            IEnumerable <TerrainDef> allDefs = DefDatabase <TerrainDef> .AllDefs;
                            foreach (TerrainDef item3 in allDefs)
                            {
                                if (item3.BuildableByPlayer && item3.designatorDropdown == null)
                                {
                                    bool flag3 = true;
                                    for (int i = 0; i < terrain.affordances.Count; i++)
                                    {
                                        if (!item3.affordances.Contains(terrain.affordances[i]))
                                        {
                                            flag3 = false;
                                            break;
                                        }
                                    }
                                    if (flag3)
                                    {
                                        Command command = BuildCopyCommandUtility.BuildCommand(item3, null, item3.label, item3.description, allowHotKey: false);
                                        if (command != null)
                                        {
                                            yield return(command);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Command command2 = BuildCopyCommandUtility.BuildCommand(sketchBuildable2.Buildable, sketchBuildable2.Stuff, entity3.Label, sketchBuildable2.Buildable.description, allowHotKey: false);
                        if (command2 != null)
                        {
                            yield return(command2);
                        }
                    }
                }
            }
            tmpUniqueBuildableDefs.Clear();
        }
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            if (!AllDone)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandCancelMonumentMarker".Translate();
                command_Action.defaultDesc  = "CommandCancelMonumentMarkerDesc".Translate();
                command_Action.icon         = CancelCommandTex;
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmCancelMonumentMarker".Translate(), delegate
                    {
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentCancelled", this.Named("SUBJECT"));
                        RemovePossiblyRelatedBlueprints();
                        this.Uninstall();
                    }, destructive: true));
                };
                yield return(command_Action);
            }
            bool flag = false;

            foreach (SketchEntity entity in sketch.Entities)
            {
                SketchBuildable sketchBuildable = entity as SketchBuildable;
                if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandPlaceBlueprints".Translate();
                command_Action2.defaultDesc  = "CommandPlaceBlueprintsDesc".Translate();
                command_Action2.icon         = PlaceBlueprintsCommandTex;
                command_Action2.action       = delegate
                {
                    IEnumerable <ThingDef> enumerable = AllowedStuffs();
                    if (!enumerable.Any())
                    {
                        PlaceAllBlueprints(null);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else if (enumerable.Count() == 1)
                    {
                        PlaceAllBlueprints(enumerable.First());
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        ListFloatMenuOptions(enumerable, delegate(ThingDef stuff)
                        {
                            PlaceAllBlueprints(stuff);
                        });
                    }
                };
                yield return(command_Action2);
            }
            foreach (Gizmo questRelatedGizmo in QuestUtility.GetQuestRelatedGizmos(this))
            {
                yield return(questRelatedGizmo);
            }
            if (Prefs.DevMode)
            {
                bool flag2 = false;
                foreach (SketchEntity entity2 in sketch.Entities)
                {
                    if (!entity2.IsSameSpawned(entity2.pos + base.Position, base.Map) && !entity2.IsSpawningBlocked(entity2.pos + base.Position, base.Map))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (flag2)
                {
                    Command_Action command_Action3 = new Command_Action();
                    command_Action3.defaultLabel = "Dev: Build all";
                    command_Action3.action       = delegate
                    {
                        DebugBuildAll();
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    };
                    yield return(command_Action3);
                }
                if (AllDone && AnyDisallowedBuilding && !DisallowedBuildingTicksExpired)
                {
                    Command_Action command_Action4 = new Command_Action();
                    command_Action4.defaultLabel = "Dev: Disallowed building ticks +6 hours";
                    command_Action4.action       = delegate
                    {
                        ticksSinceDisallowedBuilding += 15000;
                    };
                    yield return(command_Action4);
                }
            }
            tmpUniqueBuildableDefs.Clear();
            foreach (SketchEntity entity3 in sketch.Entities)
            {
                SketchBuildable buildable = entity3 as SketchBuildable;
                if (buildable == null || entity3.IsSameSpawnedOrBlueprintOrFrame(entity3.pos + base.Position, base.Map) || !tmpUniqueBuildableDefs.Add(new Pair <BuildableDef, ThingDef>(buildable.Buildable, buildable.Stuff)))
                {
                    continue;
                }
                SketchTerrain sketchTerrain;
                if ((sketchTerrain = buildable as SketchTerrain) != null && sketchTerrain.treatSimilarAsSame)
                {
                    TerrainDef terrain = buildable.Buildable as TerrainDef;
                    if (terrain.designatorDropdown != null)
                    {
                        Designator designator = BuildCopyCommandUtility.FindAllowedDesignatorRoot(buildable.Buildable);
                        if (designator != null)
                        {
                            yield return(designator);
                        }
                    }
                    else
                    {
                        IEnumerable <TerrainDef> allDefs = DefDatabase <TerrainDef> .AllDefs;
                        foreach (TerrainDef item in allDefs)
                        {
                            if (!item.BuildableByPlayer || item.designatorDropdown != null)
                            {
                                continue;
                            }
                            bool flag3 = true;
                            for (int i = 0; i < terrain.affordances.Count; i++)
                            {
                                if (!item.affordances.Contains(terrain.affordances[i]))
                                {
                                    flag3 = false;
                                    break;
                                }
                            }
                            if (flag3)
                            {
                                Command command = BuildCopyCommandUtility.BuildCommand(item, null, item.label, item.description, allowHotKey: false);
                                if (command != null)
                                {
                                    yield return(command);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Command command2 = BuildCopyCommandUtility.BuildCommand(buildable.Buildable, buildable.Stuff, entity3.LabelCap, buildable.Buildable.description, allowHotKey: false);
                    if (command2 != null)
                    {
                        yield return(command2);
                    }
                }
                Command_Action placeBlueprintsCommand = GetPlaceBlueprintsCommand(buildable);
                if (placeBlueprintsCommand != null)
                {
                    yield return(placeBlueprintsCommand);
                }
            }
            tmpUniqueBuildableDefs.Clear();
        }