Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. ' text color pointers
  4. Public Const Black As Byte = 0
  5. Public Const Blue As Byte = 1
  6. Public Const Green As Byte = 2
  7. Public Const Cyan As Byte = 3
  8. Public Const Red As Byte = 4
  9. Public Const Magenta As Byte = 5
  10. Public Const Brown As Byte = 6
  11. Public Const Grey As Byte = 7
  12. Public Const DarkGrey As Byte = 8
  13. Public Const BrightBlue As Byte = 9
  14. Public Const BrightGreen As Byte = 10
  15. Public Const BrightCyan As Byte = 11
  16. Public Const BrightRed As Byte = 12
  17. Public Const Pink As Byte = 13
  18. Public Const Yellow As Byte = 14
  19. Public Const White As Byte = 15
  20. Public Const DarkBrown As Byte = 16
  21.  
  22. Public Const SayColor As Byte = White
  23. Public Const GlobalColor As Byte = BrightBlue
  24. Public Const BroadcastColor As Byte = White
  25. Public Const TellColor As Byte = BrightGreen
  26. Public Const EmoteColor As Byte = BrightCyan
  27. Public Const AdminColor As Byte = BrightCyan
  28. Public Const HelpColor As Byte = BrightBlue
  29. Public Const WhoColor As Byte = BrightBlue
  30. Public Const JoinLeftColor As Byte = DarkGrey
  31. Public Const NpcColor As Byte = Brown
  32. Public Const AlertColor As Byte = Red
  33. Public Const NewMapColor As Byte = BrightBlue
  34.  
  35. ' Stuffs
  36. Public Type POINTAPI
  37.     x As Long
  38.     Y As Long
  39. End Type
  40.  
  41. Private Type CharVA
  42.     Vertex(0 To 3) As TLVERTEX
  43. End Type
  44.  
  45. Private Type VFH
  46.     BitmapWidth As Long
  47.     BitmapHeight As Long
  48.     CellWidth As Long
  49.     CellHeight As Long
  50.     BaseCharOffset As Byte
  51.     CharWidth(0 To 255) As Byte
  52.     CharVA(0 To 255) As CharVA
  53. End Type
  54.  
  55. Private Type CustomFont
  56.     HeaderInfo As VFH
  57.     Texture As Direct3DTexture8
  58.     RowPitch As Integer
  59.     RowFactor As Single
  60.     ColFactor As Single
  61.     CharHeight As Byte
  62.     TextureSize As POINTAPI
  63. End Type
  64.  
  65. ' Chat Buffer
  66. Public ChatVA() As TLVERTEX
  67. Public ChatVAS() As TLVERTEX
  68.  
  69. Public Const ChatTextBufferSize As Integer = 200
  70. Public ChatBufferChunk As Single
  71.  
  72. 'Text buffer
  73. Public Type ChatTextBuffer
  74.     Text As String
  75.     color As Long
  76. End Type
  77.  
  78. 'Chat vertex buffer information
  79. Public ChatArrayUbound As Long
  80. Public ChatVB As Direct3DVertexBuffer8
  81. Public ChatVBS As Direct3DVertexBuffer8
  82. Public ChatTextBuffer(1 To ChatTextBufferSize) As ChatTextBuffer
  83.  
  84. Public Font_Default As CustomFont
  85. Public Font_Georgia As CustomFont
  86.  
  87. Public Sub DrawPlayerName(ByVal Index As Long)
  88. Dim textX As Long, textY As Long, Text As String, textSize As Long, colour As Long
  89.    
  90.     Text = "[" & Player(Index).Level & "]" & (GetPlayerName(Index))
  91.     textSize = EngineGetTextWidth(Font_Default, Text)
  92.    
  93.     ' get the colour
  94.    If GetPlayerAccess(Index) > 0 Then
  95.         colour = Yellow
  96.     Else
  97.         colour = White
  98.     End If
  99.    
  100.     textX = Player(Index).x * PIC_X + Player(Index).xOffset + (PIC_X \ 2) - (textSize \ 2)
  101.     textY = Player(Index).Y * PIC_Y + Player(Index).yOffset - 32
  102.    
  103.     If GetPlayerSprite(Index) >= 1 And GetPlayerSprite(Index) <= Count_Char Then
  104.         textY = GetPlayerY(Index) * PIC_Y + Player(Index).yOffset - (D3DT_TEXTURE(Tex_Char(GetPlayerSprite(Index))).height / 4) + 12
  105.     End If
  106.    
  107.     Call RenderText(Font_Default, Text, ConvertMapX(textX), ConvertMapY(textY), colour)
  108. End Sub
  109.  
  110. Public Sub DrawNpcName(ByVal Index As Long)
  111. Dim textX As Long, textY As Long, Text As String, textSize As Long, npcNum As Long, colour As Long
  112.    
  113.     npcNum = MapNpc(Index).num
  114.     Text = Trim$(Npc(npcNum).Name)
  115.     textSize = EngineGetTextWidth(Font_Default, Text)
  116.    
  117.     If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or Npc(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKWHENATTACKED Then
  118.         ' get the colour
  119.        If Npc(npcNum).Level <= GetPlayerLevel(MyIndex) - 3 Then
  120.             colour = Grey
  121.         ElseIf Npc(npcNum).Level <= GetPlayerLevel(MyIndex) - 2 Then
  122.             colour = Green
  123.         ElseIf Npc(npcNum).Level > GetPlayerLevel(MyIndex) Then
  124.             colour = Red
  125.         Else
  126.             colour = White
  127.         End If
  128.     Else
  129.         colour = White
  130.     End If
  131.    
  132.     textX = MapNpc(Index).x * PIC_X + MapNpc(Index).xOffset + (PIC_X \ 2) - (textSize \ 2)
  133.     textY = MapNpc(Index).Y * PIC_Y + MapNpc(Index).yOffset - 32
  134.    
  135.     If Npc(npcNum).sprite >= 1 And Npc(npcNum).sprite <= Count_Char Then
  136.         textY = MapNpc(Index).Y * PIC_Y + MapNpc(Index).yOffset - (D3DT_TEXTURE(Tex_Char(Npc(npcNum).sprite)).height / 4) + 12 - (((32 * (MapNpc(Index).skale * 0.1)) - 32) * 0.9)
  137.     End If
  138.    
  139.     Call RenderText(Font_Default, Text, ConvertMapX(textX), ConvertMapY(textY), colour)
  140. End Sub
  141.  
  142. Public Sub RenderText(ByRef UseFont As CustomFont, ByVal Text As String, ByVal x As Long, ByVal Y As Long, ByVal color As Long, Optional ByVal alpha As Long = 255, Optional Shadow As Boolean = True)
  143. Dim TempVA(0 To 3)  As TLVERTEX
  144. Dim TempVAS(0 To 3) As TLVERTEX
  145. Dim TempStr() As String
  146. Dim Count As Integer
  147. Dim Ascii() As Byte
  148. Dim Row As Integer
  149. Dim u As Single
  150. Dim v As Single
  151. Dim i As Long
  152. Dim j As Long
  153. Dim KeyPhrase As Byte
  154. Dim tempcolor As Long
  155. Dim ResetColor As Byte
  156. Dim srcRECT As RECT
  157. Dim v2 As D3DVECTOR2
  158. Dim v3 As D3DVECTOR2
  159. Dim yOffset As Single
  160.  
  161.     ' set the color
  162.    color = dx8Colour(color, alpha)
  163.  
  164.     'Check for valid text to render
  165.    If LenB(Text) = 0 Then Exit Sub
  166.    
  167.     'Get the text into arrays (split by vbCrLf)
  168.    TempStr = Split(Text, vbCrLf)
  169.    
  170.     'Set the temp color (or else the first character has no color)
  171.    tempcolor = color
  172.    
  173.     'Set the texture
  174.    D3DDevice8.SetTexture 0, UseFont.Texture
  175.     CurrentTexture = -1
  176.    
  177.     'Loop through each line if there are line breaks (vbCrLf)
  178.    For i = 0 To UBound(TempStr)
  179.         If Len(TempStr(i)) > 0 Then
  180.             yOffset = i * UseFont.CharHeight
  181.             Count = 0
  182.             'Convert the characters to the ascii value
  183.            Ascii() = StrConv(TempStr(i), vbFromUnicode)
  184.            
  185.             'Loop through the characters
  186.            For j = 1 To Len(TempStr(i))
  187.                 'Copy from the cached vertex array to the temp vertex array
  188.                Call CopyMemory(TempVA(0), UseFont.HeaderInfo.CharVA(Ascii(j - 1)).Vertex(0), FVF_Size * 4)
  189.                
  190.                 'Set up the verticies
  191.                TempVA(0).x = x + Count
  192.                 TempVA(0).Y = Y + yOffset
  193.                 TempVA(1).x = TempVA(1).x + x + Count
  194.                 TempVA(1).Y = TempVA(0).Y
  195.                 TempVA(2).x = TempVA(0).x
  196.                 TempVA(2).Y = TempVA(2).Y + TempVA(0).Y
  197.                 TempVA(3).x = TempVA(1).x
  198.                 TempVA(3).Y = TempVA(2).Y
  199.                
  200.                 'Set the colors
  201.                TempVA(0).color = tempcolor
  202.                 TempVA(1).color = tempcolor
  203.                 TempVA(2).color = tempcolor
  204.                 TempVA(3).color = tempcolor
  205.                
  206.                 'Draw the verticies
  207.                Call D3DDevice8.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, TempVA(0), FVF_Size)
  208.                
  209.                
  210.                 'Shift over the the position to render the next character
  211.                Count = Count + UseFont.HeaderInfo.CharWidth(Ascii(j - 1))
  212.                
  213.                 'Check to reset the color
  214.                If ResetColor Then
  215.                     ResetColor = 0
  216.                     tempcolor = color
  217.                 End If
  218.             Next j
  219.         End If
  220.     Next i
  221. End Sub
  222.  
  223. Sub EngineInitFontTextures()
  224.     'Check if we have the device
  225.    If D3DDevice8.TestCooperativeLevel <> D3D_OK Then Exit Sub
  226.  
  227.     ' FONT DEFAULT
  228.    Set Font_Default.Texture = Direct3DX8.CreateTextureFromFileEx(D3DDevice8, App.path & Path_Font & "texdefault.png", 256, 256, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_POINT, D3DX_FILTER_POINT, RGB(255, 0, 255), ByVal 0, ByVal 0)
  229.     Font_Default.TextureSize.x = 256
  230.     Font_Default.TextureSize.Y = 256
  231.    
  232.     ' Georgia
  233.    Set Font_Georgia.Texture = Direct3DX8.CreateTextureFromFileEx(D3DDevice8, App.path & Path_Font & "georgia.png", 256, 256, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_POINT, D3DX_FILTER_POINT, RGB(255, 0, 255), ByVal 0, ByVal 0)
  234.     Font_Georgia.TextureSize.x = 256
  235.     Font_Georgia.TextureSize.Y = 256
  236. End Sub
  237.  
  238. Sub LoadFontHeader(ByRef theFont As CustomFont, ByVal filename As String)
  239. Dim FileNum As Byte
  240. Dim LoopChar As Long
  241. Dim Row As Single
  242. Dim u As Single
  243. Dim v As Single
  244.  
  245.     'Load the header information
  246.    FileNum = FreeFile
  247.     Open App.path & Path_Font & filename For Binary As #FileNum
  248.         Get #FileNum, , theFont.HeaderInfo
  249.     Close #FileNum
  250.    
  251.     'Calculate some common values
  252.    theFont.CharHeight = theFont.HeaderInfo.CellHeight - 4
  253.     theFont.RowPitch = theFont.HeaderInfo.BitmapWidth \ theFont.HeaderInfo.CellWidth
  254.     theFont.ColFactor = theFont.HeaderInfo.CellWidth / theFont.HeaderInfo.BitmapWidth
  255.     theFont.RowFactor = theFont.HeaderInfo.CellHeight / theFont.HeaderInfo.BitmapHeight
  256.    
  257.     'Cache the verticies used to draw the character (only requires setting the color and adding to the X/Y values)
  258.    For LoopChar = 0 To 255
  259.         'tU and tV value (basically tU = BitmapXPosition / BitmapWidth, and height for tV)
  260.        Row = (LoopChar - theFont.HeaderInfo.BaseCharOffset) \ theFont.RowPitch
  261.         u = ((LoopChar - theFont.HeaderInfo.BaseCharOffset) - (Row * theFont.RowPitch)) * theFont.ColFactor
  262.         v = Row * theFont.RowFactor
  263.        
  264.         'Set the verticies
  265.        With theFont.HeaderInfo.CharVA(LoopChar)
  266.             .Vertex(0).color = D3DColorARGB(255, 0, 0, 0)   'Black is the most common color
  267.            .Vertex(0).RHW = 1
  268.             .Vertex(0).tu = u
  269.             .Vertex(0).tv = v
  270.             .Vertex(0).x = 0
  271.             .Vertex(0).Y = 0
  272.             .Vertex(0).z = 0
  273.             .Vertex(1).color = D3DColorARGB(255, 0, 0, 0)
  274.             .Vertex(1).RHW = 1
  275.             .Vertex(1).tu = u + theFont.ColFactor
  276.             .Vertex(1).tv = v
  277.             .Vertex(1).x = theFont.HeaderInfo.CellWidth
  278.             .Vertex(1).Y = 0
  279.             .Vertex(1).z = 0
  280.             .Vertex(2).color = D3DColorARGB(255, 0, 0, 0)
  281.             .Vertex(2).RHW = 1
  282.             .Vertex(2).tu = u
  283.             .Vertex(2).tv = v + theFont.RowFactor
  284.             .Vertex(2).x = 0
  285.             .Vertex(2).Y = theFont.HeaderInfo.CellHeight
  286.             .Vertex(2).z = 0
  287.             .Vertex(3).color = D3DColorARGB(255, 0, 0, 0)
  288.             .Vertex(3).RHW = 1
  289.             .Vertex(3).tu = u + theFont.ColFactor
  290.             .Vertex(3).tv = v + theFont.RowFactor
  291.             .Vertex(3).x = theFont.HeaderInfo.CellWidth
  292.             .Vertex(3).Y = theFont.HeaderInfo.CellHeight
  293.             .Vertex(3).z = 0
  294.         End With
  295.     Next LoopChar
  296. End Sub
  297.  
  298. Sub EngineInitFontSettings()
  299.     LoadFontHeader Font_Default, "texdefault.dat"
  300.     LoadFontHeader Font_Georgia, "georgia.dat"
  301. End Sub
  302.  
  303. Public Function dx8Colour(ByVal colourNum As Long, ByVal alpha As Long) As Long
  304.     Select Case colourNum
  305.         Case 0 ' Black
  306.            dx8Colour = D3DColorARGB(alpha, 0, 0, 0)
  307.         Case 1 ' Blue
  308.            dx8Colour = D3DColorARGB(alpha, 16, 104, 237)
  309.         Case 2 ' Green
  310.            dx8Colour = D3DColorARGB(alpha, 119, 188, 84)
  311.         Case 3 ' Cyan
  312.            dx8Colour = D3DColorARGB(alpha, 16, 224, 237)
  313.         Case 4 ' Red
  314.            dx8Colour = D3DColorARGB(alpha, 201, 0, 0)
  315.         Case 5 ' Magenta
  316.            dx8Colour = D3DColorARGB(alpha, 255, 0, 255)
  317.         Case 6 ' Brown
  318.            dx8Colour = D3DColorARGB(alpha, 175, 149, 92)
  319.         Case 7 ' Grey
  320.            dx8Colour = D3DColorARGB(alpha, 192, 192, 192)
  321.         Case 8 ' DarkGrey
  322.            dx8Colour = D3DColorARGB(alpha, 128, 128, 128)
  323.         Case 9 ' BrightBlue
  324.            dx8Colour = D3DColorARGB(alpha, 126, 182, 240)
  325.         Case 10 ' BrightGreen
  326.            dx8Colour = D3DColorARGB(alpha, 126, 240, 137)
  327.         Case 11 ' BrightCyan
  328.            dx8Colour = D3DColorARGB(alpha, 157, 242, 242)
  329.         Case 12 ' BrightRed
  330.            dx8Colour = D3DColorARGB(alpha, 255, 0, 0)
  331.         Case 13 ' Pink
  332.            dx8Colour = D3DColorARGB(alpha, 255, 118, 221)
  333.         Case 14 ' Yellow
  334.            dx8Colour = D3DColorARGB(alpha, 255, 255, 0)
  335.         Case 15 ' White
  336.            dx8Colour = D3DColorARGB(alpha, 255, 255, 255)
  337.         Case 16 ' dark brown
  338.            dx8Colour = D3DColorARGB(alpha, 98, 84, 52)
  339.     End Select
  340. End Function
  341.  
  342. Public Function EngineGetTextWidth(ByRef UseFont As CustomFont, ByVal Text As String) As Integer
  343. Dim LoopI As Integer
  344.  
  345.     'Make sure we have text
  346.    If LenB(Text) = 0 Then Exit Function
  347.    
  348.     'Loop through the text
  349.    For LoopI = 1 To Len(Text)
  350.         EngineGetTextWidth = EngineGetTextWidth + UseFont.HeaderInfo.CharWidth(Asc(Mid$(Text, LoopI, 1)))
  351.     Next LoopI
  352.  
  353. End Function
  354.  
  355. Sub DrawActionMsg(ByVal Index As Integer)
  356. Dim x As Long, Y As Long, i As Long, Time As Long
  357. Dim LenMsg As Long, alpha As Long
  358.  
  359.     If ActionMsg(Index).message = vbNullString Then Exit Sub
  360.  
  361.     ' how long we want each message to appear
  362.    Select Case ActionMsg(Index).type
  363.         Case ACTIONMSG_STATIC
  364.             Time = 1500
  365.            
  366.             LenMsg = EngineGetTextWidth(Font_Default, Trim$(ActionMsg(Index).message))
  367.  
  368.             If ActionMsg(Index).Y > 0 Then
  369.                 x = ActionMsg(Index).x + Int(PIC_X \ 2) - (LenMsg / 2)
  370.                 Y = ActionMsg(Index).Y + PIC_Y
  371.             Else
  372.                 x = ActionMsg(Index).x + Int(PIC_X \ 2) - (LenMsg / 2)
  373.                 Y = ActionMsg(Index).Y - Int(PIC_Y \ 2) + 18
  374.             End If
  375.  
  376.         Case ACTIONMSG_SCROLL
  377.             Time = 1500
  378.        
  379.             If ActionMsg(Index).Y > 0 Then
  380.                 x = ActionMsg(Index).x + Int(PIC_X \ 2) - ((Len(Trim$(ActionMsg(Index).message)) \ 2) * 8)
  381.                 Y = ActionMsg(Index).Y - Int(PIC_Y \ 2) - 2 - (ActionMsg(Index).Scroll * 0.6)
  382.                 ActionMsg(Index).Scroll = ActionMsg(Index).Scroll + 1
  383.             Else
  384.                 x = ActionMsg(Index).x + Int(PIC_X \ 2) - ((Len(Trim$(ActionMsg(Index).message)) \ 2) * 8)
  385.                 Y = ActionMsg(Index).Y - Int(PIC_Y \ 2) + 18 + (ActionMsg(Index).Scroll * 0.001)
  386.                 ActionMsg(Index).Scroll = ActionMsg(Index).Scroll + 1
  387.             End If
  388.            
  389.             ActionMsg(Index).alpha = ActionMsg(Index).alpha - 5
  390.             If ActionMsg(Index).alpha <= 0 Then ClearActionMsg Index: Exit Sub
  391.  
  392.         Case ACTIONMSG_SCREEN
  393.             Time = 3000
  394.  
  395.             ' This will kill any action screen messages that there in the system
  396.            For i = MAX_BYTE To 1 Step -1
  397.                 If ActionMsg(i).type = ACTIONMSG_SCREEN Then
  398.                     If i <> Index Then
  399.                         ClearActionMsg Index
  400.                         Index = i
  401.                     End If
  402.                 End If
  403.             Next
  404.    
  405.             x = (400) - ((EngineGetTextWidth(Font_Default, Trim$(ActionMsg(Index).message)) \ 2))
  406.             Y = 24
  407.  
  408.     End Select
  409.    
  410.     x = ConvertMapX(x)
  411.     Y = ConvertMapY(Y)
  412.  
  413.     If ActionMsg(Index).Created > 0 Then
  414.         RenderText Font_Default, ActionMsg(Index).message, x, Y, ActionMsg(Index).color, ActionMsg(Index).alpha
  415.     End If
  416.  
  417. End Sub
  418.  
  419. Public Function DrawMapAttributes()
  420.     Dim x As Long
  421.     Dim Y As Long
  422.     Dim tx As Long
  423.     Dim ty As Long
  424.  
  425.     If frmEditor_Map.optAttribs.value Then
  426.         For x = TileView.left To TileView.Right
  427.             For Y = TileView.top To TileView.bottom
  428.                 If IsValidMapPoint(x, Y) Then
  429.                     With Map.Tile(x, Y)
  430.                         tx = ((ConvertMapX(x * PIC_X)) - 4) + (PIC_X * 0.5)
  431.                         ty = ((ConvertMapY(Y * PIC_Y)) - 7) + (PIC_Y * 0.5)
  432.                         Select Case .type
  433.                             Case TILE_TYPE_BLOCKED
  434.                                 RenderText Font_Default, "[B]", tx - 3, ty, White, , True
  435.                                
  436.                             Case TILE_TYPE_WARP
  437.                                 RenderText Font_Default, "[W]", tx - 3, ty, BrightBlue
  438.                             Case TILE_TYPE_ITEM
  439.                                 RenderText Font_Default, "[I]", tx - 3, ty, White
  440.                             Case TILE_TYPE_NPCAVOID
  441.                                 RenderText Font_Default, "[N]", tx - 3, ty, White
  442.                             Case TILE_TYPE_KEY
  443.                                 RenderText Font_Default, "[K]", tx - 3, ty, White
  444.                             Case TILE_TYPE_KEYOPEN
  445.                                 RenderText Font_Default, "[O]", tx - 3, ty, White
  446.                             Case TILE_TYPE_RESOURCE
  447.                                 RenderText Font_Default, "[R]", tx - 3, ty, Green
  448.                             Case TILE_TYPE_DOOR
  449.                                 RenderText Font_Default, "[D]", tx - 3, ty, Brown
  450.                             Case TILE_TYPE_NPCSPAWN
  451.                                 RenderText Font_Default, "[S]", tx - 3, ty, Yellow
  452.                             Case TILE_TYPE_SHOP
  453.                                 RenderText Font_Default, "[S]", tx - 3, ty, BrightBlue
  454.                             Case TILE_TYPE_TRAP
  455.                                 RenderText Font_Default, "[T]", tx - 3, ty, BrightBlue
  456.                             Case TILE_TYPE_SLIDE
  457.                                 RenderText Font_Default, "[S]", tx - 3, ty, Pink
  458.                             Case TILE_TYPE_CHAT
  459.                                 RenderText Font_Default, "[C]", tx - 3, ty, Blue
  460.                             Case TILE_TYPE_INSTANCESTART
  461.                                 RenderText Font_Default, "[IS]", tx - 3, ty, Blue
  462.                             Case TILE_TYPE_INSTANCEEND
  463.                                 RenderText Font_Default, "[IE]", tx - 3, ty, BrightRed
  464.                             Case TILE_TYPE_FRINGEOVERRIDE
  465.                                 RenderText Font_Default, "[FO]", tx - 3, ty, Cyan
  466.                             Case TILE_TYPE_ARENA
  467.                                 RenderText Font_Default, "[A]", tx - 3, ty, Yellow
  468.                             Case TILE_TYPE_DEEP
  469.                                 RenderText Font_Default, "[D]", tx - 3, ty, Yellow
  470.                             Case TILE_TYPE_HEAL
  471.                                 RenderText Font_Default, "[H]", tx - 3, ty, Cyan
  472.                         End Select
  473.                     End With
  474.                 End If
  475.             Next
  476.         Next
  477.     End If
  478.  
  479. End Function
  480.  
  481. ' Chat Box
  482. Public Sub RenderChatTextBuffer()
  483. Dim srcRECT As RECT
  484. Dim v2 As D3DVECTOR2
  485. Dim v3 As D3DVECTOR2
  486. Dim i As Long
  487.  
  488.     'Clear the LastTexture, letting the rest of the engine know that the texture needs to be changed for next rect render
  489.    D3DDevice8.SetTexture 0, Font_Default.Texture
  490.     CurrentTexture = -1
  491.  
  492.     If ChatArrayUbound > 0 Then
  493.         D3DDevice8.SetStreamSource 0, ChatVBS, FVF_Size
  494.         D3DDevice8.DrawPrimitive D3DPT_TRIANGLELIST, 0, (ChatArrayUbound + 1) \ 3
  495.         D3DDevice8.SetStreamSource 0, ChatVB, FVF_Size
  496.         D3DDevice8.DrawPrimitive D3DPT_TRIANGLELIST, 0, (ChatArrayUbound + 1) \ 3
  497.     End If
  498.    
  499. End Sub
  500.  
  501. Public Sub UpdateChatArray()
  502. Dim Chunk As Integer
  503. Dim Count As Integer
  504. Dim LoopC As Byte
  505. Dim Ascii As Byte
  506. Dim Row As Long
  507. Dim Pos As Long
  508. Dim u As Single
  509. Dim v As Single
  510. Dim x As Single
  511. Dim Y As Single
  512. Dim y2 As Single
  513. Dim i As Long
  514. Dim j As Long
  515. Dim size As Integer
  516. Dim KeyPhrase As Byte
  517. Dim ResetColor As Byte
  518. Dim tempcolor As Long
  519. Dim yOffset As Long
  520.  
  521.     ' set the offset of each line
  522.    yOffset = 14
  523.  
  524.     'Set the position
  525.    If ChatBufferChunk <= 1 Then ChatBufferChunk = 1
  526.    
  527.     Chunk = ChatScroll
  528.    
  529.     'Get the number of characters in all the visible buffer
  530.    size = 0
  531.    
  532.     For LoopC = (Chunk * ChatBufferChunk) - (8 - 1) To Chunk * ChatBufferChunk
  533.         If LoopC > ChatTextBufferSize Then Exit For
  534.         size = size + Len(ChatTextBuffer(LoopC).Text)
  535.     Next
  536.    
  537.     size = size - j
  538.     ChatArrayUbound = size * 6 - 1
  539.     If ChatArrayUbound < 0 Then Exit Sub
  540.     ReDim ChatVA(0 To ChatArrayUbound) 'Size our array to fix the 6 verticies of each character
  541.    ReDim ChatVAS(0 To ChatArrayUbound)
  542.    
  543.     'Set the base position
  544.    x = GUIWindow(GUI_CHAT).x + ChatOffsetX
  545.     Y = GUIWindow(GUI_CHAT).Y + ChatOffsetY
  546.  
  547.     'Loop through each buffer string
  548.    For LoopC = (Chunk * ChatBufferChunk) - (8 - 1) To Chunk * ChatBufferChunk
  549.         If LoopC > ChatTextBufferSize Then Exit For
  550.         If ChatBufferChunk * Chunk > ChatTextBufferSize Then ChatBufferChunk = ChatBufferChunk - 1
  551.        
  552.         'Set the temp color
  553.        tempcolor = ChatTextBuffer(LoopC).color
  554.        
  555.         'Set the Y position to be used
  556.        y2 = Y - (LoopC * yOffset) + (Chunk * ChatBufferChunk * yOffset) - 32
  557.        
  558.         'Loop through each line if there are line breaks (vbCrLf)
  559.        Count = 0   'Counts the offset value we are on
  560.        If LenB(ChatTextBuffer(LoopC).Text) <> 0 Then  'Dont bother with empty strings
  561.            
  562.             'Loop through the characters
  563.            For j = 1 To Len(ChatTextBuffer(LoopC).Text)
  564.            
  565.                 'Convert the character to the ascii value
  566.                Ascii = Asc(Mid$(ChatTextBuffer(LoopC).Text, j, 1))
  567.                
  568.                 'tU and tV value (basically tU = BitmapXPosition / BitmapWidth, and height for tV)
  569.                Row = (Ascii - Font_Default.HeaderInfo.BaseCharOffset) \ Font_Default.RowPitch
  570.                 u = ((Ascii - Font_Default.HeaderInfo.BaseCharOffset) - (Row * Font_Default.RowPitch)) * Font_Default.ColFactor
  571.                 v = Row * Font_Default.RowFactor
  572.  
  573.                 ' ****** Rectangle | Top Left ******
  574.                With ChatVA(0 + (6 * Pos))
  575.                     .color = tempcolor
  576.                     .x = (x) + Count
  577.                     .Y = (y2)
  578.                     .tu = u
  579.                     .tv = v
  580.                     .RHW = 1
  581.                 End With
  582.                
  583.                 ' ****** Rectangle | Bottom Left ******
  584.                With ChatVA(1 + (6 * Pos))
  585.                     .color = tempcolor
  586.                     .x = (x) + Count
  587.                     .Y = (y2) + Font_Default.HeaderInfo.CellHeight
  588.                     .tu = u
  589.                     .tv = v + Font_Default.RowFactor
  590.                     .RHW = 1
  591.                 End With
  592.                
  593.                 ' ****** Rectangle | Bottom Right ******
  594.                With ChatVA(2 + (6 * Pos))
  595.                     .color = tempcolor
  596.                     .x = (x) + Count + Font_Default.HeaderInfo.CellWidth
  597.                     .Y = (y2) + Font_Default.HeaderInfo.CellHeight
  598.                     .tu = u + Font_Default.ColFactor
  599.                     .tv = v + Font_Default.RowFactor
  600.                     .RHW = 1
  601.                 End With
  602.                
  603.                
  604.                 'Triangle 2 (only one new vertice is needed)
  605.                ChatVA(3 + (6 * Pos)) = ChatVA(0 + (6 * Pos)) 'Top-left corner
  606.                
  607.                 ' ****** Rectangle | Top Right ******
  608.                With ChatVA(4 + (6 * Pos))
  609.                     .color = tempcolor
  610.                     .x = (x) + Count + Font_Default.HeaderInfo.CellWidth
  611.                     .Y = (y2)
  612.                     .tu = u + Font_Default.ColFactor
  613.                     .tv = v
  614.                     .RHW = 1
  615.                 End With
  616.  
  617.                 ChatVA(5 + (6 * Pos)) = ChatVA(2 + (6 * Pos))
  618.  
  619.                 'Update the character we are on
  620.                Pos = Pos + 1
  621.  
  622.                 'Shift over the the position to render the next character
  623.                Count = Count + Font_Default.HeaderInfo.CharWidth(Ascii)
  624.                
  625.                 'Check to reset the color
  626.                If ResetColor Then
  627.                     ResetColor = 0
  628.                     tempcolor = ChatTextBuffer(LoopC).color
  629.                 End If
  630.             Next
  631.         End If
  632.     Next LoopC
  633.        
  634.     If Not D3DDevice8 Is Nothing Then   'Make sure the D3DDevice exists - this will only return false if we received messages before it had time to load
  635.        Set ChatVBS = D3DDevice8.CreateVertexBuffer(FVF_Size * Pos * 6, 0, FVF, D3DPOOL_MANAGED)
  636.         D3DVertexBuffer8SetData ChatVBS, 0, FVF_Size * Pos * 6, 0, ChatVAS(0)
  637.         Set ChatVB = D3DDevice8.CreateVertexBuffer(FVF_Size * Pos * 6, 0, FVF, D3DPOOL_MANAGED)
  638.         D3DVertexBuffer8SetData ChatVB, 0, FVF_Size * Pos * 6, 0, ChatVA(0)
  639.     End If
  640.     Erase ChatVAS()
  641.     Erase ChatVA()
  642.    
  643. End Sub
  644.  
  645. Public Sub AddText(ByVal Text As String, ByVal tColor As Long, Optional ByVal alpha As Long = 255)
  646. Dim TempSplit() As String
  647. Dim TSLoop As Long
  648. Dim lastSpace As Long
  649. Dim size As Long
  650. Dim i As Long
  651. Dim b As Long
  652. Dim color As Long
  653.  
  654.     color = dx8Colour(tColor, alpha)
  655.  
  656.     'Check if there are any line breaks - if so, we will support them
  657.    TempSplit = Split(Text, vbCrLf)
  658.    
  659.     For TSLoop = 0 To UBound(TempSplit)
  660.    
  661.         'Clear the values for the new line
  662.        size = 0
  663.         b = 1
  664.         lastSpace = 1
  665.        
  666.         'Loop through all the characters
  667.        For i = 1 To Len(TempSplit(TSLoop))
  668.        
  669.             'If it is a space, store it so we can easily break at it
  670.            Select Case Mid$(TempSplit(TSLoop), i, 1)
  671.                 Case " ": lastSpace = i
  672.                 Case "_": lastSpace = i
  673.                 Case "-": lastSpace = i
  674.             End Select
  675.            
  676.             'Add up the size
  677.            size = size + Font_Default.HeaderInfo.CharWidth(Asc(Mid$(TempSplit(TSLoop), i, 1)))
  678.            
  679.             'Check for too large of a size
  680.            If size > ChatWidth Then
  681.                
  682.                 'Check if the last space was too far back
  683.                If i - lastSpace > 10 Then
  684.                
  685.                     'Too far away to the last space, so break at the last character
  686.                    AddToChatTextBuffer_Overflow Trim$(Mid$(TempSplit(TSLoop), b, (i - 1) - b)), color
  687.                     b = i - 1
  688.                     size = 0
  689.                 Else
  690.                     'Break at the last space to preserve the word
  691.                    AddToChatTextBuffer_Overflow Trim$(Mid$(TempSplit(TSLoop), b, lastSpace - b)), color
  692.                     b = lastSpace + 1
  693.                     'Count all the words we ignored (the ones that weren't printed, but are before "i")
  694.                    size = EngineGetTextWidth(Font_Default, Mid$(TempSplit(TSLoop), lastSpace, i - lastSpace))
  695.                 End If
  696.             End If
  697.            
  698.             'This handles the remainder
  699.            If i = Len(TempSplit(TSLoop)) Then
  700.                 If b <> i Then AddToChatTextBuffer_Overflow Mid$(TempSplit(TSLoop), b, i), color
  701.             End If
  702.         Next i
  703.     Next TSLoop
  704.    
  705.     'Only update if we have set up the text (that way we can add to the buffer before it is even made)
  706.    If Font_Default.RowPitch = 0 Then Exit Sub
  707.    
  708.     If ChatScroll > 8 Then ChatScroll = ChatScroll + 1
  709.  
  710.     'Update the array
  711.    UpdateChatArray
  712. End Sub
  713.  
  714. Private Sub AddToChatTextBuffer_Overflow(ByVal Text As String, ByVal color As Long)
  715. Dim LoopC As Long
  716.  
  717.     'Move all other text up
  718.    For LoopC = (ChatTextBufferSize - 1) To 1 Step -1
  719.         ChatTextBuffer(LoopC + 1) = ChatTextBuffer(LoopC)
  720.     Next LoopC
  721.    
  722.     'Set the values
  723.    ChatTextBuffer(1).Text = Text
  724.     ChatTextBuffer(1).color = color
  725.    
  726.     ' set the total chat lines
  727.    totalChatLines = totalChatLines + 1
  728.     If totalChatLines > ChatTextBufferSize - 1 Then totalChatLines = ChatTextBufferSize - 1
  729. End Sub
  730.  
  731. Public Sub WordWrap_Array(ByVal Text As String, ByVal MaxLineLen As Long, ByRef theArray() As String)
  732. Dim lineCount As Long, i As Long, size As Long, lastSpace As Long, b As Long
  733.    
  734.     'Too small of text
  735.    If Len(Text) < 2 Then
  736.         ReDim theArray(1 To 1) As String
  737.         theArray(1) = Text
  738.         Exit Sub
  739.     End If
  740.    
  741.     ' default values
  742.    b = 1
  743.     lastSpace = 1
  744.     size = 0
  745.    
  746.     For i = 1 To Len(Text)
  747.         ' if it's a space, store it
  748.        Select Case Mid$(Text, i, 1)
  749.             Case " ": lastSpace = i
  750.             Case "_": lastSpace = i
  751.             Case "-": lastSpace = i
  752.         End Select
  753.        
  754.         'Add up the size
  755.        size = size + Font_Default.HeaderInfo.CharWidth(Asc(Mid$(Text, i, 1)))
  756.        
  757.         'Check for too large of a size
  758.        If size > MaxLineLen Then
  759.             'Check if the last space was too far back
  760.            If i - lastSpace > 12 Then
  761.                 'Too far away to the last space, so break at the last character
  762.                lineCount = lineCount + 1
  763.                 ReDim Preserve theArray(1 To lineCount) As String
  764.                 theArray(lineCount) = Trim$(Mid$(Text, b, (i - 1) - b))
  765.                 b = i - 1
  766.                 size = 0
  767.             Else
  768.                 'Break at the last space to preserve the word
  769.                lineCount = lineCount + 1
  770.                 ReDim Preserve theArray(1 To lineCount) As String
  771.                 theArray(lineCount) = Trim$(Mid$(Text, b, lastSpace - b))
  772.                 b = lastSpace + 1
  773.                
  774.                 'Count all the words we ignored (the ones that weren't printed, but are before "i")
  775.                size = EngineGetTextWidth(Font_Default, Mid$(Text, lastSpace, i - lastSpace))
  776.             End If
  777.         End If
  778.        
  779.         ' Remainder
  780.        If i = Len(Text) Then
  781.             If b <> i Then
  782.                 lineCount = lineCount + 1
  783.                 ReDim Preserve theArray(1 To lineCount) As String
  784.                 theArray(lineCount) = theArray(lineCount) & Mid$(Text, b, i)
  785.             End If
  786.         End If
  787.     Next
  788. End Sub
  789.  
  790. Public Function WordWrap(ByVal Text As String, ByVal MaxLineLen As Integer) As String
  791. Dim TempSplit() As String
  792. Dim TSLoop As Long
  793. Dim lastSpace As Long
  794. Dim size As Long
  795. Dim i As Long
  796. Dim b As Long
  797.  
  798.     'Too small of text
  799.    If Len(Text) < 2 Then
  800.         WordWrap = Text
  801.         Exit Function
  802.     End If
  803.  
  804.     'Check if there are any line breaks - if so, we will support them
  805.    TempSplit = Split(Text, vbNewLine)
  806.    
  807.     For TSLoop = 0 To UBound(TempSplit)
  808.    
  809.         'Clear the values for the new line
  810.        size = 0
  811.         b = 1
  812.         lastSpace = 1
  813.        
  814.         'Add back in the vbNewLines
  815.        If TSLoop < UBound(TempSplit()) Then TempSplit(TSLoop) = TempSplit(TSLoop) & vbNewLine
  816.        
  817.         'Only check lines with a space
  818.        If InStr(1, TempSplit(TSLoop), " ") Or InStr(1, TempSplit(TSLoop), "-") Or InStr(1, TempSplit(TSLoop), "_") Then
  819.            
  820.             'Loop through all the characters
  821.            For i = 1 To Len(TempSplit(TSLoop))
  822.            
  823.                 'If it is a space, store it so we can easily break at it
  824.                Select Case Mid$(TempSplit(TSLoop), i, 1)
  825.                     Case " ": lastSpace = i
  826.                     Case "_": lastSpace = i
  827.                     Case "-": lastSpace = i
  828.                 End Select
  829.    
  830.                 'Add up the size
  831.                size = size + Font_Default.HeaderInfo.CharWidth(Asc(Mid$(TempSplit(TSLoop), i, 1)))
  832.  
  833.                 'Check for too large of a size
  834.                If size > MaxLineLen Then
  835.                     'Check if the last space was too far back
  836.                    If i - lastSpace > 12 Then
  837.                         'Too far away to the last space, so break at the last character
  838.                        WordWrap = WordWrap & Trim$(Mid$(TempSplit(TSLoop), b, (i - 1) - b)) & vbNewLine
  839.                         b = i - 1
  840.                         size = 0
  841.                     Else
  842.                         'Break at the last space to preserve the word
  843.                        WordWrap = WordWrap & Trim$(Mid$(TempSplit(TSLoop), b, lastSpace - b)) & vbNewLine
  844.                         b = lastSpace + 1
  845.                        
  846.                         'Count all the words we ignored (the ones that weren't printed, but are before "i")
  847.                        size = EngineGetTextWidth(Font_Default, Mid$(TempSplit(TSLoop), lastSpace, i - lastSpace))
  848.                     End If
  849.                 End If
  850.                
  851.                 'This handles the remainder
  852.                If i = Len(TempSplit(TSLoop)) Then
  853.                     If b <> i Then
  854.                         WordWrap = WordWrap & Mid$(TempSplit(TSLoop), b, i)
  855.                     End If
  856.                 End If
  857.             Next i
  858.         Else
  859.             WordWrap = WordWrap & TempSplit(TSLoop)
  860.         End If
  861.     Next TSLoop
  862. End Function
  863.  
  864. Public Sub UpdateShowChatText()
  865. Dim CHATOFFSET As Long, i As Long, x As Long
  866.  
  867.     CHATOFFSET = 52
  868.    
  869.     If EngineGetTextWidth(Font_Default, MyText) > GUIWindow(GUI_CHAT).Width - CHATOFFSET Then
  870.         For i = Len(MyText) To 1 Step -1
  871.             x = x + Font_Default.HeaderInfo.CharWidth(Asc(Mid$(MyText, i, 1)))
  872.             If x > GUIWindow(GUI_CHAT).Width - CHATOFFSET Then
  873.                 RenderChatText = Right$(MyText, Len(MyText) - i + 1)
  874.                 Exit For
  875.             End If
  876.         Next
  877.     Else
  878.         RenderChatText = MyText
  879.     End If
  880. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement