source: tags/1.2.0/LocalPlayer/MessgEx.pas

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