
require "scripts/style"



BubbleButtonGraphics = {
  "widgets/inventorybar/bubble",
  "widgets/inventorybar/bubblelo",
  "widgets/inventorybar/bubblehi",
  "widgets/inventorybar/charge",  -- charge gradient
};


function MakeInventoryBubble(bubnum, xpos, ypos)
  return Bitmap
    {
        name="inventory-bubble-" .. bubnum,
        x=xpos-40, y=0,
        w=100, h=kMax,

          
        Bitmap
        {
          x=10, y=kMax-60,
          name="socket-" .. bubnum,
          image="widgets/inventorybar/socket"
        },
        AnimSprite {
          x=50, y=50, --from the center              
          name="fullglow" .. bubnum,
          animations={
            { key="idle", texture="widgets/inventorybar/bubble_empty_glowing", animation="main", default=1},            
            { key="blink", texture="widgets/inventorybar/bubble_empty_glowing", animation="blink"},            
          },
        },      

        AnimSprite
        { 
            name="container" .. bubnum,
            x=50,y=50,            
            xRef = 0, yRef = 0,
            animations={
            { key="closed", texture="widgets/inventorybar/bubble_unavailable", animation="", default=1},
            { key="opening", texture="widgets/inventorybar/bubbleopening", animation="main", next="open"},
            { key="open", texture="widgets/inventorybar/bubble_empty", animation=""},
            },
        },
        
        Bitmap
        {
          x=50, y=50,
          name="sparkle-inv-" .. bubnum,
        },
        
        StateWindow
        {
          x=15, y=20,
          w=80, h=60,
          name="invbutton" .. bubnum,
          default="off",              
          Bitmap {
            x=0, y=0,
            w=80, h=60,
            name="on",
            Button
            {
              x=0, y=0,
              w=80, h=60,
              font=StandardButtonFont,
              graphics = {
                "widgets/inventorybar/bubble_empty",
                "widgets/inventorybar/bubble_empty",
                "widgets/inventorybar/bubble_empty_hover",
                "widgets/inventorybar/bubble_empty_hover", 
              },
              -- BubbleButtonGraphics,
              type = kPush,
-- send a message to TInventoryBar::SendInventoryBarMsg. 
              command=
              function()
                SendInventoryBarMsg("invbar-select",bubnum);
              end
            },            
            PercImage
            {
              name="charge",
              x=0, y=0,
              w=80, h=60,
              image="widgets/inventorybar/bubble_full",
            },
            AnimSprite {              
              x=37, y=30, --from the center
              w=45, h=45,
              name="icon",
              animations={
	            { key="idle", texture="", animation="", default=1},
              },
            },
            --a sparkle when we're upgrading
            AnimSprite {
              
              x=42, y=50, --from the center              
              name="sparkle",
              animations={
                { key="idle", texture="", animation="", default=1},
                { key="sparkle", texture="widgets/inventorybar/upgrade", animation="main"},
              },
            },
          },
          },          
        }; 
end

function MakeInventoryBar()
  return Group {
    InventoryBar
      {        
        w=800, h=80, x=0, y=520,
        bg="widgets/inventorybar/uiFrame_bottom",
        
     
        Bitmap 
        {
          name="bubble-wrapper",
          x=200, y=0,
          w=600, h=80,
          
          Bitmap 
          {
            name="bubbles",
            x=0, y=0,
            w=600, h=80,
            MakeInventoryBubble(0, 68, 50),
            MakeInventoryBubble(1, 146, 50),
            MakeInventoryBubble(2, 225, 50),
            MakeInventoryBubble(3, 305, 50),
            MakeInventoryBubble(4, 385, 50),
            MakeInventoryBubble(5, 465, 50),        
          },
        },
        
        SetStyle(ButtonStyle),
        Button
        {
          x=45,
          y=45,
          font = StandardButtonFont,
          graphics = StandardButtonGraphics,         
          name="pause",
          label="pause",
          type = kPush,
          command=
          function()
            StopSounds(); -- stop any in-game looping sounds
            DoModal("scripts/pause.lua");
          end
        },
       
      },
  }
end
