2012-01-24 19:39:16 +01:00
|
|
|
CombatControls = {}
|
|
|
|
|
2012-02-08 00:06:52 +01:00
|
|
|
-- private variables
|
2012-02-07 02:35:46 +01:00
|
|
|
local combatControlsButton
|
2012-02-08 00:06:52 +01:00
|
|
|
local combatControlsWindow
|
|
|
|
local fightOffensiveBox
|
|
|
|
local fightBalancedBox
|
|
|
|
local fightDefensiveBox
|
|
|
|
local chaseModeButton
|
|
|
|
local safeFightButton
|
|
|
|
local fightModeRadioGroup
|
2012-02-07 02:35:46 +01:00
|
|
|
|
2012-02-08 00:06:52 +01:00
|
|
|
-- private functions
|
2012-06-07 13:52:17 +02:00
|
|
|
local function onSetFightMode(self, selectedFightButton)
|
2012-02-08 00:06:52 +01:00
|
|
|
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
|
2012-06-07 13:52:17 +02:00
|
|
|
g_game.setFightMode(fightMode)
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
local function onSetChaseMode(self, checked)
|
2012-02-08 00:06:52 +01:00
|
|
|
local chaseMode
|
|
|
|
if checked then
|
|
|
|
chaseMode = ChaseOpponent
|
|
|
|
else
|
|
|
|
chaseMode = DontChase
|
|
|
|
end
|
2012-06-07 13:52:17 +02:00
|
|
|
g_game.setChaseMode(chaseMode)
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
local function onSetSafeFight(self, checked)
|
|
|
|
g_game.setSafeFight(not checked)
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- public functions
|
2012-01-24 19:39:16 +01:00
|
|
|
function CombatControls.init()
|
2012-04-26 21:54:16 +02:00
|
|
|
combatControlsButton = TopMenu.addGameToggleButton('combatControlsButton', tr('Combat Controls'), 'combatcontrols.png', CombatControls.toggle)
|
2012-02-08 00:06:52 +01:00
|
|
|
combatControlsButton:setOn(true)
|
2012-03-22 22:47:52 +01:00
|
|
|
combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel())
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
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
|
|
|
|
|
|
|
fightModeRadioGroup = RadioGroup.create()
|
|
|
|
fightModeRadioGroup:addWidget(fightOffensiveBox)
|
|
|
|
fightModeRadioGroup:addWidget(fightBalancedBox)
|
|
|
|
fightModeRadioGroup:addWidget(fightDefensiveBox)
|
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
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
|
|
|
|
})
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-02-08 00:06:52 +01:00
|
|
|
CombatControls.online()
|
|
|
|
end
|
|
|
|
end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
|
|
|
function CombatControls.terminate()
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-02-08 00:06:52 +01:00
|
|
|
CombatControls.offline()
|
|
|
|
end
|
|
|
|
|
|
|
|
fightModeRadioGroup:destroy()
|
|
|
|
fightModeRadioGroup = nil
|
|
|
|
|
|
|
|
fightOffensiveBox = nil
|
|
|
|
fightBalancedBox = nil
|
|
|
|
fightDefensiveBox = nil
|
|
|
|
chaseModeButton = nil
|
|
|
|
safeFightButton = nil
|
|
|
|
|
2012-02-07 02:35:46 +01:00
|
|
|
combatControlsButton:destroy()
|
|
|
|
combatControlsButton = nil
|
2012-02-08 00:06:52 +01:00
|
|
|
|
|
|
|
combatControlsWindow:destroy()
|
|
|
|
combatControlsWindow = nil
|
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
disconnect(g_game, {
|
|
|
|
onGameStart = CombatControls.online,
|
|
|
|
onGameEnd = CombatControls.offline,
|
|
|
|
onFightModeChange = CombatControls.update,
|
|
|
|
onChaseModeChange = CombatControls.update,
|
|
|
|
onSafeFightChange = CombatControls.update
|
|
|
|
})
|
2012-02-08 00:06:52 +01:00
|
|
|
|
|
|
|
CombatControls = nil
|
2012-02-07 02:35:46 +01:00
|
|
|
end
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
function CombatControls.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
|
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
function CombatControls.online()
|
|
|
|
combatControlsWindow:setVisible(combatControlsButton:isOn())
|
|
|
|
CombatControls.update()
|
|
|
|
end
|
|
|
|
|
2012-02-08 00:06:52 +01:00
|
|
|
function CombatControls.offline()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CombatControls.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
|
|
|
|
|
2012-06-21 21:31:22 +02:00
|
|
|
function CombatControls.onMiniWindowClose()
|
|
|
|
combatControlsButton:setOn(false)
|
|
|
|
end
|