Ejemplo n.º 1
0
        public static MapObjectRendererType RegisMapObjectRenderer([NotNull] Type mapRendererType,
                                                                   [NotNull] Type targetType)
        {
            if (mapRendererType == null)
            {
                throw new ArgumentNullException(nameof(mapRendererType));
            }
            if (targetType == null)
            {
                throw new ArgumentNullException(nameof(targetType));
            }

            MapObjectRendererType type =
                MapObjectRendererTypeList.FirstOrDefault(typ => typ.EntryType == mapRendererType &&
                                                         typ.TargetType == targetType);

            if (type != null)
            {
                return(type);
            }

            type = new MapObjectRendererType(mapRendererType, targetType);
            MapObjectRendererTypeList.Add(type);
            MapObjectRendererTypeList.Sort((x, y) => y.TargetType.GetInheritanceDepth(typeof(MapObject))
                                           - x.TargetType.GetInheritanceDepth(typeof(MapObject)));


            return(type);
        }
Ejemplo n.º 2
0
        private void DrawObject(MapObject mapObject)
        {
            Type rendererType =
                MapObjectRendererTypeList.FirstOrDefault(renderer => renderer.TargetType == mapObject.GetType( )) ? .
                EntryType
                ?? MapObjectRendererTypeList.FirstOrDefault(renderer => renderer.TargetType.GetTypeInfo( ).
                                                            IsAssignableFrom(mapObject.GetType( ).GetTypeInfo( ))) ? .
                EntryType;
            ICharacterMapObjectRenderer objectRenderer =
                ( ICharacterMapObjectRenderer )Activator.CreateInstance(rendererType);

            objectRenderer.SetTarget(mapObject);
            MapObjectRendererList.Add(objectRenderer);
            objectRenderer.SetUnit(MapUnit);
            objectRenderer.StartUp( );
        }
Ejemplo n.º 3
0
        public void RendererCatched( )
        {
            List <MapObject> mapObjects = new List <MapObject> ( );

            for (int y = 0; y < Target.Size.Height; y++)
            {
                for (int x = 0; x < Target.Size.Width; x++)
                {
                    MapObject mapObject = Target [x, y];
                    if (mapObjects.Contains(mapObject))
                    {
                    }
                    else
                    {
                        Type rendererType =
                            MapObjectRendererTypeList.FirstOrDefault(renderer => renderer.TargetType == mapObject.GetType( )) ? .
                            EntryType
                            ?? MapObjectRendererTypeList.FirstOrDefault(renderer => renderer.TargetType.GetTypeInfo( ).
                                                                        IsAssignableFrom(mapObject.GetType( ).GetTypeInfo( ))) ? .
                            EntryType;
                        MapObjectRenderer.MapObjectRenderer objectRenderer =
                            (MapObjectRenderer.MapObjectRenderer)Activator.CreateInstance(rendererType);
                        objectRenderer.RenderTransform =
                            objectRenderer.Size.TransformTo(new Size(ObjectRendererSize.Width * mapObject.Size.Width,
                                                                     ObjectRendererSize.Height * mapObject.Size.Height));

                        objectRenderer.Width  = objectRenderer.Size.Width * mapObject.Size.Width;
                        objectRenderer.Height = objectRenderer.Size.Width * mapObject.Size.Height;

                        MainCanvas.Children.Add(objectRenderer);


                        Canvas.SetLeft(objectRenderer,
                                       ObjectRendererSize.Width * 0.25
                                       + mapObject.Position.X * ObjectRendererSize.Width
                                       + (Target.Size.Width - mapObject.Position.Y) * ObjectRendererSize.Width * 0.5);
                        Canvas.SetTop(objectRenderer, mapObject.Position.Y * ObjectRendererSize.Height);

                        (( IMapObjectRenderer )objectRenderer).SetTarget(mapObject);
                        (( IMapObjectRenderer )objectRenderer).StartUp( );

                        objectRenderer.Show( );
                        mapObjects.Add(mapObject);
                    }
                }
            }
        }