Platform fixes and rework ping

This commit is contained in:
Eduardo Bart
2013-02-24 17:26:19 -03:00
parent a8c175452b
commit 06e2b6eca2
31 changed files with 178 additions and 111 deletions

View File

@@ -145,10 +145,10 @@ function EnterGame.firstShow()
local host = g_settings.get('host')
local autologin = g_settings.getBoolean('autologin')
if #host > 0 and #password > 0 and #account > 0 and autologin then
connect(g_app, { onRun = function()
addEvent(function()
if not g_settings.getBoolean('autologin') then return end
EnterGame.doLogin()
end})
end)
end
end

View File

@@ -1,7 +1,7 @@
MainWindow
id: waitingWindow
!text: tr('Waiting List')
size: 260 160
size: 260 180
@onEscape: CharacterList.cancelWait()
Label

View File

@@ -179,15 +179,9 @@ function setOption(key, value)
if key == 'vsync' then
g_window.setVerticalSync(value)
elseif key == 'showFps' then
addEvent(function()
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
if frameCounter then frameCounter:setVisible(value) end
end)
modules.client_topmenu.setFpsVisible(value)
elseif key == 'showPing' then
addEvent(function()
local ping = rootWidget:recursiveGetChildById('pingLabel')
if ping then ping:setVisible(value) end
end)
modules.client_topmenu.setPingVisible(value)
elseif key == 'fullscreen' then
g_window.setFullscreen(value)
panel = graphicsPanel

View File

@@ -92,3 +92,8 @@ function createDebugUIItem(id)
uiitem:setItemId(id)
uiitem:show()
end
function debugPings()
g_game.setPingDelay(0)
connect(g_game, { onPingBack = function(ping) print(g_game.getWorldName() .. ' => ' .. ping .. ' ms') end })
end

View File

@@ -37,8 +37,10 @@ end
-- public functions
function init()
connect(g_game, { onGameStart = showGameButtons,
onGameEnd = hideGameButtons })
connect(g_game, { onGameStart = online,
onGameEnd = offline,
onPingBack = updatePing })
connect(g_app, { onFps = updateFps })
topMenu = g_ui.displayUI('topmenu')
@@ -46,20 +48,75 @@ function init()
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
leftGameButtonsPanel = topMenu:getChildById('leftGameButtonsPanel')
rightGameButtonsPanel = topMenu:getChildById('rightGameButtonsPanel')
pingLabel = topMenu:getChildById('pingLabel')
fpsLabel = topMenu:getChildById('fpsLabel')
if g_game.isOnline() then
leftGameButtonsPanel:show()
rightGameButtonsPanel:show()
online()
end
end
function terminate()
disconnect(g_game, { onGameStart = showGameButtons,
onGameEnd = hideGameButtons })
disconnect(g_game, { onGameStart = online,
onGameEnd = offline,
onPingBack = updatePing })
disconnect(g_app, { onFps = updateFps })
topMenu:destroy()
end
function online()
showGameButtons()
if modules.client_options.getOption('showFps') then
pingLabel:show()
end
end
function offline()
hideGameButtons()
pingLabel:hide()
end
function updateFps(fps)
text = 'FPS: ' .. fps
fpsLabel:setText(text)
end
function updatePing(ping)
local ping = -1
if g_game.getFeature(GameClientPing) or g_game.getFeature(GameExtendedClientPing) then
ping = g_game.getPing()
else
ping = g_game.getLocalPlayer():getWalkPing()
end
local text = 'Ping: '
local color
if ping < 0 then
text = text .. "??"
color = 'yellow'
else
text = text .. ping .. ' ms'
if ping >= 500 then
color = 'red'
elseif ping >= 250 then
color = 'yellow'
else
color = 'green'
end
end
pingLabel:setColor(color)
pingLabel:setText(text)
end
function setPingVisible(enable)
pingLabel:setVisible(enable)
end
function setFpsVisible(enable)
fpsLabel:setVisible(enable)
end
function addLeftButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftButtonsPanel, false, front)
end
@@ -92,16 +149,16 @@ function addRightGameToggleButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, rightGameButtonsPanel, true, front)
end
function hideGameButtons()
leftGameButtonsPanel:hide()
rightGameButtonsPanel:hide()
end
function showGameButtons()
leftGameButtonsPanel:show()
rightGameButtonsPanel:show()
end
function hideGameButtons()
leftGameButtonsPanel:hide()
rightGameButtonsPanel:hide()
end
function getButton(id)
return topMenu:recursiveGetChildById(id)
end

View File

@@ -18,17 +18,17 @@ TopMenuPanel
visible: false
TopMenuFrameCounterLabel
id: frameCounter
id: fpsLabel
text-auto-resize: true
anchors.top: parent.top
anchors.left: leftGameButtonsPanel.right
PingLabel
TopMenuPingLabel
color: white
id: pingLabel
text-auto-resize: true
anchors.top: frameCounter.bottom
anchors.left: frameCounter.left
anchors.top: fpsLabel.bottom
anchors.left: fpsLabel.left
TopMenuButtonsPanel
id: rightButtonsPanel

View File

@@ -113,6 +113,7 @@ function UIMinimap:addFlag(pos, icon, description)
flag:setIcon('/images/game/minimap/flag' .. icon)
flag:setTooltip(description)
flag.onMouseRelease = onFlagMouseRelease
flag.onDestroy = function() table.removevalue(self.flags, flag) end
table.insert(self.flags, flag)
self:centerInPosition(flag, pos)
end
@@ -162,7 +163,6 @@ function UIMinimap:removeFlag(pos, icon, description)
local flag = self:getFlag(pos)
if flag then
flag:destroy()
table.removevalue(self.flags, flag)
end
end