Example #1
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);
        }
        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);
        }