ui = nil
updateEvent = nil

function init()
  ui = g_ui.loadUI('stats', modules.game_interface.getMapPanel())
  
  if not modules.client_options.getOption("showPing") then
    ui.fps:hide()
  end
  if not modules.client_options.getOption("showFps") then
    ui.ping:hide()
  end
  
  updateEvent = scheduleEvent(update, 200)
end

function terminate()
  removeEvent(updateEvent)
end

function update()
  updateEvent = scheduleEvent(update, 500)
  if ui:isHidden() then return end

  text = 'FPS: ' .. g_app.getFps()
  ui.fps:setText(text)

  -- Arcfall: ping label is now driven directly by modules/arcfall_ping/
  -- (custom RTT over extended opcode 181, since native GameClientPing is
  -- broken on our 772 client). Skipping native update — would otherwise
  -- overwrite our value with "Ping: ??" 2x/sec via g_game.getPing()=-1.
end

function show()
  ui:setVisible(true)
end

function hide()
  ui:setVisible(false)
end