mainmenupromo.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //!base class for promo implementation
  2. class MainMenuDlcHandlerBase extends ScriptedWidgetEventHandler
  3. {
  4. protected const string TEXT_OWNED = "#layout_dlc_owned";
  5. protected const string TEXT_UNOWNED = "#layout_dlc_unowned";
  6. protected int m_ColorBackgroundOriginal;
  7. protected Widget m_Root;
  8. protected Widget m_BannerFrame;
  9. protected Widget m_Background;
  10. protected Widget m_StoreButton;
  11. protected Widget m_GamepadStoreImage;
  12. protected ImageWidget m_DlcPromotionImage;
  13. protected TextWidget m_TitleTextDlc;
  14. protected MultilineTextWidget m_DescriptionTextDlc;
  15. protected VideoWidget m_VideoWidget;
  16. protected ref ModInfo m_ThisModInfo;
  17. protected ref JsonDataDLCInfo m_DlcInfo;
  18. protected ref BannerHandlerBase m_BannerHandler;
  19. void MainMenuDlcHandlerBase(ModInfo info, Widget parent, JsonDataDLCInfo DlcInfo)
  20. {
  21. CreateRootWidget(parent);
  22. m_Root.SetHandler(this);
  23. m_DlcInfo = DlcInfo;
  24. m_ThisModInfo = info;
  25. Init();
  26. #ifdef PLATFORM_CONSOLE
  27. GetGame().GetContentDLCService().m_OnChange.Insert(OnDLCChange);
  28. if (GetGame().GetMission())
  29. {
  30. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  31. }
  32. #endif
  33. }
  34. void ~MainMenuDlcHandlerBase()
  35. {
  36. #ifdef PLATFORM_CONSOLE
  37. if (GetGame().GetContentDLCService())
  38. GetGame().GetContentDLCService().m_OnChange.Remove(OnDLCChange);
  39. #endif
  40. }
  41. void Init()
  42. {
  43. m_Background = m_Root;
  44. m_StoreButton = m_Root.FindAnyWidget("dlc_openStore");
  45. SetPlatformSpecifics();
  46. m_VideoWidget = VideoWidget.Cast(m_Root.FindAnyWidget("dlc_Video"));
  47. m_VideoWidget.Show(false);
  48. m_DlcPromotionImage = ImageWidget.Cast(m_Root.FindAnyWidget("dlc_ImageMain"));
  49. m_DlcPromotionImage.Show(true);
  50. m_BannerFrame = m_Root.FindAnyWidget("dlc_BannerFrame");//dlc_BannerFrame //dlc_BannerFrameVideo
  51. m_BannerHandler = new BannerHandlerBase(m_BannerFrame);
  52. m_TitleTextDlc = TextWidget.Cast(m_Root.FindAnyWidget("dlc_title"));
  53. m_DescriptionTextDlc = MultilineTextWidget.Cast(m_Root.FindAnyWidget("dlc_Description"));
  54. m_DescriptionTextDlc.SetLineBreakingOverride(LinebreakOverrideMode.LINEBREAK_WESTERN);
  55. m_ColorBackgroundOriginal = m_Background.GetColor();
  56. UpdateAllPromotionInfo();
  57. //StartVideo();
  58. }
  59. void CreateRootWidget(Widget parent)
  60. {
  61. m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/dlc_panels/DLC_Panel.layout", parent);
  62. }
  63. void ShowInfoPanel(bool show)
  64. {
  65. m_Root.Show(show);
  66. OnPanelVisibilityChanged();
  67. }
  68. bool IsInfoPanelVisible()
  69. {
  70. return m_Root.IsVisible();
  71. }
  72. void OnPanelVisibilityChanged()
  73. {
  74. UpdateAllPromotionInfo();
  75. return;
  76. /*if (IsInfoPanelVisible())
  77. StartVideo();
  78. else
  79. PauseVideo();*/
  80. }
  81. //works on button only
  82. override bool OnClick(Widget w, int x, int y, int button)
  83. {
  84. m_ThisModInfo.GoToStore();
  85. return super.OnClick(w,x,y,button);
  86. }
  87. //! returns 'true' when video is loaded
  88. bool LoadVideoFile()
  89. {
  90. if (m_VideoWidget.GetState() != VideoState.NONE)
  91. return true;
  92. string path = "video\\" + m_DlcInfo.VideoFileName;
  93. if (m_DlcInfo.VideoFileName != "")
  94. return m_VideoWidget.Load(path, true);
  95. return false;
  96. }
  97. void StartVideo()
  98. {
  99. if (LoadVideoFile())
  100. m_VideoWidget.Play();
  101. }
  102. void StopVideo()
  103. {
  104. m_VideoWidget.Stop();
  105. }
  106. void PauseVideo()
  107. {
  108. m_VideoWidget.Pause();
  109. }
  110. void UnloadVideo()
  111. {
  112. m_VideoWidget.Stop();
  113. m_VideoWidget.Unload();
  114. }
  115. protected void ColorFocussed(Widget w, int x, int y)
  116. {
  117. m_Background.SetColor(ARGB(255,54,16,16));
  118. }
  119. protected void ColorUnfocussed(Widget w, Widget enterW, int x, int y)
  120. {
  121. m_Background.SetColor(m_ColorBackgroundOriginal);
  122. }
  123. protected void UpdateOwnedStatus()
  124. {
  125. if (m_ThisModInfo)
  126. {
  127. if (m_ThisModInfo.GetIsOwned())
  128. {
  129. m_BannerHandler.SetBannerColor(Colors.COLOR_FROSTLINE_MOUNTAIN_BLUE);
  130. m_BannerHandler.SetBannerText(TEXT_OWNED);
  131. }
  132. else
  133. {
  134. m_BannerHandler.SetBannerColor(Colors.COLOR_DAYZ_RED);
  135. m_BannerHandler.SetBannerText(TEXT_UNOWNED);
  136. }
  137. }
  138. }
  139. protected void OnDLCChange()
  140. {
  141. UpdateOwnedStatus();
  142. }
  143. protected void SetPlatformSpecifics()
  144. {
  145. TextWidget desc = TextWidget.Cast(m_StoreButton.FindAnyWidget("dlc_openStore_label"));
  146. #ifdef PLATFORM_PS4
  147. m_GamepadStoreImage = m_Root.FindAnyWidget("image_button_ps");
  148. desc.SetText("#dlc_open_store_PS");
  149. #endif
  150. #ifdef PLATFORM_XBOX
  151. m_GamepadStoreImage = m_Root.FindAnyWidget("image_button_xbox");
  152. desc.SetText("#dlc_open_store_Xbox");
  153. #endif
  154. #ifdef PLATFORM_PC
  155. m_GamepadStoreImage = m_Root.FindAnyWidget("image_button_xbox");
  156. desc.SetText("#dlc_open_store");
  157. #endif
  158. }
  159. //updates on language change etc.
  160. void UpdateAllPromotionInfo()
  161. {
  162. UpdateDlcData();
  163. UpdateOwnedStatus();
  164. UpdateIconVisibility();
  165. }
  166. protected void UpdateDlcData()
  167. {
  168. m_TitleTextDlc.SetText(m_DlcInfo.HeaderText);
  169. m_DescriptionTextDlc.SetText(m_DlcInfo.DescriptionText);
  170. }
  171. protected void UpdateIconVisibility()
  172. {
  173. #ifdef PLATFORM_CONSOLE
  174. m_GamepadStoreImage.Show(!GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER);
  175. #endif
  176. }
  177. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  178. {
  179. UpdateIconVisibility();
  180. }
  181. ModInfo GetModInfo()
  182. {
  183. return m_ThisModInfo;
  184. }
  185. }