Example #1
0
        private CharTexture RasterizeCharacter(char ch)
        {
            string text = ch.ToString();

            // Causes truetype fonts to be rendered in their exact width
            StringFormat format = StringFormat.GenericTypographic;
            SizeF        size   = globalGraphics.MeasureString(text, font, new PointF(0, 0), format);

            // If the character is unprintable, measure it with the truetype padding to receive its padding width
            if (size.Width < 1)
            {
                format = StringFormat.GenericDefault;
                size   = globalGraphics.MeasureString(text, font);
            }

            int width  = (int)Math.Ceiling(size.Width);
            int height = (int)Math.Ceiling(size.Height);

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                graphics.DrawString(text, font, brush, 0, 0, format);
            }

            return(new CharTexture(BoardItem.TextureFromBitmap(device, bitmap), width, height));
        }
        /// <summary>
        /// Tooltip
        /// </summary>
        /// <param name="texturePool"></param>
        /// <param name="farmFrameParent"></param>
        /// <param name="tooltip"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        public static TooltipItem CreateTooltipFromProperty(TexturePool texturePool, WzSubProperty farmFrameParent, ToolTipInstance tooltip, GraphicsDevice device)
        {
            // Wz frames
            System.Drawing.Bitmap c     = ((WzCanvasProperty)farmFrameParent?["c"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap cover = ((WzCanvasProperty)farmFrameParent?["cover"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap e     = ((WzCanvasProperty)farmFrameParent?["e"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap n     = ((WzCanvasProperty)farmFrameParent?["n"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap s     = ((WzCanvasProperty)farmFrameParent?["s"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap w     = ((WzCanvasProperty)farmFrameParent?["w"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap ne    = ((WzCanvasProperty)farmFrameParent?["ne"])?.GetLinkedWzCanvasBitmap(); // top right
            System.Drawing.Bitmap nw    = ((WzCanvasProperty)farmFrameParent?["nw"])?.GetLinkedWzCanvasBitmap(); // top left
            System.Drawing.Bitmap se    = ((WzCanvasProperty)farmFrameParent?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right
            System.Drawing.Bitmap sw    = ((WzCanvasProperty)farmFrameParent?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left


            // tooltip property
            string title = tooltip.Title;
            string desc  = tooltip.Desc;

            string renderText = string.Format("{0}{1}{2}", title, Environment.NewLine, desc);

            // Constants
            const string TOOLTIP_FONT     = "Arial";
            const float  TOOLTIP_FONTSIZE = 9.25f; // thankie willified, ya'll be remembered forever here <3

            //System.Drawing.Color color_bgFill = System.Drawing.Color.FromArgb(230, 17, 54, 82); // pre V patch (dark blue theme used post-bb), leave this here in case someone needs it
            System.Drawing.Color color_bgFill     = System.Drawing.Color.FromArgb(255, 17, 17, 17); // post V patch (dark black theme used), use color picker on paint via image extracted from WZ if you need to get it
            System.Drawing.Color color_foreGround = System.Drawing.Color.White;
            const int            WIDTH_PADDING    = 10;
            const int            HEIGHT_PADDING   = 6;

            // Create
            using (System.Drawing.Font font = new System.Drawing.Font(TOOLTIP_FONT, TOOLTIP_FONTSIZE))
            {
                System.Drawing.Graphics graphics_dummy = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)); // dummy image just to get the Graphics object for measuring string
                System.Drawing.SizeF    tooltipSize    = graphics_dummy.MeasureString(renderText, font);

                int effective_width  = (int)tooltipSize.Width + WIDTH_PADDING;
                int effective_height = (int)tooltipSize.Height + HEIGHT_PADDING;

                System.Drawing.Bitmap bmp_tooltip = new System.Drawing.Bitmap(effective_width, effective_height);
                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_tooltip))
                {
                    // Frames and background
                    UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, c, effective_width, effective_height);

                    // Text
                    graphics.DrawString(renderText, font, new System.Drawing.SolidBrush(color_foreGround), WIDTH_PADDING / 2, HEIGHT_PADDING / 2);
                    graphics.Flush();
                }
                IDXObject   dxObj = new DXObject(tooltip.X, tooltip.Y, BoardItem.TextureFromBitmap(device, bmp_tooltip), 0);
                TooltipItem item  = new TooltipItem(tooltip, dxObj);

                return(item);
            }
        }
 public void CreateTexture(GraphicsDevice device)
 {
     if (image != null && image.Width == 1 && image.Height == 1)
     {
         texture = BoardItem.TextureFromBitmap(device, global::HaCreator.Properties.Resources.placeholder);
     }
     else
     {
         texture = BoardItem.TextureFromBitmap(device, image);
     }
 }
Example #4
0
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, int x, int y, int rx, int ry, int cx, int cy, int a, BackgroundType type, bool front, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                WzVectorProperty origin = (WzVectorProperty)source["origin"];

                if (source.MSTag == null)
                {
                    source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).PngProperty.GetPNG(false));
                    usedProps.Add(source);
                }

                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, new DXObject(x - origin.X.Value /* - mapCenterX*/, y - origin.Y.Value /* - mapCenterY*/, (Texture2D)source.MSTag), flip));
            }
            else if (source is WzSubProperty) //animooted
            {
                WzCanvasProperty frameProp;
                int             i      = 0;
                List <DXObject> frames = new List <DXObject>();

                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int?delay = InfoTool.GetOptionalInt(frameProp["delay"]);

                    if (delay == null)
                    {
                        delay = 100;
                    }

                    if (frameProp.MSTag == null)
                    {
                        frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.PngProperty.GetPNG(false));
                        usedProps.Add(frameProp);
                    }

                    WzVectorProperty origin = (WzVectorProperty)frameProp["origin"];
                    frames.Add(new DXObject(x - origin.X.Value /* - mapCenterX*/, y - origin.Y.Value /* - mapCenterY*/, (int)delay, (Texture2D)frameProp.MSTag));
                }

                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, frames, flip));
            }
            else
            {
                throw new Exception("unsupported property type in map simulator");
            }
        }
Example #5
0
 public virtual Texture2D GetTexture(SpriteBatch sprite)
 {
     if (texture == null)
     {
         if (image != null && image.Width == 1 && image.Height == 1)
         {
             texture = BoardItem.TextureFromBitmap(sprite.GraphicsDevice, global::HaCreator.Properties.Resources.placeholder);
         }
         else
         {
             texture = BoardItem.TextureFromBitmap(sprite.GraphicsDevice, image);
         }
     }
     return(texture);
 }
Example #6
0
        public MapSimulator(Board mapBoard)
        {
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
            }

            mapCenter  = mapBoard.CenterPoint;
            minimapPos = new Point((int)Math.Round((mapBoard.MinimapPosition.X + mapCenter.X) / (double)mapBoard.mag), (int)Math.Round((mapBoard.MinimapPosition.Y + mapCenter.Y) / (double)mapBoard.mag));

            if (mapBoard.VRRectangle == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.VRRectangle.X + mapCenter.X, mapBoard.VRRectangle.Y + mapCenter.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }

            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            InitializeComponent();
            width       = UserSettings.XGAResolution ? 1024 : 800;
            height      = UserSettings.XGAResolution ? 768 : 600;
            this.Width  = width;
            this.Height = height;
#if FULLSCREEN
            pParams.BackBufferWidth    = Math.Max(Width, 1);
            pParams.BackBufferHeight   = Math.Max(Height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.IsFullScreen       = false;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
#else
            pParams.BackBufferWidth    = Math.Max(width, 1);
            pParams.BackBufferHeight   = Math.Max(height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
            pParams.DeviceWindowHandle = Handle;
            pParams.IsFullScreen       = false;
#endif
            DxDevice     = MultiBoard.CreateGraphicsDevice(pParams);
            this.minimap = BoardItem.TextureFromBitmap(DxDevice, mapBoard.MiniMap ?? new System.Drawing.Bitmap(1, 1));
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel  = BoardItem.TextureFromBitmap(DxDevice, bmp);
            sprite = new SpriteBatch(DxDevice);
        }
        /// <summary>
        /// Load frames from WzSubProperty or WzCanvasProperty
        /// </summary>
        /// <param name="texturePool"></param>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="spineAni">Spine animation path</param>
        /// <returns></returns>
        private static List <IDXObject> LoadFrames(TexturePool texturePool, WzImageProperty source, int x, int y, GraphicsDevice device, ref List <WzObject> usedProps, string spineAni = null)
        {
            List <IDXObject> frames = new List <IDXObject>();

            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty property1 && property1.WzProperties.Count == 1)
            {
                source = property1.WzProperties[0];
            }

            if (source is WzCanvasProperty property) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, spineAni);
                if (!bLoadedSpine)
                {
                    string    canvasBitmapPath = property.FullPath;
                    Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                    if (textureFromCache != null)
                    {
                        source.MSTag = textureFromCache;
                    }
                    else
                    {
                        source.MSTag = BoardItem.TextureFromBitmap(device, property.GetLinkedWzCanvasBitmap());

                        // add to cache
                        texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)source.MSTag);
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = property.GetCanvasOriginPosition();

                    frames.Add(new DXSpineObject(spineObject, x, y, origin));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
                else // fallback
                {
                    Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzCanvasProperty frameProp;
                int i = 0;

                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                    bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, spineAni);
                    if (!bLoadedSpine)
                    {
                        if (frameProp.MSTag == null)
                        {
                            string    canvasBitmapPath = frameProp.FullPath;
                            Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                            if (textureFromCache != null)
                            {
                                frameProp.MSTag = textureFromCache;
                            }
                            else
                            {
                                frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());

                                // add to cache
                                texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)frameProp.MSTag);
                            }
                        }
                    }
                    usedProps.Add(frameProp);

                    if (frameProp.MSTagSpine != null)
                    {
                        WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                        System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXSpineObject(spineObject, x, y, origin, delay));
                    }
                    else if (frameProp.MSTag != null)
                    {
                        Texture2D             texture = (Texture2D)frameProp.MSTag;
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                    }
                    else
                    {
                        Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                    }
                }
            }
            return(frames);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param>
        /// <param name="mapBoard"></param>
        /// <param name="device"></param>
        /// <param name="MapName">The map name. i.e The Hill North</param>
        /// <param name="StreetName">The street name. i.e Hidden street</param>
        /// <returns></returns>
        public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName)
        {
            WzSubProperty maxMapProperty        = (WzSubProperty)minimapFrameProperty["MaxMap"];
            WzSubProperty miniMapProperty       = (WzSubProperty)minimapFrameProperty["MinMap"];
            WzSubProperty maxMapMirrorProperty  = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps
            WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps

            WzSubProperty useFrame;

            if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple
            {
                useFrame = maxMapMirrorProperty;
            }
            else
            {
                useFrame = maxMapProperty;
            }

            // Wz frames
            System.Drawing.Bitmap c  = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap e  = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap n  = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap s  = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap w  = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right
            System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left
            System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right
            System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left

            // Constants
            const string TOOLTIP_FONT     = "Arial";
            const float  TOOLTIP_FONTSIZE = 10f;

            System.Drawing.Color color_bgFill     = System.Drawing.Color.Transparent;
            System.Drawing.Color color_foreGround = System.Drawing.Color.White;

            // Dots pixel
            System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4);
            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel))
            {
                graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height));
                graphics.Flush();
            }
            IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, BoardItem.TextureFromBitmap(device, bmp_DotPixel), 0);
            BaseItem  item_pixelDot      = new BaseItem(dxObj_miniMapPixel, false);

            // Map background image
            System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay
            int effective_width  = miniMapImage.Width + e.Width + w.Width;
            int effective_height = miniMapImage.Height + n.Height + s.Height;

            using (System.Drawing.Font font = new System.Drawing.Font(TOOLTIP_FONT, TOOLTIP_FONTSIZE))
            {
                System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height);

                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage))
                {
                    // Frames and background
                    UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height);

                    graphics.DrawString(
                        string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName),
                        font, new System.Drawing.SolidBrush(color_foreGround), 50, 20);

                    // Map mark
                    if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark))
                    {
                        System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark];
                        graphics.DrawImage(mapMark.ToImage(), 7, 17);
                    }

                    // Map image
                    graphics.DrawImage(miniMapImage, 10, n.Height);

                    graphics.Flush();
                }
                Texture2D texturer_miniMap = BoardItem.TextureFromBitmap(device, miniMapUIImage);

                IDXObject   dxObj = new DXObject(0, 0, texturer_miniMap, 0);
                MinimapItem item  = new MinimapItem(dxObj, item_pixelDot);

                return(item);
            }
        }
Example #9
0
        /// <summary>
        /// Load game assets
        /// </summary>
        protected override void LoadContent()
        {
            // BGM
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
                if (audio != null)
                {
                    audio.Volume = 0.3f;
                    audio.Play();
                }
            }
            if (mapBoard.VRRectangle == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            // Background and objects
            List <WzObject> usedProps = new List <WzObject>();

            //WzDirectory MapFile = Program.WzManager["map"]; // Map.wz
            //WzDirectory tileDir = (WzDirectory)MapFile["Tile"];

            foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs)
            {
                WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject;

                mapObjects[tileObj.LayerNumber].Add(
                    MapSimulatorLoader.CreateMapItemFromProperty(tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false));
            }
            foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds)
            {
                WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                backgrounds_back.Add(
                    MapSimulatorLoader.CreateBackgroundFromProperty(bgParent, background, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
            }
            foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds)
            {
                WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                backgrounds_front.Add(
                    MapSimulatorLoader.CreateBackgroundFromProperty(bgParent, background, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
            }
            foreach (WzObject obj in usedProps)
            {
                obj.MSTag      = null;
                obj.MSTagSpine = null; // cleanup
            }
            usedProps.Clear();

            // Spine object
            skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonMeshRenderer.PremultipliedAlpha = false;

            // Minimap
            minimapPos   = new Point((int)Math.Round((mapBoard.MinimapPosition.X + mapBoard.CenterPoint.X) / (double)mapBoard.mag), (int)Math.Round((mapBoard.MinimapPosition.Y + mapBoard.CenterPoint.Y) / (double)mapBoard.mag));
            this.minimap = BoardItem.TextureFromBitmap(GraphicsDevice, mapBoard.MiniMap);

            //
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel = BoardItem.TextureFromBitmap(GraphicsDevice, bmp);

            sprite = new SpriteBatch(GraphicsDevice);
        }
Example #10
0
 public void CreateTexture(GraphicsDevice device)
 {
     texture = BoardItem.TextureFromBitmap(device, image);
 }
        /// <summary>
        /// Map item
        /// </summary>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static MapItem CreateMapItemFromProperty(WzImageProperty source, int x, int y, Point mapCenter, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, null);
                if (!bLoadedSpine)
                {
                    if (source.MSTag == null)
                    {
                        source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = ((WzCanvasProperty)source).GetCanvasOriginPosition();

                    return(new MapItem(new DXSpineObject(spineObject, x + mapCenter.X, y + mapCenter.Y, origin), flip));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();

                    return(new MapItem(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture), flip));
                }
                else // fallback
                {
                    Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();

                    return(new MapItem(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture), flip));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzCanvasProperty frameProp;
                int i = 0;
                List <IDXObject> frames = new List <IDXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                    bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, null);
                    if (!bLoadedSpine)
                    {
                        if (frameProp.MSTag == null)
                        {
                            frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        }
                    }
                    usedProps.Add(frameProp);

                    if (frameProp.MSTagSpine != null)
                    {
                        WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                        System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXSpineObject(spineObject, x + mapCenter.X, y + mapCenter.Y, origin, delay));
                    }
                    else if (frameProp.MSTag != null)
                    {
                        Texture2D             texture = (Texture2D)frameProp.MSTag;
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture, delay));
                    }
                    else
                    {
                        Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture, delay));
                    }
                }
                return(new MapItem(frames, flip));
            }
            else
            {
                throw new Exception("unsupported property type in map simulator");
            }
        }
        /// <summary>
        /// Background
        /// </summary>
        /// <param name="source"></param>
        /// <param name="bgInstance"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, BackgroundInstance bgInstance, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);
            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, bgInstance.SpineAni);
                if (!bLoadedSpine)
                {
                    if (source.MSTag == null)
                    {
                        source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXSpineObject         dxobj       = new DXSpineObject(spineObject, bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, origin);

                    return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode));
                }
                else  // default fallback if all things fail
                {
                    Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzCanvasProperty frameProp;
                int i = 0;
                List <IDXObject> frames = new List <IDXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                    bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, bgInstance.SpineAni);
                    if (!bLoadedSpine)
                    {
                        if (frameProp.MSTag == null)
                        {
                            frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        }
                    }
                    usedProps.Add(source);

                    if (frameProp.MSTagSpine != null)
                    {
                        WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                        System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();
                        DXSpineObject         dxobj       = new DXSpineObject(spineObject, bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, origin, delay);

                        frames.Add(dxobj);
                    }
                    else if (frameProp.MSTag != null)
                    {
                        Texture2D             texture = (Texture2D)frameProp.MSTag;
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();
                        DXObject dxObj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture, delay);

                        frames.Add(dxObj);
                    }
                    else // default fallback if all things fail
                    {
                        Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();
                        DXObject dxObj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture, delay);

                        frames.Add(dxObj);
                    }
                }
                return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, frames, flip, bgInstance.screenMode));
            }
            else
            {
                throw new Exception("Unsupported property type in map simulator");
            }
        }
Example #13
0
        public MapSimulator(Board mapBoard)
        {
            WzSoundProperty bgm = Program.InfoManager.BGMs[mapBoard.MapInfo.bgm];

            if (bgm != null)
            {
                audio = new WzMp3Streamer(bgm, true);
            }
            MapSimulator.mapCenter = mapBoard.CenterPoint;
            if (mapBoard.MapInfo.VR == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.MapInfo.VR.Value.X + mapCenter.X, mapBoard.MapInfo.VR.Value.Y + mapCenter.Y, mapBoard.MapInfo.VR.Value.Width, mapBoard.MapInfo.VR.Value.Height);
            }
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            InitializeComponent();
            this.Width  = width;
            this.Height = height;
#if FULLSCREEN
            pParams.BackBufferWidth    = Math.Max(width, 1);
            pParams.BackBufferHeight   = Math.Max(height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.IsFullScreen       = false;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
#else
            pParams.BackBufferWidth    = Math.Max(width, 1);
            pParams.BackBufferHeight   = Math.Max(height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
            pParams.DeviceWindowHandle = Handle;
            pParams.IsFullScreen       = false;
#endif

/*            try
 *          {
 *              DxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, Handle, pParams);
 *          }
 *          catch
 *          {
 *              DxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.NullReference, Handle, pParams);
 *          }*/
            try
            {
                GraphicsProfile profile = GraphicsProfile.Reach;
                if (GraphicsAdapter.DefaultAdapter.IsProfileSupported(GraphicsProfile.HiDef))
                {
                    profile = GraphicsProfile.HiDef;
                }
                else if (!GraphicsAdapter.DefaultAdapter.IsProfileSupported(GraphicsProfile.Reach))
                {
                    throw new NotSupportedException();
                }
                DxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, profile, pParams);
            }
            catch
            {
                HaRepackerLib.Warning.Error("Graphics adapter is not supported");
                Application.Exit();
            }
            graphicsDeviceService = new GraphicsDeviceService(DxDevice);
            this.minimap          = BoardItem.TextureFromBitmap(DxDevice, mapBoard.MiniMap);
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel = BoardItem.TextureFromBitmap(DxDevice, bmp);

            //pixel = BoardItem.TextureFromBitmap(DxDevice, new System.Drawing.Bitmap(1, 1));
            contentMan  = new ContentManager(this);
            defaultFont = contentMan.Load <SpriteFont>("Arial");
            sprite      = new SpriteBatch(DxDevice);
            //character = new Character(400 + mapCenter.X, 300 + mapCenter.Y);
            //character.DoFly();
        }
        public MapSimulator(Board mapBoard)
        {
            InitializeComponent();

            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
            }

            mapCenter  = mapBoard.CenterPoint;
            minimapPos = new Point((int)Math.Round((mapBoard.MinimapPosition.X + mapCenter.X) / (double)mapBoard.mag), (int)Math.Round((mapBoard.MinimapPosition.Y + mapCenter.Y) / (double)mapBoard.mag));
            if (mapBoard.VRRectangle == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.VRRectangle.X + mapCenter.X, mapBoard.VRRectangle.Y + mapCenter.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);


            switch (UserSettings.SimulateResolution)
            {
            case MapRenderResolution.Res_1024x768:      // 1024x768
                RenderHeight = 768;
                RenderWidth  = 1024;
                break;

            case MapRenderResolution.Res_1280x720:     // 1280x720
                RenderHeight = 720;
                RenderWidth  = 1280;
                break;

            case MapRenderResolution.Res_1366x768:      // 1366x768
                RenderHeight = 768;
                RenderWidth  = 1366;
                break;

            case MapRenderResolution.Res_1920x1080:
                RenderHeight = 1080;
                RenderWidth  = 1920;
                break;

            case MapRenderResolution.Res_800x600:     // 800x600
            default:
                RenderHeight = 600;
                RenderWidth  = 800;
                break;
            }
            double dpi = ScreenDPIUtil.GetScreenScaleFactor();

            // set Form window height & width
            this.Width  = (int)(RenderWidth * dpi);
            this.Height = (int)(RenderHeight * dpi);

#if FULLSCREEN
            pParams.BackBufferWidth    = Math.Max(Width, 1);
            pParams.BackBufferHeight   = Math.Max(Height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.IsFullScreen       = false;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
#else
            pParams.BackBufferWidth    = Math.Max(RenderWidth, 1);
            pParams.BackBufferHeight   = Math.Max(RenderHeight, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.DepthStencilFormat = DepthFormat.Depth24Stencil8;
            pParams.DeviceWindowHandle = Handle;
            pParams.IsFullScreen       = false;
#endif

            // default center
            mapShiftX = vr.Left;
            mapShiftY = vr.Top;


            DxDevice     = MultiBoard.CreateGraphicsDevice(pParams);
            this.minimap = BoardItem.TextureFromBitmap(DxDevice, mapBoard.MiniMap);
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel = BoardItem.TextureFromBitmap(DxDevice, bmp);

            sprite = new SpriteBatch(DxDevice);
        }
        /// <summary>
        /// Background
        /// </summary>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="rx"></param>
        /// <param name="ry"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="a"></param>
        /// <param name="type"></param>
        /// <param name="front"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, int x, int y, int rx, int ry, int cx, int cy, int a, BackgroundType type, bool front, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);
            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                if (source.MSTag == null)
                {
                    source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    usedProps.Add(source);
                }

                Texture2D texture = (Texture2D)source.MSTag;
                if (texture != null)
                {
                    System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(cx, cy, rx, ry, type, a, front, dxobj, flip));
                }
                else
                {
                    throw new Exception("Texture is null for the background property.");
                }
            }
            else if (source is WzSubProperty) //animooted
            {
                WzCanvasProperty frameProp;
                int             i      = 0;
                List <DXObject> frames = new List <DXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int?delay = InfoTool.GetOptionalInt(frameProp["delay"]);
                    if (delay == null)
                    {
                        delay = 100;
                    }

                    if (frameProp.MSTag == null)
                    {
                        frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        usedProps.Add(frameProp);
                    }

                    Texture2D texture = (Texture2D)frameProp.MSTag;
                    if (texture != null)
                    {
                        System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition();
                        frames.Add(new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture, (int)delay));
                    }
                    else
                    {
                        throw new Exception("Texture is null for the animation");
                    }
                }
                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, frames, flip));
            }
            else
            {
                throw new Exception("Unsupported property type in map simulator");
            }
        }