Ejemplo n.º 1
0
        private void dlgSave_FileOk(object sender, CancelEventArgs e)
        {
            if (this.LoadedBlueprint != null)
            {
                SaveFileDialog dlg               = (SaveFileDialog)sender;
                string         fName             = dlg.FileName;
                int            chosenFilterIndex = dlg.FilterIndex;

                if (fName.ToLower().EndsWith(".schem"))
                {
                    Schem2Formatter.writeBlueprint(fName, this.LoadedBlueprint);
                }
                else if (fName.ToLower().EndsWith(".schematic"))
                {
                    if (Materials.List.Any(x => x.IsEnabled && string.IsNullOrWhiteSpace(x.SchematicaMaterialName)))
                    {
                        DialogResult result = MessageBox.Show(this,
                                                              "Cannot create a 1.12 schematic when 1.13+ blocks are selected. Do you want to automatically " +
                                                              "disable invalid materials and restart from the beginning of the rendering process. This " +
                                                              "will remove any material choice overrides or post rendering changes.\n\nYou will need to " +
                                                              "re-render the image.",
                                                              ".schematic does not support 1.13+ blocks!"
                                                              , MessageBoxButtons.YesNo, MessageBoxIcon.Warning
                                                              );

                        if (result == DialogResult.Yes)
                        {
                            Materials.List.Where(x => x.IsEnabled && string.IsNullOrWhiteSpace(x.SchematicaMaterialName))
                            .ToList().ForEach(x => x.IsEnabled = false);
                            Options.Save();
                            this.InvokeEx(c => c.MaterialOptions.Refresh());

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                            TaskManager.Get.StartAsync((token) =>
                            {
                                ColorMatcher.Get.CompileColorPalette(token, true, Materials.List)
                                .ConfigureAwait(true).GetAwaiter().GetResult();
                            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                            return;
                        }
                    }
                    else
                    {
                        SchematicFormatter.writeBlueprint(fName, this.LoadedBlueprint);
                    }
                }
                else if (fName.ToLower().EndsWith(".png"))
                {
                    if (this.renderedImagePanel != null)
                    {
                        this.renderedImagePanel.SaveToPNG(fName);
                    }
                }
                else if (fName.ToLower().EndsWith(".pxlzip"))
                {
                    PixelStackerProjectFormatter.SaveProject(fName);
                }
                else if (fName.ToLower().EndsWith(".csv"))
                {
                    Dictionary <Material, int> materialCounts = new Dictionary <Material, int>();
                    bool isv = Options.Get.IsSideView;
                    int  xM  = this.LoadedBlueprint.Mapper.GetXLength(isv);
                    int  yM  = this.LoadedBlueprint.Mapper.GetYLength(isv);
                    int  zM  = this.LoadedBlueprint.Mapper.GetZLength(isv);
                    for (int x = 0; x < xM; x++)
                    {
                        for (int y = 0; y < yM; y++)
                        {
                            for (int z = 0; z < zM; z++)
                            {
                                Material m = this.LoadedBlueprint.Mapper.GetMaterialAt(isv, x, y, z);
                                if (m != Materials.Air)
                                {
                                    if (!materialCounts.ContainsKey(m))
                                    {
                                        materialCounts.Add(m, 0);
                                    }

                                    materialCounts[m] = materialCounts[m] + 1;
                                }
                            }
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("\"Material\",\"Block Count\",\"Full Stacks needed\"");
                    sb.AppendLine("\"Total\"," + materialCounts.Values.Sum());

                    foreach (var kvp in materialCounts.OrderByDescending(x => x.Value))
                    {
                        sb.AppendLine($"\"{kvp.Key.GetBlockNameAndData(isv).Replace("\"", "\"\"")}\",{kvp.Value},{kvp.Value / 64} stacks and {kvp.Value % 64} remaining blocks");
                    }

                    File.WriteAllText(fName, sb.ToString());
                }
            }
            else
            {
                this.exportSchematicToolStripMenuItem.Enabled = false;
            }
        }
Ejemplo n.º 2
0
        private void dlgSave_FileOk(object sender, CancelEventArgs e)
        {
            if (this.LoadedBlueprint != null)
            {
                SaveFileDialog dlg               = (SaveFileDialog)sender;
                string         fName             = dlg.FileName;
                int            chosenFilterIndex = dlg.FilterIndex;

                if (fName.ToLower().EndsWith(".schem"))
                {
                    SchemFormatter.writeBlueprint(fName, this.LoadedBlueprint);
                }
                else if (fName.ToLower().EndsWith(".schematic"))
                {
                    SchematicFormatter.writeBlueprint(fName, this.LoadedBlueprint);
                }
                else if (fName.ToLower().EndsWith(".png"))
                {
                    if (this.renderedImagePanel != null)
                    {
                        this.renderedImagePanel.SaveToPNG(fName);
                    }
                }
                else if (fName.ToLower().EndsWith(".csv"))
                {
                    Dictionary <Material, int> materialCounts = new Dictionary <Material, int>();
                    bool isv = Options.Get.IsSideView;
                    int  xM  = this.LoadedBlueprint.Mapper.GetXLength(isv);
                    int  yM  = this.LoadedBlueprint.Mapper.GetYLength(isv);
                    int  zM  = this.LoadedBlueprint.Mapper.GetZLength(isv);
                    for (int x = 0; x < xM; x++)
                    {
                        for (int y = 0; y < yM; y++)
                        {
                            for (int z = 0; z < zM; z++)
                            {
                                Material m = this.LoadedBlueprint.Mapper.GetMaterialAt(isv, x, y, z);
                                if (m != Materials.Air)
                                {
                                    if (!materialCounts.ContainsKey(m))
                                    {
                                        materialCounts.Add(m, 0);
                                    }

                                    materialCounts[m] = materialCounts[m] + 1;
                                }
                            }
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("\"Material\",\"Block Count\",\"Full Stacks needed\"");
                    sb.AppendLine("\"Total\"," + materialCounts.Values.Sum());
                    foreach (var kvp in materialCounts.OrderByDescending(x => x.Value))
                    {
                        sb.AppendLine($"\"{kvp.Key.GetBlockNameAndData(isv).Replace("\"", "\"\"")}\",{kvp.Value},{kvp.Value / 64} stacks and {kvp.Value % 64} remaining blocks");
                    }
                    File.WriteAllText(fName, sb.ToString());
                }
            }
            else
            {
                this.exportSchematicToolStripMenuItem.Enabled = false;
            }
        }