public UniverseTable(Screen screen, UniverseGroup universeGroup, Brush backColorBrush) { this.universeGroup = universeGroup; this.screen = screen; this.backColorBrush = backColorBrush; teamTables = new Dictionary <string, UniverseTeamTable>(); UniverseTeamTable teamTable = null; foreach (Team team in universeGroup.Teams) { SolidColorBrush teamColor = SolidColorBrushes.TeamColors[team.Name]; teamTable = new UniverseTeamTable(screen, team, teamColor); teamTables.Add(team.Name, teamTable); } }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="renderTarget"></param> public void Draw(float x, float y, float width, float height, RenderTarget renderTarget) { Dictionary <string, List <Player> > playerList = new Dictionary <string, List <Player> >(); Dictionary <string, SharpDX.Direct2D1.Bitmap> deletable = new Dictionary <string, Bitmap>(ImageCollections.PlayersSmallAvatars); foreach (Player player in universeGroup.Players) { if (player.IsOnline) { if (player.Team != null && !playerList.ContainsKey(player.Team.Name)) { playerList.Add(player.Team.Name, new List <Player>()); } if (deletable.ContainsKey(player.Name)) { deletable.Remove(player.Name); } else { Bitmap avatar; System.Drawing.Bitmap tempBitmap = null; try { if (player.IsActive) { byte[] data = player.SmallAvatarRAW; if (data != null && data.Length > 0) { tempBitmap = new System.Drawing.Bitmap(new System.IO.MemoryStream(data)); } } } catch { } if (tempBitmap != null) { System.Drawing.Bitmap smallAvatar = new System.Drawing.Bitmap(tempBitmap, new System.Drawing.Size(32, 32)); avatar = BitmapConverter.ToSharpDXBitmap(renderTarget, smallAvatar); tempBitmap.Dispose(); } else { avatar = null; } if (player != null) { ImageCollections.PlayersSmallAvatars.Add(player.Name, avatar); } } if (player != null && player.Team != null) { playerList[player.Team.Name].Add(player); } } } foreach (KeyValuePair <string, Bitmap> kvp in deletable) { if (kvp.Value != null) { kvp.Value.Dispose(); } ImageCollections.PlayersSmallAvatars.Remove(kvp.Key); } float currentHeight = height; float currentY = y; foreach (Team team in universeGroup.Teams) { List <Player> players; if (!playerList.TryGetValue(team.Name, out players)) { players = new List <Player>(); } UniverseTeamTable teamTable = teamTables[team.Name]; teamTable.Update(players, x, currentY, width, currentHeight); currentHeight -= teamTable.Height; currentY += teamTable.Height + 20f; } roundedRectangle = new RoundedRectangle(); roundedRectangle.RadiusX = 8; roundedRectangle.RadiusY = 8; rect = new RectangleF(x, y, width, height); roundedRectangle.Rect = rect; renderTarget.FillRoundedRectangle(roundedRectangle, backColorBrush); renderTarget.DrawRoundedRectangle(roundedRectangle, SolidColorBrushes.White); foreach (UniverseTeamTable teamTable in teamTables.Values) { teamTable.Draw(renderTarget); } }
public Row(SharpDX.DirectWrite.Factory directWriteFactory, SolidColorBrush textColor, UniverseTeamTable teamTable, PlayerEntry playerEntry, float x, float y, float width, float height) { X = x; Y = y; Width = width; rowContent = new List <IFixedDrawable>(); disposables = new List <IDisposable>(); Height = 0f; try { float columnWidth = 0f; foreach (Column column in teamTable.Columns) { if (PlayerEntry.PropertyInfos[column.FieldName].PropertyType == typeof(SharpDX.Direct2D1.Bitmap)) { Bitmap bitmap = (SharpDX.Direct2D1.Bitmap)PlayerEntry.PropertyInfos[column.FieldName].GetValue(playerEntry); ImageBox imageBox = new ImageBox(bitmap, x + UniverseTeamTable.PADDING + columnWidth, y); if (imageBox.Bitmap.PixelSize.Height > Height) { Height = imageBox.Bitmap.PixelSize.Height; } rowContent.Add(imageBox); } else { Label label = new Label(directWriteFactory, PlayerEntry.PropertyInfos[column.FieldName].GetValue(playerEntry).ToString(), FormFonts.NormalTextFont, textColor, x + UniverseTeamTable.PADDING + columnWidth, y, width, height); disposables.Add(label); if (label.TextLayout.Metrics.Height > Height) { Height = label.TextLayout.Metrics.Height; } rowContent.Add(label); } columnWidth += column.Width; } } catch { } rowLine = new Line(new Vector2(x + UniverseTeamTable.PADDING, y + Height), new Vector2(x - UniverseTeamTable.PADDING + Width, y + Height), textColor); }