33 const MaxStrIndex = 27; |
33 const MaxStrIndex = 27; |
34 |
34 |
35 type TChatLine = record |
35 type TChatLine = record |
36 s: shortstring; |
36 s: shortstring; |
37 Time: Longword; |
37 Time: Longword; |
38 Tex: PTexture; |
38 Texb, Texf: PTexture; |
39 end; |
39 end; |
40 |
40 |
41 var Strs: array[0 .. MaxStrIndex] of TChatLine; |
41 var Strs: array[0 .. MaxStrIndex] of TChatLine; |
42 lastStr: Longword = 0; |
42 lastStr: Longword = 0; |
43 visibleCount: Longword = 0; |
43 visibleCount: Longword = 0; |
44 |
44 |
45 InputStr: TChatLine; |
45 InputStr: TChatLine; |
46 InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char |
46 InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char |
47 |
47 |
48 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean); |
48 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean); |
49 var strSurface, resSurface: PSDL_Surface; |
49 var surf: PSDL_Surface; |
50 r: TSDL_Rect; |
|
51 w, h: LongInt; |
|
52 begin |
50 begin |
53 if cl.Tex <> nil then |
51 if cl.Texb <> nil then |
54 FreeTexture(cl.Tex); |
52 begin |
|
53 FreeTexture(cl.Texb); |
|
54 FreeTexture(cl.Texf) |
|
55 end; |
55 |
56 |
56 cl.s:= str; |
57 cl.s:= str; |
57 |
58 |
58 if isInput then str:= UserNick + '> ' + str + '_'; |
59 if isInput then str:= UserNick + '> ' + str + '_'; |
59 |
60 |
60 TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(str), w, h); |
61 cl.Time:= RealTicks + 12500; |
61 |
62 |
62 resSurface:= SDL_CreateRGBSurface(0, |
63 TryDo(str <> '', 'Error: null chat string', true); |
63 toPowerOf2(w + 2), |
|
64 toPowerOf2(h + 2), |
|
65 32, |
|
66 RMask, GMask, BMask, AMask); |
|
67 |
64 |
68 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $202020); |
65 surf:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $202020); |
69 r.x:= 1; |
66 surf:= SDL_DisplayFormatAlpha(surf); |
70 r.y:= 1; |
67 TryDo(surf <> nil, 'Chat: fail to render string', true); |
71 SDL_UpperBlit(strSurface, nil, resSurface, @r); |
68 cl.Texb:= Surface2Tex(surf); |
|
69 SDL_FreeSurface(surf); |
72 |
70 |
73 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF); |
71 surf:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF); |
74 SDL_UpperBlit(strSurface, nil, resSurface, nil); |
72 surf:= SDL_DisplayFormatAlpha(surf); |
75 |
73 TryDo(surf <> nil, 'Chat: fail to render string', true); |
76 SDL_FreeSurface(strSurface); |
74 cl.Texf:= Surface2Tex(surf); |
77 |
75 SDL_FreeSurface(surf) |
78 cl.Time:= RealTicks + 12500; |
|
79 cl.Tex:= Surface2Tex(resSurface); |
|
80 SDL_FreeSurface(resSurface) |
|
81 end; |
76 end; |
82 |
77 |
83 procedure AddChatString(s: shortstring); |
78 procedure AddChatString(s: shortstring); |
84 begin |
79 begin |
85 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1); |
80 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1); |
100 ((t < 7) and (Strs[i].Time > RealTicks)) |
96 ((t < 7) and (Strs[i].Time > RealTicks)) |
101 or |
97 or |
102 ((t < MaxStrIndex) and showAll) |
98 ((t < MaxStrIndex) and showAll) |
103 ) |
99 ) |
104 and |
100 and |
105 (Strs[i].Tex <> nil) do |
101 (Strs[i].Texb <> nil) do |
106 begin |
102 begin |
107 DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Tex); |
103 DrawTexture(8 + shift, (visibleCount - t) * 16 - 6 + shift, Strs[i].Texb); |
|
104 DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Texf); |
108 if i = 0 then i:= MaxStrIndex else dec(i); |
105 if i = 0 then i:= MaxStrIndex else dec(i); |
109 inc(cnt); |
106 inc(cnt); |
110 inc(t) |
107 inc(t) |
111 end; |
108 end; |
112 |
109 |
113 visibleCount:= cnt; |
110 visibleCount:= cnt; |
114 |
111 |
115 if (GameState = gsChat) |
112 if (GameState = gsChat) |
116 and (InputStr.Tex <> nil) then |
113 and (InputStr.Texb <> nil) then |
117 DrawTexture(8, visibleCount * 16 + 10, InputStr.Tex); |
114 begin |
|
115 DrawTexture(8 + shift, visibleCount * 16 + 10 + shift, InputStr.Texb); |
|
116 DrawTexture(8, visibleCount * 16 + 10, InputStr.Texf) |
|
117 end |
118 end; |
118 end; |
119 |
119 |
120 procedure AcceptChatString(s: shortstring); |
120 procedure AcceptChatString(s: shortstring); |
121 var i: TWave; |
121 var i: TWave; |
122 begin |
122 begin |