@@ -13,7 +13,7 @@ namespace CreamInstaller.Components;
13
13
14
14
internal sealed class CustomTreeView : TreeView
15
15
{
16
- private const string KoaloaderToggleString = "Koaloader " ;
16
+ private const string ProxyToggleString = "代理 " ;
17
17
18
18
private static readonly Color C1 = ColorTranslator . FromHtml ( "#FFFF99" ) ;
19
19
private static readonly Color C2 = ColorTranslator . FromHtml ( "#696900" ) ;
@@ -24,10 +24,10 @@ internal sealed class CustomTreeView : TreeView
24
24
private static readonly Color C7 = ColorTranslator . FromHtml ( "#006900" ) ;
25
25
private static readonly Color C8 = ColorTranslator . FromHtml ( "#69AA69" ) ;
26
26
27
- private readonly Dictionary < Selection , Rectangle > checkBoxBounds = new ( ) ;
28
- private readonly Dictionary < Selection , Rectangle > comboBoxBounds = new ( ) ;
27
+ private readonly Dictionary < Selection , Rectangle > checkBoxBounds = [ ] ;
28
+ private readonly Dictionary < Selection , Rectangle > comboBoxBounds = [ ] ;
29
29
30
- private readonly Dictionary < TreeNode , Rectangle > selectionBounds = new ( ) ;
30
+ private readonly Dictionary < TreeNode , Rectangle > selectionBounds = [ ] ;
31
31
private SolidBrush backBrush ;
32
32
private ToolStripDropDown comboBoxDropDown ;
33
33
private Font comboBoxFont ;
@@ -36,6 +36,7 @@ internal sealed class CustomTreeView : TreeView
36
36
internal CustomTreeView ( )
37
37
{
38
38
DrawMode = TreeViewDrawMode . OwnerDrawAll ;
39
+ Invalidated += OnInvalidated ;
39
40
DrawNode += DrawTreeNode ;
40
41
Disposed += OnDisposed ;
41
42
}
@@ -59,27 +60,38 @@ private void OnDisposed(object sender, EventArgs e)
59
60
comboBoxDropDown = null ;
60
61
}
61
62
63
+ private void OnInvalidated ( object sender , EventArgs e )
64
+ {
65
+ checkBoxBounds . Clear ( ) ;
66
+ comboBoxBounds . Clear ( ) ;
67
+ selectionBounds . Clear ( ) ;
68
+ }
69
+
62
70
private void DrawTreeNode ( object sender , DrawTreeNodeEventArgs e )
63
71
{
64
72
e . DrawDefault = true ;
65
73
TreeNode node = e . Node ;
66
74
if ( node is not { IsVisible : true } )
67
75
return ;
76
+
68
77
bool highlighted = ( e . State & TreeNodeStates . Selected ) == TreeNodeStates . Selected && Focused ;
69
78
Graphics graphics = e . Graphics ;
70
79
backBrush ??= new ( BackColor ) ;
71
80
Font font = node . NodeFont ?? Font ;
72
81
Brush brush = highlighted ? SystemBrushes . Highlight : backBrush ;
73
82
Rectangle bounds = node . Bounds ;
74
83
Rectangle selectionBounds = bounds ;
84
+
75
85
Form form = FindForm ( ) ;
76
86
if ( form is not SelectForm and not SelectDialogForm )
77
87
return ;
88
+
78
89
string id = node . Name ;
79
90
Platform platform = ( node . Tag as Platform ? ) . GetValueOrDefault ( Platform . None ) ;
80
91
DLCType dlcType = ( node . Tag as DLCType ? ) . GetValueOrDefault ( DLCType . None ) ;
81
92
if ( string . IsNullOrWhiteSpace ( id ) || platform is Platform . None && dlcType is DLCType . None )
82
93
return ;
94
+
83
95
Color color = highlighted
84
96
? C1
85
97
: Enabled
@@ -91,15 +103,15 @@ private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e)
91
103
SelectionDLC dlc = SelectionDLC . FromId ( dlcType , node . Parent ? . Name , id ) ;
92
104
text = dlc ? . Selection != null ? dlc . Selection . Platform . ToString ( ) : dlcType . ToString ( ) ;
93
105
}
94
- else
95
- text = platform . ToString ( ) ;
106
+ else text = platform . ToString ( ) ;
96
107
97
108
Size size = TextRenderer . MeasureText ( graphics , text , font ) ;
98
109
bounds = bounds with { X = bounds . X + bounds . Width , Width = size . Width } ;
99
110
selectionBounds = new ( selectionBounds . Location , selectionBounds . Size + bounds . Size with { Height = 0 } ) ;
100
111
graphics . FillRectangle ( brush , bounds ) ;
101
112
Point point = new ( bounds . Location . X - 1 , bounds . Location . Y + 1 ) ;
102
113
TextRenderer . DrawText ( graphics , text , font , point , color , TextFormatFlags . Default ) ;
114
+
103
115
if ( platform is not Platform . Paradox )
104
116
{
105
117
color = highlighted
@@ -130,7 +142,7 @@ private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e)
130
142
graphics . FillRectangle ( brush , bounds ) ;
131
143
}
132
144
133
- CheckBoxState checkBoxState = selection . Koaloader
145
+ CheckBoxState checkBoxState = selection . UseProxy
134
146
? Enabled ? CheckBoxState . CheckedPressed : CheckBoxState . CheckedDisabled
135
147
: Enabled
136
148
? CheckBoxState . UncheckedPressed
@@ -142,7 +154,8 @@ private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e)
142
154
graphics . FillRectangle ( backBrush , bounds ) ;
143
155
point = new ( bounds . Left , bounds . Top + bounds . Height / 2 - size . Height / 2 - 1 ) ;
144
156
CheckBoxRenderer . DrawCheckBox ( graphics , point , checkBoxState ) ;
145
- text = KoaloaderToggleString ;
157
+
158
+ text = ProxyToggleString ;
146
159
size = TextRenderer . MeasureText ( graphics , text , font ) ;
147
160
int left = 1 ;
148
161
bounds = bounds with { X = bounds . X + bounds . Width , Width = size . Width + left } ;
@@ -151,29 +164,48 @@ private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e)
151
164
graphics . FillRectangle ( backBrush , bounds ) ;
152
165
point = new ( bounds . Location . X - 1 + left , bounds . Location . Y + 1 ) ;
153
166
TextRenderer . DrawText ( graphics , text , font , point , Enabled ? C7 : C8 , TextFormatFlags . Default ) ;
167
+
154
168
this . checkBoxBounds [ selection ] = RectangleToClient ( checkBoxBounds ) ;
155
- if ( selection . Koaloader )
169
+
170
+ if ( selection . UseProxy )
156
171
{
157
172
comboBoxFont ??= new ( font . FontFamily , 6 , font . Style , font . Unit , font . GdiCharSet ,
158
173
font . GdiVerticalFont ) ;
159
174
ComboBoxState comboBoxState = Enabled ? ComboBoxState . Normal : ComboBoxState . Disabled ;
160
- text = ( selection . KoaloaderProxy ?? Selection . DefaultKoaloaderProxy ) + ".dll" ;
175
+ ButtonState buttonState = Enabled ? ButtonState . Normal : ButtonState . Inactive ;
176
+
177
+ text = ( selection . Proxy ?? Selection . DefaultProxy ) + ".dll" ;
161
178
size = TextRenderer . MeasureText ( graphics , text , comboBoxFont ) + new Size ( 6 , 0 ) ;
162
179
const int padding = 2 ;
163
180
bounds = new ( bounds . X + bounds . Width , bounds . Y + padding / 2 , size . Width , bounds . Height - padding ) ;
164
181
selectionBounds = new ( selectionBounds . Location ,
165
182
selectionBounds . Size + bounds . Size with { Height = 0 } ) ;
166
183
Rectangle comboBoxBounds = bounds ;
167
184
graphics . FillRectangle ( backBrush , bounds ) ;
168
- ComboBoxRenderer . DrawTextBox ( graphics , bounds , text , comboBoxFont , comboBoxState ) ;
185
+ if ( ComboBoxRenderer . IsSupported )
186
+ ComboBoxRenderer . DrawTextBox ( graphics , bounds , text , comboBoxFont , comboBoxState ) ;
187
+ else
188
+ {
189
+ graphics . FillRectangle ( SystemBrushes . ControlText , bounds ) ;
190
+ ControlPaint . DrawButton ( graphics , bounds , buttonState ) ;
191
+ point = new ( bounds . Location . X + 3 + bounds . Width / 2 - size . Width / 2 ,
192
+ bounds . Location . Y + bounds . Height / 2 - size . Height / 2 ) ;
193
+ TextRenderer . DrawText ( graphics , text , comboBoxFont , point ,
194
+ Enabled ? SystemColors . ControlText : SystemColors . GrayText , TextFormatFlags . Default ) ;
195
+ }
196
+
169
197
size = new ( 14 , 0 ) ;
170
198
left = - 1 ;
171
199
bounds = bounds with { X = bounds . X + bounds . Width + left , Width = size . Width } ;
172
200
selectionBounds = new ( selectionBounds . Location ,
173
201
selectionBounds . Size + new Size ( bounds . Size . Width + left , 0 ) ) ;
174
202
comboBoxBounds = new ( comboBoxBounds . Location ,
175
203
comboBoxBounds . Size + new Size ( bounds . Size . Width + left , 0 ) ) ;
176
- ComboBoxRenderer . DrawDropDownButton ( graphics , bounds , comboBoxState ) ;
204
+ if ( ComboBoxRenderer . IsSupported )
205
+ ComboBoxRenderer . DrawDropDownButton ( graphics , bounds , comboBoxState ) ;
206
+ else
207
+ ControlPaint . DrawComboButton ( graphics , bounds , buttonState ) ;
208
+
177
209
this . comboBoxBounds [ selection ] = RectangleToClient ( comboBoxBounds ) ;
178
210
}
179
211
else
@@ -201,20 +233,16 @@ protected override void OnMouseDown(MouseEventArgs e)
201
233
break ;
202
234
}
203
235
204
- if ( e . Button is not MouseButtons . Left )
236
+ if ( e . Button is not MouseButtons . Left || ! ComboBoxRenderer . IsSupported )
205
237
return ;
238
+
206
239
if ( comboBoxBounds . Count > 0 && selectForm is not null )
207
240
foreach ( KeyValuePair < Selection , Rectangle > pair in comboBoxBounds )
208
241
if ( ! Selection . All . ContainsKey ( pair . Key ) )
209
242
_ = comboBoxBounds . Remove ( pair . Key ) ;
210
243
else if ( pair . Value . Contains ( clickPoint ) )
211
244
{
212
- HashSet < string > proxies = EmbeddedResources
213
- . Where ( r => r . StartsWith ( "Koaloader" , StringComparison . Ordinal ) ) . Select ( p =>
214
- {
215
- p . GetProxyInfoFromIdentifier ( out string proxyName , out _ ) ;
216
- return proxyName ;
217
- } ) . ToHashSet ( ) ;
245
+ IEnumerable < string > proxies = pair . Key . GetAvailableProxies ( ) ;
218
246
comboBoxDropDown ??= new ( ) ;
219
247
comboBoxDropDown . ShowItemToolTips = false ;
220
248
comboBoxDropDown . Items . Clear ( ) ;
@@ -224,7 +252,9 @@ protected override void OnMouseDown(MouseEventArgs e)
224
252
foreach ( ( string directory , BinaryType _ ) in pair . Key . ExecutableDirectories )
225
253
{
226
254
string path = directory + @"\" + proxy + ".dll" ;
227
- if ( ! path . FileExists ( ) || path . IsResourceFile ( ResourceIdentifier . Koaloader ) )
255
+ if ( ! path . FileExists ( ) || path . IsResourceFile ( ResourceIdentifier . Koaloader ) ||
256
+ path . IsResourceFile ( ResourceIdentifier . Steamworks32 ) ||
257
+ path . IsResourceFile ( ResourceIdentifier . Steamworks64 ) )
228
258
continue ;
229
259
canUse = false ;
230
260
break ;
@@ -233,8 +263,8 @@ protected override void OnMouseDown(MouseEventArgs e)
233
263
if ( canUse )
234
264
_ = comboBoxDropDown . Items . Add ( new ToolStripButton ( proxy + ".dll" , null , ( _ , _ ) =>
235
265
{
236
- pair . Key . KoaloaderProxy = proxy == Selection . DefaultKoaloaderProxy ? null : proxy ;
237
- selectForm . OnKoaloaderChanged ( ) ;
266
+ pair . Key . Proxy = proxy == Selection . DefaultProxy ? null : proxy ;
267
+ selectForm . OnProxyChanged ( ) ;
238
268
} ) { Font = comboBoxFont } ) ;
239
269
}
240
270
@@ -247,8 +277,8 @@ protected override void OnMouseDown(MouseEventArgs e)
247
277
_ = checkBoxBounds . Remove ( pair . Key ) ;
248
278
else if ( pair . Value . Contains ( clickPoint ) )
249
279
{
250
- pair . Key . Koaloader = ! pair . Key . Koaloader ;
251
- selectForm ? . OnKoaloaderChanged ( ) ;
280
+ pair . Key . UseProxy = ! pair . Key . UseProxy ;
281
+ selectForm ? . OnProxyChanged ( ) ;
252
282
break ;
253
283
}
254
284
}
0 commit comments