This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
vcmi.frames.tools.pas
521 lines (451 loc) · 13.5 KB
/
vcmi.frames.tools.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
{ This file is a part of Map editor for VCMI project
Copyright (C) 2017 Alexander Shishkin alexvins@users.sourceforge.net
This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
version.
This code 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 General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web at
<http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit vcmi.frames.tools;
{$I compilersetup.inc}
interface
uses
Classes, SysUtils, typinfo, FileUtil, Forms, Controls, ComCtrls, ActnList, StdCtrls, Buttons, ExtCtrls, editor_types,
editor_str_consts, map, map_actions, map_road_river_actions, map_terrain_actions, map_object_actions,
map_erase_actions;
type
{ TToolsFrame }
TToolsFrame = class(TFrame)
act: TActionList;
actEraseSize1: TAction;
actEraseSize2: TAction;
actEraseSize4: TAction;
actEraseSizeRect: TAction;
actObjSizeRect: TAction;
actObjSize0: TAction;
actSizeRect: TAction;
actSize4: TAction;
actSize2: TAction;
actSize1: TAction;
btnBrush3: TSpeedButton;
btnBrush4: TSpeedButton;
btnBrush5: TSpeedButton;
btnBrush6: TSpeedButton;
btnBrush7: TSpeedButton;
btnBrush8: TSpeedButton;
btnBrushArea: TSpeedButton;
btnBrushArea1: TSpeedButton;
btnBrushArea2: TSpeedButton;
btnSelect: TSpeedButton;
EraseFilter: TCheckGroup;
gbBrushObjects: TGroupBox;
gbBrushTerrain: TGroupBox;
gbBrushTerrain1: TGroupBox;
gbTerrain: TGroupBox;
EraseObjects: TRadioGroup;
RiverType: TRadioGroup;
RoadType: TRadioGroup;
tsErase: TTabSheet;
ToolsPages: TPageControl;
tsRivers: TTabSheet;
tsRoads: TTabSheet;
tsTerrain: TTabSheet;
tsObjects: TTabSheet;
procedure actEraseSize1Execute(Sender: TObject);
procedure actEraseSize2Execute(Sender: TObject);
procedure actEraseSize4Execute(Sender: TObject);
procedure actEraseSizeRectExecute(Sender: TObject);
procedure actObjSize0Execute(Sender: TObject);
procedure actObjSizeRectExecute(Sender: TObject);
procedure actSize1Execute(Sender: TObject);
procedure actSize2Execute(Sender: TObject);
procedure actSize4Execute(Sender: TObject);
procedure actSizeRectExecute(Sender: TObject);
procedure EraseFilterItemClick(Sender: TObject; Index: integer);
procedure EraseObjectsClick(Sender: TObject);
procedure RiverTypeSelectionChanged(Sender: TObject);
procedure RoadTypeSelectionChanged(Sender: TObject);
procedure ToolsPagesChange(Sender: TObject);
procedure ToolsPagesChanging(Sender: TObject; var AllowChange: Boolean);
private
//all brushes
FIdleBrush: TIdleMapBrush;
FFixedTerrainBrush: TFixedTerrainBrush;
FAreaTerrainBrush: TAreaTerrainBrush;
FRoadRiverBrush: TRoadRiverBrush;
FObjectSelectBrush: TObjectSelectBrush;
FFixedEraseBrush: TFixedEraseBrush;
FAreaEraseBrush: TAreaEraseBrush;
FActiveBrush: TMapBrush;
FSelectedObject: TMapObject;
procedure FillLandscapeMenu;
procedure FillRoadRiverMenu;
procedure FillEraseMenu;
procedure FillObjectEraseMenu;
procedure OnTerrainButtonClick(Sender: TObject);
procedure ObjectPageSelected;
procedure SetSelectedObject(AValue: TMapObject);
procedure TerrainPageSelected;
procedure RiversPageSelected;
procedure RoadsPageSelected;
procedure ErasePageSelected;
procedure SetActiveBrush(ABrush: TMapBrush);
function ObjectEraseMode: TSelectObjectBy;
public
constructor Create(TheOwner: TComponent); override;
procedure SetVisibleObjects(VisibleObjects: TMapObjectsSelection);
property ActiveBrush: TMapBrush read FActiveBrush;
property IdleBrush: TIdleMapBrush read FIdleBrush;
property ObjectSelectBrush: TObjectSelectBrush read FObjectSelectBrush;
procedure SwitchToObjects;
property SelectedObject: TMapObject read FSelectedObject write SetSelectedObject;
end;
implementation
{$R *.lfm}
{ TToolsFrame }
procedure TToolsFrame.ToolsPagesChange(Sender: TObject);
begin
//todo: select active brush
if ToolsPages.ActivePage = tsObjects then
begin
ObjectPageSelected;
end
else if ToolsPages.ActivePage = tsTerrain then
begin
TerrainPageSelected;
end
else if ToolsPages.ActivePage = tsRivers then
begin
RiversPageSelected;
end
else if ToolsPages.ActivePage = tsRoads then
begin
RoadsPageSelected;
end
else
begin
ErasePageSelected;
end;
end;
procedure TToolsFrame.RoadTypeSelectionChanged(Sender: TObject);
begin
FRoadRiverBrush.RoadType:=TRoadType(PtrInt(RoadType.Items.Objects[RoadType.ItemIndex]));
end;
procedure TToolsFrame.RiverTypeSelectionChanged(Sender: TObject);
begin
FRoadRiverBrush.RiverType:=TRiverType(PtrInt(RiverType.Items.Objects[RiverType.ItemIndex]));
end;
procedure TToolsFrame.actObjSize0Execute(Sender: TObject);
begin
SetActiveBrush(FIdleBrush);
end;
procedure TToolsFrame.actEraseSize1Execute(Sender: TObject);
begin
SetActiveBrush(FFixedEraseBrush);
FFixedEraseBrush.Size := 1;
end;
procedure TToolsFrame.actEraseSize2Execute(Sender: TObject);
begin
SetActiveBrush(FFixedEraseBrush);
FFixedEraseBrush.Size := 2;
end;
procedure TToolsFrame.actEraseSize4Execute(Sender: TObject);
begin
SetActiveBrush(FFixedEraseBrush);
FFixedEraseBrush.Size := 4;
end;
procedure TToolsFrame.actEraseSizeRectExecute(Sender: TObject);
begin
SetActiveBrush(FAreaEraseBrush);
end;
procedure TToolsFrame.actObjSizeRectExecute(Sender: TObject);
begin
SetActiveBrush(FObjectSelectBrush);
end;
procedure TToolsFrame.actSize1Execute(Sender: TObject);
begin
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size := 1;
end;
procedure TToolsFrame.actSize2Execute(Sender: TObject);
begin
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size := 2;
end;
procedure TToolsFrame.actSize4Execute(Sender: TObject);
begin
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size := 4;
end;
procedure TToolsFrame.actSizeRectExecute(Sender: TObject);
begin
SetActiveBrush(FAreaTerrainBrush);
end;
procedure TToolsFrame.EraseFilterItemClick(Sender: TObject; Index: integer);
var
filter: TSelectFilter;
f: TSelectTarget;
begin
filter := [];
for f in TSelectFilter do
begin
if EraseFilter.Checked[Integer(f)] then
Include(filter, f);
end;
FFixedEraseBrush.Filter:=filter;
FAreaEraseBrush.Filter:=filter;
end;
procedure TToolsFrame.EraseObjectsClick(Sender: TObject);
var
m: TSelectObjectBy;
begin
m := ObjectEraseMode();
FAreaEraseBrush.ObjectFilter := m;
FFixedEraseBrush.ObjectFilter := m;
end;
procedure TToolsFrame.ToolsPagesChanging(Sender: TObject; var AllowChange: Boolean);
begin
AllowChange := true;
//TODO: clear active brush
end;
procedure TToolsFrame.FillLandscapeMenu;
var
tt: TTerrainType;
idx: Integer;
button: TSpeedButton;
first: Boolean;
begin
//todo: localization
first := true;
for tt in TTerrainType do
begin
idx := Integer(tt);
button := TSpeedButton.Create(Self);
button.Parent := gbTerrain;
button.Caption:=GetEnumName(TypeInfo(tt),idx);
button.ShowCaption := true;
button.OnClick := @OnTerrainButtonClick;
button.Tag:=idx;
button.GroupIndex:=2;
if first then
begin
button.Down := true;
first:=false;
end;
end;
end;
procedure TToolsFrame.FillRoadRiverMenu;
begin
RoadType.Items.BeginUpdate;
RiverType.Items.BeginUpdate;
try
RoadType.Items.Clear;
RoadType.Items.AddObject(rsRoadTypeDirt, TObject(PtrInt(TRoadType.dirtRoad)));
RoadType.Items.AddObject(rsRoadTypeGravel, TObject(PtrInt(TRoadType.gravelRoad)));
RoadType.Items.AddObject(rsRoadTypeCobblestone, TObject(PtrInt(TRoadType.cobblestoneRoad)));
RoadType.Items.AddObject(rsRoadTypeNone, TObject(PtrInt(TRoadType.noRoad)));
RoadType.ItemIndex := 0;
RiverType.Items.Clear;
RiverType.Items.AddObject(rsRiverTypeClear, TObject(PtrInt(TRiverType.clearRiver)));
RiverType.Items.AddObject(rsRiverTypeIcy, TObject(PtrInt(TRiverType.icyRiver)));
RiverType.Items.AddObject(rsRiverTypeMuddy, TObject(PtrInt(TRiverType.muddyRiver)));
RiverType.Items.AddObject(rsRiverTypeLava, TObject(PtrInt(TRiverType.lavaRiver)));
RiverType.Items.AddObject(rsRiverTypeNone, TObject(PtrInt(TRiverType.noRiver)));
RiverType.ItemIndex:=0;
finally
RoadType.Items.EndUpdate;
RiverType.Items.EndUpdate;
end;
end;
procedure TToolsFrame.FillEraseMenu;
var
filter_captions: array[TSelectTarget] of AnsiString;
f: TSelectTarget;
begin
filter_captions[TSelectTarget.InteractiveObjects] := rsEraseFilterInteractive;
filter_captions[TSelectTarget.Rivers] := rsEraseFilterRivers;
filter_captions[TSelectTarget.Roads] := rsEraseFilterRoads;
filter_captions[TSelectTarget.StaticObjects] := rsEraseFilterStatic;
EraseFilter.Items.BeginUpdate;
try
EraseFilter.Items.Clear;
for f in TSelectFilter do
begin
EraseFilter.Items.Add(filter_captions[f]);
end;
finally
EraseFilter.Items.EndUpdate;
end;
end;
procedure TToolsFrame.FillObjectEraseMenu;
var
filter_captions: array[TSelectObjectBy] of AnsiString;
f: TSelectObjectBy;
begin
filter_captions[TSelectObjectBy.BBox] := rsEraseObjectBBox;
filter_captions[TSelectObjectBy.VisibleMask] := rsEraseObjectVisibleMask;
filter_captions[TSelectObjectBy.BlockMask] := rsEraseObjectBlockMask;
filter_captions[TSelectObjectBy.VisitableMask] := rsEraseObjectVisitableMask;
EraseObjects.Items.BeginUpdate;
try
EraseObjects.Items.Clear;
for f in TSelectObjectBy do
begin
EraseObjects.Items.Add(filter_captions[f]);
end;
EraseObjects.ItemIndex:=0;
finally
EraseObjects.Items.EndUpdate;
end;
EraseObjectsClick(EraseObjects);
end;
procedure TToolsFrame.OnTerrainButtonClick(Sender: TObject);
var
tt: TTerrainType;
begin
tt := TTerrainType((Sender as TSpeedButton).Tag);
FFixedTerrainBrush.TT := tt;
FAreaTerrainBrush.TT:=tt;
end;
procedure TToolsFrame.ObjectPageSelected;
begin
if actObjSize0.Checked then
begin
SetActiveBrush(FIdleBrush);
end
else if actObjSizeRect.Checked then
begin
SetActiveBrush(FObjectSelectBrush);
end
else
begin
actObjSize0.Checked := true;
SetActiveBrush(FIdleBrush);
end
end;
procedure TToolsFrame.SetSelectedObject(AValue: TMapObject);
begin
FSelectedObject:=AValue;
end;
procedure TToolsFrame.TerrainPageSelected;
begin
if actSize1.Checked then
begin
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size:=1;
end
else if actSize2.Checked then
begin
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size:=2;
end
else if actSize4.Checked then
begin
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size:=4;
end
else if actSizeRect.Checked then
begin
SetActiveBrush(FAreaTerrainBrush);
end
else
begin
actSize1.Checked := true;
SetActiveBrush(FFixedTerrainBrush);
FFixedTerrainBrush.Size:=1;
end
end;
procedure TToolsFrame.RiversPageSelected;
begin
SetActiveBrush(FRoadRiverBrush);
RiverTypeSelectionChanged(nil);
end;
procedure TToolsFrame.RoadsPageSelected;
begin
SetActiveBrush(FRoadRiverBrush);
RoadTypeSelectionChanged(nil);
end;
procedure TToolsFrame.ErasePageSelected;
begin
if actEraseSize1.Checked then
begin
SetActiveBrush(FFixedEraseBrush);
FFixedEraseBrush.Size:=1;
end
else if actEraseSize2.Checked then
begin
SetActiveBrush(FFixedEraseBrush);
FFixedEraseBrush.Size:=2;
end
else if actEraseSize4.Checked then
begin
SetActiveBrush(FFixedEraseBrush);
FFixedEraseBrush.Size:=4;
end
else if actEraseSizeRect.Checked then
begin
SetActiveBrush(FAreaEraseBrush);
end
else
begin
actEraseSize1.Checked := true;
SetActiveBrush(FFixedEraseBrush);
FFixedTerrainBrush.Size:=1;
end;
EraseObjectsClick(EraseObjects);
end;
procedure TToolsFrame.SetActiveBrush(ABrush: TMapBrush);
begin
FActiveBrush := ABrush;
FActiveBrush.Clear;
FSelectedObject := nil;
end;
function TToolsFrame.ObjectEraseMode: TSelectObjectBy;
begin
if EraseObjects.ItemIndex < 0 then
begin
Result := TSelectObjectBy(0);
end
else
begin
Result := TSelectObjectBy(EraseObjects.ItemIndex);
end;
end;
constructor TToolsFrame.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FIdleBrush := TIdleMapBrush.Create(Self);
FFixedTerrainBrush := TFixedTerrainBrush.Create(Self);
FAreaTerrainBrush := TAreaTerrainBrush.Create(Self);
FRoadRiverBrush := TRoadRiverBrush.Create(Self);
FObjectSelectBrush := TObjectSelectBrush.Create(Self);
FFixedEraseBrush := TFixedEraseBrush.Create(Self);
FFixedEraseBrush.Size:=1;
FAreaEraseBrush := TAreaEraseBrush.Create(Self);
FActiveBrush := FIdleBrush;
FillLandscapeMenu;
FillRoadRiverMenu;
FillEraseMenu;
FillObjectEraseMenu;
end;
procedure TToolsFrame.SetVisibleObjects(VisibleObjects: TMapObjectsSelection);
begin
//TODO: maybe free notification?
FAreaEraseBrush.VisibleObjects := VisibleObjects;
FFixedEraseBrush.VisibleObjects := VisibleObjects;
FObjectSelectBrush.VisibleObjects := VisibleObjects;
end;
procedure TToolsFrame.SwitchToObjects;
begin
ToolsPages.ActivePage := tsObjects;
SetActiveBrush(FIdleBrush);
if not actObjSize0.Checked then
begin
actObjSize0.Execute;
end;
end;
end.