Convert remaining buttons and checkboxes to cnc variants

This commit is contained in:
Paul Chote
2011-05-07 22:42:17 +12:00
parent 1e66d57ef1
commit dded6040d6
3 changed files with 25 additions and 16 deletions

View File

@@ -464,9 +464,9 @@ namespace OpenRA.Mods.Cnc.Widgets
team.OnMouseDown = _ => ShowTeamDropDown(team);
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
var status = template.GetWidget<CheckboxWidget>("STATUS");
var status = template.GetWidget<CncCheckboxWidget>("STATUS");
status.IsChecked = () => c.State == Session.ClientState.Ready;
status.OnChange += CycleReady;
status.OnClick += CycleReady;
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
@@ -496,10 +496,10 @@ namespace OpenRA.Mods.Cnc.Widgets
var team = template.GetWidget<LabelWidget>("TEAM");
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
var status = template.GetWidget<CheckboxWidget>("STATUS");
var status = template.GetWidget<CncCheckboxWidget>("STATUS");
status.IsChecked = () => c.State == Session.ClientState.Ready;
if (c.Index == orderManager.LocalClient.Index)
status.OnChange += CycleReady;
status.OnClick += CycleReady;
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
@@ -528,7 +528,7 @@ namespace OpenRA.Mods.Cnc.Widgets
bool SpawnPointAvailable(int index) { return (index == 0) || orderManager.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
void CycleReady(bool ready)
void CycleReady()
{
orderManager.IssueOrder(Order.Command("ready"));
}

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
public Func<bool> IsDisabled = () => false;
public Action OnClick = () => {};
public Renderer.FontType Font = Renderer.FontType.Bold;
public CncMenuButtonWidget()
: base()
@@ -26,29 +27,32 @@ namespace OpenRA.Mods.Cnc.Widgets
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
}
protected CncMenuButtonWidget(CncMenuButtonWidget widget)
: base(widget)
protected CncMenuButtonWidget(CncMenuButtonWidget other)
: base(other)
{
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
Font = other.Font;
}
public override int2 ChildOrigin { get { return RenderOrigin; } }
public override void DrawInner()
{
var font = Game.Renderer.BoldFont;
var rb = RenderBounds;
var font = Game.Renderer.Fonts[Font];
var state = IsDisabled() ? "button-disabled" :
Depressed ? "button-pressed" :
RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" :
rb.Contains(Viewport.LastMousePos) ? "button-hover" :
"button";
WidgetUtils.DrawPanel(state, RenderBounds);
WidgetUtils.DrawPanel(state, rb);
var text = GetText();
font.DrawText(text,
new int2(RenderOrigin.X + UsableWidth / 2, RenderOrigin.Y + Bounds.Height / 2)
new int2(rb.X + UsableWidth / 2, rb.Y + Bounds.Height / 2)
- new int2(font.Measure(text).X / 2,
font.Measure(text).Y / 2), IsDisabled() ? Color.Gray : Color.White);
}
public override Widget Clone() { return new CncMenuButtonWidget(this); }
}
public class CncCheckboxWidget : CncMenuButtonWidget
@@ -81,6 +85,7 @@ namespace OpenRA.Mods.Cnc.Widgets
ChromeProvider.GetImage("checkbox", "checked"),
new float2(rect.Left + 2, rect.Top + 2));
}
public override Widget Clone() { return new CncCheckboxWidget(this); }
}
public class CncScrollPanelWidget : ScrollPanelWidget
@@ -148,6 +153,8 @@ namespace OpenRA.Mods.Cnc.Widgets
{
ListOffset = Math.Min(0,Bounds.Height - ContentHeight);
}
public override Widget Clone() { return new CncScrollPanelWidget(this); }
}
}

View File

@@ -109,7 +109,7 @@ Container@SERVER_LOBBY:
Height:25
X:390
Y:0
Checkbox@STATUS:
CncCheckbox@STATUS:
Id:STATUS
X:448
Y:2
@@ -139,7 +139,7 @@ Container@SERVER_LOBBY:
Height:25
X:5
Y:0-1
Button@KICK:
CncMenuButton@KICK:
Id:KICK
Text:X
Width:25
@@ -181,7 +181,7 @@ Container@SERVER_LOBBY:
Align:Center
X:390
Y:0
Checkbox@STATUS:
CncCheckbox@STATUS:
Id:STATUS
X:448
Y:2
@@ -211,9 +211,10 @@ Container@SERVER_LOBBY:
Height:25
X:5
Y:0-1
Button@JOIN:
CncMenuButton@JOIN:
Id:JOIN
Text:Play in this slot
Font:Regular
Width:278
Height:25
X:160
@@ -242,9 +243,10 @@ Container@SERVER_LOBBY:
Height:25
X:0
Y:0
Button@JOIN:
CncMenuButton@JOIN:
Id:JOIN
Text:Play in this slot
Font:Regular
Width:278
Height:25
X:160