-
Notifications
You must be signed in to change notification settings - Fork 16
/
vidgfx.pp
1103 lines (940 loc) · 28.9 KB
/
vidgfx.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit vidgfx;
{
GearHead2, a roguelike mecha CRPG
Copyright (C) 2005 Joseph Hewitt
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The full text of the LGPL can be found in license.txt.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
{$LONGSTRINGS ON}
interface
uses Video,Keyboard,ui4gh,texutil,gears;
Type
vgfx_rect = Record
X,Y,W,H: Byte;
end;
vgfx_zone = Object
X_Anchor,X_Justify,W: Integer;
Y_Anchor,Y_Justify,H: Integer;
function GetRect: VGFX_Rect;
end;
RedrawProcedureType = Procedure;
Const
vg_Pen: Byte = 0; { Will be initialied to proper value below. }
{ The real values for ZONE_Console get set at initialization below. }
ZONE_Console: vgfx_rect = ( x:1; y:21; w:80; h:5 );
Console_History_Length = 240;
NormMode: TVideoMode = ( Col: 80; Row: 25; Color: True );
RightColumnWidth = 25;
ANC_Low = 0;
ANC_Mid = 1;
ANC_High = 2;
ZONE_CharGenMenu: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -25; W: 24;
Y_Anchor: ANC_Mid; Y_Justify: -3; H: 10;
);
ZONE_CharGenPrompt: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -25; W: 24;
Y_Anchor: ANC_Mid; Y_Justify: -10; H: 6;
);
ZONE_CharGenCaption: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -25; W: 24;
Y_Anchor: ANC_Mid; Y_Justify: 9; H: 2;
);
ZONE_CharGenDesc: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 74;
Y_Anchor: ANC_High; Y_Justify: -3; H: 3;
);
ZONE_CharGenChar: vgfx_zone = (
X_Anchor: ANC_Low; X_Justify: 1; W: 52;
Y_Anchor: ANC_Low; Y_Justify: 1; H: 19;
);
ZONE_Caption: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -8; W: 16;
Y_Anchor: ANC_Low; Y_Justify: 3; H: 3;
);
ZONE_Info: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: -10; H: 7;
);
ZONE_Menu: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: -2; H: 10;
);
ZONE_Menu1: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: -2; H: 5;
);
ZONE_Menu2: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: 4; H: 4;
);
ZONE_SubCaption: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: 7; H: 1;
);
ZONE_Clock: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 2; W: RightColumnWidth - 4;
Y_Anchor: ANC_Mid; Y_Justify: 8; H: 1;
);
ZONE_CharViewChar: vgfx_zone = (
X_Anchor: ANC_Low; X_Justify: 1; W: 52;
Y_Anchor: ANC_Low; Y_Justify: 1; H: 19;
);
ZONE_CharViewMenu: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: -2; H: 10;
);
ZONE_CharViewDesc: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -RightColumnWidth + 1; W: RightColumnWidth - 2;
Y_Anchor: ANC_Mid; Y_Justify: -10; H: 7;
);
ZONE_GetItemMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -16; W: 32;
Y_Anchor: ANC_Mid; Y_Justify: - 4; H: 8;
);
ZONE_ShopCaption: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 9; H: 2;
);
ZONE_ShopMsg: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 6; H: 6;
);
ZONE_ShopMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: 1; H: 7;
);
ZONE_ShopInfo: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: 5; W: 33;
Y_Anchor: ANC_Mid; Y_Justify: -9; H: 14;
);
ZONE_ItemsInfo: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: 5; W: 33;
Y_Anchor: ANC_Mid; Y_Justify: -9; H: 14;
);
ZONE_ItemsPCInfo: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: 5; W: 33;
Y_Anchor: ANC_Mid; Y_Justify: 6; H: 2;
);
ZONE_EqpMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 6; H: 6;
);
ZONE_InvMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: 1; H: 5;
);
ZONE_BackpackInstructions: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 9; H: 2;
);
ZONE_FieldHQMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -37; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 9; H: 15;
);
InteractAreaWidth = 75;
Interact_X_Justify = -37;
Interact_Y_Justify = -9;
{ The name zone includes the JobAgeGender description. }
ZONE_InteractName: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: Interact_X_Justify; W: InteractAreaWidth;
Y_Anchor: ANC_Mid; Y_Justify: Interact_Y_Justify; H: 2;
);
ZONE_InteractStatus: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: Interact_X_Justify; W: InteractAreaWidth;
Y_Anchor: ANC_Mid; Y_Justify: Interact_Y_Justify + 2; H: 1;
);
ZONE_InteractMsg: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: Interact_X_Justify; W: InteractAreaWidth;
Y_Anchor: ANC_Mid; Y_Justify: Interact_Y_Justify + 3; H: 5;
);
ZONE_InteractMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: Interact_X_Justify; W: InteractAreaWidth;
Y_Anchor: ANC_Mid; Y_Justify: Interact_Y_Justify + 8; H: 7;
);
{ *** INTERNAL USE ONLY *** }
ZONE_InteractTotal: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: Interact_X_Justify; W: InteractAreaWidth;
Y_Anchor: ANC_Mid; Y_Justify: Interact_Y_Justify; H: 15;
);
{ *** INTERNAL USE ONLY *** }
ZONE_MemoText: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 6; H: 8;
);
ZONE_MemoMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: 3; H: 3;
);
{ The SelectArenaMission display zones: }
ZONE_SAMText: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: 0; H: 5;
);
ZONE_SAMMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: -6; H: 5;
);
ZONE_UsagePrompt: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: - 8; H: 10;
);
ZONE_UsageMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: 3; H: 7;
);
{ Note that in ASCII mode, RightInfo and LeftInfo aren't to the right and left, }
{ but instead occupy the Menu1 and Menu2 zones. }
ZONE_RightInfo: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: 1; W: 20;
Y_Anchor: ANC_Low; Y_Justify: 3; H: 7;
);
ZONE_LeftInfo: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -21; W: 20;
Y_Anchor: ANC_Low; Y_Justify: 3; H: 7;
);
ZONE_WorldMap: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -13; W: 25;
Y_Anchor: ANC_Mid; Y_Justify: - 8; H: 15;
);
ZONE_MonologueInfo: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: -8; H: 1
);
ZONE_MonologueText: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: -6; H: 10
);
ZONE_ArenaPilotMenu: vgfx_zone = (
X_Anchor: ANC_Low; X_Justify: 2; W: 20;
Y_Anchor: ANC_Low; Y_Justify: 1; H: 15
);
ZONE_ArenaMechaMenu: vgfx_zone = (
X_Anchor: ANC_Low; X_Justify: 23; W: 20;
Y_Anchor: ANC_Low; Y_Justify: 1; H: 15
);
ZONE_ArenaInfo: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -34; W: 33;
Y_Anchor: ANC_Low; Y_Justify: 1; H: 10;
);
ZONE_PCStatus: vgfx_zone = (
X_Anchor: ANC_High; X_Justify: -34; W: 33;
Y_Anchor: ANC_Low; Y_Justify: 12; H: 4;
);
ZONE_Dialog: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -39; W: 80;
Y_Anchor: ANC_Low; Y_Justify: 12; H: 3;
);
ZONE_ConcertAudience: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -30; W: 60;
Y_Anchor: ANC_Mid; Y_Justify: -7; H: 2;
);
ZONE_ConcertCaption: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -30; W: 60;
Y_Anchor: ANC_Mid; Y_Justify: -4; H: 4;
);
ZONE_ConcertMenu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -30; W: 60;
Y_Anchor: ANC_Mid; Y_Justify: 1; H: 4;
);
ZONE_ConcertDesc: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -30; W: 60;
Y_Anchor: ANC_Mid; Y_Justify: 6; H: 1;
);
ZONE_Title_Screen_Top: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -15; W: 30;
Y_Anchor: ANC_Mid; Y_Justify: -10; H: 2;
);
ZONE_Title_Screen_Title: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -15; W: 30;
Y_Anchor: ANC_Mid; Y_Justify: -10; H: 1;
);
ZONE_Title_Screen_Version: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -15; W: 30;
Y_Anchor: ANC_Mid; Y_Justify: -9; H: 1;
);
ZONE_Title_Screen_Menu: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -15; W: 30;
Y_Anchor: ANC_Mid; Y_Justify: -7; H: 15;
);
{ *** STANDARD COLORS *** }
StdBlack: Byte = Black;
StdWhite: Byte = White;
MenuItem: Byte = Cyan;
MenuSelect: Byte = LightCyan;
TerrainGreen: Byte = Green;
PlayerBlue: Byte = LightBlue;
AllyPurple: Byte = LightMagenta;
EnemyRed: Byte = Red;
NeutralGrey: Byte = LightGray;
InfoGreen: Byte = Green;
InfoHiLight: Byte = LightGreen;
TextboxGrey: Byte = DarkGray;
AttackColor: Byte = LightRed;
NeutralBrown: Byte = Yellow;
BorderBlue: Byte = Blue;
MelodyYellow: Byte = Yellow;
{ STATE VARIABLES - USE WITH CAUTION }
{ External setting of these vars is not supported, but reading should }
{ be okay most of the time. }
vg_FGColor: Byte = LightGray;
vg_BGColor: Byte = Black;
vg_X: Byte = 1; { Cursor Position. }
vg_Y: Byte = 1; { Cursor Position. }
vg_Window: vgfx_rect = ( x:1 ; y:1 ; w:80 ; h:25 );
Var
Console_History: SAttPtr;
Procedure DoFlip;
Function RPGKey: Char;
Function IsMoreKey( A: Char ): Boolean;
Procedure MoreKey;
Procedure ClrZone( const Z: vgfx_Rect );
Procedure ClrScreen;
Procedure TextColor( C: Byte );
Procedure TextBackground( C: Byte );
Procedure TextOut(X,Y : Word;Const S : String);
Procedure ClipZone( Z: vgfx_rect );
Procedure MaxClipZone;
Procedure DrawGlyph( img: Char; X,Y,FG,BG: Byte );
Procedure GameMSG( msg: string; Z: vgfx_rect; C: Byte );
Procedure GameMSG( msg: string; Z: vgfx_zone; C: Byte );
Procedure CMessage( const msg: String; Z: VGFX_Rect; C: Byte );
Procedure CMessage( const msg: String; Z: VGFX_Zone; C: Byte );
Procedure RedrawConsole;
Procedure DialogMSG(msg: string);
Function MoreHighFirstLine( LList: SAttPtr ): Integer;
Procedure MoreText( LList: SAttPtr; FirstLine: Integer );
Function GetStringFromUser( const Prompt: String; Redraw: RedrawProcedureType ): String;
Procedure SetupMemoDisplay;
Procedure DrawBPBorder;
Procedure SetupFHQDisplay;
Procedure DrawGetItemBorder;
Procedure SetupInteractDisplay( C: Byte );
Procedure SetupServicesDisplay;
Procedure InfoBox( MyDest: VGFX_Rect );
Procedure InfoBox( Z: VGFX_Zone );
Procedure ClockBorder;
Procedure SetupArenaDisplay;
Procedure SetupArenaMissionMenu;
Procedure SetupConcertDisplay;
Procedure SetupTitleScreenDisplay;
implementation
Function VGFX_Zone.GetRect(): VGFX_Rect;
{ Convert the provided zone to a rect. }
var
it: VGFX_Rect;
begin
it.W := Self.W;
it.H := Self.H;
case Self.X_Anchor of
ANC_Low: it.X := 1;
ANC_Mid: it.X := ScreenColumns div 2;
ANC_High: it.X := ScreenColumns;
end;
it.X := it.X + Self.X_Justify;
case Self.Y_Anchor of
ANC_Low: it.Y := 1;
ANC_Mid: it.Y := ScreenRows div 2;
ANC_High: it.Y := ScreenRows;
end;
it.Y := it.Y + Self.Y_Justify;
GetRect := it;
end;
Procedure DoFlip;
{ Update the screen. }
begin
UpdateScreen( False );
end;
Function RawKey: Char;
{Read a keypress from the keyboard. Convert it into a form}
{that my other procedures would be willing to call useful.}
var
getit: Char;
TK: TKeyEvent;
begin
TK := TranslateKeyEvent( GetKeyEvent );
if GetKeyEventFlags( TK ) = kbASCII then begin
getit := GetKeyEventChar( TK );
end else if GetKeyEventFlags( TK ) = kbFnKey then begin
case GetKeyEventCode( TK ) of
kbdUp: getit := KeyMap[ KMC_North ].KCode; {Up Cursor Key}
kbdHome: getit := KeyMap[ KMC_NorthWest ].KCode; {Home Cursor Key}
kbdPgUp: getit := KeyMap[ KMC_NorthEast ].KCode; {PageUp Cursor Key}
kbdDown: getit := KeyMap[ KMC_South ].KCode; {Down Cursor Key}
kbdEnd: getit := KeyMap[ KMC_SouthWest ].KCode; {End Cursor Key}
kbdPgDn: getit := KeyMap[ KMC_SouthEast ].KCode; {PageDown Cursor Key}
kbdLeft: getit := KeyMap[ KMC_West ].KCode; {Left Cursor Key}
kbdRight: getit := KeyMap[ KMC_East ].KCode; {Right Cursor Key}
end;
end else begin
getit := ' ';
end;
RawKey := getit;
end;
Function RPGKey: Char;
{ Basically, call RAWKEY then convert the result. }
var
getit: Char;
begin
getit := RawKey;
case getit of
#8: getit := #27; { Convert backspace to escape. }
#10: getit := ' '; { Convert enter to space. }
#13: getit := ' '; { Convert enter to space. }
end;
RPGKey := getit;
end;
Function IsMoreKey( A: Char ): Boolean;
{ Return TRUE if A is a "more" key, that should skip to the next message in a list. }
begin
IsMoreKey := ( A = ' ' ) or ( A = #27 );
end;
Procedure MoreKey;
{ Wait for the user to press either the space bar or the ESC key. }
var
A: Char;
begin
{ Keep reading keypresses until either a space or an ESC is found. }
repeat
A := RPGKey;
until IsMoreKey( A );
end;
Function BufferPos( X,Y: Integer ): Integer;
{ Translate screen coordinates X,Y into a video buffer index. }
begin
BufferPos := (X-1)+(Y-1)*ScreenWidth;
end;
Procedure ClrZone( const Z: vgfx_Rect );
{ Clear the specified zone. }
const
ClrChar: TVideoCell = Ord(' ')+($07 shl 8);
var
X,Y,P: Integer;
begin
for X := Z.X to ( Z.X + Z.W - 1 ) do begin
for Y := Z.Y to ( Z.Y + Z.H - 1 ) do begin
P := BufferPos( X , Y );
if ( P >= 0 ) and ( P < ( ScreenWidth * ScreenHeight ) ) then VideoBuf^[ BufferPos( X , Y ) ] := ClrChar;
end;
end;
end;
Procedure ClrScreen;
{ Clear the entire screen. Yay! }
var
sz: vgfx_rect;
begin
sz.X := 1;
sz.Y := 1;
sz.H := screenheight;
sz.W := screenwidth;
ClrZone( sz );
end;
Procedure VClrEOL;
{ Clear from the current write position to the end of the current line. }
var
sz: vgfx_rect;
begin
sz.X := VG_X;
sz.Y := VG_Y;
sz.H := 1;
sz.W := screenwidth - VG_X;
if sz.W > ( vg_window.X + vg_window.W - 1 ) then sz.W := ( vg_window.X + vg_window.W - VG_X );
ClrZone( sz );
end;
Procedure CalcPen;
{ Calculate the color bit value, based on the requested FGPen and BGPen. }
begin
VG_Pen := VG_FGColor + ( VG_BGColor shl 4 );
end;
Procedure TextColor( C: Byte );
{ Set the foreground color. }
begin
VG_FGColor := C;
CalcPen;
end;
Procedure TextBackground( C: Byte );
{ Set the background color. }
begin
VG_BGColor := C;
CalcPen;
end;
Procedure TextColorBackground( FG,BG: Byte );
{ Set the foreground color. }
begin
VG_FGColor := FG;
VG_BGColor := BG;
CalcPen;
end;
Function InWindow( X , Y: Byte ): Boolean;
{ Return TRUE if X,Y is in the window, or FALSE otherwise. }
begin
InWindow := ( X >= vg_window.X ) and ( Y >= vg_window.Y ) and ( X < ( vg_window.X + vg_window.w ) ) and ( Y < ( vg_window.y + vg_window.h ) );
end;
Procedure TextOut(X,Y : Word;Const S : String);
{ Write text to the screen at the listed coordinates. This procedure }
{ was ripped more or less exactly from the FPC documentation. }
Var
P,I,M : Word;
begin
P:=((X-1)+(Y-1) * ScreenWidth);
M:=Length(S);
If ( P + M ) > ScreenWidth*ScreenHeight then M:=ScreenWidth*ScreenHeight-P;
For I:=1 to M do if InWindow( X + I - 1 , Y ) then VideoBuf^[P+I-1]:=Ord(S[i])+( VG_Pen shl 8 );
end;
Procedure ClipZone( Z: vgfx_rect );
{ Set the clipping bounds to this defined zone. }
begin
vg_window := Z;
vg_x := Z.X;
vg_y := Z.Y;
end;
Procedure VGotoXY( X,Y: Integer );
{ Set the write position to the requested coordinates. }
begin
vg_x := X;
vg_y := Y;
end;
Procedure MaxClipZone;
{ Restore the clip area to the maximum possible area. }
begin
vg_window.X := 1;
vg_window.Y := 1;
vg_window.W := ScreenColumns;
vg_Window.H := ScreenRows;
end;
Procedure DrawGlyph( img: Char; X,Y,FG,BG: Byte );
{ Draw a character at the requested location with the given foreground and }
{ background colors. }
var
I: Integer;
begin
I := ( Y-1 ) * ScreenWidth + X - 1;
if InWindow( X,Y ) and ( I < VideoBufSize ) then begin
TextColorBackground( FG , BG );
VideoBuf^[ I ] := Ord( img )+( VG_Pen shl 8 );
end;
end;
Procedure VWrite( Const S: String );
{ Write to the screen using Video. }
Var
P,I,M : Word;
begin
P:=((VG_X-1)+(VG_Y-1) * ScreenWidth);
M:=Length(S);
If ( P + M ) > ScreenWidth*ScreenHeight then M:=ScreenWidth*ScreenHeight-P;
For I:=1 to M do begin
if InWindow( vg_x , vg_y ) then begin
VideoBuf^[P+I-1]:=( Ord(S[i]) )+( VG_Pen shl 8 );
end;
Inc( vg_X );
end;
end;
Procedure VWriteln( Const S: String );
{ Write to the screen using Video. Move to the next line afterwards. }
Var
P,I,M : Word;
begin
P:=((VG_X-1)+(VG_Y-1) * ScreenWidth);
M:=Length(S);
If ( P + M ) > ScreenWidth*ScreenHeight then M:=ScreenWidth*ScreenHeight-P;
For I:=1 to M do begin
if InWindow( vg_x , vg_y ) then begin
VideoBuf^[P+I-1]:=Ord(S[i])+( VG_Pen shl 8 );
end;
Inc( vg_X );
end;
vg_X := vg_window.X;
InC( vg_y );
end;
Procedure GameMSG( msg: string; Z: vgfx_rect; C: Byte );
{Prettyprint the string MSG with color C in screen zone Z.}
var
NextWord: String;
THELine: String; {The line under construction.}
LC: Boolean; {Loop Condition.}
begin
{ CLean up the message a bit. }
DeleteWhiteSpace( msg );
TextColorBackground( C , Black );
{Clear the message area, and set clipping bounds.}
ClrZone( Z );
ClipZone( Z );
{THELine = The first word in this iteration}
THELine := ExtractWord( msg );
{Start the main processing loop.}
while TheLine <> '' do begin
{Set the LoopCondition to True.}
LC := True;
{ Start building the line. }
repeat
NextWord := ExtractWord( Msg );
if Length(THEline + ' ' + NextWord) < Z.W then
THEline := THEline + ' ' + NextWord
else
LC := False;
until (not LC) or (NextWord = '') or ( TheLine[Length(TheLine)] = #13 );
{ If the line ended due to a line break, deal with it. }
if ( TheLine[Length(TheLine)] = #13 ) then begin
{ Display the line break as a space. }
TheLine[Length(TheLine)] := ' ';
NextWord := ExtractWord( msg );
end;
{ Output the line. }
if NextWord = '' then begin
VWrite(THELine);
end else begin
VWriteLn(THELine);
end;
{ Prepare for the next iteration. }
TheLine := NextWord;
end; { while msg <> '' }
{Restore the clip window to its maximum size.}
MaxClipZone;
end;
Procedure GameMSG( msg: string; Z: vgfx_zone; C: Byte );
{ Convert the zone to a rect and send it to the above procedure. }
begin
GameMsg( msg , Z.GetRect() , C );
end;
Procedure CMessage( const msg: String; Z: VGFX_Rect; C: Byte );
{ Display MSG centered in zone Z. }
var
X,Y: Integer;
begin
{ Figure out the coordinates for centered display. }
X := Z.X + ( Z.W div 2 ) - ( Length( msg ) div 2 );
Y := Z.Y + Z.H div 2;
{ Actually do the output. }
ClrZone( Z );
ClipZone( Z );
if X < 1 then X := 1;
if Y < 1 then Y := 1;
VGotoXY( X , Y );
TextColor( C );
VWrite(msg);
MaxClipZone;
end;
Procedure CMessage( const msg: String; Z: VGFX_Zone; C: Byte );
{ Convert the zone to a rect, and print the message. }
begin
CMessage( msg , Z.GetRect() , C );
end;
Procedure RedrawConsole;
{ Draw the console to the screen. }
var
T: Integer;
N: Integer;
begin
TextColorBackground( Green , Black );
N := NumSAtts( Console_History );
ClipZone( ZONE_Console );
for t := 1 to ZONE_Console.H do begin
if ( t + N - ZONE_Console.H ) > 0 then begin
VWriteLn( RetrieveSAtt( Console_History , ( t + N - ZONE_Console.H ) )^.Info );
end else begin
VWriteLn( ' ' );
end;
end;
MaxClipZone;
end;
Procedure DialogMSG(msg: string); {not const-able}
{ Print a message in the scrolling dialog box. }
var
NextWord: String;
THELine: String; {The line under construction.}
LC: Boolean; {Loop Condition.}
SA: SAttPtr;
begin
{ CLean up the message a bit. }
DeleteWhiteSpace( msg );
msg := '> ' + msg;
{THELine = The first word in this iteration}
THELine := ExtractWord( msg );
{Start the main processing loop.}
while TheLine <> '' do begin
{Set the LoopCondition to True.}
LC := True;
{ Start building the line. }
repeat
NextWord := ExtractWord( Msg );
if Length(THEline + ' ' + NextWord) < ZONE_Console.W then
THEline := THEline + ' ' + NextWord
else
LC := False;
until (not LC) or (NextWord = '') or ( TheLine[Length(TheLine)] = #13 );
{ If the line ended due to a line break, deal with it. }
if ( TheLine[Length(TheLine)] = #13 ) then begin
{ Display the line break as a space. }
TheLine[Length(TheLine)] := ' ';
NextWord := ExtractWord( msg );
end;
{ Output the line. }
if TheLine <> '' then begin
if NumSAtts( Console_History ) >= Console_History_Length then begin
SA := Console_History;
RemoveSAtt( Console_History , SA );
end;
StoreSAtt( Console_History , TheLine );
end;
{ Prepare for the next iteration. }
TheLine := NextWord;
end; { while msg <> '' }
{ Redraw the dialog area. }
RedrawConsole;
end;
Function MoreHighFirstLine( LList: SAttPtr ): Integer;
{ Determine the highest possible FirstLine value. }
var
it: Integer;
begin
it := NumSAtts( LList ) - ( ScreenHeight - 3 );
if it < 1 then it := 1;
MoreHighFirstLine := it;
end;
Procedure MoreText( LList: SAttPtr; FirstLine: Integer );
{ Browse this text file across the majority of the screen. }
{ Clear the screen upon exiting, though restoration of the }
{ previous display is someone else's responsibility. }
Procedure DisplayTextHere;
var
CLine: SAttPtr; { Current Line }
begin
{ Error check. }
if FirstLine < 1 then FirstLine := 1
else if FirstLine > MoreHighFirstLine( LList ) then FirstLine := MoreHighFirstLine( LList );
VGotoXY( 1 , 1 );
CLine := RetrieveSATt( LList , FirstLine );
while ( VG_Y < ( ScreenHeight - 1 ) ) do begin
VClrEOL;
if CLine <> Nil then begin
vwriteln( Copy( CLine^.Info , 1 , ScreenWidth - 1 ) );
CLine := CLine^.Next;
end else begin
vwriteln( '' );
end;
end;
DoFlip;
end;
var
A: Char;
begin
ClrScreen;
VGotoXY( 1 , ScreenHeight );
TextColorBackground( LightGreen , Black );
VWrite( MsgString( 'MORETEXT_Prompt' ) );
{ Display the screen. }
TextColor( LightGray );
DisplayTextHere;
repeat
{ Get input from user. }
A := RPGKey;
{ Possibly process this input. }
if A = KeyMap[ KMC_South ].KCode then begin
Inc( FirstLine );
DisplayTextHere;
end else if A = KeyMap[ KMC_North ].KCode then begin
Dec( FirstLine );
DisplayTextHere;
end;
until ( A = #27 ) or ( A = 'Q' );
{ CLear the display area. }
ClrScreen;
end;
Function GetStringFromUser( const Prompt: String; Redraw: RedrawProcedureType ): String;
{ Does what it says. }
const
AllowableCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890()-=_+,.?"';
MaxInputLength = 39;
ZONE_TextInputFull: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: -1; H: 2;
);
ZONE_TextInputPrompt: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: -1; H: 1;
);
ZONE_TextInput: vgfx_zone = (
X_Anchor: ANC_Mid; X_Justify: -20; W: 40;
Y_Anchor: ANC_Mid; Y_Justify: 0; H: 1;
);
var
A: Char;
it: String;
begin
{ Initialize string. }
it := '';
Redraw;
InfoBox( ZONE_TextInputFull );
{ Give us a nice blinky cursor, please. }
SetCursorType( crBlock );
repeat
{ Set up the display. }
CMessage( Prompt , ZONE_TextInputPrompt , White );
CMessage( it , ZONE_TextInput , Green );
TextColor( LightGreen );
SetCursorPos( VG_X - 1 , VG_Y - 1 );
DoFlip;
A := RawKey;
if ( A = #8 ) and ( Length( it ) > 0 ) then begin
it := Copy( it , 1 , Length( it ) - 1 );
end else if ( Pos( A , AllowableCharacters ) > 0 ) and ( Length( it ) < MaxInputLength ) then begin
it := it + A;
end;
until ( A = #13 ) or ( A = #27 );
{ Get rid of the cursor, again. }
SetCursorType( crHidden );
GetStringFromUser := it;
end;
Procedure SetupMemoDisplay;
{ Draw a border for the memo browser. }
begin
InfoBox( ZONE_MemoText );
InfoBox( ZONE_MemoMenu );
end;
Procedure DrawBPBorder;
{ Draw the backpack border. }
begin
InfoBox( ZONE_EqpMenu );
InfoBox( ZONE_InvMenu );
InfoBox( ZONE_BackpackInstructions );
InfoBox( ZONE_ItemsInfo );
InfoBox( ZONE_ItemsPCInfo );
end;
Procedure SetupFHQDisplay;
{ Draw the backpack border. }
begin
InfoBox( ZONE_FieldHQMenu );
InfoBox( ZONE_BackpackInstructions );
InfoBox( ZONE_ItemsInfo );
InfoBox( ZONE_ItemsPCInfo );
end;
Procedure DrawGetItemBorder;
{ Draw the get items border. }
begin
InfoBox( ZONE_GetItemMenu );
end;
Procedure SetupInteractDisplay( C: Byte );
{ Draw the backpack border. }
begin
ClrZone( ZONE_InteractTotal.GetRect() );
InfoBox( ZONE_InteractTotal );
end;
Procedure SetupServicesDisplay;
{ Draw the display for the services interface. }
begin
InfoBox( ZONE_ShopCaption );
InfoBox( ZONE_ShopMsg );
InfoBox( ZONE_ShopMenu );
InfoBox( ZONE_ItemsInfo );
InfoBox( ZONE_ItemsPCInfo );
end;
Procedure InfoBox( MyDest: VGFX_Rect );
{ Draw a box around the specified location. }
var
X,Y: Integer;
begin
ClrZone( MyDest );
if MyDest.X > 0 then Dec( MyDest.X );
if MyDest.Y > 0 then Dec( MyDest.Y );
MyDest.W := MyDest.W + 2;
MyDest.H := MyDest.H + 2;
for X := ( MyDest.X + 1 ) to ( MyDest.X + MyDest.W - 2 ) do begin
DrawGlyph( '-' , X , MyDest.Y , BorderBlue , StdBlack );
DrawGlyph( '-' , X , MyDest.Y + MyDest.H - 1 , BorderBlue , StdBlack );
end;
for y := ( MyDest.Y + 1 ) to ( MyDest.Y + MyDest.H - 2 ) do begin
DrawGlyph( '|' , MyDest.X , Y , BorderBlue , StdBlack );