DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ContainerWithCargo.c
См. документацию.
2{
3 protected ref CargoContainer m_CargoGrid;
4 protected int m_CargoIndex = -1;
5
6 void ContainerWithCargo( LayoutHolder parent, int sort = -1 )
7 {
8 m_LockCargo = false;
9
10 m_CargoGrid = new CargoContainer( this );
11 Insert( m_CargoGrid );
12
13 m_CargoGrid.GetRootWidget().SetSort( 1 );
14
15 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( m_MainWidget, this, "DraggingOverGrid" );
16 RecomputeOpenedContainers();
17 }
18
19 override bool IsDisplayable()
20 {
21 if (m_Entity)
22 return m_Entity.CanDisplayCargo();
23 return false;
24 }
25
26 override bool IsEmpty()
27 {
28 return m_CargoGrid.IsEmpty();
29 }
30
31 override bool IsItemActive()
32 {
33 return m_CargoGrid.IsItemActive();
34 }
35
36 override bool CanCombine()
37 {
38 return m_CargoGrid.CanCombine();
39 }
40
41 override bool CanCombineAmmo()
42 {
43 return m_CargoGrid.CanCombineAmmo();
44 }
45
47 {
48 return m_CargoGrid.IsItemWithQuantityActive();
49 }
50
51 void LockCargo(bool value)
52 {
53 if( value != m_LockCargo )
54 {
55 if( value )
56 {
57 m_LockCargo = true;
58 OnHide();
59 }
60 else
61 {
62 m_LockCargo = false;
63 SetOpenState(!m_Closed);
64 }
65 }
66 }
67
68 override void Open()
69 {
70 if( !m_LockCargo )
71 {
73 m_Closed = false;
74 SetOpenForSlotIcon(true);
75 OnShow();
76 m_Parent.m_Parent.Refresh();
77 }
78
79 if ( m_SlotIcon )
80 {
81 m_SlotIcon.GetRadialIconPanel().Show( !m_LockCargo );
82 }
83 }
84
85 override void Close()
86 {
87 if( !m_LockCargo )
88 {
90 m_Closed = true;
91 SetOpenForSlotIcon(false);
92 OnHide();
93 m_Parent.m_Parent.Refresh();
94 }
95
96 if ( m_SlotIcon )
97 {
98 m_SlotIcon.GetRadialIconPanel().Show( !m_LockCargo );
99 }
100 }
101
102 override bool IsOpened()
103 {
104 return !m_Closed && !m_LockCargo;
105 }
106
107 override void UpdateInterval()
108 {
109 if ( m_Entity )
110 {
111 if ( m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() )
112 {
113 LockCargo(true);
114 if ( m_CargoGrid.IsVisible() )
115 {
116 RecomputeOpenedContainers();
117 }
118 }
119 else
120 {
121 LockCargo(false);
122 if ( !m_CargoGrid.IsVisible() )
123 {
124 RecomputeOpenedContainers();
125 }
126 }
127
128 super.UpdateInterval();
129 m_CargoGrid.UpdateInterval();
130
131 bool hide = m_LockCargo || ItemManager.GetInstance().GetDraggedItem() == m_Entity;
132 if (!hide)
133 {
134 SetOpenForSlotIcon(IsOpened());
135 }
136
137 if ( m_SlotIcon )
138 {
139 m_SlotIcon.GetRadialIconPanel().Show( !hide );
140 }
141 }
142 }
143
145 {
146 return m_CargoGrid.IsFirstContainerFocused();
147 }
148
150 {
151 return m_CargoGrid.IsLastContainerFocused();
152 }
153
154 override void SetDefaultFocus( bool while_micromanagment_mode = false )
155 {
156 m_CargoGrid.SetDefaultFocus( while_micromanagment_mode );
157 }
158
159 override void UnfocusAll()
160 {
161 m_CargoGrid.Unfocus();
162 }
163
164 override bool SplitItem()
165 {
166 return m_CargoGrid.SplitItem();
167 }
168
169 override bool EquipItem()
170 {
171 return m_CargoGrid.EquipItem();
172 }
173
174 override bool TransferItem()
175 {
176 return m_CargoGrid.TransferItem();
177 }
178
180 {
181 return m_CargoGrid.TransferItemToVicinity();
182 }
183
184 override bool InspectItem()
185 {
186 return m_CargoGrid.InspectItem();
187 }
188
189 void SetEntity( EntityAI entity, int cargo_index = 0, bool immedUpdate = true )
190 {
191 m_Entity = entity;
192 m_CargoIndex = cargo_index;
193
194 SetOpenState( true );
195
196 m_CargoGrid.SetEntity( entity, immedUpdate );
197 m_CargoGrid.UpdateHeaderText();
198 m_ClosableHeader.SetItemPreview( entity );
199 CheckHeaderDragability();
200 ( Container.Cast( m_Parent ) ).Insert( this, -1, false );
201
202 if ( m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() )
203 LockCargo(true);
204 else
205 LockCargo(false);
206
207 if ( immedUpdate )
208 {
209 Refresh();
210 GetMainWidget().Update();
211 }
212 }
213
215 {
216 return m_Entity;
217 }
218
220 {
221 return m_Entity;
222 }
223
225 {
226 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
227 if( !ipw )
228 {
229 string name = w.GetName();
230 name.Replace( "PanelWidget", "Render" );
231 ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
232 }
233 if( !ipw )
234 {
235 ipw = ItemPreviewWidget.Cast( w );
236 }
237 if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
238 {
239 return null;
240 }
241 return ipw.GetItem();
242 }
243
244 bool DraggingOverGrid( Widget w, int x, int y, Widget reciever )
245 {
246 if( w == null )
247 {
248 return false;
249 }
250
251 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
252 if( !player.CanManipulateInventory() )
253 {
254 return false;
255 }
256
257 EntityAI item = GetItemPreviewItem( w );
258
259 if( !item )
260 {
261 return false;
262 }
263
264 if( !item.GetInventory().CanRemoveEntity() )
265 {
266 return false;
267 }
268
269 int color, c_x, c_y;
270
271 #ifdef PLATFORM_CONSOLE
272 int idx = -1;
273 #else
274 int idx = 0;
275 #endif
276
277 CargoBase cargo = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex);
278 if( cargo )
279 {
280 c_x = cargo.GetHeight();
281 c_y = cargo.GetWidth();
282 }
283
285 #ifdef PLATFORM_CONSOLE
286 x = 0;
287 y = cargo.GetItemCount();
288 m_Entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.CARGO, dst );
289 #else
290 dst.SetCargoAuto(cargo, item, x, y, item.GetInventory().GetFlipCargo());
291 #endif
292
293 #ifdef PLATFORM_CONSOLE
294 if( dst.IsValid() && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
295 #else
296 if( m_Entity && c_x > x && c_y > y && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
297 #endif
298 {
300 if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
301 {
302 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
303 }
304 else
305 {
306 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
307 }
309 }
310 else
311 {
312 color = ColorManager.RED_COLOR;
314 }
315
316 if( w.FindAnyWidget("Cursor") )
317 {
318 w.FindAnyWidget("Cursor").SetColor( color );
319 }
320 else
321 {
322 string name = w.GetName();
323 name.Replace( "PanelWidget", "Cursor" );
324 if( w.FindAnyWidget( name ) )
325 {
326 w.FindAnyWidget( name ).SetColor( color );
327 }
328 }
329
330 return true;
331 }
332
333 void DropReceived( Widget w, int x, int y )
334 {
335 float xx, yy;
336 GetMainWidget().Update();
337 GetMainWidget().GetScreenSize( xx, yy );
338 if( GetMainWidget().FindAnyWidget("Background") )
339 {
340 GetMainWidget().FindAnyWidget("Background").Show( true );
341 GetMainWidget().FindAnyWidget("Background").SetSize( xx, yy );
342 }
343 EntityAI item = GetItemPreviewItem( w );
344 if( !item )
345 {
346 return;
347 }
348
349 #ifdef PLATFORM_CONSOLE
350 if( m_CargoGrid.HasItem( item ) )
351 {
352 return;
353 }
354 #endif
355
356 #ifdef PLATFORM_CONSOLE
357 int idx = -1;
358 #else
359 int idx = 0;
360 #endif
361 int c_x, c_y;
362
363 CargoBase cargo = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex);
364
365 if( cargo )
366 {
367 c_x = cargo.GetHeight();
368 c_y = cargo.GetWidth();
369 }
370
372 #ifdef PLATFORM_CONSOLE
373 x = 0;
374 y = cargo.GetItemCount();
375 m_Entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.CARGO, dst );
376 #else
377 dst.SetCargoAuto(cargo, item, x, y, item.GetInventory().GetFlipCargo());
378 #endif
379
381 item.GetInventory().GetCurrentInventoryLocation(src);
382
383 if(src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
384 return;
385
386 #ifdef PLATFORM_CONSOLE
387 if(dst.IsValid() && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
388 #else
389 if( c_x > x && c_y > y && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
390 #endif
391 {
392 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
393
395
396 Icon icon = m_CargoGrid.GetIcon( item );
397
398 if( icon && w && w.FindAnyWidget("Cursor") )
399 {
400 w.FindAnyWidget("Cursor").SetColor( ColorManager.BASE_COLOR );
401 icon.Refresh();
402 Refresh();
403 }
404 }
405
408 }
409
410 void TakeIntoHands( notnull PlayerBase player, notnull EntityAI item )
411 {
412 ItemBase item_base = ItemBase.Cast( item );
413
414 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
415 return;
416
417 float stackable = item_base.GetTargetQuantityMax();
418
419 if( stackable == 0 || stackable >= item_base.GetQuantity() )
420 {
421 player.PredictiveTakeEntityToHands( item );
422 }
423 else if( stackable != 0 && stackable < item_base.GetQuantity() )
424 {
425 item_base.SplitIntoStackMaxHandsClient( player );
426 }
427 }
428
429 override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
430 {
431 DraggingOver( w, x, y, receiver );
432 }
433
434 override void DraggingOver( Widget w, int x, int y, Widget receiver )
435 {
436 if( !w )
437 return;
438 EntityAI item = GetItemPreviewItem( w );
439 if( !item )
440 return;
441
442 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
443 if( item.GetInventory().CanRemoveEntity() && player.CanManipulateInventory() && m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !m_Entity.GetInventory().HasEntityInCargo( item ) )
444 {
447 if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
448 {
449 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
450 }
451 else
452 {
453 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
454 }
455 }
456 else
457 {
460 }
461 }
462
463 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
464 {
465 EntityAI item = GetItemPreviewItem( w );
466 if( !item )
467 {
468 return;
469 }
470
471 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
473 if( GetEntity() && item.GetInventory().GetCurrentInventoryLocation(src))
474 {
476 if (m_Entity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, dst))
477 {
478 player.PredictiveTakeToDst(src, dst);
479 }
480
481 bool can_add = m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() );
482 bool in_cargo = !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item );
483 if( can_add && in_cargo )
484 {
486 }
487 }
488 }
489
490 CargoContainer GetCargo()
491 {
492 return m_CargoGrid;
493 }
494}
EntityAI m_Entity
Определения ActionDebug.c:11
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
override void OnShow()
Определения ControlsXbox.c:349
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
Определения InventoryLocation.c:17
override void OnHide()
Определения InventoryMenu.c:141
PlayerBase GetPlayer()
Определения ModifierBase.c:51
Widget m_Parent
Определения SizeToChild.c:92
void Refresh()
Определения SizeToChild.c:108
proto native int GetItemCount()
proto native int GetWidth()
proto native int GetHeight()
represents base for cargo storage for entities
Определения Cargo.c:7
int m_CargoIndex
Определения ContainerWithCargo.c:4
override bool IsFirstContainerFocused()
Определения ContainerWithCargo.c:144
override void SetDefaultFocus(bool while_micromanagment_mode=false)
Определения ContainerWithCargo.c:154
override void Close()
Определения ContainerWithCargo.c:85
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
Определения ContainerWithCargo.c:429
override bool IsLastContainerFocused()
Определения ContainerWithCargo.c:149
void DropReceived(Widget w, int x, int y)
Определения ContainerWithCargo.c:333
override bool EquipItem()
Определения ContainerWithCargo.c:169
override void DraggingOver(Widget w, int x, int y, Widget receiver)
Определения ContainerWithCargo.c:434
override bool CanCombineAmmo()
Определения ContainerWithCargo.c:41
override bool CanCombine()
Определения ContainerWithCargo.c:36
void SetEntity(EntityAI entity, int cargo_index=0, bool immedUpdate=true)
Определения ContainerWithCargo.c:189
override bool InspectItem()
Определения ContainerWithCargo.c:184
override bool TransferItemToVicinity()
Определения ContainerWithCargo.c:179
override bool IsOpened()
Определения ContainerWithCargo.c:102
EntityAI GetEntity()
Определения ContainerWithCargo.c:214
ref CargoContainer m_CargoGrid
Определения ContainerWithCargo.c:3
override bool IsItemActive()
Определения ContainerWithCargo.c:31
override bool IsItemWithQuantityActive()
Определения ContainerWithCargo.c:46
override void UpdateInterval()
Определения ContainerWithCargo.c:107
override bool TransferItem()
Определения ContainerWithCargo.c:174
CargoContainer GetCargo()
Определения ContainerWithCargo.c:490
EntityAI GetItemPreviewItem(Widget w)
Определения ContainerWithCargo.c:224
override bool IsEmpty()
Определения ContainerWithCargo.c:26
void LockCargo(bool value)
Определения ContainerWithCargo.c:51
override EntityAI GetFocusedContainerEntity()
Определения ContainerWithCargo.c:219
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
Определения ContainerWithCargo.c:463
override void Open()
Определения ContainerWithCargo.c:68
override bool SplitItem()
Определения ContainerWithCargo.c:164
override void UnfocusAll()
Определения ContainerWithCargo.c:159
void ContainerWithCargo(LayoutHolder parent, int sort=-1)
Определения ContainerWithCargo.c:6
void TakeIntoHands(notnull PlayerBase player, notnull EntityAI item)
Определения ContainerWithCargo.c:410
bool DraggingOverGrid(Widget w, int x, int y, Widget reciever)
Определения ContainerWithCargo.c:244
override bool IsDisplayable()
Определения ContainerWithCargo.c:19
void SetColor(Widget w, int color)
Определения ColorManager.c:32
static int BASE_COLOR
Определения ColorManager.c:15
static int GREEN_COLOR
Определения ColorManager.c:17
static int RED_COLOR
Определения ColorManager.c:16
static ColorManager GetInstance()
Определения ColorManager.c:27
Определения ColorManager.c:2
Определения CargoContainer.c:3
Определения Building.c:6
override void Refresh()
Определения Icon.c:1216
Определения Icon.c:2
proto native bool IsValid()
verify current set inventory location
proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip)
based on Cargo.IsProxyCargo uses SetProxyCargo or SetCargo respectively
proto native bool CompareLocationOnly(notnull InventoryLocation other)
proto native bool GetFlip()
returns flip status of cargo
InventoryLocation.
Определения InventoryLocation.c:29
Определения InventoryItem.c:731
EntityAI GetDraggedItem()
Определения ItemManager.c:368
void ShowSourceDropzone(EntityAI item)
Определения ItemManager.c:302
Widget GetLeftDropzone()
Определения ItemManager.c:336
Widget GetRightDropzone()
Определения ItemManager.c:344
void HideDropzones()
Определения ItemManager.c:287
void SetIsDragging(bool is_dragging)
Определения ItemManager.c:383
static ItemManager GetInstance()
Определения ItemManager.c:282
void SetDefaultOpenState(string type, bool is_opened)
Определения ItemManager.c:168
Определения ItemManager.c:2
proto native EntityAI GetItem()
Определения gameplay.c:277
Определения Container.c:2
Определения PlayerBaseClient.c:2
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
Определения SplitItemUtils.c:34
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
Определения SplitItemUtils.c:3
Определения SplitItemUtils.c:2
void RegisterOnDraggingOver(Widget w, Managed eventHandler, string functionName)
Определения WidgetEventHandler.c:112
static WidgetEventHandler GetInstance()
Определения WidgetEventHandler.c:22
Определения EnWidgets.c:190
proto native CGame GetGame()
proto native Widget FindAnyWidget(string pathname)