From b00076bcb92acbb26fa4506859dee7067e5361a9 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 9 Jan 2012 04:46:44 -0200 Subject: [PATCH] addon to show walk ping --- TODO | 2 ++ modules/addon_pingbar/pingbar.lua | 27 +++++++++++++++++++++++++++ modules/addon_pingbar/pingbar.otmod | 15 +++++++++++++++ modules/addon_terminal/terminal.otmod | 2 +- modules/client_topmenu/topmenu.otui | 4 ++-- modules/game_console/console.lua | 2 +- src/otclient/core/game.cpp | 12 +++++------- src/otclient/core/game.h | 6 +++--- 8 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 modules/addon_pingbar/pingbar.lua create mode 100644 modules/addon_pingbar/pingbar.otmod diff --git a/TODO b/TODO index 75651a1c..2280a6be 100644 --- a/TODO +++ b/TODO @@ -101,3 +101,5 @@ attack while walking cancels the walk if a spell is used while pressing arrows keys the walk is canceled and it doesnt starts walking again game map text message boxes is not displayed like tibia name/shields doesnt follow the creature when walking on parcels +hotkeys wont work with caps lock +hotkeys works while windows are locked, it shouldnt \ No newline at end of file diff --git a/modules/addon_pingbar/pingbar.lua b/modules/addon_pingbar/pingbar.lua new file mode 100644 index 00000000..c3b23c03 --- /dev/null +++ b/modules/addon_pingbar/pingbar.lua @@ -0,0 +1,27 @@ +PingBar = {} + +local pingLabel + +-- public functions +function PingBar.init() + pingLabel = createWidget('UILabel', rootWidget:recursiveGetChildById('leftButtonsPanel')) + pingLabel:applyStyle({ ['anchors.left'] = 'prev.right', + ['anchors.top'] = 'parent.top', + ['margin-top'] = 12, + ['margin-left'] = 10, + font = 'verdana-11px-rounded', + color = '#FE6500', + width = 120, + height = 16}) +end + +function PingBar.terminate() + pingLabel:destroy() +end + +-- hooked events +local function onGamePingUpdate(ping) + pingLabel:setText('Walk Ping: ' .. ping .. ' ms') +end + +connect(Game, { onWalkPingUpdate = onGamePingUpdate }) \ No newline at end of file diff --git a/modules/addon_pingbar/pingbar.otmod b/modules/addon_pingbar/pingbar.otmod new file mode 100644 index 00000000..ae22f279 --- /dev/null +++ b/modules/addon_pingbar/pingbar.otmod @@ -0,0 +1,15 @@ +Module + name: pingbar + description: Show ping in game + author: OTClient team + website: https://github.com/edubart/otclient + + autoLoad: true + autoLoadPriority: 1000 + + onLoad: | + require 'pingbar' + PingBar.init() + + onUnload: | + PingBar.terminate() diff --git a/modules/addon_terminal/terminal.otmod b/modules/addon_terminal/terminal.otmod index a8a9a710..7716c38c 100644 --- a/modules/addon_terminal/terminal.otmod +++ b/modules/addon_terminal/terminal.otmod @@ -5,7 +5,7 @@ Module website: https://github.com/edubart/otclient autoLoad: true - autoLoadPriority: 1000 + autoLoadPriority: 200 onLoad: | require 'terminal' diff --git a/modules/client_topmenu/topmenu.otui b/modules/client_topmenu/topmenu.otui index 07f7704a..5a4c2b37 100644 --- a/modules/client_topmenu/topmenu.otui +++ b/modules/client_topmenu/topmenu.otui @@ -66,11 +66,11 @@ TopPanel anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right - width: 60 + width: 70 FrameCounter id: frameCounter anchors.top: parent.top anchors.right: prev.left margin-top: 8 - margin-right: 12 \ No newline at end of file + margin-right: 5 \ No newline at end of file diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 3b9db163..1f8fba04 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -12,7 +12,7 @@ local SpeakTypes = { channelWhite = { color = '#FFFFFF' }, channelRed = { color = '#F55E5E' }, channelOrange = { color = '#FE6500' }, - private = { color = '#FFFF00' }, + private = { color = '#5FF7F7' }, playerToNpc = { color = '#9F9DFD' }, broadcast = { color = '#F55E5E' }, privateRed = { color = '#F55E5E' } diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b22ec1e8..5e879831 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -37,8 +37,7 @@ void Game::loginWorld(const std::string& account, const std::string& password, c m_online = false; m_dead = false; m_walkFeedback = true; - m_ping = 0; - m_pingTimer.restart(); + m_walkPing = 0; m_protocolGame = ProtocolGamePtr(new ProtocolGame); m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName); } @@ -77,7 +76,6 @@ void Game::processConnectionError(const boost::system::error_code& error) void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat) { - updatePing(); m_localPlayer = localPlayer; m_online = true; m_serverBeat = serverBeat; @@ -148,7 +146,7 @@ void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldP creature->cancelWalk(); } */ - if(!m_walkFeedback) { + if(!m_walkFeedback && creature == m_localPlayer) { updatePing(); m_walkFeedback = true; } @@ -183,7 +181,7 @@ void Game::walk(Otc::Direction direction) m_localPlayer->clientWalk(direction); // ping calculation restarts when the local players try to walk one tile - m_pingTimer.restart(); + m_walkPingTimer.restart(); switch(direction) { case Otc::North: @@ -388,6 +386,6 @@ bool Game::checkBotProtection() void Game::updatePing() { - m_ping = m_pingTimer.ticksElapsed(); - g_lua.callGlobalField("Game", "onPingUpdate", m_ping); + m_walkPing = m_walkPingTimer.ticksElapsed(); + g_lua.callGlobalField("Game", "onWalkPingUpdate", m_walkPing); } diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index 431cf218..ee377611 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -83,7 +83,7 @@ public: LocalPlayerPtr getLocalPlayer() { return m_localPlayer; } ProtocolGamePtr getProtocolGame() { return m_protocolGame; } int getProtocolVersion() { return PROTOCOL; } - int getPing() { return m_ping; } + int getWalkPing() { return m_walkPing; } private: void updatePing(); @@ -93,8 +93,8 @@ private: bool m_online; bool m_dead; bool m_walkFeedback; - Timer m_pingTimer; - int m_ping; + Timer m_walkPingTimer; + int m_walkPing; int m_serverBeat; };