Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlacingToolbarEditorUIComponent.c
Go to the documentation of this file.
1 
4 {
5  [Attribute()]
6  protected ref array<ref SCR_ContentBrowserEditorCard> m_aCardPrefabs;
7 
8  [Attribute("0")]
9  protected bool m_bShowBudgetCost;
10 
11  [Attribute(desc: "Value of this budget will be shown directly on prefab card.", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditableEntityBudget))]
12  protected EEditableEntityBudget m_eBudgetToShow;
13 
14  protected SCR_PlacingEditorComponent m_PlacingManager;
15  protected SCR_ContentBrowserEditorComponent m_ContentBrowserManager;
16  protected SCR_BudgetEditorComponent m_BudgetManager;
17  protected ResourceName m_RepeatPrefab;
18  protected ResourceName m_DefaultLayout;
19 
20  //------------------------------------------------------------------------------------------------
24  void OnCardHover(Widget itemWidget, int prefabIndex, bool enter)
25  {
26  // Do not reset preview cost when entity is selected / window closes
27  if (!m_ContentBrowserManager || m_PlacingManager.GetSelectedPrefab())
28  return;
29 
30  if (!enter)
31  prefabIndex = -1;
32 
33  m_ContentBrowserManager.RefreshPreviewCost(prefabIndex);
34  }
35 
36  //------------------------------------------------------------------------------------------------
38  void OnCardLMB(Widget itemWidget)
39  {
41  if (!assetCard)
42  return;
43 
44  int prefabID = assetCard.GetPrefabIndex();
45  ResourceName prefab = m_ContentBrowserManager.GetResourceNamePrefabID(prefabID);
46 
47  if (!m_PlacingManager.SetSelectedPrefab(prefab, showBudgetMaxNotification: true))
48  return;
49 
50  SCR_PlacingToolbarEditorUIComponent linkedComponent = SCR_PlacingToolbarEditorUIComponent.Cast(m_LinkedComponent);
51  if (linkedComponent)
52  linkedComponent.m_RepeatPrefab = prefab;
53 
54  if (m_bIsInDialog)
55  {
56  EditorMenuBase menu = EditorMenuBase.Cast(GetMenu());
57  if (menu)
58  menu.CloseSelf();
59  }
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected Widget CreateItem(int index)
64  {
65  int prefabID = m_ContentBrowserManager.GetFilteredPrefabID(index);
66  if (prefabID < 0)
67  return null;
68 
69  SCR_EditableEntityUIInfo info = m_ContentBrowserManager.GetInfo(prefabID);
70 
71  //--- Select layout
72  m_ItemLayout = m_DefaultLayout;
73  if (info)
74  {
75  foreach (SCR_ContentBrowserEditorCard itemLayoutCandidate: m_aCardPrefabs)
76  {
77  if (itemLayoutCandidate.m_EntityType == info.GetEntityType())
78  {
79  m_ItemLayout = itemLayoutCandidate.m_sPrefab;
80  break;
81  }
82  }
83  }
84 
85  //--- Create layout
86  Widget itemWidget;
88  if (!CreateItem(itemWidget, item))
89  return null;
90 
91  SCR_UIInfo blockingBudgetInfo;
92  array<ref SCR_EntityBudgetValue> entityBudgetCosts = { };
93  m_ContentBrowserManager.CanPlace(prefabID, entityBudgetCosts, blockingBudgetInfo);
94 
96  assetCard.GetOnHover().Insert(OnCardHover);
97  assetCard.InitCard(prefabID, info, m_ContentBrowserManager.GetResourceNamePrefabID(prefabID), blockingBudgetInfo);
98 
99  SCR_EntityBudgetValue budgetCost;
100  if (m_bShowBudgetCost && !entityBudgetCosts.IsEmpty())
101  foreach (SCR_EntityBudgetValue budgetValue: entityBudgetCosts)
102  {
103  if (budgetValue.GetBudgetType() == m_eBudgetToShow)
104  assetCard.UpdateBudgetCost(budgetValue);
105  }
106 
107  ButtonActionComponent.GetOnAction(itemWidget, true, 0).Insert(OnCardLMB);
108 
109  SCR_ButtonBaseComponent buttonComponent = SCR_ButtonBaseComponent.Cast(itemWidget.FindHandler(SCR_ButtonBaseComponent));
110  if (buttonComponent)
111  buttonComponent.SetMouseOverToFocus(false);
112 
113  return itemWidget;
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override protected void OnPageChanged(int page)
118  {
119  if (m_ContentBrowserManager.GetPageEntryCount() > 0)
120  {
121  m_iFirstShownIndex = page * m_Pagination.GetColumns();
122  int contentBrowserPageIndex = m_iFirstShownIndex / m_ContentBrowserManager.GetPageEntryCount();
123  m_ContentBrowserManager.SetPageIndex(contentBrowserPageIndex);
124  }
125 
126  super.OnPageChanged(page);
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  override protected void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
131  {
132  for (int i = indexStart; i < indexEnd; i++)
133  {
134  CreateItem(i);
135  }
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  protected void OnBudgetMaxReached(EEditableEntityBudget entityBudget, bool maxReached)
140  {
141  if (!m_ContentBrowserManager || !m_Pagination)
142  return;
143 
144  m_Pagination.RefreshPage();
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected void OnBrowserEntriesChanged()
149  {
150  if (!m_ContentBrowserManager || !m_Pagination)
151  return;
152 
153  if (m_ContentBrowserManager.GetContentBrowserDisplayConfig() && m_ContentBrowserManager.GetContentBrowserDisplayConfig().GetSaveContentBrowserState())
154  return;
155 
156  Refresh();
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  protected void OnResourceTypeEnabledChanged(array<EResourceType> disabledResourceTypes)
161  {
162  Refresh();
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  override protected void Refresh()
167  {
168  m_Pagination.SetEntryCount(m_ContentBrowserManager.GetFilteredPrefabCount());
169 
170  int contentBrowserPage = m_ContentBrowserManager.GetPageIndex();
171  int contentBrowserPageEntryCount = m_ContentBrowserManager.GetPageEntryCount();
172  int toolbarPageIndex = (contentBrowserPage * contentBrowserPageEntryCount) / m_Pagination.GetColumns();
173 
174  m_Pagination.SetPage(toolbarPageIndex);
175 
176 // SCR_EditorContentBrowserDisplayConfig displayConfig = m_ContentBrowserManager.GetContentBrowserDisplayConfig();
177 // if (displayConfig)
178 // m_bShowBudgetCost = displayConfig.GetShowAvailableBudgetCost();
179 // else
180 // m_bShowBudgetCost = false;
181 
182  super.Refresh();
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  override void OnRepeat()
187  {
188  if (m_RepeatPrefab)
189  m_PlacingManager.SetSelectedPrefab(m_RepeatPrefab, showBudgetMaxNotification: true);
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  override void HandlerAttachedScripted(Widget w)
194  {
196  if (gameMode)
197  gameMode.GetOnResourceTypeEnabledChanged().Insert(OnResourceTypeEnabledChanged);
198 
200  if (!m_PlacingManager)
201  return;
202 
205  return;
206 
207  m_ContentBrowserManager.GetOnBrowserStatesSaved().Insert(OnBrowserEntriesChanged);
208  m_ContentBrowserManager.GetOnBrowserEntriesFiltered().Insert(OnBrowserEntriesChanged);
209 
210  m_BudgetManager = SCR_BudgetEditorComponent.Cast(SCR_BudgetEditorComponent.GetInstance(SCR_BudgetEditorComponent, false, true));
211  if (m_BudgetManager)
212  m_BudgetManager.Event_OnBudgetMaxReached.Insert(OnBudgetMaxReached);
213 
214  //--- Find default card layout
215  foreach (SCR_ContentBrowserEditorCard defaultLayoutCandidate: m_aCardPrefabs)
216  {
217  if (defaultLayoutCandidate.m_EntityType == EEditableEntityType.GENERIC)
218  {
219  m_DefaultLayout = defaultLayoutCandidate.m_sPrefab;
220  break;
221  }
222  }
223 
224  super.HandlerAttachedScripted(w);
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  override void HandlerDeattached(Widget w)
229  {
230  super.HandlerDeattached(w);
231 
233  if (gameMode)
234  gameMode.GetOnResourceTypeEnabledChanged().Remove(OnResourceTypeEnabledChanged);
235 
237  {
238  m_ContentBrowserManager.GetOnBrowserStatesSaved().Remove(OnBrowserEntriesChanged);
239  m_ContentBrowserManager.GetOnBrowserEntriesFiltered().Remove(OnBrowserEntriesChanged);
240  }
241 
242  if (m_BudgetManager)
243  m_BudgetManager.Event_OnBudgetMaxReached.Remove(OnBudgetMaxReached);
244  }
245 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EditableEntityUIInfo
Definition: SCR_EditableEntityUIInfo.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_ContentBrowserEditorComponent
Definition: SCR_ContentBrowserEditorComponent.c:16
SCR_AssetCardFrontUIComponent
Content Browser Card.
Definition: SCR_AssetCardFrontUIComponent.c:4
EEditableEntityBudget
EEditableEntityBudget
Definition: EEditableEntityBudget.c:1
SCR_BudgetEditorComponent
Definition: SCR_BudgetEditorComponent.c:18
m_ContentBrowserManager
protected SCR_ContentBrowserEditorComponent m_ContentBrowserManager
Definition: SCR_CampaignBuildingEditorComponent.c:13
m_PlacingManager
protected SCR_PlacingEditorComponent m_PlacingManager
Definition: SCR_PreviewEntityEditorUIComponent.c:43
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
Attribute
typedef Attribute
Post-process effect of scripted camera.
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
EditorMenuBase
Definition: EditorMenuBase.c:7
SCR_PlacingToolbarEditorUIComponent
Definition: SCR_PlacingToolbarEditorUIComponent.c:3
SCR_EntityBudgetValue
Definition: SCR_EntityBudgetValue.c:2
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
ButtonActionComponent
Component to execute action when the button or its shortcut is pressed.
Definition: ButtonActionComponent.c:2
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_BaseToolbarItemEditorUIComponent
Definition: SCR_BaseToolbarItemEditorUIComponent.c:1
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ContentBrowserEditorCard
Definition: SCR_ContentBrowserEditorUIComponent.c:716
SCR_PlacingEditorComponent
Definition: SCR_PlacingEditorComponent.c:118
SCR_BaseToolbarEditorUIComponent
Definition: SCR_BaseToolbarEditorUIComponent.c:5