Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBuildingSupplyEditorUIComponent.c
Go to the documentation of this file.
2 {
3  protected SCR_FactionAffiliationComponent m_FactionComponent;
4  protected TextWidget m_ProviderName;
5  protected TextWidget m_ProviderCallsign;
6  protected Widget m_wInGameSupply;
7  protected TextWidget m_ProviderSupplyCurrent;
8  protected TextWidget m_ProviderSupplyMax;
9  protected OverlayWidget m_ProviderIcon;
10 
11  protected SCR_ResourceComponent m_ResourceComponent;
12  protected SCR_ResourceConsumer m_ResourceConsumer;
13  protected ref SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer;
14  protected RplId m_ResourceInventoryPlayerComponentRplId;
15 
16  //------------------------------------------------------------------------------------------------
17  override void HandlerAttached(Widget w)
18  {
19  super.HandlerAttached(w);
20  m_ProviderName = TextWidget.Cast(w.FindAnyWidget("Provider_Name"));
21  m_ProviderCallsign = TextWidget.Cast(w.FindAnyWidget("Provider_Callsign"));
22  m_ProviderSupplyCurrent = TextWidget.Cast(w.FindAnyWidget("Supply_Value_Current"));
23  m_wInGameSupply = w.FindAnyWidget("Supply_InGame_Supply");
24  m_ProviderSupplyMax = TextWidget.Cast(w.FindAnyWidget("Supply_Value_Max"));
25  m_ProviderIcon = OverlayWidget.Cast(w.FindAnyWidget("Provider_Icon_Overlay"));
26 
27  SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
28  if (!buildingEditorComponent)
29  return;
30 
31  IEntity targetEntity = buildingEditorComponent.GetProviderEntity();
32  if (!targetEntity)
33  return;
34 
35  m_FactionComponent = buildingEditorComponent.GetProviderFactionComponent();
36  if (!m_FactionComponent)
37  return;
38 
39  SetSourceIcon(targetEntity);
40  SetProviderName(targetEntity);
41 
42  if (!buildingEditorComponent.GetProviderResourceComponent(m_ResourceComponent))
43  return;
44 
46  return;
47 
48  m_ResourceInventoryPlayerComponentRplId = Replication.FindId(SCR_ResourcePlayerControllerInventoryComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
49  m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandle(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
50 
51  m_ResourceComponent.TEMP_GetOnInteractorReplicated().Insert(UpdateResources);
52  // Update once at the beginning and then every time the supply value has changed.
53  UpdateResources();
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  override void HandlerDeattached(Widget w)
58  {
59  super.HandlerDeattached(w);
60 
62  m_ResourceComponent.TEMP_GetOnInteractorReplicated().Remove(UpdateResources);
63 
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  protected void SetSourceIcon(IEntity targetEntity)
69  {
70  if (!m_ProviderIcon)
71  return;
72 
73  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
74 
75  if (!campaign)
76  return;
77 
78  Color factionColor;
79  // We need to check both here, as vehicle has not set AffiliatedFaction if it is empty, to prevent AI to shoot at the empty vehicle.
80  Faction faction = m_FactionComponent.GetAffiliatedFaction();
81  if (!faction)
82  faction = m_FactionComponent.GetDefaultAffiliatedFaction();
83 
84  if (faction)
85  factionColor = GetColorForFaction(faction.GetFactionKey());
86 
87  //This marker thing should be converted into more sandbox solution later.
89  SCR_MilitarySymbol baseIcon = new SCR_MilitarySymbol();
90 
91  switch(faction.GetFactionKey())
92  {
93  case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.INDFOR):
94  {
95  baseIcon.SetIdentity(EMilitarySymbolIdentity.INDFOR);
96  break;
97  }
98 
99  case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.OPFOR):
100  {
101  baseIcon.SetIdentity(EMilitarySymbolIdentity.OPFOR);
102  break;
103  }
104 
105  case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.BLUFOR):
106  {
107  baseIcon.SetIdentity(EMilitarySymbolIdentity.BLUFOR);
108  break;
109  }
110 
111  case "Unknown":
112  {
113  baseIcon.SetIdentity(EMilitarySymbolIdentity.UNKNOWN);
114  break;
115  }
116  }
117 
118  if (Vehicle.Cast(m_FactionComponent.GetOwner()))
119  baseIcon.SetIcons(EMilitarySymbolIcon.MOTORIZED);
120 
121  baseIcon.SetDimension(2);
122  m_ProviderIcon.SetColor(factionColor);
123  m_SymbolUI.Update(baseIcon);
124  }
125 
126  //------------------------------------------------------------------------------
127  protected Color GetColorForFaction(string factionKey)
128  {
129  FactionManager fm = GetGame().GetFactionManager();
130  if (!fm)
131  return null;
132 
133  Faction faction = fm.GetFactionByKey(factionKey);
134  if (!faction)
135  return null;
136 
137  return faction.GetFactionColor();
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  protected void UpdateResources()
142  {
143  if (!m_ResourceComponent)
144  return;
145 
146  SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
147 
148  if (!consumer)
149  return;
150 
151  if (m_ProviderSupplyCurrent)
152  m_ProviderSupplyCurrent.SetText(consumer.GetAggregatedResourceValue().ToString());
153 
154  if (m_ProviderSupplyMax)
155  m_ProviderSupplyMax.SetText(consumer.GetAggregatedMaxResourceValue().ToString());
156 
157  // Visualize supply state
158  if (consumer.GetAggregatedResourceValue() == 0)
159  m_wInGameSupply.SetColor(UIColors.WARNING);
160  else
161  m_wInGameSupply.SetColor(Color.FromInt(Color.WHITE));
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  [Obsolete("SCR_CampaignBuildingSupplyEditorUIComponent.UpdateResources() should be used instead.")]
166  protected void UpdateSupply()
167  {
168  if (!m_ResourceComponent)
169  return;
170 
171  SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
172  if (!consumer)
173  return;
174 
175  if (m_ProviderSupplyCurrent)
176  m_ProviderSupplyCurrent.SetText(consumer.GetAggregatedResourceValue().ToString());
177 
178  if (m_ProviderSupplyMax)
179  m_ProviderSupplyMax.SetText(consumer.GetAggregatedMaxResourceValue().ToString());
180 
181  // Visualize supply state
182  if (consumer.GetAggregatedResourceValue() == 0)
183  m_wInGameSupply.SetColor(UIColors.WARNING);
184  else
185  m_wInGameSupply.SetColor(Color.FromInt(Color.WHITE));
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void SetProviderName(IEntity targetEntity)
190  {
191  SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(targetEntity.FindComponent(SCR_CampaignBuildingProviderComponent));
192  if (!providerComponent)
193  return;
194 
195  m_ProviderCallsign.SetText(providerComponent.GetProviderDisplayName());
196 
197  SCR_MilitaryBaseComponent targetBase = SCR_MilitaryBaseComponent.Cast(providerComponent.GetMilitaryBaseComponent());
198  if (targetBase)
199  {
200  m_ProviderCallsign.SetText(targetBase.GetCallsignDisplayName());
201  return;
202  }
203 
204  m_ProviderName.SetText("");
205  }
206 }
m_ResourceConsumer
protected SCR_ResourceConsumer m_ResourceConsumer
Definition: SCR_BaseSupportStationComponent.c:114
SCR_MilitarySymbol
Definition: SCR_MilitarySymbol.c:2
m_FactionComponent
protected SCR_FactionAffiliationComponent m_FactionComponent
Definition: SCR_MilitaryBaseComponent.c:46
SCR_ECampaignFaction
SCR_ECampaignFaction
Definition: SCR_CampaignFactionManager.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_CampaignBuildingSupplyEditorUIComponent
Definition: SCR_CampaignBuildingSupplyEditorUIComponent.c:1
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
EMilitarySymbolIdentity
EMilitarySymbolIdentity
Definition: EMilitarySymbol.c:1
m_ResourceSubscriptionHandleConsumer
protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
Definition: SCR_BaseSupportStationComponent.c:125
UIColors
Definition: Constants.c:16
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
m_SymbolUI
protected SCR_MilitarySymbolUIComponent m_SymbolUI
Definition: SCR_GroupEditableEntityUIComponent.c:8
Faction
Definition: Faction.c:12
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
SCR_FactionAffiliationComponent
Definition: SCR_FactionAffiliationComponent.c:10
SCR_ResourceSystemSubscriptionHandleBase
Definition: SCR_ResourceSystemSubscriptionHandleBase.c:1
SCR_MilitarySymbolUIComponent
Definition: SCR_MilitarySymbolUIComponent.c:1
Obsolete
RespawnSystemComponentClass GameComponentClass Obsolete()] proto external GenericEntity DoSpawn(string prefab
RespawnSystemComponent should be attached to a gamemode to handle player spawning and respawning.
EMilitarySymbolIcon
EMilitarySymbolIcon
Definition: EMilitarySymbol.c:29
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1