From 5fbb71157dab0414a1c6abe493eb6bf430e3e22d Mon Sep 17 00:00:00 2001 From: BeniS Date: Mon, 29 Jul 2013 10:41:44 +1200 Subject: [PATCH] Added enable/disable chat mode (allows for alphabetical key controls), battle window anchoring fixed (thank you River) & more: * Added better walk key binding (for other uses, like the sample given WASD). * Made string.ends part of the string meta table rather than parameter based. --- modules/corelib/string.lua | 4 +- modules/game_battle/battle.otui | 5 +- modules/game_console/console.lua | 53 +++++++++++++++++++- modules/game_console/console.otui | 13 ++++- modules/game_interface/gameinterface.lua | 61 ++++++++++------------- modules/game_interface/widgets/uiitem.lua | 2 +- modules/gamelib/game.lua | 2 +- 7 files changed, 94 insertions(+), 46 deletions(-) diff --git a/modules/corelib/string.lua b/modules/corelib/string.lua index bcff68a5..a649338d 100644 --- a/modules/corelib/string.lua +++ b/modules/corelib/string.lua @@ -20,8 +20,8 @@ function string:starts(start) return string.sub(self, 1, #start) == start end -function string.ends(s, test) - return test =='' or string.sub(s,-string.len(test)) == test +function string:ends(test) + return test =='' or string.sub(self,-string.len(test)) == test end function string:trim() diff --git a/modules/game_battle/battle.otui b/modules/game_battle/battle.otui index 2bdaa596..1dd0e2b4 100644 --- a/modules/game_battle/battle.otui +++ b/modules/game_battle/battle.otui @@ -98,7 +98,8 @@ MiniWindow width: 74 anchors.top: parent.top anchors.left: prev.right - margin-left: 5 + anchors.horizontalCenter: parent.horizontalCenter + margin-left: -28 ComboBox id: sortOrderBox @@ -134,7 +135,7 @@ MiniWindow MiniWindowContents anchors.top: prev.bottom - margin-top: 2 + margin-top: 6 Panel id: battlePanel diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 0e496eab..767de81c 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -143,10 +143,59 @@ function init() g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels) g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab) g_keyboard.bindKeyDown('Ctrl+H', openHelp) - + + consoleToggleChat = consolePanel:getChildById('toggleChat') load() end +function toggleChat() + if consoleToggleChat:isChecked() then + disableChat() + else + enableChat() + end +end + +function enableChat() + local gameInterface = modules.game_interface + + consoleTextEdit:setVisible(true) + consoleTextEdit:setText("") + + g_keyboard.unbindKeyUp("Space") + g_keyboard.unbindKeyUp("Enter") + + gameInterface.unbindWalkKey("W") + gameInterface.unbindWalkKey("D") + gameInterface.unbindWalkKey("S") + gameInterface.unbindWalkKey("A") + + consoleToggleChat:setTooltip(tr("Disable chat mode")) +end + +function disableChat() + local gameInterface = modules.game_interface + + consoleTextEdit:setVisible(false) + consoleTextEdit:setText("") + + local quickFunc = function() + if consoleToggleChat:isChecked() then + consoleToggleChat:setChecked(false) + end + enableChat() + end + g_keyboard.bindKeyUp("Space", quickFunc) + g_keyboard.bindKeyUp("Enter", quickFunc) + + gameInterface.bindWalkKey("W", North) + gameInterface.bindWalkKey("D", East) + gameInterface.bindWalkKey("S", South) + gameInterface.bindWalkKey("A", West) + + consoleToggleChat:setTooltip(tr("Enable chat mode")) +end + function terminate() save() disconnect(g_game, { @@ -1211,4 +1260,4 @@ function offline() g_keyboard.unbindKeyDown('Ctrl+R') end clear() -end +end \ No newline at end of file diff --git a/modules/game_console/console.otui b/modules/game_console/console.otui index afbf35ef..3b7c1e2c 100644 --- a/modules/game_console/console.otui +++ b/modules/game_console/console.otui @@ -56,12 +56,21 @@ Panel id: consolePanel anchors.fill: parent + CheckBox + id: toggleChat + !tooltip: tr('Disable chat mode') + anchors.left: parent.left + anchors.top: parent.top + margin-left: 13 + margin-top: 8 + @onCheckChange: toggleChat() + TabButton id: prevChannelButton icon: /images/game/console/leftarrow - anchors.left: parent.left + anchors.left: toggleChat.right anchors.top: parent.top - margin-left: 6 + margin-left: 3 margin-top: 6 ConsoleTabBar diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index d2dcc959..247c41f4 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -57,42 +57,19 @@ end function bindKeys() gameRootPanel:setAutoRepeatDelay(250) - g_keyboard.bindKeyDown('Up', function() changeWalkDir(North) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Right', function() changeWalkDir(East) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Down', function() changeWalkDir(South) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Left', function() changeWalkDir(West) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad8', function() changeWalkDir(North) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad9', function() changeWalkDir(NorthEast) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad6', function() changeWalkDir(East) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad3', function() changeWalkDir(SouthEast) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad2', function() changeWalkDir(South) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad1', function() changeWalkDir(SouthWest) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad4', function() changeWalkDir(West) end, gameRootPanel, true) - g_keyboard.bindKeyDown('Numpad7', function() changeWalkDir(NorthWest) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Up', function() changeWalkDir(North, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Right', function() changeWalkDir(East, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Down', function() changeWalkDir(South, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Left', function() changeWalkDir(West, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad8', function() changeWalkDir(North, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad9', function() changeWalkDir(NorthEast, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad6', function() changeWalkDir(East, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad3', function() changeWalkDir(SouthEast, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad2', function() changeWalkDir(South, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad1', function() changeWalkDir(SouthWest, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad4', function() changeWalkDir(West, true) end, gameRootPanel, true) - g_keyboard.bindKeyUp('Numpad7', function() changeWalkDir(NorthWest, true) end, gameRootPanel, true) - g_keyboard.bindKeyPress('Up', function() smartWalk(North) end, gameRootPanel) - g_keyboard.bindKeyPress('Right', function() smartWalk(East) end, gameRootPanel) - g_keyboard.bindKeyPress('Down', function() smartWalk(South) end, gameRootPanel) - g_keyboard.bindKeyPress('Left', function() smartWalk(West) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad8', function() smartWalk(North) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad9', function() smartWalk(NorthEast) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad6', function() smartWalk(East) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad3', function() smartWalk(SouthEast) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad2', function() smartWalk(South) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad1', function() smartWalk(SouthWest) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad4', function() smartWalk(West) end, gameRootPanel) - g_keyboard.bindKeyPress('Numpad7', function() smartWalk(NorthWest) end, gameRootPanel) + + bindWalkKey('Up', North) + bindWalkKey('Right', East) + bindWalkKey('Down', South) + bindWalkKey('Left', West) + bindWalkKey('Numpad8', North) + bindWalkKey('Numpad9', NorthEast) + bindWalkKey('Numpad6', East) + bindWalkKey('Numpad3', SouthEast) + bindWalkKey('Numpad2', South) + bindWalkKey('Numpad1', SouthWest) + bindWalkKey('Numpad4', West) + bindWalkKey('Numpad7', NorthWest) g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel) g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel) @@ -111,6 +88,18 @@ function bindKeys() g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel) end +function bindWalkKey(key, dir) + g_keyboard.bindKeyDown(key, function() changeWalkDir(dir) end) + g_keyboard.bindKeyUp(key, function() changeWalkDir(dir, true) end) + g_keyboard.bindKeyPress(key, function() smartWalk(dir) end) +end + +function unbindWalkKey(key) + g_keyboard.unbindKeyDown(key) + g_keyboard.unbindKeyUp(key) + g_keyboard.unbindKeyPress(key) +end + function terminate() save() hide() diff --git a/modules/game_interface/widgets/uiitem.lua b/modules/game_interface/widgets/uiitem.lua index 21b8d825..5fc07f65 100644 --- a/modules/game_interface/widgets/uiitem.lua +++ b/modules/game_interface/widgets/uiitem.lua @@ -86,7 +86,7 @@ function UIItem:onMouseRelease(mousePosition, mouseButton) g_game.look(item) self.cancelNextRelease = true return true - elseif modules.game_interface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then + elseif modules.game_interface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, nil) then return true end return false diff --git a/modules/gamelib/game.lua b/modules/gamelib/game.lua index 1d90fbf7..325ba400 100644 --- a/modules/gamelib/game.lua +++ b/modules/gamelib/game.lua @@ -6,7 +6,7 @@ end function g_game.chooseRsa(host) if currentRsa ~= CIPSOFT_RSA and currentRsa ~= OTSERV_RSA then return end - if string.ends(host, '.tibia.com') or string.ends(host, '.cipsoft.com') then + if host:ends('.tibia.com') or host:ends('.cipsoft.com') then g_game.setRsa(CIPSOFT_RSA) if g_app.getOs() == 'windows' then