Exemple #1
0
        protected override PropertyEditor AutoCreateMemberEditor(MemberInfo info)
        {
            if (info.IsEquivalent(ReflectionInfo.Property_DrawTechnique_PreferredVertexFormat))
            {
                List <VertexDeclaration> vertexTypes = new List <VertexDeclaration>();
                vertexTypes.Add(null);
                foreach (TypeInfo vertexType in DualityApp.GetAvailDualityTypes(typeof(IVertexData)))
                {
                    if (vertexType.IsClass)
                    {
                        continue;
                    }
                    if (vertexType.IsAbstract)
                    {
                        continue;
                    }
                    if (vertexType.IsInterface)
                    {
                        continue;
                    }

                    vertexTypes.Add(VertexDeclaration.Get(vertexType.AsType()));
                }

                ObjectSelectorPropertyEditor e = new ObjectSelectorPropertyEditor();
                e.EditedType = (info as PropertyInfo).PropertyType;
                e.Items      = vertexTypes.Select(decl => new ObjectItem(decl, decl != null ? decl.DataType.Name : "None"));
                this.ParentGrid.ConfigureEditor(e);
                return(e);
            }
            return(base.AutoCreateMemberEditor(info));
        }
        public RigidBodyJointAddNewPropertyEditor()
        {
            this.EditedType   = typeof(Type);
            this.ButtonIcon   = AdamsLair.WinForms.Properties.ResourcesCache.ImageAdd;
            this.Hints        = HintFlags.Default | HintFlags.HasButton | HintFlags.ButtonEnabled;
            this.PropertyName = Properties.EditorBaseRes.PropertyName_AddJoint;
            this.PropertyDesc = Properties.EditorBaseRes.PropertyDesc_AddJoint;

            this.Items =
                from t in DualityApp.GetAvailDualityTypes(typeof(JointInfo))
                where !t.IsAbstract && !t.GetCustomAttributes <EditorHintFlagsAttribute>().Any(f => f.Flags.HasFlag(MemberFlags.Invisible))
                select new ObjectItem(t, t.Name.Replace("JointInfo", "Joint"));
        }
        public RigidBodyJointAddNewPropertyEditor()
        {
            this.EditedType   = typeof(Type);
            this.ButtonIcon   = AdamsLair.PropertyGrid.EmbeddedResources.Resources.ImageAdd;
            this.Hints        = HintFlags.Default | HintFlags.HasButton | HintFlags.ButtonEnabled;
            this.PropertyName = Properties.EditorBaseRes.PropertyName_AddJoint;
            this.PropertyDesc = Properties.EditorBaseRes.PropertyDesc_AddJoint;

            this.Items =
                from t in DualityApp.GetAvailDualityTypes(typeof(JointInfo))
                where !t.IsAbstract
                select new ObjectItem(t, t.Name.Replace("JointInfo", "Joint"));
        }
Exemple #4
0
 /// <summary>
 /// Retrieves a matching <see cref="Duality.Serialization.ISerializeSurrogate"/> for the specified <see cref="System.Type"/>.
 /// </summary>
 /// <param name="t">The <see cref="System.Type"/> to retrieve a <see cref="Duality.Serialization.ISerializeSurrogate"/> for.</param>
 /// <returns></returns>
 protected static ISerializeSurrogate GetSurrogateFor(Type type)
 {
     if (surrogates == null)
     {
         surrogates =
             DualityApp.GetAvailDualityTypes(typeof(ISerializeSurrogate))
             .Select(t => t.CreateInstanceOf())
             .OfType <ISerializeSurrogate>()
             .NotNull()
             .ToList();
         surrogates.StableSort((s1, s2) => s1.Priority - s2.Priority);
     }
     return(surrogates.FirstOrDefault(s => s.MatchesType(type)));
 }
Exemple #5
0
 /// <summary>
 /// Attempts to handle a serialization error dynamically by invoking available <see cref="SerializeErrorHandler">SerializeErrorHandlers</see>.
 /// </summary>
 /// <param name="error"></param>
 /// <returns>Returns true, if the error has been handled successfully.</returns>
 protected static bool HandleSerializeError(SerializeError error)
 {
     if (error.Handled)
     {
         return(true);
     }
     if (serializeHandlerCache.Count == 0)
     {
         IEnumerable <Type> handlerTypes = DualityApp.GetAvailDualityTypes(typeof(SerializeErrorHandler));
         foreach (Type handlerType in handlerTypes)
         {
             if (handlerType.IsAbstract)
             {
                 continue;
             }
             try
             {
                 SerializeErrorHandler handler = handlerType.CreateInstanceOf() as SerializeErrorHandler;
                 if (handler != null)
                 {
                     serializeHandlerCache.Add(handler);
                 }
             }
             catch (Exception) {}
         }
         serializeHandlerCache.StableSort((a, b) => b.Priority - a.Priority);
     }
     foreach (SerializeErrorHandler handler in serializeHandlerCache)
     {
         try
         {
             handler.HandleError(error);
             if (error.Handled)
             {
                 return(true);
             }
         }
         catch (Exception e)
         {
             Log.Core.WriteError("An error occurred while trying to perform a serialization fallback: {0}", Log.Exception(e));
         }
     }
     return(false);
 }
Exemple #6
0
 internal static ICloneSurrogate GetSurrogateFor(TypeInfo type)
 {
     if (surrogates == null)
     {
         surrogates =
             DualityApp.GetAvailDualityTypes(typeof(ICloneSurrogate))
             .Select(t => t.CreateInstanceOf())
             .OfType <ICloneSurrogate>()
             .NotNull()
             .ToList();
         surrogates.StableSort((s1, s2) => s1.Priority - s2.Priority);
     }
     for (int i = 0; i < surrogates.Count; i++)
     {
         if (surrogates[i].MatchesType(type))
         {
             return(surrogates[i]);
         }
     }
     return(null);
 }
Exemple #7
0
        private static void GatherAvailable()
        {
            availableCodecs = new List <IImageCodec>();
            foreach (TypeInfo imageCodecType in DualityApp.GetAvailDualityTypes(typeof(IImageCodec)))
            {
                if (imageCodecType.IsAbstract)
                {
                    continue;
                }
                if (imageCodecType.IsInterface)
                {
                    continue;
                }

                IImageCodec codec = imageCodecType.CreateInstanceOf() as IImageCodec;
                if (codec != null)
                {
                    availableCodecs.Add(codec);
                }
            }
            availableCodecs.StableSort((a, b) => b.Priority > a.Priority ? 1 : -1);
        }
        void ICmpUpdatable.OnUpdate()
        {
            // Prepare a list of camera controllers, if we don't already have one
            if (this.cameraControllers == null)
            {
                this.cameraControllers = new List <ICameraController>();

                // Use Reflection to get a list of all ICameraController classes
                TypeInfo[] availableCameraControllerTypes = DualityApp.GetAvailDualityTypes(typeof(ICameraController)).ToArray();
                foreach (TypeInfo camControllerType in availableCameraControllerTypes)
                {
                    // Create an instance of each class
                    ICameraController camController = camControllerType.CreateInstanceOf() as ICameraController;
                    if (camController != null)
                    {
                        this.cameraControllers.Add(camController);
                    }
                }
            }

            // Allow the user to select which camera controller to use
            if (DualityApp.Keyboard.KeyHit(Key.Number1))
            {
                this.ActiveCameraController--;
            }
            if (DualityApp.Keyboard.KeyHit(Key.Number2))
            {
                this.ActiveCameraController++;
            }
            if (DualityApp.Keyboard.KeyHit(Key.M))
            {
                this.movementHistoryActive = !this.movementHistoryActive;
            }

            // Is there a Gamepad we can use?
            GamepadInput gamepad = DualityApp.Gamepads.FirstOrDefault(g => g.IsAvailable);

            if (gamepad != null)
            {
                if (gamepad.ButtonHit(GamepadButton.A))
                {
                    this.ActiveCameraController--;
                }
                if (gamepad.ButtonHit(GamepadButton.B))
                {
                    this.ActiveCameraController++;
                }
                if (gamepad.ButtonHit(GamepadButton.X))
                {
                    this.movementHistoryActive = !this.movementHistoryActive;
                }
            }

            // Every 100 ms, draw one visual log entry to document movement
            if (this.movementHistoryActive)
            {
                this.movementHistoryTimer += Time.MsPFMult * Time.TimeMult;
                if (this.movementHistoryTimer > 100.0f)
                {
                    this.movementHistoryTimer -= 100.0f;
                    Vector2 targetPos = this.targetObj.Transform.Pos.Xy;
                    Vector2 cameraPos = this.mainCameraObj.Transform.Pos.Xy;
                    VisualLog.Default.DrawPoint(
                        targetPos.X,
                        targetPos.Y,
                        0.0f)
                    .WithColor(new ColorRgba(255, 128, 0))
                    .KeepAlive(3000.0f);
                    VisualLog.Default.DrawPoint(
                        cameraPos.X,
                        cameraPos.Y,
                        0.0f)
                    .WithColor(new ColorRgba(0, 255, 0))
                    .KeepAlive(3000.0f);
                }
            }
        }
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            this.itemListing.ClearSelection();
            this.itemListing.Model = this.Model;

            this.itemListing.BeginUpdate();
            this.Model.Nodes.Clear();

            if (this.SelectType)
            {
                this.Text = "Select a Type";

                foreach (TypeInfo type in DualityApp.GetAvailDualityTypes(this.FilteredType).Where(t => !t.IsAbstract && !t.IsInterface))
                {
                    this.Model.Nodes.Add(new ReferenceNode(type));
                }
            }
            else if (typeof(GameObject).IsAssignableFrom(this.FilteredType))
            {
                this.Text = "Select a GameObject";

                foreach (GameObject currentObject in Scene.Current.AllObjects)
                {
                    this.Model.Nodes.Add(new ReferenceNode(currentObject));
                }
            }
            else if (typeof(Component).IsAssignableFrom(this.FilteredType))
            {
                this.Text = string.Format("Select a {0} Component", this.FilteredType.GetTypeCSCodeName());

                foreach (Component currentComponent in Scene.Current.FindComponents(this.FilteredType))
                {
                    this.Model.Nodes.Add(new ReferenceNode(currentComponent));
                }
            }
            else
            {
                Type filteredType = typeof(Resource);

                if (this.FilteredType.IsGenericType)
                {
                    filteredType = this.FilteredType.GetGenericArguments()[0];
                    this.Text    = string.Format("Select a {0} Resource", filteredType.GetTypeCSCodeName(true));
                }
                else
                {
                    this.Text = "Select a Resource";
                }

                foreach (IContentRef contentRef in ContentProvider.GetAvailableContent(filteredType))
                {
                    this.Model.Nodes.Add(new ReferenceNode(contentRef));
                }
            }

            foreach (var treeNodeAdv in this.itemListing.AllNodes)
            {
                ReferenceNode node = treeNodeAdv.Tag as ReferenceNode;

                treeNodeAdv.IsExpanded = true;

                if (node != null && node.Origin == this.ResourcePath)
                {
                    this.itemListing.SelectedNode = treeNodeAdv;
                }
            }

            this.itemListing.EndUpdate();
            this.txtFilterInput.Focus();
        }