// if designator has no custom context menu entries but has a stock context menu, still show a right click icon
        // detection is not fool-proof, but it's good enough- and better than calling RightClickFloatMenuOptions
        private static bool DesignatorShouldHaveFallbackContextMenuProvider(Designator designator)
        {
            try
            {
                if (designator.GetType() != typeof(Designator_Build))
                {
                    var hasDesignation = AllowToolController.Instance.Reflection.DesignatorGetDesignationMethod.Invoke(designator, new object[0]) != null;
                    if (hasDesignation)
                    {
                        return(true);
                    }
                    var hasDesignateAll = (bool)AllowToolController.Instance.Reflection.DesignatorHasDesignateAllFloatMenuOptionField.GetValue(designator);
                    if (hasDesignateAll)
                    {
                        return(true);
                    }
                    var getOptionsMethod = designator.GetType().GetMethod("get_RightClickFloatMenuOptions", HugsLibUtility.AllBindingFlags);
                    var hasOptionsMethod = getOptionsMethod != null && getOptionsMethod.DeclaringType != typeof(Designator);
                    if (hasOptionsMethod)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                // no problem- the designator will just have no handler assigned
            }

            return(false);
        }
Esempio n. 2
0
        private static void WriteData(ByteWriter data, DesignatorMode mode, Designator designator)
        {
            Type designatorType = designator.GetType();

            Sync.WriteSync(data, mode);
            Sync.WriteSync(data, (ushort)Array.IndexOf(Sync.designatorTypes, designatorType));
            Sync.WriteSyncObject(data, designator, designatorType);

            if (designator is Designator_AreaAllowed)
            {
                Sync.WriteSync(data, Designator_AreaAllowed.SelectedArea);
            }

            if (designator is Designator_Place place)
            {
                Sync.WriteSync(data, place.placingRot);
            }

            if (designator is Designator_Build build && build.PlacingDef.MadeFromStuff)
            {
                Sync.WriteSync(data, build.stuffDef);
            }

            if (designator is Designator_Install)
            {
                Sync.WriteSync(data, ThingToInstall());
            }

            if (designator is Designator_Zone)
            {
                Sync.WriteSync(data, Find.Selector.SelectedZone);
            }
        }
Esempio n. 3
0
        public static bool DesignateMultiCell(Designator __instance, IEnumerable <IntVec3> __0)
        {
            if (!Multiplayer.ShouldSync)
            {
                return(true);
            }

            // No cells implies Finalize(false), which currently doesn't cause side effects
            if (__0.Count() == 0)
            {
                return(true);
            }

            Designator designator = __instance;

            Map map = Find.CurrentMap;
            LoggingByteWriter writer = new LoggingByteWriter();

            writer.log.Node("Designate multi cell: " + designator.GetType());
            IntVec3[] cellArray = __0.ToArray();

            WriteData(writer, DesignatorMode.MultiCell, designator);
            Sync.WriteSync(writer, cellArray);

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.ToArray());
            Multiplayer.WriterLog.nodes.Add(writer.log.current);

            return(false);
        }
Esempio n. 4
0
        public bool AutoDraw()
        {
            Designator des = Find.DesignatorManager.SelectedDesignator;

            return(des != null &&
                   AutoDesignator().IsAssignableFrom(des.GetType()) &&
                   DesignatorVerifier(des));
        }
Esempio n. 5
0
        public bool DesignatorAllowed(Designator d)
        {
            Designator_Place designator_Place = d as Designator_Place;

            if (designator_Place != null)
            {
                return(!disallowedBuildings.Contains(designator_Place.PlacingDef));
            }
            return(!disallowedDesignatorTypes.Contains(d.GetType()));
        }
 static Command_Action initAction(Designator des)
 {
     if (des.GetType().IsSubclassOf(typeof(Action_Designator)))
     {
         return((des as Action_Designator).init_Command_Action());
     }
     else
     {
         return(new Command_Action());
     }
 }
Esempio n. 7
0
 static Command_Action initAction(Command_Action defaultAction, Designator des)
 {
     //Log.Message($"{des}");
     if (des.GetType().IsSubclassOf(typeof(Action_Designator)))
     {
         return((des as Action_Designator).init_Command_Action());
     }
     else
     {
         return(defaultAction);
     }
 }
Esempio n. 8
0
 public static bool RegularDesignateThing(Thing t, Designator __instance)
 {
     if (use_native)
     {
         return(true);
     }
     else
     {
         parrot_designate_thing(t, __instance.GetType());
         return(false);
     }
 }
Esempio n. 9
0
 public static bool RegularDesignateMultipleCells(IEnumerable <IntVec3> cells, Designator __instance)
 {
     if (use_native)
     {
         return(true);
     }
     else
     {
         parrot_designate_multiple_cell(cells, __instance.GetType());
         return(false);
     }
 }
Esempio n. 10
0
        /// <param name="designator">The designator that will be paired to a menu provider</param>
        /// <param name="providers">All available handlers</param>
        private static void TryBindDesignatorToHandler(Designator designator, List <BaseDesignatorMenuProvider> providers)
        {
            if (designator == null || designatorMenuProviders.ContainsKey(designator))
            {
                return;
            }
            var handlerBound = false;

            for (int i = 0; i < providers.Count; i++)
            {
                var provider = providers[i];
                if (provider.HandledDesignatorType != null && provider.HandledDesignatorType.IsInstanceOfType(designator))
                {
                    designatorMenuProviders.Add(designator, provider);
                    handlerBound = true;
                    break;
                }
            }
            if (!handlerBound && designator.GetType() != typeof(Designator_Build))
            {
                try {
                    // if designator has no handler but has a context menu, provide the generic one
                    var hasDesignation     = AllowToolController.DesignatorGetDesignationMethod.Invoke(designator, new object[0]) != null;
                    var hasDesignateAll    = (bool)AllowToolController.DesignatorHasDesignateAllFloatMenuOptionField.GetValue(designator);
                    var getOptionsMethod   = designator.GetType().GetMethod("get_RightClickFloatMenuOptions", HugsLibUtility.AllBindingFlags);
                    var hasOptionsMethod   = getOptionsMethod != null && getOptionsMethod.DeclaringType != typeof(Designator) && getOptionsMethod.DeclaringType != typeof(Designator_SelectableThings);
                    var ATDesignator       = designator as Designator_SelectableThings;
                    var hasReplacedOptions = ATDesignator?.ReplacedDesignator != null;
                    if (hasDesignation || hasDesignateAll || hasOptionsMethod || hasReplacedOptions)
                    {
                        // detection is not fool-proof, but it's good enough- and better than calling RightClickFloatMenuOptions
                        designatorMenuProviders.Add(designator, providers.OfType <MenuProvider_Generic>().First());
                    }
                } catch (Exception) {
                    // no problem- the designator will just have no handler assigned
                }
            }
        }
Esempio n. 11
0
        public bool DesignatorAllowed(Designator d)
        {
            Designator_Place designator_Place = d as Designator_Place;
            bool             result;

            if (designator_Place != null)
            {
                result = !this.disallowedBuildings.Contains(designator_Place.PlacingDef);
            }
            else
            {
                result = !this.disallowedDesignatorTypes.Contains(d.GetType());
            }
            return(result);
        }
        private static bool TryPickDesignatorFromReverseDesignator(Designator designator)
        {
            var interfaceSupport = false;

            if (designator != null && designator is IReversePickableDesignator rp)
            {
                designator       = rp.PickUpReverseDesignator();
                interfaceSupport = true;
            }
            if (designator != null)
            {
                if (interfaceSupport || reversePickingSupportedDesignators.Contains(designator.GetType()))
                {
                    Find.DesignatorManager.Select(designator);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 13
0
        static void DesignatorGU(SyncWorker sync, ref Designator designator)
        {
            if (sync.isWriting)
            {
                Type t     = designator.GetType();
                byte tByte = ByteFromType(t);

                sync.Write(tByte);
            }
            else
            {
                byte tByte = sync.Read <byte>();
                Type t     = TypeFromByte(tByte);

                designator = (Designator)Activator.CreateInstance(t);

                string label = (string)AreaLabelField.GetValue(designator);

                SetSelectedAreaMethod.Invoke(designator, new object[] { label });
            }
        }
Esempio n. 14
0
        public static bool DesignateSingleCell(Designator __instance, IntVec3 __0)
        {
            if (!Multiplayer.ShouldSync)
            {
                return(true);
            }

            Designator designator = __instance;

            Map map = Find.CurrentMap;
            LoggingByteWriter writer = new LoggingByteWriter();

            writer.log.Node("Designate single cell: " + designator.GetType());

            WriteData(writer, DesignatorMode.SingleCell, designator);
            Sync.WriteSync(writer, __0);

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.ToArray());
            Multiplayer.WriterLog.nodes.Add(writer.log.current);

            return(false);
        }
Esempio n. 15
0
        private static void WriteData(ByteWriter data, DesignatorMode mode, Designator designator)
        {
            Sync.WriteSync(data, mode);
            Sync.WriteSyncObject(data, designator, designator.GetType());

            // These affect the Global context and shouldn't be SyncWorkers
            // Read at MapAsyncTimeComp.SetDesignatorState

            if (designator is Designator_AreaAllowed)
            {
                Sync.WriteSync(data, Designator_AreaAllowed.SelectedArea);
            }

            if (designator is Designator_Install install)
            {
                Sync.WriteSync(data, install.MiniToInstallOrBuildingToReinstall);
            }

            if (designator is Designator_Zone)
            {
                Sync.WriteSync(data, Find.Selector.SelectedZone);
            }
        }
Esempio n. 16
0
        private static void WriteData(ByteWriter data, DesignatorMode mode, Designator designator)
        {
            SyncSerialization.WriteSync(data, mode);
            SyncSerialization.WriteSyncObject(data, designator, designator.GetType());

            // Read at MapAsyncTimeComp.SetDesignatorState
            // The reading side affects global state so these can't be SyncWorkers

            if (designator is Designator_AreaAllowed)
            {
                SyncSerialization.WriteSync(data, Designator_AreaAllowed.SelectedArea);
            }

            if (designator is Designator_Install install)
            {
                SyncSerialization.WriteSync(data, install.MiniToInstallOrBuildingToReinstall);
            }

            if (designator is Designator_Zone)
            {
                SyncSerialization.WriteSync(data, Find.Selector.SelectedZone);
            }
        }
Esempio n. 17
0
        public static bool DesignateThing(Designator __instance, Thing __0)
        {
            if (!Multiplayer.ShouldSync)
            {
                return(true);
            }

            Designator designator = __instance;

            Map map = Find.CurrentMap;
            LoggingByteWriter writer = new LoggingByteWriter();

            writer.log.Node("Designate thing: " + __0 + " " + designator.GetType());

            WriteData(writer, DesignatorMode.Thing, designator);
            Sync.WriteSync(writer, __0);

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.ToArray());
            Multiplayer.WriterLog.nodes.Add(writer.log.current);

            MoteMaker.ThrowMetaPuffs(__0);

            return(false);
        }
 private static bool TryPickDesignatorFromReverseDesignator(Designator designator)
 {
     if (designator is Designator_SelectableThings || (designator != null && reversePickingSupportedDesignators.Contains(designator.GetType())))
     {
         Find.DesignatorManager.Select(designator);
         return(true);
     }
     return(false);
 }