예제 #1
0
 private void btnDownload_Click(object sender, RoutedEventArgs e)
 {
     if (this.downloaderManager.Destination != null && Directory.Exists(this.downloaderManager.Destination))
     {
         ButtonProgressAssist.SetValue(this.btnDownload, 50);
         //this.btnDownload.IsEnabled = false;
         this.downloaderManager.Start();
     }
 }
예제 #2
0
        private static void OnProgressValueChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UserControl_ProgressButton button = d as UserControl_ProgressButton;
            ProgressType progressType         = (ProgressType)e.NewValue;

            switch (progressType)
            {
            case ProgressType.Ini:
                ButtonProgressAssist.SetValue(button.but, 0);
                button.packIcon.Kind = button.Kind;
                ButtonProgressAssist.SetIsIndicatorVisible(button.but, false);
                break;

            case ProgressType.Start:
                ButtonProgressAssist.SetValue(button.but, 0);
                ButtonProgressAssist.SetIsIndicatorVisible(button.but, true);
                button.packIcon.Kind = PackIconKind.Sync;
                new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, (s, ee) =>
                {
                    if (ButtonProgressAssist.GetValue(button.but) <= 50)
                    {
                        ButtonProgressAssist.SetValue(button.but, ButtonProgressAssist.GetValue(button.but) + 1);
                    }
                    else
                    {
                        ((DispatcherTimer)s).Stop();
                    }
                }, Dispatcher.CurrentDispatcher);
                break;

            case ProgressType.Done:
                new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, (s, ee) =>
                {
                    if (ButtonProgressAssist.GetValue(button.but) <= 100)
                    {
                        ButtonProgressAssist.SetValue(button.but, ButtonProgressAssist.GetValue(button.but) + 1);
                    }
                    else
                    {
                        ButtonProgressAssist.SetIsIndicatorVisible(button.but, false);
                        button.packIcon.Kind = PackIconKind.Check;
                        ((DispatcherTimer)s).Stop();
                    }
                }, Dispatcher.CurrentDispatcher);
                break;
            }
        }
예제 #3
0
        private void timer_Tick(object sender, EventArgs e)
        {
            if (progress != 100)
            {
                ButtonProgressAssist.SetValue(LoginButton, progress);
                progress += 1;
            }
            else
            {
                (sender as DispatcherTimer).Stop();
                Window3 wind = new Window3(foundUser);

                wind.Show();

                context.SaveChanges();
                this.Close();
            }
        }
예제 #4
0
        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;
        }
예제 #5
0
        public HomeView()
        {
            InitializeComponent();

            this.WhenActivated(disposables =>
            {
                // Link and Start
                this.Bind(ViewModel,
                          viewModel => viewModel.Link,
                          view => view.linkTextBox.Text)
                .DisposeWith(disposables);

                linkTextBox.Events().KeyDown
                .Where(x => x.Key == Key.Enter)
                .Select(x => Unit.Default)
                .InvokeCommand(ViewModel !.StartDownloadCommand)           // Null forgiving reason: upstream limitation.
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel,
                                viewModel => viewModel.BackendService.GlobalDownloadProgressPercentage,
                                view => view.downloadButton.Content,
                                percentage => percentage > 0.0 ? percentage.ToString("P1") : "_Download")
                .DisposeWith(disposables);

                // ButtonProgressAssist bindings
                ViewModel.WhenAnyValue(x => x.BackendInstance.IsRunning)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x =>
                {
                    ButtonProgressAssist.SetIsIndicatorVisible(downloadButton, x);
                    ButtonProgressAssist.SetIsIndicatorVisible(listFormatsButton, x);
                })
                .DisposeWith(disposables);

                ViewModel.WhenAnyValue(x => x.BackendService.ProgressState)
                .Select(x => x == TaskbarItemProgressState.Indeterminate)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => ButtonProgressAssist.SetIsIndeterminate(downloadButton, x))
                .DisposeWith(disposables);

                ViewModel.WhenAnyValue(x => x.BackendService.GlobalDownloadProgressPercentage)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => ButtonProgressAssist.SetValue(downloadButton, x * 100))
                .DisposeWith(disposables);

                ViewModel.WhenAnyValue(x => x.BackendService.ProgressState)
                .Select(x => x == TaskbarItemProgressState.Indeterminate)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => ButtonProgressAssist.SetIsIndeterminate(listFormatsButton, x))
                .DisposeWith(disposables);

                // presetComboBox
                this.OneWayBind(ViewModel,
                                viewModel => viewModel.Presets,
                                view => view.presetComboBox.ItemsSource)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.SelectedPreset,
                          view => view.presetComboBox.SelectedItem)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.SelectedPresetText,
                          view => view.presetComboBox.Text)
                .DisposeWith(disposables);

                // Subtitles
                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.DownloadSubtitles,
                          view => view.subtitlesDefaultCheckBox.IsChecked)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.DownloadSubtitlesAllLanguages,
                          view => view.subtitlesAllLanguagesCheckBox.IsChecked)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.DownloadAutoGeneratedSubtitles,
                          view => view.subtitlesAutoGeneratedCheckBox.IsChecked)
                .DisposeWith(disposables);

                // Options row 1
                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.AddMetadata,
                          view => view.metadataToggle.IsChecked)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.DownloadThumbnail,
                          view => view.thumbnailToggle.IsChecked)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.DownloadPlaylist,
                          view => view.playlistToggle.IsChecked)
                .DisposeWith(disposables);

                // Options row 2
                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.UseCustomOutputTemplate,
                          view => view.filenameTemplateToggle.IsChecked)
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel,
                                viewModel => viewModel.SharedSettings.UseCustomOutputTemplate,
                                view => view.filenameTemplateTextBox.IsEnabled)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.CustomOutputTemplate,
                          view => view.filenameTemplateTextBox.Text)
                .DisposeWith(disposables);

                // Options row 3
                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.UseCustomPath,
                          view => view.pathToggle.IsChecked)
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel,
                                viewModel => viewModel.SharedSettings.UseCustomPath,
                                view => view.pathComboBox.IsEnabled)
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel,
                                viewModel => viewModel.DownloadPathHistory,
                                view => view.pathComboBox.ItemsSource)
                .DisposeWith(disposables);

                this.Bind(ViewModel,
                          viewModel => viewModel.SharedSettings.DownloadPath,
                          view => view.pathComboBox.Text)
                .DisposeWith(disposables);

                // Arguments
                this.OneWayBind(ViewModel,
                                viewModel => viewModel.DownloadArguments,
                                view => view.argumentsItemsControl.ItemsSource)
                .DisposeWith(disposables);

                // Output
                this.Bind(ViewModel,
                          viewModel => viewModel.QueuedTextBoxSink.Content,
                          view => view.resultTextBox.Text)
                .DisposeWith(disposables);

                resultTextBox.Events().TextChanged
                .Where(_ => WpfHelper.IsScrolledToEnd(resultTextBox))
                .Subscribe(_ => resultTextBox.ScrollToEnd())
                .DisposeWith(disposables);

                // Download, list, abort button
                this.BindCommand(ViewModel,
                                 viewModel => viewModel.StartDownloadCommand,
                                 view => view.downloadButton)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel,
                                 viewModel => viewModel.ListFormatsCommand,
                                 view => view.listFormatsButton)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel,
                                 viewModel => viewModel.AbortDlCommand,
                                 view => view.abortButton)
                .DisposeWith(disposables);

                // Browse and open folder button
                this.BindCommand(ViewModel,
                                 viewModel => viewModel.BrowseDownloadFolderCommand,
                                 view => view.browseButton)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel,
                                 viewModel => viewModel.OpenDownloadFolderCommand,
                                 view => view.openFolderButton)
                .DisposeWith(disposables);

                // Reset custom filename template button
                this.BindCommand(ViewModel,
                                 viewModel => viewModel.ResetCustomFilenameTemplateCommand,
                                 view => view.resetFilenameTemplateButton)
                .DisposeWith(disposables);

                // Custom preset buttons
                this.BindCommand(ViewModel,
                                 viewModel => viewModel.OpenAddCustomPresetDialogCommand,
                                 view => view.addPresetButton)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel,
                                 viewModel => viewModel.OpenEditCustomPresetDialogCommand,
                                 view => view.editPresetButton)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel,
                                 viewModel => viewModel.DuplicatePresetCommand,
                                 view => view.duplicatePresetButton)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel,
                                 viewModel => viewModel.DeleteCustomPresetCommand,
                                 view => view.deletePresetButton)
                .DisposeWith(disposables);
            });
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
 private async void GlobalProgress(object sender, double progress)
 {
     this.btnDownload.Dispatcher.Invoke(() => ButtonProgressAssist.SetValue(this.btnDownload, progress), DispatcherPriority.Background);
     Debug.WriteLine("Global progress : " + progress);
 }