minor fixes

* change chase mode while walking and attacking
* avoid lua errors in frame counter when starting
This commit is contained in:
Eduardo Bart 2012-06-07 08:52:17 -03:00
parent 48d243a11d
commit 486837a61d
3 changed files with 45 additions and 24 deletions

View File

@ -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)

View File

@ -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
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
end
local function onSafeFightChange(self, checked)
local safeFight = not checked
if g_game.isSafeFight() ~= safeFight then
local function onSetSafeFight(self, checked)
g_game.setSafeFight(not checked)
end
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

View File

@ -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)