private void AuthorsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (AuthorsListBox.SelectedItem == null) { return; } authorSelection = (AuthorListEntry)(AuthorsListBox.SelectedItem as ListBoxItem).Tag; if (authorSelection.Name == SpawnsetListHandler.AllAuthors) { foreach (Grid grid in SpawnsetsList.Children) { grid.Visibility = Visibility.Visible; SetBackgroundColor(grid); } } else { foreach (Grid grid in SpawnsetsList.Children) { grid.Visibility = (grid.Tag as SpawnsetListEntry).SpawnsetFile.Author == authorSelection.Name ? Visibility.Visible : Visibility.Collapsed; SetBackgroundColor(grid); } } }
private Grid CreateAuthorGrid(AuthorListEntry author) { Label authorLabel = new Label { Content = author.Name }; Grid.SetColumn(authorLabel, 0); Label spawnsetCountLabel = new Label { Content = author.SpawnsetCount, HorizontalAlignment = HorizontalAlignment.Right }; Grid.SetColumn(spawnsetCountLabel, 1); Grid grid = new Grid { Tag = author }; grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.Children.Add(authorLabel); grid.Children.Add(spawnsetCountLabel); return(grid); }
public bool RetrieveSpawnsetList() { try { Spawnsets.Clear(); Authors.Clear(); string downloadString = string.Empty; using (TimeoutWebClient client = new TimeoutWebClient(Timeout)) downloadString = client.DownloadString(UrlUtils.ApiGetSpawnsets); List <SpawnsetFile> spawnsetFiles = JsonConvert.DeserializeObject <List <SpawnsetFile> >(downloadString); Authors.Add(new AuthorListEntry(SpawnsetListHandler.AllAuthors, spawnsetFiles.Count)); foreach (SpawnsetFile sf in spawnsetFiles) { AuthorListEntry author = new AuthorListEntry(sf.Author, spawnsetFiles.Where(s => s.Author == sf.Author).Count()); if (!Authors.Any(a => a.Name == author.Name)) { Authors.Add(author); } } foreach (SpawnsetFile spawnsetFile in spawnsetFiles) { Spawnsets.Add(new SpawnsetListEntry { SpawnsetFile = spawnsetFile }); } return(true); } catch (WebException ex) { App.Instance.ShowError("Error retrieving spawnset list", $"Could not connect to '{UrlUtils.ApiGetSpawnsets}'.", ex); return(false); } catch (Exception ex) { App.Instance.ShowError("Unexpected error", "An unexpected error occurred.", ex); return(false); } }
private Image generateAuthorListB(bool show_twitter_id) { int shadow_shift = 2; string font_name = "Arial"; Font font = new Font(font_name, java.awt.Font.PLAIN, FONT_SIZE); Dimension size = Util.measureString("the quick brown fox jumped over the lazy dogs. THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS. 0123456789", font); int width = this.Width; int height = size.height; //StringFormat sf = new StringFormat(); Image ret = new Image(); ret.image = new System.Drawing.Bitmap((int)width, (int)(40f + m_credit.Length * height * 1.1f), System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics2D g = new Graphics2D(System.Drawing.Graphics.FromImage(ret.image)); g.setColor(Color.white); g.fillRect(0, 0, ret.getWidth(null), ret.getHeight(null)); int align = 0; int valign = 0; //sf.Alignment = StringAlignment.Center; Font f = new Font(font_name, java.awt.Font.BOLD, (int)(FONT_SIZE * 1.2f)); if (m_shadow_enablde) { g.setColor(new Color(0, 0, 0, 40)); PortUtil.drawStringEx( g, m_app_name, f, new Rectangle(shadow_shift, shadow_shift, width, height), align, valign); } g.setColor(Color.black); PortUtil.drawStringEx( g, m_app_name, f, new Rectangle(0, 0, width, height), align, valign); for (int i = 0; i < m_credit.Length; i++) { AuthorListEntry itemi = m_credit[i]; Font f2 = new Font(font_name, itemi.getStyle(), FONT_SIZE); string id = show_twitter_id ? itemi.getTwitterID() : ""; if (id == null) { id = ""; } string str = itemi.getName() + (id.Equals("") ? "" : (" (" + id + ")")); if (m_shadow_enablde) { g.setColor(new Color(0, 0, 0, 40)); PortUtil.drawStringEx( g, str, font, new Rectangle(0 + shadow_shift, 40 + (int)(i * height * 1.1) + shadow_shift, width, height), align, valign); } g.setColor(Color.black); PortUtil.drawStringEx( g, str, f2, new Rectangle(0, 40 + (int)(i * height * 1.1), width, height), align, valign); } return(ret); }