Use ScrollItem for ra replay browser

This commit is contained in:
Paul Chote
2011-05-22 14:18:41 +12:00
parent 1d24c5f49c
commit db417545e6
3 changed files with 19 additions and 12 deletions

View File

@@ -22,12 +22,14 @@ namespace OpenRA.Widgets
: base() : base()
{ {
IsVisible = () => false; IsVisible = () => false;
VisualHeight = 0;
} }
protected ScrollItemWidget(ScrollItemWidget other) protected ScrollItemWidget(ScrollItemWidget other)
: base(other) : base(other)
{ {
IsVisible = () => false; IsVisible = () => false;
VisualHeight = 0;
} }
public Func<bool> IsSelected = () => false; public Func<bool> IsSelected = () => false;

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST"); var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
var replayDir = Path.Combine(Platform.SupportDir, "Replays"); var replayDir = Path.Combine(Platform.SupportDir, "Replays");
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE"); var template = widget.GetWidget<ScrollItemWidget>("REPLAY_TEMPLATE");
CurrentReplay = null; CurrentReplay = null;
rl.RemoveChildren(); rl.RemoveChildren();
@@ -87,15 +87,14 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
} }
} }
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template) void AddReplay(ScrollPanelWidget list, string filename, ScrollItemWidget template)
{ {
var entry = template.Clone() as LabelWidget; var item = ScrollItemWidget.Setup(template,
entry.Id = "REPLAY_"; () => CurrentReplay == filename,
entry.GetText = () => " {0}".F(Path.GetFileName(filename)); () => CurrentReplay = filename);
entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null; var f = Path.GetFileName(filename);
entry.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false; CurrentReplay = filename; return true; }; item.GetWidget<LabelWidget>("TITLE").GetText = () => f;
entry.IsVisible = () => true; list.AddChild(item);
list.AddChild(entry);
} }
} }

View File

@@ -22,13 +22,19 @@ Background@REPLAYBROWSER_BG:
Width:390 Width:390
Height:300 Height:300
Children: Children:
Label@REPLAY_TEMPLATE: ScrollItem@REPLAY_TEMPLATE:
Id:REPLAY_TEMPLATE Id:REPLAY_TEMPLATE
Width:PARENT_RIGHT-28 Width:PARENT_RIGHT-27
Height:25 Height:25
X:2 X:2
Y:0 Y:0
Visible:false Visible:false
Children:
Label@TITLE:
X:10
Id:TITLE
Width:PARENT_RIGHT-20
Height:25
Container@REPLAY_INFO: Container@REPLAY_INFO:
Id:REPLAY_INFO Id:REPLAY_INFO
X:0 X:0