hedgewars/uCaptions.pas
author koda
Sat, 15 Jan 2011 21:32:44 +0100
branch0.9.15
changeset 4751 849740a91d36
parent 4393 883b979697e4
child 4808 7c3e5b52344a
permissions -rw-r--r--
possible fix hanging server on ctlr+w
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     1
unit uCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     2
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     3
interface
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     4
uses uTypes;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     5
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     6
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     7
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     8
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     9
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    10
procedure freeModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    11
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    12
implementation
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    13
uses uTextures, uRenderUtils, uVariables, uRender, uConsts;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    14
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    15
type TCaptionStr = record
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    16
                   Tex: PTexture;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    17
                   EndTime: LongWord;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    18
                   end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    19
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    20
    Captions: array[TCapGroup] of TCaptionStr;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    21
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    22
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    23
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    24
    if Captions[Group].Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    25
        FreeTexture(Captions[Group].Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    26
    Captions[Group].Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    27
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    28
    Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    29
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    30
    case Group of
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    31
        capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    32
    else
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    33
        Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    34
    end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    35
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    36
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    37
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    38
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    39
    grp: TCapGroup;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    40
    offset: LongInt;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    41
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    42
    {$IFDEF IPHONEOS}
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    43
    offset:= 40;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    44
    {$ELSE}
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    45
    if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    46
        offset:= 48
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    47
    else
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    48
        offset:= 8;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    49
    {$ENDIF}
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    50
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    51
    for grp:= Low(TCapGroup) to High(TCapGroup) do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    52
        with Captions[grp] do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    53
            if Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    54
            begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    55
                DrawCentered(0, offset, Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    56
                inc(offset, Tex^.h + 2);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    57
                if EndTime <= RealTicks then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    58
                begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    59
                    FreeTexture(Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    60
                    Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    61
                    EndTime:= 0
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    62
                end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    63
            end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    64
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    65
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    66
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    67
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    68
    FillChar(Captions, sizeof(Captions), 0)
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    69
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    70
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    71
procedure freeModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    72
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    73
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    74
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    75
end.