fixed child removal
fixed relayout on draw refactored child remove/replace into ScrollPanelWidget fixed scrolling on child remove
This commit is contained in:
@@ -21,11 +21,10 @@ namespace OpenRA.Widgets
|
|||||||
if (widget.Children.Count == 0)
|
if (widget.Children.Count == 0)
|
||||||
widget.ContentHeight = widget.ItemSpacing;
|
widget.ContentHeight = widget.ItemSpacing;
|
||||||
|
|
||||||
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()
|
public void AdjustChildren()
|
||||||
{
|
{
|
||||||
widget.ContentHeight = widget.ItemSpacing;
|
widget.ContentHeight = widget.ItemSpacing;
|
||||||
|
|||||||
@@ -50,6 +50,25 @@ namespace OpenRA.Widgets
|
|||||||
base.AddChild(child);
|
base.AddChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void RemoveChild(Widget child)
|
||||||
|
{
|
||||||
|
base.RemoveChild(child);
|
||||||
|
Layout.AdjustChildren();
|
||||||
|
Scroll(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReplaceChild(Widget oldChild, Widget newChild)
|
||||||
|
{
|
||||||
|
|
||||||
|
oldChild.Removed();
|
||||||
|
newChild.Parent = this;
|
||||||
|
Children[Children.IndexOf(oldChild)] = newChild;
|
||||||
|
Layout.AdjustChildren();
|
||||||
|
Scroll(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override void DrawOuter()
|
public override void DrawOuter()
|
||||||
{
|
{
|
||||||
if (!IsVisible())
|
if (!IsVisible())
|
||||||
@@ -95,8 +114,6 @@ 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();
|
||||||
|
|
||||||
|
|||||||
@@ -325,9 +325,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
void UpdatePlayerList()
|
void UpdatePlayerList()
|
||||||
{
|
{
|
||||||
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
|
||||||
// Todo: handle this nicer
|
|
||||||
|
|
||||||
var idx = 0;
|
var idx = 0;
|
||||||
foreach (var kv in orderManager.LobbyInfo.Slots)
|
foreach (var kv in orderManager.LobbyInfo.Slots)
|
||||||
{
|
{
|
||||||
@@ -343,7 +340,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
// Empty slot
|
// Empty slot
|
||||||
if (client == null)
|
if (client == null)
|
||||||
{
|
{
|
||||||
//template = EmptySlotTemplate.Clone();
|
|
||||||
if (template == null || template.Id != EmptySlotTemplate.Id)
|
if (template == null || template.Id != EmptySlotTemplate.Id)
|
||||||
template = EmptySlotTemplate.Clone();
|
template = EmptySlotTemplate.Clone();
|
||||||
|
|
||||||
@@ -463,12 +459,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
if (idx >= Players.Children.Count)
|
if (idx >= Players.Children.Count)
|
||||||
Players.AddChild(template);
|
Players.AddChild(template);
|
||||||
else if (Players.Children [idx].Id != template.Id)
|
else if (Players.Children[idx].Id != template.Id)
|
||||||
{
|
Players.ReplaceChild(Players.Children[idx], template);
|
||||||
Players.Children [idx].Removed();
|
|
||||||
template.Parent = Players;
|
|
||||||
Players.Children [idx] = template;
|
|
||||||
}
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,28 +521,37 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
if (idx >= Players.Children.Count)
|
if (idx >= Players.Children.Count)
|
||||||
Players.AddChild(template);
|
Players.AddChild(template);
|
||||||
else if (Players.Children [idx].Id != template.Id)
|
else if (Players.Children[idx].Id != template.Id)
|
||||||
{
|
Players.ReplaceChild(Players.Children[idx], template);
|
||||||
Players.Children [idx].Removed();
|
|
||||||
template.Parent = Players;
|
|
||||||
Players.Children [idx] = template;
|
|
||||||
}
|
|
||||||
idx++;
|
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)
|
||||||
{
|
{
|
||||||
var spec = NewSpectatorTemplate.Clone();
|
Widget spec = null;
|
||||||
|
if (idx < Players.Children.Count)
|
||||||
|
spec = Players.Children[idx];
|
||||||
|
if (spec == null || spec.Id != NewSpectatorTemplate.Id)
|
||||||
|
spec = NewSpectatorTemplate.Clone();
|
||||||
|
|
||||||
var btn = spec.Get<ButtonWidget>("SPECTATE");
|
var btn = spec.Get<ButtonWidget>("SPECTATE");
|
||||||
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
|
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
|
||||||
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
|
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||||
spec.IsVisible = () => true;
|
spec.IsVisible = () => true;
|
||||||
|
|
||||||
|
if (idx >= Players.Children.Count)
|
||||||
Players.AddChild(spec);
|
Players.AddChild(spec);
|
||||||
|
else if (Players.Children[idx].Id != spec.Id)
|
||||||
|
Players.ReplaceChild(Players.Children[idx], spec);
|
||||||
|
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (Players.Children.Count > idx)
|
||||||
|
Players.RemoveChild(Players.Children[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CycleReady()
|
void CycleReady()
|
||||||
|
|||||||
Reference in New Issue
Block a user