Small.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Microsoft.Xna.Framework;
  2. namespace OpenVIII.IGMData.Dialog
  3. {
  4. public class Small : IGMData.Base, I_Data<FF8String>
  5. {
  6. #region Fields
  7. private Rectangle _bounding;
  8. private Box_Options _options;
  9. #endregion Fields
  10. #region Properties
  11. public FF8String Data
  12. {
  13. get => ((IGMDataItem.Box)CONTAINER).Data; set
  14. {
  15. ((IGMDataItem.Box)CONTAINER).Data = value;
  16. Reposition();
  17. }
  18. }
  19. #endregion Properties
  20. #region Methods
  21. public static T Create<T>(FF8String data, int x, int y, Icons.ID? title = null, Box_Options options = Box_Options.Default, Rectangle? bounding = null) where T : Small, new()
  22. {
  23. T r = Create<T>(container: new IGMDataItem.Box { Data = data, Pos = new Rectangle(x, y, 0, 0), Title = title, Options = Box_Options.Center | Box_Options.Middle });
  24. r._options = options;
  25. // probably won't work as static size is set in update. And this may run before it's set.
  26. r._bounding = bounding ?? new Rectangle(Point.Zero, Menu.StaticSize.ToPoint());
  27. r.Reposition();
  28. return r;
  29. }
  30. public static Small Create(FF8String data, int x, int y, Icons.ID? title = null, Box_Options options = Box_Options.Default, Rectangle? bounding = null)
  31. => Create<Small>(data, x, y, title, options, bounding);
  32. private void Reposition()
  33. {
  34. if (CONTAINER.GetType() == typeof(IGMDataItem.Box))
  35. {
  36. ((IGMDataItem.Box)CONTAINER).Draw(true);
  37. Menu.BoxReturn dims = ((IGMDataItem.Box)CONTAINER).Dims;
  38. if ((_options & Box_Options.Center) != 0)
  39. {
  40. CONTAINER.X = _bounding.Width / 2 - dims.HotSpot.Width / 2;
  41. }
  42. if ((_options & Box_Options.Middle) != 0)
  43. {
  44. CONTAINER.Y = _bounding.Height / 2 - dims.HotSpot.Height / 2;
  45. }
  46. }
  47. }
  48. #endregion Methods
  49. }
  50. }