
HOListGui = public()

function HOListGui:Create()
end

function HOListGui:Open()
  self.GUI = OpenHiddenObjectGUI()
  self:SetVisible(true)
  self.Counter = TextCounter( Widgets.ObjectsList.GetCounterWidget() )
end

function HOListGui:AddItem(item)
end

function HOListGui:AddItems(objects, CurrentHO)
  items= {}
  for i = 1,#objects do
    items[#items+1] = objects[i]:GetName()
  end
  Widgets.ObjectsList.AddObjects(items, CurrentHO)
  self.Counter:Set(#objects)
  self.Counter:ShowN()
end

function HOListGui:GetObjectPos(item)
  return Widgets.ObjectsList.GetButtonPosition(item:GetName())
end

function HOListGui:RemoveItem(item, CurrentHO)
  if item == nil then return end
  Widgets.ObjectsList.DisableObject(item:GetName(), CurrentHO)
  self.Counter:Dec()
end

function HOListGui:SetVisible(visible)
  self.GUI:SetVisible( visible )
end

function HOListGui:Clear()
end

-- ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##

HOShadowGui = public()

local ShadowsGroupName = "Shadows"

function HOShadowGui:Create()
  MystInventory:Remove("HO_Inventory")
  self.Inv = MystInventory:Create("HO_Inventory", "Widgets.Inventory")
  self.LastSlot = 0
  self.SlotsCount = 12
  
  self.Slots = {}
end

function HOShadowGui:Open(name)
  self.Name = name
  self:SetVisible(true)
  
  SetTimerWidget("Inventory", "clock_anim")
  self.Counter = TextCounter( Widgets.Inventory.GetCounterWidget() )
end

function HOShadowGui:AddItem(item, CurrentHO)
  if self.LastSlot > self.SlotsCount then
    return
  end
  self.Slots[item:GetName()] = self.LastSlot
  Widgets.Inventory.SetSlotImage(self.LastSlot, item:GetProperty("Item_shadow"), self.Name, ShadowsGroupName)  
  self.LastSlot = self.LastSlot + 1
end

function HOShadowGui:AddItems(items, CurrentHO)
  if #items > self.SlotsCount then
    printerror("[HO_Shaddow] Za duzo przedmiotow, maksymalnie moze byc:", self.SlotsCount)
  end
  
  self.LastSlot = 0
  for i = 1,#items do
    self:AddItem(items[i], CurrentHO)
  end
  
  self.Counter:Set(#items)
  self.Counter:ShowN()
end

function HOShadowGui:RemoveItem(item)
  --Widgets.Inventory.SetSlotImage(self.Slots[item:GetName()], item:GetProperty("Item"))
  if item == nil then return end
  Widgets.Inventory.SetSlotImage(self.Slots[item:GetName()], nil)
  self.Counter:Dec()
end

function HOShadowGui:SetVisible(visible)
  
  if visible then
    
    self.OldInv = MystInventory:GetActive()  
    MystInventory:SetActive(self.Inv)
    Widgets.Inventory.Lock(true)
    Widgets.Inventory.BlockItemsClick(true)
    s.sys_ho_inventory = 1
  else
    --MystInventory:SetActive(self.OldInv)
    MystInventory:SetActive("ch01")
    MystInventory:Remove("HO_Inventory")
    self.Counter:Clear()
    Widgets.Inventory.Unlock()
    Widgets.Inventory.BlockItemsClick(false)
	s.sys_ho_inventory = 0
  end
  
end

function HOShadowGui:Clear()
end

function HOShadowGui:GetObjectPos(object)
  return Widgets.Inventory.GetSlotMidPos(self.Slots[object:GetName()])
end


-- ######################################################################
-- Counter GUI

-- ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##

HOCounterGui = public()

function HOCounterGui:Create()
  
  self.GUI = OpenHOCounterGUI()
  self:SetVisible(true)
  self.Counter = TextCounter( Widgets.ho_counter_list.GetCounterWidget() )
end

function HOCounterGui:Open(name)
  self:SetVisible(true)
end

function HOCounterGui:AddItem(item, CurrentHO)
end

function HOCounterGui:AddItems(items, CurrentHO)
  self.Counter:Set(#items)
  self.Counter:ShowN()
  Widgets.ho_counter_list.SetName( CurrentHO:GetProperty("item_name") )
end

function HOCounterGui:RemoveItem(item)
  if item == nil then return end
  self.Counter:Dec()
end

function HOCounterGui:SetVisible(visible)
  self.GUI:SetVisible(visible)
end

function HOCounterGui:Clear()
end


function HOCounterGui:GetObjectPos(object)  
  return Widgets.ho_counter_list.GetItemMidPos()
end

-- ######################################################################
-- Items gui

-- ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##

HOItemsGui = public()

function HOItemsGui:Create()
  MystInventory:Remove("HO_Inventory")
  self.Inv = MystInventory:Create("HO_Inventory", "Widgets.Inventory")
  self.SlotsCount = 12
  self.Slots = {}
end

function HOItemsGui:Open(name)
  self.Name = name
  self:SetVisible(true)
end

function HOItemsGui:AddItem(item, CurrentHO)
  if self.LastSlot > self.SlotsCount then
    return
  end
  self.Slots[item:GetName()] = self.LastSlot
  itemName = item:GetProperty("item")
  if itemName == nil then return end
  self.Inv:Take(itemName)
  self.LastSlot = self.LastSlot + 1
end

function HOItemsGui:AddItems(items, CurrentHO)
  if #items > self.SlotsCount then
    printerror("[HO_Shaddow] Za duzo przedmiotow, maksymalnie moze byc:", self.SlotsCount)
  end
  
  self.LastSlot = 0
  for i = 1,#items do
    self:AddItem(items[i], CurrentHO)
  end
end

function HOItemsGui:RemoveItem(item)
  if item == nil then return end
  self.Inv:Drop(item:GetProperty("item"), 1, -1)
end

function HOItemsGui:SetVisible(visible)

  if visible then
    self.OldInv = MystInventory:GetActive() 
    MystInventory:SetActive(self.Inv)
    Widgets.Inventory.Lock(true)
    states["sys_block_big_item"] = 1
	s.sys_ho_inventory = 1
  else
    MystInventory:SetActive("ch01")
    MystInventory:Remove("HO_Inventory")
    Widgets.Inventory.Unlock()
    states["sys_block_big_item"] = 0
	s.sys_ho_inventory = 0
  end  
end

function HOItemsGui:Clear()
end

function HOItemsGui:GetObjectPos(object)
  return Widgets.Inventory.GetSlotMidPos(self.Slots[object:GetName()])
end

