From d0a5f27fcf09dff19d934a6949199e07f293b5e6 Mon Sep 17 00:00:00 2001 From: AndreFaramir Date: Thu, 9 Feb 2012 05:26:52 -0200 Subject: [PATCH] improving battle window and fixes --- modules/game/game.lua | 8 ++--- modules/game_battle/battle.lua | 47 +++++++++------------------ modules/game_battle/battleButton.otui | 18 +++++----- 3 files changed, 26 insertions(+), 47 deletions(-) diff --git a/modules/game/game.lua b/modules/game/game.lua index 7a0b9952..df89e434 100644 --- a/modules/game/game.lua +++ b/modules/game/game.lua @@ -27,12 +27,8 @@ local function onUseWithMouseRelease(self, mousePosition, mouseButton) end elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then g_game.useWith(g_game.selectedThing, clickedWidget:getItem()) - elseif clickedWidget.isBattleButton or clickedWidget.battleButtonChild then - local battleButton = clickedWidget - if clickedWidget.battleButtonChild then - battleButton = clickedWidget:getParent() - end - g_game.useWith(g_game.selectedThing, battleButton.creature) + elseif clickedWidget.isBattleButton then + g_game.useWith(g_game.selectedThing, clickedWidget.creature) end end end diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index e8c9517e..eaeebacb 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -52,9 +52,6 @@ function Battle.create() mouseWidget = createWidget('UIButton') mouseWidget:setVisible(false) mouseWidget:setFocusable(false) - - connect(UIWidget, { onHoverChange = Battle.onbattlePannelHoverChange, - onMouseRelease = Battle.onMouseRelease } ) connect(Creature, { onSkullChange = Battle.checkCreatureSkull, onEmblemChange = Battle.checkCreatureEmblem } ) @@ -83,9 +80,6 @@ function Battle.destroy() battleButton = nil battleWindow:destroy() battleWindow = nil - - disconnect(UIWidget, { onHoverChange = Battle.onbattlePannelHoverChange, - onMouseRelease = Battle.onMouseRelease } ) disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull, onEmblemChange = Battle.checkCreatureEmblem } ) @@ -252,13 +246,20 @@ end function Battle.onMouseRelease(self, mousePosition, mouseButton) if mouseButton == MouseRightButton then - local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition) - if clickedWidget then - if clickedWidget:getStyleName() == 'BattleButton' then - g_game.createThingMenu(mousePosition, nil, nil, clickedWidget.creature) - return true + g_game.createThingMenu(mousePosition, nil, nil, self.creature) + 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 + return true end end @@ -270,6 +271,7 @@ function Battle.removeCreature(creature) lastBattleButtonSwitched = nil end + battleButtonsByCreaturesList[creatureId].creature:hideStaticSquare() battleButtonsByCreaturesList[creatureId]:destroy() battleButtonsByCreaturesList[creatureId] = nil end @@ -290,27 +292,10 @@ function Battle.setLifeBarPercent(battleButton, percent) lifeBarWidget:setBackgroundColor(color) 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) - if widget.isBattleButton or widget.battleButtonChild then - local battleButton = widget - if widget.battleButtonChild then - battleButton = widget:getParent() - end - - if battleButton then - battleButton.isHovered = hovered - Battle.checkBattleButton(battleButton) - end + if widget.isBattleButton then + widget.isHovered = hovered + Battle.checkBattleButton(widget) end end diff --git a/modules/game_battle/battleButton.otui b/modules/game_battle/battleButton.otui index 838ce8e8..5e55f7bb 100644 --- a/modules/game_battle/battleButton.otui +++ b/modules/game_battle/battleButton.otui @@ -4,7 +4,8 @@ BattleButton height: 20 margin-top: 5 fixed-size: true - @onClick: Battle.onButtonClick(self) + &onHoverChange: Battle.onbattlePannelHoverChange + &onMouseRelease: Battle.onMouseRelease &isBattleButton: true UICreature @@ -12,29 +13,28 @@ BattleButton size: 20 20 anchors.left: parent.left anchors.top: parent.top - @onClick: Battle.onButtonClick(parent) - &battleButtonChild: true + phantom: true UIWidget id: spacer width: 5 anchors.left: creature.right anchors.top: creature.top - &battleButtonChild: true + phantom: true UIWidget id: skull height: 11 anchors.left: spacer.right anchors.top: spacer.top - &battleButtonChild: true + phantom: true UIWidget id: emblem height: 11 anchors.left: skull.right anchors.top: creature.top - &battleButtonChild: true + phantom: true LargerLabel id: label @@ -42,8 +42,7 @@ BattleButton anchors.top: creature.top color: #888888 margin-left: 2 - @onClick: Battle.onButtonClick(parent) - &battleButtonChild: true + phantom: true ProgressBar id: lifeBar @@ -52,5 +51,4 @@ BattleButton anchors.right: parent.right anchors.top: label.bottom margin-top: 2 - @onClick: Battle.onButtonClick(parent) - &battleButtonChild: true \ No newline at end of file + phantom: true \ No newline at end of file