63 ChatReady: boolean; |
63 ChatReady: boolean; |
64 showAll: boolean; |
64 showAll: boolean; |
65 liveLua: boolean; |
65 liveLua: boolean; |
66 ChatHidden: boolean; |
66 ChatHidden: boolean; |
67 firstDraw: boolean; |
67 firstDraw: boolean; |
68 InputLinePrefix: shortstring; |
68 InputLinePrefix: TChatLine; |
69 // cursor |
69 // cursor |
70 cursorPos, cursorX, selectedPos, selectionDx: LongInt; |
70 cursorPos, cursorX, selectedPos, selectionDx: LongInt; |
71 LastKeyPressTick: LongWord; |
71 LastKeyPressTick: LongWord; |
|
72 |
72 |
73 |
73 const |
74 const |
74 InputStrLNoPred: byte = 255; |
75 InputStrLNoPred: byte = 255; |
75 |
76 |
76 colors: array[#0..#6] of TSDL_Color = ( |
77 colors: array[#0..#6] of TSDL_Color = ( |
110 if cursorPos = selectedPos then |
111 if cursorPos = selectedPos then |
111 ResetSelection(); |
112 ResetSelection(); |
112 |
113 |
113 // calculate cursor offset |
114 // calculate cursor offset |
114 |
115 |
115 str:= InputLinePrefix + InputStr.s; |
116 str:= InputStr.s; |
116 font:= CheckCJKFont(ansistring(str), fnt16); |
117 font:= CheckCJKFont(ansistring(str), fnt16); |
117 |
118 |
118 // get only substring before cursor to determine length |
119 // get only substring before cursor to determine length |
119 // SetLength(str, Length(InputLinePrefix) + cursorPos); // makes pas2c unhappy |
120 // SetLength(str, cursorPos); // makes pas2c unhappy |
120 str[0]:= char(Length(InputLinePrefix) + cursorPos); |
121 str[0]:= char(cursorPos); |
121 // get render size of text |
122 // get render size of text |
122 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @coff, nil); |
123 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @coff, nil); |
123 |
124 |
124 cursorX:= 2 + coff; |
125 cursorX:= 2 + coff; |
125 |
126 |
126 // calculate selection width on screen |
127 // calculate selection width on screen |
127 if selectedPos >= 0 then |
128 if selectedPos >= 0 then |
128 begin |
129 begin |
129 if selectedPos > cursorPos then |
130 if selectedPos > cursorPos then |
130 str:= InputLinePrefix + InputStr.s; |
131 str:= InputStr.s; |
131 // SetLength(str, Length(InputLinePrefix) + selectedPos); // makes pas2c unhappy |
132 // SetLength(str, selectedPos); // makes pas2c unhappy |
132 str[0]:= char(Length(InputLinePrefix) + selectedPos); |
133 str[0]:= char(selectedPos); |
133 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @soff, nil); |
134 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @soff, nil); |
134 selectionDx:= soff - coff; |
135 selectionDx:= soff - coff; |
135 end |
136 end |
136 else |
137 else |
137 selectionDx:= 0; |
138 selectionDx:= 0; |
251 inc(visibleCount) |
251 inc(visibleCount) |
252 end; |
252 end; |
253 |
253 |
254 procedure CheckPasteBuffer(); forward; |
254 procedure CheckPasteBuffer(); forward; |
255 |
255 |
|
256 procedure UpdateInputLinePrefix(); |
|
257 begin |
|
258 if liveLua then |
|
259 begin |
|
260 InputLinePrefix.color:= colors[#1]; |
|
261 InputLinePrefix.s:= '[Lua] >'; |
|
262 end |
|
263 else |
|
264 begin |
|
265 InputLinePrefix.color:= colors[#6]; |
|
266 InputLinePrefix.s:= UserNick + '>'; |
|
267 end; |
|
268 |
|
269 FreeAndNilTexture(InputLinePrefix.Tex); |
|
270 end; |
|
271 |
256 procedure DrawChat; |
272 procedure DrawChat; |
257 var i, t, left, top, cnt: LongInt; |
273 var i, t, left, top, cnt: LongInt; |
258 selRect: TSDL_Rect; |
274 selRect: TSDL_Rect; |
259 begin |
275 begin |
260 ChatReady:= true; // maybe move to somewhere else? |
276 ChatReady:= true; // maybe move to somewhere else? |
269 // draw chat input line first and under all other lines |
285 // draw chat input line first and under all other lines |
270 if (GameState = gsChat) and (InputStr.Tex <> nil) then |
286 if (GameState = gsChat) and (InputStr.Tex <> nil) then |
271 begin |
287 begin |
272 CheckPasteBuffer(); |
288 CheckPasteBuffer(); |
273 |
289 |
|
290 if InputLinePrefix.Tex = nil then |
|
291 RenderChatLineTex(InputLinePrefix, InputLinePrefix.s); |
|
292 |
|
293 DrawTexture(left, top, InputLinePrefix.Tex); |
|
294 inc(left, InputLinePrefix.Width); |
|
295 DrawTexture(left, top, InputStr.Tex); |
|
296 |
274 if firstDraw then |
297 if firstDraw then |
275 begin |
298 begin |
276 UpdateCursorCoords(); |
299 UpdateCursorCoords(); |
277 firstDraw:= false; |
300 firstDraw:= false; |
278 end; |
301 end; |
279 |
302 |
280 DrawTexture(left, top, InputStr.Tex); |
|
281 if selectedPos < 0 then |
303 if selectedPos < 0 then |
282 begin |
304 begin |
283 // draw cursor |
305 // draw cursor |
284 if ((RealTicks - LastKeyPressTick) and 512) < 256 then |
306 if ((RealTicks - LastKeyPressTick) and 512) < 256 then |
285 DrawLineOnScreen(left + cursorX, top + 2, left + cursorX, top + ClHeight - 2, 2.0, $00, $FF, $FF, $FF); |
307 DrawLineOnScreen(left + cursorX, top + 2, left + cursorX, top + ClHeight - 2, 2.0, $00, $FF, $FF, $FF); |
299 selRect.w:= selectionDx; |
321 selRect.w:= selectionDx; |
300 end; |
322 end; |
301 |
323 |
302 DrawRect(selRect, $FF, $FF, $FF, $40, true); |
324 DrawRect(selRect, $FF, $FF, $FF, $40, true); |
303 end; |
325 end; |
|
326 |
|
327 dec(left, InputLinePrefix.Width); |
304 end; |
328 end; |
305 |
|
306 |
329 |
307 // draw chat lines |
330 // draw chat lines |
308 if ((not ChatHidden) or showAll) and (UIDisplay <> uiNone) then |
331 if ((not ChatHidden) or showAll) and (UIDisplay <> uiNone) then |
309 begin |
332 begin |
310 if MissedCount <> 0 then // there are chat strings we missed, so print them now |
333 if MissedCount <> 0 then // there are chat strings we missed, so print them now |