//This method produces a comboboxitem for a set given a path public static ComboBoxItem Generate_Set_Item(string set) { //So first we need to make the new combo box item ComboBoxItem item = new ComboBoxItem(); //the tag will store the whole path of the folder for easier access later //plus a full list of the card objects, to reduce file I/O Set_Info new_set = new Set_Info(); new_set.dir = set; new_set.cards = new List <Card>(); //This does however mean that all the work for making these card items happens here //instead of when the card list gets populated if (Directory.Exists(set)) { FileInfo[] files = (new DirectoryInfo(set)).GetFiles(@"*.txt"); //now for each file that matches this search criteria we need to make a new card and add it to the list //remembering to zero index them int index = 0; foreach (FileInfo file in files) { new_set.cards.Add(Card.Generate_Card_From_File(file, index)); index++; } } item.Tag = new_set; item.Content = new DirectoryInfo(set).Name; return(item); }
//This produces a cropped image of the currently selected card and makes it the source for the preview image item //on the screen private void BTN_Preview_Card_Click(object sender, RoutedEventArgs e) { //This should only work if there is a valid card selected if ((ComboBoxItem)CMB_Card_Selector.SelectedItem != null && (Card)((ComboBoxItem)CMB_Card_Selector.SelectedItem).Tag != null) { //Make sure the cards are all as up to date as possible Static_Methods_Container.Update_Current_Card(this); //and that changes wont be lost Set_Info info = (Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag); Functions.Save_Set(info.cards); //First step is to dispose of the existing bitmap source if any in the preview window IMG_Card_Preview.Source = null; //then from the selected card generate a cropped image from the card selected Card c = (Card)((ComboBoxItem)CMB_Card_Selector.SelectedItem).Tag; BitmapImage i; //now make a new image source with standard boxes using (Bitmap b = Card.Generate_Cropped_Image(c, "PREVIEW", @".\Overlays\Overlay.png")) { using (MemoryStream mem = new MemoryStream()) { //save the bitmap to the stream for use of the image b.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp); mem.Position = 0; BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = mem; image.CacheOption = BitmapCacheOption.OnLoad; image.EndInit(); i = image; } } IMG_Card_Preview.Source = i; } }
//This will take the currently selected set, update the current card and generate a set of full bleed sized cards //To a path specified by the user private void BTN_Export_Bleed_Set_Click(object sender, RoutedEventArgs e) { //TODO double check this method //first of all we need to only do this is there is a set selected and its tag is not null if ((ComboBoxItem)CMB_Set_Selector.SelectedItem != null && (Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag) != null) { //Make sure the cards are all as up to date as possible Static_Methods_Container.Update_Current_Card(this); //and that changes wont be lost Set_Info info = (Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag); Functions.Save_Set(info.cards); string set_code = ""; //First of all we need the code used to identify the set in the corner InputDialog input = new InputDialog("Please Enter Set Identifier.\nIn form xxxx where 'x' is a letter or number!"); if (input.ShowDialog() == true) { //We obviously only continue if they dont cancel the dialog set_code = input.Answer(); //we also need to pick the overlay boxes we are using //we need the list of cards out of selected item List <Card> set = ((Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag)).cards; //we also need to make a bleed folder for the images if they dont exist string Bleed_Directory = ((Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag)).dir + @"\Bleed"; Directory.CreateDirectory(Bleed_Directory); //we also need an overlay to use, user can pick but just in case have a default selected string overlay = Card.DEFAULT_OVERLAY; //but give the user a choice OpenFileDialog dialog = new OpenFileDialog(); //set a file filter dialog.Filter = "Image Files (*.png;*.jpg;*.jpeg;*.bmp)|*.png;*.jpg;*.jpeg;*.bmp|All Files (*.*)|*.*"; //and make sure it opens wherever the program is for access to the overlays folder dialog.InitialDirectory = $@"{Directory.GetCurrentDirectory()}\Overlays"; if (dialog.ShowDialog() == true) { //if they selected one set it as the new overlay overlay = dialog.FileName; } //now for sake of efficiency we will generate and save the cards in a parrallel fashion //The limit of 12 concurrent tasks is mostly to avoid out of memory issues since in a stress //situation each iteration can use up to a gig of memory each so not bounding how many //could cause some problems, this still will on lower end systems but shouldn't be an issue //if you arent throwing massive images at it constantly Parallel.ForEach(set, new ParallelOptions { MaxDegreeOfParallelism = 12 }, c => { using (Bitmap b = Card.Generate_Bleed_Image(c, set_code, overlay)) { //The encoder needs some set up to function properly string s = string.Format("{0:00000}", c.Index); string filepath = $@"{Bleed_Directory}\{set_code}-{s}-Bleed.png"; b.Save(filepath, ImageFormat.Png); } }); } } }
private void BTN_Save_Set_Click(object sender, RoutedEventArgs e) { //This saves the entire set of cards currently selected into their respective text files //First we need to make sure the current card is as up do date as can be Static_Methods_Container.Update_Current_Card(this); //Now it's simply a matter of extracting the list of currently selected cards from the set_info of the selected set //Obviously assuming its selected and it has an existant set_info if ((ComboBoxItem)(CMB_Set_Selector.SelectedItem) != null && (Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag) != null) { //Now we know it's safe to do so extract this set info and pass it as a directory to save all the cards Set_Info info = (Set_Info)(((ComboBoxItem)(CMB_Set_Selector.SelectedItem)).Tag); Functions.Save_Set(info.cards); } }
private void BTN_Delete_Set_Click(object sender, RoutedEventArgs e) { //This will target and delete the directory of the selected item assuming a prompt is passed InputDialog input = new InputDialog("Are You Sure You Want To Delete The Selected Set?\nThis Action Cannot Be Undone!\n(y/n)"); if (input.ShowDialog() == true) { if (input.Answer().ToLower() == "y" && CMB_Set_Selector.SelectedItem != null) { //Can't delete what doesnt exist obviously Static_Methods_Container.Clear_Text_Boxes(this); CMB_Card_Selector.SelectedIndex = -1; CMB_Card_Selector.Items.Clear(); //We need to get the directory from the currently selected set Set_Info info = (Set_Info)((ComboBoxItem)CMB_Set_Selector.SelectedItem).Tag; //And use the directory to delete the whole directory //the true at the end indicates recursive delete so as to delete contents as well Directory.Delete(info.dir, true); //Lastly we Remove the currently selected item from the list since it holds nothing anymore CMB_Set_Selector.Items.RemoveAt(CMB_Set_Selector.SelectedIndex); } } }