move ShowSlotDropDown to LobbyUtils; kill the cnc clone of it

This commit is contained in:
Chris Forbes
2011-10-06 22:44:51 +13:00
parent 57ac95123e
commit 6d469a1414
2 changed files with 47 additions and 76 deletions

View File

@@ -298,35 +298,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
}
}
void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client)
{
var options = new List<SlotDropDownOption>()
{
new SlotDropDownOption("Open", "slot_open "+slot.PlayerReference, () => (!slot.Closed && client == null)),
new SlotDropDownOption("Closed", "slot_close "+slot.PlayerReference, () => slot.Closed)
};
if (slot.AllowBots)
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
options.Add(new SlotDropDownOption(bot,
"slot_bot {0} {1}".F(slot.PlayerReference, bot),
() => client != null && client.Bot == bot));
}
Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
o.Selected,
() => orderManager.IssueOrder(Order.Command(o.Order)));
item.GetWidget<LabelWidget>("LABEL").GetText = () => o.Title;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
}
void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client)
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (race, itemTemplate) =>
@@ -430,7 +401,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
name.IsVisible = () => true;
name.IsDisabled = () => ready;
name.GetText = getText;
name.OnMouseDown = _ => ShowSlotDropDown(name, slot, client);
name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, slot, client, orderManager);
}
else
{
@@ -459,7 +430,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
name.IsVisible = () => true;
name.IsDisabled = () => ready;
name.GetText = () => client.Name;
name.OnMouseDown = _ => ShowSlotDropDown(name, slot, client);
name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, slot, client, orderManager);
}
else
{

View File

@@ -207,50 +207,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;
}
class SlotDropDownOption
{
public string Title;
public string Order;
public Func<bool> Selected;
public SlotDropDownOption(string title, string order, Func<bool> selected)
{
Title = title;
Order = order;
Selected = selected;
}
}
public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager)
{
var options = new List<SlotDropDownOption>()
{
new SlotDropDownOption("Open", "slot_open "+slot.PlayerReference, () => (!slot.Closed && client == null)),
new SlotDropDownOption("Closed", "slot_close "+slot.PlayerReference, () => slot.Closed)
};
if (slot.AllowBots)
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
options.Add(new SlotDropDownOption("Bot: {0}".F(bot),
"slot_bot {0} {1}".F(slot.PlayerReference, bot),
() => client != null && client.Bot == bot));
}
Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
o.Selected,
() => orderManager.IssueOrder(Order.Command(o.Order)));
item.GetWidget<LabelWidget>("LABEL").GetText = () => o.Title;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
}
void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client)
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (race, itemTemplate) =>
@@ -335,7 +291,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template = EmptySlotTemplateHost.Clone();
var name = template.GetWidget<DropDownButtonWidget>("NAME");
name.GetText = () => s.Closed ? "Closed" : (c == null) ? "Open" : c.Bot;
name.OnMouseDown = _ => ShowSlotDropDown(name, s, c, orderManager);
name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, s, c, orderManager);
}
else
{
@@ -499,5 +455,49 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
name.OnLoseFocus = () => name.OnEnterKey();
}
class SlotDropDownOption
{
public string Title;
public string Order;
public Func<bool> Selected;
public SlotDropDownOption(string title, string order, Func<bool> selected)
{
Title = title;
Order = order;
Selected = selected;
}
}
public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager)
{
var options = new List<SlotDropDownOption>()
{
new SlotDropDownOption("Open", "slot_open "+slot.PlayerReference, () => (!slot.Closed && client == null)),
new SlotDropDownOption("Closed", "slot_close "+slot.PlayerReference, () => slot.Closed)
};
if (slot.AllowBots)
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
options.Add(new SlotDropDownOption("Bot: {0}".F(bot),
"slot_bot {0} {1}".F(slot.PlayerReference, bot),
() => client != null && client.Bot == bot));
}
Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
o.Selected,
() => orderManager.IssueOrder(Order.Command(o.Order)));
item.GetWidget<LabelWidget>("LABEL").GetText = () => o.Title;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
}
}
}