Goodbye hardcoded chrome!

This commit is contained in:
Paul Chote
2010-07-11 15:43:32 +12:00
parent 74383fee47
commit b0e1d37789
7 changed files with 61 additions and 118 deletions

View File

@@ -66,28 +66,7 @@ namespace OpenRA.Widgets
public void AddLine(Color c, string from, string text)
{
var sizeOwner = Game.chrome.renderer.RegularFont.Measure(from);
var sizeText = Game.chrome.renderer.RegularFont.Measure(text);
if (sizeOwner.X + sizeText.X + 10 <= Chrome.ChatWidth)
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
else
{
StringBuilder sb = new StringBuilder();
foreach (var w in text.Split(' '))
{
if ( Game.chrome.renderer.RegularFont.Measure(sb.ToString() + ' ' + w).X > Chrome.ChatWidth )
{
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = sb.ToString() } );
sb = new StringBuilder();
sb.Append(w);
}
else
sb.Append( ' ' + w);
}
if (sb.Length != 0)
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = sb.ToString() } );
}
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
if (Notification != null)
Sound.Play(Notification);

View File

@@ -76,6 +76,7 @@ namespace OpenRA.Widgets.Delegates
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
mapButton.OnMouseUp = mi => {
r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
r.OpenWindow("MAP_CHOOSER");
return true;
};

View File

@@ -28,19 +28,22 @@ namespace OpenRA.Widgets.Delegates
{
public class MapChooserDelegate : IWidgetDelegate
{
MapStub Map = null;
public MapChooserDelegate()
{
var r = Chrome.rootWidget;
var bg = r.GetWidget("MAP_CHOOSER");
bg.SpecialOneArg = (map) => RefreshMapList(map);
var ml = bg.GetWidget("MAP_LIST");
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Game.chrome.currentMap;};
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Game.chrome.currentMap.Title;};
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Game.chrome.currentMap.Width, Game.chrome.currentMap.Height);};
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Game.chrome.currentMap.Tileset].Name;};
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => {return Game.chrome.currentMap.PlayerCount.ToString();};
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Map;};
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Map.Title;};
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Map.Width, Map.Height);};
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Map.Tileset].Name;};
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => {return Map.PlayerCount.ToString();};
bg.GetWidget("BUTTON_OK").OnMouseUp = mi => {
Game.IssueOrder(Order.Chat("/map " + Game.chrome.currentMap.Uid));
Game.IssueOrder(Order.Chat("/map " + Map.Uid));
r.CloseWindow();
return true;
};
@@ -49,6 +52,37 @@ namespace OpenRA.Widgets.Delegates
r.CloseWindow();
return true;
};
var itemTemplate = ml.GetWidget<ButtonWidget>("MAP_TEMPLATE");
int offset = 0;
foreach (var kv in Game.AvailableMaps)
{
var map = kv.Value;
if (!map.Selectable)
continue;
var template = itemTemplate.Clone() as ButtonWidget;
template.Id = "MAP_{0}".F(map.Uid);
template.GetText = () => map.Title;
template.OnMouseUp = mi => {Map = map; return true;};
template.Parent = ml;
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
ml.AddChild(template);
offset += template.Bounds.Height + 5;
}
}
public void RefreshMapList(object uidobj)
{
// Set the default selected map
var uid = uidobj as string;
if (uid != null)
Map = Game.AvailableMaps[ uid ];
else
Map = Game.AvailableMaps.FirstOrDefault().Value;
}
}
}

View File

@@ -48,6 +48,7 @@ namespace OpenRA.Widgets
public static Stack<string> WindowList = new Stack<string>();
// Common Funcs that most widgets will want
public Action<object> SpecialOneArg = (arg) => {};
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};