DEADSOFTWARE

dfzip: more checks and user visible errors
[d2df-editor.git] / src / editor / f_main.pas
1 unit f_main;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics,
9 Controls, Forms, Dialogs, StdCtrls, Buttons,
10 ComCtrls, ValEdit, Types, Menus, ExtCtrls,
11 CheckLst, Grids, OpenGLContext, Utils, UTF8Process;
13 type
15 { TMainForm }
17 TMainForm = class(TForm)
18 MapTestTimer: TTimer;
19 Splitter1: TSplitter;
20 Splitter2: TSplitter;
21 StatusBar: TStatusBar;
22 OpenDialog: TOpenDialog;
23 SaveDialog: TSaveDialog;
24 ColorDialog: TColorDialog;
26 // Menu:
27 MainMenu: TMainMenu;
28 ImageList: TImageList;
29 // Apple menu:
30 miApple: TMenuItem;
31 miAppleAbout: TMenuItem;
32 miAppleLine0: TMenuItem;
33 miApplePref: TMenuItem;
34 miAppleLine1: TMenuItem;
35 // File menu:
36 miMenuFile: TMenuItem;
37 miNewMap: TMenuItem;
38 miOpenMap: TMenuItem;
39 miMacRecentSubMenu: TMenuItem;
40 miMacRecentEnd: TMenuItem;
41 miMacRecentClear: TMenuItem;
42 Separator1: TMenuItem;
43 miSaveMap: TMenuItem;
44 miSaveMapAs: TMenuItem;
45 miOpenWadMap: TMenuItem;
46 miLine1: TMenuItem;
47 miReopenMap: TMenuItem;
48 miSaveMiniMap: TMenuItem;
49 miDeleteMap: TMenuItem;
50 miPackMap: TMenuItem;
51 miWinRecentStart: TMenuItem;
52 miWinRecent: TMenuItem;
53 miLine2: TMenuItem;
54 miExit: TMenuItem;
55 // Edit menu:
56 miMenuEdit: TMenuItem;
57 miUndo: TMenuItem;
58 miLine3: TMenuItem;
59 miCopy: TMenuItem;
60 miCut: TMenuItem;
61 miPaste: TMenuItem;
62 miLine4: TMenuItem;
63 miSelectAll: TMenuItem;
64 miLine5: TMenuItem;
65 miSnapToGrid: TMenuItem;
66 miSwitchGrid: TMenuItem;
67 Separator2: TMenuItem;
68 miToFore: TMenuItem;
69 miToBack: TMenuItem;
70 miLine6: TMenuItem;
71 miMapOptions: TMenuItem;
72 miOptions: TMenuItem;
73 // View menu:
74 miMenuView: TMenuItem;
75 miLayers: TMenuItem;
76 miLayer1: TMenuItem;
77 miLayer2: TMenuItem;
78 miLayer3: TMenuItem;
79 miLayer4: TMenuItem;
80 miLayer5: TMenuItem;
81 miLayer6: TMenuItem;
82 miLayer7: TMenuItem;
83 miLayer8: TMenuItem;
84 miLayer9: TMenuItem;
85 miViewLine1: TMenuItem;
86 miMiniMap: TMenuItem;
87 miShowEdges: TMenuItem;
88 miViewLine2: TMenuItem;
89 miMapPreview: TMenuItem;
90 // Service menu:
91 miMenuService: TMenuItem;
92 miCheckMap: TMenuItem;
93 miOptimmization: TMenuItem;
94 miTestMap: TMenuItem;
95 // Window menu:
96 miMenuWindow: TMenuItem;
97 miMacMinimize: TMenuItem;
98 miMacZoom: TMenuItem;
99 // Help Menu:
100 miMenuHelp: TMenuItem;
101 miAbout: TMenuItem;
102 // HIDDEN menu:
103 miMenuHidden: TMenuItem;
104 minexttab: TMenuItem;
105 selectall1: TMenuItem;
107 // Toolbar:
108 ilToolbar: TImageList;
109 MainToolBar: TToolBar;
110 tbNewMap: TToolButton;
111 tbOpenMap: TToolButton;
112 tbSaveMap: TToolButton;
113 tbOpenWadMap: TToolButton;
114 tbLine1: TToolButton;
115 tbShowMap: TToolButton;
116 tbLine2: TToolButton;
117 tbShow: TToolButton;
118 pmShow: TPopupMenu;
119 miLayerP1: TMenuItem;
120 miLayerP2: TMenuItem;
121 miLayerP3: TMenuItem;
122 miLayerP4: TMenuItem;
123 miLayerP5: TMenuItem;
124 miLayerP6: TMenuItem;
125 miLayerP7: TMenuItem;
126 miLayerP8: TMenuItem;
127 miLayerP9: TMenuItem;
128 tbLine3: TToolButton;
129 tbGridOn: TToolButton;
130 tbGrid: TToolButton;
131 tbLine4: TToolButton;
132 tbTestMap: TToolButton;
134 // Progress bar:
135 pLoadProgress: TPanel;
136 lLoad: TLabel;
137 pbLoad: TProgressBar;
139 // Map edit area:
140 PanelMap: TPanel;
141 RenderPanel: TOpenGLControl;
142 sbHorizontal: TScrollBar;
143 sbVertical: TScrollBar;
145 // Object propertiy editor:
146 PanelProps: TPanel;
147 PanelPropApply: TPanel;
148 bApplyProperty: TButton;
149 vleObjectProperty: TValueListEditor;
151 // Object palette:
152 PanelObjs: TPanel;
153 pcObjects: TPageControl;
154 // Panels Tab:
155 tsPanels: TTabSheet;
156 PanelPanelType: TPanel;
157 lbPanelType: TListBox;
158 lbTextureList: TListBox;
159 PanelTextures: TPanel;
160 LabelTxW: TLabel;
161 lTextureWidth: TLabel;
162 LabelTxH: TLabel;
163 lTextureHeight: TLabel;
164 cbPreview: TCheckBox;
165 bbAddTexture: TBitBtn;
166 bbRemoveTexture: TBitBtn;
167 bClearTexture: TButton;
168 // Items Tab:
169 tsItems: TTabSheet;
170 lbItemList: TListBox;
171 cbOnlyDM: TCheckBox;
172 cbFall: TCheckBox;
173 // Monsters Tab:
174 tsMonsters: TTabSheet;
175 lbMonsterList: TListBox;
176 rbMonsterLeft: TRadioButton;
177 rbMonsterRight: TRadioButton;
178 // Areas Tab:
179 tsAreas: TTabSheet;
180 lbAreasList: TListBox;
181 rbAreaLeft: TRadioButton;
182 rbAreaRight: TRadioButton;
183 // Triggers Tab:
184 tsTriggers: TTabSheet;
185 lbTriggersList: TListBox;
186 clbActivationType: TCheckListBox;
187 clbKeys: TCheckListBox;
189 procedure aAboutExecute(Sender: TObject);
190 procedure aCheckMapExecute(Sender: TObject);
191 procedure aMoveToFore(Sender: TObject);
192 procedure aMoveToBack(Sender: TObject);
193 procedure aCopyObjectExecute(Sender: TObject);
194 procedure aCutObjectExecute(Sender: TObject);
195 procedure aEditorOptionsExecute(Sender: TObject);
196 procedure aExitExecute(Sender: TObject);
197 procedure aMapOptionsExecute(Sender: TObject);
198 procedure aNewMapExecute(Sender: TObject);
199 procedure aOpenMapExecute(Sender: TObject);
200 procedure aOptimizeExecute(Sender: TObject);
201 procedure aPasteObjectExecute(Sender: TObject);
202 procedure aSelectAllExecute(Sender: TObject);
203 procedure aSaveMapExecute(Sender: TObject);
204 procedure aSaveMapAsExecute(Sender: TObject);
205 procedure aUndoExecute(Sender: TObject);
206 procedure aDeleteMap(Sender: TObject);
207 procedure bApplyPropertyClick(Sender: TObject);
208 procedure bbAddTextureClick(Sender: TObject);
209 procedure bbRemoveTextureClick(Sender: TObject);
210 procedure FormActivate(Sender: TObject);
211 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
212 procedure FormCreate(Sender: TObject);
213 procedure FormDestroy(Sender: TObject);
214 procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
215 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
216 procedure FormResize(Sender: TObject);
217 procedure FormWindowStateChange(Sender: TObject);
218 procedure miRecentFileExecute(Sender: TObject);
219 procedure miMacRecentClearClick(Sender: TObject);
220 procedure miMacZoomClick(Sender: TObject);
221 procedure lbTextureListClick(Sender: TObject);
222 procedure lbTextureListDrawItem(Control: TWinControl; Index: Integer;
223 ARect: TRect; State: TOwnerDrawState);
224 procedure miMacMinimizeClick(Sender: TObject);
225 procedure miReopenMapClick(Sender: TObject);
226 procedure RenderPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
227 procedure RenderPanelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
228 procedure RenderPanelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
229 procedure RenderPanelPaint(Sender: TObject);
230 procedure RenderPanelResize(Sender: TObject);
231 procedure Splitter1Moved(Sender: TObject);
232 procedure MapTestCheck(Sender: TObject);
233 procedure vleObjectPropertyEditButtonClick(Sender: TObject);
234 procedure vleObjectPropertyApply(Sender: TObject);
235 procedure vleObjectPropertyGetPickList(Sender: TObject; const KeyName: String; Values: TStrings);
236 procedure vleObjectPropertyKeyDown(Sender: TObject; var Key: Word;
237 Shift: TShiftState);
238 procedure tbGridOnClick(Sender: TObject);
239 procedure miMapPreviewClick(Sender: TObject);
240 procedure miLayer1Click(Sender: TObject);
241 procedure miLayer2Click(Sender: TObject);
242 procedure miLayer3Click(Sender: TObject);
243 procedure miLayer4Click(Sender: TObject);
244 procedure miLayer5Click(Sender: TObject);
245 procedure miLayer6Click(Sender: TObject);
246 procedure miLayer7Click(Sender: TObject);
247 procedure miLayer8Click(Sender: TObject);
248 procedure miLayer9Click(Sender: TObject);
249 procedure tbShowClick(Sender: TObject);
250 procedure miSnapToGridClick(Sender: TObject);
251 procedure miMiniMapClick(Sender: TObject);
252 procedure miSwitchGridClick(Sender: TObject);
253 procedure miShowEdgesClick(Sender: TObject);
254 procedure minexttabClick(Sender: TObject);
255 procedure miSaveMiniMapClick(Sender: TObject);
256 procedure bClearTextureClick(Sender: TObject);
257 procedure miPackMapClick(Sender: TObject);
258 procedure miTestMapClick(Sender: TObject);
259 procedure sbVerticalScroll(Sender: TObject; ScrollCode: TScrollCode;
260 var ScrollPos: Integer);
261 procedure sbHorizontalScroll(Sender: TObject; ScrollCode: TScrollCode;
262 var ScrollPos: Integer);
263 procedure miOpenWadMapClick(Sender: TObject);
264 procedure selectall1Click(Sender: TObject);
265 procedure Splitter1CanResize(Sender: TObject; var NewSize: Integer;
266 var Accept: Boolean);
267 procedure Splitter2CanResize(Sender: TObject; var NewSize: Integer;
268 var Accept: Boolean);
269 procedure vleObjectPropertyEnter(Sender: TObject);
270 procedure vleObjectPropertyExit(Sender: TObject);
271 procedure FormKeyUp(Sender: TObject; var Key: Word;
272 Shift: TShiftState);
273 private
274 procedure Draw();
275 procedure OnIdle(Sender: TObject; var Done: Boolean);
276 procedure RefillRecentMenu (menu: TMenuItem; start: Integer; fmt: AnsiString);
277 public
278 procedure RefreshRecentMenu();
279 procedure OpenMapFile(FileName: String);
280 function RenderMousePos(): TPoint;
281 procedure RecountSelectedObjects();
282 end;
284 const
285 LAYER_BACK = 0;
286 LAYER_WALLS = 1;
287 LAYER_FOREGROUND = 2;
288 LAYER_STEPS = 3;
289 LAYER_WATER = 4;
290 LAYER_ITEMS = 5;
291 LAYER_MONSTERS = 6;
292 LAYER_AREAS = 7;
293 LAYER_TRIGGERS = 8;
295 TEST_MAP_NAME = '$$$_TEST_$$$';
296 LANGUAGE_FILE_NAME = '_Editor.txt';
298 var
299 MainForm: TMainForm;
300 StartMap: String;
301 OpenedMap: String;
302 OpenedWAD: String;
304 DotColor: TColor;
305 DotEnable: Boolean;
306 DotStep: Word;
307 DotStepOne, DotStepTwo: Word;
308 DotSize: Byte;
309 DrawTexturePanel: Boolean;
310 DrawPanelSize: Boolean;
311 BackColor: TColor;
312 PreviewColor: TColor;
313 UseCheckerboard: Boolean;
314 Scale: Byte;
315 RecentCount: Integer;
316 RecentFiles: TStringList;
317 slInvalidTextures: TStringList;
319 TestGameMode: String;
320 TestLimTime: String;
321 TestLimScore: String;
322 TestOptionsTwoPlayers: Boolean;
323 TestOptionsTeamDamage: Boolean;
324 TestOptionsAllowExit: Boolean;
325 TestOptionsWeaponStay: Boolean;
326 TestOptionsMonstersDM: Boolean;
327 TestD2dExe, TestD2DArgs: String;
328 TestMapOnce: Boolean;
330 LayerEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
331 (True, True, True, True, True, True, True, True, True);
332 ContourEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
333 (False, False, False, False, False, False, False, False, False);
334 PreviewMode: Byte = 0;
335 gLanguage: String;
337 FormCaption: String;
340 procedure OpenMap(FileName: String; mapN: String);
341 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
342 procedure RemoveSelectFromObjects();
343 procedure ChangeShownProperty(Name: String; NewValue: String);
345 implementation
347 uses
348 f_options, e_graphics, e_log, GL, Math,
349 f_mapoptions, g_basic, f_about, f_mapoptimization,
350 f_mapcheck, f_addresource_texture, g_textures,
351 f_activationtype, f_keys, wadreader, fileutil,
352 MAPREADER, f_selectmap, f_savemap, WADEDITOR, WADSTRUCT, MAPDEF,
353 g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
354 f_addresource_sound, f_choosetype,
355 g_language, ClipBrd, g_options;
357 const
358 UNDO_DELETE_PANEL = 1;
359 UNDO_DELETE_ITEM = 2;
360 UNDO_DELETE_AREA = 3;
361 UNDO_DELETE_MONSTER = 4;
362 UNDO_DELETE_TRIGGER = 5;
363 UNDO_ADD_PANEL = 6;
364 UNDO_ADD_ITEM = 7;
365 UNDO_ADD_AREA = 8;
366 UNDO_ADD_MONSTER = 9;
367 UNDO_ADD_TRIGGER = 10;
368 UNDO_MOVE_PANEL = 11;
369 UNDO_MOVE_ITEM = 12;
370 UNDO_MOVE_AREA = 13;
371 UNDO_MOVE_MONSTER = 14;
372 UNDO_MOVE_TRIGGER = 15;
373 UNDO_RESIZE_PANEL = 16;
374 UNDO_RESIZE_TRIGGER = 17;
376 MOUSEACTION_NONE = 0;
377 MOUSEACTION_DRAWPANEL = 1;
378 MOUSEACTION_DRAWTRIGGER = 2;
379 MOUSEACTION_MOVEOBJ = 3;
380 MOUSEACTION_RESIZE = 4;
381 MOUSEACTION_MOVEMAP = 5;
382 MOUSEACTION_DRAWPRESS = 6;
383 MOUSEACTION_NOACTION = 7;
385 RESIZETYPE_NONE = 0;
386 RESIZETYPE_VERTICAL = 1;
387 RESIZETYPE_HORIZONTAL = 2;
389 RESIZEDIR_NONE = 0;
390 RESIZEDIR_DOWN = 1;
391 RESIZEDIR_UP = 2;
392 RESIZEDIR_RIGHT = 3;
393 RESIZEDIR_LEFT = 4;
395 SELECTFLAG_NONE = 0;
396 SELECTFLAG_TELEPORT = 1;
397 SELECTFLAG_DOOR = 2;
398 SELECTFLAG_TEXTURE = 3;
399 SELECTFLAG_LIFT = 4;
400 SELECTFLAG_MONSTER = 5;
401 SELECTFLAG_SPAWNPOINT = 6;
402 SELECTFLAG_SHOTPANEL = 7;
403 SELECTFLAG_SELECTED = 8;
405 RECENT_FILES_MENU_START = 12;
407 CLIPBOARD_SIG = 'DF:ED';
409 type
410 TUndoRec = record
411 case UndoType: Byte of
412 UNDO_DELETE_PANEL: (Panel: ^TPanel);
413 UNDO_DELETE_ITEM: (Item: TItem);
414 UNDO_DELETE_AREA: (Area: TArea);
415 UNDO_DELETE_MONSTER: (Monster: TMonster);
416 UNDO_DELETE_TRIGGER: (Trigger: TTrigger);
417 UNDO_ADD_PANEL,
418 UNDO_ADD_ITEM,
419 UNDO_ADD_AREA,
420 UNDO_ADD_MONSTER,
421 UNDO_ADD_TRIGGER: (AddID: DWORD);
422 UNDO_MOVE_PANEL,
423 UNDO_MOVE_ITEM,
424 UNDO_MOVE_AREA,
425 UNDO_MOVE_MONSTER,
426 UNDO_MOVE_TRIGGER: (MoveID: DWORD; dX, dY: Integer);
427 UNDO_RESIZE_PANEL,
428 UNDO_RESIZE_TRIGGER: (ResizeID: DWORD; dW, dH: Integer);
429 end;
431 TCopyRec = record
432 ID: Cardinal;
433 case ObjectType: Byte of
434 OBJECT_PANEL: (Panel: ^TPanel);
435 OBJECT_ITEM: (Item: TItem);
436 OBJECT_AREA: (Area: TArea);
437 OBJECT_MONSTER: (Monster: TMonster);
438 OBJECT_TRIGGER: (Trigger: TTrigger);
439 end;
441 TCopyRecArray = Array of TCopyRec;
443 var
444 gEditorFont: DWORD;
445 gDataLoaded: Boolean = False;
446 ShowMap: Boolean = False;
447 DrawRect: PRect = nil;
448 SnapToGrid: Boolean = True;
450 MousePos: Types.TPoint;
451 LastMovePoint: Types.TPoint;
452 MouseLDown: Boolean;
453 MouseRDown: Boolean;
454 MouseMDown: Boolean;
455 MouseLDownPos: Types.TPoint;
456 MouseRDownPos: Types.TPoint;
457 MouseMDownPos: Types.TPoint;
459 SelectFlag: Byte = SELECTFLAG_NONE;
460 MouseAction: Byte = MOUSEACTION_NONE;
461 ResizeType: Byte = RESIZETYPE_NONE;
462 ResizeDirection: Byte = RESIZEDIR_NONE;
464 DrawPressRect: Boolean = False;
465 EditingProperties: Boolean = False;
467 UndoBuffer: Array of Array of TUndoRec = nil;
469 MapTestProcess: TProcessUTF8;
470 MapTestFile: String;
472 {$R *.lfm}
474 //----------------------------------------
475 //Далее идут вспомогательные процедуры
476 //----------------------------------------
478 function NameToBool(Name: String): Boolean;
479 begin
480 if Name = BoolNames[True] then
481 Result := True
482 else
483 Result := False;
484 end;
486 function NameToDir(Name: String): TDirection;
487 begin
488 if Name = DirNames[D_LEFT] then
489 Result := D_LEFT
490 else
491 Result := D_RIGHT;
492 end;
494 function NameToDirAdv(Name: String): Byte;
495 begin
496 if Name = DirNamesAdv[1] then
497 Result := 1
498 else
499 if Name = DirNamesAdv[2] then
500 Result := 2
501 else
502 if Name = DirNamesAdv[3] then
503 Result := 3
504 else
505 Result := 0;
506 end;
508 function ActivateToStr(ActivateType: Byte): String;
509 begin
510 Result := '';
512 if ByteBool(ACTIVATE_PLAYERCOLLIDE and ActivateType) then
513 Result := Result + '+PC';
514 if ByteBool(ACTIVATE_MONSTERCOLLIDE and ActivateType) then
515 Result := Result + '+MC';
516 if ByteBool(ACTIVATE_PLAYERPRESS and ActivateType) then
517 Result := Result + '+PP';
518 if ByteBool(ACTIVATE_MONSTERPRESS and ActivateType) then
519 Result := Result + '+MP';
520 if ByteBool(ACTIVATE_SHOT and ActivateType) then
521 Result := Result + '+SH';
522 if ByteBool(ACTIVATE_NOMONSTER and ActivateType) then
523 Result := Result + '+NM';
525 if (Result <> '') and (Result[1] = '+') then
526 Delete(Result, 1, 1);
527 end;
529 function StrToActivate(Str: String): Byte;
530 begin
531 Result := 0;
533 if Pos('PC', Str) > 0 then
534 Result := ACTIVATE_PLAYERCOLLIDE;
535 if Pos('MC', Str) > 0 then
536 Result := Result or ACTIVATE_MONSTERCOLLIDE;
537 if Pos('PP', Str) > 0 then
538 Result := Result or ACTIVATE_PLAYERPRESS;
539 if Pos('MP', Str) > 0 then
540 Result := Result or ACTIVATE_MONSTERPRESS;
541 if Pos('SH', Str) > 0 then
542 Result := Result or ACTIVATE_SHOT;
543 if Pos('NM', Str) > 0 then
544 Result := Result or ACTIVATE_NOMONSTER;
545 end;
547 function KeyToStr(Key: Byte): String;
548 begin
549 Result := '';
551 if ByteBool(KEY_RED and Key) then
552 Result := Result + '+RK';
553 if ByteBool(KEY_GREEN and Key) then
554 Result := Result + '+GK';
555 if ByteBool(KEY_BLUE and Key) then
556 Result := Result + '+BK';
557 if ByteBool(KEY_REDTEAM and Key) then
558 Result := Result + '+RT';
559 if ByteBool(KEY_BLUETEAM and Key) then
560 Result := Result + '+BT';
562 if (Result <> '') and (Result[1] = '+') then
563 Delete(Result, 1, 1);
564 end;
566 function StrToKey(Str: String): Byte;
567 begin
568 Result := 0;
570 if Pos('RK', Str) > 0 then
571 Result := KEY_RED;
572 if Pos('GK', Str) > 0 then
573 Result := Result or KEY_GREEN;
574 if Pos('BK', Str) > 0 then
575 Result := Result or KEY_BLUE;
576 if Pos('RT', Str) > 0 then
577 Result := Result or KEY_REDTEAM;
578 if Pos('BT', Str) > 0 then
579 Result := Result or KEY_BLUETEAM;
580 end;
582 function EffectToStr(Effect: Byte): String;
583 begin
584 if Effect in [EFFECT_TELEPORT..EFFECT_FIRE] then
585 Result := EffectNames[Effect]
586 else
587 Result := EffectNames[EFFECT_NONE];
588 end;
590 function StrToEffect(Str: String): Byte;
591 var
592 i: Integer;
593 begin
594 Result := EFFECT_NONE;
595 for i := EFFECT_TELEPORT to EFFECT_FIRE do
596 if EffectNames[i] = Str then
597 begin
598 Result := i;
599 Exit;
600 end;
601 end;
603 function MonsterToStr(MonType: Byte): String;
604 begin
605 if MonType in [MONSTER_DEMON..MONSTER_MAN] then
606 Result := MonsterNames[MonType]
607 else
608 Result := MonsterNames[MONSTER_ZOMBY];
609 end;
611 function StrToMonster(Str: String): Byte;
612 var
613 i: Integer;
614 begin
615 Result := MONSTER_ZOMBY;
616 for i := MONSTER_DEMON to MONSTER_MAN do
617 if MonsterNames[i] = Str then
618 begin
619 Result := i;
620 Exit;
621 end;
622 end;
624 function ItemToStr(ItemType: Byte): String;
625 begin
626 if ItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX] then
627 Result := ItemNames[ItemType]
628 else
629 Result := ItemNames[ITEM_AMMO_BULLETS];
630 end;
632 function StrToItem(Str: String): Byte;
633 var
634 i: Integer;
635 begin
636 Result := ITEM_AMMO_BULLETS;
637 for i := ITEM_MEDKIT_SMALL to ITEM_MAX do
638 if ItemNames[i] = Str then
639 begin
640 Result := i;
641 Exit;
642 end;
643 end;
645 function ShotToStr(ShotType: Byte): String;
646 begin
647 if ShotType in [TRIGGER_SHOT_PISTOL..TRIGGER_SHOT_MAX] then
648 Result := ShotNames[ShotType]
649 else
650 Result := ShotNames[TRIGGER_SHOT_PISTOL];
651 end;
653 function StrToShot(Str: String): Byte;
654 var
655 i: Integer;
656 begin
657 Result := TRIGGER_SHOT_PISTOL;
658 for i := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
659 if ShotNames[i] = Str then
660 begin
661 Result := i;
662 Exit;
663 end;
664 end;
666 function SelectedObjectCount(): Word;
667 var
668 a: Integer;
669 begin
670 Result := 0;
672 if SelectedObjects = nil then
673 Exit;
675 for a := 0 to High(SelectedObjects) do
676 if SelectedObjects[a].Live then
677 Result := Result + 1;
678 end;
680 function GetFirstSelected(): Integer;
681 var
682 a: Integer;
683 begin
684 Result := -1;
686 if SelectedObjects = nil then
687 Exit;
689 for a := 0 to High(SelectedObjects) do
690 if SelectedObjects[a].Live then
691 begin
692 Result := a;
693 Exit;
694 end;
695 end;
697 function Normalize16(x: Integer): Integer;
698 begin
699 Result := (x div 16) * 16;
700 end;
702 procedure MoveMap(X, Y: Integer);
703 var
704 rx, ry, ScaleSz: Integer;
705 begin
706 with MainForm.RenderPanel do
707 begin
708 ScaleSz := 16 div Scale;
709 // Размер видимой части карты:
710 rx := Min(Normalize16(Width), Normalize16(gMapInfo.Width)) div 2;
711 ry := Min(Normalize16(Height), Normalize16(gMapInfo.Height)) div 2;
712 // Место клика на мини-карте:
713 MapOffset.X := X - (Width - Max(gMapInfo.Width div ScaleSz, 1) - 1);
714 MapOffset.Y := Y - 1;
715 // Это же место на "большой" карте:
716 MapOffset.X := MapOffset.X * ScaleSz;
717 MapOffset.Y := MapOffset.Y * ScaleSz;
718 // Левый верхний угол новой видимой части карты:
719 MapOffset.X := MapOffset.X - rx;
720 MapOffset.Y := MapOffset.Y - ry;
721 // Выход за границы:
722 MapOffset.X := EnsureRange(MapOffset.X, MainForm.sbHorizontal.Min, MainForm.sbHorizontal.Max);
723 MapOffset.Y := EnsureRange(MapOffset.Y, MainForm.sbVertical.Min, MainForm.sbVertical.Max);
724 // Кратно 16:
725 // MapOffset.X := Normalize16(MapOffset.X);
726 // MapOffset.Y := Normalize16(MapOffset.Y);
727 end;
729 MainForm.sbHorizontal.Position := MapOffset.X;
730 MainForm.sbVertical.Position := MapOffset.Y;
732 MapOffset.X := -MapOffset.X;
733 MapOffset.Y := -MapOffset.Y;
735 MainForm.Resize();
736 end;
738 function IsTexturedPanel(PanelType: Word): Boolean;
739 begin
740 Result := WordBool(PanelType and (PANEL_WALL or PANEL_BACK or PANEL_FORE or
741 PANEL_STEP or PANEL_OPENDOOR or PANEL_CLOSEDOOR or
742 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2));
743 end;
745 procedure FillProperty();
746 var
747 _id: DWORD;
748 str: String;
749 begin
750 MainForm.vleObjectProperty.Strings.Clear();
751 MainForm.RecountSelectedObjects();
753 // Отображаем свойства если выделен только один объект:
754 if SelectedObjectCount() <> 1 then
755 Exit;
757 _id := GetFirstSelected();
758 if not SelectedObjects[_id].Live then
759 Exit;
761 with MainForm.vleObjectProperty do
762 with ItemProps[InsertRow(MsgPropId, IntToStr(SelectedObjects[_id].ID), True)] do
763 begin
764 EditStyle := esSimple;
765 ReadOnly := True;
766 end;
768 case SelectedObjects[0].ObjectType of
769 OBJECT_PANEL:
770 begin
771 with MainForm.vleObjectProperty,
772 gPanels[SelectedObjects[_id].ID] do
773 begin
774 with ItemProps[InsertRow(MsgPropX, IntToStr(X), True)] do
775 begin
776 EditStyle := esSimple;
777 MaxLength := 5;
778 end;
780 with ItemProps[InsertRow(MsgPropY, IntToStr(Y), True)] do
781 begin
782 EditStyle := esSimple;
783 MaxLength := 5;
784 end;
786 with ItemProps[InsertRow(MsgPropWidth, IntToStr(Width), True)] do
787 begin
788 EditStyle := esSimple;
789 MaxLength := 5;
790 end;
792 with ItemProps[InsertRow(MsgPropHeight, IntToStr(Height), True)] do
793 begin
794 EditStyle := esSimple;
795 MaxLength := 5;
796 end;
798 with ItemProps[InsertRow(MsgPropPanelType, GetPanelName(PanelType), True)] do
799 begin
800 EditStyle := esEllipsis;
801 ReadOnly := True;
802 end;
804 if IsTexturedPanel(PanelType) then
805 begin // Может быть текстура
806 with ItemProps[InsertRow(MsgPropPanelTex, TextureName, True)] do
807 begin
808 EditStyle := esEllipsis;
809 ReadOnly := True;
810 end;
812 if TextureName <> '' then
813 begin // Есть текстура
814 with ItemProps[InsertRow(MsgPropPanelAlpha, IntToStr(Alpha), True)] do
815 begin
816 EditStyle := esSimple;
817 MaxLength := 3;
818 end;
820 with ItemProps[InsertRow(MsgPropPanelBlend, BoolNames[Blending], True)] do
821 begin
822 EditStyle := esPickList;
823 ReadOnly := True;
824 end;
825 end;
826 end;
827 end;
828 end;
830 OBJECT_ITEM:
831 begin
832 with MainForm.vleObjectProperty,
833 gItems[SelectedObjects[_id].ID] do
834 begin
835 with ItemProps[InsertRow(MsgPropX, IntToStr(X), True)] do
836 begin
837 EditStyle := esSimple;
838 MaxLength := 5;
839 end;
841 with ItemProps[InsertRow(MsgPropY, IntToStr(Y), True)] do
842 begin
843 EditStyle := esSimple;
844 MaxLength := 5;
845 end;
847 with ItemProps[InsertRow(MsgPropDmOnly, BoolNames[OnlyDM], True)] do
848 begin
849 EditStyle := esPickList;
850 ReadOnly := True;
851 end;
853 with ItemProps[InsertRow(MsgPropItemFalls, BoolNames[Fall], True)] do
854 begin
855 EditStyle := esPickList;
856 ReadOnly := True;
857 end;
858 end;
859 end;
861 OBJECT_MONSTER:
862 begin
863 with MainForm.vleObjectProperty,
864 gMonsters[SelectedObjects[_id].ID] do
865 begin
866 with ItemProps[InsertRow(MsgPropX, IntToStr(X), True)] do
867 begin
868 EditStyle := esSimple;
869 MaxLength := 5;
870 end;
872 with ItemProps[InsertRow(MsgPropY, IntToStr(Y), True)] do
873 begin
874 EditStyle := esSimple;
875 MaxLength := 5;
876 end;
878 with ItemProps[InsertRow(MsgPropDirection, DirNames[Direction], True)] do
879 begin
880 EditStyle := esPickList;
881 ReadOnly := True;
882 end;
883 end;
884 end;
886 OBJECT_AREA:
887 begin
888 with MainForm.vleObjectProperty,
889 gAreas[SelectedObjects[_id].ID] do
890 begin
891 with ItemProps[InsertRow(MsgPropX, IntToStr(X), True)] do
892 begin
893 EditStyle := esSimple;
894 MaxLength := 5;
895 end;
897 with ItemProps[InsertRow(MsgPropY, IntToStr(Y), True)] do
898 begin
899 EditStyle := esSimple;
900 MaxLength := 5;
901 end;
903 with ItemProps[InsertRow(MsgPropDirection, DirNames[Direction], True)] do
904 begin
905 EditStyle := esPickList;
906 ReadOnly := True;
907 end;
908 end;
909 end;
911 OBJECT_TRIGGER:
912 begin
913 with MainForm.vleObjectProperty,
914 gTriggers[SelectedObjects[_id].ID] do
915 begin
916 with ItemProps[InsertRow(MsgPropTrType, GetTriggerName(TriggerType), True)] do
917 begin
918 EditStyle := esSimple;
919 ReadOnly := True;
920 end;
922 with ItemProps[InsertRow(MsgPropX, IntToStr(X), True)] do
923 begin
924 EditStyle := esSimple;
925 MaxLength := 5;
926 end;
928 with ItemProps[InsertRow(MsgPropY, IntToStr(Y), True)] do
929 begin
930 EditStyle := esSimple;
931 MaxLength := 5;
932 end;
934 with ItemProps[InsertRow(MsgPropWidth, IntToStr(Width), True)] do
935 begin
936 EditStyle := esSimple;
937 MaxLength := 5;
938 end;
940 with ItemProps[InsertRow(MsgPropHeight, IntToStr(Height), True)] do
941 begin
942 EditStyle := esSimple;
943 MaxLength := 5;
944 end;
946 with ItemProps[InsertRow(MsgPropTrEnabled, BoolNames[Enabled], True)] do
947 begin
948 EditStyle := esPickList;
949 ReadOnly := True;
950 end;
952 with ItemProps[InsertRow(MsgPropTrTexturePanel, IntToStr(TexturePanel), True)] do
953 begin
954 EditStyle := esEllipsis;
955 ReadOnly := True;
956 end;
958 with ItemProps[InsertRow(MsgPropTrActivation, ActivateToStr(ActivateType), True)] do
959 begin
960 EditStyle := esEllipsis;
961 ReadOnly := True;
962 end;
964 with ItemProps[InsertRow(MsgPropTrKeys, KeyToStr(Key), True)] do
965 begin
966 EditStyle := esEllipsis;
967 ReadOnly := True;
968 end;
970 case TriggerType of
971 TRIGGER_EXIT:
972 begin
973 str := win2utf(Data.MapName);
974 with ItemProps[InsertRow(MsgPropTrNextMap, str, True)] do
975 begin
976 EditStyle := esEllipsis;
977 ReadOnly := True;
978 end;
979 end;
981 TRIGGER_TELEPORT:
982 begin
983 with ItemProps[InsertRow(MsgPropTrTeleportTo, Format('(%d:%d)', [Data.TargetPoint.X, Data.TargetPoint.Y]), True)] do
984 begin
985 EditStyle := esEllipsis;
986 ReadOnly := True;
987 end;
989 with ItemProps[InsertRow(MsgPropTrD2d, BoolNames[Data.d2d_teleport], True)] do
990 begin
991 EditStyle := esPickList;
992 ReadOnly := True;
993 end;
995 with ItemProps[InsertRow(MsgPropTrTeleportSilent, BoolNames[Data.silent_teleport], True)] do
996 begin
997 EditStyle := esPickList;
998 ReadOnly := True;
999 end;
1001 with ItemProps[InsertRow(MsgPropTrTeleportDir, DirNamesAdv[Data.TlpDir], True)] do
1002 begin
1003 EditStyle := esPickList;
1004 ReadOnly := True;
1005 end;
1006 end;
1008 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR,
1009 TRIGGER_DOOR, TRIGGER_DOOR5:
1010 begin
1011 with ItemProps[InsertRow(MsgPropTrDoorPanel, IntToStr(Data.PanelID), True)] do
1012 begin
1013 EditStyle := esEllipsis;
1014 ReadOnly := True;
1015 end;
1017 with ItemProps[InsertRow(MsgPropTrSilent, BoolNames[Data.NoSound], True)] do
1018 begin
1019 EditStyle := esPickList;
1020 ReadOnly := True;
1021 end;
1023 with ItemProps[InsertRow(MsgPropTrD2d, BoolNames[Data.d2d_doors], True)] do
1024 begin
1025 EditStyle := esPickList;
1026 ReadOnly := True;
1027 end;
1028 end;
1030 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1031 begin
1032 with ItemProps[InsertRow(MsgPropTrTrapPanel, IntToStr(Data.PanelID), True)] do
1033 begin
1034 EditStyle := esEllipsis;
1035 ReadOnly := True;
1036 end;
1038 with ItemProps[InsertRow(MsgPropTrSilent, BoolNames[Data.NoSound], True)] do
1039 begin
1040 EditStyle := esPickList;
1041 ReadOnly := True;
1042 end;
1044 with ItemProps[InsertRow(MsgPropTrD2d, BoolNames[Data.d2d_doors], True)] do
1045 begin
1046 EditStyle := esPickList;
1047 ReadOnly := True;
1048 end;
1049 end;
1051 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
1052 TRIGGER_ONOFF:
1053 begin
1054 with ItemProps[InsertRow(MsgPropTrExArea,
1055 Format('(%d:%d %d:%d)', [Data.tX, Data.tY, Data.tWidth, Data.tHeight]), True)] do
1056 begin
1057 EditStyle := esEllipsis;
1058 ReadOnly := True;
1059 end;
1061 with ItemProps[InsertRow(MsgPropTrExDelay, IntToStr(Data.Wait), True)] do
1062 begin
1063 EditStyle := esSimple;
1064 MaxLength := 5;
1065 end;
1067 with ItemProps[InsertRow(MsgPropTrExCount, IntToStr(Data.Count), True)] do
1068 begin
1069 EditStyle := esSimple;
1070 MaxLength := 5;
1071 end;
1073 with ItemProps[InsertRow(MsgPropTrExMonster, IntToStr(Data.MonsterID-1), True)] do
1074 begin
1075 EditStyle := esEllipsis;
1076 ReadOnly := True;
1077 end;
1079 if TriggerType = TRIGGER_PRESS then
1080 with ItemProps[InsertRow(MsgPropTrExRandom, BoolNames[Data.ExtRandom], True)] do
1081 begin
1082 EditStyle := esPickList;
1083 ReadOnly := True;
1084 end;
1085 end;
1087 TRIGGER_SECRET:
1090 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
1091 begin
1092 with ItemProps[InsertRow(MsgPropTrLiftPanel, IntToStr(Data.PanelID), True)] do
1093 begin
1094 EditStyle := esEllipsis;
1095 ReadOnly := True;
1096 end;
1098 with ItemProps[InsertRow(MsgPropTrSilent, BoolNames[Data.NoSound], True)] do
1099 begin
1100 EditStyle := esPickList;
1101 ReadOnly := True;
1102 end;
1104 with ItemProps[InsertRow(MsgPropTrD2d, BoolNames[Data.d2d_doors], True)] do
1105 begin
1106 EditStyle := esPickList;
1107 ReadOnly := True;
1108 end;
1109 end;
1111 TRIGGER_TEXTURE:
1112 begin
1113 with ItemProps[InsertRow(MsgPropTrTextureOnce, BoolNames[Data.ActivateOnce], True)] do
1114 begin
1115 EditStyle := esPickList;
1116 ReadOnly := True;
1117 end;
1119 with ItemProps[InsertRow(MsgPropTrTextureAnimOnce, BoolNames[Data.AnimOnce], True)] do
1120 begin
1121 EditStyle := esPickList;
1122 ReadOnly := True;
1123 end;
1124 end;
1126 TRIGGER_SOUND:
1127 begin
1128 str := win2utf(Data.SoundName);
1129 with ItemProps[InsertRow(MsgPropTrSoundName, str, True)] do
1130 begin
1131 EditStyle := esEllipsis;
1132 ReadOnly := True;
1133 end;
1135 with ItemProps[InsertRow(MsgPropTrSoundVolume, IntToStr(Data.Volume), True)] do
1136 begin
1137 EditStyle := esSimple;
1138 MaxLength := 3;
1139 end;
1141 with ItemProps[InsertRow(MsgPropTrSoundPan, IntToStr(Data.Pan), True)] do
1142 begin
1143 EditStyle := esSimple;
1144 MaxLength := 3;
1145 end;
1147 with ItemProps[InsertRow(MsgPropTrSoundCount, IntToStr(Data.PlayCount), True)] do
1148 begin
1149 EditStyle := esSimple;
1150 MaxLength := 3;
1151 end;
1153 with ItemProps[InsertRow(MsgPropTrSoundLocal, BoolNames[Data.Local], True)] do
1154 begin
1155 EditStyle := esPickList;
1156 ReadOnly := True;
1157 end;
1159 with ItemProps[InsertRow(MsgPropTrSoundSwitch, BoolNames[Data.SoundSwitch], True)] do
1160 begin
1161 EditStyle := esPickList;
1162 ReadOnly := True;
1163 end;
1164 end;
1166 TRIGGER_SPAWNMONSTER:
1167 begin
1168 with ItemProps[InsertRow(MsgPropTrMonsterType, MonsterToStr(Data.MonType), True)] do
1169 begin
1170 EditStyle := esEllipsis;
1171 ReadOnly := True;
1172 end;
1174 with ItemProps[InsertRow(MsgPropTrSpawnTo,
1175 Format('(%d:%d)', [Data.MonPos.X, Data.MonPos.Y]), True)] do
1176 begin
1177 EditStyle := esEllipsis;
1178 ReadOnly := True;
1179 end;
1181 with ItemProps[InsertRow(MsgPropDirection, DirNames[TDirection(Data.MonDir)], True)] do
1182 begin
1183 EditStyle := esPickList;
1184 ReadOnly := True;
1185 end;
1187 with ItemProps[InsertRow(MsgPropTrHealth, IntToStr(Data.MonHealth), True)] do
1188 begin
1189 EditStyle := esSimple;
1190 MaxLength := 5;
1191 end;
1193 with ItemProps[InsertRow(MsgPropTrMonsterActive, BoolNames[Data.MonActive], True)] do
1194 begin
1195 EditStyle := esPickList;
1196 ReadOnly := True;
1197 end;
1199 with ItemProps[InsertRow(MsgPropTrCount, IntToStr(Data.MonCount), True)] do
1200 begin
1201 EditStyle := esSimple;
1202 MaxLength := 5;
1203 end;
1205 with ItemProps[InsertRow(MsgPropTrFxType, EffectToStr(Data.MonEffect), True)] do
1206 begin
1207 EditStyle := esEllipsis;
1208 ReadOnly := True;
1209 end;
1211 with ItemProps[InsertRow(MsgPropTrSpawnMax, IntToStr(Data.MonMax), True)] do
1212 begin
1213 EditStyle := esSimple;
1214 MaxLength := 5;
1215 end;
1217 with ItemProps[InsertRow(MsgPropTrSpawnDelay, IntToStr(Data.MonDelay), True)] do
1218 begin
1219 EditStyle := esSimple;
1220 MaxLength := 5;
1221 end;
1223 case Data.MonBehav of
1224 1: str := MsgPropTrMonsterBehaviour1;
1225 2: str := MsgPropTrMonsterBehaviour2;
1226 3: str := MsgPropTrMonsterBehaviour3;
1227 4: str := MsgPropTrMonsterBehaviour4;
1228 5: str := MsgPropTrMonsterBehaviour5;
1229 else str := MsgPropTrMonsterBehaviour0;
1230 end;
1231 with ItemProps[InsertRow(MsgPropTrMonsterBehaviour, str, True)] do
1232 begin
1233 EditStyle := esPickList;
1234 ReadOnly := True;
1235 end;
1236 end;
1238 TRIGGER_SPAWNITEM:
1239 begin
1240 with ItemProps[InsertRow(MsgPropTrItemType, ItemToStr(Data.ItemType), True)] do
1241 begin
1242 EditStyle := esEllipsis;
1243 ReadOnly := True;
1244 end;
1246 with ItemProps[InsertRow(MsgPropTrSpawnTo,
1247 Format('(%d:%d)', [Data.ItemPos.X, Data.ItemPos.Y]), True)] do
1248 begin
1249 EditStyle := esEllipsis;
1250 ReadOnly := True;
1251 end;
1253 with ItemProps[InsertRow(MsgPropDmOnly, BoolNames[Data.ItemOnlyDM], True)] do
1254 begin
1255 EditStyle := esPickList;
1256 ReadOnly := True;
1257 end;
1259 with ItemProps[InsertRow(MsgPropItemFalls, BoolNames[Data.ItemFalls], True)] do
1260 begin
1261 EditStyle := esPickList;
1262 ReadOnly := True;
1263 end;
1265 with ItemProps[InsertRow(MsgPropTrCount, IntToStr(Data.ItemCount), True)] do
1266 begin
1267 EditStyle := esSimple;
1268 MaxLength := 5;
1269 end;
1271 with ItemProps[InsertRow(MsgPropTrFxType, EffectToStr(Data.ItemEffect), True)] do
1272 begin
1273 EditStyle := esEllipsis;
1274 ReadOnly := True;
1275 end;
1277 with ItemProps[InsertRow(MsgPropTrSpawnMax, IntToStr(Data.ItemMax), True)] do
1278 begin
1279 EditStyle := esSimple;
1280 MaxLength := 5;
1281 end;
1283 with ItemProps[InsertRow(MsgPropTrSpawnDelay, IntToStr(Data.ItemDelay), True)] do
1284 begin
1285 EditStyle := esSimple;
1286 MaxLength := 5;
1287 end;
1288 end;
1290 TRIGGER_MUSIC:
1291 begin
1292 str := win2utf(Data.MusicName);
1293 with ItemProps[InsertRow(MsgPropTrMusicName, str, True)] do
1294 begin
1295 EditStyle := esEllipsis;
1296 ReadOnly := True;
1297 end;
1299 if Data.MusicAction = 1 then
1300 str := MsgPropTrMusicOn
1301 else
1302 str := MsgPropTrMusicOff;
1304 with ItemProps[InsertRow(MsgPropTrMusicAct, str, True)] do
1305 begin
1306 EditStyle := esPickList;
1307 ReadOnly := True;
1308 end;
1309 end;
1311 TRIGGER_PUSH:
1312 begin
1313 with ItemProps[InsertRow(MsgPropTrPushAngle, IntToStr(Data.PushAngle), True)] do
1314 begin
1315 EditStyle := esSimple;
1316 MaxLength := 4;
1317 end;
1318 with ItemProps[InsertRow(MsgPropTrPushForce, IntToStr(Data.PushForce), True)] do
1319 begin
1320 EditStyle := esSimple;
1321 MaxLength := 4;
1322 end;
1323 with ItemProps[InsertRow(MsgPropTrPushReset, BoolNames[Data.ResetVel], True)] do
1324 begin
1325 EditStyle := esPickList;
1326 ReadOnly := True;
1327 end;
1328 end;
1330 TRIGGER_SCORE:
1331 begin
1332 case Data.ScoreAction of
1333 1: str := MsgPropTrScoreAct1;
1334 2: str := MsgPropTrScoreAct2;
1335 3: str := MsgPropTrScoreAct3;
1336 else str := MsgPropTrScoreAct0;
1337 end;
1338 with ItemProps[InsertRow(MsgPropTrScoreAct, str, True)] do
1339 begin
1340 EditStyle := esPickList;
1341 ReadOnly := True;
1342 end;
1343 with ItemProps[InsertRow(MsgPropTrCount, IntToStr(Data.ScoreCount), True)] do
1344 begin
1345 EditStyle := esSimple;
1346 MaxLength := 3;
1347 end;
1348 case Data.ScoreTeam of
1349 1: str := MsgPropTrScoreTeam1;
1350 2: str := MsgPropTrScoreTeam2;
1351 3: str := MsgPropTrScoreTeam3;
1352 else str := MsgPropTrScoreTeam0;
1353 end;
1354 with ItemProps[InsertRow(MsgPropTrScoreTeam, str, True)] do
1355 begin
1356 EditStyle := esPickList;
1357 ReadOnly := True;
1358 end;
1359 with ItemProps[InsertRow(MsgPropTrScoreCon, BoolNames[Data.ScoreCon], True)] do
1360 begin
1361 EditStyle := esPickList;
1362 ReadOnly := True;
1363 end;
1364 with ItemProps[InsertRow(MsgPropTrScoreMsg, BoolNames[Data.ScoreMsg], True)] do
1365 begin
1366 EditStyle := esPickList;
1367 ReadOnly := True;
1368 end;
1369 end;
1371 TRIGGER_MESSAGE:
1372 begin
1373 case Data.MessageKind of
1374 1: str := MsgPropTrMessageKind1;
1375 else str := MsgPropTrMessageKind0;
1376 end;
1377 with ItemProps[InsertRow(MsgPropTrMessageKind, str, True)] do
1378 begin
1379 EditStyle := esPickList;
1380 ReadOnly := True;
1381 end;
1382 case Data.MessageSendTo of
1383 1: str := MsgPropTrMessageTo1;
1384 2: str := MsgPropTrMessageTo2;
1385 3: str := MsgPropTrMessageTo3;
1386 4: str := MsgPropTrMessageTo4;
1387 5: str := MsgPropTrMessageTo5;
1388 else str := MsgPropTrMessageTo0;
1389 end;
1390 with ItemProps[InsertRow(MsgPropTrMessageTo, str, True)] do
1391 begin
1392 EditStyle := esPickList;
1393 ReadOnly := True;
1394 end;
1395 str := win2utf(Data.MessageText);
1396 with ItemProps[InsertRow(MsgPropTrMessageText, str, True)] do
1397 begin
1398 EditStyle := esSimple;
1399 MaxLength := 100;
1400 end;
1401 with ItemProps[InsertRow(MsgPropTrMessageTime, IntToStr(Data.MessageTime), True)] do
1402 begin
1403 EditStyle := esSimple;
1404 MaxLength := 5;
1405 end;
1406 end;
1408 TRIGGER_DAMAGE:
1409 begin
1410 with ItemProps[InsertRow(MsgPropTrDamageValue, IntToStr(Data.DamageValue), True)] do
1411 begin
1412 EditStyle := esSimple;
1413 MaxLength := 5;
1414 end;
1415 with ItemProps[InsertRow(MsgPropTrInterval, IntToStr(Data.DamageInterval), True)] do
1416 begin
1417 EditStyle := esSimple;
1418 MaxLength := 5;
1419 end;
1420 case Data.DamageKind of
1421 3: str := MsgPropTrDamageKind3;
1422 4: str := MsgPropTrDamageKind4;
1423 5: str := MsgPropTrDamageKind5;
1424 6: str := MsgPropTrDamageKind6;
1425 7: str := MsgPropTrDamageKind7;
1426 8: str := MsgPropTrDamageKind8;
1427 else str := MsgPropTrDamageKind0;
1428 end;
1429 with ItemProps[InsertRow(MsgPropTrDamageKind, str, True)] do
1430 begin
1431 EditStyle := esPickList;
1432 ReadOnly := True;
1433 end;
1434 end;
1436 TRIGGER_HEALTH:
1437 begin
1438 with ItemProps[InsertRow(MsgPropTrHealth, IntToStr(Data.HealValue), True)] do
1439 begin
1440 EditStyle := esSimple;
1441 MaxLength := 5;
1442 end;
1443 with ItemProps[InsertRow(MsgPropTrInterval, IntToStr(Data.HealInterval), True)] do
1444 begin
1445 EditStyle := esSimple;
1446 MaxLength := 5;
1447 end;
1448 with ItemProps[InsertRow(MsgPropTrHealthMax, BoolNames[Data.HealMax], True)] do
1449 begin
1450 EditStyle := esPickList;
1451 ReadOnly := True;
1452 end;
1453 with ItemProps[InsertRow(MsgPropTrSilent, BoolNames[Data.HealSilent], True)] do
1454 begin
1455 EditStyle := esPickList;
1456 ReadOnly := True;
1457 end;
1458 end;
1460 TRIGGER_SHOT:
1461 begin
1462 with ItemProps[InsertRow(MsgPropTrShotType, ShotToStr(Data.ShotType), True)] do
1463 begin
1464 EditStyle := esEllipsis;
1465 ReadOnly := True;
1466 end;
1468 with ItemProps[InsertRow(MsgPropTrShotSound, BoolNames[Data.ShotSound], True)] do
1469 begin
1470 EditStyle := esPickList;
1471 ReadOnly := True;
1472 end;
1474 with ItemProps[InsertRow(MsgPropTrShotPanel, IntToStr(Data.ShotPanelID), True)] do
1475 begin
1476 EditStyle := esEllipsis;
1477 ReadOnly := True;
1478 end;
1480 case Data.ShotTarget of
1481 1: str := MsgPropTrShotTo1;
1482 2: str := MsgPropTrShotTo2;
1483 3: str := MsgPropTrShotTo3;
1484 4: str := MsgPropTrShotTo4;
1485 5: str := MsgPropTrShotTo5;
1486 6: str := MsgPropTrShotTo6;
1487 else str := MsgPropTrShotTo0;
1488 end;
1489 with ItemProps[InsertRow(MsgPropTrShotTo, str, True)] do
1490 begin
1491 EditStyle := esPickList;
1492 ReadOnly := True;
1493 end;
1495 with ItemProps[InsertRow(MsgPropTrShotSight, IntToStr(Data.ShotIntSight), True)] do
1496 begin
1497 EditStyle := esSimple;
1498 MaxLength := 3;
1499 end;
1501 case Data.ShotAim of
1502 1: str := MsgPropTrShotAim1;
1503 2: str := MsgPropTrShotAim2;
1504 3: str := MsgPropTrShotAim3;
1505 else str := MsgPropTrShotAim0;
1506 end;
1507 with ItemProps[InsertRow(MsgPropTrShotAim, str, True)] do
1508 begin
1509 EditStyle := esPickList;
1510 ReadOnly := True;
1511 end;
1513 with ItemProps[InsertRow(MsgPropTrSpawnTo,
1514 Format('(%d:%d)', [Data.ShotPos.X, Data.ShotPos.Y]), True)] do
1515 begin
1516 EditStyle := esEllipsis;
1517 ReadOnly := True;
1518 end;
1520 with ItemProps[InsertRow(MsgPropTrShotAngle, IntToStr(Data.ShotAngle), True)] do
1521 begin
1522 EditStyle := esSimple;
1523 MaxLength := 4;
1524 end;
1526 with ItemProps[InsertRow(MsgPropTrExDelay, IntToStr(Data.ShotWait), True)] do
1527 begin
1528 EditStyle := esSimple;
1529 MaxLength := 5;
1530 end;
1532 with ItemProps[InsertRow(MsgPropTrShotAcc, IntToStr(Data.ShotAccuracy), True)] do
1533 begin
1534 EditStyle := esSimple;
1535 MaxLength := 5;
1536 end;
1538 with ItemProps[InsertRow(MsgPropTrShotAmmo, IntToStr(Data.ShotAmmo), True)] do
1539 begin
1540 EditStyle := esSimple;
1541 MaxLength := 5;
1542 end;
1544 with ItemProps[InsertRow(MsgPropTrShotReload, IntToStr(Data.ShotIntReload), True)] do
1545 begin
1546 EditStyle := esSimple;
1547 MaxLength := 4;
1548 end;
1549 end;
1551 TRIGGER_EFFECT:
1552 begin
1553 with ItemProps[InsertRow(MsgPropTrCount, IntToStr(Data.FXCount), True)] do
1554 begin
1555 EditStyle := esSimple;
1556 MaxLength := 3;
1557 end;
1559 if Data.FXType = 0 then
1560 str := MsgPropTrEffectParticle
1561 else
1562 str := MsgPropTrEffectAnimation;
1563 with ItemProps[InsertRow(MsgPropTrEffectType, str, True)] do
1564 begin
1565 EditStyle := esEllipsis;
1566 ReadOnly := True;
1567 end;
1569 str := '';
1570 if Data.FXType = 0 then
1571 case Data.FXSubType of
1572 TRIGGER_EFFECT_SLIQUID:
1573 str := MsgPropTrEffectSliquid;
1574 TRIGGER_EFFECT_LLIQUID:
1575 str := MsgPropTrEffectLliquid;
1576 TRIGGER_EFFECT_DLIQUID:
1577 str := MsgPropTrEffectDliquid;
1578 TRIGGER_EFFECT_BLOOD:
1579 str := MsgPropTrEffectBlood;
1580 TRIGGER_EFFECT_SPARK:
1581 str := MsgPropTrEffectSpark;
1582 TRIGGER_EFFECT_BUBBLE:
1583 str := MsgPropTrEffectBubble;
1584 end;
1585 if Data.FXType = 1 then
1586 begin
1587 if (Data.FXSubType = 0) or (Data.FXSubType > EFFECT_FIRE) then
1588 Data.FXSubType := EFFECT_TELEPORT;
1589 str := EffectToStr(Data.FXSubType);
1590 end;
1591 with ItemProps[InsertRow(MsgPropTrEffectSubtype, str, True)] do
1592 begin
1593 EditStyle := esEllipsis;
1594 ReadOnly := True;
1595 end;
1597 with ItemProps[InsertRow(MsgPropTrEffectColor, IntToStr(Data.FXColorR or (Data.FXColorG shl 8) or (Data.FXColorB shl 16)), True)] do
1598 begin
1599 EditStyle := esEllipsis;
1600 ReadOnly := True;
1601 end;
1603 with ItemProps[InsertRow(MsgPropTrEffectCenter, BoolNames[Data.FXPos = 0], True)] do
1604 begin
1605 EditStyle := esPickList;
1606 ReadOnly := True;
1607 end;
1609 with ItemProps[InsertRow(MsgPropTrExDelay, IntToStr(Data.FXWait), True)] do
1610 begin
1611 EditStyle := esSimple;
1612 MaxLength := 5;
1613 end;
1615 with ItemProps[InsertRow(MsgPropTrEffectVelx, IntToStr(Data.FXVelX), True)] do
1616 begin
1617 EditStyle := esSimple;
1618 MaxLength := 4;
1619 end;
1621 with ItemProps[InsertRow(MsgPropTrEffectVely, IntToStr(Data.FXVelY), True)] do
1622 begin
1623 EditStyle := esSimple;
1624 MaxLength := 4;
1625 end;
1627 with ItemProps[InsertRow(MsgPropTrEffectSpl, IntToStr(Data.FXSpreadL), True)] do
1628 begin
1629 EditStyle := esSimple;
1630 MaxLength := 3;
1631 end;
1633 with ItemProps[InsertRow(MsgPropTrEffectSpr, IntToStr(Data.FXSpreadR), True)] do
1634 begin
1635 EditStyle := esSimple;
1636 MaxLength := 3;
1637 end;
1639 with ItemProps[InsertRow(MsgPropTrEffectSpu, IntToStr(Data.FXSpreadU), True)] do
1640 begin
1641 EditStyle := esSimple;
1642 MaxLength := 3;
1643 end;
1645 with ItemProps[InsertRow(MsgPropTrEffectSpd, IntToStr(Data.FXSpreadD), True)] do
1646 begin
1647 EditStyle := esSimple;
1648 MaxLength := 3;
1649 end;
1650 end;
1651 end; //case TriggerType
1652 end;
1653 end; // OBJECT_TRIGGER:
1654 end;
1655 end;
1657 procedure ChangeShownProperty(Name: String; NewValue: String);
1658 var
1659 row: Integer;
1660 begin
1661 if SelectedObjectCount() <> 1 then
1662 Exit;
1663 if not SelectedObjects[GetFirstSelected()].Live then
1664 Exit;
1666 // Есть ли такой ключ:
1667 if MainForm.vleObjectProperty.FindRow(Name, row) then
1668 begin
1669 MainForm.vleObjectProperty.Values[Name] := NewValue;
1670 end;
1671 end;
1673 procedure SelectObject(fObjectType: Byte; fID: DWORD; Multi: Boolean);
1674 var
1675 a: Integer;
1676 b: Boolean;
1677 begin
1678 if Multi then
1679 begin
1680 b := False;
1682 // Уже выделен - убираем:
1683 if SelectedObjects <> nil then
1684 for a := 0 to High(SelectedObjects) do
1685 with SelectedObjects[a] do
1686 if Live and (ID = fID) and
1687 (ObjectType = fObjectType) then
1688 begin
1689 Live := False;
1690 b := True;
1691 end;
1693 if b then
1694 Exit;
1696 SetLength(SelectedObjects, Length(SelectedObjects)+1);
1698 with SelectedObjects[High(SelectedObjects)] do
1699 begin
1700 ObjectType := fObjectType;
1701 ID := fID;
1702 Live := True;
1703 end;
1704 end
1705 else // not Multi
1706 begin
1707 SetLength(SelectedObjects, 1);
1709 with SelectedObjects[0] do
1710 begin
1711 ObjectType := fObjectType;
1712 ID := fID;
1713 Live := True;
1714 end;
1715 end;
1717 MainForm.miCopy.Enabled := True;
1718 MainForm.miCut.Enabled := True;
1720 if fObjectType = OBJECT_PANEL then
1721 begin
1722 MainForm.miToFore.Enabled := True;
1723 MainForm.miToBack.Enabled := True;
1724 end;
1725 end;
1727 procedure RemoveSelectFromObjects();
1728 begin
1729 SelectedObjects := nil;
1730 DrawPressRect := False;
1731 MouseLDown := False;
1732 MouseRDown := False;
1733 MouseAction := MOUSEACTION_NONE;
1734 SelectFlag := SELECTFLAG_NONE;
1735 ResizeType := RESIZETYPE_NONE;
1736 ResizeDirection := RESIZEDIR_NONE;
1738 MainForm.vleObjectProperty.Strings.Clear();
1740 MainForm.miCopy.Enabled := False;
1741 MainForm.miCut.Enabled := False;
1742 MainForm.miToFore.Enabled := False;
1743 MainForm.miToBack.Enabled := False;
1744 end;
1746 procedure DeleteSelectedObjects();
1747 var
1748 i, a, ii: Integer;
1749 b: Boolean;
1750 begin
1751 if SelectedObjects = nil then
1752 Exit;
1754 b := False;
1755 i := 0;
1757 for a := 0 to High(SelectedObjects) do
1758 with SelectedObjects[a] do
1759 if Live then
1760 begin
1761 if not b then
1762 begin
1763 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1764 i := High(UndoBuffer);
1765 b := True;
1766 end;
1768 SetLength(UndoBuffer[i], Length(UndoBuffer[i])+1);
1769 ii := High(UndoBuffer[i]);
1771 case ObjectType of
1772 OBJECT_PANEL:
1773 begin
1774 UndoBuffer[i, ii].UndoType := UNDO_DELETE_PANEL;
1775 New(UndoBuffer[i, ii].Panel);
1776 UndoBuffer[i, ii].Panel^ := gPanels[ID];
1777 end;
1778 OBJECT_ITEM:
1779 begin
1780 UndoBuffer[i, ii].UndoType := UNDO_DELETE_ITEM;
1781 UndoBuffer[i, ii].Item := gItems[ID];
1782 end;
1783 OBJECT_AREA:
1784 begin
1785 UndoBuffer[i, ii].UndoType := UNDO_DELETE_AREA;
1786 UndoBuffer[i, ii].Area := gAreas[ID];
1787 end;
1788 OBJECT_TRIGGER:
1789 begin
1790 UndoBuffer[i, ii].UndoType := UNDO_DELETE_TRIGGER;
1791 UndoBuffer[i, ii].Trigger := gTriggers[ID];
1792 end;
1793 end;
1795 RemoveObject(ID, ObjectType);
1796 end;
1798 RemoveSelectFromObjects();
1800 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1801 MainForm.RecountSelectedObjects();
1802 end;
1804 procedure Undo_Add(ObjectType: Byte; ID: DWORD; Group: Boolean = False);
1805 var
1806 i, ii: Integer;
1807 begin
1808 if (not Group) or (Length(UndoBuffer) = 0) then
1809 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1810 SetLength(UndoBuffer[High(UndoBuffer)], Length(UndoBuffer[High(UndoBuffer)])+1);
1811 i := High(UndoBuffer);
1812 ii := High(UndoBuffer[i]);
1814 case ObjectType of
1815 OBJECT_PANEL:
1816 UndoBuffer[i, ii].UndoType := UNDO_ADD_PANEL;
1817 OBJECT_ITEM:
1818 UndoBuffer[i, ii].UndoType := UNDO_ADD_ITEM;
1819 OBJECT_MONSTER:
1820 UndoBuffer[i, ii].UndoType := UNDO_ADD_MONSTER;
1821 OBJECT_AREA:
1822 UndoBuffer[i, ii].UndoType := UNDO_ADD_AREA;
1823 OBJECT_TRIGGER:
1824 UndoBuffer[i, ii].UndoType := UNDO_ADD_TRIGGER;
1825 end;
1827 UndoBuffer[i, ii].AddID := ID;
1829 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1830 end;
1832 procedure FullClear();
1833 begin
1834 RemoveSelectFromObjects();
1835 ClearMap();
1836 LoadSky(gMapInfo.SkyName);
1837 UndoBuffer := nil;
1838 slInvalidTextures.Clear();
1839 MapCheckForm.lbErrorList.Clear();
1840 MapCheckForm.mErrorDescription.Clear();
1842 MainForm.miUndo.Enabled := False;
1843 MainForm.sbHorizontal.Position := 0;
1844 MainForm.sbVertical.Position := 0;
1845 MainForm.FormResize(nil);
1846 MainForm.Caption := FormCaption;
1847 OpenedMap := '';
1848 OpenedWAD := '';
1849 end;
1851 procedure ErrorMessageBox(str: String);
1852 begin
1853 Application.MessageBox(PChar(str), PChar(MsgMsgError),
1854 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
1855 end;
1857 function CheckProperty(): Boolean;
1858 var
1859 _id: Integer;
1860 begin
1861 Result := False;
1863 _id := GetFirstSelected();
1865 if SelectedObjects[_id].ObjectType = OBJECT_PANEL then
1866 with gPanels[SelectedObjects[_id].ID] do
1867 begin
1868 if TextureWidth <> 0 then
1869 if StrToIntDef(MainForm.vleObjectProperty.Values[MsgPropWidth], 1) mod TextureWidth <> 0 then
1870 begin
1871 ErrorMessageBox(Format(MsgMsgWrongTexwidth,
1872 [TextureWidth]));
1873 Exit;
1874 end;
1876 if TextureHeight <> 0 then
1877 if StrToIntDef(Trim(MainForm.vleObjectProperty.Values[MsgPropHeight]), 1) mod TextureHeight <> 0 then
1878 begin
1879 ErrorMessageBox(Format(MsgMsgWrongTexheight,
1880 [TextureHeight]));
1881 Exit;
1882 end;
1884 if IsTexturedPanel(PanelType) and (TextureName <> '') then
1885 if not (StrToIntDef(MainForm.vleObjectProperty.Values[MsgPropPanelAlpha], -1) in [0..255]) then
1886 begin
1887 ErrorMessageBox(MsgMsgWrongAlpha);
1888 Exit;
1889 end;
1890 end;
1892 if SelectedObjects[_id].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
1893 if (StrToIntDef(MainForm.vleObjectProperty.Values[MsgPropWidth], 0) <= 0) or
1894 (StrToIntDef(MainForm.vleObjectProperty.Values[MsgPropHeight], 0) <= 0) then
1895 begin
1896 ErrorMessageBox(MsgMsgWrongSize);
1897 Exit;
1898 end;
1900 if (Trim(MainForm.vleObjectProperty.Values[MsgPropX]) = '') or
1901 (Trim(MainForm.vleObjectProperty.Values[MsgPropY]) = '') then
1902 begin
1903 ErrorMessageBox(MsgMsgWrongXy);
1904 Exit;
1905 end;
1907 Result := True;
1908 end;
1910 procedure SelectTexture(ID: Integer);
1911 begin
1912 MainForm.lbTextureList.ItemIndex := ID;
1913 MainForm.lbTextureListClick(nil);
1914 end;
1916 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
1917 var
1918 a, FrameLen: Integer;
1919 ok: Boolean;
1920 FileName: String;
1921 ResourceName: String;
1922 FullResourceName: String;
1923 SectionName: String;
1924 Data: Pointer;
1925 Width, Height: Word;
1926 fn: String;
1927 begin
1928 Data := nil;
1929 FrameLen := 0;
1930 Width := 0;
1931 Height := 0;
1933 if aSection = '..' then
1934 SectionName := ''
1935 else
1936 SectionName := aSection;
1938 if aWAD = '' then
1939 aWAD := MsgWadSpecialMap;
1941 if aWAD = MsgWadSpecialMap then
1942 begin // Файл карты
1943 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
1944 FileName := fn;
1945 ResourceName := ':'+SectionName+'\'+aTex;
1946 end
1947 else
1948 if aWAD = MsgWadSpecialTexs then
1949 begin // Спец. текстуры
1950 FileName := '';
1951 ResourceName := aTex;
1952 end
1953 else
1954 begin // Внешний WAD
1955 FileName := WadsDir + DirectorySeparator + aWAD;
1956 ResourceName := aWAD+':'+SectionName+'\'+aTex;
1957 end;
1959 ok := True;
1961 // Есть ли уже такая текстура:
1962 for a := 0 to MainForm.lbTextureList.Items.Count-1 do
1963 if ResourceName = MainForm.lbTextureList.Items[a] then
1964 begin
1965 if not silent then
1966 ErrorMessageBox(Format(MsgMsgTextureAlready,
1967 [ResourceName]));
1968 ok := False;
1969 end;
1971 // Название ресурса <= 64 символов:
1972 if Length(ResourceName) > 64 then
1973 begin
1974 if not silent then
1975 ErrorMessageBox(Format(MsgMsgResName64,
1976 [ResourceName]));
1977 ok := False;
1978 end;
1980 if ok then
1981 begin
1982 a := -1;
1983 if aWAD = MsgWadSpecialTexs then
1984 begin
1985 a := MainForm.lbTextureList.Items.Add(ResourceName);
1986 if not silent then
1987 SelectTexture(a);
1988 Result := True;
1989 Exit;
1990 end;
1992 FullResourceName := FileName+':'+SectionName+'\'+aTex;
1994 if IsAnim(FullResourceName) then
1995 begin // Аним. текстура
1996 GetFrame(FullResourceName, Data, FrameLen, Width, Height);
1998 if not g_CreateTextureMemorySize(Data, FrameLen, ResourceName, 0, 0, Width, Height, 1) then
1999 ok := False;
2000 a := MainForm.lbTextureList.Items.Add(ResourceName);
2001 end
2002 else // Обычная текстура
2003 begin
2004 if not g_CreateTextureWAD(ResourceName, FullResourceName) then
2005 ok := False;
2006 a := MainForm.lbTextureList.Items.Add(ResourceName);
2007 end;
2008 if (not ok) and (slInvalidTextures.IndexOf(ResourceName) = -1) then
2009 begin
2010 slInvalidTextures.Add(ResourceName);
2011 ok := True;
2012 end;
2013 if (a > -1) and (not silent) then
2014 SelectTexture(a);
2015 end;
2017 Result := ok;
2018 end;
2020 procedure UpdateCaption(sMap, sFile, sRes: String);
2021 begin
2022 with MainForm do
2023 if (sFile = '') and (sRes = '') and (sMap = '') then
2024 Caption := FormCaption
2025 else
2026 if sMap = '' then
2027 Caption := Format('%s - %s:%s', [FormCaption, sFile, sRes])
2028 else
2029 if (sFile <> '') and (sRes <> '') then
2030 Caption := Format('%s - %s (%s:%s)', [FormCaption, sMap, sFile, sRes])
2031 else
2032 Caption := Format('%s - %s', [FormCaption, sMap]);
2033 end;
2035 procedure OpenMap(FileName: String; mapN: String);
2036 var
2037 MapName: String;
2038 idx: Integer;
2039 begin
2040 SelectMapForm.Caption := MsgCapOpen;
2041 SelectMapForm.GetMaps(FileName);
2043 if (FileName = OpenedWAD) and
2044 (OpenedMap <> '') then
2045 begin
2046 MapName := OpenedMap;
2047 while (Pos(':\', MapName) > 0) do
2048 Delete(MapName, 1, Pos(':\', MapName) + 1);
2050 idx := SelectMapForm.lbMapList.Items.IndexOf(MapName);
2051 SelectMapForm.lbMapList.ItemIndex := idx;
2052 end
2053 else
2054 if SelectMapForm.lbMapList.Count > 0 then
2055 SelectMapForm.lbMapList.ItemIndex := 0
2056 else
2057 SelectMapForm.lbMapList.ItemIndex := -1;
2059 if mapN = '' then
2060 idx := -1
2061 else
2062 idx := SelectMapForm.lbMapList.Items.IndexOf(mapN);
2064 if idx < 0 then
2065 begin
2066 if (SelectMapForm.ShowModal() = mrOK) and
2067 (SelectMapForm.lbMapList.ItemIndex <> -1) then
2068 idx := SelectMapForm.lbMapList.ItemIndex
2069 else
2070 Exit;
2071 end;
2073 MapName := SelectMapForm.lbMapList.Items[idx];
2075 with MainForm do
2076 begin
2077 FullClear();
2079 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
2080 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
2081 pLoadProgress.Show();
2083 OpenedMap := FileName+':\'+MapName;
2084 OpenedWAD := FileName;
2086 idx := RecentFiles.IndexOf(OpenedMap);
2087 // Такая карта уже недавно открывалась:
2088 if idx >= 0 then
2089 RecentFiles.Delete(idx);
2090 RecentFiles.Insert(0, OpenedMap);
2091 RefreshRecentMenu();
2093 LoadMap(OpenedMap);
2095 pLoadProgress.Hide();
2096 FormResize(nil);
2098 lbTextureList.Sorted := True;
2099 lbTextureList.Sorted := False;
2101 UpdateCaption(gMapInfo.Name, ExtractFileName(FileName), MapName);
2102 end;
2103 end;
2105 procedure MoveSelectedObjects(Wall, alt: Boolean; dx, dy: Integer);
2106 var
2107 okX, okY: Boolean;
2108 a: Integer;
2109 begin
2110 if SelectedObjects = nil then
2111 Exit;
2113 okX := True;
2114 okY := True;
2116 if Wall then
2117 for a := 0 to High(SelectedObjects) do
2118 if SelectedObjects[a].Live then
2119 begin
2120 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, dx, 0) then
2121 okX := False;
2123 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, 0, dy) then
2124 okY := False;
2126 if (not okX) or (not okY) then
2127 Break;
2128 end;
2130 if okX or okY then
2131 begin
2132 for a := 0 to High(SelectedObjects) do
2133 if SelectedObjects[a].Live then
2134 begin
2135 if okX then
2136 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, dx, 0);
2138 if okY then
2139 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, 0, dy);
2141 if alt and (SelectedObjects[a].ObjectType = OBJECT_TRIGGER) then
2142 begin
2143 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_PRESS,
2144 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
2145 begin // Двигаем зону Расширителя
2146 if okX then
2147 gTriggers[SelectedObjects[a].ID].Data.tX := gTriggers[SelectedObjects[a].ID].Data.tX+dx;
2148 if okY then
2149 gTriggers[SelectedObjects[a].ID].Data.tY := gTriggers[SelectedObjects[a].ID].Data.tY+dy;
2150 end;
2152 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_TELEPORT] then
2153 begin // Двигаем точку назначения Телепорта
2154 if okX then
2155 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X+dx;
2156 if okY then
2157 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y+dy;
2158 end;
2160 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNMONSTER] then
2161 begin // Двигаем точку создания монстра
2162 if okX then
2163 gTriggers[SelectedObjects[a].ID].Data.MonPos.X := gTriggers[SelectedObjects[a].ID].Data.MonPos.X+dx;
2164 if okY then
2165 gTriggers[SelectedObjects[a].ID].Data.MonPos.Y := gTriggers[SelectedObjects[a].ID].Data.MonPos.Y+dy;
2166 end;
2168 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNITEM] then
2169 begin // Двигаем точку создания предмета
2170 if okX then
2171 gTriggers[SelectedObjects[a].ID].Data.ItemPos.X := gTriggers[SelectedObjects[a].ID].Data.ItemPos.X+dx;
2172 if okY then
2173 gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y := gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y+dy;
2174 end;
2176 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SHOT] then
2177 begin // Двигаем точку создания выстрела
2178 if okX then
2179 gTriggers[SelectedObjects[a].ID].Data.ShotPos.X := gTriggers[SelectedObjects[a].ID].Data.ShotPos.X+dx;
2180 if okY then
2181 gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y := gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y+dy;
2182 end;
2183 end;
2184 end;
2186 LastMovePoint := MousePos;
2187 end;
2188 end;
2190 procedure ShowLayer(Layer: Byte; show: Boolean);
2191 begin
2192 LayerEnabled[Layer] := show;
2194 case Layer of
2195 LAYER_BACK:
2196 begin
2197 MainForm.miLayer1.Checked := show;
2198 MainForm.miLayerP1.Checked := show;
2199 end;
2200 LAYER_WALLS:
2201 begin
2202 MainForm.miLayer2.Checked := show;
2203 MainForm.miLayerP2.Checked := show;
2204 end;
2205 LAYER_FOREGROUND:
2206 begin
2207 MainForm.miLayer3.Checked := show;
2208 MainForm.miLayerP3.Checked := show;
2209 end;
2210 LAYER_STEPS:
2211 begin
2212 MainForm.miLayer4.Checked := show;
2213 MainForm.miLayerP4.Checked := show;
2214 end;
2215 LAYER_WATER:
2216 begin
2217 MainForm.miLayer5.Checked := show;
2218 MainForm.miLayerP5.Checked := show;
2219 end;
2220 LAYER_ITEMS:
2221 begin
2222 MainForm.miLayer6.Checked := show;
2223 MainForm.miLayerP6.Checked := show;
2224 end;
2225 LAYER_MONSTERS:
2226 begin
2227 MainForm.miLayer7.Checked := show;
2228 MainForm.miLayerP7.Checked := show;
2229 end;
2230 LAYER_AREAS:
2231 begin
2232 MainForm.miLayer8.Checked := show;
2233 MainForm.miLayerP8.Checked := show;
2234 end;
2235 LAYER_TRIGGERS:
2236 begin
2237 MainForm.miLayer9.Checked := show;
2238 MainForm.miLayerP9.Checked := show;
2239 end;
2240 end;
2242 RemoveSelectFromObjects();
2243 end;
2245 procedure SwitchLayer(Layer: Byte);
2246 begin
2247 ShowLayer(Layer, not LayerEnabled[Layer]);
2248 end;
2250 procedure SwitchMap();
2251 begin
2252 ShowMap := not ShowMap;
2253 MainForm.tbShowMap.Down := ShowMap;
2254 MainForm.miMiniMap.Checked := ShowMap;
2255 end;
2257 procedure ShowEdges();
2258 begin
2259 if drEdge[3] < 255 then
2260 drEdge[3] := 255
2261 else
2262 drEdge[3] := gAlphaEdge;
2263 MainForm.miShowEdges.Checked := drEdge[3] <> 255;
2264 end;
2266 function SelectedTexture(): String;
2267 begin
2268 if MainForm.lbTextureList.ItemIndex <> -1 then
2269 Result := MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]
2270 else
2271 Result := '';
2272 end;
2274 function IsSpecialTextureSel(): Boolean;
2275 begin
2276 Result := (MainForm.lbTextureList.ItemIndex <> -1) and
2277 IsSpecialTexture(MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]);
2278 end;
2280 function CopyBufferToString(var CopyBuf: TCopyRecArray): String;
2281 var
2282 i, j: Integer;
2283 Res: String;
2285 procedure AddInt(x: Integer);
2286 begin
2287 Res := Res + IntToStr(x) + ' ';
2288 end;
2290 begin
2291 Result := '';
2293 if Length(CopyBuf) = 0 then
2294 Exit;
2296 Res := CLIPBOARD_SIG + ' ';
2298 for i := 0 to High(CopyBuf) do
2299 begin
2300 if (CopyBuf[i].ObjectType = OBJECT_PANEL) and
2301 (CopyBuf[i].Panel = nil) then
2302 Continue;
2304 // Тип объекта:
2305 AddInt(CopyBuf[i].ObjectType);
2306 Res := Res + '; ';
2308 // Свойства объекта:
2309 case CopyBuf[i].ObjectType of
2310 OBJECT_PANEL:
2311 with CopyBuf[i].Panel^ do
2312 begin
2313 AddInt(PanelType);
2314 AddInt(X);
2315 AddInt(Y);
2316 AddInt(Width);
2317 AddInt(Height);
2318 Res := Res + '"' + TextureName + '" ';
2319 AddInt(Alpha);
2320 AddInt(IfThen(Blending, 1, 0));
2321 end;
2323 OBJECT_ITEM:
2324 with CopyBuf[i].Item do
2325 begin
2326 AddInt(ItemType);
2327 AddInt(X);
2328 AddInt(Y);
2329 AddInt(IfThen(OnlyDM, 1, 0));
2330 AddInt(IfThen(Fall, 1, 0));
2331 end;
2333 OBJECT_MONSTER:
2334 with CopyBuf[i].Monster do
2335 begin
2336 AddInt(MonsterType);
2337 AddInt(X);
2338 AddInt(Y);
2339 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2340 end;
2342 OBJECT_AREA:
2343 with CopyBuf[i].Area do
2344 begin
2345 AddInt(AreaType);
2346 AddInt(X);
2347 AddInt(Y);
2348 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2349 end;
2351 OBJECT_TRIGGER:
2352 with CopyBuf[i].Trigger do
2353 begin
2354 AddInt(TriggerType);
2355 AddInt(X);
2356 AddInt(Y);
2357 AddInt(Width);
2358 AddInt(Height);
2359 AddInt(ActivateType);
2360 AddInt(Key);
2361 AddInt(IfThen(Enabled, 1, 0));
2362 AddInt(TexturePanel);
2364 for j := 0 to 127 do
2365 AddInt(Data.Default[j]);
2366 end;
2367 end;
2368 end;
2370 Result := Res;
2371 end;
2373 procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray; var pmin: TPoint);
2374 var
2375 i, j, t: Integer;
2376 minArea, newArea, newX, newY: LongInt;
2378 function GetNext(): String;
2379 var
2380 p: Integer;
2382 begin
2383 if Str[1] = '"' then
2384 begin
2385 Delete(Str, 1, 1);
2386 p := Pos('"', Str);
2388 if p = 0 then
2389 begin
2390 Result := Str;
2391 Str := '';
2392 end
2393 else
2394 begin
2395 Result := Copy(Str, 1, p-1);
2396 Delete(Str, 1, p);
2397 Str := Trim(Str);
2398 end;
2399 end
2400 else
2401 begin
2402 p := Pos(' ', Str);
2404 if p = 0 then
2405 begin
2406 Result := Str;
2407 Str := '';
2408 end
2409 else
2410 begin
2411 Result := Copy(Str, 1, p-1);
2412 Delete(Str, 1, p);
2413 Str := Trim(Str);
2414 end;
2415 end;
2416 end;
2418 begin
2419 minArea := High(minArea);
2420 Str := Trim(Str);
2422 if GetNext() <> CLIPBOARD_SIG then
2423 Exit;
2425 while Str <> '' do
2426 begin
2427 // Тип объекта:
2428 t := StrToIntDef(GetNext(), 0);
2430 if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or (GetNext() <> ';') then
2431 begin // Что-то не то => пропускаем:
2432 t := Pos(';', Str);
2433 Delete(Str, 1, t);
2434 Str := Trim(Str);
2436 Continue;
2437 end;
2439 i := Length(CopyBuf);
2440 SetLength(CopyBuf, i + 1);
2442 CopyBuf[i].ObjectType := t;
2443 CopyBuf[i].Panel := nil;
2445 // Свойства объекта:
2446 case t of
2447 OBJECT_PANEL:
2448 begin
2449 New(CopyBuf[i].Panel);
2451 with CopyBuf[i].Panel^ do
2452 begin
2453 PanelType := StrToIntDef(GetNext(), PANEL_WALL);
2454 X := StrToIntDef(GetNext(), 0);
2455 Y := StrToIntDef(GetNext(), 0);
2456 Width := StrToIntDef(GetNext(), 16);
2457 Height := StrToIntDef(GetNext(), 16);
2458 TextureName := GetNext();
2459 Alpha := StrToIntDef(GetNext(), 0);
2460 Blending := (GetNext() = '1');
2461 newArea := X * Y - Width * Height;
2462 newX := X;
2463 newY := Y;
2464 end;
2465 end;
2467 OBJECT_ITEM:
2468 with CopyBuf[i].Item do
2469 begin
2470 ItemType := StrToIntDef(GetNext(), ITEM_MEDKIT_SMALL);
2471 X := StrToIntDef(GetNext(), 0);
2472 Y := StrToIntDef(GetNext(), 0);
2473 OnlyDM := (GetNext() = '1');
2474 Fall := (GetNext() = '1');
2475 newArea := X * Y;
2476 newX := X;
2477 newY := Y;
2478 end;
2480 OBJECT_MONSTER:
2481 with CopyBuf[i].Monster do
2482 begin
2483 MonsterType := StrToIntDef(GetNext(), MONSTER_DEMON);
2484 X := StrToIntDef(GetNext(), 0);
2485 Y := StrToIntDef(GetNext(), 0);
2486 if GetNext() = '1'
2487 then Direction := D_LEFT
2488 else Direction := D_RIGHT;
2489 newArea := X * Y;
2490 newX := X;
2491 newY := Y;
2492 end;
2494 OBJECT_AREA:
2495 with CopyBuf[i].Area do
2496 begin
2497 AreaType := StrToIntDef(GetNext(), AREA_PLAYERPOINT1);
2498 X := StrToIntDef(GetNext(), 0);
2499 Y := StrToIntDef(GetNext(), 0);
2500 if GetNext() = '1'
2501 then Direction := D_LEFT
2502 else Direction := D_RIGHT;
2503 newArea := X * Y;
2504 newX := X;
2505 newY := Y;
2506 end;
2508 OBJECT_TRIGGER:
2509 with CopyBuf[i].Trigger do
2510 begin
2511 TriggerType := StrToIntDef(GetNext(), TRIGGER_EXIT);
2512 X := StrToIntDef(GetNext(), 0);
2513 Y := StrToIntDef(GetNext(), 0);
2514 Width := StrToIntDef(GetNext(), 16);
2515 Height := StrToIntDef(GetNext(), 16);
2516 ActivateType := StrToIntDef(GetNext(), 0);
2517 Key := StrToIntDef(GetNext(), 0);
2518 Enabled := (GetNext() = '1');
2519 TexturePanel := StrToIntDef(GetNext(), 0);
2520 for j := 0 to 127
2521 do Data.Default[j] := StrToIntDef(GetNext(), 0);
2522 newArea := X * Y - Width * Height;
2523 newX := X;
2524 newY := Y;
2525 end;
2526 end;
2528 if newArea < minArea then
2529 begin
2530 minArea := newArea;
2531 pmin.X := newX;
2532 pmin.Y := newY;
2533 end;
2534 end;
2535 end;
2537 //----------------------------------------
2538 //Закончились вспомогательные процедуры
2539 //----------------------------------------
2541 procedure TMainForm.miRecentFileExecute (Sender: TObject);
2542 var
2543 s, fn: AnsiString;
2544 begin
2545 s := RecentFiles[(Sender as TMenuItem).Tag];
2546 fn := g_ExtractWadName(s);
2547 if FileExists(fn) then
2548 OpenMap(fn, g_ExtractFilePathName(s))
2549 else
2550 Application.MessageBox('', 'File not available anymore', MB_OK);
2551 // if Application.MessageBox(PChar(MsgMsgDelRecentPrompt), PChar(MsgMsgDelRecent), MB_ICONQUESTION or MB_YESNO) = idYes then
2552 // begin
2553 // RecentFiles.Delete(n);
2554 // RefreshRecentMenu();
2555 // end;
2556 end;
2558 procedure TMainForm.RefillRecentMenu (menu: TMenuItem; start: Integer; fmt: AnsiString);
2559 var i: Integer; MI: TMenuItem; s: AnsiString;
2560 begin
2561 Assert(menu <> nil);
2562 Assert(start >= 0);
2563 Assert(start <= menu.Count);
2565 // clear all the recent entries from menu
2566 i := start;
2567 while i < menu.Count do
2568 begin
2569 MI := menu.Items[i];
2570 if @MI.OnClick <> @TMainForm.miRecentFileExecute then
2571 i += 1
2572 else
2573 begin
2574 menu.Delete(i);
2575 MI.Destroy();
2576 end;
2577 end;
2579 // fill with a new ones
2580 for i := 0 to RecentFiles.Count-1 do
2581 begin
2582 MI := TMenuItem.Create(menu);
2583 s := RecentFiles[i];
2584 MI.Caption := Format(fmt, [i+1, g_ExtractWadNameNoPath(s), g_ExtractFilePathName(s)]);
2585 MI.OnClick := miRecentFileExecute;
2586 MI.Tag := i;
2587 menu.Insert(start + i, MI); // transfers ownership
2588 end;
2589 end;
2591 procedure TMainForm.RefreshRecentMenu();
2592 var start: Integer;
2593 begin
2594 while RecentFiles.Count > RecentCount do
2595 RecentFiles.Delete(RecentFiles.Count - 1);
2597 if miMacRecentSubMenu.Visible then
2598 begin
2599 // Reconstruct OSX-like recent list
2600 RefillRecentMenu(miMacRecentSubMenu, 0, '%1:s - %2:s');
2601 miMacRecentEnd.Enabled := RecentFiles.Count <> 0;
2602 miMacRecentEnd.Visible := RecentFiles.Count <> 0;
2603 end;
2605 if miWinRecentStart.Visible then
2606 begin
2607 // Reconstruct Windows-like recent list
2608 start := miMenuFile.IndexOf(miWinRecent);
2609 if start < 0 then start := miMenuFile.Count else start += 1;
2610 RefillRecentMenu(miMenuFile, start, '%0:d %1:s:%2:s');
2611 miWinRecent.Enabled := False;
2612 miWinRecent.Visible := RecentFiles.Count = 0;
2613 end;
2614 end;
2616 procedure TMainForm.miMacRecentClearClick(Sender: TObject);
2617 begin
2618 RecentFiles.Clear();
2619 RefreshRecentMenu();
2620 end;
2622 procedure TMainForm.aEditorOptionsExecute(Sender: TObject);
2623 begin
2624 OptionsForm.ShowModal();
2625 end;
2627 procedure LoadStdFont(cfgres, texture: string; var FontID: DWORD);
2628 var
2629 cwdt, chgt: Byte;
2630 spc: ShortInt;
2631 ID: DWORD;
2632 wad: TWADEditor_1;
2633 cfgdata: Pointer;
2634 cfglen: Integer;
2635 config: TConfig;
2636 begin
2637 cfgdata := nil;
2638 cfglen := 0;
2639 ID := 0;
2641 wad := TWADEditor_1.Create;
2642 if wad.ReadFile(GameWad) then
2643 wad.GetResource('FONTS', cfgres, cfgdata, cfglen);
2644 wad.Free();
2646 if cfglen <> 0 then
2647 begin
2648 if not g_CreateTextureWAD('FONT_STD', GameWad + ':FONTS\' + texture) then
2649 e_WriteLog('ERROR ERROR ERROR', MSG_WARNING);
2651 config := TConfig.CreateMem(cfgdata, cfglen);
2652 cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
2653 chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
2654 spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
2656 if g_GetTexture('FONT_STD', ID) then
2657 e_TextureFontBuild(ID, FontID, cwdt, chgt, spc-2);
2659 config.Free();
2660 end
2661 else
2662 e_WriteLog('Could not load FONT_STD', MSG_WARNING);
2664 if cfglen <> 0 then FreeMem(cfgdata);
2665 end;
2667 procedure TMainForm.FormCreate(Sender: TObject);
2668 var
2669 config: TConfig;
2670 i: Integer;
2671 s: String;
2672 begin
2673 Randomize();
2675 {$IFDEF DARWIN}
2676 miApple.Enabled := True;
2677 miApple.Visible := True;
2678 miMacRecentSubMenu.Enabled := True;
2679 miMacRecentSubMenu.Visible := True;
2680 miWinRecentStart.Enabled := False;
2681 miWinRecentStart.Visible := False;
2682 miWinRecent.Enabled := False;
2683 miWinRecent.Visible := False;
2684 miLine2.Enabled := False;
2685 miLine2.Visible := False;
2686 miExit.Enabled := False;
2687 miExit.Visible := False;
2688 miOptions.Enabled := False;
2689 miOptions.Visible := False;
2690 miMenuWindow.Enabled := True;
2691 miMenuWindow.Visible := True;
2692 miAbout.Enabled := False;
2693 miAbout.Visible := False;
2694 {$ELSE}
2695 miApple.Enabled := False;
2696 miApple.Visible := False;
2697 miMacRecentSubMenu.Enabled := False;
2698 miMacRecentSubMenu.Visible := False;
2699 miWinRecentStart.Enabled := True;
2700 miWinRecentStart.Visible := True;
2701 miWinRecent.Enabled := True;
2702 miWinRecent.Visible := True;
2703 miLine2.Enabled := True;
2704 miLine2.Visible := True;
2705 miExit.Enabled := True;
2706 miExit.Visible := True;
2707 miOptions.Enabled := True;
2708 miOptions.Visible := True;
2709 miMenuWindow.Enabled := False;
2710 miMenuWindow.Visible := False;
2711 miAbout.Enabled := True;
2712 miAbout.Visible := True;
2713 {$ENDIF}
2715 miNewMap.ShortCut := ShortCut(VK_N, [ssModifier]);
2716 miOpenMap.ShortCut := ShortCut(VK_O, [ssModifier]);
2717 miSaveMap.ShortCut := ShortCut(VK_S, [ssModifier]);
2718 {$IFDEF DARWIN}
2719 miSaveMapAs.ShortCut := ShortCut(VK_S, [ssModifier, ssShift]);
2720 miReopenMap.ShortCut := ShortCut(VK_F5, [ssModifier]);
2721 {$ENDIF}
2722 miUndo.ShortCut := ShortCut(VK_Z, [ssModifier]);
2723 miCopy.ShortCut := ShortCut(VK_C, [ssModifier]);
2724 miCut.ShortCut := ShortCut(VK_X, [ssModifier]);
2725 miPaste.ShortCut := ShortCut(VK_V, [ssModifier]);
2726 miSelectAll.ShortCut := ShortCut(VK_A, [ssModifier]);
2727 miToFore.ShortCut := ShortCut(VK_LCL_CLOSE_BRACKET, [ssModifier]);
2728 miToBack.ShortCut := ShortCut(VK_LCL_OPEN_BRACKET, [ssModifier]);
2729 {$IFDEF DARWIN}
2730 miMapOptions.Shortcut := ShortCut(VK_P, [ssModifier, ssAlt]);
2731 selectall1.Shortcut := ShortCut(VK_A, [ssModifier, ssAlt]);
2732 {$ENDIF}
2734 e_WriteLog('Doom 2D: Forever Editor version ' + EDITOR_VERSION, MSG_NOTIFY);
2735 e_WriteLog('Build date: ' + EDITOR_BUILDDATE + ' ' + EDITOR_BUILDTIME, MSG_NOTIFY);
2736 e_WriteLog('Build hash: ' + g_GetBuildHash(), MSG_NOTIFY);
2737 e_WriteLog('Build by: ' + g_GetBuilderName(), MSG_NOTIFY);
2739 slInvalidTextures := TStringList.Create;
2741 ShowLayer(LAYER_BACK, True);
2742 ShowLayer(LAYER_WALLS, True);
2743 ShowLayer(LAYER_FOREGROUND, True);
2744 ShowLayer(LAYER_STEPS, True);
2745 ShowLayer(LAYER_WATER, True);
2746 ShowLayer(LAYER_ITEMS, True);
2747 ShowLayer(LAYER_MONSTERS, True);
2748 ShowLayer(LAYER_AREAS, True);
2749 ShowLayer(LAYER_TRIGGERS, True);
2751 ClearMap();
2753 FormCaption := MainForm.Caption;
2754 OpenedMap := '';
2755 OpenedWAD := '';
2757 config := TConfig.CreateFile(CfgFileName);
2759 gWADEditorLogLevel := config.ReadInt('WADEditor', 'LogLevel', DFWAD_LOG_DEFAULT);
2761 if config.ReadInt('Editor', 'XPos', -1) = -1 then
2762 Position := poDesktopCenter
2763 else begin
2764 Left := config.ReadInt('Editor', 'XPos', Left);
2765 Top := config.ReadInt('Editor', 'YPos', Top);
2766 Width := config.ReadInt('Editor', 'Width', Width);
2767 Height := config.ReadInt('Editor', 'Height', Height);
2768 end;
2769 if config.ReadBool('Editor', 'Maximize', False) then
2770 WindowState := wsMaximized;
2771 ShowMap := config.ReadBool('Editor', 'Minimap', False);
2772 PanelProps.Width := config.ReadInt('Editor', 'PanelProps', PanelProps.ClientWidth);
2773 Splitter1.Left := PanelProps.Left;
2774 PanelObjs.Height := config.ReadInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
2775 Splitter2.Top := PanelObjs.Top;
2776 StatusBar.Top := PanelObjs.BoundsRect.Bottom;
2777 DotEnable := config.ReadBool('Editor', 'DotEnable', True);
2778 DotColor := config.ReadInt('Editor', 'DotColor', $FFFFFF);
2779 DotStepOne := config.ReadInt('Editor', 'DotStepOne', 16);
2780 DotStepTwo := config.ReadInt('Editor', 'DotStepTwo', 8);
2781 DotStep := config.ReadInt('Editor', 'DotStep', DotStepOne);
2782 DrawTexturePanel := config.ReadBool('Editor', 'DrawTexturePanel', True);
2783 DrawPanelSize := config.ReadBool('Editor', 'DrawPanelSize', True);
2784 BackColor := config.ReadInt('Editor', 'BackColor', $7F6040);
2785 PreviewColor := config.ReadInt('Editor', 'PreviewColor', $00FF00);
2786 UseCheckerboard := config.ReadBool('Editor', 'UseCheckerboard', True);
2787 gColorEdge := config.ReadInt('Editor', 'EdgeColor', COLOR_EDGE);
2788 gAlphaEdge := config.ReadInt('Editor', 'EdgeAlpha', ALPHA_EDGE);
2789 if gAlphaEdge = 255 then
2790 gAlphaEdge := ALPHA_EDGE;
2791 drEdge[0] := GetRValue(gColorEdge);
2792 drEdge[1] := GetGValue(gColorEdge);
2793 drEdge[2] := GetBValue(gColorEdge);
2794 if not config.ReadBool('Editor', 'EdgeShow', True) then
2795 drEdge[3] := 255
2796 else
2797 drEdge[3] := gAlphaEdge;
2798 gAlphaTriggerLine := config.ReadInt('Editor', 'LineAlpha', ALPHA_LINE);
2799 if gAlphaTriggerLine = 255 then
2800 gAlphaTriggerLine := ALPHA_LINE;
2801 gAlphaTriggerArea := config.ReadInt('Editor', 'TriggerAlpha', ALPHA_AREA);
2802 if gAlphaTriggerArea = 255 then
2803 gAlphaTriggerArea := ALPHA_AREA;
2804 gAlphaMonsterRect := config.ReadInt('Editor', 'MonsterRectAlpha', 0);
2805 gAlphaAreaRect := config.ReadInt('Editor', 'AreaRectAlpha', 0);
2806 Scale := Max(config.ReadInt('Editor', 'Scale', 1), 1);
2807 DotSize := Max(config.ReadInt('Editor', 'DotSize', 1), 1);
2808 OpenDialog.InitialDir := config.ReadStr('Editor', 'LastOpenDir', MapsDir);
2809 SaveDialog.InitialDir := config.ReadStr('Editor', 'LastSaveDir', MapsDir);
2811 s := config.ReadStr('Editor', 'Language', '');
2812 gLanguage := s;
2814 TestGameMode := config.ReadStr('TestRun', 'GameMode', 'DM');
2815 TestLimTime := config.ReadStr('TestRun', 'LimTime', '0');
2816 TestLimScore := config.ReadStr('TestRun', 'LimScore', '0');
2817 TestOptionsTwoPlayers := config.ReadBool('TestRun', 'TwoPlayers', False);
2818 TestOptionsTeamDamage := config.ReadBool('TestRun', 'TeamDamage', False);
2819 TestOptionsAllowExit := config.ReadBool('TestRun', 'AllowExit', True);
2820 TestOptionsWeaponStay := config.ReadBool('TestRun', 'WeaponStay', False);
2821 TestOptionsMonstersDM := config.ReadBool('TestRun', 'MonstersDM', False);
2822 TestMapOnce := config.ReadBool('TestRun', 'MapOnce', False);
2823 {$IF DEFINED(DARWIN)}
2824 TestD2dExe := config.ReadStr('TestRun', 'ExeDrawin', GameExeFile);
2825 {$ELSEIF DEFINED(WINDOWS)}
2826 TestD2dExe := config.ReadStr('TestRun', 'ExeWindows', GameExeFile);
2827 {$ELSE}
2828 TestD2dExe := config.ReadStr('TestRun', 'ExeUnix', GameExeFile);
2829 {$ENDIF}
2830 TestD2DArgs := config.ReadStr('TestRun', 'Args', '');
2832 RecentCount := config.ReadInt('Editor', 'RecentCount', 5);
2833 if RecentCount > 10 then
2834 RecentCount := 10;
2835 if RecentCount < 2 then
2836 RecentCount := 2;
2838 RecentFiles := TStringList.Create();
2839 for i := 0 to RecentCount-1 do
2840 begin
2841 {$IFDEF WINDOWS}
2842 s := config.ReadStr('RecentFilesWin', IntToStr(i), '');
2843 {$ELSE}
2844 s := config.ReadStr('RecentFilesUnix', IntToStr(i), '');
2845 {$ENDIF}
2846 if s <> '' then
2847 RecentFiles.Add(s);
2848 end;
2849 RefreshRecentMenu();
2851 config.Free();
2853 tbShowMap.Down := ShowMap;
2854 tbGridOn.Down := DotEnable;
2855 pcObjects.ActivePageIndex := 0;
2856 Application.Title := MsgEditorTitle;
2858 Application.OnIdle := OnIdle;
2859 end;
2861 procedure PrintBlack(X, Y: Integer; Text: string; FontID: DWORD);
2862 begin
2863 // NOTE: all the font printing routines assume CP1251
2864 e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0);
2865 end;
2867 procedure InitGraphics;
2868 begin
2869 // FIXME: this is a shitty hack
2870 if not gDataLoaded then
2871 begin
2872 e_WriteLog('Init OpenGL', MSG_NOTIFY);
2873 e_InitGL();
2874 e_WriteLog('Loading data', MSG_NOTIFY);
2875 LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
2876 e_WriteLog('Loading more data', MSG_NOTIFY);
2877 LoadData();
2878 e_WriteLog('Loading even more data', MSG_NOTIFY);
2879 gDataLoaded := True;
2880 MainForm.FormResize(nil);
2881 end;
2882 end;
2884 procedure TMainForm.Draw();
2885 var
2886 x, y: Integer;
2887 a, b: Integer;
2888 ID, PID: DWORD;
2889 Width, Height: Word;
2890 Rect: TRectWH;
2891 ObjCount: Word;
2892 aX, aY, aX2, aY2, XX, ScaleSz: Integer;
2893 begin
2894 ID := 0;
2895 PID := 0;
2896 Width := 0;
2897 Height := 0;
2899 InitGraphics();
2901 e_BeginRender();
2903 e_Clear(GL_COLOR_BUFFER_BIT,
2904 GetRValue(BackColor)/255,
2905 GetGValue(BackColor)/255,
2906 GetBValue(BackColor)/255);
2908 DrawMap();
2910 ObjCount := SelectedObjectCount();
2912 // Обводим выделенные объекты красной рамкой:
2913 if ObjCount > 0 then
2914 begin
2915 for a := 0 to High(SelectedObjects) do
2916 if SelectedObjects[a].Live then
2917 begin
2918 Rect := ObjectGetRect(SelectedObjects[a].ObjectType, SelectedObjects[a].ID);
2920 with Rect do
2921 begin
2922 e_DrawQuad(X+MapOffset.X, Y+MapOffset.Y,
2923 X+MapOffset.X+Width-1, Y+MapOffset.Y+Height-1,
2924 255, 0, 0);
2926 // Рисуем точки изменения размеров:
2927 if (ObjCount = 1) and
2928 (SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) then
2929 begin
2930 e_DrawPoint(5, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2931 e_DrawPoint(5, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2932 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 255, 255);
2933 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 255, 255);
2935 e_DrawPoint(3, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2936 e_DrawPoint(3, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2937 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 0, 0);
2938 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 0, 0);
2939 end;
2940 end;
2941 end;
2942 end;
2944 // Рисуем сетку:
2945 if DotEnable and (PreviewMode = 0) then
2946 begin
2947 if DotSize = 2 then
2948 a := -1
2949 else
2950 a := 0;
2952 x := MapOffset.X mod DotStep;
2953 y := MapOffset.Y mod DotStep;
2955 while x < RenderPanel.Width do
2956 begin
2957 while y < RenderPanel.Height do
2958 begin
2959 e_DrawPoint(DotSize, x + a, y + a,
2960 GetRValue(DotColor),
2961 GetGValue(DotColor),
2962 GetBValue(DotColor));
2963 y += DotStep;
2964 end;
2965 x += DotStep;
2966 y := MapOffset.Y mod DotStep;
2967 end;
2968 end;
2970 // Превью текстуры:
2971 if (lbTextureList.ItemIndex <> -1) and (cbPreview.Checked) and
2972 (not IsSpecialTextureSel()) and (PreviewMode = 0) then
2973 begin
2974 if not g_GetTexture(SelectedTexture(), ID) then
2975 g_GetTexture('NOTEXTURE', ID);
2976 g_GetTextureSizeByID(ID, Width, Height);
2977 if UseCheckerboard then
2978 begin
2979 if g_GetTexture('PREVIEW', PID) then
2980 e_DrawFill(PID, RenderPanel.Width-Width, RenderPanel.Height-Height, Width div 16 + 1, Height div 16 + 1, 0, True, False);
2981 end else
2982 e_DrawFillQuad(RenderPanel.Width-Width-2, RenderPanel.Height-Height-2,
2983 RenderPanel.Width-1, RenderPanel.Height-1,
2984 GetRValue(PreviewColor), GetGValue(PreviewColor), GetBValue(PreviewColor), 0);
2985 e_Draw(ID, RenderPanel.Width-Width, RenderPanel.Height-Height, 0, True, False);
2986 end;
2988 // Подсказка при выборе точки Телепорта:
2989 if SelectFlag = SELECTFLAG_TELEPORT then
2990 begin
2991 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
2992 if Data.d2d_teleport then
2993 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2994 MousePos.X+16, MousePos.Y-1,
2995 0, 0, 255)
2996 else
2997 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+AreaSize[AREA_DMPOINT].Width-1,
2998 MousePos.Y+AreaSize[AREA_DMPOINT].Height-1, 255, 255, 255);
3000 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
3001 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
3002 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintTeleport), gEditorFont);
3003 end;
3005 // Подсказка при выборе точки появления:
3006 if SelectFlag = SELECTFLAG_SPAWNPOINT then
3007 begin
3008 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
3009 MousePos.X+16, MousePos.Y-1,
3010 0, 0, 255);
3011 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
3012 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
3013 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintSpawn), gEditorFont);
3014 end;
3016 // Подсказка при выборе панели двери:
3017 if SelectFlag = SELECTFLAG_DOOR then
3018 begin
3019 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
3020 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
3021 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintPanelDoor), gEditorFont);
3022 end;
3024 // Подсказка при выборе панели с текстурой:
3025 if SelectFlag = SELECTFLAG_TEXTURE then
3026 begin
3027 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 192, 192, 192, 127);
3028 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 255, 255, 255);
3029 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintPanelTexture), gEditorFont);
3030 end;
3032 // Подсказка при выборе панели индикации выстрела:
3033 if SelectFlag = SELECTFLAG_SHOTPANEL then
3034 begin
3035 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 192, 192, 192, 127);
3036 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 255, 255, 255);
3037 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintPanelShot), gEditorFont);
3038 end;
3040 // Подсказка при выборе панели лифта:
3041 if SelectFlag = SELECTFLAG_LIFT then
3042 begin
3043 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
3044 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
3045 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintPanelLift), gEditorFont);
3046 end;
3048 // Подсказка при выборе монстра:
3049 if SelectFlag = SELECTFLAG_MONSTER then
3050 begin
3051 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 192, 192, 192, 127);
3052 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 255, 255, 255);
3053 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintMonster), gEditorFont);
3054 end;
3056 // Подсказка при выборе области воздействия:
3057 if DrawPressRect then
3058 begin
3059 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 192, 192, 192, 127);
3060 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 255, 255, 255);
3061 PrintBlack(MousePos.X+2, MousePos.Y+2, utf8to1251(MsgHintExtArea), gEditorFont);
3062 end;
3064 // Рисуем текстуры, если чертим панель:
3065 if (MouseAction = MOUSEACTION_DRAWPANEL) and (DrawTexturePanel) and
3066 (lbTextureList.ItemIndex <> -1) and (DrawRect <> nil) and
3067 (lbPanelType.ItemIndex in [0..8]) and not IsSpecialTextureSel() then
3068 begin
3069 if not g_GetTexture(SelectedTexture(), ID) then
3070 g_GetTexture('NOTEXTURE', ID);
3071 g_GetTextureSizeByID(ID, Width, Height);
3072 with DrawRect^ do
3073 if (Abs(Right-Left) >= Width) and (Abs(Bottom-Top) >= Height) then
3074 e_DrawFill(ID, Min(Left, Right), Min(Top, Bottom), Abs(Right-Left) div Width,
3075 Abs(Bottom-Top) div Height, 64, True, False);
3076 end;
3078 // Прямоугольник выделения:
3079 if DrawRect <> nil then
3080 with DrawRect^ do
3081 e_DrawQuad(Left, Top, Right-1, Bottom-1, 255, 255, 255);
3083 // Чертим мышью панель/триггер или меняем мышью их размер:
3084 if (((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
3085 not(ssCtrl in GetKeyShiftState())) or (MouseAction = MOUSEACTION_RESIZE)) and
3086 (DrawPanelSize) then
3087 begin
3088 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 192, 192, 192, 127);
3089 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 255, 255, 255);
3091 if MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER] then
3092 begin // Чертим новый
3093 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(utf8to1251(MsgHintWidth),
3094 [Abs(MousePos.X-MouseLDownPos.X)]), gEditorFont);
3095 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(utf8to1251(MsgHintHeight),
3096 [Abs(MousePos.Y-MouseLDownPos.Y)]), gEditorFont);
3097 end
3098 else // Растягиваем существующий
3099 if SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
3100 begin
3101 if SelectedObjects[GetFirstSelected].ObjectType = OBJECT_PANEL then
3102 begin
3103 Width := gPanels[SelectedObjects[GetFirstSelected].ID].Width;
3104 Height := gPanels[SelectedObjects[GetFirstSelected].ID].Height;
3105 end
3106 else
3107 begin
3108 Width := gTriggers[SelectedObjects[GetFirstSelected].ID].Width;
3109 Height := gTriggers[SelectedObjects[GetFirstSelected].ID].Height;
3110 end;
3112 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(utf8to1251(MsgHintWidth), [Width]),
3113 gEditorFont);
3114 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(utf8to1251(MsgHintHeight), [Height]),
3115 gEditorFont);
3116 end;
3117 end;
3119 // Ближайшая к курсору мыши точка на сетке:
3120 e_DrawPoint(3, MousePos.X, MousePos.Y, 0, 0, 255);
3122 // Мини-карта:
3123 if ShowMap then
3124 begin
3125 // Сколько пикселов карты в 1 пикселе мини-карты:
3126 ScaleSz := 16 div Scale;
3127 // Размеры мини-карты:
3128 aX := max(gMapInfo.Width div ScaleSz, 1);
3129 aY := max(gMapInfo.Height div ScaleSz, 1);
3130 // X-координата на RenderPanel нулевой x-координаты карты:
3131 XX := RenderPanel.Width - aX - 1;
3132 // Рамка карты:
3133 e_DrawFillQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 0, 0, 0, 0);
3134 e_DrawQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 197, 197, 197);
3136 if gPanels <> nil then
3137 begin
3138 // Рисуем панели:
3139 for a := 0 to High(gPanels) do
3140 with gPanels[a] do
3141 if PanelType <> 0 then
3142 begin
3143 // Левый верхний угол:
3144 aX := XX + (X div ScaleSz);
3145 aY := 1 + (Y div ScaleSz);
3146 // Размеры:
3147 aX2 := max(Width div ScaleSz, 1);
3148 aY2 := max(Height div ScaleSz, 1);
3149 // Правый нижний угол:
3150 aX2 := aX + aX2 - 1;
3151 aY2 := aY + aY2 - 1;
3153 case PanelType of
3154 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3155 PANEL_WATER: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3156 PANEL_ACID1: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3157 PANEL_ACID2: e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3158 PANEL_STEP: e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3159 PANEL_LIFTUP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3160 PANEL_LIFTDOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3161 PANEL_LIFTLEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3162 PANEL_LIFTRIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3163 PANEL_OPENDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 100, 220, 92, 0);
3164 PANEL_CLOSEDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 212, 184, 64, 0);
3165 PANEL_BLOCKMON: e_DrawFillQuad(aX, aY, aX2, aY2, 192, 0, 192, 0);
3166 end;
3167 end;
3169 // Рисуем красным выделенные панели:
3170 if SelectedObjects <> nil then
3171 for b := 0 to High(SelectedObjects) do
3172 with SelectedObjects[b] do
3173 if Live and (ObjectType = OBJECT_PANEL) then
3174 with gPanels[SelectedObjects[b].ID] do
3175 if PanelType and not(PANEL_BACK or PANEL_FORE) <> 0 then
3176 begin
3177 // Левый верхний угол:
3178 aX := XX + (X div ScaleSz);
3179 aY := 1 + (Y div ScaleSz);
3180 // Размеры:
3181 aX2 := max(Width div ScaleSz, 1);
3182 aY2 := max(Height div ScaleSz, 1);
3183 // Правый нижний угол:
3184 aX2 := aX + aX2 - 1;
3185 aY2 := aY + aY2 - 1;
3187 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0)
3188 end;
3189 end;
3191 if (gMapInfo.Width > RenderPanel.Width) or
3192 (gMapInfo.Height > RenderPanel.Height) then
3193 begin
3194 // Окно, показывающее текущее положение экрана на карте:
3195 // Размеры окна:
3196 x := max(min(RenderPanel.Width, gMapInfo.Width) div ScaleSz, 1);
3197 y := max(min(RenderPanel.Height, gMapInfo.Height) div ScaleSz, 1);
3198 // Левый верхний угол:
3199 aX := XX + ((-MapOffset.X) div ScaleSz);
3200 aY := 1 + ((-MapOffset.Y) div ScaleSz);
3201 // Правый нижний угол:
3202 aX2 := aX + x - 1;
3203 aY2 := aY + y - 1;
3205 e_DrawFillQuad(aX, aY, aX2, aY2, 127, 192, 127, 127, B_BLEND);
3206 e_DrawQuad(aX, aY, aX2, aY2, 255, 0, 0);
3207 end;
3208 end; // Мини-карта
3210 e_EndRender();
3211 RenderPanel.SwapBuffers();
3212 end;
3214 procedure TMainForm.FormResize(Sender: TObject);
3215 begin
3216 e_SetViewPort(0, 0, RenderPanel.Width, RenderPanel.Height);
3218 sbHorizontal.Min := Min(gMapInfo.Width - RenderPanel.Width, -RenderPanel.Width div 2);
3219 sbHorizontal.Max := Max(0, gMapInfo.Width - RenderPanel.Width div 2);
3220 sbVertical.Min := Min(gMapInfo.Height - RenderPanel.Height, -RenderPanel.Height div 2);
3221 sbVertical.Max := Max(0, gMapInfo.Height - RenderPanel.Height div 2);
3223 MapOffset.X := -sbHorizontal.Position;
3224 MapOffset.Y := -sbVertical.Position;
3225 end;
3227 procedure TMainForm.FormWindowStateChange(Sender: TObject);
3228 {$IFDEF DARWIN}
3229 var e: Boolean;
3230 {$ENDIF}
3231 begin
3232 {$IFDEF DARWIN}
3233 // deactivate all menus when main window minimized
3234 e := self.WindowState <> wsMinimized;
3235 miMenuFile.Enabled := e;
3236 miMenuEdit.Enabled := e;
3237 miMenuView.Enabled := e;
3238 miMenuService.Enabled := e;
3239 miMenuWindow.Enabled := e;
3240 miMenuHelp.Enabled := e;
3241 miMenuHidden.Enabled := e;
3242 {$ENDIF}
3243 end;
3245 procedure SelectNextObject(X, Y: Integer; ObjectType: Byte; ID: DWORD);
3246 var
3247 j, j_max: Integer;
3248 res: Boolean;
3249 begin
3250 j_max := 0; // shut up compiler
3251 case ObjectType of
3252 OBJECT_PANEL:
3253 begin
3254 res := (gPanels <> nil) and
3255 PanelInShownLayer(gPanels[ID].PanelType) and
3256 g_CollidePoint(X, Y, gPanels[ID].X, gPanels[ID].Y,
3257 gPanels[ID].Width,
3258 gPanels[ID].Height);
3259 j_max := Length(gPanels) - 1;
3260 end;
3262 OBJECT_ITEM:
3263 begin
3264 res := (gItems <> nil) and
3265 LayerEnabled[LAYER_ITEMS] and
3266 g_CollidePoint(X, Y, gItems[ID].X, gItems[ID].Y,
3267 ItemSize[gItems[ID].ItemType][0],
3268 ItemSize[gItems[ID].ItemType][1]);
3269 j_max := Length(gItems) - 1;
3270 end;
3272 OBJECT_MONSTER:
3273 begin
3274 res := (gMonsters <> nil) and
3275 LayerEnabled[LAYER_MONSTERS] and
3276 g_CollidePoint(X, Y, gMonsters[ID].X, gMonsters[ID].Y,
3277 MonsterSize[gMonsters[ID].MonsterType].Width,
3278 MonsterSize[gMonsters[ID].MonsterType].Height);
3279 j_max := Length(gMonsters) - 1;
3280 end;
3282 OBJECT_AREA:
3283 begin
3284 res := (gAreas <> nil) and
3285 LayerEnabled[LAYER_AREAS] and
3286 g_CollidePoint(X, Y, gAreas[ID].X, gAreas[ID].Y,
3287 AreaSize[gAreas[ID].AreaType].Width,
3288 AreaSize[gAreas[ID].AreaType].Height);
3289 j_max := Length(gAreas) - 1;
3290 end;
3292 OBJECT_TRIGGER:
3293 begin
3294 res := (gTriggers <> nil) and
3295 LayerEnabled[LAYER_TRIGGERS] and
3296 g_CollidePoint(X, Y, gTriggers[ID].X, gTriggers[ID].Y,
3297 gTriggers[ID].Width,
3298 gTriggers[ID].Height);
3299 j_max := Length(gTriggers) - 1;
3300 end;
3302 else
3303 res := False;
3304 end;
3306 if not res then
3307 Exit;
3309 // Перебор ID: от ID-1 до 0; потом от High до ID+1:
3310 j := ID;
3312 while True do
3313 begin
3314 Dec(j);
3316 if j < 0 then
3317 j := j_max;
3318 if j = Integer(ID) then
3319 Break;
3321 case ObjectType of
3322 OBJECT_PANEL:
3323 res := PanelInShownLayer(gPanels[j].PanelType) and
3324 g_CollidePoint(X, Y, gPanels[j].X, gPanels[j].Y,
3325 gPanels[j].Width,
3326 gPanels[j].Height);
3327 OBJECT_ITEM:
3328 res := (gItems[j].ItemType <> ITEM_NONE) and
3329 g_CollidePoint(X, Y, gItems[j].X, gItems[j].Y,
3330 ItemSize[gItems[j].ItemType][0],
3331 ItemSize[gItems[j].ItemType][1]);
3332 OBJECT_MONSTER:
3333 res := (gMonsters[j].MonsterType <> MONSTER_NONE) and
3334 g_CollidePoint(X, Y, gMonsters[j].X, gMonsters[j].Y,
3335 MonsterSize[gMonsters[j].MonsterType].Width,
3336 MonsterSize[gMonsters[j].MonsterType].Height);
3337 OBJECT_AREA:
3338 res := (gAreas[j].AreaType <> AREA_NONE) and
3339 g_CollidePoint(X, Y, gAreas[j].X, gAreas[j].Y,
3340 AreaSize[gAreas[j].AreaType].Width,
3341 AreaSize[gAreas[j].AreaType].Height);
3342 OBJECT_TRIGGER:
3343 res := (gTriggers[j].TriggerType <> TRIGGER_NONE) and
3344 g_CollidePoint(X, Y, gTriggers[j].X, gTriggers[j].Y,
3345 gTriggers[j].Width,
3346 gTriggers[j].Height);
3347 else
3348 res := False;
3349 end;
3351 if res then
3352 begin
3353 SetLength(SelectedObjects, 1);
3355 SelectedObjects[0].ObjectType := ObjectType;
3356 SelectedObjects[0].ID := j;
3357 SelectedObjects[0].Live := True;
3359 FillProperty();
3360 Break;
3361 end;
3362 end;
3363 end;
3365 procedure TMainForm.RenderPanelMouseDown(Sender: TObject;
3366 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3367 var
3368 i: Integer;
3369 Rect: TRectWH;
3370 c1, c2, c3, c4: Boolean;
3371 item: TItem;
3372 area: TArea;
3373 monster: TMonster;
3374 IDArray: DWArray;
3375 begin
3376 MainForm.ActiveControl := RenderPanel;
3377 RenderPanel.SetFocus();
3379 RenderPanelMouseMove(RenderPanel, Shift, X, Y);
3381 if Button = mbLeft then // Left Mouse Button
3382 begin
3383 // Двигаем карту с помощью мыши и мини-карты:
3384 if ShowMap and
3385 g_CollidePoint(X, Y,
3386 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3387 1,
3388 max(gMapInfo.Width div (16 div Scale), 1),
3389 max(gMapInfo.Height div (16 div Scale), 1) ) then
3390 begin
3391 MoveMap(X, Y);
3392 MouseAction := MOUSEACTION_MOVEMAP;
3393 end
3394 else // Ставим предмет/монстра/область:
3395 if (pcObjects.ActivePageIndex in [1, 2, 3]) and
3396 (not (ssShift in Shift)) then
3397 begin
3398 case pcObjects.ActivePageIndex of
3399 1:
3400 if lbItemList.ItemIndex = -1 then
3401 ErrorMessageBox(MsgMsgChooseItem)
3402 else
3403 begin
3404 item.ItemType := lbItemList.ItemIndex + ITEM_MEDKIT_SMALL;
3405 if item.ItemType >= ITEM_WEAPON_KASTET then
3406 item.ItemType := item.ItemType + 2;
3407 item.X := MousePos.X-MapOffset.X;
3408 item.Y := MousePos.Y-MapOffset.Y;
3410 if not (ssCtrl in Shift) then
3411 begin
3412 item.X := item.X - (ItemSize[item.ItemType][0] div 2);
3413 item.Y := item.Y - ItemSize[item.ItemType][1];
3414 end;
3416 item.OnlyDM := cbOnlyDM.Checked;
3417 item.Fall := cbFall.Checked;
3418 Undo_Add(OBJECT_ITEM, AddItem(item));
3419 end;
3420 2:
3421 if lbMonsterList.ItemIndex = -1 then
3422 ErrorMessageBox(MsgMsgChooseMonster)
3423 else
3424 begin
3425 monster.MonsterType := lbMonsterList.ItemIndex + MONSTER_DEMON;
3426 monster.X := MousePos.X-MapOffset.X;
3427 monster.Y := MousePos.Y-MapOffset.Y;
3429 if not (ssCtrl in Shift) then
3430 begin
3431 monster.X := monster.X - (MonsterSize[monster.MonsterType].Width div 2);
3432 monster.Y := monster.Y - MonsterSize[monster.MonsterType].Height;
3433 end;
3435 if rbMonsterLeft.Checked then
3436 monster.Direction := D_LEFT
3437 else
3438 monster.Direction := D_RIGHT;
3439 Undo_Add(OBJECT_MONSTER, AddMonster(monster));
3440 end;
3441 3:
3442 if lbAreasList.ItemIndex = -1 then
3443 ErrorMessageBox(MsgMsgChooseArea)
3444 else
3445 if (lbAreasList.ItemIndex + 1) <> AREA_DOMFLAG then
3446 begin
3447 area.AreaType := lbAreasList.ItemIndex + AREA_PLAYERPOINT1;
3448 area.X := MousePos.X-MapOffset.X;
3449 area.Y := MousePos.Y-MapOffset.Y;
3451 if not (ssCtrl in Shift) then
3452 begin
3453 area.X := area.X - (AreaSize[area.AreaType].Width div 2);
3454 area.Y := area.Y - AreaSize[area.AreaType].Height;
3455 end;
3457 if rbAreaLeft.Checked then
3458 area.Direction := D_LEFT
3459 else
3460 area.Direction := D_RIGHT;
3461 Undo_Add(OBJECT_AREA, AddArea(area));
3462 end;
3463 end;
3464 end
3465 else
3466 begin
3467 i := GetFirstSelected();
3469 // Выбираем объект под текущим:
3470 if (SelectedObjects <> nil) and
3471 (ssShift in Shift) and (i >= 0) and
3472 (SelectedObjects[i].Live) then
3473 begin
3474 if SelectedObjectCount() = 1 then
3475 SelectNextObject(X-MapOffset.X, Y-MapOffset.Y,
3476 SelectedObjects[i].ObjectType,
3477 SelectedObjects[i].ID);
3478 end
3479 else
3480 begin
3481 // Рисуем область триггера "Расширитель":
3482 if DrawPressRect and (i >= 0) and
3483 (SelectedObjects[i].ObjectType = OBJECT_TRIGGER) and
3484 (gTriggers[SelectedObjects[i].ID].TriggerType in
3485 [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) then
3486 MouseAction := MOUSEACTION_DRAWPRESS
3487 else // Рисуем панель:
3488 if pcObjects.ActivePageIndex = 0 then
3489 begin
3490 if (lbPanelType.ItemIndex >= 0) then
3491 MouseAction := MOUSEACTION_DRAWPANEL
3492 end
3493 else // Рисуем триггер:
3494 if (lbTriggersList.ItemIndex >= 0) then
3495 begin
3496 MouseAction := MOUSEACTION_DRAWTRIGGER;
3497 end;
3498 end;
3499 end;
3500 end; // if Button = mbLeft
3502 if Button = mbRight then // Right Mouse Button
3503 begin
3504 // Клик по мини-карте:
3505 if ShowMap and
3506 g_CollidePoint(X, Y,
3507 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3508 1,
3509 max(gMapInfo.Width div (16 div Scale), 1),
3510 max(gMapInfo.Height div (16 div Scale), 1) ) then
3511 begin
3512 MouseAction := MOUSEACTION_NOACTION;
3513 end
3514 else // Нужно что-то выбрать мышью:
3515 if SelectFlag <> SELECTFLAG_NONE then
3516 begin
3517 case SelectFlag of
3518 SELECTFLAG_TELEPORT:
3519 // Точку назначения телепортации:
3520 with gTriggers[SelectedObjects[
3521 GetFirstSelected() ].ID].Data.TargetPoint do
3522 begin
3523 X := MousePos.X-MapOffset.X;
3524 Y := MousePos.Y-MapOffset.Y;
3525 end;
3527 SELECTFLAG_SPAWNPOINT:
3528 // Точку создания монстра:
3529 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
3530 if TriggerType = TRIGGER_SPAWNMONSTER then
3531 begin
3532 Data.MonPos.X := MousePos.X-MapOffset.X;
3533 Data.MonPos.Y := MousePos.Y-MapOffset.Y;
3534 end
3535 else if TriggerType = TRIGGER_SPAWNITEM then
3536 begin // Точка создания предмета:
3537 Data.ItemPos.X := MousePos.X-MapOffset.X;
3538 Data.ItemPos.Y := MousePos.Y-MapOffset.Y;
3539 end
3540 else if TriggerType = TRIGGER_SHOT then
3541 begin // Точка создания выстрела:
3542 Data.ShotPos.X := MousePos.X-MapOffset.X;
3543 Data.ShotPos.Y := MousePos.Y-MapOffset.Y;
3544 end;
3546 SELECTFLAG_DOOR:
3547 // Дверь:
3548 begin
3549 IDArray := ObjectInRect(X-MapOffset.X,
3550 Y-MapOffset.Y,
3551 2, 2, OBJECT_PANEL, True);
3552 if IDArray <> nil then
3553 begin
3554 for i := 0 to High(IDArray) do
3555 if (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3556 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR) then
3557 begin
3558 gTriggers[SelectedObjects[
3559 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3560 Break;
3561 end;
3562 end
3563 else
3564 gTriggers[SelectedObjects[
3565 GetFirstSelected() ].ID].Data.PanelID := -1;
3566 end;
3568 SELECTFLAG_TEXTURE:
3569 // Панель с текстурой:
3570 begin
3571 IDArray := ObjectInRect(X-MapOffset.X,
3572 Y-MapOffset.Y,
3573 2, 2, OBJECT_PANEL, True);
3574 if IDArray <> nil then
3575 begin
3576 for i := 0 to High(IDArray) do
3577 if ((gPanels[IDArray[i]].PanelType in
3578 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3579 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3580 PANEL_STEP]) or
3581 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3582 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3583 (gPanels[IDArray[i]].TextureName <> '') then
3584 begin
3585 gTriggers[SelectedObjects[
3586 GetFirstSelected() ].ID].TexturePanel := IDArray[i];
3587 Break;
3588 end;
3589 end
3590 else
3591 gTriggers[SelectedObjects[
3592 GetFirstSelected() ].ID].TexturePanel := -1;
3593 end;
3595 SELECTFLAG_LIFT:
3596 // Лифт:
3597 begin
3598 IDArray := ObjectInRect(X-MapOffset.X,
3599 Y-MapOffset.Y,
3600 2, 2, OBJECT_PANEL, True);
3601 if IDArray <> nil then
3602 begin
3603 for i := 0 to High(IDArray) do
3604 if (gPanels[IDArray[i]].PanelType = PANEL_LIFTUP) or
3605 (gPanels[IDArray[i]].PanelType = PANEL_LIFTDOWN) or
3606 (gPanels[IDArray[i]].PanelType = PANEL_LIFTLEFT) or
3607 (gPanels[IDArray[i]].PanelType = PANEL_LIFTRIGHT) then
3608 begin
3609 gTriggers[SelectedObjects[
3610 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3611 Break;
3612 end;
3613 end
3614 else
3615 gTriggers[SelectedObjects[
3616 GetFirstSelected() ].ID].Data.PanelID := -1;
3617 end;
3619 SELECTFLAG_MONSTER:
3620 // Монстра:
3621 begin
3622 IDArray := ObjectInRect(X-MapOffset.X,
3623 Y-MapOffset.Y,
3624 2, 2, OBJECT_MONSTER, False);
3625 if IDArray <> nil then
3626 gTriggers[SelectedObjects[
3627 GetFirstSelected() ].ID].Data.MonsterID := IDArray[0]+1
3628 else
3629 gTriggers[SelectedObjects[
3630 GetFirstSelected() ].ID].Data.MonsterID := 0;
3631 end;
3633 SELECTFLAG_SHOTPANEL:
3634 // Панель индикации выстрела:
3635 begin
3636 if gTriggers[SelectedObjects[
3637 GetFirstSelected() ].ID].TriggerType = TRIGGER_SHOT then
3638 begin
3639 IDArray := ObjectInRect(X-MapOffset.X,
3640 Y-MapOffset.Y,
3641 2, 2, OBJECT_PANEL, True);
3642 if IDArray <> nil then
3643 begin
3644 for i := 0 to High(IDArray) do
3645 if ((gPanels[IDArray[i]].PanelType in
3646 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3647 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3648 PANEL_STEP]) or
3649 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3650 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3651 (gPanels[IDArray[i]].TextureName <> '') then
3652 begin
3653 gTriggers[SelectedObjects[
3654 GetFirstSelected() ].ID].Data.ShotPanelID := IDArray[i];
3655 Break;
3656 end;
3657 end
3658 else
3659 gTriggers[SelectedObjects[
3660 GetFirstSelected() ].ID].Data.ShotPanelID := -1;
3661 end;
3662 end;
3663 end;
3665 SelectFlag := SELECTFLAG_SELECTED;
3666 end
3667 else // if SelectFlag <> SELECTFLAG_NONE...
3668 begin
3669 // Что уже выбрано и не нажат Ctrl:
3670 if (SelectedObjects <> nil) and
3671 (not (ssCtrl in Shift)) then
3672 for i := 0 to High(SelectedObjects) do
3673 with SelectedObjects[i] do
3674 if Live then
3675 begin
3676 if (ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) and
3677 (SelectedObjectCount() = 1) then
3678 begin
3679 Rect := ObjectGetRect(ObjectType, ID);
3681 c1 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3682 Rect.X-2, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3683 c2 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3684 Rect.X+Rect.Width-3, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3685 c3 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3686 Rect.X+(Rect.Width div 2)-2, Rect.Y-2, 4, 4);
3687 c4 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3688 Rect.X+(Rect.Width div 2)-2, Rect.Y+Rect.Height-3, 4, 4);
3690 // Меняем размер панели или триггера:
3691 if c1 or c2 or c3 or c4 then
3692 begin
3693 MouseAction := MOUSEACTION_RESIZE;
3694 LastMovePoint := MousePos;
3696 if c1 or c2 then
3697 begin // Шире/уже
3698 ResizeType := RESIZETYPE_HORIZONTAL;
3699 if c1 then
3700 ResizeDirection := RESIZEDIR_LEFT
3701 else
3702 ResizeDirection := RESIZEDIR_RIGHT;
3703 RenderPanel.Cursor := crSizeWE;
3704 end
3705 else
3706 begin // Выше/ниже
3707 ResizeType := RESIZETYPE_VERTICAL;
3708 if c3 then
3709 ResizeDirection := RESIZEDIR_UP
3710 else
3711 ResizeDirection := RESIZEDIR_DOWN;
3712 RenderPanel.Cursor := crSizeNS;
3713 end;
3715 Break;
3716 end;
3717 end;
3719 // Перемещаем панель или триггер:
3720 if ObjectCollide(ObjectType, ID,
3721 X-MapOffset.X-1,
3722 Y-MapOffset.Y-1, 2, 2) then
3723 begin
3724 MouseAction := MOUSEACTION_MOVEOBJ;
3725 LastMovePoint := MousePos;
3727 Break;
3728 end;
3729 end;
3730 end;
3731 end; // if Button = mbRight
3733 if Button = mbMiddle then // Middle Mouse Button
3734 begin
3735 SetCapture(RenderPanel.Handle);
3736 RenderPanel.Cursor := crSize;
3737 end;
3739 MouseMDown := Button = mbMiddle;
3740 if MouseMDown then
3741 MouseMDownPos := Mouse.CursorPos;
3743 MouseRDown := Button = mbRight;
3744 if MouseRDown then
3745 MouseRDownPos := MousePos;
3747 MouseLDown := Button = mbLeft;
3748 if MouseLDown then
3749 MouseLDownPos := MousePos;
3750 end;
3752 procedure TMainForm.RenderPanelMouseUp(Sender: TObject;
3753 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3754 var
3755 panel: TPanel;
3756 trigger: TTrigger;
3757 rRect: TRectWH;
3758 rSelectRect: Boolean;
3759 wWidth, wHeight: Word;
3760 TextureID: DWORD;
3762 procedure SelectObjects(ObjectType: Byte);
3763 var
3764 i: Integer;
3765 IDArray: DWArray;
3766 begin
3767 IDArray := ObjectInRect(rRect.X, rRect.Y,
3768 rRect.Width, rRect.Height,
3769 ObjectType, rSelectRect);
3771 if IDArray <> nil then
3772 for i := 0 to High(IDArray) do
3773 SelectObject(ObjectType, IDArray[i], (ssCtrl in Shift) or rSelectRect);
3774 end;
3775 begin
3776 if Button = mbLeft then
3777 MouseLDown := False;
3778 if Button = mbRight then
3779 MouseRDown := False;
3780 if Button = mbMiddle then
3781 MouseMDown := False;
3783 if DrawRect <> nil then
3784 begin
3785 Dispose(DrawRect);
3786 DrawRect := nil;
3787 end;
3789 ResizeType := RESIZETYPE_NONE;
3790 TextureID := 0;
3792 if Button = mbLeft then // Left Mouse Button
3793 begin
3794 if MouseAction <> MOUSEACTION_NONE then
3795 begin // Было действие мышью
3796 // Мышь сдвинулась во время удержания клавиши,
3797 // либо активирован режим быстрого рисования:
3798 if ((MousePos.X <> MouseLDownPos.X) and
3799 (MousePos.Y <> MouseLDownPos.Y)) or
3800 ((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
3801 (ssCtrl in Shift)) then
3802 case MouseAction of
3803 // Рисовали панель:
3804 MOUSEACTION_DRAWPANEL:
3805 begin
3806 // Фон или передний план без текстуры - ошибка:
3807 if (lbPanelType.ItemIndex in [1, 2]) and
3808 (lbTextureList.ItemIndex = -1) then
3809 ErrorMessageBox(MsgMsgChooseTexture)
3810 else // Назначаем параметры панели:
3811 begin
3812 case lbPanelType.ItemIndex of
3813 0: Panel.PanelType := PANEL_WALL;
3814 1: Panel.PanelType := PANEL_BACK;
3815 2: Panel.PanelType := PANEL_FORE;
3816 3: Panel.PanelType := PANEL_OPENDOOR;
3817 4: Panel.PanelType := PANEL_CLOSEDOOR;
3818 5: Panel.PanelType := PANEL_STEP;
3819 6: Panel.PanelType := PANEL_WATER;
3820 7: Panel.PanelType := PANEL_ACID1;
3821 8: Panel.PanelType := PANEL_ACID2;
3822 9: Panel.PanelType := PANEL_LIFTUP;
3823 10: Panel.PanelType := PANEL_LIFTDOWN;
3824 11: Panel.PanelType := PANEL_LIFTLEFT;
3825 12: Panel.PanelType := PANEL_LIFTRIGHT;
3826 13: Panel.PanelType := PANEL_BLOCKMON;
3827 end;
3829 Panel.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3830 Panel.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3831 if ssCtrl in Shift then
3832 begin
3833 wWidth := DotStep;
3834 wHeight := DotStep;
3835 if (lbTextureList.ItemIndex <> -1) and
3836 (not IsSpecialTextureSel()) then
3837 begin
3838 if not g_GetTexture(SelectedTexture(), TextureID) then
3839 g_GetTexture('NOTEXTURE', TextureID);
3840 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
3841 end;
3842 Panel.Width := wWidth;
3843 Panel.Height := wHeight;
3844 end
3845 else
3846 begin
3847 Panel.Width := Abs(MousePos.X-MouseLDownPos.X);
3848 Panel.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3849 end;
3851 // Лифты, блокМон или отсутствие текстуры - пустая текстура:
3852 if (lbPanelType.ItemIndex in [9, 10, 11, 12, 13]) or
3853 (lbTextureList.ItemIndex = -1) then
3854 begin
3855 Panel.TextureHeight := 1;
3856 Panel.TextureWidth := 1;
3857 Panel.TextureName := '';
3858 Panel.TextureID := TEXTURE_SPECIAL_NONE;
3859 end
3860 else // Есть текстура:
3861 begin
3862 Panel.TextureName := SelectedTexture();
3864 // Обычная текстура:
3865 if not IsSpecialTextureSel() then
3866 begin
3867 g_GetTextureSizeByName(Panel.TextureName,
3868 Panel.TextureWidth, Panel.TextureHeight);
3869 g_GetTexture(Panel.TextureName, Panel.TextureID);
3870 end
3871 else // Спец.текстура:
3872 begin
3873 Panel.TextureHeight := 1;
3874 Panel.TextureWidth := 1;
3875 Panel.TextureID := SpecialTextureID(SelectedTexture());
3876 end;
3877 end;
3879 Panel.Alpha := 0;
3880 Panel.Blending := False;
3882 Undo_Add(OBJECT_PANEL, AddPanel(Panel));
3883 end;
3884 end;
3886 // Рисовали триггер:
3887 MOUSEACTION_DRAWTRIGGER:
3888 begin
3889 trigger.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3890 trigger.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3891 if ssCtrl in Shift then
3892 begin
3893 wWidth := DotStep;
3894 wHeight := DotStep;
3895 trigger.Width := wWidth;
3896 trigger.Height := wHeight;
3897 end
3898 else
3899 begin
3900 trigger.Width := Abs(MousePos.X-MouseLDownPos.X);
3901 trigger.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3902 end;
3904 trigger.Enabled := True;
3905 trigger.TriggerType := lbTriggersList.ItemIndex+1;
3906 trigger.TexturePanel := -1;
3908 // Типы активации:
3909 trigger.ActivateType := 0;
3911 if clbActivationType.Checked[0] then
3912 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERCOLLIDE;
3913 if clbActivationType.Checked[1] then
3914 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERCOLLIDE;
3915 if clbActivationType.Checked[2] then
3916 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERPRESS;
3917 if clbActivationType.Checked[3] then
3918 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERPRESS;
3919 if clbActivationType.Checked[4] then
3920 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_SHOT;
3921 if clbActivationType.Checked[5] then
3922 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_NOMONSTER;
3924 // Необходимые для активации ключи:
3925 trigger.Key := 0;
3927 if clbKeys.Checked[0] then
3928 trigger.Key := Trigger.Key or KEY_RED;
3929 if clbKeys.Checked[1] then
3930 trigger.Key := Trigger.Key or KEY_GREEN;
3931 if clbKeys.Checked[2] then
3932 trigger.Key := Trigger.Key or KEY_BLUE;
3933 if clbKeys.Checked[3] then
3934 trigger.Key := Trigger.Key or KEY_REDTEAM;
3935 if clbKeys.Checked[4] then
3936 trigger.Key := Trigger.Key or KEY_BLUETEAM;
3938 // Параметры триггера:
3939 FillByte(trigger.Data.Default[0], 128, 0);
3941 case trigger.TriggerType of
3942 // Переключаемая панель:
3943 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
3944 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
3945 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
3946 begin
3947 Trigger.Data.PanelID := -1;
3948 end;
3950 // Телепортация:
3951 TRIGGER_TELEPORT:
3952 begin
3953 trigger.Data.TargetPoint.X := trigger.X-64;
3954 trigger.Data.TargetPoint.Y := trigger.Y-64;
3955 trigger.Data.d2d_teleport := True;
3956 trigger.Data.TlpDir := 0;
3957 end;
3959 // Изменение других триггеров:
3960 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
3961 TRIGGER_ONOFF:
3962 begin
3963 trigger.Data.Count := 1;
3964 end;
3966 // Звук:
3967 TRIGGER_SOUND:
3968 begin
3969 trigger.Data.Volume := 255;
3970 trigger.Data.Pan := 127;
3971 trigger.Data.PlayCount := 1;
3972 trigger.Data.Local := True;
3973 trigger.Data.SoundSwitch := False;
3974 end;
3976 // Музыка:
3977 TRIGGER_MUSIC:
3978 begin
3979 trigger.Data.MusicAction := 1;
3980 end;
3982 // Создание монстра:
3983 TRIGGER_SPAWNMONSTER:
3984 begin
3985 trigger.Data.MonType := MONSTER_ZOMBY;
3986 trigger.Data.MonPos.X := trigger.X-64;
3987 trigger.Data.MonPos.Y := trigger.Y-64;
3988 trigger.Data.MonHealth := 0;
3989 trigger.Data.MonActive := False;
3990 trigger.Data.MonCount := 1;
3991 end;
3993 // Создание предмета:
3994 TRIGGER_SPAWNITEM:
3995 begin
3996 trigger.Data.ItemType := ITEM_AMMO_BULLETS;
3997 trigger.Data.ItemPos.X := trigger.X-64;
3998 trigger.Data.ItemPos.Y := trigger.Y-64;
3999 trigger.Data.ItemOnlyDM := False;
4000 trigger.Data.ItemFalls := False;
4001 trigger.Data.ItemCount := 1;
4002 trigger.Data.ItemMax := 0;
4003 trigger.Data.ItemDelay := 0;
4004 end;
4006 // Ускорение:
4007 TRIGGER_PUSH:
4008 begin
4009 trigger.Data.PushAngle := 90;
4010 trigger.Data.PushForce := 10;
4011 trigger.Data.ResetVel := True;
4012 end;
4014 TRIGGER_SCORE:
4015 begin
4016 trigger.Data.ScoreCount := 1;
4017 trigger.Data.ScoreCon := True;
4018 trigger.Data.ScoreMsg := True;
4019 end;
4021 TRIGGER_MESSAGE:
4022 begin
4023 trigger.Data.MessageKind := 0;
4024 trigger.Data.MessageSendTo := 0;
4025 trigger.Data.MessageText := '';
4026 trigger.Data.MessageTime := 144;
4027 end;
4029 TRIGGER_DAMAGE:
4030 begin
4031 trigger.Data.DamageValue := 5;
4032 trigger.Data.DamageInterval := 12;
4033 end;
4035 TRIGGER_HEALTH:
4036 begin
4037 trigger.Data.HealValue := 5;
4038 trigger.Data.HealInterval := 36;
4039 end;
4041 TRIGGER_SHOT:
4042 begin
4043 trigger.Data.ShotType := TRIGGER_SHOT_BULLET;
4044 trigger.Data.ShotSound := True;
4045 trigger.Data.ShotPanelID := -1;
4046 trigger.Data.ShotTarget := 0;
4047 trigger.Data.ShotIntSight := 0;
4048 trigger.Data.ShotAim := TRIGGER_SHOT_AIM_DEFAULT;
4049 trigger.Data.ShotPos.X := trigger.X-64;
4050 trigger.Data.ShotPos.Y := trigger.Y-64;
4051 trigger.Data.ShotAngle := 0;
4052 trigger.Data.ShotWait := 18;
4053 trigger.Data.ShotAccuracy := 0;
4054 trigger.Data.ShotAmmo := 0;
4055 trigger.Data.ShotIntReload := 0;
4056 end;
4058 TRIGGER_EFFECT:
4059 begin
4060 trigger.Data.FXCount := 1;
4061 trigger.Data.FXType := TRIGGER_EFFECT_PARTICLE;
4062 trigger.Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
4063 trigger.Data.FXColorR := 0;
4064 trigger.Data.FXColorG := 0;
4065 trigger.Data.FXColorB := 255;
4066 trigger.Data.FXPos := TRIGGER_EFFECT_POS_CENTER;
4067 trigger.Data.FXWait := 1;
4068 trigger.Data.FXVelX := 0;
4069 trigger.Data.FXVelY := -20;
4070 trigger.Data.FXSpreadL := 5;
4071 trigger.Data.FXSpreadR := 5;
4072 trigger.Data.FXSpreadU := 4;
4073 trigger.Data.FXSpreadD := 0;
4074 end;
4075 end;
4077 Undo_Add(OBJECT_TRIGGER, AddTrigger(trigger));
4078 end;
4080 // Рисовали область триггера "Расширитель":
4081 MOUSEACTION_DRAWPRESS:
4082 with gTriggers[SelectedObjects[GetFirstSelected].ID] do
4083 begin
4084 Data.tX := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
4085 Data.tY := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
4086 Data.tWidth := Abs(MousePos.X-MouseLDownPos.X);
4087 Data.tHeight := Abs(MousePos.Y-MouseLDownPos.Y);
4089 DrawPressRect := False;
4090 end;
4091 end;
4093 MouseAction := MOUSEACTION_NONE;
4094 end;
4095 end // if Button = mbLeft...
4096 else if Button = mbRight then // Right Mouse Button:
4097 begin
4098 if MouseAction = MOUSEACTION_NOACTION then
4099 begin
4100 MouseAction := MOUSEACTION_NONE;
4101 Exit;
4102 end;
4104 // Объект передвинут или изменен в размере:
4105 if MouseAction in [MOUSEACTION_MOVEOBJ, MOUSEACTION_RESIZE] then
4106 begin
4107 RenderPanel.Cursor := crDefault;
4108 MouseAction := MOUSEACTION_NONE;
4109 FillProperty();
4110 Exit;
4111 end;
4113 // Еще не все выбрали:
4114 if SelectFlag <> SELECTFLAG_NONE then
4115 begin
4116 if SelectFlag = SELECTFLAG_SELECTED then
4117 SelectFlag := SELECTFLAG_NONE;
4118 FillProperty();
4119 Exit;
4120 end;
4122 // Мышь сдвинулась во время удержания клавиши:
4123 if (MousePos.X <> MouseRDownPos.X) and
4124 (MousePos.Y <> MouseRDownPos.Y) then
4125 begin
4126 rSelectRect := True;
4128 rRect.X := Min(MousePos.X, MouseRDownPos.X)-MapOffset.X;
4129 rRect.Y := Min(MousePos.Y, MouseRDownPos.Y)-MapOffset.Y;
4130 rRect.Width := Abs(MousePos.X-MouseRDownPos.X);
4131 rRect.Height := Abs(MousePos.Y-MouseRDownPos.Y);
4132 end
4133 else // Мышь не сдвинулась - нет прямоугольника:
4134 begin
4135 rSelectRect := False;
4137 rRect.X := X-MapOffset.X-1;
4138 rRect.Y := Y-MapOffset.Y-1;
4139 rRect.Width := 2;
4140 rRect.Height := 2;
4141 end;
4143 // Если зажат Ctrl - выделять еще, иначе только один выделенный объект:
4144 if not (ssCtrl in Shift) then
4145 RemoveSelectFromObjects();
4147 // Выделяем всё в выбранном прямоугольнике:
4148 if (ssCtrl in Shift) and (ssAlt in Shift) then
4149 begin
4150 SelectObjects(OBJECT_PANEL);
4151 SelectObjects(OBJECT_ITEM);
4152 SelectObjects(OBJECT_MONSTER);
4153 SelectObjects(OBJECT_AREA);
4154 SelectObjects(OBJECT_TRIGGER);
4155 end
4156 else
4157 SelectObjects(pcObjects.ActivePageIndex+1);
4159 FillProperty();
4160 end
4162 else // Middle Mouse Button
4163 begin
4164 RenderPanel.Cursor := crDefault;
4165 ReleaseCapture();
4166 end;
4167 end;
4169 procedure TMainForm.RenderPanelPaint(Sender: TObject);
4170 begin
4171 Draw();
4172 end;
4174 function TMainForm.RenderMousePos(): Types.TPoint;
4175 begin
4176 Result := RenderPanel.ScreenToClient(Mouse.CursorPos);
4177 end;
4179 procedure TMainForm.RecountSelectedObjects();
4180 begin
4181 if SelectedObjectCount() = 0 then
4182 StatusBar.Panels[0].Text := ''
4183 else
4184 StatusBar.Panels[0].Text := Format(MsgCapStatSelected, [SelectedObjectCount()]);
4185 end;
4187 procedure TMainForm.RenderPanelMouseMove(Sender: TObject;
4188 Shift: TShiftState; X, Y: Integer);
4189 var
4190 sX, sY: Integer;
4191 dWidth, dHeight: Integer;
4192 _id: Integer;
4193 TextureID: DWORD;
4194 wWidth, wHeight: Word;
4195 begin
4196 _id := GetFirstSelected();
4197 TextureID := 0;
4199 // Рисуем панель с текстурой, сетка - размеры текстуры:
4200 if (MouseAction = MOUSEACTION_DRAWPANEL) and
4201 (lbPanelType.ItemIndex in [0..8]) and
4202 (lbTextureList.ItemIndex <> -1) and
4203 (not IsSpecialTextureSel()) then
4204 begin
4205 sX := StrToIntDef(lTextureWidth.Caption, DotStep);
4206 sY := StrToIntDef(lTextureHeight.Caption, DotStep);
4207 end
4208 else
4209 // Меняем размер панели с текстурой, сетка - размеры текстуры:
4210 if (MouseAction = MOUSEACTION_RESIZE) and
4211 ( (SelectedObjects[_id].ObjectType = OBJECT_PANEL) and
4212 IsTexturedPanel(gPanels[SelectedObjects[_id].ID].PanelType) and
4213 (gPanels[SelectedObjects[_id].ID].TextureName <> '') and
4214 (not IsSpecialTexture(gPanels[SelectedObjects[_id].ID].TextureName)) ) then
4215 begin
4216 sX := gPanels[SelectedObjects[_id].ID].TextureWidth;
4217 sY := gPanels[SelectedObjects[_id].ID].TextureHeight;
4218 end
4219 else
4220 // Выравнивание по сетке:
4221 if SnapToGrid then
4222 begin
4223 sX := DotStep;
4224 sY := DotStep;
4225 end
4226 else // Нет выравнивания по сетке:
4227 begin
4228 sX := 1;
4229 sY := 1;
4230 end;
4232 // Новая позиция мыши:
4233 if MouseLDown then
4234 begin // Зажата левая кнопка мыши
4235 MousePos.X := (Round((X-MouseLDownPos.X)/sX)*sX)+MouseLDownPos.X;
4236 MousePos.Y := (Round((Y-MouseLDownPos.Y)/sY)*sY)+MouseLDownPos.Y;
4237 end
4238 else
4239 if MouseRDown then
4240 begin // Зажата правая кнопка мыши
4241 MousePos.X := (Round((X-MouseRDownPos.X)/sX)*sX)+MouseRDownPos.X;
4242 MousePos.Y := (Round((Y-MouseRDownPos.Y)/sY)*sY)+MouseRDownPos.Y;
4243 end
4244 else
4245 begin // Кнопки мыши не зажаты
4246 MousePos.X := Round((-MapOffset.X + X) / sX) * sX + MapOffset.X;
4247 MousePos.Y := Round((-MapOffset.Y + Y) / sY) * sY + MapOffset.Y;
4248 end;
4250 // Зажата только правая кнопка мыши:
4251 if (not MouseLDown) and (MouseRDown) and (not MouseMDown) then
4252 begin
4253 // Рисуем прямоугольник выделения:
4254 if MouseAction = MOUSEACTION_NONE then
4255 begin
4256 if DrawRect = nil then
4257 New(DrawRect);
4258 DrawRect.Top := MouseRDownPos.y;
4259 DrawRect.Left := MouseRDownPos.x;
4260 DrawRect.Bottom := MousePos.y;
4261 DrawRect.Right := MousePos.x;
4262 end
4263 else
4264 // Двигаем выделенные объекты:
4265 if MouseAction = MOUSEACTION_MOVEOBJ then
4266 begin
4267 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
4268 MousePos.X-LastMovePoint.X,
4269 MousePos.Y-LastMovePoint.Y);
4270 end
4271 else
4272 // Меняем размер выделенного объекта:
4273 if MouseAction = MOUSEACTION_RESIZE then
4274 begin
4275 if (SelectedObjectCount = 1) and
4276 (SelectedObjects[GetFirstSelected].Live) then
4277 begin
4278 dWidth := MousePos.X-LastMovePoint.X;
4279 dHeight := MousePos.Y-LastMovePoint.Y;
4281 case ResizeType of
4282 RESIZETYPE_VERTICAL: dWidth := 0;
4283 RESIZETYPE_HORIZONTAL: dHeight := 0;
4284 end;
4286 case ResizeDirection of
4287 RESIZEDIR_UP: dHeight := -dHeight;
4288 RESIZEDIR_LEFT: dWidth := -dWidth;
4289 end;
4291 if ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
4292 SelectedObjects[GetFirstSelected].ID,
4293 dWidth, dHeight, ResizeDirection) then
4294 LastMovePoint := MousePos;
4295 end;
4296 end;
4297 end;
4299 // Зажата только левая кнопка мыши:
4300 if (not MouseRDown) and (MouseLDown) and (not MouseMDown) then
4301 begin
4302 // Рисуем прямоугольник планирования панели:
4303 if MouseAction in [MOUSEACTION_DRAWPANEL,
4304 MOUSEACTION_DRAWTRIGGER,
4305 MOUSEACTION_DRAWPRESS] then
4306 begin
4307 if DrawRect = nil then
4308 New(DrawRect);
4309 if ssCtrl in Shift then
4310 begin
4311 wWidth := DotStep;
4312 wHeight := DotStep;
4313 if (lbTextureList.ItemIndex <> -1) and (not IsSpecialTextureSel()) and
4314 (MouseAction = MOUSEACTION_DRAWPANEL) then
4315 begin
4316 if not g_GetTexture(SelectedTexture(), TextureID) then
4317 g_GetTexture('NOTEXTURE', TextureID);
4318 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
4319 end;
4320 DrawRect.Top := MouseLDownPos.y;
4321 DrawRect.Left := MouseLDownPos.x;
4322 DrawRect.Bottom := DrawRect.Top + wHeight;
4323 DrawRect.Right := DrawRect.Left + wWidth;
4324 end
4325 else
4326 begin
4327 DrawRect.Top := MouseLDownPos.y;
4328 DrawRect.Left := MouseLDownPos.x;
4329 DrawRect.Bottom := MousePos.y;
4330 DrawRect.Right := MousePos.x;
4331 end;
4332 end
4333 else // Двигаем карту:
4334 if MouseAction = MOUSEACTION_MOVEMAP then
4335 begin
4336 MoveMap(X, Y);
4337 end;
4338 end;
4340 // Only Middle Mouse Button is pressed
4341 if (not MouseLDown) and (not MouseRDown) and (MouseMDown) then
4342 begin
4343 MapOffset.X := -EnsureRange(-MapOffset.X + MouseMDownPos.X - Mouse.CursorPos.X,
4344 sbHorizontal.Min, sbHorizontal.Max);
4345 sbHorizontal.Position := -MapOffset.X;
4346 MapOffset.Y := -EnsureRange(-MapOffset.Y + MouseMDownPos.Y - Mouse.CursorPos.Y,
4347 sbVertical.Min, sbVertical.Max);
4348 sbVertical.Position := -MapOffset.Y;
4349 MouseMDownPos := Mouse.CursorPos;
4350 end;
4352 // Клавиши мыши не зажаты:
4353 if (not MouseRDown) and (not MouseLDown) and (DrawRect <> nil) then
4354 begin
4355 Dispose(DrawRect);
4356 DrawRect := nil;
4357 end;
4359 // Строка состояния - координаты мыши:
4360 StatusBar.Panels[1].Text := Format('(%d:%d)',
4361 [MousePos.X-MapOffset.X, MousePos.Y-MapOffset.Y]);
4363 RenderPanel.Invalidate;
4364 end;
4366 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
4367 begin
4368 CanClose := Application.MessageBox(PChar(MsgMsgExitPrompt),
4369 PChar(MsgMsgExit),
4370 MB_ICONQUESTION or MB_YESNO or
4371 MB_DEFBUTTON1) = idYes;
4372 end;
4374 procedure TMainForm.aExitExecute(Sender: TObject);
4375 begin
4376 Close();
4377 end;
4379 procedure TMainForm.FormDestroy(Sender: TObject);
4380 var
4381 config: TConfig;
4382 s: AnsiString;
4383 i: Integer;
4384 begin
4385 config := TConfig.CreateFile(CfgFileName);
4387 config.WriteInt('WADEditor', 'LogLevel', gWADEditorLogLevel);
4389 if WindowState <> wsMaximized then
4390 begin
4391 config.WriteInt('Editor', 'XPos', Left);
4392 config.WriteInt('Editor', 'YPos', Top);
4393 config.WriteInt('Editor', 'Width', Width);
4394 config.WriteInt('Editor', 'Height', Height);
4395 end
4396 else
4397 begin
4398 config.WriteInt('Editor', 'XPos', RestoredLeft);
4399 config.WriteInt('Editor', 'YPos', RestoredTop);
4400 config.WriteInt('Editor', 'Width', RestoredWidth);
4401 config.WriteInt('Editor', 'Height', RestoredHeight);
4402 end;
4403 config.WriteBool('Editor', 'Maximize', WindowState = wsMaximized);
4404 config.WriteBool('Editor', 'Minimap', ShowMap);
4405 config.WriteInt('Editor', 'PanelProps', PanelProps.ClientWidth);
4406 config.WriteInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
4407 config.WriteBool('Editor', 'DotEnable', DotEnable);
4408 config.WriteInt('Editor', 'DotStep', DotStep);
4409 config.WriteStr('Editor', 'LastOpenDir', OpenDialog.InitialDir);
4410 config.WriteStr('Editor', 'LastSaveDir', SaveDialog.InitialDir);
4411 config.WriteStr('Editor', 'Language', gLanguage);
4412 config.WriteBool('Editor', 'EdgeShow', drEdge[3] < 255);
4413 config.WriteInt('Editor', 'EdgeColor', gColorEdge);
4414 config.WriteInt('Editor', 'EdgeAlpha', gAlphaEdge);
4415 config.WriteInt('Editor', 'LineAlpha', gAlphaTriggerLine);
4416 config.WriteInt('Editor', 'TriggerAlpha', gAlphaTriggerArea);
4417 config.WriteInt('Editor', 'MonsterRectAlpha', gAlphaMonsterRect);
4418 config.WriteInt('Editor', 'AreaRectAlpha', gAlphaAreaRect);
4420 for i := 0 to RecentCount - 1 do
4421 begin
4422 if i < RecentFiles.Count then s := RecentFiles[i] else s := '';
4423 {$IFDEF WINDOWS}
4424 config.WriteStr('RecentFilesWin', IntToStr(i), s);
4425 {$ELSE}
4426 config.WriteStr('RecentFilesUnix', IntToStr(i), s);
4427 {$ENDIF}
4428 end;
4429 RecentFiles.Free();
4431 config.SaveFile(CfgFileName);
4432 config.Free();
4434 slInvalidTextures.Free;
4435 end;
4437 procedure TMainForm.FormDropFiles(Sender: TObject;
4438 const FileNames: array of String);
4439 begin
4440 if Length(FileNames) <> 1 then
4441 Exit;
4443 OpenMapFile(FileNames[0]);
4444 end;
4446 procedure TMainForm.RenderPanelResize(Sender: TObject);
4447 begin
4448 if MainForm.Visible then
4449 MainForm.Resize();
4450 end;
4452 procedure TMainForm.Splitter1Moved(Sender: TObject);
4453 begin
4454 FormResize(Sender);
4455 end;
4457 procedure TMainForm.MapTestCheck(Sender: TObject);
4458 begin
4459 if MapTestProcess <> nil then
4460 begin
4461 if MapTestProcess.Running = false then
4462 begin
4463 if MapTestProcess.ExitCode <> 0 then
4464 Application.MessageBox(PChar(MsgMsgExecError), 'FIXME', MB_OK or MB_ICONERROR);
4465 SysUtils.DeleteFile(MapTestFile);
4466 MapTestFile := '';
4467 FreeAndNil(MapTestProcess);
4468 tbTestMap.Enabled := True;
4469 end;
4470 end;
4471 end;
4473 procedure TMainForm.aMapOptionsExecute(Sender: TObject);
4474 var
4475 ResName: String;
4476 begin
4477 MapOptionsForm.ShowModal();
4479 ResName := OpenedMap;
4480 while (Pos(':\', ResName) > 0) do
4481 Delete(ResName, 1, Pos(':\', ResName) + 1);
4483 UpdateCaption(gMapInfo.Name, ExtractFileName(OpenedWAD), ResName);
4484 end;
4486 procedure TMainForm.aAboutExecute(Sender: TObject);
4487 begin
4488 AboutForm.ShowModal();
4489 end;
4491 procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
4492 var
4493 dx, dy, i: Integer;
4494 FileName: String;
4495 ok: Boolean;
4496 begin
4497 if (not EditingProperties) then
4498 begin
4499 if ssCtrl in Shift then
4500 begin
4501 case Chr(Key) of
4502 '1': ContourEnabled[LAYER_BACK] := not ContourEnabled[LAYER_BACK];
4503 '2': ContourEnabled[LAYER_WALLS] := not ContourEnabled[LAYER_WALLS];
4504 '3': ContourEnabled[LAYER_FOREGROUND] := not ContourEnabled[LAYER_FOREGROUND];
4505 '4': ContourEnabled[LAYER_STEPS] := not ContourEnabled[LAYER_STEPS];
4506 '5': ContourEnabled[LAYER_WATER] := not ContourEnabled[LAYER_WATER];
4507 '6': ContourEnabled[LAYER_ITEMS] := not ContourEnabled[LAYER_ITEMS];
4508 '7': ContourEnabled[LAYER_MONSTERS] := not ContourEnabled[LAYER_MONSTERS];
4509 '8': ContourEnabled[LAYER_AREAS] := not ContourEnabled[LAYER_AREAS];
4510 '9': ContourEnabled[LAYER_TRIGGERS] := not ContourEnabled[LAYER_TRIGGERS];
4511 '0':
4512 begin
4513 ok := False;
4514 for i := Low(ContourEnabled) to High(ContourEnabled) do
4515 if ContourEnabled[i] then
4516 ok := True;
4517 for i := Low(ContourEnabled) to High(ContourEnabled) do
4518 ContourEnabled[i] := not ok
4519 end
4520 end
4521 end
4522 else
4523 begin
4524 case Chr(key) of
4525 '1': SwitchLayer(LAYER_BACK);
4526 '2': SwitchLayer(LAYER_WALLS);
4527 '3': SwitchLayer(LAYER_FOREGROUND);
4528 '4': SwitchLayer(LAYER_STEPS);
4529 '5': SwitchLayer(LAYER_WATER);
4530 '6': SwitchLayer(LAYER_ITEMS);
4531 '7': SwitchLayer(LAYER_MONSTERS);
4532 '8': SwitchLayer(LAYER_AREAS);
4533 '9': SwitchLayer(LAYER_TRIGGERS);
4534 '0': tbShowClick(tbShow);
4535 end
4536 end;
4538 if Key = Ord('I') then
4539 begin // Поворот монстров и областей:
4540 if (SelectedObjects <> nil) then
4541 begin
4542 for i := 0 to High(SelectedObjects) do
4543 if (SelectedObjects[i].Live) then
4544 begin
4545 if (SelectedObjects[i].ObjectType = OBJECT_MONSTER) then
4546 begin
4547 g_ChangeDir(gMonsters[SelectedObjects[i].ID].Direction);
4548 end
4549 else
4550 if (SelectedObjects[i].ObjectType = OBJECT_AREA) then
4551 begin
4552 g_ChangeDir(gAreas[SelectedObjects[i].ID].Direction);
4553 end;
4554 end;
4555 end
4556 else
4557 begin
4558 if pcObjects.ActivePage = tsMonsters then
4559 begin
4560 if rbMonsterLeft.Checked then
4561 rbMonsterRight.Checked := True
4562 else
4563 rbMonsterLeft.Checked := True;
4564 end;
4565 if pcObjects.ActivePage = tsAreas then
4566 begin
4567 if rbAreaLeft.Checked then
4568 rbAreaRight.Checked := True
4569 else
4570 rbAreaLeft.Checked := True;
4571 end;
4572 end;
4573 end;
4575 if not (ssCtrl in Shift) then
4576 begin
4577 // Быстрое превью карты:
4578 if Key = Ord('E') then
4579 begin
4580 if PreviewMode = 0 then
4581 PreviewMode := 2;
4582 end;
4584 // Вертикальный скролл карты:
4585 with sbVertical do
4586 begin
4587 if Key = Ord('W') then
4588 begin
4589 dy := Position;
4590 if ssShift in Shift then Position := EnsureRange(Position - DotStep * 4, Min, Max)
4591 else Position := EnsureRange(Position - DotStep, Min, Max);
4592 MapOffset.Y := -Position;
4593 dy -= Position;
4595 if (MouseLDown or MouseRDown) then
4596 begin
4597 if DrawRect <> nil then
4598 begin
4599 Inc(MouseLDownPos.y, dy);
4600 Inc(MouseRDownPos.y, dy);
4601 end;
4602 Inc(LastMovePoint.Y, dy);
4603 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4604 end;
4605 end;
4607 if Key = Ord('S') then
4608 begin
4609 dy := Position;
4610 if ssShift in Shift then Position := EnsureRange(Position + DotStep * 4, Min, Max)
4611 else Position := EnsureRange(Position + DotStep, Min, Max);
4612 MapOffset.Y := -Position;
4613 dy -= Position;
4615 if (MouseLDown or MouseRDown) then
4616 begin
4617 if DrawRect <> nil then
4618 begin
4619 Inc(MouseLDownPos.y, dy);
4620 Inc(MouseRDownPos.y, dy);
4621 end;
4622 Inc(LastMovePoint.Y, dy);
4623 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4624 end;
4625 end;
4626 end;
4628 // Горизонтальный скролл карты:
4629 with sbHorizontal do
4630 begin
4631 if Key = Ord('A') then
4632 begin
4633 dx := Position;
4634 if ssShift in Shift then Position := EnsureRange(Position - DotStep * 4, Min, Max)
4635 else Position := EnsureRange(Position - DotStep, Min, Max);
4636 MapOffset.X := -Position;
4637 dx -= Position;
4639 if (MouseLDown or MouseRDown) then
4640 begin
4641 if DrawRect <> nil then
4642 begin
4643 Inc(MouseLDownPos.x, dx);
4644 Inc(MouseRDownPos.x, dx);
4645 end;
4646 Inc(LastMovePoint.X, dx);
4647 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4648 end;
4649 end;
4651 if Key = Ord('D') then
4652 begin
4653 dx := Position;
4654 if ssShift in Shift then Position := EnsureRange(Position + DotStep * 4, Min, Max)
4655 else Position := EnsureRange(Position + DotStep, Min, Max);
4656 MapOffset.X := -Position;
4657 dx -= Position;
4659 if (MouseLDown or MouseRDown) then
4660 begin
4661 if DrawRect <> nil then
4662 begin
4663 Inc(MouseLDownPos.x, dx);
4664 Inc(MouseRDownPos.x, dx);
4665 end;
4666 Inc(LastMovePoint.X, dx);
4667 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4668 end;
4669 end;
4670 end;
4671 end
4672 else // ssCtrl in Shift
4673 begin
4674 if ssShift in Shift then
4675 begin
4676 // Вставка по абсолютному смещению:
4677 if Key = Ord('V') then
4678 aPasteObjectExecute(Sender);
4679 end;
4680 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4681 end;
4682 end;
4684 // Удалить выделенные объекты:
4685 if (Key = VK_DELETE) and (SelectedObjects <> nil) and
4686 RenderPanel.Focused() then
4687 DeleteSelectedObjects();
4689 // Снять выделение:
4690 if (Key = VK_ESCAPE) and (SelectedObjects <> nil) then
4691 RemoveSelectFromObjects();
4693 // Передвинуть объекты:
4694 if MainForm.ActiveControl = RenderPanel then
4695 begin
4696 dx := 0;
4697 dy := 0;
4699 if Key = VK_NUMPAD4 then
4700 dx := IfThen(ssAlt in Shift, -1, -DotStep);
4701 if Key = VK_NUMPAD6 then
4702 dx := IfThen(ssAlt in Shift, 1, DotStep);
4703 if Key = VK_NUMPAD8 then
4704 dy := IfThen(ssAlt in Shift, -1, -DotStep);
4705 if Key = VK_NUMPAD5 then
4706 dy := IfThen(ssAlt in Shift, 1, DotStep);
4708 if (dx <> 0) or (dy <> 0) then
4709 begin
4710 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift, dx, dy);
4711 Key := 0;
4712 end;
4713 end;
4715 if ssCtrl in Shift then
4716 begin
4717 // Выбор панели с текстурой для триггера
4718 if Key = Ord('T') then
4719 begin
4720 DrawPressRect := False;
4721 if SelectFlag = SELECTFLAG_TEXTURE then
4722 begin
4723 SelectFlag := SELECTFLAG_NONE;
4724 Exit;
4725 end;
4726 vleObjectProperty.FindRow(MsgPropTrTexturePanel, i);
4727 if i > 0 then
4728 SelectFlag := SELECTFLAG_TEXTURE;
4729 end;
4731 if Key = Ord('D') then
4732 begin
4733 SelectFlag := SELECTFLAG_NONE;
4734 if DrawPressRect then
4735 begin
4736 DrawPressRect := False;
4737 Exit;
4738 end;
4739 i := -1;
4741 // Выбор области воздействия, в зависимости от типа триггера
4742 vleObjectProperty.FindRow(MsgPropTrExArea, i);
4743 if i > 0 then
4744 begin
4745 DrawPressRect := True;
4746 Exit;
4747 end;
4748 vleObjectProperty.FindRow(MsgPropTrDoorPanel, i);
4749 if i <= 0 then
4750 vleObjectProperty.FindRow(MsgPropTrTrapPanel, i);
4751 if i > 0 then
4752 begin
4753 SelectFlag := SELECTFLAG_DOOR;
4754 Exit;
4755 end;
4756 vleObjectProperty.FindRow(MsgPropTrLiftPanel, i);
4757 if i > 0 then
4758 begin
4759 SelectFlag := SELECTFLAG_LIFT;
4760 Exit;
4761 end;
4762 vleObjectProperty.FindRow(MsgPropTrTeleportTo, i);
4763 if i > 0 then
4764 begin
4765 SelectFlag := SELECTFLAG_TELEPORT;
4766 Exit;
4767 end;
4768 vleObjectProperty.FindRow(MsgPropTrSpawnTo, i);
4769 if i > 0 then
4770 begin
4771 SelectFlag := SELECTFLAG_SPAWNPOINT;
4772 Exit;
4773 end;
4775 // Выбор основного параметра, в зависимости от типа триггера
4776 vleObjectProperty.FindRow(MsgPropTrNextMap, i);
4777 if i > 0 then
4778 begin
4779 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
4780 SelectMapForm.Caption := MsgCapSelect;
4781 SelectMapForm.GetMaps(FileName);
4783 if SelectMapForm.ShowModal() = mrOK then
4784 begin
4785 vleObjectProperty.Cells[1, i] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
4786 bApplyProperty.Click();
4787 end;
4788 Exit;
4789 end;
4790 vleObjectProperty.FindRow(MsgPropTrSoundName, i);
4791 if i <= 0 then
4792 vleObjectProperty.FindRow(MsgPropTrMusicName, i);
4793 if i > 0 then
4794 begin
4795 AddSoundForm.OKFunction := nil;
4796 AddSoundForm.lbResourcesList.MultiSelect := False;
4797 AddSoundForm.SetResource := vleObjectProperty.Cells[1, i];
4799 if (AddSoundForm.ShowModal() = mrOk) then
4800 begin
4801 vleObjectProperty.Cells[1, i] := AddSoundForm.ResourceName;
4802 bApplyProperty.Click();
4803 end;
4804 Exit;
4805 end;
4806 vleObjectProperty.FindRow(MsgPropTrPushAngle, i);
4807 if i <= 0 then
4808 vleObjectProperty.FindRow(MsgPropTrMessageText, i);
4809 if i > 0 then
4810 begin
4811 vleObjectProperty.Row := i;
4812 vleObjectProperty.SetFocus();
4813 Exit;
4814 end;
4815 end;
4816 end;
4817 end;
4819 procedure TMainForm.aOptimizeExecute(Sender: TObject);
4820 begin
4821 RemoveSelectFromObjects();
4822 MapOptimizationForm.ShowModal();
4823 end;
4825 procedure TMainForm.aCheckMapExecute(Sender: TObject);
4826 begin
4827 MapCheckForm.ShowModal();
4828 end;
4830 procedure TMainForm.bbAddTextureClick(Sender: TObject);
4831 begin
4832 AddTextureForm.lbResourcesList.MultiSelect := True;
4833 AddTextureForm.ShowModal();
4834 end;
4836 procedure TMainForm.lbTextureListClick(Sender: TObject);
4837 var
4838 TextureID: DWORD;
4839 TextureWidth, TextureHeight: Word;
4840 begin
4841 TextureID := 0;
4842 TextureWidth := 0;
4843 TextureHeight := 0;
4844 if (lbTextureList.ItemIndex <> -1) and
4845 (not IsSpecialTextureSel()) then
4846 begin
4847 if g_GetTexture(SelectedTexture(), TextureID) then
4848 begin
4849 g_GetTextureSizeByID(TextureID, TextureWidth, TextureHeight);
4851 lTextureWidth.Caption := IntToStr(TextureWidth);
4852 lTextureHeight.Caption := IntToStr(TextureHeight);
4853 end else
4854 begin
4855 lTextureWidth.Caption := MsgNotAccessible;
4856 lTextureHeight.Caption := MsgNotAccessible;
4857 end;
4858 end
4859 else
4860 begin
4861 lTextureWidth.Caption := '';
4862 lTextureHeight.Caption := '';
4863 end;
4864 end;
4866 procedure TMainForm.lbTextureListDrawItem(Control: TWinControl; Index: Integer;
4867 ARect: TRect; State: TOwnerDrawState);
4868 begin
4869 with Control as TListBox do
4870 begin
4871 if LCLType.odSelected in State then
4872 begin
4873 Canvas.Brush.Color := clHighlight;
4874 Canvas.Font.Color := clHighlightText;
4875 end else
4876 if (Items <> nil) and (Index >= 0) then
4877 if slInvalidTextures.IndexOf(Items[Index]) > -1 then
4878 begin
4879 Canvas.Brush.Color := clRed;
4880 Canvas.Font.Color := clWhite;
4881 end;
4882 Canvas.FillRect(ARect);
4883 Canvas.TextRect(ARect, ARect.Left, ARect.Top, Items[Index]);
4884 end;
4885 end;
4887 procedure TMainForm.miMacMinimizeClick(Sender: TObject);
4888 begin
4889 self.WindowState := wsMinimized;
4890 self.FormWindowStateChange(Sender);
4891 end;
4893 procedure TMainForm.miMacZoomClick(Sender: TObject);
4894 begin
4895 if self.WindowState = wsMaximized then
4896 self.WindowState := wsNormal
4897 else
4898 self.WindowState := wsMaximized;
4899 self.FormWindowStateChange(Sender);
4900 end;
4902 procedure TMainForm.miReopenMapClick(Sender: TObject);
4903 var
4904 FileName, Resource: String;
4905 begin
4906 if OpenedMap = '' then
4907 Exit;
4909 if Application.MessageBox(PChar(MsgMsgReopenMapPrompt),
4910 PChar(MsgMenuFileReopen), MB_ICONQUESTION or MB_YESNO) <> idYes then
4911 Exit;
4913 g_ProcessResourceStr(OpenedMap, @FileName, nil, @Resource);
4914 OpenMap(FileName, Resource);
4915 end;
4917 procedure TMainForm.vleObjectPropertyGetPickList(Sender: TObject;
4918 const KeyName: String; Values: TStrings);
4919 begin
4920 if vleObjectProperty.ItemProps[KeyName].EditStyle = esPickList then
4921 begin
4922 if KeyName = MsgPropDirection then
4923 begin
4924 Values.Add(DirNames[D_LEFT]);
4925 Values.Add(DirNames[D_RIGHT]);
4926 end
4927 else if KeyName = MsgPropTrTeleportDir then
4928 begin
4929 Values.Add(DirNamesAdv[0]);
4930 Values.Add(DirNamesAdv[1]);
4931 Values.Add(DirNamesAdv[2]);
4932 Values.Add(DirNamesAdv[3]);
4933 end
4934 else if KeyName = MsgPropTrMusicAct then
4935 begin
4936 Values.Add(MsgPropTrMusicOn);
4937 Values.Add(MsgPropTrMusicOff);
4938 end
4939 else if KeyName = MsgPropTrMonsterBehaviour then
4940 begin
4941 Values.Add(MsgPropTrMonsterBehaviour0);
4942 Values.Add(MsgPropTrMonsterBehaviour1);
4943 Values.Add(MsgPropTrMonsterBehaviour2);
4944 Values.Add(MsgPropTrMonsterBehaviour3);
4945 Values.Add(MsgPropTrMonsterBehaviour4);
4946 Values.Add(MsgPropTrMonsterBehaviour5);
4947 end
4948 else if KeyName = MsgPropTrScoreAct then
4949 begin
4950 Values.Add(MsgPropTrScoreAct0);
4951 Values.Add(MsgPropTrScoreAct1);
4952 Values.Add(MsgPropTrScoreAct2);
4953 Values.Add(MsgPropTrScoreAct3);
4954 end
4955 else if KeyName = MsgPropTrScoreTeam then
4956 begin
4957 Values.Add(MsgPropTrScoreTeam0);
4958 Values.Add(MsgPropTrScoreTeam1);
4959 Values.Add(MsgPropTrScoreTeam2);
4960 Values.Add(MsgPropTrScoreTeam3);
4961 end
4962 else if KeyName = MsgPropTrMessageKind then
4963 begin
4964 Values.Add(MsgPropTrMessageKind0);
4965 Values.Add(MsgPropTrMessageKind1);
4966 end
4967 else if KeyName = MsgPropTrMessageTo then
4968 begin
4969 Values.Add(MsgPropTrMessageTo0);
4970 Values.Add(MsgPropTrMessageTo1);
4971 Values.Add(MsgPropTrMessageTo2);
4972 Values.Add(MsgPropTrMessageTo3);
4973 Values.Add(MsgPropTrMessageTo4);
4974 Values.Add(MsgPropTrMessageTo5);
4975 end
4976 else if KeyName = MsgPropTrShotTo then
4977 begin
4978 Values.Add(MsgPropTrShotTo0);
4979 Values.Add(MsgPropTrShotTo1);
4980 Values.Add(MsgPropTrShotTo2);
4981 Values.Add(MsgPropTrShotTo3);
4982 Values.Add(MsgPropTrShotTo4);
4983 Values.Add(MsgPropTrShotTo5);
4984 Values.Add(MsgPropTrShotTo6);
4985 end
4986 else if KeyName = MsgPropTrShotAim then
4987 begin
4988 Values.Add(MsgPropTrShotAim0);
4989 Values.Add(MsgPropTrShotAim1);
4990 Values.Add(MsgPropTrShotAim2);
4991 Values.Add(MsgPropTrShotAim3);
4992 end
4993 else if KeyName = MsgPropTrDamageKind then
4994 begin
4995 Values.Add(MsgPropTrDamageKind0);
4996 Values.Add(MsgPropTrDamageKind3);
4997 Values.Add(MsgPropTrDamageKind4);
4998 Values.Add(MsgPropTrDamageKind5);
4999 Values.Add(MsgPropTrDamageKind6);
5000 Values.Add(MsgPropTrDamageKind7);
5001 Values.Add(MsgPropTrDamageKind8);
5002 end
5003 else if (KeyName = MsgPropPanelBlend) or
5004 (KeyName = MsgPropDmOnly) or
5005 (KeyName = MsgPropItemFalls) or
5006 (KeyName = MsgPropTrEnabled) or
5007 (KeyName = MsgPropTrD2d) or
5008 (KeyName = MsgPropTrSilent) or
5009 (KeyName = MsgPropTrTeleportSilent) or
5010 (KeyName = MsgPropTrExRandom) or
5011 (KeyName = MsgPropTrTextureOnce) or
5012 (KeyName = MsgPropTrTextureAnimOnce) or
5013 (KeyName = MsgPropTrSoundLocal) or
5014 (KeyName = MsgPropTrSoundSwitch) or
5015 (KeyName = MsgPropTrMonsterActive) or
5016 (KeyName = MsgPropTrPushReset) or
5017 (KeyName = MsgPropTrScoreCon) or
5018 (KeyName = MsgPropTrScoreMsg) or
5019 (KeyName = MsgPropTrHealthMax) or
5020 (KeyName = MsgPropTrShotSound) or
5021 (KeyName = MsgPropTrEffectCenter) then
5022 begin
5023 Values.Add(BoolNames[True]);
5024 Values.Add(BoolNames[False]);
5025 end;
5026 end;
5027 end;
5029 procedure TMainForm.bApplyPropertyClick(Sender: TObject);
5030 var
5031 _id, a, r, c: Integer;
5032 s: String;
5033 res: Boolean;
5034 NoTextureID: DWORD;
5035 NW, NH: Word;
5036 begin
5037 NoTextureID := 0;
5038 NW := 0;
5039 NH := 0;
5041 if SelectedObjectCount() <> 1 then
5042 Exit;
5043 if not SelectedObjects[GetFirstSelected()].Live then
5044 Exit;
5046 try
5047 if not CheckProperty() then
5048 Exit;
5049 except
5050 Exit;
5051 end;
5053 _id := GetFirstSelected();
5055 r := vleObjectProperty.Row;
5056 c := vleObjectProperty.Col;
5058 case SelectedObjects[_id].ObjectType of
5059 OBJECT_PANEL:
5060 begin
5061 with gPanels[SelectedObjects[_id].ID] do
5062 begin
5063 X := StrToInt(Trim(vleObjectProperty.Values[MsgPropX]));
5064 Y := StrToInt(Trim(vleObjectProperty.Values[MsgPropY]));
5065 Width := StrToInt(Trim(vleObjectProperty.Values[MsgPropWidth]));
5066 Height := StrToInt(Trim(vleObjectProperty.Values[MsgPropHeight]));
5068 PanelType := GetPanelType(vleObjectProperty.Values[MsgPropPanelType]);
5070 // Сброс ссылки на триггеры смены текстуры:
5071 if not WordBool(PanelType and (PANEL_WALL or PANEL_FORE or PANEL_BACK)) then
5072 if gTriggers <> nil then
5073 for a := 0 to High(gTriggers) do
5074 begin
5075 if (gTriggers[a].TriggerType <> 0) and
5076 (gTriggers[a].TexturePanel = Integer(SelectedObjects[_id].ID)) then
5077 gTriggers[a].TexturePanel := -1;
5078 if (gTriggers[a].TriggerType = TRIGGER_SHOT) and
5079 (gTriggers[a].Data.ShotPanelID = Integer(SelectedObjects[_id].ID)) then
5080 gTriggers[a].Data.ShotPanelID := -1;
5081 end;
5083 // Сброс ссылки на триггеры лифта:
5084 if not WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
5085 if gTriggers <> nil then
5086 for a := 0 to High(gTriggers) do
5087 if (gTriggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
5088 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
5089 gTriggers[a].Data.PanelID := -1;
5091 // Сброс ссылки на триггеры двери:
5092 if not WordBool(PanelType and (PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
5093 if gTriggers <> nil then
5094 for a := 0 to High(gTriggers) do
5095 if (gTriggers[a].TriggerType in [TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5096 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP]) and
5097 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
5098 gTriggers[a].Data.PanelID := -1;
5100 if IsTexturedPanel(PanelType) then
5101 begin // Может быть текстура
5102 if TextureName <> '' then
5103 begin // Была текстура
5104 Alpha := StrToInt(Trim(vleObjectProperty.Values[MsgPropPanelAlpha]));
5105 Blending := NameToBool(vleObjectProperty.Values[MsgPropPanelBlend]);
5106 end
5107 else // Не было
5108 begin
5109 Alpha := 0;
5110 Blending := False;
5111 end;
5113 // Новая текстура:
5114 TextureName := vleObjectProperty.Values[MsgPropPanelTex];
5116 if TextureName <> '' then
5117 begin // Есть текстура
5118 // Обычная текстура:
5119 if not IsSpecialTexture(TextureName) then
5120 begin
5121 g_GetTextureSizeByName(TextureName,
5122 TextureWidth, TextureHeight);
5124 // Проверка кратности размеров панели:
5125 res := True;
5126 if TextureWidth <> 0 then
5127 if gPanels[SelectedObjects[_id].ID].Width mod TextureWidth <> 0 then
5128 begin
5129 ErrorMessageBox(Format(MsgMsgWrongTexwidth,
5130 [TextureWidth]));
5131 Res := False;
5132 end;
5133 if Res and (TextureHeight <> 0) then
5134 if gPanels[SelectedObjects[_id].ID].Height mod TextureHeight <> 0 then
5135 begin
5136 ErrorMessageBox(Format(MsgMsgWrongTexheight,
5137 [TextureHeight]));
5138 Res := False;
5139 end;
5141 if Res then
5142 begin
5143 if not g_GetTexture(TextureName, TextureID) then
5144 // Не удалось загрузить текстуру, рисуем NOTEXTURE
5145 if g_GetTexture('NOTEXTURE', NoTextureID) then
5146 begin
5147 TextureID := TEXTURE_SPECIAL_NOTEXTURE;
5148 g_GetTextureSizeByID(NoTextureID, NW, NH);
5149 TextureWidth := NW;
5150 TextureHeight := NH;
5151 end else
5152 begin
5153 TextureID := TEXTURE_SPECIAL_NONE;
5154 TextureWidth := 1;
5155 TextureHeight := 1;
5156 end;
5157 end
5158 else
5159 begin
5160 TextureName := '';
5161 TextureWidth := 1;
5162 TextureHeight := 1;
5163 TextureID := TEXTURE_SPECIAL_NONE;
5164 end;
5165 end
5166 else // Спец.текстура
5167 begin
5168 TextureHeight := 1;
5169 TextureWidth := 1;
5170 TextureID := SpecialTextureID(TextureName);
5171 end;
5172 end
5173 else // Нет текстуры
5174 begin
5175 TextureWidth := 1;
5176 TextureHeight := 1;
5177 TextureID := TEXTURE_SPECIAL_NONE;
5178 end;
5179 end
5180 else // Не может быть текстуры
5181 begin
5182 Alpha := 0;
5183 Blending := False;
5184 TextureName := '';
5185 TextureWidth := 1;
5186 TextureHeight := 1;
5187 TextureID := TEXTURE_SPECIAL_NONE;
5188 end;
5189 end;
5190 end;
5192 OBJECT_ITEM:
5193 begin
5194 with gItems[SelectedObjects[_id].ID] do
5195 begin
5196 X := StrToInt(Trim(vleObjectProperty.Values[MsgPropX]));
5197 Y := StrToInt(Trim(vleObjectProperty.Values[MsgPropY]));
5198 OnlyDM := NameToBool(vleObjectProperty.Values[MsgPropDmOnly]);
5199 Fall := NameToBool(vleObjectProperty.Values[MsgPropItemFalls]);
5200 end;
5201 end;
5203 OBJECT_MONSTER:
5204 begin
5205 with gMonsters[SelectedObjects[_id].ID] do
5206 begin
5207 X := StrToInt(Trim(vleObjectProperty.Values[MsgPropX]));
5208 Y := StrToInt(Trim(vleObjectProperty.Values[MsgPropY]));
5209 Direction := NameToDir(vleObjectProperty.Values[MsgPropDirection]);
5210 end;
5211 end;
5213 OBJECT_AREA:
5214 begin
5215 with gAreas[SelectedObjects[_id].ID] do
5216 begin
5217 X := StrToInt(Trim(vleObjectProperty.Values[MsgPropX]));
5218 Y := StrToInt(Trim(vleObjectProperty.Values[MsgPropY]));
5219 Direction := NameToDir(vleObjectProperty.Values[MsgPropDirection]);
5220 end;
5221 end;
5223 OBJECT_TRIGGER:
5224 begin
5225 with gTriggers[SelectedObjects[_id].ID] do
5226 begin
5227 X := StrToInt(Trim(vleObjectProperty.Values[MsgPropX]));
5228 Y := StrToInt(Trim(vleObjectProperty.Values[MsgPropY]));
5229 Width := StrToInt(Trim(vleObjectProperty.Values[MsgPropWidth]));
5230 Height := StrToInt(Trim(vleObjectProperty.Values[MsgPropHeight]));
5231 Enabled := NameToBool(vleObjectProperty.Values[MsgPropTrEnabled]);
5232 ActivateType := StrToActivate(vleObjectProperty.Values[MsgPropTrActivation]);
5233 Key := StrToKey(vleObjectProperty.Values[MsgPropTrKeys]);
5235 case TriggerType of
5236 TRIGGER_EXIT:
5237 begin
5238 s := utf2win(vleObjectProperty.Values[MsgPropTrNextMap]);
5239 FillByte(Data.MapName[0], 16, 0);
5240 if s <> '' then
5241 Move(s[1], Data.MapName[0], Min(Length(s), 16));
5242 end;
5244 TRIGGER_TEXTURE:
5245 begin
5246 Data.ActivateOnce := NameToBool(vleObjectProperty.Values[MsgPropTrTextureOnce]);
5247 Data.AnimOnce := NameToBool(vleObjectProperty.Values[MsgPropTrTextureAnimOnce]);
5248 end;
5250 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
5251 begin
5252 Data.Wait := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrExDelay], 0), 65535);
5253 Data.Count := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrExCount], 0), 65535);
5254 if Data.Count < 1 then
5255 Data.Count := 1;
5256 if TriggerType = TRIGGER_PRESS then
5257 Data.ExtRandom := NameToBool(vleObjectProperty.Values[MsgPropTrExRandom]);
5258 end;
5260 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
5261 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP, TRIGGER_LIFTDOWN,
5262 TRIGGER_LIFT:
5263 begin
5264 Data.NoSound := NameToBool(vleObjectProperty.Values[MsgPropTrSilent]);
5265 Data.d2d_doors := NameToBool(vleObjectProperty.Values[MsgPropTrD2d]);
5266 end;
5268 TRIGGER_TELEPORT:
5269 begin
5270 Data.d2d_teleport := NameToBool(vleObjectProperty.Values[MsgPropTrD2d]);
5271 Data.silent_teleport := NameToBool(vleObjectProperty.Values[MsgPropTrTeleportSilent]);
5272 Data.TlpDir := NameToDirAdv(vleObjectProperty.Values[MsgPropTrTeleportDir]);
5273 end;
5275 TRIGGER_SOUND:
5276 begin
5277 s := utf2win(vleObjectProperty.Values[MsgPropTrSoundName]);
5278 FillByte(Data.SoundName[0], 64, 0);
5279 if s <> '' then
5280 Move(s[1], Data.SoundName[0], Min(Length(s), 64));
5282 Data.Volume := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSoundVolume], 0), 255);
5283 Data.Pan := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSoundPan], 0), 255);
5284 Data.PlayCount := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSoundCount], 0), 255);
5285 Data.Local := NameToBool(vleObjectProperty.Values[MsgPropTrSoundLocal]);
5286 Data.SoundSwitch := NameToBool(vleObjectProperty.Values[MsgPropTrSoundSwitch]);
5287 end;
5289 TRIGGER_SPAWNMONSTER:
5290 begin
5291 Data.MonType := StrToMonster(vleObjectProperty.Values[MsgPropTrMonsterType]);
5292 Data.MonDir := Byte(NameToDir(vleObjectProperty.Values[MsgPropDirection]));
5293 Data.MonHealth := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrHealth], 0), 1000000);
5294 if Data.MonHealth < 0 then
5295 Data.MonHealth := 0;
5296 Data.MonActive := NameToBool(vleObjectProperty.Values[MsgPropTrMonsterActive]);
5297 Data.MonCount := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrCount], 0), 64);
5298 if Data.MonCount < 1 then
5299 Data.MonCount := 1;
5300 Data.MonEffect := StrToEffect(vleObjectProperty.Values[MsgPropTrFxType]);
5301 Data.MonMax := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSpawnMax], 0), 65535);
5302 Data.MonDelay := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSpawnDelay], 0), 65535);
5303 Data.MonBehav := 0;
5304 if vleObjectProperty.Values[MsgPropTrMonsterBehaviour] = MsgPropTrMonsterBehaviour1 then
5305 Data.MonBehav := 1;
5306 if vleObjectProperty.Values[MsgPropTrMonsterBehaviour] = MsgPropTrMonsterBehaviour2 then
5307 Data.MonBehav := 2;
5308 if vleObjectProperty.Values[MsgPropTrMonsterBehaviour] = MsgPropTrMonsterBehaviour3 then
5309 Data.MonBehav := 3;
5310 if vleObjectProperty.Values[MsgPropTrMonsterBehaviour] = MsgPropTrMonsterBehaviour4 then
5311 Data.MonBehav := 4;
5312 if vleObjectProperty.Values[MsgPropTrMonsterBehaviour] = MsgPropTrMonsterBehaviour5 then
5313 Data.MonBehav := 5;
5314 end;
5316 TRIGGER_SPAWNITEM:
5317 begin
5318 Data.ItemType := StrToItem(vleObjectProperty.Values[MsgPropTrItemType]);
5319 Data.ItemOnlyDM := NameToBool(vleObjectProperty.Values[MsgPropDmOnly]);
5320 Data.ItemFalls := NameToBool(vleObjectProperty.Values[MsgPropItemFalls]);
5321 Data.ItemCount := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrCount], 0), 64);
5322 if Data.ItemCount < 1 then
5323 Data.ItemCount := 1;
5324 Data.ItemEffect := StrToEffect(vleObjectProperty.Values[MsgPropTrFxType]);
5325 Data.ItemMax := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSpawnMax], 0), 65535);
5326 Data.ItemDelay := Min(StrToIntDef(vleObjectProperty.Values[MsgPropTrSpawnDelay], 0), 65535);
5327 end;
5329 TRIGGER_MUSIC:
5330 begin
5331 s := utf2win(vleObjectProperty.Values[MsgPropTrMusicName]);
5332 FillByte(Data.MusicName[0], 64, 0);
5333 if s <> '' then
5334 Move(s[1], Data.MusicName[0], Min(Length(s), 64));
5336 if vleObjectProperty.Values[MsgPropTrMusicAct] = MsgPropTrMusicOn then
5337 Data.MusicAction := 1
5338 else
5339 Data.MusicAction := 0;
5340 end;
5342 TRIGGER_PUSH:
5343 begin
5344 Data.PushAngle := Min(
5345 StrToIntDef(vleObjectProperty.Values[MsgPropTrPushAngle], 0), 360);
5346 Data.PushForce := Min(
5347 StrToIntDef(vleObjectProperty.Values[MsgPropTrPushForce], 0), 255);
5348 Data.ResetVel := NameToBool(vleObjectProperty.Values[MsgPropTrPushReset]);
5349 end;
5351 TRIGGER_SCORE:
5352 begin
5353 Data.ScoreAction := 0;
5354 if vleObjectProperty.Values[MsgPropTrScoreAct] = MsgPropTrScoreAct1 then
5355 Data.ScoreAction := 1
5356 else if vleObjectProperty.Values[MsgPropTrScoreAct] = MsgPropTrScoreAct2 then
5357 Data.ScoreAction := 2
5358 else if vleObjectProperty.Values[MsgPropTrScoreAct] = MsgPropTrScoreAct3 then
5359 Data.ScoreAction := 3;
5360 Data.ScoreCount := Min(Max(
5361 StrToIntDef(vleObjectProperty.Values[MsgPropTrCount], 0), 0), 255);
5362 Data.ScoreTeam := 0;
5363 if vleObjectProperty.Values[MsgPropTrScoreTeam] = MsgPropTrScoreTeam1 then
5364 Data.ScoreTeam := 1
5365 else if vleObjectProperty.Values[MsgPropTrScoreTeam] = MsgPropTrScoreTeam2 then
5366 Data.ScoreTeam := 2
5367 else if vleObjectProperty.Values[MsgPropTrScoreTeam] = MsgPropTrScoreTeam3 then
5368 Data.ScoreTeam := 3;
5369 Data.ScoreCon := NameToBool(vleObjectProperty.Values[MsgPropTrScoreCon]);
5370 Data.ScoreMsg := NameToBool(vleObjectProperty.Values[MsgPropTrScoreMsg]);
5371 end;
5373 TRIGGER_MESSAGE:
5374 begin
5375 Data.MessageKind := 0;
5376 if vleObjectProperty.Values[MsgPropTrMessageKind] = MsgPropTrMessageKind1 then
5377 Data.MessageKind := 1;
5379 Data.MessageSendTo := 0;
5380 if vleObjectProperty.Values[MsgPropTrMessageTo] = MsgPropTrMessageTo1 then
5381 Data.MessageSendTo := 1
5382 else if vleObjectProperty.Values[MsgPropTrMessageTo] = MsgPropTrMessageTo2 then
5383 Data.MessageSendTo := 2
5384 else if vleObjectProperty.Values[MsgPropTrMessageTo] = MsgPropTrMessageTo3 then
5385 Data.MessageSendTo := 3
5386 else if vleObjectProperty.Values[MsgPropTrMessageTo] = MsgPropTrMessageTo4 then
5387 Data.MessageSendTo := 4
5388 else if vleObjectProperty.Values[MsgPropTrMessageTo] = MsgPropTrMessageTo5 then
5389 Data.MessageSendTo := 5;
5391 s := utf2win(vleObjectProperty.Values[MsgPropTrMessageText]);
5392 FillByte(Data.MessageText[0], 100, 0);
5393 if s <> '' then
5394 Move(s[1], Data.MessageText[0], Min(Length(s), 100));
5396 Data.MessageTime := Min(Max(
5397 StrToIntDef(vleObjectProperty.Values[MsgPropTrMessageTime], 0), 0), 65535);
5398 end;
5400 TRIGGER_DAMAGE:
5401 begin
5402 Data.DamageValue := Min(Max(
5403 StrToIntDef(vleObjectProperty.Values[MsgPropTrDamageValue], 0), 0), 65535);
5404 Data.DamageInterval := Min(Max(
5405 StrToIntDef(vleObjectProperty.Values[MsgPropTrInterval], 0), 0), 65535);
5406 s := vleObjectProperty.Values[MsgPropTrDamageKind];
5407 if s = MsgPropTrDamageKind3 then
5408 Data.DamageKind := 3
5409 else if s = MsgPropTrDamageKind4 then
5410 Data.DamageKind := 4
5411 else if s = MsgPropTrDamageKind5 then
5412 Data.DamageKind := 5
5413 else if s = MsgPropTrDamageKind6 then
5414 Data.DamageKind := 6
5415 else if s = MsgPropTrDamageKind7 then
5416 Data.DamageKind := 7
5417 else if s = MsgPropTrDamageKind8 then
5418 Data.DamageKind := 8
5419 else
5420 Data.DamageKind := 0;
5421 end;
5423 TRIGGER_HEALTH:
5424 begin
5425 Data.HealValue := Min(Max(
5426 StrToIntDef(vleObjectProperty.Values[MsgPropTrHealth], 0), 0), 65535);
5427 Data.HealInterval := Min(Max(
5428 StrToIntDef(vleObjectProperty.Values[MsgPropTrInterval], 0), 0), 65535);
5429 Data.HealMax := NameToBool(vleObjectProperty.Values[MsgPropTrHealthMax]);
5430 Data.HealSilent := NameToBool(vleObjectProperty.Values[MsgPropTrSilent]);
5431 end;
5433 TRIGGER_SHOT:
5434 begin
5435 Data.ShotType := StrToShot(vleObjectProperty.Values[MsgPropTrShotType]);
5436 Data.ShotSound := NameToBool(vleObjectProperty.Values[MsgPropTrShotSound]);
5437 Data.ShotTarget := 0;
5438 if vleObjectProperty.Values[MsgPropTrShotTo] = MsgPropTrShotTo1 then
5439 Data.ShotTarget := 1
5440 else if vleObjectProperty.Values[MsgPropTrShotTo] = MsgPropTrShotTo2 then
5441 Data.ShotTarget := 2
5442 else if vleObjectProperty.Values[MsgPropTrShotTo] = MsgPropTrShotTo3 then
5443 Data.ShotTarget := 3
5444 else if vleObjectProperty.Values[MsgPropTrShotTo] = MsgPropTrShotTo4 then
5445 Data.ShotTarget := 4
5446 else if vleObjectProperty.Values[MsgPropTrShotTo] = MsgPropTrShotTo5 then
5447 Data.ShotTarget := 5
5448 else if vleObjectProperty.Values[MsgPropTrShotTo] = MsgPropTrShotTo6 then
5449 Data.ShotTarget := 6;
5450 Data.ShotIntSight := Min(Max(
5451 StrToIntDef(vleObjectProperty.Values[MsgPropTrShotSight], 0), 0), 65535);
5452 Data.ShotAim := 0;
5453 if vleObjectProperty.Values[MsgPropTrShotAim] = MsgPropTrShotAim1 then
5454 Data.ShotAim := 1
5455 else if vleObjectProperty.Values[MsgPropTrShotAim] = MsgPropTrShotAim2 then
5456 Data.ShotAim := 2
5457 else if vleObjectProperty.Values[MsgPropTrShotAim] = MsgPropTrShotAim3 then
5458 Data.ShotAim := 3;
5459 Data.ShotAngle := Min(
5460 StrToIntDef(vleObjectProperty.Values[MsgPropTrShotAngle], 0), 360);
5461 Data.ShotWait := Min(Max(
5462 StrToIntDef(vleObjectProperty.Values[MsgPropTrExDelay], 0), 0), 65535);
5463 Data.ShotAccuracy := Min(Max(
5464 StrToIntDef(vleObjectProperty.Values[MsgPropTrShotAcc], 0), 0), 65535);
5465 Data.ShotAmmo := Min(Max(
5466 StrToIntDef(vleObjectProperty.Values[MsgPropTrShotAmmo], 0), 0), 65535);
5467 Data.ShotIntReload := Min(Max(
5468 StrToIntDef(vleObjectProperty.Values[MsgPropTrShotReload], 0), 0), 65535);
5469 end;
5471 TRIGGER_EFFECT:
5472 begin
5473 Data.FXCount := Min(Max(
5474 StrToIntDef(vleObjectProperty.Values[MsgPropTrCount], 0), 0), 255);
5475 if vleObjectProperty.Values[MsgPropTrEffectType] = MsgPropTrEffectParticle then
5476 begin
5477 Data.FXType := TRIGGER_EFFECT_PARTICLE;
5478 Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
5479 if vleObjectProperty.Values[MsgPropTrEffectSubtype] = MsgPropTrEffectSliquid then
5480 Data.FXSubType := TRIGGER_EFFECT_SLIQUID
5481 else if vleObjectProperty.Values[MsgPropTrEffectSubtype] = MsgPropTrEffectLliquid then
5482 Data.FXSubType := TRIGGER_EFFECT_LLIQUID
5483 else if vleObjectProperty.Values[MsgPropTrEffectSubtype] = MsgPropTrEffectDliquid then
5484 Data.FXSubType := TRIGGER_EFFECT_DLIQUID
5485 else if vleObjectProperty.Values[MsgPropTrEffectSubtype] = MsgPropTrEffectBlood then
5486 Data.FXSubType := TRIGGER_EFFECT_BLOOD
5487 else if vleObjectProperty.Values[MsgPropTrEffectSubtype] = MsgPropTrEffectSpark then
5488 Data.FXSubType := TRIGGER_EFFECT_SPARK
5489 else if vleObjectProperty.Values[MsgPropTrEffectSubtype] = MsgPropTrEffectBubble then
5490 Data.FXSubType := TRIGGER_EFFECT_BUBBLE;
5491 end else
5492 begin
5493 Data.FXType := TRIGGER_EFFECT_ANIMATION;
5494 Data.FXSubType := StrToEffect(vleObjectProperty.Values[MsgPropTrEffectSubtype]);
5495 end;
5496 a := Min(Max(
5497 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectColor], 0), 0), $FFFFFF);
5498 Data.FXColorR := a and $FF;
5499 Data.FXColorG := (a shr 8) and $FF;
5500 Data.FXColorB := (a shr 16) and $FF;
5501 if NameToBool(vleObjectProperty.Values[MsgPropTrEffectCenter]) then
5502 Data.FXPos := 0
5503 else
5504 Data.FXPos := 1;
5505 Data.FXWait := Min(Max(
5506 StrToIntDef(vleObjectProperty.Values[MsgPropTrExDelay], 0), 0), 65535);
5507 Data.FXVelX := Min(Max(
5508 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectVelx], 0), -128), 127);
5509 Data.FXVelY := Min(Max(
5510 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectVely], 0), -128), 127);
5511 Data.FXSpreadL := Min(Max(
5512 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectSpl], 0), 0), 255);
5513 Data.FXSpreadR := Min(Max(
5514 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectSpr], 0), 0), 255);
5515 Data.FXSpreadU := Min(Max(
5516 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectSpu], 0), 0), 255);
5517 Data.FXSpreadD := Min(Max(
5518 StrToIntDef(vleObjectProperty.Values[MsgPropTrEffectSpd], 0), 0), 255);
5519 end;
5520 end;
5521 end;
5522 end;
5523 end;
5525 FillProperty();
5527 vleObjectProperty.Row := r;
5528 vleObjectProperty.Col := c;
5529 end;
5531 procedure TMainForm.bbRemoveTextureClick(Sender: TObject);
5532 var
5533 a, i: Integer;
5534 begin
5535 i := lbTextureList.ItemIndex;
5536 if i = -1 then
5537 Exit;
5539 if Application.MessageBox(PChar(Format(MsgMsgDelTexturePrompt,
5540 [SelectedTexture()])),
5541 PChar(MsgMsgDelTexture),
5542 MB_ICONQUESTION or MB_YESNO or
5543 MB_DEFBUTTON1) <> idYes then
5544 Exit;
5546 if gPanels <> nil then
5547 for a := 0 to High(gPanels) do
5548 if (gPanels[a].PanelType <> 0) and
5549 (gPanels[a].TextureName = SelectedTexture()) then
5550 begin
5551 ErrorMessageBox(MsgMsgDelTextureCant);
5552 Exit;
5553 end;
5555 g_DeleteTexture(SelectedTexture());
5556 i := slInvalidTextures.IndexOf(lbTextureList.Items[i]);
5557 if i > -1 then
5558 slInvalidTextures.Delete(i);
5559 if lbTextureList.ItemIndex > -1 then
5560 lbTextureList.Items.Delete(lbTextureList.ItemIndex)
5561 end;
5563 procedure TMainForm.aNewMapExecute(Sender: TObject);
5564 begin
5565 if Application.MessageBox(PChar(MsgMsgClearMapPrompt), PChar(MsgMsgClearMap), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON1) = mrYes then
5566 FullClear();
5567 end;
5569 procedure TMainForm.aUndoExecute(Sender: TObject);
5570 var
5571 a: Integer;
5572 begin
5573 if UndoBuffer = nil then
5574 Exit;
5575 if UndoBuffer[High(UndoBuffer)] = nil then
5576 Exit;
5578 for a := 0 to High(UndoBuffer[High(UndoBuffer)]) do
5579 with UndoBuffer[High(UndoBuffer)][a] do
5580 begin
5581 case UndoType of
5582 UNDO_DELETE_PANEL:
5583 begin
5584 AddPanel(Panel^);
5585 Panel := nil;
5586 end;
5587 UNDO_DELETE_ITEM: AddItem(Item);
5588 UNDO_DELETE_AREA: AddArea(Area);
5589 UNDO_DELETE_MONSTER: AddMonster(Monster);
5590 UNDO_DELETE_TRIGGER: AddTrigger(Trigger);
5591 UNDO_ADD_PANEL: RemoveObject(AddID, OBJECT_PANEL);
5592 UNDO_ADD_ITEM: RemoveObject(AddID, OBJECT_ITEM);
5593 UNDO_ADD_AREA: RemoveObject(AddID, OBJECT_AREA);
5594 UNDO_ADD_MONSTER: RemoveObject(AddID, OBJECT_MONSTER);
5595 UNDO_ADD_TRIGGER: RemoveObject(AddID, OBJECT_TRIGGER);
5596 end;
5597 end;
5599 SetLength(UndoBuffer, Length(UndoBuffer)-1);
5601 RemoveSelectFromObjects();
5603 miUndo.Enabled := UndoBuffer <> nil;
5604 end;
5607 procedure TMainForm.aCopyObjectExecute(Sender: TObject);
5608 var
5609 a, b: Integer;
5610 CopyBuffer: TCopyRecArray;
5611 str: String;
5612 ok: Boolean;
5614 function CB_Compare(I1, I2: TCopyRec): Integer;
5615 begin
5616 Result := Integer(I1.ObjectType) - Integer(I2.ObjectType);
5618 if Result = 0 then // Одного типа
5619 Result := Integer(I1.ID) - Integer(I2.ID);
5620 end;
5622 procedure QuickSortCopyBuffer(L, R: Integer);
5623 var
5624 I, J: Integer;
5625 P, T: TCopyRec;
5626 begin
5627 repeat
5628 I := L;
5629 J := R;
5630 P := CopyBuffer[(L + R) shr 1];
5632 repeat
5633 while CB_Compare(CopyBuffer[I], P) < 0 do
5634 Inc(I);
5635 while CB_Compare(CopyBuffer[J], P) > 0 do
5636 Dec(J);
5638 if I <= J then
5639 begin
5640 T := CopyBuffer[I];
5641 CopyBuffer[I] := CopyBuffer[J];
5642 CopyBuffer[J] := T;
5643 Inc(I);
5644 Dec(J);
5645 end;
5646 until I > J;
5648 if L < J then
5649 QuickSortCopyBuffer(L, J);
5651 L := I;
5652 until I >= R;
5653 end;
5655 begin
5656 if SelectedObjects = nil then
5657 Exit;
5659 b := -1;
5660 CopyBuffer := nil;
5662 // Копируем объекты:
5663 for a := 0 to High(SelectedObjects) do
5664 if SelectedObjects[a].Live then
5665 with SelectedObjects[a] do
5666 begin
5667 SetLength(CopyBuffer, Length(CopyBuffer)+1);
5668 b := High(CopyBuffer);
5669 CopyBuffer[b].ID := ID;
5670 CopyBuffer[b].Panel := nil;
5672 case ObjectType of
5673 OBJECT_PANEL:
5674 begin
5675 CopyBuffer[b].ObjectType := OBJECT_PANEL;
5676 New(CopyBuffer[b].Panel);
5677 CopyBuffer[b].Panel^ := gPanels[ID];
5678 end;
5680 OBJECT_ITEM:
5681 begin
5682 CopyBuffer[b].ObjectType := OBJECT_ITEM;
5683 CopyBuffer[b].Item := gItems[ID];
5684 end;
5686 OBJECT_MONSTER:
5687 begin
5688 CopyBuffer[b].ObjectType := OBJECT_MONSTER;
5689 CopyBuffer[b].Monster := gMonsters[ID];
5690 end;
5692 OBJECT_AREA:
5693 begin
5694 CopyBuffer[b].ObjectType := OBJECT_AREA;
5695 CopyBuffer[b].Area := gAreas[ID];
5696 end;
5698 OBJECT_TRIGGER:
5699 begin
5700 CopyBuffer[b].ObjectType := OBJECT_TRIGGER;
5701 CopyBuffer[b].Trigger := gTriggers[ID];
5702 end;
5703 end;
5704 end;
5706 // Сортировка по ID:
5707 if CopyBuffer <> nil then
5708 begin
5709 QuickSortCopyBuffer(0, b);
5710 end;
5712 // Постановка ссылок триггеров:
5713 for a := 0 to Length(CopyBuffer)-1 do
5714 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5715 begin
5716 case CopyBuffer[a].Trigger.TriggerType of
5717 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5718 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5719 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5720 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5721 begin
5722 ok := False;
5724 for b := 0 to Length(CopyBuffer)-1 do
5725 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5726 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.PanelID) then
5727 begin
5728 CopyBuffer[a].Trigger.Data.PanelID := b;
5729 ok := True;
5730 Break;
5731 end;
5733 // Этих панелей нет среди копируемых:
5734 if not ok then
5735 CopyBuffer[a].Trigger.Data.PanelID := -1;
5736 end;
5738 TRIGGER_PRESS, TRIGGER_ON,
5739 TRIGGER_OFF, TRIGGER_ONOFF:
5740 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5741 begin
5742 ok := False;
5744 for b := 0 to Length(CopyBuffer)-1 do
5745 if (CopyBuffer[b].ObjectType = OBJECT_MONSTER) and
5746 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.MonsterID-1) then
5747 begin
5748 CopyBuffer[a].Trigger.Data.MonsterID := b+1;
5749 ok := True;
5750 Break;
5751 end;
5753 // Этих монстров нет среди копируемых:
5754 if not ok then
5755 CopyBuffer[a].Trigger.Data.MonsterID := 0;
5756 end;
5758 TRIGGER_SHOT:
5759 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5760 begin
5761 ok := False;
5763 for b := 0 to Length(CopyBuffer)-1 do
5764 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5765 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.ShotPanelID) then
5766 begin
5767 CopyBuffer[a].Trigger.Data.ShotPanelID := b;
5768 ok := True;
5769 Break;
5770 end;
5772 // Этих панелей нет среди копируемых:
5773 if not ok then
5774 CopyBuffer[a].Trigger.Data.ShotPanelID := -1;
5775 end;
5776 end;
5778 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5779 begin
5780 ok := False;
5782 for b := 0 to Length(CopyBuffer)-1 do
5783 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5784 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.TexturePanel) then
5785 begin
5786 CopyBuffer[a].Trigger.TexturePanel := b;
5787 ok := True;
5788 Break;
5789 end;
5791 // Этих панелей нет среди копируемых:
5792 if not ok then
5793 CopyBuffer[a].Trigger.TexturePanel := -1;
5794 end;
5795 end;
5797 // В буфер обмена:
5798 str := CopyBufferToString(CopyBuffer);
5799 ClipBoard.AsText := str;
5801 for a := 0 to Length(CopyBuffer)-1 do
5802 if (CopyBuffer[a].ObjectType = OBJECT_PANEL) and
5803 (CopyBuffer[a].Panel <> nil) then
5804 Dispose(CopyBuffer[a].Panel);
5806 CopyBuffer := nil;
5807 end;
5809 procedure TMainForm.aPasteObjectExecute(Sender: TObject);
5810 var
5811 a, h: Integer;
5812 CopyBuffer: TCopyRecArray;
5813 res, rel: Boolean;
5814 swad, ssec, sres: String;
5815 NoTextureID: DWORD;
5816 pmin: TPoint;
5817 xadj, yadj: LongInt;
5818 begin
5819 CopyBuffer := nil;
5820 NoTextureID := 0;
5822 pmin.X := High(pmin.X);
5823 pmin.Y := High(pmin.Y);
5825 StringToCopyBuffer(ClipBoard.AsText, CopyBuffer, pmin);
5826 if CopyBuffer = nil then
5827 Exit;
5829 rel := not(ssShift in GetKeyShiftState());
5830 h := High(CopyBuffer);
5831 RemoveSelectFromObjects();
5833 if g_CollidePoint(
5834 pmin.X, pmin.Y, -MapOffset.X-32, -MapOffset.Y-32, RenderPanel.Width, RenderPanel.Height) then
5835 begin
5836 xadj := DotStep;
5837 yadj := DotStep;
5838 end
5839 else
5840 begin
5841 xadj := Floor((-pmin.X - MapOffset.X + 32) / DotStep) * DotStep;
5842 yadj := Floor((-pmin.Y - MapOffset.Y + 32) / DotStep) * DotStep;
5843 end;
5845 for a := 0 to h do
5846 with CopyBuffer[a] do
5847 begin
5848 case ObjectType of
5849 OBJECT_PANEL:
5850 if Panel <> nil then
5851 begin
5852 if rel then
5853 begin
5854 Panel^.X += xadj;
5855 Panel^.Y += yadj;
5856 end;
5858 Panel^.TextureID := TEXTURE_SPECIAL_NONE;
5859 Panel^.TextureWidth := 1;
5860 Panel^.TextureHeight := 1;
5862 if (Panel^.PanelType = PANEL_LIFTUP) or
5863 (Panel^.PanelType = PANEL_LIFTDOWN) or
5864 (Panel^.PanelType = PANEL_LIFTLEFT) or
5865 (Panel^.PanelType = PANEL_LIFTRIGHT) or
5866 (Panel^.PanelType = PANEL_BLOCKMON) or
5867 (Panel^.TextureName = '') then
5868 begin // Нет или не может быть текстуры:
5869 end
5870 else // Есть текстура:
5871 begin
5872 // Обычная текстура:
5873 if not IsSpecialTexture(Panel^.TextureName) then
5874 begin
5875 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5877 if not res then
5878 begin
5879 g_ProcessResourceStr(Panel^.TextureName, swad, ssec, sres);
5880 AddTexture(swad, ssec, sres, True);
5881 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5882 end;
5884 if res then
5885 g_GetTextureSizeByName(Panel^.TextureName,
5886 Panel^.TextureWidth, Panel^.TextureHeight)
5887 else
5888 if g_GetTexture('NOTEXTURE', NoTextureID) then
5889 begin
5890 Panel^.TextureID := TEXTURE_SPECIAL_NOTEXTURE;
5891 g_GetTextureSizeByID(NoTextureID, Panel^.TextureWidth, Panel^.TextureHeight);
5892 end;
5893 end
5894 else // Спец.текстура:
5895 begin
5896 Panel^.TextureID := SpecialTextureID(Panel^.TextureName);
5897 with MainForm.lbTextureList.Items do
5898 if IndexOf(Panel^.TextureName) = -1 then
5899 Add(Panel^.TextureName);
5900 end;
5901 end;
5903 ID := AddPanel(Panel^);
5904 Dispose(Panel);
5905 Undo_Add(OBJECT_PANEL, ID, a > 0);
5906 SelectObject(OBJECT_PANEL, ID, True);
5907 end;
5909 OBJECT_ITEM:
5910 begin
5911 if rel then
5912 begin
5913 Item.X += xadj;
5914 Item.Y += yadj;
5915 end;
5917 ID := AddItem(Item);
5918 Undo_Add(OBJECT_ITEM, ID, a > 0);
5919 SelectObject(OBJECT_ITEM, ID, True);
5920 end;
5922 OBJECT_MONSTER:
5923 begin
5924 if rel then
5925 begin
5926 Monster.X += xadj;
5927 Monster.Y += yadj;
5928 end;
5930 ID := AddMonster(Monster);
5931 Undo_Add(OBJECT_MONSTER, ID, a > 0);
5932 SelectObject(OBJECT_MONSTER, ID, True);
5933 end;
5935 OBJECT_AREA:
5936 begin
5937 if rel then
5938 begin
5939 Area.X += xadj;
5940 Area.Y += yadj;
5941 end;
5943 ID := AddArea(Area);
5944 Undo_Add(OBJECT_AREA, ID, a > 0);
5945 SelectObject(OBJECT_AREA, ID, True);
5946 end;
5948 OBJECT_TRIGGER:
5949 begin
5950 if rel then
5951 with Trigger do
5952 begin
5953 X += xadj;
5954 Y += yadj;
5956 case TriggerType of
5957 TRIGGER_TELEPORT:
5958 begin
5959 Data.TargetPoint.X += xadj;
5960 Data.TargetPoint.Y += yadj;
5961 end;
5962 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
5963 begin
5964 Data.tX += xadj;
5965 Data.tY += yadj;
5966 end;
5967 TRIGGER_SPAWNMONSTER:
5968 begin
5969 Data.MonPos.X += xadj;
5970 Data.MonPos.Y += yadj;
5971 end;
5972 TRIGGER_SPAWNITEM:
5973 begin
5974 Data.ItemPos.X += xadj;
5975 Data.ItemPos.Y += yadj;
5976 end;
5977 TRIGGER_SHOT:
5978 begin
5979 Data.ShotPos.X += xadj;
5980 Data.ShotPos.Y += yadj;
5981 end;
5982 end;
5983 end;
5985 ID := AddTrigger(Trigger);
5986 Undo_Add(OBJECT_TRIGGER, ID, a > 0);
5987 SelectObject(OBJECT_TRIGGER, ID, True);
5988 end;
5989 end;
5990 end;
5992 // Переставляем ссылки триггеров:
5993 for a := 0 to High(CopyBuffer) do
5994 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5995 begin
5996 case CopyBuffer[a].Trigger.TriggerType of
5997 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5998 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5999 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6000 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
6001 gTriggers[CopyBuffer[a].ID].Data.PanelID :=
6002 CopyBuffer[CopyBuffer[a].Trigger.Data.PanelID].ID;
6004 TRIGGER_PRESS, TRIGGER_ON,
6005 TRIGGER_OFF, TRIGGER_ONOFF:
6006 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
6007 gTriggers[CopyBuffer[a].ID].Data.MonsterID :=
6008 CopyBuffer[CopyBuffer[a].Trigger.Data.MonsterID-1].ID+1;
6010 TRIGGER_SHOT:
6011 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
6012 gTriggers[CopyBuffer[a].ID].Data.ShotPanelID :=
6013 CopyBuffer[CopyBuffer[a].Trigger.Data.ShotPanelID].ID;
6014 end;
6016 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
6017 gTriggers[CopyBuffer[a].ID].TexturePanel :=
6018 CopyBuffer[CopyBuffer[a].Trigger.TexturePanel].ID;
6019 end;
6021 CopyBuffer := nil;
6023 if h = 0 then
6024 FillProperty();
6025 end;
6027 procedure TMainForm.aCutObjectExecute(Sender: TObject);
6028 begin
6029 miCopy.Click();
6030 DeleteSelectedObjects();
6031 end;
6033 procedure TMainForm.vleObjectPropertyEditButtonClick(Sender: TObject);
6034 var
6035 Key, FileName: String;
6036 b: Byte;
6037 begin
6038 Key := vleObjectProperty.Keys[vleObjectProperty.Row];
6040 if Key = MsgPropPanelType then
6041 begin
6042 with ChooseTypeForm, vleObjectProperty do
6043 begin // Выбор типа панели:
6044 Caption := MsgPropPanelType;
6045 lbTypeSelect.Items.Clear();
6047 for b := 0 to High(PANELNAMES) do
6048 begin
6049 lbTypeSelect.Items.Add(PANELNAMES[b]);
6050 if Values[Key] = PANELNAMES[b] then
6051 lbTypeSelect.ItemIndex := b;
6052 end;
6054 if ShowModal() = mrOK then
6055 begin
6056 b := lbTypeSelect.ItemIndex;
6057 Values[Key] := PANELNAMES[b];
6058 vleObjectPropertyApply(Sender);
6059 end;
6060 end
6061 end
6062 else if Key = MsgPropTrTeleportTo then
6063 SelectFlag := SELECTFLAG_TELEPORT
6064 else if Key = MsgPropTrSpawnTo then
6065 SelectFlag := SELECTFLAG_SPAWNPOINT
6066 else if (Key = MsgPropTrDoorPanel) or
6067 (Key = MsgPropTrTrapPanel) then
6068 SelectFlag := SELECTFLAG_DOOR
6069 else if Key = MsgPropTrTexturePanel then
6070 begin
6071 DrawPressRect := False;
6072 SelectFlag := SELECTFLAG_TEXTURE;
6073 end
6074 else if Key = MsgPropTrShotPanel then
6075 SelectFlag := SELECTFLAG_SHOTPANEL
6076 else if Key = MsgPropTrLiftPanel then
6077 SelectFlag := SELECTFLAG_LIFT
6078 else if key = MsgPropTrExMonster then
6079 SelectFlag := SELECTFLAG_MONSTER
6080 else if Key = MsgPropTrExArea then
6081 begin
6082 SelectFlag := SELECTFLAG_NONE;
6083 DrawPressRect := True;
6084 end
6085 else if Key = MsgPropTrNextMap then
6086 begin // Выбор следующей карты:
6087 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
6088 SelectMapForm.Caption := MsgCapSelect;
6089 SelectMapForm.GetMaps(FileName);
6091 if SelectMapForm.ShowModal() = mrOK then
6092 begin
6093 vleObjectProperty.Values[Key] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
6094 vleObjectPropertyApply(Sender);
6095 end;
6096 end
6097 else if (Key = MsgPropTrSoundName) or
6098 (Key = MsgPropTrMusicName) then
6099 begin // Выбор файла звука/музыки:
6100 AddSoundForm.OKFunction := nil;
6101 AddSoundForm.lbResourcesList.MultiSelect := False;
6102 AddSoundForm.SetResource := vleObjectProperty.Values[Key];
6104 if (AddSoundForm.ShowModal() = mrOk) then
6105 begin
6106 vleObjectProperty.Values[Key] := AddSoundForm.ResourceName;
6107 vleObjectPropertyApply(Sender);
6108 end;
6109 end
6110 else if Key = MsgPropTrActivation then
6111 with ActivationTypeForm, vleObjectProperty do
6112 begin // Выбор типов активации:
6113 cbPlayerCollide.Checked := Pos('PC', Values[Key]) > 0;
6114 cbMonsterCollide.Checked := Pos('MC', Values[Key]) > 0;
6115 cbPlayerPress.Checked := Pos('PP', Values[Key]) > 0;
6116 cbMonsterPress.Checked := Pos('MP', Values[Key]) > 0;
6117 cbShot.Checked := Pos('SH', Values[Key]) > 0;
6118 cbNoMonster.Checked := Pos('NM', Values[Key]) > 0;
6120 if ShowModal() = mrOK then
6121 begin
6122 b := 0;
6123 if cbPlayerCollide.Checked then
6124 b := ACTIVATE_PLAYERCOLLIDE;
6125 if cbMonsterCollide.Checked then
6126 b := b or ACTIVATE_MONSTERCOLLIDE;
6127 if cbPlayerPress.Checked then
6128 b := b or ACTIVATE_PLAYERPRESS;
6129 if cbMonsterPress.Checked then
6130 b := b or ACTIVATE_MONSTERPRESS;
6131 if cbShot.Checked then
6132 b := b or ACTIVATE_SHOT;
6133 if cbNoMonster.Checked then
6134 b := b or ACTIVATE_NOMONSTER;
6136 Values[Key] := ActivateToStr(b);
6137 vleObjectPropertyApply(Sender);
6138 end;
6139 end
6140 else if Key = MsgPropTrKeys then
6141 with KeysForm, vleObjectProperty do
6142 begin // Выбор необходимых ключей:
6143 cbRedKey.Checked := Pos('RK', Values[Key]) > 0;
6144 cbGreenKey.Checked := Pos('GK', Values[Key]) > 0;
6145 cbBlueKey.Checked := Pos('BK', Values[Key]) > 0;
6146 cbRedTeam.Checked := Pos('RT', Values[Key]) > 0;
6147 cbBlueTeam.Checked := Pos('BT', Values[Key]) > 0;
6149 if ShowModal() = mrOK then
6150 begin
6151 b := 0;
6152 if cbRedKey.Checked then
6153 b := KEY_RED;
6154 if cbGreenKey.Checked then
6155 b := b or KEY_GREEN;
6156 if cbBlueKey.Checked then
6157 b := b or KEY_BLUE;
6158 if cbRedTeam.Checked then
6159 b := b or KEY_REDTEAM;
6160 if cbBlueTeam.Checked then
6161 b := b or KEY_BLUETEAM;
6163 Values[Key] := KeyToStr(b);
6164 vleObjectPropertyApply(Sender);
6165 end;
6166 end
6167 else if Key = MsgPropTrFxType then
6168 with ChooseTypeForm, vleObjectProperty do
6169 begin // Выбор типа эффекта:
6170 Caption := MsgCapFxType;
6171 lbTypeSelect.Items.Clear();
6173 for b := EFFECT_NONE to EFFECT_FIRE do
6174 lbTypeSelect.Items.Add(EffectToStr(b));
6176 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]);
6178 if ShowModal() = mrOK then
6179 begin
6180 b := lbTypeSelect.ItemIndex;
6181 Values[Key] := EffectToStr(b);
6182 vleObjectPropertyApply(Sender);
6183 end;
6184 end
6185 else if Key = MsgPropTrMonsterType then
6186 with ChooseTypeForm, vleObjectProperty do
6187 begin // Выбор типа монстра:
6188 Caption := MsgCapMonsterType;
6189 lbTypeSelect.Items.Clear();
6191 for b := MONSTER_DEMON to MONSTER_MAN do
6192 lbTypeSelect.Items.Add(MonsterToStr(b));
6194 lbTypeSelect.ItemIndex := StrToMonster(Values[Key]) - MONSTER_DEMON;
6196 if ShowModal() = mrOK then
6197 begin
6198 b := lbTypeSelect.ItemIndex + MONSTER_DEMON;
6199 Values[Key] := MonsterToStr(b);
6200 vleObjectPropertyApply(Sender);
6201 end;
6202 end
6203 else if Key = MsgPropTrItemType then
6204 with ChooseTypeForm, vleObjectProperty do
6205 begin // Выбор типа предмета:
6206 Caption := MsgCapItemType;
6207 lbTypeSelect.Items.Clear();
6209 for b := ITEM_MEDKIT_SMALL to ITEM_KEY_BLUE do
6210 lbTypeSelect.Items.Add(ItemToStr(b));
6211 lbTypeSelect.Items.Add(ItemToStr(ITEM_BOTTLE));
6212 lbTypeSelect.Items.Add(ItemToStr(ITEM_HELMET));
6213 lbTypeSelect.Items.Add(ItemToStr(ITEM_JETPACK));
6214 lbTypeSelect.Items.Add(ItemToStr(ITEM_INVIS));
6215 lbTypeSelect.Items.Add(ItemToStr(ITEM_WEAPON_FLAMETHROWER));
6216 lbTypeSelect.Items.Add(ItemToStr(ITEM_AMMO_FUELCAN));
6218 b := StrToItem(Values[Key]);
6219 if b >= ITEM_BOTTLE then
6220 b := b - 2;
6221 lbTypeSelect.ItemIndex := b - ITEM_MEDKIT_SMALL;
6223 if ShowModal() = mrOK then
6224 begin
6225 b := lbTypeSelect.ItemIndex + ITEM_MEDKIT_SMALL;
6226 if b >= ITEM_WEAPON_KASTET then
6227 b := b + 2;
6228 Values[Key] := ItemToStr(b);
6229 vleObjectPropertyApply(Sender);
6230 end;
6231 end
6232 else if Key = MsgPropTrShotType then
6233 with ChooseTypeForm, vleObjectProperty do
6234 begin // Выбор типа предмета:
6235 Caption := MsgPropTrShotType;
6236 lbTypeSelect.Items.Clear();
6238 for b := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
6239 lbTypeSelect.Items.Add(ShotToStr(b));
6241 lbTypeSelect.ItemIndex := StrToShot(Values[Key]);
6243 if ShowModal() = mrOK then
6244 begin
6245 b := lbTypeSelect.ItemIndex;
6246 Values[Key] := ShotToStr(b);
6247 vleObjectPropertyApply(Sender);
6248 end;
6249 end
6250 else if Key = MsgPropTrEffectType then
6251 with ChooseTypeForm, vleObjectProperty do
6252 begin // Выбор типа эффекта:
6253 Caption := MsgCapFxType;
6254 lbTypeSelect.Items.Clear();
6256 lbTypeSelect.Items.Add(MsgPropTrEffectParticle);
6257 lbTypeSelect.Items.Add(MsgPropTrEffectAnimation);
6258 if Values[Key] = MsgPropTrEffectAnimation then
6259 lbTypeSelect.ItemIndex := 1
6260 else
6261 lbTypeSelect.ItemIndex := 0;
6263 if ShowModal() = mrOK then
6264 begin
6265 b := lbTypeSelect.ItemIndex;
6266 if b = 0 then
6267 Values[Key] := MsgPropTrEffectParticle
6268 else
6269 Values[Key] := MsgPropTrEffectAnimation;
6270 vleObjectPropertyApply(Sender);
6271 end;
6272 end
6273 else if Key = MsgPropTrEffectSubtype then
6274 with ChooseTypeForm, vleObjectProperty do
6275 begin // Выбор подтипа эффекта:
6276 Caption := MsgCapFxType;
6277 lbTypeSelect.Items.Clear();
6279 if Values[MsgPropTrEffectType] = MsgPropTrEffectAnimation then
6280 begin
6281 for b := EFFECT_TELEPORT to EFFECT_FIRE do
6282 lbTypeSelect.Items.Add(EffectToStr(b));
6284 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]) - 1;
6285 end else
6286 begin
6287 lbTypeSelect.Items.Add(MsgPropTrEffectSliquid);
6288 lbTypeSelect.Items.Add(MsgPropTrEffectLliquid);
6289 lbTypeSelect.Items.Add(MsgPropTrEffectDliquid);
6290 lbTypeSelect.Items.Add(MsgPropTrEffectBlood);
6291 lbTypeSelect.Items.Add(MsgPropTrEffectSpark);
6292 lbTypeSelect.Items.Add(MsgPropTrEffectBubble);
6293 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SLIQUID;
6294 if Values[Key] = MsgPropTrEffectLliquid then
6295 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_LLIQUID;
6296 if Values[Key] = MsgPropTrEffectDliquid then
6297 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_DLIQUID;
6298 if Values[Key] = MsgPropTrEffectBlood then
6299 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BLOOD;
6300 if Values[Key] = MsgPropTrEffectSpark then
6301 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SPARK;
6302 if Values[Key] = MsgPropTrEffectBubble then
6303 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BUBBLE;
6304 end;
6306 if ShowModal() = mrOK then
6307 begin
6308 b := lbTypeSelect.ItemIndex;
6310 if Values[MsgPropTrEffectType] = MsgPropTrEffectAnimation then
6311 Values[Key] := EffectToStr(b + 1)
6312 else begin
6313 Values[Key] := MsgPropTrEffectSliquid;
6314 if b = TRIGGER_EFFECT_LLIQUID then
6315 Values[Key] := MsgPropTrEffectLliquid;
6316 if b = TRIGGER_EFFECT_DLIQUID then
6317 Values[Key] := MsgPropTrEffectDliquid;
6318 if b = TRIGGER_EFFECT_BLOOD then
6319 Values[Key] := MsgPropTrEffectBlood;
6320 if b = TRIGGER_EFFECT_SPARK then
6321 Values[Key] := MsgPropTrEffectSpark;
6322 if b = TRIGGER_EFFECT_BUBBLE then
6323 Values[Key] := MsgPropTrEffectBubble;
6324 end;
6326 vleObjectPropertyApply(Sender);
6327 end;
6328 end
6329 else if Key = MsgPropTrEffectColor then
6330 with vleObjectProperty do
6331 begin // Выбор цвета эффекта:
6332 ColorDialog.Color := StrToIntDef(Values[Key], 0);
6333 if ColorDialog.Execute then
6334 begin
6335 Values[Key] := IntToStr(ColorDialog.Color);
6336 vleObjectPropertyApply(Sender);
6337 end;
6338 end
6339 else if Key = MsgPropPanelTex then
6340 begin // Смена текстуры:
6341 vleObjectProperty.Values[Key] := SelectedTexture();
6342 vleObjectPropertyApply(Sender);
6343 end;
6344 end;
6346 procedure TMainForm.vleObjectPropertyApply(Sender: TObject);
6347 begin
6348 // hack to prevent empty ID in list
6349 RenderPanel.SetFocus();
6350 bApplyProperty.Click();
6351 vleObjectProperty.SetFocus();
6352 end;
6354 procedure TMainForm.aSaveMapExecute(Sender: TObject);
6355 var
6356 FileName, Section, Res: String;
6357 begin
6358 if OpenedMap = '' then
6359 begin
6360 aSaveMapAsExecute(nil);
6361 Exit;
6362 end;
6364 g_ProcessResourceStr(OpenedMap, FileName, Section, Res);
6366 SaveMap(FileName+':\'+Res, '');
6367 end;
6369 procedure TMainForm.aOpenMapExecute(Sender: TObject);
6370 begin
6371 OpenDialog.Filter := MsgFileFilterAll;
6373 if OpenDialog.Execute() then
6374 begin
6375 OpenMapFile(OpenDialog.FileName);
6376 OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
6377 end;
6378 end;
6380 procedure TMainForm.OpenMapFile(FileName: String);
6381 begin
6382 if (Pos('.ini', LowerCase(ExtractFileName(FileName))) > 0) then
6383 begin // INI карты:
6384 FullClear();
6386 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
6387 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
6388 pLoadProgress.Show();
6390 OpenedMap := '';
6391 OpenedWAD := '';
6393 LoadMapOld(FileName);
6395 MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(FileName)]);
6397 pLoadProgress.Hide();
6398 MainForm.FormResize(Self);
6399 end
6400 else // Карты из WAD:
6401 begin
6402 OpenMap(FileName, '');
6403 end;
6404 end;
6406 procedure TMainForm.FormActivate(Sender: TObject);
6407 begin
6408 MainForm.ActiveControl := RenderPanel;
6409 end;
6411 procedure TMainForm.aDeleteMap(Sender: TObject);
6412 var
6413 WAD: TWADEditor_1;
6414 MapList: SArray;
6415 MapName: Char16;
6416 a: Integer;
6417 str: String;
6418 begin
6419 OpenDialog.Filter := MsgFileFilterWad;
6421 if not OpenDialog.Execute() then
6422 Exit;
6424 WAD := TWADEditor_1.Create();
6426 if not WAD.ReadFile(OpenDialog.FileName) then
6427 begin
6428 WAD.Free();
6429 Exit;
6430 end;
6432 WAD.CreateImage();
6434 MapList := WAD.GetResourcesList('');
6436 SelectMapForm.Caption := MsgCapRemove;
6437 SelectMapForm.lbMapList.Items.Clear();
6439 if MapList <> nil then
6440 for a := 0 to High(MapList) do
6441 SelectMapForm.lbMapList.Items.Add(win2utf(MapList[a]));
6443 if (SelectMapForm.ShowModal() = mrOK) then
6444 begin
6445 str := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
6446 MapName := '';
6447 Move(str[1], MapName[0], Min(16, Length(str)));
6449 if Application.MessageBox(PChar(Format(MsgMsgDeleteMapPrompt, [MapName, OpenDialog.FileName])), PChar(MsgMsgDeleteMap), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2) <> mrYes then
6450 Exit;
6452 WAD.RemoveResource('', utf2win(MapName));
6454 Application.MessageBox(
6455 PChar(Format(MsgMsgMapDeletedPrompt, [MapName])),
6456 PChar(MsgMsgMapDeleted),
6457 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1
6458 );
6460 WAD.SaveTo(OpenDialog.FileName);
6462 // Удалили текущую карту - сохранять по старому ее нельзя:
6463 if OpenedMap = (OpenDialog.FileName+':\'+MapName) then
6464 begin
6465 OpenedMap := '';
6466 OpenedWAD := '';
6467 MainForm.Caption := FormCaption;
6468 end;
6469 end;
6471 WAD.Free();
6472 end;
6474 procedure TMainForm.vleObjectPropertyKeyDown(Sender: TObject;
6475 var Key: Word; Shift: TShiftState);
6476 begin
6477 if Key = VK_RETURN then
6478 vleObjectPropertyApply(Sender);
6479 end;
6481 procedure MovePanel(var ID: DWORD; MoveType: Byte);
6482 var
6483 _id, a: Integer;
6484 tmp: TPanel;
6485 begin
6486 if (ID = 0) and (MoveType = 0) then
6487 Exit;
6488 if (ID = DWORD(High(gPanels))) and (MoveType <> 0) then
6489 Exit;
6490 if (ID > DWORD(High(gPanels))) then
6491 Exit;
6493 _id := Integer(ID);
6495 if MoveType = 0 then // to Back
6496 begin
6497 if gTriggers <> nil then
6498 for a := 0 to High(gTriggers) do
6499 with gTriggers[a] do
6500 begin
6501 if TriggerType = TRIGGER_NONE then
6502 Continue;
6504 if TexturePanel = _id then
6505 TexturePanel := 0
6506 else
6507 if (TexturePanel >= 0) and (TexturePanel < _id) then
6508 Inc(TexturePanel);
6510 case TriggerType of
6511 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6512 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6513 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6514 if Data.PanelID = _id then
6515 Data.PanelID := 0
6516 else
6517 if (Data.PanelID >= 0) and (Data.PanelID < _id) then
6518 Inc(Data.PanelID);
6520 TRIGGER_SHOT:
6521 if Data.ShotPanelID = _id then
6522 Data.ShotPanelID := 0
6523 else
6524 if (Data.ShotPanelID >= 0) and (Data.ShotPanelID < _id) then
6525 Inc(Data.ShotPanelID);
6526 end;
6527 end;
6529 tmp := gPanels[_id];
6531 for a := _id downto 1 do
6532 gPanels[a] := gPanels[a-1];
6534 gPanels[0] := tmp;
6536 ID := 0;
6537 end
6538 else // to Front
6539 begin
6540 if gTriggers <> nil then
6541 for a := 0 to High(gTriggers) do
6542 with gTriggers[a] do
6543 begin
6544 if TriggerType = TRIGGER_NONE then
6545 Continue;
6547 if TexturePanel = _id then
6548 TexturePanel := High(gPanels)
6549 else
6550 if TexturePanel > _id then
6551 Dec(TexturePanel);
6553 case TriggerType of
6554 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6555 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6556 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6557 if Data.PanelID = _id then
6558 Data.PanelID := High(gPanels)
6559 else
6560 if Data.PanelID > _id then
6561 Dec(Data.PanelID);
6563 TRIGGER_SHOT:
6564 if Data.ShotPanelID = _id then
6565 Data.ShotPanelID := High(gPanels)
6566 else
6567 if Data.ShotPanelID > _id then
6568 Dec(Data.ShotPanelID);
6569 end;
6570 end;
6572 tmp := gPanels[_id];
6574 for a := _id to High(gPanels)-1 do
6575 gPanels[a] := gPanels[a+1];
6577 gPanels[High(gPanels)] := tmp;
6579 ID := High(gPanels);
6580 end;
6581 end;
6583 procedure TMainForm.aMoveToBack(Sender: TObject);
6584 var
6585 a: Integer;
6586 begin
6587 if SelectedObjects = nil then
6588 Exit;
6590 for a := 0 to High(SelectedObjects) do
6591 with SelectedObjects[a] do
6592 if Live and (ObjectType = OBJECT_PANEL) then
6593 begin
6594 SelectedObjects[0] := SelectedObjects[a];
6595 SetLength(SelectedObjects, 1);
6596 MovePanel(ID, 0);
6597 FillProperty();
6598 Break;
6599 end;
6600 end;
6602 procedure TMainForm.aMoveToFore(Sender: TObject);
6603 var
6604 a: Integer;
6605 begin
6606 if SelectedObjects = nil then
6607 Exit;
6609 for a := 0 to High(SelectedObjects) do
6610 with SelectedObjects[a] do
6611 if Live and (ObjectType = OBJECT_PANEL) then
6612 begin
6613 SelectedObjects[0] := SelectedObjects[a];
6614 SetLength(SelectedObjects, 1);
6615 MovePanel(ID, 1);
6616 FillProperty();
6617 Break;
6618 end;
6619 end;
6621 procedure TMainForm.aSaveMapAsExecute(Sender: TObject);
6622 var i, idx: Integer; list: TStringList; fmt: String;
6623 begin
6624 list := TStringList.Create();
6626 // TODO: get loclized strings automatically from language files
6627 SaveDialog.DefaultExt := '.dfz';
6628 SaveDialog.FilterIndex := 1;
6629 SaveDialog.Filter := '';
6630 gWADEditorFactory.GetRegistredEditors(list);
6631 for i := 0 to list.Count - 1 do
6632 begin
6633 if list[i] = 'DFZIP' then
6634 SaveDialog.FilterIndex := i + 1;
6636 if i <> 0 then
6637 SaveDialog.Filter := SaveDialog.Filter + '|';
6639 if list[i] = 'DFWAD' then
6640 SaveDialog.Filter := SaveDialog.Filter + MsgFileFilterSaveDFWAD
6641 else if list[i] = 'DFZIP' then
6642 SaveDialog.Filter := SaveDialog.Filter + MsgFileFilterSaveDFZIP
6643 else
6644 SaveDialog.Filter := SaveDialog.Filter + list[i] + '|*.*';
6645 end;
6647 if SaveDialog.Execute() then
6648 begin
6649 i := SaveDialog.FilterIndex - 1;
6650 if (i >= 0) and (i < list.Count) then fmt := list[i] else fmt := '';
6652 SaveMapForm.GetMaps(SaveDialog.FileName, True, fmt);
6653 if SaveMapForm.ShowModal() = mrOK then
6654 begin
6655 SaveDialog.InitialDir := ExtractFileDir(SaveDialog.FileName);
6656 OpenedMap := SaveDialog.FileName+':\'+SaveMapForm.eMapName.Text;
6657 OpenedWAD := SaveDialog.FileName;
6659 idx := RecentFiles.IndexOf(OpenedMap);
6660 // Такая карта уже недавно открывалась:
6661 if idx >= 0 then
6662 RecentFiles.Delete(idx);
6663 RecentFiles.Insert(0, OpenedMap);
6664 RefreshRecentMenu;
6666 SaveMap(OpenedMap, fmt);
6668 gMapInfo.FileName := SaveDialog.FileName;
6669 gMapInfo.MapName := SaveMapForm.eMapName.Text;
6670 UpdateCaption(gMapInfo.Name, ExtractFileName(gMapInfo.FileName), gMapInfo.MapName);
6671 end;
6672 end;
6674 list.Free();
6675 end;
6677 procedure TMainForm.aSelectAllExecute(Sender: TObject);
6678 var
6679 a: Integer;
6680 begin
6681 RemoveSelectFromObjects();
6683 case pcObjects.ActivePageIndex+1 of
6684 OBJECT_PANEL:
6685 if gPanels <> nil then
6686 for a := 0 to High(gPanels) do
6687 if gPanels[a].PanelType <> PANEL_NONE then
6688 SelectObject(OBJECT_PANEL, a, True);
6689 OBJECT_ITEM:
6690 if gItems <> nil then
6691 for a := 0 to High(gItems) do
6692 if gItems[a].ItemType <> ITEM_NONE then
6693 SelectObject(OBJECT_ITEM, a, True);
6694 OBJECT_MONSTER:
6695 if gMonsters <> nil then
6696 for a := 0 to High(gMonsters) do
6697 if gMonsters[a].MonsterType <> MONSTER_NONE then
6698 SelectObject(OBJECT_MONSTER, a, True);
6699 OBJECT_AREA:
6700 if gAreas <> nil then
6701 for a := 0 to High(gAreas) do
6702 if gAreas[a].AreaType <> AREA_NONE then
6703 SelectObject(OBJECT_AREA, a, True);
6704 OBJECT_TRIGGER:
6705 if gTriggers <> nil then
6706 for a := 0 to High(gTriggers) do
6707 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6708 SelectObject(OBJECT_TRIGGER, a, True);
6709 end;
6711 RecountSelectedObjects();
6712 end;
6714 procedure TMainForm.tbGridOnClick(Sender: TObject);
6715 begin
6716 DotEnable := not DotEnable;
6717 (Sender as TToolButton).Down := DotEnable;
6718 end;
6720 procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean);
6721 var f: AnsiString;
6722 begin
6723 if StartMap <> '' then
6724 begin
6725 f := StartMap;
6726 StartMap := '';
6727 OpenMap(f, '');
6728 end;
6729 end;
6731 procedure TMainForm.miMapPreviewClick(Sender: TObject);
6732 begin
6733 if PreviewMode = 2 then
6734 Exit;
6736 if PreviewMode = 0 then
6737 begin
6738 Splitter2.Visible := False;
6739 Splitter1.Visible := False;
6740 StatusBar.Visible := False;
6741 PanelObjs.Visible := False;
6742 PanelProps.Visible := False;
6743 MainToolBar.Visible := False;
6744 sbHorizontal.Visible := False;
6745 sbVertical.Visible := False;
6746 end
6747 else
6748 begin
6749 StatusBar.Visible := True;
6750 PanelObjs.Visible := True;
6751 PanelProps.Visible := True;
6752 Splitter2.Visible := True;
6753 Splitter1.Visible := True;
6754 MainToolBar.Visible := True;
6755 sbHorizontal.Visible := True;
6756 sbVertical.Visible := True;
6757 end;
6759 PreviewMode := PreviewMode xor 1;
6760 (Sender as TMenuItem).Checked := PreviewMode > 0;
6762 FormResize(Self);
6763 end;
6765 procedure TMainForm.miLayer1Click(Sender: TObject);
6766 begin
6767 SwitchLayer(LAYER_BACK);
6768 end;
6770 procedure TMainForm.miLayer2Click(Sender: TObject);
6771 begin
6772 SwitchLayer(LAYER_WALLS);
6773 end;
6775 procedure TMainForm.miLayer3Click(Sender: TObject);
6776 begin
6777 SwitchLayer(LAYER_FOREGROUND);
6778 end;
6780 procedure TMainForm.miLayer4Click(Sender: TObject);
6781 begin
6782 SwitchLayer(LAYER_STEPS);
6783 end;
6785 procedure TMainForm.miLayer5Click(Sender: TObject);
6786 begin
6787 SwitchLayer(LAYER_WATER);
6788 end;
6790 procedure TMainForm.miLayer6Click(Sender: TObject);
6791 begin
6792 SwitchLayer(LAYER_ITEMS);
6793 end;
6795 procedure TMainForm.miLayer7Click(Sender: TObject);
6796 begin
6797 SwitchLayer(LAYER_MONSTERS);
6798 end;
6800 procedure TMainForm.miLayer8Click(Sender: TObject);
6801 begin
6802 SwitchLayer(LAYER_AREAS);
6803 end;
6805 procedure TMainForm.miLayer9Click(Sender: TObject);
6806 begin
6807 SwitchLayer(LAYER_TRIGGERS);
6808 end;
6810 procedure TMainForm.tbShowClick(Sender: TObject);
6811 var
6812 a: Integer;
6813 b: Boolean;
6814 begin
6815 b := True;
6816 for a := 0 to High(LayerEnabled) do
6817 b := b and LayerEnabled[a];
6819 b := not b;
6821 ShowLayer(LAYER_BACK, b);
6822 ShowLayer(LAYER_WALLS, b);
6823 ShowLayer(LAYER_FOREGROUND, b);
6824 ShowLayer(LAYER_STEPS, b);
6825 ShowLayer(LAYER_WATER, b);
6826 ShowLayer(LAYER_ITEMS, b);
6827 ShowLayer(LAYER_MONSTERS, b);
6828 ShowLayer(LAYER_AREAS, b);
6829 ShowLayer(LAYER_TRIGGERS, b);
6830 end;
6832 procedure TMainForm.miMiniMapClick(Sender: TObject);
6833 begin
6834 SwitchMap();
6835 end;
6837 procedure TMainForm.miSwitchGridClick(Sender: TObject);
6838 begin
6839 if DotStep = DotStepOne then
6840 DotStep := DotStepTwo
6841 else
6842 DotStep := DotStepOne;
6844 MousePos.X := (MousePos.X div DotStep) * DotStep;
6845 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6846 end;
6848 procedure TMainForm.miShowEdgesClick(Sender: TObject);
6849 begin
6850 ShowEdges();
6851 end;
6853 procedure TMainForm.miSnapToGridClick(Sender: TObject);
6854 begin
6855 SnapToGrid := not SnapToGrid;
6857 MousePos.X := (MousePos.X div DotStep) * DotStep;
6858 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6860 miSnapToGrid.Checked := SnapToGrid;
6861 end;
6863 procedure TMainForm.minexttabClick(Sender: TObject);
6864 begin
6865 if pcObjects.ActivePageIndex < pcObjects.PageCount-1 then
6866 pcObjects.ActivePageIndex := pcObjects.ActivePageIndex+1
6867 else
6868 pcObjects.ActivePageIndex := 0;
6869 end;
6871 procedure TMainForm.miSaveMiniMapClick(Sender: TObject);
6872 begin
6873 SaveMiniMapForm.ShowModal();
6874 end;
6876 procedure TMainForm.bClearTextureClick(Sender: TObject);
6877 begin
6878 lbTextureList.ItemIndex := -1;
6879 lTextureWidth.Caption := '';
6880 lTextureHeight.Caption := '';
6881 end;
6883 procedure TMainForm.miPackMapClick(Sender: TObject);
6884 begin
6885 PackMapForm.ShowModal();
6886 end;
6888 type SSArray = array of String;
6890 function ParseString (Str: AnsiString): SSArray;
6891 function GetStr (var Str: AnsiString): AnsiString;
6892 var a, b: Integer;
6893 begin
6894 Result := '';
6895 if Str[1] = '"' then
6896 for b := 1 to Length(Str) do
6897 if (b = Length(Str)) or (Str[b + 1] = '"') then
6898 begin
6899 Result := Copy(Str, 2, b - 1);
6900 Delete(Str, 1, b + 1);
6901 Str := Trim(Str);
6902 Exit;
6903 end;
6904 for a := 1 to Length(Str) do
6905 if (a = Length(Str)) or (Str[a + 1] = ' ') then
6906 begin
6907 Result := Copy(Str, 1, a);
6908 Delete(Str, 1, a + 1);
6909 Str := Trim(Str);
6910 Exit;
6911 end;
6912 end;
6913 begin
6914 Result := nil;
6915 Str := Trim(Str);
6916 while Str <> '' do
6917 begin
6918 SetLength(Result, Length(Result)+1);
6919 Result[High(Result)] := GetStr(Str);
6920 end;
6921 end;
6923 procedure TMainForm.miTestMapClick(Sender: TObject);
6924 var
6925 newWAD, oldWAD, tempMap, ext: String;
6926 args: SSArray;
6927 opt: LongWord;
6928 time, i: Integer;
6929 proc: TProcessUTF8;
6930 res: Boolean;
6931 begin
6932 // Ignore while map testing in progress
6933 if MapTestProcess <> nil then
6934 Exit;
6936 // Сохраняем временную карту:
6937 time := 0;
6938 repeat
6939 newWAD := Format('%s/temp%.4d', [MapsDir, time]);
6940 Inc(time);
6941 until not FileExists(newWAD);
6942 if OpenedMap <> '' then
6943 begin
6944 oldWad := g_ExtractWadName(OpenedMap);
6945 newWad := newWad + ExtractFileExt(oldWad);
6946 if CopyFile(oldWad, newWad) = false then
6947 e_WriteLog('MapTest: unable to copy [' + oldWad + '] to [' + newWad + ']', MSG_WARNING)
6948 end
6949 else
6950 begin
6951 newWad := newWad + '.wad'
6952 end;
6953 tempMap := newWAD + ':\' + TEST_MAP_NAME;
6954 SaveMap(tempMap, '');
6956 // Опции игры:
6957 opt := 32 + 64;
6958 if TestOptionsTwoPlayers then
6959 opt := opt + 1;
6960 if TestOptionsTeamDamage then
6961 opt := opt + 2;
6962 if TestOptionsAllowExit then
6963 opt := opt + 4;
6964 if TestOptionsWeaponStay then
6965 opt := opt + 8;
6966 if TestOptionsMonstersDM then
6967 opt := opt + 16;
6969 // Запускаем:
6970 proc := TProcessUTF8.Create(nil);
6971 proc.Executable := TestD2dExe;
6972 {$IFDEF DARWIN}
6973 // TODO: get real executable name from Info.plist
6974 if LowerCase(ExtractFileExt(TestD2dExe)) = '.app' then
6975 proc.Executable := TestD2dExe + DirectorySeparator + 'Contents' + DirectorySeparator + 'MacOS' + DirectorySeparator + 'Doom2DF';
6976 {$ENDIF}
6977 proc.Parameters.Add('-map');
6978 proc.Parameters.Add(tempMap);
6979 proc.Parameters.Add('-gm');
6980 proc.Parameters.Add(TestGameMode);
6981 proc.Parameters.Add('-limt');
6982 proc.Parameters.Add(TestLimTime);
6983 proc.Parameters.Add('-lims');
6984 proc.Parameters.Add(TestLimScore);
6985 proc.Parameters.Add('-opt');
6986 proc.Parameters.Add(IntToStr(opt));
6987 proc.Parameters.Add('--debug');
6988 if TestMapOnce then
6989 proc.Parameters.Add('--close');
6991 args := ParseString(TestD2DArgs);
6992 for i := 0 to High(args) do
6993 proc.Parameters.Add(args[i]);
6995 res := True;
6996 try
6997 proc.Execute();
6998 except
6999 res := False;
7000 end;
7001 if res then
7002 begin
7003 tbTestMap.Enabled := False;
7004 MapTestFile := newWAD;
7005 MapTestProcess := proc;
7006 end
7007 else
7008 begin
7009 Application.MessageBox(PChar(MsgMsgExecError), 'FIXME', MB_OK or MB_ICONERROR);
7010 SysUtils.DeleteFile(newWAD);
7011 proc.Free();
7012 end;
7013 end;
7015 procedure TMainForm.sbVerticalScroll(Sender: TObject;
7016 ScrollCode: TScrollCode; var ScrollPos: Integer);
7017 begin
7018 MapOffset.Y := -sbVertical.Position;
7019 RenderPanel.Invalidate;
7020 end;
7022 procedure TMainForm.sbHorizontalScroll(Sender: TObject;
7023 ScrollCode: TScrollCode; var ScrollPos: Integer);
7024 begin
7025 MapOffset.X := -sbHorizontal.Position;
7026 RenderPanel.Invalidate;
7027 end;
7029 procedure TMainForm.miOpenWadMapClick(Sender: TObject);
7030 begin
7031 if OpenedWAD <> '' then
7032 begin
7033 OpenMap(OpenedWAD, '');
7034 end;
7035 end;
7037 procedure TMainForm.selectall1Click(Sender: TObject);
7038 var
7039 a: Integer;
7040 begin
7041 RemoveSelectFromObjects();
7043 if gPanels <> nil then
7044 for a := 0 to High(gPanels) do
7045 if gPanels[a].PanelType <> PANEL_NONE then
7046 SelectObject(OBJECT_PANEL, a, True);
7048 if gItems <> nil then
7049 for a := 0 to High(gItems) do
7050 if gItems[a].ItemType <> ITEM_NONE then
7051 SelectObject(OBJECT_ITEM, a, True);
7053 if gMonsters <> nil then
7054 for a := 0 to High(gMonsters) do
7055 if gMonsters[a].MonsterType <> MONSTER_NONE then
7056 SelectObject(OBJECT_MONSTER, a, True);
7058 if gAreas <> nil then
7059 for a := 0 to High(gAreas) do
7060 if gAreas[a].AreaType <> AREA_NONE then
7061 SelectObject(OBJECT_AREA, a, True);
7063 if gTriggers <> nil then
7064 for a := 0 to High(gTriggers) do
7065 if gTriggers[a].TriggerType <> TRIGGER_NONE then
7066 SelectObject(OBJECT_TRIGGER, a, True);
7068 RecountSelectedObjects();
7069 end;
7071 procedure TMainForm.Splitter1CanResize(Sender: TObject;
7072 var NewSize: Integer; var Accept: Boolean);
7073 begin
7074 Accept := (NewSize > 140);
7075 end;
7077 procedure TMainForm.Splitter2CanResize(Sender: TObject;
7078 var NewSize: Integer; var Accept: Boolean);
7079 begin
7080 Accept := (NewSize > 110);
7081 end;
7083 procedure TMainForm.vleObjectPropertyEnter(Sender: TObject);
7084 begin
7085 EditingProperties := True;
7086 end;
7088 procedure TMainForm.vleObjectPropertyExit(Sender: TObject);
7089 begin
7090 EditingProperties := False;
7091 end;
7093 procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
7094 begin
7095 // Объекты передвигались:
7096 if MainForm.ActiveControl = RenderPanel then
7097 begin
7098 if (Key = VK_NUMPAD4) or
7099 (Key = VK_NUMPAD6) or
7100 (Key = VK_NUMPAD8) or
7101 (Key = VK_NUMPAD5) or
7102 (Key = Ord('V')) then
7103 FillProperty();
7104 end;
7105 // Быстрое превью карты:
7106 if Key = Ord('E') then
7107 begin
7108 if PreviewMode = 2 then
7109 PreviewMode := 0;
7110 end;
7111 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
7112 end;
7114 end.