P3D-Legacy/P3D/Screens/NewMenuScreen.vb

344 lines
14 KiB
VB.net
Raw Normal View History

Public Class NewMenuScreen
Inherits Screen
Private _menuOptions As New List(Of String)
Private _menuIndex As Integer = 0
Private _texture As Texture2D
'Intro animation:
Private _gradientFade As Integer = 0
Private _buttonFadeIndex As Integer = 0
Private _currentButtonFade As Integer = 0
Private _buttonIntroFinished As Boolean = False
'cursor animation:
Private _cursorPosition As Vector2 = New Vector2(0, 0)
Private _cursorDestPosition As Vector2 = New Vector2(0, 0)
Private _preScreenTexture As RenderTarget2D
Private _preScreenTarget As RenderTarget2D
Public Sub New(ByVal currentScreen As Screen)
Identification = Identifications.MenuScreen
PreScreen = currentScreen
IsDrawingGradients = True
MouseVisible = True
2022-06-04 16:12:03 +02:00
If windowSize.Width > 0 AndAlso windowSize.Height > 0 Then
_preScreenTarget = New RenderTarget2D(GraphicsDevice, windowSize.Width, windowSize.Height, False, SurfaceFormat.Color, DepthFormat.Depth24Stencil8)
_blur = New Resources.Blur.BlurHandler(windowSize.Width, windowSize.Height)
End If
_texture = TextureManager.GetTexture("GUI\Menus\General")
ConstructMenu()
_menuIndex = Player.Temp.MenuIndex
SetCursorPosition(_menuIndex)
_cursorPosition = _cursorDestPosition
End Sub
Private Sub ConstructMenu()
If Screen.Level.SaveOnly = False Then
If Core.Player.HasPokedex = True Then
_menuOptions.Add("Pokédex")
End If
If Screen.Level.IsBugCatchingContest = True Then
_menuOptions.AddRange({Screen.Level.BugCatchingContestData.GetSplit(2) & " x" & Core.Player.Inventory.GetItemAmount(177),
"Bag",
"|||" & Core.Player.Name, 'Trainer card
"End Contest"})
Else
If Core.Player.Pokemons.Count > 0 Then
_menuOptions.Add("Pokémon")
End If
_menuOptions.AddRange({"Bag",
"|||" & Core.Player.Name,
"Save"})
End If
_menuOptions.Add("Options")
Else
_menuOptions.Add("Save")
End If
End Sub
2018-02-22 23:43:27 +01:00
Private _blur As Resources.Blur.BlurHandler
Private Sub DrawPrescreen()
2022-06-04 16:12:03 +02:00
If windowSize.Width > 0 And windowSize.Height > 0 Then
If _preScreenTarget Is Nothing Then
_preScreenTarget = New RenderTarget2D(GraphicsDevice, windowSize.Width, windowSize.Height, False, SurfaceFormat.Color, DepthFormat.Depth24Stencil8)
End If
If _blur Is Nothing Then
_blur = New Resources.Blur.BlurHandler(windowSize.Width, windowSize.Height)
End If
If _preScreenTexture Is Nothing OrElse _preScreenTexture.IsContentLost Then
SpriteBatch.EndBatch()
2022-06-04 16:12:03 +02:00
Dim target As RenderTarget2D = _preScreenTarget
GraphicsDevice.SetRenderTarget(target)
GraphicsDevice.Clear(BackgroundColor)
2022-06-04 16:12:03 +02:00
SpriteBatch.BeginBatch()
2022-06-04 16:12:03 +02:00
PreScreen.Draw()
2022-06-04 16:12:03 +02:00
SpriteBatch.EndBatch()
2022-06-04 16:12:03 +02:00
GraphicsDevice.SetRenderTarget(Nothing)
2022-06-04 16:12:03 +02:00
SpriteBatch.BeginBatch()
2022-06-04 16:12:03 +02:00
_preScreenTexture = target
End If
If _preScreenTexture IsNot Nothing Then
If _preScreenTexture.Width > 0 And _preScreenTexture.Height > 0 Then
SpriteBatch.Draw(_blur.Perform(_preScreenTexture), windowSize, Color.White)
End If
End If
End If
End Sub
Public Overrides Sub Draw()
DrawPrescreen()
DrawGradients(_gradientFade)
If Me.IsCurrentScreen() = True Then
'Draw buttons:
If _gradientFade = 255 Then
If Core.Player.IsGameJoltSave = True Then
GameJolt.Emblem.Draw(GameJolt.API.username, Core.GameJoltSave.GameJoltID, Core.GameJoltSave.Points, Core.GameJoltSave.Gender, Core.GameJoltSave.Emblem, New Vector2(CSng(Core.windowSize.Width / 2 - 256), 30), 4, Core.GameJoltSave.DownloadedSprite)
End If
For i = 0 To _menuOptions.Count - 1
Dim text As String = _menuOptions(i).Replace("|||", "")
If _buttonIntroFinished = True Or _buttonFadeIndex > i Then
Dim pos = GetButtonPosition(i)
Core.SpriteBatch.Draw(_texture, New Rectangle(CInt(pos.X), CInt(pos.Y), 64, 64), New Rectangle(16, 16, 16, 16), Color.White)
Core.SpriteBatch.Draw(_texture, New Rectangle(CInt(pos.X) + 64, CInt(pos.Y), 64 * 4, 64), New Rectangle(32, 16, 16, 16), Color.White)
Core.SpriteBatch.Draw(_texture, New Rectangle(CInt(pos.X) + 64 * 5, CInt(pos.Y), 64, 64), New Rectangle(16, 16, 16, 16), Color.White, 0.0F, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0F)
Core.SpriteBatch.DrawString(FontManager.MainFont, text, New Vector2(CInt(pos.X) + 20, CInt(pos.Y) + 20), Color.Black, 0.0F, Vector2.Zero, 1.0F, SpriteEffects.None, 0.0F)
Else
Dim pos = GetButtonPosition(i)
Core.SpriteBatch.Draw(_texture, New Rectangle(CInt(pos.X), CInt(pos.Y), 64, 64), New Rectangle(16, 16, 16, 16), New Color(255, 255, 255, _currentButtonFade))
Core.SpriteBatch.Draw(_texture, New Rectangle(CInt(pos.X) + 64, CInt(pos.Y), 64 * 4, 64), New Rectangle(32, 16, 16, 16), New Color(255, 255, 255, _currentButtonFade))
Core.SpriteBatch.Draw(_texture, New Rectangle(CInt(pos.X) + 64 * 5, CInt(pos.Y), 64, 64), New Rectangle(16, 16, 16, 16), New Color(255, 255, 255, _currentButtonFade), 0.0F, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0F)
Core.SpriteBatch.DrawString(FontManager.MainFont, text, New Vector2(CInt(pos.X) + 20, CInt(pos.Y) + 20), New Color(0, 0, 0, _currentButtonFade), 0.0F, Vector2.Zero, 1.0F, SpriteEffects.None, 0.0F)
Exit For
End If
Next
End If
DrawCursor()
Else
_buttonFadeIndex = 0
_currentButtonFade = 0
_buttonIntroFinished = False
End If
End Sub
Private Sub DrawCursor()
If _buttonIntroFinished = True Or _buttonFadeIndex > _menuIndex Then
Dim t As Texture2D = TextureManager.GetTexture("GUI\Menus\General", New Rectangle(0, 0, 16, 16), "")
Core.SpriteBatch.Draw(t, New Rectangle(CInt(_cursorPosition.X), CInt(_cursorPosition.Y), 64, 64), Color.White)
End If
End Sub
Private Sub SetCursorPosition(ByVal _buttonIndex As Integer)
Dim pos = GetButtonPosition(_buttonIndex)
Dim cPosition As Vector2 = New Vector2(CInt(pos.X + 180), CInt(pos.Y - 42))
_cursorDestPosition = cPosition
End Sub
Private Function GetButtonPosition(ByVal index As Integer) As Vector2
'button size: 384x64
'space between buttons horizontally: 150
'space between buttons vertically: 80
Dim X As Single = 0F
Dim Y As Single = 0F
If (index Mod 2) = 0 Then
X = Core.windowSize.Width / 2.0F - 384 - 75
Else
X = Core.windowSize.Width / 2.0F + 75
End If
Select Case Math.Floor(index / 2)
Case 0
Y = (Core.windowSize.Height / 2.0F) - 64 - 80 - 32
Case 1
Y = (Core.windowSize.Height / 2.0F) - 32
Case 2
Y = (Core.windowSize.Height / 2.0F) + 32 + 80
End Select
Return New Vector2(X, Y)
End Function
Public Overrides Sub Update()
If _gradientFade < 255 Then
_gradientFade += 25
If _gradientFade >= 255 Then
_gradientFade = 255
End If
Else
If _buttonIntroFinished = False Then
_currentButtonFade += 45
If _currentButtonFade >= 255 Then
_currentButtonFade = 0
_buttonFadeIndex += 1
If _buttonFadeIndex > _menuOptions.Count - 1 Then
_buttonIntroFinished = True
End If
End If
End If
End If
If _buttonIntroFinished = True Then
Player.Temp.MenuIndex = _menuIndex
Dim preMenuIndex As Integer = _menuIndex
If _cursorDestPosition.X <> _cursorPosition.X Or _cursorDestPosition.Y <> _cursorPosition.Y Then
_cursorPosition.X = CInt(MathHelper.Lerp(_cursorDestPosition.X, _cursorPosition.X, 0.75F))
_cursorPosition.Y = CInt(MathHelper.Lerp(_cursorDestPosition.Y, _cursorPosition.Y, 0.75F))
If Math.Abs(_cursorDestPosition.X - _cursorPosition.X) < 0.1F Then
_cursorPosition.X = CInt(_cursorDestPosition.X)
End If
If Math.Abs(_cursorDestPosition.Y - _cursorPosition.Y) < 0.1F Then
_cursorPosition.Y = CInt(_cursorDestPosition.Y)
End If
End If
If Math.Abs(_cursorDestPosition.Y - _cursorPosition.Y) < 5.0F Then
If Controls.Accept(True, False, False) = True Then
For i = 0 To _menuOptions.Count - 1
Dim pos = GetButtonPosition(i)
If New Rectangle(CInt(pos.X), CInt(pos.Y), 64 * 6, 64).Contains(MouseHandler.MousePosition) Then
If _menuIndex = i Then
_cursorPosition.X = CInt(_cursorDestPosition.X)
Fix audio engine & contentpacks (#35) * Replaced existing Gen 2 SFX with better sounding ones (no ugly reverb) Replaced MediaPlayer with NAudio(and NAudio.Vorbis) for playing music in order to fix random stopping issues. The game now directly loads .ogg files instead of the .wma/.xnb combination from before. ContentPacks are now able to replace Music and SFX again (I haven't added a menu yet for choosing ContentPacks). To make older GameModes work with current versions, you can add the GameMode property EnterType and set it to "1", this will make the game use the older 2D NewGameScreen. * Delete GameController.vb * Add gamecontroller.vb back * Fix sfx missing * Battleintro doodle now doesn't loop anymore (for no trainer) Changed the shutter sound (aka Large Door sound) to something more large door-y Made the enter sound slightly louder The enter sound now plays when going through any warp to or from an indoor map (including falling through holes) The flying sound effect is played earlier in the animation after selecting a location Changed played sound effect when using the Escape Rope to "teleport" instead of "destroy" The bump noise now also plays when bumping into something in first person Fixed small gap between the end of the intro song and the start of the main song Replaced some songs with better songs * Fixed some more intro issues * Forgot to change a thing * Fixed an error where the main music would play, ignoring the muted musicmanager. * fix indenting in musicmanager * The music player will now only start playback on a new song if the music player is not muted, fixed the end time calculation of the intro of a song after muting, Music can't be unmuted now as long as a sound effect plays that stops the music. * Fixed league restplace position, fixed sound effects sharing the volume slider of the music, sound effects are now also muted when pressing M, changed music on/off popup to audio on/off, removed bump delay in first person, added more control on whether played songs should be looping or not. * Fixed some more scripts that turn on thirdperson mode but don't check if it was on before or set it back to what it was before afterwards, also fixed a small error in creditsscreen.vb. * Fixed indenting error in musicmanager.vb, fixed an error of mine where the loopsong parameter would be seen as the playintro parameter. * Added more music commands, added quite some menu select noises, will add more later * More select sound effects! * Fix music not resuming after soundeffect * Trainer using item now plays the single_heal soundeffect * Pokémon cries now sound louder * Possibly fixing crash when playing Pokémon cry at volume higher than 0.71 * Added better quality Pokémon cries, made random overworld cries slightly less loud, added cries for 719 and 720. * Sound effects now sound louder * Revert "Added better quality Pokémon cries, made random overworld cries slightly less loud, added cries for 719 and 720." This reverts commit 8c9296ed1a82144d17f303a52c3f2e9e65a5bfea. * Fixed the cause of why the title screen music plays even when the game is muted * Tabs to spaces * Revert Co-authored-by: darkfire006 <blazer257@live.com> Co-authored-by: JappaWakkaP3D <66885565+JappaWakkaP3D@users.noreply.github.com> Co-authored-by: JappaWakkaP3D <jasper.speelman@outlook.com> Co-authored-by: Vitaly Mikhailov <personal@aragas.org>
2020-07-09 19:59:42 +02:00
SoundManager.PlaySound("select")
PressButton()
Else
_menuIndex = i
SetCursorPosition(_menuIndex)
preMenuIndex = _menuIndex 'Prevent the update of the mouse position below.
Exit For
End If
End If
Next
End If
If Controls.Accept(False, True, True) = True Then
_cursorPosition.X = CInt(_cursorDestPosition.X)
Fix audio engine & contentpacks (#35) * Replaced existing Gen 2 SFX with better sounding ones (no ugly reverb) Replaced MediaPlayer with NAudio(and NAudio.Vorbis) for playing music in order to fix random stopping issues. The game now directly loads .ogg files instead of the .wma/.xnb combination from before. ContentPacks are now able to replace Music and SFX again (I haven't added a menu yet for choosing ContentPacks). To make older GameModes work with current versions, you can add the GameMode property EnterType and set it to "1", this will make the game use the older 2D NewGameScreen. * Delete GameController.vb * Add gamecontroller.vb back * Fix sfx missing * Battleintro doodle now doesn't loop anymore (for no trainer) Changed the shutter sound (aka Large Door sound) to something more large door-y Made the enter sound slightly louder The enter sound now plays when going through any warp to or from an indoor map (including falling through holes) The flying sound effect is played earlier in the animation after selecting a location Changed played sound effect when using the Escape Rope to "teleport" instead of "destroy" The bump noise now also plays when bumping into something in first person Fixed small gap between the end of the intro song and the start of the main song Replaced some songs with better songs * Fixed some more intro issues * Forgot to change a thing * Fixed an error where the main music would play, ignoring the muted musicmanager. * fix indenting in musicmanager * The music player will now only start playback on a new song if the music player is not muted, fixed the end time calculation of the intro of a song after muting, Music can't be unmuted now as long as a sound effect plays that stops the music. * Fixed league restplace position, fixed sound effects sharing the volume slider of the music, sound effects are now also muted when pressing M, changed music on/off popup to audio on/off, removed bump delay in first person, added more control on whether played songs should be looping or not. * Fixed some more scripts that turn on thirdperson mode but don't check if it was on before or set it back to what it was before afterwards, also fixed a small error in creditsscreen.vb. * Fixed indenting error in musicmanager.vb, fixed an error of mine where the loopsong parameter would be seen as the playintro parameter. * Added more music commands, added quite some menu select noises, will add more later * More select sound effects! * Fix music not resuming after soundeffect * Trainer using item now plays the single_heal soundeffect * Pokémon cries now sound louder * Possibly fixing crash when playing Pokémon cry at volume higher than 0.71 * Added better quality Pokémon cries, made random overworld cries slightly less loud, added cries for 719 and 720. * Sound effects now sound louder * Revert "Added better quality Pokémon cries, made random overworld cries slightly less loud, added cries for 719 and 720." This reverts commit 8c9296ed1a82144d17f303a52c3f2e9e65a5bfea. * Fixed the cause of why the title screen music plays even when the game is muted * Tabs to spaces * Revert Co-authored-by: darkfire006 <blazer257@live.com> Co-authored-by: JappaWakkaP3D <66885565+JappaWakkaP3D@users.noreply.github.com> Co-authored-by: JappaWakkaP3D <jasper.speelman@outlook.com> Co-authored-by: Vitaly Mikhailov <personal@aragas.org>
2020-07-09 19:59:42 +02:00
SoundManager.PlaySound("select")
PressButton()
End If
End If
If Controls.Up(True, True, False, True, True, True) = True Then
If _menuIndex > 1 Then
_menuIndex -= 2
End If
End If
If Controls.Down(True, True, False, True, True, True) = True Then
If _menuIndex < _menuOptions.Count - 2 Then
_menuIndex += 2
End If
End If
If Controls.Right(True, True, True, True, True, True) = True Then
If _menuIndex < _menuOptions.Count - 1 Then
_menuIndex += 1
End If
End If
If Controls.Left(True, True, True, True, True, True) = True Then
If _menuIndex > 0 Then
_menuIndex -= 1
End If
End If
If _menuIndex <> preMenuIndex Then
SetCursorPosition(_menuIndex)
End If
End If
2021-09-21 17:45:29 +02:00
If CurrentScreen.Identification = Identifications.MenuScreen Then
If Controls.Dismiss() = True Then
Core.SetScreen(PreScreen)
End If
End If
End Sub
Private Sub PressButton()
Select Case _menuOptions(_menuIndex)
Case "Pokédex"
Core.SetScreen(New TransitionScreen(Core.CurrentScreen, New PokedexSelectScreen(Me), Color.White, False))
Case "Pokémon"
SetScreen(New PartyScreen(Me))
Case "Bag"
Core.SetScreen(New NewInventoryScreen(Me))
Case "|||" & Core.Player.Name
Core.SetScreen(New NewTrainerScreen(Me))
Case "Save"
2022-10-06 21:24:18 +02:00
If CBool(GameModeManager.GetGameRuleValue("SavingDisabled", "0")) = True AndAlso Core.Player.SandBoxMode = False Then
Dim s As Screen = Core.CurrentScreen
While Not s.PreScreen Is Nothing And s.Identification <> Identifications.OverworldScreen
s = s.PreScreen
End While
Core.SetScreen(s)
Screen.TextBox.Show("Saving is not possible right now.")
Else
Core.SetScreen(New SaveScreen(Me))
End If
Case "Options"
2017-10-15 21:12:47 +02:00
Core.SetScreen(New NewOptionScreen(Me))
Case "Exit"
Core.SetScreen(PreScreen)
Case Screen.Level.BugCatchingContestData.GetSplit(2) & " x" & Core.Player.Inventory.GetItemAmount(177)
Me.ShowBalls()
Case "End Contest"
Me.EndContest()
End Select
End Sub
Private Sub ShowBalls()
''' Requires new scripting system
'Dim s As Screen = Me.PreScreen
'Construct.Controller.GetInstance().RunFromFile(Screen.Level.BugCatchingContestData.GetSplit(1))
'Core.SetScreen(s)
Dim s As Screen = Me.PreScreen
CType(s, OverworldScreen).ActionScript.StartScript(Screen.Level.BugCatchingContestData.GetSplit(1), 0)
Core.SetScreen(s)
End Sub
Private Sub EndContest()
''' Requires new scripting system
'Dim s As Screen = Me.PreScreen
'Construct.Controller.GetInstance().RunFromFile(Screen.Level.BugCatchingContestData.GetSplit(0))
'Core.SetScreen(s)
Dim s As Screen = Me.PreScreen
CType(s, OverworldScreen).ActionScript.StartScript(Screen.Level.BugCatchingContestData.GetSplit(0), 0)
Core.SetScreen(s)
End Sub
Public Overrides Sub SizeChanged()
SetCursorPosition(_menuIndex)
_cursorPosition = _cursorDestPosition
End Sub
End Class