Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ImageGalleryComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_ImageGalleryComponent : ScriptedWidgetComponent
3 {
4  [Attribute("", UIWidgets.ResourceAssignArray, "")]
5  protected ref array<ref ResourceName> m_aResourceNames;
6 
7  protected ref array<ref SCR_ImageGalleryButtonComponent> m_aImages = new array <ref SCR_ImageGalleryButtonComponent>;
8 
9  private Widget m_wPagingSpinbox;
10  private SCR_SpinBoxPagingComponent m_wPagingSpinboxComponent;
11 
12 
13  //[Attribute(defvalue: "", desc: "When the texture is an image set, define the quad name here")]
14  //private string m_sImageName;
15 
16  protected ref array<Widget> m_aElementWidgets = new array<Widget>();
17  protected SCR_ImageGalleryButtonComponent m_SelectedItem;
18 
19  //protected ScrollLayoutWidget m_wScrollLayout;
20 
21  Widget m_wRoot;
22 
23  Widget m_wGalleryGrid;
24 
25  protected int m_iSelectedItemIndex;
26  protected ImageWidget m_MainImage;
27 
28  protected WorkspaceWidget m_Workspace;
29  protected bool m_bItemSelected = false;
30 
31  protected const ResourceName LAYOUT_GALLERY_ELEMENT = "{F7C52551E0B04BE1}UI/layouts/WidgetLibrary/ImageWidgets/WLib_ImageGalleryItem.layout";
32 
33  //------------------------------------------------------------------------------------------------
34  override void HandlerAttached(Widget w)
35  {
36  super.HandlerAttached(w);
37  m_wRoot = w;
38  Init();
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  void Init()
43  {
44  if (!m_wRoot)
45  return;
46 
47  m_wGalleryGrid = m_wRoot.FindAnyWidget("GalleryGrid");
48  m_MainImage = ImageWidget.Cast(m_wRoot.FindAnyWidget("MainImage"));
49  m_wPagingSpinbox = m_wRoot.FindAnyWidget("PagingSpinbox");
50  if (m_wPagingSpinbox)
51  {
52  m_wPagingSpinboxComponent = SCR_SpinBoxPagingComponent.Cast(m_wPagingSpinbox.FindHandler(SCR_SpinBoxPagingComponent));
53 
54  if (m_wPagingSpinboxComponent)
55  m_wPagingSpinboxComponent.m_OnChanged.Insert(Paging);
56  }
57  m_Workspace = GetGame().GetWorkspace();
58 
59  if (!m_Workspace)
60  return;
61 
62  if (!m_aResourceNames)
63  return;
64 
65 
66  SetPagingLayout(0, m_aResourceNames.Count());
67 
68  /*
69  foreach (ResourceName content : m_aResourceNames)
70  {
71  // Create tab button
72  Widget button = m_Workspace.CreateWidgets(LAYOUT_GALLERY_ELEMENT, m_wGalleryGrid);
73 
74  if (!button)
75  continue;
76 
77  SCR_ImageGalleryButtonComponent galleryButtonComponent = SCR_ImageGalleryButtonComponent.Cast(button.FindHandler(SCR_ImageGalleryButtonComponent));
78 
79  if (!galleryButtonComponent)
80  continue;
81 
82  galleryButtonComponent.SetImage(content);
83  galleryButtonComponent.m_OnClicked.Insert(OnImageSelected);
84  HorizontalLayoutSlot.SetPadding(button, 4, 4, 4, 4);
85  m_aImages.Insert(galleryButtonComponent);
86  if (!m_aImages.IsEmpty() && !m_bItemSelected)
87  OnImageSelected(m_aImages[0]);
88 
89  }
90  */
91 
92 
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  int AddItem(string item)
97  {
98  int i = -1;
99  if (!m_aResourceNames)
100  m_aResourceNames = new array<ref ResourceName>;
101 
102  i = m_aResourceNames.InsertAt(item, 0);
103 
104 
105  SetPagingLayout(0, m_aResourceNames.Count());
106  return i;
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  void RemoveItem(int item)
111  {
112  if (!m_aResourceNames || item < 0 || item > m_aResourceNames.Count())
113  return;
114 
115  //m_aElementWidgets[item].RemoveFromHierarchy();
116  m_aResourceNames.Remove(item);
117  SetPagingLayout(0, m_aResourceNames.Count());
118  //m_iSelectedItemIndex = -1;
119 
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  int GetCurrentIndex()
124  {
125  return m_iSelectedItemIndex;
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  string GetCurrentItem()
130  {
131  if (!m_aResourceNames || m_iSelectedItemIndex < 0 || m_iSelectedItemIndex >= m_aResourceNames.Count())
132  return string.Empty;
133 
134  return m_aResourceNames[m_iSelectedItemIndex];
135  }
136 
137  //------------------------------------------------------------------------------------------------
138  void OnImageSelected(string item)
139  {
140  m_MainImage.LoadImageTexture(0,item, false, true);
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  void SetPagingLayout(int index, int maxIndex)
145  {
146 
147  m_wPagingSpinboxComponent.SetCurrentItem(index);
148  m_wPagingSpinboxComponent.SetPageCount(maxIndex);
149  if (m_aResourceNames && !m_aResourceNames.IsEmpty())
150  OnImageSelected(m_aResourceNames[0]);
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  void Paging()
155  {
156  if (!m_aResourceNames.IsEmpty())
157  OnImageSelected(m_aResourceNames[m_wPagingSpinboxComponent.GetCurrentIndex()]);
158  }
159 
160  void SetCanNavigate(bool canNavigate)
161  {
162  m_wPagingSpinboxComponent.SetCanNavigate(canNavigate);
163  }
164 
165 
166 
167 
168 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_SpinBoxPagingComponent
Definition: SCR_SpinBoxPaging.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_Workspace
protected WorkspaceWidget m_Workspace
Definition: SCR_EntitiesEditorUIComponent.c:13
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17