Esempio n. 1
0
        private void UpdateContent()
        {
            if (!GangOSClient.PlayerList.Any())
            {
                if (Controls.OfType <CharacterItem>().Any())
                {
                    CleanUp(Controls.OfType <CharacterItem>().ToList());
                }

                labelNoCharacters.Visible = true;
                return;
            }

            Dictionary <Player, CharacterItem> items = Controls.OfType <CharacterItem>().ToDictionary(page => (Player)page.Tag);

            List <Player> players = new List <Player>();

            players.AddRange(GangOSClient.PlayerList);

            int index = 0;
            List <CharacterItem> CharacterItems = Controls.OfType <CharacterItem>().ToList();

            foreach (var ls in players)
            {
                CharacterItem currentCharacterItem = (index < CharacterItems.Count ? CharacterItems[index] : null);
                Player        currentTag           = currentCharacterItem != null ? (Player)currentCharacterItem.Tag : null;

                if (currentTag != ls)
                {
                    CharacterItem CharacterItem;
                    if (items.TryGetValue(ls, out CharacterItem))
                    {
                        CharacterItems.Remove(CharacterItem);
                    }
                    else
                    {
                        CharacterItem = GetCharacterItem(ls);
                    }

                    CharacterItems.Insert(index, CharacterItem);
                }

                if (ls != null)
                {
                    items.Remove(ls);
                }

                index++;
            }

            CleanUp(items.Values.ToList());
            foreach (var item in items.Values)
            {
                CharacterItems.Remove(item);
            }

            Controls.AddRange(CharacterItems.ToArray <Control>());

            PerformCustomLayout();
        }
Esempio n. 2
0
        private CharacterItem GetCharacterItem(Player player)
        {
            CharacterItem CharacterItem;
            CharacterItem tempCharacterItem = null;

            try
            {
                tempCharacterItem           = new CharacterItem(player);
                tempCharacterItem.onClick  += item_Click;
                tempCharacterItem.Clickable = true;

                tempCharacterItem.CreateControl();

                CharacterItem     = tempCharacterItem;
                tempCharacterItem = null;
            }
            finally
            {
                if (tempCharacterItem != null)
                {
                    tempCharacterItem.Dispose();
                }
            }

            return(CharacterItem);
        }
Esempio n. 3
0
        private void PerformCustomLayout()
        {
            if (!Visible)
            {
                return;
            }

            IEnumerable <CharacterItem> CharacterItems = Controls.OfType <CharacterItem>();

            int numControls = CharacterItems.Count();

            if (numControls == 0)
            {
                return;
            }

            const int Pad = 20;

            int scrollBarPosition = VerticalScroll.Value;

            VerticalScroll.Value = 0;

            SuspendLayout();
            try
            {
                int itemWidth = CharacterItems.First().PreferredSize.Width;

                int numColumns = Math.Max(1, Math.Min(numControls, ClientSize.Width / itemWidth));

                int neededWidth = numColumns * (itemWidth + Pad) - Pad;
                int marginH     = Math.Max(0, (ClientSize.Width - neededWidth) / 2);

                int rowIndex  = 0;
                int rowHeight = 0;
                int height    = 0;
                foreach (var CharacterItem in CharacterItems)
                {
                    rowHeight = Math.Max(rowHeight, CharacterItem.PreferredSize.Height);
                    rowIndex++;

                    if (rowIndex != numColumns)
                    {
                        continue;
                    }

                    height   += rowHeight + Pad;
                    rowHeight = 0;
                    rowIndex  = 0;
                }

                height -= Pad;
                int marginV = Math.Max(0, (ClientSize.Height - height) / 3);

                rowIndex  = 0;
                rowHeight = 0;
                height    = marginV;
                foreach (var CharacterItem in CharacterItems)
                {
                    CharacterItem.SetBounds(marginH + rowIndex * (itemWidth + Pad), height, CharacterItem.PreferredSize.Width,
                                            CharacterItem.PreferredSize.Height);
                    rowHeight = Math.Max(rowHeight, CharacterItem.PreferredSize.Height);
                    rowIndex++;

                    if (rowIndex != numColumns)
                    {
                        continue;
                    }

                    height   += rowHeight + Pad;
                    rowHeight = 0;
                    rowIndex  = 0;
                }
            }
            finally
            {
                ResumeLayout(true);
                labelNoCharacters.Visible = !GangOSClient.PlayerList.Any();

                //VScroll = true;

                VerticalScroll.Value = scrollBarPosition;
            }
        }