DayZ 1.24
Loading...
Searching...
No Matches
QuickBarBase.c
Go to the documentation of this file.
2// Script File
4{
7
9 {
10 m_entity = NULL;
11 m_enabled = false;
12 }
13}
14
15class QuickBarBase
16{
19 protected int m_slotsCount;
20
22 {
23 for (int i = 0; i < MAX_QUICKBAR_SLOTS_COUNT; i++)
24 {
26 m_aQuickbarEnts[i].m_enabled = false;
27 m_aQuickbarEnts[i].m_entity = NULL;
28 }
29
31 m_slotsCount = 0;
32 }
33 //-------------------------------------------------------------
34 void SetSize(int newSize)
35 {
36 int i = m_slotsCount;
37 if (newSize == m_slotsCount)
38 return;
39
42
43 if (newSize > i)
44 {
45 for (; i < newSize; i++)
46 {
47 EntityAI entity = m_aQuickbarEnts[i].m_entity;
48 if (entity != NULL && entity.GetHierarchyRootPlayer() == _player)
49 m_aQuickbarEnts[i].m_enabled = true;
50 }
51 }
52 else
53 {
54 for (i--; i >= newSize; i--)
55 m_aQuickbarEnts[i].m_enabled = false;
56 }
57
59
60 if (_player.m_Hud)
61 _player.m_Hud.RefreshQuickbar(true);
62 }
63 //-------------------------------------------------------------
65 {
66 int count = 0;
67 for (int i = 0; i < m_slotsCount; i++)
68 {
69 if (m_aQuickbarEnts[i].m_enabled)
70 count++;
71 }
72
73 return count;
74 }
75 //-------------------------------------------------------------
77 {
79 return NULL;
80
81 if (m_aQuickbarEnts[index].m_enabled)
82 return m_aQuickbarEnts[index].m_entity;
83
84 return NULL;
85 }
86
87 //-------------------------------------------------------------
88 int GetSize()
89 {
90 return m_slotsCount;
91 }
92 //-------------------------------------------------------------
94 {
95 for (int i = 0; i < MAX_QUICKBAR_SLOTS_COUNT; i++)
96 {
97 if (m_aQuickbarEnts[i].m_entity == entity)
98 return i;
99 }
100
101 return -1;
102 }
103 //-------------------------------------------------------------
105 {
107 {
109 return true;
110 }
111
112 return false;
113 }
114 //-------------------------------------------------------------
116 {
118 if (!m_aQuickbarEnts[index].m_enabled)
120
121 if (_player.m_Hud)
122 _player.m_Hud.RefreshQuickbar(true);
123 }
124 //-------------------------------------------------------------
126 {
128 if (!m_aQuickbarEnts[index].m_enabled)
130
131 if (_player.m_Hud)
132 _player.m_Hud.RefreshQuickbar(true);
133 }
134 //-------------------------------------------------------------
136 {
138 entity.GetInventory().GetCurrentInventoryLocation(loc);
139 EntityAI parent = loc.GetParent();
140
141 return (entity && entity.GetHierarchyRootPlayer() == _player && parent.CanAssignAttachmentsToQuickbar() && entity.CanAssignToQuickbar());
142 }
143 //-------------------------------------------------------------
144 void SetEntityShortcut(EntityAI entity, int index, bool force = false)
145 {
146 //Client
147 if (GetGame().IsClient())
148 {
150 {
153 ctx.Write(entity);
154 ctx.Write(index);
155 ctx.Write(force);
156 ctx.Send();
157
159 }
160 }
161 //Server
162 else if (GetGame().IsMultiplayer() && GetGame().IsServer())
164 else
165 {
166 // Single player
168 }
169 }
170 //-------------------------------------------------------------
171 void OnSetEntityNoSync(EntityAI entity, int index, bool force = false)
172 {
174 }
175 //-------------------------------------------------------------
178 {
180 if (!ctx.Read(param))
181 return;
182
183 EntityAI entity1 = EntityAI.Cast(param.param1);
184 _SetEntityShortcut(entity1, param.param2, false);
185 }
186 //-------------------------------------------------------------
189 {
190 EntityAI eai = null;
191 if (!ctx.Read(eai))
192 return;
193
194 int index = -1;
195 if (!ctx.Read(index))
196 return;
197
198 bool force = false;
199 if (!ctx.Read(force))
200 return
201
203 }
204 //-------------------------------------------------------------
205 protected void _SetEntityShortcut(EntityAI entity, int index, bool force = false)
206 {
207 //TODO Check, if is in inventory
208 //if(entity.GetLoca)
209 if (entity == NULL)
210 {
212 return;
213 }
214
215 int i = FindEntityIndex(entity);
216
217 if (i != -1)
219
222 }
223 //-------------------------------------------------------------
225 {
226 int slotsCount = _player.GetQuickBarBonus();
227 int attCount = _player.GetInventory().AttachmentCount();
228
229 for (int i = 0; i < attCount; ++i)
230 slotsCount += _player.GetInventory().GetAttachmentFromIndex(i).GetQuickBarBonus();
231
232 //max slots is 10
234 }
235 //-------------------------------------------------------------
236 protected void _RemoveEntity(int index)
237 {
239 {
241
242 m_aQuickbarEnts[index].m_entity = NULL;
243 m_aQuickbarEnts[index].m_enabled = false;
244
245 if (_player.m_Hud)
246 _player.m_Hud.RefreshQuickbar(true);
247 }
248 }
249 //-------------------------------------------------------------
250 protected void _SetEntity(EntityAI entity, int index, bool force = false)
251 {
253 {
255 {
256 m_aQuickbarEnts[index].m_entity = entity;
257 m_aQuickbarEnts[index].m_enabled = true;
258 }
259 else
260 {
262 m_aQuickbarEnts[index].m_enabled = false;
263 }
264
265 if (_player.m_Hud)
266 _player.m_Hud.RefreshQuickbar(true);
267 }
268 }
269 //-------------------------------------------------------------
271 {
272
273 }
274 //-------------------------------------------------------------
275 protected void CancelContinuousUse(int index)
276 {
277 if (_player.m_QuickBarHold)
278 {
279 HumanInputController hic = _player.GetInputController();
280 if (hic && hic.IsQuickBarSlot() == index + 1)
281 _player.OnQuickBarContinuousUseEnd(index + 1);
282 }
283 }
284}
const int INPUT_UDT_QUICKABARSHORTCUT
Definition _constants.c:5
bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
void _RemoveEntity(int index)
void QuickBarBase(PlayerBase player)
void OnSetEntityRequest(ParamsReadContext ctx)
Reaction on SetEntityShortcut from client.
class QuickBarItem m_aQuickbarEnts[MAX_QUICKBAR_SLOTS_COUNT]
PlayerBase _player
EntityAI GetEntity(int index)
void _SetEntity(EntityAI entity, int index, bool force=false)
void ~QuickBarBase()
void OnSetEntityRPC(ParamsReadContext ctx)
Reaction on Rpc from server for set inicial state for quickbar.
void _SetEntityShortcut(EntityAI entity, int index, bool force=false)
void SetEntityShortcut(EntityAI entity, int index, bool force=false)
void OnSetEntityNoSync(EntityAI entity, int index, bool force=false)
void updateSlotsCount()
int m_slotsCount
const int MAX_QUICKBAR_SLOTS_COUNT
Definition QuickBarBase.c:1
void CancelContinuousUse(int index)
bool CanAddAsShortcut(EntityAI entity)
int GetNonEmptyCount()
void SetShotcutEnable(int index, bool value)
void UpdateShotcutVisibility(int index)
int GetSize()
int FindEntityIndex(EntityAI entity)
static void SendQuickbarSetShortcut(DayZPlayer pPlayer, EntityAI item, int index, bool force=false)
InventoryLocation.
Definition EnMath.c:7
EntityAI m_entity
Definition QuickBarBase.c:5
void QuickBarItem()
Definition QuickBarBase.c:8
proto static native bool CanStoreInputUserData()
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
static proto float Min(float x, float y)
Returns smaller of two given values.
proto native void SetSize(float w, float h, bool immedUpdate=true)