TestScreens.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using MonoGame.Extended.Screens;
  4. namespace MonoGame.Extended.Tests.Screens;
  5. public class TestScreen : Screen
  6. {
  7. public bool DisposeCalled { get; private set; }
  8. public int UpdateCallCount { get; private set; }
  9. public int DrawCallCount { get; private set; }
  10. public GameTime LastUpdateGameTime { get; private set; }
  11. public GameTime LastDrawGameTime { get; private set; }
  12. public string Name { get; set; }
  13. // Events for tracking order
  14. public event Action<string> OnUpdate;
  15. public event Action<string> OnDraw;
  16. public TestScreen(string name = "TestScreen")
  17. {
  18. Name = name;
  19. }
  20. public override void Dispose()
  21. {
  22. DisposeCalled = true;
  23. base.Dispose();
  24. }
  25. public override void Update(GameTime gameTime)
  26. {
  27. OnUpdate?.Invoke(Name);
  28. UpdateCallCount++;
  29. LastUpdateGameTime = gameTime;
  30. }
  31. public override void Draw(GameTime gameTime)
  32. {
  33. OnDraw?.Invoke(Name);
  34. DrawCallCount++;
  35. LastDrawGameTime = gameTime;
  36. }
  37. public void Reset()
  38. {
  39. DisposeCalled = false;
  40. UpdateCallCount = 0;
  41. DrawCallCount = 0;
  42. LastUpdateGameTime = null;
  43. LastDrawGameTime = null;
  44. OnUpdate = null;
  45. OnDraw = null;
  46. }
  47. }
  48. public class TestGameScreen : GameScreen
  49. {
  50. public TestGameScreen(Game game) : base(game) { }
  51. public override void Update(GameTime gameTime) { }
  52. public override void Draw(GameTime gameTime) { }
  53. }