/// <summary> /// Updates all of the current buffer users. /// </summary> public void UpdateBufferUsers() { for (var i = 0; i < UserBuffer.Count; i++) { var bufferObject = UserBuffer.ElementAt(i); // In the event that there aren't any available users left, we want to remove these unused // contained drawable objects. if (AvailableUsers.ElementAtOrDefault(PoolStartingIndex + i) == null) { RemoveContainedDrawable(bufferObject); UserBufferObjectsUsed--; continue; } bufferObject.Y = (PoolStartingIndex + i) * DrawableOnlineUser.HEIGHT; bufferObject.UpdateUser(AvailableUsers[PoolStartingIndex + i]); // Make sure the object is contained if it isn't already. if (bufferObject.Parent != ContentContainer) { AddContainedDrawable(bufferObject); } } }
/// <summary> /// Handles shifting the pool whenever the container is scrolled. /// Also initializing any new objects that need it. /// </summary> /// <param name="direction"></param> private void HandlePoolShifting(Direction direction) { switch (direction) { case Direction.Forward: // If there are no available users then there's no need to do anything. if (AvailableUsers.ElementAtOrDefault(PoolStartingIndex) == null || AvailableUsers.ElementAtOrDefault(PoolStartingIndex + MAX_USERS_SHOWN) == null) { return; } var firstUser = UserBuffer.First(); // Check if the object is in the rect of the ScrollContainer. // If it is, then there's no updating that needs to happen. if (!Rectangle.Intersect(firstUser.ScreenRectangle, ScreenRectangle).IsEmpty) { return; } // Update the user's information and y position. firstUser.Y = (PoolStartingIndex + MAX_USERS_SHOWN) * DrawableOnlineUser.HEIGHT; lock (AvailableUsers) firstUser.UpdateUser(AvailableUsers[PoolStartingIndex + MAX_USERS_SHOWN]); // Circuluarly Shift the list forward one. UserBuffer.RemoveFirst(); UserBuffer.AddLast(firstUser); // Take this user, and place them at the bottom. PoolStartingIndex++; break; case Direction.Backward: // If there are no previous available user then there's no need to shift. if (AvailableUsers.ElementAtOrDefault(PoolStartingIndex - 1) == null) { return; } var lastUser = UserBuffer.Last(); // Check if the object is in the rect of the ScrollContainer. // If it is, then there's no updating that needs to happen. if (!Rectangle.Intersect(lastUser.ScreenRectangle, ScreenRectangle).IsEmpty) { return; } lastUser.Y = (PoolStartingIndex - 1) * DrawableOnlineUser.HEIGHT; lock (AvailableUsers) lastUser.UpdateUser(AvailableUsers[PoolStartingIndex - 1]); UserBuffer.RemoveLast(); UserBuffer.AddFirst(lastUser); PoolStartingIndex--; break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } }