Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
quickbarbase.c
Go to the documentation of this file.
1 const int MAX_QUICKBAR_SLOTS_COUNT = 10;
2 // Script File
4 {
5  EntityAI m_entity;
6  bool m_enabled;
7 
8  void QuickBarItem()
9  {
10  m_entity = NULL;
11  m_enabled = false;
12  }
13 }
14 
15 class QuickBarBase
16 {
18  protected PlayerBase _player;
19  protected int m_slotsCount;
20 
21  void QuickBarBase(PlayerBase player)
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 
30  _player = player;
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 
40  if (newSize > MAX_QUICKBAR_SLOTS_COUNT)
41  newSize = MAX_QUICKBAR_SLOTS_COUNT;
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  {
50  m_aQuickbarEnts[i].m_enabled = true;
51  }
52  }
53  }
54  else
55  {
56  for (i--; i >= newSize; i--)
57  m_aQuickbarEnts[i].m_enabled = false;
58  }
59 
60  m_slotsCount = newSize;
61 
62  if (_player.m_Hud)
63  _player.m_Hud.RefreshQuickbar(true);
64  }
65 //-------------------------------------------------------------
67  {
68  int count = 0;
69  for ( int i = 0; i < m_slotsCount; i++ )
70  {
71  if (m_aQuickbarEnts[i].m_enabled)
72  count++;
73  }
74 
75  return count;
76  }
77 //-------------------------------------------------------------
78  EntityAI GetEntity(int index)
79  {
80  if (index < 0 || index >= m_slotsCount)
81  return NULL;
82 
83  if (m_aQuickbarEnts[index].m_enabled)
84  return m_aQuickbarEnts[index].m_entity;
85 
86  return NULL;
87  }
88 
89 //-------------------------------------------------------------
90  int GetSize()
91  {
92  return m_slotsCount;
93  }
94 //-------------------------------------------------------------
96  {
97  for (int i = 0; i < MAX_QUICKBAR_SLOTS_COUNT; i++)
98  {
99  if (m_aQuickbarEnts[i].m_entity == entity)
100  return i;
101  }
102 
103  return -1;
104  }
105 //-------------------------------------------------------------
106  bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
107  {
108  if ( userDataType == INPUT_UDT_QUICKABARSHORTCUT)
109  {
110  OnSetEntityRequest(ctx);
111  return true;
112  }
113 
114  return false;
115  }
116 //-------------------------------------------------------------
117  void UpdateShotcutVisibility(int index)
118  {
119  m_aQuickbarEnts[index].m_enabled = CanAddAsShortcut(m_aQuickbarEnts[index].m_entity);
120  if (!m_aQuickbarEnts[index].m_enabled)
121  CancelContinuousUse(index);
122 
123  if (_player.m_Hud)
124  _player.m_Hud.RefreshQuickbar(true);
125  }
126 //-------------------------------------------------------------
127  void SetShotcutEnable(int index, bool value)
128  {
129  m_aQuickbarEnts[index].m_enabled = value && CanAddAsShortcut(m_aQuickbarEnts[index].m_entity);
130  if (!m_aQuickbarEnts[index].m_enabled)
131  CancelContinuousUse(index);
132 
133  if (_player.m_Hud)
134  _player.m_Hud.RefreshQuickbar(true);
135  }
136 //-------------------------------------------------------------
138  {
140  entity.GetInventory().GetCurrentInventoryLocation(loc);
141  EntityAI parent = loc.GetParent();
142 
143  return (entity && entity.GetHierarchyRootPlayer() == _player && parent.CanAssignAttachmentsToQuickbar() && entity.CanAssignToQuickbar());
144  }
145 //-------------------------------------------------------------
146  void SetEntityShortcut(EntityAI entity, int index, bool force = false)
147  {
148  //Client
149  if (GetGame().IsClient())
150  {
151  if (ScriptInputUserData.CanStoreInputUserData())
152  {
154  ctx.Write(INPUT_UDT_QUICKABARSHORTCUT);
155  ctx.Write(entity);
156  ctx.Write(index);
157  ctx.Write(force);
158  ctx.Send();
159 
160  _SetEntityShortcut(entity, index, force);
161  }
162  }
163  //Server
164  else if (GetGame().IsMultiplayer() && GetGame().IsServer())
165  {
166  DayZPlayerSyncJunctures.SendQuickbarSetShortcut(_player, entity, index, force);
167  }
168  else
169  {
170  // Single player
171  _SetEntityShortcut(entity,index,force);
172  }
173  }
174 //-------------------------------------------------------------
175  void OnSetEntityNoSync(EntityAI entity, int index, bool force = false )
176  {
177  _SetEntityShortcut(entity, index, force);
178  }
179 //-------------------------------------------------------------
182  {
183  Param2<Entity,int> param;
184  if (!ctx.Read(param))
185  return;
186 
187  EntityAI entity1 = EntityAI.Cast(param.param1);
188  _SetEntityShortcut(entity1, param.param2, false);
189  }
190 //-------------------------------------------------------------
193  {
194  EntityAI eai = null;
195  if (!ctx.Read(eai))
196  return;
197 
198  int index = -1;
199  if (!ctx.Read(index))
200  return;
201 
202  bool force = false;
203  if (!ctx.Read(force))
204  return
205 
206  _SetEntityShortcut(eai, index, force);
207  }
208 //-------------------------------------------------------------
209  protected void _SetEntityShortcut(EntityAI entity, int index, bool force = false)
210  {
211  //TODO Check, if is in inventory
212  //if(entity.GetLoca)
213  if ( entity == NULL )
214  {
215  _RemoveEntity(index);
216  return;
217  }
218 
219  int i = FindEntityIndex(entity);
220 
221  if ( i != -1 )
222  _RemoveEntity(i);
223 
224  _RemoveEntity(index);
225  _SetEntity( entity, index, force);
226  }
227 //-------------------------------------------------------------
229  {
230  int slotsCount = _player.GetQuickBarBonus();
231  int attCount = _player.GetInventory().AttachmentCount();
232 
233  for ( int i = 0; i < attCount; ++i)
234  {
235  slotsCount += _player.GetInventory().GetAttachmentFromIndex(i).GetQuickBarBonus();
236  }
237 
238  //max slots is 10
239  SetSize(Math.Min(slotsCount, 10));
240  }
241 //-------------------------------------------------------------
242  protected void _RemoveEntity(int index)
243  {
244  if ( index >= 0 && index < MAX_QUICKBAR_SLOTS_COUNT )
245  {
246  CancelContinuousUse(index);
247 
248  m_aQuickbarEnts[index].m_entity = NULL;
249  m_aQuickbarEnts[index].m_enabled = false;
250 
251  if (_player.m_Hud)
252  _player.m_Hud.RefreshQuickbar(true);
253  }
254  }
255 //-------------------------------------------------------------
256  protected void _SetEntity( EntityAI entity, int index, bool force = false)
257  {
258  if ( index >= 0 && index < MAX_QUICKBAR_SLOTS_COUNT )
259  {
260  if ( CanAddAsShortcut(entity) )
261  {
262  m_aQuickbarEnts[index].m_entity = entity;
263  m_aQuickbarEnts[index].m_enabled = true;
264  }
265  else
266  {
267  CancelContinuousUse(index);
268  m_aQuickbarEnts[index].m_enabled = false;
269  }
270 
271  if (_player.m_Hud)
272  _player.m_Hud.RefreshQuickbar(true);
273  }
274  }
275 //-------------------------------------------------------------
277  {
278 
279  }
280 //-------------------------------------------------------------
281  protected void CancelContinuousUse(int index)
282  {
283  if (_player.m_QuickBarHold)
284  {
285  HumanInputController hic = _player.GetInputController();
286  if (hic && hic.IsQuickBarSlot() == index + 1)
287  _player.OnQuickBarContinuousUseEnd(index + 1);
288  }
289  }
290 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
QuickBarBase
void QuickBarBase(PlayerBase player)
Definition: quickbarbase.c:21
OnSetEntityRequest
void OnSetEntityRequest(ParamsReadContext ctx)
Reaction on SetEntityShortcut from client.
Definition: quickbarbase.c:192
updateSlotsCount
void updateSlotsCount()
Definition: quickbarbase.c:228
_SetEntity
protected void _SetEntity(EntityAI entity, int index, bool force=false)
Definition: quickbarbase.c:256
ScriptInputUserData
Definition: gameplay.c:120
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
_SetEntityShortcut
protected void _SetEntityShortcut(EntityAI entity, int index, bool force=false)
Definition: quickbarbase.c:209
OnSetEntityNoSync
void OnSetEntityNoSync(EntityAI entity, int index, bool force=false)
Definition: quickbarbase.c:175
m_slotsCount
protected int m_slotsCount
Definition: quickbarbase.c:19
CanAddAsShortcut
bool CanAddAsShortcut(EntityAI entity)
Definition: quickbarbase.c:137
_RemoveEntity
protected void _RemoveEntity(int index)
Definition: quickbarbase.c:242
FindEntityIndex
int FindEntityIndex(EntityAI entity)
Definition: quickbarbase.c:95
GetNonEmptyCount
int GetNonEmptyCount()
Definition: quickbarbase.c:66
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
OnSetEntityRPC
void OnSetEntityRPC(ParamsReadContext ctx)
Reaction on Rpc from server for set inicial state for quickbar.
Definition: quickbarbase.c:181
_player
protected PlayerBase _player
Definition: quickbarbase.c:18
QuickBarItem
Definition: quickbarbase.c:3
PlayerBase
Definition: playerbaseclient.c:1
UpdateShotcutVisibility
void UpdateShotcutVisibility(int index)
Definition: quickbarbase.c:117
m_aQuickbarEnts
class QuickBarItem m_aQuickbarEnts[MAX_QUICKBAR_SLOTS_COUNT]
SetSize
void SetSize(int newSize)
Definition: quickbarbase.c:34
DayZPlayerSyncJunctures
Definition: dayzplayersyncjunctures.c:4
HumanInputController
Definition: human.c:17
~QuickBarBase
void ~QuickBarBase()
Definition: quickbarbase.c:276
GetEntity
EntityAI GetEntity(int index)
Definition: quickbarbase.c:78
SetShotcutEnable
void SetShotcutEnable(int index, bool value)
Definition: quickbarbase.c:127
Math
Definition: enmath.c:6
OnInputUserDataProcess
bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
Definition: quickbarbase.c:106
MAX_QUICKBAR_SLOTS_COUNT
const int MAX_QUICKBAR_SLOTS_COUNT
Definition: quickbarbase.c:1
EntityAI
Definition: building.c:5
GetSize
int GetSize()
Definition: quickbarbase.c:90
SetEntityShortcut
void SetEntityShortcut(EntityAI entity, int index, bool force=false)
Definition: quickbarbase.c:146
INPUT_UDT_QUICKABARSHORTCUT
const int INPUT_UDT_QUICKABARSHORTCUT
Definition: _constants.c:5
CancelContinuousUse
protected void CancelContinuousUse(int index)
Definition: quickbarbase.c:281