author | nemo |
Thu, 31 Oct 2013 20:50:20 -0400 | |
changeset 9663 | 1fa74f92555d |
parent 9569 | dd1861ca4def |
child 9666 | 8dcb25112d96 |
permissions | -rw-r--r-- |
942 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
9080 | 3 |
* Copyright (c) 2004-2013 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; |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
31 |
procedure KeyPressChat(Key, Sym: 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; |
9569 | 44 |
TChatCmd = (quit, pause, finish, showhistory, fullscreen); |
942 | 45 |
|
946 | 46 |
var Strs: array[0 .. MaxStrIndex] of TChatLine; |
3539 | 47 |
MStrs: array[0 .. MaxStrIndex] of shortstring; |
8740
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
48 |
LocalStrs: array[0 .. MaxStrIndex] of shortstring; |
3539 | 49 |
missedCount: LongWord; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
50 |
lastStr: LongWord; |
9145 | 51 |
localLastStr: LongInt; |
52 |
history: LongInt; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
53 |
visibleCount: LongWord; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
54 |
InputStr: TChatLine; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
55 |
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
|
56 |
ChatReady: boolean; |
e19791f08443
smaller rearrangement of (non stereo related) variables
koda
parents:
4467
diff
changeset
|
57 |
showAll: boolean; |
942 | 58 |
|
8152 | 59 |
const |
60 |
colors: array[#0..#6] of TSDL_Color = ( |
|
9311
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
61 |
(r:$FF; g:$FF; b:$FF; a:$FF), // unused, feel free to take it for anything |
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
62 |
(r:$FF; g:$FF; b:$FF; a:$FF), // chat message [White] |
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
63 |
(r:$FF; g:$00; b:$FF; a:$FF), // action message [Purple] |
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
64 |
(r:$90; g:$FF; b:$90; a:$FF), // join/leave message [Lime] |
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
65 |
(r:$FF; g:$FF; b:$A0; a:$FF), // team message [Light Yellow] |
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
66 |
(r:$FF; g:$00; b:$00; a:$FF), // error messages [Red] |
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9145
diff
changeset
|
67 |
(r:$00; g:$FF; b:$FF; a:$FF) // input line [Light Blue] |
8152 | 68 |
); |
69 |
ChatCommandz: array [TChatCmd] of record |
|
70 |
ChatCmd: string[31]; |
|
71 |
ProcedureCallChatCmd: string[31]; |
|
72 |
end = ( |
|
73 |
(ChatCmd: '/quit'; ProcedureCallChatCmd: 'halt'), |
|
74 |
(ChatCmd: '/pause'; ProcedureCallChatCmd: 'pause'), |
|
75 |
(ChatCmd: '/finish'; ProcedureCallChatCmd: 'finish'), |
|
9569 | 76 |
(ChatCmd: '/history'; ProcedureCallChatCmd: 'history'), |
8152 | 77 |
(ChatCmd: '/fullscreen'; ProcedureCallChatCmd: 'fullscr') |
78 |
); |
|
2396 | 79 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
80 |
procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean); |
1118 | 81 |
var strSurface, resSurface: PSDL_Surface; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
82 |
w, h: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
83 |
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
|
84 |
font: THWFont; |
942 | 85 |
begin |
4925 | 86 |
if cl.Tex <> nil then |
87 |
FreeTexture(cl.Tex); |
|
2396 | 88 |
|
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
89 |
cl.s:= str; |
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
90 |
|
2396 | 91 |
if isInput then |
6379 | 92 |
begin |
5392 | 93 |
color:= colors[#6]; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
94 |
str:= UserNick + '> ' + str + '_' |
6379 | 95 |
end |
2664
949c189ba568
powerpc and gameserver compilation disabled temporarily
koda
parents:
2630
diff
changeset
|
96 |
else |
6379 | 97 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
98 |
color:= colors[str[1]]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
99 |
delete(str, 1, 1) |
6379 | 100 |
end; |
2396 | 101 |
|
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
|
102 |
font:= CheckCJKFont(str, fnt16); |
3407 | 103 |
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
|
104 |
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
|
105 |
|
2622 | 106 |
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
|
107 |
|
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
|
108 |
strSurface:= TTF_RenderUTF8_Solid(Fontz[font].Handle, Str2PChar(str), color); |
1431 | 109 |
cl.Width:= w + 4; |
1118 | 110 |
SDL_UpperBlit(strSurface, nil, resSurface, nil); |
111 |
SDL_FreeSurface(strSurface); |
|
112 |
||
113 |
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
|
114 |
cl.Tex:= Surface2Tex(resSurface, false); |
1431 | 115 |
|
1118 | 116 |
SDL_FreeSurface(resSurface) |
946 | 117 |
end; |
118 |
||
6379 | 119 |
// For uStore texture recreation |
120 |
procedure ReloadLines; |
|
6381 | 121 |
var i, t: LongWord; |
6379 | 122 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
123 |
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
|
124 |
SetLine(InputStr, InputStr.s, true); |
6381 | 125 |
for i:= 0 to MaxStrIndex do |
126 |
if Strs[i].s <> '' then |
|
127 |
begin |
|
128 |
t:= Strs[i].Time; |
|
129 |
SetLine(Strs[i], Strs[i].s, false); |
|
130 |
Strs[i].Time:= t |
|
131 |
end; |
|
6379 | 132 |
end; |
133 |
||
946 | 134 |
procedure AddChatString(s: shortstring); |
135 |
begin |
|
3539 | 136 |
if not ChatReady then |
137 |
begin |
|
138 |
if MissedCount < MaxStrIndex - 1 then |
|
139 |
MStrs[MissedCount]:= s |
|
140 |
else if MissedCount < MaxStrIndex then |
|
141 |
MStrs[MissedCount]:= #5 + '[...]'; |
|
142 |
inc(MissedCount); |
|
143 |
exit |
|
144 |
end; |
|
145 |
||
946 | 146 |
lastStr:= (lastStr + 1) mod (MaxStrIndex + 1); |
147 |
||
990
dfa6a6fe1542
Implement history for chat (27 entries), no key binding yet
unc0rr
parents:
988
diff
changeset
|
148 |
SetLine(Strs[lastStr], s, false); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
149 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
150 |
inc(visibleCount) |
942 | 151 |
end; |
152 |
||
153 |
procedure DrawChat; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
154 |
var i, t, cnt: Longword; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
155 |
r: TSDL_Rect; |
942 | 156 |
begin |
3539 | 157 |
ChatReady:= true; // maybe move to somewhere else? |
158 |
if MissedCount <> 0 then // there are chat strings we missed, so print them now |
|
159 |
begin |
|
160 |
for i:= 0 to MissedCount - 1 do |
|
161 |
AddChatString(MStrs[i]); |
|
162 |
MissedCount:= 0; |
|
163 |
end; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
164 |
cnt:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
165 |
t:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
166 |
i:= lastStr; |
1431 | 167 |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2131
diff
changeset
|
168 |
r.x:= 6 - cScreenWidth div 2; |
1431 | 169 |
r.y:= (visibleCount - t) * 16 + 10; |
170 |
r.h:= 16; |
|
171 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
172 |
if (GameState = gsChat) and (InputStr.Tex <> nil) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
173 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
174 |
r.w:= InputStr.Width; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
175 |
DrawFillRect(r); |
3390 | 176 |
Tint($00, $00, $00, $80); |
3085 | 177 |
DrawTexture(9 - cScreenWidth div 2, visibleCount * 16 + 11, InputStr.Tex); |
3390 | 178 |
Tint($FF, $FF, $FF, $FF); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
179 |
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
|
180 |
end; |
1431 | 181 |
|
182 |
dec(r.y, 16); |
|
183 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
184 |
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
|
185 |
and (Strs[i].Tex <> nil) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
186 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
187 |
r.w:= Strs[i].Width; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
188 |
DrawFillRect(r); |
3390 | 189 |
Tint($00, $00, $00, $80); |
3085 | 190 |
DrawTexture(9 - cScreenWidth div 2, (visibleCount - t) * 16 - 5, Strs[i].Tex); |
3390 | 191 |
Tint($FF, $FF, $FF, $FF); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
192 |
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
|
193 |
dec(r.y, 16); |
2376 | 194 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
195 |
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
|
196 |
i:= MaxStrIndex |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
197 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
198 |
dec(i); |
8745 | 199 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
200 |
inc(cnt); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
201 |
inc(t) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
202 |
end; |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
203 |
|
947 | 204 |
visibleCount:= cnt; |
942 | 205 |
end; |
206 |
||
4467 | 207 |
procedure SendHogSpeech(s: shortstring); |
208 |
begin |
|
209 |
SendIPC('h' + s); |
|
210 |
ParseCommand('/hogsay '+s, true) |
|
211 |
end; |
|
212 |
||
1033 | 213 |
procedure AcceptChatString(s: shortstring); |
1035 | 214 |
var i: TWave; |
8152 | 215 |
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
|
216 |
c, t: LongInt; |
4467 | 217 |
x: byte; |
1033 | 218 |
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
|
219 |
t:= LocalTeam; |
4467 | 220 |
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
|
221 |
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
|
222 |
then x:= 1 |
8745 | 223 |
|
6580
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:= 2 |
8745 | 226 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6453
diff
changeset
|
227 |
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
|
228 |
x:= 3; |
8745 | 229 |
|
4467 | 230 |
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
|
231 |
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
|
232 |
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
|
233 |
t:= c; |
4467 | 234 |
|
235 |
if x <> 0 then |
|
2017 | 236 |
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
|
237 |
if t = -1 then |
2111 | 238 |
ParseCommand('/say ' + copy(s, 2, Length(s)-2), true) |
239 |
else |
|
4467 | 240 |
SendHogSpeech(char(x) + char(t) + copy(s, 2, Length(s)-2)); |
2017 | 241 |
exit |
242 |
end; |
|
4467 | 243 |
|
2017 | 244 |
// These 3 are same as above, only are to make the hedgehog say it on next attack |
245 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hsa ') then |
|
246 |
begin |
|
2111 | 247 |
if CurrentTeam^.ExtDriven then |
2112 | 248 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 249 |
else |
4467 | 250 |
SendHogSpeech(#4 + copy(s, 6, Length(s)-5)); |
2017 | 251 |
exit |
252 |
end; |
|
253 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hta ') then |
|
254 |
begin |
|
2111 | 255 |
if CurrentTeam^.ExtDriven then |
2112 | 256 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 257 |
else |
4467 | 258 |
SendHogSpeech(#5 + copy(s, 6, Length(s)-5)); |
2017 | 259 |
exit |
260 |
end; |
|
261 |
if (s[1] = '/') and (copy(s, 1, 5) = '/hya ') then |
|
262 |
begin |
|
2111 | 263 |
if CurrentTeam^.ExtDriven then |
2112 | 264 |
ParseCommand('/say ' + copy(s, 6, Length(s)-5), true) |
2111 | 265 |
else |
4467 | 266 |
SendHogSpeech(#6 + copy(s, 6, Length(s)-5)); |
2017 | 267 |
exit |
268 |
end; |
|
2111 | 269 |
|
2518 | 270 |
if (copy(s, 1, 6) = '/team ') and (length(s) > 6) then |
2124 | 271 |
begin |
2403 | 272 |
ParseCommand(s, true); |
2124 | 273 |
exit |
274 |
end; |
|
1378 | 275 |
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
|
276 |
begin |
4121 | 277 |
if CurrentTeam^.ExtDriven or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then |
278 |
exit; |
|
2376 | 279 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
280 |
for i:= Low(TWave) to High(TWave) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
281 |
if (s = Wavez[i].cmd) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
282 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
283 |
ParseCommand('/taunt ' + char(i), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
284 |
exit |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
285 |
end; |
8152 | 286 |
|
8745 | 287 |
for j:= Low(TChatCmd) to High(TChatCmd) do |
8152 | 288 |
if (s = ChatCommandz[j].ChatCmd) then |
289 |
begin |
|
290 |
ParseCommand(ChatCommandz[j].ProcedureCallChatCmd, true); |
|
291 |
exit |
|
292 |
end; |
|
2017 | 293 |
end |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
294 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
295 |
ParseCommand('/say ' + s, true); |
1033 | 296 |
end; |
297 |
||
8738 | 298 |
procedure CleanupInput; |
299 |
begin |
|
300 |
FreezeEnterKey; |
|
301 |
history:= 0; |
|
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
302 |
{$IFNDEF SDL2} |
8738 | 303 |
SDL_EnableKeyRepeat(0,0); |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
304 |
{$ENDIF} |
8738 | 305 |
GameState:= gsGame; |
306 |
ResetKbd; |
|
307 |
end; |
|
308 |
||
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
309 |
procedure KeyPressChat(Key, Sym: Longword); |
6893 | 310 |
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
|
311 |
var i, btw, index: integer; |
8740
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
312 |
utf8: shortstring; |
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
313 |
action: boolean; |
946 | 314 |
begin |
8745 | 315 |
action:= true; |
8743 | 316 |
case Sym of |
317 |
SDLK_BACKSPACE: |
|
318 |
begin |
|
319 |
if Length(InputStr.s) > 0 then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
320 |
begin |
8743 | 321 |
InputStr.s[0]:= InputStrL[byte(InputStr.s[0])]; |
322 |
SetLine(InputStr, InputStr.s, true) |
|
323 |
end |
|
324 |
end; |
|
8745 | 325 |
SDLK_ESCAPE: |
8743 | 326 |
begin |
8745 | 327 |
if Length(InputStr.s) > 0 then |
8743 | 328 |
SetLine(InputStr, '', true) |
329 |
else CleanupInput |
|
330 |
end; |
|
9319
492a0ad67e33
allow to send chat messages with numpad enter key too (regression?)
koda
parents:
9317
diff
changeset
|
331 |
SDLK_RETURN, SDLK_KP_ENTER: |
8743 | 332 |
begin |
333 |
if Length(InputStr.s) > 0 then |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
334 |
begin |
8743 | 335 |
AcceptChatString(InputStr.s); |
336 |
SetLine(InputStr, '', false) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
337 |
end; |
8743 | 338 |
CleanupInput |
339 |
end; |
|
340 |
SDLK_UP, SDLK_DOWN: |
|
341 |
begin |
|
342 |
if (Sym = SDLK_UP) and (history < localLastStr) then inc(history); |
|
343 |
if (Sym = SDLK_DOWN) and (history > 0) then dec(history); |
|
344 |
index:= localLastStr - history + 1; |
|
345 |
if (index > localLastStr) then |
|
346 |
SetLine(InputStr, '', true) |
|
347 |
else SetLine(InputStr, LocalStrs[index], true) |
|
8745 | 348 |
end; |
349 |
SDLK_RIGHT, SDLK_LEFT, SDLK_DELETE, |
|
350 |
SDLK_HOME, SDLK_END, |
|
351 |
SDLK_PAGEUP, SDLK_PAGEDOWN: |
|
352 |
begin |
|
353 |
// ignore me!!! |
|
354 |
end; |
|
355 |
else |
|
356 |
action:= false; |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
357 |
end; |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
358 |
if not action and (Key <> 0) then |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
359 |
begin |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
360 |
if (Key < $80) then |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
361 |
btw:= 1 |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
362 |
else if (Key < $800) then |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
363 |
btw:= 2 |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
364 |
else if (Key < $10000) then |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
365 |
btw:= 3 |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
366 |
else |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
367 |
btw:= 4; |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
368 |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
369 |
utf8:= ''; |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
370 |
|
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
371 |
for i:= btw downto 2 do |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
372 |
begin |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
373 |
utf8:= char((Key or $80) and $BF) + utf8; |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
374 |
Key:= Key shr 6 |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
375 |
end; |
2376 | 376 |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
377 |
utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8; |
946 | 378 |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
379 |
if byte(InputStr.s[0]) + btw > 240 then |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
380 |
exit; |
2376 | 381 |
|
8742
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
382 |
InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0]; |
b7b8bd398c1b
Key returned 0 for arrows under linux. Sym works, clearer anyway.
nemo
parents:
8741
diff
changeset
|
383 |
SetLine(InputStr, InputStr.s + utf8, true) |
8735 | 384 |
end |
946 | 385 |
end; |
386 |
||
4404 | 387 |
procedure chChatMessage(var s: shortstring); |
388 |
begin |
|
389 |
AddChatString(s) |
|
390 |
end; |
|
391 |
||
4402 | 392 |
procedure chSay(var s: shortstring); |
393 |
begin |
|
394 |
SendIPC('s' + s); |
|
395 |
||
396 |
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
|
397 |
s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4) |
4402 | 398 |
else |
8740
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
399 |
begin |
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
400 |
localLastStr:= (localLastStr + 1) mod MaxStrIndex; |
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
401 |
LocalStrs[localLastStr]:= s; |
4402 | 402 |
s:= #1 + UserNick + ': ' + s; |
8740
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
403 |
end; |
4402 | 404 |
|
405 |
AddChatString(s) |
|
406 |
end; |
|
407 |
||
408 |
procedure chTeamSay(var s: shortstring); |
|
409 |
begin |
|
410 |
SendIPC('b' + s); |
|
411 |
||
412 |
s:= #4 + '[Team] ' + UserNick + ': ' + s; |
|
413 |
||
414 |
AddChatString(s) |
|
415 |
end; |
|
416 |
||
417 |
procedure chHistory(var s: shortstring); |
|
418 |
begin |
|
419 |
s:= s; // avoid compiler hint |
|
6854
873929cbd54b
Normalize RecordFields before conversion. Helps with namespaces problem.
unc0rr
parents:
6700
diff
changeset
|
420 |
showAll:= not showAll |
4402 | 421 |
end; |
422 |
||
423 |
procedure chChat(var s: shortstring); |
|
424 |
begin |
|
425 |
s:= s; // avoid compiler hint |
|
426 |
GameState:= gsChat; |
|
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
427 |
{$IFNDEF SDL2} |
5099
ce1a761d3c1e
enable keyrepeat while chatting so you can keep backspace pressed to delete a line (fix issue 111)
koda
parents:
4976
diff
changeset
|
428 |
SDL_EnableKeyRepeat(200,45); |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
429 |
{$ENDIF} |
4402 | 430 |
if length(s) = 0 then |
5100 | 431 |
SetLine(InputStr, '', true) |
4402 | 432 |
else |
8739 | 433 |
SetLine(InputStr, '/team ', true) |
4402 | 434 |
end; |
435 |
||
3038 | 436 |
procedure initModule; |
4925 | 437 |
var i: ShortInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
438 |
begin |
6898 | 439 |
RegisterVariable('chatmsg', @chChatMessage, true); |
440 |
RegisterVariable('say', @chSay, true); |
|
441 |
RegisterVariable('team', @chTeamSay, true); |
|
442 |
RegisterVariable('history', @chHistory, true ); |
|
443 |
RegisterVariable('chat', @chChat, true ); |
|
4402 | 444 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
445 |
lastStr:= 0; |
8740
3eb1891f81ef
use a local storage for chat history which prevents mix ups in netgame and simplifies code
koda
parents:
8739
diff
changeset
|
446 |
localLastStr:= 0; |
8737
0d56265dd60a
implement up and down keys to navigate in the chat history, needs testing over network
koda
parents:
8736
diff
changeset
|
447 |
history:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
448 |
visibleCount:= 0; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
449 |
showAll:= false; |
3539 | 450 |
ChatReady:= false; |
451 |
missedCount:= 0; |
|
4925 | 452 |
|
453 |
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
|
454 |
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
|
455 |
Strs[i].Tex := nil; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
456 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
457 |
|
3038 | 458 |
procedure freeModule; |
4901 | 459 |
var i: ShortInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
460 |
begin |
4901 | 461 |
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
|
462 |
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
|
463 |
FreeTexture(Strs[i].Tex); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2699
diff
changeset
|
464 |
end; |
946 | 465 |
|
942 | 466 |
end. |