author | koda |
Sat, 26 Jun 2010 04:36:28 +0200 | |
changeset 3556 | 4bdc59101ce5 |
parent 3539 | c3d1fccbe0ed |
child 3676 | fa29572fa56a |
permissions | -rw-r--r-- |
942 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
942 | 3 |
* Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 |
* |
|
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 |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
942 | 21 |
unit uChat; |
22 |
||
23 |
interface |
|
24 |
||
3038 | 25 |
procedure initModule; |
26 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
27 |
|
942 | 28 |
procedure AddChatString(s: shortstring); |
29 |
procedure DrawChat; |
|
946 | 30 |
procedure KeyPressChat(Key: Longword); |
942 | 31 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
32 |
var UserNick: shortstring; |
3539 | 33 |
ChatReady: boolean; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
34 |
showAll: boolean; |
949 | 35 |
|
942 | 36 |
implementation |
1035 | 37 |
uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys, uTeams; |
942 | 38 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
39 |
const MaxStrIndex = 27; |
942 | 40 |
|
946 | 41 |
type TChatLine = record |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
42 |
Tex: PTexture; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
43 |
Time: Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
44 |
Width: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
45 |
s: shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
46 |
end; |
942 | 47 |
|
946 | 48 |
var Strs: array[0 .. MaxStrIndex] of TChatLine; |
3539 | 49 |
MStrs: array[0 .. MaxStrIndex] of shortstring; |
50 |
missedCount: LongWord; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
51 |
lastStr: LongWord; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
52 |
visibleCount: LongWord; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
53 |
InputStr: TChatLine; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
54 |
InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char |
942 | 55 |
|
3539 | 56 |
const colors: array[#1..#5] of TSDL_Color = ( |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
57 |
(r:$FF; g:$FF; b:$FF; unused:$FF), // chat message [White] |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
58 |
(r:$FF; g:$00; b:$FF; unused:$FF), // action message [Purple] |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
59 |
(r:$90; g:$FF; b:$90; unused:$FF), // join/leave message [Lime] |
3539 | 60 |
(r:$FF; g:$FF; b:$A0; unused:$FF), // team message [Light Yellow] |
61 |
(r:$FF; g:$00; b:$00; unused:$ff) // error messages [Red] |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
62 |
); |
2396 | 63 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
64 |
procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean); |
1118 | 65 |
var strSurface, resSurface: PSDL_Surface; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
66 |
w, h: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
67 |
color: TSDL_Color; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2664
diff
changeset
|
68 |
font: THWFont; |
942 | 69 |
begin |
1118 | 70 |
if cl.Tex <> nil then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
71 |
FreeTexture(cl.Tex); |
942 | 72 |
|
2396 | 73 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
74 |
cl.s:= str; |
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
75 |
|
2396 | 76 |
if isInput then |
2664
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
77 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
78 |
// [Light Blue] |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
79 |
color.r:= $00; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
80 |
color.g:= $FF; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
81 |
color.b:= $FF; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
82 |
color.unused:= $FF; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
83 |
str:= UserNick + '> ' + str + '_' |
2664
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
84 |
end |
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
85 |
else |
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
86 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
87 |
color:= colors[str[1]]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
88 |
delete(str, 1, 1) |
2664
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
89 |
end; |
2396 | 90 |
|
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2664
diff
changeset
|
91 |
font:= CheckCJKFont(str, fnt16); |
3407 | 92 |
w:= 0; h:= 0; // avoid compiler hints |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2664
diff
changeset
|
93 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), w, h); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
94 |
|
2622 | 95 |
resSurface:= SDL_CreateRGBSurface(0, toPowerOf2(w), toPowerOf2(h), 32, RMask, GMask, BMask, AMask); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
96 |
|
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2664
diff
changeset
|
97 |
strSurface:= TTF_RenderUTF8_Solid(Fontz[font].Handle, Str2PChar(str), color); |
1431 | 98 |
cl.Width:= w + 4; |
1118 | 99 |
SDL_UpperBlit(strSurface, nil, resSurface, nil); |
100 |
SDL_FreeSurface(strSurface); |
|
101 |
||
102 |
cl.Time:= RealTicks + 12500; |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2161
diff
changeset
|
103 |
cl.Tex:= Surface2Tex(resSurface, false); |
1431 | 104 |
|
1118 | 105 |
SDL_FreeSurface(resSurface) |
946 | 106 |
end; |
107 |
||
108 |
procedure AddChatString(s: shortstring); |
|
109 |
begin |
|
3539 | 110 |
if not ChatReady then |
111 |
begin |
|
112 |
if MissedCount < MaxStrIndex - 1 then |
|
113 |
MStrs[MissedCount]:= s |
|
114 |
else if MissedCount < MaxStrIndex then |
|
115 |
MStrs[MissedCount]:= #5 + '[...]'; |
|
116 |
inc(MissedCount); |
|
117 |
exit |
|
118 |
end; |
|
119 |
||
946 | 120 |
lastStr:= (lastStr + 1) mod (MaxStrIndex + 1); |
121 |
||
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
122 |
SetLine(Strs[lastStr], s, false); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
123 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
124 |
inc(visibleCount) |
942 | 125 |
end; |
126 |
||
127 |
procedure DrawChat; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
128 |
var i, t, cnt: Longword; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
129 |
r: TSDL_Rect; |
942 | 130 |
begin |
3539 | 131 |
ChatReady:= true; // maybe move to somewhere else? |
132 |
if MissedCount <> 0 then // there are chat strings we missed, so print them now |
|
133 |
begin |
|
134 |
for i:= 0 to MissedCount - 1 do |
|
135 |
AddChatString(MStrs[i]); |
|
136 |
MissedCount:= 0; |
|
137 |
end; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
138 |
cnt:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
139 |
t:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
140 |
i:= lastStr; |
1431 | 141 |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2131
diff
changeset
|
142 |
r.x:= 6 - cScreenWidth div 2; |
1431 | 143 |
r.y:= (visibleCount - t) * 16 + 10; |
144 |
r.h:= 16; |
|
145 |
||
146 |
if (GameState = gsChat) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
147 |
and (InputStr.Tex <> nil) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
148 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
149 |
r.w:= InputStr.Width; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
150 |
DrawFillRect(r); |
3390 | 151 |
Tint($00, $00, $00, $80); |
3085 | 152 |
DrawTexture(9 - cScreenWidth div 2, visibleCount * 16 + 11, InputStr.Tex); |
3390 | 153 |
Tint($FF, $FF, $FF, $FF); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
154 |
DrawTexture(8 - cScreenWidth div 2, visibleCount * 16 + 10, InputStr.Tex); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
155 |
end; |
1431 | 156 |
|
157 |
dec(r.y, 16); |
|
158 |
||
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
159 |
while |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
160 |
( |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
161 |
((t < 7) and (Strs[i].Time > RealTicks)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
162 |
or |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
163 |
((t < MaxStrIndex) and showAll) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
164 |
) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
165 |
and |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
166 |
(Strs[i].Tex <> nil) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
167 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
168 |
r.w:= Strs[i].Width; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
169 |
DrawFillRect(r); |
3390 | 170 |
Tint($00, $00, $00, $80); |
3085 | 171 |
DrawTexture(9 - cScreenWidth div 2, (visibleCount - t) * 16 - 5, Strs[i].Tex); |
3390 | 172 |
Tint($FF, $FF, $FF, $FF); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
173 |
DrawTexture(8 - cScreenWidth div 2, (visibleCount - t) * 16 - 6, Strs[i].Tex); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
174 |
dec(r.y, 16); |
2376 | 175 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
176 |
if i = 0 then i:= MaxStrIndex else dec(i); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
177 |
inc(cnt); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
178 |
inc(t) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
179 |
end; |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
180 |
|
947 | 181 |
visibleCount:= cnt; |
942 | 182 |
end; |
183 |
||
1033 | 184 |
procedure AcceptChatString(s: shortstring); |
1035 | 185 |
var i: TWave; |
2124 | 186 |
|
1033 | 187 |
begin |
2017 | 188 |
// "Make hedgehog say something" |
2376 | 189 |
if (s[1] = '"') and (s[Length(s)] = '"') then |
2017 | 190 |
begin |
2111 | 191 |
if CurrentTeam^.ExtDriven then |
192 |
ParseCommand('/say ' + copy(s, 2, Length(s)-2), true) |
|
193 |
else |
|
194 |
ParseCommand('/hogsay '#1 + copy(s, 2, Length(s)-2), true); |
|
2017 | 195 |
exit |
196 |
end; |
|
197 |
// 'Make hedgehog think something' |
|
2376 | 198 |
if (s[1] = '''') and (s[Length(s)] = '''') then |
2017 | 199 |
begin |
2111 | 200 |
if CurrentTeam^.ExtDriven then |
201 |
ParseCommand('/say ' + copy(s, 2, Length(s)-2), true) |
|
202 |
else |
|
203 |
ParseCommand('/hogsay '#2 + copy(s, 2, Length(s)-2), true); |
|
2017 | 204 |
exit |
205 |
end; |
|
206 |
// -Make hedgehog yell something- |
|
2376 | 207 |
if (s[1] = '-') and (s[Length(s)] = '-') then |
2017 | 208 |
begin |
2111 | 209 |
if CurrentTeam^.ExtDriven then |
210 |
ParseCommand('/say ' + copy(s, 2, Length(s)-2), true) |
|
211 |
else |
|
212 |
ParseCommand('/hogsay '#3 + copy(s, 2, Length(s)-2), true); |
|
2017 | 213 |
exit |
214 |
end; |
|
215 |
// These 3 are same as above, only are to make the hedgehog say it on next attack |
|
216 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hsa ') then |
|
217 |
begin |
|
2111 | 218 |
if CurrentTeam^.ExtDriven then |
2112 | 219 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 220 |
else |
2112 | 221 |
ParseCommand('/hogsay '#4 + copy(s, 6, Length(s)-5), true); |
2017 | 222 |
exit |
223 |
end; |
|
224 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hta ') then |
|
225 |
begin |
|
2111 | 226 |
if CurrentTeam^.ExtDriven then |
2112 | 227 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 228 |
else |
2112 | 229 |
ParseCommand('/hogsay '#5 + copy(s, 6, Length(s)-5), true); |
2017 | 230 |
exit |
231 |
end; |
|
232 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hya ') then |
|
233 |
begin |
|
2111 | 234 |
if CurrentTeam^.ExtDriven then |
2112 | 235 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 236 |
else |
2112 | 237 |
ParseCommand('/hogsay '#6 + copy(s, 6, Length(s)-5), true); |
2017 | 238 |
exit |
239 |
end; |
|
2111 | 240 |
|
2518 | 241 |
if (copy(s, 1, 6) = '/team ') and (length(s) > 6) then |
2124 | 242 |
begin |
2403 | 243 |
ParseCommand(s, true); |
2124 | 244 |
exit |
245 |
end; |
|
1378 | 246 |
if (s[1] = '/') and (copy(s, 1, 4) <> '/me ') then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
247 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
248 |
if CurrentTeam^.ExtDriven then exit; |
2376 | 249 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
250 |
for i:= Low(TWave) to High(TWave) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
251 |
if (s = Wavez[i].cmd) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
252 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
253 |
ParseCommand('/taunt ' + char(i), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
254 |
exit |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
255 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
256 |
if (s = '/newgrave') then |
2017 | 257 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
258 |
ParseCommand('/newgrave', true); |
2017 | 259 |
exit |
260 |
end; |
|
261 |
end |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
262 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
263 |
ParseCommand('/say ' + s, true); |
1033 | 264 |
end; |
265 |
||
946 | 266 |
procedure KeyPressChat(Key: Longword); |
267 |
const firstByteMark: array[1..4] of byte = (0, $C0, $E0, $F0); |
|
268 |
var i, btw: integer; |
|
1001 | 269 |
utf8: shortstring; |
946 | 270 |
begin |
1819 | 271 |
|
946 | 272 |
if Key <> 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
273 |
case Key of |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
274 |
{Backspace} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
275 |
8, 127: if Length(InputStr.s) > 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
276 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
277 |
InputStr.s[0]:= InputStrL[byte(InputStr.s[0])]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
278 |
SetLine(InputStr, InputStr.s, true) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
279 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
280 |
{Esc} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
281 |
27: SetLine(InputStr, '', true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
282 |
{Return} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
283 |
3, 13, 271: begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
284 |
if Length(InputStr.s) > 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
285 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
286 |
AcceptChatString(InputStr.s); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
287 |
SetLine(InputStr, '', false) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
288 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
289 |
FreezeEnterKey; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
290 |
GameState:= gsGame |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
291 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
292 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
293 |
if (Key < $80) then btw:= 1 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
294 |
else if (Key < $800) then btw:= 2 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
295 |
else if (Key < $10000) then btw:= 3 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
296 |
else btw:= 4; |
2376 | 297 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
298 |
utf8:= ''; |
946 | 299 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
300 |
for i:= btw downto 2 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
301 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
302 |
utf8:= char((Key or $80) and $BF) + utf8; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
303 |
Key:= Key shr 6 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
304 |
end; |
2376 | 305 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
306 |
utf8:= char(Key or firstByteMark[btw]) + utf8; |
946 | 307 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
308 |
if byte(InputStr.s[0]) + btw > 240 then exit; |
1485
51c11e77408a
Fix chat bugs leading to serialized data corruption
unc0rr
parents:
1431
diff
changeset
|
309 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
310 |
InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
311 |
SetLine(InputStr, InputStr.s + utf8, true) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
312 |
end |
946 | 313 |
end; |
314 |
||
3038 | 315 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
316 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
317 |
lastStr:= 0; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
318 |
visibleCount:= 0; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
319 |
UserNick:= ''; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
320 |
showAll:= false; |
3539 | 321 |
ChatReady:= false; |
322 |
missedCount:= 0; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
323 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
324 |
|
3038 | 325 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
326 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
327 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
328 |
end; |
946 | 329 |
|
942 | 330 |
end. |