-
Notifications
You must be signed in to change notification settings - Fork 4
/
mapeditor.pas
1907 lines (1653 loc) · 58.6 KB
/
mapeditor.pas
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 mapeditor;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,Types,
ComCtrls, Menus,rmthumb,mapcore,rwmap,mapexiportprops,rmcodegen,drawprocs,rmtools,rmclipboard,
rmconfig, LCLType,setcustommapsize,setcustomtilesize;
const
AddImage = 1;
InsertImage = 2;
UpdateImage = 3;
type
{ TMapEdit }
TMapEdit = class(TForm)
GroupBox1: TGroupBox;
MapImageList: TImageList;
Clear: TMenuItem;
CloneMap: TMenuItem;
CopyToClipBoard: TMenuItem;
Properties: TMenuItem;
PasteFromClipBoard: TMenuItem;
Undo: TMenuItem;
SetTileCustomSize: TMenuItem;
MenuItem15: TMenuItem;
MenuDeleteAll: TMenuItem;
ShowTileCustomSize: TMenuItem;
ShowCustomSize: TMenuItem;
SetMapCustomSize: TMenuItem;
MenuPopupNew: TMenuItem;
MenuPopupDelete: TMenuItem;
Panel1: TPanel;
RadioDraw: TRadioButton;
RadioErase: TRadioButton;
ReSizeMap256x256: TMenuItem;
ReSizeMap128x128: TMenuItem;
StatusBar1: TStatusBar;
StatusBar2: TStatusBar;
TileImageList: TImageList;
ToolPencilMenu: TMenuItem;
ToolLineMenu: TMenuItem;
ToolRectangleMenu: TMenuItem;
ToolFRectangleMenu: TMenuItem;
ToolCircleMenu: TMenuItem;
ToolFCircleMenu: TMenuItem;
ToolEllipseMenu: TMenuItem;
ToolFEllipseMenu: TMenuItem;
ToolPaintMenu: TMenuItem;
ToolSprayPaintMenu: TMenuItem;
ToolSelectAreaMenu: TMenuItem;
ToolGridMenu: TMenuItem;
ToolFlipMenu: TMenuItem;
Horizontal: TMenuItem;
Vertical: TMenuItem;
ScrollMenu: TMenuItem;
ScrollRightMenu: TMenuItem;
ScrollLeftMenu: TMenuItem;
ScrollUpMenu: TMenuItem;
ScrollDownMenu: TMenuItem;
Panel2: TPanel;
MenuItem10: TMenuItem;
ExportCArray: TMenuItem;
ExportPascalArray: TMenuItem;
MenuItem13: TMenuItem;
BasicLNMapData: TMenuItem;
MenuMapProps: TMenuItem;
MenuItem2: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
ExportBasicMapData: TMenuItem;
MenuNew: TMenuItem;
OpenDialog1: TOpenDialog;
ExportMapsPropsMenu: TPopupMenu;
MapPaintBox: TPaintBox;
SaveDialog1: TSaveDialog;
ToolCircleIcon: TImage;
ToolEllipseIcon: TImage;
ToolFCircleIcon: TImage;
ToolFEllipseIcon: TImage;
ToolFRectangleIcon: TImage;
ToolGridIcon: TImage;
ToolHFLIPButton: TButton;
ToolLineIcon: TImage;
ToolPaintIcon: TImage;
ReSize64x64: TMenuItem;
ReSize128x128: TMenuItem;
ReSize256x256: TMenuItem;
ReSizeMap64x64: TMenuItem;
MenuItem17: TMenuItem;
MenuItem19: TMenuItem;
TileModeDraw: TMenuItem;
TileModeErase: TMenuItem;
SelectedTileImage: TImage;
MainMenu1: TMainMenu;
FileMenuItem: TMenuItem;
MenuItem1: TMenuItem;
ReSize8x8: TMenuItem;
ReSize16x16: TMenuItem;
ReSize32x32: TMenuItem;
MenuSaveMap: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
ReSizeMap8x8: TMenuItem;
ReSizeMap16x16: TMenuItem;
ReSizeMap32x32: TMenuItem;
MenuItem9: TMenuItem;
TileListView: TListView;
MapListView: TListView;
SelectedTilePanel: TPanel;
LeftBottomPanel: TPanel;
MiddlePanel: TPanel;
RightPanel: TPanel;
LeftPanel: TPanel;
ToolPencilIcon: TImage;
ToolRectangleIcon: TImage;
ToolScrollDownIcon: TImage;
ToolScrollLeftIcon: TImage;
ToolScrollRightIcon: TImage;
ToolScrollUpIcon: TImage;
ToolSelectAreaIcon: TImage;
ToolSprayPaintIcon: TImage;
ToolUndoIcon: TImage;
ToolVFLIPButton: TButton;
TopMiddlePanel: TPanel;
MapScrollBox: TScrollBox;
LeftVertSplitter: TSplitter;
LeftSplitter: TSplitter;
RightSplitter: TSplitter;
TileZoom: TTrackBar;
procedure Button1Click(Sender: TObject);
procedure CheckBoxDisplayGridChange(Sender: TObject);
procedure CloneMapClick(Sender: TObject);
procedure CopyToClipBoardClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure MapImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MapImageMouseLeave(Sender: TObject);
procedure MapImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ClearMapClick(Sender: TObject);
procedure MapListViewClick(Sender: TObject);
procedure MapPaintBoxPaint(Sender: TObject);
procedure MenuDeleteAllClick(Sender: TObject);
procedure MenuDeleteClick(Sender: TObject);
procedure MenuExportBasicLNMapData(Sender: TObject);
procedure MenuExportBasicMapData(Sender: TObject);
procedure MenuExportCArray(Sender: TObject);
procedure MenuExportPascalArray(Sender: TObject);
procedure MenuMapPropsClick(Sender: TObject);
procedure MenuOpenClick(Sender: TObject);
procedure MenuNewClick(Sender: TObject);
procedure MenuSaveClick(Sender: TObject);
procedure PasteFromClipBoardClick(Sender: TObject);
procedure ReSizeMapClick(Sender: TObject);
procedure SetMapCustomSizeClick(Sender: TObject);
procedure SetTileCustomSizeClick(Sender: TObject);
procedure TileModeDrawClick(Sender: TObject);
procedure TileModeEraseClick(Sender: TObject);
procedure RadioDrawClick(Sender: TObject);
procedure RadioEraseClick(Sender: TObject);
procedure ReSizeTiles(Sender: TObject);
procedure TileListViewClick(Sender: TObject);
procedure TileZoomChange(Sender: TObject);
procedure MPaintBoxMouseDownXYX2Y2Tool(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure MPaintBoxMouseMoveXYX2Y2Tool(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure MPaintBoxMouseUpXYX2Y2Tool(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MPaintBoxMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MPaintBoxMouseUpXYTool(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MPaintBoxMouseDownXYTool(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure MPaintBoxMouseMoveXYTool(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure MPaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure MPaintBoxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ToolGridIconClick(Sender: TObject);
procedure ToolHFLIPButtonClick(Sender: TObject);
procedure ToolIconClick(Sender: TObject);
procedure ToolMenuClick(Sender: TObject);
procedure ToolScrollDownIconClick(Sender: TObject);
procedure ToolScrollLeftIconClick(Sender: TObject);
procedure ToolScrollRightIconClick(Sender: TObject);
procedure ToolScrollUpIconClick(Sender: TObject);
procedure ToolUndoIconClick(Sender: TObject);
procedure ToolVFLIPButtonClick(Sender: TObject);
private
public
hpos,vpos : integer;
CurrentMap : integer;
TileWidth : integer;
TileHeight : integer;
CTile : TileRec;
CTileBitMap : TBitMap;
TileMode : integer;
DrawTool : integer;
RenderDrawToolShape : Boolean;
FormShowActivate : boolean;
MapX,MapY,MapX2,MapY2,OldMapX,OldMapY : integer;
procedure Init;
function GetMapX(x : integer) : integer;
function GetMapY(y : integer) : integer;
procedure PlotTileAt(x,y : integer; TTile : TileRec);
procedure PlotTile(mx,my : integer; TTile : TileRec);
procedure ImageListPlotTile(mx,my : integer;var TTile : TileRec);
procedure ClearTile(mx,my : integer);
procedure PlotMissingTile(mx,my : integer);
Procedure SetMapTileMode(Tool : integer);
procedure SetDrawTool(tool : integer);
procedure APlotTile(x,y : integer;var TTile : TileRec); //convert to grid format and store on array
procedure AClearTile(x,y : integer);
procedure CPlotTile(ColX,ColY : integer;var TTile : TileRec); //draw to canvas - do not store
procedure CClearTile(ColX,ColY : integer);
Procedure DrawOverLayOnClipArea;
procedure LoadTile(index : integer);
procedure LoadTilesToTileImageList;
procedure VerifyTileImageList;
procedure UpdateTileView;
procedure UpdateCurrentTile;
procedure UpdateMapInfo(x,y : integer);
procedure UpdateInfoBarX1Y1X2Y2;
procedure UpdateMapView;
Procedure UpdateMapListView;
procedure UpdatePageSize;
procedure DrawGrid;
Procedure LoadResourceIcons;
Procedure UpdateToolSelectionIcons;
procedure ClearCheckedMenus;
procedure UpdateMenus;
procedure UpdateEditMenus;
function ExportTextFileToClipboard(Sender: TObject) : boolean;
procedure MapPreviewPlotTile(MPCanvas : TCanvas;mx,my : integer;var TTile : TileRec);
Procedure UpdateMapPreviewImageIcons(MapIndex,ImageAction : integer);
procedure DeleteAll;
end;
var
MapEdit: TMapEdit;
implementation
{$R *.lfm}
{ TMapEdit }
procedure DrawTileCB(x,y,index,mode : integer);
var
TT : TileRec;
begin
if mode = 1 then
begin
if MapEdit.TileMode = 0 then
begin
TT.ImageIndex:=TileClear;
MapCoreBase.SetMapTile(MapCoreBase.GetCurrentMap,x,y,TT);
end
else
begin
MapCoreBase.SetMapTile(MapCoreBase.GetCurrentMap,x,y,MapEdit.CTile);
end;
end
else
begin
MapEdit.ImageListPlotTile(x,y,MapEdit.CTile);
end;
end;
function GetTileTB(x,y : integer) : integer;
var
TT : TileRec;
begin
MapCoreBase.GetMapTile(MapCoreBase.GetCurrentMap,x,y,TT);
result:=TT.ImageIndex;
end;
procedure TMapEdit.FormCreate(Sender: TObject);
begin
CTileBitmap:=TBitMap.Create;
FormShowActivate:=false;
LoadResourceIcons;
SetDrawPixelProc(@DrawTileCB);
SetGetPixelProc(@GetTileTB);
Init;
end;
procedure TMapEdit.Init;
begin
SetMapTileMode(1); //draw
SetDrawTool(DrawShapePencil);
CurrentMap:=MapCoreBase.GetCurrentMap;
MapCoreBase.SetZoomSize(CurrentMap,1);
TileZoom.Position:=MapCoreBase.GetZoomSize(CurrentMap);
MapCoreBase.SetMapTileSize(CurrentMap,32,32);
TileWidth:=MapCoreBase.GetZoomMapTileWidth(CurrentMap);
TileHeight:=MapCoreBase.GetZoomMapTileHeight(CurrentMap);
CTile.ImageIndex:=TileMissing;
LoadTile(0);
MapX:=0;
MapY:=0;
MapX2:=0;
MapY2:=0;
OldMapX:=-1;
OldMapY:=-1;
RenderDrawToolShape:=False;
UpdateToolSelectionIcons;
UpdateEditMenus;
// MapCoreBase.SetCurrentMap(MapCoreBase.GetMapCount-1);
// CurrentMap:=MapCoreBase.GetCurrentMap;
TileMode:=1; //draw
MapCoreBase.SetMapTileMode(CurrentMap,TileMode); // we set to draw because the copied data from map 0 may be in erase mode
// TileZoom.Position:=4;
// MapCoreBase.SetZoomSize(CurrentMap,TileZoom.Position);
UpdateMapListView;
UpdatePageSize;
MapScrollBox.HorzScrollBar.Position:=0;
MapScrollBox.VertScrollBar.Position:=0;
SetDrawTool(DrawShapePencil);
// UpdateToolSelectionIcons;
UpdateMenus;
// UpdateEditMenus;
MapPaintBox.Invalidate;
end;
procedure TMapEdit.FormDestroy(Sender: TObject);
begin
CTileBitmap.Free;
end;
procedure TMapEdit.FormShow(Sender: TObject);
begin
LoadTilesToTileImageList;
VerifyTileImageList;
if CTile.ImageIndex = TileMissing then
begin
LoadTile(0); // first time opening MApEdit Window
end
else
begin
LoadTile(CTile.ImageIndex); // Follow ScrollUpMenu open windows - reload current tile incase it was edited
end;
UpdateCurrentTile;
UpdateMapListView;
MapPaintBox.Width:=0; //this hack updated the scrollbars properly after the 2nd and following attempts
MapPaintBox.Height:=0;
MapPaintBox.Invalidate;
MapPaintBox.Width:=MapCoreBase.GetZoomMapPageWidth(CurrentMap)+1; //do not remove the +1 - hack to display ScrollRightMenu and bottom corner of grid
MapPaintBox.Height:=MapCoreBase.GetZoomMapPageHeight(CurrentMap)+1;
MapPaintBox.Invalidate; //forces a paint which draws the map
MapScrollBox.HorzScrollBar.Position:=hpos;
MapScrollBox.VertScrollBar.Position:=vpos;
FormShowActivate:=true; //this is going to also trigger an onfocus event - letting event handler know it was because of onopen
end;
procedure TMapEdit.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
hpos:=MapScrollBox.HorzScrollBar.Position;
vpos:=MapScrollBox.VertScrollBar.Position;
end;
procedure TMapEdit.FormActivate(Sender: TObject);
begin
if FormShowActivate then
begin
FormShowActivate:=false; //next on focus will be real onfocus
end;
ImageThumbBase.CopyCoreToIndexImage(ImageThumbBase.GetCurrent);
LoadTilesToTileImageList;
VerifyTileImageList;
// if CTile.ImageIndex > (ImageThumbBase.GetCount-1) then //check if the CTile has been deleted
// begin
// CTile.ImageIndex:=0; //set it to the first tile/sprite
// end;
if ImageThumbBase.FindUID(CTile.ImageUID) = -1 then //check if current tile was deleted
begin
CTile.ImageIndex:=TileMissing;
end;
if CTile.ImageIndex = TileMissing then
begin
LoadTile(0); // first time opening MApEdit Window
end
else
begin
LoadTile(CTile.ImageIndex); // Follow ScrollUpMenu open windows - reload current tile incase it was edited
end;
UpdateCurrentTile;
UpdateTileView;
UpdateMapListView; //if new project is open or inserted - we need to update maplist view
UpdateMenus;
UpdateEditMenus;
UpdateToolSelectionIcons;
MapPaintBox.Invalidate;
end;
procedure TMapEdit.SetDrawTool(tool : integer);
begin
DrawTool:=tool;
MapCoreBase.SetMapDrawTool(MapCoreBase.GetCurrentMap,DrawTool);
end;
function TMapEdit.GetMapX(x : integer) : integer;
begin
result:=x div TileWidth;
end;
function TMapEdit.GetMapY(y : integer) : integer;
begin
result:=y div TileHeight;
end;
procedure TMapEdit.CheckBoxDisplayGridChange(Sender: TObject);
begin
MapPaintBox.Invalidate;
end;
procedure TMapEdit.CloneMapClick(Sender: TObject);
begin
MapCoreBase.CloneMap;
MapCoreBase.SetCurrentMap(MapCoreBase.GetMapCount-1);
CurrentMap:=MapCoreBase.GetCurrentMap;
UpdateMapListView;
MapScrollBox.HorzScrollBar.Position:=0;
MapScrollBox.VertScrollBar.Position:=0;
MapPaintBox.Invalidate;
ShowMessage('Map Cloned!');
end;
procedure TMapEdit.CopyToClipBoardClick(Sender: TObject);
var
ca : MapClipAreaRec;
begin
MapCoreBase.GetMapClipAreaCoords(MapCoreBase.GetCurrentMap,ca);
MapCoreBase.CopyToClipBoard(MapCoreBase.GetCurrentMap,ca.x,ca.y,ca.x2,ca.y2);
end;
procedure TMapEdit.PasteFromClipBoardClick(Sender: TObject);
var
ca : MapClipAreaRec;
begin
MapCoreBase.GetMapClipAreaCoords(MapCoreBase.GetCurrentMap,ca);
MapCoreBase.PasteFromClipboard(MapCoreBase.GetCurrentMap,ca.x,ca.y,ca.x2,ca.y2);
MapPaintBox.Invalidate;
end;
procedure TMapEdit.PlotTile(mx,my : integer; TTile : TileRec);
var
gx,gy : integer;
begin
if (mx < 0) or (my<0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit;
MapCoreBase.SetMapTile(CurrentMap,mx,my,CTile);
gx:=mx*TileWidth;
gy:=my*TileHeight;
MapPaintBox.canvas.CopyRect(Rect(gx, gy, gx+TileWidth, gy+TileHeight), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height));
end;
procedure TMapEdit.ImageListPlotTile(mx,my : integer;var TTile : TileRec);
var
gx,gy : integer;
begin
gx:=mx*TileWidth;
gy:=my*TileHeight;
TileImageList.Draw(MapPaintBox.Canvas,gx,gy,TTile.ImageIndex,true);
end;
procedure TMapEdit.ClearTile(mx,my : integer);
var
T : TileRec;
begin
if (mx < 0) or (my<0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit;
T.ImageIndex:=TileClear;
MapCoreBase.SetMapTile(CurrentMap,mx,my,T);
end;
procedure TMapEdit.PlotMissingTile(mx,my : integer);
var
gx,gy : integer;
begin
gx:=mx*TileWidth;
gy:=my*TileHeight;
//red circle on white background
MapPaintBox.Canvas.Brush.Color:=clWhite;
MapPaintBox.Canvas.FillRect(gx,gy,gx+TileWidth,gy+TileHeight);
MapPaintBox.Canvas.Brush.Color:=clRed;
MapPaintBox.Canvas.Ellipse(gx,gy,gx+TileWidth,gy+TileHeight);
end;
procedure TMapEdit.PlotTileAt(x,y : integer;TTile : TileRec);
var
mx,my : integer;
begin
mx:=x div TileWidth;
my:=y div TileHeight;
PlotTile(mx,my,TTile);
end;
procedure TMapEdit.APlotTile(x,y : integer;var TTile : TileRec);
var
mx,my : integer;
begin
mx:=(x div TileWidth);
if (mx < 0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) then exit;
my:=(y div TileHeight);
if (my<0) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit;
MapCoreBase.SetMapTile(CurrentMap,mx,my,TTile);
end;
procedure TMapEdit.AClearTile(x,y : integer);
var
mx,my : integer;
T : TileRec;
begin
mx:=(x div TileWidth);
if (mx < 0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) then exit;
my:=(y div TileHeight);
if (my<0) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit;
T.ImageIndex:=TileClear;
MapCoreBase.SetMapTile(CurrentMap,mx,my,T);
end;
//called from onpaint
procedure TMapEdit.CPlotTile(ColX,ColY : integer;var TTile : TileRec); //draw to canvas - do not store
var
gx,gy : integer;
begin
if (ColX < 0) or (ColY<0) or (ColX >= MapCoreBase.GetMapWidth(CurrentMap)) or (ColY >= MapCoreBase.GetMapHeight(CurrentMap)) then exit;
//MapCoreBase.SetMapTile(CurrentMap,mx,my,CTile);
gx:=ColX*TileWidth;
gy:=ColY*TileHeight;
MapPaintBox.canvas.CopyRect(Rect(gx, gy, gx+TileWidth, gy+TileHeight), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height));
end;
//called from onpaint
procedure TMapEdit.CClearTile(ColX,ColY : integer);
var
gx,gy : integer;
begin
if (ColX < 0) or (ColY<0) or (ColX >= MapCoreBase.GetMapWidth(CurrentMap)) or (ColY >= MapCoreBase.GetMapHeight(CurrentMap)) then exit;
gx:=ColX*TileWidth;
gy:=ColY*TileHeight;
MapPaintBox.Canvas.Brush.Color:=clBlack;
MapPaintBox.Canvas.FillRect(gx,gy,gx+TileWidth,gy+TileHeight);
end;
procedure TMapEdit.MapImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
(*
MDownLeft:=False;
MDownRight:=False;
if Button = mbRight then
begin
MDownRight:=True;
AClearTile(x,y);
end
else if Button = mbLeft then
begin
MDownLeft:=True;
if TileMode = 1 then
begin
APlotTile(x,y,CTile);
end
else if TileMode = 0 then
begin
AClearTile(x,y);
end;
end;
MapPaintbox.Invalidate
*)
end;
procedure TMapEdit.MapImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
(*MDownLeft:=False;
MDownRight:=False;
MapPaintBox.Invalidate;*)
end;
procedure TMapEdit.ClearMapClick(Sender: TObject);
begin
MapCoreBase.ClearMap(CurrentMap,TileClear);
VerifyTileImageList;
MapPaintBox.Invalidate;
UpdateMapPreviewImageIcons(CurrentMap,UpdateImage);
MapListView.Repaint;
end;
Procedure TMapEdit.DrawGrid;
var
x,y : integer;
begin
MapPaintBox.Canvas.Brush.Style:=bsClear;
MapPaintBox.Canvas.Pen.Style := psSolid;
MapPaintBox.Canvas.Pen.Mode :=pmXor;
MapPaintBox.Canvas.Pen.Width :=1;
MapPaintBox.Canvas.Pen.Color := clWhite;
x:=0;
While x <= MapPaintBox.Width do
begin
MapPaintBox.Canvas.Line(x,0,x,MapPaintBox.Height);
inc(x,TileWidth);
end;
y:=0;
While y <= MapPaintBox.Height do
begin
MapPaintBox.Canvas.Line(0,y,MapPaintBox.Width,y);
inc(y,TileHeight);
end;
MapPaintBox.Canvas.Pen.Mode :=pmCopy;
end;
Procedure TMapEdit.DrawOverLayOnClipArea;
var
ca : MapClipAreaRec;
begin
MapPaintBox.Canvas.Brush.Style:=bsClear;
MapPaintBox.Canvas.Pen.Color:=clYellow;
MapCoreBase.GetMapClipAreaCoords(MapCoreBase.GetCurrentMap,ca);
MapPaintBox.Canvas.Rectangle(ca.x*TileWidth-2,ca.y*TileHeight-2,(ca.x2+1)*TileWidth+3,(ca.y2+1)*TileHeight+3);
MapPaintBox.Canvas.Rectangle(ca.x*TileWidth-3,ca.y*TileHeight-3,(ca.x2+1)*TileWidth+4,(ca.y2+1)*TileHeight+4);
end;
procedure TMapEdit.UpdateMapView;
var
i,j : integer;
T : TileRec;
begin
for j:=0 to MapCoreBase.GetMapHeight(CurrentMap)-1 do
begin
for i:=0 to MapCoreBase.GetMapWidth(CurrentMap)-1 do
begin
MapCoreBase.GetMapTile(CurrentMap,i,j,T);
if T.ImageIndex = TileMissing then PlotMissingTile(i,j)
else if T.ImageIndex <> TileClear then ImageListPlotTile(i,j,T);
end;
end;
end;
procedure TMapEdit.MapPaintBoxPaint(Sender: TObject);
begin
UpdateMapView;
if RenderDrawToolShape then DrawItem(DrawTool,MapX,MapY,MapX2,MapY2,CTile.ImageIndex,0);
if MapCoreBase.GetMapGridStatus(MapCoreBase.GetCurrentMap) = 1 then DrawGrid;
if MapCoreBase.GetMapClipStatus(MapCoreBase.GetCurrentMap) = 1 then DrawOverLayOnClipArea;
end;
procedure TMapEdit.MenuDeleteAllClick(Sender: TObject);
begin
DeleteAll;
end;
procedure TMapEdit.DeleteAll;
begin
MapCoreBase.Init; //init core to default values
Init; //init map editor to default values
end;
procedure TMapEdit.MenuDeleteClick(Sender: TObject);
var
index : integer;
item : TListItem;
begin
if MapCoreBase.GetMapCount > 1 then
begin
if (MapListView.SelCount > 0) then //if map is selected
begin
item:=MapListView.LastSelected;
index:=item.index;
if index > -1 then
begin
MapCoreBase.DeleteMap(Index);
end
else
begin
MapCoreBase.DeleteMap(CurrentMap);
end;
if CurrentMap > (MapCoreBase.GetMapCount-1) then
begin
CurrentMap:=MapCoreBase.GetMapCount-1;
MapCoreBase.SetCurrentMap(CurrentMap);
end;
UpdateMapListView;
UpdatePageSize;
//UpdateMapView;
MapPaintBox.Invalidate;
end;
end
else
begin
MapCoreBase.ClearMap(0,TileClear); // if there is only one map we just clear it
UpdatePageSize;
UpdateMapListView;
//UpdateMapView;
MapPaintBox.Invalidate;
end;
end;
function TMapEdit.ExportTextFileToClipboard(Sender: TObject) : boolean;
var
filename : string;
begin
if rmconfigbase.GetExportTextFileToClipStatus = false then
begin
result:=false;
exit;
end;
filename:=GetTemporaryPathWithProvidedFileName(MapCoreBase.GetExportName(MapCoreBase.GetCurrentMap));
Case (Sender As TMenuItem).Name of 'ExportBasicMapData':ExportMap(FileName,BasicLan,True);
'BasicLNMapData':ExportMap(FileName,BasicLNLan,True);
'ExportCArray': ExportMap(FileName,CLan,true);
'ExportPascalArray':ExportMap(FileName,PascalLan,true);
else
result:=false; //did not find a supported format return false
exit;
End;
result:=true; //found supported format - return true
ReadFileAndCopyToClipboard(filename);
EraseFile(filename);
ShowMessage('Exported to Clipboard!');
end;
procedure TMapEdit.MenuExportBasicLNMapData(Sender: TObject);
begin
if ExportTextFileToClipboard(Sender) then exit;
SaveDialog1.Filter := 'Basic|*.bas|All Files|*.*';
if SaveDialog1.Execute then
begin
ExportMap(SaveDialog1.FileName,BasicLNLan,True);
end;
end;
procedure TMapEdit.MenuExportBasicMapData(Sender: TObject);
begin
if ExportTextFileToClipboard(Sender) then exit;
SaveDialog1.Filter := 'Basic|*.bas|All Files|*.*';
if SaveDialog1.Execute then
begin
ExportMap(SaveDialog1.FileName,BasicLan,true);
end;
end;
procedure TMapEdit.MenuExportCArray(Sender: TObject);
begin
if ExportTextFileToClipboard(Sender) then exit;
SaveDialog1.Filter := 'c|*.c|All Files|*.*';
if SaveDialog1.Execute then
begin
ExportMap(SaveDialog1.FileName,CLan,true);
end;
end;
procedure TMapEdit.MenuExportPascalArray(Sender: TObject);
begin
if ExportTextFileToClipboard(Sender) then exit;
SaveDialog1.Filter := 'Pascal|*.pas|All Files|*.*';
if SaveDialog1.Execute then
begin
ExportMap(SaveDialog1.FileName,PascalLan,true);
end;
end;
procedure TMapEdit.MenuMapPropsClick(Sender: TObject);
var
EO : MapExportFormatRec;
index : integer;
begin
index:=MapListView.ItemIndex;
if index = -1 then index:=0;
MapCoreBase.GetMapExportProps(index,EO);
MapExportForm.InitComboBoxes;
MapExportForm.SetExportProps(EO);
if MapExportForm.ShowModal = mrOK then
begin
MapExportForm.GetExportProps(EO);
MapCoreBase.SetMapExportProps(index,EO);
end;
end;
procedure TMapEdit.MenuNewClick(Sender: TObject);
begin
//capture vert/scroll bar positions
MapCoreBase.SetMapScrollHorizPos(MapCoreBase.GetCurrentMap,MapScrollBox.HorzScrollBar.Position);
MapCoreBase.SetMapScrollVertPos(MapCoreBase.GetCurrentMap,MapScrollBox.VertScrollBar.Position);
MapCoreBase.AddMap; //making copy of Map 0 for all new maps - Map 0 is the primary map
MapCoreBase.SetCurrentMap(MapCoreBase.GetMapCount-1);
CurrentMap:=MapCoreBase.GetCurrentMap;
TileMode:=1; //draw
MapCoreBase.SetMapTileMode(CurrentMap,TileMode); // we set to draw because the copied data from map 0 may be in erase mode
TileZoom.Position:=4;
MapCoreBase.SetZoomSize(CurrentMap,TileZoom.Position);
UpdateMapListView;
UpdatePageSize;
MapScrollBox.HorzScrollBar.Position:=0;
MapScrollBox.VertScrollBar.Position:=0;
SetDrawTool(DrawShapePencil);
UpdateToolSelectionIcons;
UpdateMenus;
UpdateEditMenus;
MapPaintBox.Invalidate;
end;
procedure TMapEdit.MenuOpenClick(Sender: TObject);
begin
OpenDialog1.Filter := 'RM MAP Files|*.map|All Files|*.*';
if OpenDialog1.Execute then
begin
ReadMap(OpenDialog1.FileName);
UpdatePageSize;
//UpdateMapView;
MapPaintBox.Invalidate;
end;
end;
procedure TMapEdit.MenuSaveClick(Sender: TObject);
begin
SaveDialog1.Filter := 'RM MAP Files|*.map|All Files|*.*';
if SaveDialog1.Execute then
begin
WriteMap(SaveDialog1.FileName);
end;
end;
procedure TMapEdit.UpdateEditMenus;
var
mwidth,mheight : integer;
twidth,theight : integer;
begin
ReSizeMap8x8.Checked:=false;
ReSizeMap16x16.Checked:=false;
ReSizeMap32x32.Checked:=false;
ReSizeMap64x64.Checked:=false;
ReSizeMap128x128.Checked:=false;
ReSizeMap256x256.Checked:=false;
//clear show custom size menu
ShowCustomSize.Checked:=false;
ShowCustomSize.Caption:='';
mwidth:=MapCoreBase.GetMapWidth(MapCoreBase.GetCurrentMap);
mheight:=MapCoreBase.GetMapHeight(MapCoreBase.GetCurrentMap);
if (mwidth=8) and (mheight=8) then ReSizeMap8x8.Checked:=true
else if (mwidth=16) and (mheight=16) then ReSizeMap16x16.Checked:=true
else if (mwidth=32) and (mheight=32) then ReSizeMap32x32.Checked:=true
else if (mwidth=64) and (mheight=64) then ReSizeMap64x64.Checked:=true
else if (mwidth=128) and (mheight=128) then ReSizeMap128x128.Checked:=true
else if (mwidth=256) and (mheight=256) then ReSizeMap256x256.Checked:=true
else
begin
//if custom set checked and dimensions
ShowCustomSize.Checked:=true;
ShowCustomSize.Caption:=IntToStr(mwidth)+'x'+IntToStr(mheight);
end;
ReSize8x8.Checked:=false;
ReSize16x16.Checked:=false;
ReSize32x32.Checked:=false;
ReSize64x64.Checked:=false;
ReSize128x128.Checked:=false;
ReSize256x256.Checked:=false;
ShowTileCustomSize.Checked:=false;
ShowTileCustomSize.Caption:='';
twidth:=MapCoreBase.GetMapTileWidth(MapCoreBase.GetCurrentMap);
theight:=MapCoreBase.GetMapTileHeight(MapCoreBase.GetCurrentMap);
if (twidth=8) and (theight=8) then ReSize8x8.Checked:=true
else if (twidth=16) and (theight=16) then ReSize16x16.Checked:=true
else if (twidth=32) and (theight=32) then ReSize32x32.Checked:=true
else if (twidth=64) and (theight=64) then ReSize64x64.Checked:=true
else if (twidth=128) and (theight=128) then ReSize128x128.Checked:=true
else if (twidth=256) and (theight=256) then ReSize256x256.Checked:=true
else
begin
ShowTileCustomSize.Checked:=true;
ShowTileCustomSize.Caption:=IntToStr(twidth)+'x'+IntToStr(theight);
MapCoreBase.SetMapTileSize(MapCoreBase.GetCurrentMap,twidth,theight);
end;
end;
procedure TMapEdit.ReSizeMapClick(Sender: TObject);
var
mwidth,mheight : integer;
begin
Case (Sender As TMenuItem).Name of 'ReSizeMap8x8' :begin
mwidth:=8;
mheight:=8;
end;
'ReSizeMap16x16' :begin
mwidth:=16;
mheight:=16;
end;
'ReSizeMap32x32' :begin
mwidth:=32;
mheight:=32;
end;
'ReSizeMap64x64' :begin
mwidth:=64;
mheight:=64;
end;
'ReSizeMap128x128' :begin
mwidth:=128;
mheight:=128;
end;
'ReSizeMap256x256' :begin
mwidth:=256;
mheight:=256;
end;
'SetMapCustomSize' :begin
mwidth:=setcustommapsizeform.SpinEditCustomWidth.Value;