Index: binaries/data/mods/mod/gui/gui.rnc
===================================================================
--- binaries/data/mods/mod/gui/gui.rnc
+++ binaries/data/mods/mod/gui/gui.rnc
@@ -112,6 +112,7 @@
attribute textcolor_selected { ccolor }?&
attribute text_align { align }?&
attribute text_valign { valign }?&
+ attribute text_nowrap { 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
@@ -453,6 +453,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,10 @@
this.counters = [];
this.enabledCounters = [];
this.lastTick = undefined;
- this.lastLineCount = undefined;
+ this.lastTextSize = {
+ "height": this.dataCounter.size.top - this.dataCounter.size.bottom,
+ "width": this.dataCounter.size.right - this.dataCounter.size.left
+ };
this.resizeHandlers = [];
for (let name of this.availableCounterNames())
@@ -78,39 +81,32 @@
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)
- this.dataCounter.caption = txt;
+ this.dataCounter.caption = txt;
+ this.dataCounter.hidden = !txt;
- // The caption changes more often than not,
- // but adding or removing lines happens rarely.
- if (this.lastLineCount == lineCount)
+ if (!txt)
return;
- this.lastLineCount = lineCount;
+ // The caption changes more often than not, but the size changes rarely.
+ let textSize = this.dataCounter.getTextSize();
+ if (this.lastTextSize.height == textSize.height && this.lastTextSize.width == textSize.width)
+ return;
- if (lineCount)
- {
- 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.lastTextSize = textSize;
- this.dataCounter.hidden = !lineCount;
+ let size = this.dataCounter.size;
+ size.bottom = size.top + textSize.height;
+ size.left = size.right - textSize.width;
+ this.dataCounter.size = size;
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"
+ text_nowrap="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
@@ -188,6 +188,7 @@
const IGUIObject* pObject,
const SGenerateTextImages& Images,
const EAlign align,
+ const bool noWrap,
const float prelim_line_height,
const float Width,
const float BufferZone,
@@ -215,6 +216,7 @@
void ComputeLineRange(
const SGenerateTextImages& Images,
+ const bool noWrap,
const float y,
const float Width,
const float prelim_line_height,
@@ -225,6 +227,7 @@
const CGUI& pGUI,
const CGUIString& string,
const CStrIntern& Font,
+ const bool noWrap,
const bool FirstLine,
const float Width,
const float width_range_to,
@@ -237,6 +240,7 @@
const CGUI& pGUI,
const CGUIString& string,
const CStrIntern& Font,
+ const bool noWrap,
const IGUIObject* pObject,
const bool FirstLine,
const float Width,
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
@@ -84,6 +84,8 @@
if (pObject->SettingExists("text_align"))
align = pObject->GetSetting("text_align");
+ const bool noWrap = pObject->SettingExists("text_nowrap") && pObject->GetSetting("text_nowrap");
+
// Go through string word by word
for (int i = 0; i < static_cast(string.m_Words.size()) - 1; ++i)
{
@@ -107,8 +109,8 @@
prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.cy);
// 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))
+ if (((Width != 0 && ((!noWrap && x > Width - BufferZone) || Feedback.m_NewLine)) || i == static_cast(string.m_Words.size()) - 2) &&
+ ProcessLine(pGUI, string, Font, pObject, Images, align, noWrap, prelim_line_height, Width, BufferZone, FirstLine, x, y, i, from))
return;
}
}
@@ -166,6 +168,7 @@
const CGUI& pGUI,
const CGUIString& string,
const CStrIntern& Font,
+ const bool noWrap,
const bool FirstLine,
const float Width,
const float width_range_to,
@@ -187,7 +190,7 @@
// Append X value.
x += Feedback2.m_Size.cx;
- if (Width != 0 && x > width_range_to && j != temp_from && !Feedback2.m_NewLine)
+ if (Width != 0 && !noWrap && x > width_range_to && j != temp_from && !Feedback2.m_NewLine)
{
// The calculated width of each word includes the space between the current
// word and the next. When we're wrapping, we need subtract the width of the
@@ -218,6 +221,7 @@
const IGUIObject* pObject,
const SGenerateTextImages& Images,
const EAlign align,
+ const bool noWrap,
const float prelim_line_height,
const float Width,
const float BufferZone,
@@ -232,30 +236,31 @@
from = i;
float width_range_from = BufferZone;
+ // If we don't wrap, make sure we have enough space.
float width_range_to = Width - BufferZone;
- ComputeLineRange(Images, y, Width, prelim_line_height, width_range_from, width_range_to);
+ ComputeLineRange(Images, noWrap, y, Width, prelim_line_height, width_range_from, width_range_to);
// Reset X for the next loop
x = width_range_from;
CSize line_size;
- ComputeLineSize(pGUI, string, Font, FirstLine, Width, width_range_to, i, temp_from, x, line_size);
+ ComputeLineSize(pGUI, string, Font, noWrap, FirstLine, Width, width_range_to, i, temp_from, x, line_size);
// Reset x once more
x = width_range_from;
- // Move down, because font drawing starts from the baseline
+ // Move down, because font drawing starts from the baseline.
y += line_size.cy;
const float dx = GetLineOffset(align, width_range_from, width_range_to, line_size);
- // Do the real processing now
- const bool done = AssembleCalls(pGUI, string, Font, pObject, FirstLine, Width, width_range_to, dx, y, temp_from, i, x, from);
+ // Do the real processing now.
+ const bool done = AssembleCalls(pGUI, string, Font, noWrap, pObject, FirstLine, Width, width_range_to, dx, y, temp_from, i, x, from);
- // Reset X
+ // Reset X.
x = BufferZone;
- // Update dimensions
+ // Update dimensions.
m_Size.cx = std::max(m_Size.cx, line_size.cx + BufferZone * 2);
m_Size.cy = std::max(m_Size.cy, y + BufferZone);
@@ -280,6 +285,7 @@
// Loop through left and right side, from and to.
void CGUIText::ComputeLineRange(
const SGenerateTextImages& Images,
+ const bool noWrap,
const float y,
const float Width,
const float prelim_line_height,
@@ -287,7 +293,7 @@
float& width_range_to) const
{
// Floating images are only applicable if word-wrapping is enabled.
- if (Width == 0)
+ if (Width == 0 || noWrap)
return;
for (int j = 0; j < 2; ++j)
@@ -340,6 +346,7 @@
const CGUI& pGUI,
const CGUIString& string,
const CStrIntern& Font,
+ const bool noWrap,
const IGUIObject* pObject,
const bool FirstLine,
const float Width,
@@ -397,12 +404,12 @@
std::make_move_iterator(Feedback2.m_SpriteCalls.end()));
break;
}
- else if (x > width_range_to && j == temp_from)
+ else if (!noWrap && x > width_range_to && j == temp_from)
{
from = j+1;
// do not break, since we want it to be added to m_TextCalls
}
- else if (x > width_range_to)
+ else if (!noWrap && x > width_range_to)
{
from = j;
break;
Index: source/gui/ObjectTypes/CText.h
===================================================================
--- source/gui/ObjectTypes/CText.h
+++ source/gui/ObjectTypes/CText.h
@@ -92,6 +92,7 @@
EVAlign m_TextVAlign;
CGUIColor m_TextColor;
CGUIColor m_TextColorDisabled;
+ bool m_TextNoWrap;
CStrW m_IconTooltip;
CStr m_IconTooltipStyle;
};
Index: source/gui/ObjectTypes/CText.cpp
===================================================================
--- source/gui/ObjectTypes/CText.cpp
+++ source/gui/ObjectTypes/CText.cpp
@@ -43,6 +43,7 @@
m_TextVAlign(),
m_TextColor(),
m_TextColorDisabled(),
+ m_TextNoWrap(),
m_IconTooltip(),
m_IconTooltipStyle()
{
@@ -60,6 +61,7 @@
RegisterSetting("text_valign", m_TextVAlign);
RegisterSetting("textcolor", m_TextColor);
RegisterSetting("textcolor_disabled", m_TextColorDisabled);
+ RegisterSetting("text_nowrap", m_TextNoWrap);
// Private settings
RegisterSetting("_icon_tooltip", m_IconTooltip);
RegisterSetting("_icon_tooltip_style", m_IconTooltipStyle);