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
|
|
|
|
local function onFightModeChange(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
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.getFightMode ~= fightMode then
|
|
|
|
g_game.setFightMode(fightMode)
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onChaseModeChange(self, checked)
|
|
|
|
local chaseMode
|
|
|
|
if checked then
|
|
|
|
chaseMode = ChaseOpponent
|
|
|
|
else
|
|
|
|
chaseMode = DontChase
|
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.getChaseMode() ~= chaseMode then
|
|
|
|
g_game.setChaseMode(chaseMode)
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onSafeFightChange(self, checked)
|
|
|
|
local safeFight = not checked
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isSafeFight() ~= safeFight then
|
|
|
|
g_game.setSafeFight(not checked)
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- public functions
|
2012-01-24 19:39:16 +01:00
|
|
|
function CombatControls.init()
|
2012-02-07 02:35:46 +01:00
|
|
|
combatControlsButton = TopMenu.addGameButton('combatControlsButton', '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-02-08 00:06:52 +01:00
|
|
|
fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox')
|
|
|
|
fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox')
|
|
|
|
fightDefensiveBox = combatControlsWindow:getChildById('fightDefensiveBox')
|
|
|
|
chaseModeButton = combatControlsWindow:getChildById('chaseModeBox')
|
|
|
|
safeFightButton = combatControlsWindow:getChildById('safeFightBox')
|
|
|
|
|
|
|
|
fightModeRadioGroup = RadioGroup.create()
|
|
|
|
fightModeRadioGroup:addWidget(fightOffensiveBox)
|
|
|
|
fightModeRadioGroup:addWidget(fightBalancedBox)
|
|
|
|
fightModeRadioGroup:addWidget(fightDefensiveBox)
|
|
|
|
|
|
|
|
connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
|
|
|
|
connect(chaseModeButton, { onCheckChange = onChaseModeChange })
|
|
|
|
connect(safeFightButton, { onCheckChange = onSafeFightChange })
|
2012-02-08 22:23:15 +01:00
|
|
|
connect(g_game, { onGameStart = CombatControls.online })
|
|
|
|
connect(g_game, { onGameEnd = CombatControls.offline })
|
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-02-08 22:23:15 +01:00
|
|
|
disconnect(g_game, { onGameStart = CombatControls.online })
|
|
|
|
disconnect(g_game, { onGameEnd = CombatControls.offline })
|
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
|
|
|
|
|
|
|
function CombatControls.online()
|
|
|
|
combatControlsWindow:setVisible(combatControlsButton:isOn())
|
|
|
|
|
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 CombatControls.offline()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CombatControls.toggle()
|
|
|
|
local visible = not combatControlsWindow:isExplicitlyVisible()
|
|
|
|
combatControlsWindow:setVisible(visible)
|
|
|
|
combatControlsButton:setOn(visible)
|
|
|
|
end
|
|
|
|
|