Better listbox rows

This commit is contained in:
Paul Chote
2010-07-12 21:10:00 +12:00
parent e23ee6d892
commit 7d2a5d6f42
6 changed files with 41 additions and 34 deletions

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Widgets.Delegates
var r = Chrome.rootWidget;
var bg = r.GetWidget("MAP_CHOOSER");
bg.SpecialOneArg = (map) => RefreshMapList(map);
var ml = bg.GetWidget("MAP_LIST");
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Map;};
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Map.Title;};
@@ -53,7 +53,7 @@ namespace OpenRA.Widgets.Delegates
return true;
};
var itemTemplate = ml.GetWidget<ButtonWidget>("MAP_TEMPLATE");
var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
int offset = itemTemplate.Bounds.Y;
foreach (var kv in Game.AvailableMaps)
{
@@ -61,10 +61,11 @@ namespace OpenRA.Widgets.Delegates
if (!map.Selectable)
continue;
var template = itemTemplate.Clone() as ButtonWidget;
var template = itemTemplate.Clone() as LabelWidget;
template.Id = "MAP_{0}".F(map.Uid);
template.GetText = () => map.Title;
template.OnMouseUp = mi => {Map = map; return true;};
template.GetText = () => " "+map.Title;
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);
@@ -72,6 +73,7 @@ namespace OpenRA.Widgets.Delegates
ml.AddChild(template);
offset += template.Bounds.Height;
ml.ContentHeight += template.Bounds.Height;
}
}

View File

@@ -32,15 +32,18 @@ namespace OpenRA.Widgets
Right
}
public string Text = "";
public string Text = null;
public string Background = null;
public TextAlign Align = TextAlign.Left;
public bool Bold = false;
public Func<string> GetText;
public Func<string> GetBackground;
public LabelWidget()
: base()
{
GetText = () => { return Text; };
GetBackground = () => { return Background; };
}
public LabelWidget(Widget other)
@@ -50,10 +53,16 @@ namespace OpenRA.Widgets
Align = (other as LabelWidget).Align;
Bold = (other as LabelWidget).Bold;
GetText = (other as LabelWidget).GetText;
GetBackground = (other as LabelWidget).GetBackground;
}
public override void DrawInner(World world)
{
var bg = GetBackground();
if (bg != null)
WidgetUtils.DrawPanel(bg, RenderBounds );
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
var text = GetText();
if (text == null)

View File

@@ -28,6 +28,8 @@ namespace OpenRA.Widgets
public readonly float ScrollVelocity = 4f;
public readonly int HeaderHeight = 25;
public int ContentHeight = 0;
float ListOffset = 0;
bool UpPressed = false;
bool DownPressed = false;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Widgets
public string Width = "0";
public string Height = "0";
public string Delegate = null;
public bool ClickThrough = false;
public bool ClickThrough = true;
public bool Visible = true;
public readonly List<Widget> Children = new List<Widget>();
@@ -173,7 +173,7 @@ namespace OpenRA.Widgets
return true;
}
public virtual bool HandleInput(MouseInput mi) { return false; }
public virtual bool HandleInput(MouseInput mi) { return !ClickThrough; }
public bool HandleMouseInputOuter(MouseInput mi)
{
// Are we able to handle this event?

View File

@@ -1,14 +1,5 @@
Container:
ClickThrough:true
Children:
PostGame@POSTGAME_TEXT:
Id:POSTGAME_TEXT
X:0
Y:0
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
ClickThrough: true
Visible: true
Background@MAINMENU_BG:
Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2
@@ -776,10 +767,11 @@ Container:
Width:500
Height:480
Children:
Button@MAP_TEMPLATE:
Label@MAP_TEMPLATE:
Id:MAP_TEMPLATE
Width:PARENT_RIGHT-28
Height:25
ClickThrough:false
X:2
Y:25
Visible:false
@@ -881,6 +873,12 @@ Container:
Delegate:IngameChromeDelegate
Visible:false
Children:
PostGame@POSTGAME_TEXT:
Id:POSTGAME_TEXT
X:0
Y:0
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
SpecialPowerBin@INGAME_POWERS_BIN:
Id:INGAME_POWERS_BIN
X:0
@@ -1006,14 +1004,12 @@ Container:
Height: 250
Children:
PerfGraph@GRAPH:
ClickThrough:true
Id:GRAPH
X:5
Y:5
Width:200
Height:200
Label@TEXT:
ClickThrough:true
Id:TEXT
Bold: false
X:20

View File

@@ -1,14 +1,5 @@
Container:
ClickThrough:true
Children:
PostGame@POSTGAME_TEXT:
Id:POSTGAME_TEXT
X:0
Y:0
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
ClickThrough: true
Visible: true
Background@MAINMENU_BG:
Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2
@@ -776,10 +767,11 @@ Container:
Width:500
Height:480
Children:
Button@MAP_TEMPLATE:
Label@MAP_TEMPLATE:
Id:MAP_TEMPLATE
Width:PARENT_RIGHT-28
Height:25
ClickThrough:false
X:2
Y:25
Visible:false
@@ -881,6 +873,12 @@ Container:
Delegate:IngameChromeDelegate
Visible:false
Children:
PostGame@POSTGAME_TEXT:
Id:POSTGAME_TEXT
X:0
Y:0
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
SpecialPowerBin@INGAME_POWERS_BIN:
Id:INGAME_POWERS_BIN
X:0
@@ -1006,14 +1004,12 @@ Container:
Height: 250
Children:
PerfGraph@GRAPH:
ClickThrough:true
Id:GRAPH
X:5
Y:5
Width:200
Height:200
Label@TEXT:
ClickThrough:true
Id:TEXT
Bold: false
X:20
@@ -1104,4 +1100,6 @@ Container:
Width:25
Height:25
ImageCollection:music
ImageName:prev
ImageName:prev