Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SaveArsenalLoadoutAction.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 [Attribute("0", desc: "If true will try and get the Arsenal component from parent if none found. This is to check if saving is allowed. If no arsenal is found then saving is always true")]
6
8
9 //~ Ref
11 protected SCR_ArsenalManagerComponent m_ArsenalManager;
12
13 protected const LocalizedString SPECIFIC_FACTION_CANNOT_PERFORM = "#AR-ArsenalSaveType_FACTION_ITEMS_ONLY_CannotPerformAction";
14
15 //------------------------------------------------------------------------------------------------
16 override protected bool CanBeShownScript(IEntity user)
17 {
18#ifdef DISABLE_ARSENAL_LOADOUTS
19 return false;
20#endif
21
23 {
24 if (!UserActionInit())
25 return false;
26 }
27
28 if (!super.CanBeShownScript(user))
29 return false;
30
31 //~ If has arsenal component and arsenal has an inventory. Only show if saving is allowed and not disabled at the start
32 if (!m_ArsenalComponent || !m_ArsenalComponent.GetArsenalInventoryComponent() || (m_ArsenalComponent.GetArsenalSaveType() == SCR_EArsenalSaveType.SAVING_DISABLED && !m_ArsenalComponent.IsArsenalSavingDisplayedIfDisabled()))
33 return false;
34
36 if (!playerController || playerController.IsPossessing())
37 return false;
38
39 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(user);
40 if (!character)
41 return false;
42
43 SCR_Faction faction = SCR_Faction.Cast(character.GetFaction());
44 return faction && faction.IsCustomLoadoutSupported();
45 }
46
47 //------------------------------------------------------------------------------------------------
48 override protected bool CanBePerformedScript(IEntity user)
49 {
51
52 if (m_ArsenalComponent.GetArsenalSaveType() == SCR_EArsenalSaveType.SAVING_DISABLED)
53 return false;
54
55 if (!super.CanBePerformedScript(user))
56 {
57 m_sSaveTypeDisplayName = string.Empty;
58 return false;
59 }
60
61 if (m_ArsenalComponent.GetArsenalSaveType() == SCR_EArsenalSaveType.FACTION_ITEMS_ONLY)
62 {
63 Faction arsenalFaction = m_ArsenalComponent.GetAssignedFaction();
64
65 if (arsenalFaction)
66 {
67 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
68 if (factionAffiliation && factionAffiliation.GetAffiliatedFaction() != arsenalFaction)
69 {
70 m_sSaveTypeDisplayName = string.Empty;
71 SetCannotPerformReason(WidgetManager.Translate(SPECIFIC_FACTION_CANNOT_PERFORM, arsenalFaction.GetFactionName()));
72 return false;
73 }
74 }
75 }
76
77 return true;
78 }
79
80 //------------------------------------------------------------------------------------------------
81 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
82 {
83 super.Init(pOwnerEntity, pManagerComponent);
84
86 return;
87
89 }
90
91 //------------------------------------------------------------------------------------------------
92 protected bool UserActionInit()
93 {
94 SCR_ArsenalManagerComponent.GetArsenalManager(m_ArsenalManager);
96 return false;
97
98 //~ Get Arsenal component
102
103 //~ Could not get arsenal
105 {
106 Print("SCR_SaveArsenalLoadout is attached to an entity that does not have an arsenal on self or parent (if m_bAllowGetArsenalFromParent is true)!", LogLevel.WARNING);
107 return false;
108 }
109
110 //~ Allows editor to set the set the allowing of arsenal saving
111 m_ArsenalComponent.SetHasSaveArsenalAction(true);
112 return true;
113 }
114
115 //------------------------------------------------------------------------------------------------
116 protected void UpdateActionDisplayName(notnull IEntity user)
117 {
118 //~ There is no arsenal component
120 return;
121
122 //~ Makes sure it is only updated when needed
123 SCR_EArsenalSaveType arsenalSaveType = m_ArsenalComponent.GetArsenalSaveType();
124
125 //~ There is no arsenal manager
126 if (!m_ArsenalManager)
127 return;
128
129 //~ Get the arseal save type holder
130 SCR_ArsenalSaveTypeInfoHolder saveTypesHolder = m_ArsenalManager.GetArsenalSaveTypeInfoHolder();
131 if (!saveTypesHolder)
132 return;
133
134 //~ Get the save type UIinfo of the current arsenal save type
135 SCR_ArsenalSaveTypeUIInfo saveTypeUIInfo = saveTypesHolder.GetUIInfoOfType(arsenalSaveType);
136 if (!saveTypeUIInfo)
137 {
138 m_sSaveTypeDisplayName = string.Empty;
139 return;
140 }
141
142 //~ Get Action display name
144
145 //~ No custom display name for the action so use default
147 {
148 SetCannotPerformReason(string.Empty);
149 return;
150 }
151
152 //~ Action is disabled so show the action name in disabled () and use default
153 if (arsenalSaveType == SCR_EArsenalSaveType.SAVING_DISABLED)
154 {
156 m_sSaveTypeDisplayName = string.Empty;
157 return;
158 }
159
160 if (arsenalSaveType == SCR_EArsenalSaveType.FACTION_ITEMS_ONLY)
161 {
163 {
164 m_sSaveTypeDisplayName = string.Empty;
165 return;
166 }
167
168 Faction faction = m_ArsenalComponent.GetAssignedFaction();
169 if (!faction)
170 {
171 m_sSaveTypeDisplayName = string.Empty;
172 return;
173 }
174
175 m_sSaveTypeDisplayName = WidgetManager.Translate(m_sSaveTypeDisplayName, faction.GetFactionName());
176 }
177 }
178
179 //------------------------------------------------------------------------------------------------
180 override bool GetActionNameScript(out string outName)
181 {
183 outName = m_sSaveTypeDisplayName;
184 else
185 return super.GetActionNameScript(outName);
186
187 return true;
188 }
189
190 //------------------------------------------------------------------------------------------------
191 override protected void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
192 {
194 {
195 if (!UserActionInit())
196 return;
197 }
198
199 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
200 if (playerId <= 0)
201 return;
202
203 super.PerformAction(pOwnerEntity, pUserEntity);
204
205 m_ArsenalManager.SetPlayerArsenalLoadout(playerId, GameEntity.Cast(pUserEntity), m_ArsenalComponent, SCR_EArsenalSupplyCostType.RESPAWN_COST);
206 }
207};
ArmaReforgerScripted GetGame()
Definition game.c:1398
Faction GetParent()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetCannotPerformReason(string reason)
proto external Managed FindComponent(typename typeName)
SCR_ArsenalSaveTypeUIInfo GetUIInfoOfType(SCR_EArsenalSaveType saveTypeToCheck)
LocalizedString GetPlayerActionDisplayName()
bool IsCustomLoadoutSupported()
static bool IsEditMode()
Definition Functions.c:1566
const LocalizedString SPECIFIC_FACTION_CANNOT_PERFORM
SCR_ArsenalManagerComponent m_ArsenalManager
SCR_ArsenalComponent m_ArsenalComponent
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override bool GetActionNameScript(out string outName)
void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
void UpdateActionDisplayName(notnull IEntity user)
static bool IsEmptyOrWhiteSpace(string input)
IEntity GetOwner()
Owner entity of the fuel tank.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()