--top menu window
--------------------------------------------------------------------
--button
local WidgetCaption;
local debugVersion = false
function Show(s)
  self:SetVisible(s)
end

function OnCreate()
  WidgetCaption = self:FindChild("caption")
  debugVersion = ( Config["debug"] == "true" )
end

-- function Update(_dt)
  -- UpdateCaption()
-- end

function UpdateCaption()
  local newCaption = ""
  local itemInHand = ""
  local regionUnderMouse  = states["sys_region_under_mouse"]
  local itemUnderMouse    = states["sys_item_under_mouse"] --Widgets.Inventory.ItemUnderMouse 
  local interfaceCaption  = states["sys_interface_caption"] 
  local inv = MystInventory:GetActive()
  if inv then
    itemInHand = tostring(inv:GetSelectedItem())
  end
  
  if itemInHand ~= "" then 
    itemInHand = "#{"..itemInHand.."}"
  end
  
  if itemUnderMouse ~= "" and itemUnderMouse ~= 0  then
    newCaption = "#{"..itemUnderMouse.."}"
  elseif regionUnderMouse ~= "" and regionUnderMouse ~= 0 then
    newCaption = "#{"..regionUnderMouse.."}"
    -- if debugVersion then
      -- newCaption = newCaption .."("..regionUnderMouse..")"
    -- end
  end

  if interfaceCaption ~= "" and interfaceCaption ~= 0 then  
    newCaption = interfaceCaption
    itemInHand = ""
  end
  
  if newCaption ~= ""  then
    if  itemInHand ~= "" then
      newCaption = itemInHand.." + "..newCaption
    end
    newCaption = MystLocaleManager:ExpandLine(newCaption)
  end

  WidgetCaption:SetText(newCaption)
end
--------------------------------------------------------------------
