author | koda |
Sun, 17 Mar 2013 01:15:22 +0100 | |
changeset 8738 | 50291d9a4ca0 |
parent 8737 | 0d56265dd60a |
child 8739 | bbab7e35eaf2 |
permissions | -rw-r--r-- |
942 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
942 | 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; |
|
6379 | 27 |
procedure ReloadLines; |
8738 | 28 |
procedure CleanupInput; |
942 | 29 |
procedure AddChatString(s: shortstring); |
30 |
procedure DrawChat; |
|
946 | 31 |
procedure KeyPressChat(Key: Longword); |
942 | 32 |
|
33 |
implementation |
|
6954
a61458a81480
changed uKeys to uInputHandler to better reflect its function
Xeli
parents:
6898
diff
changeset
|
34 |
uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO; |
942 | 35 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
36 |
const MaxStrIndex = 27; |
942 | 37 |
|
946 | 38 |
type TChatLine = record |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
39 |
Tex: PTexture; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
40 |
Time: Longword; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
41 |
Width: LongInt; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
42 |
s: shortstring; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
43 |
end; |
8152 | 44 |
TChatCmd = (quit, pause, finish, fullscreen); |
942 | 45 |
|
946 | 46 |
var Strs: array[0 .. MaxStrIndex] of TChatLine; |
3539 | 47 |
MStrs: array[0 .. MaxStrIndex] of shortstring; |
48 |
missedCount: LongWord; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
49 |
lastStr: LongWord; |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
50 |
history: LongWord; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
51 |
visibleCount: LongWord; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
52 |
InputStr: TChatLine; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
53 |
InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char |
4814
e19791f08443
smaller rearrangement of (non stereo related) variables
koda
parents:
4467
diff
changeset
|
54 |
ChatReady: boolean; |
e19791f08443
smaller rearrangement of (non stereo related) variables
koda
parents:
4467
diff
changeset
|
55 |
showAll: boolean; |
942 | 56 |
|
8152 | 57 |
const |
58 |
colors: array[#0..#6] of TSDL_Color = ( |
|
59 |
(r:$FF; g:$FF; b:$FF; unused:$FF), // unused, feel free to take it for anything |
|
60 |
(r:$FF; g:$FF; b:$FF; unused:$FF), // chat message [White] |
|
61 |
(r:$FF; g:$00; b:$FF; unused:$FF), // action message [Purple] |
|
62 |
(r:$90; g:$FF; b:$90; unused:$FF), // join/leave message [Lime] |
|
63 |
(r:$FF; g:$FF; b:$A0; unused:$FF), // team message [Light Yellow] |
|
64 |
(r:$FF; g:$00; b:$00; unused:$FF), // error messages [Red] |
|
65 |
(r:$00; g:$FF; b:$FF; unused:$FF) // input line [Light Blue] |
|
66 |
); |
|
67 |
ChatCommandz: array [TChatCmd] of record |
|
68 |
ChatCmd: string[31]; |
|
69 |
ProcedureCallChatCmd: string[31]; |
|
70 |
end = ( |
|
71 |
(ChatCmd: '/quit'; ProcedureCallChatCmd: 'halt'), |
|
72 |
(ChatCmd: '/pause'; ProcedureCallChatCmd: 'pause'), |
|
73 |
(ChatCmd: '/finish'; ProcedureCallChatCmd: 'finish'), |
|
74 |
(ChatCmd: '/fullscreen'; ProcedureCallChatCmd: 'fullscr') |
|
75 |
); |
|
2396 | 76 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
77 |
procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean); |
1118 | 78 |
var strSurface, resSurface: PSDL_Surface; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
79 |
w, h: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
80 |
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
|
81 |
font: THWFont; |
942 | 82 |
begin |
4925 | 83 |
if cl.Tex <> nil then |
84 |
FreeTexture(cl.Tex); |
|
2396 | 85 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
86 |
cl.s:= str; |
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
87 |
|
2396 | 88 |
if isInput then |
6379 | 89 |
begin |
5392 | 90 |
color:= colors[#6]; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
91 |
str:= UserNick + '> ' + str + '_' |
6379 | 92 |
end |
2664
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
93 |
else |
6379 | 94 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
95 |
color:= colors[str[1]]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
96 |
delete(str, 1, 1) |
6379 | 97 |
end; |
2396 | 98 |
|
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
|
99 |
font:= CheckCJKFont(str, fnt16); |
3407 | 100 |
w:= 0; h:= 0; // avoid compiler hints |
6286
835392304f81
and while we are giving SDLh.pas all this love, let's fix the signature of one SDL_ttf calls
koda
parents:
5392
diff
changeset
|
101 |
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
|
102 |
|
2622 | 103 |
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
|
104 |
|
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
|
105 |
strSurface:= TTF_RenderUTF8_Solid(Fontz[font].Handle, Str2PChar(str), color); |
1431 | 106 |
cl.Width:= w + 4; |
1118 | 107 |
SDL_UpperBlit(strSurface, nil, resSurface, nil); |
108 |
SDL_FreeSurface(strSurface); |
|
109 |
||
110 |
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
|
111 |
cl.Tex:= Surface2Tex(resSurface, false); |
1431 | 112 |
|
1118 | 113 |
SDL_FreeSurface(resSurface) |
946 | 114 |
end; |
115 |
||
6379 | 116 |
// For uStore texture recreation |
117 |
procedure ReloadLines; |
|
6381 | 118 |
var i, t: LongWord; |
6379 | 119 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
120 |
if InputStr.s <> '' then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
121 |
SetLine(InputStr, InputStr.s, true); |
6381 | 122 |
for i:= 0 to MaxStrIndex do |
123 |
if Strs[i].s <> '' then |
|
124 |
begin |
|
125 |
t:= Strs[i].Time; |
|
126 |
SetLine(Strs[i], Strs[i].s, false); |
|
127 |
Strs[i].Time:= t |
|
128 |
end; |
|
6379 | 129 |
end; |
130 |
||
946 | 131 |
procedure AddChatString(s: shortstring); |
132 |
begin |
|
3539 | 133 |
if not ChatReady then |
134 |
begin |
|
135 |
if MissedCount < MaxStrIndex - 1 then |
|
136 |
MStrs[MissedCount]:= s |
|
137 |
else if MissedCount < MaxStrIndex then |
|
138 |
MStrs[MissedCount]:= #5 + '[...]'; |
|
139 |
inc(MissedCount); |
|
140 |
exit |
|
141 |
end; |
|
142 |
||
946 | 143 |
lastStr:= (lastStr + 1) mod (MaxStrIndex + 1); |
144 |
||
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
145 |
SetLine(Strs[lastStr], s, false); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
146 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
147 |
inc(visibleCount) |
942 | 148 |
end; |
149 |
||
150 |
procedure DrawChat; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
151 |
var i, t, cnt: Longword; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
152 |
r: TSDL_Rect; |
942 | 153 |
begin |
3539 | 154 |
ChatReady:= true; // maybe move to somewhere else? |
155 |
if MissedCount <> 0 then // there are chat strings we missed, so print them now |
|
156 |
begin |
|
157 |
for i:= 0 to MissedCount - 1 do |
|
158 |
AddChatString(MStrs[i]); |
|
159 |
MissedCount:= 0; |
|
160 |
end; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
161 |
cnt:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
162 |
t:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
163 |
i:= lastStr; |
1431 | 164 |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2131
diff
changeset
|
165 |
r.x:= 6 - cScreenWidth div 2; |
1431 | 166 |
r.y:= (visibleCount - t) * 16 + 10; |
167 |
r.h:= 16; |
|
168 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
169 |
if (GameState = gsChat) and (InputStr.Tex <> nil) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
170 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
171 |
r.w:= InputStr.Width; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
172 |
DrawFillRect(r); |
3390 | 173 |
Tint($00, $00, $00, $80); |
3085 | 174 |
DrawTexture(9 - cScreenWidth div 2, visibleCount * 16 + 11, InputStr.Tex); |
3390 | 175 |
Tint($FF, $FF, $FF, $FF); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
176 |
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
|
177 |
end; |
1431 | 178 |
|
179 |
dec(r.y, 16); |
|
180 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
181 |
while (((t < 7) and (Strs[i].Time > RealTicks)) or ((t < MaxStrIndex) and showAll)) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
182 |
and (Strs[i].Tex <> nil) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
183 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
184 |
r.w:= Strs[i].Width; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
185 |
DrawFillRect(r); |
3390 | 186 |
Tint($00, $00, $00, $80); |
3085 | 187 |
DrawTexture(9 - cScreenWidth div 2, (visibleCount - t) * 16 - 5, Strs[i].Tex); |
3390 | 188 |
Tint($FF, $FF, $FF, $FF); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
189 |
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
|
190 |
dec(r.y, 16); |
2376 | 191 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
192 |
if i = 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
193 |
i:= MaxStrIndex |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
194 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
195 |
dec(i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
196 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
197 |
inc(cnt); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
198 |
inc(t) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
199 |
end; |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
200 |
|
947 | 201 |
visibleCount:= cnt; |
942 | 202 |
end; |
203 |
||
4467 | 204 |
procedure SendHogSpeech(s: shortstring); |
205 |
begin |
|
206 |
SendIPC('h' + s); |
|
207 |
ParseCommand('/hogsay '+s, true) |
|
208 |
end; |
|
209 |
||
1033 | 210 |
procedure AcceptChatString(s: shortstring); |
1035 | 211 |
var i: TWave; |
8152 | 212 |
j: TChatCmd; |
4465
743673c67d0c
Allow hog speech when not your turn. Currently is set to 40% opacity (could be fainter) and drawn behind the hogs instead of in front. Also allows hog targetting using a number.
nemo
parents:
4404
diff
changeset
|
213 |
c, t: LongInt; |
4467 | 214 |
x: byte; |
1033 | 215 |
begin |
4465
743673c67d0c
Allow hog speech when not your turn. Currently is set to 40% opacity (could be fainter) and drawn behind the hogs instead of in front. Also allows hog targetting using a number.
nemo
parents:
4404
diff
changeset
|
216 |
t:= LocalTeam; |
4467 | 217 |
x:= 0; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
218 |
if (s[1] = '"') and (s[Length(s)] = '"') |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
219 |
then x:= 1 |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
220 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
221 |
else if (s[1] = '''') and (s[Length(s)] = '''') then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
222 |
x:= 2 |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
223 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
224 |
else if (s[1] = '-') and (s[Length(s)] = '-') then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
225 |
x:= 3; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
226 |
|
4467 | 227 |
if not CurrentTeam^.ExtDriven and (x <> 0) then |
4465
743673c67d0c
Allow hog speech when not your turn. Currently is set to 40% opacity (could be fainter) and drawn behind the hogs instead of in front. Also allows hog targetting using a number.
nemo
parents:
4404
diff
changeset
|
228 |
for c:= 0 to Pred(TeamsCount) do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
229 |
if (TeamsArray[c] = CurrentTeam) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
230 |
t:= c; |
4467 | 231 |
|
232 |
if x <> 0 then |
|
2017 | 233 |
begin |
4465
743673c67d0c
Allow hog speech when not your turn. Currently is set to 40% opacity (could be fainter) and drawn behind the hogs instead of in front. Also allows hog targetting using a number.
nemo
parents:
4404
diff
changeset
|
234 |
if t = -1 then |
2111 | 235 |
ParseCommand('/say ' + copy(s, 2, Length(s)-2), true) |
236 |
else |
|
4467 | 237 |
SendHogSpeech(char(x) + char(t) + copy(s, 2, Length(s)-2)); |
2017 | 238 |
exit |
239 |
end; |
|
4467 | 240 |
|
2017 | 241 |
// These 3 are same as above, only are to make the hedgehog say it on next attack |
242 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hsa ') then |
|
243 |
begin |
|
2111 | 244 |
if CurrentTeam^.ExtDriven then |
2112 | 245 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 246 |
else |
4467 | 247 |
SendHogSpeech(#4 + copy(s, 6, Length(s)-5)); |
2017 | 248 |
exit |
249 |
end; |
|
250 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hta ') then |
|
251 |
begin |
|
2111 | 252 |
if CurrentTeam^.ExtDriven then |
2112 | 253 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 254 |
else |
4467 | 255 |
SendHogSpeech(#5 + copy(s, 6, Length(s)-5)); |
2017 | 256 |
exit |
257 |
end; |
|
258 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hya ') then |
|
259 |
begin |
|
2111 | 260 |
if CurrentTeam^.ExtDriven then |
2112 | 261 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 262 |
else |
4467 | 263 |
SendHogSpeech(#6 + copy(s, 6, Length(s)-5)); |
2017 | 264 |
exit |
265 |
end; |
|
2111 | 266 |
|
2518 | 267 |
if (copy(s, 1, 6) = '/team ') and (length(s) > 6) then |
2124 | 268 |
begin |
2403 | 269 |
ParseCommand(s, true); |
2124 | 270 |
exit |
271 |
end; |
|
1378 | 272 |
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
|
273 |
begin |
4121 | 274 |
if CurrentTeam^.ExtDriven or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then |
275 |
exit; |
|
2376 | 276 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
277 |
for i:= Low(TWave) to High(TWave) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
278 |
if (s = Wavez[i].cmd) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
279 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
280 |
ParseCommand('/taunt ' + char(i), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
281 |
exit |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
282 |
end; |
8152 | 283 |
|
284 |
for j:= Low(TChatCmd) to High(TChatCmd) do |
|
285 |
if (s = ChatCommandz[j].ChatCmd) then |
|
286 |
begin |
|
287 |
ParseCommand(ChatCommandz[j].ProcedureCallChatCmd, true); |
|
288 |
exit |
|
289 |
end; |
|
2017 | 290 |
end |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
291 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
292 |
ParseCommand('/say ' + s, true); |
1033 | 293 |
end; |
294 |
||
8738 | 295 |
procedure CleanupInput; |
296 |
begin |
|
297 |
FreezeEnterKey; |
|
298 |
history:= 0; |
|
299 |
SDL_EnableKeyRepeat(0,0); |
|
300 |
GameState:= gsGame; |
|
301 |
ResetKbd; |
|
302 |
end; |
|
303 |
||
946 | 304 |
procedure KeyPressChat(Key: Longword); |
6893 | 305 |
const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
306 |
var i, btw, index: integer; |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
307 |
utf8, chatLine: shortstring; |
946 | 308 |
begin |
8735 | 309 |
if Key <> 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
310 |
case Key of |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
311 |
{Backspace} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
312 |
8, 127: if Length(InputStr.s) > 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
313 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
314 |
InputStr.s[0]:= InputStrL[byte(InputStr.s[0])]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
315 |
SetLine(InputStr, InputStr.s, true) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
316 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
317 |
{Esc} |
5100 | 318 |
27: if Length(InputStr.s) > 0 then SetLine(InputStr, '', true) |
8738 | 319 |
else CleanupInput; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
320 |
{Return} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
321 |
3, 13, 271: begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
322 |
if Length(InputStr.s) > 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
323 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
324 |
AcceptChatString(InputStr.s); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
325 |
SetLine(InputStr, '', false) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
326 |
end; |
8738 | 327 |
CleanupInput; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
328 |
end; |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
329 |
{arrow keys (up, down)} |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
330 |
63232, 63233: begin |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
331 |
|
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
332 |
if (Key = 63232) and (history < lastStr) then inc(history); |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
333 |
if (Key = 63233) and (history > 0) then dec(history); |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
334 |
|
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
335 |
index:= lastStr - history + 1; |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
336 |
if (index > lastStr) then |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
337 |
SetLine(InputStr, '', true) |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
338 |
else |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
339 |
begin |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
340 |
btw:= Pos(': ', Strs[index].s) + 2; // remove the nick |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
341 |
chatLine:= copy(Strs[index].s, btw, Length(Strs[index].s)); |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
342 |
SetLine(InputStr, chatLine, true); |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
343 |
end; |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
344 |
end; |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
345 |
{arrow keys (left, right)} |
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
346 |
63234, 63235: begin end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
347 |
else |
8735 | 348 |
if (Key < $80) then |
349 |
btw:= 1 |
|
350 |
else if (Key < $800) then |
|
351 |
btw:= 2 |
|
352 |
else if (Key < $10000) then |
|
353 |
btw:= 3 |
|
354 |
else |
|
355 |
btw:= 4; |
|
2376 | 356 |
|
8735 | 357 |
utf8:= ''; |
946 | 358 |
|
8735 | 359 |
for i:= btw downto 2 do |
360 |
begin |
|
361 |
utf8:= char((Key or $80) and $BF) + utf8; |
|
362 |
Key:= Key shr 6 |
|
363 |
end; |
|
2376 | 364 |
|
8735 | 365 |
utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8; |
946 | 366 |
|
8735 | 367 |
if byte(InputStr.s[0]) + btw > 240 then |
368 |
exit; |
|
1485
51c11e77408a
Fix chat bugs leading to serialized data corruption
unc0rr
parents:
1431
diff
changeset
|
369 |
|
8735 | 370 |
InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0]; |
371 |
SetLine(InputStr, InputStr.s + utf8, true) |
|
372 |
end |
|
946 | 373 |
end; |
374 |
||
4404 | 375 |
procedure chChatMessage(var s: shortstring); |
376 |
begin |
|
377 |
AddChatString(s) |
|
378 |
end; |
|
379 |
||
4402 | 380 |
procedure chSay(var s: shortstring); |
381 |
begin |
|
382 |
SendIPC('s' + s); |
|
383 |
||
384 |
if copy(s, 1, 4) = '/me ' then |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6381
diff
changeset
|
385 |
s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4) |
4402 | 386 |
else |
387 |
s:= #1 + UserNick + ': ' + s; |
|
388 |
||
389 |
AddChatString(s) |
|
390 |
end; |
|
391 |
||
392 |
procedure chTeamSay(var s: shortstring); |
|
393 |
begin |
|
394 |
SendIPC('b' + s); |
|
395 |
||
396 |
s:= #4 + '[Team] ' + UserNick + ': ' + s; |
|
397 |
||
398 |
AddChatString(s) |
|
399 |
end; |
|
400 |
||
401 |
procedure chHistory(var s: shortstring); |
|
402 |
begin |
|
403 |
s:= s; // avoid compiler hint |
|
6854
873929cbd54b
Normalize RecordFields before conversion. Helps with namespaces problem.
unc0rr
parents:
6700
diff
changeset
|
404 |
showAll:= not showAll |
4402 | 405 |
end; |
406 |
||
407 |
procedure chChat(var s: shortstring); |
|
408 |
begin |
|
409 |
s:= s; // avoid compiler hint |
|
410 |
GameState:= gsChat; |
|
5099
ce1a761d3c1e
enable keyrepeat while chatting so you can keep backspace pressed to delete a line (fix issue 111)
koda
parents:
4976
diff
changeset
|
411 |
SDL_EnableKeyRepeat(200,45); |
4402 | 412 |
if length(s) = 0 then |
5100 | 413 |
SetLine(InputStr, '', true) |
4402 | 414 |
else |
415 |
begin |
|
8516
e422cbf9aa33
pretty sure esc here is just a holdover from past, and has no use in rearranged implementation.
nemo
parents:
8152
diff
changeset
|
416 |
// "/team " |
4402 | 417 |
KeyPressChat(47); |
418 |
KeyPressChat(116); |
|
419 |
KeyPressChat(101); |
|
420 |
KeyPressChat(97); |
|
421 |
KeyPressChat(109); |
|
422 |
KeyPressChat(32) |
|
423 |
end |
|
424 |
end; |
|
425 |
||
3038 | 426 |
procedure initModule; |
4925 | 427 |
var i: ShortInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
428 |
begin |
6898 | 429 |
RegisterVariable('chatmsg', @chChatMessage, true); |
430 |
RegisterVariable('say', @chSay, true); |
|
431 |
RegisterVariable('team', @chTeamSay, true); |
|
432 |
RegisterVariable('history', @chHistory, true ); |
|
433 |
RegisterVariable('chat', @chChat, true ); |
|
4402 | 434 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
435 |
lastStr:= 0; |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
436 |
history:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
437 |
visibleCount:= 0; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
438 |
showAll:= false; |
3539 | 439 |
ChatReady:= false; |
440 |
missedCount:= 0; |
|
4925 | 441 |
|
442 |
inputStr.Tex := nil; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
443 |
for i:= 0 to MaxStrIndex do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
444 |
Strs[i].Tex := nil; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
445 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
446 |
|
3038 | 447 |
procedure freeModule; |
4901 | 448 |
var i: ShortInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
449 |
begin |
4901 | 450 |
FreeTexture(InputStr.Tex); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
451 |
for i:= 0 to MaxStrIndex do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
452 |
FreeTexture(Strs[i].Tex); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
453 |
end; |
946 | 454 |
|
942 | 455 |
end. |