Ejemplo n.º 1
0
        private void DesignateWithPredicate(Designator designator, Map map, Func <Thing, bool> shouldDesignateThing = null, string successMessageKey = null)
        {
            int hitCount = 0;

            foreach (var thing in map.listerThings.ThingsInGroup(DesignatorRequestGroup))
            {
                if (ValidForDesignation(thing) &&
                    designator.CanDesignateThing(thing).Accepted&&
                    !thing.def.designateHaulable &&
                    (shouldDesignateThing == null || shouldDesignateThing(thing)))
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                }
            }
            if (successMessageKey == null)
            {
                successMessageKey = EntryTextKey + SuccessMessageStringIdSuffix;
            }
            if (hitCount > 0)
            {
                Messages.Message(successMessageKey.Translate(hitCount), MessageTypeDefOf.TaskCompletion);
            }
            else
            {
                Messages.Message((EntryTextKey + FailureMessageStringIdSuffix).Translate(), MessageTypeDefOf.RejectInput);
            }
        }
Ejemplo n.º 2
0
 public static void DrawInspectGizmoGridFor(IEnumerable <object> selectedObjects, out Gizmo mouseoverGizmo)
 {
     mouseoverGizmo = null;
     try
     {
         objList.Clear();
         objList.AddRange(selectedObjects);
         gizmoList.Clear();
         for (int i = 0; i < objList.Count; i++)
         {
             ISelectable selectable = objList[i] as ISelectable;
             if (selectable != null)
             {
                 gizmoList.AddRange(selectable.GetGizmos());
             }
         }
         for (int j = 0; j < objList.Count; j++)
         {
             Thing t = objList[j] as Thing;
             if (t == null)
             {
                 continue;
             }
             List <Designator> allDesignators = Find.ReverseDesignatorDatabase.AllDesignators;
             for (int k = 0; k < allDesignators.Count; k++)
             {
                 Designator des = allDesignators[k];
                 if (!des.CanDesignateThing(t).Accepted)
                 {
                     continue;
                 }
                 Command_Action command_Action = new Command_Action();
                 command_Action.defaultLabel = des.LabelCapReverseDesignating(t);
                 command_Action.icon         = des.IconReverseDesignating(t, out var angle, out var offset);
                 command_Action.iconAngle    = angle;
                 command_Action.iconOffset   = offset;
                 command_Action.defaultDesc  = des.DescReverseDesignating(t);
                 command_Action.order        = ((des is Designator_Uninstall) ? (-11f) : (-20f));
                 command_Action.action       = delegate
                 {
                     if (TutorSystem.AllowAction(des.TutorTagDesignate))
                     {
                         des.DesignateThing(t);
                         des.Finalize(somethingSucceeded: true);
                     }
                 };
                 command_Action.hotKey   = des.hotKey;
                 command_Action.groupKey = des.groupKey;
                 gizmoList.Add(command_Action);
             }
         }
         objList.Clear();
         GizmoGridDrawer.DrawGizmoGrid(gizmoList, InspectPaneUtility.PaneWidthFor(Find.WindowStack.WindowOfType <IInspectPane>()) + GizmoGridDrawer.GizmoSpacing.y, out mouseoverGizmo);
         gizmoList.Clear();
     }
     catch (Exception ex)
     {
         Log.ErrorOnce(ex.ToString(), 3427734);
     }
 }
 public static void DrawInspectGizmoGridFor(IEnumerable <object> selectedObjects, out Gizmo mouseoverGizmo)
 {
     mouseoverGizmo = null;
     try
     {
         InspectGizmoGrid.objList.Clear();
         InspectGizmoGrid.objList.AddRange(selectedObjects);
         InspectGizmoGrid.gizmoList.Clear();
         for (int i = 0; i < InspectGizmoGrid.objList.Count; i++)
         {
             ISelectable selectable = InspectGizmoGrid.objList[i] as ISelectable;
             if (selectable != null)
             {
                 InspectGizmoGrid.gizmoList.AddRange(selectable.GetGizmos());
             }
         }
         for (int j = 0; j < InspectGizmoGrid.objList.Count; j++)
         {
             Thing t = InspectGizmoGrid.objList[j] as Thing;
             if (t != null)
             {
                 List <Designator> allDesignators = Find.ReverseDesignatorDatabase.AllDesignators;
                 for (int k = 0; k < allDesignators.Count; k++)
                 {
                     Designator des = allDesignators[k];
                     if (des.CanDesignateThing(t).Accepted)
                     {
                         Command_Action command_Action = new Command_Action();
                         command_Action.defaultLabel = des.LabelCapReverseDesignating(t);
                         float   iconAngle;
                         Vector2 iconOffset;
                         command_Action.icon        = des.IconReverseDesignating(t, out iconAngle, out iconOffset);
                         command_Action.iconAngle   = iconAngle;
                         command_Action.iconOffset  = iconOffset;
                         command_Action.defaultDesc = des.DescReverseDesignating(t);
                         command_Action.order       = ((!(des is Designator_Uninstall)) ? -20f : -11f);
                         command_Action.action      = delegate()
                         {
                             if (TutorSystem.AllowAction(des.TutorTagDesignate))
                             {
                                 des.DesignateThing(t);
                                 des.Finalize(true);
                             }
                         };
                         command_Action.hotKey   = des.hotKey;
                         command_Action.groupKey = des.groupKey;
                         InspectGizmoGrid.gizmoList.Add(command_Action);
                     }
                 }
             }
         }
         InspectGizmoGrid.objList.Clear();
         GizmoGridDrawer.DrawGizmoGrid(InspectGizmoGrid.gizmoList, InspectPaneUtility.PaneWidthFor(Find.WindowStack.WindowOfType <IInspectPane>()) + 20f, out mouseoverGizmo);
         InspectGizmoGrid.gizmoList.Clear();
     }
     catch (Exception ex)
     {
         Log.ErrorOnce(ex.ToString(), 3427734, false);
     }
 }
 public static void DrawInspectGizmoGridFor(IEnumerable <object> selectedObjects)
 {
     try
     {
         InspectGizmoGrid.objList.Clear();
         InspectGizmoGrid.objList.AddRange(selectedObjects);
         InspectGizmoGrid.gizmoList.Clear();
         for (int i = 0; i < InspectGizmoGrid.objList.Count; i++)
         {
             ISelectable selectable = InspectGizmoGrid.objList[i] as ISelectable;
             if (selectable != null)
             {
                 foreach (Gizmo current in selectable.GetGizmos())
                 {
                     InspectGizmoGrid.gizmoList.Add(current);
                 }
             }
         }
         for (int j = 0; j < InspectGizmoGrid.objList.Count; j++)
         {
             Thing t = InspectGizmoGrid.objList[j] as Thing;
             if (t != null)
             {
                 List <Designator> allDesignators = ReverseDesignatorDatabase.AllDesignators;
                 for (int k = 0; k < allDesignators.Count; k++)
                 {
                     Designator des = allDesignators[k];
                     if (des.CanDesignateThing(t).Accepted)
                     {
                         Command_Action command_Action = new Command_Action();
                         command_Action.defaultLabel = des.LabelCapReverseDesignating(t);
                         command_Action.icon         = des.IconReverseDesignating(t);
                         command_Action.defaultDesc  = des.DescReverseDesignating(t);
                         command_Action.action       = delegate
                         {
                             des.DesignateThing(t);
                             des.Finalize(true);
                         };
                         command_Action.hotKey   = des.hotKey;
                         command_Action.groupKey = des.groupKey;
                         InspectGizmoGrid.gizmoList.Add(command_Action);
                     }
                 }
             }
         }
         Gizmo gizmo;
         GizmoGridDrawer.DrawGizmoGrid(InspectGizmoGrid.gizmoList, RimWorld.MainTabWindow_Inspect.PaneSize.x + 20f, out gizmo);
     }
     catch (Exception ex)
     {
         Log.ErrorOnce(ex.ToString(), 3427734);
     }
 }
        public virtual void ContextMenuAction(Designator designator, Map map)
        {
            int hitCount = 0;

            foreach (var thing in map.listerThings.ThingsInGroup(DesingatorRequestGroup))
            {
                if (ValidForDesignation(thing) && designator.CanDesignateThing(thing).Accepted)
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                }
            }
            ReportActionResult(hitCount);
        }
        protected int DesignateAllThings(Designator designator, Map map, Predicate <Thing> thingFilter)
        {
            int hitCount = 0;

            foreach (var thing in map.listerThings.ThingsInGroup(DesignationRequestGroup))
            {
                if (ThingIsValidForDesignation(thing) && (thingFilter == null || thingFilter(thing)) && designator.CanDesignateThing(thing).Accepted)
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                }
            }
            return(hitCount);
        }
        public override void ContextMenuAction(Designator designator, Map map)
        {
            int hitCount      = 0;
            var playerFaction = Faction.OfPlayer;

            foreach (var thing in map.listerThings.ThingsInGroup(DesingatorRequestGroup))
            {
                if (thing.Faction != playerFaction && designator.CanDesignateThing(thing).Accepted)
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                }
            }
            ReportActionResult(hitCount);
        }
Ejemplo n.º 8
0
 public static void parrot_designate_thing(Thing t, System.Type iType)
 {
     use_native = true;
     try
     {
         MethodInfo mi  = ExpressionHelper.GetMethodInfo(() => DesignatorUtility.FindAllowedDesignator <Designator>());
         MethodInfo mii = mi.GetGenericMethodDefinition().MakeGenericMethod(iType);
         Designator d   = (Designator)mii.Invoke(null, new object[] { });
         d.DesignateThing(t);
     }
     finally
     {
         use_native = false;
     }
 }
Ejemplo n.º 9
0
        public virtual void HarvestAction(Designator designator, Map map, bool homeAreaOnly)
        {
            int hitCount = 0;
            var homeArea = map.areaManager.Home;

            foreach (var thing in map.listerThings.ThingsInGroup(DesignatorRequestGroup))
            {
                if (!ValidForDesignation(thing))
                {
                    continue;
                }
                var cellIndex = map.cellIndices.CellToIndex(thing.Position);
                if ((!homeAreaOnly || homeArea.GetCellBool(cellIndex)) && designator.CanDesignateThing(thing).Accepted)
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                }
            }
            ReportActionResult(hitCount);
        }
Ejemplo n.º 10
0
        public override void ContextMenuAction(Designator designator, Map map)
        {
            int  hitCount        = 0;
            bool friendliesFound = false;

            foreach (var thing in map.listerThings.ThingsInGroup(DesingatorRequestGroup))
            {
                if (ValidForDesignation(thing) && designator.CanDesignateThing(thing).Accepted)
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                    if (AllowToolUtility.PawnIsFriendly(thing))
                    {
                        friendliesFound = true;
                    }
                }
            }
            if (hitCount > 0 && friendliesFound)
            {
                Messages.Message("Designator_context_finish_allies".Translate(hitCount), MessageSound.Standard);
            }
            ReportActionResult(hitCount);
        }
        public override ActivationResult Activate(Designator designator, Map map)
        {
            int  hitCount        = 0;
            bool friendliesFound = false;

            foreach (var thing in map.listerThings.ThingsInGroup(DesignationRequestGroup))
            {
                if (ThingIsValidForDesignation(thing) && designator.CanDesignateThing(thing).Accepted)
                {
                    designator.DesignateThing(thing);
                    hitCount++;
                    if (AllowToolUtility.PawnIsFriendly(thing))
                    {
                        friendliesFound = true;
                    }
                }
            }
            if (hitCount > 0 && friendliesFound)
            {
                Messages.Message("Designator_context_finish_allies".Translate(hitCount), MessageTypeDefOf.CautionInput);
            }
            return(ActivationResult.FromCount(hitCount, BaseTextKey));
        }
        public static void Detour(IEnumerable <object> selectedObjects, ref Gizmo mouseoverGizmo)
        {
            var DoRebuild = !(Analyzer.Settings.OptimizeDrawInspectGizmoGrid && Event.current.type != EventType.Repaint);

            Profiler prof = null;

            if (DoRebuild)
            {
                mouseoverGizmo = null;
                try
                {
                    InspectGizmoGrid.objList.Clear();
                    InspectGizmoGrid.objList.AddRange(selectedObjects);
                    InspectGizmoGrid.gizmoList.Clear();
                    var slam = InspectGizmoGrid.objList.Count;
                    for (var i = 0; i < slam; i++)
                    {
                        if (InspectGizmoGrid.objList[i] is ISelectable selectable)
                        {
                            if (Active)
                            {
                                var me = string.Intern($"{selectable.GetType()} Gizmos");
                                prof = Analyzer.Start(me);
                                InspectGizmoGrid.gizmoList.AddRange(selectable.GetGizmos());
                                prof.Stop();
                            }
                            else
                            {
                                InspectGizmoGrid.gizmoList.AddRange(selectable.GetGizmos());
                            }
                        }
                    }
                    for (var j = 0; j < InspectGizmoGrid.objList.Count; j++)
                    {
                        if (InspectGizmoGrid.objList[j] is Thing t)
                        {
                            var allDesignators = Find.ReverseDesignatorDatabase.AllDesignators;
                            var coo            = allDesignators.Count;
                            for (var k = 0; k < coo; k++)
                            {
                                Designator des = allDesignators[k];
                                if (des.CanDesignateThing(t).Accepted)
                                {
                                    var command_Action = new Command_Action
                                    {
                                        defaultLabel = des.LabelCapReverseDesignating(t),
                                        icon         = des.IconReverseDesignating(t, out var iconAngle, out var iconOffset),
                                        iconAngle    = iconAngle,
                                        iconOffset   = iconOffset,
                                        defaultDesc  = des.DescReverseDesignating(t),
                                        order        = (!(des is Designator_Uninstall) ? -20f : -11f),
                                        action       = delegate
                                        {
                                            if (!TutorSystem.AllowAction(des.TutorTagDesignate))
                                            {
                                                return;
                                            }

                                            des.DesignateThing(t);
                                            des.Finalize(true);
                                        },
                                        hotKey   = des.hotKey,
                                        groupKey = des.groupKey
                                    };
                                    InspectGizmoGrid.gizmoList.Add(command_Action);
                                }
                            }
                        }
                    }
                    InspectGizmoGrid.objList.Clear();
                }
                catch (Exception ex)
                {
                    Log.ErrorOnce(ex.ToString(), 3427734);
                }
            }

            if (Active)
            {
                prof = Analyzer.Start(str);
            }
            GizmoGridDrawer.DrawGizmoGrid(InspectGizmoGrid.gizmoList, InspectPaneUtility.PaneWidthFor(Find.WindowStack.WindowOfType <IInspectPane>()) + 20f, out mouseoverGizmo);
            if (Active)
            {
                prof.Stop();
            }
        }