@@ -150,19 +150,42 @@ Public Class B2SScreen
150150
151151 line(i) = 0
152152 line(i + 1 ) = 0
153- Me .PlayfieldSize = New Size( CInt (line( 0 )), CInt (line( 1 )))
154- Me .BackglassSize = New Size( CInt (line( 2 )), CInt (line( 3 )))
153+
155154 Me .BackglassMonitor = line( 4 )
156- Me .BackglassLocation = New Point( CInt (line( 5 )), CInt (line( 6 )))
157- Me .DMDSize = New Size( CInt (line( 7 )), CInt (line( 8 )))
158- Me .DMDLocation = New Point( CInt (line( 9 )), CInt (line( 10 )))
155+ EvalateBackglassScreen()
156+
157+ Me .PlayfieldSize = New Size( CInt (CalcValue(line( 0 ), ScreensOrdered( 0 ).Bounds.Width)), CInt (CalcValue(line( 1 ), ScreensOrdered( 0 ).Bounds.Height)))
158+ If (line( 0 ).Contains( "%" ) Or line( 1 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile PlayfieldSize: " &
159+ line( 0 ) & "," & line( 1 ) & "->" & Me .PlayfieldSize.Width & "," & Me .PlayfieldSize.Height)
160+
161+ Me .BackglassSize = New Size( CInt (CalcValue(line( 2 ), Me .BackglassScreen.Bounds.Width)), CInt (CalcValue(line( 3 ), Me .BackglassScreen.Bounds.Height)))
162+ If (line( 2 ).Contains( "%" ) Or line( 3 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile BackglassSize: " &
163+ line( 2 ) & "," & line( 3 ) & "->" & Me .BackglassSize.Width & "," & Me .BackglassSize.Height)
164+
165+ Me .BackglassLocation = New Point( CInt (CalcValue(line( 5 ), Me .BackglassScreen.Bounds.Width)), CInt (CalcValue(line( 6 ), Me .BackglassScreen.Bounds.Height)))
166+ If (line( 5 ).Contains( "%" ) Or line( 6 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile BackglassLocation: " &
167+ line( 5 ) & "," & line( 6 ) & "->" & Me .BackglassLocation.X & "," & Me .BackglassLocation.Y)
168+
169+ Me .DMDSize = New Size( CInt (CalcValue(line( 7 ), Me .BackglassScreen.Bounds.Width)), CInt (CalcValue(line( 8 ), Me .BackglassScreen.Bounds.Height)))
170+ If (line( 7 ).Contains( "%" ) Or line( 8 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile DMDSize: " &
171+ line( 7 ) & "," & line( 8 ) & "->" & Me .DMDSize.Width & "," & Me .DMDSize.Height)
172+
173+ Me .DMDLocation = New Size( CInt (CalcValue(line( 9 ), Me .BackglassScreen.Bounds.Width)), CInt (CalcValue(line( 10 ), Me .BackglassScreen.Bounds.Height)))
174+ If (line( 9 ).Contains( "%" ) Or line( 10 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile DMDLocation: " &
175+ line( 9 ) & "," & line( 10 ) & "->" & Me .DMDLocation.X & "," & Me .DMDLocation.Y)
176+
159177 Me .DMDFlipY = (Trim(line( 11 )) = "1" )
160178
161179 If (i > 15 ) Then
162- Me .BackgroundLocation = New Point( CInt (line( 12 )), CInt (line( 13 )))
163- Me .BackgroundSize = New Size( CInt (line( 14 )), CInt (line( 15 )))
180+ Me .BackgroundLocation = New Point( CInt (CalcValue(line( 12 ), Me .BackglassScreen.Bounds.Width)), CInt (CalcValue(line( 13 ), Me .BackglassScreen.Bounds.Height)))
181+ If (line( 12 ).Contains( "%" ) Or line( 13 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile BackgroundLocation: " &
182+ line( 12 ) & "," & line( 13 ) & "->" & Me .BackgroundLocation.X & "," & Me .BackgroundLocation.Y)
183+ Me .BackgroundSize = New Size( CInt (CalcValue(line( 14 ), Me .BackglassScreen.Bounds.Width)), CInt (CalcValue(line( 15 ), Me .BackglassScreen.Bounds.Height)))
184+ If (line( 14 ).Contains( "%" ) Or line( 15 ).Contains( "%" )) Then debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile BackgroundSize: " &
185+ line( 14 ) & "," & line( 15 ) & "->" & Me .BackgroundSize.Width & "," & Me .BackgroundSize.Height)
164186 Me .BackgroundPath = line( 16 )
165187 If Me .BackgroundPath.Contains( "{" ) Then
188+ debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile BackgroundPath contains template:" & Me .BackgroundPath)
166189 ' We will try to replace the placeholders with the real values
167190 Me .BackgroundPath = GetBackgroundPath( Me .BackgroundPath, B2SData.TableFileName, B2SSettings.GameName)
168191 debugLog.WriteLogEntry( "B2SScreen.ReadB2SSettingsFromFile GetBackgroundPath called and returned " & Me .BackgroundPath)
@@ -187,6 +210,32 @@ Public Class B2SScreen
187210# End If
188211 End If
189212 End Sub
213+ Private Function CalcValue(StringValue As String , totalValue As Integer ) As Integer
214+ ' Calculates an integer value from a string, which may be a percentage (e.g., "50%") or an absolute value.
215+ ' If the string ends with '%', it returns the percentage of totalValue.
216+ ' If the string is a number, it returns the integer value.
217+ ' Returns 0 if the string is invalid or cannot be parsed.
218+
219+ If StringValue Is Nothing Then Return 0
220+
221+ StringValue = StringValue.Trim()
222+ If StringValue.EndsWith( "%" ) Then
223+ Dim percentStr As String = StringValue.Substring( 0 , StringValue.Length - 1 )
224+ Dim percentValue As Double
225+ If Double .TryParse(percentStr, percentValue) Then
226+ Return CInt (totalValue * percentValue / 100.0 )
227+ Else
228+ Return 0
229+ End If
230+ Else
231+ Dim intValue As Integer
232+ If Integer .TryParse(StringValue, intValue) Then
233+ Return intValue
234+ Else
235+ Return 0
236+ End If
237+ End If
238+ End Function
190239 Private Function GetBackgroundPath(BackgroundPath As String , ByVal TableFileName As String , ByVal GameName As String ) As String
191240 Dim pattern As String = "^(?'name'[\w \-\!']+)(\((?'manufactor'[A-Za-z ]+)? (?'year'[\d{4}]+)\))?(?'extra'.*)?$"
192241 Dim regex As New Regex(pattern)
@@ -349,24 +398,7 @@ Public Class B2SScreen
349398
350399 End Sub
351400
352- Private Sub Show()
353- 'Dim searchPathLog As Log = New Log("BackglassShow")
354- 'searchPathLog.IsLogOn = B2SSettings.IsBackglassSearchLogOn
355-
356- 'searchPathLog.WriteLogEntry("Start Show")
357-
358- 'On Error Resume Next
359- If ( Not Me .BackgroundSize.IsEmpty) And ((B2SSettings.StartBackground.HasValue And B2SSettings.StartBackground) Or
360- ( Not B2SSettings.StartBackground.HasValue And B2SSettings.GlobalStartBackground.HasValue And B2SSettings.GlobalStartBackground)) Then
361- StartBackground = True
362- End If
363-
364- ' first of all get the info whether the DMD is to be shown or not
365- IsDMDToBeShown = ( Me .formDMD IsNot Nothing AndAlso Not Point.Empty.Equals( Me .DMDLocation) AndAlso
366- (( Me .DMDViewMode = eDMDViewMode.ShowDMD) OrElse
367- ( Me .DMDViewMode = eDMDViewMode.ShowDMDOnlyAtDefaultLocation AndAlso Me .DMDAtDefaultLocation) OrElse
368- ( Me .DMDViewMode = eDMDViewMode.DoNotShowDMDAtDefaultLocation AndAlso Not Me .DMDAtDefaultLocation)))
369-
401+ Private Sub EvalateBackglassScreen()
370402 On Error Resume Next
371403
372404 ' get the correct screen
@@ -398,6 +430,27 @@ Public Class B2SScreen
398430 Next
399431 On Error GoTo 0
400432
433+ End Sub
434+
435+ Private Sub Show()
436+ 'Dim searchPathLog As Log = New Log("BackglassShow")
437+ 'searchPathLog.IsLogOn = B2SSettings.IsBackglassSearchLogOn
438+
439+ 'searchPathLog.WriteLogEntry("Start Show")
440+
441+ 'On Error Resume Next
442+ If ( Not Me .BackgroundSize.IsEmpty) And ((B2SSettings.StartBackground.HasValue And B2SSettings.StartBackground) Or
443+ ( Not B2SSettings.StartBackground.HasValue And B2SSettings.GlobalStartBackground.HasValue And B2SSettings.GlobalStartBackground)) Then
444+ StartBackground = True
445+ End If
446+
447+ ' first of all get the info whether the DMD is to be shown or not
448+ IsDMDToBeShown = ( Me .formDMD IsNot Nothing AndAlso Not Point.Empty.Equals( Me .DMDLocation) AndAlso
449+ (( Me .DMDViewMode = eDMDViewMode.ShowDMD) OrElse
450+ ( Me .DMDViewMode = eDMDViewMode.ShowDMDOnlyAtDefaultLocation AndAlso Me .DMDAtDefaultLocation) OrElse
451+ ( Me .DMDViewMode = eDMDViewMode.DoNotShowDMDAtDefaultLocation AndAlso Not Me .DMDAtDefaultLocation)))
452+
453+ 'EvalateBackglassScreen()
401454
402455 ' Westworld show background form, only if background is set and enabled in setting
403456 Dim DMDKeepBackglassLocation = Me .BackglassLocation
0 commit comments