mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 20:43:26 +02:00
Some more UI updates and fixes.
* Added UICreatureButton class for handling/replacing "battle buttons" (can now be used in other modules). * Added the ability to use items on creatures via the battle window. * Some minor cosmetics.
This commit is contained in:
@@ -12,20 +12,6 @@ hideMonstersButton = nil
|
||||
hideSkullsButton = nil
|
||||
hidePartyButton = nil
|
||||
|
||||
BattleButtonColors = {
|
||||
onIdle = {notHovered = '#888888', hovered = '#FFFFFF' },
|
||||
onTargeted = {notHovered = '#FF0000', hovered = '#FF8888' },
|
||||
onFollowed = {notHovered = '#00FF00', hovered = '#88FF88' }
|
||||
}
|
||||
|
||||
LifeBarColors = {} --Must be sorted by percentAbove
|
||||
table.insert(LifeBarColors, {percentAbove = 92, color = '#00BC00' } )
|
||||
table.insert(LifeBarColors, {percentAbove = 60, color = '#50A150' } )
|
||||
table.insert(LifeBarColors, {percentAbove = 30, color = '#A1A100' } )
|
||||
table.insert(LifeBarColors, {percentAbove = 8, color = '#3C2727' } )
|
||||
table.insert(LifeBarColors, {percentAbove = 3, color = '#3C0000' } )
|
||||
table.insert(LifeBarColors, {percentAbove = -1, color = '#4F0000' } )
|
||||
|
||||
function init()
|
||||
g_ui.importStyle('battlebutton.otui')
|
||||
battleButton = TopMenu.addRightGameToggleButton('battleButton', tr('Battle') .. ' (Ctrl+B)', 'battle.png', toggle)
|
||||
@@ -52,17 +38,20 @@ function init()
|
||||
battleWindow:setContentMinimumHeight(80)
|
||||
--battleWindow:setContentMaximumHeight(384)
|
||||
|
||||
connect(Creature, { onSkullChange = checkCreatureSkull,
|
||||
onEmblemChange = checkCreatureEmblem,
|
||||
onHealthPercentChange = onCreatureHealthPercentChange,
|
||||
onPositionChange = onCreaturePositionChange,
|
||||
onAppear = onCreatureAppear,
|
||||
onDisappear = onCreatureDisappear
|
||||
} )
|
||||
connect(Creature, {
|
||||
onSkullChange = updateCreatureSkull,
|
||||
onEmblemChange = updateCreatureEmblem,
|
||||
onHealthPercentChange = onCreatureHealthPercentChange,
|
||||
onPositionChange = onCreaturePositionChange,
|
||||
onAppear = onCreatureAppear,
|
||||
onDisappear = onCreatureDisappear
|
||||
})
|
||||
|
||||
connect(g_game, { onAttackingCreatureChange = onAttack,
|
||||
onFollowingCreatureChange = onFollow,
|
||||
onGameEnd = removeAllCreatures } )
|
||||
connect(g_game, {
|
||||
onAttackingCreatureChange = onAttack,
|
||||
onFollowingCreatureChange = onFollow,
|
||||
onGameEnd = removeAllCreatures
|
||||
})
|
||||
|
||||
checkCreatures()
|
||||
battleWindow:setup()
|
||||
@@ -75,17 +64,20 @@ function terminate()
|
||||
battleWindow:destroy()
|
||||
mouseWidget:destroy()
|
||||
|
||||
disconnect(Creature, { onSkullChange = checkCreatureSkull,
|
||||
onEmblemChange = checkCreatureEmblem,
|
||||
onHealthPercentChange = onCreatureHealthPercentChange,
|
||||
onPositionChange = onCreaturePositionChange,
|
||||
onAppear = onCreatureAppear,
|
||||
onDisappear = onCreatureDisappear
|
||||
} )
|
||||
disconnect(Creature, {
|
||||
onSkullChange = updateCreatureSkull,
|
||||
onEmblemChange = updateCreatureEmblem,
|
||||
onHealthPercentChange = onCreatureHealthPercentChange,
|
||||
onPositionChange = onCreaturePositionChange,
|
||||
onAppear = onCreatureAppear,
|
||||
onDisappear = onCreatureDisappear
|
||||
})
|
||||
|
||||
disconnect(g_game, { onAttackingCreatureChange = onAttack,
|
||||
onFollowingCreatureChange = onFollow,
|
||||
onGameEnd = removeAllCreatures } )
|
||||
disconnect(g_game, {
|
||||
onAttackingCreatureChange = onAttack,
|
||||
onFollowingCreatureChange = onFollow,
|
||||
onGameEnd = removeAllCreatures
|
||||
})
|
||||
end
|
||||
|
||||
function toggle()
|
||||
@@ -158,7 +150,7 @@ end
|
||||
function onCreatureHealthPercentChange(creature, health)
|
||||
local battleButton = battleButtonsByCreaturesList[creature:getId()]
|
||||
if battleButton then
|
||||
setLifeBarPercent(battleButton, creature:getHealthPercent())
|
||||
battleButton:setLifeBarPercent(creature:getHealthPercent())
|
||||
end
|
||||
end
|
||||
|
||||
@@ -193,32 +185,16 @@ end
|
||||
|
||||
function addCreature(creature)
|
||||
local creatureId = creature:getId()
|
||||
|
||||
local battleButton = battleButtonsByCreaturesList[creature:getId()]
|
||||
local battleButton = battleButtonsByCreaturesList[creatureId]
|
||||
if not battleButton then
|
||||
battleButton = g_ui.createWidget('BattleButton', battlePanel)
|
||||
local creatureWidget = battleButton:getChildById('creature')
|
||||
local labelWidget = battleButton:getChildById('label')
|
||||
local lifeBarWidget = battleButton:getChildById('lifeBar')
|
||||
battleButton:setup(creature)
|
||||
|
||||
battleButton.onHoverChange = onBattleButtonHoverChange
|
||||
battleButton.onMouseRelease = onMouseRelease
|
||||
|
||||
battleButton:setId('BattleButton_' .. creature:getName():gsub('%s','_'))
|
||||
battleButton.creatureId = creatureId
|
||||
battleButton.creature = creature
|
||||
battleButton.isHovered = false
|
||||
battleButton.isTarget = false
|
||||
battleButton.isFollowed = false
|
||||
|
||||
labelWidget:setText(creature:getName())
|
||||
creatureWidget:setCreature(creature)
|
||||
setLifeBarPercent(battleButton, creature:getHealthPercent())
|
||||
|
||||
battleButtonsByCreaturesList[creatureId] = battleButton
|
||||
|
||||
checkCreatureSkull(battleButton.creature)
|
||||
checkCreatureEmblem(battleButton.creature)
|
||||
|
||||
if creature == g_game.getAttackingCreature() then
|
||||
onAttack(creature)
|
||||
end
|
||||
@@ -227,52 +203,7 @@ function addCreature(creature)
|
||||
onFollow(creature)
|
||||
end
|
||||
else
|
||||
setLifeBarPercent(battleButton, creature:getHealthPercent())
|
||||
end
|
||||
end
|
||||
|
||||
function checkCreatureSkull(creature, skullId)
|
||||
local battleButton = battleButtonsByCreaturesList[creature:getId()]
|
||||
if battleButton then
|
||||
local skullWidget = battleButton:getChildById('skull')
|
||||
local labelWidget = battleButton:getChildById('label')
|
||||
local creature = battleButton.creature
|
||||
|
||||
if creature:getSkull() ~= SkullNone then
|
||||
skullWidget:setWidth(skullWidget:getHeight())
|
||||
local imagePath = getSkullImagePath(creature:getSkull())
|
||||
skullWidget:setImageSource(imagePath)
|
||||
labelWidget:setMarginLeft(5)
|
||||
else
|
||||
skullWidget:setWidth(0)
|
||||
if creature:getEmblem() == EmblemNone then
|
||||
labelWidget:setMarginLeft(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function checkCreatureEmblem(creature, emblemId)
|
||||
local battleButton = battleButtonsByCreaturesList[creature:getId()]
|
||||
if battleButton then
|
||||
local emblemId = emblemId or creature:getEmblem()
|
||||
local emblemWidget = battleButton:getChildById('emblem')
|
||||
local labelWidget = battleButton:getChildById('label')
|
||||
local creature = battleButton.creature
|
||||
|
||||
if emblemId ~= EmblemNone then
|
||||
emblemWidget:setWidth(emblemWidget:getHeight())
|
||||
local imagePath = getEmblemImagePath(emblemId)
|
||||
emblemWidget:setImageSource(imagePath)
|
||||
emblemWidget:setMarginLeft(5)
|
||||
labelWidget:setMarginLeft(5)
|
||||
else
|
||||
emblemWidget:setWidth(0)
|
||||
emblemWidget:setMarginLeft(0)
|
||||
if creature:getSkull() == SkullNone then
|
||||
labelWidget:setMarginLeft(2)
|
||||
end
|
||||
end
|
||||
battleButton:setLifeBarPercent(creature:getHealthPercent())
|
||||
end
|
||||
end
|
||||
|
||||
@@ -314,25 +245,10 @@ function removeCreature(creature)
|
||||
end
|
||||
end
|
||||
|
||||
function setLifeBarPercent(battleButton, percent)
|
||||
local lifeBarWidget = battleButton:getChildById('lifeBar')
|
||||
lifeBarWidget:setPercent(percent)
|
||||
|
||||
local color
|
||||
for i, v in pairs(LifeBarColors) do
|
||||
if percent > v.percentAbove then
|
||||
color = v.color
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
lifeBarWidget:setBackgroundColor(color)
|
||||
end
|
||||
|
||||
function onBattleButtonHoverChange(widget, hovered)
|
||||
if widget.isBattleButton then
|
||||
widget.isHovered = hovered
|
||||
checkBattleButton(widget)
|
||||
updateBattleButton(widget)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -340,7 +256,7 @@ function onAttack(creature)
|
||||
local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
|
||||
if battleButton then
|
||||
battleButton.isTarget = creature and true or false
|
||||
checkBattleButton(battleButton)
|
||||
updateBattleButton(battleButton)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -348,37 +264,32 @@ function onFollow(creature)
|
||||
local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
|
||||
if battleButton then
|
||||
battleButton.isFollowed = creature and true or false
|
||||
checkBattleButton(battleButton)
|
||||
updateBattleButton(battleButton)
|
||||
end
|
||||
end
|
||||
|
||||
function checkBattleButton(battleButton)
|
||||
local color = BattleButtonColors.onIdle
|
||||
if battleButton.isTarget then
|
||||
color = BattleButtonColors.onTargeted
|
||||
elseif battleButton.isFollowed then
|
||||
color = BattleButtonColors.onFollowed
|
||||
function updateCreatureSkull(creature, skullId)
|
||||
local battleButton = battleButtonsByCreaturesList[creature:getId()]
|
||||
if battleButton then
|
||||
battleButton:updateSkull(skullId)
|
||||
end
|
||||
end
|
||||
|
||||
color = battleButton.isHovered and color.hovered or color.notHovered
|
||||
|
||||
if battleButton.isHovered or battleButton.isTarget or battleButton.isFollowed then
|
||||
battleButton.creature:showStaticSquare(color)
|
||||
battleButton:getChildById('creature'):setBorderWidth(1)
|
||||
battleButton:getChildById('creature'):setBorderColor(color)
|
||||
battleButton:getChildById('label'):setColor(color)
|
||||
else
|
||||
battleButton.creature:hideStaticSquare()
|
||||
battleButton:getChildById('creature'):setBorderWidth(0)
|
||||
battleButton:getChildById('label'):setColor(color)
|
||||
function updateCreatureEmblem(creature, emblemId)
|
||||
local battleButton = battleButtonsByCreaturesList[creature:getId()]
|
||||
if battleButton then
|
||||
battleButton:updateSkull(emblemId)
|
||||
end
|
||||
end
|
||||
|
||||
function updateBattleButton(battleButton)
|
||||
battleButton:update()
|
||||
if battleButton.isTarget or battleButton.isFollowed then
|
||||
-- set new last battle button switched
|
||||
if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then
|
||||
lastBattleButtonSwitched.isTarget = false
|
||||
lastBattleButtonSwitched.isFollowed = false
|
||||
checkBattleButton(lastBattleButtonSwitched)
|
||||
updateBattleButton(lastBattleButtonSwitched)
|
||||
end
|
||||
lastBattleButtonSwitched = battleButton
|
||||
end
|
||||
|
@@ -1,49 +1,2 @@
|
||||
BattleButton < UIButton
|
||||
height: 20
|
||||
margin-bottom: 5
|
||||
&isBattleButton: true
|
||||
|
||||
UICreature
|
||||
id: creature
|
||||
size: 20 20
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
phantom: true
|
||||
|
||||
UIWidget
|
||||
id: spacer
|
||||
width: 5
|
||||
anchors.left: creature.right
|
||||
anchors.top: creature.top
|
||||
phantom: true
|
||||
|
||||
UIWidget
|
||||
id: skull
|
||||
height: 11
|
||||
anchors.left: spacer.right
|
||||
anchors.top: spacer.top
|
||||
phantom: true
|
||||
|
||||
UIWidget
|
||||
id: emblem
|
||||
height: 11
|
||||
anchors.left: skull.right
|
||||
anchors.top: creature.top
|
||||
phantom: true
|
||||
|
||||
Label
|
||||
id: label
|
||||
anchors.left: emblem.right
|
||||
anchors.top: creature.top
|
||||
color: #888888
|
||||
margin-left: 2
|
||||
phantom: true
|
||||
|
||||
ProgressBar
|
||||
id: lifeBar
|
||||
height: 5
|
||||
anchors.left: spacer.right
|
||||
anchors.right: parent.right
|
||||
anchors.top: label.bottom
|
||||
margin-top: 2
|
||||
phantom: true
|
||||
BattleButton < CreatureButton
|
||||
&isBattleButton: true
|
Reference in New Issue
Block a user