Example #1
0
        private void RefreshServerView()
        {
            int scrollPos = _lastScrollPositions[(int)_viewState];

            Server selected = shardListControl.SelectedItem == null ? null : shardListControl.SelectedItem.Server;

            shardListControl.Items.Clear();

            Server[] servers = null;

            switch (_viewState)
            {
            case ServerListViewState.PublicServers:
                btnPublicServers.Select();
                servers = _storageService.PublicServers;
                Text    = string.Format("ConnectUO - {0} - Public Servers", _applicationService.FormattedVersionString);
                break;

            case ServerListViewState.FavoritesServers:
                btnFavoriteServers.Select();
                servers = _storageService.FavoriteServers;
                Text    = string.Format("ConnectUO - {0} - Favorites", _applicationService.FormattedVersionString);
                break;

            default:
                btnLocalServer.Select();
                servers = _storageService.LocalServers;
                Text    = string.Format("ConnectUO - {0} - Local Servers", _applicationService.FormattedVersionString);
                break;
            }

            _comparer.OrderBy = (ServerListOrderBy)cboSortBy.SelectedIndex;
            _comparer.Reverse = chkReverseSortBy.Checked;

            Array.Sort(servers, _comparer);

            for (int i = 0; i < servers.Length; i++)
            {
                Server shard = servers[i];

                if (string.IsNullOrEmpty(txtFilter.Text) ||
                    (shard.Name.ToLower().Contains(txtFilter.Text.ToLower()) || shard.Description.ToLower().Contains(txtFilter.Text.ToLower())))
                {
                    ShardListItem item = new ShardListItem(shard);

                    item.Buttons.Add(new PlayShardListItemButton(item));

                    if (!shard.Favorite && shard.Public)
                    {
                        item.Buttons.Add(new AddToFavoritesShardListItemButton(item));
                        //item.Buttons.Add(new HideListItemButton(item));
                    }

                    if (shard.Favorite && _viewState == ServerListViewState.FavoritesServers)
                    {
                        item.Buttons.Add(new RemoveFavoriteShardListItemButton(item));
                    }

                    if (!shard.Public)
                    {
                        item.Buttons.Add(new EditLocalShardListItemButton(item));
                        item.Buttons.Add(new RemoveCustomShardListItemButton(item));
                    }
                    else
                    {
                        item.Buttons.Add(new WebsiteListItemButton(item));
                    }

                    if (shard.HasPatches)
                    {
                        item.Buttons.Add(new ResetPatchesListItemButton(item));
                    }

                    shardListControl.Items.Add(item);
                }
            }

            shardListControl.ScrollPosition = scrollPos;

            if (selected != null && selected is Server)
            {
                Server selectedServer = (Server)selected;

                for (int i = 0; i < shardListControl.Items.Count; i++)
                {
                    Server shard = (Server)shardListControl.Items[i].Server;

                    if (shard.Name == selectedServer.Name)
                    {
                        shardListControl.SelectedItem = shardListControl.Items[i];
                        break;
                    }
                }
            }

            pbLogo.Visible = shardListControl.Items.Count == 0;
            shardListControl.Invalidate();
        }
        private void RefreshServerView()
        {
            int scrollPos = _lastScrollPositions[(int)_viewState];

            Server selected = shardListControl.SelectedItem == null ? null : shardListControl.SelectedItem.Server;

            shardListControl.Items.Clear();

            Server[] servers = null;

            switch (_viewState)
            {
                case ServerListViewState.PublicServers:
                    btnPublicServers.Select();
                    servers = _storageService.PublicServers;
                    Text = string.Format("ConnectUO - {0} - Public Servers", _applicationService.FormattedVersionString);
                    break;
                case ServerListViewState.FavoritesServers:
                    btnFavoriteServers.Select();
                    servers = _storageService.FavoriteServers;
                    Text = string.Format("ConnectUO - {0} - Favorites", _applicationService.FormattedVersionString);
                    break;
                default:
                    btnLocalServer.Select();
                    servers = _storageService.LocalServers;
                    Text = string.Format("ConnectUO - {0} - Local Servers", _applicationService.FormattedVersionString);
                    break;
            }

            _comparer.OrderBy = (ServerListOrderBy)cboSortBy.SelectedIndex;
            _comparer.Reverse = chkReverseSortBy.Checked;

            Array.Sort(servers, _comparer);

            for (int i = 0; i < servers.Length; i++)
            {
                Server shard = servers[i];

                if (string.IsNullOrEmpty(txtFilter.Text) ||
                    (shard.Name.ToLower().Contains(txtFilter.Text.ToLower()) || shard.Description.ToLower().Contains(txtFilter.Text.ToLower())))
                {
                    ShardListItem item = new ShardListItem(shard);

                    item.Buttons.Add(new PlayShardListItemButton(item));

                    if (!shard.Favorite && shard.Public)
                    {
                        item.Buttons.Add(new AddToFavoritesShardListItemButton(item));
                        //item.Buttons.Add(new HideListItemButton(item));
                    }

                    if (shard.Favorite && _viewState == ServerListViewState.FavoritesServers)
                    {
                        item.Buttons.Add(new RemoveFavoriteShardListItemButton(item));
                    }

                    if (!shard.Public)
                    {
                        item.Buttons.Add(new EditLocalShardListItemButton(item));
                        item.Buttons.Add(new RemoveCustomShardListItemButton(item));
                    }
                    else
                    {
                        item.Buttons.Add(new WebsiteListItemButton(item));
                    }

                    if (shard.HasPatches)
                    {
                        item.Buttons.Add(new ResetPatchesListItemButton(item));
                    }

                    shardListControl.Items.Add(item);
                }
            }

            shardListControl.ScrollPosition = scrollPos;

            if (selected != null && selected is Server)
            {
                Server selectedServer = (Server)selected;

                for (int i = 0; i < shardListControl.Items.Count; i++)
                {
                    Server shard = (Server)shardListControl.Items[i].Server;

                    if (shard.Name == selectedServer.Name)
                    {
                        shardListControl.SelectedItem = shardListControl.Items[i];
                        break;
                    }
                }
            }

            pbLogo.Visible = shardListControl.Items.Count == 0;
            shardListControl.Invalidate();
        }