OpenRA.Mods.Common.Widgets.Logic.ObserverShroudSelectorLogic.ObserverShroudSelectorLogic C# (CSharp) Method

ObserverShroudSelectorLogic() private method

private ObserverShroudSelectorLogic ( OpenRA.Widgets.Widget widget, World world ) : System
widget OpenRA.Widgets.Widget
world World
return System
        public ObserverShroudSelectorLogic(Widget widget, World world)
        {
            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.GetText = () => option.Label;
                    label.GetColor = () => option.Color;

                    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);
            };

            var 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.OnKeyPress = HandleKeyPress;

            selected = limitViews ? groups.First().Value.First() : disableShroud;
            selected.OnClick();
        }