Added author and description to map chooser, fixes #290. Added word wrap to the LabelWidget to support it.
This commit is contained in:
committed by
Paul Chote
parent
b44cb9ad57
commit
57f74606f0
@@ -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<string> GetText;
|
||||
public Func<string> 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<string> newLines = new List<string>();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
var ml = bg.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => Map.Author;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => Map.Description;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Bounds.Width, Map.Bounds.Height);
|
||||
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user