Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ContentBrowser_GalleryDialog.c
Go to the documentation of this file.
1 /*
2 Dialog which shows big image gallery over whole screen.
3 */
4 
6 {
8 
9  protected ref array<ref BackendImage> m_aImages = {};
10 
11  protected int m_iCurrentItem;
12 
13  //----------------------------------------------------------------------------------
14  static SCR_ContentBrowser_GalleryDialog CreateForImages(array<BackendImage> images, int selectedImageIndex)
15  {
16  MenuBase menuBase = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.GalleryDialog);
18  galleryDialog.Init(images, selectedImageIndex);
19  return galleryDialog;
20  }
21 
22 
23  //----------------------------------------------------------------------------------
24  protected void Init(array<BackendImage> images, int selectedImageIndex)
25  {
26  m_Widgets.m_SpinBoxComponent.ClearAll();
27  m_aImages.Clear();
28 
29  int total = images.Count();
30  foreach (int i, BackendImage img : images)
31  {
32  m_Widgets.m_SpinBoxComponent.AddItem(string.Empty, i == total - 1);
33  m_aImages.Insert(img);
34  }
35 
36  if (!m_aImages.IsEmpty())
37  {
38  m_iCurrentItem = selectedImageIndex;
39  ShowImage(selectedImageIndex);
40  }
41  }
42 
43 
44  //----------------------------------------------------------------------------------
45  protected void ShowImage(int id)
46  {
47  if (id < 0 || id >= m_aImages.Count())
48  return;
49 
50  BackendImage backendImage = m_aImages[id];
51 
52  m_Widgets.m_BackendImageComponent.SetImage(backendImage);
53 
54  m_Widgets.m_SpinBoxComponent.SetCurrentItem(id);
55 
56  UpdateButtons();
57  }
58 
59 
60  //----------------------------------------------------------------------------------
61  protected void UpdateButtons()
62  {
63  m_Widgets.m_NextButtonComponent.SetEnabled(m_iCurrentItem < (m_aImages.Count() - 1));
64  m_Widgets.m_PrevButtonComponent.SetEnabled(m_iCurrentItem > 0);
65  }
66 
67 
68  //------------------------------------------------------------------------------------------
70  protected void OffsetCurrentItem(int offset)
71  {
72  m_iCurrentItem = m_iCurrentItem + offset;
73  m_iCurrentItem = Math.ClampInt(m_iCurrentItem, 0, m_aImages.Count() - 1);
74  ShowImage(m_iCurrentItem);
75  }
76 
77 
78  //----------------------------------------------------------------------------------
79  protected void OnBackButton()
80  {
81  this.Close();
82  }
83 
84  //------------------------------------------------------------------------------------------
85  protected void OnNextButton()
86  {
87  OffsetCurrentItem(1);
88  }
89 
90  //------------------------------------------------------------------------------------------
91  protected void OnPrevButton()
92  {
93  OffsetCurrentItem(-1);
94  }
95 
96  //----------------------------------------------------------------------------------
97  override void OnMenuOpen()
98  {
99  m_Widgets.Init(GetRootWidget());
100 
101  m_Widgets.m_BackButtonComponent.m_OnActivated.Insert(OnBackButton);
102  m_Widgets.m_NextButtonComponent.m_OnClicked.Insert(OnNextButton);
103  m_Widgets.m_PrevButtonComponent.m_OnClicked.Insert(OnPrevButton);
104 
105  // Close this dialog when user clicks outside
106  SCR_ModularButtonComponent backgroundButtonComponent = SCR_ModularButtonComponent.Cast(GetRootWidget().FindHandler(SCR_ModularButtonComponent));
107  backgroundButtonComponent.m_OnClicked.Insert(OnBackButton);
108 
109  // Also close this when user clicks on cross at top-right
110  m_Widgets.m_CloseButtonComponent.m_OnClicked.Insert(OnBackButton);
111 
112  // Listen to inputs
113  if (!SCR_Global.IsEditMode())
114  {
115  GetGame().GetInputManager().AddActionListener("MenuRight", EActionTrigger.DOWN, OnNextButton);
116  GetGame().GetInputManager().AddActionListener("MenuLeft", EActionTrigger.DOWN, OnPrevButton);
117  }
118 
119  GetGame().GetWorkspace().SetFocusedWidget(GetRootWidget());
120  }
121 
122 
123  //----------------------------------------------------------------------------------
124  override void OnMenuClose()
125  {
126  if (!SCR_Global.IsEditMode())
127  {
128  GetGame().GetInputManager().RemoveActionListener("MenuRight", EActionTrigger.DOWN, OnNextButton);
129  GetGame().GetInputManager().RemoveActionListener("MenuLeft", EActionTrigger.DOWN, OnPrevButton);
130  }
131  }
132 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_Global
Definition: Functions.c:6
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3