diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index 208ad55adb..c9f8c8d9c0 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -11,6 +11,7 @@ using System; using System.Drawing; using OpenRA.Graphics; +using System.Collections.Generic; namespace OpenRA.Widgets { @@ -24,6 +25,7 @@ namespace OpenRA.Widgets public TextAlign Align = TextAlign.Left; public TextVAlign VAlign = TextVAlign.Middle; public bool Bold = false; + public bool WordWrap = false; public Func GetText; public Func GetBackground; @@ -58,7 +60,7 @@ namespace OpenRA.Widgets int2 textSize = font.Measure(text); int2 position = RenderOrigin; - + if (VAlign == TextVAlign.Middle) position += new int2(0, (Bounds.Height - textSize.Y)/2); @@ -69,7 +71,58 @@ namespace OpenRA.Widgets position += new int2((Bounds.Width - textSize.X)/2, 0); if (Align == TextAlign.Right) - position += new int2(Bounds.Width - textSize.X,0); + position += new int2(Bounds.Width - textSize.X,0); + + if (WordWrap) + { + if (textSize.X > Bounds.Width) + { + string[] lines = text.Split('\n'); + List newLines = new List(); + int i = 0; + string line = lines[i++]; + while (true) + { + newLines.Add(line); + int2 m = font.Measure(line); + int spaceIndex = 0, start = line.Length - 1; + + if (m.X <= Bounds.Width) + { + if (i < lines.Length - 1) + { + line = lines[i++]; + continue; + } + else + break; + } + + while (m.X > Bounds.Width) + { + if (-1 == (spaceIndex = line.LastIndexOf(' ', start))) + break; + start = spaceIndex - 1; + m = font.Measure(line.Substring(0, spaceIndex)); + } + + if (spaceIndex != -1) + { + newLines.RemoveAt(newLines.Count - 1); + newLines.Add(line.Substring(0, spaceIndex)); + line = line.Substring(spaceIndex + 1); + } + else if (i < lines.Length - 1) + { + line = lines[i++]; + continue; + } + else + break; + } + text = string.Join("\n", newLines.ToArray()); + } + } font.DrawText(text, position, Color.White); } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs index b57031ec91..f12f58202c 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs @@ -34,6 +34,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var ml = bg.GetWidget("MAP_LIST"); bg.GetWidget("MAPCHOOSER_MAP_PREVIEW").Map = () => Map; bg.GetWidget("CURMAP_TITLE").GetText = () => Map.Title; + bg.GetWidget("CURMAP_AUTHOR").GetText = () => Map.Author; + bg.GetWidget("CURMAP_DESC").GetText = () => Map.Description; bg.GetWidget("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Bounds.Width, Map.Bounds.Height); bg.GetWidget("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name; bg.GetWidget("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString(); diff --git a/mods/cnc/chrome/gamelobby.yaml b/mods/cnc/chrome/gamelobby.yaml index b02df84ecf..2ae2710df6 100644 --- a/mods/cnc/chrome/gamelobby.yaml +++ b/mods/cnc/chrome/gamelobby.yaml @@ -478,10 +478,44 @@ Background@MAP_CHOOSER: Align:Left Width:70 Height:20 + Label@CURMAP_AUTHOR_LABEL: + Id:CURMAP_AUTHOR_LABEL + X:PARENT_RIGHT - 200 - WIDTH + Y:331 + Align:Right + Width:70 + Height:20 + Text:Author: + Bold:True + Label@CURMAP_AUTHOR: + Id:CURMAP_AUTHOR + X:PARENT_RIGHT - 195 + Y:331 + Align:Left + Width:175 + Height:20 + WordWrap:True + Label@CURMAP_DESC_LABEL: + Id:CURMAP_DESC_LABEL + X:PARENT_RIGHT - 200 - WIDTH + Y:371 + Align:Right + Width:70 + Height:20 + Text:Desc.: + Bold:True + Label@CURMAP_DESC: + Id:CURMAP_DESC + X:PARENT_RIGHT - 195 + Y:371 + Align:Left + Width:175 + Height:20 + WordWrap:True Label@CURMAP_SIZE_LABEL: Id:CURMAP_SIZE_LABEL X:PARENT_RIGHT - 200 - WIDTH - Y:331 + Y:411 Align:Right Width:70 Height:20 @@ -490,14 +524,14 @@ Background@MAP_CHOOSER: Label@CURMAP_SIZE: Id:CURMAP_SIZE X:PARENT_RIGHT - 195 - Y:331 + Y:411 Align:Left Width:70 Height:20 Label@CURMAP_THEATER_LABEL: Id:CURMAP_THEATER_LABEL X:PARENT_RIGHT - 200 - WIDTH - Y:351 + Y:431 Align:Right Width:70 Height:20 @@ -506,14 +540,14 @@ Background@MAP_CHOOSER: Label@CURMAP_THEATER: Id:CURMAP_THEATER X:PARENT_RIGHT - 195 - Y:351 + Y:431 Align:Left Width:70 Height:20 Label@CURMAP_PLAYERS_LABEL: Id:CURMAP_PLAYERS_LABEL X:PARENT_RIGHT - 200 - WIDTH - Y:371 + Y:451 Align:Right Width:70 Height:20 @@ -522,7 +556,7 @@ Background@MAP_CHOOSER: Label@CURMAP_PLAYERS: Id:CURMAP_PLAYERS X:PARENT_RIGHT - 195 - Y:371 + Y:451 Align:Left Width:70 Height:20 diff --git a/mods/ra/chrome/gamelobby.yaml b/mods/ra/chrome/gamelobby.yaml index 1b2db6d0d1..53aa0946cf 100644 --- a/mods/ra/chrome/gamelobby.yaml +++ b/mods/ra/chrome/gamelobby.yaml @@ -478,10 +478,44 @@ Background@MAP_CHOOSER: Align:Left Width:70 Height:20 + Label@CURMAP_AUTHOR_LABEL: + Id:CURMAP_AUTHOR_LABEL + X:PARENT_RIGHT - 200 - WIDTH + Y:331 + Align:Right + Width:70 + Height:20 + Text:Author: + Bold:True + Label@CURMAP_AUTHOR: + Id:CURMAP_AUTHOR + X:PARENT_RIGHT - 195 + Y:331 + Align:Left + Width:175 + Height:20 + WordWrap:True + Label@CURMAP_DESC_LABEL: + Id:CURMAP_DESC_LABEL + X:PARENT_RIGHT - 200 - WIDTH + Y:371 + Align:Right + Width:70 + Height:20 + Text:Desc.: + Bold:True + Label@CURMAP_DESC: + Id:CURMAP_DESC + X:PARENT_RIGHT - 195 + Y:371 + Align:Left + Width:175 + Height:20 + WordWrap:True Label@CURMAP_SIZE_LABEL: Id:CURMAP_SIZE_LABEL X:PARENT_RIGHT - 200 - WIDTH - Y:331 + Y:411 Align:Right Width:70 Height:20 @@ -490,14 +524,14 @@ Background@MAP_CHOOSER: Label@CURMAP_SIZE: Id:CURMAP_SIZE X:PARENT_RIGHT - 195 - Y:331 + Y:411 Align:Left Width:70 Height:20 Label@CURMAP_THEATER_LABEL: Id:CURMAP_THEATER_LABEL X:PARENT_RIGHT - 200 - WIDTH - Y:351 + Y:431 Align:Right Width:70 Height:20 @@ -506,14 +540,14 @@ Background@MAP_CHOOSER: Label@CURMAP_THEATER: Id:CURMAP_THEATER X:PARENT_RIGHT - 195 - Y:351 + Y:431 Align:Left Width:70 Height:20 Label@CURMAP_PLAYERS_LABEL: Id:CURMAP_PLAYERS_LABEL X:PARENT_RIGHT - 200 - WIDTH - Y:371 + Y:451 Align:Right Width:70 Height:20 @@ -522,7 +556,7 @@ Background@MAP_CHOOSER: Label@CURMAP_PLAYERS: Id:CURMAP_PLAYERS X:PARENT_RIGHT - 195 - Y:371 + Y:451 Align:Left Width:70 Height:20