Skip to content

Commit

Permalink
NPBruce#553 Fix issue with text box height
Browse files Browse the repository at this point in the history
GameObject needs to be new for Unity to provide a proper height.
Apply to width too just in case.
  • Loading branch information
BenRQ committed Jul 12, 2018
1 parent 231dca7 commit 9d13257
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
12 changes: 5 additions & 7 deletions unity/Assets/Scripts/Quest/DialogWindow.cs
Expand Up @@ -64,13 +64,12 @@ public DialogWindow(EventManager.Event e)
public void CreateWindow()
{
// Draw text
float offset = UIElement.GetStringHeight(text, 28);
UIElement ui = new UIElement();
float offset = ui.GetStringHeight(text, 28);
if (offset < 4)
{
offset = 4;
}

UIElement ui = new UIElement();
ui.SetLocation(UIScaler.GetHCenter(-14f), 0.5f, 28, offset);
ui.SetText(text);
new UIElementBorder(ui);
Expand All @@ -85,7 +84,7 @@ public void CreateWindow()
List<DialogWindow.EventButton> buttons = eventData.GetButtons();
foreach (EventButton eb in buttons)
{
float length = UIElement.GetStringWidth(eb.GetLabel().Translate(), UIScaler.GetMediumFont());
float length = ui.GetStringWidth(eb.GetLabel().Translate(), UIScaler.GetMediumFont());
if (length > buttonWidth)
{
buttonWidth = length;
Expand Down Expand Up @@ -123,13 +122,12 @@ public void CreateWindow()
public void CreateQuotaWindow()
{
// Draw text
float offset = UIElement.GetStringHeight(text, 28);
UIElement ui = new UIElement();
float offset = ui.GetStringHeight(text, 28);
if (offset < 4)
{
offset = 4;
}

UIElement ui = new UIElement();
ui.SetLocation(UIScaler.GetHCenter(-14f), 0.5f, 28, offset);
ui.SetText(text);
new UIElementBorder(ui);
Expand Down
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/Quest/LogWindow.cs
Expand Up @@ -51,7 +51,7 @@ public void Update(bool toggle = false)
string entry = e.GetEntry(developerToggle).Trim('\n');
if (entry.Length == 0) continue;
ui = new UIElement(scrollArea.GetScrollTransform());
float height = UIElement.GetStringHeight(entry, textWidth);
float height = ui.GetStringHeight(entry, textWidth);
ui.SetLocation(0, offset, textWidth, height);
ui.SetText(entry, Color.black);
ui.SetBGColor(Color.white);
Expand Down
8 changes: 4 additions & 4 deletions unity/Assets/Scripts/UI/Screens/QuestDetailsScreen.cs
Expand Up @@ -32,17 +32,17 @@ public QuestDetailsScreen(QuestData.Quest q)
}

// Draw Description
float height = UIElement.GetStringHeight(q.description, 30);
if (height > 25) height = 25;
ui = new UIElement();
float height = ui.GetStringHeight(q.description, 30);
if (height > 25) height = 25;
ui.SetLocation(UIScaler.GetHCenter(-7), 15 - (height / 2), 30, height);
ui.SetText(q.description);
new UIElementBorder(ui);

// Draw authors
height = UIElement.GetStringHeight(q.authors, 14);
if (height > 25) height = 25;
ui = new UIElement();
height = ui.GetStringHeight(q.authors, 14);
if (height > 25) height = 25;
ui.SetLocation(UIScaler.GetHCenter(-23), 18.5f - (height / 2), 14, height);
ui.SetText(q.authors);
new UIElementBorder(ui);
Expand Down
14 changes: 7 additions & 7 deletions unity/Assets/Scripts/UI/UIElement.cs
Expand Up @@ -21,8 +21,8 @@ public class UIElement
protected float textPadding = textPaddingDefault;

// Used for calculating text size
protected static GameObject textWidthObj;
protected static GameObject textHeightObj;
protected GameObject textWidthObj;
protected GameObject textHeightObj;

protected UnityEngine.Events.UnityAction buttonCall;

Expand Down Expand Up @@ -301,7 +301,7 @@ public virtual bool Empty()
/// <param name="content">Text to translate.</param>
/// <returns>
/// The size of the text in UIScaler units.</returns>
public static float GetStringWidth(StringKey content)
public float GetStringWidth(StringKey content)
{
return GetStringWidth(content.Translate());
}
Expand All @@ -311,7 +311,7 @@ public static float GetStringWidth(StringKey content)
/// <param name="content">Text to measure.</param>
/// <returns>
/// The size of the text in UIScaler units.</returns>
public static float GetStringWidth(string content)
public float GetStringWidth(string content)
{
return GetStringWidth(content, UIScaler.GetSmallFont());
}
Expand All @@ -322,7 +322,7 @@ public static float GetStringWidth(string content)
/// <param name="fontSize">Size of font.</param>
/// <returns>
/// The size of the text in UIScaler units.</returns>
public static float GetStringWidth(string content, int fontSize)
public float GetStringWidth(string content, int fontSize)
{
if (textWidthObj == null)
{
Expand All @@ -344,7 +344,7 @@ public static float GetStringWidth(string content, int fontSize)
/// <param name="width">Width of the text box in UIScaler units.</param>
/// <returns>
/// The required text box height in UIScaler units.</returns>
public static float GetStringHeight(StringKey content, float width)
public float GetStringHeight(StringKey content, float width)
{
return GetStringHeight(content.Translate(), width);
}
Expand All @@ -355,7 +355,7 @@ public static float GetStringHeight(StringKey content, float width)
/// <param name="width">Width of the text box in UIScaler units.</param>
/// <returns>
/// The required text box height in UIScaler units.</returns>
public static float GetStringHeight(string content, float width)
public float GetStringHeight(string content, float width)
{
if (textHeightObj == null)
{
Expand Down

0 comments on commit 9d13257

Please sign in to comment.