-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParamsWindow.xaml.cs
98 lines (79 loc) · 3 KB
/
ParamsWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using AdonisUI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;
using MessageBox = AdonisUI.Controls.MessageBox;
using MessageBoxButton = AdonisUI.Controls.MessageBoxButton;
using MessageBoxImage = AdonisUI.Controls.MessageBoxImage;
namespace PD2SoundBankEditor {
public partial class ParamsWindow : AdonisWindow {
private SoundBank soundBank;
private IEnumerable<Sound> soundObjects;
private bool usingSlider = false;
private bool enteringText = false;
public ParamsWindow(SoundBank soundBank) {
InitializeComponent();
this.soundBank = soundBank;
soundObjects = ((HircSection)soundBank.Sections.Find(x => x.Name == "HIRC")).SoundObjects;
soundIdListBox.ItemsSource = soundObjects;
soundIdListBox.SelectAll();
}
private void OnSoundIdSelectionChanged(object sender, RoutedEventArgs e) {
numItemsSelectedLabel.Content = $"{soundIdListBox.SelectedItems.Count} of {soundIdListBox.Items.Count} selected";
applyButton.IsEnabled = soundIdListBox.SelectedItem != null;
}
private void OnClipboardMatchClick(object sender, RoutedEventArgs e) {
if (!Clipboard.ContainsText()) {
return;
}
var re = new Regex("([0-9]{4,})", RegexOptions.Compiled);
var idMatches = re.Matches(Clipboard.GetText()).Cast<Match>().Select(m => uint.Parse(m.Value)).ToHashSet();
soundIdListBox.UnselectAll();
foreach (Sound sound in soundIdListBox.Items) {
if (idMatches.Contains(sound.SourceId)) {
soundIdListBox.SelectedItems.Add(sound);
}
}
if (soundIdListBox.SelectedItem != null) {
soundIdListBox.ScrollIntoView(soundIdListBox.SelectedItem);
}
}
private void OnAudioLevelSliderChange(object sender, RoutedEventArgs e) {
if (enteringText) {
return;
}
usingSlider = true;
audioLevelTextBox.Text = audioLevelSlider.Value.ToString("F1", System.Globalization.NumberFormatInfo.InvariantInfo);
usingSlider = false;
}
private void OnAudioLevelTextChange(object sender, RoutedEventArgs e) {
if (usingSlider) {
return;
}
var numberStyles = System.Globalization.NumberStyles.Any & ~System.Globalization.NumberStyles.AllowCurrencySymbol;
if (!float.TryParse(audioLevelTextBox.Text, numberStyles, System.Globalization.NumberFormatInfo.InvariantInfo, out var num)) {
num = 0;
}
enteringText = true;
audioLevelSlider.Value = Math.Clamp(num, audioLevelSlider.Minimum, audioLevelSlider.Maximum);
enteringText = false;
}
private void OnApplyClick(object sender, RoutedEventArgs e) {
foreach (Sound sound in soundIdListBox.SelectedItems) {
sound.NodeBaseParams.Properties1[0] = (float)audioLevelSlider.Value;
}
soundBank.IsDirty = true;
(Owner as MainWindow).UpdateWindowTitle();
Close();
}
private void OnCancelClick(object sender, RoutedEventArgs e) {
Close();
}
private void CheckAudioLevelText(object sender, TextCompositionEventArgs e) {
e.Handled = !Regex.IsMatch(e.Text, "[0-9.+-]");
}
}
}