hedgewars/uChat.pas
author unc0rr
Sat, 24 May 2008 17:34:06 +0000
changeset 945 4ead9cde4e14
parent 942 b41af014d85e
child 946 42c5cc87cbd1
permissions -rw-r--r--
- Start chat implementation: chat strings are on the screen - Fix teleportation on water regression
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     1
(*
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com>
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     4
 *
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     8
 *
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    13
 *
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    17
 *)
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    18
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    19
unit uChat;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    20
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    21
interface
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    22
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    23
procedure AddChatString(s: shortstring);
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    24
procedure DrawChat;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    25
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    26
implementation
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    27
uses uMisc, uStore, uConsts, SDLh;
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    28
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    29
const MaxStrIndex = 7;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    30
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    31
type TStr = record
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    32
		Time: Longword;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    33
		Tex: PTexture;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    34
		end;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    35
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    36
var Strs: array[0 .. MaxStrIndex] of TStr;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    37
	lastStr: Longword = 0;
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    38
	visibleCount: Longword = 0;
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    39
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    40
procedure AddChatString(s: shortstring);
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    41
var strSurface, resSurface: PSDL_Surface;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    42
    r: TSDL_Rect;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    43
    w, h: LongInt;
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    44
begin
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    45
lastStr:= (lastStr + 1) mod (MaxStrIndex + 1);
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    46
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    47
TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(s), w, h);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    48
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    49
resSurface:= SDL_CreateRGBSurface(0,
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    50
		toPowerOf2(w + 2),
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    51
		toPowerOf2(h + 2),
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    52
		32,
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    53
		RMask, GMask, BMask, AMask);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    54
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    55
strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $202020);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    56
r.x:= 1;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    57
r.y:= 1;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    58
SDL_UpperBlit(strSurface, nil, resSurface, @r);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    59
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    60
strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    61
SDL_UpperBlit(strSurface, nil, resSurface, nil);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    62
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    63
SDL_FreeSurface(strSurface);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    64
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    65
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    66
Strs[lastStr].Time:= RealTicks + 7500;
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    67
Strs[lastStr].Tex:= Surface2Tex(resSurface);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    68
SDL_FreeSurface(resSurface);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    69
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    70
inc(visibleCount)
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    71
end;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    72
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    73
procedure DrawChat;
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    74
var i, t, cnt: Longword;
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    75
begin
945
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    76
cnt:= 0;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    77
t:= 0;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    78
i:= lastStr;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    79
while (t <= MaxStrIndex)
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    80
	and (Strs[i].Tex <> nil)
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    81
	and (Strs[i].Time > RealTicks) do
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    82
	begin
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    83
	DrawTexture(8, (visibleCount - t) * 16 - 8, Strs[i].Tex);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    84
	if i = 0 then i:= MaxStrIndex else dec(i);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    85
	inc(cnt);
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    86
	inc(t)
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    87
	end;
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    88
4ead9cde4e14 - Start chat implementation: chat strings are on the screen
unc0rr
parents: 942
diff changeset
    89
visibleCount:= cnt
942
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    90
end;
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    91
b41af014d85e Stub for chat implementation
unc0rr
parents:
diff changeset
    92
end.