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:
parent
f93d79649f
commit
0763b266d5
|
@ -12,6 +12,7 @@ local skin = {
|
|||
|
||||
styles = {
|
||||
'buttons.otui',
|
||||
'creaturebuttons.otui',
|
||||
'labels.otui',
|
||||
'panels.otui',
|
||||
'separators.otui',
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
CreatureButton < UICreatureButton
|
||||
height: 20
|
||||
margin-bottom: 5
|
||||
|
||||
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
|
|
@ -0,0 +1,140 @@
|
|||
-- @docclass
|
||||
UICreatureButton = extends(UIWidget)
|
||||
|
||||
local CreatureButtonColors = {
|
||||
onIdle = {notHovered = '#888888', hovered = '#FFFFFF' },
|
||||
onTargeted = {notHovered = '#FF0000', hovered = '#FF8888' },
|
||||
onFollowed = {notHovered = '#00FF00', hovered = '#88FF88' }
|
||||
}
|
||||
|
||||
local 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 UICreatureButton.create()
|
||||
local button = UICreatureButton.internalCreate()
|
||||
button:setFocusable(false)
|
||||
button.creature = nil
|
||||
button.isHovered = false
|
||||
button.isTarget = false
|
||||
button.isFollowed = false
|
||||
return button
|
||||
end
|
||||
|
||||
function UICreatureButton:getClassName()
|
||||
return 'UICreatureButton'
|
||||
end
|
||||
|
||||
function UICreatureButton:setCreature(creature)
|
||||
self.creature = creature
|
||||
end
|
||||
|
||||
function UICreatureButton:getCreature()
|
||||
return self.creature
|
||||
end
|
||||
|
||||
function UICreatureButton:getCreatureId()
|
||||
return self.creature:getId()
|
||||
end
|
||||
|
||||
function UICreatureButton:setup(creature)
|
||||
self.creature = creature
|
||||
|
||||
local creatureWidget = self:getChildById('creature')
|
||||
local labelWidget = self:getChildById('label')
|
||||
local lifeBarWidget = self:getChildById('lifeBar')
|
||||
|
||||
labelWidget:setText(creature:getName())
|
||||
creatureWidget:setCreature(creature)
|
||||
|
||||
self:setId('CreatureButton_' .. creature:getName():gsub('%s','_'))
|
||||
self:setLifeBarPercent(creature:getHealthPercent())
|
||||
|
||||
self:updateSkull(creature:getSkull())
|
||||
self:updateEmblem(creature:getEmblem())
|
||||
end
|
||||
|
||||
function UICreatureButton:update()
|
||||
local color = CreatureButtonColors.onIdle
|
||||
if self.isTarget then
|
||||
color = CreatureButtonColors.onTargeted
|
||||
elseif self.isFollowed then
|
||||
color = CreatureButtonColors.onFollowed
|
||||
end
|
||||
color = self.isHovered and color.hovered or color.notHovered
|
||||
|
||||
if self.isHovered or self.isTarget or self.isFollowed then
|
||||
self.creature:showStaticSquare(color)
|
||||
self:getChildById('creature'):setBorderWidth(1)
|
||||
self:getChildById('creature'):setBorderColor(color)
|
||||
self:getChildById('label'):setColor(color)
|
||||
else
|
||||
self.creature:hideStaticSquare()
|
||||
self:getChildById('creature'):setBorderWidth(0)
|
||||
self:getChildById('label'):setColor(color)
|
||||
end
|
||||
end
|
||||
|
||||
function UICreatureButton:updateSkull(skullId)
|
||||
if not self.creature then
|
||||
return
|
||||
end
|
||||
local skullId = skullId or self.creature:getSkull()
|
||||
local skullWidget = self:getChildById('skull')
|
||||
local labelWidget = self:getChildById('label')
|
||||
|
||||
if skullId ~= SkullNone then
|
||||
skullWidget:setWidth(skullWidget:getHeight())
|
||||
print(skullId)
|
||||
local imagePath = getSkullImagePath(skullId)
|
||||
skullWidget:setImageSource(imagePath)
|
||||
labelWidget:setMarginLeft(5)
|
||||
else
|
||||
skullWidget:setWidth(0)
|
||||
if self.creature:getEmblem() == EmblemNone then
|
||||
labelWidget:setMarginLeft(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UICreatureButton:updateEmblem(emblemId)
|
||||
if not self.creature then
|
||||
return
|
||||
end
|
||||
local emblemId = emblemId or self.creature:getEmblem()
|
||||
local emblemWidget = self:getChildById('emblem')
|
||||
local labelWidget = self:getChildById('label')
|
||||
|
||||
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 self.creature:getSkull() == SkullNone then
|
||||
labelWidget:setMarginLeft(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UICreatureButton:setLifeBarPercent(percent)
|
||||
local lifeBarWidget = self: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
|
|
@ -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,
|
||||
connect(Creature, {
|
||||
onSkullChange = updateCreatureSkull,
|
||||
onEmblemChange = updateCreatureEmblem,
|
||||
onHealthPercentChange = onCreatureHealthPercentChange,
|
||||
onPositionChange = onCreaturePositionChange,
|
||||
onAppear = onCreatureAppear,
|
||||
onDisappear = onCreatureDisappear
|
||||
})
|
||||
|
||||
connect(g_game, { onAttackingCreatureChange = onAttack,
|
||||
connect(g_game, {
|
||||
onAttackingCreatureChange = onAttack,
|
||||
onFollowingCreatureChange = onFollow,
|
||||
onGameEnd = removeAllCreatures } )
|
||||
onGameEnd = removeAllCreatures
|
||||
})
|
||||
|
||||
checkCreatures()
|
||||
battleWindow:setup()
|
||||
|
@ -75,17 +64,20 @@ function terminate()
|
|||
battleWindow:destroy()
|
||||
mouseWidget:destroy()
|
||||
|
||||
disconnect(Creature, { onSkullChange = checkCreatureSkull,
|
||||
onEmblemChange = checkCreatureEmblem,
|
||||
disconnect(Creature, {
|
||||
onSkullChange = updateCreatureSkull,
|
||||
onEmblemChange = updateCreatureEmblem,
|
||||
onHealthPercentChange = onCreatureHealthPercentChange,
|
||||
onPositionChange = onCreaturePositionChange,
|
||||
onAppear = onCreatureAppear,
|
||||
onDisappear = onCreatureDisappear
|
||||
})
|
||||
|
||||
disconnect(g_game, { onAttackingCreatureChange = onAttack,
|
||||
disconnect(g_game, {
|
||||
onAttackingCreatureChange = onAttack,
|
||||
onFollowingCreatureChange = onFollow,
|
||||
onGameEnd = removeAllCreatures } )
|
||||
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
|
||||
BattleButton < CreatureButton
|
||||
&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
|
||||
|
|
|
@ -182,6 +182,11 @@ function onUseWith(clickedWidget, mousePosition)
|
|||
end
|
||||
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
||||
g_game.useWith(selectedThing, clickedWidget:getItem())
|
||||
elseif clickedWidget:getClassName() == 'UICreatureButton' then
|
||||
local creature = clickedWidget:getCreature()
|
||||
if creature then
|
||||
g_game.useWith(selectedThing, creature)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -154,6 +154,11 @@ local function clearFilters()
|
|||
end
|
||||
end
|
||||
|
||||
local function clearFee()
|
||||
feeLabel:setText('')
|
||||
fee = 0
|
||||
end
|
||||
|
||||
local function refreshTypeList()
|
||||
offerTypeList:clearOptions()
|
||||
offerTypeList:addOption('Buy')
|
||||
|
@ -165,11 +170,6 @@ local function refreshTypeList()
|
|||
end
|
||||
end
|
||||
|
||||
local function refreshFee()
|
||||
feeLabel:setText('')
|
||||
fee = 0
|
||||
end
|
||||
|
||||
local function addOffer(offer, type)
|
||||
if not offer then
|
||||
return false
|
||||
|
@ -841,7 +841,7 @@ function Market.resetCreateOffer()
|
|||
totalPriceEdit:setValue(1)
|
||||
amountEdit:setValue(1)
|
||||
refreshTypeList()
|
||||
refreshFee()
|
||||
clearFee()
|
||||
end
|
||||
|
||||
function Market.refreshItemsWidget(selectItem)
|
||||
|
|
|
@ -64,14 +64,14 @@ TexturePtr TextureManager::getTexture(const std::string& fileName)
|
|||
try {
|
||||
// currently only png textures are supported
|
||||
if(!stdext::ends_with(filePath, ".png"))
|
||||
stdext::throw_exception("texture file format no supported");
|
||||
stdext::throw_exception("texture file format not supported");
|
||||
|
||||
// load texture file data
|
||||
std::stringstream fin;
|
||||
g_resources.loadFile(filePath, fin);
|
||||
texture = loadPNG(fin);
|
||||
} catch(stdext::exception& e) {
|
||||
g_logger.error(stdext::format("unable to load texture '%s': %s", fileName, e.what()));
|
||||
g_logger.error(stdext::format("Unable to load texture '%s': %s", fileName, e.what()));
|
||||
texture = g_textures.getEmptyTexture();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue