Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

CrystalShire Bubble Chat on EO 2.0


Mondo
 Share

Recommended Posts

  • Replies 108
  • Created
  • Last Reply

Top Posters In This Topic

@Erwin:

> It looks like something that can be fixed by using Trim$ a few times, but I'm not sure that will work.

Yeah the problem really is that the text width is "calculated" by guess estimating the pixel sizes of each letter, so you calculate the bubble size to be say 150 pixels, but the reality is that your text is only 100 pixels long (o's being wider that i's). And since the text is placed on the left border of the bubble you get 50 pixels of air.

I've been thinking to fix it, just never came around it.

The magic will happen at:

```
                ' render each line centralised
                y = y - (yheight - 5)
                For i = 1 To UBound(theArray)
                    DrawTextNoShadow TexthDC, x - (xwidth - 10), y, theArray(i), QBColor(Black) ' .colour
                    y = y + 12
                Next

```
I just need to figure out how to better calculate x - (xwidth - 10).
Link to comment
Share on other sites

Smtn works

```
                ' render each line centralised
                Y = Y - (yheight - 5)
                For i = 1 To UBound(theArray)
                    DrawTextNoShadow TexthDC, x - (xwidth - (x / xwidth)), Y, theArray(i), QBColor(Black)  ' .colour
                    Y = Y + 12
                Next

```
P.S. _**THIS WORKS ONLY WITH ~ 5+ LETTERS!**_ :(
Link to comment
Share on other sites

@Domino_:

> Smtn works
>
> ```
>                 ' render each line centralised
>                 Y = Y - (yheight - 5)
>                 For i = 1 To UBound(theArray)
>                     DrawTextNoShadow TexthDC, x - (xwidth - (x / xwidth)), Y, theArray(i), QBColor(Black)  ' .colour
>                     Y = Y + 12
>                 Next
>
> ```
> P.S. _**THIS WORKS ONLY WITH ~ 5+ LETTERS!**_ :(

Its a bit more complicated than that, you need to calculate the TextDC width, and then half that and substract that amount from the bubble's xwidth divided by half… or something fo the sort... ;)

I'll review it tonight after work.
Link to comment
Share on other sites

@Lumiere:

> Uhm when i write something and press enter the game closes,there is no error ,weird.

It did that to me once, the game closes when its broken in a routine that has no error handler…

When it happened to me it was that my game didn't know how to handle the server message to open a bubble... So it could be somewhere in handlechatbubble routine or the declarations of the SChatBubble in the serverpackets.
Link to comment
Share on other sites

@Mondo:

> It did that to me once, the game closes when its broken in a routine that has no error handler…
>
> When it happened to me it was that my game didn't know how to handle the server message to open a bubble... So it could be somewhere in handlechatbubble routine or the declarations of the SChatBubble in the serverpackets.

Oh dummy me,fixed ^^ thanksie
Link to comment
Share on other sites

Ok this is the corrected DrawChatBubble routine, it does center now.

```
' CHAT BUBBLE HACK
Public Sub DrawChatBubble(ByVal Index As Long)
Dim theArray() As String, x As Long, Y As Long, i As Long, MaxWidth As Long, xwidth As Long, yheight As Long, colour As Long, x3 As Long, y3 As Long

Dim MMx As Long
Dim MMy As Long

Dim TOPLEFTrect As RECT
Dim TOPCENTERrect As RECT
Dim TOPRIGHTrect As RECT
Dim MIDDLELEFTrect As RECT
Dim MIDDLECENTERrect As RECT
Dim MIDDLERIGHTrect As RECT
Dim BOTTOMLEFTrect As RECT
Dim BOTTOMCENTERrect As RECT
Dim BOTTOMRIGHTrect As RECT
Dim TIPrect As RECT

' DESIGNATE CHATBUBBLE SECTIONS FROM CHATBUBBLE IMAGE
With TOPRIGHTrect
    .top = 0
    .Bottom = .top + 4
    .Left = 0
    .Right = .Left + 4
End With

With TOPCENTERrect
    .top = 0
    .Bottom = .top + 4
    .Left = 4
    .Right = .Left + 4
End With

With TOPLEFTrect
    .top = 0
    .Bottom = .top + 4
    .Left = 8
    .Right = .Left + 4
End With

With MIDDLERIGHTrect
    .top = 4
    .Bottom = .top + 4
    .Left = 0
    .Right = .Left + 4
End With

With MIDDLECENTERrect
    .top = 4
    .Bottom = .top + 4
    .Left = 4
    .Right = .Left + 4
End With

With MIDDLELEFTrect
    .top = 4
    .Bottom = .top + 4
    .Left = 8
    .Right = .Left + 4
End With

With BOTTOMRIGHTrect
    .top = 8
    .Bottom = .top + 4
    .Left = 0
    .Right = .Left + 4
End With

With BOTTOMCENTERrect
    .top = 8
    .Bottom = .top + 4
    .Left = 4
    .Right = .Left + 4
End With

With BOTTOMLEFTrect
    .top = 8
    .Bottom = .top + 4
    .Left = 8
    .Right = .Left + 4
End With

With TIPrect
    .top = 12
    .Bottom = .top + 4
    .Left = 0
    .Right = .Left + 4
End With

    Call DDS_BackBuffer.SetForeColor(RGB(255, 255, 255))

    With chatBubble(Index)
        If .targetType = TARGET_TYPE_PLAYER Then
            ' it's a player
            If GetPlayerMap(.target) = GetPlayerMap(MyIndex) Then
                ' change the colour depending on access
                colour = QBColor(Yellow)

                ' it's on our map - get co-ords
                x = ConvertMapX((Player(.target).x * 32) + Player(.target).XOffset) + 16
                Y = ConvertMapY((Player(.target).Y * 32) + Player(.target).YOffset) - 16

                ' word wrap the text
                WordWrap_Array .Msg, ChatBubbleWidth, theArray

                ' find max width
                For i = 1 To UBound(theArray)
                    If getWidth(TexthDC, theArray(i)) > MaxWidth Then MaxWidth = getWidth(TexthDC, theArray(i))
                Next

                ' calculate the new position xwidth relative to DDS_ChatBubble and yheight relative to DDS_ChatBubble
                xwidth = 10 + MaxWidth ' the first five is just air.
                yheight = 3 + (UBound(theArray) * 7) ' the first three are just air.

                ' Compensate the yheight drift
                Y = Y - yheight

                ' render bubble

                ' top left
                ' RenderTexture Tex_GUI(37), xwidth - 9, yheight - 5, 0, 0, 9, 5, 9, 5
                Call Engine_BltFast(x + (xwidth + 4), Y - (yheight - 4), DDS_ChatBubble, TOPLEFTrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

                ' top center
                ' RenderTexture Tex_GUI(37), xwidth + MaxWidth, yheight - 5, 119, 0, 9, 5, 9, 5
                For x3 = x - (xwidth - 8) To x + (xwidth)
                    Call Engine_BltFast(x3, Y - (yheight - 4), DDS_ChatBubble, TOPCENTERrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
                Next x3

                ' top right
                ' RenderTexture Tex_GUI(37), xwidth, yheight - 5, 9, 0, MaxWidth, 5, 5, 5
                Call Engine_BltFast(x - (xwidth - 4), Y - (yheight - 4), DDS_ChatBubble, TOPRIGHTrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

                ' middle left
                ' RenderTexture Tex_GUI(37), xwidth - 9, y, 0, 19, 9, 6, 9, 6
                For y3 = Y - (yheight - 8) To Y + (yheight)
                    Call Engine_BltFast(x + (xwidth + 4), y3, DDS_ChatBubble, MIDDLELEFTrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
                Next y3

                ' middle center
                ' RenderTexture Tex_GUI(37), xwidth + MaxWidth, y, 119, 19, 9, 6, 9, 6
                For y3 = Y - (yheight - 8) To Y + (yheight)
                    For x3 = x - (xwidth - 8) To x + (xwidth)
                        Call Engine_BltFast(x3, y3, DDS_ChatBubble, MIDDLECENTERrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
                    Next x3
                Next y3

                ' middle right
                ' RenderTexture Tex_GUI(37), xwidth, y, 9, 19, (MaxWidth \ 2) - 5, 6, 9, 6
                For y3 = Y - (yheight - 8) To Y + (yheight)
                    Call Engine_BltFast(x - (xwidth - 4), y3, DDS_ChatBubble, MIDDLERIGHTrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
                Next y3

                ' bottom left
                ' RenderTexture Tex_GUI(37), xwidth + (MaxWidth \ 2) + 6, y, 9, 19, (MaxWidth \ 2) - 5, 6, 9, 6
                Call Engine_BltFast(x + (xwidth + 4), Y + (yheight + 4), DDS_ChatBubble, BOTTOMLEFTrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

                ' bottom center
                ' RenderTexture Tex_GUI(37), xwidth - 9, yheight, 0, 6, 9, (UBound(theArray) * 12), 9, 1
                For x3 = x - (xwidth - 8) To x + (xwidth)
                    Call Engine_BltFast(x3, Y + (yheight + 4), DDS_ChatBubble, BOTTOMCENTERrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
                Next x3

                ' bottom right
                ' RenderTexture Tex_GUI(37), xwidth + MaxWidth, yheight, 119, 6, 9, (UBound(theArray) * 12), 9, 1
                Call Engine_BltFast(x - (xwidth - 4), Y + (yheight + 4), DDS_ChatBubble, BOTTOMRIGHTrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

                ' little pointy bit
                ' RenderTexture Tex_GUI(37), x - 5, y, 58, 19, 11, 11, 11, 11
                Call Engine_BltFast(x, Y + (yheight + 8), DDS_ChatBubble, TIPrect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)

                ' Lock the backbuffer so we can draw text and names
                TexthDC = DDS_BackBuffer.GetDC

                ' render each line centralised
                Y = Y - (yheight - 5)
                For i = 1 To UBound(theArray)
                    DrawTextNoShadow TexthDC, x - (getWidth(TexthDC, theArray(i)) - 10), Y, theArray(i), QBColor(Black) ' .colour
                    Y = Y + 12
                Next

                ' Release DC
                DDS_BackBuffer.ReleaseDC TexthDC

            End If
        End If

        ' check if it's timed out - close it if so
        If .Timer + 5000 < GetTickCount Then
            .active = False
        End If
    End With
End Sub
' CHAT BUBBLE HACK
```
The real change was only to call the old getwidth function, passing the texthdc and the message as parameters and it gets you back the real size, no guesstimating anymore.

Try it out…
Link to comment
Share on other sites

Very good,thank you ^.^
But is not really centered,tell me where to change some numbers and such to fit?
Because the text is more to the right side
![](http://s15.postimage.org/f0fjueqfv/hppl.png)
Link to comment
Share on other sites

@DarkDino:

> I dont added chat channels :/

Then do again the tutorial ,instead waiting for answers,is not so long,try again! ;)
Link to comment
Share on other sites

@Lumiere:

> Very good,thank you ^.^
> But is not really centered,tell me where to change some numbers and such to fit?
> Because the text is more to the right side
> ![](http://s15.postimage.org/f0fjueqfv/hppl.png)

Bump on this problem.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...