DEADSOFTWARE

more zip related fixes for packmap
[d2df-editor.git] / src / editor / f_saveminimap.pas
1 unit f_saveminimap;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes,
9 Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
11 type
12 TSaveMiniMapForm = class(TForm)
13 SaveDialog: TSaveDialog;
14 pbMiniMap: TPaintBox;
15 Panel1: TPanel;
16 LabelScale: TLabel;
17 cbScale: TComboBox;
18 bSave: TButton;
19 bClose: TButton;
21 procedure bCloseClick(Sender: TObject);
22 procedure cbScaleChange(Sender: TObject);
23 procedure FormActivate(Sender: TObject);
24 procedure pbMiniMapPaint(Sender: TObject);
25 procedure bSaveClick(Sender: TObject);
27 private
28 { Private declarations }
29 public
30 { Public declarations }
31 end;
33 var
34 SaveMiniMapForm: TSaveMiniMapForm;
36 implementation
38 uses
39 e_graphics, g_map, MAPDEF, Math, f_main;
41 {$R *.lfm}
43 procedure DrawMiniMap(canv: TCanvas);
44 var
45 a, w, h, Scale, aX, aY, aX2, aY2: Integer;
46 c: TRGB;
48 begin
49 if SaveMiniMapForm.cbScale.ItemIndex = 0 then
50 Scale := 1
51 else
52 Scale := 2;
54 w := (gMapInfo.Width div (16 div Scale))+4;
55 h := (gMapInfo.Height div (16 div Scale))+4;
57 canv.Brush.Color := $00000000;
58 canv.FillRect(canv.ClipRect);
60 canv.Pen.Color := $00FFFFFF;
61 canv.Rectangle(0, 0, w, h);
63 if gPanels = nil then
64 Exit;
66 for a := 0 to High(gPanels) do
67 with gPanels[a] do
68 if PanelType <> 0 then
69 begin
70 aX := 2+(X div (16 div Scale));
71 aY := 2+(Y div (16 div Scale));
73 if Width div (16 div Scale) = 0 then
74 aX2 := aX+1
75 else
76 aX2 := aX+Width div (16 div Scale);
78 if Height div (16 div Scale) = 0 then
79 aY2 := aY+1
80 else
81 aY2 := aY+Height div (16 div Scale);
83 case PanelType of
84 PANEL_WALL: c := _RGB(208, 208, 208);
85 PANEL_CLOSEDOOR: c := _RGB(255, 255, 0);
86 PANEL_WATER: c := _RGB(0, 0, 252);
87 PANEL_ACID1: c := _RGB(200, 80, 4);
88 PANEL_ACID2: c := _RGB(252, 140, 56);
89 PANEL_STEP: c := _RGB(128, 128, 128);
90 else Continue;
91 end;
93 canv.Brush.Color := c.R+c.G*256+c.B*256*256;
94 canv.FillRect(Rect(aX, aY, aX2, aY2));
95 end;
96 end;
98 procedure TSaveMiniMapForm.bCloseClick(Sender: TObject);
99 begin
100 Close();
101 end;
103 procedure TSaveMiniMapForm.cbScaleChange(Sender: TObject);
104 begin
105 DrawMiniMap(pbMiniMap.Canvas)
106 end;
108 procedure TSaveMiniMapForm.FormActivate(Sender: TObject);
109 begin
110 DrawMiniMap(pbMiniMap.Canvas);
111 end;
113 procedure TSaveMiniMapForm.pbMiniMapPaint(Sender: TObject);
114 begin
115 DrawMiniMap(pbMiniMap.Canvas);
116 end;
118 procedure TSaveMiniMapForm.bSaveClick(Sender: TObject);
119 var
120 bmp: TBitmap;
121 Scale, w, h: Integer;
123 begin
124 SaveDialog.FileName := ChangeFileExt(ExtractFileName(gMapInfo.FileName), '')
125 + '_' + LowerCase(gMapInfo.MapName);
127 // Filter out special characters
128 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '/', '', [rfReplaceAll]);
129 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '\', '', [rfReplaceAll]);
130 SaveDialog.FileName := StringReplace(SaveDialog.FileName, ':', '', [rfReplaceAll]);
131 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '*', '', [rfReplaceAll]);
132 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '?', '', [rfReplaceAll]);
133 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '"', '', [rfReplaceAll]);
134 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '<', '', [rfReplaceAll]);
135 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '>', '', [rfReplaceAll]);
136 SaveDialog.FileName := StringReplace(SaveDialog.FileName, '|', '', [rfReplaceAll]);
138 if SaveDialog.FileName = '_' then
139 SaveDialog.FileName := '';
141 if SaveDialog.Execute() then
142 begin
143 bmp := TBitmap.Create();
145 if SaveMiniMapForm.cbScale.ItemIndex = 0 then
146 Scale := 1
147 else
148 Scale := 2;
150 w := (gMapInfo.Width div (16 div Scale))+4;
151 h := (gMapInfo.Height div (16 div Scale))+4;
153 bmp.Width := w;
154 bmp.Height := h;
156 DrawMiniMap(bmp.Canvas);
158 bmp.SaveToFile(SaveDialog.FileName);
160 bmp.Free();
161 end;
162 end;
164 end.