diff --git a/ryzom/client/src/interface_v3/dbctrl_sheet.cpp b/ryzom/client/src/interface_v3/dbctrl_sheet.cpp index f1f3a650e..70efd1f59 100644 --- a/ryzom/client/src/interface_v3/dbctrl_sheet.cpp +++ b/ryzom/client/src/interface_v3/dbctrl_sheet.cpp @@ -569,6 +569,7 @@ CCtrlDraggable(param) _RegenTextEnabled = true; _RegenTextShadow = true; _RegenTextOutline = false; + _RegenTextFctLua = false; _RegenTextY = 2; _RegenTextFontSize = 8; _RegenTextColor = NLMISC::CRGBA::White; @@ -694,6 +695,8 @@ bool CDBCtrlSheet::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) XML_READ_COLOR(cur, "regen_text_color", _RegenTextColor, NLMISC::CRGBA::White); XML_READ_COLOR(cur, "regen_text_shadow_color", _RegenTextShadowColor, NLMISC::CRGBA::Black); XML_READ_COLOR(cur, "regen_text_outline_color", _RegenTextOutlineColor, NLMISC::CRGBA::Black); + XML_READ_STRING(cur, "regen_text_fct", _RegenTextFct, ""); + _RegenTextFctLua = startsWith(_RegenTextFct, "lua:"); updateActualType(); // Init size for Type @@ -2166,13 +2169,13 @@ void CDBCtrlSheet::drawRegenText() _RegenText->setParent(_Parent); _RegenText->setOverflowText(std::string()); _RegenText->setModulateGlobalColor(false); - _RegenText->setMultiLine(false); + _RegenText->setMultiLine(true); _RegenText->setTextMode(CViewText::ClipWord); _RegenText->setFontSize(_RegenTextFontSize); _RegenText->setColor(_RegenTextColor); // do not set shadow if outline is set to avoid clearing it on draw (would call invalidate) _RegenText->setShadow(_RegenTextShadow && !_RegenTextOutline); - _RegenText->setShadowOutline(false);//_RegenTextOutline); + _RegenText->setShadowOutline(false); _RegenText->setShadowColor(_RegenTextShadowColor); _RegenText->setActive(true); @@ -2180,29 +2183,62 @@ void CDBCtrlSheet::drawRegenText() } // TODO: 10 hardcoded (ticks in second) - uint32 nextValue = _RegenTickRange.EndTick > LastGameCycle ? (_RegenTickRange.EndTick - LastGameCycle) / 10 : 0; + sint32 nextValue; + if (_RegenTickRange.EndTick > LastGameCycle) + nextValue = (_RegenTickRange.EndTick - LastGameCycle) / 10; + else if (_RegenTextFctLua) + nextValue = ((sint64)_RegenTickRange.EndTick - (sint64)LastGameCycle) / 10; + else + nextValue = 0; + if (_RegenTextValue != nextValue) { _RegenTextValue = nextValue; - // format as "10m", "9'59", "59" - if (_RegenTextValue > 600) - { - _RegenText->setText(toString("%dm", _RegenTextValue / 60)); - } - else if (_RegenTextValue > 0) + if (_RegenTextFct.empty()) { - if (_RegenTextValue < 60) - _RegenText->setText(toString("%d", _RegenTextValue)); + // format as "10m", "9'59", "59" + if (_RegenTextValue > 600) + { + _RegenText->setText(toString("%dm", _RegenTextValue / 60)); + } + else if (_RegenTextValue > 0) + { + if (_RegenTextValue < 60) + _RegenText->setText(toString("%d", _RegenTextValue)); + else + _RegenText->setText(toString("%d'%02d", _RegenTextValue / 60, _RegenTextValue % 60)); + } else - _RegenText->setText(toString("%d'%02d", _RegenTextValue / 60, _RegenTextValue % 60)); + { + _RegenText->setText(""); + } } else { - _RegenText->setText(""); + std::string fct; + if (_RegenTextFctLua) + { + CCDBNodeBranch *root = getRootBranch(); + if (root) + fct = toString("%s(%d, '%s')", _RegenTextFct.c_str(), _RegenTextValue, root->getFullName().c_str()); + else + fct = toString("%s(%d, nil)", _RegenTextFct.c_str(), _RegenTextValue); + } + else + { + fct = toString("%s(%d)", _RegenTextFct.c_str(), _RegenTextValue); + } + + // if using color tags in format, then RegenText color should be set to CRGBA::White + // as tag color is modulated with main color + std::string result; + if (CInterfaceExpr::evalAsString(fct, result)) + _RegenText->setTextFormatTaged(result); } _RegenText->updateTextContext(); // todo: posref + // note: if x,y is moved outside icon area it might get cliped and not be visible (wreal/hreal == 0) _RegenText->setX(_WReal / 2 -_RegenText->getMaxUsedW() / 2); // move RegenTextY=0 to baseline _RegenText->setY(_RegenTextY - _RegenText->getFontLegHeight()); @@ -4830,6 +4866,12 @@ std::string CDBCtrlSheet::getContextHelpWindowName() const return CCtrlBase::getContextHelpWindowName(); } +// *************************************************************************** +void CDBCtrlSheet::setRegenTextFct(const std::string &s) +{ + _RegenTextFct = s; + _RegenTextFctLua = startsWith(s, "lua:"); +} // *************************************************************************** void CDBCtrlSheet::setRegenTickRange(const CTickRange &tickRange) diff --git a/ryzom/client/src/interface_v3/dbctrl_sheet.h b/ryzom/client/src/interface_v3/dbctrl_sheet.h index fee96150f..ab44ce99f 100644 --- a/ryzom/client/src/interface_v3/dbctrl_sheet.h +++ b/ryzom/client/src/interface_v3/dbctrl_sheet.h @@ -604,6 +604,15 @@ public: // Default regen text is displayed on bottom of icon. void setRegenText(bool b) { _RegenTextEnabled = b; } + // Allow to override default formatter. + // First parameter will be replaced with current timer value (always >= 0) + // If its a lua function, then parameters are + // 1: current timer value; can be negative + // 2: DB path for ctrl root (ie UI:VARIABLES:BONUSES:0), or nil + // + // ie: "secondsToTimeStringShort" -> CInterfaceExpr::evalAsString("secondsToTimeStringShort(123)", ret) + // ie: "lua:secondsToTimeStringShort" -> CInterfaceExpr::evalAsString("lua:secondsToTimeStringShort(123, 'UI:VARIABLES:BONUSES:0')", ret) + void setRegenTextFct(const std::string &s); void setRegenTextY(sint32 y) { _RegenTextY = y; } void setRegenTextShadow(bool b) { _RegenTextShadow = b; } void setRegenTextShadowColor(NLMISC::CRGBA c) { _RegenTextShadowColor = c; } @@ -748,8 +757,10 @@ protected: CTickRange _RegenTickRange; NLGUI::CViewText *_RegenText; - uint32 _RegenTextValue; + sint32 _RegenTextValue; // + std::string _RegenTextFct; + bool _RegenTextFctLua; bool _RegenTextEnabled; bool _RegenTextShadow; bool _RegenTextOutline; diff --git a/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.cpp b/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.cpp index 5fb68745c..f41dd3085 100644 --- a/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.cpp +++ b/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.cpp @@ -36,6 +36,7 @@ NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupListSheetBonusMalus, std::string, "lis // *************************************************************************** CDBGroupListSheetBonusMalus::CDBGroupListSheetBonusMalus(const TCtorParam ¶m) : CDBGroupListSheet(param), + _RegenTextEnabled(true), _RegenTextY(-14), _RegenTextFontSize(8), _RegenTextColor(NLMISC::CRGBA::White), _RegenTextDisabledColor(NLMISC::CRGBA(127,127,127)) @@ -77,6 +78,8 @@ void CDBGroupListSheetBonusMalus::CSheetChildTimer::init(CDBGroupListSheet *pFat Ctrl->setRegenTextY(owner->_RegenTextY); Ctrl->setRegenTextColor(owner->_RegenTextColor); Ctrl->setRegenTextFontSize(owner->_RegenTextFontSize); + if (!owner->_RegenTextFct.empty()) + Ctrl->setRegenTextFct(owner->_RegenTextFct); } Ctrl->setRegenTextOutline(true); @@ -130,6 +133,7 @@ bool CDBGroupListSheetBonusMalus::parse (xmlNodePtr cur, CInterfaceGroup *parent XML_READ_UINT(cur, "regen_text_fontsize", _RegenTextFontSize, 8); XML_READ_COLOR(cur, "regen_text_color", _RegenTextColor, NLMISC::CRGBA::White); XML_READ_COLOR(cur, "regen_text_disabled_color", _RegenTextDisabledColor, NLMISC::CRGBA(127, 127, 127)); + XML_READ_STRING(cur, "regen_text_fct", _RegenTextFct, ""); return true; } diff --git a/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.h b/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.h index c70e9f465..d63e664ed 100644 --- a/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.h +++ b/ryzom/client/src/interface_v3/dbgroup_list_sheet_bonus_malus.h @@ -62,6 +62,7 @@ private: friend CSheetChildTimer; bool _RegenTextEnabled; + std::string _RegenTextFct; sint32 _RegenTextY; uint32 _RegenTextFontSize; NLMISC::CRGBA _RegenTextColor;