improving battle window and fixes

This commit is contained in:
AndreFaramir 2012-02-09 05:26:52 -02:00
parent c707f990bf
commit d0a5f27fcf
3 changed files with 26 additions and 47 deletions

View File

@ -27,12 +27,8 @@ local function onUseWithMouseRelease(self, mousePosition, mouseButton)
end end
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(g_game.selectedThing, clickedWidget:getItem()) g_game.useWith(g_game.selectedThing, clickedWidget:getItem())
elseif clickedWidget.isBattleButton or clickedWidget.battleButtonChild then elseif clickedWidget.isBattleButton then
local battleButton = clickedWidget g_game.useWith(g_game.selectedThing, clickedWidget.creature)
if clickedWidget.battleButtonChild then
battleButton = clickedWidget:getParent()
end
g_game.useWith(g_game.selectedThing, battleButton.creature)
end end
end end
end end

View File

@ -53,9 +53,6 @@ function Battle.create()
mouseWidget:setVisible(false) mouseWidget:setVisible(false)
mouseWidget:setFocusable(false) mouseWidget:setFocusable(false)
connect(UIWidget, { onHoverChange = Battle.onbattlePannelHoverChange,
onMouseRelease = Battle.onMouseRelease } )
connect(Creature, { onSkullChange = Battle.checkCreatureSkull, connect(Creature, { onSkullChange = Battle.checkCreatureSkull,
onEmblemChange = Battle.checkCreatureEmblem } ) onEmblemChange = Battle.checkCreatureEmblem } )
@ -84,9 +81,6 @@ function Battle.destroy()
battleWindow:destroy() battleWindow:destroy()
battleWindow = nil battleWindow = nil
disconnect(UIWidget, { onHoverChange = Battle.onbattlePannelHoverChange,
onMouseRelease = Battle.onMouseRelease } )
disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull, disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull,
onEmblemChange = Battle.checkCreatureEmblem } ) onEmblemChange = Battle.checkCreatureEmblem } )
@ -252,13 +246,20 @@ end
function Battle.onMouseRelease(self, mousePosition, mouseButton) function Battle.onMouseRelease(self, mousePosition, mouseButton)
if mouseButton == MouseRightButton then if mouseButton == MouseRightButton then
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition) g_game.createThingMenu(mousePosition, nil, nil, self.creature)
if clickedWidget then
if clickedWidget:getStyleName() == 'BattleButton' then
g_game.createThingMenu(mousePosition, nil, nil, clickedWidget.creature)
return true return true
elseif mouseButton == MouseLeftButton then
local modifiers = g_window.getKeyboardModifiers()
if modifiers == KeyboardShiftModifier then
g_game.look(self.creature)
else
if self.isTarget then
g_game.cancelAttack()
else
g_game.attack(self.creature)
end end
end end
return true
end end
end end
@ -270,6 +271,7 @@ function Battle.removeCreature(creature)
lastBattleButtonSwitched = nil lastBattleButtonSwitched = nil
end end
battleButtonsByCreaturesList[creatureId].creature:hideStaticSquare()
battleButtonsByCreaturesList[creatureId]:destroy() battleButtonsByCreaturesList[creatureId]:destroy()
battleButtonsByCreaturesList[creatureId] = nil battleButtonsByCreaturesList[creatureId] = nil
end end
@ -290,27 +292,10 @@ function Battle.setLifeBarPercent(battleButton, percent)
lifeBarWidget:setBackgroundColor(color) lifeBarWidget:setBackgroundColor(color)
end end
function Battle.onButtonClick(battleButton)
if battleButton then
if battleButton.isTarget then
g_game.cancelAttack()
else
g_game.attack(battleButton.creature)
end
end
end
function Battle.onbattlePannelHoverChange(widget, hovered) function Battle.onbattlePannelHoverChange(widget, hovered)
if widget.isBattleButton or widget.battleButtonChild then if widget.isBattleButton then
local battleButton = widget widget.isHovered = hovered
if widget.battleButtonChild then Battle.checkBattleButton(widget)
battleButton = widget:getParent()
end
if battleButton then
battleButton.isHovered = hovered
Battle.checkBattleButton(battleButton)
end
end end
end end

View File

@ -4,7 +4,8 @@ BattleButton
height: 20 height: 20
margin-top: 5 margin-top: 5
fixed-size: true fixed-size: true
@onClick: Battle.onButtonClick(self) &onHoverChange: Battle.onbattlePannelHoverChange
&onMouseRelease: Battle.onMouseRelease
&isBattleButton: true &isBattleButton: true
UICreature UICreature
@ -12,29 +13,28 @@ BattleButton
size: 20 20 size: 20 20
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
@onClick: Battle.onButtonClick(parent) phantom: true
&battleButtonChild: true
UIWidget UIWidget
id: spacer id: spacer
width: 5 width: 5
anchors.left: creature.right anchors.left: creature.right
anchors.top: creature.top anchors.top: creature.top
&battleButtonChild: true phantom: true
UIWidget UIWidget
id: skull id: skull
height: 11 height: 11
anchors.left: spacer.right anchors.left: spacer.right
anchors.top: spacer.top anchors.top: spacer.top
&battleButtonChild: true phantom: true
UIWidget UIWidget
id: emblem id: emblem
height: 11 height: 11
anchors.left: skull.right anchors.left: skull.right
anchors.top: creature.top anchors.top: creature.top
&battleButtonChild: true phantom: true
LargerLabel LargerLabel
id: label id: label
@ -42,8 +42,7 @@ BattleButton
anchors.top: creature.top anchors.top: creature.top
color: #888888 color: #888888
margin-left: 2 margin-left: 2
@onClick: Battle.onButtonClick(parent) phantom: true
&battleButtonChild: true
ProgressBar ProgressBar
id: lifeBar id: lifeBar
@ -52,5 +51,4 @@ BattleButton
anchors.right: parent.right anchors.right: parent.right
anchors.top: label.bottom anchors.top: label.bottom
margin-top: 2 margin-top: 2
@onClick: Battle.onButtonClick(parent) phantom: true
&battleButtonChild: true