2012-07-24 07:30:08 +02:00
|
|
|
combatControlsButton = nil
|
|
|
|
combatControlsWindow = nil
|
|
|
|
fightOffensiveBox = nil
|
|
|
|
fightBalancedBox = nil
|
|
|
|
fightDefensiveBox = nil
|
|
|
|
chaseModeButton = nil
|
|
|
|
safeFightButton = nil
|
2013-11-19 00:50:00 +01:00
|
|
|
whiteDoveBox = nil
|
|
|
|
whiteHandBox = nil
|
|
|
|
yellowHandBox = nil
|
|
|
|
redFistBox = nil
|
|
|
|
mountButton = nil
|
|
|
|
pvpModesPanel = nil
|
2012-07-24 07:30:08 +02:00
|
|
|
fightModeRadioGroup = nil
|
2013-11-19 00:50:00 +01:00
|
|
|
pvpModeRadioGroup = nil
|
2012-07-24 07:30:08 +02:00
|
|
|
|
|
|
|
function init()
|
2013-01-18 23:39:11 +01:00
|
|
|
combatControlsButton = modules.client_topmenu.addRightGameToggleButton('combatControlsButton', tr('Combat Controls'), '/images/topbuttons/combatcontrols', toggle)
|
2012-02-08 00:06:52 +01:00
|
|
|
combatControlsButton:setOn(true)
|
2013-01-18 23:39:11 +01:00
|
|
|
combatControlsWindow = g_ui.loadUI('combatcontrols', modules.game_interface.getRightPanel())
|
2012-07-13 01:40:55 +02:00
|
|
|
combatControlsWindow:disableResize()
|
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')
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
chaseModeButton = combatControlsWindow:recursiveGetChildById('chaseModeBox')
|
|
|
|
safeFightButton = combatControlsWindow:recursiveGetChildById('safeFightBox')
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
mountButton = combatControlsWindow:recursiveGetChildById('mountButton')
|
|
|
|
mountButton.onClick = onMountButtonClick
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
pvpModesPanel = combatControlsWindow:recursiveGetChildById('pvpModesPanel')
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
whiteDoveBox = combatControlsWindow:recursiveGetChildById('whiteDoveBox')
|
|
|
|
whiteHandBox = combatControlsWindow:recursiveGetChildById('whiteHandBox')
|
|
|
|
yellowHandBox = combatControlsWindow:recursiveGetChildById('yellowHandBox')
|
|
|
|
redFistBox = combatControlsWindow:recursiveGetChildById('redFistBox')
|
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)
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
pvpModeRadioGroup = UIRadioGroup.create()
|
|
|
|
pvpModeRadioGroup:addWidget(whiteDoveBox)
|
|
|
|
pvpModeRadioGroup:addWidget(whiteHandBox)
|
|
|
|
pvpModeRadioGroup:addWidget(yellowHandBox)
|
|
|
|
pvpModeRadioGroup:addWidget(redFistBox)
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
connect(fightModeRadioGroup, { onSelectionChange = onSetFightMode })
|
2013-11-19 00:50:00 +01:00
|
|
|
connect(pvpModeRadioGroup, { onSelectionChange = onSetPVPMode })
|
2012-06-07 13:52:17 +02:00
|
|
|
connect(chaseModeButton, { onCheckChange = onSetChaseMode })
|
|
|
|
connect(safeFightButton, { onCheckChange = onSetSafeFight })
|
|
|
|
connect(g_game, {
|
2012-07-24 07:30:08 +02:00
|
|
|
onGameStart = online,
|
|
|
|
onGameEnd = offline,
|
|
|
|
onFightModeChange = update,
|
|
|
|
onChaseModeChange = update,
|
|
|
|
onSafeFightChange = update,
|
2013-11-19 00:50:00 +01:00
|
|
|
onPVPModeChange = update,
|
2012-08-18 05:30:40 +02:00
|
|
|
onWalk = check,
|
|
|
|
onAutoWalk = check
|
2012-06-07 13:52:17 +02:00
|
|
|
})
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
connect(LocalPlayer, { onOutfitChange = onOutfitChange })
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-07-24 07:30:08 +02:00
|
|
|
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
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function terminate()
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-07-24 07:30:08 +02:00
|
|
|
offline()
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
fightModeRadioGroup:destroy()
|
2013-11-19 00:50:00 +01:00
|
|
|
pvpModeRadioGroup:destroy()
|
2012-02-08 00:06:52 +01:00
|
|
|
combatControlsWindow:destroy()
|
2013-02-01 05:32:15 +01:00
|
|
|
combatControlsButton:destroy()
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-06-07 13:52:17 +02:00
|
|
|
disconnect(g_game, {
|
2012-07-24 07:30:08 +02:00
|
|
|
onGameStart = online,
|
|
|
|
onGameEnd = offline,
|
|
|
|
onFightModeChange = update,
|
|
|
|
onChaseModeChange = update,
|
|
|
|
onSafeFightChange = update,
|
2013-11-19 00:50:00 +01:00
|
|
|
onPVPModeChange = update,
|
2012-08-18 05:30:40 +02:00
|
|
|
onWalk = check,
|
|
|
|
onAutoWalk = check
|
2012-06-07 13:52:17 +02:00
|
|
|
})
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
disconnect(LocalPlayer, { onOutfitChange = onOutfitChange })
|
2012-02-07 02:35:46 +01:00
|
|
|
end
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-07-24 07:30:08 +02: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)
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
if g_game.getFeature(GamePVPMode) then
|
|
|
|
local pvpMode = g_game.getPVPMode()
|
|
|
|
local pvpWidget = getPVPBoxByMode(pvpMode)
|
|
|
|
if pvpWidget then
|
|
|
|
pvpModeRadioGroup:selectWidget(pvpWidget)
|
|
|
|
end
|
|
|
|
end
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function check()
|
2013-01-18 23:39:11 +01:00
|
|
|
if modules.client_options.getOption('autoChaseOverride') then
|
2012-08-17 07:31:23 +02:00
|
|
|
if g_game.isAttacking() and g_game.getChaseMode() == ChaseOpponent then
|
2012-07-07 16:09:50 +02:00
|
|
|
g_game.setChaseMode(DontChase)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function online()
|
2012-07-12 18:45:22 +02:00
|
|
|
local player = g_game.getLocalPlayer()
|
2012-08-17 07:31:23 +02:00
|
|
|
if player then
|
2013-01-30 21:23:26 +01:00
|
|
|
local char = g_game.getCharacterName()
|
2012-07-13 01:40:55 +02:00
|
|
|
|
2014-04-01 05:51:38 +02:00
|
|
|
local lastCombatControls = g_settings.getNode('LastCombatControls')
|
2012-07-13 01:40:55 +02:00
|
|
|
|
2012-08-17 07:31:23 +02:00
|
|
|
if not table.empty(lastCombatControls) then
|
|
|
|
if lastCombatControls[char] then
|
2012-07-12 18:45:22 +02:00
|
|
|
g_game.setFightMode(lastCombatControls[char].fightMode)
|
|
|
|
g_game.setChaseMode(lastCombatControls[char].chaseMode)
|
|
|
|
g_game.setSafeFight(lastCombatControls[char].safeFight)
|
2013-11-19 00:55:42 +01:00
|
|
|
if lastCombatControls[char].pvpMode then
|
2013-11-19 00:50:00 +01:00
|
|
|
g_game.setPVPMode(lastCombatControls[char].pvpMode)
|
|
|
|
end
|
2012-07-12 18:45:22 +02:00
|
|
|
end
|
|
|
|
end
|
2013-11-19 00:50:00 +01:00
|
|
|
|
|
|
|
if g_game.getFeature(GamePlayerMounts) then
|
|
|
|
mountButton:setVisible(true)
|
|
|
|
mountButton:setChecked(player:isMounted())
|
|
|
|
else
|
|
|
|
mountButton:setVisible(false)
|
|
|
|
end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
if g_game.getFeature(GamePVPMode) then
|
|
|
|
pvpModesPanel:setVisible(true)
|
|
|
|
combatControlsWindow:setHeight(combatControlsWindow.extendedControlsHeight)
|
|
|
|
else
|
|
|
|
pvpModesPanel:setVisible(false)
|
|
|
|
combatControlsWindow:setHeight(combatControlsWindow.simpleControlsHeight)
|
|
|
|
end
|
2012-07-12 18:45:22 +02:00
|
|
|
end
|
2012-07-13 01:40:55 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
update()
|
2012-06-07 13:52:17 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function offline()
|
2014-04-01 05:51:38 +02:00
|
|
|
local lastCombatControls = g_settings.getNode('LastCombatControls')
|
2012-08-17 07:31:23 +02:00
|
|
|
if not lastCombatControls then
|
2012-07-12 18:45:22 +02:00
|
|
|
lastCombatControls = {}
|
|
|
|
end
|
2012-07-13 01:40:55 +02:00
|
|
|
|
2012-07-12 18:45:22 +02:00
|
|
|
local player = g_game.getLocalPlayer()
|
2012-08-17 07:31:23 +02:00
|
|
|
if player then
|
2013-01-30 21:23:26 +01:00
|
|
|
local char = g_game.getCharacterName()
|
2012-07-12 18:45:22 +02:00
|
|
|
lastCombatControls[char] = {
|
|
|
|
fightMode = g_game.getFightMode(),
|
|
|
|
chaseMode = g_game.getChaseMode(),
|
|
|
|
safeFight = g_game.isSafeFight()
|
|
|
|
}
|
2012-07-13 01:40:55 +02:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
if g_game.getFeature(GamePVPMode) then
|
|
|
|
lastCombatControls[char].pvpMode = g_game.getPVPMode()
|
|
|
|
end
|
|
|
|
|
2012-07-12 18:45:22 +02:00
|
|
|
-- save last combat control settings
|
2014-04-01 05:51:38 +02:00
|
|
|
g_settings.setNode('LastCombatControls', lastCombatControls)
|
2012-07-12 18:45:22 +02:00
|
|
|
end
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
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
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
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
|
2012-08-17 07:31:23 +02:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
function onSetPVPMode(self, selectedPVPButton)
|
|
|
|
if selectedPVPButton == nil then
|
|
|
|
return
|
|
|
|
end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
local buttonId = selectedPVPButton:getId()
|
|
|
|
local pvpMode = PVPWhiteDove
|
|
|
|
if buttonId == 'whiteDoveBox' then
|
|
|
|
pvpMode = PVPWhiteDove
|
|
|
|
elseif buttonId == 'whiteHandBox' then
|
|
|
|
pvpMode = PVPWhiteHand
|
|
|
|
elseif buttonId == 'yellowHandBox' then
|
|
|
|
pvpMode = PVPYellowHand
|
|
|
|
elseif buttonId == 'redFistBox' then
|
|
|
|
pvpMode = PVPRedFist
|
|
|
|
end
|
2013-11-19 00:55:42 +01:00
|
|
|
|
|
|
|
g_game.setPVPMode(pvpMode)
|
2013-11-19 00:50:00 +01:00
|
|
|
end
|
|
|
|
|
2012-08-17 07:31:23 +02:00
|
|
|
function onMiniWindowClose()
|
|
|
|
combatControlsButton:setOn(false)
|
|
|
|
end
|
2013-11-19 00:50:00 +01:00
|
|
|
|
|
|
|
function onMountButtonClick(self, mousePos)
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if player then
|
|
|
|
player:toggleMount()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function onOutfitChange(localPlayer, outfit, oldOutfit)
|
|
|
|
if outfit.mount == oldOutfit.mount then
|
|
|
|
return
|
|
|
|
end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
mountButton:setChecked(outfit.mount ~= nil and outfit.mount > 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function getPVPBoxByMode(mode)
|
|
|
|
local widget = nil
|
|
|
|
if mode == PVPWhiteDove then
|
|
|
|
widget = whiteDoveBox
|
|
|
|
elseif mode == PVPWhiteHand then
|
|
|
|
widget = whiteHandBox
|
|
|
|
elseif mode == PVPYellowHand then
|
|
|
|
widget = yellowHandBox
|
|
|
|
elseif mode == PVPRedFist then
|
|
|
|
widget = redFistBox
|
|
|
|
end
|
|
|
|
return widget
|
|
|
|
end
|