local janelaWindow = nil
local pokeBarWindow = nil
local pokeBarButton = nil
local barList = {}
local barVar = nil
function init()
connect(g_game, { onGameStart = online,
onGameEnd = offline})
janelaWindow = g_ui.displayUI('janela.otui')
pokeBarWindow = g_ui.displayUI('selectPokemon', modules.game_interface.getRightPanel())
pokeBarWindow:move(250,50)
pokeBarWindow:hide()
janelaWindow:hide()
g_keyboard.bindKeyDown('Ctrl+L', toggle)
ProtocolGame.registerExtendedOpcode(160, receive)
connect(g_game, 'onTextMessage', portrait)
end
function terminate()
disconnect(g_game, { onGameStart = online,
onGameEnd = offline})
pokeBarWindow:destroy()
janelaWindow:destroy()
g_keyboard.unbindKeyDown('CTRL+L')
disconnect(g_game, 'onTextMessage', portrait)
end
function portrait(mode, text)
if not g_game.isOnline() then return end
if mode == MessageModes.Failure then
local t = text:explode(",")
table.remove(t, 1)
if string.find(text, 'p#') then
for i = 6, 1, -1 do
barVar = #t
pokeBarWindow:setHeight((66*#t))
if i <= #t then
local t2 = t[i]:explode("|")
pokeBarWindow:getChildById('slot'..i):setVisible(true)
pokeBarWindow:getChildById('slot'..i):setItemId(tonumber(t2[1]))
pokeBarWindow:getChildById('bar'..i).onClick = function() g_game.talk('!@pokebar@ '..tonumber(t2[3])) end
pokeBarWindow:getChildById('L'..i):setColor("red")
pokeBarWindow:getChildById('bar'..i):setImageSource("bar.png")
pokeBarWindow:getChildById('bar'..i):setVisible(true)
pokeBarWindow:getChildById('gl'..i):setVisible(true)
pokeBarWindow:getChildById('N'..i):setVisible(true)
pokeBarWindow:getChildById('B'..i):setVisible(true)
pokeBarWindow:getChildById('EXP'..i):setVisible(true)
receive(i, t2[2], tonumber(t2[4]), tonumber(t2[5]), tonumber(t2[6]), tonumber(t2[7]), tonumber(t2[8]))
barList["list"..tonumber(t2[3])] = {num = i}
else
pokeBarWindow:getChildById('slot'..i):setItemId(3283)
pokeBarWindow:getChildById('slot'..i):setVisible(false)
pokeBarWindow:getChildById('bar'..i):setVisible(false)
pokeBarWindow:getChildById('gl'..i):setVisible(false)
pokeBarWindow:getChildById('N'..i):setVisible(false)
pokeBarWindow:getChildById('B'..i):setVisible(false)
pokeBarWindow:getChildById('EXP'..i):setVisible(false)
pokeBarWindow:getChildById('bar'..i).onClick = function() end
receive(i, "", 0, 0, 0, 0, 0)
end
end
elseif string.find(text, 'pGS') then
local t2 = t[1]:explode("|")
lifeBarAtual(tonumber(t2[2]), tonumber(t2[1]), t2[3])
elseif string.find(text, 'KGT') then
local t2 = t[1]:explode("|")
levelBarAtual(t2[1], 0)
elseif string.find(text, 'bCGT') then
local t2 = t[1]:explode("|")
imageBarAtual(t2[1])
elseif string.find(text, 'LHDN') then
local t2 = t[1]:explode("|")
imageBarAtualS(t2[1])
end
end
end
function imageBarAtualS(i)
pokeBarWindow:getChildById('bar'..i):setImageSource("bar.png")
pokeBarWindow:getChildById('L'..i):setColor("red")
end
function imageBarAtual(i)
pokeBarWindow:getChildById('bar'..i):setImageSource("bar1.png")
pokeBarWindow:getChildById('L'..i):setColor("green")
end
function levelBarAtual(i, level)
pokeBarWindow:getChildById('bar'..i):setImageSource("bar1.png")
pokeBarWindow:getChildById('L'..i):setColor("green")
end
function lifeBarAtual(i, hp, level)
color = '#'
pokeBarWindow:getChildById('HP'..i):setBackgroundColor("#ff0000")
if tonumber(hp) == 0 then
pokeBarWindow:getChildById('HP'..i):setText("Desmaiado")
pokeBarWindow:getChildById('HP'..i):setPercent(100);
pokeBarWindow:getChildById('HP'..i):setBackgroundColor("#202020")
pokeBarWindow:getChildById('L'..i):setColor("gray")
pokeBarWindow:getChildById('bar'..i):setImageSource("bar2.png")
else
color = color..string.format("%.2x",255-math.ceil(hp)*2.5)..string.format("%.2x",math.ceil(hp)*2.5)..string.format("%.2x",0)
pokeBarWindow:getChildById('HP'..i):setBackgroundColor(color)
if tonumber(hp) == -1 then
pokeBarWindow:getChildById('HP'..i):setPercent(100);
pokeBarWindow:getChildById('HP'..i):setText(string.format( "%3d %%", 100 ) ) ;
else
pokeBarWindow:getChildById('HP'..i):setPercent(hp);
pokeBarWindow:getChildById('HP'..i):setText(hp.."%");
end
end
end
function receive(i, name, sexo, hp, lvl, boost, expL)
color = '#'
pokeBarWindow:getChildById('L'..i):setText(name)
if tonumber(boost) then
pokeBarWindow:getChildById('B'..i):setText("boost: +"..boost)
else
pokeBarWindow:getChildById('B'..i):setText("boost: +0")
end
pokeBarWindow:getChildById('N'..i):setText("Lv. "..lvl)
if tonumber(sexo) == 3 then
pokeBarWindow:getChildById('gl'..i):setImageSource('skull_white.png')
elseif tonumber(sexo) == 4 then
pokeBarWindow:getChildById('gl'..i):setImageSource('skull_red.png')
elseif tonumber(sexo) == 7 then
pokeBarWindow:getChildById('gl'..i):setImageSource('skull_pink.png')
end
pokeBarWindow:getChildById('HP'..i):setBackgroundColor("#ff0000")
if tonumber(hp) == 0 then
pokeBarWindow:getChildById('HP'..i):setText("Desmaiado")
pokeBarWindow:getChildById('HP'..i):setPercent(100);
pokeBarWindow:getChildById('HP'..i):setBackgroundColor("#202020")
pokeBarWindow:getChildById('L'..i):setColor("gray")
pokeBarWindow:getChildById('bar'..i):setImageSource("bar2.png")
else
color = color..string.format("%.2x",255-math.ceil(hp)*2.5)..string.format("%.2x",math.ceil(hp)*2.5)..string.format("%.2x",0)
pokeBarWindow:getChildById('HP'..i):setBackgroundColor(color)
if tonumber(hp) == -1 then
pokeBarWindow:getChildById('HP'..i):setPercent(100);
pokeBarWindow:getChildById('HP'..i):setText(string.format( "%3d %%", 100 ) ) ;
else
pokeBarWindow:getChildById('HP'..i):setPercent(hp);
pokeBarWindow:getChildById('HP'..i):setText(hp.."%");
end
end
if tonumber(expL) == 0 then
pokeBarWindow:getChildById('EXP'..i):setText("0%")
pokeBarWindow:getChildById('EXP'..i):setPercent(0);
else
if tonumber(expL) == -1 then
pokeBarWindow:getChildById('EXP'..i):setPercent(0);
pokeBarWindow:getChildById('EXP'..i):setText(string.format( "%3d %%", 0 ) ) ;
else
pokeBarWindow:getChildById('EXP'..i):setPercent(expL);
pokeBarWindow:getChildById('EXP'..i):setText(expL.."%");
end
end
end
function toggle()
if pokeBarWindow:isVisible() then
pokeBarWindow:hide()
else
pokeBarWindow:show()
end
end
function online()
if g_game.isOnline() then
pokeBarWindow:show()
janelaWindow:show()
end
end
function offline()
pokeBarWindow:hide()
janelaWindow:hide()
pokeBarButton:setOn(false)
end
function onMoveBottomPanelHoverChange(widget)
if widget:isHovered() and not g_mouse.isPressed(MouseLeftButton) then
addEvent(function() g_effects.fadeIn(widget, 250) end)
elseif not widget:isHovered() and not g_mouse.isPressed(MouseLeftButton) then
addEvent(function() g_effects.fadeOut(widget, 250) end)
end
end
function getMoveBottomPanel()
return gameRootPanel:recursiveGetChildById('moveBottomPanel')
end