Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingSupplyEditorUIComponent.c
Go to the documentation of this file.
2{
10
11 protected SCR_ResourceComponent m_ResourceComponent;
12 protected SCR_ResourceConsumer m_ResourceConsumer;
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();
37 return;
38
39 SetSourceIcon(targetEntity);
40 SetProviderName(targetEntity);
41
42 if (!buildingEditorComponent.GetProviderResourceComponent(m_ResourceComponent))
43 return;
44
46 return;
47
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.
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.
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 {
144 return;
145
146 SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
147
148 if (!consumer)
149 return;
150
152 m_ProviderSupplyCurrent.SetText(consumer.GetAggregatedResourceValue().ToString());
153
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 {
169 return;
170
171 SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
172 if (!consumer)
173 return;
174
176 m_ProviderSupplyCurrent.SetText(consumer.GetAggregatedResourceValue().ToString());
177
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 string providerName = providerComponent.GetProviderDisplayName();
196 string callsignName;
197
198 // Campaign behavior
199 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
200 if (campaign)
201 {
202 SCR_CampaignMilitaryBaseComponent targetBase = providerComponent.GetCampaignMilitaryBaseComponent();
203 if (targetBase)
204 {
205 callsignName = targetBase.GetCallsignDisplayName();
206 providerName = targetBase.GetBaseName();
207 }
208 }
209 else
210 {
211 SCR_MilitaryBaseComponent targetBase = providerComponent.GetMilitaryBaseComponent();
212 if (targetBase)
213 callsignName = targetBase.GetCallsignDisplayName();
214 }
215
216 m_ProviderCallsign.SetText(callsignName);
217 m_ProviderName.SetText(providerName);
218 }
219}
EMilitarySymbolIdentity
EMilitarySymbolIcon
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
SCR_MilitarySymbolUIComponent m_SymbolUI
EResourceGeneratorID
Definition Color.c:13
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
ref SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
string GetBaseName()
Returns the name of this base.
void SetDimension(EMilitarySymbolDimension dimension)
void SetIcons(EMilitarySymbolIcon icons)
void SetIdentity(EMilitarySymbolIdentity identity)
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
proto external PlayerController GetPlayerController()