local barPoke = nil
local icons = {}

-- Public functions
function init()
   info = g_ui.displayUI('infopoke', modules.game_interface.getRootPanel())
   info:setVisible(false)  
   info:move(250,50)
   connect(g_game, 'onTextMessage', getParams)
   connect(g_game, { onGameEnd = hide } )
end

function terminate()
   disconnect(g_game, { onGameEnd = hide })
   disconnect(g_game, 'onTextMessage', getParams)

   destroyIcons()
   info:destroy()
end


function getParams(mode, text)
if not g_game.isOnline() then return end
   if mode == MessageModes.Failure then 
      if string.find(text, "InfoClosed") then
      hide()
      elseif string.sub(text, 1, 7) == "NewInfo" then
         newInfoPoke(text)
   end
end
end

function newInfoPoke(text)
boost = info:recursiveGetChildById('boost')
happy = info:recursiveGetChildById('happy')
if not g_game.isOnline() then return end
show()
local t = string.explode(text, "/")
local poke = t[2]
changeIconPoke(poke)
boost:setText(t[3].."/50 Boost Level") 
print(t[4])
happy:setText(t[4].." Happy Points") 
end


function changeIconPoke(poke)
icon = info:recursiveGetChildById('iconpoke')
local image = "pokes/"..poke..".png"
icon:setImageSource(image)
print("oi")
end

function hide()
   info:setVisible(false)
end

function show()
   info:setVisible(true)
end
-- End public functions