1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Windows ;
1
+ using System . Windows ;
4
2
using System . Windows . Controls ;
5
3
using System . Windows . Input ;
6
4
using BardMusicPlayer . DalamudBridge ;
@@ -15,80 +13,80 @@ namespace BardMusicPlayer.Controls;
15
13
/// </summary>
16
14
public sealed partial class BardExtSettingsWindow
17
15
{
18
- private Performer _performer ;
19
- private List < CheckBox > _cpuBoxes = new ( ) ;
16
+ private readonly Performer ? _performer ;
17
+ private readonly List < CheckBox > _cpuBoxes = new ( ) ;
20
18
21
- public BardExtSettingsWindow ( Performer performer )
19
+ public BardExtSettingsWindow ( Performer ? performer )
22
20
{
23
21
_performer = performer ;
24
22
InitializeComponent ( ) ;
25
- Title = "Settings for: " + _performer . PlayerName ;
23
+ Title = "Settings for: " + _performer ? . PlayerName ;
26
24
27
- Songtitle_Post_Type . SelectedIndex = 0 ;
28
- Songtitle_Chat_Type . SelectedIndex = 0 ;
29
- Chat_Type . SelectedIndex = 0 ;
25
+ SongTitlePostType . SelectedIndex = 0 ;
26
+ SongTitleChatType . SelectedIndex = 0 ;
27
+ ChatType . SelectedIndex = 0 ;
30
28
31
29
//Get the values for the song parsing bard
32
30
var tpBard = BmpMaestro . Instance . GetSongTitleParsingBard ( ) ;
33
31
if ( tpBard . Value != null )
34
32
{
35
- if ( tpBard . Value . game . Pid == _performer . game . Pid )
33
+ if ( _performer != null && tpBard . Value . game . Pid == _performer . game . Pid )
36
34
{
37
- Songtitle_Chat_Prefix . Text = tpBard . Key . prefix ;
35
+ SongTitleChatPrefix . Text = tpBard . Key . prefix ;
38
36
39
37
if ( tpBard . Key . channelType . ChannelCode == ChatMessageChannelType . Say . ChannelCode )
40
- Songtitle_Chat_Type . SelectedIndex = 0 ;
38
+ SongTitleChatType . SelectedIndex = 0 ;
41
39
else if ( tpBard . Key . channelType . ChannelCode == ChatMessageChannelType . Yell . ChannelCode )
42
- Songtitle_Chat_Type . SelectedIndex = 1 ;
40
+ SongTitleChatType . SelectedIndex = 1 ;
43
41
else if ( tpBard . Key . channelType . ChannelCode == ChatMessageChannelType . Party . ChannelCode )
44
- Songtitle_Chat_Type . SelectedIndex = 2 ;
42
+ SongTitleChatType . SelectedIndex = 2 ;
45
43
46
- Songtitle_Post_Type . SelectedIndex = tpBard . Key . channelType . Equals ( ChatMessageChannelType . None ) ? 0 : 1 ;
44
+ SongTitlePostType . SelectedIndex = tpBard . Key . channelType . Equals ( ChatMessageChannelType . None ) ? 0 : 1 ;
47
45
}
48
46
}
49
47
50
- Lyrics_TrackNr . Value = performer . SingerTrackNr . ToString ( ) ;
51
- GfxTest . IsChecked = _performer . game . GfxSettingsLow ;
52
- PopulateCPUTab ( ) ;
48
+ LyricsTrackNr . Value = performer ? . SingerTrackNr . ToString ( ) ;
49
+ GfxTest . IsChecked = _performer ? . game . GfxSettingsLow ;
50
+ PopulateCpuTab ( ) ;
53
51
}
54
52
55
53
private void SongTitle_Post_Type_SelectionChanged ( object sender , SelectionChangedEventArgs e )
56
54
{
57
- var chanType = Songtitle_Chat_Type . SelectedIndex switch
55
+ var chanType = SongTitleChatType . SelectedIndex switch
58
56
{
59
57
0 => ChatMessageChannelType . Say ,
60
58
1 => ChatMessageChannelType . Yell ,
61
59
2 => ChatMessageChannelType . Party ,
62
60
_ => ChatMessageChannelType . None
63
61
} ;
64
62
65
- switch ( Songtitle_Post_Type . SelectedIndex )
63
+ switch ( SongTitlePostType . SelectedIndex )
66
64
{
67
65
case 0 :
68
66
BmpMaestro . Instance . SetSongTitleParsingBard ( ChatMessageChannelType . None , "" , null ) ;
69
67
break ;
70
68
case 1 :
71
- BmpMaestro . Instance . SetSongTitleParsingBard ( chanType , Songtitle_Chat_Prefix . Text , _performer ) ;
69
+ BmpMaestro . Instance . SetSongTitleParsingBard ( chanType , SongTitleChatPrefix . Text , _performer ) ;
72
70
break ;
73
71
}
74
72
}
75
73
76
74
private void PostSongTitle_Click ( object sender , RoutedEventArgs e )
77
75
{
78
- if ( _performer . SongName == "" )
76
+ if ( _performer ? . SongName == "" )
79
77
return ;
80
78
81
- var chanType = Songtitle_Chat_Type . SelectedIndex switch
79
+ var chanType = SongTitleChatType . SelectedIndex switch
82
80
{
83
81
0 => ChatMessageChannelType . Say ,
84
82
1 => ChatMessageChannelType . Yell ,
85
83
2 => ChatMessageChannelType . Party ,
86
84
_ => ChatMessageChannelType . None
87
85
} ;
88
86
89
- if ( _performer . SongName != null )
87
+ if ( _performer ? . SongName != null )
90
88
{
91
- var songName = $ "{ Songtitle_Chat_Prefix . Text } { _performer . SongName } { Songtitle_Chat_Prefix . Text } ";
89
+ var songName = $ "{ SongTitleChatPrefix . Text } { _performer . SongName } { SongTitleChatPrefix . Text } ";
92
90
_performer . game . SendText ( chanType , songName ) ;
93
91
}
94
92
}
@@ -97,7 +95,7 @@ private void ChatInputText_KeyDown(object sender, KeyEventArgs e)
97
95
{
98
96
if ( e . Key == Key . Return )
99
97
{
100
- var chanType = Chat_Type . SelectedIndex switch
98
+ var chanType = ChatType . SelectedIndex switch
101
99
{
102
100
0 => ChatMessageChannelType . Say ,
103
101
1 => ChatMessageChannelType . Yell ,
@@ -107,7 +105,7 @@ private void ChatInputText_KeyDown(object sender, KeyEventArgs e)
107
105
_ => ChatMessageChannelType . None
108
106
} ;
109
107
var text = new string ( ChatInputText . Text . ToCharArray ( ) ) ;
110
- _performer . game . SendText ( chanType , text ) ;
108
+ _performer ? . game . SendText ( chanType , text ) ;
111
109
ChatInputText . Text = "" ;
112
110
}
113
111
}
@@ -117,46 +115,49 @@ private void Lyrics_TrackNr_PreviewMouseUp(object sender, MouseButtonEventArgs e
117
115
if ( sender is NumericUpDown ctl ) ctl . OnValueChanged += Lyrics_TrackNr_OnValueChanged ;
118
116
}
119
117
120
- private void Lyrics_TrackNr_OnValueChanged ( object sender , int s )
118
+ private void Lyrics_TrackNr_OnValueChanged ( object ? sender , int s )
121
119
{
122
- _performer . SingerTrackNr = s ;
120
+ if ( _performer != null ) _performer . SingerTrackNr = s ;
123
121
if ( sender is NumericUpDown ctl ) ctl . OnValueChanged -= Lyrics_TrackNr_OnValueChanged ;
124
122
}
125
123
126
124
#region CPU-Tab
127
- private void PopulateCPUTab ( )
125
+ private void PopulateCpuTab ( )
128
126
{
129
127
//Get the our application's process.
130
- var process = _performer . game . Process ;
128
+ var _ = _performer ? . game . Process ;
131
129
132
130
//Get the processor count of our machine.
133
131
var cpuCount = Environment . ProcessorCount ;
134
- var AffinityMask = ( long ) _performer . game . GetAffinity ( ) ;
135
-
136
- var res = ( int ) Math . Ceiling ( cpuCount / ( double ) 3 ) ;
137
- var idx = 1 ;
138
- for ( var col = 0 ; col != 3 ; col ++ )
132
+ if ( _performer != null )
139
133
{
140
- CPUDisplay . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
141
-
142
- for ( var i = 0 ; i != res + 1 ; i ++ )
134
+ var affinityMask = ( long ) _performer . game . GetAffinity ( ) ;
135
+
136
+ var res = ( int ) Math . Ceiling ( cpuCount / ( double ) 3 ) ;
137
+ var idx = 1 ;
138
+ for ( var col = 0 ; col != 3 ; col ++ )
143
139
{
144
- if ( idx == cpuCount + 1 )
145
- break ;
146
- if ( CPUDisplay . RowDefinitions . Count < res + 1 )
147
- CPUDisplay . RowDefinitions . Add ( new RowDefinition ( ) ) ;
148
- var uc = new CheckBox
140
+ CpuDisplay . ColumnDefinitions . Add ( new ColumnDefinition ( ) ) ;
141
+
142
+ for ( var i = 0 ; i != res + 1 ; i ++ )
149
143
{
150
- Name = "CPU" + idx ,
151
- Content = "CPU" + idx
152
- } ;
153
- if ( ( AffinityMask & ( 1 << idx - 1 ) ) > 0 ) //-1 since we count at 1
154
- uc . IsChecked = true ;
155
- _cpuBoxes . Add ( uc ) ;
156
- CPUDisplay . Children . Add ( uc ) ;
157
- Grid . SetRow ( uc , i ) ;
158
- Grid . SetColumn ( uc , CPUDisplay . ColumnDefinitions . Count - 1 ) ;
159
- idx ++ ;
144
+ if ( idx == cpuCount + 1 )
145
+ break ;
146
+ if ( CpuDisplay . RowDefinitions . Count < res + 1 )
147
+ CpuDisplay . RowDefinitions . Add ( new RowDefinition ( ) ) ;
148
+ var uc = new CheckBox
149
+ {
150
+ Name = "CPU" + idx ,
151
+ Content = "CPU" + idx
152
+ } ;
153
+ if ( ( affinityMask & ( 1 << idx - 1 ) ) > 0 ) //-1 since we count at 1
154
+ uc . IsChecked = true ;
155
+ _cpuBoxes . Add ( uc ) ;
156
+ CpuDisplay . Children . Add ( uc ) ;
157
+ Grid . SetRow ( uc , i ) ;
158
+ Grid . SetColumn ( uc , CpuDisplay . ColumnDefinitions . Count - 1 ) ;
159
+ idx ++ ;
160
+ }
160
161
}
161
162
}
162
163
}
@@ -181,7 +182,7 @@ private void Save_CPU_Click(object sender, RoutedEventArgs e)
181
182
return ;
182
183
}
183
184
else
184
- _performer . game . SetAffinity ( ( long ) mask ) ;
185
+ _performer ? . game . SetAffinity ( ( long ) mask ) ;
185
186
}
186
187
187
188
private void Clear_CPU_Click ( object sender , RoutedEventArgs e )
@@ -206,17 +207,17 @@ private void GfxTest_Checked(object sender, RoutedEventArgs e)
206
207
{
207
208
if ( GfxTest . IsChecked != null && ( bool ) GfxTest . IsChecked )
208
209
{
209
- if ( _performer . game . GfxSettingsLow )
210
+ if ( _performer != null && _performer . game . GfxSettingsLow )
210
211
return ;
211
- _performer . game . GfxSetLow ( true ) ;
212
- _performer . game . GfxSettingsLow = true ;
212
+ _performer ? . game . GfxSetLow ( true ) ;
213
+ if ( _performer != null ) _performer . game . GfxSettingsLow = true ;
213
214
}
214
215
else
215
216
{
216
- if ( ! _performer . game . GfxSettingsLow )
217
+ if ( _performer != null && ! _performer . game . GfxSettingsLow )
217
218
return ;
218
- _performer . game . GfxSetLow ( false ) ;
219
- _performer . game . GfxSettingsLow = false ;
219
+ _performer ? . game . GfxSetLow ( false ) ;
220
+ if ( _performer != null ) _performer . game . GfxSettingsLow = false ;
220
221
}
221
222
}
222
- }
223
+ }
0 commit comments