Team dropdown.

This commit is contained in:
Paul Chote
2010-11-28 12:00:14 +13:00
parent 45cd6caeec
commit 0b9a984b7a

View File

@@ -278,6 +278,26 @@ namespace OpenRA.Widgets.Delegates
});
}
void ShowTeamDropDown(ButtonWidget team)
{
var dropDownOptions = new List<Pair<string, Action>>();
for (int i = 0; i <= Map.PlayerCount; i++)
{
var ii = i;
dropDownOptions.Add(new Pair<string, Action>( ii == 0 ? "-" : ii.ToString(),
() => orderManager.IssueOrder( Order.Command("team "+ii) )) );
};
DropDownButtonWidget.ShowDropDown( team,
dropDownOptions,
(ac, w) => new LabelWidget
{
Bounds = new Rectangle(0, 0, w, 24),
Text = " {0}".F(ac.First),
OnMouseUp = mi => { ac.Second(); return true; },
});
}
void UpdatePlayerList()
{
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
@@ -392,7 +412,7 @@ namespace OpenRA.Widgets.Delegates
factionflag.GetImageCollection = () => "flags";
var team = template.GetWidget<ButtonWidget>("TEAM");
team.OnMouseUp = CycleTeam;
team.OnMouseDown = _ => {ShowTeamDropDown(team); return true;};
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
var status = template.GetWidget<CheckboxWidget>("STATUS");
@@ -456,15 +476,5 @@ namespace OpenRA.Widgets.Delegates
orderManager.IssueOrder(Order.Command("ready"));
return true;
}
bool CycleTeam(MouseInput mi)
{
var d = (mi.Button == MouseButton.Left) ? +1 : Map.PlayerCount;
var newIndex = (orderManager.LocalClient.Team + d) % (Map.PlayerCount + 1);
orderManager.IssueOrder(
Order.Command("team " + newIndex));
return true;
}
}
}