Remove a pile of unnecessary state management from Scrollpanels.

This commit is contained in:
Paul Chote
2011-01-01 16:47:52 +13:00
parent e2b739cd3e
commit d90dec9c8e
22 changed files with 57 additions and 115 deletions

View File

@@ -293,10 +293,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
{
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
// Todo: handle this nicer
Players.Children.Clear();
Players.ContentHeight = 0;
Players.ClearChildren();
int offset = 0;
foreach (var slot in orderManager.LobbyInfo.Slots)
{
var s = slot;
@@ -446,19 +444,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
}
template.Id = "SLOT_{0}".F(s.Index);
template.Parent = Players;
template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
Players.AddChild(template);
offset += template.Bounds.Height;
// Hack to ensure correct ContentHeight
if (Players.ContentHeight == 0)
Players.ContentHeight += template.Bounds.Y;
Players.ContentHeight += template.Bounds.Height;
}
}

View File

@@ -55,7 +55,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
};
var itemTemplate = ml.GetWidget<ContainerWidget>("MAP_TEMPLATE");
int offset = itemTemplate.Bounds.Y;
foreach (var kv in Game.modData.AvailableMaps.OrderBy(kv => kv.Value.Title))
{
var map = kv.Value;
@@ -66,19 +65,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
template.Id = "MAP_{0}".F(map.Uid);
template.GetBackground = () => ((Map == map) ? "dialog2" : null);
template.OnMouseDown = mi => { Map = map; return true; };
template.Parent = ml;
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
template.GetWidget<LabelWidget>("TITLE").GetText = () => " " + map.Title;
template.GetWidget<LabelWidget>("TYPE").GetText = () => map.Type + " ";
ml.AddChild(template);
offset += template.Bounds.Height;
// Padding hack
if (ml.ContentHeight == 0)
ml.ContentHeight += 2*template.Bounds.Y;
ml.ContentHeight += template.Bounds.Height;
}
}
}

View File

@@ -98,7 +98,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var ml = bg.GetWidget<ScrollPanelWidget>("MUSIC_LIST");
var itemTemplate = ml.GetWidget<LabelWidget>("MUSIC_TEMPLATE");
int offset = itemTemplate.Bounds.Y;
if (!Rules.Music.Where(m => m.Value.Exists).Any())
{
@@ -122,24 +121,12 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
return true;
};
template.Parent = ml;
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
template.IsVisible = () => true;
template.GetWidget<LabelWidget>("TITLE").GetText = () => " " + Rules.Music[song].Title;
template.GetWidget<LabelWidget>("LENGTH").GetText = () => "{0:D1}:{1:D2}".F(Rules.Music[song].Length / 60, Rules.Music[song].Length % 60);
ml.AddChild(template);
offset += template.Bounds.Height;
// Padding hack
if (ml.ContentHeight == 0)
ml.ContentHeight += 2*template.Bounds.Y;
ml.ContentHeight += template.Bounds.Height;
}
}

View File

@@ -40,11 +40,9 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE");
CurrentReplay = null;
rl.Children.Clear();
rl.ContentHeight = 0;
var offset = template.Bounds.Y;
rl.ClearChildren();
foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse())
AddReplay(rl, replayFile, template, ref offset);
AddReplay(rl, replayFile, template);
widget.GetWidget("WATCH_BUTTON").OnMouseUp = mi =>
{
@@ -100,27 +98,15 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
}
}
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template, ref int offset)
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template)
{
var entry = template.Clone() as LabelWidget;
entry.Id = "REPLAY_";
entry.GetText = () => " {0}".F(Path.GetFileName(filename));
entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null;
entry.OnMouseDown = mi => { CurrentReplay = filename; return true; };
entry.Parent = list;
entry.Bounds = new Rectangle(entry.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
entry.IsVisible = () => true;
list.AddChild(entry);
if (offset == template.Bounds.Y)
CurrentReplay = filename;
offset += template.Bounds.Height;
// Padding hack
if (list.ContentHeight == 0)
list.ContentHeight += 2*template.Bounds.Y;
list.ContentHeight += template.Bounds.Height;
}
}

View File

@@ -139,7 +139,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var sl = bg.GetWidget<ScrollPanelWidget>("SERVER_LIST");
sl.Children.Clear();
sl.ClearChildren();
currentServer = null;
if (games == null)
@@ -161,8 +161,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false;
sl.ContentHeight = 0;
int offset = ServerTemplate.Bounds.Y;
int i = 0;
foreach (var loop in gamesWaiting)
{
@@ -174,20 +172,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
game.Address);
template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
template.OnMouseDown = mi => { currentServer = game; return true; };
template.Parent = sl;
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
sl.AddChild(template);
if (i == 0) currentServer = game;
offset += template.Bounds.Height;
// Padding hack
if (sl.ContentHeight == 0)
sl.ContentHeight += 2*template.Bounds.Y;
sl.ContentHeight += template.Bounds.Height;
i++;
}
}

View File

@@ -57,7 +57,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var vl = bg.GetWidget<ScrollPanelWidget>("VIDEO_LIST");
var itemTemplate = vl.GetWidget<LabelWidget>("VIDEO_TEMPLATE");
int offset = itemTemplate.Bounds.Y;
foreach (var kv in Rules.Movies)
{
@@ -79,14 +78,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
player.Load(video);
return true;
};
template.Parent = vl;
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
vl.AddChild(template);
offset += template.Bounds.Height;
vl.ContentHeight += template.Bounds.Height;
}
}
}