Пример #1
0
        static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)
        {
            var flag = template.Get <ImageWidget>("FLAG");

            flag.GetImageCollection = () => "flags";
            flag.GetImageName       = () => player.Faction.InternalName;

            var playerName = template.Get <LabelWidget>("PLAYER");

            WidgetUtils.BindPlayerNameAndStatus(playerName, player);

            playerName.GetColor = () => player.Color;
        }
Пример #2
0
 public CameraOption(ObserverShroudSelectorLogic logic, Player p)
 {
     Player     = p;
     Label      = p.PlayerName;
     Color      = p.Color;
     Faction    = p.Faction.InternalName;
     IsSelected = () => p.World.RenderPlayer == p;
     OnClick    = () =>
     {
         p.World.RenderPlayer = p;
         logic.selected       = this;
         p.World.Selection.Clear();
         WidgetUtils.BindPlayerNameAndStatus(logic.shroudLabel, p);
     };
 }
Пример #3
0
        public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, WorldRenderer worldRenderer, Action <bool> hideMenu)
        {
            var player      = world.LocalPlayer;
            var playerPanel = widget.Get <ScrollPanelWidget>("PLAYER_LIST");

            if (player != null && !player.NonCombatant)
            {
                var checkbox    = widget.Get <CheckboxWidget>("STATS_CHECKBOX");
                var statusLabel = widget.Get <LabelWidget>("STATS_STATUS");

                checkbox.IsChecked    = () => player.WinState != WinState.Undefined;
                checkbox.GetCheckType = () => player.WinState == WinState.Won ?
                                        "checked" : "crossed";

                if (player.HasObjectives)
                {
                    var mo = player.PlayerActor.Trait <MissionObjectives>();
                    checkbox.GetText = () => mo.Objectives.First().Description;
                }

                statusLabel.GetText = () => player.WinState == WinState.Won ? "Accomplished" :
                                      player.WinState == WinState.Lost ? "Failed" : "In progress";
                statusLabel.GetColor = () => player.WinState == WinState.Won ? Color.LimeGreen :
                                       player.WinState == WinState.Lost ? Color.Red : Color.White;
            }
            else
            {
                // Expand the stats window to cover the hidden objectives
                var objectiveGroup = widget.Get("OBJECTIVE");
                var statsHeader    = widget.Get("STATS_HEADERS");

                objectiveGroup.Visible     = false;
                statsHeader.Bounds.Y      -= objectiveGroup.Bounds.Height;
                playerPanel.Bounds.Y      -= objectiveGroup.Bounds.Height;
                playerPanel.Bounds.Height += objectiveGroup.Bounds.Height;
            }

            var teamTemplate      = playerPanel.Get <ScrollItemWidget>("TEAM_TEMPLATE");
            var playerTemplate    = playerPanel.Get("PLAYER_TEMPLATE");
            var spectatorTemplate = playerPanel.Get("SPECTATOR_TEMPLATE");

            playerPanel.RemoveChildren();

            var teams = world.Players.Where(p => !p.NonCombatant && p.Playable)
                        .Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault <PlayerStatistics>()))
                        .OrderByDescending(p => p.PlayerStatistics?.Experience ?? 0)
                        .GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
                        .OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics?.Experience ?? 0));

            foreach (var t in teams)
            {
                if (teams.Count() > 1)
                {
                    var teamHeader = ScrollItemWidget.Setup(teamTemplate, () => true, () => { });
                    teamHeader.Get <LabelWidget>("TEAM").GetText = () => t.Key == 0 ? "No Team" : "Team {0}".F(t.Key);
                    var teamRating       = teamHeader.Get <LabelWidget>("TEAM_SCORE");
                    var scoreCache       = new CachedTransform <int, string>(s => s.ToString());
                    var teamMemberScores = t.Select(tt => tt.PlayerStatistics).Where(s => s != null).ToArray().Select(s => s.Experience);
                    teamRating.GetText = () => scoreCache.Update(teamMemberScores.Sum());

                    playerPanel.AddChild(teamHeader);
                }

                foreach (var p in t.ToList())
                {
                    var pp     = p.Player;
                    var client = world.LobbyInfo.ClientWithIndex(pp.ClientIndex);
                    var item   = playerTemplate.Clone();
                    LobbyUtils.SetupProfileWidget(item, client, orderManager, worldRenderer);

                    var nameLabel = item.Get <LabelWidget>("NAME");
                    WidgetUtils.BindPlayerNameAndStatus(nameLabel, pp);
                    nameLabel.GetColor = () => pp.Color;

                    var flag = item.Get <ImageWidget>("FACTIONFLAG");
                    flag.GetImageCollection = () => "flags";
                    if (player == null || player.RelationshipWith(pp) == PlayerRelationship.Ally || player.WinState != WinState.Undefined)
                    {
                        flag.GetImageName = () => pp.Faction.InternalName;
                        var factionName = pp.Faction.Name != pp.DisplayFaction.Name ? "{0} ({1})".F(pp.DisplayFaction.Name, pp.Faction.Name) : pp.Faction.Name;
                        item.Get <LabelWidget>("FACTION").GetText = () => factionName;
                    }
                    else
                    {
                        flag.GetImageName = () => pp.DisplayFaction.InternalName;
                        item.Get <LabelWidget>("FACTION").GetText = () => pp.DisplayFaction.Name;
                    }

                    var scoreCache = new CachedTransform <int, string>(s => s.ToString());
                    item.Get <LabelWidget>("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics?.Experience ?? 0);

                    playerPanel.AddChild(item);
                }
            }

            var spectators = orderManager.LobbyInfo.Clients.Where(c => c.IsObserver).ToList();

            if (spectators.Any())
            {
                var spectatorHeader = ScrollItemWidget.Setup(teamTemplate, () => true, () => { });
                spectatorHeader.Get <LabelWidget>("TEAM").GetText = () => "Spectators";

                playerPanel.AddChild(spectatorHeader);

                foreach (var client in spectators)
                {
                    var item = spectatorTemplate.Clone();
                    LobbyUtils.SetupProfileWidget(item, client, orderManager, worldRenderer);

                    var nameLabel = item.Get <LabelWidget>("NAME");
                    var nameFont  = Game.Renderer.Fonts[nameLabel.Font];

                    var suffixLength = new CachedTransform <string, int>(s => nameFont.Measure(s).X);
                    var name         = new CachedTransform <(string Name, string Suffix), string>(c =>
                                                                                                  WidgetUtils.TruncateText(c.Name, nameLabel.Bounds.Width - suffixLength.Update(c.Suffix), nameFont) + c.Suffix);

                    nameLabel.GetText = () =>
                    {
                        var suffix = client.State == Session.ClientState.Disconnected ? " (Gone)" : "";
                        return(name.Update((client.Name, suffix)));
                    };

                    var kickButton = item.Get <ButtonWidget>("KICK");
                    kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient.Index && client.State != Session.ClientState.Disconnected;
                    kickButton.OnClick   = () =>
                    {
                        hideMenu(true);
                        ConfirmationDialogs.ButtonPrompt(
                            title: "Kick {0}?".F(client.Name),
                            text: "They will not be able to rejoin this game.",
                            onConfirm: () =>
                        {
                            orderManager.IssueOrder(Order.Command("kick {0} {1}".F(client.Index, false)));
                            hideMenu(false);
                        },
                            onCancel: () => hideMenu(false),
                            confirmText: "Kick");
                    };

                    playerPanel.AddChild(item);
                }
            }
        }
Пример #4
0
        public ObserverShroudSelectorLogic(Widget widget, ModData modData, World world, WorldRenderer worldRenderer, Dictionary <string, MiniYaml> logicArgs)
        {
            this.world = world;

            MiniYaml yaml;

            if (logicArgs.TryGetValue("CombinedViewKey", out yaml))
            {
                combinedViewKey = modData.Hotkeys[yaml.Value];
            }

            if (logicArgs.TryGetValue("WorldViewKey", out yaml))
            {
                worldViewKey = modData.Hotkeys[yaml.Value];
            }

            limitViews = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector);

            var groups = new Dictionary <string, IEnumerable <CameraOption> >();

            combined      = new CameraOption(this, world, "All Players", world.Players.First(p => p.InternalName == "Everyone"));
            disableShroud = new CameraOption(this, world, "Disable Shroud", null);
            if (!limitViews)
            {
                groups.Add("Other", new List <CameraOption>()
                {
                    combined, disableShroud
                });
            }

            teams = world.Players.Where(p => !p.NonCombatant && p.Playable)
                    .Select(p => new CameraOption(this, p))
                    .GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
                    .OrderBy(g => g.Key);

            var noTeams = teams.Count() == 1;

            foreach (var t in teams)
            {
                var label = noTeams ? "Players" : t.Key == 0 ? "No Team" : "Team {0}".F(t.Key);
                groups.Add(label, t);
            }

            var shroudSelector = widget.Get <DropDownButtonWidget>("SHROUD_SELECTOR");

            shroudSelector.OnMouseDown = _ =>
            {
                Func <CameraOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item     = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
                    var showFlag = option.Faction != null;

                    var label = item.Get <LabelWidget>("LABEL");
                    label.IsVisible = () => showFlag;
                    label.GetColor  = () => option.Color;

                    if (showFlag)
                    {
                        WidgetUtils.BindPlayerNameAndStatus(label, option.Player);
                    }
                    else
                    {
                        label.GetText = () => option.Label;
                    }

                    var flag = item.Get <ImageWidget>("FLAG");
                    flag.IsVisible          = () => showFlag;
                    flag.GetImageCollection = () => "flags";
                    flag.GetImageName       = () => option.Faction;

                    var labelAlt = item.Get <LabelWidget>("NOFLAG_LABEL");
                    labelAlt.IsVisible = () => !showFlag;
                    labelAlt.GetText   = () => option.Label;
                    labelAlt.GetColor  = () => option.Color;

                    return(item);
                };

                shroudSelector.ShowDropDown("SPECTATOR_DROPDOWN_TEMPLATE", 400, groups, setupItem);
            };

            shroudLabel           = shroudSelector.Get <LabelWidget>("LABEL");
            shroudLabel.IsVisible = () => selected.Faction != null;
            shroudLabel.GetText   = () => selected.Label;
            shroudLabel.GetColor  = () => selected.Color;

            var shroudFlag = shroudSelector.Get <ImageWidget>("FLAG");

            shroudFlag.IsVisible          = () => selected.Faction != null;
            shroudFlag.GetImageCollection = () => "flags";
            shroudFlag.GetImageName       = () => selected.Faction;

            var shroudLabelAlt = shroudSelector.Get <LabelWidget>("NOFLAG_LABEL");

            shroudLabelAlt.IsVisible = () => selected.Faction == null;
            shroudLabelAlt.GetText   = () => selected.Label;
            shroudLabelAlt.GetColor  = () => selected.Color;

            var keyhandler = shroudSelector.Get <LogicKeyListenerWidget>("SHROUD_KEYHANDLER");

            keyhandler.AddHandler(HandleKeyPress);

            selected = limitViews ? groups.First().Value.First() : world.WorldActor.Owner.Shroud.ExploreMapEnabled ? combined : disableShroud;
            selected.OnClick();

            // Enable zooming out to fractional zoom levels
            worldRenderer.Viewport.UnlockMinimumZoom(0.5f);
        }