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 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
@@ -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 = { "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 +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.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"
+ 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
@@ -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
@@ -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,
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("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;
}
}
@@ -218,6 +220,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,7 +235,8 @@
from = i;
float width_range_from = BufferZone;
- float width_range_to = Width - BufferZone;
+ // If we don't wrap, make sure we have enough space.
+ float width_range_to = noWrap ? x + BufferZone : Width - BufferZone;
ComputeLineRange(Images, y, Width, prelim_line_height, width_range_from, width_range_to);
// Reset X for the next loop
@@ -244,18 +248,21 @@
// 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;
+ // Don't mess up positioning the text when not wrapping.
+ width_range_to = Width - BufferZone;
+
const float dx = GetLineOffset(align, width_range_from, width_range_to, line_size);
- // Do the real processing now
+ // 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);
- // 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);
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_TextNoWrap;
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_TextNoWrap(),
m_IconTooltip(),
m_IconTooltipStyle()
{
@@ -59,6 +60,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);