Implement new cool features

* Implement walk booster (dash) as an option in settings menu
* Dash is smarter (can pre-animate)
* Implement smart walking (walk in diagonal when holding two arrow keys)
* Implement ping meter for all protocols
* Ping meter uses uses real ping packet for 9.6 and walk for others
This commit is contained in:
Eduardo Bart
2012-08-25 16:11:54 -03:00
parent 0763b266d5
commit 4bac36d3bc
15 changed files with 193 additions and 63 deletions

View File

@@ -1,12 +1,4 @@
Panel
OptionCheckBox
id: classicControl
!text: tr('Classic control')
OptionCheckBox
id: autoChaseOverride
!text: tr('Allow auto chase override')
OptionCheckBox
id: showInfoMessagesInConsole
!text: tr('Show info messages in console')
@@ -33,12 +25,4 @@ Panel
OptionCheckBox
id: showPrivateMessagesOnScreen
!text: tr('Show private messages on screen')
OptionCheckBox
id: enableMusic
!text: tr('Enable music')
OptionCheckBox
id: showLeftPanel
!text: tr('Show left panel')
!text: tr('Show private messages on screen')

View File

@@ -0,0 +1,21 @@
Panel
OptionCheckBox
id: classicControl
!text: tr('Classic control')
OptionCheckBox
id: autoChaseOverride
!text: tr('Allow auto chase override')
OptionCheckBox
id: walkBooster
!text: tr('Enable walk booster')
!tooltip: tr('Also know as dash in tibia community, recommended\nfor playing characters with high speed')
OptionCheckBox
id: enableMusic
!text: tr('Enable music')
OptionCheckBox
id: showLeftPanel
!text: tr('Show left panel')

View File

@@ -5,6 +5,8 @@ local defaultOptions = {
showfps = true,
fullscreen = false,
classicControl = false,
walkBooster = false,
smartWalk = false,
autoChaseOverride = true,
showStatusMessagesInConsole = true,
showEventMessagesInConsole = true,
@@ -68,8 +70,8 @@ function Options.init()
end
end
g_keyboard.bindKeyDown('Ctrl+D', Options.toggle)
g_keyboard.bindKeyDown('Ctrl+F', function() Options.toggleOption('fullscreen') end)
g_keyboard.bindKeyDown('Ctrl+D', function() Options.toggleOption('walkBooster') end)
optionsWindow = g_ui.displayUI('options.otui')
optionsWindow:hide()
@@ -78,8 +80,11 @@ function Options.init()
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
generalPanel = g_ui.loadUI('general.otui')
optionsTabBar:addTab(tr('General'), generalPanel)
generalPanel = g_ui.loadUI('game.otui')
optionsTabBar:addTab(tr('Game'), generalPanel)
generalPanel = g_ui.loadUI('console.otui')
optionsTabBar:addTab(tr('Console'), generalPanel)
graphicsPanel = g_ui.loadUI('graphics.otui')
optionsTabBar:addTab(tr('Graphics'), graphicsPanel)
@@ -147,8 +152,8 @@ function Options.setOption(key, value)
end
if graphicsPanel then
graphicsPanel:getChildById('backgroundFrameRateLabel'):setText(tr('Game framerate limit: %s', text))
end
graphicsPanel:getChildById('backgroundFrameRateLabel'):setText(tr('Game framerate limit: %s', text))
end
g_app.setBackgroundPaneMaxFps(value)
elseif key == 'foregroundFrameRate' then
local text = value
@@ -158,7 +163,7 @@ function Options.setOption(key, value)
end
if graphicsPanel then
graphicsPanel:getChildById('foregroundFrameRateLabel'):setText(tr('Interface framerate limit: %s', text))
graphicsPanel:getChildById('foregroundFrameRateLabel'):setText(tr('Interface framerate limit: %s', text))
end
g_app.setForegroundPaneMaxFps(value)
elseif key == 'painterEngine' then

View File

@@ -24,9 +24,43 @@ GameLabel < UILabel
color: #bbbbbb
FrameCounterLabel < Label
font: verdana-11px-rounded
@onSetup: |
self.updateEvent = cycleEvent(function()
local text = 'FPS: ' .. g_app.getBackgroundPaneFps()
self:setText(text)
end, 1000)
@onDestroy: self.updateEvent:cancel()
PingLabel < Label
font: verdana-11px-rounded
@onSetup: |
self.updateEvent = cycleEvent(function()
if g_game.isOnline() then
local ping = -1
if g_game.getFeature(GameClientPing) then
ping = g_game.getPing()
else
ping = g_game.getLocalPlayer():getWalkPing()
end
local text = 'Ping: '
if ping < 0 then
text = text .. "??"
self:setColor('yellow')
else
text = text .. ping .. ' ms'
if ping >= 500 then
self:setColor('red')
elseif ping >= 250 then
self:setColor('yellow')
else
self:setColor('green')
end
end
self:setText(text)
self:show()
else
self:hide()
end
end, 1000)
@onDestroy: self.updateEvent:cancel()

View File

@@ -67,11 +67,21 @@ TopMenuPanel
anchors.left: prev.right
visible: false
TopMenuFrameCounterLabel
FrameCounterLabel
color: white
margin-top: 4
margin-left: 5
id: frameCounter
text-auto-resize: true
anchors.top: parent.top
anchors.left: prev.right
anchors.left: leftGameButtonsPanel.right
PingLabel
color: white
id: pingLabel
text-auto-resize: true
anchors.top: frameCounter.bottom
anchors.left: frameCounter.left
TopMenuButtonsPanel
id: rightButtonsPanel

View File

@@ -15,6 +15,14 @@ function translateKeyCombo(keyCombo)
return keyComboDesc
end
local function getKeyCode(key)
for keyCode, keyDesc in pairs(KeyCodeDescs) do
if keyDesc:lower() == key:trim():lower() then
return keyCode
end
end
end
local function retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc == nil then
error('Unable to translate key combo \'' .. keyComboDesc .. '\'')
@@ -140,6 +148,13 @@ function g_keyboard.getModifiers()
return g_window.getKeyboardModifiers()
end
function g_keyboard.isKeyPressed(key)
if type(key) == 'string' then
key = getKeyCode(key)
end
return g_window.isKeyPressed(key)
end
function g_keyboard.isCtrlPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardCtrlModifier) ~= 0
end

View File

@@ -33,10 +33,18 @@ function init()
logoutButton = TopMenu.addRightButton('logoutButton', 'Logout', '/images/logout.png', tryLogout)
logoutButton:hide()
g_keyboard.bindKeyPress('Up', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Right', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Down', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Left', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
bindKeys()
if g_game.isOnline() then
show()
end
end
function bindKeys()
g_keyboard.bindKeyPress('Up', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Right', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Down', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Left', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad8', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad9', function() g_game.walk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad6', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
@@ -59,19 +67,8 @@ function init()
g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+L', logout, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+.', function()
if gameMapPanel:isKeepAspectRatioEnabled() then
gameMapPanel:setKeepAspectRatio(false)
else
gameMapPanel:setKeepAspectRatio(true)
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
end
end, gameRootPanel)
if g_game.isOnline() then
show()
end
g_keyboard.bindKeyDown('Ctrl+;', toggleDash, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+.', toggleAspectRatio, gameRootPanel)
end
function terminate()
@@ -155,6 +152,46 @@ function tryLogout()
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end
function smartWalk()
local dir
if g_keyboard.isKeyPressed('Up') and g_keyboard.isKeyPressed('Left') then
dir = NorthWest
elseif g_keyboard.isKeyPressed('Up') and g_keyboard.isKeyPressed('Right') then
dir = NorthEast
elseif g_keyboard.isKeyPressed('Down') and g_keyboard.isKeyPressed('Left') then
dir = SouthWest
elseif g_keyboard.isKeyPressed('Down') and g_keyboard.isKeyPressed('Right') then
dir = SouthEast
elseif g_keyboard.isKeyPressed('Up') then
dir = North
elseif g_keyboard.isKeyPressed('Down') then
dir = South
elseif g_keyboard.isKeyPressed('Left') then
dir = West
elseif g_keyboard.isKeyPressed('Right') then
dir = East
end
if Options.getOption('walkBooster') then
if g_game.getLocalPlayer():canWalk(dir) then
g_game.walk(dir)
else
g_game.forceWalk(dir)
end
else
g_game.walk(dir)
end
end
function toggleAspectRatio()
if gameMapPanel:isKeepAspectRatioEnabled() then
gameMapPanel:setKeepAspectRatio(false)
else
gameMapPanel:setKeepAspectRatio(true)
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
end
end
function onMouseGrabberRelease(self, mousePosition, mouseButton)
if selectedThing == nil then return false end
if mouseButton == MouseLeftButton then

View File

@@ -64,6 +64,7 @@ GameOfflineTrainingTime = 20
GamePurseSlot = 21
GameFormatCreatureName = 22
GameSpellList = 23
GameClientPing = 24
TextColors = {
red = '#f55e5e', --'#c83200'