Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FieldManual_ImageGalleryComponent.c
Go to the documentation of this file.
2 {
7 }
8 
9 class SCR_FieldManual_ImageGalleryComponent : ScriptedWidgetComponent
10 {
11  [Attribute(defvalue: SCR_Enum.GetDefault(SCR_EFieldManual_ImageGalleryType.GALLERY_HORIZONTAL), uiwidget: UIWidgets.ComboBox, enums: SCR_Enum.GetList(SCR_EFieldManual_ImageGalleryType))]
13 
14  [Attribute()]
15  protected ref array<ref SCR_FieldManual_ImageGalleryLayoutInfo> m_aEnumLayoutPairs;
16 
17  [Attribute()]
18  protected ref array<ref SCR_FieldManual_ImageData> m_aImagesData;
19 
20  [Attribute()]
21  protected string m_sText;
22 
23  protected Widget m_wRoot;
24  protected Widget m_wGallery;
25  protected static const string S_IMAGES_PARENT_WIDGET_NAME = "Images";
26  protected static const string S_IMAGE_WIDGET_NAME = "Image";
27  protected static const string S_CAPTION_WIDGET_NAME = "Caption";
28  protected static const string S_TEXT_WIDGET_NAME = "Text";
29 
30  //------------------------------------------------------------------------------------------------
31  // constructor
33  {
34  if (!m_aEnumLayoutPairs)
35  m_aEnumLayoutPairs = {};
36 
38 
39  if (!m_aImagesData)
40  m_aImagesData = {};
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  override void HandlerAttached(Widget w)
45  {
46  super.HandlerAttached(w);
47  m_wRoot = w;
48  Rebuild(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
49  }
50 
51  //------------------------------------------------------------------------------------------------
56  void Init(SCR_EFieldManual_ImageGalleryType type, string text, array<ref SCR_FieldManual_ImageData> imagesData)
57  {
58  m_eType = type;
59  m_sText = text;
60  if (imagesData)
61  m_aImagesData = imagesData;
62 
63  Rebuild(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
64  }
65 
66  //------------------------------------------------------------------------------------------------
68  void ClearImages()
69  {
70  m_aImagesData.Clear();
71  Rebuild(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
72  }
73 
74  //------------------------------------------------------------------------------------------------
76  void SetImages(array<ref SCR_FieldManual_ImageData> imagesData)
77  {
78  if (!imagesData || imagesData.IsEmpty())
79  return;
80 
81  m_aImagesData = imagesData;
82  Rebuild(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
83  }
84 
85  //------------------------------------------------------------------------------------------------
87  void SetText(string text)
88  {
89  m_sText = text;
90 
91  if (!m_wGallery)
92  return;
93 
94  TextWidget textWidget = TextWidget.Cast(m_wGallery.FindAnyWidget(S_TEXT_WIDGET_NAME));
95  if (textWidget)
96  textWidget.SetText(m_sText);
97  }
98 
99  //------------------------------------------------------------------------------------------------
102  {
103  m_eType = type;
104  Rebuild(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
105  }
106 
107  //------------------------------------------------------------------------------------------------
110  void Rebuild(bool isGamepad)
111  {
112  if (!m_wRoot || !m_aEnumLayoutPairs)
113  return;
114 
117  {
118  if (layoutInfo && layoutInfo.m_eType == m_eType)
119  {
120  galleryInfo = layoutInfo;
121  break;
122  }
123  }
124 
125  if (!galleryInfo || galleryInfo.m_sGalleryLayout.IsEmpty() || galleryInfo.m_sImageLayout.IsEmpty())
126  return;
127 
128  SCR_WidgetHelper.RemoveAllChildren(m_wRoot);
129 
130  m_wGallery = GetGame().GetWorkspace().CreateWidgets(galleryInfo.m_sGalleryLayout, m_wRoot);
131  if (!m_wGallery)
132  return;
133 
134  TextWidget textWidget = TextWidget.Cast(m_wGallery.FindAnyWidget(S_TEXT_WIDGET_NAME));
135  if (textWidget)
136  textWidget.SetText(m_sText);
137 
138  Widget imagesParent = m_wGallery.FindAnyWidget(S_IMAGES_PARENT_WIDGET_NAME);
139  if (!imagesParent)
140  return;
141 
142  array<SCR_EInputTypeCondition> conditions = { SCR_EInputTypeCondition.ALL_INPUTS };
143  if (isGamepad)
144  conditions.Insert(SCR_EInputTypeCondition.GAMEPAD_ONLY);
145  else
146  conditions.Insert(SCR_EInputTypeCondition.KEYBOARD_ONLY);
147 
148  Widget image;
149  foreach (SCR_FieldManual_ImageData imageData : m_aImagesData)
150  {
151  if (!conditions.Contains(imageData.m_eInputDisplayCondition))
152  continue;
153 
154  image = GetGame().GetWorkspace().CreateWidgets(galleryInfo.m_sImageLayout, imagesParent);
155  if (!image)
156  continue;
157 
158  SetImageData(image, imageData);
159  }
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  protected void SetImageData(Widget widget, SCR_FieldManual_ImageData imageData)
164  {
165  ImageWidget imageWidget = ImageWidget.Cast(SCR_WidgetHelper.GetWidgetOrChild(widget, S_IMAGE_WIDGET_NAME));
166  if (imageWidget && !imageData.m_Image.IsEmpty())
167  {
168  if (imageData.m_sImageName.IsEmpty())
169  {
170  imageWidget.LoadImageTexture(0, imageData.m_Image);
171  }
172  else
173  {
174  imageWidget.LoadImageFromSet(0, imageData.m_Image, imageData.m_sImageName);
175  }
176  SCR_WidgetHelper.ResizeToImage(imageWidget);
177  }
178 
179  TextWidget captionWidget = TextWidget.Cast(widget.FindAnyWidget(S_CAPTION_WIDGET_NAME));
180  if (captionWidget)
181  captionWidget.SetText(imageData.m_sCaption);
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  protected void AddMissingEnumLayoutPairs()
186  {
187  set<SCR_EFieldManual_ImageGalleryType> foundEnums = new set<SCR_EFieldManual_ImageGalleryType>();
189  {
190  foundEnums.Insert(pair.m_eType);
191  }
192 
193  if (!foundEnums.Contains(SCR_EFieldManual_ImageGalleryType.ICONS_VERTICAL))
194  {
196  info.m_eType = SCR_EFieldManual_ImageGalleryType.ICONS_VERTICAL;
197  info.m_sGalleryLayout = "{912B608D2650F8B9}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/ICONS_VERTICAL_ImageGallery.layout";
198  info.m_sImageLayout = "{BF790BE149822E0F}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/ICONS_VERTICAL_Image.layout";
199  m_aEnumLayoutPairs.Insert(info);
200  }
201 
202  if (!foundEnums.Contains(SCR_EFieldManual_ImageGalleryType.ICONS_LIST))
203  {
205  info.m_eType = SCR_EFieldManual_ImageGalleryType.ICONS_LIST;
206  info.m_sGalleryLayout = "{B4DF69D7D553CFBC}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/ICONS_LIST_ImageGallery.layout";
207  info.m_sImageLayout = "{3194AFE59F1B877E}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/ICONS_LIST_Image.layout";
208  m_aEnumLayoutPairs.Insert(info);
209  }
210 
211  if (!foundEnums.Contains(SCR_EFieldManual_ImageGalleryType.GALLERY_HORIZONTAL))
212  {
214  info.m_eType = SCR_EFieldManual_ImageGalleryType.GALLERY_HORIZONTAL;
215  info.m_sGalleryLayout = "{D8E4A2905F167C53}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/GALLERY_HORIZONTAL_ImageGallery.layout";
216  info.m_sImageLayout = "{D08B8D5E3209D733}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/GALLERY_HORIZONTAL_Image.layout";
217  m_aEnumLayoutPairs.Insert(info);
218  }
219 
220  if (!foundEnums.Contains(SCR_EFieldManual_ImageGalleryType.GALLERY_VERTICAL))
221  {
223  info.m_eType = SCR_EFieldManual_ImageGalleryType.GALLERY_VERTICAL;
224  info.m_sGalleryLayout = "{856A53946CA73978}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/GALLERY_VERTICAL_ImageGallery.layout";
225  info.m_sImageLayout = "{D077D7EA510D2FC5}UI/layouts/Menus/FieldManual/Pieces/ImageGallery/GALLERY_VERTICAL_Image.layout";
226  m_aEnumLayoutPairs.Insert(info);
227  }
228  }
229 }
230 
231 [BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(enumType: SCR_EFieldManual_ImageGalleryType, propertyName: "m_eType", format: "Image Gallery %1")]
233 {
234  [Attribute(defvalue: SCR_Enum.GetDefault(SCR_EFieldManual_ImageGalleryType.GALLERY_HORIZONTAL), uiwidget: UIWidgets.ComboBox, enums: SCR_Enum.GetList(SCR_EFieldManual_ImageGalleryType))]
236 
237  [Attribute()]
238  ResourceName m_sGalleryLayout;
239 
240  [Attribute()]
241  ResourceName m_sImageLayout;
242 }
SCR_Enum
Definition: SCR_Enum.c:1
SCR_BaseContainerCustomTitleEnum
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
Definition: SCR_CampaignHintStorage.c:22
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_WidgetHelper
Definition: SCR_WidgetHelper.c:1
SCR_EInputTypeCondition
SCR_EInputTypeCondition
Definition: SCR_EInputTypeCondition.c:1
m_eType
protected SCR_ECampaignBaseType m_eType
Definition: SCR_CampaignMilitaryBaseComponent.c:59
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_FieldManual_ImageData
Definition: SCR_FieldManual_ImageData.c:2
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468