public void DrawShadow2(int l, int t, int r, int b) { MirImage image = BodyLibrary?.GetImage(ArmourFrame); if (image == null) { return; } int w = (DrawX + image.OffSetX) - l; int h = (DrawY + image.OffSetY) - t; Matrix m = Matrix.Scaling(1F, 0.5f, 0); m.M21 = -0.50F; DXManager.Sprite.Transform = m * Matrix.Translation(DrawX + image.ShadowOffSetX - w + (image.Height) / 2 + h / 2, DrawY + image.ShadowOffSetY - h / 2, 0); DXManager.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.None); float oldOpacity = DXManager.Opacity; if (oldOpacity != 0.5F) { DXManager.SetOpacity(0.5F); } DXManager.Sprite.Draw(DXManager.ScratchTexture, Rectangle.FromLTRB(l, t, r, b), Vector3.Zero, Vector3.Zero, Color.Black); DXManager.Sprite.Transform = Matrix.Identity; DXManager.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point); if (0.5F != oldOpacity) { DXManager.SetOpacity(oldOpacity); } }
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); 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(); }
public Main() { InitializeComponent(); This = this; Application.Idle += Application_Idle; FormClosing += Main_FormClosing; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Selectable, true); FormBorderStyle = Settings.FullScreen ? FormBorderStyle.None : FormBorderStyle.FixedDialog; ClientSize = Settings.ScreenSize; MouseClick += Main_MouseClick; MouseDown += Main_MouseDown; MouseUp += Main_MouseUp; MouseMove += Main_MouseMove; MouseDoubleClick += Main_MouseDoubleClick; KeyPress += Main_KeyPress; KeyDown += Main_KeyDown; KeyUp += Main_KeyUp; Deactivate += Main_Deactivate; DXManager.Create(); }
protected internal virtual void DrawControl() { if (!DrawControlTexture) { return; } if (!TextureValid) { CreateTexture(); } if (ControlTexture == null || ControlTexture.Disposed) { return; } float oldOpacity = DXManager.Opacity; DXManager.SetOpacity(Opacity); DXManager.Sprite.Draw(ControlTexture, new Rectangle(0, 0, Size.Width, Size.Height), Vector3.Zero, new Vector3?(new Vector3((float)(DisplayLocation.X), (float)(DisplayLocation.Y), 0.0f)), Color.White); CMain.DPSCounter++; DXManager.SetOpacity(oldOpacity); CleanTime = CMain.Time + Settings.CleanDelay; }
static void RenderEnviroment() { try { if (DXManager.DeviceLost) { DXManager.AttemptReset(); Thread.Sleep(1); return; } if (MirScene.ActiveScene != null) { MirScene.ActiveScene.Draw(); } DXManager.Device.Present(); } catch (DeviceLostException) { //Do Nothing, Handled Elsewhere. } catch (Exception Ex) { if (Settings.LogErrors) { SaveError(Ex.ToString()); } DXManager.AttemptRecovery(); } }
protected internal override void DrawControl() { base.DrawControl(); if (DrawImage && Library != null) { bool oldGray = DXManager.GrayScale; if (GrayScale) { DXManager.SetGrayscale(true); } if (Blending) { Library.DrawBlend(Index, DisplayLocation, ForeColour, false, BlendingRate); } else { Library.Draw(Index, DisplayLocation, ForeColour, false, Opacity); } if (GrayScale) { DXManager.SetGrayscale(oldGray); } } }
protected internal virtual void DrawControl() { if (!DrawControlTexture) { return; } if (!TextureValid) { CreateTexture(); } if (ControlTexture == null || ControlTexture.Disposed) { return; } float oldOpacity = DXManager.Opacity; DXManager.SetOpacity(Opacity); DXManager.Sprite.Draw2D(ControlTexture, Point.Empty, 0F, DisplayLocation, Color.White); DXManager.SetOpacity(oldOpacity); CleanTime = CMain.Time + Settings.CleanDelay; }
private static void UpdateEnviroment() { if (Time >= _fpsTime) { _fpsTime = Time + 1000; FPS = _fps; _fps = 0; DXManager.Clean(); // Clean once a second. } else { _fps++; } Network.Process(); if (MirScene.ActiveScene != null) { MirScene.ActiveScene.Process(); } for (int i = 0; i < MirAnimatedControl.Animations.Count; i++) { MirAnimatedControl.Animations[i].UpdateOffSet(); } for (int i = 0; i < MirAnimatedButton.Animations.Count; i++) { MirAnimatedButton.Animations[i].UpdateOffSet(); } CreateHintLabel(); CreateDebugLabel(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); foreach (KeyValuePair <LibraryFile, string> pair in Libraries.LibraryList) { if (!File.Exists(@".\" + pair.Value)) { continue; } CEnvir.LibraryList[pair.Key] = new MirLibrary(@".\" + pair.Value); } ConfigReader.Load(); CEnvir.LoadDatabase(); CEnvir.Target = new TargetForm(); DXManager.Create(); DXSoundManager.Create(); DXControl.ActiveScene = new LoginScene(Config.IntroSceneSize); MessagePump.Run(CEnvir.Target, CEnvir.GameLoop); ConfigReader.Save(); CEnvir.Session?.Save(true); CEnvir.Unload(); DXManager.Unload(); DXSoundManager.Unload(); }
public void DrawBlend() { DrawColour = Color.FromArgb(255, 200, 200, 200); DXManager.SetBlend(true); Draw(); DXManager.SetBlend(false); DrawColour = Color.White; }
public void StartGame(S.StartGame p) { StartGameButton.Enabled = true; switch (p.Result) { case 0: MirMessageBox.Show("Starting the game is currently disabled."); break; case 1: MirMessageBox.Show("You are not logged in."); break; case 2: MirMessageBox.Show("Your character could not be found."); break; case 3: MirMessageBox.Show("No active map and/or start point found."); break; case 4: if (p.Resolution < Settings.Resolution || Settings.Resolution == 0) { Settings.Resolution = p.Resolution; } switch (Settings.Resolution) { default: case 1024: Settings.Resolution = 1024; CMain.SetResolution(1024, 768); break; case 1280: CMain.SetResolution(1280, 800); break; case 1366: CMain.SetResolution(1366, 768); break; case 1920: CMain.SetResolution(1920, 1080); break; } ActiveScene = new GameScene(); DXManager.ResetDevice(); Dispose(); break; } }
public override void DrawBlend() { if (BodyLibrary == null) { return; } DXManager.SetBlend(true, 0.60F, BlendMode.HIGHLIGHT); DrawBody(); DXManager.SetBlend(false); }
private void CMain_Load(object sender, EventArgs e) { try { ClientSize = new Size(Settings.ScreenWidth, Settings.ScreenHeight); DXManager.Create(); SoundManager.Create(); } catch (Exception ex) { SaveError(ex.ToString()); } }
public static void SetResolution(int width, int height) { if (Settings.ScreenWidth == width && Settings.ScreenHeight == height) { return; } Settings.ScreenWidth = width; Settings.ScreenHeight = height; Program.Form.ClientSize = new Size(width, height); DXManager.Device.Clear(ClearFlags.Target, Color.Black, 0, 0); DXManager.Device.Present(); DXManager.ResetDevice(); Program.Form.CenterToScreen(); }
//Enviroment:更新系统,更新画面,每秒更新一次,同时计算帧数,这个帧数计算很不准吧?通过空闲调用计算 private static void UpdateEnviroment() { //更新系统,更新画面,每秒更新一次,同时计算帧数 if (Time >= _fpsTime) { _fpsTime = Time + 1000; FPS = _fps; _fps = 0; DXManager.Clean(); // Clean once a second. //这里加入游戏名称的更新 if (GameScene.User != null && GameScene.User.Name != null && Program.Form.Text != null && !Program.Form.Text.Contains(GameScene.User.Name)) { Program.Form.Text = Settings.serverName != null ? Settings.serverName + " -- " + GameScene.User.Name : "夜火传奇"; } } else { _fps++; } //网络数据处理 Network.Process(); //场景处理 if (MirScene.ActiveScene != null) { MirScene.ActiveScene.Process(); } //动画要一直更新么 for (int i = 0; i < MirAnimatedControl.Animations.Count; i++) { MirAnimatedControl.Animations[i].UpdateOffSet(); } for (int i = 0; i < MirAnimatedButton.Animations.Count; i++) { MirAnimatedButton.Animations[i].UpdateOffSet(); } //这个是鼠标移动到物体,菜单上显示的提示信息 CreateHintLabel(); //FPS等信息输出 CreateDebugLabel(); }
private static void ToggleFullScreen() { Settings.FullScreen = !Settings.FullScreen; Program.Form.FormBorderStyle = Settings.FullScreen ? FormBorderStyle.None : FormBorderStyle.FixedDialog; DXManager.Parameters.Windowed = !Settings.FullScreen; Program.Form.ClientSize = new Size(Settings.ScreenWidth, Settings.ScreenHeight); DXManager.ResetDevice(); if (MirScene.ActiveScene == GameScene.Scene) { GameScene.Scene.MapControl.FloorValid = false; } GameScene.Scene.TextureValid = false; }
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(); }
private void CMain_Load(object sender, EventArgs e) { this.Text = GameLanguage.GameName; try { ClientSize = new Size(Settings.ScreenWidth, Settings.ScreenHeight); LoadMouseCursors(); SetMouseCursor(MouseCursor.Default); DXManager.Create(); SoundManager.Create(); CenterToScreen(); } catch (Exception ex) { SaveError(ex.ToString()); } }
protected virtual void DrawControl() { if (!DrawControlTexture) { return; } if (!TextureValid || ControlTexture == null || ControlTexture.Disposed) { if (!CreateTexture()) { return; } } float OldOpacity = DXManager.Opacity; DXManager.SetOpacity(Opacity); DXManager.Sprite.Draw2D(ControlTexture, Point.Empty, 0F, DisplayLocation, Color.White); DXManager.SetOpacity(OldOpacity); }
protected internal virtual void DrawControl() { if (!DrawControlTexture) { return; } if (!TextureValid) { CreateTexture(); } if (ControlTexture == null || ControlTexture.Disposed) { return; } DXManager.DrawOpaque(ControlTexture, new Rectangle(0, 0, Size.Width, Size.Height), new Vector3?(new Vector3((float)(DisplayLocation.X), (float)(DisplayLocation.Y), 0.0f)), Color.White, Opacity); CleanTime = CMain.Time + Settings.CleanDelay; }
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(); } }
protected internal override void DrawControl() { base.DrawControl(); if (DrawImage && Library != null) { if (GrayScale) { DXManager.SetGrayscale(1F, Color.White); } else if (Blending) { Library.DrawBlend(Index, DisplayLocation, ForeColour, false, BlendingRate); } Library.Draw(Index, DisplayLocation, ForeColour, false, Opacity); if (GrayScale) { DXManager.SetNormal(1F, Color.White); } } }
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); }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); CEnvir.Shift = e.Shift; CEnvir.Alt = e.Alt; CEnvir.Ctrl = e.Control; try { if (e.Alt && e.KeyCode == Keys.Enter) { DXManager.ToggleFullScreen(); return; } DXControl.ActiveScene?.OnKeyDown(e); e.Handled = true; } catch (Exception ex) { CEnvir.SaveError(ex.ToString()); } }
public virtual void DrawBlend() { DXManager.SetBlend(true, 0.3F); //0.8 Draw(); DXManager.SetBlend(false); }
private void SaveSettings(object o, MouseEventArgs e) { if (Config.FullScreen != FullScreenCheckBox.Checked) { DXManager.ToggleFullScreen(); } if (GameSizeComboBox.SelectedItem is Size && Config.GameSize != (Size)GameSizeComboBox.SelectedItem) { Config.GameSize = (Size)GameSizeComboBox.SelectedItem; if (ActiveScene is GameScene) { ActiveScene.Size = Config.GameSize; DXManager.SetResolution(ActiveScene.Size); } } if (LanguageComboBox.SelectedItem is string && Config.Language != (string)LanguageComboBox.SelectedItem) { Config.Language = (string)LanguageComboBox.SelectedItem; if (CEnvir.Connection != null && CEnvir.Connection.ServerConnected) { CEnvir.Enqueue(new C.SelectLanguage { Language = Config.Language }); } } if (Config.VSync != VSyncCheckBox.Checked) { Config.VSync = VSyncCheckBox.Checked; DXManager.ResetDevice(); } Config.LimitFPS = LimitFPSCheckBox.Checked; Config.ClipMouse = ClipMouseCheckBox.Checked; Config.DebugLabel = DebugLabelCheckBox.Checked; DebugLabel.IsVisible = Config.DebugLabel; PingLabel.IsVisible = Config.DebugLabel; if (Config.SoundInBackground != BackgroundSoundBox.Checked) { Config.SoundInBackground = BackgroundSoundBox.Checked; DXSoundManager.UpdateFlags(); } bool volumeChanged = false; if (Config.SystemVolume != SystemVolumeBox.Value) { Config.SystemVolume = (int)SystemVolumeBox.Value; volumeChanged = true; } if (Config.MusicVolume != MusicVolumeBox.Value) { Config.MusicVolume = (int)MusicVolumeBox.Value; volumeChanged = true; } if (Config.PlayerVolume != PlayerVolumeBox.Value) { Config.PlayerVolume = (int)PlayerVolumeBox.Value; volumeChanged = true; } if (Config.MonsterVolume != MonsterVolumeBox.Value) { Config.MonsterVolume = (int)MonsterVolumeBox.Value; volumeChanged = true; } if (Config.MagicVolume != SpellVolumeBox.Value) { Config.MagicVolume = (int)SpellVolumeBox.Value; volumeChanged = true; } Config.ShowItemNames = ItemNameCheckBox.Checked; Config.ShowMonsterNames = MonsterNameCheckBox.Checked; Config.ShowPlayerNames = PlayerNameCheckBox.Checked; Config.ShowUserHealth = UserHealthCheckBox.Checked; Config.ShowMonsterHealth = MonsterHealthCheckBox.Checked; Config.ShowDamageNumbers = DamageNumbersCheckBox.Checked; Config.EscapeCloseAll = EscapeCloseAllCheckBox.Checked; Config.ShiftOpenChat = ShiftOpenChatCheckBox.Checked; Config.RightClickDeTarget = RightClickDeTargetCheckBox.Checked; Config.MonsterBoxVisible = MonsterBoxVisibleCheckBox.Checked; Config.LogChat = LogChatCheckBox.Checked; Config.DrawEffects = DrawEffectsCheckBox.Checked; if (volumeChanged) { DXSoundManager.AdjustVolume(); } Config.UseNetworkConfig = UseNetworkConfigCheckBox.Checked; Config.IPAddress = IPAddressTextBox.TextBox.Text; Config.Port = (int)PortBox.Value; bool coloursChanged = false; if (Config.LocalTextColour != LocalColourBox.BackColour) { Config.LocalTextColour = LocalColourBox.BackColour; coloursChanged = true; } if (Config.GMWhisperInTextColour != GMWhisperInColourBox.BackColour) { Config.GMWhisperInTextColour = GMWhisperInColourBox.BackColour; coloursChanged = true; } if (Config.WhisperInTextColour != WhisperInColourBox.BackColour) { Config.WhisperInTextColour = WhisperInColourBox.BackColour; coloursChanged = true; } if (Config.WhisperOutTextColour != WhisperOutColourBox.BackColour) { Config.WhisperOutTextColour = WhisperOutColourBox.BackColour; coloursChanged = true; } if (Config.GroupTextColour != GroupColourBox.BackColour) { Config.GroupTextColour = GroupColourBox.BackColour; coloursChanged = true; } if (Config.GuildTextColour != GuildColourBox.BackColour) { Config.GuildTextColour = GuildColourBox.BackColour; coloursChanged = true; } if (Config.ShoutTextColour != ShoutColourBox.BackColour) { Config.ShoutTextColour = ShoutColourBox.BackColour; coloursChanged = true; } if (Config.GlobalTextColour != GlobalColourBox.BackColour) { Config.GlobalTextColour = GlobalColourBox.BackColour; coloursChanged = true; } if (Config.ObserverTextColour != ObserverColourBox.BackColour) { Config.ObserverTextColour = ObserverColourBox.BackColour; coloursChanged = true; } if (Config.HintTextColour != HintColourBox.BackColour) { Config.HintTextColour = HintColourBox.BackColour; coloursChanged = true; } if (Config.SystemTextColour != SystemColourBox.BackColour) { Config.SystemTextColour = SystemColourBox.BackColour; coloursChanged = true; } if (Config.GainsTextColour != GainsColourBox.BackColour) { Config.GainsTextColour = GainsColourBox.BackColour; coloursChanged = true; } if (Config.AnnouncementTextColour != AnnouncementColourBox.BackColour) { Config.AnnouncementTextColour = AnnouncementColourBox.BackColour; coloursChanged = true; } if (coloursChanged && GameScene.Game != null) { foreach (ChatTab tab in ChatTab.Tabs) { tab.UpdateColours(); } } }
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); } }
public void StartGame(S.StartGame p) { StartGameButton.Enabled = true; if (p.Resolution < Settings.Resolution || Settings.Resolution == 0) { Settings.Resolution = p.Resolution; } if (p.Resolution < 1024 || Settings.Resolution < 1024) { Settings.Resolution = 800; } else if (p.Resolution < 1366 || Settings.Resolution < 1280) { Settings.Resolution = 1024; } else if (p.Resolution < 1366 || Settings.Resolution < 1366) { Settings.Resolution = 1280; //not adding an extra setting for 1280 on server cause well it just depends on the aspect ratio of your screen } else if (p.Resolution >= 1366 && Settings.Resolution >= 1366) { Settings.Resolution = 1366; } switch (p.Result) { case 0: MirMessageBox.Show("Starting the game is currently disabled."); break; case 1: MirMessageBox.Show("You are not logged in."); break; case 2: MirMessageBox.Show("Your character could not be found."); break; case 3: MirMessageBox.Show("No active map and/or start point found."); break; case 4: if (Settings.Resolution == 1024) { CMain.SetResolution(1024, 768); } else if (Settings.Resolution == 1280) { CMain.SetResolution(1280, 800); } else if (Settings.Resolution == 1366) { CMain.SetResolution(1366, 768); } ActiveScene = new GameScene(); DXManager.ResetDevice(); Dispose(); break; } }
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); }
public ShaderManager(Device device, DXManager dxman) { Device = device; DXMan = dxman; Lines = new LineShader(device); RasterizerStateDescription rsd = new RasterizerStateDescription() { CullMode = CullMode.Back, DepthBias = 0, DepthBiasClamp = 0.0f, FillMode = FillMode.Solid, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = true, IsFrontCounterClockwise = true, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0.0f }; rsSolid = new RasterizerState(device, rsd); rsd.FillMode = FillMode.Wireframe; rsWireframe = new RasterizerState(device, rsd); rsd.CullMode = CullMode.None; rsWireframeDblSided = new RasterizerState(device, rsd); rsd.FillMode = FillMode.Solid; rsSolidDblSided = new RasterizerState(device, rsd); BlendStateDescription bsd = new BlendStateDescription() { AlphaToCoverageEnable = false,//true, IndependentBlendEnable = false, }; bsd.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; bsd.RenderTarget[0].BlendOperation = BlendOperation.Add; bsd.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; bsd.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; bsd.RenderTarget[0].IsBlendEnabled = true; bsd.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; bsd.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero; bsd.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; bsd.RenderTarget[1] = bsd.RenderTarget[0]; bsd.RenderTarget[2] = bsd.RenderTarget[0]; bsd.RenderTarget[3] = bsd.RenderTarget[0]; bsDefault = new BlendState(device, bsd); bsd.AlphaToCoverageEnable = true; bsAlpha = new BlendState(device, bsd); bsd.AlphaToCoverageEnable = false; bsd.RenderTarget[0].DestinationBlend = BlendOption.One; bsAdd = new BlendState(device, bsd); DepthStencilStateDescription dsd = new DepthStencilStateDescription() { BackFace = new DepthStencilOperationDescription() { Comparison = Comparison.GreaterEqual, DepthFailOperation = StencilOperation.Zero, FailOperation = StencilOperation.Zero, PassOperation = StencilOperation.Zero, }, DepthComparison = Comparison.GreaterEqual, DepthWriteMask = DepthWriteMask.All, FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.GreaterEqual, DepthFailOperation = StencilOperation.Zero, FailOperation = StencilOperation.Zero, PassOperation = StencilOperation.Zero }, IsDepthEnabled = true, IsStencilEnabled = false, StencilReadMask = 0, StencilWriteMask = 0 }; dsEnabled = new DepthStencilState(device, dsd); dsd.DepthWriteMask = DepthWriteMask.Zero; dsDisableWrite = new DepthStencilState(device, dsd); dsd.DepthComparison = Comparison.LessEqual; dsDisableWriteRev = new DepthStencilState(device, dsd); dsd.DepthComparison = Comparison.Always; dsDisableComp = new DepthStencilState(device, dsd); dsd.IsDepthEnabled = false; dsDisableAll = new DepthStencilState(device, dsd); }