public static Designator FindAllowedDesignator <T>() where T : Designator
        {
            List <DesignationCategoryDef> allDefsListForReading = DefDatabase <DesignationCategoryDef> .AllDefsListForReading;
            GameRules rules = Current.Game.Rules;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                List <Designator> allResolvedDesignators = allDefsListForReading[i].AllResolvedDesignators;
                for (int j = 0; j < allResolvedDesignators.Count; j++)
                {
                    if (rules.DesignatorAllowed(allResolvedDesignators[j]))
                    {
                        T t = allResolvedDesignators[j] as T;
                        if (t != null)
                        {
                            return(t);
                        }
                    }
                }
            }
            Designator designator = DesignatorUtility.StandaloneDesignators.TryGetValue(typeof(T), null);

            if (designator == null)
            {
                designator = (Activator.CreateInstance(typeof(T)) as Designator);
                DesignatorUtility.StandaloneDesignators[typeof(T)] = designator;
            }
            return(designator);
        }
Beispiel #2
0
        private void ResolveDesignators()
        {
            this.resolvedDesignators.Clear();
            foreach (Type specialDesignatorClass in this.specialDesignatorClasses)
            {
                Designator designator = null;
                try
                {
                    designator = (Designator)Activator.CreateInstance(specialDesignatorClass);
                }
                catch (Exception ex)
                {
                    Log.Error("DesignationCategoryDef" + base.defName + " could not instantiate special designator from class " + specialDesignatorClass + ".\n Exception: \n" + ex.ToString());
                }
                if (designator != null)
                {
                    this.resolvedDesignators.Add(designator);
                }
            }
            IEnumerable <BuildableDef> enumerable = from tDef in DefDatabase <ThingDef> .AllDefs.Cast <BuildableDef>().Concat(DefDatabase <TerrainDef> .AllDefs.Cast <BuildableDef>())
                                                        where tDef.designationCategory == this
                                                    select tDef;

            foreach (BuildableDef item in enumerable)
            {
                this.resolvedDesignators.Add(new Designator_Build(item));
            }
        }
 public void Deselect()
 {
     if (this.selectedDesignator != null)
     {
         this.selectedDesignator = null;
         this.dragger.EndDrag();
     }
 }
Beispiel #4
0
 public void Deselect()
 {
     if (selectedDesignator != null)
     {
         selectedDesignator = null;
         dragger.EndDrag();
     }
 }
 public static void RenderHighlightOverSelectableCells(Designator designator, List <IntVec3> dragCells)
 {
     for (int i = 0; i < dragCells.Count; i++)
     {
         Vector3 position = dragCells[i].ToVector3Shifted();
         position.y = AltitudeLayer.MetaOverlays.AltitudeFor();
         Graphics.DrawMesh(MeshPool.plane10, position, Quaternion.identity, DesignatorUtility.DragHighlightCellMat, 0);
     }
 }
Beispiel #6
0
        public virtual IEnumerable <Gizmo> GetGizmos()
        {
            Command_Action command_Action = new Command_Action();

            command_Action.icon = ContentFinder <Texture2D> .Get("UI/Commands/RenameZone");

            command_Action.defaultLabel = "CommandRenameZoneLabel".Translate();
            command_Action.defaultDesc  = "CommandRenameZoneDesc".Translate();
            command_Action.action       = delegate
            {
                Dialog_RenameZone dialog_RenameZone = new Dialog_RenameZone(this);
                if (KeyBindingDefOf.Misc1.IsDown)
                {
                    dialog_RenameZone.WasOpenedByHotkey();
                }
                Find.WindowStack.Add(dialog_RenameZone);
            };
            command_Action.hotKey = KeyBindingDefOf.Misc1;
            yield return(command_Action);

            Command_Toggle command_Toggle = new Command_Toggle();

            command_Toggle.icon = ContentFinder <Texture2D> .Get("UI/Commands/HideZone");

            command_Toggle.defaultLabel = (hidden ? "CommandUnhideZoneLabel".Translate() : "CommandHideZoneLabel".Translate());
            command_Toggle.defaultDesc  = "CommandHideZoneDesc".Translate();
            command_Toggle.isActive     = (() => hidden);
            command_Toggle.toggleAction = delegate
            {
                hidden = !hidden;
                foreach (IntVec3 cell in Cells)
                {
                    Map.mapDrawer.MapMeshDirty(cell, MapMeshFlag.Zone);
                }
            };
            command_Toggle.hotKey = KeyBindingDefOf.Misc2;
            yield return(command_Toggle);

            foreach (Gizmo zoneAddGizmo in GetZoneAddGizmos())
            {
                yield return(zoneAddGizmo);
            }
            Designator designator = DesignatorUtility.FindAllowedDesignator <Designator_ZoneDelete_Shrink>();

            if (designator != null)
            {
                yield return(designator);
            }
            Command_Action command_Action2 = new Command_Action();

            command_Action2.icon         = TexButton.DeleteX;
            command_Action2.defaultLabel = "CommandDeleteZoneLabel".Translate();
            command_Action2.defaultDesc  = "CommandDeleteZoneDesc".Translate();
            command_Action2.action       = Delete;
            command_Action2.hotKey       = KeyBindingDefOf.Designator_Deconstruct;
            yield return(command_Action2);
        }
        public void ProcessInputEvents()
        {
            if (this.CheckSelectedDesignatorValid())
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    if (this.selectedDesignator.DraggableDimensions == 0)
                    {
                        Designator       designator       = this.selectedDesignator;
                        AcceptanceReport acceptanceReport = this.selectedDesignator.CanDesignateCell(UI.MouseCell());
                        if (acceptanceReport.Accepted)
                        {
                            designator.DesignateSingleCell(UI.MouseCell());
                            designator.Finalize(true);
                        }
                        else
                        {
                            Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.SilentInput);
                            this.selectedDesignator.Finalize(false);
                        }
                    }
                    else
                    {
                        this.dragger.StartDrag();
                    }
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                {
                    goto IL_00ec;
                }
                if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    goto IL_00ec;
                }
                goto IL_0121;
            }
            return;

IL_00ec:
            SoundDefOf.CancelMode.PlayOneShotOnCamera(null);
            this.Deselect();
            this.dragger.EndDrag();
            Event.current.Use();
            TutorSystem.Notify_Event("ClearDesignatorSelection");
            goto IL_0121;
IL_0121:
            if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && this.dragger.Dragging)
            {
                this.selectedDesignator.DesignateMultiCell(this.dragger.DragCells);
                this.dragger.EndDrag();
                Event.current.Use();
            }
        }
Beispiel #8
0
        public virtual IEnumerable <Gizmo> GetGizmos()
        {
            yield return(new Command_Action
            {
                icon = ContentFinder <Texture2D> .Get("UI/Commands/RenameZone", true),
                defaultLabel = "CommandRenameZoneLabel".Translate(),
                defaultDesc = "CommandRenameZoneDesc".Translate(),
                action = delegate()
                {
                    Find.WindowStack.Add(new Dialog_RenameZone(this));
                },
                hotKey = KeyBindingDefOf.Misc1
            });

            yield return(new Command_Toggle
            {
                icon = ContentFinder <Texture2D> .Get("UI/Commands/HideZone", true),
                defaultLabel = ((!this.hidden) ? "CommandHideZoneLabel".Translate() : "CommandUnhideZoneLabel".Translate()),
                defaultDesc = "CommandHideZoneDesc".Translate(),
                isActive = (() => this.hidden),
                toggleAction = delegate()
                {
                    this.hidden = !this.hidden;
                    foreach (IntVec3 loc in this.Cells)
                    {
                        this.Map.mapDrawer.MapMeshDirty(loc, MapMeshFlag.Zone);
                    }
                },
                hotKey = KeyBindingDefOf.Misc2
            });

            foreach (Gizmo gizmo in this.GetZoneAddGizmos())
            {
                yield return(gizmo);
            }
            Designator delete = DesignatorUtility.FindAllowedDesignator <Designator_ZoneDelete_Shrink>();

            if (delete != null)
            {
                yield return(delete);
            }
            yield return(new Command_Action
            {
                icon = ContentFinder <Texture2D> .Get("UI/Buttons/Delete", true),
                defaultLabel = "CommandDeleteZoneLabel".Translate(),
                defaultDesc = "CommandDeleteZoneDesc".Translate(),
                action = new Action(this.Delete),
                hotKey = KeyBindingDefOf.Misc3
            });

            yield break;
        }
        private void ResolveDesignators()
        {
            this.resolvedDesignators.Clear();
            foreach (Type current in this.specialDesignatorClasses)
            {
                Designator designator = null;
                try
                {
                    designator = (Designator)Activator.CreateInstance(current);
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "DesignationCategoryDef",
                        this.defName,
                        " could not instantiate special designator from class ",
                        current,
                        ".\n Exception: \n",
                        ex.ToString()
                    }), false);
                }
                if (designator != null)
                {
                    this.resolvedDesignators.Add(designator);
                }
            }
            IEnumerable <BuildableDef> enumerable = from tDef in DefDatabase <TerrainDef> .AllDefs.Cast <BuildableDef>().Concat(DefDatabase <ThingDef> .AllDefs.Cast <BuildableDef>())
                                                        where tDef.designationCategory == this
                                                    select tDef;

            Dictionary <DesignatorDropdownGroupDef, Designator_Dropdown> dictionary = new Dictionary <DesignatorDropdownGroupDef, Designator_Dropdown>();

            foreach (BuildableDef current2 in enumerable)
            {
                if (current2.designatorDropdown != null)
                {
                    if (!dictionary.ContainsKey(current2.designatorDropdown))
                    {
                        dictionary[current2.designatorDropdown] = new Designator_Dropdown();
                        this.resolvedDesignators.Add(dictionary[current2.designatorDropdown]);
                    }
                    dictionary[current2.designatorDropdown].Add(new Designator_Build(current2));
                }
                else
                {
                    this.resolvedDesignators.Add(new Designator_Build(current2));
                }
            }
        }
Beispiel #10
0
 public void ProcessInputEvents()
 {
     if (!CheckSelectedDesignatorValid())
     {
         return;
     }
     if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
     {
         if (selectedDesignator.DraggableDimensions == 0)
         {
             Designator       designator       = selectedDesignator;
             AcceptanceReport acceptanceReport = selectedDesignator.CanDesignateCell(UI.MouseCell());
             if (acceptanceReport.Accepted)
             {
                 designator.DesignateSingleCell(UI.MouseCell());
                 designator.Finalize(somethingSucceeded: true);
             }
             else
             {
                 Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.SilentInput, historical: false);
                 selectedDesignator.Finalize(somethingSucceeded: false);
             }
         }
         else
         {
             dragger.StartDrag();
         }
         Event.current.Use();
     }
     if ((Event.current.type == EventType.MouseDown && Event.current.button == 1) || KeyBindingDefOf.Cancel.KeyDownEvent)
     {
         SoundDefOf.CancelMode.PlayOneShotOnCamera();
         Deselect();
         dragger.EndDrag();
         Event.current.Use();
         TutorSystem.Notify_Event("ClearDesignatorSelection");
     }
     if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && dragger.Dragging)
     {
         selectedDesignator.DesignateMultiCell(dragger.DragCells);
         dragger.EndDrag();
         Event.current.Use();
     }
 }
 public static void RenderHighlightOverSelectableThings(Designator designator, List <IntVec3> dragCells)
 {
     DesignatorUtility.selectedThings.Clear();
     for (int i = 0; i < dragCells.Count; i++)
     {
         List <Thing> thingList = dragCells[i].GetThingList(designator.Map);
         for (int j = 0; j < thingList.Count; j++)
         {
             if (designator.CanDesignateThing(thingList[j]).Accepted&& !DesignatorUtility.selectedThings.Contains(thingList[j]))
             {
                 DesignatorUtility.selectedThings.Add(thingList[j]);
                 Vector3 drawPos = thingList[j].DrawPos;
                 drawPos.y = AltitudeLayer.MetaOverlays.AltitudeFor();
                 Graphics.DrawMesh(MeshPool.plane10, drawPos, Quaternion.identity, DesignatorUtility.DragHighlightThingMat, 0);
             }
         }
     }
     DesignatorUtility.selectedThings.Clear();
 }
Beispiel #12
0
        private void ResolveDesignators()
        {
            resolvedDesignators.Clear();
            foreach (Type specialDesignatorClass in specialDesignatorClasses)
            {
                Designator designator = null;
                try
                {
                    designator         = (Designator)Activator.CreateInstance(specialDesignatorClass);
                    designator.isOrder = true;
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat("DesignationCategoryDef", defName, " could not instantiate special designator from class ", specialDesignatorClass, ".\n Exception: \n", ex.ToString()));
                }
                if (designator != null)
                {
                    resolvedDesignators.Add(designator);
                }
            }
            IEnumerable <BuildableDef> enumerable = from tDef in DefDatabase <TerrainDef> .AllDefs.Cast <BuildableDef>().Concat(DefDatabase <ThingDef> .AllDefs.Cast <BuildableDef>())
                                                        where tDef.designationCategory == this
                                                    select tDef;

            Dictionary <DesignatorDropdownGroupDef, Designator_Dropdown> dictionary = new Dictionary <DesignatorDropdownGroupDef, Designator_Dropdown>();

            foreach (BuildableDef item in enumerable)
            {
                if (item.designatorDropdown != null)
                {
                    if (!dictionary.ContainsKey(item.designatorDropdown))
                    {
                        dictionary[item.designatorDropdown] = new Designator_Dropdown();
                        resolvedDesignators.Add(dictionary[item.designatorDropdown]);
                    }
                    dictionary[item.designatorDropdown].Add(new Designator_Build(item));
                }
                else
                {
                    resolvedDesignators.Add(new Designator_Build(item));
                }
            }
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    rules = Current.Game.Rules;
                    i     = 0;
                    break;

                case 1u:
IL_91:
                    i++;
                    break;

                default:
                    return(false);
                }
                if (i >= this.resolvedDesignators.Count)
                {
                    this.$PC = -1;
                }
                else
                {
                    des = this.resolvedDesignators[i];
                    if (rules.DesignatorAllowed(des))
                    {
                        this.$current = des;
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    goto IL_91;
                }
                return(false);
            }
 public void Select(Designator des)
 {
     this.Deselect();
     this.selectedDesignator = des;
     this.selectedDesignator.Selected();
 }
Beispiel #15
0
 private static bool <InitDesignators> m__0(Designator des)
 {
     return(!Current.Game.Rules.DesignatorAllowed(des));
 }
Beispiel #16
0
 public void Select(Designator des)
 {
     Deselect();
     selectedDesignator = des;
     selectedDesignator.Selected();
 }