1 (* |
1 (* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
66 cursorPos, cursorX, selectedPos, selectionDx: LongInt; |
66 cursorPos, cursorX, selectedPos, selectionDx: LongInt; |
67 LastKeyPressTick: LongWord; |
67 LastKeyPressTick: LongWord; |
68 |
68 |
69 |
69 |
70 const |
70 const |
71 colors: array[#0..#6] of TSDL_Color = ( |
71 colors: array[#0..#9] of TSDL_Color = ( |
72 (r:$FF; g:$FF; b:$FF; a:$FF), // unused, feel free to take it for anything |
72 (r:$FF; g:$FF; b:$FF; a:$FF), // #0 unused, feel free to take it for anything |
73 (r:$FF; g:$FF; b:$FF; a:$FF), // chat message [White] |
73 (r:$FF; g:$FF; b:$FF; a:$FF), // #1 chat message [White] |
74 (r:$FF; g:$00; b:$FF; a:$FF), // action message [Purple] |
74 (r:$FF; g:$00; b:$FF; a:$FF), // #2 action message [Purple] |
75 (r:$90; g:$FF; b:$90; a:$FF), // join/leave message [Lime] |
75 (r:$90; g:$FF; b:$90; a:$FF), // #3 join/leave message [Lime] |
76 (r:$FF; g:$FF; b:$A0; a:$FF), // team message [Light Yellow] |
76 (r:$FF; g:$FF; b:$A0; a:$FF), // #4 team message [Light Yellow] |
77 (r:$FF; g:$00; b:$00; a:$FF), // error messages [Red] |
77 (r:$FF; g:$00; b:$00; a:$FF), // #5 error messages [Red] |
78 (r:$00; g:$FF; b:$FF; a:$FF) // input line [Light Blue] |
78 (r:$00; g:$FF; b:$FF; a:$FF), // #6 input line [Light Blue] |
|
79 (r:$FF; g:$80; b:$80; a:$FF), // #7 team gone [Light Red] |
|
80 (r:$FF; g:$D0; b:$80; a:$FF), // #8 team back [Light Orange] |
|
81 (r:$DF; g:$DF; b:$DF; a:$FF) // #9 hog speech [Light Gray] |
79 ); |
82 ); |
80 ChatCommandz: array [TChatCmd] of record |
83 ChatCommandz: array [TChatCmd] of record |
81 ChatCmd: string[31]; |
84 ChatCmd: string[31]; |
82 ProcedureCallChatCmd: string[31]; |
85 ProcedureCallChatCmd: string[31]; |
83 end = ( |
86 end = ( |
150 ResetSelection(); |
153 ResetSelection(); |
151 cursorPos:= 0; |
154 cursorPos:= 0; |
152 UpdateCursorCoords(); |
155 UpdateCursorCoords(); |
153 end; |
156 end; |
154 |
157 |
|
158 (* This procedure [re]renders a texture showing str for the chat line cl. |
|
159 * It will use the color stored in cl and update width |
|
160 *) |
155 procedure RenderChatLineTex(var cl: TChatLine; var str: shortstring); |
161 procedure RenderChatLineTex(var cl: TChatLine; var str: shortstring); |
156 var strSurface, |
162 var strSurface, |
157 resSurface: PSDL_Surface; |
163 resSurface: PSDL_Surface; |
158 dstrect : TSDL_Rect; // destination rectangle for blitting |
164 dstrect : TSDL_Rect; // destination rectangle for blitting |
159 font : THWFont; |
165 font : THWFont; |
160 const |
166 const |
161 shadowint = $80 shl AShift; |
167 shadowint = $80 shl AShift; |
162 begin |
168 begin |
163 |
169 |
|
170 FreeAndNilTexture(cl.Tex); |
|
171 |
164 font:= CheckCJKFont(ansistring(str), fnt16); |
172 font:= CheckCJKFont(ansistring(str), fnt16); |
165 |
173 |
166 // get render size of text |
174 // get render size of text |
167 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @cl.Width, nil); |
175 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @cl.Width, nil); |
168 |
176 |
230 cl.Time:= RealTicks + ClDisplayDuration; |
235 cl.Time:= RealTicks + ClDisplayDuration; |
231 end; |
236 end; |
232 |
237 |
233 // For uStore texture recreation |
238 // For uStore texture recreation |
234 procedure ReloadLines; |
239 procedure ReloadLines; |
235 var i, t: LongWord; |
240 var i: LongWord; |
236 begin |
241 begin |
237 if InputStr.s <> '' then |
242 if InputStr.s <> '' then |
238 SetLine(InputStr, InputStr.s, true); |
243 SetLine(InputStr, InputStr.s, true); |
239 for i:= 0 to MaxStrIndex do |
244 for i:= 0 to MaxStrIndex do |
240 if Strs[i].s <> '' then |
245 if Strs[i].s <> '' then |
241 begin |
246 begin |
242 t:= Strs[i].Time; |
247 RenderChatLineTex(Strs[i], Strs[i].s); |
243 SetLine(Strs[i], Strs[i].s, false); |
|
244 Strs[i].Time:= t |
|
245 end; |
248 end; |
246 end; |
249 end; |
247 |
250 |
248 procedure AddChatString(s: shortstring); |
251 procedure AddChatString(s: shortstring); |
249 begin |
252 begin |
792 end; |
795 end; |
793 end; |
796 end; |
794 |
797 |
795 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
798 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
796 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
799 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
|
800 nonStateMask = (not (KMOD_NUM or KMOD_CAPS)); |
797 var i, btw, index: integer; |
801 var i, btw, index: integer; |
798 utf8: shortstring; |
802 utf8: shortstring; |
799 action, selMode, ctrl: boolean; |
803 action, selMode, ctrl, ctrlonly: boolean; |
800 skip: TCharSkip; |
804 skip: TCharSkip; |
801 begin |
805 begin |
802 LastKeyPressTick:= RealTicks; |
806 LastKeyPressTick:= RealTicks; |
803 action:= true; |
807 action:= true; |
804 |
808 |
805 CheckPasteBuffer(); |
809 CheckPasteBuffer(); |
806 |
810 |
807 selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0; |
811 selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0; |
808 ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0; |
812 ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0; |
|
813 ctrlonly:= ctrl and ((modifier and nonStateMask and (not (KMOD_LCTRL or KMOD_RCTRL))) = 0); |
809 skip:= none; |
814 skip:= none; |
810 |
815 |
811 case Sym of |
816 case Sym of |
812 SDLK_BACKSPACE: |
817 SDLK_BACKSPACE: |
813 begin |
818 begin |