Index: binaries/data/mods/mod/gui/gui.rnc =================================================================== --- binaries/data/mods/mod/gui/gui.rnc +++ binaries/data/mods/mod/gui/gui.rnc @@ -110,6 +110,7 @@ attribute textcolor_selected { ccolor }?& attribute text_align { align }?& attribute text_valign { valign }?& + attribute no_text_wrap { bool }?& attribute tooltip { text }?& attribute tooltip_style { text }? Index: binaries/data/mods/mod/gui/gui.rng =================================================================== --- binaries/data/mods/mod/gui/gui.rng +++ binaries/data/mods/mod/gui/gui.rng @@ -445,6 +445,11 @@ + + + + + Index: binaries/data/mods/public/gui/common/OverlayCounterManager.js =================================================================== --- binaries/data/mods/public/gui/common/OverlayCounterManager.js +++ binaries/data/mods/public/gui/common/OverlayCounterManager.js @@ -12,7 +12,7 @@ this.counters = []; this.enabledCounters = []; this.lastTick = undefined; - this.lastLineCount = undefined; + this.lastTextSize = undefined; this.resizeHandlers = []; for (let name of this.availableCounterNames()) @@ -78,39 +78,34 @@ this.lastTick = now; - let lineCount = 0; let txt = ""; for (let counter of this.enabledCounters) { let newTxt = counter.get(); - if (!newTxt) - continue; - - ++lineCount; - txt += newTxt + "\n"; + if (newTxt) + txt += newTxt + "\n"; } - if (lineCount) + if (txt) this.dataCounter.caption = txt; - // The caption changes more often than not, - // but adding or removing lines happens rarely. - if (this.lastLineCount == lineCount) + // The caption changes more often than not, but the size changes rarely. + let textSize = this.dataCounter.getTextSize(); + if (this.lastTextSize && this.lastTextSize.height == textSize.height && this.lastTextSize.width == textSize.width) return; - this.lastLineCount = lineCount; + this.lastTextSize = textSize; - if (lineCount) + if (txt) { - let textSize = this.dataCounter.getTextSize(); let size = this.dataCounter.size; size.bottom = size.top + textSize.height; size.left = size.right - textSize.width; this.dataCounter.size = size; } - this.dataCounter.hidden = !lineCount; + this.dataCounter.hidden = !txt; for (let handler of this.resizeHandlers) handler(textSize); Index: binaries/data/mods/public/gui/common/global.xml =================================================================== --- binaries/data/mods/public/gui/common/global.xml +++ binaries/data/mods/public/gui/common/global.xml @@ -44,6 +44,7 @@ textcolor="white" text_align="right" text_valign="top" + no_text_wrap="true" sprite="color: 0 0 0 100" > Index: source/gui/CGUIText.h =================================================================== --- source/gui/CGUIText.h +++ source/gui/CGUIText.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -167,7 +167,7 @@ * @param pObject Optional parameter for error output. Used *only* if error parsing fails, * and we need to be able to output which object the error occurred in to aid the user. */ - CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject); + CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, float Width, const float BufferZone, const IGUIObject* pObject); /** * Draw this CGUIText object Index: source/gui/CGUIText.cpp =================================================================== --- source/gui/CGUIText.cpp +++ source/gui/CGUIText.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -60,7 +60,7 @@ m_Indentation = Size.cx + BufferZone * 2; } -CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject) +CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, float Width, const float BufferZone, const IGUIObject* pObject) { if (string.m_Words.empty()) return; @@ -84,6 +84,8 @@ if (pObject->SettingExists("text_align")) align = pObject->GetSetting("text_align"); + bool noWrap = pObject->SettingExists("no_text_wrap") && pObject->GetSetting("no_text_wrap"); + // Go through string word by word for (int i = 0; i < static_cast(string.m_Words.size()) - 1; ++i) { @@ -106,6 +108,9 @@ x += Feedback.m_Size.cx; prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.cy); + if (Width != 0 && noWrap) + Width = x + BufferZone; + // If Width is 0, then there's no word-wrapping, disable NewLine. if (((Width != 0 && (x > Width - BufferZone || Feedback.m_NewLine)) || i == static_cast(string.m_Words.size()) - 2) && ProcessLine(pGUI, string, Font, pObject, Images, align, prelim_line_height, Width, BufferZone, FirstLine, x, y, i, from)) Index: source/gui/ObjectTypes/CText.h =================================================================== --- source/gui/ObjectTypes/CText.h +++ source/gui/ObjectTypes/CText.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -95,6 +95,7 @@ EVAlign m_TextVAlign; CGUIColor m_TextColor; CGUIColor m_TextColorDisabled; + bool m_NoTextWrap; CStrW m_IconTooltip; CStr m_IconTooltipStyle; }; Index: source/gui/ObjectTypes/CText.cpp =================================================================== --- source/gui/ObjectTypes/CText.cpp +++ source/gui/ObjectTypes/CText.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -42,6 +42,7 @@ m_TextVAlign(), m_TextColor(), m_TextColorDisabled(), + m_NoTextWrap(), m_IconTooltip(), m_IconTooltipStyle() { @@ -59,6 +60,7 @@ RegisterSetting("text_valign", m_TextVAlign); RegisterSetting("textcolor", m_TextColor); RegisterSetting("textcolor_disabled", m_TextColorDisabled); + RegisterSetting("no_text_wrap", m_NoTextWrap); // Private settings RegisterSetting("_icon_tooltip", m_IconTooltip); RegisterSetting("_icon_tooltip_style", m_IconTooltipStyle);