From 12a08025f9403c81c54dc63dc768c4562bd0e744 Mon Sep 17 00:00:00 2001 From: Eagle Date: Sun, 22 Jun 2025 17:18:42 +0200 Subject: [PATCH] First pass refactor of storage system menu Per-function logic and syntax shrinking, inlining of single-use one-liner functions, addition of variables in some places to reduce line width and increase clarity, merging of filtering regions as they got smaller. Vertical whitespaces have been temporarily added to help with diffing. 2712 -> 1926 lines. --- P3D/Screens/PC/StorageSystemScreen.vb | 2330 ++++++++----------------- 1 file changed, 772 insertions(+), 1558 deletions(-) diff --git a/P3D/Screens/PC/StorageSystemScreen.vb b/P3D/Screens/PC/StorageSystemScreen.vb index dd0ec5b10..ef589933b 100644 --- a/P3D/Screens/PC/StorageSystemScreen.vb +++ b/P3D/Screens/PC/StorageSystemScreen.vb @@ -91,70 +91,51 @@ Public Class StorageSystemScreen End Sub Private Shared Function LoadBoxes() As List(Of Box) - Dim boxes As New List(Of Box) + Dim boxes = New Dictionary(Of Integer, Box) For i = 0 To Core.Player.BoxAmount - 1 - boxes.Add(New Box(i)) + boxes.Add(i, New Box(i)) Next For Each line As String In Core.Player.BoxData.SplitAtNewline() - If line.StartsWith("BOX") = False And line <> "" Then - Dim Data() As String = line.Split(CChar(",")) + If Not line.StartsWith("BOX") And line <> "" Then + Dim Data = line.Split(",") - Dim boxIndex As String = Data(0) - Dim pokemonIndex As String = Data(1) - Dim pokemonData As String = line.Remove(0, line.IndexOf("{")) + Dim boxIndex = CInt(Data(0)) + Dim pokemonIndex = CInt(Data(1)) + Dim pokemonData = line.Remove(0, line.IndexOf("{")) + Dim box As Box = Nothing - If GetBox(CInt(boxIndex), boxes) Is Nothing Then - boxes.Add(New Box(CInt(boxIndex))) + If Not boxes.TryGetValue(boxIndex, box) Then + boxes.Add(boxIndex, New Box(boxIndex)) End If - If GetBox(CInt(boxIndex), boxes).Pokemon.ContainsKey(CInt(pokemonIndex)) = False Then - GetBox(CInt(boxIndex), boxes).Pokemon.Add(CInt(pokemonIndex), New PokemonWrapper(pokemonData)) ' Pokemon.GetPokemonByData(pokemonData)) + If Not box.Pokemon.ContainsKey(pokemonIndex) Then + box.Pokemon.Add(pokemonIndex, New PokemonWrapper(pokemonData)) ' Pokemon.GetPokemonByData(pokemonData)) End If - ElseIf line.StartsWith("BOX") = True Then - Dim boxData() As String = line.Split(CChar("|")) + ElseIf line.StartsWith("BOX") Then + Dim boxData = line.Split("|") - Dim boxIndex As Integer = CInt(boxData(1)) - Dim boxName As String = boxData(2) - Dim boxBackground As Integer = CInt(boxData(3)) + Dim boxIndex = CInt(boxData(1)) + Dim box As Box = Nothing - If GetBox(boxIndex, boxes) Is Nothing Then - boxes.Add(New Box(boxIndex)) + If Not boxes.TryGetValue(boxIndex, box) Then + boxes.Add(boxIndex, New Box(boxIndex)) End If - GetBox(boxIndex, boxes).Background = boxBackground - GetBox(boxIndex, boxes).Name = boxName + box.Background = CInt(boxData(3)) + box.Name = boxData(2) End If Next - Dim minBox As Integer = -1 - Dim maxBox As Integer = -1 + Dim bounds = (min:=boxes.Min(Function(x) x.Value.index), max:=boxes.Max(Function(x) x.Value.index)) - For Each b As Box In boxes - If b.index < minBox Or minBox = -1 Then - minBox = b.index - End If - If b.index > maxBox Or maxBox = -1 Then - maxBox = b.index - End If + For i = bounds.min To bounds.max + If Not boxes.ContainsKey(i) Then boxes.Add(i, New Box(i)) Next + boxes(bounds.max).IsBattleBox = True - For i = minBox To maxBox - If GetBox(i, boxes) Is Nothing Then - boxes.Add(New Box(i)) - End If - Next - - Dim lastBox As Box = boxes(0) - For Each b As Box In boxes - If b.index > lastBox.index Then - lastBox = b - End If - Next - lastBox.IsBattleBox = True - - Return boxes + Return boxes.Values.ToList() End Function Private Sub LoadScreen() @@ -174,77 +155,53 @@ Public Class StorageSystemScreen Public Overrides Sub Update() TextBox.Update() - If ControllerHandler.ButtonPressed(Buttons.Back) = True Or KeyBoardHandler.KeyPressed(KeyBindings.SpecialKey) = True Then + If ControllerHandler.ButtonPressed(Buttons.Back) Or KeyBoardHandler.KeyPressed(KeyBindings.SpecialKey) Then Core.SetScreen(New StorageSystemFilterScreen(Me)) End If - If TextBox.Showing = False Then - If MenuVisible = True Then + If Not TextBox.Showing Then + If MenuVisible Then For i = 0 To Me.MenuEntries.Count - 1 - If i <= Me.MenuEntries.Count - 1 Then - Dim m As MenuEntry = Me.MenuEntries(i) - - m.Update(Me) - End If + If i <= Me.MenuEntries.Count - 1 Then Me.MenuEntries(i).Update(Me) Next - If Controls.Up(True, True) = True Then - Me.MenuCursor -= 1 - End If - If Controls.Down(True, True) = True Then - Me.MenuCursor += 1 - End If + If Controls.Up(True, True) Then Me.MenuCursor -= 1 + If Controls.Down(True, True) Then Me.MenuCursor += 1 - Dim maxIndex As Integer = 0 - Dim minIndex As Integer = 100 + Dim maxIndex = Me.MenuEntries.Max(Function(x) x.Index) + Dim minIndex = Me.MenuEntries.Min(Function(x) x.Index) - For Each e As MenuEntry In Me.MenuEntries - If e.Index < minIndex Then - minIndex = e.Index - End If - If e.Index > maxIndex Then - maxIndex = e.Index - End If - Next - - If Me.MenuCursor > maxIndex Then - Me.MenuCursor = minIndex - ElseIf Me.MenuCursor < minIndex Then - Me.MenuCursor = maxIndex - End If + If Me.MenuCursor > maxIndex Then Me.MenuCursor = minIndex + If Me.MenuCursor < minIndex Then Me.MenuCursor = maxIndex Else TurnModel() - If CursorMoving = True Then + If CursorMoving Then MoveCursor() Else - If ControllerHandler.ButtonPressed(Buttons.RightTrigger) = True Or Controls.Right(True, False, True, False, False, False) = True Then + If ControllerHandler.ButtonPressed(Buttons.RightTrigger) Or Controls.Right(True, False, True, False, False, False) Then Me.CurrentBox += 1 - If CurrentBox > Me.Boxes.Count - 1 Then - CurrentBox = 0 - End If + If CurrentBox > Me.Boxes.Count - 1 Then CurrentBox = 0 End If - If ControllerHandler.ButtonPressed(Buttons.LeftTrigger) = True Or Controls.Left(True, False, True, False, False, False) = True Then + If ControllerHandler.ButtonPressed(Buttons.LeftTrigger) Or Controls.Left(True, False, True, False, False, False) Then Me.CurrentBox -= 1 - If CurrentBox < 0 Then - CurrentBox = Me.Boxes.Count - 1 - End If + If CurrentBox < 0 Then CurrentBox = Me.Boxes.Count - 1 End If PressNumberButtons() - If GetRelativeMousePosition() <> New Vector2(-1) AndAlso GetRelativeMousePosition() = CursorPosition AndAlso Controls.Accept(True, False, False) = True Then + If GetRelativeMousePosition() <> New Vector2(-1) AndAlso GetRelativeMousePosition() = CursorPosition AndAlso Controls.Accept(True, False, False) Then SoundManager.PlaySound("select") ChooseObject() End If ControlCursor() - If Controls.Accept(False, True, True) = True Then + If Controls.Accept(False, True, True) Then SoundManager.PlaySound("select") ChooseObject() End If - If Controls.Dismiss(True, True, True) = True Then + If Controls.Dismiss(True, True, True) Then SoundManager.PlaySound("select") CloseScreen() End If @@ -259,60 +216,24 @@ Public Class StorageSystemScreen End Sub Private Sub TurnModel() - If Controls.ShiftDown("L", False) = True Then - modelRoll -= 0.1F - End If - If ControllerHandler.ButtonDown(Buttons.RightThumbstickLeft) = True Then - Dim gPadState As GamePadState = GamePad.GetState(PlayerIndex.One) + If Controls.ShiftDown("L", False) Then modelRoll -= 0.1F + If Controls.ShiftDown("R", False) Then modelRoll += 0.1F + + If ControllerHandler.ButtonDown(Buttons.RightThumbstickLeft Or Buttons.RightThumbstickRight) Then + Dim gPadState = GamePad.GetState(PlayerIndex.One) modelRoll -= gPadState.ThumbSticks.Right.X * 0.1F End If - If ControllerHandler.ButtonDown(Buttons.RightThumbstickRight) = True Then - Dim gPadState As GamePadState = GamePad.GetState(PlayerIndex.One) - modelRoll -= gPadState.ThumbSticks.Right.X * 0.1F - End If - If Controls.ShiftDown("R", False) = True Then - modelRoll += 0.1F - End If End Sub Private Sub PressNumberButtons() - Dim switchTo As Integer = -1 - If KeyBoardHandler.KeyPressed(Keys.D1) = True Then - switchTo = 0 - End If - If KeyBoardHandler.KeyPressed(Keys.D2) = True Then - switchTo = 1 - End If - If KeyBoardHandler.KeyPressed(Keys.D3) = True Then - switchTo = 2 - End If - If KeyBoardHandler.KeyPressed(Keys.D4) = True Then - switchTo = 3 - End If - If KeyBoardHandler.KeyPressed(Keys.D5) = True Then - switchTo = 4 - End If - If KeyBoardHandler.KeyPressed(Keys.D6) = True Then - switchTo = 5 - End If - If KeyBoardHandler.KeyPressed(Keys.D7) = True Then - switchTo = 6 - End If - If KeyBoardHandler.KeyPressed(Keys.D8) = True Then - switchTo = 7 - End If - If KeyBoardHandler.KeyPressed(Keys.D9) = True Then - switchTo = 8 - End If - If KeyBoardHandler.KeyPressed(Keys.D0) = True Then - switchTo = 9 + Dim switchTo As Integer = If(KeyBoardHandler.KeyPressed(Keys.D0), 9, -1) + If switchTo < 0 Then + Dim keysPressed = KeyBoardHandler.GetPressedKeys.Where(Function(key) key >= Keys.D1 AndAlso key <= Keys.D9) + switchTo = If(keysPressed.Count < 1, switchTo, keysPressed.Max() - Keys.D1) End If - If switchTo > -1 Then - If Me.Boxes.Count - 1 >= switchTo Then - CurrentBox = switchTo - End If - End If + If switchTo < 0 Then Return + If Me.Boxes.Count - 1 >= switchTo Then CurrentBox = switchTo End Sub Private Sub ChooseObject() @@ -321,38 +242,33 @@ Public Class StorageSystemScreen Select Case CursorPosition.X Case 0 Me.CurrentBox -= 1 - If CurrentBox < 0 Then - CurrentBox = Me.Boxes.Count - 1 - End If + If CurrentBox < 0 Then CurrentBox = Me.Boxes.Count - 1 Case 1, 2, 3, 4 - If Me.BoxChooseMode = True Then + If Me.BoxChooseMode Then Me.BoxChooseMode = False - Else - Dim e As New MenuEntry(3, "Choose Box", False, AddressOf Me.ChooseBox) - Dim e1 As New MenuEntry(4, "Change Mode", False, AddressOf Me.ChangemodeMenu) - If GetBox(CurrentBox).IsBattleBox = True Then - Dim e4 As New MenuEntry(5, "Cancel", True, Nothing) - Me.SetupMenu({e, e1, e4}, "What do you want to do?") - Else - Dim e2 As New MenuEntry(5, "Wallpaper", False, AddressOf WallpaperMain) - Dim e3 As New MenuEntry(6, "Name", False, AddressOf SelectNameBox) - Dim e4 As New MenuEntry(7, "Cancel", True, Nothing) - Me.SetupMenu({e, e1, e2, e3, e4}, "What do you want to do?") - End If + Exit Select End If + Dim entries = New List(Of MenuEntry) + entries.Add(New MenuEntry(3, "Choose Box", False, Sub() Me.BoxChooseMode = Not Me.BoxChooseMode)) + entries.Add(New MenuEntry(4, "Change Mode", False, AddressOf Me.ChangemodeMenu)) + Dim battlebox = GetBox(CurrentBox).IsBattleBox + If Not battlebox Then + entries.Add(New MenuEntry(5, "Wallpaper", False, AddressOf WallpaperMain)) + entries.Add(New MenuEntry(6, "Name", False, AddressOf SelectNameBox)) + End If + entries.Add(New MenuEntry(entries.Max(Function(x) x.Index) + 1, "Cancel", True, Nothing)) + Me.SetupMenu(entries.ToArray(), "What do you want to do?") Case 5 Me.CurrentBox += 1 - If CurrentBox > Me.Boxes.Count - 1 Then - CurrentBox = 0 - End If + If CurrentBox > Me.Boxes.Count - 1 Then CurrentBox = 0 Case 6 SelectPokemon() End Select Case 1, 2, 3, 4, 5 - If BoxChooseMode = True And CursorPosition.X < 6 And CursorPosition.Y > 0 Then + If BoxChooseMode And CursorPosition.X < 6 And CursorPosition.Y > 0 Then Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) - If Not GetBox(id) Is Nothing Then + If GetBox(id) IsNot Nothing Then Me.CurrentBox = id Me.BoxChooseMode = False End If @@ -362,45 +278,22 @@ Public Class StorageSystemScreen End Select End Sub -#Region "ChangeMode" - Private Sub ChangemodeMenu() - Dim e As New MenuEntry(3, "Withdraw", False, AddressOf SelectWithdraw) - Dim e1 As New MenuEntry(4, "Deposit", False, AddressOf SelectDeposit) - Dim e2 As New MenuEntry(5, "Single Move", False, AddressOf Me.SelectSingleMove) - Dim e3 As New MenuEntry(6, "Easy Move", False, AddressOf Me.SelectEasyMove) + Dim e As New MenuEntry(3, "Withdraw", False, Sub() Me.SelectionMode = SelectionModes.Withdraw) + Dim e1 As New MenuEntry(4, "Deposit", False, Sub() Me.SelectionMode = SelectionModes.Deposit) + Dim e2 As New MenuEntry(5, "Single Move", False, Sub() Me.SelectionMode = SelectionModes.SingleMove) + Dim e3 As New MenuEntry(6, "Easy Move", False, Sub() Me.SelectionMode = SelectionModes.EasyMove) Dim e4 As New MenuEntry(7, "Cancel", True, AddressOf Me.ChooseObject) Me.SetupMenu({e, e1, e2, e3, e4}, "Choose a mode to use.") End Sub - Private Sub SelectWithdraw() - Me.SelectionMode = SelectionModes.Withdraw - End Sub - - Private Sub SelectDeposit() - Me.SelectionMode = SelectionModes.Deposit - End Sub - - Private Sub SelectSingleMove() - Me.SelectionMode = SelectionModes.SingleMove - End Sub - - Private Sub SelectEasyMove() - Me.SelectionMode = SelectionModes.EasyMove - End Sub - -#End Region - - Private Shadows Sub ChooseBox() - Me.BoxChooseMode = Not Me.BoxChooseMode - End Sub - Private Sub SelectNameBox() - Core.SetScreen(New InputScreen(Core.CurrentScreen, "BOX " & CStr(GetBox(CurrentBox).index + 1), InputScreen.InputModes.Text, GetBox(CurrentBox).Name, 11, New List(Of Texture2D), AddressOf Me.NameBox)) - End Sub - - Private Sub NameBox(ByVal name As String) - GetBox(CurrentBox).Name = name + Dim box = GetBox(CurrentBox) + Dim defaultName = $"BOX{box.index + 1}" + Dim inputMode = InputScreen.InputModes.Text + Dim rename = Sub(name As String) box.Name = name + Dim screen = New InputScreen(Core.CurrentScreen, defaultName, inputMode, box.Name, 11, New List(Of Texture2D), rename) + Core.SetScreen(screen) End Sub #Region "Backgrounds" @@ -408,34 +301,18 @@ Public Class StorageSystemScreen Private Sub WallpaperMain() Dim badges As Integer = Core.Player.Badges.Count - If Core.Player.SandBoxMode = True Or GameController.IS_DEBUG_ACTIVE = True Then + If Core.Player.SandBoxMode Or GameController.IS_DEBUG_ACTIVE Then badges = 16 End If - Select Case badges - Case 0, 1 - Dim e As New MenuEntry(3, "Package 1", False, AddressOf WallpaperPackage1) - Dim e4 As New MenuEntry(4, "Cancel", True, AddressOf ChooseObject) - SetupMenu({e, e4}, "Please pick a theme.") - Case 2, 3, 4 - Dim e As New MenuEntry(3, "Package 1", False, AddressOf WallpaperPackage1) - Dim e1 As New MenuEntry(4, "Package 2", False, AddressOf WallpaperPackage2) - Dim e4 As New MenuEntry(5, "Cancel", True, AddressOf ChooseObject) - SetupMenu({e, e1, e4}, "Please pick a theme.") - Case 5, 6, 7 - Dim e As New MenuEntry(3, "Package 1", False, AddressOf WallpaperPackage1) - Dim e1 As New MenuEntry(4, "Package 2", False, AddressOf WallpaperPackage2) - Dim e2 As New MenuEntry(5, "Package 3", False, AddressOf WallpaperPackage3) - Dim e4 As New MenuEntry(6, "Cancel", True, AddressOf ChooseObject) - SetupMenu({e, e1, e2, e4}, "Please pick a theme.") - Case Else - Dim e As New MenuEntry(3, "Package 1", False, AddressOf WallpaperPackage1) - Dim e1 As New MenuEntry(4, "Package 2", False, AddressOf WallpaperPackage2) - Dim e2 As New MenuEntry(5, "Package 3", False, AddressOf WallpaperPackage3) - Dim e3 As New MenuEntry(6, "Package 4", False, AddressOf WallpaperPackage4) - Dim e4 As New MenuEntry(7, "Cancel", True, AddressOf ChooseObject) - SetupMenu({e, e1, e2, e3, e4}, "Please pick a theme.") - End Select + Dim entries = New List(Of MenuEntry) + Dim cancelIndex = 4 + entries.Add(New MenuEntry(3, "Package 1", False, AddressOf WallpaperPackage1)) + If badges > 1 Then entries.Add(New MenuEntry(4, "Package 2", False, AddressOf WallpaperPackage2)) + If badges > 4 Then entries.Add(New MenuEntry(5, "Package 3", False, AddressOf WallpaperPackage3)) + If badges > 7 Then entries.Add(New MenuEntry(6, "Package 4", False, AddressOf WallpaperPackage4)) + entries.Add(New MenuEntry(entries.Max(Function(x) x.Index) + 1, "Cancel", True, AddressOf ChooseObject)) + SetupMenu(entries.ToArray(), "Please pick a theme.") End Sub Private Sub WallpaperPackage1() @@ -497,163 +374,97 @@ Public Class StorageSystemScreen For y = 0 To t.Height - 1 For x = 0 To t.Width - 1 - If cArr(x + y * t.Height) <> Color.Transparent Then - Me.yOffset = y - Exit For - End If + If cArr(x + y * t.Height) = Color.Transparent Then Continue For + Me.yOffset = y + Exit For Next - If Me.yOffset <> -1 Then - Exit For - End If + If Me.yOffset <> -1 Then Exit For Next End Sub Private Sub MoveCursor() - Dim changedPosition As Boolean = False + Dim changedPosition = CursorMovePosition <> CursorAimPosition - If CursorMovePosition <> CursorAimPosition Then - changedPosition = True - End If + Dim difference = CursorMovePosition - CursorAimPosition + Dim speed = New Vector2(Math.Sign(difference.X), Math.Sign(difference.Y)) * Me.CursorSpeed + CursorMovePosition -= speed - If CursorMovePosition.X < CursorAimPosition.X Then - CursorMovePosition.X += Me.CursorSpeed - If CursorMovePosition.X >= CursorAimPosition.X Then - CursorMovePosition.X = CursorAimPosition.X - End If - End If - If CursorMovePosition.X > CursorAimPosition.X Then - CursorMovePosition.X -= Me.CursorSpeed - If CursorMovePosition.X <= CursorAimPosition.X Then - CursorMovePosition.X = CursorAimPosition.X - End If - End If - If CursorMovePosition.Y < CursorAimPosition.Y Then - CursorMovePosition.Y += Me.CursorSpeed - If CursorMovePosition.Y >= CursorAimPosition.Y Then - CursorMovePosition.Y = CursorAimPosition.Y - End If - End If - If CursorMovePosition.Y > CursorAimPosition.Y Then - CursorMovePosition.Y -= Me.CursorSpeed - If CursorMovePosition.Y <= CursorAimPosition.Y Then - CursorMovePosition.Y = CursorAimPosition.Y - End If - End If + CursorMovePosition.X = If(speed.X > 0, Math.Max(CursorMovePosition.X, CursorAimPosition.X), Math.Min(CursorMovePosition.X, CursorAimPosition.X)) + CursorMovePosition.Y = If(speed.Y > 0, Math.Max(CursorMovePosition.Y, CursorAimPosition.Y), Math.Min(CursorMovePosition.Y, CursorAimPosition.Y)) - If CursorAimPosition = CursorMovePosition Then - Me.CursorMoving = False + If CursorAimPosition <> CursorMovePosition Then Return + Me.CursorMoving = False - If Me.SelectionMode = SelectionModes.EasyMove And changedPosition = True And Me.ClickedObject = True Then - ChooseObject() - End If + If Me.SelectionMode = SelectionModes.EasyMove And changedPosition And Me.ClickedObject Then + ChooseObject() End If End Sub Dim ClickedObject As Boolean = False Private Sub ControlCursor() - Dim PreCursor As Vector2 = CursorPosition - If Controls.Right(True, True, False) = True Then - Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) - Me.CursorPosition.X += 1 - If Me.CursorPosition.Y = 0 And Me.CursorPosition.X > 1 And Me.CursorPosition.X < 5 Then + Dim PreCursor = CursorPosition + Dim box = GetBox(CurrentBox) + Dim direction = Vector2.Zero + Dim cancel = ControllerHandler.ButtonPressed(Buttons.X) + Dim confirm = Controls.Accept(True, False, False) AndAlso GetRelativeMousePosition() <> New Vector2(-1) + Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) + If cancel Then + Me.CursorPosition = New Vector2(1, 0) + ElseIf confirm Then + Me.CursorPosition = GetRelativeMousePosition() + Else + If Controls.Right(True, True, False) Then direction.X += 1 + If Controls.Left(True, True, False) Then direction.X -= 1 + If Controls.Up(True, True, False) Then direction.Y -= 1 + If Controls.Down(True, True, False) Then direction.Y += 1 + Me.CursorPosition += direction + If direction.X > 0 And Me.CursorPosition.Y = 0 And Me.CursorPosition.X > 1 And Me.CursorPosition.X < 5 Then Me.CursorPosition.X = 5 End If - Me.CursorMoving = True - Me.ClickedObject = False - End If - If Controls.Left(True, True, False) = True Then - Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) - Me.CursorPosition.X -= 1 - If Me.CursorPosition.Y = 0 And Me.CursorPosition.X > 0 And Me.CursorPosition.X < 4 Then + If direction.X < 0 And Me.CursorPosition.Y = 0 And Me.CursorPosition.X > 0 And Me.CursorPosition.X < 4 Then Me.CursorPosition.X = 0 End If - Me.CursorMoving = True - Me.ClickedObject = False - End If - If Controls.Up(True, True, False) Then - Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) - Me.CursorPosition.Y -= 1 - Me.CursorMoving = True - Me.ClickedObject = False - End If - If Controls.Down(True, True, False) Then - Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) - Me.CursorPosition.Y += 1 - Me.CursorMoving = True - Me.ClickedObject = False - If Me.CursorPosition.Y = 1 And GetBox(CurrentBox).IsBattleBox = True And Me.CursorPosition.X < 6 And BoxChooseMode = False Then + If direction.Y > 0 And Me.CursorPosition.Y = 1 And box.IsBattleBox And Me.CursorPosition.X < 6 And Not BoxChooseMode Then Me.CursorPosition.X = 2 End If End If - If ControllerHandler.ButtonPressed(Buttons.X) = True Then - Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) - Me.CursorPosition = New Vector2(1, 0) - Me.CursorMoving = True - Me.ClickedObject = False - End If + Me.CursorMoving = cancel Or confirm Or direction <> Vector2.Zero + Me.ClickedObject = confirm - If Controls.Accept(True, False, False) = True AndAlso GetRelativeMousePosition() <> New Vector2(-1) Then - Me.CursorMovePosition = GetAbsoluteCursorPosition(Me.CursorPosition) - Me.CursorPosition = GetRelativeMousePosition() - Me.CursorMoving = True - Me.ClickedObject = True - End If - Dim XRange() As Integer = {0, 6} + Dim XRange() = {0, 6} - If Me.BoxChooseMode = False Then + If Not Me.BoxChooseMode Then If Me.SelectionMode = SelectionModes.Withdraw And CursorPosition.Y > 0 Then - If GetBox(CurrentBox).IsBattleBox = True Then - XRange = {2, 3} - Else - XRange = {0, 5} - End If + XRange = If(box.IsBattleBox, {2, 3}, {0, 5}) ElseIf Me.SelectionMode = SelectionModes.Deposit And CursorPosition.Y > 0 Then XRange = {6, 6} - Else - If GetBox(CurrentBox).IsBattleBox = True Then - If CursorPosition.Y = 0 Then - XRange = {0, 6} - Else - XRange = {2, 6} - End If - End If + ElseIf box.IsBattleBox Then + XRange = If(CursorPosition.Y = 0, {0, 6}, {2, 6}) End If End If - If CursorPosition.X < XRange(0) Then - CursorPosition.X = XRange(1) - End If - If CursorPosition.X > XRange(1) Then - CursorPosition.X = XRange(0) - End If + If CursorPosition.X < XRange(0) Then CursorPosition.X = XRange(1) + If CursorPosition.X > XRange(1) Then CursorPosition.X = XRange(0) - If GetBox(CurrentBox).IsBattleBox = True And Me.BoxChooseMode = False Then + If box.IsBattleBox And Not Me.BoxChooseMode Then If Me.CursorPosition.Y > 0 And Me.CursorPosition.X > 3 And Me.CursorPosition.X < 6 Then - If PreCursor.X > Me.CursorPosition.X Then - Me.CursorPosition.X = 3 - Else - Me.CursorPosition.X = 6 - End If + Me.CursorPosition.X = If(PreCursor.X > Me.CursorPosition.X, 3, 6) End If End If - Dim YRange() As Integer = {0, 5} + Dim YRange() = {0, 5} - If Me.BoxChooseMode = False Then - If GetBox(CurrentBox).IsBattleBox = True And Me.CursorPosition.X < 6 Then + If Not Me.BoxChooseMode Then + If box.IsBattleBox And Me.CursorPosition.X < 6 Then YRange = {0, 3} End If End If - If CursorPosition.Y < YRange(0) Then - CursorPosition.Y = YRange(1) - End If - If CursorPosition.Y > YRange(1) Then - CursorPosition.Y = YRange(0) - End If + If CursorPosition.Y < YRange(0) Then CursorPosition.Y = YRange(1) + If CursorPosition.Y > YRange(1) Then CursorPosition.Y = YRange(0) CursorAimPosition = GetAbsoluteCursorPosition(Me.CursorPosition) @@ -661,20 +472,18 @@ Public Class StorageSystemScreen End Sub Private Sub CloseScreen() - If Me.BoxChooseMode = True Then + If Me.BoxChooseMode Then Me.BoxChooseMode = False Else - If Not MovingPokemon Is Nothing Then + If MovingPokemon IsNot Nothing Then If PickupPlace.X = 6 Then Core.Player.Pokemons.Add(Me.MovingPokemon) Else - Dim id As Integer = CInt(PickupPlace.X) + CInt((PickupPlace.Y - 1) * 6) + Dim id = CInt(PickupPlace.X) + CInt((PickupPlace.Y - 1) * 6) - If GetBox(PickupBox).IsBattleBox = True Then - GetBox(PickupBox).Pokemon.Add(GetBox(PickupBox).Pokemon.Count, New PokemonWrapper(Me.MovingPokemon)) ' Me.MovingPokemon)) - Else - GetBox(PickupBox).Pokemon.Add(id, New PokemonWrapper(Me.MovingPokemon)) ' Me.MovingPokemon) - End If + Dim box = GetBox(PickupBox) + Dim index = If(box.IsBattleBox, box.Pokemon.Count, id) + box.Pokemon.Add(index, New PokemonWrapper(Me.MovingPokemon)) ' Me.MovingPokemon)) CurrentBox = PickupBox End If @@ -693,51 +502,44 @@ Public Class StorageSystemScreen End Sub Private Shared Function GetBoxSaveData(ByVal boxes As List(Of Box)) As String - Dim BoxesFull As Boolean = True - Dim newData As New List(Of String) + Dim BoxesFull = True + Dim newData = New List(Of String) For Each b As Box In boxes - If b.IsBattleBox = False Then - newData.Add("BOX|" & b.index & "|" & b.Name & "|" & b.Background) + If b.IsBattleBox Then Continue For + newData.Add($"BOX|{b.index}|{b.Name}|{b.Background}") - Dim hasPokemon As Boolean = False - For i = 0 To 29 - If b.Pokemon.Keys.Contains(i) = True Then - hasPokemon = True - newData.Add(b.index.ToString() & "," & i.ToString() & "," & b.Pokemon(i).PokemonData) - End If - Next - If hasPokemon = False Then - BoxesFull = False - End If - End If + Dim hasPokemon = False + For i = 0 To 29 + If Not b.Pokemon.ContainsKey(i) Then Continue For + hasPokemon = True + newData.Add($"{b.index},{i},{b.Pokemon(i).PokemonData}") + Next + If Not hasPokemon Then BoxesFull = False Next - Dim addedBoxes As Integer = 0 - If BoxesFull = True And boxes.Count < 30 Then - Dim newBoxes As Integer = (5).Clamp(1, 30 - boxes.Count) + Dim addedBoxes = 0 + If BoxesFull And boxes.Count < 30 Then + Dim newBoxes = 5.Clamp(1, 30 - boxes.Count) addedBoxes = newBoxes For i = 0 To newBoxes - 1 - Dim newBoxID As Integer = boxes.Count - 1 + i + Dim newBoxID = boxes.Count - 1 + i - newData.Add("BOX|" & newBoxID.ToString() & "|BOX " & (newBoxID + 1).ToString() & "|" & Core.Random.Next(0, 19).ToString()) + newData.Add($"BOX|{newBoxID}|BOX {newBoxID + 1}|{Core.Random.Next(0, 19)}") Next End If Dim battleBox As Box = boxes.Last - newData.Add("BOX|" & CStr(boxes.Count - 1 + addedBoxes) & "|" & battleBox.Name & "|" & battleBox.Background) + newData.Add($"BOX|{boxes.Count - 1 + addedBoxes}|{battleBox.Name}|{battleBox.Background}") For i = 0 To 29 - If battleBox.Pokemon.Keys.Contains(i) = True Then - newData.Add(CStr(boxes.Count - 1 + addedBoxes) & "," & i.ToString() & "," & battleBox.Pokemon(i).PokemonData) - End If + If Not battleBox.Pokemon.ContainsKey(i) Then Continue For + newData.Add($"{boxes.Count - 1 + addedBoxes},{i},{battleBox.Pokemon(i).PokemonData}") Next - Dim returnData As String = "" + Dim returnData = "" For Each l As String In newData - If returnData <> "" Then - returnData &= Environment.NewLine - End If + If returnData <> "" Then returnData &= Environment.NewLine returnData &= l Next @@ -747,28 +549,22 @@ Public Class StorageSystemScreen Private Function GetRelativeMousePosition() As Vector2 For x = 0 To 5 For y = 0 To 4 - If New Rectangle(50 + x * 100, 200 + y * 84, 64, 64).Contains(MouseHandler.MousePosition) = True Then + If New Rectangle(50 + x * 100, 200 + y * 84, 64, 64).Contains(MouseHandler.MousePosition) Then Return New Vector2(x, y + 1) End If Next Next For y = 0 To 5 - If New Rectangle(Core.windowSize.Width - 260, y * 100 + 50, 128, 80).Contains(MouseHandler.MousePosition) = True Then + If New Rectangle(Core.windowSize.Width - 260, y * 100 + 50, 128, 80).Contains(MouseHandler.MousePosition) Then Return New Vector2(6, y) End If Next - If New Rectangle(10, 52, 96, 96).Contains(MouseHandler.MousePosition) = True Then - Return New Vector2(0, 0) - End If - If New Rectangle(655, 52, 96, 96).Contains(MouseHandler.MousePosition) = True Then - Return New Vector2(5, 0) - End If + If New Rectangle(10, 52, 96, 96).Contains(MouseHandler.MousePosition) Then Return New Vector2(0, 0) + If New Rectangle(655, 52, 96, 96).Contains(MouseHandler.MousePosition) Then Return New Vector2(5, 0) + If New Rectangle(80, 50, 600, 100).Contains(MouseHandler.MousePosition) Then Return New Vector2(1, 0) - If New Rectangle(80, 50, 600, 100).Contains(MouseHandler.MousePosition) = True Then - Return New Vector2(1, 0) - End If Return New Vector2(-1) End Function @@ -797,337 +593,210 @@ Public Class StorageSystemScreen End Function Private Function GetBattleBoxID() As Integer - Dim id As Integer = -1 - - If CursorPosition.X = 2 Then - Select Case CursorPosition.Y - Case 1 - Return 0 - Case 2 - Return 2 - Case 3 - Return 4 - End Select - ElseIf CursorPosition.X = 3 Then - Select Case CursorPosition.Y - Case 1 - Return 1 - Case 2 - Return 3 - Case 3 - Return 5 - End Select - End If - + If CursorPosition.Y < 1 Or CursorPosition.Y > 3 Then Return -1 + If CursorPosition.X = 2 Then Return CInt(CursorPosition.Y * 2 - 2) + If CursorPosition.X = 3 Then Return CInt(CursorPosition.Y * 2 - 1) Return -1 End Function Private Sub SelectPokemon() - Select Case Me.SelectionMode - Case SelectionModes.SingleMove, SelectionModes.Withdraw, SelectionModes.Deposit - If Me.MovingPokemon Is Nothing Then - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) + If SelectionMode = SelectionModes.EasyMove Then + PickupPokemon() + Return + End If + If SelectionMode <> SelectionModes.SingleMove And SelectionMode <> SelectionModes.Withdraw And SelectionMode <> SelectionModes.Deposit Then + Return + End If + If Me.MovingPokemon IsNot Nothing Then + PickupPokemon() + Return + End If + Dim box = GetBox(CurrentBox) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - If GetBox(CurrentBox).Pokemon.Keys.Contains(id) = True And CursorPosition.X < 6 Or CursorPosition.X = 6 And Core.Player.Pokemons.Count - 1 >= CInt(CursorPosition.Y) Then - Dim p As Pokemon = Nothing - If CursorPosition.X = 6 Then - p = Core.Player.Pokemons(CInt(CursorPosition.Y)) - Else - p = GetBox(CurrentBox).Pokemon(id).GetPokemon() - End If + If box.Pokemon.ContainsKey(id) And CursorPosition.X < 6 Or CursorPosition.X = 6 And Core.Player.Pokemons.Count - 1 >= CInt(CursorPosition.Y) Then + Dim p = If(CursorPosition.X = 6, Core.Player.Pokemons(CInt(CursorPosition.Y)), box.Pokemon(id).GetPokemon()) - Dim e As MenuEntry + Dim entries = New List(Of MenuEntry) - Select Case Me.SelectionMode - Case SelectionModes.Withdraw - e = New MenuEntry(3, "Withdraw", False, AddressOf WithdrawPokemon) - Case SelectionModes.Deposit - e = New MenuEntry(3, "Deposit", False, AddressOf DepositPokemon) - Case Else - e = New MenuEntry(3, "Move", False, AddressOf PickupPokemon) - End Select + If Me.SelectionMode = SelectionModes.Withdraw Then + entries.Add(New MenuEntry(3, "Withdraw", False, AddressOf WithdrawPokemon)) + ElseIf Me.SelectionMode = SelectionModes.Deposit Then + entries.Add(New MenuEntry(3, "Deposit", False, AddressOf DepositPokemon)) + Else + entries.Add(New MenuEntry(3, "Move", False, AddressOf PickupPokemon)) + End If - Dim e1 As New MenuEntry(4, "Summary", False, AddressOf SummaryPokemon) + entries.Add(New MenuEntry(4, "Summary", False, AddressOf SummaryPokemon)) - Dim eMail As MenuEntry = Nothing - If CursorPosition.X = 6 Then - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item IsNot Nothing Then - eMail = New MenuEntry(5, "Take Item", False, AddressOf TakeItemPokemon) - End If - Else - If GetBox(CurrentBox).Pokemon(id).GetPokemon().Item IsNot Nothing Then - eMail = New MenuEntry(5, "Take Item", False, AddressOf TakeItemPokemon) - End If - End If + Dim itemOffset = If(p.Item IsNot Nothing, 1, 0) - If eMail IsNot Nothing Then - Dim e2 As New MenuEntry(6, "Release", False, AddressOf ReleasePokemon) - Dim e3 As New MenuEntry(7, "Cancel", True, Nothing) - SetupMenu({e, e1, eMail, e2, e3}, p.GetDisplayName() & " is selected.") - Else - Dim e2 As New MenuEntry(5, "Release", False, AddressOf ReleasePokemon) - Dim e3 As New MenuEntry(6, "Cancel", True, Nothing) - SetupMenu({e, e1, e2, e3}, p.GetDisplayName() & " is selected.") - End If - - End If - Else - PickupPokemon() - End If - Case SelectionModes.EasyMove - PickupPokemon() - End Select + If p.Item IsNot Nothing Then entries.Add(New MenuEntry(5, "Take Item", False, AddressOf TakeItemPokemon)) + entries.Add(New MenuEntry(5 + itemOffset, "Release", False, AddressOf ReleasePokemon)) + entries.Add(New MenuEntry(6 + itemOffset, "Cancel", True, Nothing)) + SetupMenu(entries.ToArray(), p.GetDisplayName() & " is selected.") + End If End Sub Private Sub PickupPokemon() If CursorPosition.X = 6 Then If Core.Player.Pokemons.Count - 1 >= CursorPosition.Y Then - If Not Me.MovingPokemon Is Nothing Then - Dim l As New List(Of Pokemon) - l.AddRange(Core.Player.Pokemons.ToArray()) - l.RemoveAt(CInt(CursorPosition.Y)) + Dim l As New List(Of Pokemon) + l.AddRange(Core.Player.Pokemons.ToArray()) + l.RemoveAt(CInt(CursorPosition.Y)) + If Me.MovingPokemon IsNot Nothing Then l.Add(Me.MovingPokemon) - Dim hasPokemon As Boolean = False - For Each p As Pokemon In l - If p.IsEgg() = False And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0 Then - hasPokemon = True - Exit For - End If - Next + End If + Dim hasPokemon = l.Any(Function(p) Not p.IsEgg() And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0) - If hasPokemon = True Then - Dim sPokemon As Pokemon = Core.Player.Pokemons(CInt(CursorPosition.Y)) + If Not hasPokemon Then + SetupMenu({New MenuEntry(3, "OK", True, Nothing)}, "Can't remove last Pokémon from party.") + Else + If Me.MovingPokemon IsNot Nothing Then + Dim sPokemon = Core.Player.Pokemons(CInt(CursorPosition.Y)) Me.MovingPokemon.FullRestore() Core.Player.Pokemons.Insert(CInt(CursorPosition.Y), Me.MovingPokemon) - MovingPokemon = sPokemon + Me.MovingPokemon = sPokemon Core.Player.Pokemons.RemoveAt(CInt(CursorPosition.Y) + 1) Else - Dim e As New MenuEntry(3, "OK", True, Nothing) - SetupMenu({e}, "Can't remove last Pokémon from party.") - End If - Else - Dim l As New List(Of Pokemon) - l.AddRange(Core.Player.Pokemons.ToArray()) - l.RemoveAt(CInt(CursorPosition.Y)) - Dim hasPokemon As Boolean = False - For Each p As Pokemon In l - If p.IsEgg() = False And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0 Then - hasPokemon = True - Exit For - End If - Next - - If hasPokemon = True Then Me.MovingPokemon = Core.Player.Pokemons(CInt(CursorPosition.Y)) Core.Player.Pokemons.RemoveAt(CInt(CursorPosition.Y)) PickupBox = 0 PickupPlace = New Vector2(6, 0) - Else - Dim e As New MenuEntry(3, "OK", True, Nothing) - SetupMenu({e}, "Can't remove last Pokémon from party.") End If End If - Else - If Not Me.MovingPokemon Is Nothing Then - Me.MovingPokemon.FullRestore() - Core.Player.Pokemons.Add(Me.MovingPokemon) - Me.MovingPokemon = Nothing - End If + ElseIf Me.MovingPokemon IsNot Nothing Then + Me.MovingPokemon.FullRestore() + Core.Player.Pokemons.Add(Me.MovingPokemon) + Me.MovingPokemon = Nothing End If Else - Dim pokemonExists As Boolean = False - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) + Dim box = GetBox(CurrentBox) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - pokemonExists = GetBox(CurrentBox).Pokemon.Keys.Contains(id) + Dim pokemonExists = box.Pokemon.ContainsKey(id) - If pokemonExists = True Then + If pokemonExists Then If Me.MovingPokemon Is Nothing Then - Me.MovingPokemon = GetBox(CurrentBox).Pokemon(id).GetPokemon() - GetBox(CurrentBox).Pokemon.Remove(id) + Me.MovingPokemon = box.Pokemon(id).GetPokemon() + box.Pokemon.Remove(id) PickupBox = CurrentBox PickupPlace = CursorPosition - RearrangeBattleBox(GetBox(CurrentBox)) + RearrangeBattleBox(box) Else Me.MovingPokemon.FullRestore() - Dim sPokemon As Pokemon = GetBox(CurrentBox).Pokemon(id).GetPokemon() - GetBox(CurrentBox).Pokemon(id) = New PokemonWrapper(Me.MovingPokemon) ' Me.MovingPokemon + Dim sPokemon = box.Pokemon(id).GetPokemon() + box.Pokemon(id) = New PokemonWrapper(Me.MovingPokemon) ' Me.MovingPokemon Me.MovingPokemon = sPokemon End If - Else - If Not Me.MovingPokemon Is Nothing Then - Me.MovingPokemon.FullRestore() + ElseIf Me.MovingPokemon IsNot Nothing Then + Me.MovingPokemon.FullRestore() - If GetBox(CurrentBox).IsBattleBox = True Then - GetBox(CurrentBox).Pokemon.Add(GetBox(CurrentBox).Pokemon.Count, New PokemonWrapper(Me.MovingPokemon)) ' Me.MovingPokemon) - Else - GetBox(CurrentBox).Pokemon.Add(id, New PokemonWrapper(Me.MovingPokemon)) ' Me.MovingPokemon) - End If + Dim index = If(box.IsBattleBox, box.Pokemon.Count, id) + box.Pokemon.Add(index, New PokemonWrapper(Me.MovingPokemon)) ' Me.MovingPokemon) - Me.MovingPokemon = Nothing - End If + Me.MovingPokemon = Nothing End If End If End Sub Private Sub WithdrawPokemon() - If Core.Player.Pokemons.Count < 6 Then - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) + Dim box = GetBox(CurrentBox) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - Dim pokemonExists As Boolean = GetBox(CurrentBox).Pokemon.Keys.Contains(id) - - If pokemonExists = True Then - Core.Player.Pokemons.Add(GetBox(CurrentBox).Pokemon(id).GetPokemon()) - GetBox(CurrentBox).Pokemon.Remove(id) - End If - Else - Dim e As New MenuEntry(3, "OK", True, Nothing) - SetupMenu({e}, "Party is full!") + If Core.Player.Pokemons.Count > 5 Then + SetupMenu({New MenuEntry(3, "OK", True, Nothing)}, "Party is full!") + ElseIf box.Pokemon.ContainsKey(id) Then + Core.Player.Pokemons.Add(box.Pokemon(id).GetPokemon()) + box.Pokemon.Remove(id) End If - - RearrangeBattleBox(GetBox(CurrentBox)) + RearrangeBattleBox(box) End Sub Private Sub DepositPokemon() - If GetBox(CurrentBox).Pokemon.Count < 30 Then - If Core.Player.Pokemons.Count - 1 >= CInt(Me.CursorPosition.Y) Then - Dim l As New List(Of Pokemon) - l.AddRange(Core.Player.Pokemons.ToArray()) - l.RemoveAt(CInt(CursorPosition.Y)) - Dim hasPokemon As Boolean = False - For Each p As Pokemon In l - If p.IsEgg() = False And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0 Then - hasPokemon = True - Exit For - End If - Next + Dim box = GetBox(CurrentBox) + If box.Pokemon.Count > 29 Then Return + If Core.Player.Pokemons.Count - 1 < CInt(Me.CursorPosition.Y) Then Return + Dim l = New List(Of Pokemon) + l.AddRange(Core.Player.Pokemons.ToArray()) + l.RemoveAt(CInt(CursorPosition.Y)) + Dim hasPokemon = l.Any(Function(p) Not p.IsEgg() And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0) - If hasPokemon = True Then - Dim nextIndex As Integer = 0 - While GetBox(CurrentBox).Pokemon.Keys.Contains(nextIndex) = True - nextIndex += 1 - End While - Core.Player.Pokemons(CInt(Me.CursorPosition.Y)).FullRestore() - GetBox(CurrentBox).Pokemon.Add(nextIndex, New PokemonWrapper(Core.Player.Pokemons(CInt(Me.CursorPosition.Y)))) ' Core.Player.Pokemons(CInt(Me.CursorPosition.Y))) - Core.Player.Pokemons.RemoveAt(CInt(Me.CursorPosition.Y)) - Else - Dim e As New MenuEntry(3, "OK", True, Nothing) - SetupMenu({e}, "Can't remove last Pokémon from party.") - End If - End If + If Not hasPokemon Then + SetupMenu({New MenuEntry(3, "OK", True, Nothing)}, "Can't remove last Pokémon from party.") + Else + Dim nextIndex = 0 + While box.Pokemon.ContainsKey(nextIndex) + nextIndex += 1 + End While + Core.Player.Pokemons(CInt(Me.CursorPosition.Y)).FullRestore() + box.Pokemon.Add(nextIndex, New PokemonWrapper(Core.Player.Pokemons(CInt(Me.CursorPosition.Y)))) ' Core.Player.Pokemons(CInt(Me.CursorPosition.Y))) + Core.Player.Pokemons.RemoveAt(CInt(Me.CursorPosition.Y)) End If End Sub Private Sub SummaryPokemon() If CursorPosition.X = 6 Then Core.SetScreen(New SummaryScreen(Me, Core.Player.Pokemons.ToArray(), CInt(CursorPosition.Y))) - Else - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - - Core.SetScreen(New SummaryScreen(Me, GetBox(CurrentBox).GetPokemonList().ToArray(), GetBox(CurrentBox).GetPokemonList().IndexOf(GetBox(CurrentBox).Pokemon(id).GetPokemon()))) + Return End If + Dim box = GetBox(CurrentBox) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) + Dim pokemonList = box.GetPokemonList() + Dim partyIndex = pokemonList.IndexOf(box.Pokemon(id).GetPokemon()) + + Core.SetScreen(New SummaryScreen(Me, pokemonList.ToArray(), partyIndex)) End Sub Private Sub TakeItemPokemon() - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - If CursorPosition.X = 6 Then - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item IsNot Nothing Then - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.IsMail And Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.AdditionalData <> "" Then - Screen.TextBox.Show("The Mail was taken to your~inbox on your PC.") + Dim box = GetBox(CurrentBox) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) + Dim pokemon = If(CursorPosition.X = 6, Core.Player.Pokemons(CInt(CursorPosition.Y)), box.Pokemon(id).GetPokemon) + If pokemon.Item Is Nothing Then Return + If pokemon.Item.IsMail And pokemon.Item.AdditionalData <> "" Then + Screen.TextBox.Show("The Mail was taken to your~inbox on your PC.") - Core.Player.Mails.Add(Items.MailItem.GetMailDataFromString(Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.AdditionalData)) + Core.Player.Mails.Add(Items.MailItem.GetMailDataFromString(pokemon.Item.AdditionalData)) - Core.Player.Pokemons(CInt(CursorPosition.Y)).Item = Nothing - Else - Screen.TextBox.Show("Taken " & Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.OneLineName() & "~from " & Core.Player.Pokemons(CInt(CursorPosition.Y)).GetDisplayName() & ".") - Dim ItemID As String - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.IsGameModeItem Then - ItemID = Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.gmID - Else - ItemID = Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.ID.ToString - End If - Core.Player.Inventory.AddItem(ItemID, 1) - Core.Player.Pokemons(CInt(CursorPosition.Y)).Item = Nothing - End If - End If Else - If GetBox(CurrentBox).Pokemon(id).GetPokemon.Item IsNot Nothing Then - If GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.IsMail And GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.AdditionalData <> "" Then - Screen.TextBox.Show("The Mail was taken to your~inbox on your PC.") + Screen.TextBox.Show($"Taken {pokemon.Item.OneLineName()}~from {pokemon.GetDisplayName()}.") + Dim ItemID = If(pokemon.Item.IsGameModeItem, pokemon.Item.gmID, pokemon.Item.ID.ToString()) - Core.Player.Mails.Add(Items.MailItem.GetMailDataFromString(GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.AdditionalData)) + Core.Player.Inventory.AddItem(ItemID, 1) - GetBox(CurrentBox).Pokemon(id).GetPokemon.Item = Nothing - Else - Screen.TextBox.Show("Taken " & GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.OneLineName() & "~from " & GetBox(CurrentBox).Pokemon(id).GetPokemon.GetDisplayName() & ".") - Dim ItemID As String - If GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.IsGameModeItem Then - ItemID = GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.gmID - Else - ItemID = GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.ID.ToString - End If - Core.Player.Inventory.AddItem(ItemID, 1) - GetBox(CurrentBox).Pokemon(id).GetPokemon.Item = Nothing - End If - End If End If + pokemon.Item = Nothing End Sub Private Sub ReleasePokemon() - Dim hasPokemon As Boolean = False + Dim hasPokemon = False - If Me.CursorPosition.X = 6 Then - Dim l As New List(Of Pokemon) + If Me.CursorPosition.X <> 6 Then + hasPokemon = True + Else + Dim l = New List(Of Pokemon) l.AddRange(Core.Player.Pokemons.ToArray()) l.RemoveAt(CInt(CursorPosition.Y)) - For Each p As Pokemon In l - If p.IsEgg() = False And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0 Then - hasPokemon = True - Exit For - End If - Next - Else - hasPokemon = True + hasPokemon = l.Any(Function(p) Not p.IsEgg() And p.Status <> Pokemon.StatusProblems.Fainted And p.HP > 0) End If - If hasPokemon = True Then - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) + If hasPokemon Then + Dim box = GetBox(CurrentBox) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - Dim p As Pokemon = Nothing - If CursorPosition.X = 6 Then - p = Core.Player.Pokemons(CInt(CursorPosition.Y)) - Else - p = GetBox(CurrentBox).Pokemon(id).GetPokemon() - End If + Dim p = If(CursorPosition.X = 6, Core.Player.Pokemons(CInt(CursorPosition.Y)), box.Pokemon(id).GetPokemon()) - If p.IsEgg() = False Then + If Not p.IsEgg() Then Dim e1 As New MenuEntry(3, "No", True, AddressOf SelectPokemon) Dim e As New MenuEntry(4, "Yes", False, AddressOf ConfirmRelease) - Me.SetupMenu({e1, e}, "Release " & p.GetDisplayName() & "?") + Me.SetupMenu({e1, e}, $"Release {p.GetDisplayName()}?") Else Me.SetupMenu({New MenuEntry(3, "OK", True, Nothing)}, "Cannot release an Egg.") End If @@ -1137,65 +806,39 @@ Public Class StorageSystemScreen End Sub Private Sub ConfirmRelease() - Dim id As Integer = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) - If CursorPosition.X = 6 Then - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item IsNot Nothing Then - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.IsMail And Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.AdditionalData <> "" Then - Screen.TextBox.Show("The Mail was taken to your~inbox on your PC.") + Dim id = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) + Dim box = GetBox(CurrentBox) + Dim pokemon = If(CursorPosition.X = 6, Core.Player.Pokemons(CInt(CursorPosition.Y)), box.Pokemon(id).GetPokemon()) + If pokemon.Item IsNot Nothing Then + If pokemon.Item.IsMail And pokemon.Item.AdditionalData <> "" Then + Screen.TextBox.Show("The Mail was taken to your~inbox on your PC.") - Core.Player.Mails.Add(Items.MailItem.GetMailDataFromString(Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.AdditionalData)) + Core.Player.Mails.Add(Items.MailItem.GetMailDataFromString(pokemon.Item.AdditionalData)) - Core.Player.Pokemons(CInt(CursorPosition.Y)).Item = Nothing - Else - Screen.TextBox.Show("Taken " & Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.OneLineName() & "~from " & Core.Player.Pokemons(CInt(CursorPosition.Y)).GetDisplayName() & ".") - Dim ItemID As String - If Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.IsGameModeItem Then - ItemID = Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.gmID - Else - ItemID = Core.Player.Pokemons(CInt(CursorPosition.Y)).Item.ID.ToString - End If - Core.Player.Inventory.AddItem(ItemID, 1) - Core.Player.Pokemons(CInt(CursorPosition.Y)).Item = Nothing - End If + Else + Screen.TextBox.Show($"Taken {pokemon.Item.OneLineName()}~from {pokemon.GetDisplayName()}.") + Dim ItemID = If(pokemon.Item.IsGameModeItem, pokemon.Item.gmID, pokemon.Item.ID.ToString()) + Core.Player.Inventory.AddItem(ItemID, 1) End If - Screen.TextBox.Show("Goodbye, " & Core.Player.Pokemons(CInt(CursorPosition.Y)).GetDisplayName() & "!") + pokemon.Item = Nothing + End If + Screen.TextBox.Show($"Goodbye, {pokemon.GetDisplayName()}!") + If CursorPosition.X = 6 Then Core.Player.Pokemons.RemoveAt(CInt(CursorPosition.Y)) Else - If GetBox(CurrentBox).Pokemon(id).GetPokemon.Item IsNot Nothing Then - If GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.IsMail And GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.AdditionalData <> "" Then - Screen.TextBox.Show("The Mail was taken to your~inbox on your PC.") - - Core.Player.Mails.Add(Items.MailItem.GetMailDataFromString(GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.AdditionalData)) - - GetBox(CurrentBox).Pokemon(id).GetPokemon.Item = Nothing - Else - Screen.TextBox.Show("Taken " & GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.OneLineName() & "~from " & GetBox(CurrentBox).Pokemon(id).GetPokemon.GetDisplayName() & ".") - Dim ItemID As String - If GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.IsGameModeItem Then - ItemID = GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.gmID - Else - ItemID = GetBox(CurrentBox).Pokemon(id).GetPokemon.Item.ID.ToString - End If - Core.Player.Inventory.AddItem(ItemID, 1) - GetBox(CurrentBox).Pokemon(id).GetPokemon.Item = Nothing - End If - End If - - Screen.TextBox.Show("Goodbye, " & GetBox(CurrentBox).Pokemon(id).GetPokemon.GetDisplayName() & "!") - GetBox(CurrentBox).Pokemon.Remove(id) + box.Pokemon.Remove(id) End If End Sub Private Sub RearrangeBattleBox(ByVal b As Box) - If b.IsBattleBox = True Then - Dim p As List(Of Pokemon) = b.GetPokemonList() - b.Pokemon.Clear() + If Not b.IsBattleBox Then Return + Dim p = b.GetPokemonList() + b.Pokemon.Clear() - For i = 0 To p.Count - 1 - b.Pokemon.Add(i, New PokemonWrapper(p(i))) ' p(i)) - Next - End If + For i = 0 To p.Count - 1 + b.Pokemon.Add(i, New PokemonWrapper(p(i))) ' p(i)) + Next End Sub #End Region @@ -1210,280 +853,220 @@ Public Class StorageSystemScreen DrawTopBar() DrawTeamWindow() - If Me.MenuVisible = False Then - DrawCursor() - Else - DrawMenuEntries() - End If + Dim action = If(Me.MenuVisible, CType(AddressOf Me.DrawMenuEntries, Action), AddressOf Me.DrawCursor) + action() TextBox.Draw() End Sub Private Sub DrawTopBar() - Dim b As Box = Nothing - Dim boxIndex As Integer = 0 - If BoxChooseMode = True Then - If CursorPosition.X < 6 And CursorPosition.Y > 0 Then - boxIndex = CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6) - Else - boxIndex = CurrentBox - End If - Else - boxIndex = Me.CurrentBox + Dim boxIndex = Me.CurrentBox + If BoxChooseMode Then + boxIndex = If(CursorPosition.X < 6 And CursorPosition.Y > 0, CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6), CurrentBox) End If - b = GetBox(boxIndex) + Dim b = GetBox(boxIndex) - If Not b Is Nothing Then - If b.IsBattleBox = True Then - Core.SpriteBatch.Draw(TextureManager.GetTexture("GUI\Box\BattleBox"), New Rectangle(80, 50, 600, 100), Color.White) + If b Is Nothing Then Return + Dim texturePath = If(b.IsBattleBox, "GUI\Box\BattleBox", $"GUI\Box\{b.Background}") + Core.SpriteBatch.Draw(TextureManager.GetTexture(texturePath), New Rectangle(80, 50, 600, 100), Color.White) - Dim cArr(0) As Color - TextureManager.GetTexture("GUI\Box\BattleBox", New Rectangle(0, 0, 1, 1), "").GetData(cArr) - Canvas.DrawScrollBar(New Vector2(80, 36), Me.Boxes.Count, 1, boxIndex, New Size(600, 14), True, New Color(0, 0, 0, 0), cArr(0)) - Else - Core.SpriteBatch.Draw(TextureManager.GetTexture("GUI\Box\" & b.Background.ToString()), New Rectangle(80, 50, 600, 100), Color.White) - - Dim cArr(0) As Color - TextureManager.GetTexture("GUI\Box\" & b.Background, New Rectangle(0, 0, 1, 1), "").GetData(cArr) - Canvas.DrawScrollBar(New Vector2(80, 36), Me.Boxes.Count, 1, boxIndex, New Size(600, 14), True, New Color(0, 0, 0, 0), cArr(0)) - End If + Dim cArr(0) As Color + TextureManager.GetTexture(texturePath, New Rectangle(0, 0, 1, 1), "").GetData(cArr) + Canvas.DrawScrollBar(New Vector2(80, 36), Me.Boxes.Count, 1, boxIndex, New Size(600, 14), True, Color.TransparentBlack, cArr(0)) - Core.SpriteBatch.DrawString(FontManager.MainFont, b.Name, New Vector2(384 - FontManager.MainFont.MeasureString(b.Name).X, 80), Color.Black, 0.0F, New Vector2(0), 2, SpriteEffects.None, 0.0F) - Core.SpriteBatch.DrawString(FontManager.MainFont, b.Name, New Vector2(380 - FontManager.MainFont.MeasureString(b.Name).X, 76), Color.White, 0.0F, New Vector2(0), 2, SpriteEffects.None, 0.0F) - Core.SpriteBatch.Draw(Me.menuTexture, New Rectangle(10, 52, 96, 96), New Rectangle(0, 16, 16, 16), Color.White) - Core.SpriteBatch.Draw(Me.menuTexture, New Rectangle(655, 52, 96, 96), New Rectangle(0, 16, 16, 16), Color.White, 0.0F, New Vector2(0), SpriteEffects.FlipHorizontally, 0.0F) - End If + Core.SpriteBatch.DrawString(FontManager.MainFont, b.Name, New Vector2(384 - FontManager.MainFont.MeasureString(b.Name).X, 80), Color.Black, 0.0F, New Vector2(0), 2, SpriteEffects.None, 0.0F) + Core.SpriteBatch.DrawString(FontManager.MainFont, b.Name, New Vector2(380 - FontManager.MainFont.MeasureString(b.Name).X, 76), Color.White, 0.0F, New Vector2(0), 2, SpriteEffects.None, 0.0F) + + Core.SpriteBatch.Draw(Me.menuTexture, New Rectangle(10, 52, 96, 96), New Rectangle(0, 16, 16, 16), Color.White) + Core.SpriteBatch.Draw(Me.menuTexture, New Rectangle(655, 52, 96, 96), New Rectangle(0, 16, 16, 16), Color.White, 0.0F, New Vector2(0), SpriteEffects.FlipHorizontally, 0.0F) End Sub Private Sub DrawMainWindow() - If BoxChooseMode = True Then + If BoxChooseMode Then Canvas.DrawRectangle(Core.windowSize, New Color(220, 220, 220)) For x = 0 To 5 For y = 0 To 4 - Dim id As Integer = y * 6 + x + Dim id = y * 6 + x - If Me.Boxes.Count - 1 >= id Then - Dim pCount As Integer = BoxPokemonCount(id, True) + If Me.Boxes.Count - 1 < id Then Continue For + Dim pCount = BoxPokemonCount(id, True) - Dim tCoord As New Vector2(64, 0) - If pCount = 0 Then - tCoord = New Vector2(64, 32) - ElseIf pCount = 30 Then - tCoord = New Vector2(32, 32) - End If + Dim tCoord = New Vector2(64, 0) + If pCount = 0 Then tCoord = New Vector2(64, 32) + If pCount = 30 Then tCoord = New Vector2(32, 32) - Core.SpriteBatch.Draw(Me.texture, New Rectangle(50 + x * 100, 200 + y * 84, 64, 64), New Rectangle(CInt(tCoord.X), CInt(tCoord.Y), 32, 32), Color.White) - End If + Core.SpriteBatch.Draw(Me.texture, New Rectangle(50 + x * 100, 200 + y * 84, 64, 64), New Rectangle(CInt(tCoord.X), CInt(tCoord.Y), 32, 32), Color.White) Next Next + Return + End If + Dim box = GetBox(CurrentBox) + If box.IsBattleBox Then + Canvas.DrawGradient(Core.windowSize, New Color(203, 40, 41), New Color(238, 128, 128), False, -1) + + Dim cArr(0) As Color + TextureManager.GetTexture("GUI\Box\BattleBox", New Rectangle(0, 0, 1, 1), "").GetData(cArr) + + For i = 0 To 5 + Dim x = i + 2 + Dim y = 0 + While x > 3 + x -= 2 + y += 1 + End While + Canvas.DrawRectangle(New Rectangle(50 + x * 100, 200 + y * 84, 64, 64), New Color(cArr(0).R, cArr(0).G, cArr(0).B, 150)) + + If Not box.Pokemon.ContainsKey(i) Then Continue For + Dim pokemon = box.Pokemon(i).GetPokemon() + Dim c = If(IsLit(pokemon), Color.White, New Color(65, 65, 65, 255)) + Dim pokeTexture = pokemon.GetMenuTexture() + Dim pokeTextureScale = New Vector2(CSng(32 / pokeTexture.Width) * 2, CSng(32 / pokeTexture.Height) * 2) + Core.SpriteBatch.Draw(pokeTexture, New Rectangle(50 + x * 100, 200 + y * 84, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) + If pokemon.Item Is Nothing Or pokemon.IsEgg() Then Continue For + Core.SpriteBatch.Draw(pokemon.Item.Texture, New Rectangle(CInt(50 + x * 100 + 32), CInt(200 + y * 84 + 32), 24, 24), Color.White) + Next Else - If GetBox(CurrentBox).IsBattleBox = True Then - Canvas.DrawGradient(Core.windowSize, New Color(203, 40, 41), New Color(238, 128, 128), False, -1) + Dim xt = box.Background + Dim yt = 0 + While xt > 7 + xt -= 8 + yt += 1 + End While + For x = 0 To Core.windowSize.Width Step 64 + For y = 0 To Core.windowSize.Height Step 64 + Core.SpriteBatch.Draw(Me.texture, New Rectangle(x, y, 64, 64), New Rectangle(xt * 16, yt * 16 + 64, 16, 16), Color.White) + Next + Next - Dim cArr(0) As Color - TextureManager.GetTexture("GUI\Box\BattleBox", New Rectangle(0, 0, 1, 1), "").GetData(cArr) + Dim cArr(0) As Color + TextureManager.GetTexture("GUI\Box\" & box.Background, New Rectangle(0, 0, 1, 1), "").GetData(cArr) + For x = 0 To 5 + For y = 0 To 4 + Dim id = y * 6 + x - For i = 0 To 5 - Dim id As Integer = i - Dim x As Integer = i + 2 - Dim y As Integer = 0 - While x > 3 - x -= 2 - y += 1 - End While Canvas.DrawRectangle(New Rectangle(50 + x * 100, 200 + y * 84, 64, 64), New Color(cArr(0).R, cArr(0).G, cArr(0).B, 150)) - Dim box As Box = GetBox(CurrentBox) - If box.Pokemon.Keys.Contains(id) = True Then - Dim c As Color = Color.White - If IsLit(box.Pokemon(id).GetPokemon()) = False Then - c = New Color(65, 65, 65, 255) - End If - Dim pokeTexture = box.Pokemon(id).GetPokemon().GetMenuTexture() - Dim pokeTextureScale As Vector2 = New Vector2(CSng(32 / pokeTexture.Width) * 2, CSng(32 / pokeTexture.Height) * 2) - Core.SpriteBatch.Draw(pokeTexture, New Rectangle(50 + x * 100, 200 + y * 84, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) - If Not box.Pokemon(id).GetPokemon().Item Is Nothing And box.Pokemon(id).GetPokemon().IsEgg() = False Then - Core.SpriteBatch.Draw(box.Pokemon(id).GetPokemon().Item.Texture, New Rectangle(CInt(50 + x * 100 + 32), CInt(200 + y * 84 + 32), 24, 24), Color.White) - End If - End If + If Not box.Pokemon.ContainsKey(id) Then Continue For + Dim pokemon = box.Pokemon(id).GetPokemon() + Dim c = If(IsLit(pokemon), Color.White, New Color(65, 65, 65, 255)) + Dim pokeTexture = pokemon.GetMenuTexture() + Dim pokeTextureScale = New Vector2(CSng(32 / pokeTexture.Width) * 2, CSng(32 / pokeTexture.Height) * 2) + Core.SpriteBatch.Draw(pokeTexture, New Rectangle(50 + x * 100, 200 + y * 84, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) + If pokemon.Item Is Nothing Or pokemon.IsEgg() Then Continue For + Core.SpriteBatch.Draw(pokemon.Item.Texture, New Rectangle(CInt(50 + x * 100 + 32), CInt(200 + y * 84 + 32), 24, 24), Color.White) Next - Else - Dim xt As Integer = GetBox(CurrentBox).Background - Dim yt As Integer = 0 - - While xt > 7 - xt -= 8 - yt += 1 - End While - - For x = 0 To Core.windowSize.Width Step 64 - For y = 0 To Core.windowSize.Height Step 64 - Core.SpriteBatch.Draw(Me.texture, New Rectangle(x, y, 64, 64), New Rectangle(xt * 16, yt * 16 + 64, 16, 16), Color.White) - Next - Next - - Dim cArr(0) As Color - TextureManager.GetTexture("GUI\Box\" & GetBox(CurrentBox).Background, New Rectangle(0, 0, 1, 1), "").GetData(cArr) - For x = 0 To 5 - For y = 0 To 4 - Dim id As Integer = y * 6 + x - - Canvas.DrawRectangle(New Rectangle(50 + x * 100, 200 + y * 84, 64, 64), New Color(cArr(0).R, cArr(0).G, cArr(0).B, 150)) - - Dim box As Box = GetBox(CurrentBox) - If box.Pokemon.Keys.Contains(id) = True Then - Dim c As Color = Color.White - If IsLit(box.Pokemon(id).GetPokemon()) = False Then - c = New Color(65, 65, 65, 255) - End If - Dim pokeTexture = box.Pokemon(id).GetPokemon().GetMenuTexture() - Dim pokeTextureScale As Vector2 = New Vector2(CSng(32 / pokeTexture.Width) * 2, CSng(32 / pokeTexture.Height) * 2) - Core.SpriteBatch.Draw(pokeTexture, New Rectangle(50 + x * 100, 200 + y * 84, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) - If Not box.Pokemon(id).GetPokemon().Item Is Nothing And box.Pokemon(id).GetPokemon().IsEgg() = False Then - Core.SpriteBatch.Draw(box.Pokemon(id).GetPokemon().Item.Texture, New Rectangle(CInt(50 + x * 100 + 32), CInt(200 + y * 84 + 32), 24, 24), Color.White) - End If - End If - Next - Next - Core.SpriteBatch.DrawString(FontManager.MainFont, "Press" & " " & KeyBindings.SpecialKey.ToString & " " & "on the keyboard to filter.", New Vector2(44, 200 + 5 * 84), Color.Black) - Core.SpriteBatch.DrawString(FontManager.MainFont, "Press" & " " & KeyBindings.SpecialKey.ToString & " " & "on the keyboard to filter.", New Vector2(44 - 2, 200 + 5 * 84 - 2), Color.White) - End If + Next + Core.SpriteBatch.DrawString(FontManager.MainFont, "Press" & " " & KeyBindings.SpecialKey.ToString & " " & "on the keyboard to filter.", New Vector2(44, 200 + 5 * 84), Color.Black) + Core.SpriteBatch.DrawString(FontManager.MainFont, "Press" & " " & KeyBindings.SpecialKey.ToString & " " & "on the keyboard to filter.", New Vector2(44 - 2, 200 + 5 * 84 - 2), Color.White) End If End Sub Dim yOffset As Integer = 0 Private Sub DrawPokemonStatus() - If Me.BoxChooseMode = True And CursorPosition.X < 6 And CursorPosition.Y > 0 Then - Dim box As Box = GetBox(CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) + If Me.BoxChooseMode And CursorPosition.X < 6 And CursorPosition.Y > 0 Then + Dim box = GetBox(CInt(CursorPosition.X) + CInt((CursorPosition.Y - 1) * 6)) - If Not box Is Nothing Then + If box IsNot Nothing Then Canvas.DrawRectangle(New Rectangle(660, 200, 200, 200), New Color(84, 198, 216, 150)) - Dim minLevel As Integer = -1 - Dim maxLevel As Integer = -1 + Dim minLevel = -1 + Dim maxLevel = -1 For x = 0 To 5 For y = 0 To 4 - Dim id As Integer = y * 6 + x + Dim id = y * 6 + x - If box.Pokemon.Keys.Contains(id) = True Then - Dim c As Color = Color.White - If IsLit(box.Pokemon(id).GetPokemon()) = False Then - c = New Color(65, 65, 65, 255) - End If + If Not box.Pokemon.ContainsKey(id) Then Continue For + Dim pokemon = box.Pokemon(id).GetPokemon() + Dim c = If(IsLit(pokemon), Color.White, New Color(65, 65, 65, 255)) - Dim pokeTexture = box.Pokemon(id).GetPokemon().GetMenuTexture() - Dim pokeTextureScale As Vector2 = New Vector2(CSng(32 / pokeTexture.Width), CSng(32 / pokeTexture.Height)) - Core.SpriteBatch.Draw(pokeTexture, New Rectangle(664 + x * 32, 215 + y * 32, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) + Dim pokeTexture = pokemon.GetMenuTexture() + Dim pokeTextureScale = New Vector2(CSng(32 / pokeTexture.Width), CSng(32 / pokeTexture.Height)) + Core.SpriteBatch.Draw(pokeTexture, New Rectangle(664 + x * 32, 215 + y * 32, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) - If box.Pokemon(id).GetPokemon().Level < minLevel Or minLevel = -1 Then - minLevel = box.Pokemon(id).GetPokemon().Level - End If - If box.Pokemon(id).GetPokemon().Level > maxLevel Or maxLevel = -1 Then - maxLevel = box.Pokemon(id).GetPokemon().Level - End If - End If + If pokemon.Level < minLevel Or minLevel = -1 Then minLevel = pokemon.Level + If pokemon.Level > maxLevel Or maxLevel = -1 Then maxLevel = pokemon.Level Next Next Canvas.DrawRectangle(New Rectangle(660, 410, 200, 210), New Color(84, 198, 216, 150)) - Dim levelString As String = minLevel & " - " & maxLevel - If minLevel = -1 Or maxLevel = -1 Then - levelString = "None" - End If + Dim levelString = If(minLevel = -1 Or maxLevel = -1, "None", $"{minLevel} - {maxLevel}") - Dim maxPokemon As Integer = 30 - If box.IsBattleBox = True Then - maxPokemon = 6 - End If + Dim maxPokemon = If(box.IsBattleBox, 6, 30) - Dim t As String = "Box: " & box.Name & Environment.NewLine & "Pokémon: " & box.Pokemon.Count & " / " & maxPokemon & Environment.NewLine & "Level: " & levelString + Dim t = $"Box: {box.Name}{Environment.NewLine}" + t &= $"Pokémon: {box.Pokemon.Count} / {maxPokemon}{Environment.NewLine}" + t &= $"Level: {levelString}" Core.SpriteBatch.DrawString(FontManager.MainFont, t, New Vector2(667, 417), Color.Black) Core.SpriteBatch.DrawString(FontManager.MainFont, t, New Vector2(665, 415), Color.White) End If Else - Dim p As Pokemon = Nothing + Dim box = GetBox(CurrentBox) + Dim p = Me.MovingPokemon - If Not Me.MovingPokemon Is Nothing Then - p = Me.MovingPokemon - Else + If p Is Nothing Then If CursorPosition.X = 6 Then If Core.Player.Pokemons.Count - 1 >= CursorPosition.Y Then p = Core.Player.Pokemons(CInt(CursorPosition.Y)) End If Else - Dim id As Integer = CInt(Me.CursorPosition.X) + CInt((Me.CursorPosition.Y - 1) * 6) + Dim id = If(box.IsBattleBox, GetBattleBoxID(), CInt(Me.CursorPosition.X) + CInt((Me.CursorPosition.Y - 1) * 6)) - If GetBox(CurrentBox).IsBattleBox = True Then - id = GetBattleBoxID() - End If - If GetBox(CurrentBox).Pokemon.Keys.Contains(id) = True Then - p = GetBox(CurrentBox).Pokemon(id).GetPokemon() + If box.Pokemon.ContainsKey(id) Then + p = box.Pokemon(id).GetPokemon() End If End If End If - If Not p Is Nothing Then + If p IsNot Nothing Then Dim cArr(0) As Color - If GetBox(CurrentBox).IsBattleBox = True Then - TextureManager.GetTexture("GUI\Box\BattleBox", New Rectangle(0, 0, 1, 1), "").GetData(cArr) - Else - TextureManager.GetTexture("GUI\Box\" & GetBox(CurrentBox).Background, New Rectangle(0, 0, 1, 1), "").GetData(cArr) - End If + Dim texturePath = If(box.IsBattleBox, "GUI\Box\BattleBox", $"GUI\Box\{box.Background}") + TextureManager.GetTexture(texturePath, New Rectangle(0, 0, 1, 1), "").GetData(cArr) - Dim c As Color = New Color(cArr(0).R, cArr(0).G, cArr(0).B, 150) - If BoxChooseMode = True Then - c = New Color(84, 198, 216, 150) - End If + Dim c = If(BoxChooseMode, New Color(84, 198, 216, 150), New Color(cArr(0).R, cArr(0).G, cArr(0).B, 150)) Canvas.DrawRectangle(New Rectangle(660, 200, 256, 256), c) - Dim modelName As String = p.AnimationName - Dim shinyString As String = "Normal" - If p.IsShiny = True Then - shinyString = "Shiny" - End If - If Core.Player.ShowModelsInBattle = True AndAlso ModelManager.ModelExist("Models\Pokemon\" & modelName & "\" & shinyString) = True And p.IsEgg() = False Then - Draw3DModel(p, "Models\Pokemon\" & modelName & "\" & shinyString) + Dim modelName = p.AnimationName + Dim shinyString = If(p.IsShiny, "Shiny", "Normal") + If Core.Player.ShowModelsInBattle AndAlso ModelManager.ModelExist($"Models\Pokemon\{modelName}\{shinyString}") And Not p.IsEgg() Then + Draw3DModel(p, $"Models\Pokemon\{modelName}\{shinyString}") Else GetYOffset(p) - Core.SpriteBatch.Draw(p.GetTexture(True), New Rectangle(792 - CInt(MathHelper.Min(p.GetTexture(True).Width * 3, 288) / 2), 192 - yOffset, MathHelper.Min(p.GetTexture(True).Width * 3, 288), MathHelper.Min(p.GetTexture(True).Height * 3, 288)), Color.White) + Dim texture = p.GetTexture(True) + Dim size = New Point(MathHelper.Min(texture.Width * 3, 288), MathHelper.Min(texture.Height * 3, 288)) + Dim position = New Point(792 - CInt(size.X / 2), 192 - yOffset) + Core.SpriteBatch.Draw(texture, New Rectangle(position, size), Color.White) End If Canvas.DrawRectangle(New Rectangle(660, 472, 320, 240), c) - If p.IsEgg() = True Then + If p.IsEgg() Then Core.SpriteBatch.DrawString(FontManager.MainFont, "Egg", New Vector2(667, 477 + 2), Color.Black) Core.SpriteBatch.DrawString(FontManager.MainFont, "Egg", New Vector2(665, 477), Color.White) Else - Dim itemString As String = "None" - If Not p.Item Is Nothing Then - itemString = p.Item.Name - End If + Dim itemString = If(p.Item Is Nothing, "None", p.Item.Name) - Dim nameString As String = p.GetDisplayName() & "/" & p.GetName - If p.NickName = "" Then - nameString = p.GetDisplayName() - End If + Dim nameString = If(p.NickName = "", p.GetDisplayName(), $"{p.GetDisplayName()}/{p.GetName}") - Dim t As String = nameString & Environment.NewLine & - "DEX NO. " & p.Number & Environment.NewLine & - "LEVEL " & p.Level & Environment.NewLine & - "HP " & p.HP & " / " & p.MaxHP & Environment.NewLine & - "ATTACK " & p.Attack & Environment.NewLine & - "DEFENSE " & p.Defense & Environment.NewLine & - "SP. ATK " & p.SpAttack & Environment.NewLine & - "SP. DEF " & p.SpDefense & Environment.NewLine & - "SPEED " & p.Speed & Environment.NewLine & - "ITEM " & itemString + Dim t = $"{nameString}{Environment.NewLine}" + t &= $"DEX NO. {p.Number}{Environment.NewLine}" + t &= $"LEVEL {p.Level}{Environment.NewLine}" + t &= $"HP {p.HP} / {p.MaxHP}{Environment.NewLine}" + t &= $"ATTACK {p.Attack}{Environment.NewLine}" + t &= $"DEFENSE {p.Defense}{Environment.NewLine}" + t &= $"SP. ATK {p.SpAttack}{Environment.NewLine}" + t &= $"SP. DEF {p.SpDefense}{Environment.NewLine}" + t &= $"SPEED {p.Speed}{Environment.NewLine}" + t &= $"ITEM {itemString}" Core.SpriteBatch.DrawString(FontManager.MainFont, t, New Vector2(667, 477 + 2), Color.Black) Core.SpriteBatch.DrawString(FontManager.MainFont, t, New Vector2(665, 477), Color.White) @@ -1495,14 +1078,12 @@ Public Class StorageSystemScreen Private Sub Draw3DModel(ByVal p As Pokemon, ByVal modelName As String) Dim propList = p.GetModelProperties() - Dim scale As Single = propList.Item1 * 10 - Dim x As Single = propList.Item2 - Dim y As Single = propList.Item3 - Dim z As Single = propList.Item4 + Dim scale = propList.Item1 * 10 + Dim position = New Vector3(propList.Item2, propList.Item3, propList.Item4) - Dim roll As Single = propList.Item5 + Dim roll = propList.Item5 - Dim t As Texture2D = ModelManager.DrawModelToTexture(modelName, renderTarget, New Vector3(x, y, z), New Vector3(0.0F, 10.0F, 50.0F), New Vector3(roll + modelRoll, 0, 0), scale, True) + Dim t As Texture2D = ModelManager.DrawModelToTexture(modelName, renderTarget, position, New Vector3(0.0F, 10.0F, 50.0F), New Vector3(roll + modelRoll, 0, 0), scale, True) Core.SpriteBatch.Draw(t, New Rectangle(192, 72, 1200, 680), Color.White) End Sub @@ -1512,134 +1093,89 @@ Public Class StorageSystemScreen For y = -64 To Core.windowSize.Height Step 64 Core.SpriteBatch.Draw(Me.menuTexture, New Rectangle(Core.windowSize.Width - 128, y + StorageSystemScreen.TileOffset, 128, 64), New Rectangle(48, 0, 16, 16), Color.White) Next + Dim halfHeight = CInt(Core.windowSize.Height / 2) + Dim destination = New Rectangle(96, 0, 32, 64) - Core.SpriteBatch.Draw(Me.texture, New Rectangle(Core.windowSize.Width - 430, 0, 128, CInt(Core.windowSize.Height / 2)), New Rectangle(96, 0, 32, 64), Color.White) - Core.SpriteBatch.Draw(Me.texture, New Rectangle(Core.windowSize.Width - 430, CInt(Core.windowSize.Height / 2), 128, CInt(Core.windowSize.Height / 2)), New Rectangle(96, 0, 32, 64), Color.White, 0.0F, New Vector2(0), SpriteEffects.FlipVertically, 0.0F) + Core.SpriteBatch.Draw(Me.texture, New Rectangle(Core.windowSize.Width - 430, 0, 128, halfHeight), destination, Color.White) + Core.SpriteBatch.Draw(Me.texture, New Rectangle(Core.windowSize.Width - 430, halfHeight, 128, halfHeight), destination, Color.White, 0.0F, New Vector2(0), SpriteEffects.FlipVertically, 0.0F) For i = 0 To 5 Canvas.DrawBorder(2, New Rectangle(Core.windowSize.Width - 260, i * 100 + 50, 128, 80), New Color(42, 167, 198)) - If Core.Player.Pokemons.Count - 1 >= i Then - Dim c As Color = Color.White - If IsLit(Core.Player.Pokemons(i)) = False Then - c = New Color(65, 65, 65, 255) - End If + If Core.Player.Pokemons.Count - 1 < i Then Continue For + Dim pokemon = Core.Player.Pokemons(i) + Dim c As Color = If(IsLit(pokemon), Color.White, New Color(65, 65, 65, 255)) - Dim pokeTexture = Core.Player.Pokemons(i).GetMenuTexture() - Dim pokeTextureScale As Vector2 = New Vector2(CSng(32 / pokeTexture.Width) * 2, CSng(32 / pokeTexture.Height) * 2) - Core.SpriteBatch.Draw(pokeTexture, New Rectangle(Core.windowSize.Width - 228, i * 100 + 60, CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), c) + Dim pokeTexture = pokemon.GetMenuTexture() + Dim pokeTextureScale = New Vector2(CSng(32 / pokeTexture.Width), CSng(32 / pokeTexture.Height)) * 2 + Dim scale = New Vector2(pokeTexture.Width, pokeTexture.Height) * pokeTextureScale + Core.SpriteBatch.Draw(pokeTexture, New Rectangle(Core.windowSize.Width - 228, i * 100 + 60, CInt(scale.X), CInt(scale.Y)), c) - If Not Core.Player.Pokemons(i).Item Is Nothing And Core.Player.Pokemons(i).IsEgg() = False Then - Core.SpriteBatch.Draw(Core.Player.Pokemons(i).Item.Texture, New Rectangle(Core.windowSize.Width - 196, i * 100 + 92, 24, 24), Color.White) - End If - End If + If pokemon.Item Is Nothing Or pokemon.IsEgg Then Continue For + Core.SpriteBatch.Draw(pokemon.Item.Texture, New Rectangle(Core.windowSize.Width - 196, i * 100 + 92, 24, 24), Color.White) Next End Sub Private Sub DrawCursor() - Dim cPosition As Vector2 = GetAbsoluteCursorPosition(Me.CursorPosition) + Dim cPosition = If(CursorMoving, CursorMovePosition, GetAbsoluteCursorPosition(Me.CursorPosition)) - If CursorMoving = True Then - cPosition = CursorMovePosition - End If - If Not Me.MovingPokemon Is Nothing Then + If Me.MovingPokemon IsNot Nothing Then Dim pokeTexture = Me.MovingPokemon.GetMenuTexture() - Dim pokeTextureScale As Vector2 = New Vector2(CSng(32 / pokeTexture.Width) * 2, CSng(32 / pokeTexture.Height) * 2) - Core.SpriteBatch.Draw(pokeTexture, New Rectangle(CInt(cPosition.X - 10), CInt(cPosition.Y + 44), CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), New Color(0, 0, 0, 150)) - Core.SpriteBatch.Draw(pokeTexture, New Rectangle(CInt(cPosition.X - 20), CInt(cPosition.Y + 34), CInt(pokeTexture.Width * pokeTextureScale.X), CInt(pokeTexture.Height * pokeTextureScale.Y)), Color.White) + Dim pokeTextureScale = New Vector2(CSng(32 / pokeTexture.Width), CSng(32 / pokeTexture.Height)) * 2 + Dim size = New Vector2(pokeTexture.Width, pokeTexture.Height) * pokeTextureScale + Core.SpriteBatch.Draw(pokeTexture, New Rectangle(CInt(cPosition.X - 10), CInt(cPosition.Y + 44), CInt(size.X), CInt(size.Y)), New Color(0, 0, 0, 150)) + Core.SpriteBatch.Draw(pokeTexture, New Rectangle(CInt(cPosition.X - 20), CInt(cPosition.Y + 34), CInt(size.X), CInt(size.Y)), Color.White) - If Not Me.MovingPokemon.Item Is Nothing And Me.MovingPokemon.IsEgg() = False Then + If Me.MovingPokemon.Item IsNot Nothing And Not Me.MovingPokemon.IsEgg() Then Core.SpriteBatch.Draw(Me.MovingPokemon.Item.Texture, New Rectangle(CInt(cPosition.X - 20) + 32, CInt(cPosition.Y + 34) + 32, 24, 24), Color.White) End If End If - Dim t As Texture2D = GetCursorTexture() - Core.SpriteBatch.Draw(t, New Rectangle(CInt(cPosition.X), CInt(cPosition.Y), 64, 64), Color.White) + Core.SpriteBatch.Draw(GetCursorTexture(), New Rectangle(CInt(cPosition.X), CInt(cPosition.Y), 64, 64), Color.White) End Sub Private Sub DrawMenuEntries() If Me.MenuHeader <> "" Then + Dim font = FontManager.MainFont Canvas.DrawRectangle(New Rectangle(Core.windowSize.Width - 370, 100, 356, 64), New Color(0, 0, 0, 180)) - Core.SpriteBatch.DrawString(FontManager.MainFont, MenuHeader, New Vector2(Core.windowSize.Width - 192 - FontManager.MainFont.MeasureString(MenuHeader).X / 2, 120), Color.White) + Core.SpriteBatch.DrawString(font, MenuHeader, New Vector2(Core.windowSize.Width - 192 - font.MeasureString(MenuHeader).X / 2, 120), Color.White) End If - For Each e As MenuEntry In Me.MenuEntries - e.Draw(Me.MenuCursor, GetCursorTexture()) - Next + Me.MenuEntries.ForEach(Sub(x) x.Draw(Me.MenuCursor, GetCursorTexture())) End Sub Private Function GetCursorTexture() As Texture2D - Select Case Me.SelectionMode - Case SelectionModes.SingleMove - Return TextureManager.GetTexture("GUI\Menus\General", New Rectangle(0, 0, 16, 16), "") - Case SelectionModes.EasyMove - Return TextureManager.GetTexture("GUI\Menus\General", New Rectangle(16, 0, 16, 16), "") - Case SelectionModes.Deposit - Return TextureManager.GetTexture("GUI\Menus\General", New Rectangle(32, 0, 16, 16), "") - Case SelectionModes.Withdraw - Return TextureManager.GetTexture("GUI\Menus\General", New Rectangle(0, 32, 16, 16), "") - End Select + Dim rectangles = New Dictionary(Of SelectionModes, Rectangle) + rectangles.Add(SelectionModes.SingleMove, New Rectangle(0, 0, 16, 16)) + rectangles.Add(SelectionModes.EasyMove, New Rectangle(16, 0, 16, 16)) + rectangles.Add(SelectionModes.Deposit, New Rectangle(32, 0, 16, 16)) + rectangles.Add(SelectionModes.Withdraw, New Rectangle(0, 32, 16, 16)) - Return Nothing + Return If(rectangles.ContainsKey(Me.SelectionMode), TextureManager.GetTexture("GUI\Menus\General", rectangles(Me.SelectionMode), ""), Nothing) End Function #End Region Private Function IsLit(ByVal p As Pokemon) As Boolean - If Me.Filters.Count > 0 Then - If p.IsEgg() = True Then - Return False + If Me.Filters.Count < 1 Then Return True + If p.IsEgg() Then Return False + Dim criteria = New Dictionary(Of FilterTypes, Func(Of Filter, Boolean)) + criteria.Add(FilterTypes.Ability, Function(f) p.Ability.Name.ToLower() = f.FilterValue.ToLower()) + criteria.Add(FilterTypes.Gender, Function(f) p.Gender.ToString().ToLower() = f.FilterValue.ToLower()) + criteria.Add(FilterTypes.Nature, Function(f) p.Nature.ToString().ToLower() = f.FilterValue.ToLower()) + criteria.Add(FilterTypes.Pokémon, Function(f) p.GetName().ToLower() = f.FilterValue.ToLower()) + criteria.Add(FilterTypes.Move, Function(f) p.Attacks.Any(Function(a) a.Name.ToLower() = f.FilterValue.ToLower())) + criteria.Add(FilterTypes.Type1, Function(f) p.Type1.Type = New Element(f.FilterValue).Type) + criteria.Add(FilterTypes.Type2, Function(f) p.Type2.Type = New Element(f.FilterValue).Type) + For Each f As Filter In Filters + Dim check As Func(Of Filter, Boolean) = Nothing + If criteria.TryGetValue(f.FilterType, check) AndAlso Not criteria(f.FilterType)(f) Then Return False + If f.FilterType = FilterTypes.HeldItem Then + If f.FilterValue = "Has no Held Item" And p.Item IsNot Nothing Then Return False + If f.FilterValue = "Has a Held Item" And p.Item Is Nothing Then Return False End If - For Each f As Filter In Filters - Select Case f.FilterType - Case FilterTypes.Ability - If p.Ability.Name.ToLower() <> f.FilterValue.ToLower() Then - Return False - End If - Case FilterTypes.Gender - If p.Gender.ToString().ToLower() <> f.FilterValue.ToLower() Then - Return False - End If - Case FilterTypes.HeldItem - If f.FilterValue = "Has no Held Item" And Not p.Item Is Nothing Then - Return False - ElseIf f.FilterValue = "Has a Held Item" And p.Item Is Nothing Then - Return False - End If - Case FilterTypes.Move - Dim hasAttack As Boolean = False - For Each a As BattleSystem.Attack In p.Attacks - If a.Name.ToLower() = f.FilterValue.ToLower() Then - hasAttack = True - Exit For - End If - Next - If hasAttack = False Then - Return False - End If - Case FilterTypes.Nature - If p.Nature.ToString().ToLower() <> f.FilterValue.ToLower() Then - Return False - End If - Case FilterTypes.Pokémon - If p.GetName() <> f.FilterValue Then - Return False - End If - Case FilterTypes.Type1 - Dim t As Element = New Element(f.FilterValue) - If p.Type1.Type <> t.Type Then - Return False - End If - Case FilterTypes.Type2 - Dim t As Element = New Element(f.FilterValue) - If p.Type2.Type <> t.Type Then - Return False - End If - End Select - Next - End If - + Next Return True End Function @@ -1649,39 +1185,33 @@ Public Class StorageSystemScreen Public Shared Function DepositPokemon(ByVal p As Pokemon, Optional ByVal BoxIndex As Integer = -1) As Integer p.FullRestore() - Dim Boxes As List(Of Box) = LoadBoxes() - Dim startIndex As Integer = 0 - If BoxIndex > -1 Then - startIndex = BoxIndex - End If + Dim Boxes = LoadBoxes() + Dim startIndex = If(BoxIndex > -1, BoxIndex, 0) For i = startIndex To Boxes.Count - 1 - If GetBox(i, Boxes).Pokemon.Count < 30 Then - For l = 0 To 29 - If GetBox(i, Boxes).Pokemon.Keys.Contains(l) = False Then - GetBox(i, Boxes).Pokemon.Add(l, New PokemonWrapper(p)) ' p) - Exit For - End If - Next - Core.Player.BoxData = GetBoxSaveData(Boxes) - Return i - End If + Dim pokemons = GetBox(i, Boxes).Pokemon + If pokemons.Count > 29 Then Continue For + For l = 0 To 29 + If pokemons.ContainsKey(l) Then Continue For + pokemons.Add(l, New PokemonWrapper(p)) ' p) + Exit For + Next + Core.Player.BoxData = GetBoxSaveData(Boxes) + Return i Next - If startIndex <> 0 Then - For i = 0 To startIndex - 1 - If GetBox(i, Boxes).Pokemon.Count < 30 Then - For l = 0 To 29 - If GetBox(i, Boxes).Pokemon.Keys.Contains(l) = False Then - GetBox(i, Boxes).Pokemon.Add(l, New PokemonWrapper(p)) ' p) - Exit For - End If - Next - Core.Player.BoxData = GetBoxSaveData(Boxes) - Return i - End If + If startIndex = 0 Then Return -1 + For i = 0 To startIndex - 1 + Dim pokemons = GetBox(i, Boxes).Pokemon + If pokemons.Count > 29 Then Continue For + For l = 0 To 29 + If pokemons.ContainsKey(l) Then Continue For + pokemons.Add(l, New PokemonWrapper(p)) ' p) + Exit For Next - End If + Core.Player.BoxData = GetBoxSaveData(Boxes) + Return i + Next Return -1 End Function @@ -1691,40 +1221,25 @@ Public Class StorageSystemScreen End Function Private Shared Function GetBox(ByVal index As Integer, ByVal boxes As List(Of Box)) As Box - For Each b As Box In boxes - If b.index = index Then - Return b - End If - Next - - Return Nothing + Return boxes.FirstOrDefault(Function(x) x.index = index) End Function Private Function GetBox(ByVal index As Integer) As Box - For Each b As Box In Me.Boxes - If b.index = index Then - Return b - End If - Next - - Return Nothing + Return GetBox(index, Me.Boxes) End Function Private Function BoxPokemonCount(ByVal selBox As Integer, ByVal lit As Boolean) As Integer - Dim c As Integer = 0 + Dim c = 0 - Dim box As Box = GetBox(selBox) - If Not box Is Nothing Then - For Each p As PokemonWrapper In box.Pokemon.Values - If lit = True Then - If IsLit(p.GetPokemon()) = True Then - c += 1 - End If - Else - c += 1 - End If - Next - End If + Dim box = GetBox(selBox) + If box Is Nothing Then Return c + For Each p As PokemonWrapper In box.Pokemon.Values + If Not lit Then + c += 1 + Continue For + End If + If IsLit(p.GetPokemon()) Then c += 1 + Next Return c End Function @@ -1754,20 +1269,15 @@ Public Class StorageSystemScreen End Sub Public Function GetPokemon() As Pokemon - If _loaded = False Then - _loaded = True - _pokemon = Pokemon.GetPokemonByData(Me._pokemonData) - End If + If _loaded Then Return Me._pokemon + _loaded = True + _pokemon = Pokemon.GetPokemonByData(Me._pokemonData) Return Me._pokemon End Function Public ReadOnly Property PokemonData() As String Get - If _loaded = True Then - Return Me._pokemon.GetSaveData() - Else - Return Me._pokemonData - End If + Return If(_loaded, Me._pokemon.GetSaveData(), Me._pokemonData) End Get End Property @@ -1786,7 +1296,7 @@ Public Class StorageSystemScreen Public Sub New(ByVal index As Integer) Me.index = index - Me.Name = "BOX " & (index + 1).ToString() + Me.Name = $"BOX {index + 1}" Me.Background = index End Sub @@ -1797,11 +1307,7 @@ Public Class StorageSystemScreen End Property Public Function GetPokemonList() As List(Of Pokemon) - Dim l As New List(Of Pokemon) - For i = 0 To Pokemon.Count - 1 - l.Add(Pokemon.Values(i).GetPokemon()) - Next - Return l + Return Pokemon.Values.Select(Function(x) x.GetPokemon()).ToList() End Function Public Property IsBattleBox() As Boolean @@ -1810,9 +1316,7 @@ Public Class StorageSystemScreen End Get Set(value As Boolean) Me._isBattleBox = value - If Me._isBattleBox = True Then - Me.Name = "BATTLE BOX" - End If + If Me._isBattleBox Then Me.Name = "BATTLE BOX" End Set End Property @@ -1848,20 +1352,21 @@ Public Class StorageSystemScreen End Sub Public Sub Update(ByVal s As StorageSystemScreen) - If Controls.Accept(True, False, False) = True And s.MenuCursor = Me.Index And New Rectangle(Core.windowSize.Width - 270, 66 * Index, 256, 64).Contains(MouseHandler.MousePosition) = True Or - Controls.Accept(False, True, True) = True And s.MenuCursor = Me.Index Or Controls.Dismiss(True, True, True) = True And Me.IsBack = True Then + Dim hovering = New Rectangle(Core.windowSize.Width - 270, 66 * Index, 256, 64).Contains(MouseHandler.MousePosition) + Dim acceptPointer = Controls.Accept(True, False, False) And hovering + Dim acceptButtons = Controls.Accept(False, True, True) + Dim dismiss = Controls.Dismiss(True, True, True) And Me.IsBack + If (acceptPointer Or acceptButtons) And s.MenuCursor = Me.Index Or dismiss Then s.MenuVisible = False - If Not ClickHandler Is Nothing Then - ClickHandler(Me) - End If + ClickHandler?(Me) End If - If New Rectangle(Core.windowSize.Width - 270, 66 * Index, 256, 64).Contains(MouseHandler.MousePosition) = True And Controls.Accept(True, False, False) = True Then + If acceptPointer Then s.MenuCursor = Me.Index End If End Sub Public Sub Draw(ByVal CursorIndex As Integer, ByVal CursorTexture As Texture2D) - Dim startPos As New Vector2(Core.windowSize.Width - 270, 66 * Index) + Dim startPos = New Vector2(Core.windowSize.Width - 270, 66 * Index) Core.SpriteBatch.Draw(t1, New Rectangle(CInt(startPos.X), CInt(startPos.Y), 64, 64), Color.White) Core.SpriteBatch.Draw(t2, New Rectangle(CInt(startPos.X + 64), CInt(startPos.Y), 64, 64), Color.White) @@ -1870,74 +1375,58 @@ Public Class StorageSystemScreen Core.SpriteBatch.DrawString(FontManager.MainFont, Me.Text, New Vector2(startPos.X + 128 - (FontManager.MainFont.MeasureString(Me.Text).X * 1.4F) / 2, startPos.Y + 15), Color.Black, 0.0F, Vector2.Zero, 1.4F, SpriteEffects.None, 0.0F) - If Me.Index = CursorIndex Then - Dim cPosition As Vector2 = New Vector2(startPos.X + 128, startPos.Y - 40) - Dim t As Texture2D = CursorTexture - Core.SpriteBatch.Draw(t, New Rectangle(CInt(cPosition.X), CInt(cPosition.Y), 64, 64), Color.White) - End If + If Me.Index <> CursorIndex Then Return + Dim cPosition = New Point(CInt(startPos.X) + 128, CInt(startPos.Y) - 40) + Core.SpriteBatch.Draw(CursorTexture, New Rectangle(cPosition, New Point(64)), Color.White) End Sub End Class Public Shared Function GetAllBoxPokemon() As List(Of Pokemon) - Dim Pokemons As New List(Of Pokemon) - Dim Data() As String = Core.Player.BoxData.SplitAtNewline() + Dim Pokemons = New List(Of Pokemon) + Dim Data() = Core.Player.BoxData.SplitAtNewline() For Each line As String In Data - If line.StartsWith("BOX|") = False And line <> "" Then - Dim pokeData As String = line.Remove(0, line.IndexOf("{")) - Pokemons.Add(Pokemon.GetPokemonByData(pokeData)) - End If + If Not line.StartsWith("BOX|") Or line = "" Then Continue For + Dim pokeData = line.Remove(0, line.IndexOf("{")) + Pokemons.Add(Pokemon.GetPokemonByData(pokeData)) Next Return Pokemons End Function Public Function GetPokemonList(ByVal includeTeam As Boolean, ByVal lit As Boolean) As List(Of Pokemon) - Dim L As New List(Of Pokemon) - For Each Box As Box In Me.Boxes - If Box.HasPokemon = True Then - For i = 0 To Box.Pokemon.Count - 1 - If (lit = True AndAlso IsLit(Box.Pokemon.Values(i).GetPokemon()) = True) = True Or lit = False Then - L.Add(Box.Pokemon.Values(i).GetPokemon()) - End If - Next - End If + Dim L = New List(Of Pokemon) + For Each Box In Me.Boxes + If Not Box.HasPokemon Then Continue For + Dim pokemons = Box.Pokemon.Values.Select(Function(x) x.GetPokemon()) + L.AddRange(pokemons.Where(Function(pokemon) (lit AndAlso IsLit(pokemon)) Or Not lit)) Next - If includeTeam = True Then - For Each p As Pokemon In Core.Player.Pokemons - If (lit = True AndAlso IsLit(p) = True) = True Or lit = False Then - L.Add(p) - End If - Next + If includeTeam Then + L.AddRange(Core.Player.Pokemons.Where(Function(pokemon) (lit AndAlso IsLit(pokemon)) Or Not lit)) End If Return L End Function Public Shared Function GetBattleBoxPokemon() As List(Of Pokemon) - Dim BattleBoxID As Integer = 0 - Dim Data() As String = Core.Player.BoxData.SplitAtNewline() - Dim PokemonList As New List(Of Pokemon) + Dim BattleBoxID = 0 + Dim Data() = Core.Player.BoxData.SplitAtNewline() + Dim PokemonList = New List(Of Pokemon) - For Each line As String In Data - If line.StartsWith("BOX|") = True Then - Dim boxData() As String = line.Split(CChar("|")) - If CInt(boxData(1)) > BattleBoxID Then - BattleBoxID = CInt(boxData(1)) - End If - End If + For Each line In Data + If Not line.StartsWith("BOX|") Then Continue For + Dim boxData() = line.Split(CChar("|")) + BattleBoxID = Math.Min(CInt(boxData(1)), BattleBoxID) Next - For Each line As String In Data - If line.StartsWith(BattleBoxID.ToString() & ",") = True And line.EndsWith("}") = True Then - Dim pokemonData As String = line.Remove(0, line.IndexOf("{")) - PokemonList.Add(Pokemon.GetPokemonByData(pokemonData)) - End If + For Each line In Data + If Not line.StartsWith(BattleBoxID.ToString() & ",") Or Not line.EndsWith("}") Then Continue For + Dim pokemonData = line.Remove(0, line.IndexOf("{")) + PokemonList.Add(Pokemon.GetPokemonByData(pokemonData)) Next - ' Prevent more than six Pokémon: - While PokemonList.Count > 6 - PokemonList.RemoveAt(PokemonList.Count - 1) - End While + If PokemonList.Count > 6 Then + PokemonList.RemoveRange(5, PokemonList.Count - 6) + End If Return PokemonList End Function @@ -1976,72 +1465,53 @@ Public Class StorageSystemFilterScreen End Sub Public Sub Update() - If Visible = True Then - If Controls.Up(True, True, True, True, True, True) = True Then - Me.Index -= 1 - End If - If Controls.Down(True, True, True, True, True, True) = True Then - Me.Index += 1 - End If - Me.Index = Me.Index.Clamp(0, Me.Items.Count - 1) + If Not Visible Then Return + If Controls.Up(True, True, True, True, True, True) Then Me.Index -= 1 + If Controls.Down(True, True, True, True, True, True) Then Me.Index += 1 + Me.Index = Me.Index.Clamp(0, Me.Items.Count - 1) - For i = Scroll To Me.Scroll + 8 - If i <= Me.Items.Count - 1 Then - If Controls.Accept(True, False, False) = True And i = Me.Index And New Rectangle(Core.windowSize.Width - 270, 66 * ((i + 1) - Scroll), 256, 64).Contains(MouseHandler.MousePosition) = True Or - Controls.Accept(False, True, True) = True And i = Me.Index Or Controls.Dismiss(True, True, True) = True And Me.BackIndex = Me.Index Then + For i = Scroll To Me.Scroll + 8 + If i > Me.Items.Count - 1 Then Continue For + Dim hovering = New Rectangle(Core.windowSize.Width - 270, 66 * (i + 1 - Scroll), 256, 64).Contains(MouseHandler.MousePosition) + Dim acceptPointer = Controls.Accept(True, False, False) And hovering + Dim acceptButtons = Controls.Accept(False, True, True) + Dim dismiss = Controls.Dismiss(True, True, True) + If (acceptPointer Or acceptButtons) And i = Me.Index Or dismiss And Me.BackIndex = Me.Index Then - If Not ClickHandler Is Nothing Then - ClickHandler(Me) - SoundManager.PlaySound("select") - End If - Me.Visible = False - End If - If Controls.Dismiss(True, True, True) = True Then - Me.Index = Me.BackIndex - If Not ClickHandler Is Nothing Then - ClickHandler(Me) - SoundManager.PlaySound("select") - End If - Me.Visible = False - End If - If New Rectangle(Core.windowSize.Width - 270, 66 * ((i + 1) - Scroll), 256, 64).Contains(MouseHandler.MousePosition) = True And Controls.Accept(True, False, False) = True Then - Me.Index = i - End If + If ClickHandler IsNot Nothing Then + ClickHandler(Me) + SoundManager.PlaySound("select") End If - Next + Me.Visible = False + End If + If dismiss Then Me.Index = Me.BackIndex + If acceptPointer Then Me.Index = i + Next - If Index - Scroll > 8 Then - Scroll = Index - 8 - End If - If Index - Scroll < 0 Then - Scroll = Index - End If - End If + If Index - Scroll > 8 Then Scroll = Index - 8 + If Index - Scroll < 0 Then Scroll = Index End Sub Public Sub Draw() - If Visible = True Then - For i = Scroll To Me.Scroll + 8 - If i <= Me.Items.Count - 1 Then - Dim Text As String = Items(i) + If Not Visible Then Return + For i = Scroll To Me.Scroll + 8 + If i > Me.Items.Count - 1 Then Continue For + Dim Text = Items(i) - Dim startPos As New Vector2(Core.windowSize.Width - 270, 66 * ((i + 1) - Scroll)) + Dim startPos = New Vector2(Core.windowSize.Width - 270, 66 * ((i + 1) - Scroll)) - Core.SpriteBatch.Draw(t1, New Rectangle(CInt(startPos.X), CInt(startPos.Y), 64, 64), Color.White) - Core.SpriteBatch.Draw(t2, New Rectangle(CInt(startPos.X + 64), CInt(startPos.Y), 64, 64), Color.White) - Core.SpriteBatch.Draw(t2, New Rectangle(CInt(startPos.X + 128), CInt(startPos.Y), 64, 64), Color.White) - Core.SpriteBatch.Draw(t1, New Rectangle(CInt(startPos.X + 192), CInt(startPos.Y), 64, 64), Nothing, Color.White, 0.0F, New Vector2(0), SpriteEffects.FlipHorizontally, 0.0F) + Core.SpriteBatch.Draw(t1, New Rectangle(CInt(startPos.X), CInt(startPos.Y), 64, 64), Color.White) + Core.SpriteBatch.Draw(t2, New Rectangle(CInt(startPos.X + 64), CInt(startPos.Y), 64, 64), Color.White) + Core.SpriteBatch.Draw(t2, New Rectangle(CInt(startPos.X + 128), CInt(startPos.Y), 64, 64), Color.White) + Core.SpriteBatch.Draw(t1, New Rectangle(CInt(startPos.X + 192), CInt(startPos.Y), 64, 64), Nothing, Color.White, 0.0F, New Vector2(0), SpriteEffects.FlipHorizontally, 0.0F) - Core.SpriteBatch.DrawString(FontManager.MainFont, Text, New Vector2(startPos.X + 128 - (FontManager.MainFont.MeasureString(Text).X * 1.4F) / 2, startPos.Y + 15), Color.Black, 0.0F, Vector2.Zero, 1.4F, SpriteEffects.None, 0.0F) + Core.SpriteBatch.DrawString(FontManager.MainFont, Text, New Vector2(startPos.X + 128 - (FontManager.MainFont.MeasureString(Text).X * 1.4F) / 2, startPos.Y + 15), Color.Black, 0.0F, Vector2.Zero, 1.4F, SpriteEffects.None, 0.0F) - If Me.Index = i Then - Dim cPosition As Vector2 = New Vector2(startPos.X + 128, startPos.Y - 40) - Dim t As Texture2D = TextureManager.GetTexture("GUI\Menus\General", New Rectangle(0, 0, 16, 16), "") - Core.SpriteBatch.Draw(t, New Rectangle(CInt(cPosition.X), CInt(cPosition.Y), 64, 64), Color.White) - End If - End If - Next - End If + If Me.Index <> i Then Continue For + Dim cPosition = New Point(CInt(startPos.X) + 128, y:=CInt(startPos.Y) - 40) + Dim t = TextureManager.GetTexture("GUI\Menus\General", New Rectangle(0, 0, 16, 16), "") + Core.SpriteBatch.Draw(t, New Rectangle(cPosition, New Point(64)), Color.White) + Next End Sub Public ReadOnly Property SelectedItem() As String @@ -2070,9 +1540,7 @@ Public Class StorageSystemFilterScreen Me.texture = TextureManager.GetTexture("GUI\Menus\General") - For Each Filter As StorageSystemScreen.Filter In currentScreen.Filters - Me.Filters.Add(Filter) - Next + Me.Filters.AddRange(currentScreen.Filters) Me.MouseVisible = True Me.CanMuteAudio = True @@ -2088,85 +1556,67 @@ Public Class StorageSystemFilterScreen Canvas.DrawRectangle(Core.windowSize, New Color(84, 198, 216)) For y = -64 To Core.windowSize.Height Step 64 - Core.SpriteBatch.Draw(Me.texture, New Rectangle(Core.windowSize.Width - 128, y + StorageSystemScreen.TileOffset, 128, 64), New Rectangle(48, 0, 16, 16), Color.White) + Dim source = New Rectangle(48, 0, 16, 16) + Dim destination = New Rectangle(Core.windowSize.Width - 128, y + StorageSystemScreen.TileOffset, 128, 64) + Core.SpriteBatch.Draw(Me.texture, destination, source, Color.White) Next + Dim tones = (A:=New Color(42, 167, 198), B:=New Color(42, 167, 198, 0)) - Canvas.DrawGradient(New Rectangle(0, 0, CInt(Core.windowSize.Width), 200), New Color(42, 167, 198), New Color(42, 167, 198, 0), False, -1) - Canvas.DrawGradient(New Rectangle(0, CInt(Core.windowSize.Height - 200), CInt(Core.windowSize.Width), 200), New Color(42, 167, 198, 0), New Color(42, 167, 198), False, -1) + Canvas.DrawGradient(New Rectangle(0, 0, CInt(Core.windowSize.Width), 200), tones.A, tones.B, False, -1) + Canvas.DrawGradient(New Rectangle(0, CInt(Core.windowSize.Height - 200), CInt(Core.windowSize.Width), 200), tones.B, tones.A, False, -1) Core.SpriteBatch.DrawString(FontManager.MainFont, "Configure the filters:", New Vector2(100, 24), Color.White, 0.0F, Vector2.Zero, 2.0F, SpriteEffects.None, 0.0F) For i = Scroll To Scroll + 5 - If i <= Me.mainMenuItems.Count - 1 Then - Dim p As Integer = i - Scroll + If i > Me.mainMenuItems.Count - 1 Then Continue For + Dim p = i - Scroll - Core.SpriteBatch.Draw(Me.texture, New Rectangle(100, 100 + p * 96, 64, 64), New Rectangle(16, 16, 16, 16), Color.White) - Core.SpriteBatch.Draw(Me.texture, New Rectangle(100 + 64, 100 + p * 96, 64 * 8, 64), New Rectangle(32, 16, 16, 16), Color.White) - Core.SpriteBatch.Draw(Me.texture, New Rectangle(100 + 64 * 9, 100 + p * 96, 64, 64), New Rectangle(16, 16, 16, 16), Color.White, 0.0F, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0F) + Core.SpriteBatch.Draw(Me.texture, New Rectangle(100, 100 + p * 96, 64, 64), New Rectangle(16, 16, 16, 16), Color.White) + Core.SpriteBatch.Draw(Me.texture, New Rectangle(100 + 64, 100 + p * 96, 64 * 8, 64), New Rectangle(32, 16, 16, 16), Color.White) + Core.SpriteBatch.Draw(Me.texture, New Rectangle(100 + 64 * 9, 100 + p * 96, 64, 64), New Rectangle(16, 16, 16, 16), Color.White, 0.0F, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0F) - Dim s As String = mainMenuItems(i) - If GetFilterText(mainMenuItems(i)) <> "" Then - s &= " (" & GetFilterText(mainMenuItems(i)) & ")" - Core.SpriteBatch.Draw(Me.texture, New Rectangle(120, 116 + p * 96, 32, 32), New Rectangle(16, 48, 16, 16), Color.White) - Else - Core.SpriteBatch.Draw(Me.texture, New Rectangle(120, 116 + p * 96, 32, 32), New Rectangle(16, 32, 16, 16), Color.White) - End If - - Core.SpriteBatch.DrawString(FontManager.MainFont, s, New Vector2(160, 116 + p * 96), Color.Black, 0.0F, Vector2.Zero, 1.25F, SpriteEffects.None, 0.0F) - End If + Dim filterText = GetFilterText(mainMenuItems(i)) + Dim s = If(filterText <> "", $"{mainMenuItems(i)} ({filterText})", mainMenuItems(i)) + Dim sourceRectangle = If(filterText <> "", New Rectangle(16, 48, 16, 16), New Rectangle(16, 32, 16, 16)) + Core.SpriteBatch.Draw(Me.texture, New Rectangle(120, 116 + p * 96, 32, 32), sourceRectangle, Color.White) + Core.SpriteBatch.DrawString(FontManager.MainFont, s, New Vector2(160, 116 + p * 96), Color.Black, 0.0F, Vector2.Zero, 1.25F, SpriteEffects.None, 0.0F) Next If Filters.Count > 0 Then - Core.SpriteBatch.DrawString(FontManager.MainFont, "Results: " & Environment.NewLine & Environment.NewLine & "Filters: ", New Vector2(90 + 64 * 11, 119), Color.Black) - Core.SpriteBatch.DrawString(FontManager.MainFont, Me.Results & Environment.NewLine & Environment.NewLine & Me.Filters.Count, New Vector2(190 + 64 * 11, 119), Color.White) + Core.SpriteBatch.DrawString(FontManager.MainFont, $"Results: {Environment.NewLine}{Environment.NewLine}Filters: ", New Vector2(90 + 64 * 11, 119), Color.Black) + Core.SpriteBatch.DrawString(FontManager.MainFont, $"{Me.Results}{Environment.NewLine}{Environment.NewLine}{Me.Filters.Count}", New Vector2(190 + 64 * 11, 119), Color.White) End If - If Menu.Visible = True Then - Menu.Draw() - Else - DrawCursor() - End If + Dim draw = If(Menu.Visible, CType(AddressOf Menu.Draw, Action), AddressOf DrawCursor) + draw() End Sub Private Function GetFilterText(ByVal filterTypeString As String) As String - For Each f As StorageSystemScreen.Filter In Me.Filters - If f.FilterType.ToString().ToLower() = filterTypeString.ToLower() Then - Return f.FilterValue - End If - Next - Return "" + Dim filter = Me.Filters.Cast(Of StorageSystemScreen.Filter?).FirstOrDefault(Function(f) f.Value.FilterType.ToString().ToLower() = filterTypeString.ToLower()) + Return If(filter.HasValue, filter.Value.FilterValue, "") End Function Private Sub DrawCursor() - Dim cPosition As Vector2 = New Vector2(520, 100 + Me.Cursor * 96 - 42) + Dim cPosition = New Point(520, 100 + Me.Cursor * 96 - 42) Dim t As Texture2D = TextureManager.GetTexture("GUI\Menus\General", New Rectangle(0, 0, 16, 16), "") - Core.SpriteBatch.Draw(t, New Rectangle(CInt(cPosition.X), CInt(cPosition.Y), 64, 64), Color.White) + Core.SpriteBatch.Draw(t, New Rectangle(cPosition, New Point(64, 64)), Color.White) End Sub Private Sub ApplyFilters() Me._storageSystemScreen.Filters.Clear() - For Each f As StorageSystemScreen.Filter In Me.Filters - Me._storageSystemScreen.Filters.Add(f) - Next + Me._storageSystemScreen.Filters.AddRange(Me.Filters) End Sub Public Overrides Sub Update() - If Menu.Visible = True Then + If Menu.Visible Then Menu.Update() Else - If Controls.Down(True, True, True, True, True, True) = True Then - Me.Cursor += 1 - If Controls.ShiftDown() = True Then - Me.Cursor += 4 - End If - End If - If Controls.Up(True, True, True, True, True, True) = True Then - Me.Cursor -= 1 - If Controls.ShiftDown() = True Then - Me.Cursor -= 4 - End If - End If + Dim direction = 0 + If Controls.Down(True, True, True, True, True, True) Then direction = 1 + If Controls.Up(True, True, True, True, True, True) Then direction = -1 + Me.Cursor += direction + If Controls.ShiftDown() Then Me.Cursor += direction * 4 While Me.Cursor > 5 Me.Cursor -= 1 @@ -2177,41 +1627,31 @@ Public Class StorageSystemFilterScreen Me.Scroll -= 1 End While - If Me.mainMenuItems.Count < 7 Then - Me.Scroll = 0 - Else - Me.Scroll = Me.Scroll.Clamp(0, Me.mainMenuItems.Count - 6) - End If + Me.Scroll = If(Me.mainMenuItems.Count < 7, 0, Me.Scroll.Clamp(0, Me.mainMenuItems.Count - 6)) - If Me.mainMenuItems.Count < 6 Then - Me.Cursor = Me.Cursor.Clamp(0, Me.mainMenuItems.Count - 1) - Else - Me.Cursor = Me.Cursor.Clamp(0, 5) - End If + Me.Cursor = If(Me.mainMenuItems.Count < 6, Me.Cursor.Clamp(0, Me.mainMenuItems.Count - 1), Me.Cursor.Clamp(0, 5)) If Me.mainMenuItems.Count > 0 Then - If Controls.Accept(True, False, False) = True Then + If Controls.Accept(True, False, False) Then For i = Scroll To Scroll + 5 - If i <= Me.mainMenuItems.Count - 1 Then - If New Rectangle(100, 100 + (i - Scroll) * 96, 640, 64).Contains(MouseHandler.MousePosition) = True Then - If i = Cursor + Scroll Then - SelectFilter() - SoundManager.PlaySound("select") - Else - Cursor = i - Scroll - End If - End If + Dim hovering = New Rectangle(100, 100 + (i - Scroll) * 96, 640, 64).Contains(MouseHandler.MousePosition) + If i > Me.mainMenuItems.Count - 1 OrElse Not hovering Then Continue For + If i <> Cursor + Scroll Then + Cursor = i - Scroll + Continue For End If + SelectFilter() + SoundManager.PlaySound("select") Next End If - If Controls.Accept(False, True, True) = True Then + If Controls.Accept(False, True, True) Then SelectFilter() SoundManager.PlaySound("select") End If End If - If Controls.Dismiss(True, True, True) = True Then + If Controls.Dismiss(True, True, True) Then ApplyFilters() Core.SetScreen(Me._storageSystemScreen) SoundManager.PlaySound("select") @@ -2220,491 +1660,265 @@ Public Class StorageSystemFilterScreen CalculateResults() - StorageSystemScreen.TileOffset += 1 - If StorageSystemScreen.TileOffset >= 64 Then - StorageSystemScreen.TileOffset = 0 - End If + StorageSystemScreen.TileOffset = (StorageSystemScreen.TileOffset + 1) Mod 64 End Sub Private Sub CalculateResults() - Dim s As String = "" - Dim s1 As String = "" - For Each f As StorageSystemScreen.Filter In Me.CalculatedFilters - s &= f.FilterType.ToString() & "|" & f.FilterValue - Next - For Each f As StorageSystemScreen.Filter In Me.Filters - s1 &= f.FilterType.ToString() & "|" & f.FilterValue - Next + Dim s = "" + Dim s1 = "" + Me.CalculatedFilters.ForEach(Sub(f) s &= $"{f.FilterType}|{f.FilterValue}") + Me.Filters.ForEach(Sub(f) s1 &= $"{f.FilterType}|{f.FilterValue}") - If s1 <> s Then - Me.CalculatedFilters.Clear() - For Each f As StorageSystemScreen.Filter In Me.Filters - Me.CalculatedFilters.Add(f) - Next - ApplyFilters() - Me.Results = Me._storageSystemScreen.GetPokemonList(True, True).Count - End If + If s1 = s Then Return + Me.CalculatedFilters.Clear() + Me.CalculatedFilters.AddRange(Me.Filters) + ApplyFilters() + Me.Results = Me._storageSystemScreen.GetPokemonList(True, True).Count End Sub Private Sub SelectFilter() - Dim filterType As String = Me.mainMenuItems(Me.Scroll + Me.Cursor) - - Select Case filterType.ToLower() - Case "pokémon" - Me.OpenPokemonMenu() - Case "type1" - Me.OpenType1Menu() - Case "type2" - Me.OpenType2Menu() - Case "move" - Me.OpenMoveMenu() - Case "ability" - Me.OpenAbilityMenu() - Case "nature" - Me.OpenNatureMenu() - Case "gender" - Me.OpenGenderMenu() - Case "helditem" - Me.OpenHeldItemMenu() - End Select + Dim filterType = Me.mainMenuItems(Me.Scroll + Me.Cursor).ToLower() + Dim menus = New Dictionary(Of String, Action) + menus.Add("pokémon", AddressOf Me.OpenPokemonMenu) + menus.Add("type1", AddressOf Me.OpenType1Menu) + menus.Add("type2", AddressOf Me.OpenType2Menu) + menus.Add("move", AddressOf Me.OpenMoveMenu) + menus.Add("ability", AddressOf Me.OpenAbilityMenu) + menus.Add("nature", AddressOf Me.OpenNatureMenu) + menus.Add("gender", AddressOf Me.OpenGenderMenu) + menus.Add("helditem", AddressOf Me.OpenHeldItemMenu) + If menus.ContainsKey(filterType) Then menus(filterType)() End Sub -#Region "PokémonFilter" +#Region "Filtering" Private Sub OpenPokemonMenu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim letters As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim GetLetter = Function(pokemon As Pokemon) pokemon.GetName()(0).ToString().ToUpper() + Dim letters = l.Select(GetLetter).Distinct().ToList() - For Each p As Pokemon In l - If letters.Contains(p.GetName()(0).ToString().ToUpper()) = False Then - letters.Add(p.GetName()(0).ToString().ToUpper()) - End If - Next - letters = (From letter As String In letters Order By letter Ascending).ToList() + letters.Sort() letters.Add("Back") - If GetFilterText("Pokémon") <> "" Then - letters.Insert(0, "Clear") - End If + If GetFilterText("Pokémon") <> "" Then letters.Insert(0, "Clear") Me.Menu = New SelectMenu(letters, 0, AddressOf SelectPokemonLetter, -1) End Sub Private Sub SelectPokemonLetter(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Pokémon Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - Dim chosenLetter As String = s.SelectedItem + If s.SelectedItem = "Back" Then Return + If s.SelectedItem = "Clear" Then + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Pokémon) + Return + End If + Dim chosenLetter = s.SelectedItem - Dim pokemonList As New List(Of String) - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim LetterMatches = Function(name As String) name.ToUpper().StartsWith(chosenLetter) + Dim pokemonList = l.Select(Function(p) p.GetName()).Where(LetterMatches).Distinct().ToList() - For Each p As Pokemon In l - If p.GetName().ToString().ToUpper().StartsWith(chosenLetter) And pokemonList.Contains(p.GetName()) = False Then - pokemonList.Add(p.GetName) - End If - Next - pokemonList = (From name As String In pokemonList Order By name Ascending).ToList() + pokemonList.Sort() - pokemonList.Add("Back") + pokemonList.Add("Back") - Me.Menu = New SelectMenu(pokemonList, 0, AddressOf SelectPokemon, -1) - End Select + Me.Menu = New SelectMenu(pokemonList, 0, AddressOf SelectPokemon, -1) End Sub Private Sub SelectPokemon(ByVal s As SelectMenu) - If s.SelectedItem <> "Back" Then - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Pokémon Then - Filters.Remove(Filter) - Exit For - End If - Next - - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Pokémon, .FilterValue = s.SelectedItem}) - Else + If s.SelectedItem = "Back" Then OpenPokemonMenu() + Return End If + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Pokémon) + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Pokémon, .FilterValue = s.SelectedItem}) End Sub -#End Region - -#Region "Type1Filter" - Private Sub OpenType1Menu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim types As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim types = l.Select(Function(p) p.Type1.ToString()).Distinct().ToList() - For Each p As Pokemon In l - If types.Contains(p.Type1.ToString()) = False Then - types.Add(p.Type1.ToString()) - End If - Next - types = (From type As String In types Order By type Ascending).ToList() + types.Sort() types.Add("Back") - If GetFilterText("Type1") <> "" Then - types.Insert(0, "Clear") - End If + If GetFilterText("Type1") <> "" Then types.Insert(0, "Clear") Me.Menu = New SelectMenu(types, 0, AddressOf SelectType1Type, -1) End Sub Private Sub SelectType1Type(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Type1 Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Type1 Then - Filters.Remove(Filter) - Exit For - End If - Next + If s.SelectedItem = "Back" Then Return + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Type1) + If s.SelectedItem = "Clear" Then Return - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Type1, .FilterValue = s.SelectedItem}) - End Select + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Type1, .FilterValue = s.SelectedItem}) End Sub -#End Region - -#Region "Type2Filter" - Private Sub OpenType2Menu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim types As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim types = l.Select(Function(p) p.Type2.ToString()).Distinct.ToList() - For Each p As Pokemon In l - If types.Contains(p.Type2.ToString()) = False Then - types.Add(p.Type2.ToString()) - End If - Next - types = (From type As String In types Order By type Ascending).ToList() + types.Sort() types.Add("Back") - If GetFilterText("Type2") <> "" Then - types.Insert(0, "Clear") - End If + If GetFilterText("Type2") <> "" Then types.Insert(0, "Clear") Me.Menu = New SelectMenu(types, 0, AddressOf SelectType2Type, -1) End Sub Private Sub SelectType2Type(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Type2 Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Type2 Then - Filters.Remove(Filter) - Exit For - End If - Next + If s.SelectedItem = "Back" Then Return + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Type2) + If s.SelectedItem = "Clear" Then Return - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Type2, .FilterValue = s.SelectedItem}) - End Select + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Type2, .FilterValue = s.SelectedItem}) End Sub - -#End Region - -#Region "MoveFilter" - Private Sub OpenMoveMenu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim letters As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim GetLetter = Function(attack As BattleSystem.Attack) attack.Name(0).ToString().ToUpper() + Dim letters = l.SelectMany(Function(p) p.Attacks).Select(GetLetter).Distinct.ToList() - For Each p As Pokemon In l - For Each a As BattleSystem.Attack In p.Attacks - If letters.Contains(a.Name(0).ToString().ToUpper()) = False Then - letters.Add(a.Name(0).ToString().ToUpper()) - End If - Next - Next - letters = (From letter As String In letters Order By letter Ascending).ToList() + letters.Sort() letters.Add("Back") - If GetFilterText("Move") <> "" Then - letters.Insert(0, "Clear") - End If + If GetFilterText("Move") <> "" Then letters.Insert(0, "Clear") Me.Menu = New SelectMenu(letters, 0, AddressOf SelectMoveLetter, -1) End Sub Private Sub SelectMoveLetter(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Move Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - Dim chosenLetter As String = s.SelectedItem + If s.SelectedItem = "Back" Then Return + If s.SelectedItem = "Clear" Then + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Move) + Return + End If + Dim chosenLetter = s.SelectedItem - Dim attackList As New List(Of String) - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) - For Each p As Pokemon In l - For Each a As BattleSystem.Attack In p.Attacks - If a.Name(0).ToString().ToUpper() = chosenLetter And attackList.Contains(a.Name) = False Then - attackList.Add(a.Name) - End If - Next - Next + Dim LetterMatches = Function(name As String) name.ToUpper().StartsWith(chosenLetter) + Dim attackList = l.SelectMany(Function(p) p.Attacks).Select(Function(a) a.Name).Where(LetterMatches).Distinct().ToList() - attackList = (From name As String In attackList Order By name Ascending).ToList() + attackList.Sort() - attackList.Add("Back") + attackList.Add("Back") - Me.Menu = New SelectMenu(attackList, 0, AddressOf SelectMove, -1) - End Select + Me.Menu = New SelectMenu(attackList, 0, AddressOf SelectMove, -1) End Sub Private Sub SelectMove(ByVal s As SelectMenu) - If s.SelectedItem <> "Back" Then - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Move Then - Filters.Remove(Filter) - Exit For - End If - Next - - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Move, .FilterValue = s.SelectedItem}) - Else + If s.SelectedItem = "Back" Then OpenMoveMenu() + Return End If + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Move) + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Move, .FilterValue = s.SelectedItem}) End Sub -#End Region - -#Region "AbilityFilter" - Private Sub OpenAbilityMenu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim letters As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim GetLetter = Function(pokemon As Pokemon) pokemon.Ability.Name(0).ToString().ToUpper() + Dim letters = l.Select(GetLetter).Distinct.ToList() - For Each p As Pokemon In l - If letters.Contains(p.Ability.Name(0).ToString().ToUpper()) = False Then - letters.Add(p.Ability.Name(0).ToString().ToUpper()) - End If - Next - letters = (From letter As String In letters Order By letter Ascending).ToList() + letters.Sort() letters.Add("Back") - If GetFilterText("Ability") <> "" Then - letters.Insert(0, "Clear") - End If + If GetFilterText("Ability") <> "" Then letters.Insert(0, "Clear") Me.Menu = New SelectMenu(letters, 0, AddressOf SelectAbilityLetter, -1) End Sub Private Sub SelectAbilityLetter(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Ability Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - Dim chosenLetter As String = s.SelectedItem + If s.SelectedItem = "Back" Then Return + If s.SelectedItem = "Clear" Then + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Ability) + Return + End If + Dim chosenLetter = s.SelectedItem - Dim abilityList As New List(Of String) - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim LetterMatches = Function(name As String) name.ToUpper().StartsWith(chosenLetter) + Dim abilityList = l.Select(Function(p) p.Ability.Name).Where(LetterMatches).Distinct().ToList() - For Each p As Pokemon In l - If p.Ability.Name(0).ToString().ToUpper() = chosenLetter And abilityList.Contains(p.Ability.Name) = False Then - abilityList.Add(p.Ability.Name) - End If - Next - abilityList = (From name As String In abilityList Order By name Ascending).ToList() + abilityList.Sort() - abilityList.Add("Back") + abilityList.Add("Back") - Me.Menu = New SelectMenu(abilityList, 0, AddressOf SelectAbility, -1) - End Select + Me.Menu = New SelectMenu(abilityList, 0, AddressOf SelectAbility, -1) End Sub Private Sub SelectAbility(ByVal s As SelectMenu) - If s.SelectedItem <> "Back" Then - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Ability Then - Filters.Remove(Filter) - Exit For - End If - Next - - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Ability, .FilterValue = s.SelectedItem}) - Else + If s.SelectedItem = "Back" Then OpenAbilityMenu() + Return End If + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Ability) + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Ability, .FilterValue = s.SelectedItem}) End Sub -#End Region - -#Region "NatureFilter" - Private Sub OpenNatureMenu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim natures As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim natures = l.Select(Function(p) p.Nature.ToString()).Distinct.ToList() - For Each p As Pokemon In l - If natures.Contains(p.Nature.ToString()) = False Then - natures.Add(p.Nature.ToString()) - End If - Next - natures = (From nature As String In natures Order By nature Ascending).ToList() + natures.Sort() natures.Add("Back") - If GetFilterText("Nature") <> "" Then - natures.Insert(0, "Clear") - End If + If GetFilterText("Nature") <> "" Then natures.Insert(0, "Clear") Me.Menu = New SelectMenu(natures, 0, AddressOf SelectNatureType, -1) End Sub Private Sub SelectNatureType(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Nature Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Nature Then - Filters.Remove(Filter) - Exit For - End If - Next + If s.SelectedItem = "Back" Then Return + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Nature) + If s.SelectedItem = "Clear" Then Return - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Nature, .FilterValue = s.SelectedItem}) - End Select + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Nature, .FilterValue = s.SelectedItem}) End Sub -#End Region - -#Region "GenderFilter" - Private Sub OpenGenderMenu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim genders As New List(Of String) + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim genders = l.Select(Function(p) p.Gender.ToString()).Distinct.ToList() - For Each p As Pokemon In l - If genders.Contains(p.Gender.ToString()) = False Then - genders.Add(p.Gender.ToString()) - End If - Next - genders = (From gender As String In genders Order By gender Ascending).ToList() + genders.Sort() genders.Add("Back") - If GetFilterText("Gender") <> "" Then - genders.Insert(0, "Clear") - End If + If GetFilterText("Gender") <> "" Then genders.Insert(0, "Clear") Me.Menu = New SelectMenu(genders, 0, AddressOf SelectGenderType, -1) End Sub Private Sub SelectGenderType(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Gender Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.Gender Then - Filters.Remove(Filter) - Exit For - End If - Next + If s.SelectedItem = "Back" Then Return + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.Gender) + If s.SelectedItem = "Clear" Then Return - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Gender, .FilterValue = s.SelectedItem}) - End Select + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.Gender, .FilterValue = s.SelectedItem}) End Sub -#End Region - -#Region "HeldItemFilter" - Private Sub OpenHeldItemMenu() - Dim l As List(Of Pokemon) = Me._storageSystemScreen.GetPokemonList(True, False) - Dim helditems As List(Of String) = {"Has a Held Item", "Has no Held Item", "Back"}.ToList() + Dim l = Me._storageSystemScreen.GetPokemonList(True, False) + Dim helditems = {"Has a Held Item", "Has no Held Item", "Back"}.ToList() - If GetFilterText("HeldItem") <> "" Then - helditems.Insert(0, "Clear") - End If + If GetFilterText("HeldItem") <> "" Then helditems.Insert(0, "Clear") Me.Menu = New SelectMenu(helditems, 0, AddressOf SelectHeldItemType, -1) End Sub Private Sub SelectHeldItemType(ByVal s As SelectMenu) - Select Case s.SelectedItem - Case "Back" - ' Go back. - Case "Clear" - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.HeldItem Then - Filters.Remove(Filter) - Exit For - End If - Next - Case Else - For Each Filter As StorageSystemScreen.Filter In Me.Filters - If Filter.FilterType = StorageSystemScreen.FilterTypes.HeldItem Then - Filters.Remove(Filter) - Exit For - End If - Next + If s.SelectedItem = "Back" Then Return + Me.Filters.RemoveAll(Function(filter) filter.FilterType = StorageSystemScreen.FilterTypes.HeldItem) + If s.SelectedItem = "Clear" Then Return - Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.HeldItem, .FilterValue = s.SelectedItem}) - End Select + Me.Filters.Add(New StorageSystemScreen.Filter() With {.FilterType = StorageSystemScreen.FilterTypes.HeldItem, .FilterValue = s.SelectedItem}) End Sub #End Region