public void UpdateControls() { Session s = SavedState.Data.CurrentSession; if (s == null) { return; } SessionType sType = SavedState.Data.SessionTypes.First(x => x.Id == s.TypeId); TimeSpan timeRemaining; if (s.Paused) { iconPlayPause.Kind = PackIconKind.PlayOutline; iconPlayPause.Margin = new Thickness(5, 0, 0, 0); timeRemaining = sType.Time - s.TimeElapsed; btnPlayPause.ToolTip = "Start"; } else { iconPlayPause.Kind = PackIconKind.Pause; iconPlayPause.Margin = new Thickness(0); timeRemaining = sType.Time - s.TimeElapsed - stopwatch.Elapsed; btnPlayPause.ToolTip = "Pause"; } if (!sType.CountUp && timeRemaining.TotalSeconds < -5) { lblOvertime.Visibility = Visibility.Visible; } else { lblOvertime.Visibility = Visibility.Collapsed; } if (timeRemaining.TotalSeconds > 0) { lblTimerHour.Text = ((int)Math.Floor(timeRemaining.TotalHours)).ToString("00"); lblTimerMinute.Text = timeRemaining.Minutes.ToString("00"); lblTimerSecond.Text = timeRemaining.Seconds.ToString("00"); ButtonProgressAssist.SetMaximum(btnPlayPause, sType.Time.TotalSeconds); ButtonProgressAssist.SetValue(btnPlayPause, timeRemaining.TotalSeconds); } else if (timeRemaining.TotalSeconds < -5 || sType.CountUp) { timeRemaining = -timeRemaining; lblTimerHour.Text = ((int)Math.Floor(timeRemaining.TotalHours)).ToString("00"); lblTimerMinute.Text = timeRemaining.Minutes.ToString("00"); lblTimerSecond.Text = timeRemaining.Seconds.ToString("00"); ButtonProgressAssist.SetMaximum(btnPlayPause, sType.Time.TotalSeconds); ButtonProgressAssist.SetValue(btnPlayPause, 0); } else { lblTimerHour.Text = "00"; lblTimerMinute.Text = "00"; lblTimerSecond.Text = "00"; ButtonProgressAssist.SetMaximum(btnPlayPause, 5); ButtonProgressAssist.SetValue(btnPlayPause, -timeRemaining.TotalSeconds); } if (lblTimerHour.Text == "00") { lblTimerHour.Opacity = 0.5; if (lblTimerMinute.Text == "00") { lblTimerMinute.Opacity = 0.5; if (lblTimerSecond.Text == "00") { lblTimerSecond.Opacity = 0.5; } else { lblTimerSecond.Opacity = 1; } } else { lblTimerMinute.Opacity = 1; lblTimerSecond.Opacity = 1; } } else { lblTimerHour.Opacity = 1; lblTimerMinute.Opacity = 1; lblTimerSecond.Opacity = 1; } lblColon1.Opacity = lblTimerHour.Opacity; lblColon2.Opacity = lblTimerMinute.Opacity; lblSessionName.Text = sType.Name; }
private async void ExportButton_Click(object sender, RoutedEventArgs e) { if (ImageConverter.IsLoaded) { ExportButton.IsEnabled = false; Options.IsEnabled = false; BrowsImageButton.IsEnabled = false; BrowsFolderButton.IsEnabled = false; ButtonProgressAssist.SetValue(ExportButton, 0); int coord = CoordinateAxis.SelectedIndex; int verAlig = VerticalAlignmentBox.SelectedIndex; int horAlig = HorizontalAlignmentBox.SelectedIndex; Particle[] particles = ImageConverter.GetParticles(coord, verAlig, horAlig); ButtonProgressAssist.SetMaximum(ExportButton, particles.Length + 20); ButtonProgressAssist.SetValue(ExportButton, 20); ExportButton.UpdateLayout(); string fileName = System.IO.Path.GetFileNameWithoutExtension(FilePathBox.Text); string filePath = FolderPathBox.Text + "\\" + fileName.ToLower() + ".mcfunction"; Encoding enc = new System.Text.UTF8Encoding();; StreamWriter writer = null; try { string cs = "~"; switch (((ComboBoxItem)CoordinateModeBox.SelectedItem).Tag) { case "Relative": cs = "~"; break; case "Local": cs = "^"; break; } if (!Directory.Exists(System.IO.Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filePath)); } var fullname = typeof(App).Assembly.Location; var info = FileVersionInfo.GetVersionInfo(fullname); var ver = info.FileVersion; writer = new StreamWriter(filePath, false, enc); writer.WriteLine($"### Particle Image Function"); writer.WriteLine($"### Version: {ver}"); writer.WriteLine($"### Width: {ImageConverter.ResizedWidth}"); writer.WriteLine($"### Height: {ImageConverter.ResizedHeight}"); writer.WriteLine($"### ParticleType: {ParticleTypeBox.SelectedValue}"); writer.WriteLine($""); writer.WriteLine($"### This file was generated by Kemo431's Particle-Converter."); writer.WriteLine($"### Download Link: https://github.com/kemo14331/Particle-Converter"); writer.WriteLine($""); for (int i = 0; i < particles.Length; i++) { var p = particles[i]; string axis = $"{cs}{Math.Round(p.x, 7).ToString("R", format)} {cs}{Math.Round(p.y, 7).ToString("R", format)} {cs}{Math.Round(p.z, 7).ToString("R", format)}"; string particle = "minecraft:" + ParticleTypeBox.Text; if (ParticleTypeBox.SelectedValue.Equals("dust")) { if (UseStaticDustColor.IsChecked.Value) { Color color = (Color)ColorConverter.ConvertFromString(ColorCodeBox.Text); particle += $" {Math.Round(color.R / 255.0d, 2).ToString("R", format)} {Math.Round(color.G / 255.0d, 2).ToString("R", format)} {Math.Round(color.B / 255.0d, 2).ToString("R", format)} {double.Parse(ParticleSizeBox.Text).ToString("R", format)}"; } else { particle += $" {Math.Round(p.r / 255.0d, 2).ToString("R", format)} {Math.Round(p.g / 255.0d, 2).ToString("R", format)} {Math.Round(p.b / 255.0d, 2).ToString("R", format)} {double.Parse(ParticleSizeBox.Text).ToString("R", format)}"; } } string particleString = $"particle {particle} {axis} 0 0 0 0 1 {((ComboBoxItem)DisplayModeBox.SelectedItem).Tag} {ParticleViewerBox.Text}"; await Task.Run(() => { writer.WriteLine(particleString); }); ButtonProgressAssist.SetValue(ExportButton, 20 + 1 + i); } } catch (Exception exc) { MessageBox.Show("ファイルの書き込みに失敗しました\nFailed to export a file.", "エラー/Error", MessageBoxButton.OK, MessageBoxImage.Error); Logger.WriteExceptionLog(exc); } finally { if (writer != null) { writer.Close(); } } ButtonProgressAssist.SetValue(ExportButton, 0); Options.IsEnabled = true; ExportButton.IsEnabled = true; BrowsImageButton.IsEnabled = true; BrowsFolderButton.IsEnabled = true; SystemSounds.Beep.Play(); } else { SystemSounds.Beep.Play(); } }