julioCCs

vb.net power selection HUD sample

Jul 24th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.87 KB | None | 0 0
  1. 'list of powers:
  2. Private powers As New List(Of TPowers)
  3.  
  4. ...
  5.  
  6. 'add the powers integer ID, image and display name:
  7. powers.Add(New TPowers(powerID_1, modFilesFolder & "Images\power1.png", "power 1"))
  8.             powers.Add(New TPowers(powerID_2, modFilesFolder & "Images\power2.png", "power 2"))
  9.             powers.Add(New TPowers(powerID_3, modFilesFolder & "Images\power3.png", "power 3"))
  10.  
  11.             HUD_ImageSize = New Vector2(0.05, 0.09)
  12.             HUD_indicatorIconFile = modFilesFolder & "Images\crosshair.png"
  13.             HUD_indicatorIconColor = Color.White
  14.             HUD_indicatorIconSizeCoef = 1
  15.             HUD_backGround = modFilesFolder & "Images\background.png"
  16.             HUD_powers = powers
  17.             HUD_nonSelectedColor = Color.FromArgb(200, 150, 150, 150)
  18.             HUD_DescriptionPos = New Vector2(0.5, 0.9)
  19.  
  20. ...
  21.  
  22. 'basic class to retain powers info:
  23. Public Class TPowers
  24.     Public hudImg As String
  25.     Public powerID As Integer
  26.     Public description As String
  27.  
  28.     Public Sub New(pPower As Integer, pImg As String, pDescription As String)
  29.         powerID = pPower
  30.         hudImg = pImg
  31.         description = pDescription
  32.     End Sub
  33. End Class
  34.  
  35. ...
  36.  
  37. 'im not using a class like i should, this is why all vars are "Shared":
  38. Private Shared HUD_powersSelectionHeading As Double = 0
  39. Private Shared HUD_powersFakeMousePos As Vector3 = New Vector3(0.5, 0.5, 0)
  40. Private Shared HUD_radius As Double = 0
  41. Public Shared bShowPowersSelectionWheel As Boolean = False
  42. Private Shared HUD_powers_startup As Boolean = True
  43. Public Shared HUD_selectedPower As Integer = 0
  44. Public Shared HUD_ImageSize As Vector2 = New Vector2(0.074, 0.124)
  45. Public Shared HUD_reset As Boolean = False
  46. Public Shared HUD_backGround As String = ""
  47. Public Shared HUD_backGroundSize As Vector2 = New Vector2(1, 1)
  48. Public Shared HUD_backGroundPos As Vector2 = New Vector2(0, 0)
  49. Public Shared HUD_indicatorIconFile As String = ""
  50. Public Shared HUD_indicatorIconColor As Color = Color.White
  51. Public Shared HUD_indicatorIconSizeCoef As Double = 1
  52. Public Shared HUD_powers As List(Of TPowers)
  53. Public Shared HUD_nonSelectedColor As Color = Color.FromArgb(150, 100, 100, 100)
  54. Public Shared HUD_selectedColor As Color = Color.White
  55. Public Shared HUD_isOff As Boolean = True
  56. Private Shared HUD_iniFile As CustomIniFile = Nothing
  57. Public Shared HUD_DescriptionPos As Vector2 = Nothing
  58.  
  59. 'call in a tick, set bShowPowersSelectionWheel = true to show
  60. Public Shared Sub HUD_powerSelectionTick()
  61.     If bShowPowersSelectionWheel Then
  62.         If HUD_powers.Count = 0 Then
  63.             Exit Sub
  64.         End If
  65.  
  66.         If HUD_isOff Then
  67.             HUD_isOff = False
  68.         End If
  69.  
  70.         If HUD_powers_startup Then
  71.             HUD_powers_startup = False
  72.  
  73.             HUD_iniFile = New CustomIniFile
  74.  
  75.             HUD_powersFakeMousePos.X = HUD_iniFile.settingsGetDouble("x", "HUD_powersFakeMousePos", 0.5)
  76.             HUD_powersFakeMousePos.Y = HUD_iniFile.settingsGetDouble("y", "HUD_powersFakeMousePos", 0.5)
  77.             HUD_powersFakeMousePos.Z = HUD_iniFile.settingsGetDouble("z", "HUD_powersFakeMousePos", 0)
  78.         End If
  79.  
  80.         HUD_reset = True
  81.  
  82.         Game.TimeScale = 0
  83.  
  84.         toggleCameraControls(False)
  85.  
  86.         'determine fake mouse pos
  87.         Dim tmpX As Double = 0.5
  88.         Dim tmpY As Double = 0.5
  89.         Dim tmpHSpacing As Double = 360 / HUD_powers.Count
  90.         Dim tmpHeading As Double = 0
  91.         Dim tmpPos As Vector3 = New Vector3(tmpX, tmpY, 0)
  92.         Dim tmpSize As Vector2 = HUD_ImageSize
  93.         Dim tmpRadius As Double = HUD_radius
  94.         Dim tmpIndex As Integer = 0
  95.         Dim tmpRatio As Double = Game.ScreenResolution.Height / Game.ScreenResolution.Width
  96.  
  97.         If HUD_radius < 0.25 Then
  98.             HUD_radius += 0.035
  99.         End If
  100.  
  101.         HUD_powersFakeMousePos.X += getMouseChange_X(usingController) * 0.01
  102.         HUD_powersFakeMousePos.Y += getMouseChange_Y(usingController) * 0.01
  103.  
  104.         Dim tmpFakeMousePos As Vector3 = New Vector3(HUD_powersFakeMousePos.X, HUD_powersFakeMousePos.Y, 0)
  105.         Dim tmpCenterPos As Vector3 = New Vector3(0.5, 0.5, 0)
  106.         Dim tmpMouseDir As Vector3 = Vector3.Normalize(tmpFakeMousePos - tmpCenterPos)
  107.         Dim tmpMouseHeading As Double = directionToHeading(tmpMouseDir)
  108.         Dim tmpMouse2dPos As Vector2 = New Vector2((tmpCenterPos + tmpMouseDir * tmpRadius).X, (tmpCenterPos + tmpMouseDir * tmpRadius).Y)
  109.         Dim tmpArrowOffset As Double = 0.68
  110.         Dim tmpArrowSize As Vector2 = New Vector2(0.0449, 0.0789) * HUD_indicatorIconSizeCoef
  111.         Dim tmpArrowPos As Vector2 = New Vector2((tmpCenterPos + tmpMouseDir * tmpRadius * tmpArrowOffset).X, (tmpCenterPos + tmpMouseDir * tmpRadius * tmpArrowOffset).Y)
  112.  
  113.         HUD_powersFakeMousePos = tmpCenterPos + tmpMouseDir
  114.  
  115.         'draw the arrow
  116.         tmpArrowPos.X *= tmpRatio
  117.         tmpArrowPos.X += 0.24 - tmpArrowSize.X
  118.         tmpArrowPos.Y -= tmpArrowSize.Y * 0.5
  119.  
  120.         If HUD_backGround <> "" Then
  121.             drawTextureAux(HUD_backGround, HUD_backGroundPos, HUD_backGroundSize, 0, Color.White)
  122.         End If
  123.  
  124.         If HUD_indicatorIconFile <> "" Then
  125.             drawTextureAux(HUD_indicatorIconFile, tmpArrowPos, tmpArrowSize, 0, HUD_indicatorIconColor)
  126.         End If
  127.  
  128.         'draw the hud power icons
  129.         Dim tmpSelected As Integer = HUD_selectedPower
  130.         Dim tmpCloserH As Double = 1000
  131.         Dim tmpCloserPos3d As Vector3
  132.  
  133.         For Each i As TPowers In HUD_powers
  134.             Dim tmpDir As Vector3 = HeadingToDirection(tmpHeading) * tmpRadius
  135.             tmpDir.X *= tmpRatio
  136.  
  137.             Dim tmp As Vector3 = tmpPos + tmpDir
  138.  
  139.             tmpHeading += tmpHSpacing
  140.  
  141.             Dim tmpImgPos2d As Vector2 = New Vector2(tmp.X, tmp.Y) '+ tmpSize * 0.5
  142.             Dim tmpImgPos3d As Vector3 = New Vector3(tmpImgPos2d.X, tmpImgPos2d.Y, 0)
  143.             Dim tmpImgHeading As Double = directionToHeading(Vector3.Normalize(tmpImgPos3d - tmpCenterPos))
  144.             Dim tmpHDiff As Double = Abs(headingDiff(tmpImgHeading, tmpMouseHeading))
  145.  
  146.             If (tmpHDiff < tmpCloserH) Then
  147.                 tmpCloserH = tmpHDiff
  148.                 tmpSelected = i.powerID
  149.                 tmpCloserPos3d = tmpImgPos3d
  150.             End If
  151.         Next
  152.  
  153.         HUD_selectedPower = tmpSelected
  154.  
  155.         tmpHeading = 0
  156.  
  157.         Dim tmpDescription As String = ""
  158.  
  159.         For Each i As TPowers In HUD_powers
  160.             Dim tmpDir As Vector3 = HeadingToDirection(tmpHeading) * tmpRadius
  161.             tmpDir.X *= tmpRatio
  162.  
  163.             Dim tmp As Vector3 = tmpPos + tmpDir
  164.  
  165.             tmpHeading += tmpHSpacing
  166.  
  167.             Dim tmpImgPos2d As Vector2 = New Vector2(tmp.X, tmp.Y) - tmpSize * 0.5
  168.  
  169.             If tmpSelected = i.powerID Then
  170.                 drawTextureAux(i.hudImg, New Vector2(tmp.X, tmp.Y) - tmpSize * 0.5, tmpSize, 0, HUD_selectedColor, 100, tmpIndex)
  171.  
  172.                 tmpDescription = i.description
  173.             Else
  174.                 drawTextureAux(i.hudImg, New Vector2(tmp.X, tmp.Y) - tmpSize * 0.5, tmpSize, 0, HUD_nonSelectedColor, 100, tmpIndex)
  175.             End If
  176.  
  177.             tmpIndex += 1
  178.         Next
  179.  
  180.         If HUD_DescriptionPos = Nothing Then
  181.             HUD_DescriptionPos = New Vector2(0.5, 0.5)
  182.         End If
  183.  
  184.         drawText(tmpDescription, HUD_DescriptionPos.X, HUD_DescriptionPos.Y, Color.White, True)
  185.     Else
  186.         If HUD_reset Then
  187.             HUD_reset = False
  188.  
  189.             HUD_radius = 0
  190.  
  191.             Game.TimeScale = 1
  192.  
  193.             If Not HUD_iniFile Is Nothing Then
  194.                 HUD_iniFile.WriteINI("x", "HUD_powersFakeMousePos", HUD_powersFakeMousePos.X)
  195.                 HUD_iniFile.WriteINI("y", "HUD_powersFakeMousePos", HUD_powersFakeMousePos.Y)
  196.                 HUD_iniFile.WriteINI("z", "HUD_powersFakeMousePos", HUD_powersFakeMousePos.Z)
  197.             End If
  198.         End If
  199.  
  200.         If Not HUD_isOff Then
  201.             HUD_isOff = True
  202.         End If
  203.     End If
  204. End Sub
Add Comment
Please, Sign In to add comment