CompassDialog.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. namespace Client.MirScenes.Dialogs
  4. {
  5. public class CompassDialog : MirControl
  6. {
  7. public Point Destination = Point.Empty;
  8. private readonly MirImageControl _image;
  9. public CompassDialog()
  10. {
  11. Location = new Point((Settings.ScreenWidth / 2) - 25, (Settings.ScreenHeight / 2) - 120);
  12. NotControl = true;
  13. Size = new Size(10, 10);
  14. Movable = false;
  15. Sort = true;
  16. _image = new MirImageControl
  17. {
  18. Parent = this,
  19. Index = 0,
  20. Library = Libraries.Prguse2,
  21. NotControl = true,
  22. UseOffSet = true,
  23. Location = new Point(0, 0),
  24. Visible = true
  25. };
  26. }
  27. public void ClearPoint()
  28. {
  29. Destination = Point.Empty;
  30. }
  31. public void SetPoint(Point point)
  32. {
  33. Destination = point;
  34. }
  35. public void Process()
  36. {
  37. if (Destination == Point.Empty || (Destination.X == GameScene.User.CurrentLocation.X && Destination.Y == GameScene.User.CurrentLocation.Y))
  38. {
  39. Visible = false;
  40. return;
  41. }
  42. Visible = true;
  43. float xDiff = GameScene.User.CurrentLocation.X - Destination.X;
  44. float yDiff = GameScene.User.CurrentLocation.Y - Destination.Y;
  45. var angle = Math.Atan2(xDiff * -1, yDiff) * 180 / Math.PI;
  46. var degree = (angle + 360) % 360;
  47. var offset = (double)40 / 360 * degree;
  48. _image.Index = (int)(1470 + Math.Floor(offset));
  49. }
  50. }
  51. }