2016-09-07 18:50:38 +02:00
Public Class MainGameFunctions
Public Shared Sub FunctionKeys ( )
2017-02-11 15:14:09 +01:00
If KeyBoardHandler . KeyPressed ( KeyBindings . GUIControlKey ) = True Then
Core . GameOptions . ShowGUI = Not Core . GameOptions . ShowGUI
Core . GameOptions . SaveOptions ( )
ElseIf KeyBoardHandler . KeyPressed ( KeyBindings . ScreenshotKey ) AndAlso Core . CurrentScreen . CanTakeScreenshot Then
2016-09-07 18:50:38 +02:00
CaptureScreen ( )
2017-02-11 15:14:09 +01:00
ElseIf KeyBoardHandler . KeyPressed ( KeyBindings . DebugKey ) Then
2016-09-07 18:50:38 +02:00
Core . GameOptions . ShowDebug += 1
If Core . GameOptions . ShowDebug >= 2 Then
Core . GameOptions . ShowDebug = 0
End If
Core . GameOptions . SaveOptions ( )
2017-02-11 15:14:09 +01:00
ElseIf KeyBoardHandler . KeyPressed ( KeyBindings . LightKey ) Then
Core . GameOptions . LightingEnabled = Not Core . GameOptions . LightingEnabled
2016-09-07 18:50:38 +02:00
Core . GameOptions . SaveOptions ( )
2017-02-11 15:14:09 +01:00
If Core . GameOptions . LightingEnabled Then
Core . GameMessage . ShowMessage ( Localization . GetString ( " game_message_lighting_on " , " Lighting Enabled " ) , 12 , FontManager . MainFont , Color . White )
Else
Core . GameMessage . ShowMessage ( Localization . GetString ( " game_message_lighting_off " , " Lighting Disabled " ) , 12 , FontManager . MainFont , Color . White )
End If
ElseIf KeyBoardHandler . KeyPressed ( KeyBindings . FullScreenKey ) AndAlso Core . CurrentScreen . CanGoFullscreen Then
ToggleFullScreen ( )
ElseIf KeyBoardHandler . KeyPressed ( KeyBindings . MuteMusicKey ) AndAlso Core . CurrentScreen . CanMuteMusic Then
2018-02-24 01:20:42 +01:00
MusicManager . Muted = Not MediaPlayer . IsMuted
2018-02-22 03:40:20 +01:00
SoundManager . Muted = MediaPlayer . IsMuted
2016-09-07 18:50:38 +02:00
Core . GameOptions . SaveOptions ( )
Core . CurrentScreen . ToggledMute ( )
End If
2017-02-11 15:14:09 +01:00
2016-09-07 18:50:38 +02:00
If KeyBoardHandler . KeyDown ( KeyBindings . DebugKey ) = True Then
2017-02-11 15:14:09 +01:00
If KeyBoardHandler . KeyPressed ( Keys . F ) Then
2016-09-07 18:50:38 +02:00
TextureManager . TextureList . Clear ( )
2017-02-11 15:14:09 +01:00
Core . GameMessage . ShowMessage ( Localization . GetString ( " game_message_debug_texture_list_clear " , " Texture list have cleared " ) , 12 , FontManager . MainFont , Color . White )
ElseIf KeyBoardHandler . KeyPressed ( Keys . S ) Then
2016-09-07 18:50:38 +02:00
Core . SetWindowSize ( New Vector2 ( 1200 , 680 ) )
2017-02-11 15:14:09 +01:00
ElseIf KeyBoardHandler . KeyPressed ( Keys . L ) Then
Logger . DisplayLog = Not Logger . DisplayLog
ElseIf KeyBoardHandler . KeyPressed ( Keys . B ) Then
Entity . drawViewBox = Not Entity . drawViewBox
2016-09-07 18:50:38 +02:00
End If
End If
2017-02-11 15:14:09 +01:00
2016-09-07 18:50:38 +02:00
If ControllerHandler . ButtonPressed ( Buttons . Back , True ) = True Then
Core . GameOptions . GamePadEnabled = Not Core . GameOptions . GamePadEnabled
2017-02-11 15:14:09 +01:00
If Core . GameOptions . GamePadEnabled Then
2016-09-07 18:50:38 +02:00
Core . GameMessage . ShowMessage ( " Enabled XBOX 360 GamePad support. " , 12 , FontManager . MainFont , Color . White )
Else
Core . GameMessage . ShowMessage ( " Disabled XBOX 360 GamePad support. " , 12 , FontManager . MainFont , Color . White )
End If
Core . GameOptions . SaveOptions ( )
End If
End Sub
Private Shared Sub CaptureScreen ( )
Try
Core . GameMessage . HideMessage ( )
Dim fileName As String = " "
With My . Computer . Clock . LocalTime
Dim month As String = . Month . ToString ( )
If month . Length = 1 Then
month = " 0 " & month
End If
Dim day As String = . Day . ToString ( )
If day . Length = 1 Then
day = " 0 " & day
End If
Dim hour As String = . Hour . ToString ( )
If hour . Length = 1 Then
hour = " 0 " & hour
End If
Dim minute As String = . Minute . ToString ( )
If minute . Length = 1 Then
minute = " 0 " & minute
End If
Dim second As String = . Second . ToString ( )
If second . Length = 1 Then
second = " 0 " & second
End If
fileName = . Year & " - " & month & " - " & day & " _ " & hour & " . " & minute & " . " & second & " .png "
End With
2017-02-11 12:19:11 +01:00
If Directory . Exists ( GameController . GamePath & " \screenshots\ " ) = False Then
Directory . CreateDirectory ( GameController . GamePath & " \screenshots\ " )
2016-09-07 18:50:38 +02:00
End If
If Core . GraphicsManager . IsFullScreen = False Then
2017-02-11 15:14:09 +01:00
Dim b As New Drawing . Bitmap ( Core . windowSize . Width , Core . windowSize . Height )
Using g As Drawing . Graphics = Drawing . Graphics . FromImage ( b )
2018-02-24 01:20:42 +01:00
g . CopyFromScreen ( Core . Window . ClientBounds . X , Core . Window . ClientBounds . Y , 0 , 0 , New Drawing . Size ( b . Width , b . Height ) )
2016-09-07 18:50:38 +02:00
End Using
2017-02-11 15:14:09 +01:00
b . Save ( GameController . GamePath & " \screenshots\ " & fileName , Drawing . Imaging . ImageFormat . Png )
2016-09-07 18:50:38 +02:00
Else
Dim screenshot As New RenderTarget2D ( Core . GraphicsDevice , Core . windowSize . Width , Core . windowSize . Height , False , SurfaceFormat . Color , DepthFormat . Depth24Stencil8 )
Core . GraphicsDevice . SetRenderTarget ( screenshot )
Core . Draw ( )
Core . GraphicsDevice . SetRenderTarget ( Nothing )
2017-02-11 12:19:11 +01:00
Dim stream As Stream = File . OpenWrite ( GameController . GamePath & " \screenshots\ " & fileName )
2016-09-07 18:50:38 +02:00
screenshot . SaveAsPng ( stream , Core . windowSize . Width , Core . windowSize . Height )
stream . Dispose ( )
End If
Core . GameMessage . SetupText ( Localization . GetString ( " game_message_screenshot " ) & fileName , FontManager . MainFont , Color . White )
Core . GameMessage . ShowMessage ( 12 , Core . GraphicsDevice )
Catch ex As Exception
Logger . Log ( Logger . LogTypes . ErrorMessage , " Basic.vb: " & Localization . GetString ( " game_message_screenshot_failed " ) & " . More information: " & ex . Message )
End Try
End Sub
Private Shared Sub ToggleFullScreen ( )
If Core . GraphicsManager . IsFullScreen = False Then
2017-02-11 12:19:11 +01:00
' MonoGame Bug > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width != System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
' MonoGame Bug > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height != System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
' Temp Fix just in case someone else face this as well.
2017-02-11 15:14:09 +01:00
If GraphicsAdapter . DefaultAdapter . CurrentDisplayMode . Width <> Windows . Forms . Screen . PrimaryScreen . Bounds . Width OrElse
GraphicsAdapter . DefaultAdapter . CurrentDisplayMode . Height <> Windows . Forms . Screen . PrimaryScreen . Bounds . Height Then
Core . GraphicsManager . PreferredBackBufferWidth = Windows . Forms . Screen . PrimaryScreen . Bounds . Width
Core . GraphicsManager . PreferredBackBufferHeight = Windows . Forms . Screen . PrimaryScreen . Bounds . Height
Core . windowSize = New Rectangle ( 0 , 0 , Windows . Forms . Screen . PrimaryScreen . Bounds . Width , Windows . Forms . Screen . PrimaryScreen . Bounds . Height )
2017-02-11 12:19:11 +01:00
Else
Core . GraphicsManager . PreferredBackBufferWidth = GraphicsAdapter . DefaultAdapter . CurrentDisplayMode . Width
Core . GraphicsManager . PreferredBackBufferHeight = GraphicsAdapter . DefaultAdapter . CurrentDisplayMode . Height
Core . windowSize = New Rectangle ( 0 , 0 , GraphicsAdapter . DefaultAdapter . CurrentDisplayMode . Width , GraphicsAdapter . DefaultAdapter . CurrentDisplayMode . Height )
End If
2016-09-07 18:50:38 +02:00
2017-02-11 12:19:11 +01:00
Windows . Forms . Application . VisualStyleState = Windows . Forms . VisualStyles . VisualStyleState . ClientAndNonClientAreasEnabled
2016-09-07 18:50:38 +02:00
Core . GraphicsManager . ToggleFullScreen ( )
Core . GameMessage . ShowMessage ( Localization . GetString ( " game_message_fullscreen_on " ) , 12 , FontManager . MainFont , Color . White )
Else
Core . GraphicsManager . PreferredBackBufferWidth = 1200
Core . GraphicsManager . PreferredBackBufferHeight = 680
Core . windowSize = New Rectangle ( 0 , 0 , 1200 , 680 )
2017-02-11 12:19:11 +01:00
Windows . Forms . Application . VisualStyleState = Windows . Forms . VisualStyles . VisualStyleState . ClientAndNonClientAreasEnabled
2016-09-07 18:50:38 +02:00
Core . GraphicsManager . ToggleFullScreen ( )
Core . GameMessage . ShowMessage ( Localization . GetString ( " game_message_fullscreen_off " ) , 12 , FontManager . MainFont , Color . White )
End If
Core . GraphicsManager . ApplyChanges ( )
NetworkPlayer . ScreenRegionChanged ( )
End Sub
End Class