Ignore:
Timestamp:
Jan 7, 2017, 11:32:14 AM (8 years ago)
Author:
chronos
Message:
  • Modified: Formated all project source files using Delphi formatter as original indentation and other formatting was really bad.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/MessgEx.pas

    r2 r6  
    11{$INCLUDE switches}
    2 
    32unit MessgEx;
    43
     
    65
    76uses
    8   Messg,Protocol,ScreenTools,
    9 
    10   Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,ButtonA,
     7  Messg, Protocol, ScreenTools,
     8
     9  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ButtonA,
    1110  ButtonB, ButtonBase, StdCtrls;
    1211
     
    1817    RemoveBtn: TButtonB;
    1918    EInput: TEdit;
    20     procedure FormCreate(Sender:TObject);
    21     procedure FormPaint(Sender:TObject);
     19    procedure FormCreate(Sender: TObject);
     20    procedure FormPaint(Sender: TObject);
    2221    procedure FormShow(Sender: TObject);
    2322    procedure Button1Click(Sender: TObject);
     
    3029    Kind, IconKind, IconIndex, HelpKind, HelpNo, CenterTo: integer;
    3130    OpenSound: string;
    32     function ShowModal: Integer; override;
     31    function ShowModal: integer; override;
    3332    procedure CancelMovie;
    3433  private
    3534    MovieCancelled: boolean;
    36     procedure PaintBook(ca: TCanvas; x,y,clPage,clCover: integer);
     35    procedure PaintBook(ca: TCanvas; x, y, clPage, clCover: integer);
    3736    procedure PaintMyArmy;
    3837    procedure PaintEnemyArmy;
    39     procedure OnPlaySound(var Msg:TMessage); message WM_PLAYSOUND;
     38    procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND;
    4039  end;
    4140
    4241const
    43 // extra message kinds
    44 mkYesNoCancel=4; mkOkCancelRemove=5; mkOkHelp=6; mkModel=7;
    45 
    46 
    47 //message icon kinds
    48 mikNone=-1; mikImp=0; mikModel=1; mikTribe=2; mikBook=3; mikAge=4;
    49 mikPureIcon=5; mikMyArmy=6; mikEnemyArmy=7; mikFullControl=8; mikShip=9;
    50 mikBigIcon=10; mikEnemyShipComplete=11;
    51 
    52 
    53 var
    54   MessgExDlg:TMessgExDlg;
     42  // extra message kinds
     43  mkYesNoCancel = 4;
     44  mkOkCancelRemove = 5;
     45  mkOkHelp = 6;
     46  mkModel = 7;
     47
     48  // message icon kinds
     49  mikNone = -1;
     50  mikImp = 0;
     51  mikModel = 1;
     52  mikTribe = 2;
     53  mikBook = 3;
     54  mikAge = 4;
     55  mikPureIcon = 5;
     56  mikMyArmy = 6;
     57  mikEnemyArmy = 7;
     58  mikFullControl = 8;
     59  mikShip = 9;
     60  mikBigIcon = 10;
     61  mikEnemyShipComplete = 11;
     62
     63var
     64  MessgExDlg: TMessgExDlg;
    5565
    5666procedure SoundMessageEx(SimpleText, SoundItem: string);
    5767procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
    58 function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string):
    59   integer;
    60 procedure ContextMessage(SimpleText, SoundItem: string; ContextKind,
    61   ContextNo: integer);
    62 
     68function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string)
     69  : integer;
     70procedure ContextMessage(SimpleText, SoundItem: string;
     71  ContextKind, ContextNo: integer);
    6372
    6473implementation
    6574
    6675uses
    67 ClientTools,BaseWin,Term,Help, Select, Diplomacy, Inp, UnitStat, Tribes,
    68 IsoEngine,Diagram;
     76  ClientTools, BaseWin, Term, Help, Select, Diplomacy, Inp, UnitStat, Tribes,
     77  IsoEngine, Diagram;
    6978
    7079{$R *.DFM}
    7180
    7281const
    73 LostUnitsPerLine=6;
    74 
    75 var
    76 PerfFreq: int64;
    77 
    78 
    79 procedure TMessgExDlg.FormCreate(Sender:TObject);
    80 begin
    81 inherited;
    82 IconKind:=mikNone;
    83 CenterTo:=0;
    84 OpenSound:='';
     82  LostUnitsPerLine = 6;
     83
     84var
     85  PerfFreq: int64;
     86
     87procedure TMessgExDlg.FormCreate(Sender: TObject);
     88begin
     89  inherited;
     90  IconKind := mikNone;
     91  CenterTo := 0;
     92  OpenSound := '';
    8593end;
    8694
    8795procedure TMessgExDlg.FormShow(Sender: TObject);
    8896var
    89 i: integer;
    90 begin
    91 if IconKind=mikEnemyArmy then
    92   InitAllEnemyModels;
    93 
    94 Button1.Visible:= GameMode<>cMovie;
    95 Button2.Visible:= (GameMode<>cMovie) and (Kind<>mkOk);
    96 Button3.Visible:= (GameMode<>cMovie) and (Kind=mkYesNoCancel);
    97 RemoveBtn.Visible:= (GameMode<>cMovie) and (Kind=mkOkCancelRemove);
    98 EInput.Visible:= (GameMode<>cMovie) and (Kind=mkModel);
    99 if Button3.Visible then
    100   begin Button1.Left:=43; Button2.Left:=159; end
    101 else if Button2.Visible then
    102   begin Button1.Left:=101; Button2.Left:=217; end
    103 else Button1.Left:=159;
    104 RemoveBtn.Left:=ClientWidth-38;
    105 case Kind of
    106   mkYesNo, mkYesNoCancel:
     97  i: integer;
     98begin
     99  if IconKind = mikEnemyArmy then
     100    InitAllEnemyModels;
     101
     102  Button1.Visible := GameMode <> cMovie;
     103  Button2.Visible := (GameMode <> cMovie) and (Kind <> mkOk);
     104  Button3.Visible := (GameMode <> cMovie) and (Kind = mkYesNoCancel);
     105  RemoveBtn.Visible := (GameMode <> cMovie) and (Kind = mkOkCancelRemove);
     106  EInput.Visible := (GameMode <> cMovie) and (Kind = mkModel);
     107  if Button3.Visible then
     108  begin
     109    Button1.Left := 43;
     110    Button2.Left := 159;
     111  end
     112  else if Button2.Visible then
     113  begin
     114    Button1.Left := 101;
     115    Button2.Left := 217;
     116  end
     117  else
     118    Button1.Left := 159;
     119  RemoveBtn.Left := ClientWidth - 38;
     120  case Kind of
     121    mkYesNo, mkYesNoCancel:
     122      begin
     123        Button1.Caption := Phrases.Lookup('BTN_YES');
     124        Button2.Caption := Phrases.Lookup('BTN_NO')
     125      end;
     126    mkOKCancel, mkOkCancelRemove:
     127      begin
     128        Button1.Caption := Phrases.Lookup('BTN_OK');
     129        Button2.Caption := Phrases.Lookup('BTN_CANCEL');
     130      end;
     131  else
    107132    begin
    108     Button1.Caption:=Phrases.Lookup('BTN_YES');
    109     Button2.Caption:=Phrases.Lookup('BTN_NO')
     133      Button1.Caption := Phrases.Lookup('BTN_OK');
     134      Button2.Caption := Phrases.Lookup('BTN_INFO');
    110135    end;
    111   mkOKCancel, mkOkCancelRemove:
     136  end;
     137  Button3.Caption := Phrases.Lookup('BTN_CANCEL');
     138  RemoveBtn.Hint := Phrases.Lookup('BTN_DELGAME');
     139
     140  case IconKind of
     141    mikImp, mikModel, mikAge, mikPureIcon:
     142      TopSpace := 56;
     143    mikBigIcon:
     144      TopSpace := 152;
     145    mikEnemyShipComplete:
     146      TopSpace := 136;
     147    mikBook:
     148      if IconIndex >= 0 then
     149        TopSpace := 84
     150      else
     151        TopSpace := 47;
     152    mikTribe:
     153      begin
     154        Tribe[IconIndex].InitAge(GetAge(IconIndex));
     155        if Tribe[IconIndex].faceHGr >= 0 then
     156          TopSpace := 64
     157      end;
     158    mikFullControl:
     159      TopSpace := 80;
     160    mikShip:
     161      TopSpace := 240;
     162  else
     163    TopSpace := 0;
     164  end;
     165
     166  SplitText(true);
     167  ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
     168  if GameMode = cMovie then
     169    ClientHeight := ClientHeight - 32;
     170  if Kind = mkModel then
     171    ClientHeight := ClientHeight + 36;
     172  if IconKind in [mikMyArmy, mikEnemyArmy] then
     173  begin
     174    if nLostArmy > LostUnitsPerLine * 6 then
     175      ClientHeight := ClientHeight + 6 * 48
     176    else
     177      ClientHeight := ClientHeight + ((nLostArmy - 1) div LostUnitsPerLine
     178        + 1) * 48;
     179  end;
     180  case CenterTo of
     181    0:
     182      begin
     183        Left := (Screen.Width - ClientWidth) div 2;
     184        Top := (Screen.Height - ClientHeight) div 2 - MapCenterUp;
     185      end;
     186    1:
     187      begin
     188        Left := (Screen.Width - ClientWidth) div 4;
     189        Top := (Screen.Height - ClientHeight) * 2 div 3 - MapCenterUp;
     190      end;
     191    -1:
     192      begin
     193        Left := (Screen.Width - ClientWidth) div 4;
     194        Top := (Screen.Height - ClientHeight) div 3 - MapCenterUp;
     195      end;
     196  end;
     197  for i := 0 to ControlCount - 1 do
     198    Controls[i].Top := ClientHeight - (34 + Border);
     199  if Kind = mkModel then
     200    EInput.Top := ClientHeight - (76 + Border);
     201end;
     202
     203function TMessgExDlg.ShowModal: integer;
     204var
     205  Ticks0, Ticks: int64;
     206begin
     207  if GameMode = cMovie then
     208  begin
     209    if not((GameMode = cMovie) and (MovieSpeed = 4)) then
    112210    begin
    113     Button1.Caption:=Phrases.Lookup('BTN_OK');
    114     Button2.Caption:=Phrases.Lookup('BTN_CANCEL');
     211      MovieCancelled := false;
     212      Show;
     213      QueryPerformanceCounter(Ticks0);
     214      repeat
     215        Application.ProcessMessages;
     216        Sleep(1);
     217        QueryPerformanceCounter(Ticks);
     218      until MovieCancelled or ((Ticks - Ticks0) * 1000 >= 1500 * PerfFreq);
     219      Hide;
    115220    end;
    116   else
     221    result := mrOk;
     222  end
     223  else
     224    result := inherited ShowModal;
     225end;
     226
     227procedure TMessgExDlg.CancelMovie;
     228begin
     229  MovieCancelled := true;
     230end;
     231
     232procedure TMessgExDlg.PaintBook(ca: TCanvas; x, y, clPage, clCover: integer);
     233const
     234  xScrewed = 77;
     235  yScrewed = 10;
     236  wScrewed = 43;
     237  hScrewed = 27;
     238type
     239  TLine = array [0 .. 9999, 0 .. 2] of Byte;
     240var
     241  ix, iy, xDst, yDst, dx, dy, xIcon, yIcon, xb, yb, wb, hb: integer;
     242  x1, xR, yR, share: single;
     243  Screwed: array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of single;
     244  SrcLine: ^TLine;
     245
     246begin
     247  if IconIndex >= 0 then
     248  begin
     249    xIcon := IconIndex mod 7 * xSizeBig;
     250    yIcon := (IconIndex + SystemIconLines * 7) div 7 * ySizeBig;
     251    // prepare screwed icon
     252    fillchar(Screwed, sizeof(Screwed), 0);
     253    for iy := 0 to 39 do
    117254    begin
    118     Button1.Caption:=Phrases.Lookup('BTN_OK');
    119     Button2.Caption:=Phrases.Lookup('BTN_INFO');
     255      SrcLine := BigImp.ScanLine[iy + yIcon];
     256      for ix := 0 to 55 do
     257      begin
     258        xR := ix * (37 + iy * 5 / 40) / 56;
     259        xDst := Trunc(xR);
     260        xR := Frac(xR);
     261        x1 := (120 - ix) * (120 - ix) - 10000;
     262        yR := iy * 18 / 40 + x1 * x1 / 4000000;
     263        yDst := Trunc(yR);
     264        yR := Frac(yR);
     265        for dx := 0 to 1 do
     266          for dy := 0 to 1 do
     267          begin
     268            if dx = 0 then
     269              share := 1 - xR
     270            else
     271              share := xR;
     272            if dy = 0 then
     273              share := share * (1 - yR)
     274            else
     275              share := share * yR;
     276            Screwed[xDst + dx, yDst + dy, 0] := Screwed[xDst + dx, yDst + dy, 0]
     277              + share * SrcLine[ix + xIcon, 0];
     278            Screwed[xDst + dx, yDst + dy, 1] := Screwed[xDst + dx, yDst + dy, 1]
     279              + share * SrcLine[ix + xIcon, 1];
     280            Screwed[xDst + dx, yDst + dy, 2] := Screwed[xDst + dx, yDst + dy, 2]
     281              + share * SrcLine[ix + xIcon, 2];
     282            Screwed[xDst + dx, yDst + dy, 3] := Screwed[xDst + dx, yDst + dy,
     283              3] + share;
     284          end
     285      end;
    120286    end;
    121   end;
    122 Button3.Caption:=Phrases.Lookup('BTN_CANCEL');
    123 RemoveBtn.Hint:=Phrases.Lookup('BTN_DELGAME');
    124 
    125 case IconKind of
    126   mikImp,mikModel,mikAge,mikPureIcon:
    127     TopSpace:=56;
    128   mikBigIcon:
    129     TopSpace:=152;
    130   mikEnemyShipComplete:
    131     TopSpace:=136;
    132   mikBook:
    133     if IconIndex>=0 then TopSpace:=84
    134     else TopSpace:=47;
    135   mikTribe:
     287    xb := xBBook;
     288    yb := yBBook;
     289    wb := wBBook;
     290    hb := hBBook;
     291  end
     292  else
     293  begin
     294    xb := xSBook;
     295    yb := ySBook;
     296    wb := wSBook;
     297    hb := hSBook;
     298  end;
     299  x := x - wb div 2;
     300
     301  // paint
     302  BitBlt(LogoBuffer.Canvas.Handle, 0, 0, wb, hb, ca.Handle, x, y, SRCCOPY);
     303
     304  if IconIndex >= 0 then
     305    for iy := 0 to hScrewed - 1 do
     306      for ix := 0 to wScrewed - 1 do
     307        if Screwed[ix, iy, 3] > 0.01 then
     308          LogoBuffer.Canvas.Pixels[xScrewed + ix, yScrewed + iy] :=
     309            Trunc(Screwed[ix, iy, 2] / Screwed[ix, iy, 3]) +
     310            Trunc(Screwed[ix, iy, 1] / Screwed[ix, iy, 3]) shl 8 +
     311            Trunc(Screwed[ix, iy, 0] / Screwed[ix, iy, 3]) shl 16;
     312
     313  ImageOp_BCC(LogoBuffer, Templates, 0, 0, xb, yb, wb, hb, clCover, clPage);
     314
     315  BitBlt(ca.Handle, x, y, wb, hb, LogoBuffer.Canvas.Handle, 0, 0, SRCCOPY);
     316end;
     317
     318procedure TMessgExDlg.PaintMyArmy;
     319begin
     320end;
     321
     322procedure TMessgExDlg.PaintEnemyArmy;
     323var
     324  emix, ix, iy, x, y, count, UnitsInLine: integer;
     325begin
     326  ix := 0;
     327  iy := 0;
     328  if nLostArmy > LostUnitsPerLine then
     329    UnitsInLine := LostUnitsPerLine
     330  else
     331    UnitsInLine := nLostArmy;
     332  for emix := 0 to MyRO.nEnemyModel - 1 do
     333    for count := 0 to LostArmy[emix] - 1 do
    136334    begin
    137     Tribe[IconIndex].InitAge(GetAge(IconIndex));
    138     if Tribe[IconIndex].faceHGr>=0 then
    139       TopSpace:=64
    140     end;
    141   mikFullControl:
    142     TopSpace:=80; 
    143   mikShip:
    144     TopSpace:=240;
    145   else TopSpace:=0;
    146   end;
    147 
    148 SplitText(true);
    149 ClientHeight:=72+Border+TopSpace+Lines*MessageLineSpacing;
    150 if GameMode=cMovie then ClientHeight:=ClientHeight-32;
    151 if Kind=mkModel then
    152   ClientHeight:=ClientHeight+36;
    153 if IconKind in [mikMyArmy,mikEnemyArmy] then
    154   begin
    155   if nLostArmy>LostUnitsPerLine*6 then ClientHeight:=ClientHeight+6*48
    156   else ClientHeight:=ClientHeight+((nLostArmy-1) div LostUnitsPerLine +1)*48;
    157   end;
    158 case CenterTo of
    159   0:
    160     begin
    161     Left:=(Screen.Width-ClientWidth) div 2;
    162     Top:=(Screen.Height-ClientHeight) div 2-MapCenterUp;
    163     end;
    164   1:
    165     begin
    166     Left:=(Screen.Width-ClientWidth) div 4;
    167     Top:=(Screen.Height-ClientHeight)*2 div 3-MapCenterUp;
    168     end;
    169   -1:
    170     begin
    171     Left:=(Screen.Width-ClientWidth) div 4;
    172     Top:=(Screen.Height-ClientHeight) div 3-MapCenterUp;
    173     end;
    174   end;
    175 for i:=0 to ControlCount-1 do
    176   Controls[i].Top:=ClientHeight-(34+Border);
    177 if Kind=mkModel then
    178   EInput.Top:=ClientHeight-(76+Border);
    179 end;
    180 
    181 function TMessgExDlg.ShowModal: Integer;
    182 var
    183 Ticks0,Ticks: int64;
    184 begin
    185 if GameMode=cMovie then
    186   begin
    187   if not ((GameMode=cMovie) and (MovieSpeed=4)) then
    188     begin
    189     MovieCancelled:=false;
    190     Show;
    191     QueryPerformanceCounter(Ticks0);
    192     repeat
    193       Application.ProcessMessages;
    194       Sleep(1);
    195       QueryPerformanceCounter(Ticks);
    196     until MovieCancelled or ((Ticks-Ticks0)*1000>=1500*PerfFreq);
    197     Hide;
    198     end;
    199   result:=mrOk;
    200   end
    201 else
    202   result:=inherited ShowModal;
    203 end;
    204 
    205 procedure TMessgExDlg.CancelMovie;
    206 begin
    207 MovieCancelled:=true;
    208 end;
    209 
    210 procedure TMessgExDlg.PaintBook(ca: TCanvas; x,y,clPage,clCover: integer);
    211 const
    212 xScrewed=77; yScrewed=10; wScrewed=43; hScrewed=27;
    213 type
    214 TLine=array[0..9999,0..2] of Byte;
    215 var
    216 ix,iy,xDst,yDst,dx,dy,xIcon,yIcon,xb,yb,wb,hb: integer;
    217 x1,xR,yR,share: single;
    218 Screwed: array[0..wScrewed-1,0..hScrewed-1,0..3] of single;
    219 SrcLine: ^TLine;
    220 
    221 begin
    222 if IconIndex>=0 then
    223   begin
    224   xIcon:=IconIndex mod 7*xSizeBig;
    225   yIcon:=(IconIndex+SystemIconLines*7) div 7*ySizeBig;
    226   // prepare screwed icon
    227   fillchar(Screwed,sizeof(Screwed),0);
    228   for iy:=0 to 39 do
    229     begin
    230     SrcLine:=BigImp.ScanLine[iy+yIcon];
    231     for ix:=0 to 55 do
    232       begin
    233       xR:=ix*(37+iy*5/40)/56;
    234       xDst:=Trunc(xR);
    235       xR:=Frac(xR);
    236       x1:=(120-ix)*(120-ix)-10000;
    237       yR:=iy*18/40 +x1*x1/4000000;
    238       yDst:=Trunc(yR);
    239       yR:=Frac(yR);
    240       for dx:=0 to 1 do for dy:=0 to 1 do
    241         begin
    242         if dx=0 then share:=1-xR else share:=xR;
    243         if dy=0 then share:=share*(1-yR) else share:=share*yR;
    244         Screwed[xDst+dx,yDst+dy,0]:=
    245           Screwed[xDst+dx,yDst+dy,0]+share*SrcLine[ix+xIcon,0];
    246         Screwed[xDst+dx,yDst+dy,1]:=
    247           Screwed[xDst+dx,yDst+dy,1]+share*SrcLine[ix+xIcon,1];
    248         Screwed[xDst+dx,yDst+dy,2]:=
    249           Screwed[xDst+dx,yDst+dy,2]+share*SrcLine[ix+xIcon,2];
    250         Screwed[xDst+dx,yDst+dy,3]:=
    251           Screwed[xDst+dx,yDst+dy,3]+share;
    252         end
    253       end;
    254     end;
    255   xb:=xBBook; yb:=yBBook; wb:=wBBook; hb:=hBBook;
    256   end
    257 else begin xb:=xSBook; yb:=ySBook; wb:=wSBook; hb:=hSBook; end;
    258 x:=x-wb div 2;
    259 
    260 // paint
    261 BitBlt(LogoBuffer.Canvas.Handle,0,0,wb,hb,ca.handle,x,y,SRCCOPY);
    262 
    263 if IconIndex>=0 then
    264   for iy:=0 to hScrewed-1 do for ix:=0 to wScrewed-1 do
    265     if Screwed[ix,iy,3]>0.01 then
    266     LogoBuffer.Canvas.Pixels[xScrewed+ix,yScrewed+iy]:=
    267       trunc(Screwed[ix,iy,2]/Screwed[ix,iy,3])
    268       +trunc(Screwed[ix,iy,1]/Screwed[ix,iy,3]) shl 8
    269       +trunc(Screwed[ix,iy,0]/Screwed[ix,iy,3]) shl 16;
    270 
    271 ImageOp_BCC(LogoBuffer,Templates,0,0,xb,yb,wb,hb,clCover,clPage);
    272 
    273 BitBlt(ca.handle,x,y,wb,hb,LogoBuffer.Canvas.Handle,0,0,SRCCOPY);
    274 end;
    275 
    276 procedure TMessgExDlg.PaintMyArmy;
    277 begin
    278 end;
    279 
    280 procedure TMessgExDlg.PaintEnemyArmy;
    281 var
    282 emix,ix,iy,x,y,count,UnitsInLine: integer;
    283 begin
    284 ix:=0;
    285 iy:=0;
    286 if nLostArmy>LostUnitsPerLine then
    287   UnitsInLine:=LostUnitsPerLine
    288 else UnitsInLine:=nLostArmy;
    289 for emix:=0 to MyRO.nEnemyModel-1 do
    290   for count:=0 to LostArmy[emix]-1 do
    291     begin
    292     x:=ClientWidth div 2+ix*64-UnitsInLine*32;
    293     y:=26+Border+TopSpace+Lines*MessageLineSpacing+iy*48;
    294     with MyRO.EnemyModel[emix],Tribe[Owner].ModelPicture[mix] do
    295       begin
    296       BitBlt(Canvas.Handle,x,y,64,48,GrExt[HGr].Mask.Canvas.Handle,
    297         pix mod 10 *65+1,pix div 10 *49+1,SRCAND);
    298       BitBlt(Canvas.Handle,x,y,64,48,GrExt[HGr].Data.Canvas.Handle,
    299         pix mod 10 *65+1,pix div 10 *49+1,SRCPAINT);
    300       end; 
    301 
    302     // next position
    303     inc(ix);
    304     if ix=LostUnitsPerLine then
     335      x := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
     336      y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
     337      with MyRO.EnemyModel[emix], Tribe[Owner].ModelPicture[mix] do
     338      begin
     339        BitBlt(Canvas.Handle, x, y, 64, 48, GrExt[HGr].Mask.Canvas.Handle,
     340          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND);
     341        BitBlt(Canvas.Handle, x, y, 64, 48, GrExt[HGr].Data.Canvas.Handle,
     342          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCPAINT);
     343      end;
     344
     345      // next position
     346      inc(ix);
     347      if ix = LostUnitsPerLine then
    305348      begin // next line
    306       ix:=0;
    307       inc(iy);
    308       if iy=6 then
    309         exit;
    310       UnitsInLine:=nLostArmy-LostUnitsPerLine*iy;
    311       if UnitsInLine>LostUnitsPerLine then
    312         UnitsInLine:=LostUnitsPerLine;
     349        ix := 0;
     350        inc(iy);
     351        if iy = 6 then
     352          exit;
     353        UnitsInLine := nLostArmy - LostUnitsPerLine * iy;
     354        if UnitsInLine > LostUnitsPerLine then
     355          UnitsInLine := LostUnitsPerLine;
    313356      end
    314357    end;
    315358end;
    316359
    317 procedure TMessgExDlg.FormPaint(Sender:TObject);
    318 var
    319 p1,clSaveTextLight,clSaveTextShade: integer;
    320 begin
    321 if (IconKind=mikImp) and (IconIndex=27) then
     360procedure TMessgExDlg.FormPaint(Sender: TObject);
     361var
     362  p1, clSaveTextLight, clSaveTextShade: integer;
     363begin
     364  if (IconKind = mikImp) and (IconIndex = 27) then
    322365  begin // "YOU WIN" message
    323   clSaveTextLight:=MainTexture.clTextLight;
    324   clSaveTextShade:=MainTexture.clTextShade;
    325   MainTexture.clTextLight:=$000000; // gold
    326   MainTexture.clTextShade:=$0FDBFF;
    327   inherited;
    328   MainTexture.clTextLight:=clSaveTextLight;
    329   MainTexture.clTextShade:=clSaveTextShade;
    330   end
    331 else
    332   inherited;
    333 
    334 case IconKind of
    335   mikImp:
    336     if Imp[IconIndex].Kind=ikWonder then
    337       begin
    338       p1:=MyRO.Wonder[IconIndex].EffectiveOwner;
    339       BitBlt(Buffer.Canvas.Handle,0,0,xSizeBig+2*GlowRange,ySizeBig+2*GlowRange,
    340         Canvas.Handle,ClientWidth div 2-(28+GlowRange),24-GlowRange,SRCCOPY);
    341       BitBlt(Buffer.Canvas.Handle,GlowRange,GlowRange,xSizeBig,ySizeBig,
    342         BigImp.Canvas.Handle,IconIndex mod 7*xSizeBig,
    343         (IconIndex+SystemIconLines*7) div 7*ySizeBig,SRCCOPY);
    344       if p1<0 then
    345         GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig, $000000)
    346       else GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig,
    347         Tribe[p1].Color);
    348       BitBlt(Canvas.Handle,ClientWidth div 2-(28+GlowRange),24-GlowRange,
    349         xSizeBig+2*GlowRange,ySizeBig+2*GlowRange,Buffer.Canvas.Handle,0,0,
    350         SRCCOPY);
     366    clSaveTextLight := MainTexture.clTextLight;
     367    clSaveTextShade := MainTexture.clTextShade;
     368    MainTexture.clTextLight := $000000; // gold
     369    MainTexture.clTextShade := $0FDBFF;
     370    inherited;
     371    MainTexture.clTextLight := clSaveTextLight;
     372    MainTexture.clTextShade := clSaveTextShade;
     373  end
     374  else
     375    inherited;
     376
     377  case IconKind of
     378    mikImp:
     379      if Imp[IconIndex].Kind = ikWonder then
     380      begin
     381        p1 := MyRO.Wonder[IconIndex].EffectiveOwner;
     382        BitBlt(Buffer.Canvas.Handle, 0, 0, xSizeBig + 2 * GlowRange,
     383          ySizeBig + 2 * GlowRange, Canvas.Handle,
     384          ClientWidth div 2 - (28 + GlowRange), 24 - GlowRange, SRCCOPY);
     385        BitBlt(Buffer.Canvas.Handle, GlowRange, GlowRange, xSizeBig, ySizeBig,
     386          BigImp.Canvas.Handle, IconIndex mod 7 * xSizeBig,
     387          (IconIndex + SystemIconLines * 7) div 7 * ySizeBig, SRCCOPY);
     388        if p1 < 0 then
     389          GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig, $000000)
     390        else
     391          GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig,
     392            Tribe[p1].Color);
     393        BitBlt(Canvas.Handle, ClientWidth div 2 - (28 + GlowRange),
     394          24 - GlowRange, xSizeBig + 2 * GlowRange, ySizeBig + 2 * GlowRange,
     395          Buffer.Canvas.Handle, 0, 0, SRCCOPY);
    351396      end
    352     else ImpImage(Canvas,ClientWidth div 2-28,24,IconIndex);
    353   mikAge:
    354     begin
    355     if IconIndex=0 then
    356       ImpImage(Canvas,ClientWidth div 2-28,24,-7)
    357     else ImpImage(Canvas,ClientWidth div 2-28,24,24+IconIndex)
    358     end;
    359   mikModel:
    360     with Tribe[me].ModelPicture[IconIndex] do
    361       begin
    362       FrameImage(Canvas,BigImp,ClientWidth div 2-28,24,xSizeBig,ySizeBig,0,0);
    363       BitBlt(Canvas.Handle,ClientWidth div 2-32,20,64,44,
    364         GrExt[HGr].Mask.Canvas.Handle,pix mod 10 *65+1,pix div 10*49+1,SRCAND);
    365       BitBlt(Canvas.Handle,ClientWidth div 2-32,20,64,44,
    366         GrExt[HGr].Data.Canvas.Handle,pix mod 10 *65+1,pix div 10*49+1,SRCPAINT);
    367       end;
    368   mikBook:
    369     PaintBook(Canvas,ClientWidth div 2,24,MainTexture.clPage,MainTexture.clCover);
    370   mikTribe:
    371     if Tribe[IconIndex].faceHGr>=0 then
    372       begin
    373       Frame(Canvas,ClientWidth div 2-32-1,24-1,ClientWidth div 2+32,
    374         24+48,$000000,$000000);
    375       BitBlt(Canvas.Handle,ClientWidth div 2-32,24,64,48,
    376         GrExt[Tribe[IconIndex].faceHGr].Data.Canvas.Handle,
    377         1+Tribe[IconIndex].facepix mod 10 *65,
    378         1+Tribe[IconIndex].facepix div 10 *49, SRCCOPY)
    379       end;
    380   mikPureIcon:
    381     FrameImage(Canvas, BigImp, ClientWidth div 2-28,24,xSizeBig, ySizeBig,
    382       IconIndex mod 7*xSizeBig,
    383       IconIndex div 7*ySizeBig);
    384   mikBigIcon:
    385     FrameImage(Canvas, BigImp, ClientWidth div 2-3*28,32,xSizeBig*3, ySizeBig*3,
    386       IconIndex mod 2*3*xSizeBig,
    387       IconIndex div 2*3*ySizeBig);
    388   mikEnemyShipComplete:
    389     begin
    390     BitBlt(Buffer.Canvas.Handle,0,0,140,120,Canvas.Handle,
    391       (ClientWidth-140) div 2,24,SRCCOPY);
    392     ImageOp_BCC(Buffer,Templates,0,0,1,279,140,120,0,$FFFFFF);
    393     BitBlt(Canvas.Handle,(ClientWidth-140) div 2,24,140,
    394       120,Buffer.Canvas.Handle,0,0,SRCCOPY);
    395     end;
    396   mikMyArmy:
    397     PaintMyArmy;
    398   mikEnemyArmy:
    399     PaintEnemyArmy;
    400   mikFullControl:
    401     Sprite(Canvas,HGrSystem2,ClientWidth div 2-31,24,63,63,1,281);
    402   mikShip:
    403     PaintColonyShip(Canvas,IconIndex,17,ClientWidth-34,38);
    404   end;
    405 
    406 if EInput.Visible then EditFrame(Canvas,EInput.BoundsRect,MainTexture);
    407 
    408 if OpenSound<>'' then PostMessage(Handle, WM_PLAYSOUND, 0, 0);
    409 end; {FormPaint}
     397      else
     398        ImpImage(Canvas, ClientWidth div 2 - 28, 24, IconIndex);
     399    mikAge:
     400      begin
     401        if IconIndex = 0 then
     402          ImpImage(Canvas, ClientWidth div 2 - 28, 24, -7)
     403        else
     404          ImpImage(Canvas, ClientWidth div 2 - 28, 24, 24 + IconIndex)
     405      end;
     406    mikModel:
     407      with Tribe[me].ModelPicture[IconIndex] do
     408      begin
     409        FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig,
     410          ySizeBig, 0, 0);
     411        BitBlt(Canvas.Handle, ClientWidth div 2 - 32, 20, 64, 44,
     412          GrExt[HGr].Mask.Canvas.Handle, pix mod 10 * 65 + 1,
     413          pix div 10 * 49 + 1, SRCAND);
     414        BitBlt(Canvas.Handle, ClientWidth div 2 - 32, 20, 64, 44,
     415          GrExt[HGr].Data.Canvas.Handle, pix mod 10 * 65 + 1,
     416          pix div 10 * 49 + 1, SRCPAINT);
     417      end;
     418    mikBook:
     419      PaintBook(Canvas, ClientWidth div 2, 24, MainTexture.clPage,
     420        MainTexture.clCover);
     421    mikTribe:
     422      if Tribe[IconIndex].faceHGr >= 0 then
     423      begin
     424        Frame(Canvas, ClientWidth div 2 - 32 - 1, 24 - 1,
     425          ClientWidth div 2 + 32, 24 + 48, $000000, $000000);
     426        BitBlt(Canvas.Handle, ClientWidth div 2 - 32, 24, 64, 48,
     427          GrExt[Tribe[IconIndex].faceHGr].Data.Canvas.Handle,
     428          1 + Tribe[IconIndex].facepix mod 10 * 65,
     429          1 + Tribe[IconIndex].facepix div 10 * 49, SRCCOPY)
     430      end;
     431    mikPureIcon:
     432      FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig, ySizeBig,
     433        IconIndex mod 7 * xSizeBig, IconIndex div 7 * ySizeBig);
     434    mikBigIcon:
     435      FrameImage(Canvas, BigImp, ClientWidth div 2 - 3 * 28, 32, xSizeBig * 3,
     436        ySizeBig * 3, IconIndex mod 2 * 3 * xSizeBig,
     437        IconIndex div 2 * 3 * ySizeBig);
     438    mikEnemyShipComplete:
     439      begin
     440        BitBlt(Buffer.Canvas.Handle, 0, 0, 140, 120, Canvas.Handle,
     441          (ClientWidth - 140) div 2, 24, SRCCOPY);
     442        ImageOp_BCC(Buffer, Templates, 0, 0, 1, 279, 140, 120, 0, $FFFFFF);
     443        BitBlt(Canvas.Handle, (ClientWidth - 140) div 2, 24, 140, 120,
     444          Buffer.Canvas.Handle, 0, 0, SRCCOPY);
     445      end;
     446    mikMyArmy:
     447      PaintMyArmy;
     448    mikEnemyArmy:
     449      PaintEnemyArmy;
     450    mikFullControl:
     451      Sprite(Canvas, HGrSystem2, ClientWidth div 2 - 31, 24, 63, 63, 1, 281);
     452    mikShip:
     453      PaintColonyShip(Canvas, IconIndex, 17, ClientWidth - 34, 38);
     454  end;
     455
     456  if EInput.Visible then
     457    EditFrame(Canvas, EInput.BoundsRect, MainTexture);
     458
     459  if OpenSound <> '' then
     460    PostMessage(Handle, WM_PLAYSOUND, 0, 0);
     461end; { FormPaint }
    410462
    411463procedure TMessgExDlg.Button1Click(Sender: TObject);
    412464begin
    413 ModalResult:=mrOK;
     465  ModalResult := mrOk;
    414466end;
    415467
    416468procedure TMessgExDlg.Button2Click(Sender: TObject);
    417469begin
    418 if Kind=mkOkHelp then
    419   HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
    420 else if Kind=mkModel then
    421   UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
    422 else ModalResult:=mrIgnore;
     470  if Kind = mkOkHelp then
     471    HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
     472  else if Kind = mkModel then
     473    UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
     474  else
     475    ModalResult := mrIgnore;
    423476end;
    424477
    425478procedure TMessgExDlg.Button3Click(Sender: TObject);
    426479begin
    427 ModalResult:=mrCancel
     480  ModalResult := mrCancel
    428481end;
    429482
    430483procedure TMessgExDlg.RemoveBtnClick(Sender: TObject);
    431484begin
    432 ModalResult:=mrNo
     485  ModalResult := mrNo
    433486end;
    434487
    435488procedure TMessgExDlg.FormKeyPress(Sender: TObject; var Key: char);
    436489begin
    437 if Key=#13 then ModalResult:=mrOK
    438 else if (Key=#27) then
    439   if Button3.Visible then ModalResult:=mrCancel
    440   else if Button2.Visible then ModalResult:=mrIgnore
     490  if Key = #13 then
     491    ModalResult := mrOk
     492  else if (Key = #27) then
     493    if Button3.Visible then
     494      ModalResult := mrCancel
     495    else if Button2.Visible then
     496      ModalResult := mrIgnore
    441497end;
    442498
     
    444500// because Messg.SoundMessage not capable of movie mode
    445501begin
    446 with MessgExDlg do
    447   begin
    448   MessgText:=SimpleText;
    449   OpenSound:=SoundItem;
    450   Kind:=mkOK;
    451   ShowModal;
     502  with MessgExDlg do
     503  begin
     504    MessgText := SimpleText;
     505    OpenSound := SoundItem;
     506    Kind := mkOk;
     507    ShowModal;
    452508  end
    453509end;
     
    455511procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
    456512begin
    457 with MessgExDlg do
    458   begin
    459   OpenSound:=SoundItem;
    460   MessgText:=SimpleText;
    461   Kind:=mkOK;
    462   IconKind:=mikTribe;
    463   IconIndex:=p;
    464   ShowModal;
    465   end;
    466 end;
    467 
    468 function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string):
    469   integer;
    470 begin
    471 with MessgExDlg do
    472   begin
    473   MessgText:=SimpleText;
    474   OpenSound:=SoundItem;
    475   Kind:=QueryKind;
    476   ShowModal;
    477   result:=ModalResult
    478   end
    479 end;
    480 
    481 procedure ContextMessage(SimpleText, SoundItem: string; ContextKind,
    482   ContextNo: integer);
    483 begin
    484 with MessgExDlg do
    485   begin
    486   MessgText:=SimpleText;
    487   OpenSound:=SoundItem;
    488   Kind:=mkOkHelp;
    489   HelpKind:=ContextKind;
    490   HelpNo:=ContextNo;
    491   ShowModal;
     513  with MessgExDlg do
     514  begin
     515    OpenSound := SoundItem;
     516    MessgText := SimpleText;
     517    Kind := mkOk;
     518    IconKind := mikTribe;
     519    IconIndex := p;
     520    ShowModal;
     521  end;
     522end;
     523
     524function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string)
     525  : integer;
     526begin
     527  with MessgExDlg do
     528  begin
     529    MessgText := SimpleText;
     530    OpenSound := SoundItem;
     531    Kind := QueryKind;
     532    ShowModal;
     533    result := ModalResult
     534  end
     535end;
     536
     537procedure ContextMessage(SimpleText, SoundItem: string;
     538  ContextKind, ContextNo: integer);
     539begin
     540  with MessgExDlg do
     541  begin
     542    MessgText := SimpleText;
     543    OpenSound := SoundItem;
     544    Kind := mkOkHelp;
     545    HelpKind := ContextKind;
     546    HelpNo := ContextNo;
     547    ShowModal;
    492548  end
    493549end;
     
    495551procedure TMessgExDlg.FormClose(Sender: TObject; var Action: TCloseAction);
    496552begin
    497 IconKind:=mikNone;
    498 CenterTo:=0;
    499 end;
    500 
    501 procedure TMessgExDlg.OnPlaySound(var Msg:TMessage);
    502 begin
    503 Play(OpenSound);
    504 OpenSound:='';
    505 end;
    506 
     553  IconKind := mikNone;
     554  CenterTo := 0;
     555end;
     556
     557procedure TMessgExDlg.OnPlaySound(var Msg: TMessage);
     558begin
     559  Play(OpenSound);
     560  OpenSound := '';
     561end;
    507562
    508563initialization
     564
    509565QueryPerformanceFrequency(PerfFreq);
    510566
    511567end.
    512 
Note: See TracChangeset for help on using the changeset viewer.