Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlacingToolbarEditorUIComponent.c
Go to the documentation of this file.
1
2
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))]
13
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
51 if (linkedComponent)
52 linkedComponent.m_RepeatPrefab = prefab;
53
54 if (m_bIsInDialog)
55 {
57 if (menu)
58 menu.CloseSelf();
59 }
60 }
61
62 //------------------------------------------------------------------------------------------------
63 protected Widget CreateItem(int index, Faction factionAffiliationOverride = null)
64 {
65 int prefabID = m_ContentBrowserManager.GetFilteredPrefabID(index);
66 if (prefabID < 0)
67 return null;
68
70
71 //--- Select layout
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 // some objects can be available for multiple factions, but we dont want to show in building menu that they are colored with other faction colors
86 if (info && factionAffiliationOverride)
87 info.OverrideFactionKey(factionAffiliationOverride.GetFactionKey());
88
89 //--- Create layout
90 Widget itemWidget;
92 if (!CreateItem(itemWidget, item))
93 return null;
94
95 SCR_UIInfo blockingBudgetInfo;
96 array<ref SCR_EntityBudgetValue> entityBudgetCosts = {};
97 EEditableEntityBudget blockingBudgetType;
98 m_ContentBrowserManager.CanPlace(prefabID, entityBudgetCosts, blockingBudgetInfo, false, blockingBudgetType);
99
100 if (blockingBudgetInfo && blockingBudgetType >= EEditableEntityBudget.RANK_PRIVATE && blockingBudgetType <= EEditableEntityBudget.RANK_GENERAL)
101 ValidateRankRequirement(entityBudgetCosts, blockingBudgetType, blockingBudgetInfo);
102
104 assetCard.GetOnHover().Insert(OnCardHover);
105 assetCard.InitCard(prefabID, info, m_ContentBrowserManager.GetResourceNamePrefabID(prefabID), blockingBudgetInfo, m_ContentBrowserManager);
106
107 SCR_EntityBudgetValue budgetCost;
108 if (m_bShowBudgetCost && !entityBudgetCosts.IsEmpty())
109 {
110 foreach (SCR_EntityBudgetValue budgetValue: entityBudgetCosts)
111 {
112 if (budgetValue.GetBudgetType() == m_eBudgetToShow)
113 assetCard.UpdateBudgetCost(budgetValue);
114 }
115 }
116
117 ButtonActionComponent.GetOnAction(itemWidget, true, 0).Insert(OnCardLMB);
118
119 SCR_ButtonBaseComponent buttonComponent = SCR_ButtonBaseComponent.Cast(itemWidget.FindHandler(SCR_ButtonBaseComponent));
120 if (buttonComponent)
121 buttonComponent.SetMouseOverToFocus(false);
122
123 return itemWidget;
124 }
125
126 //------------------------------------------------------------------------------------------------
131 protected void ValidateRankRequirement(notnull array<ref SCR_EntityBudgetValue> entityBudgetCosts, EEditableEntityBudget blockingBudgetType, inout notnull SCR_UIInfo blockingBudgetInfo)
132 {
133 SCR_Faction localPlayerFaction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
134 if (!localPlayerFaction)
135 return;
136
137 int requiredRank;
138 foreach (SCR_EntityBudgetValue budget: entityBudgetCosts)
139 {
140 if (budget.GetBudgetType() != blockingBudgetType)
141 continue;
142
143 requiredRank = budget.GetBudgetValue();
144 break;
145 }
146
147 SCR_RankContainer ranks = localPlayerFaction.GetRanks();
148 SCR_RankInfo rankInfo = ranks.GetRankByID(requiredRank);
149 if (!rankInfo)
150 {
151 rankInfo = ranks.GetRankByID(ranks.GetNextRank(requiredRank));
152 if (!rankInfo)
153 return;
154 }
155 else if (rankInfo.GetRankInsignia() == blockingBudgetInfo.GetIconSetName())
156 {
157 return; // if such rank exists and its data matches then we dont need to change enything
158 }
159
160 SCR_BudgetUIInfo budgetInfo = SCR_BudgetUIInfo.Cast(blockingBudgetInfo);
161 if (budgetInfo)
162 blockingBudgetInfo = SCR_BudgetUIInfo.CreateInfo(budgetInfo.GetPriorityOrder(), budgetInfo.GetName(), budgetInfo.GetDescription(), budgetInfo.GetIcon(), rankInfo.GetRankInsignia());
163 else
164 blockingBudgetInfo = SCR_UIInfo.CreateInfo(blockingBudgetInfo.GetName(), blockingBudgetInfo.GetDescription(), blockingBudgetInfo.GetIcon(), rankInfo.GetRankInsignia());
165 }
166
167 //------------------------------------------------------------------------------------------------
168 override protected void OnPageChanged(int page)
169 {
170 if (m_ContentBrowserManager.GetPageEntryCount() > 0)
171 {
172 m_iFirstShownIndex = page * m_Pagination.GetColumns();
173 int contentBrowserPageIndex = m_iFirstShownIndex / m_ContentBrowserManager.GetPageEntryCount();
174 m_ContentBrowserManager.SetPageIndex(contentBrowserPageIndex);
175 }
176
177 super.OnPageChanged(page);
178 }
179
180 //------------------------------------------------------------------------------------------------
181 override protected void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
182 {
183 Faction affiliatedFactionOverride;
184 SCR_CampaignBuildingPlacingEditorComponent campaignPlacingEditorComp = SCR_CampaignBuildingPlacingEditorComponent.Cast(m_PlacingManager);
185 if (campaignPlacingEditorComp)
186 affiliatedFactionOverride = campaignPlacingEditorComp.GetProviderAffiliatedFaction();
187
188 for (int i = indexStart; i < indexEnd; i++)
189 {
190 CreateItem(i, affiliatedFactionOverride);
191 }
192 }
193
194 //------------------------------------------------------------------------------------------------
195 protected void OnBudgetMaxReached(EEditableEntityBudget entityBudget, bool maxReached)
196 {
198 return;
199
200 m_Pagination.RefreshPage();
201 }
202
203 //------------------------------------------------------------------------------------------------
204 protected void OnBrowserEntriesChanged()
205 {
207 return;
208
209 if (m_ContentBrowserManager.GetContentBrowserDisplayConfig() && m_ContentBrowserManager.GetContentBrowserDisplayConfig().GetSaveContentBrowserState())
210 return;
211
212 Refresh();
213 }
214
215 //------------------------------------------------------------------------------------------------
216 protected void OnResourceTypeEnabledChanged(array<EResourceType> disabledResourceTypes)
217 {
218 Refresh();
219 }
220
221 //------------------------------------------------------------------------------------------------
222 override protected void Refresh()
223 {
224 m_Pagination.SetEntryCount(m_ContentBrowserManager.GetFilteredPrefabCount());
225
226 int contentBrowserPage = m_ContentBrowserManager.GetPageIndex();
227 int contentBrowserPageEntryCount = m_ContentBrowserManager.GetPageEntryCount();
228 int toolbarPageIndex = (contentBrowserPage * contentBrowserPageEntryCount) / m_Pagination.GetColumns();
229
230 m_Pagination.SetPage(toolbarPageIndex);
231
232// SCR_EditorContentBrowserDisplayConfig displayConfig = m_ContentBrowserManager.GetContentBrowserDisplayConfig();
233// if (displayConfig)
234// m_bShowBudgetCost = displayConfig.GetShowAvailableBudgetCost();
235// else
236// m_bShowBudgetCost = false;
237
238 super.Refresh();
239 }
240
241 //------------------------------------------------------------------------------------------------
242 override void OnRepeat()
243 {
244 if (m_RepeatPrefab)
245 m_PlacingManager.SetSelectedPrefab(m_RepeatPrefab, showBudgetMaxNotification: true);
246 }
247
248 //------------------------------------------------------------------------------------------------
250 {
252 if (gameMode)
254
256 if (!m_PlacingManager)
257 return;
258
261 return;
262
263 m_ContentBrowserManager.GetOnBrowserStatesSaved().Insert(OnBrowserEntriesChanged);
264 m_ContentBrowserManager.GetOnBrowserEntriesFiltered().Insert(OnBrowserEntriesChanged);
265
267 if (m_BudgetManager)
268 m_BudgetManager.Event_OnBudgetMaxReached.Insert(OnBudgetMaxReached);
269
270 //--- Find default card layout
271 foreach (SCR_ContentBrowserEditorCard defaultLayoutCandidate: m_aCardPrefabs)
272 {
273 if (defaultLayoutCandidate.m_EntityType == EEditableEntityType.GENERIC)
274 {
275 m_DefaultLayout = defaultLayoutCandidate.m_sPrefab;
276 break;
277 }
278 }
279
280 super.HandlerAttachedScripted(w);
281 }
282
283 //------------------------------------------------------------------------------------------------
284 override void HandlerDeattached(Widget w)
285 {
286 super.HandlerDeattached(w);
287
289 if (gameMode)
291
293 {
294 m_ContentBrowserManager.GetOnBrowserStatesSaved().Remove(OnBrowserEntriesChanged);
295 m_ContentBrowserManager.GetOnBrowserEntriesFiltered().Remove(OnBrowserEntriesChanged);
296 }
297
298 if (m_BudgetManager)
299 m_BudgetManager.Event_OnBudgetMaxReached.Remove(OnBudgetMaxReached);
300 }
301}
EEditableEntityBudget
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_RadialMenu GetMenu()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Component to execute action when the button or its shortcut is pressed.
ScriptInvokerBase< SCR_BaseGameMode_OnResourceEnabledChanged > GetOnResourceTypeEnabledChanged()
SCR_ExternalPaginationUIComponent m_Pagination
static SCR_BudgetUIInfo CreateInfo(int priority, LocalizedString name, LocalizedString description=LocalizedString.Empty, ResourceName icon=ResourceName.Empty, string iconSetName=string.Empty)
Base class for any button, regardless its own content.
SCR_DialogEditorUIComponent m_LinkedComponent
EEditableEntityType GetEntityType()
void OverrideFactionKey(FactionKey newKey)
SCR_RankContainer GetRanks()
void OnBudgetMaxReached(EEditableEntityBudget entityBudget, bool maxReached)
SCR_ContentBrowserEditorComponent m_ContentBrowserManager
void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
void ValidateRankRequirement(notnull array< ref SCR_EntityBudgetValue > entityBudgetCosts, EEditableEntityBudget blockingBudgetType, inout notnull SCR_UIInfo blockingBudgetInfo)
ref array< ref SCR_ContentBrowserEditorCard > m_aCardPrefabs
void OnCardHover(Widget itemWidget, int prefabIndex, bool enter)
void OnResourceTypeEnabledChanged(array< EResourceType > disabledResourceTypes)
Widget CreateItem(int index, Faction factionAffiliationOverride=null)
SCR_ECharacterRank GetNextRank(SCR_ECharacterRank rankID)
SCR_RankInfo GetRankByID(SCR_ECharacterRank rankIdentifier)
string GetRankInsignia()
static SCR_UIInfo CreateInfo(UIInfo source)
Definition SCR_UIInfo.c:146
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
SCR_FieldOfViewSettings Attribute