branch | sdl2transition |
changeset 11360 | 7a7611adf715 |
parent 9798 | f2b18754742f |
child 11362 | ed5a6478e710 |
9798:f2b18754742f | 11360:7a7611adf715 |
---|---|
29 procedure CleanupInput; |
29 procedure CleanupInput; |
30 procedure AddChatString(s: shortstring); |
30 procedure AddChatString(s: shortstring); |
31 procedure DrawChat; |
31 procedure DrawChat; |
32 procedure SendHogSpeech(s: shortstring); |
32 procedure SendHogSpeech(s: shortstring); |
33 |
33 |
34 {$IFDEF SDL2} |
|
35 procedure KeyPressChat(Sym: Longword); |
34 procedure KeyPressChat(Sym: Longword); |
36 procedure TextInput(var event: TSDL_TextInputEvent); |
35 procedure TextInput(var event: TSDL_TextInputEvent); |
37 {$ELSE} |
|
38 procedure KeyPressChat(Key, Sym: Longword); |
|
39 {$ENDIF} |
|
40 |
36 |
41 implementation |
37 implementation |
42 uses uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO; |
38 uses uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO; |
43 |
39 |
44 const MaxStrIndex = 27; |
40 const MaxStrIndex = 27; |
314 |
310 |
315 procedure CleanupInput; |
311 procedure CleanupInput; |
316 begin |
312 begin |
317 FreezeEnterKey; |
313 FreezeEnterKey; |
318 history:= 0; |
314 history:= 0; |
319 {$IFDEF SDL2} |
|
320 SDL_StopTextInput(); |
315 SDL_StopTextInput(); |
321 {$ELSE} |
|
322 SDL_EnableKeyRepeat(0,0); |
|
323 {$ENDIF} |
|
324 GameState:= gsGame; |
316 GameState:= gsGame; |
325 ResetKbd; |
317 ResetKbd; |
326 end; |
318 end; |
327 |
319 |
328 {$IFDEF SDL2} |
|
329 procedure TextInput(var event: TSDL_TextInputEvent); |
320 procedure TextInput(var event: TSDL_TextInputEvent); |
330 var s: shortstring; |
321 var s: shortstring; |
331 l: byte; |
322 l: byte; |
332 begin |
323 begin |
333 l:= 0; |
324 l:= 0; |
343 InputStrL[byte(InputStr.s[0]) + l]:= InputStr.s[0]; |
334 InputStrL[byte(InputStr.s[0]) + l]:= InputStr.s[0]; |
344 SetLine(InputStr, InputStr.s + s, true) |
335 SetLine(InputStr, InputStr.s + s, true) |
345 end; |
336 end; |
346 |
337 |
347 procedure KeyPressChat(Sym: Longword); |
338 procedure KeyPressChat(Sym: Longword); |
348 {$ELSE} |
|
349 procedure KeyPressChat(Key, Sym: Longword); |
|
350 {$ENDIF} |
|
351 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
339 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
352 var i, btw, index: integer; |
340 var i, btw, index: integer; |
353 utf8: shortstring; |
341 utf8: shortstring; |
354 action: boolean; |
342 action: boolean; |
355 begin |
343 begin |
395 end; |
383 end; |
396 else |
384 else |
397 action:= false; |
385 action:= false; |
398 end; |
386 end; |
399 |
387 |
400 {$IFNDEF SDL2} |
|
401 if not action and (Key <> 0) then |
|
402 begin |
|
403 if (Key < $80) then |
|
404 btw:= 1 |
|
405 else if (Key < $800) then |
|
406 btw:= 2 |
|
407 else if (Key < $10000) then |
|
408 btw:= 3 |
|
409 else |
|
410 btw:= 4; |
|
411 |
|
412 utf8:= ''; |
|
413 |
|
414 for i:= btw downto 2 do |
|
415 begin |
|
416 utf8:= char((Key or $80) and $BF) + utf8; |
|
417 Key:= Key shr 6 |
|
418 end; |
|
419 |
|
420 utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8; |
|
421 |
|
422 if byte(InputStr.s[0]) + btw > 240 then |
|
423 exit; |
|
424 |
|
425 InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0]; |
|
426 SetLine(InputStr, InputStr.s + utf8, true) |
|
427 end |
|
428 {$ENDIF} |
|
429 end; |
388 end; |
430 |
389 |
431 procedure chChatMessage(var s: shortstring); |
390 procedure chChatMessage(var s: shortstring); |
432 begin |
391 begin |
433 AddChatString(s) |
392 AddChatString(s) |
466 |
425 |
467 procedure chChat(var s: shortstring); |
426 procedure chChat(var s: shortstring); |
468 begin |
427 begin |
469 s:= s; // avoid compiler hint |
428 s:= s; // avoid compiler hint |
470 GameState:= gsChat; |
429 GameState:= gsChat; |
471 {$IFDEF SDL2} |
|
472 SDL_StartTextInput(); |
430 SDL_StartTextInput(); |
473 {$ELSE} |
|
474 SDL_EnableKeyRepeat(200,45); |
|
475 {$ENDIF} |
|
476 if length(s) = 0 then |
431 if length(s) = 0 then |
477 SetLine(InputStr, '', true) |
432 SetLine(InputStr, '', true) |
478 else |
433 else |
479 SetLine(InputStr, '/team ', true) |
434 SetLine(InputStr, '/team ', true) |
480 end; |
435 end; |