Exemple #1
0
        public void RefreshServerListInner(IEnumerable <GameServer> games)
        {
            if (games == null)
            {
                return;
            }

            var rows = new List <Widget>();

            foreach (var loop in games.OrderByDescending(g => g.CanJoin()).ThenByDescending(g => g.Players))
            {
                var game = loop;
                if (game == null)
                {
                    continue;
                }

                var canJoin = game.CanJoin();

                var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));

                var map     = Game.modData.MapCache[game.Map];
                var preview = item.GetOrNull <MapPreviewWidget>("MAP_PREVIEW");
                if (preview != null)
                {
                    preview.Preview = () => map;
                }

                var title = item.GetOrNull <LabelWidget>("TITLE");
                if (title != null)
                {
                    title.GetText  = () => game.Name;
                    title.GetColor = () => canJoin ? title.TextColor : Color.Gray;
                }

                var maptitle = item.GetOrNull <LabelWidget>("MAP");
                if (title != null)
                {
                    maptitle.GetText  = () => map.Title;
                    maptitle.GetColor = () => canJoin ? maptitle.TextColor : Color.Gray;
                }

                var players = item.GetOrNull <LabelWidget>("PLAYERS");
                if (players != null)
                {
                    players.GetText  = () => "{0} / {1}".F(game.Players, map.PlayerCount);
                    players.GetColor = () => canJoin ? players.TextColor : Color.Gray;
                }

                var state = item.GetOrNull <LabelWidget>("STATE");
                if (state != null)
                {
                    state.GetText  = () => GetStateLabel(game);
                    state.GetColor = () => canJoin ? state.TextColor : Color.Gray;
                }

                var ip = item.GetOrNull <LabelWidget>("IP");
                if (ip != null)
                {
                    ip.GetText  = () => game.Address;
                    ip.GetColor = () => canJoin ? ip.TextColor : Color.Gray;
                }

                var version = item.GetOrNull <LabelWidget>("VERSION");
                if (version != null)
                {
                    version.GetText   = () => GenerateModLabel(game);
                    version.IsVisible = () => !game.CompatibleVersion();
                    version.GetColor  = () => canJoin ? version.TextColor : Color.Gray;
                }

                var location = item.GetOrNull <LabelWidget>("LOCATION");
                if (location != null)
                {
                    var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
                    location.GetText   = () => cachedServerLocation;
                    location.IsVisible = () => game.CompatibleVersion();
                    location.GetColor  = () => canJoin ? location.TextColor : Color.Gray;
                }

                if (!Filtered(game))
                {
                    rows.Add(item);
                }
            }

            Game.RunAfterTick(() =>
            {
                serverList.RemoveChildren();
                currentServer = null;

                if (games == null)
                {
                    searchStatus = SearchStatus.Failed;
                    return;
                }

                if (!games.Any())
                {
                    searchStatus = SearchStatus.NoGames;
                    return;
                }

                currentServer = games.FirstOrDefault();
                searchStatus  = SearchStatus.Hidden;

                // Search for any unknown maps
                if (Game.Settings.Game.AllowDownloading)
                {
                    Game.modData.MapCache.QueryRemoteMapDetails(games.Where(g => !Filtered(g)).Select(g => g.Map));
                }

                foreach (var row in rows)
                {
                    serverList.AddChild(row);
                }
            });
        }
Exemple #2
0
        public void RefreshServerList(Widget panel, IEnumerable <GameServer> games)
        {
            var sl = panel.Get <ScrollPanelWidget>("SERVER_LIST");

            searchStatus = SearchStatus.Fetching;

            sl.RemoveChildren();
            currentServer = null;

            if (games == null)
            {
                searchStatus = SearchStatus.Failed;
                return;
            }

            if (games.Count() == 0)
            {
                searchStatus = SearchStatus.NoGames;
                return;
            }

            searchStatus  = SearchStatus.Hidden;
            currentServer = games.FirstOrDefault();

            foreach (var loop in games.OrderByDescending(g => g.CanJoin()).ThenByDescending(g => g.Players))
            {
                var game = loop;

                var canJoin = game.CanJoin();

                var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));

                var preview = item.Get <MapPreviewWidget>("MAP_PREVIEW");
                preview.Map       = () => GetMapPreview(game);
                preview.IsVisible = () => GetMapPreview(game) != null;

                var title = item.Get <LabelWidget>("TITLE");
                title.GetText = () => game.Name;

                // TODO: Use game.MapTitle once the server supports it
                var maptitle = item.Get <LabelWidget>("MAP");
                maptitle.GetText = () =>
                {
                    var map = Game.modData.FindMapByUid(game.Map);
                    return(map == null ? "Unknown Map" : map.Title);
                };

                // TODO: Use game.MaxPlayers once the server supports it
                var players = item.Get <LabelWidget>("PLAYERS");
                players.GetText = () => GetPlayersLabel(game);

                var state = item.Get <LabelWidget>("STATE");
                state.GetText = () => GetStateLabel(game);

                var ip = item.Get <LabelWidget>("IP");
                ip.GetText = () => game.Address;

                var version = item.Get <LabelWidget>("VERSION");
                version.GetText   = () => GenerateModsLabel(game);
                version.IsVisible = () => !game.CompatibleVersion();

                var location             = item.Get <LabelWidget>("LOCATION");
                var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
                location.GetText   = () => cachedServerLocation;
                location.IsVisible = () => game.CompatibleVersion();

                if (!canJoin)
                {
                    title.GetColor    = () => Color.Gray;
                    maptitle.GetColor = () => Color.Gray;
                    players.GetColor  = () => Color.Gray;
                    state.GetColor    = () => Color.Gray;
                    ip.GetColor       = () => Color.Gray;
                    version.GetColor  = () => Color.Gray;
                    location.GetColor = () => Color.Gray;
                }

                if (!Filtered(game))
                {
                    sl.AddChild(item);
                }
            }
        }
Exemple #3
0
        public ClientTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex)
        {
            var admin     = widget.Get <LabelWidget>("ADMIN");
            var adminFont = Game.Renderer.Fonts[admin.Font];

            var latency     = widget.Get <LabelWidget>("LATENCY");
            var latencyFont = Game.Renderer.Fonts[latency.Font];

            var latencyPrefix     = widget.Get <LabelWidget>("LATENCY_PREFIX");
            var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font];

            var ip     = widget.Get <LabelWidget>("IP");
            var ipFont = Game.Renderer.Fonts[ip.Font];

            var location     = widget.Get <LabelWidget>("LOCATION");
            var locationFont = Game.Renderer.Fonts[location.Font];

            var locationOffset = location.Bounds.Y;
            var ipOffset       = ip.Bounds.Y;
            var latencyOffset  = latency.Bounds.Y;
            var tooltipHeight  = widget.Bounds.Height;

            var margin = widget.Bounds.Width;

            tooltipContainer.IsVisible    = () => (orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null);
            tooltipContainer.BeforeRender = () =>
            {
                var latencyPrefixSize = latencyPrefix.Bounds.X + latencyPrefixFont.Measure(latencyPrefix.GetText() + " ").X;
                var width             = Math.Max(locationFont.Measure(location.GetText()).X, (Math.Max(adminFont.Measure(admin.GetText()).X,
                                                                                                       Math.Max(ipFont.Measure(ip.GetText()).X, latencyPrefixSize + latencyFont.Measure(latency.GetText()).X))));
                widget.Bounds.Width   = width + 2 * margin;
                latency.Bounds.Width  = widget.Bounds.Width;
                ip.Bounds.Width       = widget.Bounds.Width;
                admin.Bounds.Width    = widget.Bounds.Width;
                location.Bounds.Width = widget.Bounds.Width;

                ip.Bounds.Y          = ipOffset;
                latency.Bounds.Y     = latencyOffset;
                location.Bounds.Y    = locationOffset;
                widget.Bounds.Height = tooltipHeight;

                if (admin.IsVisible())
                {
                    ip.Bounds.Y          += admin.Bounds.Height;
                    latency.Bounds.Y     += admin.Bounds.Height;
                    location.Bounds.Y    += admin.Bounds.Height;
                    widget.Bounds.Height += admin.Bounds.Height;
                }

                latencyPrefix.Bounds.Y = latency.Bounds.Y;
                latency.Bounds.X       = latencyPrefixSize;
            };

            admin.IsVisible  = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin;
            latency.GetText  = () => LobbyUtils.LatencyDescription(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency);
            latency.GetColor = () => LobbyUtils.LatencyColor(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency);
            var ipAddress = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress;

            if ((ipAddress == null || ipAddress == "127.0.0.1") && UPnP.NatDevice != null)
            {
                ipAddress = UPnP.NatDevice.GetExternalIP().ToString();
            }
            var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(ipAddress);

            ip.GetText = () => cachedDescriptiveIP;
            var cachedCountryLookup = LobbyUtils.LookupCountry(ipAddress);

            location.GetText = () => cachedCountryLookup;
        }