コード例 #1
0
ファイル: LobbyLogic.cs プロジェクト: xbayrockx/OpenRA
        void UpdatePlayerList()
        {
            var idx = 0;

            foreach (var kv in orderManager.LobbyInfo.Slots)
            {
                var    key      = kv.Key;
                var    slot     = kv.Value;
                var    client   = orderManager.LobbyInfo.ClientInSlot(key);
                Widget template = null;

                // get template for possible reuse
                if (idx < Players.Children.Count)
                {
                    template = Players.Children[idx];
                }

                // Empty slot
                if (client == null)
                {
                    if (template == null || template.Id != EmptySlotTemplate.Id)
                    {
                        template = EmptySlotTemplate.Clone();
                    }

                    if (Game.IsHost)
                    {
                        LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager);
                    }
                    else
                    {
                        LobbyUtils.SetupSlotWidget(template, slot, client);
                    }

                    var join = template.Get <ButtonWidget>("JOIN");
                    join.IsVisible  = () => !slot.Closed;
                    join.IsDisabled = () => orderManager.LocalClient.IsReady;
                    join.OnClick    = () => orderManager.IssueOrder(Order.Command("slot " + key));
                }

                // Editable player in slot
                else if ((client.Index == orderManager.LocalClient.Index) ||
                         (client.Bot != null && Game.IsHost))
                {
                    if (template == null || template.Id != EditablePlayerTemplate.Id)
                    {
                        template = EditablePlayerTemplate.Clone();
                    }

                    LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);

                    if (client.Bot != null)
                    {
                        LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager);
                    }
                    else
                    {
                        LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
                    }

                    LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview);
                    LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, CountryNames);
                    LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map.GetSpawnPoints().Length);
                    LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager);
                }
                else
                {                       // Non-editable player in slot
                    if (template == null || template.Id != NonEditablePlayerTemplate.Id)
                    {
                        template = NonEditablePlayerTemplate.Clone();
                    }

                    LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);
                    LobbyUtils.SetupNameWidget(template, slot, client);
                    LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby,
                                               () => panel = PanelType.Kick, () => panel = PanelType.Players);
                    LobbyUtils.SetupColorWidget(template, slot, client);
                    LobbyUtils.SetupFactionWidget(template, slot, client, CountryNames);
                    LobbyUtils.SetupTeamWidget(template, slot, client);
                    LobbyUtils.SetupReadyWidget(template, slot, client);
                }

                template.IsVisible = () => true;

                if (idx >= Players.Children.Count)
                {
                    Players.AddChild(template);
                }
                else if (Players.Children[idx].Id != template.Id)
                {
                    Players.ReplaceChild(Players.Children[idx], template);
                }

                idx++;
            }

            // Add spectators
            foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
            {
                Widget template = null;
                var    c        = client;

                // get template for possible reuse
                if (idx < Players.Children.Count)
                {
                    template = Players.Children[idx];
                }

                // Editable spectator
                if (c.Index == orderManager.LocalClient.Index)
                {
                    if (template == null || template.Id != EditableSpectatorTemplate.Id)
                    {
                        template = EditableSpectatorTemplate.Clone();
                    }

                    LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager);
                }
                // Non-editable spectator
                else
                {
                    if (template == null || template.Id != NonEditableSpectatorTemplate.Id)
                    {
                        template = NonEditableSpectatorTemplate.Clone();
                    }

                    LobbyUtils.SetupNameWidget(template, null, client);
                    LobbyUtils.SetupKickWidget(template, null, client, orderManager, lobby,
                                               () => panel = PanelType.Kick, () => panel = PanelType.Players);
                }

                LobbyUtils.SetupClientWidget(template, null, c, orderManager, true);
                template.IsVisible = () => true;

                if (idx >= Players.Children.Count)
                {
                    Players.AddChild(template);
                }
                else if (Players.Children[idx].Id != template.Id)
                {
                    Players.ReplaceChild(Players.Children[idx], template);
                }

                idx++;
            }

            // Spectate button
            if (orderManager.LocalClient.Slot != null)
            {
                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");
                btn.OnClick    = () => orderManager.IssueOrder(Order.Command("spectate"));
                btn.IsDisabled = () => orderManager.LocalClient.IsReady;
                spec.IsVisible = () => true;

                if (idx >= Players.Children.Count)
                {
                    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]);
            }
        }
コード例 #2
0
        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
            Players.RemoveChildren();

            foreach (var kv in orderManager.LobbyInfo.Slots)
            {
                var    key    = kv.Key;
                var    slot   = kv.Value;
                var    client = orderManager.LobbyInfo.ClientInSlot(key);
                Widget template;

                // Empty slot
                if (client == null)
                {
                    template = EmptySlotTemplate.Clone();
                    Func <string> getText = () => slot.Closed ? "Closed" : "Open";
                    var           ready   = orderManager.LocalClient.IsReady;

                    if (Game.IsHost)
                    {
                        var name = template.GetWidget <DropDownButtonWidget>("NAME_HOST");
                        name.IsVisible   = () => true;
                        name.IsDisabled  = () => ready;
                        name.GetText     = getText;
                        name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, slot, client, orderManager);
                    }
                    else
                    {
                        var name = template.GetWidget <LabelWidget>("NAME");
                        name.IsVisible = () => true;
                        name.GetText   = getText;
                    }

                    var join = template.GetWidget <ButtonWidget>("JOIN");
                    join.IsVisible  = () => !slot.Closed;
                    join.IsDisabled = () => ready;
                    join.OnClick    = () => orderManager.IssueOrder(Order.Command("slot " + key));
                }
                // Editable player in slot
                else if ((client.Index == orderManager.LocalClient.Index) ||
                         (client.Bot != null && Game.IsHost))
                {
                    template = EditablePlayerTemplate.Clone();
                    var botReady = client.Bot != null && Game.IsHost && orderManager.LocalClient.IsReady;
                    var ready    = botReady || client.IsReady;

                    if (client.Bot != null)
                    {
                        var name = template.GetWidget <DropDownButtonWidget>("BOT_DROPDOWN");
                        name.IsVisible   = () => true;
                        name.IsDisabled  = () => ready;
                        name.GetText     = () => client.Name;
                        name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, slot, client, orderManager);
                    }
                    else
                    {
                        var name = template.GetWidget <TextFieldWidget>("NAME");
                        name.IsVisible  = () => true;
                        name.IsDisabled = () => ready;
                        LobbyUtils.SetupNameWidget(orderManager, client, name);
                    }

                    var color = template.GetWidget <DropDownButtonWidget>("COLOR");
                    color.IsDisabled  = () => slot.LockColor || ready;
                    color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, PlayerPalettePreview);

                    var colorBlock = color.GetWidget <ColorBlockWidget>("COLORBLOCK");
                    colorBlock.GetColor = () => client.ColorRamp.GetColor(0);

                    var faction = template.GetWidget <DropDownButtonWidget>("FACTION");
                    faction.IsDisabled  = () => slot.LockRace || ready;
                    faction.OnMouseDown = _ => LobbyUtils.ShowRaceDropDown(faction, client, orderManager, CountryNames);

                    var factionname = faction.GetWidget <LabelWidget>("FACTIONNAME");
                    factionname.GetText = () => CountryNames[client.Country];
                    var factionflag = faction.GetWidget <ImageWidget>("FACTIONFLAG");
                    factionflag.GetImageName       = () => client.Country;
                    factionflag.GetImageCollection = () => "flags";

                    var team = template.GetWidget <DropDownButtonWidget>("TEAM");
                    team.IsDisabled  = () => slot.LockTeam || ready;
                    team.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(team, client, orderManager, Map);
                    team.GetText     = () => (client.Team == 0) ? "-" : client.Team.ToString();

                    if (client.Bot == null)
                    {
                        // local player
                        var status = template.GetWidget <CheckboxWidget>("STATUS_CHECKBOX");
                        status.IsChecked = () => ready;
                        status.IsVisible = () => true;
                        status.OnClick  += CycleReady;
                    }
                    else                     // Bot
                    {
                        template.GetWidget <ImageWidget>("STATUS_IMAGE").IsVisible = () => true;
                    }
                }
                else
                {                       // Non-editable player in slot
                    template = NonEditablePlayerTemplate.Clone();
                    template.GetWidget <LabelWidget>("NAME").GetText = () => client.Name;
                    var color = template.GetWidget <ColorBlockWidget>("COLOR");
                    color.GetColor = () => client.ColorRamp.GetColor(0);

                    var faction     = template.GetWidget <LabelWidget>("FACTION");
                    var factionname = faction.GetWidget <LabelWidget>("FACTIONNAME");
                    factionname.GetText = () => CountryNames[client.Country];
                    var factionflag = faction.GetWidget <ImageWidget>("FACTIONFLAG");
                    factionflag.GetImageName       = () => client.Country;
                    factionflag.GetImageCollection = () => "flags";

                    var team = template.GetWidget <LabelWidget>("TEAM");
                    team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();

                    template.GetWidget <ImageWidget>("STATUS_IMAGE").IsVisible = () =>
                                                                                 client.Bot != null || client.IsReady;

                    var kickButton = template.GetWidget <ButtonWidget>("KICK");
                    kickButton.IsVisible  = () => Game.IsHost && client.Index != orderManager.LocalClient.Index;
                    kickButton.IsDisabled = () => orderManager.LocalClient.IsReady;
                    kickButton.OnClick    = () => orderManager.IssueOrder(Order.Command("kick " + client.Index));
                }

                template.IsVisible = () => true;
                Players.AddChild(template);
            }

            // Add spectators
            foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
            {
                Widget template;
                var    c     = client;
                var    ready = c.IsReady;

                // Editable spectator
                if (c.Index == orderManager.LocalClient.Index)
                {
                    template = EditableSpectatorTemplate.Clone();
                    var name = template.GetWidget <TextFieldWidget>("NAME");
                    name.IsDisabled = () => ready;
                    LobbyUtils.SetupNameWidget(orderManager, c, name);

                    var color = template.GetWidget <DropDownButtonWidget>("COLOR");
                    color.IsDisabled  = () => ready;
                    color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview);

                    var colorBlock = color.GetWidget <ColorBlockWidget>("COLORBLOCK");
                    colorBlock.GetColor = () => c.ColorRamp.GetColor(0);

                    var status = template.GetWidget <CheckboxWidget>("STATUS_CHECKBOX");
                    status.IsChecked = () => ready;
                    status.OnClick  += CycleReady;
                }
                // Non-editable spectator
                else
                {
                    template = NonEditableSpectatorTemplate.Clone();
                    template.GetWidget <LabelWidget>("NAME").GetText = () => c.Name;
                    var color = template.GetWidget <ColorBlockWidget>("COLOR");
                    color.GetColor = () => c.ColorRamp.GetColor(0);

                    template.GetWidget <ImageWidget>("STATUS_IMAGE").IsVisible = () => c.Bot != null || c.IsReady;

                    var kickButton = template.GetWidget <ButtonWidget>("KICK");
                    kickButton.IsVisible  = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
                    kickButton.IsDisabled = () => orderManager.LocalClient.IsReady;
                    kickButton.OnClick    = () => orderManager.IssueOrder(Order.Command("kick " + c.Index));
                }

                template.IsVisible = () => true;
                Players.AddChild(template);
            }

            // Spectate button
            if (orderManager.LocalClient.Slot != null)
            {
                var spec = NewSpectatorTemplate.Clone();
                var btn  = spec.GetWidget <ButtonWidget>("SPECTATE");
                btn.OnClick    = () => orderManager.IssueOrder(Order.Command("spectate"));
                btn.IsDisabled = () => orderManager.LocalClient.IsReady;
                spec.IsVisible = () => true;
                Players.AddChild(spec);
            }
        }