Dropdown listboxes
This commit is contained in:
@@ -103,14 +103,14 @@ namespace OpenRA.Widgets.Delegates
|
||||
bg.AddChild(theirStance);
|
||||
controls.Add(theirStance);
|
||||
|
||||
var myStance = new ButtonWidget
|
||||
var myStance = new DropDownButtonWidget
|
||||
{
|
||||
Bounds = new Rectangle( margin + 2 * labelWidth + 20, y, labelWidth, 25),
|
||||
Id = "DIPLOMACY_PLAYER_LABEL_MY_{0}".F(p.Index),
|
||||
Text = world.LocalPlayer.Stances[ pp ].ToString(),
|
||||
};
|
||||
|
||||
myStance.OnMouseUp = mi => { CycleStance(pp, myStance); return true; };
|
||||
myStance.OnMouseDown = mi => { ShowDropDown(pp, myStance); return true; };
|
||||
|
||||
bg.AddChild(myStance);
|
||||
controls.Add(myStance);
|
||||
@@ -119,29 +119,26 @@ namespace OpenRA.Widgets.Delegates
|
||||
}
|
||||
}
|
||||
|
||||
Stance GetNextStance(Stance s)
|
||||
void ShowDropDown(Player p, Widget w)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case Stance.Ally: return Stance.Enemy;
|
||||
case Stance.Enemy: return Stance.Neutral;
|
||||
case Stance.Neutral: return Stance.Ally;
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
DropDownButtonWidget.ShowDropDown(w, Enum.GetValues(typeof(Stance)).OfType<Stance>(),
|
||||
(s, width) => new LabelWidget
|
||||
{
|
||||
Bounds = new Rectangle(0, 0, width, 24),
|
||||
Text = " {0}".F(s),
|
||||
OnMouseUp = mi => { SetStance((ButtonWidget)w, p, s); return true; },
|
||||
});
|
||||
}
|
||||
|
||||
void CycleStance(Player p, ButtonWidget bw)
|
||||
void SetStance(ButtonWidget bw, Player p, Stance ss)
|
||||
{
|
||||
if (p.World.LobbyInfo.GlobalSettings.LockTeams)
|
||||
return; // team changes are banned
|
||||
|
||||
var nextStance = GetNextStance((Stance)Enum.Parse(typeof(Stance), bw.Text));
|
||||
|
||||
world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor,
|
||||
false) { TargetLocation = new int2(p.Index, (int)nextStance) });
|
||||
false) { TargetLocation = new int2(p.Index, (int)ss) });
|
||||
|
||||
bw.Text = nextStance.ToString();
|
||||
bw.Text = ss.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Graphics;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
@@ -215,6 +216,34 @@ namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
return orderManager.LobbyInfo.ClientInSlot( slot );
|
||||
}
|
||||
|
||||
void ShowDropDown(Session.Slot slot, ButtonWidget name, bool showBotOptions)
|
||||
{
|
||||
var dropDownOptions = new List<Pair<string, Action>>
|
||||
{
|
||||
new Pair<string, Action>( "Open",
|
||||
() => orderManager.IssueOrder( Order.Command( "slot_open " + slot.Index ) )),
|
||||
new Pair<string, Action>( "Closed",
|
||||
() => orderManager.IssueOrder( Order.Command( "slot_close " + slot.Index ) )),
|
||||
};
|
||||
|
||||
if (showBotOptions)
|
||||
{
|
||||
var bots = new string[] { "HackyAI" };
|
||||
bots.Do(bot =>
|
||||
dropDownOptions.Add(new Pair<string, Action>("Bot: {0}".F(bot),
|
||||
() => orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot.Index, bot))))));
|
||||
}
|
||||
|
||||
DropDownButtonWidget.ShowDropDown( name,
|
||||
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()
|
||||
{
|
||||
@@ -240,40 +269,15 @@ namespace OpenRA.Widgets.Delegates
|
||||
var btn = template.GetWidget<ButtonWidget>("JOIN");
|
||||
btn.GetText = () => "Spectate in this slot";
|
||||
name.GetText = () => s.Closed ? "Closed" : "Open";
|
||||
name.OnMouseUp = _ =>
|
||||
{
|
||||
if (s.Closed)
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("slot_open " + s.Index));
|
||||
}
|
||||
else
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("slot_close " + s.Index));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
name.OnMouseDown = _ => { ShowDropDown(s, name, false); return true; };
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
template = EmptySlotTemplateHost.Clone();
|
||||
var name = template.GetWidget<ButtonWidget>("NAME");
|
||||
name.GetText = () => s.Closed ? "Closed" : (s.Bot == null) ? "Open" : "Bot: " + s.Bot;
|
||||
name.OnMouseUp = _ =>
|
||||
{
|
||||
if (s.Closed)
|
||||
{
|
||||
s.Bot = null;
|
||||
orderManager.IssueOrder(Order.Command("slot_open " + s.Index));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s.Bot == null && Map.Players[s.MapPlayer].AllowBots)
|
||||
orderManager.IssueOrder(Order.Command("slot_bot {0} HackyAI".F(s.Index)));
|
||||
else
|
||||
orderManager.IssueOrder(Order.Command("slot_close " + s.Index));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
name.OnMouseDown = _ => { ShowDropDown(s, name, Map.Players[ s.MapPlayer ].AllowBots); return true; };
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user