private void ApplyToUI(FleetImageArgument args) { int[] fleetIDs = args.FleetIDs ?? new int[0]; TargetFleet1.Checked = fleetIDs.Contains(1); TargetFleet2.Checked = fleetIDs.Contains(2); TargetFleet3.Checked = fleetIDs.Contains(3); TargetFleet4.Checked = fleetIDs.Contains(4); if (!SyncronizeTitleAndFileName.Checked) { Title.Text = args.Title; } Comment.Text = string.IsNullOrWhiteSpace(args.Comment) ? "" : LFtoCRLF.Replace(args.Comment, "\r\n"); // 保存データからのロード時に \n に変換されてしまっているため HorizontalFleetCount.Value = args.HorizontalFleetCount; HorizontalShipCount.Value = args.HorizontalShipCount; ReflectDamageGraphic.Checked = args.ReflectDamageGraphic; AvoidTwitterDeterioration.Checked = args.AvoidTwitterDeterioration; BackgroundImagePath.Text = args.BackgroundImagePath; for (int i = 0; i < TextFontList.Length; i++) { TextFontList[i].Text = SerializableFont.FontToString(args.Fonts[i], true); } }
private Bitmap GenerateFleetImage(FleetImageArgument args, int mode) { switch (mode) { case 0: default: return(FleetImageGenerator.GenerateCardBitmap(args)); case 1: return(FleetImageGenerator.GenerateCutinBitmap(args)); case 2: return(FleetImageGenerator.GenerateBannerBitmap(args)); } }
private void ButtonClearFont_Click(object sender, EventArgs e) { if (MessageBox.Show("フォントをデフォルト設定に戻します。\r\nよろしいですか?", "クリア確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { if (GeneralFont != null) { GeneralFont.Dispose(); } GeneralFont = null; TextGeneralFont.Text = ""; var defaultFonts = FleetImageArgument.GetDefaultFonts(); for (int i = 0; i < TextFontList.Length; i++) { TextFontList[i].Text = SerializableFont.FontToString(defaultFonts[i]); defaultFonts[i].Dispose(); } } }
private void ButtonClearFont_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to reset font\r\nsettings to the default values?", "Clear Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { if (GeneralFont != null) { GeneralFont.Dispose(); } GeneralFont = null; TextGeneralFont.Text = ""; var defaultFonts = FleetImageArgument.GetDefaultFonts(); for (int i = 0; i < TextFontList.Length; i++) { TextFontList[i].Text = SerializableFont.FontToString(defaultFonts[i]); defaultFonts[i].Dispose(); } } }
private void LoadConfiguration() { var config = Utility.Configuration.Config.FleetImageGenerator; CurrentArgument = config.Argument.Clone(); switch (config.ImageType) { case 0: default: ImageTypeCard.Checked = true; break; case 1: ImageTypeCutin.Checked = true; break; case 2: ImageTypeBanner.Checked = true; break; } OutputToClipboard.Checked = config.OutputType == 1; OpenImageAfterOutput.Checked = config.OpenImageAfterOutput; DisableOverwritePrompt.Checked = config.DisableOverwritePrompt; OutputPath.Text = config.LastOutputPath; try { SaveImageDialog.FileName = Path.GetFileName(config.LastOutputPath); SaveImageDialog.InitialDirectory = string.IsNullOrWhiteSpace(config.LastOutputPath) ? "" : Path.GetDirectoryName(config.LastOutputPath); } catch (Exception) { } SyncronizeTitleAndFileName.Checked = config.SyncronizeTitleAndFileName; AutoSetFileNameToDate.Checked = config.AutoSetFileNameToDate; }
private FleetImageArgument ApplyToArgument(FleetImageArgument defaultValue = null) { var ret = defaultValue == null ? new FleetImageArgument() : defaultValue.Clone(); ret.FleetIDs = new[] { TargetFleet1.Checked ? 1 : 0, TargetFleet2.Checked ? 2 : 0, TargetFleet3.Checked ? 3 : 0, TargetFleet4.Checked ? 4 : 0 }.Where(i => i > 0).ToArray(); ret.HorizontalFleetCount = (int)HorizontalFleetCount.Value; ret.HorizontalShipCount = (int)HorizontalShipCount.Value; ret.ReflectDamageGraphic = ReflectDamageGraphic.Checked; ret.AvoidTwitterDeterioration = AvoidTwitterDeterioration.Checked; var fonts = ret.Fonts; for (int i = 0; i < fonts.Length; i++) { if (fonts[i] != null) { fonts[i].Dispose(); } fonts[i] = SerializableFont.StringToFont(TextFontList[i].Text, true); } ret.Fonts = fonts; ret.BackgroundImagePath = BackgroundImagePath.Text; ret.Title = Title.Text; ret.Comment = Comment.Text; return(ret); }
private void ButtonOK_Click(object sender, EventArgs e) { var args = ApplyToArgument(); // validation if (args.FleetIDs == null || args.FleetIDs.Length == 0) { MessageBox.Show("出力する艦隊が指定されていません。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (args.HorizontalFleetCount <= 0 || args.HorizontalShipCount <= 0) { MessageBox.Show("艦隊・艦船の横幅は 1 以上にしてください。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (args.Fonts.Any(f => f == null)) { MessageBox.Show("未入力・不正なフォントが存在します。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (!OutputToClipboard.Checked) { if (string.IsNullOrWhiteSpace(OutputPath.Text)) { MessageBox.Show("出力先ファイル名が入力されていません。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (OutputPath.Text.ToCharArray().Intersect(Path.GetInvalidPathChars()).Any()) { MessageBox.Show("出力先に使用できない文字が含まれています。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (!DisableOverwritePrompt.Checked && File.Exists(OutputPath.Text)) { if (MessageBox.Show(Path.GetFileName(OutputPath.Text) + "\r\nは既に存在します。\r\n上書きしますか?", "上書き確認", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No) { args.DisposeResources(); return; } } } int mode; if (ImageTypeCard.Checked) { mode = 0; } else if (ImageTypeCutin.Checked) { mode = 1; } else if (ImageTypeBanner.Checked) { mode = 2; } else { mode = 0; } try { if (!OutputToClipboard.Checked) { using (var image = GenerateFleetImage(args, mode)) { if (!Directory.Exists(Path.GetDirectoryName(OutputPath.Text))) { Directory.CreateDirectory(Path.GetDirectoryName(OutputPath.Text)); } switch (Path.GetExtension(OutputPath.Text).ToLower()) { case ".png": default: image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Png); break; case ".bmp": case ".dib": image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Bmp); break; case ".gif": image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Gif); break; case ".tif": case ".tiff": image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Tiff); break; case ".jpg": case ".jpeg": case ".jpe": case ".jfif": { // jpeg quality settings var encoderParams = new System.Drawing.Imaging.EncoderParameters(); encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L); var codecInfo = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec => codec.MimeType == "image/jpeg"); image.Save(OutputPath.Text, codecInfo, encoderParams); } break; } if (OpenImageAfterOutput.Checked) { System.Diagnostics.Process.Start(OutputPath.Text); } } } else { using (var image = GenerateFleetImage(args, mode)) { Clipboard.SetImage(image); } } if (CurrentArgument != null) { CurrentArgument.DisposeResources(); } CurrentArgument = args; SaveConfiguration(); Utility.Logger.Add(2, "編成画像を出力しました。"); } catch (Exception ex) { ErrorReporter.SendErrorReport(ex, "編成画像の出力に失敗しました。"); MessageBox.Show("編成画像の出力に失敗しました。\r\n" + ex.GetType().Name + "\r\n" + ex.Message, "編成画像出力失敗", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { args.DisposeResources(); } Close(); }
private void ButtonOK_Click(object sender, EventArgs e) { var args = ApplyToArgument(); // validation if (args.FleetIDs == null || args.FleetIDs.Length == 0) { MessageBox.Show("Please select a fleet to export.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (args.HorizontalFleetCount <= 0 || args.HorizontalShipCount <= 0) { MessageBox.Show("The fleet must contain at least 1 ship.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (args.Fonts.Any(f => f == null)) { MessageBox.Show("The specified font does not exists.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (!OutputToClipboard.Checked) { if (string.IsNullOrWhiteSpace(OutputPath.Text)) { MessageBox.Show("Please enter the destination path.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (OutputPath.Text.ToCharArray().Intersect(Path.GetInvalidPathChars()).Any()) { MessageBox.Show("The destination path contains invalid characters.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); args.DisposeResources(); return; } if (!DisableOverwritePrompt.Checked && File.Exists(OutputPath.Text)) { if (MessageBox.Show(Path.GetFileName(OutputPath.Text) + " already exists.\r\nDo you want to replace it?", "Overwrite Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No) { args.DisposeResources(); return; } } } int mode; if (ImageTypeCard.Checked) { mode = 0; } else if (ImageTypeCutin.Checked) { mode = 1; } else if (ImageTypeBanner.Checked) { mode = 2; } else { mode = 3; } try { if (!OutputToClipboard.Checked) { using (var image = GenerateFleetImage(args, mode)) { if (!Directory.Exists(Path.GetDirectoryName(OutputPath.Text))) { Directory.CreateDirectory(Path.GetDirectoryName(OutputPath.Text)); } switch (Path.GetExtension(OutputPath.Text).ToLower()) { case ".png": default: image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Png); break; case ".bmp": case ".dib": image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Bmp); break; case ".gif": image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Gif); break; case ".tif": case ".tiff": image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Tiff); break; case ".jpg": case ".jpeg": case ".jpe": case ".jfif": { // jpeg quality settings var encoderParams = new System.Drawing.Imaging.EncoderParameters(); encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L); var codecInfo = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec => codec.MimeType == "image/jpeg"); image.Save(OutputPath.Text, codecInfo, encoderParams); } break; } if (OpenImageAfterOutput.Checked) { System.Diagnostics.Process.Start(OutputPath.Text); } } } else { using (var image = GenerateFleetImage(args, mode)) { Clipboard.SetImage(image); } } if (CurrentArgument != null) { CurrentArgument.DisposeResources(); } CurrentArgument = args; SaveConfiguration(); Utility.Logger.Add(2, "Fleet image exported successfully."); } catch (Exception ex) { ErrorReporter.SendErrorReport(ex, "Failed to export fleet image."); MessageBox.Show("Failed to export fleet image.\r\n" + ex.GetType().Name + "\r\n" + ex.Message, "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { args.DisposeResources(); } Close(); }