Notifications Implementation Part 2

This commit is contained in:
JappaWakka 2021-10-11 21:16:39 +02:00
parent d3a010e050
commit 78e25a85c0
8 changed files with 116 additions and 132 deletions

View File

@ -96,8 +96,8 @@ game_interaction_gamemenu,Game Menu
game_interaction_pokegear,Pokégear
game_interaction_pausemenu,Pause Menu
game_interaction_notification,Notification
game_notification_respond,Press <button.special> to respond to the notification.
game_notification_dismiss,Press <button.special> to dismiss the notification.
game_notification_accept,Press <button.special> to accept.
game_notification_dismiss,Press <button.special> to dismiss.
---
MainMenuScreen:
main_menu_continue,Continue

Binary file not shown.

Before

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -4,23 +4,25 @@
Public Class NotificationPopup
Private _background As Texture2D
Private _box As Texture2D
Private _icon As Texture2D
Private FrameSizeBack As Integer
Private FramesizeBox As Integer
Private FramesizeIcon As Integer
Private _positionY As Single = -12
Private _delay As Date
Private _started As Boolean = False
Private _scale As Single = CInt(SpriteBatch.InterfaceScale * 2)
Private _soundEffect As String = ""
Private _text As String = ""
Private _size As Size = New Size(10, 3)
Private _size As Size = New Size(13, 3)
Private _backgroundIndex As Vector2 = New Vector2(0, 0)
Private _iconIndex As Vector2 = New Vector2(0, 0)
Private _delay As Integer = Nothing
Public _delayDate As Date = Nothing
Public _waitForInput As Boolean = False
Public _scriptFile As String = ""
Public _show As Boolean = False
Public IsReady As Boolean = False
''' <summary>
''' Sets the values of the NotificationPopup and displays it on the screen.
@ -28,14 +30,21 @@ Public Class NotificationPopup
Public Sub Setup(Text As String, Optional Delay As Integer = 500, Optional BackgroundIndex As Integer = 0, Optional IconIndex As Integer = 0, Optional SoundEffect As String = "", Optional ScriptFile As String = "")
_text = Text
If Delay <= 0 Then
_waitForInput = True
_delay = Date.Now
If Delay <> -1 Then
If Delay = 0 Then
_waitForInput = True
End If
_delay = Delay
Else
_delay = Date.Now.AddMilliseconds(CDbl(Delay * 10))
_delay = 500
End If
If BackgroundIndex <> -1 Then
_backgroundIndex = New Vector2(BackgroundIndex, 0)
Else
_backgroundIndex = New Vector2(0, 0)
End If
_backgroundIndex = New Vector2(BackgroundIndex, 0)
While _backgroundIndex.X >= 3
_backgroundIndex.X -= 3
_backgroundIndex.Y += 1
@ -43,16 +52,19 @@ Public Class NotificationPopup
If _backgroundIndex.X < 0 Then
_backgroundIndex.X = 0
End If
FrameSizeBack = CInt(TextureManager.GetTexture(GameModeManager.ActiveGameMode.ContentPath & "Textures\Notifications\Backgrounds").Width / 3)
_background = TextureManager.GetTexture(GameModeManager.ActiveGameMode.ContentPath & "Textures\Notifications\Backgrounds", New Rectangle(CInt(_backgroundIndex.X * FrameSizeBack), CInt(_backgroundIndex.Y * FrameSizeBack), FrameSizeBack, FrameSizeBack))
_positionY = CInt(0 - _size.Height * (FrameSizeBack / 3) - 12)
Dim BackTexture As Texture2D = TextureManager.GetTexture("Textures\Notifications\Backgrounds")
FrameSizeBack = CInt(BackTexture.Width / 3)
_background = TextureManager.GetTexture(BackTexture, New Rectangle(CInt(_backgroundIndex.X * FrameSizeBack), CInt(_backgroundIndex.Y * FrameSizeBack), FrameSizeBack, FrameSizeBack))
FramesizeBox = CInt(TextureManager.GetTexture(GameModeManager.ActiveGameMode.ContentPath & "Textures\Notifications\Boxes").Width / 3)
_box = TextureManager.GetTexture(GameModeManager.ActiveGameMode.ContentPath & "Textures\Notifications\Backgrounds", New Rectangle(CInt(_backgroundIndex.X * FramesizeBox), CInt(_backgroundIndex.Y * FramesizeBox), FramesizeBox, FramesizeBox))
_positionY = CInt(0 - _size.Height * (FrameSizeBack / 3) * _scale - 12)
If IconIndex <> -1 Then
_iconIndex = New Vector2(IconIndex, 0)
Else
_iconIndex = New Vector2(0, 0)
End If
FramesizeIcon = CInt(TextureManager.GetTexture(GameModeManager.ActiveGameMode.ContentPath & "Textures\Notifications\Icons").Width / 3)
_iconIndex = New Vector2(IconIndex, 0)
While _iconIndex.X >= 3
_iconIndex.X -= 3
_iconIndex.Y += 1
@ -60,27 +72,14 @@ Public Class NotificationPopup
If _iconIndex.X < 0 Then
_iconIndex.X = 0
End If
_icon = TextureManager.GetTexture(GameModeManager.ActiveGameMode.ContentPath & "Textures\Notifications\Icons", New Rectangle(CInt(_iconIndex.X * FramesizeIcon), CInt(_iconIndex.Y * FramesizeIcon), FramesizeIcon, FramesizeIcon))
Dim IconTexture As Texture2D = TextureManager.GetTexture("Textures\Notifications\Icons")
FramesizeIcon = CInt(IconTexture.Width / 3)
_icon = TextureManager.GetTexture(IconTexture, New Rectangle(CInt(_iconIndex.X * FramesizeIcon), CInt(_iconIndex.Y * FramesizeIcon), FramesizeIcon, FramesizeIcon))
_scriptFile = ScriptFile
If Me._scriptFile <> "" Then
Me._text &= "~[" & Localization.GetString("game_notification_respond") & "]"
Else
Me._text &= "~[" & Localization.GetString("game_notification_dismiss") & "]"
End If
_soundEffect = SoundEffect
_show = True
End Sub
''' <summary>
''' Execute the specified script
''' </summary>
Public Sub Accept()
CType(Core.CurrentScreen, OverworldScreen).ActionScript.StartScript(_scriptFile, 0, False)
Me._waitForInput = False
Me._delay = Date.Now
End Sub
''' <summary>
@ -88,16 +87,21 @@ Public Class NotificationPopup
''' </summary>
Public Sub Dismiss()
Me._waitForInput = False
Me._delay = Date.Now
Me._delayDate = Date.Now
End Sub
''' <summary>
''' Update the NotificationPopup.
''' </summary>
Public Sub Update()
If Date.Now < Me._delay Then
If _started = False Then
_delayDate = Date.Now.AddMilliseconds(CDbl(_delay * 10))
_started = True
End If
If _waitForInput = True Then
If Me._positionY < 5.0F Then
Me._positionY += CInt(0.7 * (FrameSizeBack / _size.Height))
Me._positionY += CInt(0.7 * (FrameSizeBack / 3 * _scale) / _size.Height)
Else
If _soundEffect IsNot "" Then
SoundManager.PlaySound("Notifications\" & _soundEffect)
@ -105,19 +109,27 @@ Public Class NotificationPopup
End If
End If
Else
If _waitForInput = False Then
Dim BackY As Integer = CInt(0 - _size.Height * FrameSizeBack - 12)
If Me._positionY > BackY Then
Me._positionY -= CInt(0.7 * (FrameSizeBack / _size.Height))
If Me._positionY <= BackY Then
Me._positionY = BackY
Me._show = False
If Date.Now < _delayDate Then
If Me._positionY < 5.0F Then
Me._positionY += CInt(0.7 * (FrameSizeBack / 3 * _scale) / _size.Height)
Else
If _soundEffect IsNot "" Then
SoundManager.PlaySound("Notifications\" & _soundEffect)
_soundEffect = ""
End If
End If
Else
If Me._scriptFile <> "" Then
CType(Core.CurrentScreen, OverworldScreen).ActionScript.StartScript(Me._scriptFile, 0, False)
Me._waitForInput = False
Me.IsReady = True
End If
Dim BackY As Integer = CInt(0 - _size.Height * (FrameSizeBack / 3) * _scale - (FrameSizeBack / 3 * _scale) - 5)
If Me._positionY > BackY Then
Me._positionY -= CInt(0.7 * (FrameSizeBack / 3 * _scale) / _size.Height)
If Me._positionY <= BackY Then
Me._positionY = BackY
Me.IsReady = True
End If
End If
End If
End If
@ -127,50 +139,45 @@ Public Class NotificationPopup
''' Renders the NotificationPopup.
''' </summary>
Public Sub Draw()
If Me._show = True Then
Dim TextBody As String = ""
Dim TextHeader As String
Dim Scale As Double = SpriteBatch.InterfaceScale() * 2
Dim TextHeader As String = _text.GetSplit(0, "*").Replace(CChar("~"), Environment.NewLine).CropStringToWidth(FontManager.InGameFont, CInt(_scale), CInt((_size.Width * (FrameSizeBack / 3) - FrameSizeBack / 3 * 4) * _scale))
Dim TextBody As String = _text.GetSplit(1, "*").Replace(CChar("~"), Environment.NewLine)
If _text.Contains("*") Then
TextHeader = _text.GetSplit(0, "*").Replace(CChar("~"), Environment.NewLine)
TextBody = _text.GetSplit(1, "*").Replace(CChar("~"), Environment.NewLine)
While FontManager.InGameFont.MeasureString(TextHeader).Y * 2 + FontManager.InGameFont.MeasureString(TextBody).Y > CInt(((_size.Height * FrameSizeBack / 3) - FrameSizeBack / 3) * _scale - 5)
_size.Height += 1
End While
Dim BackGroundOffsetX As Integer = CInt(Core.windowSize.Width - (_size.Width * (FrameSizeBack / 3) * _scale) - (FrameSizeBack / 3) * 2 - 5)
'Draw the frame.
Canvas.DrawImageBorder(_background, CInt(_scale), New Rectangle(BackGroundOffsetX, CInt(Me._positionY), CInt(_size.Width * (FrameSizeBack / 3) * _scale), CInt(_size.Height * (FrameSizeBack / 3) * _scale)))
'Draw the icon.
Core.SpriteBatch.DrawInterface(_icon, New Rectangle(CInt(BackGroundOffsetX + (FrameSizeBack / 3 + 3) * _scale - _icon.Width / 3), CInt(Me._positionY + ((FrameSizeBack / 3 * _size.Height / 2) - FrameSizeBack / 3 * 0.5) * _scale - _icon.Width / 3), CInt(_icon.Width * _scale), CInt(_icon.Height * _scale)), Color.White)
Dim TextOffset = CInt(BackGroundOffsetX + FrameSizeBack / 3 * _scale * 4)
If TextBody <> "" Then
If TextHeader <> "" Then
'Draw the header, then the body
Core.SpriteBatch.DrawString(FontManager.InGameFont, TextHeader.CropStringToWidth(FontManager.InGameFont, CInt(_scale), CInt((_size.Width * (FrameSizeBack / 3) - FrameSizeBack / 3 * 4) * _scale)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack / 3)), Color.Black, 0.0F, Vector2.Zero, CSng(_scale), SpriteEffects.None, 0.0F)
Core.SpriteBatch.DrawString(FontManager.InGameFont, TextBody.CropStringToWidth(FontManager.InGameFont, CInt(_scale / 2), CInt((_size.Width * (FrameSizeBack / 3) - FrameSizeBack / 3 * 4) * _scale)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack / 3 + (FontManager.InGameFont.MeasureString(TextHeader).Y * _scale))), Color.Black, 0.0F, Vector2.Zero, CSng(_scale / 2), SpriteEffects.None, 0.0F)
Else
TextHeader = _text.Replace(CChar("~"), Environment.NewLine)
End If
While FontManager.InGameFont.MeasureString(_text.Replace(CChar("~"), Environment.NewLine)).Y > CInt(_size.Height * FrameSizeBack - 2 * FrameSizeBack)
_size.Height += 1
End While
Dim BackGroundOffsetX As Integer = CInt(Core.windowSize.Width - _size.Width * FrameSizeBack - 5)
Dim TextOffset As Integer
'Draw the frame.
Canvas.DrawImageBorder(_background, CInt(Scale), New Rectangle(BackGroundOffsetX, CInt(Me._positionY), CInt(_size.Width * FrameSizeBack), CInt(_size.Height * FrameSizeBack)), True)
'Draw the (icon) box.
Core.SpriteBatch.DrawInterface(_box, New Rectangle(CInt(FramesizeBox * Scale + 5), CInt(FramesizeBox * Scale + Me._positionY), CInt(_box.Width * Scale), CInt(_box.Height * Scale)), Color.White)
'Draw the icon.
Core.SpriteBatch.DrawInterface(_icon, New Rectangle(CInt(FramesizeIcon * Scale + 5), CInt(FramesizeIcon * Scale + Me._positionY), CInt(_icon.Width * Scale), CInt(_icon.Height * Scale)), Color.White)
TextOffset = CInt(FrameSizeBack * Scale + BackGroundOffsetX * Scale)
If TextBody <> "" Then
If TextHeader <> "" Then
'Draw the header, then the body
Core.SpriteBatch.DrawInterfaceString(FontManager.InGameFont, TextBody.CropStringToWidth(FontManager.InGameFont, CInt(Scale), CInt(_size.Width * FrameSizeBack - FrameSizeBack * 4)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack)), Color.Black)
Core.SpriteBatch.DrawInterfaceString(FontManager.InGameFont, TextHeader.CropStringToWidth(FontManager.InGameFont, CInt(Scale / 2), CInt(_size.Width * FrameSizeBack - FrameSizeBack * 4)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack + FontManager.InGameFont.MeasureString(TextHeader).Y)), Color.Black)
Else
'Just draw the body
Core.SpriteBatch.DrawInterfaceString(FontManager.InGameFont, TextBody.CropStringToWidth(FontManager.InGameFont, CInt(Scale / 2), CInt(_size.Width * FrameSizeBack - FrameSizeBack * 4)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack)), Color.Black)
End If
Else
'Just draw the header
Core.SpriteBatch.DrawInterfaceString(FontManager.InGameFont, TextHeader.CropStringToWidth(FontManager.InGameFont, CInt(Scale), CInt(_size.Width * FrameSizeBack) - FrameSizeBack * 4), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack)), Color.Black)
'Just draw the body
Core.SpriteBatch.DrawString(FontManager.InGameFont, TextBody.CropStringToWidth(FontManager.InGameFont, CInt(_scale / 2), CInt((_size.Width * (FrameSizeBack / 3) - FrameSizeBack / 3 * 4) * _scale)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack / 3)), Color.Black, 0.0F, Vector2.Zero, CSng(_scale / 2), SpriteEffects.None, 0.0F)
End If
Else
'Just draw the header
Core.SpriteBatch.DrawString(FontManager.InGameFont, TextHeader.CropStringToWidth(FontManager.InGameFont, CInt(_scale), CInt((_size.Width * (FrameSizeBack / 3) - FrameSizeBack / 3 * 4) * _scale)), New Vector2(TextOffset, CInt(Me._positionY + FrameSizeBack / 3)), Color.Black, 0.0F, Vector2.Zero, CSng(_scale), SpriteEffects.None, 0.0F)
End If
Dim InteractText As String = "[" & Localization.GetString("game_notification_dismiss") & "]"
If Me._scriptFile <> "" Then
InteractText = "[" & Localization.GetString("game_notification_accept") & "]"
End If
Dim InteractOffset As Vector2 = New Vector2(CInt(Core.windowSize.Width - FrameSizeBack / 3 * _scale - FontManager.InGameFont.MeasureString(InteractText).X * _scale / 2), CInt(Me._positionY + _size.Height * (FrameSizeBack / 3) * _scale + 5))
Core.SpriteBatch.DrawInterface(_background, New Rectangle(CInt(InteractOffset.X), CInt(InteractOffset.Y), CInt(FontManager.InGameFont.MeasureString(InteractText).X * _scale / 2), CInt(FontManager.InGameFont.MeasureString(InteractText).Y * _scale / 2)), New Rectangle(CInt(FrameSizeBack / 3), CInt(FrameSizeBack / 3), CInt(FrameSizeBack / 3), CInt(FrameSizeBack / 3)), Color.White)
Core.SpriteBatch.DrawString(FontManager.InGameFont, InteractText, New Vector2(CInt(InteractOffset.X), CInt(InteractOffset.Y)), Color.Black)
End Sub
End Class

View File

@ -12,7 +12,8 @@ Public Class OverworldScreen
Private Shared _fadeColor As Color = Color.Black 'Fade screen color.
Private Shared _fadeValue As Integer = 0 'Fade progress value for the screen fade.
Private Shared _drawRodID As Integer = -1 'The rod ID to display on the screen during the fishing animation.
Public NotificationPopupList As List(Of NotificationPopup) = Nothing
Public NotificationPopupList As List(Of NotificationPopup) = New List(Of NotificationPopup)
Private _actionScript As ActionScript 'Private ActionScript instance.
Private _particlesTexture As Texture2D 'A texture field to contain the particles texture, currently only used for the crosshair.
@ -27,7 +28,6 @@ Public Class OverworldScreen
#End Region
#Region "Properties"
''' <summary>
''' Array of Title objects to be rendered on the screen.
''' </summary>
@ -189,14 +189,11 @@ Public Class OverworldScreen
PokemonImageView.Update()
End If
If Level.NotificationPopup IsNot Nothing Then
Level.NotificationPopup.Update()
If Level.NotificationPopup._show = False Then
Level.NotificationPopup = Nothing
If NotificationPopupList.Count > 0 Then
NotificationPopupList(0).Update()
If NotificationPopupList(0).IsReady = True Then
NotificationPopupList.Remove(NotificationPopupList(0))
End If
ElseIf NotificationPopupList.Count > 0 Then
Level.NotificationPopup = NotificationPopupList(0)
NotificationPopupList.RemoveAt(0)
End If
'Middle click/Thumbstick press: Show first Pokémon in party.
@ -235,18 +232,14 @@ Public Class OverworldScreen
'Open the PokégearScreen:
If KeyBoardHandler.KeyPressed(KeyBindings.SpecialKey) = True Or ControllerHandler.ButtonPressed(Buttons.Y) = True Then
If Level.NotificationPopup Is Nothing Then
If NotificationPopupList.Count > 0 Then
NotificationPopupList(0).Dismiss()
Else
If Core.Player.HasPokegear = True Or GameController.IS_DEBUG_ACTIVE = True Or Core.Player.SandBoxMode = True Then
If Screen.Camera.IsMoving() = False And ActionScript.IsReady = True Then
Core.SetScreen(New GameJolt.PokegearScreen(Me, GameJolt.PokegearScreen.EntryModes.MainMenu, {}))
End If
End If
Else
If Level.NotificationPopup._scriptFile <> "" Then
Level.NotificationPopup.Accept()
Else
Level.NotificationPopup.Dismiss()
End If
End If
End If
ActionScript.Update() 'Update the action script.
@ -359,19 +352,16 @@ Public Class OverworldScreen
Level.RouteSign.Draw()
If Level.NotificationPopup IsNot Nothing Then
Level.NotificationPopup.Draw()
If NotificationPopupList.Count > 0 Then
NotificationPopupList(0).Draw()
End If
'If the XBOX render control delay is 0, render the controls.
If ShowControlsDelay = 0.0F Then
Dim d As New Dictionary(Of Buttons, String)
If Level.NotificationPopup IsNot Nothing Then
If Level.NotificationPopup._scriptFile <> "" Then
d.Add(Buttons.A, Localization.GetString("game_interaction_notification", "Notification"))
Else
End If
If NotificationPopupList.Count > 0 Then
d.Add(Buttons.A, Localization.GetString("game_interaction_notification", "Notification"))
Else
d.Add(Buttons.A, Localization.GetString("game_interaction_interact", "Interact"))
End If

View File

@ -15583,7 +15583,7 @@
<Content Include="Content\Textures\Notifications\Backgrounds.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Notifications\Boxes.png">
<Content Include="Content\Textures\Notifications\Icons.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\NPC\0_bow.png">

View File

@ -16,26 +16,22 @@
Dim args As String() = argument.Split(CChar(","))
Select Case args.Length
Case 1
_NotificationPopup.Setup(args(0))
_NotificationPopup.Setup(argument)
Case 2
_NotificationPopup.Setup(args(0), CInt(args(1)))
_NotificationPopup.Setup(args(0), int(args(1)))
Case 3
_NotificationPopup.Setup(args(0), CInt(args(1)), CInt(args(2)))
_NotificationPopup.Setup(args(0), int(args(1)), int(args(2)))
Case 4
_NotificationPopup.Setup(args(0), CInt(args(1)), CInt(args(2)), CInt(args(3)))
_NotificationPopup.Setup(args(0), int(args(1)), int(args(2)), int(args(3)))
Case 5
_NotificationPopup.Setup(args(0), CInt(args(1)), CInt(args(2)), CInt(args(3)), args(4))
_NotificationPopup.Setup(args(0), int(args(1)), int(args(2)), int(args(3)), args(4))
Case 6, 7
_NotificationPopup.Setup(args(0), CInt(args(1)), CInt(args(2)), CInt(args(3)), args(4), args(5))
_NotificationPopup.Setup(args(0), int(args(1)), int(args(2)), int(args(3)), args(4), args(5))
End Select
If args.Length = 7 AndAlso CBool(args(6)) = True Then
CType(CurrentScreen, OverworldScreen).NotificationPopupList.Insert(0, _NotificationPopup)
If Screen.Level.NotificationPopup IsNot Nothing Then
CType(CurrentScreen, OverworldScreen).NotificationPopupList.Insert(1, Screen.Level.NotificationPopup)
Screen.Level.NotificationPopup = Nothing
Else
CType(CurrentScreen, OverworldScreen).NotificationPopupList.Add(_NotificationPopup)
End If
Else
CType(CurrentScreen, OverworldScreen).NotificationPopupList.Add(_NotificationPopup)
End If
Case "show"
Screen.TextBox.reDelay = 0.0F

View File

@ -7,7 +7,6 @@ Public Class Level
#Region "Fields"
Private _routeSign As RouteSign = Nothing
Private _notificationPopup As NotificationPopup = Nothing
Private _world As World = Nothing
Private _pokemonEncounter As PokemonEncounter = Nothing
@ -99,14 +98,6 @@ Public Class Level
Return Me._routeSign
End Get
End Property
Public Property NotificationPopup() As NotificationPopup
Set(value As NotificationPopup)
Me._notificationPopup = value
End Set
Get
Return Me._notificationPopup
End Get
End Property
''' <summary>
''' Indicates whether the player is Surfing.