tibia-client/modules/game_combatcontrols/combatcontrols.lua

172 lines
4.6 KiB
Lua
Raw Normal View History

combatControlsButton = nil
combatControlsWindow = nil
fightOffensiveBox = nil
fightBalancedBox = nil
fightDefensiveBox = nil
chaseModeButton = nil
safeFightButton = nil
fightModeRadioGroup = nil
function init()
combatControlsButton = TopMenu.addRightGameToggleButton('combatControlsButton', tr('Combat Controls'), 'combatcontrols.png', toggle)
2012-02-08 00:06:52 +01:00
combatControlsButton:setOn(true)
combatControlsWindow = g_ui.loadUI('combatcontrols.otui', modules.game_interface.getRightPanel())
combatControlsWindow:disableResize()
fightOffensiveBox = combatControlsWindow:recursiveGetChildById('fightOffensiveBox')
fightBalancedBox = combatControlsWindow:recursiveGetChildById('fightBalancedBox')
fightDefensiveBox = combatControlsWindow:recursiveGetChildById('fightDefensiveBox')
chaseModeButton = combatControlsWindow:recursiveGetChildById('chaseModeBox')
safeFightButton = combatControlsWindow:recursiveGetChildById('safeFightBox')
2012-02-08 00:06:52 +01:00
2012-06-26 00:13:30 +02:00
fightModeRadioGroup = UIRadioGroup.create()
2012-02-08 00:06:52 +01:00
fightModeRadioGroup:addWidget(fightOffensiveBox)
fightModeRadioGroup:addWidget(fightBalancedBox)
fightModeRadioGroup:addWidget(fightDefensiveBox)
connect(fightModeRadioGroup, { onSelectionChange = onSetFightMode })
connect(chaseModeButton, { onCheckChange = onSetChaseMode })
connect(safeFightButton, { onCheckChange = onSetSafeFight })
connect(g_game, {
onGameStart = online,
onGameEnd = offline,
onFightModeChange = update,
onChaseModeChange = update,
onSafeFightChange = update,
2012-08-18 05:30:40 +02:00
onWalk = check,
onAutoWalk = check
})
2012-02-08 00:06:52 +01:00
2012-02-08 22:23:15 +01:00
if g_game.isOnline() then
online()
2012-02-08 00:06:52 +01:00
end
2012-08-21 23:40:47 +02:00
combatControlsWindow:setup()
2012-02-08 00:06:52 +01:00
end
function terminate()
2012-02-08 22:23:15 +01:00
if g_game.isOnline() then
offline()
2012-02-08 00:06:52 +01:00
end
fightModeRadioGroup:destroy()
2012-02-07 02:35:46 +01:00
combatControlsButton:destroy()
2012-02-08 00:06:52 +01:00
combatControlsWindow:destroy()
disconnect(g_game, {
onGameStart = online,
onGameEnd = offline,
onFightModeChange = update,
onChaseModeChange = update,
onSafeFightChange = update,
2012-08-18 05:30:40 +02:00
onWalk = check,
onAutoWalk = check
})
2012-02-07 02:35:46 +01:00
end
2012-02-08 00:06:52 +01:00
function update()
2012-02-08 22:23:15 +01:00
local fightMode = g_game.getFightMode()
2012-02-08 00:06:52 +01:00
if fightMode == FightOffensive then
fightModeRadioGroup:selectWidget(fightOffensiveBox)
elseif fightMode == FightBalanced then
fightModeRadioGroup:selectWidget(fightBalancedBox)
else
fightModeRadioGroup:selectWidget(fightDefensiveBox)
end
2012-02-08 22:23:15 +01:00
local chaseMode = g_game.getChaseMode()
2012-02-08 00:06:52 +01:00
chaseModeButton:setChecked(chaseMode == ChaseOpponent)
2012-02-08 22:23:15 +01:00
local safeFight = g_game.isSafeFight()
2012-02-08 00:06:52 +01:00
safeFightButton:setChecked(not safeFight)
end
function check()
if Options.getOption('autoChaseOverride') then
if g_game.isAttacking() and g_game.getChaseMode() == ChaseOpponent then
g_game.setChaseMode(DontChase)
end
end
end
function online()
local player = g_game.getLocalPlayer()
if player then
local char = player:getName()
local lastCombatControls = g_settings.getNode('LastCombatControls')
if not table.empty(lastCombatControls) then
if lastCombatControls[char] then
g_game.setFightMode(lastCombatControls[char].fightMode)
g_game.setChaseMode(lastCombatControls[char].chaseMode)
g_game.setSafeFight(lastCombatControls[char].safeFight)
end
end
end
update()
end
function offline()
local lastCombatControls = g_settings.getNode('LastCombatControls')
if not lastCombatControls then
lastCombatControls = {}
end
local player = g_game.getLocalPlayer()
if player then
local char = player:getName()
lastCombatControls[char] = {
fightMode = g_game.getFightMode(),
chaseMode = g_game.getChaseMode(),
safeFight = g_game.isSafeFight()
}
-- save last combat control settings
g_settings.setNode('LastCombatControls', lastCombatControls)
end
2012-02-08 00:06:52 +01:00
end
function toggle()
2012-06-21 21:31:22 +02:00
if combatControlsButton:isOn() then
combatControlsWindow:close()
combatControlsButton:setOn(false)
else
combatControlsWindow:open()
combatControlsButton:setOn(true)
end
2012-02-08 00:06:52 +01:00
end
function onSetFightMode(self, selectedFightButton)
if selectedFightButton == nil then return end
local buttonId = selectedFightButton:getId()
local fightMode
if buttonId == 'fightOffensiveBox' then
fightMode = FightOffensive
elseif buttonId == 'fightBalancedBox' then
fightMode = FightBalanced
else
fightMode = FightDefensive
end
g_game.setFightMode(fightMode)
end
function onSetChaseMode(self, checked)
local chaseMode
if checked then
chaseMode = ChaseOpponent
else
chaseMode = DontChase
end
g_game.setChaseMode(chaseMode)
end
function onSetSafeFight(self, checked)
g_game.setSafeFight(not checked)
end
function onMiniWindowClose()
combatControlsButton:setOn(false)
end