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 ) ;
2022-12-19 03:34:45 +01:00
2022-11-19 17:02:31 +01:00
// 2. Rebuild/apply UiManager content (list of items) base on slots values after its updating
2022-12-19 03:34:45 +01:00
// 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
UpdatePanelContent ( ) ;
}
public override void DoubleLeftMouseClick ( ItemSlot itemSlot )
{
2022-12-22 03:38:00 +01:00
Debug . Log ( "Used item" ) ;
2022-12-19 03:34:45 +01:00
if ( AllowToUseItemInPanel )
2022-12-22 03:38:00 +01:00
{
ItemEffectsManager . Instance . UseItemEffect ( itemSlot , Type ) ;
}
//itemSlot.Item?.InvokeEffectAction();
2022-12-19 03:34:45 +01:00
}
public override void BuildPanelContent ( List < IndexValuePair < int , EquippableItem > > elements )
{
base . BuildPanelContent ( elements ) ;
ClearSlots ( ) ;
}
public void UpdatePanelContent ( )
{
2022-11-19 17:02:31 +01:00
// 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
2022-11-24 03:03:30 +01:00
var ChildBoxListCopy = new List < IndexValuePair < int , EquippableItem > > ( ChildBoxList . Where ( slot = > slot . Item ! = null ) . Select ( slot = > new IndexValuePair < int , EquippableItem > ( slot . Number , slot . Item ) ) . ToList ( ) ) ;
2022-11-19 17:02:31 +01:00
UiManager . RemoveAll ( ) ;
2022-12-19 03:34:45 +01:00
foreach ( IndexValuePair < int , EquippableItem > slot in ChildBoxListCopy )
2022-11-19 17:02:31 +01:00
{
if ( slot . Value ! = null )
{
Debug . Log ( $"Slot nr: {slot.Key} with item: {slot.Value}" ) ;
2022-11-24 03:03:30 +01:00
UiManager . Add ( new IndexValuePair < int , EquippableItem > ( slot . Key , slot . Value ) ) ;
2022-11-19 17:02:31 +01:00
}
else
{
UiManager . RemoveByPosition ( slot . Key ) ;
}
}
}
2022-11-06 21:34:17 +01:00
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 ) ;
}