From 1782de7336e4863bf9cdd088ef8c5aa7766ce41a Mon Sep 17 00:00:00 2001 From: BeniS Date: Sun, 30 Dec 2012 06:41:14 +1300 Subject: [PATCH] Game control precision edits and many other fixes: * Updated the walking(mouse/keys) control to be a lot more responsive/smooth! * Updated creature diagonal steps to animate faster (due to demand). * Added a warning popup for boost walker option in cipsoft servers. * Added KeyUp event controls in the g_keyboard class. * Fixed an issue with the minimap not reconfiguring. * Fixed a bug with creature lights drawing properly. * Fixed refreshContainer method. * Some layout edits. * Some minor typo fixes. TODO: * Add walk event stack. * Test new walking edits extensively. * Finish pending state feature. --- modules/client/client.otmod | 2 +- modules/client_entergame/entergame.lua | 7 +- modules/client_options/options.lua | 36 ++++++++-- .../skins/default/images/button_square.png | Bin 315 -> 281 bytes .../skins/default/images/menubutton.png | Bin 0 -> 315 bytes .../skins/default/styles/popupmenus.otui | 2 +- modules/corelib/const.lua | 3 + modules/corelib/keyboard.lua | 62 +++++++++++++++++ modules/game_interface/gameinterface.lua | 63 ++++++++++++++++-- modules/game_minimap/minimap.lua | 11 +-- modules/game_ruleviolation/ruleviolation.lua | 2 +- modules/game_textwindow/textwindow.otui | 6 +- src/otclient/creature.cpp | 15 ++--- src/otclient/creature.h | 2 +- src/otclient/game.cpp | 19 ++++-- src/otclient/game.h | 6 +- src/otclient/localplayer.cpp | 2 +- src/otclient/luafunctions.cpp | 2 +- src/otclient/protocolcodes.h | 1 + src/otclient/protocolgame.h | 4 +- src/otclient/protocolgameparse.cpp | 16 ++--- src/otclient/protocolgamesend.cpp | 5 +- 22 files changed, 205 insertions(+), 61 deletions(-) create mode 100644 modules/client_skins/skins/default/images/menubutton.png diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 6bbde146..41fa3a57 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -11,10 +11,10 @@ Module //- client_particles - client_topmenu - client_background + - client_entergame - client_options - client_terminal - client_modulemanager - - client_entergame //- client_stats @onLoad: | diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index 6221e834..0b8fc5d4 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -3,6 +3,7 @@ EnterGame = { } -- private variables local loadBox local enterGame +local motdWindow local motdButton local enterGameButton local protocolBox @@ -121,6 +122,8 @@ function EnterGame.terminate() enterGame = nil enterGameButton:destroy() enterGameButton = nil + motdWindow:destroy() + motdWindow = nil motdButton:destroy() motdButton = nil protocolBox = nil @@ -200,7 +203,9 @@ function EnterGame.doLogin() end function EnterGame.displayMotd() - displayInfoBox(tr('Message of the day'), G.motdMessage) + if not motdWindow or not motdWindow:isVisible() then + motdWindow = displayInfoBox(tr('Message of the day'), G.motdMessage) + end end function EnterGame.setDefaultServer(host, port, protocol) diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 1a46256e..b38a6d6d 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -25,11 +25,13 @@ local defaultOptions = { painterEngine = 0 } +local warningWindow local optionsWindow local optionsButton local optionsTabBar local options = {} -local generalPanel +local gamePanel +local consolePanel local graphicsPanel local function setupGraphicsEngines() @@ -62,6 +64,21 @@ local function setupGraphicsEngines() end end +function displayWarning(widget, warning) + if warningWindow and warningWindow:isVisible() then + return + end + if g_game.isOfficialTibia() and widget:isChecked() then + local yesCallback = function() warningWindow:destroy() warningWindow=nil end + local noCallback = function() widget:setChecked(false) warningWindow:destroy() warningWindow=nil end + + warningWindow = displayGeneralBox('Warning', tr(warning), { + { text='Yes', callback=yesCallback }, + { text='No', callback=noCallback }, + anchor=AnchorHorizontalCenter}, yesCallback, noCallback) + end +end + function Options.init() -- load options for k,v in pairs(defaultOptions) do @@ -83,15 +100,21 @@ function Options.init() optionsTabBar = optionsWindow:getChildById('optionsTabBar') optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent')) - generalPanel = g_ui.loadUI('game.otui') - optionsTabBar:addTab(tr('Game'), generalPanel) + gamePanel = g_ui.loadUI('game.otui') + optionsTabBar:addTab(tr('Game'), gamePanel) - generalPanel = g_ui.loadUI('console.otui') - optionsTabBar:addTab(tr('Console'), generalPanel) + consolePanel = g_ui.loadUI('console.otui') + optionsTabBar:addTab(tr('Console'), consolePanel) graphicsPanel = g_ui.loadUI('graphics.otui') optionsTabBar:addTab(tr('Graphics'), graphicsPanel) + local optionWalkBooster = gamePanel:getChildById('walkBooster') + optionWalkBooster.onCheckChange = function(widget) + displayWarning(widget, "This feature could be detectable by official Tibia servers. Would like to continue?") + Options.setOption(widget:getId(), widget:isChecked()) + end + setupGraphicsEngines() end @@ -103,7 +126,8 @@ function Options.terminate() optionsButton:destroy() optionsButton = nil optionsTabBar = nil - generalPanel = nil + gamePanel = nil + consolePanel = nil graphicsPanel = nil Options = nil end diff --git a/modules/client_skins/skins/default/images/button_square.png b/modules/client_skins/skins/default/images/button_square.png index 75b2c6cc743a0812a1b7da66c9a63d29bf30d45e..ad8374ef5b06b7e01a1f01a1f43fbec165424c39 100644 GIT binary patch delta 253 zcmVnM zopMXAPFSbc2b!=p3M#0eg0*?w!{g0J}*v|4yjX~ z)jbQFuhx9n3^K@I?>oge7PGR{XE)7O>#4v&lght328Gf$w;5SIareUsJnZ zPGafa>N)q)t#Ywt$As;2*d$Xne4qR2_j!*45z?DlgetLight(); - if(m_light.intensity != light.intensity && m_light.color != light.color) + if(m_light.intensity != light.intensity || m_light.color != light.color) light = m_light; // local player always have a minimum light in complete darkness @@ -384,7 +384,7 @@ void Creature::updateWalkAnimation(int totalPixelsWalked) int footAnimPhases = getAnimationPhases() - 1; if(totalPixelsWalked == 32 || footAnimPhases == 0) m_walkAnimationPhase = 0; - else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= getStepDuration() / 4 ) { + else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= getStepDuration(true) / 4 ) { m_footStep++; m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases); m_footStepDrawn = false; @@ -459,8 +459,7 @@ void Creature::nextWalkUpdate() void Creature::updateWalk() { - int stepDuration = getStepDuration(); - float walkTicksPerPixel = stepDuration / 32; + float walkTicksPerPixel = getStepDuration(true) / 32; int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); // needed for paralyze effect @@ -472,7 +471,7 @@ void Creature::updateWalk() updateWalkingTile(); // terminate walk - if(m_walking && m_walkTimer.ticksElapsed() >= stepDuration) + if(m_walking && m_walkTimer.ticksElapsed() >= getStepDuration()) terminateWalk(); } @@ -670,7 +669,7 @@ Point Creature::getDrawOffset() return drawOffset; } -int Creature::getStepDuration() +int Creature::getStepDuration(bool ignoreDiagonal) { int speed = m_speed; if(g_game.getFeature(Otc::GameNewSpeedLaw)) @@ -707,8 +706,8 @@ int Creature::getStepDuration() interval = std::max(interval, g_game.getServerBeat()); - if(m_lastStepDirection == Otc::NorthWest || m_lastStepDirection == Otc::NorthEast || - m_lastStepDirection == Otc::SouthWest || m_lastStepDirection == Otc::SouthEast) + if(!ignoreDiagonal && (m_lastStepDirection == Otc::NorthWest || m_lastStepDirection == Otc::NorthEast || + m_lastStepDirection == Otc::SouthWest || m_lastStepDirection == Otc::SouthEast)) interval *= 3; return interval; diff --git a/src/otclient/creature.h b/src/otclient/creature.h index b15d9a97..015eb631 100644 --- a/src/otclient/creature.h +++ b/src/otclient/creature.h @@ -84,7 +84,7 @@ public: uint8 getEmblem() { return m_emblem; } bool isPassable() { return m_passable; } Point getDrawOffset(); - int getStepDuration(); + int getStepDuration(bool ignoreDiagonal = false); Point getWalkOffset() { return m_walkOffset; } Position getLastStepFromPosition() { return m_lastStepFromPosition; } Position getLastStepToPosition() { return m_lastStepToPosition; } diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index c89f7570..ecc37150 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -495,7 +495,7 @@ bool Game::walk(Otc::Direction direction) if(isFollowing()) cancelFollow(); - // msut cancel auto walking and wait next try + // must cancel auto walking and wait next try if(m_localPlayer->isAutoWalking()) { m_protocolGame->sendStop(); return false; @@ -549,7 +549,7 @@ bool Game::walk(Otc::Direction direction) return true; } -void Game::autoWalk(const std::vector& dirs) +void Game::autoWalk(std::vector dirs) { if(!canPerformGameAction()) return; @@ -567,11 +567,16 @@ void Game::autoWalk(const std::vector& dirs) if(isFollowing()) cancelFollow(); - Otc::Direction direction = dirs.front(); + auto it = dirs.begin(); + Otc::Direction direction = *it; if(m_localPlayer->canWalk(direction)) { TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction)); if(toTile && toTile->isWalkable() && !m_localPlayer->isAutoWalking()) + { m_localPlayer->preWalk(direction); + forceWalk(direction); + dirs.erase(it); + } } g_lua.callGlobalField("g_game", "onAutoWalk", dirs); @@ -777,11 +782,11 @@ void Game::close(const ContainerPtr& container) m_protocolGame->sendCloseContainer(container->getId()); } -void Game::refreshContainer() +void Game::refreshContainer(const ContainerPtr& container) { if(!canPerformGameAction()) return; - m_protocolGame->sendRefreshContainer(); + m_protocolGame->sendRefreshContainer(container->getId()); } void Game::attack(CreaturePtr creature) @@ -1095,11 +1100,11 @@ void Game::reportBug(const std::string& comment) m_protocolGame->sendBugReport(comment); } -void Game::reportRuleVilation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment) +void Game::reportRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment) { if(!canPerformGameAction()) return; - m_protocolGame->sendRuleVilation(target, reason, action, comment, statement, statementId, ipBanishment); + m_protocolGame->sendRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment); } void Game::debugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d) diff --git a/src/otclient/game.h b/src/otclient/game.h index 8d318f81..428ad66e 100644 --- a/src/otclient/game.h +++ b/src/otclient/game.h @@ -140,7 +140,7 @@ public: // walk related bool walk(Otc::Direction direction); - void autoWalk(const std::vector& dirs); + void autoWalk(std::vector dirs); void forceWalk(Otc::Direction direction); void turn(Otc::Direction direction); void stop(); @@ -159,7 +159,7 @@ public: void open(const ItemPtr& item, const ContainerPtr& previousContainer); void openParent(const ContainerPtr& container); void close(const ContainerPtr& container); - void refreshContainer(); + void refreshContainer(const ContainerPtr& container); // attack/follow related void attack(CreaturePtr creature); @@ -225,7 +225,7 @@ public: // reports void reportBug(const std::string& comment); - void reportRuleVilation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment); + void reportRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment); void debugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d); // questlog related diff --git a/src/otclient/localplayer.cpp b/src/otclient/localplayer.cpp index bcf8d536..c1284762 100644 --- a/src/otclient/localplayer.cpp +++ b/src/otclient/localplayer.cpp @@ -190,7 +190,7 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked) void LocalPlayer::updateWalk() { int stepDuration = getStepDuration(); - float walkTicksPerPixel = stepDuration / 32.0f; + float walkTicksPerPixel = getStepDuration(true) / 32.0f; int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); // update walk animation and offsets diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 98e185c2..43193eea 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -194,7 +194,7 @@ void OTClient::registerLuaFunctions() g_lua.bindSingletonFunction("g_game", "acceptTrade", &Game::acceptTrade, &g_game); g_lua.bindSingletonFunction("g_game", "rejectTrade", &Game::rejectTrade, &g_game); g_lua.bindSingletonFunction("g_game", "reportBug", &Game::reportBug, &g_game); - g_lua.bindSingletonFunction("g_game", "reportRuleVilation", &Game::reportRuleVilation, &g_game); + g_lua.bindSingletonFunction("g_game", "reportRuleViolation", &Game::reportRuleViolation, &g_game); g_lua.bindSingletonFunction("g_game", "debugReport", &Game::debugReport, &g_game); g_lua.bindSingletonFunction("g_game", "editText", &Game::editText, &g_game); g_lua.bindSingletonFunction("g_game", "editList", &Game::editList, &g_game); diff --git a/src/otclient/protocolcodes.h b/src/otclient/protocolcodes.h index 96834fb3..0c95c3ac 100644 --- a/src/otclient/protocolcodes.h +++ b/src/otclient/protocolcodes.h @@ -214,6 +214,7 @@ namespace Proto { ClientInviteToOwnChannel = 171, ClientExcludeFromOwnChannel = 172, ClientCancelAttackAndFollow = 190, + ClientUpdateTile = 201, ClientRefreshContainer = 202, ClientRequestOutfit = 210, ClientChangeOutfit = 211, diff --git a/src/otclient/protocolgame.h b/src/otclient/protocolgame.h index aca63451..7e5b0f9e 100644 --- a/src/otclient/protocolgame.h +++ b/src/otclient/protocolgame.h @@ -92,14 +92,14 @@ public: void sendInviteToOwnChannel(const std::string& name); void sendExcludeFromOwnChannel(const std::string& name); void sendCancelAttackAndFollow(); - void sendRefreshContainer(); + void sendRefreshContainer(int containerId); void sendRequestOutfit(); void sendChangeOutfit(const Outfit& outfit); void sendMountStatus(bool mount); void sendAddVip(const std::string& name); void sendRemoveVip(uint playerId); void sendBugReport(const std::string& comment); - void sendRuleVilation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment); + void sendRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment); void sendDebugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d); void sendRequestQuestLog(); void sendRequestQuestLine(int questId); diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index 56270857..84b2b22c 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -1411,24 +1411,24 @@ void ProtocolGame::parseShowModalDialog(const InputMessagePtr& msg) int sizeButtons = msg->getU8(); std::map buttonList; for(int i = 0; i < sizeButtons; ++i) { - std::string name = msg->getString(); - int value = msg->getU8(); - buttonList[value] = name; + std::string value = msg->getString(); + int id = msg->getU8(); + buttonList[id] = value; } int sizeChoices = msg->getU8(); std::vector > choiceList; for(int i = 0; i < sizeChoices; ++i) { - std::string name = msg->getString(); - int value = msg->getU8(); - choiceList.push_back(std::make_tuple(value, name)); + std::string value = msg->getString(); + int id = msg->getU8(); + choiceList.push_back(std::make_tuple(id, value)); } int enterButton = msg->getU8(); int escapeButton = msg->getU8(); msg->getU8(); // popup value (no clue what it is for) - std::map::iterator itEnter = buttonList.find(enterButton); + std::map::iterator itEnter = buttonList.find(enterButton); if(itEnter == buttonList.end()) { g_logger.info(stdext::format("Enter button does not exist for dialog id: %d", id)); @@ -1743,7 +1743,7 @@ Position ProtocolGame::getPosition(const InputMessagePtr& msg) { uint16 x = msg->getU16(); uint16 y = msg->getU16(); - uint8 z = msg->getU8(); + uint8 z = msg->getU8(); return Position(x, y, z); } diff --git a/src/otclient/protocolgamesend.cpp b/src/otclient/protocolgamesend.cpp index 7ef465d9..b9fa6025 100644 --- a/src/otclient/protocolgamesend.cpp +++ b/src/otclient/protocolgamesend.cpp @@ -629,10 +629,11 @@ void ProtocolGame::sendCancelAttackAndFollow() send(msg); } -void ProtocolGame::sendRefreshContainer() +void ProtocolGame::sendRefreshContainer(int containerId) { OutputMessagePtr msg(new OutputMessage); msg->addU8(Proto::ClientRefreshContainer); + msg->addU8(containerId); send(msg); } @@ -694,7 +695,7 @@ void ProtocolGame::sendBugReport(const std::string& comment) send(msg); } -void ProtocolGame::sendRuleVilation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment) +void ProtocolGame::sendRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment) { OutputMessagePtr msg(new OutputMessage); msg->addU8(Proto::ClientRuleViolation);