modsmenusimple.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. class ModsMenuSimple extends ScriptedWidgetEventHandler
  2. {
  3. protected const int MOD_DISPLAY_COUNT_MAX = 3;
  4. protected Widget m_Root;
  5. protected Widget m_MoreButton;
  6. protected Widget m_MoreHighlight;
  7. protected ref map<ModInfo, ref ModsMenuSimpleEntry> m_Data;
  8. protected ModsMenuDetailed m_DetailMenu;
  9. void ModsMenuSimple(array<ref ModInfo> data, Widget parent, ModsMenuDetailed detail_menu)
  10. {
  11. m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/mods_menu/mods_menu_simple.layout", parent);
  12. m_MoreButton = m_Root.FindAnyWidget("ModMore");
  13. m_MoreHighlight = m_Root.FindAnyWidget("ModMoreOverlay");
  14. m_Data = new map<ModInfo, ref ModsMenuSimpleEntry>;
  15. m_DetailMenu = detail_menu;
  16. m_Root.SetHandler(this);
  17. LoadEntries(data);
  18. }
  19. void ~ModsMenuSimple()
  20. {
  21. delete m_Root;
  22. }
  23. void LoadEntries(array<ref ModInfo> data)
  24. {
  25. m_MoreButton.Show(data.Count() > MOD_DISPLAY_COUNT_MAX);
  26. int count = Math.Clamp(data.Count(),0,MOD_DISPLAY_COUNT_MAX);
  27. for (int i = 0; i < count; i++)
  28. {
  29. ref ModsMenuSimpleEntry entry = new ModsMenuSimpleEntry(data[i], i, m_Root, this);
  30. m_Data.Insert(data[i], entry);
  31. }
  32. }
  33. void Select(ModInfo mod)
  34. {
  35. m_DetailMenu.Open();
  36. m_DetailMenu.Highlight(mod);
  37. }
  38. override bool OnMouseButtonUp(Widget w, int x, int y, int button)
  39. {
  40. if (w == m_MoreButton)
  41. {
  42. if (m_DetailMenu.IsOpen())
  43. m_DetailMenu.Close();
  44. else
  45. m_DetailMenu.Open();
  46. return true;
  47. }
  48. return false;
  49. }
  50. override bool OnMouseEnter(Widget w, int x, int y)
  51. {
  52. if (w == m_MoreButton)
  53. {
  54. m_MoreHighlight.Show(true);
  55. return true;
  56. }
  57. return false;
  58. }
  59. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  60. {
  61. if (enterW != m_MoreButton)
  62. {
  63. m_MoreHighlight.Show(false);
  64. return true;
  65. }
  66. return false;
  67. }
  68. override bool OnFocus(Widget w, int x, int y)
  69. {
  70. if (w == m_MoreButton)
  71. {
  72. m_MoreHighlight.Show(true);
  73. return true;
  74. }
  75. return false;
  76. }
  77. override bool OnFocusLost(Widget w, int x, int y)
  78. {
  79. if (w == m_MoreButton)
  80. {
  81. m_MoreHighlight.Show(false);
  82. return true;
  83. }
  84. return false;
  85. }
  86. }