Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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")]
5  protected bool m_bAllowGetArsenalFromParent;
6 
7  protected LocalizedString m_sSaveTypeDisplayName;
8 
9  //~ Ref
10  protected SCR_ArsenalComponent m_ArsenalComponent;
11  protected SCR_ArsenalManagerComponent m_ArsenalManager;
12 
13  //------------------------------------------------------------------------------------------------
14  override protected bool CanBeShownScript(IEntity user)
15  {
16 #ifdef DISABLE_ARSENAL_LOADOUTS
17  return false;
18 #endif
19  if (!m_ArsenalManager || !super.CanBeShownScript(user))
20  return false;
21 
22  //~ If has arsenal component and arsenal has an inventory. Only show if saving is allowed and not disabled at the start
23  if (!m_ArsenalComponent || !m_ArsenalComponent.GetArsenalInventoryComponent() || (m_ArsenalComponent.GetArsenalSaveType() == SCR_EArsenalSaveType.SAVING_DISABLED && !m_ArsenalComponent.IsArsenalSavingDisplayedIfDisabled()))
24  return false;
25 
27  SCR_ArsenalManagerComponent arsenalManager;
28  return (!playerController || !playerController.IsPossessing());
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  override protected bool CanBePerformedScript(IEntity user)
33  {
34  UpdateActionDisplayName(user);
35 
36  if (m_ArsenalComponent.GetArsenalSaveType() == SCR_EArsenalSaveType.SAVING_DISABLED)
37  return false;
38 
39  if (!super.CanBePerformedScript(user))
40  {
41  m_sSaveTypeDisplayName = string.Empty;
42  return false;
43  }
44 
45  return true;
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
50  {
51  if (SCR_Global.IsEditMode())
52  return;
53 
54  super.Init(pOwnerEntity, pManagerComponent);
55 
56  SCR_ArsenalManagerComponent.GetArsenalManager(m_ArsenalManager);
57  if (!m_ArsenalManager)
58  return;
59 
60  //~ Get Arsenal component
61  m_ArsenalComponent = SCR_ArsenalComponent.Cast(GetOwner().FindComponent(SCR_ArsenalComponent));
62  if (!m_ArsenalComponent && m_bAllowGetArsenalFromParent && GetOwner().GetParent())
63  m_ArsenalComponent = SCR_ArsenalComponent.Cast(GetOwner().GetParent().FindComponent(SCR_ArsenalComponent));
64 
65  //~ Could not get arsenal
66  if (!m_ArsenalComponent)
67  {
68  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);
69  return;
70  }
71 
72  //~ Allows editor to set the set the allowing of arsenal saving
73  m_ArsenalComponent.SetHasSaveArsenalAction(true);
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  protected void UpdateActionDisplayName(notnull IEntity user)
78  {
79  //~ There is no arsenal component
80  if (!m_ArsenalComponent)
81  return;
82 
83  //~ Makes sure it is only updated when needed
84  SCR_EArsenalSaveType arsenalSaveType = m_ArsenalComponent.GetArsenalSaveType();
85 
86  //~ There is no arsenal manager
87  if (!m_ArsenalManager)
88  return;
89 
90  //~ Get the arseal save type holder
91  SCR_ArsenalSaveTypeInfoHolder saveTypesHolder = m_ArsenalManager.GetArsenalSaveTypeInfoHolder();
92  if (!saveTypesHolder)
93  return;
94 
95  //~ Get the save type UIinfo of the current arsenal save type
96  SCR_ArsenalSaveTypeUIInfo saveTypeUIInfo = saveTypesHolder.GetUIInfoOfType(arsenalSaveType);
97  if (!saveTypeUIInfo)
98  {
99  m_sSaveTypeDisplayName = string.Empty;
100  return;
101  }
102 
103  //~ Get Action display name
104  m_sSaveTypeDisplayName = saveTypeUIInfo.GetPlayerActionDisplayName();
105 
106  //~ No custom display name for the action so use default
107  if (SCR_StringHelper.IsEmptyOrWhiteSpace(m_sSaveTypeDisplayName))
108  {
109  SetCannotPerformReason(string.Empty);
110  return;
111  }
112 
113  //~ Action is disabled so show the action name in disabled () and use default
114  if (arsenalSaveType == SCR_EArsenalSaveType.SAVING_DISABLED)
115  {
116  SetCannotPerformReason(m_sSaveTypeDisplayName);
117  m_sSaveTypeDisplayName = string.Empty;
118  return;
119  }
120 
121  if (arsenalSaveType == SCR_EArsenalSaveType.FACTION_ITEMS_ONLY)
122  {
123  FactionAffiliationComponent userFactionAffiliation = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
124  if (!userFactionAffiliation)
125  {
126  m_sSaveTypeDisplayName = string.Empty;
127  return;
128  }
129 
130  Faction faction = userFactionAffiliation.GetAffiliatedFaction();
131  if (!faction)
132  {
133  m_sSaveTypeDisplayName = string.Empty;
134  return;
135  }
136 
137  m_sSaveTypeDisplayName = WidgetManager.Translate(m_sSaveTypeDisplayName, faction.GetFactionName());
138  }
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  override bool GetActionNameScript(out string outName)
143  {
144  if (!SCR_StringHelper.IsEmptyOrWhiteSpace(m_sSaveTypeDisplayName))
145  outName = m_sSaveTypeDisplayName;
146  else
147  return super.GetActionNameScript(outName);
148 
149  return true;
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  override protected void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
154  {
155  if (!m_ArsenalManager || !m_ArsenalComponent)
156  return;
157 
158  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
159  if (playerId <= 0)
160  return;
161 
162  super.PerformAction(pOwnerEntity, pUserEntity);
163 
164  m_ArsenalManager.SetPlayerArsenalLoadout(playerId, GameEntity.Cast(pUserEntity), m_ArsenalComponent, SCR_EArsenalSupplyCostType.RESPAWN_COST);
165  }
166 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_ArsenalSaveTypeInfoHolder
Definition: SCR_ArsenalSaveTypeInfoHolder.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SaveArsenalLoadout
Definition: SCR_SaveArsenalLoadoutAction.c:2
SCR_StringHelper
Definition: SCR_StringHelper.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Faction
Definition: Faction.c:12
SCR_Global
Definition: Functions.c:6
SCR_ArsenalSaveTypeUIInfo
Definition: SCR_ArsenalSaveTypeUIInfo.c:2
SCR_BaseFactionCheckUserAction
Definition: SCR_BaseFactionCheckUserAction.c:2
SCR_ArsenalComponent
Definition: SCR_ArsenalComponent.c:9
LocalizedString
Definition: LocalizedString.c:21