From 486837a61d0fafbd942c3e7d8ef632f8becc166d Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 7 Jun 2012 08:52:17 -0300 Subject: [PATCH] minor fixes * change chase mode while walking and attacking * avoid lua errors in frame counter when starting --- modules/client_topmenu/topmenu.otui | 5 +- .../game_combatcontrols/combatcontrols.lua | 52 +++++++++++-------- src/otclient/core/game.cpp | 12 +++++ 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/modules/client_topmenu/topmenu.otui b/modules/client_topmenu/topmenu.otui index 523609ae..65750cf6 100644 --- a/modules/client_topmenu/topmenu.otui +++ b/modules/client_topmenu/topmenu.otui @@ -81,5 +81,8 @@ TopPanel margin-right: 5 @onSetup: | cycleEvent(function() - rootWidget:recursiveGetChildById('frameCounter'):setText('FPS: ' .. g_app.getBackgroundPaneFps()) + local frameCounter = rootWidget:recursiveGetChildById('frameCounter') + if frameCounter then + frameCounter:setText('FPS: ' .. g_app.getBackgroundPaneFps()) + end end, 250) diff --git a/modules/game_combatcontrols/combatcontrols.lua b/modules/game_combatcontrols/combatcontrols.lua index 9494d755..27fe569f 100644 --- a/modules/game_combatcontrols/combatcontrols.lua +++ b/modules/game_combatcontrols/combatcontrols.lua @@ -11,7 +11,7 @@ local safeFightButton local fightModeRadioGroup -- private functions -local function onFightModeChange(self, selectedFightButton) +local function onSetFightMode(self, selectedFightButton) if selectedFightButton == nil then return end local buttonId = selectedFightButton:getId() local fightMode @@ -22,28 +22,21 @@ local function onFightModeChange(self, selectedFightButton) else fightMode = FightDefensive end - if g_game.getFightMode() ~= fightMode then - g_game.setFightMode(fightMode) - end + g_game.setFightMode(fightMode) end -local function onChaseModeChange(self, checked) +local function onSetChaseMode(self, checked) local chaseMode if checked then chaseMode = ChaseOpponent else chaseMode = DontChase end - if g_game.getChaseMode() ~= chaseMode then - g_game.setChaseMode(chaseMode) - end + g_game.setChaseMode(chaseMode) end -local function onSafeFightChange(self, checked) - local safeFight = not checked - if g_game.isSafeFight() ~= safeFight then - g_game.setSafeFight(not checked) - end +local function onSetSafeFight(self, checked) + g_game.setSafeFight(not checked) end -- public functions @@ -63,11 +56,16 @@ function CombatControls.init() fightModeRadioGroup:addWidget(fightBalancedBox) fightModeRadioGroup:addWidget(fightDefensiveBox) - connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange }) - connect(chaseModeButton, { onCheckChange = onChaseModeChange }) - connect(safeFightButton, { onCheckChange = onSafeFightChange }) - connect(g_game, { onGameStart = CombatControls.online }) - connect(g_game, { onGameEnd = CombatControls.offline }) + connect(fightModeRadioGroup, { onSelectionChange = onSetFightMode }) + connect(chaseModeButton, { onCheckChange = onSetChaseMode }) + connect(safeFightButton, { onCheckChange = onSetSafeFight }) + connect(g_game, { + onGameStart = CombatControls.online, + onGameEnd = CombatControls.offline, + onFightModeChange = CombatControls.update, + onChaseModeChange = CombatControls.update, + onSafeFightChange = CombatControls.update + }) if g_game.isOnline() then CombatControls.online() @@ -94,15 +92,18 @@ function CombatControls.terminate() combatControlsWindow:destroy() combatControlsWindow = nil - disconnect(g_game, { onGameStart = CombatControls.online }) - disconnect(g_game, { onGameEnd = CombatControls.offline }) + disconnect(g_game, { + onGameStart = CombatControls.online, + onGameEnd = CombatControls.offline, + onFightModeChange = CombatControls.update, + onChaseModeChange = CombatControls.update, + onSafeFightChange = CombatControls.update + }) CombatControls = nil end -function CombatControls.online() - combatControlsWindow:setVisible(combatControlsButton:isOn()) - +function CombatControls.update() local fightMode = g_game.getFightMode() if fightMode == FightOffensive then fightModeRadioGroup:selectWidget(fightOffensiveBox) @@ -119,6 +120,11 @@ function CombatControls.online() safeFightButton:setChecked(not safeFight) end +function CombatControls.online() + combatControlsWindow:setVisible(combatControlsButton:isOn()) + CombatControls.update() +end + function CombatControls.offline() end diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b097518c..5ef0cd96 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -487,6 +487,9 @@ void Game::forceWalk(Otc::Direction direction) if(!canPerformGameAction()) return; + // always cancel chasing attacks + setChaseMode(Otc::DontChase); + switch(direction) { case Otc::North: m_protocolGame->sendWalkNorth(); @@ -879,24 +882,33 @@ void Game::setChaseMode(Otc::ChaseModes chaseMode) { if(!canPerformGameAction()) return; + if(m_chaseMode == chaseMode) + return; m_chaseMode = chaseMode; m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); + g_lua.callGlobalField("g_game", "onChaseModeChange", chaseMode); } void Game::setFightMode(Otc::FightModes fightMode) { if(!canPerformGameAction()) return; + if(m_fightMode == fightMode) + return; m_fightMode = fightMode; m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); + g_lua.callGlobalField("g_game", "onFightModeChange", fightMode); } void Game::setSafeFight(bool on) { if(!canPerformGameAction()) return; + if(m_safeFight == on) + return; m_safeFight = on; m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); + g_lua.callGlobalField("g_game", "onSafeFightChange", on); } void Game::inspectNpcTrade(const ItemPtr& item)