update player list in lobby gracefully for better user experience
This commit is contained in:
@@ -41,6 +41,11 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
widget.ContentHeight = Math.Max(widget.ContentHeight, pos.Y + widget.ItemSpacing + w.Bounds.Height);
|
widget.ContentHeight = Math.Max(widget.ContentHeight, pos.Y + widget.ItemSpacing + w.Bounds.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AdjustChildren()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,5 +24,16 @@ namespace OpenRA.Widgets
|
|||||||
w.Bounds.Y += widget.ContentHeight;
|
w.Bounds.Y += widget.ContentHeight;
|
||||||
widget.ContentHeight += w.Bounds.Height + widget.ItemSpacing;
|
widget.ContentHeight += w.Bounds.Height + widget.ItemSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void AdjustChildren()
|
||||||
|
{
|
||||||
|
widget.ContentHeight = widget.ItemSpacing;
|
||||||
|
foreach (var w in widget.Children)
|
||||||
|
{
|
||||||
|
w.Bounds.Y = widget.ContentHeight;
|
||||||
|
widget.ContentHeight += w.Bounds.Height + widget.ItemSpacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using OpenRA.Graphics;
|
|||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
public interface ILayout { void AdjustChild(Widget w); }
|
public interface ILayout { void AdjustChild(Widget w); void AdjustChildren(); }
|
||||||
|
|
||||||
public class ScrollPanelWidget : Widget
|
public class ScrollPanelWidget : Widget
|
||||||
{
|
{
|
||||||
@@ -95,6 +95,8 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
Game.Renderer.EnableScissor(backgroundRect.X + 1, backgroundRect.Y + 1, backgroundRect.Width - 2, backgroundRect.Height - 2);
|
Game.Renderer.EnableScissor(backgroundRect.X + 1, backgroundRect.Y + 1, backgroundRect.Width - 2, backgroundRect.Height - 2);
|
||||||
|
|
||||||
|
Layout.AdjustChildren();
|
||||||
|
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
child.DrawOuter();
|
child.DrawOuter();
|
||||||
|
|
||||||
|
|||||||
@@ -327,19 +327,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{
|
{
|
||||||
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
||||||
// Todo: handle this nicer
|
// Todo: handle this nicer
|
||||||
Players.RemoveChildren();
|
|
||||||
|
|
||||||
|
var idx = 0;
|
||||||
foreach (var kv in orderManager.LobbyInfo.Slots)
|
foreach (var kv in orderManager.LobbyInfo.Slots)
|
||||||
{
|
{
|
||||||
var key = kv.Key;
|
var key = kv.Key;
|
||||||
var slot = kv.Value;
|
var slot = kv.Value;
|
||||||
var client = orderManager.LobbyInfo.ClientInSlot(key);
|
var client = orderManager.LobbyInfo.ClientInSlot(key);
|
||||||
Widget template;
|
Widget template = null;
|
||||||
|
|
||||||
|
// get template for possible reuse
|
||||||
|
if (idx < Players.Children.Count)
|
||||||
|
template = Players.Children [idx];
|
||||||
|
|
||||||
// Empty slot
|
// Empty slot
|
||||||
if (client == null)
|
if (client == null)
|
||||||
{
|
{
|
||||||
|
//template = EmptySlotTemplate.Clone();
|
||||||
|
if (template == null || template.Id != EmptySlotTemplate.Id)
|
||||||
template = EmptySlotTemplate.Clone();
|
template = EmptySlotTemplate.Clone();
|
||||||
|
|
||||||
Func<string> getText = () => slot.Closed ? "Closed" : "Open";
|
Func<string> getText = () => slot.Closed ? "Closed" : "Open";
|
||||||
var ready = orderManager.LocalClient.IsReady;
|
var ready = orderManager.LocalClient.IsReady;
|
||||||
|
|
||||||
@@ -367,7 +374,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
else if ((client.Index == orderManager.LocalClient.Index) ||
|
else if ((client.Index == orderManager.LocalClient.Index) ||
|
||||||
(client.Bot != null && Game.IsHost))
|
(client.Bot != null && Game.IsHost))
|
||||||
{
|
{
|
||||||
|
if (template == null || template.Id != EditablePlayerTemplate.Id)
|
||||||
template = EditablePlayerTemplate.Clone();
|
template = EditablePlayerTemplate.Clone();
|
||||||
|
|
||||||
var botReady = client.Bot != null && Game.IsHost && orderManager.LocalClient.IsReady;
|
var botReady = client.Bot != null && Game.IsHost && orderManager.LocalClient.IsReady;
|
||||||
var ready = botReady || client.IsReady;
|
var ready = botReady || client.IsReady;
|
||||||
|
|
||||||
@@ -422,7 +431,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Non-editable player in slot
|
{ // Non-editable player in slot
|
||||||
|
if (template == null || template.Id != NonEditablePlayerTemplate.Id)
|
||||||
template = NonEditablePlayerTemplate.Clone();
|
template = NonEditablePlayerTemplate.Clone();
|
||||||
|
|
||||||
template.Get<LabelWidget>("NAME").GetText = () => client.Name;
|
template.Get<LabelWidget>("NAME").GetText = () => client.Name;
|
||||||
if (client.IsAdmin)
|
if (client.IsAdmin)
|
||||||
template.Get<LabelWidget>("NAME").Font = "Bold";
|
template.Get<LabelWidget>("NAME").Font = "Bold";
|
||||||
@@ -449,20 +460,35 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
template.IsVisible = () => true;
|
template.IsVisible = () => true;
|
||||||
|
|
||||||
|
if (idx >= Players.Children.Count)
|
||||||
Players.AddChild(template);
|
Players.AddChild(template);
|
||||||
|
else if (Players.Children [idx].Id != template.Id)
|
||||||
|
{
|
||||||
|
Players.Children [idx].Removed();
|
||||||
|
template.Parent = Players;
|
||||||
|
Players.Children [idx] = template;
|
||||||
|
}
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add spectators
|
// Add spectators
|
||||||
foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
|
foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
|
||||||
{
|
{
|
||||||
Widget template;
|
Widget template = null;
|
||||||
var c = client;
|
var c = client;
|
||||||
var ready = c.IsReady;
|
var ready = c.IsReady;
|
||||||
|
|
||||||
|
// get template for possible reuse
|
||||||
|
if (idx < Players.Children.Count)
|
||||||
|
template = Players.Children[idx];
|
||||||
|
|
||||||
// Editable spectator
|
// Editable spectator
|
||||||
if (c.Index == orderManager.LocalClient.Index)
|
if (c.Index == orderManager.LocalClient.Index)
|
||||||
{
|
{
|
||||||
|
if (template == null || template.Id != EditableSpectatorTemplate.Id)
|
||||||
template = EditableSpectatorTemplate.Clone();
|
template = EditableSpectatorTemplate.Clone();
|
||||||
|
|
||||||
var name = template.Get<TextFieldWidget>("NAME");
|
var name = template.Get<TextFieldWidget>("NAME");
|
||||||
name.IsDisabled = () => ready;
|
name.IsDisabled = () => ready;
|
||||||
LobbyUtils.SetupNameWidget(orderManager, c, name);
|
LobbyUtils.SetupNameWidget(orderManager, c, name);
|
||||||
@@ -481,7 +507,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
// Non-editable spectator
|
// Non-editable spectator
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (template == null || template.Id != NonEditableSpectatorTemplate.Id)
|
||||||
template = NonEditableSpectatorTemplate.Clone();
|
template = NonEditableSpectatorTemplate.Clone();
|
||||||
|
|
||||||
template.Get<LabelWidget>("NAME").GetText = () => c.Name;
|
template.Get<LabelWidget>("NAME").GetText = () => c.Name;
|
||||||
if (client.IsAdmin)
|
if (client.IsAdmin)
|
||||||
template.Get<LabelWidget>("NAME").Font = "Bold";
|
template.Get<LabelWidget>("NAME").Font = "Bold";
|
||||||
@@ -497,8 +525,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
template.IsVisible = () => true;
|
template.IsVisible = () => true;
|
||||||
|
|
||||||
|
if (idx >= Players.Children.Count)
|
||||||
Players.AddChild(template);
|
Players.AddChild(template);
|
||||||
|
else if (Players.Children [idx].Id != template.Id)
|
||||||
|
{
|
||||||
|
Players.Children [idx].Removed();
|
||||||
|
template.Parent = Players;
|
||||||
|
Players.Children [idx] = template;
|
||||||
}
|
}
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = idx; i < Players.Children.Count; i++)
|
||||||
|
Players.RemoveChild(Players.Children[i]);
|
||||||
|
|
||||||
// Spectate button
|
// Spectate button
|
||||||
if (orderManager.LocalClient.Slot != null)
|
if (orderManager.LocalClient.Slot != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user