From 1074b6b7876af9dfc1058844a2f732c3e22d0715 Mon Sep 17 00:00:00 2001 From: BenDol Date: Thu, 3 Apr 2014 05:20:35 +1300 Subject: [PATCH] Provide the option to suppress lua call in setText --- modules/game_cooldown/cooldown.lua | 18 ++++++++++++++---- modules/gamelib/spells.lua | 5 ++++- src/framework/ui/uiwidget.h | 2 +- src/framework/ui/uiwidgettext.cpp | 7 +++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/game_cooldown/cooldown.lua b/modules/game_cooldown/cooldown.lua index f583967d..c126f3fc 100644 --- a/modules/game_cooldown/cooldown.lua +++ b/modules/game_cooldown/cooldown.lua @@ -14,7 +14,8 @@ function init() onSpellGroupCooldown = onSpellGroupCooldown, onSpellCooldown = onSpellCooldown }) - cooldownButton = modules.client_topmenu.addRightGameToggleButton('cooldownButton', tr('Cooldowns'), '/images/topbuttons/cooldowns', toggle) + cooldownButton = modules.client_topmenu.addRightGameToggleButton('cooldownButton', + tr('Cooldowns'), '/images/topbuttons/cooldowns', toggle) cooldownButton:setOn(true) cooldownButton:hide() @@ -47,6 +48,7 @@ end function loadIcon(iconId) local spell, profile, spellName = Spells.getSpellByIcon(iconId) if not spellName then return end + if not profile then return end clientIconId = Spells.getClientId(spellName) if not clientIconId then return end @@ -57,8 +59,13 @@ function loadIcon(iconId) icon:setId(iconId) end - icon:setImageSource(SpelllistSettings[profile].iconFile) - icon:setImageClip(Spells.getImageClip(clientIconId, profile)) + local spellSettings = SpelllistSettings[profile] + if spellSettings then + icon:setImageSource(spellSettings.iconFile) + icon:setImageClip(Spells.getImageClip(clientIconId, profile)) + else + icon = nil + end return icon end @@ -133,7 +140,10 @@ function updateCooldown(progressRect, duration) if progressRect:getPercent() < 100 then removeEvent(progressRect.event) - progressRect.event = scheduleEvent(function() progressRect.callback[ProgressCallback.update]() end, 100) + + progressRect.event = scheduleEvent(function() + progressRect.callback[ProgressCallback.update]() + end, 100) else progressRect.callback[ProgressCallback.finish]() end diff --git a/modules/gamelib/spells.lua b/modules/gamelib/spells.lua index 74adff2e..223ff32e 100644 --- a/modules/gamelib/spells.lua +++ b/modules/gamelib/spells.lua @@ -403,5 +403,8 @@ function Spells.getSpellProfileByName(spellName) end function Spells.getImageClip(id, profile) - return (((id-1)%12)*SpelllistSettings[profile].iconSize.width) .. ' ' .. ((math.ceil(id/12)-1)*SpelllistSettings[profile].iconSize.height) .. ' ' .. SpelllistSettings[profile].iconSize.width .. ' ' .. SpelllistSettings[profile].iconSize.height + return (((id-1)%12)*SpelllistSettings[profile].iconSize.width) .. ' ' + .. ((math.ceil(id/12)-1)*SpelllistSettings[profile].iconSize.height) .. ' ' + .. SpelllistSettings[profile].iconSize.width .. ' ' + .. SpelllistSettings[profile].iconSize.height end \ No newline at end of file diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index c6af53ee..c0228faa 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -492,7 +492,7 @@ public: void resizeToText() { setSize(getTextSize()); } void clearText() { setText(""); } - void setText(std::string text); + void setText(std::string text, bool fireLuaCall = true); void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; updateText(); } void setTextOffset(const Point& offset) { m_textOffset = offset; updateText(); } void setTextWrap(bool textWrap) { m_textWrap = textWrap; updateText(); } diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index 80eee5dc..b9569323 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -112,7 +112,7 @@ void UIWidget::onFontChange(const std::string& font) callLuaField("onFontChange", font); } -void UIWidget::setText(std::string text) +void UIWidget::setText(std::string text, bool fireLuaCall) { if(m_textOnlyUpperCase) stdext::toupper(text); @@ -125,7 +125,10 @@ void UIWidget::setText(std::string text) updateText(); text = m_text; - onTextChange(text, oldText); + + if(fireLuaCall) { + onTextChange(text, oldText); + } } void UIWidget::setFont(const std::string& fontName)