source: trunk/LocalPlayer/MessgEx.pas@ 352

Last change on this file since 352 was 352, checked in by chronos, 10 months ago
  • Modified: TTexture changed from record to class.
  • Modified: Code cleanup.
File size: 16.1 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 Assigned(Tribe[IconIndex].faceHGr) 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;
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: integer;
236 BookRect: TRect;
237 x1, xR, yR, share: single;
238 Screwed: array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of single;
239 SrcPtr: TPixelPointer;
240 Width: Integer;
241 Height: Integer;
242begin
243 Width := 56;
244 Height := 40;
245 if IconIndex >= 0 then begin
246 xIcon := IconIndex mod 7 * xSizeBig;
247 yIcon := (IconIndex + SystemIconLines * 7) div 7 * ySizeBig;
248 // prepare screwed icon
249 FillChar(Screwed, sizeof(Screwed), 0);
250 BigImp.BeginUpdate;
251 SrcPtr := PixelPointer(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));
252 for iy := 0 to ScaleToNative(Height) - 1 do begin
253 for ix := 0 to ScaleToNative(Width) - 1 do begin
254 xR := ScaleFromNative(ix) * (37 + ScaleFromNative(iy) * 5 / Height) / Width;
255 xDst := Trunc(xR);
256 xR := Frac(xR);
257 x1 := (120 - ScaleFromNative(ix)) * (120 - ScaleFromNative(ix)) - 10000;
258 yR := ScaleFromNative(iy) * 18 / Height + x1 * x1 / 4000000;
259 yDst := Trunc(yR);
260 yR := Frac(yR);
261 for dx := 0 to 1 do
262 for dy := 0 to 1 do begin
263 if dx = 0 then
264 share := 1 - xR
265 else
266 share := xR;
267 if dy = 0 then
268 share := share * (1 - yR)
269 else
270 share := share * yR;
271 Screwed[xDst + dx, yDst + dy, 0] := Screwed[xDst + dx, yDst + dy, 0]
272 + share * SrcPtr.Pixel^.B;
273 Screwed[xDst + dx, yDst + dy, 1] := Screwed[xDst + dx, yDst + dy, 1]
274 + share * SrcPtr.Pixel^.G;
275 Screwed[xDst + dx, yDst + dy, 2] := Screwed[xDst + dx, yDst + dy, 2]
276 + share * SrcPtr.Pixel^.R;
277 Screwed[xDst + dx, yDst + dy, 3] := Screwed[xDst + dx, yDst + dy,
278 3] + share;
279 end;
280 SrcPtr.NextPixel;
281 end;
282 SrcPtr.NextLine;
283 end;
284 BigImp.EndUpdate;
285 BookRect := BigBook.BoundsRect;
286 end
287 else
288 begin
289 BookRect := SmallBook.BoundsRect;
290 end;
291 x := x - BookRect.Width div 2;
292
293 // paint
294 UnshareBitmap(LogoBuffer);
295 BitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, 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.Data, Point(0, 0), BookRect, clCover, clPage);
307
308 BitBltCanvas(ca, x, y, BookRect.Width, BookRect.Height, 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, HGr.Mask.Canvas,
333 pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND);
334 BitBltCanvas(Canvas, x, y, 64, 48, 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.ColorTextLight;
360 clSaveTextShade := MainTexture.ColorTextShade;
361 MainTexture.ColorTextLight := $000000; // gold
362 MainTexture.ColorTextShade := $0FDBFF;
363 inherited;
364 MainTexture.ColorTextLight := clSaveTextLight;
365 MainTexture.ColorTextShade := 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 UnshareBitmap(Buffer);
376 BitBltCanvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange,
377 ySizeBig + 2 * GlowRange, Canvas,
378 ClientWidth div 2 - (28 + GlowRange), 24 - GlowRange);
379 BitBltCanvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig,
380 BigImp.Canvas, IconIndex mod 7 * xSizeBig,
381 (IconIndex + SystemIconLines * 7) div 7 * ySizeBig);
382 if p1 < 0 then
383 GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig, $000000)
384 else
385 GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig,
386 Tribe[p1].Color);
387 BitBltCanvas(Canvas, ClientWidth div 2 - (28 + GlowRange),
388 24 - GlowRange, xSizeBig + 2 * GlowRange, ySizeBig + 2 * GlowRange,
389 Buffer.Canvas, 0, 0);
390 end
391 else
392 ImpImage(Canvas, ClientWidth div 2 - 28, 24, IconIndex);
393 mikAge:
394 begin
395 if IconIndex = 0 then
396 ImpImage(Canvas, ClientWidth div 2 - 28, 24, -7)
397 else
398 ImpImage(Canvas, ClientWidth div 2 - 28, 24, 24 + IconIndex)
399 end;
400 mikModel:
401 with Tribe[me].ModelPicture[IconIndex] do
402 begin
403 FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig,
404 ySizeBig, 0, 0);
405 BitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
406 HGr.Mask.Canvas, pix mod 10 * 65 + 1,
407 pix div 10 * 49 + 1, SRCAND);
408 BitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
409 HGr.Data.Canvas, pix mod 10 * 65 + 1,
410 pix div 10 * 49 + 1, SRCPAINT);
411 end;
412 mikBook:
413 PaintBook(Canvas, ClientWidth div 2, 24, MainTexture.ColorPage,
414 MainTexture.ColorCover);
415 mikTribe:
416 if Assigned(Tribe[IconIndex].faceHGr) then
417 begin
418 Frame(Canvas, ClientWidth div 2 - 32 - 1, 24 - 1,
419 ClientWidth div 2 + 32, 24 + 48, $000000, $000000);
420 BitBltCanvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48,
421 Tribe[IconIndex].faceHGr.Data.Canvas,
422 1 + Tribe[IconIndex].facepix mod 10 * 65,
423 1 + Tribe[IconIndex].facepix div 10 * 49)
424 end;
425 mikPureIcon:
426 FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig, ySizeBig,
427 IconIndex mod 7 * xSizeBig, IconIndex div 7 * ySizeBig);
428 mikBigIcon:
429 FrameImage(Canvas, BigImp, ClientWidth div 2 - 3 * 28, 32, xSizeBig * 3,
430 ySizeBig * 3, IconIndex mod 2 * 3 * xSizeBig,
431 IconIndex div 2 * 3 * ySizeBig);
432 mikEnemyShipComplete:
433 begin
434 BitBltCanvas(Buffer.Canvas, 0, 0, 140, 120, Canvas,
435 (ClientWidth - 140) div 2, 24);
436 ImageOp_BCC(Buffer, Templates.Data, Point(0, 0), StarshipDeparted.BoundsRect, 0, $FFFFFF);
437 BitBltCanvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120,
438 Buffer.Canvas, 0, 0);
439 end;
440 mikMyArmy:
441 PaintMyArmy;
442 mikEnemyArmy:
443 PaintEnemyArmy;
444 mikFullControl:
445 Sprite(Canvas, HGrSystem2, ClientWidth div 2 - 31, 24, 63, 63, 1, 281);
446 mikShip:
447 PaintColonyShip(Canvas, IconIndex, 17, ClientWidth - 34, 38);
448 end;
449
450 if EInput.Visible then
451 EditFrame(Canvas, EInput.BoundsRect, MainTexture);
452
453 if OpenSound <> '' then
454 PostMessage(Handle, WM_PLAYSOUND, 0, 0);
455end;
456
457procedure TMessgExDlg.Button1Click(Sender: TObject);
458begin
459 ModalResult := mrOk;
460end;
461
462procedure TMessgExDlg.Button2Click(Sender: TObject);
463begin
464 if Kind = mkOkHelp then
465 HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
466 else if Kind = mkModel then
467 UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
468 else
469 ModalResult := mrIgnore;
470end;
471
472procedure TMessgExDlg.Button3Click(Sender: TObject);
473begin
474 ModalResult := mrCancel;
475end;
476
477procedure TMessgExDlg.RemoveBtnClick(Sender: TObject);
478begin
479 ModalResult := mrNo;
480end;
481
482procedure TMessgExDlg.FormKeyPress(Sender: TObject; var Key: char);
483begin
484 if Key = #13 then
485 ModalResult := mrOk
486 else if (Key = #27) then
487 if Button3.Visible then
488 ModalResult := mrCancel
489 else if Button2.Visible then
490 ModalResult := mrIgnore;
491end;
492
493procedure SoundMessageEx(SimpleText, SoundItem: string);
494// because Messg.SoundMessage not capable of movie mode
495begin
496 with MessgExDlg do
497 begin
498 MessgText := SimpleText;
499 OpenSound := SoundItem;
500 Kind := mkOk;
501 ShowModal;
502 end;
503end;
504
505procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
506begin
507 with MessgExDlg do
508 begin
509 OpenSound := SoundItem;
510 MessgText := SimpleText;
511 Kind := mkOk;
512 IconKind := mikTribe;
513 IconIndex := p;
514 ShowModal;
515 end;
516end;
517
518function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string)
519 : integer;
520begin
521 with MessgExDlg do
522 begin
523 MessgText := SimpleText;
524 OpenSound := SoundItem;
525 Kind := QueryKind;
526 ShowModal;
527 result := ModalResult;
528 end;
529end;
530
531procedure ContextMessage(SimpleText, SoundItem: string;
532 ContextKind, ContextNo: integer);
533begin
534 with MessgExDlg do
535 begin
536 MessgText := SimpleText;
537 OpenSound := SoundItem;
538 Kind := mkOkHelp;
539 HelpKind := ContextKind;
540 HelpNo := ContextNo;
541 ShowModal;
542 end;
543end;
544
545procedure TMessgExDlg.FormClose(Sender: TObject; var Action: TCloseAction);
546begin
547 IconKind := mikNone;
548 CenterTo := 0;
549end;
550
551procedure TMessgExDlg.OnPlaySound(var Msg: TMessage);
552begin
553 Play(OpenSound);
554 OpenSound := '';
555end;
556
557
558initialization
559
560end.
Note: See TracBrowser for help on using the repository browser.