DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
AttachmentCategoriesRow.c
Go to the documentation of this file.
2{
3 protected string m_CategoryIdentifier;
4 protected string m_RowConfigPath;
5 protected bool m_Refreshing;
6
9
10 void AttachmentCategoriesRow( LayoutHolder parent, int sort = -1 )
11 {
12 m_Refreshing = false;
15
16 m_Body.Insert(m_AttachmentsContainer);
17
18 m_ClosableHeader.GetMainWidget().ClearFlags( WidgetFlags.DRAGGABLE );
19
20 RecomputeOpenedContainers();
21 }
22
24 {
26 }
27
29 {
30 SlotsIcon icon = GetFocusedSlotsIcon();
31 if (icon)
32 {
33 return icon.GetSlotID();
34 }
35 return -1;
36 }
37
38 override bool Select()
39 {
40 Man player = GetGame().GetPlayer();
41 SlotsIcon focused_icon = GetFocusedSlotsIcon();
42 EntityAI focused_item = GetFocusedItem();
43 Container focused_cont = GetFocusedContainer();
44 ItemBase selected_item = ItemBase.Cast( ItemManager.GetInstance().GetSelectedItem() ); // == dragged item
45
46 if( selected_item && focused_item != selected_item)//dropping from micromanagement
47 {
48 if( selected_item.GetInventory().CanRemoveEntity() )
49 {
50 int stack_max;
51
52 if (!focused_icon)
53 {
54 if (focused_cont)
55 {
56 focused_cont.Select();
57 }
58 }
59 else if( !focused_item && m_Entity && m_Entity.GetInventory().CanAddAttachmentEx( selected_item, focused_icon.GetSlotID() ) )
60 {
61 stack_max = InventorySlots.GetStackMaxForSlotId( focused_icon.GetSlotID() );
62 float quantity = selected_item.GetQuantity();
63 if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
64 {
65 player.PredictiveTakeEntityToTargetAttachmentEx( m_Entity, selected_item, focused_icon.GetSlotID() );
66 return true;
67 }
68 else
69 {
70 selected_item.SplitIntoStackMaxClient( m_Entity, focused_icon.GetSlotID() );
71 return true;
72 }
73 }
74 else if (focused_icon.GetSlotID() != -1)
75 {
76 if (focused_item && focused_item.GetHierarchyParent() && focused_item.GetHierarchyParent().GetInventory().CanAddAttachment(selected_item))
77 {
79 focused_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
80 stack_max = InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
81 quantity = focused_item.GetQuantity();
82 if( focused_item.CanBeCombined( ItemBase.Cast( selected_item ) ) )
83 {
84 focused_item.CombineItemsClient( selected_item, true );
85 return true;
86 }
87 else if( stack_max == 0 && GameInventory.CanSwapEntitiesEx( focused_item, selected_item ) )
88 {
89 player.PredictiveSwapEntities( selected_item, focused_item );
90 return true;
91 }
92 else if( m_AttachmentCargos.Contains( inv_loc.GetSlot() ) )
93 {
94 if( focused_item.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo() ) )
95 {
96 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( player ), focused_item, selected_item );
97 return true;
98 }
99 }
100 }
101 }
102 }
103 }
104 else //clicking
105 {
106 if( focused_item && focused_item.GetInventory().CanRemoveEntity() && (!focused_icon || !focused_icon.IsOutOfReach()) )
107 {
108 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
109 if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
110 {
111 if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
112 {
113 player.PredictiveSwapEntities( item_in_hands, focused_item );
114 return true;
115 }
116 }
117 else
118 {
119 if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
120 {
121 player.PredictiveTakeEntityToHands( focused_item );
122 return true;
123 }
124 }
125 }
126 }
127
128 return false;
129 }
130
131 override bool TransferItem()
132 {
133 EntityAI entity = GetFocusedItem();
134 SlotsIcon focused_icon = GetFocusedSlotsIcon();
135 if( entity && !entity.IsLockedInSlot() && (!focused_icon || !focused_icon.IsOutOfReach()) )
136 {
137 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
138 GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, entity );
139 return true;
140 }
141 return false;
142 }
143
145 {
146 ItemBase item = ItemBase.Cast(GetFocusedItem());
147 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
148 SlotsIcon focused_icon = GetFocusedSlotsIcon();
149
150 if( item && !item.IsLockedInSlot() && (focused_icon && !focused_icon.IsOutOfReach()) )
151 {
152 if( item.GetTargetQuantityMax() < item.GetQuantity() )
153 item.SplitIntoStackMaxClient( null, -1 );
154 else
155 player.PhysicalPredictiveDropItem( item );
156 return true;
157 }
158 return false;
159 }
160
161 override bool Combine()
162 {
163 Man player = GetGame().GetPlayer();
164 ItemBase prev_item = ItemBase.Cast( GetFocusedItem() );
165 ItemBase selected_item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
166 SlotsIcon focused_icon = GetFocusedSlotsIcon();
167
168 if( selected_item )
169 {
170 int selected_slot = GetFocusedSlot();
171 int stack_max;
172 if( selected_item && selected_item.GetInventory().CanRemoveEntity() && (focused_icon && !focused_icon.IsOutOfReach()) )
173 {
174 if( !prev_item && m_Entity.GetInventory().CanAddAttachmentEx( selected_item, selected_slot ) )
175 {
176 stack_max = InventorySlots.GetStackMaxForSlotId( selected_slot );
177 float quantity = selected_item.GetQuantity();
178 if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
179 {
180 player.PredictiveTakeEntityToTargetAttachmentEx( m_Entity, selected_item, selected_slot );
181 return false;
182 }
183 else
184 {
185 selected_item.SplitIntoStackMaxClient( m_Entity, selected_slot );
186 return false;
187 }
188 }
189 else if( selected_slot != -1 )
190 {
191 if( prev_item )
192 {
194 prev_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
195 stack_max = InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
196 quantity = prev_item.GetQuantity();
197 if( prev_item.CanBeCombined( ItemBase.Cast( selected_item ) ) )
198 {
199 prev_item.CombineItemsClient( selected_item, true );
200 return false;
201 }
202 else if( stack_max == 0 && GameInventory.CanSwapEntitiesEx( prev_item, selected_item ) )
203 {
204 player.PredictiveSwapEntities( selected_item, prev_item );
205 return false;
206 }
207 else if( m_AttachmentCargos.Contains( inv_loc.GetSlot() ) )
208 {
209 if( prev_item.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo() ) )
210 {
211 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( player ), prev_item, selected_item );
212 return false;
213 }
214 }
215 }
216 }
217 }
218 }
219 return true;
220 }
221
222 override bool CanSplitEx(EntityAI focusedItem)
223 {
224 return false;
225 }
226
227 override bool SplitItem()
228 {
229 return false;
230 }
231
232 override bool EquipItem() //TODO: may be possible, but the hint doesn't reflect it anyway
233 {
234 return false;
235 }
236
237 override bool CanCombine()
238 {
239 Man player = GetGame().GetPlayer();
240 ItemBase prev_item = ItemBase.Cast( GetFocusedItem() );
241 ItemBase selected_item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
242 SlotsIcon focused_icon = GetFocusedSlotsIcon();
243
244 if( selected_item )
245 {
246 int selected_slot = GetFocusedSlot();
247 int stack_max;
248 if( selected_item && selected_item.GetInventory().CanRemoveEntity() && (focused_icon && !focused_icon.IsOutOfReach()) )
249 {
250 if( m_Entity.GetInventory().CanAddAttachmentEx( selected_item, selected_slot ) )
251 {
252 stack_max = InventorySlots.GetStackMaxForSlotId( selected_slot );
253 float quantity = selected_item.GetQuantity();
254 if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
255 {
256 return true;
257 }
258 else
259 {
260 return true;
261 }
262 }
263 else if( selected_slot != -1 )
264 {
265 if( prev_item )
266 {
268 prev_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
269 stack_max = InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
270 quantity = prev_item.GetQuantity();
271 if( prev_item.CanBeCombined( ItemBase.Cast( selected_item ) ) )
272 {
273 return true;
274 }
275 }
276 }
277 }
278 }
279 return false;
280 }
281
282 override bool CanCombineAmmo()
283 {
284 return false;
285 }
286
287 override bool IsItemActive()
288 {
289 SlotsIcon icon = GetFocusedSlotsIcon();
290 return GetFocusedItem() != null && (!icon || !icon.IsOutOfReach());
291 }
292
294 {
295 ItemBase item = ItemBase.Cast(GetFocusedItem());
296 SlotsIcon icon = GetFocusedSlotsIcon();
297 return item && ( !icon || !icon.IsOutOfReach()) && item.CanBeSplit();
298 }
299
300 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
301 {
304 SlotsIcon slots_icon;
305 EntityAI receiver_item;
306 int slot_id = -1;
307 bool is_reserved = false;
308 EntityAI attached_entity;
309 receiver.GetUserData(slots_icon);
310 float stackable = 0.0;
312
313 if( slots_icon )
314 {
315 receiver_item = slots_icon.GetEntity();
316 slot_id = slots_icon.GetSlotID();
317 attached_entity = slots_icon.GetSlotParent();
318 is_reserved = slots_icon.IsReserved();
319 }
320
321 EntityAI item = GetItemPreviewItem( w );
322 if( !item )
323 {
324 return;
325 }
326 ItemBase item_base = ItemBase.Cast( item );
327
328 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
329 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
330 return;
331
332 EntityAI target_att_entity = m_Entity;
333 Weapon_Base wpn;
334 Magazine mag;
335 if( Class.CastTo(wpn, m_Entity ) && Class.CastTo(mag, item ) )
336 {
337 if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
338 {
339 player.GetWeaponManager().AttachMagazine( mag );
340 }
341 }
342 else if( receiver_item && !is_reserved )
343 {
344 if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
345 {
346 ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
347 }
348 else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
349 {
350 if( !receiver_item.GetInventory().CanRemoveEntity() )
351 return;
352 GetGame().GetPlayer().PredictiveSwapEntities( receiver_item, item );
353 }
354 else if( receiver_item.GetInventory().CanAddAttachment( item ) )
355 {
356 player.PredictiveTakeEntityToTargetAttachment(receiver_item, item);
357 }
358 }
359 else if( attached_entity && slot_id != -1 && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
360 {
361 item_base = ItemBase.Cast( item );
362 stackable = item_base.GetTargetQuantityMax( slot_id );
363
364 if( stackable == 0 || stackable >= item_base.GetQuantity() )
365 {
366 player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, slot_id);
367 }
368 else if( stackable != 0 && stackable < item_base.GetQuantity() )
369 {
370 item_base.SplitIntoStackMaxClient( m_Entity, slot_id );
371 }
372 }
373 else if(attached_entity && slot_id == -1 && attached_entity.GetInventory().FindFreeLocationFor(item,FindInventoryLocationType.ATTACHMENT,il))
374 {
375 item_base = ItemBase.Cast( item );
376 stackable = item_base.GetTargetQuantityMax( il.GetSlot() );
377
378 if( stackable == 0 || stackable >= item_base.GetQuantity() )
379 {
380 player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, il.GetSlot());
381 }
382 else if( stackable != 0 && stackable < item_base.GetQuantity() )
383 {
384 item_base.SplitIntoStackMaxClient( m_Entity, il.GetSlot() );
385 }
386 }
387 /*else if( ( m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && ( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item )) ) )
388 {
389 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
390 }*/
391 }
392
393 override void UnfocusAll()
394 {
395 int i;
396 for ( i = 1; i < Count(); i++ )
397 {
398 for ( int j = 0; j < ITEMS_IN_ROW; j++ )
399 {
400 Widget w = Get( i ).GetMainWidget().FindAnyWidget( "Cursor" + j );
401 if( w )
402 w.Show( false );
403 }
404 }
405 for ( i = 0; i < m_AttachmentCargos.Count(); i++ )
406 {
407 m_AttachmentCargos.GetElement( i ).Unfocus();
408 m_AttachmentCargos.GetElement( i ).SetActive( false );
409 }
410 }
411
412 override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
413 {
414 if( w == null )
415 {
416 return;
417 }
418 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
419 if(!iw)
420 {
421 string name = w.GetName();
422 name.Replace("PanelWidget", "Render");
423 iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name) );
424 }
425 if(!iw)
426 {
427 iw = ItemPreviewWidget.Cast( w );
428 }
429
430 if( !iw || !iw.GetItem() || (iw.GetItem() == m_Entity) )
431 {
432 return;
433 }
434
435 ItemBase item;
436 ItemBase receiver_item;
437 name = receiver.GetName();
438 name.Replace("PanelWidget", "Render");
439 ItemPreviewWidget receiver_iw = ItemPreviewWidget.Cast( receiver.FindAnyWidget(name) );
440 if(receiver_iw)
441 receiver_item = ItemBase.Cast( receiver_iw.GetItem() );
442
443 SlotsIcon slots_icon;
444 receiver.GetUserData(slots_icon);
445
446 if( receiver_item )
447 {
448 int stack_max = InventorySlots.GetStackMaxForSlotId( receiver_item.GetInventory().GetSlotId(0) );
449 //int quantity = receiver_item.GetQuantity();
450 //bool combinable = ( quantity < stack_max ) && ( ItemBase.Cast( receiver_item ).CanBeCombined( ItemBase.Cast( iw.GetItem() ) ) );
451 if( receiver_item.CanBeCombined( ItemBase.Cast( iw.GetItem() ) ) )
452 {
454 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
456 }
457 else if( stack_max == 0 && GameInventory.CanSwapEntitiesEx( receiver_item, iw.GetItem() ) )
458 {
460 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
462 }
463 else
464 {
467 }
468 }
469 else if( slots_icon && slots_icon.GetSlotID() != -1 )
470 {
471 item = ItemBase.Cast( iw.GetItem() );
472
473 if( item && m_Entity.GetInventory().CanAddAttachmentEx( item, slots_icon.GetSlotID() ) )
474 {
476 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
478 }
479 else
480 {
483 }
484 }
485 else
486 {
489 }
490 }
491
492 void DoubleClick(Widget w, int x, int y, int button)
493 {
494 if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
495 {
496 if( w == null )
497 {
498 return;
499 }
500 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
501 if( !iw )
502 {
503 string name = w.GetName();
504 name.Replace( "PanelWidget", "Render" );
505 iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
506 }
507 if( !iw )
508 {
509 iw = ItemPreviewWidget.Cast( w );
510 }
511 if( !iw.GetItem() )
512 {
513 return;
514 }
515
516 SlotsIcon slots_icon;
517 w.GetUserData(slots_icon);
518
519 if( slots_icon && m_Entity.GetInventory().GetSlotLock( iw.GetUserID() ) )
520 {
521 return;
522 }
523
524 ItemBase item = ItemBase.Cast( iw.GetItem() );
525
526 if( !item.GetInventory().CanRemoveEntity() )
527 return;
528
529 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
530
531 if( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
532 {
533 player.PredictiveTakeEntityToHands( item );
534 }
535 else
536 {
537 if(player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
538 {
539 if( item.GetTargetQuantityMax() < item.GetQuantity() )
540 {
541 item.SplitIntoStackMaxClient( player, -1 );
542 }
543 else
544 {
545 player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, item );
546 }
547 }
548 else
549 {
550 if( player.GetHumanInventory().CanAddEntityInHands( item ) )
551 {
552 if( item.GetTargetQuantityMax() < item.GetQuantity() )
553 {
554 item.SplitIntoStackMaxHandsClient( player );
555 }
556 else
557 {
558 player.PredictiveTakeEntityToHands( item );
559 }
560 }
561 }
562 }
563
564 HideOwnedTooltip();
565
566 name = w.GetName();
567 name.Replace( "PanelWidget", "Temperature" );
568 w.FindAnyWidget( name ).Show( false );
569 }
570 }
571
572 bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
573 {
574 if( w == null )
575 {
576 return false;
577 }
578
579 EntityAI item = GetItemPreviewItem( w );
580
581 if( !item )
582 {
583 return false;
584 }
585
586 int color;
587 int idx = 0;
588 int c_x, c_y;
589
590 EntityAI target_entity;
591 CargoBase target_cargo;
592
593 target_entity = cargo.GetEntity() ;
594 if( target_entity )
595 {
596 target_cargo = target_entity.GetInventory().GetCargo();
597 }
598 else
599 return false;
600
601 if( target_cargo && target_entity )
602 {
603 c_x = target_cargo.GetHeight();
604 c_y = target_cargo.GetWidth();
605 }
606 else
607 return false;
608
609 if( c_x > x && c_y > y && target_entity.GetInventory().CanAddEntityInCargoEx( item, idx, x, y, item.GetInventory().GetFlipCargo() ) )
610 {
612 }
613 else
614 {
615 color = ColorManager.RED_COLOR;
616 }
617
618 if( w.FindAnyWidget("Selected") )
619 {
620 w.FindAnyWidget("Selected").SetColor( color );
621 }
622 else
623 {
624 string name = w.GetName();
625 name.Replace( "PanelWidget", "Selected" );
626 if( w.FindAnyWidget( name ) )
627 {
628 w.FindAnyWidget( name ).SetColor( color );
629 }
630 }
631
632 return true;
633 }
634
635 void DropReceived( Widget w, int x, int y, CargoContainer cargo )
636 {
637 EntityAI item = GetItemPreviewItem( w );
638 if( !item )
639 {
640 return;
641 }
642
643 int idx = 0;
644 int c_x, c_y;
645
646 EntityAI target_entity;
647 CargoBase target_cargo;
648
649 target_entity = cargo.GetEntity();
650 if( target_entity )
651 {
652 target_cargo = target_entity.GetInventory().GetCargo();
653 }
654 else
655 return;
656
657 if( target_cargo && target_entity )
658 {
659 c_x = target_cargo.GetHeight();
660 c_y = target_cargo.GetWidth();
661 }
662 else
663 return;
664
666 dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
667
668 if( c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
669 {
670 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
671
673
674 Icon icon = cargo.GetIcon( item );
675
676 if( icon )
677 {
678 icon.GetRootWidget().FindAnyWidget("Selected").SetColor( ColorManager.BASE_COLOR );
679 icon.RefreshPos( x, y );
680 icon.Refresh();
681 Refresh();
682 }
683 }
684 }
685
687 {
688 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
689 if( !ipw )
690 {
691 string name = w.GetName();
692 name.Replace( "PanelWidget", "Render" );
693 ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
694 }
695 if( !ipw )
696 {
697 ipw = ItemPreviewWidget.Cast( w );
698 }
699 if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
700 {
701 return null;
702 }
703 return ipw.GetItem();
704 }
705
706 override void Refresh()
707 {
708 if (!m_Refreshing)
709 {
710 if( !m_Closed )
711 {
712 super.Refresh();
714 }
715 }
716 }
717
719 {
720 m_Refreshing = true;
721 int row_count = m_AttachmentsContainer.GetRowCount();
722 int row;
723 for (row = 0; row < row_count; row++)
724 {
725 int col_count = m_AttachmentsContainer.GetColumnCountForRow(row);
726 int col;
727 for (col = 0; col < col_count; col++)
728 {
729 RefreshSlot(row, col, -1, "");
730 }
731 }
732 m_Refreshing = false;
733 }
734
735 //slot_id and slot_name parametr is not used
736 void RefreshSlot( int row, int column, int slot_id, string slot_name )
737 {
739 int slot_id_ = icon.GetSlotID();
740 EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id_ );
742
743 if( !m_Entity.CanDisplayAttachmentSlot( slot_id_ ) )
744 {
745 icon.Clear();
746 icon.GetMainWidget().Show( false );
747 }
748 else if( !item )
749 {
750 icon.Clear();
751 icon.GetMainWidget().Show( true );
752 cont = m_AttachmentCargos.Get(slot_id_);
753 if( cont )
754 {
755 m_AttachmentCargos.Remove(slot_id_);
756 this.Remove(cont);
757 ( Container.Cast( cont.m_Parent ) ).Remove( cont );
758 }
759 }
760 else
761 {
762 icon.GetMainWidget().Show( true );
763 if (icon.GetEntity() != item)
764 {
765 icon.Init( item );
766 }
767 else
768 {
769 icon.Refresh();
770 }
771 //icon.Refresh();
772
773 cont = m_AttachmentCargos.Get(slot_id_);
774 if( cont && cont.GetEntity() != item)
775 {
776 m_AttachmentCargos.Remove(slot_id_);
777 ( Container.Cast( cont.m_Parent ) ).Remove( cont );
778 this.Remove(cont);
779 cont = null;
780 }
781
782 if( !cont )
783 {
784 if( item.GetInventory().GetCargo() && m_AttachmentCargos )
785 {
786 cont = new ContainerWithCargo( this, true );
787 cont.GetRootWidget().SetSort( m_AttachmentCargos.Count() + 10 );
788 cont.SetEntity( item );
789 cont.SetSlotIcon( icon );
790
791 m_AttachmentCargos.Insert( slot_id_, cont );
792 icon.SetContainer(cont);
793
794 //icon.GetRadialIconPanel().Show( true );
795 //icon.GetRadialIconPanel().Show( cont.IsDisplayable() );
796
797 SetOpenForSlotIcon(cont.IsOpened(),icon);
798 }
799 }
800
801 if (cont)
802 {
803 icon.GetRadialIconPanel().Show( cont.IsDisplayable() );
804 }
805
806 string slot_name_ = InventorySlots.GetSlotName(slot_id_);
807 bool draggable = true;
808 bool can_be_removed = item.GetInventory().CanRemoveEntity();
809 bool in_hands_condition = m_Entity.GetHierarchyRoot() == GetGame().GetPlayer();
810 bool in_vicinity_condition = AttachmentsOutOfReach.IsAttachmentReachable( m_Entity, slot_name_ );
811 if( m_Entity.GetInventory().GetSlotLock( slot_id_ ) && ItemManager.GetInstance().GetDraggedItem() != item )
812 {
813 icon.GetMountedWidget().Show( true );
814 draggable = false;
815 }
816 else
817 {
818 icon.GetMountedWidget().Show( false );
819 }
820
821 if( !m_Entity.CanReleaseAttachment( item ) )
822 {
823 draggable = false;
824 }
825
826 if ((in_hands_condition || in_vicinity_condition) && can_be_removed)
827 {
828 icon.GetOutOfReachWidget().Show( false );
829 }
830 else
831 {
832 icon.GetOutOfReachWidget().Show( true );
833 draggable = false;
834 }
835
836 if( draggable )
837 {
838 icon.GetRender().GetParent().SetFlags( WidgetFlags.DRAGGABLE );
839 }
840 else
841 {
842 icon.GetRender().GetParent().ClearFlags( WidgetFlags.DRAGGABLE );
843 }
844 }
845 }
846
847 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
848 {
849 super.OnMouseButtonDown(w, x, y, button);
850
851 SlotsIcon slots_icon;
852 w.GetUserData(slots_icon);
853
854 Container c = Container.Cast( slots_icon.GetContainer() );
855 if ( c )
856 {
857 if ( c.IsOpened() )
858 {
859 c.Close();
860 }
861 else
862 {
863 c.Open();
864 }
865 }
866
867 #ifdef DIAG_DEVELOPER
868 if ( GetDayZGame().IsLeftCtrlDown() && button == MouseState.RIGHT )
869 {
870 SlotsIcon user_data;
871 w.GetUserData(user_data);
872 if (user_data)
873 {
874 ShowActionMenu( user_data.GetItem() );
875 return true;
876 }
877 }
878 #endif
879 return false;
880 }
881
882 void Init(int attachments_categories_count, int i, string attachment_category, string config_path_attachment_categories, EntityAI entity, int parent_m_Body_count )
883 {
884 m_Entity = entity;
885 Header he = GetHeader();
886
887 m_CategoryIdentifier = attachment_category;
888
889 ref array<string> player_ghosts_slots2 = new array<string>;
890 string category_name;
891
892 m_RowConfigPath = config_path_attachment_categories + " " + attachment_category + " attachmentSlots";
893 string config_path_category_name = config_path_attachment_categories + " " + attachment_category + " name";
894 GetGame().ConfigGetTextArray( m_RowConfigPath, player_ghosts_slots2 );
895 GetGame().ConfigGetText( config_path_category_name, category_name );
896 he.SetName( category_name );
897
899 SetHeader(null);
900
901 int count = player_ghosts_slots2.Count();
902 int last_row = count / ITEMS_IN_ROW;
904
905 for ( int j = 0; j < count; j++ )
906 {
907 string slot_name = player_ghosts_slots2.Get(j);
908 string icon_name; //must be in format "set:<setname> image:<imagename>"
909 string path = "CfgSlots" + " Slot_" + slot_name;
910
911 int slot_id = InventorySlots.GetSlotIdFromString( slot_name );
912
913 GetGame().ConfigGetText( path + " ghostIcon", icon_name );
914 GetGame().ConfigGetText( path + " name", slot_name );
915
916 int row = j / ITEMS_IN_ROW;
917 int column = j % ITEMS_IN_ROW;
918 if (column == 0)
919 {
921 ic.GetRootWidget().SetAlpha(0.7);
922 if (row == last_row)
923 {
924 ic.SetColumnCount( count % ITEMS_IN_ROW );
925 }
926 else
927 {
928 ic.SetColumnCount( ITEMS_IN_ROW );
929 }
930 m_AttachmentsContainer.Insert(ic);
931 ic.GetRootWidget().SetSort( row );
932 }
933
934 SlotsIcon icon = ic.GetSlotIcon( column );
935 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetMainWidget(), this, "OnDropReceivedFromHeader" );
936 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), this, "OnDropReceivedFromHeader" );
937 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(), this, "OnDropReceivedFromHeader" );
938
939 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetMainWidget(), this, "DraggingOverHeader" );
940 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(), this, "DraggingOverHeader" );
941 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(), this, "DraggingOverHeader" );
942
943 WidgetEventHandler.GetInstance().RegisterOnDrop( icon.GetMainWidget(), this, "OnIconDrop" );
944 WidgetEventHandler.GetInstance().RegisterOnDrop( icon.GetPanelWidget(), this, "OnIconDrop" );
945
946 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(), this, "OnMouseButtonDown" );
947
949
950 icon.SetSlotID(slot_id);
952
953 //RefreshSlot( row, column, slot_id, slot_name );
954 }
956 }
957
958 override void UpdateInterval()
959 {
960 super.UpdateInterval();
962 }
963}
const int ITEMS_IN_ROW
Definition Attachments.c:1
void Remove(Object object)
DayZGame g_Game
Definition DayZGame.c:3654
DayZGame GetDayZGame()
Definition DayZGame.c:3656
string GetHeader()
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition ItemBase.c:5444
PlayerBase GetPlayer()
array< ref PlayerStatBase > Get()
string name
class PluginItemDiagnosticEventHandler extends ScriptedWidgetEventHandler m_Entity
void DropReceived(Widget w, int x, int y, CargoContainer cargo)
void AttachmentCategoriesRow(LayoutHolder parent, int sort=-1)
protected ref map< int, ref ContainerWithCargo > m_AttachmentCargos
void Init(int attachments_categories_count, int i, string attachment_category, string config_path_attachment_categories, EntityAI entity, int parent_m_Body_count)
protected ref AttachmentsGroupContainer m_AttachmentsContainer
void RefreshSlot(int row, int column, int slot_id, string slot_name)
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
EntityAI GetItemPreviewItem(Widget w)
override bool CanSplitEx(EntityAI focusedItem)
void DoubleClick(Widget w, int x, int y, int button)
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
bool DraggingOverGrid(Widget w, int x, int y, Widget reciever, CargoContainer cargo)
protected string m_CategoryIdentifier
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
int GetRowCount(bool include_invisible=true)
int GetColumnCountForRow(int row, bool include_invisible=true)
override void SetHeader(Header header)
SlotsIcon GetSlotsIcon(int row, int column, bool include_invisible=true)
static bool IsAttachmentReachable(EntityAI e, string att_slot_name="", int slot_id=-1, float range=1.5)
proto native DayZPlayer GetPlayer()
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native void ConfigGetTextArray(string path, out TStringArray values)
Get array of strings from config on path.
represents base for cargo storage for entities
Definition Cargo.c:7
proto native int GetHeight()
proto native int GetWidth()
Super root of all classes in Enforce script.
Definition EnScript.c:11
void ContainerWithCargo(Container parent, int sort=-1)
static int GREEN_COLOR
static ColorManager GetInstance()
static int RED_COLOR
static int SWAP_COLOR
static int BASE_COLOR
static int COMBINE_COLOR
void SetColor(Widget w, int color)
override LayoutHolder Get(int x)
override void Close()
override bool Select()
override void Open()
bool PredictiveSwapEntities(notnull EntityAI item1, notnull EntityAI item2)
Definition Man.c:477
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
Definition Header.c:2
void SetName(string name)
Definition Header.c:33
Definition Icon.c:2
override void Refresh()
Definition Icon.c:1370
void RefreshPos(int row, int column)
Definition Icon.c:1409
InventoryLocation.
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 int GetSlot()
returns slot id if current type is Attachment
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static proto native int GetStackMaxForSlotId(int slot_Id)
static proto native owned string GetSlotName(int id)
converts slot_id to string
static proto native owned string GetSlotDisplayName(int id)
converts slot_id to string
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition Rag.c:52
EntityAI GetSelectedItem()
Definition ItemManager.c:82
void ShowSourceDropzone(EntityAI item)
Widget GetLeftDropzone()
void HideDropzones()
void SetIsDragging(bool is_dragging)
static ItemManager GetInstance()
EntityAI GetDraggedItem()
proto native EntityAI GetItem()
SlotsIcon GetSlotIcon(int index)
ItemBase GetItem()
Definition SlotsIcon.c:358
void SetSlotDisplayName(string text)
Definition SlotsIcon.c:144
override void Refresh()
Definition SlotsIcon.c:333
Widget GetRadialIconPanel()
Definition SlotsIcon.c:295
EntityAI GetEntity()
Definition SlotsIcon.c:353
EntityAI GetSlotParent()
Definition SlotsIcon.c:185
int GetSlotID()
Definition SlotsIcon.c:190
ItemPreviewWidget GetRender()
Definition SlotsIcon.c:230
Widget GetOutOfReachWidget()
Definition SlotsIcon.c:260
Widget GetMountedWidget()
Definition SlotsIcon.c:225
Container GetContainer()
Definition SlotsIcon.c:149
void Clear()
Definition SlotsIcon.c:502
bool IsReserved()
Definition SlotsIcon.c:200
Widget GetPanelWidget()
Definition SlotsIcon.c:205
ImageWidget GetGhostSlot()
Definition SlotsIcon.c:235
void SetSlotID(int slot_ID)
Definition SlotsIcon.c:195
void Init(EntityAI obj, bool reservation=false)
Definition SlotsIcon.c:460
void SetContainer(Container container)
Definition SlotsIcon.c:139
bool IsOutOfReach()
Definition SlotsIcon.c:607
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
static const int IMAGESETGROUP_INVENTORY
static string VerifyIconImageString(int imageset_group=IMAGESETGROUP_INVENTORY, string icon_name="")
Checks for improperly formated, legacy image names and corrects them to default format.
void RegisterOnMouseButtonDown(Widget w, Managed eventHandler, string functionName)
static WidgetEventHandler GetInstance()
void RegisterOnDrop(Widget w, Managed eventHandler, string functionName)
void RegisterOnDropReceived(Widget w, Managed eventHandler, string functionName)
void RegisterOnDraggingOver(Widget w, Managed eventHandler, string functionName)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
MouseState
Definition EnSystem.c:311
proto int Replace(string sample, string replace)
Replace all occurrances of 'sample' in 'str' by 'replace'.
WidgetFlags
Definition EnWidgets.c:57