Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FlagComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Campaign", description: "Simple component for changing material of flags and signs.", color: "0 0 255 255")]
3 {
4  [Attribute("1", UIWidgets.CheckBox, "Is Owner entity Flag Pole?", "")]
5  protected bool m_bIsFlagPole;
6 
7  [Attribute("{9BE1341F99D33483}Assets/Props/Fabric/Flags/Data/Flag_1_2_EVERON.emat", UIWidgets.ResourcePickerThumbnail, "Default material to be used.", params: "emat")]
8  protected ResourceName m_sDefaultMaterial;
9 
10  [Attribute("", UIWidgets.ResourcePickerThumbnail, "Optional MLOD, if required.", params: "emat")]
11  protected ResourceName m_sDefaultMLOD;
12 
13  //------------------------------------------------------------------------------------------------
15  bool IsFlagPole()
16  {
17  return m_bIsFlagPole;
18  }
19 
20  //------------------------------------------------------------------------------------------------
22  ResourceName GetDefaultMaterial()
23  {
24  return m_sDefaultMaterial;
25  }
26 
27  //------------------------------------------------------------------------------------------------
29  ResourceName GetDefaultMLOD()
30  {
31  return m_sDefaultMLOD;
32  }
33 }
34 
35 //------------------------------------------------------------------------------------------------
36 class SCR_FlagComponent : SCR_MilitaryBaseLogicComponent
37 {
38  //------------------------------------------------------------------------------------------------
41 
42  //------------------------------------------------------------------------------------------------
46  void ChangeMaterial(ResourceName flagResource, ResourceName resourceMLOD = string.Empty)
47  {
48  IEntity flag = GetFlagEntity();
49  if (!flag)
50  return;
51 
52  SignalsManagerComponent signalsManager = SignalsManagerComponent.Cast(flag.FindComponent(SignalsManagerComponent));
53 
54  if (flagResource.IsEmpty())
55  {
56  flag.ClearFlags(EntityFlags.VISIBLE);
57 
58  if (signalsManager)
59  signalsManager.SetSignalValue(signalsManager.AddOrFindSignal("IsNotVisible"), 1);
60 
61  return;
62  }
63 
64  flag.SetFlags(EntityFlags.VISIBLE);
65 
66  if (signalsManager)
67  signalsManager.SetSignalValue(signalsManager.AddOrFindSignal("IsNotVisible"), 0);
68 
69  //Custom set material. Finds original material "slot" with MLOD and assigns appropriate new one, if possible.
70  VObject mesh = flag.GetVObject();
71  if (!mesh)
72  return;
73 
74  string remap;
75  string materials[256];
76  int numMats = mesh.GetMaterials(materials);
77 
78  for (int i = 0; i < numMats; i++)
79  {
80  if (materials[i].Contains("MLOD"))
81  remap += string.Format("$remap '%1' '%2';", materials[i], resourceMLOD);
82  else
83  remap += string.Format("$remap '%1' '%2';", materials[i], flagResource);
84  }
85 
86  flag.SetObject(mesh, remap);
87  }
88 
89  //------------------------------------------------------------------------------------------------
91  IEntity GetFlagEntity()
92  {
93  SCR_FlagComponentClass prefabData = SCR_FlagComponentClass.Cast(GetComponentData(GetOwner()));
94  if (prefabData && !prefabData.IsFlagPole())
95  return GetOwner();
96 
97  SlotManagerComponent slotManager = SlotManagerComponent.Cast(GetOwner().FindComponent(SlotManagerComponent));
98  if (!slotManager)
99  return null;
100 
101  array<EntitySlotInfo> slots = {};
102  slotManager.GetSlotInfos(slots);
103 
104  foreach (EntitySlotInfo slot : slots)
105  {
106  IEntity flag = slot.GetAttachedEntity();
107  if (!flag)
108  continue;
109 
110  return flag;
111  }
112 
113  return null;
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override void EOnInit(IEntity owner)
118  {
119  super.EOnInit(owner);
120 
121  SCR_FlagComponentClass prefabData = SCR_FlagComponentClass.Cast(GetComponentData(GetOwner()));
122  if (prefabData)
123  ChangeMaterial(prefabData.GetDefaultMaterial(), prefabData.GetDefaultMLOD());
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  override void OnPostInit(IEntity owner)
128  {
129  super.OnPostInit(owner);
130  SetEventMask(owner, EntityEvent.INIT);
131  }
132 }
m_sDefaultMLOD
protected ResourceName m_sDefaultMLOD
Definition: SCR_FlagComponent.c:9
SCR_FlagComponentClass
Definition: SCR_FlagComponent.c:2
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_MilitaryBaseLogicComponentClass
Definition: SCR_MilitaryBaseLogicComponent.c:1
m_sDefaultMaterial
protected ResourceName m_sDefaultMaterial
Definition: SCR_FlagComponent.c:6
EntitySlotInfo
Adds ability to attach an object to a slot.
Definition: EntitySlotInfo.c:8
Attribute
typedef Attribute
Post-process effect of scripted camera.
ChangeMaterial
SCR_FlagComponentClass SCR_MilitaryBaseLogicComponentClass ChangeMaterial(ResourceName flagResource, ResourceName resourceMLOD=string.Empty)
Definition: SCR_FlagComponent.c:46
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_FlagComponent.c:127
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Contains
proto external sealed bool Contains(IEntity item)
GetFlagEntity
IEntity GetFlagEntity()
Definition: SCR_FlagComponent.c:91
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_FlagComponent.c:117
m_bIsFlagPole
protected bool m_bIsFlagPole
Definition: SCR_FlagComponent.c:3
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180