Пример #1
0
        protected virtual void CreateTexture()
        {
            try
            {
                if (ControlTexture != null && !ControlTexture.Disposed && Size != TextureSize)
                {
                    ControlTexture.Dispose();
                }

                if (ControlTexture == null || ControlTexture.Disposed)
                {
                    DXManager.ControlList.Add(this);
                    ControlTexture            = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                    ControlTexture.Disposing += ControlTexture_Disposing;
                    TextureSize = Size;
                }

                Surface oldSurface = DXManager.CurrentSurface;
                Surface surface    = ControlTexture.GetSurfaceLevel(0);
                DXManager.SetSurface(surface);
                DXManager.Device.Clear(ClearFlags.Target, BackColour, 0, 0);
                DXManager.SetSurface(oldSurface);

                TextureValid = true;
                surface.Dispose();
            }
            catch (Exception ex)
            {
                var tmp = this.Parent;
                CMain.SaveError(ex.ToString());
            }
        }
Пример #2
0
        protected override void CreateTexture()
        {
            if (ControlTexture != null && !ControlTexture.Disposed && Size != TextureSize)
            {
                ControlTexture.Dispose();
            }

            if (ControlTexture == null || ControlTexture.Disposed)
            {
                DXManager.ControlList.Add(this);
                ControlTexture            = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                ControlTexture.Disposing += ControlTexture_Disposing;
                TextureSize = Size;
            }
            Surface oldSurface = DXManager.CurrentSurface;
            Surface surface    = ControlTexture.GetSurfaceLevel(0);

            DXManager.SetSurface(surface);


            DXManager.Device.Clear(ClearFlags.Target, BackColour, 0, 0);

            BeforeDrawControl();
            DrawChildControls();
            AfterDrawControl();

            DXManager.Sprite.Flush();


            DXManager.SetSurface(oldSurface);
            TextureValid = true;
            surface.Dispose();
        }
Пример #3
0
        protected virtual void CreateTexture()
        {
            if (ControlTexture == null || ControlTexture.IsDisposed)
            {
                DXManager.ControlList.Add(this);
                ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                TextureSize    = Size;
            }

            Surface oldSurface = DXManager.CurrentSurface;
            Surface surface    = ControlTexture.GetSurfaceLevel(0);

            DXManager.SetSurface(surface);
            DXManager.Device.Clear(ClearFlags.Target, BackColour.ToRawColorBGRA(), 0, 0);
            DXManager.SetSurface(oldSurface);

            TextureValid = true;
            surface.Dispose();
        }
Пример #4
0
        private static void RenderEnvironment()
        {
            try
            {
                if (DXManager.DeviceLost)
                {
                    DXManager.AttemptReset();
                    Thread.Sleep(1);
                    return;
                }
                else
                {
                    DXManager.Device.Clear(ClearFlags.Target, Color.CornflowerBlue, 0, 0);
                    DXManager.Device.BeginScene();
                    DXManager.Sprite.Begin(SpriteFlags.AlphaBlend);
                    DXManager.SetSurface(DXManager.MainSurface);

                    if (MirScene.ActiveScene != null)
                    {
                        MirScene.ActiveScene.Draw();
                    }

                    DXManager.Sprite.End();
                    DXManager.Device.EndScene();
                    DXManager.Device.Present();
                }
            }
            catch (Direct3D9Exception ex)
            {
                DXManager.DeviceLost = true;
            }
            catch (Exception ex)
            {
                SaveError(ex.ToString());

                DXManager.AttemptRecovery();
            }
        }
Пример #5
0
        protected virtual bool CreateTexture()
        {
            if (Size == Size.Empty)
            {
                return(false);
            }

            if (ControlTexture != null && !ControlTexture.Disposed)
            {
                ControlTexture.Dispose();
            }

            ControlTexture            = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            ControlTexture.Disposing += ControlTexture_Disposing;

            Surface OldSurface = DXManager.CurrentSurface;

            DXManager.SetSurface(ControlTexture.GetSurfaceLevel(0));
            DXManager.Device.Clear(ClearFlags.Target, BackColor, 0, 0);
            DXManager.SetSurface(OldSurface);

            TextureValid = true;
            return(true);
        }
Пример #6
0
        public void DrawBody(bool shadow)
        {
            Surface oldSurface = DXManager.CurrentSurface;

            DXManager.SetSurface(DXManager.ScratchSurface);
            DXManager.Device.Clear(ClearFlags.Target, 0, 0, 0);
            DXManager.Sprite.Flush();

            int l = int.MaxValue, t = int.MaxValue, r = int.MinValue, b = int.MinValue;


            MirImage image;

            switch (Direction)
            {
            case MirDirection.Up:
            case MirDirection.DownLeft:
            case MirDirection.Left:
            case MirDirection.UpLeft:
                if (!DrawWeapon)
                {
                    break;
                }
                image = WeaponLibrary1?.GetImage(WeaponFrame);
                if (image == null)
                {
                    break;
                }

                WeaponLibrary1.Draw(WeaponFrame, DrawX, DrawY, Color.White, true, 1F, ImageType.Image);

                l = Math.Min(l, DrawX + image.OffSetX);
                t = Math.Min(t, DrawY + image.OffSetY);
                r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                b = Math.Max(b, image.Height + DrawY + image.OffSetY);
                break;

            default:
                if (!DrawWeapon)
                {
                    break;
                }
                image = WeaponLibrary2?.GetImage(WeaponFrame);
                if (image == null)
                {
                    break;
                }

                WeaponLibrary2.Draw(WeaponFrame, DrawX, DrawY, Color.White, true, 1F, ImageType.Image);

                l = Math.Min(l, DrawX + image.OffSetX);
                t = Math.Min(t, DrawY + image.OffSetY);
                r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                b = Math.Max(b, image.Height + DrawY + image.OffSetY);
                break;
            }


            image = BodyLibrary?.GetImage(ArmourFrame);
            if (image != null)
            {
                BodyLibrary.Draw(ArmourFrame, DrawX, DrawY, Color.White, true, 1F, ImageType.Image);

                if (ArmourColour.ToArgb() != 0)
                {
                    BodyLibrary.Draw(ArmourFrame, DrawX, DrawY, ArmourColour, true, 1F, ImageType.Overlay);
                }

                l = Math.Min(l, DrawX + image.OffSetX);
                t = Math.Min(t, DrawY + image.OffSetY);
                r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                b = Math.Max(b, image.Height + DrawY + image.OffSetY);
            }


            if (HelmetShape > 0)
            {
                image = HelmetLibrary?.GetImage(HelmetFrame);
                if (image != null)
                {
                    HelmetLibrary.Draw(HelmetFrame, DrawX, DrawY, Color.White, true, 1F, ImageType.Image);

                    l = Math.Min(l, DrawX + image.OffSetX);
                    t = Math.Min(t, DrawY + image.OffSetY);
                    r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                    b = Math.Max(b, image.Height + DrawY + image.OffSetY);
                }
            }
            else
            {
                image = HairLibrary.GetImage(HairFrame);
                if (HairType > 0 && image != null)
                {
                    HairLibrary.Draw(HairFrame, DrawX, DrawY, HairColour, true, 1F, ImageType.Image);

                    l = Math.Min(l, DrawX + image.OffSetX);
                    t = Math.Min(t, DrawY + image.OffSetY);
                    r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                    b = Math.Max(b, image.Height + DrawY + image.OffSetY);
                }
            }

            switch (Direction)
            {
            case MirDirection.UpRight:
            case MirDirection.Right:
            case MirDirection.DownRight:
            case MirDirection.Down:
                if (!DrawWeapon)
                {
                    break;
                }
                image = WeaponLibrary1?.GetImage(WeaponFrame);
                if (image == null)
                {
                    break;
                }

                WeaponLibrary1.Draw(WeaponFrame, DrawX, DrawY, Color.White, true, 1F, ImageType.Image);

                l = Math.Min(l, DrawX + image.OffSetX);
                t = Math.Min(t, DrawY + image.OffSetY);
                r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                b = Math.Max(b, image.Height + DrawY + image.OffSetY);
                break;

            default:
                if (!DrawWeapon)
                {
                    break;
                }
                image = WeaponLibrary2?.GetImage(WeaponFrame);
                if (image == null)
                {
                    break;
                }

                WeaponLibrary2.Draw(WeaponFrame, DrawX, DrawY, Color.White, true, 1F, ImageType.Image);

                l = Math.Min(l, DrawX + image.OffSetX);
                t = Math.Min(t, DrawY + image.OffSetY);
                r = Math.Max(r, image.Width + DrawX + image.OffSetX);
                b = Math.Max(b, image.Height + DrawY + image.OffSetY);
                break;
            }

            DXManager.SetSurface(oldSurface);
            float oldOpacity = DXManager.Opacity;

            if (shadow)
            {
                switch (CurrentAnimation)
                {
                case MirAnimation.HorseStanding:
                case MirAnimation.HorseWalking:
                case MirAnimation.HorseRunning:
                case MirAnimation.HorseStruck:
                    HorseLibrary?.Draw(HorseFrame, DrawX, DrawY, Color.Black, true, 0.5F, ImageType.Shadow);
                    break;

                default:
                    DrawShadow2(l, t, r, b);
                    break;
                }
            }

            if (oldOpacity != Opacity && !DXManager.Blending)
            {
                DXManager.SetOpacity(Opacity);
            }


            switch (CurrentAnimation)
            {
            case MirAnimation.HorseStanding:
            case MirAnimation.HorseWalking:
            case MirAnimation.HorseRunning:
            case MirAnimation.HorseStruck:

                switch (HorseShape)
                {
                case 0:
                    HorseLibrary?.Draw(HorseFrame, DrawX, DrawY, Color.White, true, Opacity, ImageType.Image);
                    break;

                case 1:
                case 2:
                case 3:
                    HorseShapeLibrary?.Draw(HorseFrame, DrawX, DrawY, Color.White, true, Opacity, ImageType.Image);
                    break;

                case 4:
                    HorseShapeLibrary?.Draw(DrawFrame, DrawX, DrawY, Color.White, true, Opacity, ImageType.Image);
                    break;

                case 5:
                    HorseShapeLibrary?.Draw(DrawFrame, DrawX, DrawY, Color.White, true, Opacity, ImageType.Image);
                    if (shadow)
                    {
                        HorseShapeLibrary2?.DrawBlend(DrawFrame, DrawX, DrawY, Color.White, true, Opacity, ImageType.Image);
                    }
                    break;
                }

                break;
            }



            DXManager.Sprite.Draw(DXManager.ScratchTexture, Rectangle.FromLTRB(l, t, r, b), Vector3.Zero, new Vector3(l, t, 0), DrawColour);
            CEnvir.DPSCounter++;
            if (oldOpacity != Opacity && !DXManager.Blending)
            {
                DXManager.SetOpacity(oldOpacity);
            }
        }
Пример #7
0
        protected override bool CreateTexture()
        {
            if (string.IsNullOrEmpty(Text) || !Main.This.Created)
            {
                return(false);
            }

            if (DXFont == null || DXFont.Disposed)
            {
                if (Font != null)
                {
                    DXFont = new Microsoft.DirectX.Direct3D.Font(DXManager.Device, Font);
                }
                else
                {
                    return(false);
                }
            }

            if (AutoSize)
            {
                Size = DXFont.MeasureString(null, Text, DrawFormat, ForeColor).Size;
                if (OutLine && Size != Size.Empty)
                {
                    Size = new Size(Size.Width + 2, Size.Height + 2);
                }
            }

            if (Size == Size.Empty)
            {
                return(false);
            }


            if (ControlTexture != null && !ControlTexture.Disposed)
            {
                ControlTexture.Dispose();
            }

            ControlTexture            = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            ControlTexture.Disposing += ControlTexture_Disposing;

            Surface OldSurface = DXManager.CurrentSurface;

            DXManager.SetSurface(ControlTexture.GetSurfaceLevel(0));
            DXManager.Device.Clear(ClearFlags.Target, BackColor, 0, 0);

            Point TempPoint = Point.Empty;

            if (OutLine)
            {
                TempPoint.X = 1;
                TempPoint.Y = 0;
                if (DrawFormat == DrawTextFormat.None)
                {
                    DXFont.DrawText(null, Text, TempPoint, OutLineColor);
                }
                else
                {
                    DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor);
                }

                TempPoint.X = 0;
                TempPoint.Y = 1;
                if (DrawFormat == DrawTextFormat.None)
                {
                    DXFont.DrawText(null, Text, TempPoint, OutLineColor);
                }
                else
                {
                    DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor);
                }

                TempPoint.X = 2;
                TempPoint.Y = 1;
                if (DrawFormat == DrawTextFormat.None)
                {
                    DXFont.DrawText(null, Text, TempPoint, OutLineColor);
                }
                else
                {
                    DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor);
                }

                TempPoint.X = 1;
                TempPoint.Y = 2;
                if (DrawFormat == DrawTextFormat.None)
                {
                    DXFont.DrawText(null, Text, TempPoint, OutLineColor);
                }
                else
                {
                    DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor);
                }

                TempPoint = new Point(1, 1);
            }

            if (DrawFormat == DrawTextFormat.None)
            {
                DXFont.DrawText(null, Text, TempPoint, ForeColor);
            }
            else
            {
                DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, ForeColor);
            }

            DXManager.SetSurface(OldSurface);

            TextureValid = true;
            return(true);
        }
Пример #8
0
        private static void RenderLights()
        {
            if (DXManager.Lights == null || DXManager.Lights.Count == 0)
            {
                return;
            }

            if (LightTexture == null || LightTexture.Disposed)
            {
                LightTexture            = new Texture(DXManager.Device, Settings.ScreenSize.Width, Settings.ScreenSize.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                LightTexture.Disposing += new EventHandler(LightTexture_Disposing);
                LightSurface            = LightTexture.GetSurfaceLevel(0);
            }

            DXManager.Sprite.Flush();

            Surface OldSurface = DXManager.CurrentSurface;

            DXManager.SetSurface(LightSurface);
            DXManager.Device.Clear(ClearFlags.Target, MapInfo.Lights == LightSetting.Night ? Color.Black : Color.FromArgb(255, 50, 50, 50), 0, 0);


            DXManager.SetBlend(true);

            int   Light;
            Point Location;

            for (int I = 0; I < ObjectList.Count; I++)
            {
                if (ObjectList[I].Light > 0)
                {
                    Light = ObjectList[I].Light;

                    if (Light >= DXManager.Lights.Count)
                    {
                        Light = DXManager.Lights.Count - 1;
                    }

                    Location = ObjectList[I].DisplayRectangle.Location;
                    Location.Offset(((Light + 1) * -65 + Globals.CellWidth) / 2, ((Light + 1) * -50 + Globals.CellHeight) / 2);


                    if (DXManager.Lights[Light] != null && !DXManager.Lights[Light].Disposed)
                    {
                        DXManager.Sprite.Draw2D(DXManager.Lights[Light], PointF.Empty, 0, Location, Color.WhiteSmoke);
                    }
                }
            }


            for (int Y = MapObject.User.Location.Y - ViewRangeY - 5; Y <= MapObject.User.Location.Y + ViewRangeY + 5; Y++)
            {
                if (Y < 0)
                {
                    continue;
                }
                if (Y >= MapSize.Height)
                {
                    break;
                }
                for (int X = MapObject.User.Location.X - ViewRangeX - 5; X < MapObject.User.Location.X + ViewRangeX + 5; X++)
                {
                    if (X < 0)
                    {
                        continue;
                    }
                    if (X >= MapSize.Width)
                    {
                        break;
                    }
                    int ImageIndex = (M2CellInfo[X, Y].FrontImage & 0x7FFF) - 1;
                    if (M2CellInfo[X, Y].Light > 0 && M2CellInfo[X, Y].Light < 10)
                    {
                        Light = M2CellInfo[X, Y].Light * 3;
                        int  FileIndex = M2CellInfo[X, Y].FileIndex;
                        Size S         = Libraries.Objects[FileIndex].GetSize(ImageIndex);
                        Location = new Point(
                            (X + Settings.PlayerOffSet.X - MapObject.User.MovePoint.X) * Globals.CellWidth + MapObject.User.MovingOffSet.X,
                            (Y + Settings.PlayerOffSet.Y - MapObject.User.MovePoint.Y) * Globals.CellHeight + MapObject.User.MovingOffSet.Y + 32);// - S.Height);
                        Location.Offset(((Light + 1) * -65 + Globals.CellWidth) / 2, ((Light + 1) * -50 + Globals.CellHeight) / 2);

                        if (M2CellInfo[X, Y].AnimationFrame > 0)
                        {
                            Location.Offset(Libraries.Objects[FileIndex].GetOffSet(ImageIndex));
                        }

                        if (Light > DXManager.Lights.Count)
                        {
                            Light = DXManager.Lights.Count - 1;
                        }

                        if (DXManager.Lights[Light] != null && !DXManager.Lights[Light].Disposed)
                        {
                            DXManager.Sprite.Draw2D(DXManager.Lights[Light], PointF.Empty, 0, Location, Color.WhiteSmoke);
                        }
                    }
                }
            }

            DXManager.SetBlend(false);
            DXManager.Sprite.Flush();
            DXManager.SetSurface(OldSurface);

            //Draw Light Scene
            DXManager.Device.RenderState.SourceBlend      = Blend.Zero;
            DXManager.Device.RenderState.DestinationBlend = Blend.SourceColor;

            DXManager.Sprite.Draw2D(LightTexture, PointF.Empty, 0, PointF.Empty, Color.White);
            DXManager.Sprite.End();

            DXManager.Sprite.Begin(SpriteFlags.AlphaBlend);
        }
Пример #9
0
        private static void RenderFloor()
        {
            if (FloorTexture == null || FloorTexture.Disposed)
            {
                FloorTexture = new Texture(DXManager.Device, Settings.ScreenSize.Width,
                                           Settings.ScreenSize.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                FloorTexture.Disposing += new EventHandler(FloorTexture_Disposing);
                FloorSurface            = FloorTexture.GetSurfaceLevel(0);
            }


            Surface OldSurface = DXManager.CurrentSurface;

            DXManager.SetSurface(FloorSurface);
            DXManager.Device.Clear(ClearFlags.Target, Color.Black, 0, 0);

            Point P;
            Size  S;
            int   ImageIndex, FileIndex;

            #region Big Tiles
            for (int Y = MapObject.User.Location.Y - ViewRangeY; Y <= MapObject.User.Location.Y + ViewRangeY + 2; Y++)
            {
                if (Y < 0 || Y % 2 == 1)
                {
                    continue;
                }
                if (Y >= MapSize.Height)
                {
                    break;
                }
                for (int X = MapObject.User.Location.X - ViewRangeX; X < MapObject.User.Location.X + ViewRangeX; X++)
                {
                    if (X < 0 || X % 2 == 1)
                    {
                        continue;
                    }
                    if (X >= MapSize.Width)
                    {
                        break;
                    }

                    if (M2CellInfo[X, Y].BackImage == 0)
                    {
                        continue;
                    }
                    ImageIndex = (M2CellInfo[X, Y].BackImage & 0x7FFF);

                    P = new Point((X + Settings.PlayerOffSet.X - MapObject.User.MovePoint.X) * Globals.CellWidth + MapObject.User.MovingOffSet.X, (Y + Settings.PlayerOffSet.Y - MapObject.User.MovePoint.Y) * Globals.CellHeight + MapObject.User.MovingOffSet.Y);
                    Libraries.Tiles.Draw(ImageIndex - 1, P, Color.White, 1F, false);
                }
            }
            #endregion
            #region Small Tiles
            for (int Y = MapObject.User.Location.Y - ViewRangeY; Y <= MapObject.User.Location.Y + ViewRangeY + 2; Y++)
            {
                if (Y < 0)
                {
                    continue;
                }
                if (Y >= MapSize.Height)
                {
                    break;
                }
                for (int X = MapObject.User.Location.X - ViewRangeX; X < MapObject.User.Location.X + ViewRangeX; X++)
                {
                    if (X < 0)
                    {
                        continue;
                    }
                    if (X >= MapSize.Width)
                    {
                        break;
                    }
                    ImageIndex = M2CellInfo[X, Y].MiddleImage;

                    if (ImageIndex-- > 0)
                    {
                        P = new Point((X + Settings.PlayerOffSet.X - MapObject.User.MovePoint.X) * Globals.CellWidth + MapObject.User.MovingOffSet.X, (Y + Settings.PlayerOffSet.Y - MapObject.User.MovePoint.Y) * Globals.CellHeight + MapObject.User.MovingOffSet.Y);
                        Libraries.SmallTiles.Draw(ImageIndex, P, Color.White, 1F, false);
                    }
                }
            }
            #endregion
            #region Objects
            for (int Y = MapObject.User.Location.Y - ViewRangeY; Y <= MapObject.User.Location.Y + ViewRangeY + 2; Y++)
            {
                if (Y < 0)
                {
                    continue;
                }
                if (Y >= MapSize.Height)
                {
                    break;
                }
                for (int X = MapObject.User.Location.X - ViewRangeX; X < MapObject.User.Location.X + ViewRangeX; X++)
                {
                    if (X < 0)
                    {
                        continue;
                    }
                    if (X >= MapSize.Width)
                    {
                        break;
                    }
                    ImageIndex = M2CellInfo[X, Y].FrontImage & 0x7FFF;
                    if (ImageIndex-- > 0)
                    {
                        FileIndex = M2CellInfo[X, Y].FileIndex;
                        S         = Libraries.Objects[FileIndex].GetSize(ImageIndex);

                        if (S.Width != Globals.CellWidth || S.Height != Globals.CellHeight)
                        {
                            continue;
                        }

                        P = new Point((X + Settings.PlayerOffSet.X - MapObject.User.MovePoint.X) * Globals.CellWidth + MapObject.User.MovingOffSet.X, (Y + Settings.PlayerOffSet.Y - MapObject.User.MovePoint.Y) * Globals.CellHeight + MapObject.User.MovingOffSet.Y);
                        Libraries.Objects[FileIndex].Draw(ImageIndex, P, Color.White, 1F, false);
                    }
                }
            }
            #endregion

            DXManager.Sprite.Flush();
            DXManager.SetSurface(OldSurface);

            ValidFloor  = true;
            FloorOffSet = MapObject.User.MovingOffSet;
        }