modsmenudetailedentry.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. class ModsMenuDetailedEntry extends ScriptedWidgetEventHandler
  2. {
  3. protected Widget m_Root;
  4. protected Widget m_Detail;
  5. //Header
  6. protected ImageWidget m_IconSmall;
  7. protected ImageWidget m_IconCollapse;
  8. protected TextWidget m_Name;
  9. //Left Side Panel
  10. protected ImageWidget m_IconBig;
  11. protected MultilineTextWidget m_Author;
  12. protected TextWidget m_Version;
  13. protected RichTextWidget m_ActionWebsite;
  14. protected RichTextWidget m_ActionPurchase;
  15. //Description Panel
  16. protected RichTextWidget m_Description;
  17. protected ModInfo m_Data;
  18. protected ModsMenuDetailed m_ParentMenu;
  19. protected bool m_IsOpen;
  20. void ModsMenuDetailedEntry(ModInfo data, Widget parent, ModsMenuDetailed parent_menu)
  21. {
  22. m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/mods_menu/mods_menu_detailed_entry.layout", parent);
  23. m_Detail = m_Root.FindAnyWidget("DetailContainer");
  24. m_IconSmall = ImageWidget.Cast(m_Root.FindAnyWidget("IconSmall"));
  25. m_IconCollapse = ImageWidget.Cast(m_Root.FindAnyWidget("collapse_button"));
  26. m_IconCollapse.LoadImageFile( 1, "set:dayz_gui image:icon_open" );
  27. m_Name = TextWidget.Cast(m_Root.FindAnyWidget("Name"));
  28. m_IconBig = ImageWidget.Cast(m_Root.FindAnyWidget("IconBig"));
  29. m_Author = MultilineTextWidget.Cast(m_Root.FindAnyWidget("Author"));
  30. m_Author.SetLineBreakingOverride(LinebreakOverrideMode.LINEBREAK_WESTERN);
  31. m_Version = TextWidget.Cast(m_Root.FindAnyWidget("Version"));
  32. m_ActionWebsite = RichTextWidget.Cast(m_Root.FindAnyWidget("Link"));
  33. m_ActionPurchase = RichTextWidget.Cast(m_Root.FindAnyWidget("Purchase"));
  34. #ifdef PLATFORM_PS4
  35. m_ActionPurchase.SetText("#mod_detail_info_store_PS");
  36. #endif
  37. #ifdef PLATFORM_XBOX
  38. m_ActionPurchase.SetText("#mod_detail_info_store_Xbox");
  39. #endif
  40. m_Description = RichTextWidget.Cast(m_Root.FindAnyWidget("Description"));
  41. m_Data = data;
  42. m_ParentMenu = parent_menu;
  43. m_Root.SetHandler(this);
  44. LoadData();
  45. }
  46. void ~ModsMenuDetailedEntry()
  47. {
  48. delete m_Root;
  49. }
  50. Widget GetWidget()
  51. {
  52. return m_Root;
  53. }
  54. void Select()
  55. {
  56. m_Root.SetColor( ARGBF( m_Root.GetAlpha(), 0.3, 0, 0 ) );
  57. m_Detail.Show(true);
  58. m_IconBig.Show( true );
  59. m_IconSmall.Show( false );
  60. m_IconCollapse.SetImage( 1 );
  61. m_Detail.Update();
  62. m_Root.Update();
  63. m_IsOpen = true;
  64. }
  65. void Deselect()
  66. {
  67. m_Root.SetColor( ARGBF( m_Root.GetAlpha(), 0.2, 0.2, 0.2 ) );
  68. m_Detail.Show(false);
  69. m_IconBig.Show( false );
  70. m_IconSmall.Show( true );
  71. m_IconCollapse.SetImage( 0 );
  72. m_Detail.Update();
  73. m_Root.Update();
  74. m_IsOpen = false;
  75. }
  76. void LoadData()
  77. {
  78. string picture = m_Data.GetPicture();
  79. string logo = m_Data.GetLogoSmall();
  80. string name = m_Data.GetName();
  81. string description = m_Data.GetOverview();
  82. string author = m_Data.GetAuthor();
  83. string version = m_Data.GetVersion();
  84. string action = m_Data.GetAction();
  85. //Load Large Icon
  86. if (picture != "")
  87. {
  88. m_IconBig.LoadImageFile(0, picture);
  89. }
  90. else if (logo != "")
  91. {
  92. m_IconBig.LoadImageFile(0, logo);
  93. }
  94. else
  95. {
  96. m_IconBig.LoadImageFile(0, ModInfo.DEFAULT_PICTURE);
  97. }
  98. //Load Small Icon
  99. if (logo != "")
  100. {
  101. m_IconSmall.LoadImageFile(0, logo);
  102. }
  103. else if (picture != "")
  104. {
  105. m_IconSmall.LoadImageFile(0, picture);
  106. }
  107. else
  108. {
  109. m_IconSmall.LoadImageFile(0, ModInfo.DEFAULT_LOGO_SMALL);
  110. }
  111. if (name != "")
  112. {
  113. m_Name.SetText(name);
  114. }
  115. if (description != "")
  116. {
  117. m_Description.SetText(description);
  118. }
  119. else
  120. {
  121. m_Description.SetText(ModInfo.DEFAULT_OVERVIEW);
  122. }
  123. m_Description.Update();
  124. m_Detail.Update();
  125. if (author != "")
  126. {
  127. m_Author.Show( true );
  128. m_Author.SetText(author);
  129. }
  130. if (version != "")
  131. {
  132. m_Version.Show( true );
  133. m_Version.SetText(version);
  134. }
  135. #ifdef PLATFORM_WINDOWS
  136. if (action != "")
  137. {
  138. m_ActionWebsite.Show( true );
  139. }
  140. #endif
  141. if ( m_Data.GetIsDLC() )
  142. {
  143. bool isOwned = m_Data.GetIsOwned();
  144. m_Root.FindAnyWidget("ModOwnership").Show( true );
  145. m_Root.FindAnyWidget("Owned").Show( isOwned );
  146. m_Root.FindAnyWidget("Unowned").Show( !isOwned );
  147. m_ActionPurchase.Show( true );
  148. m_Version.Show( false );
  149. }
  150. }
  151. override bool OnMouseButtonUp(Widget w, int x, int y, int button)
  152. {
  153. if (w == m_IconCollapse)
  154. {
  155. m_ParentMenu.Select(m_Data, !m_IsOpen);
  156. return true;
  157. }
  158. else if (w == m_ActionWebsite)
  159. {
  160. GetGame().OpenURL(m_Data.GetAction());
  161. }
  162. else if (w == m_ActionPurchase)
  163. {
  164. m_Data.GoToStore();
  165. }
  166. return false;
  167. }
  168. override bool OnMouseEnter(Widget w, int x, int y)
  169. {
  170. if (w == m_ActionWebsite)
  171. m_ActionWebsite.SetBold(true);
  172. if (w == m_ActionPurchase)
  173. m_ActionPurchase.SetBold(true);
  174. if (w == m_Root)
  175. {
  176. if (m_Data.GetTooltip() != "")
  177. m_ParentMenu.PrepareTooltip(m_Data);
  178. return true;
  179. }
  180. return false;
  181. }
  182. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  183. {
  184. if (w == m_ActionWebsite)
  185. m_ActionWebsite.SetBold(false);
  186. if (w == m_ActionPurchase)
  187. m_ActionPurchase.SetBold( false );
  188. if (enterW != m_Root)
  189. {
  190. m_ParentMenu.HideTooltip();
  191. return true;
  192. }
  193. return false;
  194. }
  195. }