2022-11-06 21:34:17 +01:00
using System ;
using System.Collections.Generic ;
2022-11-19 17:02:31 +01:00
using System.Linq ;
2022-11-06 21:34:17 +01:00
using UnityEditor ;
using UnityEngine ;
public abstract class WarehousePanelController : DraggablePanelController
{
2022-11-19 17:02:31 +01:00
public override void EndDrag ( ItemSlot itemSlot )
{
if ( ! DraggedSlotController . Instance . IsDragged ( ) ) // if there was nothing dragged - ignore event
return ;
DraggedSlotController . Instance . RemoveDraggedSlot ( ) ;
// 1. Remove from slot - for case where EndDrag and Drop work on differen UiManager's
// Important: clear slot not only reset itemn!!!
if ( ! itemSlot . Item )
( ( ItemSlot ) ChildBoxList . Where ( slot = > slot . Number = = itemSlot . Number ) . First ( ) ) . ResetSlot ( ) ;
else
( ( ItemSlot ) ChildBoxList . Where ( slot = > slot . Number = = itemSlot . Number ) . First ( ) ) . SetItem ( itemSlot . Item ) ;
// 2. Rebuild/apply UiManager content (list of items) base on slots values after its updating
// 2.1 Make copy because Add -> base.Add() -> base.Add() -> UpdateList() rebuild content ad pass "new" list (in this case with only one - firtst passed - item) to ChestContentUiMangaer.Element
var ChildBoxListCopy = new List < KeyValuePair < int , Item > > ( ChildBoxList . Where ( slot = > slot . Item ! = null ) . Select ( slot = > new KeyValuePair < int , Item > ( slot . Number , slot . Item ) ) . ToList ( ) ) ;
UiManager . RemoveAll ( ) ;
foreach ( KeyValuePair < int , Item > slot in ChildBoxListCopy )
{
if ( slot . Value ! = null )
{
Debug . Log ( $"Slot nr: {slot.Key} with item: {slot.Value}" ) ;
UiManager . Add ( new KeyValuePair < int , Item > ( slot . Key , slot . Value ) ) ;
}
else
{
UiManager . RemoveByPosition ( slot . Key ) ;
}
}
}
2022-11-06 21:34:17 +01:00
public override void BuildPanelContent ( List < KeyValuePair < int , Item > > elements )
{
base . BuildPanelContent ( elements ) ;
ClearSlots ( ) ;
}
public override void ClearSlots ( )
{
foreach ( ItemSlot ChestSlot in ChildBoxList )
{
ChestSlot . ResetSlot ( ) ;
}
}
public abstract override void BuildPanelSlots ( ) ;
public abstract override GameObject BuildSlot ( int key , GameObject _parent ) ;
}