New pvp modes to combat controls

This commit is contained in:
Sam
2013-11-19 00:50:00 +01:00
parent c98439ae65
commit 4d656f8bd1
15 changed files with 210 additions and 25 deletions

View File

@@ -5,7 +5,14 @@ fightBalancedBox = nil
fightDefensiveBox = nil
chaseModeButton = nil
safeFightButton = nil
whiteDoveBox = nil
whiteHandBox = nil
yellowHandBox = nil
redFistBox = nil
mountButton = nil
pvpModesPanel = nil
fightModeRadioGroup = nil
pvpModeRadioGroup = nil
function init()
combatControlsButton = modules.client_topmenu.addRightGameToggleButton('combatControlsButton', tr('Combat Controls'), '/images/topbuttons/combatcontrols', toggle)
@@ -16,15 +23,33 @@ function init()
fightOffensiveBox = combatControlsWindow:recursiveGetChildById('fightOffensiveBox')
fightBalancedBox = combatControlsWindow:recursiveGetChildById('fightBalancedBox')
fightDefensiveBox = combatControlsWindow:recursiveGetChildById('fightDefensiveBox')
chaseModeButton = combatControlsWindow:recursiveGetChildById('chaseModeBox')
safeFightButton = combatControlsWindow:recursiveGetChildById('safeFightBox')
mountButton = combatControlsWindow:recursiveGetChildById('mountButton')
mountButton.onClick = onMountButtonClick
pvpModesPanel = combatControlsWindow:recursiveGetChildById('pvpModesPanel')
whiteDoveBox = combatControlsWindow:recursiveGetChildById('whiteDoveBox')
whiteHandBox = combatControlsWindow:recursiveGetChildById('whiteHandBox')
yellowHandBox = combatControlsWindow:recursiveGetChildById('yellowHandBox')
redFistBox = combatControlsWindow:recursiveGetChildById('redFistBox')
fightModeRadioGroup = UIRadioGroup.create()
fightModeRadioGroup:addWidget(fightOffensiveBox)
fightModeRadioGroup:addWidget(fightBalancedBox)
fightModeRadioGroup:addWidget(fightDefensiveBox)
pvpModeRadioGroup = UIRadioGroup.create()
pvpModeRadioGroup:addWidget(whiteDoveBox)
pvpModeRadioGroup:addWidget(whiteHandBox)
pvpModeRadioGroup:addWidget(yellowHandBox)
pvpModeRadioGroup:addWidget(redFistBox)
connect(fightModeRadioGroup, { onSelectionChange = onSetFightMode })
connect(pvpModeRadioGroup, { onSelectionChange = onSetPVPMode })
connect(chaseModeButton, { onCheckChange = onSetChaseMode })
connect(safeFightButton, { onCheckChange = onSetSafeFight })
connect(g_game, {
@@ -33,9 +58,12 @@ function init()
onFightModeChange = update,
onChaseModeChange = update,
onSafeFightChange = update,
onPVPModeChange = update,
onWalk = check,
onAutoWalk = check
})
connect(LocalPlayer, { onOutfitChange = onOutfitChange })
if g_game.isOnline() then
online()
@@ -50,6 +78,7 @@ function terminate()
end
fightModeRadioGroup:destroy()
pvpModeRadioGroup:destroy()
combatControlsWindow:destroy()
combatControlsButton:destroy()
@@ -59,9 +88,12 @@ function terminate()
onFightModeChange = update,
onChaseModeChange = update,
onSafeFightChange = update,
onPVPModeChange = update,
onWalk = check,
onAutoWalk = check
})
disconnect(LocalPlayer, { onOutfitChange = onOutfitChange })
end
function update()
@@ -79,6 +111,14 @@ function update()
local safeFight = g_game.isSafeFight()
safeFightButton:setChecked(not safeFight)
if g_game.getFeature(GamePVPMode) then
local pvpMode = g_game.getPVPMode()
local pvpWidget = getPVPBoxByMode(pvpMode)
if pvpWidget then
pvpModeRadioGroup:selectWidget(pvpWidget)
end
end
end
function check()
@@ -101,8 +141,26 @@ function online()
g_game.setFightMode(lastCombatControls[char].fightMode)
g_game.setChaseMode(lastCombatControls[char].chaseMode)
g_game.setSafeFight(lastCombatControls[char].safeFight)
if g_game.getFeature(GamePVPMode) and lastCombatControls[char].pvpMode then
g_game.setPVPMode(lastCombatControls[char].pvpMode)
end
end
end
if g_game.getFeature(GamePlayerMounts) then
mountButton:setVisible(true)
mountButton:setChecked(player:isMounted())
else
mountButton:setVisible(false)
end
if g_game.getFeature(GamePVPMode) then
pvpModesPanel:setVisible(true)
combatControlsWindow:setHeight(combatControlsWindow.extendedControlsHeight)
else
pvpModesPanel:setVisible(false)
combatControlsWindow:setHeight(combatControlsWindow.simpleControlsHeight)
end
end
update()
@@ -123,6 +181,10 @@ function offline()
safeFight = g_game.isSafeFight()
}
if g_game.getFeature(GamePVPMode) then
lastCombatControls[char].pvpMode = g_game.getPVPMode()
end
-- save last combat control settings
g_settings.setNode('LastCombatControls', lastCombatControls)
end
@@ -166,6 +228,57 @@ function onSetSafeFight(self, checked)
g_game.setSafeFight(not checked)
end
function onSetPVPMode(self, selectedPVPButton)
if selectedPVPButton == nil then
return
end
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
if g_game.getFeature(GamePVPMode) then
g_game.setPVPMode(pvpMode)
end
end
function onMiniWindowClose()
combatControlsButton:setOn(false)
end
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
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

View File

@@ -1,12 +1,7 @@
CombatBox < UICheckBox
size: 20 20
image-clip: 0 0 20 20
anchors.top: parent.top
margin: 0 4
$first:
margin: 0 1
$last:
margin: 0 1
margin: 2 4
$checked:
image-clip: 0 20 20 20
@@ -21,33 +16,78 @@ ChaseModeBox < CombatBox
image-source: /images/game/combatmodes/chasemode
SafeFightBox < CombatBox
image-source: /images/game/combatmodes/safefight
MountButton < CombatBox
image-source: /images/game/combatmodes/mount
WhiteDoveBox < CombatBox
image-source: /images/game/combatmodes/whitedovemode
WhiteHandBox < CombatBox
image-source: /images/game/combatmodes/whitehandmode
YellowHandBox < CombatBox
image-source: /images/game/combatmodes/yellowhandmode
RedFistBox < CombatBox
image-source: /images/game/combatmodes/redfistmode
MiniWindow
id: combatControlsWindow
!text: tr('Combat Controls')
icon: /images/topbuttons/combatcontrols
height: 48
height: 49
&save: true
&simpleControlsHeight: 49
&extendedControlsHeight: 72
@onClose: modules.game_combatcontrols.onMiniWindowClose()
MiniWindowContents
FightOffensiveBox
id: fightOffensiveBox
anchors.top: parent.top
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
margin: 2 1
FightBalancedBox
id: fightBalancedBox
anchors.top: parent.top
anchors.left: prev.right
anchors.verticalCenter: parent.verticalCenter
FightDefensiveBox
id: fightDefensiveBox
anchors.top: parent.top
anchors.left: prev.right
anchors.verticalCenter: parent.verticalCenter
MountButton
id: mountButton
anchors.top: parent.top
anchors.right: next.left
ChaseModeBox
id: chaseModeBox
anchors.top: parent.top
anchors.right: next.left
anchors.verticalCenter: parent.verticalCenter
SafeFightBox
id: safeFightBox
anchors.top: parent.top
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
margin: 2 1
Panel
id: pvpModesPanel
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 20
WhiteDoveBox
id: whiteDoveBox
anchors.left: parent.left
anchors.bottom: parent.bottom
margin: 2 1
WhiteHandBox
id: whiteHandBox
anchors.left: prev.right
anchors.bottom: parent.bottom
YellowHandBox
id: yellowHandBox
anchors.left: prev.right
anchors.bottom: parent.bottom
RedFistBox
id: redFistBox
anchors.left: prev.right
anchors.bottom: parent.bottom

View File

@@ -47,6 +47,11 @@ FightDefensive = 3
DontChase = 0
ChaseOpponent = 1
PVPWhiteDove = 0
PVPWhiteHand = 1
PVPYellowHand = 2
PVPRedFist = 3
GameProtocolChecksum = 1
GameAccountNames = 2
GameChallengeOnLogin = 3
@@ -94,6 +99,7 @@ GameMesssageLevel = 46
GameNewFluids = 47
GamePlayerStateU16 = 48
GameNewOutfitProtocol = 49
GamePVPMode = 50
TextColors = {
red = '#f55e5e', --'#c83200'