2016-09-19 03:26:44 +02:00
''' <summary>
2016-09-07 18:50:38 +02:00
''' A class to name Pokémon and other objects (namely the rival).
''' </summary>
''' <remarks>Inherits from screen.</remarks>
Public Class NameObjectScreen
Inherits Screen
2017-01-22 00:01:31 +01:00
Private _pokemon As Pokemon ' Temporarly stores the Pokémon to rename.
Private _currentText As String = " " ' The current Text in the textbox.
Private _mainTexture As Texture2D ' The temporary texture. Loads "GUI\Menus\Menu".
2016-09-07 18:50:38 +02:00
2017-01-22 00:01:31 +01:00
Private _index As Integer = 0 ' The button index (0 or 1).
Private _askedRename As Boolean = False ' If the question to rename is answered or not.
Private _renamePokemon As Boolean = False ' If a Pokémon is getting renamed.
2016-09-07 18:50:38 +02:00
2017-01-22 00:01:31 +01:00
Private _canChooseNo As Boolean = True ' If the player can choose to not rename the object.
Private _defaultName As String = " Name " ' The default name (that also gets mentioned in the question).
Private _delay As Single = 0 . 0F ' The delay until the question can be answered.
2016-09-07 18:50:38 +02:00
''' <summary>
''' Handles the NameAccept event which fires if the object gets renamed.
''' </summary>
''' <param name="Name">The new name of the object</param>
Public Delegate Sub DNameAcceptEventHandler ( ByVal Name As String )
Private _acceptName As DNameAcceptEventHandler
''' <summary>
''' Creates a new instance of the NameObjectScreen class and sets its mode to "Rename Pokémon".
''' </summary>
''' <param name="CurrentScreen">The currently active screen.</param>
''' <param name="Pokemon">The Pokémon reference to rename.</param>
Public Sub New ( ByVal CurrentScreen As Screen , ByVal Pokemon As Pokemon )
2017-01-22 00:01:31 +01:00
' Set default values:
2016-09-07 18:50:38 +02:00
Me . Identification = Identifications . NameObjectScreen
Me . PreScreen = CurrentScreen
Me . MouseVisible = True
Me . CanChat = False
2021-10-01 15:24:54 +02:00
Me . CanMuteAudio = False
2016-09-07 18:50:38 +02:00
Me . CanBePaused = False
2022-04-29 21:14:06 +02:00
Me . _canChooseNo = True
2016-09-07 18:50:38 +02:00
Me . _pokemon = Pokemon
Me . _defaultName = Pokemon . GetDisplayName ( )
Me . _renamePokemon = True
2017-01-22 00:01:31 +01:00
' Load texture:
2016-09-07 18:50:38 +02:00
Me . _mainTexture = TextureManager . GetTexture ( " GUI\Menus\Menu " )
2017-01-22 00:01:31 +01:00
' Show the Pokémon image:
2016-09-07 18:50:38 +02:00
Screen . PokemonImageView . Show ( Pokemon , True )
End Sub
Public Sub New ( ByVal CurrentScreen As Screen , ByVal Texture As Texture2D , ByVal canExit As Boolean , ByVal canChoose As Boolean , ByVal NameString As String , ByVal DefaultName As String , ByVal AcceptName As DNameAcceptEventHandler )
Me . Identification = Identifications . NameObjectScreen
Me . PreScreen = CurrentScreen
Me . _mainTexture = TextureManager . GetTexture ( " GUI\Menus\Menu " )
Me . _acceptName = AcceptName
Me . _canChooseNo = canExit
If canChoose = False Then
Me . _delay = 5 . 0F
End If
Me . _askedRename = Not canChoose
Me . _defaultName = NameString
Me . _currentText = DefaultName
Me . _renamePokemon = False
Me . MouseVisible = True
Me . CanBePaused = True
Me . CanChat = False
2021-10-01 15:24:54 +02:00
Me . CanMuteAudio = False
2016-09-07 18:50:38 +02:00
Screen . PokemonImageView . Show ( Texture )
End Sub
Public Overrides Sub Draw ( )
Me . PreScreen . Draw ( )
Canvas . DrawRectangle ( Core . windowSize , New Color ( 0 , 0 , 0 , 150 ) )
Dim CanvasTexture As Texture2D
For i = 0 To 1
Dim Text As String = " Rename "
If _askedRename = True Then
Text = " OK "
End If
If i = 1 Then
Text = " Cancel "
End If
If i = _index Then
CanvasTexture = TextureManager . GetTexture ( " GUI\Menus\Menu " , New Rectangle ( 0 , 48 , 48 , 48 ) , " " )
Else
CanvasTexture = TextureManager . GetTexture ( " GUI\Menus\Menu " , New Rectangle ( 0 , 0 , 48 , 48 ) , " " )
End If
If i = 1 And _canChooseNo = True Or i = 0 Then
Canvas . DrawImageBorder ( CanvasTexture , 2 , New Rectangle ( CInt ( Core . windowSize . Width / 2 ) - 182 + i * 192 + 22 , Core . windowSize . Height - 128 , 128 , 64 ) )
Core . SpriteBatch . DrawString ( FontManager . InGameFont , Text , New Vector2 ( CInt ( Core . windowSize . Width / 2 ) - 164 + i * 192 + 22 , Core . windowSize . Height - 96 ) , Color . Black )
End If
Next
If _askedRename = False Then
Dim genderString As String = " "
If _renamePokemon = True Then
If _pokemon . Gender = Pokemon . Genders . Male Then
2022-06-02 12:58:54 +02:00
genderString = " ♂ "
2016-09-07 18:50:38 +02:00
ElseIf _pokemon . Gender = Pokemon . Genders . Female Then
2022-06-02 12:58:54 +02:00
genderString = " ♀ "
2016-09-07 18:50:38 +02:00
End If
End If
2022-06-02 12:58:54 +02:00
Core . SpriteBatch . DrawString ( FontManager . InGameFont , " Rename " & Me . _defaultName & genderString & " ? " , New Vector2 ( CInt ( Core . windowSize . Width / 2 ) - CInt ( FontManager . InGameFont . MeasureString ( " Rename " & Me . _defaultName & genderString & " ? " ) . X / 2 ) + 2 , 96 + 2 ) , Color . Black )
Core . SpriteBatch . DrawString ( FontManager . InGameFont , " Rename " & Me . _defaultName & genderString & " ? " , New Vector2 ( CInt ( Core . windowSize . Width / 2 ) - CInt ( FontManager . InGameFont . MeasureString ( " Rename " & Me . _defaultName & genderString & " ? " ) . X / 2 ) , 96 ) , Color . White )
2016-09-07 18:50:38 +02:00
ChooseBox . Showing = False
Else
If _delay = 0 . 0F Then
Dim genderString As String = " "
Dim genderUnicode As Integer = 0
If _renamePokemon = True Then
If _pokemon . Gender = Pokemon . Genders . Male Then
2022-06-02 12:58:54 +02:00
genderString = " ♂ "
2016-09-07 18:50:38 +02:00
ElseIf _pokemon . Gender = Pokemon . Genders . Female Then
2022-06-02 12:58:54 +02:00
genderString = " ♀ "
2016-09-07 18:50:38 +02:00
End If
End If
2022-06-02 12:58:54 +02:00
Core . SpriteBatch . DrawString ( FontManager . InGameFont , " Enter name for " & Me . _defaultName & genderString & " : " , New Vector2 ( CInt ( Core . windowSize . Width / 2 ) - CInt ( FontManager . InGameFont . MeasureString ( " Enter name for " & Me . _defaultName & genderString & " : " ) . X / 2 ) + 2 , 96 + 2 ) , Color . Black )
Core . SpriteBatch . DrawString ( FontManager . InGameFont , " Enter name for " & Me . _defaultName & genderString & " : " , New Vector2 ( CInt ( Core . windowSize . Width / 2 ) - CInt ( FontManager . InGameFont . MeasureString ( " Enter name for " & Me . _defaultName & genderString & " : " ) . X / 2 ) , 96 ) , Color . White )
2016-09-07 18:50:38 +02:00
2022-06-02 12:58:54 +02:00
Canvas . DrawRectangle ( New Rectangle ( CInt ( TextboxPosition ( ) . X ) - 4 , CInt ( TextboxPosition ( ) . Y ) - 4 , 320 + 8 , 32 ) , New Color ( 101 , 142 , 255 ) )
2018-01-07 18:01:32 +01:00
DrawTextBox ( )
2016-09-07 18:50:38 +02:00
End If
2018-01-07 18:01:32 +01:00
End If
2016-09-07 18:50:38 +02:00
PokemonImageView . Draw ( )
2021-10-17 17:44:01 +02:00
ImageView . Draw ( )
2016-09-07 18:50:38 +02:00
End Sub
Private Function TextboxPosition ( ) As Vector2
2022-06-02 12:58:54 +02:00
Return New Vector2 ( CInt ( Core . windowSize . Width / 2 ) - 160 , 140 )
2016-09-07 18:50:38 +02:00
End Function
Private Sub DrawTextBox ( )
2022-06-02 12:58:54 +02:00
Canvas . DrawRectangle ( New Rectangle ( CInt ( TextboxPosition ( ) . X ) , CInt ( TextboxPosition ( ) . Y ) , 320 , 24 ) , Color . White )
2016-09-07 18:50:38 +02:00
Dim t As String = Me . _currentText
If t . Length < 20 Then
t &= " _ "
End If
2022-06-02 12:58:54 +02:00
Core . SpriteBatch . DrawString ( FontManager . InGameFont , t , TextboxPosition ( ) , Color . Black )
2016-09-07 18:50:38 +02:00
End Sub
Public Overrides Sub Update ( )
If CBool ( GameModeManager . GetGameRuleValue ( " ForceRename " , " 0 " ) ) = True Then
Me . _askedRename = True
Me . _canChooseNo = False
End If
Dim mouseOver As Boolean = False
For i = 0 To 1
If New Rectangle ( CInt ( Core . windowSize . Width / 2 ) - 182 + i * 192 , Core . windowSize . Height - 128 , 128 + 32 , 64 + 32 ) . Contains ( MouseHandler . MousePosition ) = True Then
_index = i
mouseOver = True
End If
Next
If Controls . Accept ( True , False , True ) = True Or KeyBoardHandler . KeyPressed ( KeyBindings . EnterKey1 ) = True Then
Select Case _index
Case 0
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 " )
2016-09-07 18:50:38 +02:00
ClickYes ( )
Case 1
If _canChooseNo = True Then
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 " )
2016-09-07 18:50:38 +02:00
ClickNo ( )
End If
End Select
End If
If _askedRename = True Then
If Controls . Right ( True , True , True , False , True ) = True Then
_index = 1
End If
If Controls . Left ( True , True , True , False , True ) = True Then
_index = 0
End If
If _delay > 0 . 0F Then
_delay -= 0 . 1F
If _delay <= 0 . 0F Then
_delay = 0 . 0F
End If
Else
KeyBindings . GetNameInput ( Me . _currentText , 20 )
Me . _currentText = Me . ReplaceInvalidChars ( Me . _currentText )
If Controls . Dismiss ( True , False , True ) = True And _canChooseNo = True Then
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 " )
2016-09-07 18:50:38 +02:00
ClickNo ( )
End If
End If
Else
If Controls . Right ( True , True , True , True , True ) = True Then
_index = 1
End If
If Controls . Left ( True , True , True , True , True ) = True Then
_index = 0
End If
End If
End Sub
''' <summary>
''' This function replaces characters in the string with nothing if the characters aren't allowed in the name.
''' </summary>
''' <param name="text">The name string.</param>
''' <remarks>Only numbers and alphabetic characters are allowed (0-9, a-z, A-Z)</remarks>
Private Function ReplaceInvalidChars ( ByVal text As String ) As String
2017-01-22 00:01:31 +01:00
' Creating the char array:
2023-02-02 15:59:26 +01:00
Dim chars ( ) As Char = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " . ToCharArray ( )
2016-09-07 18:50:38 +02:00
2017-01-22 00:01:31 +01:00
' Create a new string to store the "purified" text in. YOU SHALL NOT PASS, EXTENDED LATIN.
2016-09-07 18:50:38 +02:00
Dim newText As String = " "
2017-01-22 00:01:31 +01:00
' Loop through all of the original text and only put in the allowed ones.
2016-09-07 18:50:38 +02:00
For i = 0 To text . Length - 1
If chars . Contains ( text ( i ) ) = True Then
newText &= text ( i ) . ToString ( )
End If
Next
2017-01-22 00:01:31 +01:00
' Return the newly created string.
2016-09-07 18:50:38 +02:00
Return newText
End Function
Private Sub ClickYes ( )
If _askedRename = True Then
2023-02-23 12:30:24 +01:00
' Remove spaces at the start
While _currentText . StartsWith ( " " )
_currentText = _currentText . Remove ( 0 , 1 )
End While
' Remove spaces at the end
While _currentText . EndsWith ( " " )
_currentText = _currentText . Remove ( _currentText . Length - 1 , 1 )
End While
2016-09-07 18:50:38 +02:00
If _currentText <> " " Then
If _renamePokemon = True Then
If _pokemon . GetName ( ) <> _currentText Then
_pokemon . NickName = _currentText
End If
Else
Me . _acceptName ( _currentText )
End If
PokemonImageView . Showing = False
Core . SetScreen ( Me . PreScreen )
End If
Else
Me . _askedRename = True
If ControllerHandler . IsConnected ( ) = True Then
2023-02-02 15:59:26 +01:00
If _pokemon IsNot Nothing Then
Core . SetScreen ( New InputScreen ( Me , Me . _defaultName , InputScreen . InputModes . Pokemon , Me . _defaultName , 14 , New List ( Of Texture2D ) , AddressOf Me . GetControllerInput ) )
Else
Core . SetScreen ( New InputScreen ( Me , Me . _defaultName , InputScreen . InputModes . Name , Me . _defaultName , 14 , New List ( Of Texture2D ) , AddressOf Me . GetControllerInput ) )
End If
2016-09-07 18:50:38 +02:00
End If
End If
End Sub
Private Sub ClickNo ( )
If Me . _askedRename = True Then
Me . _askedRename = False
Else
PokemonImageView . Showing = False
Core . SetScreen ( Me . PreScreen )
End If
End Sub
Public Sub GetControllerInput ( ByVal input As String )
2023-02-02 15:59:26 +01:00
Me . _currentText = ReplaceInvalidChars ( input )
2016-09-07 18:50:38 +02:00
End Sub
2017-01-22 00:01:31 +01:00
End Class