Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BudgetEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 }
5 
6 void ScriptInvoker_EntityBudgetMaxUpdated(EEditableEntityBudget budgetType, int currentBudgetValue, int newMaxBudgetValue);
8 typedef ScriptInvokerBase<ScriptInvoker_EntityBudgetMaxUpdated> ScriptInvoker_EntityBudgetMaxUpdatedEvent;
9 
10 void ScriptInvoker_EntityBudgetUpdated(EEditableEntityBudget budgetType, int originalBudgetValue, int updatedBudgetValue, int maxBudgetValue);
12 typedef ScriptInvokerBase<ScriptInvoker_EntityBudgetUpdated> ScriptInvoker_EntityBudgetUpdatedEvent;
13 
14 void ScriptInvoker_EntityBudgetMaxReached(EEditableEntityBudget budgetType, bool maxReached);
16 typedef ScriptInvokerBase<ScriptInvoker_EntityBudgetMaxReached> ScriptInvoker_EntityBudgetMaxReachedEvent;
17 
19 {
20  const int DEFAULT_MAX_BUDGET = 100;
21  const int DEFAULT_MIN_COST = 1;
22 
23  [Attribute(desc: "Define maximum budget values for player")]
24  protected ref array<ref SCR_EntityBudgetValue> m_MaxBudgets;
25 
26  protected SCR_EditableEntityCore m_EntityCore;
27  protected SCR_BaseEditableEntityFilter m_DestroyedEntityFilter;
28 
29  protected ref map<EEditableEntityBudget, SCR_EditableEntityCoreBudgetSetting> m_BudgetSettingsMap = new map<EEditableEntityBudget, SCR_EditableEntityCoreBudgetSetting>;
30 
34  ref ScriptInvoker Event_OnBudgetPreviewUpdated = new ScriptInvoker();
35  ref ScriptInvoker Event_OnBudgetPreviewReset = new ScriptInvoker();
36 
37  //Delayed set max values
38  protected ref map<EEditableEntityBudget, int> m_DelayedSetMaxBudgetsMap = new map<EEditableEntityBudget, int>();
39  protected bool m_bListenToMaxBudgetDelay = false;
40 
41  //------------------------------------------------------------------------------------------------
47  bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out EEditableEntityBudget blockingBudget, bool showNotification)
48  {
49  array<ref SCR_EntityBudgetValue> budgetCosts = {};
50  return CanPlaceEntityInfo(info, budgetCosts, blockingBudget, showNotification);
51  }
52 
53  //------------------------------------------------------------------------------------------------
60  bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget, bool showNotification)
61  {
62  if (!IsBudgetCapEnabled())
63  return true;
64 
65  bool canPlace = false;
66  if (GetEntityPreviewBudgetCosts(info, budgetCosts))
67  canPlace = CanPlace(budgetCosts, blockingBudget);
68  else
69  canPlace = CanPlaceEntityType(info.GetEntityType(), budgetCosts, blockingBudget);
70 
71  if (showNotification)
72  CanPlaceResult(canPlace, showNotification);
73 
74  return canPlace;
75  }
76 
77  //------------------------------------------------------------------------------------------------
85  bool CanPlaceEntitySource(IEntityComponentSource editableEntitySource, out EEditableEntityBudget blockingBudget, bool isPlacingPlayer = false, bool updatePreview = true, bool showNotification = true)
86  {
87  bool canPlace = true;
88  if (editableEntitySource && IsBudgetCapEnabled())
89  {
90  array<ref SCR_EntityBudgetValue> budgetCosts = {};
91  if (!GetEntitySourcePreviewBudgetCosts(editableEntitySource, budgetCosts))
92  {
93  canPlace = false;
94  }
95  // Clear budget cost when placing as player
96  if (isPlacingPlayer)
97  budgetCosts.Clear();
98 
99  if (updatePreview)
100  UpdatePreviewCost(budgetCosts);
101 
102  canPlace = canPlace && CanPlace(budgetCosts, blockingBudget);
103  }
104  return CanPlaceResult(canPlace, showNotification);
105  }
106 
107  //------------------------------------------------------------------------------------------------
113  protected bool CanPlaceEntityType(EEditableEntityType entityType, out notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget)
114  {
115  if (!IsBudgetCapEnabled())
116  return true;
117 
118  GetEntityTypeBudgetCost(entityType, budgetCosts);
119  return CanPlace(budgetCosts, blockingBudget);
120  }
121 
122  //------------------------------------------------------------------------------------------------
127  bool CanPlace(notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget)
128  {
129  if (!IsBudgetCapEnabled() || budgetCosts.IsEmpty())
130  return true;
131 
132  foreach (SCR_EntityBudgetValue budgetCost : budgetCosts)
133  {
134  if (!CanPlace(budgetCost, blockingBudget))
135  return false;
136  }
137  return true;
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  protected bool CanPlace(SCR_EntityBudgetValue budgetCost, out EEditableEntityBudget blockingBudget)
142  {
143  EEditableEntityBudget budgetType = budgetCost.GetBudgetType();
144  int maxBudgetValue;
145  if (!GetMaxBudgetValue(budgetType, maxBudgetValue))
146  return false;
147 
148  int originalBudgetValue = GetCurrentBudgetValue(budgetType);
149  int budgetChange = budgetCost.GetBudgetValue();
150  if (!CanPlace(originalBudgetValue, budgetChange, maxBudgetValue))
151  {
152  blockingBudget = budgetType;
153  return false;
154  }
155  else
156  {
157  return true;
158  }
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  protected bool CanPlace(int currentBudget, int budgetChange, int maxBudget)
163  {
164  return currentBudget + budgetChange <= maxBudget;
165  }
166 
167  //------------------------------------------------------------------------------------------------
171  bool GetEntityPreviewBudgetCosts(SCR_EditableEntityUIInfo entityUIInfo, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
172  {
173  if (!entityUIInfo)
174  return false;
175 
176  if (!entityUIInfo.GetEntityBudgetCost(budgetCosts))
177  GetEntityTypeBudgetCost(entityUIInfo.GetEntityType(), budgetCosts);
178 
179  array<ref SCR_EntityBudgetValue> entityChildrenBudgetCosts = {};
180  entityUIInfo.GetEntityChildrenBudgetCost(entityChildrenBudgetCosts);
181 
182  SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, entityChildrenBudgetCosts);
183 
184  FilterAvailableBudgets(budgetCosts);
185 
186  return true;
187  }
188 
189  //------------------------------------------------------------------------------------------------
193  bool GetEntitySourcePreviewBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
194  {
195  if (!editableEntitySource)
196  return false;
197 
198  SCR_EditableEntityUIInfo editableUIInfo = SCR_EditableEntityUIInfo.Cast(SCR_EditableEntityComponentClass.GetInfo(editableEntitySource));
199  if (editableUIInfo)
200  return GetEntityPreviewBudgetCosts(editableUIInfo, budgetCosts);
201 
202  return false;
203  }
204 
205  //------------------------------------------------------------------------------------------------
212  bool GetVehicleOccupiedBudgetCosts(IEntityComponentSource editableEntitySource, EEditorPlacingFlags placingFlags, out notnull array<ref SCR_EntityBudgetValue> budgetCosts, bool includeVehicleCost = true)
213  {
214  if (includeVehicleCost && !GetEntitySourcePreviewBudgetCosts(editableEntitySource, budgetCosts))
215  return false;
216 
217  SCR_EditableVehicleUIInfo editableUIInfo = SCR_EditableVehicleUIInfo.Cast(SCR_EditableEntityComponentClass.GetInfo(editableEntitySource));
218  return GetVehicleOccupiedBudgetCosts(editableUIInfo, placingFlags, budgetCosts);
219  }
220 
221  //------------------------------------------------------------------------------------------------
226  bool GetVehicleOccupiedBudgetCosts(SCR_EditableVehicleUIInfo editableUIInfo, EEditorPlacingFlags placingFlags, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
227  {
228  if (!editableUIInfo)
229  return false;
230 
231  array<ref SCR_EntityBudgetValue> vehicleOccupantsBudgetCosts = {};
232 
233  if (placingFlags & EEditorPlacingFlags.VEHICLE_CREWED)
234  {
235  editableUIInfo.GetFillBudgetCostsOfCrew(vehicleOccupantsBudgetCosts);
236  SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, vehicleOccupantsBudgetCosts);
237  }
238 
239  if (placingFlags & EEditorPlacingFlags.VEHICLE_PASSENGER)
240  {
241  editableUIInfo.GetFillBudgetCostsOfPassengers(vehicleOccupantsBudgetCosts);
242  SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, vehicleOccupantsBudgetCosts);
243  }
244 
245  return true;
246  }
247 
248  //------------------------------------------------------------------------------------------------
251  void UpdatePreviewCost(notnull array<ref SCR_EntityBudgetValue> budgetCosts)
252  {
253  ResetPreviewCost();
254  foreach (SCR_EntityBudgetValue budgetCost : budgetCosts)
255  {
256  EEditableEntityBudget budgetType = budgetCost.GetBudgetType();
257  int budgetValue = budgetCost.GetBudgetValue();
258  int maxBudget;
259  if (!GetMaxBudgetValue(budgetType, maxBudget))
260  continue;
261 
262  float max = maxBudget;
263  // Calculate current budget percentage
264  int currentBudget = GetCurrentBudgetValue(budgetType);
265  float newBudgetPercent;
266  float budgetChange;
267  if (max != 0)
268  {
269  // Calculate budget percentage after entity is placed
270  float currentBudgetPercent = currentBudget / max * 100;
271  int newBudget = currentBudget + budgetValue;
272 
273  newBudgetPercent = newBudget / max * 100;
274  // How much the budget percentage is increased
275  budgetChange = newBudgetPercent - currentBudgetPercent;
276  }
277  else
278  {
279  newBudgetPercent = 100;
280  budgetChange = 0; // Show no change when maxbudget is 0
281  }
282 
283  Event_OnBudgetPreviewUpdated.Invoke(budgetType, newBudgetPercent, budgetChange);
284  }
285  }
286 
287  //------------------------------------------------------------------------------------------------
289  void ResetPreviewCost()
290  {
291  Event_OnBudgetPreviewReset.Invoke();
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  protected bool IsBudgetAvailable(EEditableEntityBudget type)
296  {
297  SCR_EntityBudgetValue budget;
298  return GetMaxBudget(type, budget);
299  }
300 
301  //------------------------------------------------------------------------------------------------
302  protected bool GetMaxBudget(EEditableEntityBudget type, out SCR_EntityBudgetValue budget)
303  {
304  foreach (SCR_EntityBudgetValue maxBudget : m_MaxBudgets)
305  {
306  if (maxBudget.GetBudgetType() == type)
307  {
308  budget = maxBudget;
309  return true;
310  }
311  }
312  return false;
313  }
314 
315  //------------------------------------------------------------------------------------------------
320  bool GetMaxBudgetValue(EEditableEntityBudget type, out int maxBudget)
321  {
322  SCR_EntityBudgetValue budgetValue;
323  if (GetMaxBudget(type, budgetValue))
324  {
325  maxBudget = budgetValue.GetBudgetValue();
326  return true;
327  }
328  return false;
329  }
330 
331  //------------------------------------------------------------------------------------------------
335  void SetMaxBudgetValue(EEditableEntityBudget type, int newValue)
336  {
337  int oldValue = 0;
338  SCR_EntityBudgetValue maxBudget;
339  if (GetMaxBudget(type, maxBudget))
340  {
341  oldValue = maxBudget.GetBudgetValue();
342  maxBudget.SetBudgetValue(newValue);
343  }
344  Rpc(UpdateMaxBudgetOwner, type, oldValue, newValue);
345  }
346 
347  //------------------------------------------------------------------------------------------------
352  void DelayedSetMaxBudgetSetup(EEditableEntityBudget type, int newValue, int playerChangingBudget)
353  {
354  m_DelayedSetMaxBudgetsMap.Insert(type, newValue);
355 
356  if (!m_bListenToMaxBudgetDelay)
357  {
358  m_bListenToMaxBudgetDelay = true;
359  GetGame().GetCallqueue().CallLater(DelayedSetMaxBudget, 100, false, playerChangingBudget);
360  }
361  }
362 
363  //------------------------------------------------------------------------------------------------
364  protected void DelayedSetMaxBudget(int playerChangingBudget)
365  {
366  m_bListenToMaxBudgetDelay = false;
367  SetMultiMaxBudgetValues(m_DelayedSetMaxBudgetsMap, playerChangingBudget);
368  m_DelayedSetMaxBudgetsMap.Clear();
369  }
370 
371  //------------------------------------------------------------------------------------------------
374  void SetMultiMaxBudgetValues(notnull map<EEditableEntityBudget, int> budgets, int playerChangingBudget)
375  {
376  foreach (EEditableEntityBudget type, int budget: budgets)
377  {
378  SetMaxBudgetValue(type, budget);
379  }
380  }
381 
382  //------------------------------------------------------------------------------------------------
386  void GetEntityTypeBudgetCost(EEditableEntityType entityType, out array<ref SCR_EntityBudgetValue> budgetCosts)
387  {
388  EEditableEntityBudget entityBudgetType = m_EntityCore.GetBudgetForEntityType(entityType);
389  int minBudgetCost = GetEntityTypeBudgetCost(entityBudgetType);
390 
391  budgetCosts = { new SCR_EntityBudgetValue(entityBudgetType, minBudgetCost) };
392  }
393 
394  //------------------------------------------------------------------------------------------------
395  protected int GetEntityTypeBudgetCost(EEditableEntityBudget budgetType)
396  {
397  int minCost;
398  SCR_EditableEntityCoreBudgetSetting budgetSettings = m_BudgetSettingsMap.Get(budgetType);
399  if (budgetSettings)
400  return budgetSettings.GetMinBudgetCost();
401 
402  return DEFAULT_MIN_COST;
403  }
404 
405  //------------------------------------------------------------------------------------------------
409  int GetCurrentBudgetValue(EEditableEntityBudget type)
410  {
412  if (!GetCurrentBudgetSettings(type, budgetSettings))
413  return 0;
414 
415  return budgetSettings.GetCurrentBudget() + budgetSettings.GetReservedBudget();
416  }
417 
418  //------------------------------------------------------------------------------------------------
422  void SetCurrentBudgetValue(EEditableEntityBudget budgetType, int value)
423  {
424  int originalBudgetValue, budgetChange, maxBudgetValue;
426  if (GetCurrentBudgetSettings(budgetType, budgetSettings) && GetMaxBudgetValue(budgetType, maxBudgetValue))
427  {
428  originalBudgetValue = budgetSettings.GetCurrentBudget();
429  budgetChange = budgetSettings.SetCurrentBudget(value);
430 
431  if (budgetChange != value - originalBudgetValue)
432  budgetChange = 0;
433 
434  bool budgetMaxReached;
435  bool sendBudgetMaxEvent = CheckMaxBudgetReached(budgetType, budgetChange, originalBudgetValue, value, maxBudgetValue, budgetMaxReached);
436 
437  Rpc(OnEntityCoreBudgetUpdatedOwner, budgetType, value, budgetChange, sendBudgetMaxEvent, budgetMaxReached);
438  }
439  }
440 
441  //------------------------------------------------------------------------------------------------
446  bool GetCurrentBudgetInfo(EEditableEntityBudget budgetType, out SCR_UIInfo blockingBudgetInfo)
447  {
449  if (GetCurrentBudgetSettings(budgetType, budgetSettings))
450  {
451  blockingBudgetInfo = budgetSettings.GetInfo();
452  return true;
453  }
454  return false;
455  }
456 
457  //------------------------------------------------------------------------------------------------
459  void GetBudgets(out notnull array<ref SCR_EditableEntityCoreBudgetSetting> budgets)
460  {
461  foreach (EEditableEntityBudget budgetType, SCR_EditableEntityCoreBudgetSetting setting : m_BudgetSettingsMap)
462  {
463  budgets.Insert(setting);
464  }
465  }
466 
467  //------------------------------------------------------------------------------------------------
468  protected bool GetCurrentBudgetSettings(EEditableEntityBudget budgetType, out SCR_EditableEntityCoreBudgetSetting budgetSettings)
469  {
470  return m_BudgetSettingsMap.Find(budgetType, budgetSettings);
471  }
472 
473  //------------------------------------------------------------------------------------------------
475  protected void RefreshBudgetSettings()
476  {
477  m_BudgetSettingsMap.Clear();
478 
479  if (!m_EntityCore)
480  return;
481 
482  array<ref SCR_EditableEntityCoreBudgetSetting> outBudgets = {};
483  m_EntityCore.GetBudgets(outBudgets);
484 
486  for (int i = outBudgets.Count() - 1; i >= 0; i--)
487  {
488  budget = outBudgets[i];
489  EEditableEntityBudget budgetType = budget.GetBudgetType();
490  int maxBudget;
491  if (GetMaxBudgetValue(budgetType, maxBudget))
492  {
493  m_BudgetSettingsMap.Insert(budgetType, budget);
494  int currentBudgetValue = budget.GetCurrentBudget();
495  Event_OnBudgetUpdated.Invoke(budgetType, currentBudgetValue, currentBudgetValue, maxBudget);
496  Event_OnBudgetMaxUpdated.Invoke(budgetType, currentBudgetValue, maxBudget);
497  }
498  else
499  {
500  outBudgets.RemoveOrdered(i);
501  }
502  }
503  }
504 
505  //------------------------------------------------------------------------------------------------
506  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
507  protected void UpdateMaxBudgetOwner(int budgetType, int oldMaxBudget, int newMaxBudget)
508  {
509  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES))
510  Print(string.Format("Updated maximum budget received for type %1: %2", budgetType, newMaxBudget), LogLevel.NORMAL);
511 
512  SCR_EntityBudgetValue maxBudget;
513  if (GetMaxBudget(budgetType, maxBudget))
514  maxBudget.SetBudgetValue(newMaxBudget);
515 
516  int currentBudget = GetCurrentBudgetValue(budgetType);
517  // Notify max budget reached
518  if (oldMaxBudget == 0 || (currentBudget > oldMaxBudget && currentBudget < newMaxBudget)) // current budget above old budget, below new max budget
519  Event_OnBudgetMaxReached.Invoke(budgetType, false);
520  else if (newMaxBudget == 0 || (currentBudget < oldMaxBudget && currentBudget > newMaxBudget)) // current budget below old budget, above new max budget
521  Event_OnBudgetMaxReached.Invoke(budgetType, true);
522 
523  Event_OnBudgetMaxUpdated.Invoke(budgetType, currentBudget, newMaxBudget);
524  }
525 
526  //------------------------------------------------------------------------------------------------
527  protected bool CanPlaceResult(bool canPlace, bool showNotification)
528  {
529  if (showNotification)
530  Rpc(CanPlaceOwner, canPlace);
531 
532  return canPlace;
533  }
534 
535  //------------------------------------------------------------------------------------------------
536  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
537  protected void CanPlaceOwner(bool canPlace)
538  {
539  if (!canPlace)
540  {
541  GetManager().SendNotification(ENotification.EDITOR_PLACING_BUDGET_MAX);
542  //Event_OnBudgetMaxReached.Invoke(budgetType, maxBudgetReached);
543  }
544  }
545 
546  //------------------------------------------------------------------------------------------------
547  protected void OnEntityCoreBudgetUpdated(EEditableEntityBudget entityBudget, int originalBudgetValue, int budgetChange, int updatedBudgetValue, SCR_EditableEntityComponent entity)
548  {
549  int maxBudgetValue;
550  if (!GetMaxBudgetValue(entityBudget, maxBudgetValue))
551  return;
552 
553  bool budgetMaxReached;
554  bool sendBudgetMaxEvent = CheckMaxBudgetReached(entityBudget, budgetChange, originalBudgetValue, updatedBudgetValue, maxBudgetValue, budgetMaxReached);
555  /*if (!IsOwner())*/
556  Rpc(OnEntityCoreBudgetUpdatedOwner, entityBudget, updatedBudgetValue, budgetChange, sendBudgetMaxEvent, budgetMaxReached);
557  }
558 
559  //------------------------------------------------------------------------------------------------
560  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
561  protected void OnEntityCoreBudgetUpdatedOwner(EEditableEntityBudget entityBudget, int budgetValue, int budgetChange, bool sendBudgetMaxEvent, bool budgetMaxReached)
562  {
563  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES))
564  Print(string.Format("Updated budget received for type %1: %2", entityBudget, budgetValue), LogLevel.NORMAL);
565 
566  int maxBudget;
568  if (GetCurrentBudgetSettings(entityBudget, budgetSettings) && GetMaxBudgetValue(entityBudget, maxBudget))
569  {
570  int currentBudget = budgetSettings.GetCurrentBudget();
571  int ownerBudgetChange = budgetSettings.SetCurrentBudget(budgetValue);
572 
573  Event_OnBudgetUpdated.Invoke(entityBudget, currentBudget, budgetValue, maxBudget);
574 
575  if (sendBudgetMaxEvent)
576  Event_OnBudgetMaxReached.Invoke(entityBudget, budgetMaxReached);
577  }
578  }
579 
580  //------------------------------------------------------------------------------------------------
581  protected bool CheckMaxBudgetReached(EEditableEntityBudget entityBudget, int budgetChange, int originalBudgetValue, int updatedBudgetValue, int maxBudgetValue, out bool maxBudgetReached)
582  {
583  if (budgetChange >= 0 && originalBudgetValue + budgetChange >= maxBudgetValue)
584  {
585  // Send budget max reached true event
586  maxBudgetReached = true;
587  return true;
588  }
589  else if (budgetChange < 0 && updatedBudgetValue < maxBudgetValue)
590  {
591  // Send when budget is lowered between 100-90%, budget max reached false event
592  if (originalBudgetValue >= maxBudgetValue * 0.9)
593  {
594  maxBudgetReached = false;
595  return true;
596  }
597  }
598  // Do not send max budget reached event
599  return false;
600  }
601 
602  //------------------------------------------------------------------------------------------------
603  protected void FilterAvailableBudgets(inout notnull array<ref SCR_EntityBudgetValue> budgetCosts)
604  {
605  SCR_EntityBudgetValue budget;
606  for (int i = budgetCosts.Count() - 1; i >= 0; i--)
607  {
608  budget = budgetCosts[i];
609  if (!IsBudgetAvailable(budget.GetBudgetType()))
610  budgetCosts.Remove(i);
611  }
612  }
613 
614  //------------------------------------------------------------------------------------------------
618  {
619  return m_BudgetSettingsMap.Get(budgetType);
620  }
621 
622  //------------------------------------------------------------------------------------------------
623  protected EEditableEntityBudget GetFirstAvailableBudget()
624  {
625  if (!m_MaxBudgets || m_MaxBudgets.IsEmpty())
626  return null;
627  else
628  return m_MaxBudgets[0].GetBudgetType();;
629  }
630 
631  //------------------------------------------------------------------------------------------------
633  void DemandBudgetUpdateFromServer()
634  {
635  if (!m_RplComponent)
636  return;
637 
638  if (m_RplComponent.Role() != RplRole.Proxy)
639  return;
640 
641  Rpc(RpcServer_UpdateBudget);
642  }
643 
644  //------------------------------------------------------------------------------------------------
646  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
647  void RpcServer_UpdateBudget()
648  {
649  array<ref SCR_EditableEntityCoreBudgetSetting> outBudgets = {};
650  m_EntityCore.GetBudgets(outBudgets);
651 
652  foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : outBudgets)
653  {
654  Rpc(RpcOwner_UpdateBudget, budgetSetting.GetBudgetType(), budgetSetting.GetCurrentBudget());
655  }
656  }
657 
658  //------------------------------------------------------------------------------------------------
662  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
663  void RpcOwner_UpdateBudget(EEditableEntityBudget budgetType, int currentBudget)
664  {
666  if (!m_BudgetSettingsMap.Find(budgetType, budget))
667  return;
668 
669  budget.SetCurrentBudget(currentBudget);
670 
671  int maxBudget;
672  if (GetMaxBudgetValue(budgetType, maxBudget))
673  {
674  m_BudgetSettingsMap.Insert(budgetType, budget);
675  int currentBudgetValue = budget.GetCurrentBudget();
676  Event_OnBudgetUpdated.Invoke(budgetType, currentBudgetValue, currentBudgetValue, maxBudget);
677  Event_OnBudgetMaxUpdated.Invoke(budgetType, currentBudgetValue, maxBudget);
678  }
679  }
680 
681  //------------------------------------------------------------------------------------------------
682  protected bool IsBudgetCapEnabled()
683  {
684  #ifdef ENABLE_DIAG
685  return DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP);
686  #else
687  return true;
688  #endif
689  }
690 
691  //------------------------------------------------------------------------------------------------
692  override protected void EOnEditorDebug(array<string> debugTexts)
693  {
694  SCR_EntityBudgetValue maxBudget;
695  foreach (EEditableEntityBudget type, SCR_EditableEntityCoreBudgetSetting budgetSettings : m_BudgetSettingsMap)
696  {
697  GetMaxBudget(type, maxBudget);
698  debugTexts.Insert(string.Format("%1: %2 / %3", typename.EnumToString(EEditableEntityBudget, type), budgetSettings.GetCurrentBudget(), maxBudget.GetBudgetValue()));
699  }
700  }
701 
702  //------------------------------------------------------------------------------------------------
703  protected override void EOnEditorInitServer()
704  {
706  m_EntityCore.Event_OnEntityBudgetUpdated.Insert(OnEntityCoreBudgetUpdated);
707  }
708 
709  //------------------------------------------------------------------------------------------------
710  protected override void EOnEditorDeleteServer()
711  {
712  if (m_EntityCore)
713  m_EntityCore.Event_OnEntityBudgetUpdated.Remove(OnEntityCoreBudgetUpdated);
714 
715 // if (m_DestroyedEntityFilter)
716 // m_DestroyedEntityFilter.GetOnChanged().Remove(OnDestroyedChanged);
717  }
718 
719  //------------------------------------------------------------------------------------------------
720  protected override void EOnEditorActivate()
721  {
722 // SCR_EntitiesManagerEditorComponent entitiesManager = SCR_EntitiesManagerEditorComponent.Cast(SCR_EntitiesManagerEditorComponent.GetInstance(SCR_EntitiesManagerEditorComponent, true));
723 // if (entitiesManager)
724 // {
725 // //m_DestroyedEntityFilter = entitiesManager.GetFilter(EEditableEntityState.DESTROYED);
726 // //m_DestroyedEntityFilter.GetOnChanged().Insert(OnDestroyedChanged);
727 // }
728 
729  RefreshBudgetSettings();
730 
731  if (m_RplComponent && m_RplComponent.Role() != RplRole.Authority)
732  Rpc(RpcServer_UpdateBudget);
733  }
734 
735  //------------------------------------------------------------------------------------------------
736  protected override void EOnEditorInit()
737  {
739 
740  #ifdef ENABLE_DIAG
741  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES, "", "Log Budget Changes", "Editable Entities");
742  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP, "", "Enable Budget Cap", "Editable Entities");
743  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP, 1);
744  #endif
745 
746  foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : m_BudgetSettingsMap)
747  {
748  budgetSetting.SetBudgetComponent(this);
749  }
750  }
751 
752  //------------------------------------------------------------------------------------------------
753  // destructor
755  {
756  #ifdef ENABLE_DIAG
757  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES);
758  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP);
759  #endif
760  }
761 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_BudgetEditorComponentClass
Definition: SCR_BudgetEditorComponent.c:2
ScriptInvoker_EntityBudgetMaxReached
func ScriptInvoker_EntityBudgetMaxReached
Definition: SCR_BudgetEditorComponent.c:15
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
SCR_EditableEntityCoreBudgetSetting
Definition: SCR_EditableEntityCoreBudgetSetting.c:2
ScriptInvoker_EntityBudgetUpdatedEvent
ScriptInvokerBase< ScriptInvoker_EntityBudgetUpdated > ScriptInvoker_EntityBudgetUpdatedEvent
Definition: SCR_BudgetEditorComponent.c:12
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
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
func
func
Definition: SCR_AIThreatSystem.c:5
EEditableEntityBudget
EEditableEntityBudget
Definition: EEditableEntityBudget.c:1
SCR_BudgetEditorComponent
Definition: SCR_BudgetEditorComponent.c:18
ENotification
ENotification
Definition: ENotification.c:4
ScriptInvoker_EntityBudgetMaxUpdatedEvent
ScriptInvokerBase< ScriptInvoker_EntityBudgetMaxUpdated > ScriptInvoker_EntityBudgetMaxUpdatedEvent
Definition: SCR_BudgetEditorComponent.c:8
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
Attribute
typedef Attribute
Post-process effect of scripted camera.
ScriptInvoker_EntityBudgetMaxUpdated
func ScriptInvoker_EntityBudgetMaxUpdated
Definition: SCR_BudgetEditorComponent.c:7
m_EntityCore
protected SCR_EditableEntityCore m_EntityCore
Definition: SCR_CampaignBuildingManagerComponent.c:40
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
SCR_EntityBudgetValue
Definition: SCR_EntityBudgetValue.c:2
EEditorPlacingFlags
EEditorPlacingFlags
Definition: EEditorPlacingFlags.c:1
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
ScriptInvoker_EntityBudgetMaxReachedEvent
ScriptInvokerBase< ScriptInvoker_EntityBudgetMaxReached > ScriptInvoker_EntityBudgetMaxReachedEvent
Definition: SCR_BudgetEditorComponent.c:16
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
ScriptInvoker_EntityBudgetUpdated
func ScriptInvoker_EntityBudgetUpdated
Definition: SCR_BudgetEditorComponent.c:11
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_EditableEntityComponentClass
Definition: SCR_EditableEntityComponentClass.c:2
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditableVehicleUIInfo
Definition: SCR_EditableVehicleUIInfo.c:2