opts: add option --wads-dir
[d2df-editor.git] / src / editor / f_main.pas
blobe3c6288d2419f49a2b6d2f38fca31b5e1eec0da4
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 lLoad: TLabel;
19 // Главное меню:
20 MainMenu: TMainMenu;
21 // "Файл":
22 miMenuFile: TMenuItem;
23 miNewMap: TMenuItem;
24 miOpenMap: TMenuItem;
25 miSaveMap: TMenuItem;
26 miSaveMapAs: TMenuItem;
27 miOpenWadMap: TMenuItem;
28 miLine1: TMenuItem;
29 miReopenMap: TMenuItem;
30 miSaveMiniMap: TMenuItem;
31 miDeleteMap: TMenuItem;
32 miPackMap: TMenuItem;
33 miLine2: TMenuItem;
34 miExit: TMenuItem;
35 // "Правка":
36 miMenuEdit: TMenuItem;
37 miUndo: TMenuItem;
38 miLine3: TMenuItem;
39 miCopy: TMenuItem;
40 miCut: TMenuItem;
41 miPaste: TMenuItem;
42 miLine4: TMenuItem;
43 miSelectAll: TMenuItem;
44 miLine5: TMenuItem;
45 miToFore: TMenuItem;
46 miToBack: TMenuItem;
47 // "Инструменты":
48 miMenuTools: TMenuItem;
49 miSnapToGrid: TMenuItem;
50 miMiniMap: TMenuItem;
51 miSwitchGrid: TMenuItem;
52 miShowEdges: TMenuItem;
53 miLayers: TMenuItem;
54 miLayer1: TMenuItem;
55 miLayer2: TMenuItem;
56 miLayer3: TMenuItem;
57 miLayer4: TMenuItem;
58 miLayer5: TMenuItem;
59 miLayer6: TMenuItem;
60 miLayer7: TMenuItem;
61 miLayer8: TMenuItem;
62 miLayer9: TMenuItem;
63 // "Сервис":
64 miMenuService: TMenuItem;
65 miCheckMap: TMenuItem;
66 miOptimmization: TMenuItem;
67 miMapPreview: TMenuItem;
68 miTestMap: TMenuItem;
69 // "Настройка":
70 miMenuSettings: TMenuItem;
71 miMapOptions: TMenuItem;
72 miLine6: TMenuItem;
73 miOptions: TMenuItem;
74 miLine7: TMenuItem;
75 miMapTestSettings: TMenuItem;
76 // "Справка":
77 miMenuHelp: TMenuItem;
78 miAbout: TMenuItem;
79 // Скрытый пункт меню для Ctrl+Tab:
80 miHidden1: TMenuItem;
81 minexttab: TMenuItem;
83 // Панель инструментов:
84 MainToolBar: TToolBar;
85 pbLoad: TProgressBar;
86 pLoadProgress: TPanel;
87 RenderPanel: TOpenGLControl;
88 tbNewMap: TToolButton;
89 tbOpenMap: TToolButton;
90 tbSaveMap: TToolButton;
91 tbOpenWadMap: TToolButton;
92 tbLine1: TToolButton;
93 tbShowMap: TToolButton;
94 tbLine2: TToolButton;
95 tbShow: TToolButton;
96 tbLine3: TToolButton;
97 tbGridOn: TToolButton;
98 tbGrid: TToolButton;
99 tbLine4: TToolButton;
100 tbTestMap: TToolButton;
101 // Всплывающее меню для кнопки слоев:
102 pmShow: TPopupMenu;
103 miLayerP1: TMenuItem;
104 miLayerP2: TMenuItem;
105 miLayerP3: TMenuItem;
106 miLayerP4: TMenuItem;
107 miLayerP5: TMenuItem;
108 miLayerP6: TMenuItem;
109 miLayerP7: TMenuItem;
110 miLayerP8: TMenuItem;
111 miLayerP9: TMenuItem;
112 // Всплывающее меню для кнопки теста карты:
113 pmMapTest: TPopupMenu;
114 miMapTestPMSet: TMenuItem;
116 // Панель карты:
117 PanelMap: TPanel;
118 // Полосы прокрутки:
119 sbHorizontal: TScrollBar;
120 sbVertical: TScrollBar;
122 // Панель свойств:
123 PanelProps: TPanel;
124 // Панель применения свойств:
125 PanelPropApply: TPanel;
126 bApplyProperty: TButton;
127 MapTestTimer: TTimer;
128 // Редактор свойств объектов:
129 vleObjectProperty: TValueListEditor;
131 // Панель объектов - вкладки:
132 PanelObjs: TPanel;
133 pcObjects: TPageControl;
134 // Вкладка "Панели":
135 tsPanels: TTabSheet;
136 lbTextureList: TListBox;
137 // Панель настройки текстур:
138 PanelTextures: TPanel;
139 LabelTxW: TLabel;
140 lTextureWidth: TLabel;
141 LabelTxH: TLabel;
142 lTextureHeight: TLabel;
143 cbPreview: TCheckBox;
144 bbAddTexture: TBitBtn;
145 bbRemoveTexture: TBitBtn;
146 bClearTexture: TButton;
147 // Панель типов панелей:
148 PanelPanelType: TPanel;
149 lbPanelType: TListBox;
150 // Вкладка "Предметы":
151 tsItems: TTabSheet;
152 lbItemList: TListBox;
153 cbOnlyDM: TCheckBox;
154 cbFall: TCheckBox;
155 // Вкладка "Монстры":
156 tsMonsters: TTabSheet;
157 lbMonsterList: TListBox;
158 rbMonsterLeft: TRadioButton;
159 rbMonsterRight: TRadioButton;
160 // Вкладка "Области":
161 tsAreas: TTabSheet;
162 lbAreasList: TListBox;
163 rbAreaLeft: TRadioButton;
164 rbAreaRight: TRadioButton;
165 // Вкладка "Триггеры":
166 tsTriggers: TTabSheet;
167 lbTriggersList: TListBox;
168 clbActivationType: TCheckListBox;
169 clbKeys: TCheckListBox;
171 // Остальные панели
172 Splitter1: TSplitter;
173 Splitter2: TSplitter;
174 StatusBar: TStatusBar;
176 // Специальные объекты:
177 ImageList: TImageList;
178 ilToolbar: TImageList;
179 OpenDialog: TOpenDialog;
180 SaveDialog: TSaveDialog;
181 selectall1: TMenuItem;
182 ColorDialog: TColorDialog;
184 procedure aAboutExecute(Sender: TObject);
185 procedure aCheckMapExecute(Sender: TObject);
186 procedure aMoveToFore(Sender: TObject);
187 procedure aMoveToBack(Sender: TObject);
188 procedure aCopyObjectExecute(Sender: TObject);
189 procedure aCutObjectExecute(Sender: TObject);
190 procedure aEditorOptionsExecute(Sender: TObject);
191 procedure aExitExecute(Sender: TObject);
192 procedure aMapOptionsExecute(Sender: TObject);
193 procedure aNewMapExecute(Sender: TObject);
194 procedure aOpenMapExecute(Sender: TObject);
195 procedure aOptimizeExecute(Sender: TObject);
196 procedure aPasteObjectExecute(Sender: TObject);
197 procedure aSelectAllExecute(Sender: TObject);
198 procedure aSaveMapExecute(Sender: TObject);
199 procedure aSaveMapAsExecute(Sender: TObject);
200 procedure aUndoExecute(Sender: TObject);
201 procedure aDeleteMap(Sender: TObject);
202 procedure bApplyPropertyClick(Sender: TObject);
203 procedure bbAddTextureClick(Sender: TObject);
204 procedure bbRemoveTextureClick(Sender: TObject);
205 procedure FormActivate(Sender: TObject);
206 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
207 procedure FormCreate(Sender: TObject);
208 procedure FormDestroy(Sender: TObject);
209 procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
210 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
211 procedure FormResize(Sender: TObject);
212 procedure lbTextureListClick(Sender: TObject);
213 procedure lbTextureListDrawItem(Control: TWinControl; Index: Integer;
214 ARect: TRect; State: TOwnerDrawState);
215 procedure miReopenMapClick(Sender: TObject);
216 procedure RenderPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
217 procedure RenderPanelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
218 procedure RenderPanelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
219 procedure RenderPanelPaint(Sender: TObject);
220 procedure RenderPanelResize(Sender: TObject);
221 procedure Splitter1Moved(Sender: TObject);
222 procedure MapTestCheck(Sender: TObject);
223 procedure vleObjectPropertyEditButtonClick(Sender: TObject);
224 procedure vleObjectPropertyApply(Sender: TObject);
225 procedure vleObjectPropertyGetPickList(Sender: TObject; const KeyName: String; Values: TStrings);
226 procedure vleObjectPropertyKeyDown(Sender: TObject; var Key: Word;
227 Shift: TShiftState);
228 procedure tbGridOnClick(Sender: TObject);
229 procedure miMapPreviewClick(Sender: TObject);
230 procedure miLayer1Click(Sender: TObject);
231 procedure miLayer2Click(Sender: TObject);
232 procedure miLayer3Click(Sender: TObject);
233 procedure miLayer4Click(Sender: TObject);
234 procedure miLayer5Click(Sender: TObject);
235 procedure miLayer6Click(Sender: TObject);
236 procedure miLayer7Click(Sender: TObject);
237 procedure miLayer8Click(Sender: TObject);
238 procedure miLayer9Click(Sender: TObject);
239 procedure tbShowClick(Sender: TObject);
240 procedure miSnapToGridClick(Sender: TObject);
241 procedure miMiniMapClick(Sender: TObject);
242 procedure miSwitchGridClick(Sender: TObject);
243 procedure miShowEdgesClick(Sender: TObject);
244 procedure minexttabClick(Sender: TObject);
245 procedure miSaveMiniMapClick(Sender: TObject);
246 procedure bClearTextureClick(Sender: TObject);
247 procedure miPackMapClick(Sender: TObject);
248 procedure aRecentFileExecute(Sender: TObject);
249 procedure miMapTestSettingsClick(Sender: TObject);
250 procedure miTestMapClick(Sender: TObject);
251 procedure sbVerticalScroll(Sender: TObject; ScrollCode: TScrollCode;
252 var ScrollPos: Integer);
253 procedure sbHorizontalScroll(Sender: TObject; ScrollCode: TScrollCode;
254 var ScrollPos: Integer);
255 procedure miOpenWadMapClick(Sender: TObject);
256 procedure selectall1Click(Sender: TObject);
257 procedure Splitter1CanResize(Sender: TObject; var NewSize: Integer;
258 var Accept: Boolean);
259 procedure Splitter2CanResize(Sender: TObject; var NewSize: Integer;
260 var Accept: Boolean);
261 procedure vleObjectPropertyEnter(Sender: TObject);
262 procedure vleObjectPropertyExit(Sender: TObject);
263 procedure FormKeyUp(Sender: TObject; var Key: Word;
264 Shift: TShiftState);
265 private
266 procedure Draw();
267 procedure OnIdle(Sender: TObject; var Done: Boolean);
268 public
269 procedure RefreshRecentMenu();
270 procedure OpenMapFile(FileName: String);
271 function RenderMousePos(): TPoint;
272 procedure RecountSelectedObjects();
273 end;
275 const
276 LAYER_BACK = 0;
277 LAYER_WALLS = 1;
278 LAYER_FOREGROUND = 2;
279 LAYER_STEPS = 3;
280 LAYER_WATER = 4;
281 LAYER_ITEMS = 5;
282 LAYER_MONSTERS = 6;
283 LAYER_AREAS = 7;
284 LAYER_TRIGGERS = 8;
286 TEST_MAP_NAME = '$$$_TEST_$$$';
287 LANGUAGE_FILE_NAME = '_Editor.txt';
290 MainForm: TMainForm;
291 StartMap: String;
292 OpenedMap: String;
293 OpenedWAD: String;
295 DotColor: TColor;
296 DotEnable: Boolean;
297 DotStep: Word;
298 DotStepOne, DotStepTwo: Word;
299 DotSize: Byte;
300 DrawTexturePanel: Boolean;
301 DrawPanelSize: Boolean;
302 BackColor: TColor;
303 PreviewColor: TColor;
304 UseCheckerboard: Boolean;
305 Scale: Byte;
306 RecentCount: Integer;
307 RecentFiles: TStringList;
308 slInvalidTextures: TStringList;
310 TestGameMode: String;
311 TestLimTime: String;
312 TestLimScore: String;
313 TestOptionsTwoPlayers: Boolean;
314 TestOptionsTeamDamage: Boolean;
315 TestOptionsAllowExit: Boolean;
316 TestOptionsWeaponStay: Boolean;
317 TestOptionsMonstersDM: Boolean;
318 TestD2dExe, TestD2DArgs: String;
319 TestMapOnce: Boolean;
321 LayerEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
322 (True, True, True, True, True, True, True, True, True);
323 ContourEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
324 (False, False, False, False, False, False, False, False, False);
325 PreviewMode: Byte = 0;
326 gLanguage: String;
328 FormCaption: String;
331 procedure OpenMap(FileName: String; mapN: String);
332 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
333 procedure RemoveSelectFromObjects();
334 procedure ChangeShownProperty(Name: String; NewValue: String);
336 implementation
338 uses
339 f_options, e_graphics, e_log, GL, Math,
340 f_mapoptions, g_basic, f_about, f_mapoptimization,
341 f_mapcheck, f_addresource_texture, g_textures,
342 f_activationtype, f_keys, wadreader, fileutil,
343 MAPREADER, f_selectmap, f_savemap, WADEDITOR, MAPDEF,
344 g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
345 f_addresource_sound, f_maptest, f_choosetype,
346 g_language, f_selectlang, ClipBrd, g_resources, g_options;
348 const
349 UNDO_DELETE_PANEL = 1;
350 UNDO_DELETE_ITEM = 2;
351 UNDO_DELETE_AREA = 3;
352 UNDO_DELETE_MONSTER = 4;
353 UNDO_DELETE_TRIGGER = 5;
354 UNDO_ADD_PANEL = 6;
355 UNDO_ADD_ITEM = 7;
356 UNDO_ADD_AREA = 8;
357 UNDO_ADD_MONSTER = 9;
358 UNDO_ADD_TRIGGER = 10;
359 UNDO_MOVE_PANEL = 11;
360 UNDO_MOVE_ITEM = 12;
361 UNDO_MOVE_AREA = 13;
362 UNDO_MOVE_MONSTER = 14;
363 UNDO_MOVE_TRIGGER = 15;
364 UNDO_RESIZE_PANEL = 16;
365 UNDO_RESIZE_TRIGGER = 17;
367 MOUSEACTION_NONE = 0;
368 MOUSEACTION_DRAWPANEL = 1;
369 MOUSEACTION_DRAWTRIGGER = 2;
370 MOUSEACTION_MOVEOBJ = 3;
371 MOUSEACTION_RESIZE = 4;
372 MOUSEACTION_MOVEMAP = 5;
373 MOUSEACTION_DRAWPRESS = 6;
374 MOUSEACTION_NOACTION = 7;
376 RESIZETYPE_NONE = 0;
377 RESIZETYPE_VERTICAL = 1;
378 RESIZETYPE_HORIZONTAL = 2;
380 RESIZEDIR_NONE = 0;
381 RESIZEDIR_DOWN = 1;
382 RESIZEDIR_UP = 2;
383 RESIZEDIR_RIGHT = 3;
384 RESIZEDIR_LEFT = 4;
386 SELECTFLAG_NONE = 0;
387 SELECTFLAG_TELEPORT = 1;
388 SELECTFLAG_DOOR = 2;
389 SELECTFLAG_TEXTURE = 3;
390 SELECTFLAG_LIFT = 4;
391 SELECTFLAG_MONSTER = 5;
392 SELECTFLAG_SPAWNPOINT = 6;
393 SELECTFLAG_SHOTPANEL = 7;
394 SELECTFLAG_SELECTED = 8;
396 RECENT_FILES_MENU_START = 12;
398 CLIPBOARD_SIG = 'DF:ED';
400 type
401 TUndoRec = record
402 UndoType: Byte;
403 case Byte of
404 UNDO_DELETE_PANEL: (Panel: ^TPanel);
405 UNDO_DELETE_ITEM: (Item: TItem);
406 UNDO_DELETE_AREA: (Area: TArea);
407 UNDO_DELETE_MONSTER: (Monster: TMonster);
408 UNDO_DELETE_TRIGGER: (Trigger: TTrigger);
409 UNDO_ADD_PANEL,
410 UNDO_ADD_ITEM,
411 UNDO_ADD_AREA,
412 UNDO_ADD_MONSTER,
413 UNDO_ADD_TRIGGER: (AddID: DWORD);
414 UNDO_MOVE_PANEL,
415 UNDO_MOVE_ITEM,
416 UNDO_MOVE_AREA,
417 UNDO_MOVE_MONSTER,
418 UNDO_MOVE_TRIGGER: (MoveID: DWORD; dX, dY: Integer);
419 UNDO_RESIZE_PANEL,
420 UNDO_RESIZE_TRIGGER: (ResizeID: DWORD; dW, dH: Integer);
421 end;
423 TCopyRec = record
424 ObjectType: Byte;
425 ID: Cardinal;
426 case Byte of
427 OBJECT_PANEL: (Panel: ^TPanel);
428 OBJECT_ITEM: (Item: TItem);
429 OBJECT_AREA: (Area: TArea);
430 OBJECT_MONSTER: (Monster: TMonster);
431 OBJECT_TRIGGER: (Trigger: TTrigger);
432 end;
434 TCopyRecArray = Array of TCopyRec;
437 gEditorFont: DWORD;
438 gDataLoaded: Boolean = False;
439 ShowMap: Boolean = False;
440 DrawRect: PRect = nil;
441 SnapToGrid: Boolean = True;
443 MousePos: Types.TPoint;
444 LastMovePoint: Types.TPoint;
445 MouseLDown: Boolean;
446 MouseRDown: Boolean;
447 MouseMDown: Boolean;
448 MouseLDownPos: Types.TPoint;
449 MouseRDownPos: Types.TPoint;
450 MouseMDownPos: Types.TPoint;
452 SelectFlag: Byte = SELECTFLAG_NONE;
453 MouseAction: Byte = MOUSEACTION_NONE;
454 ResizeType: Byte = RESIZETYPE_NONE;
455 ResizeDirection: Byte = RESIZEDIR_NONE;
457 DrawPressRect: Boolean = False;
458 EditingProperties: Boolean = False;
460 UndoBuffer: Array of Array of TUndoRec = nil;
462 MapTestProcess: TProcessUTF8;
463 MapTestFile: String;
465 {$R *.lfm}
467 //----------------------------------------
468 //Далее идут вспомогательные процедуры
469 //----------------------------------------
471 function NameToBool(Name: String): Boolean;
472 begin
473 if Name = BoolNames[True] then
474 Result := True
475 else
476 Result := False;
477 end;
479 function NameToDir(Name: String): TDirection;
480 begin
481 if Name = DirNames[D_LEFT] then
482 Result := D_LEFT
483 else
484 Result := D_RIGHT;
485 end;
487 function NameToDirAdv(Name: String): Byte;
488 begin
489 if Name = DirNamesAdv[1] then
490 Result := 1
491 else
492 if Name = DirNamesAdv[2] then
493 Result := 2
494 else
495 if Name = DirNamesAdv[3] then
496 Result := 3
497 else
498 Result := 0;
499 end;
501 function ActivateToStr(ActivateType: Byte): String;
502 begin
503 Result := '';
505 if ByteBool(ACTIVATE_PLAYERCOLLIDE and ActivateType) then
506 Result := Result + '+PC';
507 if ByteBool(ACTIVATE_MONSTERCOLLIDE and ActivateType) then
508 Result := Result + '+MC';
509 if ByteBool(ACTIVATE_PLAYERPRESS and ActivateType) then
510 Result := Result + '+PP';
511 if ByteBool(ACTIVATE_MONSTERPRESS and ActivateType) then
512 Result := Result + '+MP';
513 if ByteBool(ACTIVATE_SHOT and ActivateType) then
514 Result := Result + '+SH';
515 if ByteBool(ACTIVATE_NOMONSTER and ActivateType) then
516 Result := Result + '+NM';
518 if (Result <> '') and (Result[1] = '+') then
519 Delete(Result, 1, 1);
520 end;
522 function StrToActivate(Str: String): Byte;
523 begin
524 Result := 0;
526 if Pos('PC', Str) > 0 then
527 Result := ACTIVATE_PLAYERCOLLIDE;
528 if Pos('MC', Str) > 0 then
529 Result := Result or ACTIVATE_MONSTERCOLLIDE;
530 if Pos('PP', Str) > 0 then
531 Result := Result or ACTIVATE_PLAYERPRESS;
532 if Pos('MP', Str) > 0 then
533 Result := Result or ACTIVATE_MONSTERPRESS;
534 if Pos('SH', Str) > 0 then
535 Result := Result or ACTIVATE_SHOT;
536 if Pos('NM', Str) > 0 then
537 Result := Result or ACTIVATE_NOMONSTER;
538 end;
540 function KeyToStr(Key: Byte): String;
541 begin
542 Result := '';
544 if ByteBool(KEY_RED and Key) then
545 Result := Result + '+RK';
546 if ByteBool(KEY_GREEN and Key) then
547 Result := Result + '+GK';
548 if ByteBool(KEY_BLUE and Key) then
549 Result := Result + '+BK';
550 if ByteBool(KEY_REDTEAM and Key) then
551 Result := Result + '+RT';
552 if ByteBool(KEY_BLUETEAM and Key) then
553 Result := Result + '+BT';
555 if (Result <> '') and (Result[1] = '+') then
556 Delete(Result, 1, 1);
557 end;
559 function StrToKey(Str: String): Byte;
560 begin
561 Result := 0;
563 if Pos('RK', Str) > 0 then
564 Result := KEY_RED;
565 if Pos('GK', Str) > 0 then
566 Result := Result or KEY_GREEN;
567 if Pos('BK', Str) > 0 then
568 Result := Result or KEY_BLUE;
569 if Pos('RT', Str) > 0 then
570 Result := Result or KEY_REDTEAM;
571 if Pos('BT', Str) > 0 then
572 Result := Result or KEY_BLUETEAM;
573 end;
575 function EffectToStr(Effect: Byte): String;
576 begin
577 if Effect in [EFFECT_TELEPORT..EFFECT_FIRE] then
578 Result := EffectNames[Effect]
579 else
580 Result := EffectNames[EFFECT_NONE];
581 end;
583 function StrToEffect(Str: String): Byte;
585 i: Integer;
586 begin
587 Result := EFFECT_NONE;
588 for i := EFFECT_TELEPORT to EFFECT_FIRE do
589 if EffectNames[i] = Str then
590 begin
591 Result := i;
592 Exit;
593 end;
594 end;
596 function MonsterToStr(MonType: Byte): String;
597 begin
598 if MonType in [MONSTER_DEMON..MONSTER_MAN] then
599 Result := MonsterNames[MonType]
600 else
601 Result := MonsterNames[MONSTER_ZOMBY];
602 end;
604 function StrToMonster(Str: String): Byte;
606 i: Integer;
607 begin
608 Result := MONSTER_ZOMBY;
609 for i := MONSTER_DEMON to MONSTER_MAN do
610 if MonsterNames[i] = Str then
611 begin
612 Result := i;
613 Exit;
614 end;
615 end;
617 function ItemToStr(ItemType: Byte): String;
618 begin
619 if ItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX] then
620 Result := ItemNames[ItemType]
621 else
622 Result := ItemNames[ITEM_AMMO_BULLETS];
623 end;
625 function StrToItem(Str: String): Byte;
627 i: Integer;
628 begin
629 Result := ITEM_AMMO_BULLETS;
630 for i := ITEM_MEDKIT_SMALL to ITEM_MAX do
631 if ItemNames[i] = Str then
632 begin
633 Result := i;
634 Exit;
635 end;
636 end;
638 function ShotToStr(ShotType: Byte): String;
639 begin
640 if ShotType in [TRIGGER_SHOT_PISTOL..TRIGGER_SHOT_MAX] then
641 Result := ShotNames[ShotType]
642 else
643 Result := ShotNames[TRIGGER_SHOT_PISTOL];
644 end;
646 function StrToShot(Str: String): Byte;
648 i: Integer;
649 begin
650 Result := TRIGGER_SHOT_PISTOL;
651 for i := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
652 if ShotNames[i] = Str then
653 begin
654 Result := i;
655 Exit;
656 end;
657 end;
659 function SelectedObjectCount(): Word;
661 a: Integer;
662 begin
663 Result := 0;
665 if SelectedObjects = nil then
666 Exit;
668 for a := 0 to High(SelectedObjects) do
669 if SelectedObjects[a].Live then
670 Result := Result + 1;
671 end;
673 function GetFirstSelected(): Integer;
675 a: Integer;
676 begin
677 Result := -1;
679 if SelectedObjects = nil then
680 Exit;
682 for a := 0 to High(SelectedObjects) do
683 if SelectedObjects[a].Live then
684 begin
685 Result := a;
686 Exit;
687 end;
688 end;
690 function Normalize16(x: Integer): Integer;
691 begin
692 Result := (x div 16) * 16;
693 end;
695 procedure MoveMap(X, Y: Integer);
697 rx, ry, ScaleSz: Integer;
698 begin
699 with MainForm.RenderPanel do
700 begin
701 ScaleSz := 16 div Scale;
702 // Размер видимой части карты:
703 rx := Min(Normalize16(Width), Normalize16(gMapInfo.Width)) div 2;
704 ry := Min(Normalize16(Height), Normalize16(gMapInfo.Height)) div 2;
705 // Место клика на мини-карте:
706 MapOffset.X := X - (Width - Max(gMapInfo.Width div ScaleSz, 1) - 1);
707 MapOffset.Y := Y - 1;
708 // Это же место на "большой" карте:
709 MapOffset.X := MapOffset.X * ScaleSz;
710 MapOffset.Y := MapOffset.Y * ScaleSz;
711 // Левый верхний угол новой видимой части карты:
712 MapOffset.X := MapOffset.X - rx;
713 MapOffset.Y := MapOffset.Y - ry;
714 // Выход за границы:
715 MapOffset.X := EnsureRange(MapOffset.X, MainForm.sbHorizontal.Min, MainForm.sbHorizontal.Max);
716 MapOffset.Y := EnsureRange(MapOffset.Y, MainForm.sbVertical.Min, MainForm.sbVertical.Max);
717 // Кратно 16:
718 // MapOffset.X := Normalize16(MapOffset.X);
719 // MapOffset.Y := Normalize16(MapOffset.Y);
720 end;
722 MainForm.sbHorizontal.Position := MapOffset.X;
723 MainForm.sbVertical.Position := MapOffset.Y;
725 MapOffset.X := -MapOffset.X;
726 MapOffset.Y := -MapOffset.Y;
728 MainForm.Resize();
729 end;
731 function IsTexturedPanel(PanelType: Word): Boolean;
732 begin
733 Result := WordBool(PanelType and (PANEL_WALL or PANEL_BACK or PANEL_FORE or
734 PANEL_STEP or PANEL_OPENDOOR or PANEL_CLOSEDOOR or
735 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2));
736 end;
738 procedure FillProperty();
740 _id: DWORD;
741 str: String;
742 begin
743 MainForm.vleObjectProperty.Strings.Clear();
744 MainForm.RecountSelectedObjects();
746 // Отображаем свойства если выделен только один объект:
747 if SelectedObjectCount() <> 1 then
748 Exit;
750 _id := GetFirstSelected();
751 if not SelectedObjects[_id].Live then
752 Exit;
754 with MainForm.vleObjectProperty do
755 with ItemProps[InsertRow(_lc[I_PROP_ID], IntToStr(SelectedObjects[_id].ID), True)] do
756 begin
757 EditStyle := esSimple;
758 ReadOnly := True;
759 end;
761 case SelectedObjects[0].ObjectType of
762 OBJECT_PANEL:
763 begin
764 with MainForm.vleObjectProperty,
765 gPanels[SelectedObjects[_id].ID] do
766 begin
767 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
768 begin
769 EditStyle := esSimple;
770 MaxLength := 5;
771 end;
773 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
774 begin
775 EditStyle := esSimple;
776 MaxLength := 5;
777 end;
779 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
780 begin
781 EditStyle := esSimple;
782 MaxLength := 5;
783 end;
785 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
786 begin
787 EditStyle := esSimple;
788 MaxLength := 5;
789 end;
791 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TYPE], GetPanelName(PanelType), True)] do
792 begin
793 EditStyle := esEllipsis;
794 ReadOnly := True;
795 end;
797 if IsTexturedPanel(PanelType) then
798 begin // Может быть текстура
799 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TEX], TextureName, True)] do
800 begin
801 EditStyle := esEllipsis;
802 ReadOnly := True;
803 end;
805 if TextureName <> '' then
806 begin // Есть текстура
807 with ItemProps[InsertRow(_lc[I_PROP_PANEL_ALPHA], IntToStr(Alpha), True)] do
808 begin
809 EditStyle := esSimple;
810 MaxLength := 3;
811 end;
813 with ItemProps[InsertRow(_lc[I_PROP_PANEL_BLEND], BoolNames[Blending], True)] do
814 begin
815 EditStyle := esPickList;
816 ReadOnly := True;
817 end;
818 end;
819 end;
820 end;
821 end;
823 OBJECT_ITEM:
824 begin
825 with MainForm.vleObjectProperty,
826 gItems[SelectedObjects[_id].ID] do
827 begin
828 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
829 begin
830 EditStyle := esSimple;
831 MaxLength := 5;
832 end;
834 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
835 begin
836 EditStyle := esSimple;
837 MaxLength := 5;
838 end;
840 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[OnlyDM], True)] do
841 begin
842 EditStyle := esPickList;
843 ReadOnly := True;
844 end;
846 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Fall], True)] do
847 begin
848 EditStyle := esPickList;
849 ReadOnly := True;
850 end;
851 end;
852 end;
854 OBJECT_MONSTER:
855 begin
856 with MainForm.vleObjectProperty,
857 gMonsters[SelectedObjects[_id].ID] do
858 begin
859 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
860 begin
861 EditStyle := esSimple;
862 MaxLength := 5;
863 end;
865 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
866 begin
867 EditStyle := esSimple;
868 MaxLength := 5;
869 end;
871 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
872 begin
873 EditStyle := esPickList;
874 ReadOnly := True;
875 end;
876 end;
877 end;
879 OBJECT_AREA:
880 begin
881 with MainForm.vleObjectProperty,
882 gAreas[SelectedObjects[_id].ID] do
883 begin
884 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
885 begin
886 EditStyle := esSimple;
887 MaxLength := 5;
888 end;
890 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
891 begin
892 EditStyle := esSimple;
893 MaxLength := 5;
894 end;
896 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
897 begin
898 EditStyle := esPickList;
899 ReadOnly := True;
900 end;
901 end;
902 end;
904 OBJECT_TRIGGER:
905 begin
906 with MainForm.vleObjectProperty,
907 gTriggers[SelectedObjects[_id].ID] do
908 begin
909 with ItemProps[InsertRow(_lc[I_PROP_TR_TYPE], GetTriggerName(TriggerType), True)] do
910 begin
911 EditStyle := esSimple;
912 ReadOnly := True;
913 end;
915 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
916 begin
917 EditStyle := esSimple;
918 MaxLength := 5;
919 end;
921 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
922 begin
923 EditStyle := esSimple;
924 MaxLength := 5;
925 end;
927 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
928 begin
929 EditStyle := esSimple;
930 MaxLength := 5;
931 end;
933 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
934 begin
935 EditStyle := esSimple;
936 MaxLength := 5;
937 end;
939 with ItemProps[InsertRow(_lc[I_PROP_TR_ENABLED], BoolNames[Enabled], True)] do
940 begin
941 EditStyle := esPickList;
942 ReadOnly := True;
943 end;
945 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_PANEL], IntToStr(TexturePanel), True)] do
946 begin
947 EditStyle := esEllipsis;
948 ReadOnly := True;
949 end;
951 with ItemProps[InsertRow(_lc[I_PROP_TR_ACTIVATION], ActivateToStr(ActivateType), True)] do
952 begin
953 EditStyle := esEllipsis;
954 ReadOnly := True;
955 end;
957 with ItemProps[InsertRow(_lc[I_PROP_TR_KEYS], KeyToStr(Key), True)] do
958 begin
959 EditStyle := esEllipsis;
960 ReadOnly := True;
961 end;
963 case TriggerType of
964 TRIGGER_EXIT:
965 begin
966 str := win2utf(Data.MapName);
967 with ItemProps[InsertRow(_lc[I_PROP_TR_NEXT_MAP], str, True)] do
968 begin
969 EditStyle := esEllipsis;
970 ReadOnly := True;
971 end;
972 end;
974 TRIGGER_TELEPORT:
975 begin
976 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_TO], Format('(%d:%d)', [Data.TargetPoint.X, Data.TargetPoint.Y]), True)] do
977 begin
978 EditStyle := esEllipsis;
979 ReadOnly := True;
980 end;
982 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_teleport], True)] do
983 begin
984 EditStyle := esPickList;
985 ReadOnly := True;
986 end;
988 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_SILENT], BoolNames[Data.silent_teleport], True)] do
989 begin
990 EditStyle := esPickList;
991 ReadOnly := True;
992 end;
994 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_DIR], DirNamesAdv[Data.TlpDir], True)] do
995 begin
996 EditStyle := esPickList;
997 ReadOnly := True;
998 end;
999 end;
1001 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR,
1002 TRIGGER_DOOR, TRIGGER_DOOR5:
1003 begin
1004 with ItemProps[InsertRow(_lc[I_PROP_TR_DOOR_PANEL], IntToStr(Data.PanelID), True)] do
1005 begin
1006 EditStyle := esEllipsis;
1007 ReadOnly := True;
1008 end;
1010 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1011 begin
1012 EditStyle := esPickList;
1013 ReadOnly := True;
1014 end;
1016 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1017 begin
1018 EditStyle := esPickList;
1019 ReadOnly := True;
1020 end;
1021 end;
1023 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1024 begin
1025 with ItemProps[InsertRow(_lc[I_PROP_TR_TRAP_PANEL], IntToStr(Data.PanelID), True)] do
1026 begin
1027 EditStyle := esEllipsis;
1028 ReadOnly := True;
1029 end;
1031 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1032 begin
1033 EditStyle := esPickList;
1034 ReadOnly := True;
1035 end;
1037 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1038 begin
1039 EditStyle := esPickList;
1040 ReadOnly := True;
1041 end;
1042 end;
1044 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
1045 TRIGGER_ONOFF:
1046 begin
1047 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_AREA],
1048 Format('(%d:%d %d:%d)', [Data.tX, Data.tY, Data.tWidth, Data.tHeight]), True)] do
1049 begin
1050 EditStyle := esEllipsis;
1051 ReadOnly := True;
1052 end;
1054 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.Wait), True)] do
1055 begin
1056 EditStyle := esSimple;
1057 MaxLength := 5;
1058 end;
1060 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_COUNT], IntToStr(Data.Count), True)] do
1061 begin
1062 EditStyle := esSimple;
1063 MaxLength := 5;
1064 end;
1066 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_MONSTER], IntToStr(Data.MonsterID-1), True)] do
1067 begin
1068 EditStyle := esEllipsis;
1069 ReadOnly := True;
1070 end;
1072 if TriggerType = TRIGGER_PRESS then
1073 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_RANDOM], BoolNames[Data.ExtRandom], True)] do
1074 begin
1075 EditStyle := esPickList;
1076 ReadOnly := True;
1077 end;
1078 end;
1080 TRIGGER_SECRET:
1083 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
1084 begin
1085 with ItemProps[InsertRow(_lc[I_PROP_TR_LIFT_PANEL], IntToStr(Data.PanelID), True)] do
1086 begin
1087 EditStyle := esEllipsis;
1088 ReadOnly := True;
1089 end;
1091 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1092 begin
1093 EditStyle := esPickList;
1094 ReadOnly := True;
1095 end;
1097 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1098 begin
1099 EditStyle := esPickList;
1100 ReadOnly := True;
1101 end;
1102 end;
1104 TRIGGER_TEXTURE:
1105 begin
1106 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ONCE], BoolNames[Data.ActivateOnce], True)] do
1107 begin
1108 EditStyle := esPickList;
1109 ReadOnly := True;
1110 end;
1112 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ANIM_ONCE], BoolNames[Data.AnimOnce], True)] do
1113 begin
1114 EditStyle := esPickList;
1115 ReadOnly := True;
1116 end;
1117 end;
1119 TRIGGER_SOUND:
1120 begin
1121 str := win2utf(Data.SoundName);
1122 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_NAME], str, True)] do
1123 begin
1124 EditStyle := esEllipsis;
1125 ReadOnly := True;
1126 end;
1128 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_VOLUME], IntToStr(Data.Volume), True)] do
1129 begin
1130 EditStyle := esSimple;
1131 MaxLength := 3;
1132 end;
1134 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_PAN], IntToStr(Data.Pan), True)] do
1135 begin
1136 EditStyle := esSimple;
1137 MaxLength := 3;
1138 end;
1140 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_COUNT], IntToStr(Data.PlayCount), True)] do
1141 begin
1142 EditStyle := esSimple;
1143 MaxLength := 3;
1144 end;
1146 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_LOCAL], BoolNames[Data.Local], True)] do
1147 begin
1148 EditStyle := esPickList;
1149 ReadOnly := True;
1150 end;
1152 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_SWITCH], BoolNames[Data.SoundSwitch], True)] do
1153 begin
1154 EditStyle := esPickList;
1155 ReadOnly := True;
1156 end;
1157 end;
1159 TRIGGER_SPAWNMONSTER:
1160 begin
1161 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_TYPE], MonsterToStr(Data.MonType), True)] do
1162 begin
1163 EditStyle := esEllipsis;
1164 ReadOnly := True;
1165 end;
1167 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1168 Format('(%d:%d)', [Data.MonPos.X, Data.MonPos.Y]), True)] do
1169 begin
1170 EditStyle := esEllipsis;
1171 ReadOnly := True;
1172 end;
1174 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[TDirection(Data.MonDir)], True)] do
1175 begin
1176 EditStyle := esPickList;
1177 ReadOnly := True;
1178 end;
1180 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.MonHealth), True)] do
1181 begin
1182 EditStyle := esSimple;
1183 MaxLength := 5;
1184 end;
1186 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_ACTIVE], BoolNames[Data.MonActive], True)] do
1187 begin
1188 EditStyle := esPickList;
1189 ReadOnly := True;
1190 end;
1192 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.MonCount), True)] do
1193 begin
1194 EditStyle := esSimple;
1195 MaxLength := 5;
1196 end;
1198 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.MonEffect), True)] do
1199 begin
1200 EditStyle := esEllipsis;
1201 ReadOnly := True;
1202 end;
1204 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.MonMax), True)] do
1205 begin
1206 EditStyle := esSimple;
1207 MaxLength := 5;
1208 end;
1210 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.MonDelay), True)] do
1211 begin
1212 EditStyle := esSimple;
1213 MaxLength := 5;
1214 end;
1216 case Data.MonBehav of
1217 1: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1];
1218 2: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2];
1219 3: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3];
1220 4: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4];
1221 5: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5];
1222 else str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_0];
1223 end;
1224 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_BEHAVIOUR], str, True)] do
1225 begin
1226 EditStyle := esPickList;
1227 ReadOnly := True;
1228 end;
1229 end;
1231 TRIGGER_SPAWNITEM:
1232 begin
1233 with ItemProps[InsertRow(_lc[I_PROP_TR_ITEM_TYPE], ItemToStr(Data.ItemType), True)] do
1234 begin
1235 EditStyle := esEllipsis;
1236 ReadOnly := True;
1237 end;
1239 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1240 Format('(%d:%d)', [Data.ItemPos.X, Data.ItemPos.Y]), True)] do
1241 begin
1242 EditStyle := esEllipsis;
1243 ReadOnly := True;
1244 end;
1246 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[Data.ItemOnlyDM], True)] do
1247 begin
1248 EditStyle := esPickList;
1249 ReadOnly := True;
1250 end;
1252 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Data.ItemFalls], True)] do
1253 begin
1254 EditStyle := esPickList;
1255 ReadOnly := True;
1256 end;
1258 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ItemCount), True)] do
1259 begin
1260 EditStyle := esSimple;
1261 MaxLength := 5;
1262 end;
1264 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.ItemEffect), True)] do
1265 begin
1266 EditStyle := esEllipsis;
1267 ReadOnly := True;
1268 end;
1270 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.ItemMax), True)] do
1271 begin
1272 EditStyle := esSimple;
1273 MaxLength := 5;
1274 end;
1276 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.ItemDelay), True)] do
1277 begin
1278 EditStyle := esSimple;
1279 MaxLength := 5;
1280 end;
1281 end;
1283 TRIGGER_MUSIC:
1284 begin
1285 str := win2utf(Data.MusicName);
1286 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_NAME], str, True)] do
1287 begin
1288 EditStyle := esEllipsis;
1289 ReadOnly := True;
1290 end;
1292 if Data.MusicAction = 1 then
1293 str := _lc[I_PROP_TR_MUSIC_ON]
1294 else
1295 str := _lc[I_PROP_TR_MUSIC_OFF];
1297 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_ACT], str, True)] do
1298 begin
1299 EditStyle := esPickList;
1300 ReadOnly := True;
1301 end;
1302 end;
1304 TRIGGER_PUSH:
1305 begin
1306 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_ANGLE], IntToStr(Data.PushAngle), True)] do
1307 begin
1308 EditStyle := esSimple;
1309 MaxLength := 4;
1310 end;
1311 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_FORCE], IntToStr(Data.PushForce), True)] do
1312 begin
1313 EditStyle := esSimple;
1314 MaxLength := 4;
1315 end;
1316 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_RESET], BoolNames[Data.ResetVel], True)] do
1317 begin
1318 EditStyle := esPickList;
1319 ReadOnly := True;
1320 end;
1321 end;
1323 TRIGGER_SCORE:
1324 begin
1325 case Data.ScoreAction of
1326 1: str := _lc[I_PROP_TR_SCORE_ACT_1];
1327 2: str := _lc[I_PROP_TR_SCORE_ACT_2];
1328 3: str := _lc[I_PROP_TR_SCORE_ACT_3];
1329 else str := _lc[I_PROP_TR_SCORE_ACT_0];
1330 end;
1331 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_ACT], str, True)] do
1332 begin
1333 EditStyle := esPickList;
1334 ReadOnly := True;
1335 end;
1336 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ScoreCount), True)] do
1337 begin
1338 EditStyle := esSimple;
1339 MaxLength := 3;
1340 end;
1341 case Data.ScoreTeam of
1342 1: str := _lc[I_PROP_TR_SCORE_TEAM_1];
1343 2: str := _lc[I_PROP_TR_SCORE_TEAM_2];
1344 3: str := _lc[I_PROP_TR_SCORE_TEAM_3];
1345 else str := _lc[I_PROP_TR_SCORE_TEAM_0];
1346 end;
1347 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_TEAM], str, True)] do
1348 begin
1349 EditStyle := esPickList;
1350 ReadOnly := True;
1351 end;
1352 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_CON], BoolNames[Data.ScoreCon], True)] do
1353 begin
1354 EditStyle := esPickList;
1355 ReadOnly := True;
1356 end;
1357 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_MSG], BoolNames[Data.ScoreMsg], True)] do
1358 begin
1359 EditStyle := esPickList;
1360 ReadOnly := True;
1361 end;
1362 end;
1364 TRIGGER_MESSAGE:
1365 begin
1366 case Data.MessageKind of
1367 1: str := _lc[I_PROP_TR_MESSAGE_KIND_1];
1368 else str := _lc[I_PROP_TR_MESSAGE_KIND_0];
1369 end;
1370 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_KIND], str, True)] do
1371 begin
1372 EditStyle := esPickList;
1373 ReadOnly := True;
1374 end;
1375 case Data.MessageSendTo of
1376 1: str := _lc[I_PROP_TR_MESSAGE_TO_1];
1377 2: str := _lc[I_PROP_TR_MESSAGE_TO_2];
1378 3: str := _lc[I_PROP_TR_MESSAGE_TO_3];
1379 4: str := _lc[I_PROP_TR_MESSAGE_TO_4];
1380 5: str := _lc[I_PROP_TR_MESSAGE_TO_5];
1381 else str := _lc[I_PROP_TR_MESSAGE_TO_0];
1382 end;
1383 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TO], str, True)] do
1384 begin
1385 EditStyle := esPickList;
1386 ReadOnly := True;
1387 end;
1388 str := win2utf(Data.MessageText);
1389 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TEXT], str, True)] do
1390 begin
1391 EditStyle := esSimple;
1392 MaxLength := 100;
1393 end;
1394 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TIME], IntToStr(Data.MessageTime), True)] do
1395 begin
1396 EditStyle := esSimple;
1397 MaxLength := 5;
1398 end;
1399 end;
1401 TRIGGER_DAMAGE:
1402 begin
1403 with ItemProps[InsertRow(_lc[I_PROP_TR_DAMAGE_VALUE], IntToStr(Data.DamageValue), True)] do
1404 begin
1405 EditStyle := esSimple;
1406 MaxLength := 5;
1407 end;
1408 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.DamageInterval), True)] do
1409 begin
1410 EditStyle := esSimple;
1411 MaxLength := 5;
1412 end;
1413 case Data.DamageKind of
1414 3: str := _lc[I_PROP_TR_DAMAGE_KIND_3];
1415 4: str := _lc[I_PROP_TR_DAMAGE_KIND_4];
1416 5: str := _lc[I_PROP_TR_DAMAGE_KIND_5];
1417 6: str := _lc[I_PROP_TR_DAMAGE_KIND_6];
1418 7: str := _lc[I_PROP_TR_DAMAGE_KIND_7];
1419 8: str := _lc[I_PROP_TR_DAMAGE_KIND_8];
1420 else str := _lc[I_PROP_TR_DAMAGE_KIND_0];
1421 end;
1422 with ItemProps[InsertRow(_lc[I_PROP_TR_DAMAGE_KIND], str, True)] do
1423 begin
1424 EditStyle := esPickList;
1425 ReadOnly := True;
1426 end;
1427 end;
1429 TRIGGER_HEALTH:
1430 begin
1431 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.HealValue), True)] do
1432 begin
1433 EditStyle := esSimple;
1434 MaxLength := 5;
1435 end;
1436 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.HealInterval), True)] do
1437 begin
1438 EditStyle := esSimple;
1439 MaxLength := 5;
1440 end;
1441 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH_MAX], BoolNames[Data.HealMax], True)] do
1442 begin
1443 EditStyle := esPickList;
1444 ReadOnly := True;
1445 end;
1446 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.HealSilent], True)] do
1447 begin
1448 EditStyle := esPickList;
1449 ReadOnly := True;
1450 end;
1451 end;
1453 TRIGGER_SHOT:
1454 begin
1455 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TYPE], ShotToStr(Data.ShotType), True)] do
1456 begin
1457 EditStyle := esEllipsis;
1458 ReadOnly := True;
1459 end;
1461 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SOUND], BoolNames[Data.ShotSound], True)] do
1462 begin
1463 EditStyle := esPickList;
1464 ReadOnly := True;
1465 end;
1467 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_PANEL], IntToStr(Data.ShotPanelID), True)] do
1468 begin
1469 EditStyle := esEllipsis;
1470 ReadOnly := True;
1471 end;
1473 case Data.ShotTarget of
1474 1: str := _lc[I_PROP_TR_SHOT_TO_1];
1475 2: str := _lc[I_PROP_TR_SHOT_TO_2];
1476 3: str := _lc[I_PROP_TR_SHOT_TO_3];
1477 4: str := _lc[I_PROP_TR_SHOT_TO_4];
1478 5: str := _lc[I_PROP_TR_SHOT_TO_5];
1479 6: str := _lc[I_PROP_TR_SHOT_TO_6];
1480 else str := _lc[I_PROP_TR_SHOT_TO_0];
1481 end;
1482 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TO], str, True)] do
1483 begin
1484 EditStyle := esPickList;
1485 ReadOnly := True;
1486 end;
1488 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SIGHT], IntToStr(Data.ShotIntSight), True)] do
1489 begin
1490 EditStyle := esSimple;
1491 MaxLength := 3;
1492 end;
1494 case Data.ShotAim of
1495 1: str := _lc[I_PROP_TR_SHOT_AIM_1];
1496 2: str := _lc[I_PROP_TR_SHOT_AIM_2];
1497 3: str := _lc[I_PROP_TR_SHOT_AIM_3];
1498 else str := _lc[I_PROP_TR_SHOT_AIM_0];
1499 end;
1500 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AIM], str, True)] do
1501 begin
1502 EditStyle := esPickList;
1503 ReadOnly := True;
1504 end;
1506 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1507 Format('(%d:%d)', [Data.ShotPos.X, Data.ShotPos.Y]), True)] do
1508 begin
1509 EditStyle := esEllipsis;
1510 ReadOnly := True;
1511 end;
1513 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ANGLE], IntToStr(Data.ShotAngle), True)] do
1514 begin
1515 EditStyle := esSimple;
1516 MaxLength := 4;
1517 end;
1519 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.ShotWait), True)] do
1520 begin
1521 EditStyle := esSimple;
1522 MaxLength := 5;
1523 end;
1525 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ACC], IntToStr(Data.ShotAccuracy), True)] do
1526 begin
1527 EditStyle := esSimple;
1528 MaxLength := 5;
1529 end;
1531 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AMMO], IntToStr(Data.ShotAmmo), True)] do
1532 begin
1533 EditStyle := esSimple;
1534 MaxLength := 5;
1535 end;
1537 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_RELOAD], IntToStr(Data.ShotIntReload), True)] do
1538 begin
1539 EditStyle := esSimple;
1540 MaxLength := 4;
1541 end;
1542 end;
1544 TRIGGER_EFFECT:
1545 begin
1546 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.FXCount), True)] do
1547 begin
1548 EditStyle := esSimple;
1549 MaxLength := 3;
1550 end;
1552 if Data.FXType = 0 then
1553 str := _lc[I_PROP_TR_EFFECT_PARTICLE]
1554 else
1555 str := _lc[I_PROP_TR_EFFECT_ANIMATION];
1556 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_TYPE], str, True)] do
1557 begin
1558 EditStyle := esEllipsis;
1559 ReadOnly := True;
1560 end;
1562 str := '';
1563 if Data.FXType = 0 then
1564 case Data.FXSubType of
1565 TRIGGER_EFFECT_SLIQUID:
1566 str := _lc[I_PROP_TR_EFFECT_SLIQUID];
1567 TRIGGER_EFFECT_LLIQUID:
1568 str := _lc[I_PROP_TR_EFFECT_LLIQUID];
1569 TRIGGER_EFFECT_DLIQUID:
1570 str := _lc[I_PROP_TR_EFFECT_DLIQUID];
1571 TRIGGER_EFFECT_BLOOD:
1572 str := _lc[I_PROP_TR_EFFECT_BLOOD];
1573 TRIGGER_EFFECT_SPARK:
1574 str := _lc[I_PROP_TR_EFFECT_SPARK];
1575 TRIGGER_EFFECT_BUBBLE:
1576 str := _lc[I_PROP_TR_EFFECT_BUBBLE];
1577 end;
1578 if Data.FXType = 1 then
1579 begin
1580 if (Data.FXSubType = 0) or (Data.FXSubType > EFFECT_FIRE) then
1581 Data.FXSubType := EFFECT_TELEPORT;
1582 str := EffectToStr(Data.FXSubType);
1583 end;
1584 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SUBTYPE], str, True)] do
1585 begin
1586 EditStyle := esEllipsis;
1587 ReadOnly := True;
1588 end;
1590 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_COLOR], IntToStr(Data.FXColorR or (Data.FXColorG shl 8) or (Data.FXColorB shl 16)), True)] do
1591 begin
1592 EditStyle := esEllipsis;
1593 ReadOnly := True;
1594 end;
1596 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_CENTER], BoolNames[Data.FXPos = 0], True)] do
1597 begin
1598 EditStyle := esPickList;
1599 ReadOnly := True;
1600 end;
1602 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.FXWait), True)] do
1603 begin
1604 EditStyle := esSimple;
1605 MaxLength := 5;
1606 end;
1608 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELX], IntToStr(Data.FXVelX), True)] do
1609 begin
1610 EditStyle := esSimple;
1611 MaxLength := 4;
1612 end;
1614 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELY], IntToStr(Data.FXVelY), True)] do
1615 begin
1616 EditStyle := esSimple;
1617 MaxLength := 4;
1618 end;
1620 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPL], IntToStr(Data.FXSpreadL), True)] do
1621 begin
1622 EditStyle := esSimple;
1623 MaxLength := 3;
1624 end;
1626 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPR], IntToStr(Data.FXSpreadR), True)] do
1627 begin
1628 EditStyle := esSimple;
1629 MaxLength := 3;
1630 end;
1632 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPU], IntToStr(Data.FXSpreadU), True)] do
1633 begin
1634 EditStyle := esSimple;
1635 MaxLength := 3;
1636 end;
1638 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPD], IntToStr(Data.FXSpreadD), True)] do
1639 begin
1640 EditStyle := esSimple;
1641 MaxLength := 3;
1642 end;
1643 end;
1644 end; //case TriggerType
1645 end;
1646 end; // OBJECT_TRIGGER:
1647 end;
1648 end;
1650 procedure ChangeShownProperty(Name: String; NewValue: String);
1652 row: Integer;
1653 begin
1654 if SelectedObjectCount() <> 1 then
1655 Exit;
1656 if not SelectedObjects[GetFirstSelected()].Live then
1657 Exit;
1659 // Есть ли такой ключ:
1660 if MainForm.vleObjectProperty.FindRow(Name, row) then
1661 begin
1662 MainForm.vleObjectProperty.Values[Name] := NewValue;
1663 end;
1664 end;
1666 procedure SelectObject(fObjectType: Byte; fID: DWORD; Multi: Boolean);
1668 a: Integer;
1669 b: Boolean;
1670 begin
1671 if Multi then
1672 begin
1673 b := False;
1675 // Уже выделен - убираем:
1676 if SelectedObjects <> nil then
1677 for a := 0 to High(SelectedObjects) do
1678 with SelectedObjects[a] do
1679 if Live and (ID = fID) and
1680 (ObjectType = fObjectType) then
1681 begin
1682 Live := False;
1683 b := True;
1684 end;
1686 if b then
1687 Exit;
1689 SetLength(SelectedObjects, Length(SelectedObjects)+1);
1691 with SelectedObjects[High(SelectedObjects)] do
1692 begin
1693 ObjectType := fObjectType;
1694 ID := fID;
1695 Live := True;
1696 end;
1698 else // not Multi
1699 begin
1700 SetLength(SelectedObjects, 1);
1702 with SelectedObjects[0] do
1703 begin
1704 ObjectType := fObjectType;
1705 ID := fID;
1706 Live := True;
1707 end;
1708 end;
1710 MainForm.miCopy.Enabled := True;
1711 MainForm.miCut.Enabled := True;
1713 if fObjectType = OBJECT_PANEL then
1714 begin
1715 MainForm.miToFore.Enabled := True;
1716 MainForm.miToBack.Enabled := True;
1717 end;
1718 end;
1720 procedure RemoveSelectFromObjects();
1721 begin
1722 SelectedObjects := nil;
1723 DrawPressRect := False;
1724 MouseLDown := False;
1725 MouseRDown := False;
1726 MouseAction := MOUSEACTION_NONE;
1727 SelectFlag := SELECTFLAG_NONE;
1728 ResizeType := RESIZETYPE_NONE;
1729 ResizeDirection := RESIZEDIR_NONE;
1731 MainForm.vleObjectProperty.Strings.Clear();
1733 MainForm.miCopy.Enabled := False;
1734 MainForm.miCut.Enabled := False;
1735 MainForm.miToFore.Enabled := False;
1736 MainForm.miToBack.Enabled := False;
1737 end;
1739 procedure DeleteSelectedObjects();
1741 i, a, ii: Integer;
1742 b: Boolean;
1743 begin
1744 if SelectedObjects = nil then
1745 Exit;
1747 b := False;
1748 i := 0;
1750 for a := 0 to High(SelectedObjects) do
1751 with SelectedObjects[a] do
1752 if Live then
1753 begin
1754 if not b then
1755 begin
1756 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1757 i := High(UndoBuffer);
1758 b := True;
1759 end;
1761 SetLength(UndoBuffer[i], Length(UndoBuffer[i])+1);
1762 ii := High(UndoBuffer[i]);
1764 case ObjectType of
1765 OBJECT_PANEL:
1766 begin
1767 UndoBuffer[i, ii].UndoType := UNDO_DELETE_PANEL;
1768 New(UndoBuffer[i, ii].Panel);
1769 UndoBuffer[i, ii].Panel^ := gPanels[ID];
1770 end;
1771 OBJECT_ITEM:
1772 begin
1773 UndoBuffer[i, ii].UndoType := UNDO_DELETE_ITEM;
1774 UndoBuffer[i, ii].Item := gItems[ID];
1775 end;
1776 OBJECT_AREA:
1777 begin
1778 UndoBuffer[i, ii].UndoType := UNDO_DELETE_AREA;
1779 UndoBuffer[i, ii].Area := gAreas[ID];
1780 end;
1781 OBJECT_TRIGGER:
1782 begin
1783 UndoBuffer[i, ii].UndoType := UNDO_DELETE_TRIGGER;
1784 UndoBuffer[i, ii].Trigger := gTriggers[ID];
1785 end;
1786 end;
1788 RemoveObject(ID, ObjectType);
1789 end;
1791 RemoveSelectFromObjects();
1793 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1794 MainForm.RecountSelectedObjects();
1795 end;
1797 procedure Undo_Add(ObjectType: Byte; ID: DWORD; Group: Boolean = False);
1799 i, ii: Integer;
1800 begin
1801 if (not Group) or (Length(UndoBuffer) = 0) then
1802 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1803 SetLength(UndoBuffer[High(UndoBuffer)], Length(UndoBuffer[High(UndoBuffer)])+1);
1804 i := High(UndoBuffer);
1805 ii := High(UndoBuffer[i]);
1807 case ObjectType of
1808 OBJECT_PANEL:
1809 UndoBuffer[i, ii].UndoType := UNDO_ADD_PANEL;
1810 OBJECT_ITEM:
1811 UndoBuffer[i, ii].UndoType := UNDO_ADD_ITEM;
1812 OBJECT_MONSTER:
1813 UndoBuffer[i, ii].UndoType := UNDO_ADD_MONSTER;
1814 OBJECT_AREA:
1815 UndoBuffer[i, ii].UndoType := UNDO_ADD_AREA;
1816 OBJECT_TRIGGER:
1817 UndoBuffer[i, ii].UndoType := UNDO_ADD_TRIGGER;
1818 end;
1820 UndoBuffer[i, ii].AddID := ID;
1822 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1823 end;
1825 procedure FullClear();
1826 begin
1827 RemoveSelectFromObjects();
1828 ClearMap();
1829 LoadSky(gMapInfo.SkyName);
1830 UndoBuffer := nil;
1831 slInvalidTextures.Clear();
1832 MapCheckForm.lbErrorList.Clear();
1833 MapCheckForm.mErrorDescription.Clear();
1835 MainForm.miUndo.Enabled := False;
1836 MainForm.sbHorizontal.Position := 0;
1837 MainForm.sbVertical.Position := 0;
1838 MainForm.FormResize(nil);
1839 MainForm.Caption := FormCaption;
1840 OpenedMap := '';
1841 OpenedWAD := '';
1842 end;
1844 procedure ErrorMessageBox(str: String);
1845 begin
1846 MessageBox(0, PChar(str), PChar(_lc[I_MSG_ERROR]),
1847 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
1848 end;
1850 function CheckProperty(): Boolean;
1852 _id: Integer;
1853 begin
1854 Result := False;
1856 _id := GetFirstSelected();
1858 if SelectedObjects[_id].ObjectType = OBJECT_PANEL then
1859 with gPanels[SelectedObjects[_id].ID] do
1860 begin
1861 if TextureWidth <> 0 then
1862 if StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 1) mod TextureWidth <> 0 then
1863 begin
1864 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
1865 [TextureWidth]));
1866 Exit;
1867 end;
1869 if TextureHeight <> 0 then
1870 if StrToIntDef(Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]), 1) mod TextureHeight <> 0 then
1871 begin
1872 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
1873 [TextureHeight]));
1874 Exit;
1875 end;
1877 if IsTexturedPanel(PanelType) and (TextureName <> '') then
1878 if not (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]], -1) in [0..255]) then
1879 begin
1880 ErrorMessageBox(_lc[I_MSG_WRONG_ALPHA]);
1881 Exit;
1882 end;
1883 end;
1885 if SelectedObjects[_id].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
1886 if (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 0) <= 0) or
1887 (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]], 0) <= 0) then
1888 begin
1889 ErrorMessageBox(_lc[I_MSG_WRONG_SIZE]);
1890 Exit;
1891 end;
1893 if (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_X]]) = '') or
1894 (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_Y]]) = '') then
1895 begin
1896 ErrorMessageBox(_lc[I_MSG_WRONG_XY]);
1897 Exit;
1898 end;
1900 Result := True;
1901 end;
1903 procedure SelectTexture(ID: Integer);
1904 begin
1905 MainForm.lbTextureList.ItemIndex := ID;
1906 MainForm.lbTextureListClick(nil);
1907 end;
1909 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
1911 a, FrameLen: Integer;
1912 ok: Boolean;
1913 FileName: String;
1914 ResourceName: String;
1915 FullResourceName: String;
1916 SectionName: String;
1917 Data: Pointer;
1918 Width, Height: Word;
1919 fn: String;
1920 begin
1921 Data := nil;
1922 FrameLen := 0;
1923 Width := 0;
1924 Height := 0;
1926 if aSection = '..' then
1927 SectionName := ''
1928 else
1929 SectionName := aSection;
1931 if aWAD = '' then
1932 aWAD := _lc[I_WAD_SPECIAL_MAP];
1934 if aWAD = _lc[I_WAD_SPECIAL_MAP] then
1935 begin // Файл карты
1936 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
1937 //FileName := EditorDir+'maps\'+ExtractFileName(fn);
1938 FileName := fn;
1939 ResourceName := ':'+SectionName+'\'+aTex;
1941 else
1942 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1943 begin // Спец. текстуры
1944 FileName := '';
1945 ResourceName := aTex;
1947 else
1948 begin // Внешний WAD
1949 FileName := WadsDir + DirectorySeparator + aWAD;
1950 ResourceName := aWAD+':'+SectionName+'\'+aTex;
1951 end;
1953 ok := True;
1955 // Есть ли уже такая текстура:
1956 for a := 0 to MainForm.lbTextureList.Items.Count-1 do
1957 if ResourceName = MainForm.lbTextureList.Items[a] then
1958 begin
1959 if not silent then
1960 ErrorMessageBox(Format(_lc[I_MSG_TEXTURE_ALREADY],
1961 [ResourceName]));
1962 ok := False;
1963 end;
1965 // Название ресурса <= 64 символов:
1966 if Length(ResourceName) > 64 then
1967 begin
1968 if not silent then
1969 ErrorMessageBox(Format(_lc[I_MSG_RES_NAME_64],
1970 [ResourceName]));
1971 ok := False;
1972 end;
1974 if ok then
1975 begin
1976 a := -1;
1977 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1978 begin
1979 a := MainForm.lbTextureList.Items.Add(ResourceName);
1980 if not silent then
1981 SelectTexture(a);
1982 Result := True;
1983 Exit;
1984 end;
1986 FullResourceName := FileName+':'+SectionName+'\'+aTex;
1988 if IsAnim(FullResourceName) then
1989 begin // Аним. текстура
1990 GetFrame(FullResourceName, Data, FrameLen, Width, Height);
1992 if not g_CreateTextureMemorySize(Data, FrameLen, ResourceName, 0, 0, Width, Height, 1) then
1993 ok := False;
1994 a := MainForm.lbTextureList.Items.Add(ResourceName);
1996 else // Обычная текстура
1997 begin
1998 if not g_CreateTextureWAD(ResourceName, FullResourceName) then
1999 ok := False;
2000 a := MainForm.lbTextureList.Items.Add(ResourceName);
2001 end;
2002 if (not ok) and (slInvalidTextures.IndexOf(ResourceName) = -1) then
2003 begin
2004 slInvalidTextures.Add(ResourceName);
2005 ok := True;
2006 end;
2007 if (a > -1) and (not silent) then
2008 SelectTexture(a);
2009 end;
2011 Result := ok;
2012 end;
2014 procedure UpdateCaption(sMap, sFile, sRes: String);
2015 begin
2016 with MainForm do
2017 if (sFile = '') and (sRes = '') and (sMap = '') then
2018 Caption := FormCaption
2019 else
2020 if sMap = '' then
2021 Caption := Format('%s - %s:%s', [FormCaption, sFile, sRes])
2022 else
2023 if (sFile <> '') and (sRes <> '') then
2024 Caption := Format('%s - %s (%s:%s)', [FormCaption, sMap, sFile, sRes])
2025 else
2026 Caption := Format('%s - %s', [FormCaption, sMap]);
2027 end;
2029 procedure OpenMap(FileName: String; mapN: String);
2031 MapName: String;
2032 idx: Integer;
2033 begin
2034 SelectMapForm.Caption := _lc[I_CAP_OPEN];
2035 SelectMapForm.GetMaps(FileName);
2037 if (FileName = OpenedWAD) and
2038 (OpenedMap <> '') then
2039 begin
2040 MapName := OpenedMap;
2041 while (Pos(':\', MapName) > 0) do
2042 Delete(MapName, 1, Pos(':\', MapName) + 1);
2044 idx := SelectMapForm.lbMapList.Items.IndexOf(MapName);
2045 SelectMapForm.lbMapList.ItemIndex := idx;
2047 else
2048 if SelectMapForm.lbMapList.Count > 0 then
2049 SelectMapForm.lbMapList.ItemIndex := 0
2050 else
2051 SelectMapForm.lbMapList.ItemIndex := -1;
2053 if mapN = '' then
2054 idx := -1
2055 else
2056 idx := SelectMapForm.lbMapList.Items.IndexOf(mapN);
2058 if idx < 0 then
2059 begin
2060 if (SelectMapForm.ShowModal() = mrOK) and
2061 (SelectMapForm.lbMapList.ItemIndex <> -1) then
2062 idx := SelectMapForm.lbMapList.ItemIndex
2063 else
2064 Exit;
2065 end;
2067 MapName := SelectMapForm.lbMapList.Items[idx];
2069 with MainForm do
2070 begin
2071 FullClear();
2073 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
2074 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
2075 pLoadProgress.Show();
2077 OpenedMap := FileName+':\'+MapName;
2078 OpenedWAD := FileName;
2080 idx := RecentFiles.IndexOf(OpenedMap);
2081 // Такая карта уже недавно открывалась:
2082 if idx >= 0 then
2083 RecentFiles.Delete(idx);
2084 RecentFiles.Insert(0, OpenedMap);
2085 RefreshRecentMenu();
2087 LoadMap(OpenedMap);
2089 pLoadProgress.Hide();
2090 FormResize(nil);
2092 lbTextureList.Sorted := True;
2093 lbTextureList.Sorted := False;
2095 UpdateCaption(gMapInfo.Name, ExtractFileName(FileName), MapName);
2096 end;
2097 end;
2099 procedure MoveSelectedObjects(Wall, alt: Boolean; dx, dy: Integer);
2101 okX, okY: Boolean;
2102 a: Integer;
2103 begin
2104 if SelectedObjects = nil then
2105 Exit;
2107 okX := True;
2108 okY := True;
2110 if Wall then
2111 for a := 0 to High(SelectedObjects) do
2112 if SelectedObjects[a].Live then
2113 begin
2114 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, dx, 0) then
2115 okX := False;
2117 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, 0, dy) then
2118 okY := False;
2120 if (not okX) or (not okY) then
2121 Break;
2122 end;
2124 if okX or okY then
2125 begin
2126 for a := 0 to High(SelectedObjects) do
2127 if SelectedObjects[a].Live then
2128 begin
2129 if okX then
2130 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, dx, 0);
2132 if okY then
2133 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, 0, dy);
2135 if alt and (SelectedObjects[a].ObjectType = OBJECT_TRIGGER) then
2136 begin
2137 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_PRESS,
2138 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
2139 begin // Двигаем зону Расширителя
2140 if okX then
2141 gTriggers[SelectedObjects[a].ID].Data.tX := gTriggers[SelectedObjects[a].ID].Data.tX+dx;
2142 if okY then
2143 gTriggers[SelectedObjects[a].ID].Data.tY := gTriggers[SelectedObjects[a].ID].Data.tY+dy;
2144 end;
2146 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_TELEPORT] then
2147 begin // Двигаем точку назначения Телепорта
2148 if okX then
2149 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X+dx;
2150 if okY then
2151 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y+dy;
2152 end;
2154 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNMONSTER] then
2155 begin // Двигаем точку создания монстра
2156 if okX then
2157 gTriggers[SelectedObjects[a].ID].Data.MonPos.X := gTriggers[SelectedObjects[a].ID].Data.MonPos.X+dx;
2158 if okY then
2159 gTriggers[SelectedObjects[a].ID].Data.MonPos.Y := gTriggers[SelectedObjects[a].ID].Data.MonPos.Y+dy;
2160 end;
2162 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNITEM] then
2163 begin // Двигаем точку создания предмета
2164 if okX then
2165 gTriggers[SelectedObjects[a].ID].Data.ItemPos.X := gTriggers[SelectedObjects[a].ID].Data.ItemPos.X+dx;
2166 if okY then
2167 gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y := gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y+dy;
2168 end;
2170 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SHOT] then
2171 begin // Двигаем точку создания выстрела
2172 if okX then
2173 gTriggers[SelectedObjects[a].ID].Data.ShotPos.X := gTriggers[SelectedObjects[a].ID].Data.ShotPos.X+dx;
2174 if okY then
2175 gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y := gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y+dy;
2176 end;
2177 end;
2178 end;
2180 LastMovePoint := MousePos;
2181 end;
2182 end;
2184 procedure ShowLayer(Layer: Byte; show: Boolean);
2185 begin
2186 LayerEnabled[Layer] := show;
2188 case Layer of
2189 LAYER_BACK:
2190 begin
2191 MainForm.miLayer1.Checked := show;
2192 MainForm.miLayerP1.Checked := show;
2193 end;
2194 LAYER_WALLS:
2195 begin
2196 MainForm.miLayer2.Checked := show;
2197 MainForm.miLayerP2.Checked := show;
2198 end;
2199 LAYER_FOREGROUND:
2200 begin
2201 MainForm.miLayer3.Checked := show;
2202 MainForm.miLayerP3.Checked := show;
2203 end;
2204 LAYER_STEPS:
2205 begin
2206 MainForm.miLayer4.Checked := show;
2207 MainForm.miLayerP4.Checked := show;
2208 end;
2209 LAYER_WATER:
2210 begin
2211 MainForm.miLayer5.Checked := show;
2212 MainForm.miLayerP5.Checked := show;
2213 end;
2214 LAYER_ITEMS:
2215 begin
2216 MainForm.miLayer6.Checked := show;
2217 MainForm.miLayerP6.Checked := show;
2218 end;
2219 LAYER_MONSTERS:
2220 begin
2221 MainForm.miLayer7.Checked := show;
2222 MainForm.miLayerP7.Checked := show;
2223 end;
2224 LAYER_AREAS:
2225 begin
2226 MainForm.miLayer8.Checked := show;
2227 MainForm.miLayerP8.Checked := show;
2228 end;
2229 LAYER_TRIGGERS:
2230 begin
2231 MainForm.miLayer9.Checked := show;
2232 MainForm.miLayerP9.Checked := show;
2233 end;
2234 end;
2236 RemoveSelectFromObjects();
2237 end;
2239 procedure SwitchLayer(Layer: Byte);
2240 begin
2241 ShowLayer(Layer, not LayerEnabled[Layer]);
2242 end;
2244 procedure SwitchMap();
2245 begin
2246 ShowMap := not ShowMap;
2247 MainForm.tbShowMap.Down := ShowMap;
2248 end;
2250 procedure ShowEdges();
2251 begin
2252 if drEdge[3] < 255 then
2253 drEdge[3] := 255
2254 else
2255 drEdge[3] := gAlphaEdge;
2256 end;
2258 function SelectedTexture(): String;
2259 begin
2260 if MainForm.lbTextureList.ItemIndex <> -1 then
2261 Result := MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]
2262 else
2263 Result := '';
2264 end;
2266 function IsSpecialTextureSel(): Boolean;
2267 begin
2268 Result := (MainForm.lbTextureList.ItemIndex <> -1) and
2269 IsSpecialTexture(MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]);
2270 end;
2272 function CopyBufferToString(var CopyBuf: TCopyRecArray): String;
2274 i, j: Integer;
2275 Res: String;
2277 procedure AddInt(x: Integer);
2278 begin
2279 Res := Res + IntToStr(x) + ' ';
2280 end;
2282 begin
2283 Result := '';
2285 if Length(CopyBuf) = 0 then
2286 Exit;
2288 Res := CLIPBOARD_SIG + ' ';
2290 for i := 0 to High(CopyBuf) do
2291 begin
2292 if (CopyBuf[i].ObjectType = OBJECT_PANEL) and
2293 (CopyBuf[i].Panel = nil) then
2294 Continue;
2296 // Тип объекта:
2297 AddInt(CopyBuf[i].ObjectType);
2298 Res := Res + '; ';
2300 // Свойства объекта:
2301 case CopyBuf[i].ObjectType of
2302 OBJECT_PANEL:
2303 with CopyBuf[i].Panel^ do
2304 begin
2305 AddInt(PanelType);
2306 AddInt(X);
2307 AddInt(Y);
2308 AddInt(Width);
2309 AddInt(Height);
2310 Res := Res + '"' + TextureName + '" ';
2311 AddInt(Alpha);
2312 AddInt(IfThen(Blending, 1, 0));
2313 end;
2315 OBJECT_ITEM:
2316 with CopyBuf[i].Item do
2317 begin
2318 AddInt(ItemType);
2319 AddInt(X);
2320 AddInt(Y);
2321 AddInt(IfThen(OnlyDM, 1, 0));
2322 AddInt(IfThen(Fall, 1, 0));
2323 end;
2325 OBJECT_MONSTER:
2326 with CopyBuf[i].Monster do
2327 begin
2328 AddInt(MonsterType);
2329 AddInt(X);
2330 AddInt(Y);
2331 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2332 end;
2334 OBJECT_AREA:
2335 with CopyBuf[i].Area do
2336 begin
2337 AddInt(AreaType);
2338 AddInt(X);
2339 AddInt(Y);
2340 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2341 end;
2343 OBJECT_TRIGGER:
2344 with CopyBuf[i].Trigger do
2345 begin
2346 AddInt(TriggerType);
2347 AddInt(X);
2348 AddInt(Y);
2349 AddInt(Width);
2350 AddInt(Height);
2351 AddInt(ActivateType);
2352 AddInt(Key);
2353 AddInt(IfThen(Enabled, 1, 0));
2354 AddInt(TexturePanel);
2356 for j := 0 to 127 do
2357 AddInt(Data.Default[j]);
2358 end;
2359 end;
2360 end;
2362 Result := Res;
2363 end;
2365 procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray;
2366 var pmin: TPoint);
2368 i, j, t: Integer;
2370 function GetNext(): String;
2372 p: Integer;
2374 begin
2375 if Str[1] = '"' then
2376 begin
2377 Delete(Str, 1, 1);
2378 p := Pos('"', Str);
2380 if p = 0 then
2381 begin
2382 Result := Str;
2383 Str := '';
2385 else
2386 begin
2387 Result := Copy(Str, 1, p-1);
2388 Delete(Str, 1, p);
2389 Str := Trim(Str);
2390 end;
2392 else
2393 begin
2394 p := Pos(' ', Str);
2396 if p = 0 then
2397 begin
2398 Result := Str;
2399 Str := '';
2401 else
2402 begin
2403 Result := Copy(Str, 1, p-1);
2404 Delete(Str, 1, p);
2405 Str := Trim(Str);
2406 end;
2407 end;
2408 end;
2410 begin
2411 Str := Trim(Str);
2413 if GetNext() <> CLIPBOARD_SIG then
2414 Exit;
2416 while Str <> '' do
2417 begin
2418 // Тип объекта:
2419 t := StrToIntDef(GetNext(), 0);
2421 if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or
2422 (GetNext() <> ';') then
2423 begin // Что-то не то => пропускаем:
2424 t := Pos(';', Str);
2425 Delete(Str, 1, t);
2426 Str := Trim(Str);
2428 Continue;
2429 end;
2431 i := Length(CopyBuf);
2432 SetLength(CopyBuf, i + 1);
2434 CopyBuf[i].ObjectType := t;
2435 CopyBuf[i].Panel := nil;
2437 // Свойства объекта:
2438 case t of
2439 OBJECT_PANEL:
2440 begin
2441 New(CopyBuf[i].Panel);
2443 with CopyBuf[i].Panel^ do
2444 begin
2445 PanelType := StrToIntDef(GetNext(), PANEL_WALL);
2446 X := StrToIntDef(GetNext(), 0);
2447 Y := StrToIntDef(GetNext(), 0);
2448 pmin.X := Min(X, pmin.X);
2449 pmin.Y := Min(Y, pmin.Y);
2450 Width := StrToIntDef(GetNext(), 16);
2451 Height := StrToIntDef(GetNext(), 16);
2452 TextureName := GetNext();
2453 Alpha := StrToIntDef(GetNext(), 0);
2454 Blending := (GetNext() = '1');
2455 end;
2456 end;
2458 OBJECT_ITEM:
2459 with CopyBuf[i].Item do
2460 begin
2461 ItemType := StrToIntDef(GetNext(), ITEM_MEDKIT_SMALL);
2462 X := StrToIntDef(GetNext(), 0);
2463 Y := StrToIntDef(GetNext(), 0);
2464 pmin.X := Min(X, pmin.X);
2465 pmin.Y := Min(Y, pmin.Y);
2466 OnlyDM := (GetNext() = '1');
2467 Fall := (GetNext() = '1');
2468 end;
2470 OBJECT_MONSTER:
2471 with CopyBuf[i].Monster do
2472 begin
2473 MonsterType := StrToIntDef(GetNext(), MONSTER_DEMON);
2474 X := StrToIntDef(GetNext(), 0);
2475 Y := StrToIntDef(GetNext(), 0);
2476 pmin.X := Min(X, pmin.X);
2477 pmin.Y := Min(Y, pmin.Y);
2479 if GetNext() = '1' then
2480 Direction := D_LEFT
2481 else
2482 Direction := D_RIGHT;
2483 end;
2485 OBJECT_AREA:
2486 with CopyBuf[i].Area do
2487 begin
2488 AreaType := StrToIntDef(GetNext(), AREA_PLAYERPOINT1);
2489 X := StrToIntDef(GetNext(), 0);
2490 Y := StrToIntDef(GetNext(), 0);
2491 pmin.X := Min(X, pmin.X);
2492 pmin.Y := Min(Y, pmin.Y);
2493 if GetNext() = '1' then
2494 Direction := D_LEFT
2495 else
2496 Direction := D_RIGHT;
2497 end;
2499 OBJECT_TRIGGER:
2500 with CopyBuf[i].Trigger do
2501 begin
2502 TriggerType := StrToIntDef(GetNext(), TRIGGER_EXIT);
2503 X := StrToIntDef(GetNext(), 0);
2504 Y := StrToIntDef(GetNext(), 0);
2505 pmin.X := Min(X, pmin.X);
2506 pmin.Y := Min(Y, pmin.Y);
2507 Width := StrToIntDef(GetNext(), 16);
2508 Height := StrToIntDef(GetNext(), 16);
2509 ActivateType := StrToIntDef(GetNext(), 0);
2510 Key := StrToIntDef(GetNext(), 0);
2511 Enabled := (GetNext() = '1');
2512 TexturePanel := StrToIntDef(GetNext(), 0);
2514 for j := 0 to 127 do
2515 Data.Default[j] := StrToIntDef(GetNext(), 0);
2517 case TriggerType of
2518 TRIGGER_TELEPORT:
2519 begin
2520 pmin.X := Min(Data.TargetPoint.X, pmin.X);
2521 pmin.Y := Min(Data.TargetPoint.Y, pmin.Y);
2522 end;
2523 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
2524 begin
2525 pmin.X := Min(Data.tX, pmin.X);
2526 pmin.Y := Min(Data.tY, pmin.Y);
2527 end;
2528 TRIGGER_SPAWNMONSTER:
2529 begin
2530 pmin.X := Min(Data.MonPos.X, pmin.X);
2531 pmin.Y := Min(Data.MonPos.Y, pmin.Y);
2532 end;
2533 TRIGGER_SPAWNITEM:
2534 begin
2535 pmin.X := Min(Data.ItemPos.X, pmin.X);
2536 pmin.Y := Min(Data.ItemPos.Y, pmin.Y);
2537 end;
2538 TRIGGER_SHOT:
2539 begin
2540 pmin.X := Min(Data.ShotPos.X, pmin.X);
2541 pmin.Y := Min(Data.ShotPos.Y, pmin.Y);
2542 end;
2543 end;
2544 end;
2545 end;
2546 end;
2547 end;
2549 //----------------------------------------
2550 //Закончились вспомогательные процедуры
2551 //----------------------------------------
2553 procedure TMainForm.RefreshRecentMenu();
2555 i: Integer;
2556 MI: TMenuItem;
2557 begin
2558 // Лишние запомненные карты:
2559 while RecentFiles.Count > RecentCount do
2560 RecentFiles.Delete(RecentFiles.Count-1);
2562 // Лишние строки меню:
2563 while MainMenu.Items[0].Count > RECENT_FILES_MENU_START do
2564 MainMenu.Items[0].Delete(MainMenu.Items[0].Count-1);
2566 // Отделение списка карт от строки "Выход":
2567 if RecentFiles.Count > 0 then
2568 begin
2569 MI := TMenuItem.Create(MainMenu.Items[0]);
2570 MI.Caption := '-';
2571 MainMenu.Items[0].Add(MI);
2572 end;
2574 // Добавление в меню списка запомненных карт:
2575 for i := 0 to RecentFiles.Count-1 do
2576 begin
2577 MI := TMenuItem.Create(MainMenu.Items[0]);
2578 MI.Caption := IntToStr(i+1) + ' ' + RecentFiles[i];
2579 MI.OnClick := aRecentFileExecute;
2580 MainMenu.Items[0].Add(MI);
2581 end;
2582 end;
2584 procedure TMainForm.aRecentFileExecute(Sender: TObject);
2586 n: Integer;
2587 fn, s: String;
2588 begin
2589 s := LowerCase((Sender as TMenuItem).Caption);
2590 Delete(s, Pos('&', s), 1);
2591 s := Trim(Copy(s, 1, 2));
2592 n := StrToIntDef(s, 0) - 1;
2593 if (n >= 0) and (n <= RecentFiles.Count) then
2594 begin
2595 fn := g_ExtractWadName(RecentFiles[n]);
2596 if FileExists(fn) then
2597 begin
2598 s := g_ExtractFilePathName(RecentFiles[n]);
2599 OpenMap(fn, s)
2601 else if MessageBox(0, PChar(_lc[I_MSG_DEL_RECENT_PROMT]), PChar(_lc[I_MSG_DEL_RECENT]), MB_ICONQUESTION or MB_YESNO) = idYes then
2602 begin
2603 RecentFiles.Delete(n);
2604 RefreshRecentMenu();
2607 end;
2609 procedure TMainForm.aEditorOptionsExecute(Sender: TObject);
2610 begin
2611 OptionsForm.ShowModal();
2612 end;
2614 procedure LoadStdFont(cfgres, texture: string; var FontID: DWORD);
2616 cwdt, chgt: Byte;
2617 spc: ShortInt;
2618 ID: DWORD;
2619 cfgdata: Pointer;
2620 cfglen: Integer;
2621 config: TConfig;
2622 begin
2623 ID := 0;
2624 g_ReadResource(GameWad, 'FONTS', cfgres, cfgdata, cfglen);
2625 if cfgdata <> nil then
2626 begin
2627 if not g_CreateTextureWAD('FONT_STD', GameWad + ':FONTS\' + texture) then
2628 e_WriteLog('ERROR ERROR ERROR', MSG_WARNING);
2630 config := TConfig.CreateMem(cfgdata, cfglen);
2631 cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
2632 chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
2633 spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
2635 if g_GetTexture('FONT_STD', ID) then
2636 e_TextureFontBuild(ID, FontID, cwdt, chgt, spc - 2);
2638 config.Free();
2639 FreeMem(cfgdata)
2641 else
2642 begin
2643 e_WriteLog('Could not load FONT_STD', MSG_WARNING)
2645 end;
2647 procedure TMainForm.FormCreate(Sender: TObject);
2649 config: TConfig;
2650 i: Integer;
2651 s: String;
2652 begin
2653 Randomize();
2655 e_WriteLog('Doom 2D: Forever Editor version ' + EDITOR_VERSION, MSG_NOTIFY);
2656 e_WriteLog('Build date: ' + EDITOR_BUILDDATE + ' ' + EDITOR_BUILDTIME, MSG_NOTIFY);
2657 e_WriteLog('Build hash: ' + g_GetBuildHash(), MSG_NOTIFY);
2658 e_WriteLog('Build by: ' + g_GetBuilderName(), MSG_NOTIFY);
2660 slInvalidTextures := TStringList.Create;
2662 ShowLayer(LAYER_BACK, True);
2663 ShowLayer(LAYER_WALLS, True);
2664 ShowLayer(LAYER_FOREGROUND, True);
2665 ShowLayer(LAYER_STEPS, True);
2666 ShowLayer(LAYER_WATER, True);
2667 ShowLayer(LAYER_ITEMS, True);
2668 ShowLayer(LAYER_MONSTERS, True);
2669 ShowLayer(LAYER_AREAS, True);
2670 ShowLayer(LAYER_TRIGGERS, True);
2672 ClearMap();
2674 FormCaption := MainForm.Caption;
2675 OpenedMap := '';
2676 OpenedWAD := '';
2678 config := TConfig.CreateFile(CfgFileName);
2680 if config.ReadInt('Editor', 'XPos', -1) = -1 then
2681 Position := poDesktopCenter
2682 else begin
2683 Left := config.ReadInt('Editor', 'XPos', Left);
2684 Top := config.ReadInt('Editor', 'YPos', Top);
2685 Width := config.ReadInt('Editor', 'Width', Width);
2686 Height := config.ReadInt('Editor', 'Height', Height);
2687 end;
2688 if config.ReadBool('Editor', 'Maximize', False) then
2689 WindowState := wsMaximized;
2690 ShowMap := config.ReadBool('Editor', 'Minimap', False);
2691 PanelProps.Width := config.ReadInt('Editor', 'PanelProps', PanelProps.ClientWidth);
2692 Splitter1.Left := PanelProps.Left;
2693 PanelObjs.Height := config.ReadInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
2694 Splitter2.Top := PanelObjs.Top;
2695 StatusBar.Top := PanelObjs.BoundsRect.Bottom;
2696 DotEnable := config.ReadBool('Editor', 'DotEnable', True);
2697 DotColor := config.ReadInt('Editor', 'DotColor', $FFFFFF);
2698 DotStepOne := config.ReadInt('Editor', 'DotStepOne', 16);
2699 DotStepTwo := config.ReadInt('Editor', 'DotStepTwo', 8);
2700 DotStep := config.ReadInt('Editor', 'DotStep', DotStepOne);
2701 DrawTexturePanel := config.ReadBool('Editor', 'DrawTexturePanel', True);
2702 DrawPanelSize := config.ReadBool('Editor', 'DrawPanelSize', True);
2703 BackColor := config.ReadInt('Editor', 'BackColor', $7F6040);
2704 PreviewColor := config.ReadInt('Editor', 'PreviewColor', $00FF00);
2705 UseCheckerboard := config.ReadBool('Editor', 'UseCheckerboard', True);
2706 gColorEdge := config.ReadInt('Editor', 'EdgeColor', COLOR_EDGE);
2707 gAlphaEdge := config.ReadInt('Editor', 'EdgeAlpha', ALPHA_EDGE);
2708 if gAlphaEdge = 255 then
2709 gAlphaEdge := ALPHA_EDGE;
2710 drEdge[0] := GetRValue(gColorEdge);
2711 drEdge[1] := GetGValue(gColorEdge);
2712 drEdge[2] := GetBValue(gColorEdge);
2713 if not config.ReadBool('Editor', 'EdgeShow', True) then
2714 drEdge[3] := 255
2715 else
2716 drEdge[3] := gAlphaEdge;
2717 gAlphaTriggerLine := config.ReadInt('Editor', 'LineAlpha', ALPHA_LINE);
2718 if gAlphaTriggerLine = 255 then
2719 gAlphaTriggerLine := ALPHA_LINE;
2720 gAlphaTriggerArea := config.ReadInt('Editor', 'TriggerAlpha', ALPHA_AREA);
2721 if gAlphaTriggerArea = 255 then
2722 gAlphaTriggerArea := ALPHA_AREA;
2723 gAlphaMonsterRect := config.ReadInt('Editor', 'MonsterRectAlpha', 0);
2724 gAlphaAreaRect := config.ReadInt('Editor', 'AreaRectAlpha', 0);
2725 if config.ReadInt('Editor', 'Scale', 0) = 1 then
2726 Scale := 2
2727 else
2728 Scale := 1;
2729 if config.ReadInt('Editor', 'DotSize', 0) = 1 then
2730 DotSize := 2
2731 else
2732 DotSize := 1;
2733 OpenDialog.InitialDir := config.ReadStr('Editor', 'LastOpenDir', EditorDir);
2734 SaveDialog.InitialDir := config.ReadStr('Editor', 'LastSaveDir', EditorDir);
2736 s := config.ReadStr('Editor', 'Language', '');
2737 gLanguage := s;
2739 Compress := config.ReadBool('Editor', 'Compress', True);
2740 Backup := config.ReadBool('Editor', 'Backup', True);
2742 RecentCount := config.ReadInt('Editor', 'RecentCount', 5);
2743 if RecentCount > 10 then
2744 RecentCount := 10;
2745 if RecentCount < 2 then
2746 RecentCount := 2;
2748 RecentFiles := TStringList.Create();
2749 for i := 0 to RecentCount-1 do
2750 begin
2751 s := config.ReadStr('RecentFiles', IntToStr(i+1), '');
2752 if s <> '' then
2753 RecentFiles.Add(s);
2754 end;
2755 RefreshRecentMenu();
2757 config.Free();
2759 tbShowMap.Down := ShowMap;
2760 tbGridOn.Down := DotEnable;
2761 pcObjects.ActivePageIndex := 0;
2762 Application.Title := _lc[I_EDITOR_TITLE];
2764 Application.OnIdle := OnIdle;
2765 end;
2767 procedure PrintBlack(X, Y: Integer; Text: string; FontID: DWORD);
2768 begin
2769 // NOTE: all the font printing routines assume CP1251
2770 e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0);
2771 end;
2773 procedure TMainForm.Draw();
2775 x, y: Integer;
2776 a, b: Integer;
2777 ID, PID: DWORD;
2778 Width, Height: Word;
2779 Rect: TRectWH;
2780 ObjCount: Word;
2781 aX, aY, aX2, aY2, XX, ScaleSz: Integer;
2782 begin
2783 ID := 0;
2784 PID := 0;
2785 Width := 0;
2786 Height := 0;
2788 e_BeginRender();
2790 e_Clear(GL_COLOR_BUFFER_BIT,
2791 GetRValue(BackColor)/255,
2792 GetGValue(BackColor)/255,
2793 GetBValue(BackColor)/255);
2795 DrawMap();
2797 ObjCount := SelectedObjectCount();
2799 // Обводим выделенные объекты красной рамкой:
2800 if ObjCount > 0 then
2801 begin
2802 for a := 0 to High(SelectedObjects) do
2803 if SelectedObjects[a].Live then
2804 begin
2805 Rect := ObjectGetRect(SelectedObjects[a].ObjectType, SelectedObjects[a].ID);
2807 with Rect do
2808 begin
2809 e_DrawQuad(X+MapOffset.X, Y+MapOffset.Y,
2810 X+MapOffset.X+Width-1, Y+MapOffset.Y+Height-1,
2811 255, 0, 0);
2813 // Рисуем точки изменения размеров:
2814 if (ObjCount = 1) and
2815 (SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) then
2816 begin
2817 e_DrawPoint(5, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2818 e_DrawPoint(5, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2819 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 255, 255);
2820 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 255, 255);
2822 e_DrawPoint(3, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2823 e_DrawPoint(3, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2824 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 0, 0);
2825 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 0, 0);
2826 end;
2827 end;
2828 end;
2829 end;
2831 // Рисуем сетку:
2832 if DotEnable and (PreviewMode = 0) then
2833 begin
2834 if DotSize = 2 then
2835 a := -1
2836 else
2837 a := 0;
2839 x := MapOffset.X mod DotStep;
2840 y := MapOffset.Y mod DotStep;
2842 while x < RenderPanel.Width do
2843 begin
2844 while y < RenderPanel.Height do
2845 begin
2846 e_DrawPoint(DotSize, x + a, y + a,
2847 GetRValue(DotColor),
2848 GetGValue(DotColor),
2849 GetBValue(DotColor));
2850 y += DotStep;
2851 end;
2852 x += DotStep;
2853 y := MapOffset.Y mod DotStep;
2854 end;
2855 end;
2857 // Превью текстуры:
2858 if (lbTextureList.ItemIndex <> -1) and (cbPreview.Checked) and
2859 (not IsSpecialTextureSel()) and (PreviewMode = 0) then
2860 begin
2861 if not g_GetTexture(SelectedTexture(), ID) then
2862 g_GetTexture('NOTEXTURE', ID);
2863 g_GetTextureSizeByID(ID, Width, Height);
2864 if UseCheckerboard then
2865 begin
2866 if g_GetTexture('PREVIEW', PID) then
2867 e_DrawFill(PID, RenderPanel.Width-Width, RenderPanel.Height-Height, Width div 16 + 1, Height div 16 + 1, 0, True, False);
2868 end else
2869 e_DrawFillQuad(RenderPanel.Width-Width-2, RenderPanel.Height-Height-2,
2870 RenderPanel.Width-1, RenderPanel.Height-1,
2871 GetRValue(PreviewColor), GetGValue(PreviewColor), GetBValue(PreviewColor), 0);
2872 e_Draw(ID, RenderPanel.Width-Width, RenderPanel.Height-Height, 0, True, False);
2873 end;
2875 // Подсказка при выборе точки Телепорта:
2876 if SelectFlag = SELECTFLAG_TELEPORT then
2877 begin
2878 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
2879 if Data.d2d_teleport then
2880 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2881 MousePos.X+16, MousePos.Y-1,
2882 0, 0, 255)
2883 else
2884 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+AreaSize[AREA_DMPOINT].Width-1,
2885 MousePos.Y+AreaSize[AREA_DMPOINT].Height-1, 255, 255, 255);
2887 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2888 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2889 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_TELEPORT], gEditorFont);
2890 end;
2892 // Подсказка при выборе точки появления:
2893 if SelectFlag = SELECTFLAG_SPAWNPOINT then
2894 begin
2895 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2896 MousePos.X+16, MousePos.Y-1,
2897 0, 0, 255);
2898 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2899 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2900 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_SPAWN], gEditorFont);
2901 end;
2903 // Подсказка при выборе панели двери:
2904 if SelectFlag = SELECTFLAG_DOOR then
2905 begin
2906 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2907 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2908 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_DOOR], gEditorFont);
2909 end;
2911 // Подсказка при выборе панели с текстурой:
2912 if SelectFlag = SELECTFLAG_TEXTURE then
2913 begin
2914 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 192, 192, 192, 127);
2915 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 255, 255, 255);
2916 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_TEXTURE], gEditorFont);
2917 end;
2919 // Подсказка при выборе панели индикации выстрела:
2920 if SelectFlag = SELECTFLAG_SHOTPANEL then
2921 begin
2922 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 192, 192, 192, 127);
2923 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 255, 255, 255);
2924 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_SHOT], gEditorFont);
2925 end;
2927 // Подсказка при выборе панели лифта:
2928 if SelectFlag = SELECTFLAG_LIFT then
2929 begin
2930 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2931 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2932 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_LIFT], gEditorFont);
2933 end;
2935 // Подсказка при выборе монстра:
2936 if SelectFlag = SELECTFLAG_MONSTER then
2937 begin
2938 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 192, 192, 192, 127);
2939 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 255, 255, 255);
2940 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_MONSTER], gEditorFont);
2941 end;
2943 // Подсказка при выборе области воздействия:
2944 if DrawPressRect then
2945 begin
2946 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 192, 192, 192, 127);
2947 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 255, 255, 255);
2948 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_EXT_AREA], gEditorFont);
2949 end;
2951 // Рисуем текстуры, если чертим панель:
2952 if (MouseAction = MOUSEACTION_DRAWPANEL) and (DrawTexturePanel) and
2953 (lbTextureList.ItemIndex <> -1) and (DrawRect <> nil) and
2954 (lbPanelType.ItemIndex in [0..8]) and not IsSpecialTextureSel() then
2955 begin
2956 if not g_GetTexture(SelectedTexture(), ID) then
2957 g_GetTexture('NOTEXTURE', ID);
2958 g_GetTextureSizeByID(ID, Width, Height);
2959 with DrawRect^ do
2960 if (Abs(Right-Left) >= Width) and (Abs(Bottom-Top) >= Height) then
2961 e_DrawFill(ID, Min(Left, Right), Min(Top, Bottom), Abs(Right-Left) div Width,
2962 Abs(Bottom-Top) div Height, 64, True, False);
2963 end;
2965 // Прямоугольник выделения:
2966 if DrawRect <> nil then
2967 with DrawRect^ do
2968 e_DrawQuad(Left, Top, Right-1, Bottom-1, 255, 255, 255);
2970 // Чертим мышью панель/триггер или меняем мышью их размер:
2971 if (((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
2972 not(ssCtrl in GetKeyShiftState())) or (MouseAction = MOUSEACTION_RESIZE)) and
2973 (DrawPanelSize) then
2974 begin
2975 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 192, 192, 192, 127);
2976 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 255, 255, 255);
2978 if MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER] then
2979 begin // Чертим новый
2980 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH],
2981 [Abs(MousePos.X-MouseLDownPos.X)]), gEditorFont);
2982 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(_glc[I_HINT_HEIGHT],
2983 [Abs(MousePos.Y-MouseLDownPos.Y)]), gEditorFont);
2985 else // Растягиваем существующий
2986 if SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
2987 begin
2988 if SelectedObjects[GetFirstSelected].ObjectType = OBJECT_PANEL then
2989 begin
2990 Width := gPanels[SelectedObjects[GetFirstSelected].ID].Width;
2991 Height := gPanels[SelectedObjects[GetFirstSelected].ID].Height;
2993 else
2994 begin
2995 Width := gTriggers[SelectedObjects[GetFirstSelected].ID].Width;
2996 Height := gTriggers[SelectedObjects[GetFirstSelected].ID].Height;
2997 end;
2999 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH], [Width]),
3000 gEditorFont);
3001 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(_glc[I_HINT_HEIGHT], [Height]),
3002 gEditorFont);
3003 end;
3004 end;
3006 // Ближайшая к курсору мыши точка на сетке:
3007 e_DrawPoint(3, MousePos.X, MousePos.Y, 0, 0, 255);
3009 // Мини-карта:
3010 if ShowMap then
3011 begin
3012 // Сколько пикселов карты в 1 пикселе мини-карты:
3013 ScaleSz := 16 div Scale;
3014 // Размеры мини-карты:
3015 aX := max(gMapInfo.Width div ScaleSz, 1);
3016 aY := max(gMapInfo.Height div ScaleSz, 1);
3017 // X-координата на RenderPanel нулевой x-координаты карты:
3018 XX := RenderPanel.Width - aX - 1;
3019 // Рамка карты:
3020 e_DrawFillQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 0, 0, 0, 0);
3021 e_DrawQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 197, 197, 197);
3023 if gPanels <> nil then
3024 begin
3025 // Рисуем панели:
3026 for a := 0 to High(gPanels) do
3027 with gPanels[a] do
3028 if PanelType <> 0 then
3029 begin
3030 // Левый верхний угол:
3031 aX := XX + (X div ScaleSz);
3032 aY := 1 + (Y div ScaleSz);
3033 // Размеры:
3034 aX2 := max(Width div ScaleSz, 1);
3035 aY2 := max(Height div ScaleSz, 1);
3036 // Правый нижний угол:
3037 aX2 := aX + aX2 - 1;
3038 aY2 := aY + aY2 - 1;
3040 case PanelType of
3041 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3042 PANEL_WATER: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3043 PANEL_ACID1: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3044 PANEL_ACID2: e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3045 PANEL_STEP: e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3046 PANEL_LIFTUP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3047 PANEL_LIFTDOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3048 PANEL_LIFTLEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3049 PANEL_LIFTRIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3050 PANEL_OPENDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 100, 220, 92, 0);
3051 PANEL_CLOSEDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 212, 184, 64, 0);
3052 PANEL_BLOCKMON: e_DrawFillQuad(aX, aY, aX2, aY2, 192, 0, 192, 0);
3053 end;
3054 end;
3056 // Рисуем красным выделенные панели:
3057 if SelectedObjects <> nil then
3058 for b := 0 to High(SelectedObjects) do
3059 with SelectedObjects[b] do
3060 if Live and (ObjectType = OBJECT_PANEL) then
3061 with gPanels[SelectedObjects[b].ID] do
3062 if PanelType and not(PANEL_BACK or PANEL_FORE) <> 0 then
3063 begin
3064 // Левый верхний угол:
3065 aX := XX + (X div ScaleSz);
3066 aY := 1 + (Y div ScaleSz);
3067 // Размеры:
3068 aX2 := max(Width div ScaleSz, 1);
3069 aY2 := max(Height div ScaleSz, 1);
3070 // Правый нижний угол:
3071 aX2 := aX + aX2 - 1;
3072 aY2 := aY + aY2 - 1;
3074 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0)
3075 end;
3076 end;
3078 if (gMapInfo.Width > RenderPanel.Width) or
3079 (gMapInfo.Height > RenderPanel.Height) then
3080 begin
3081 // Окно, показывающее текущее положение экрана на карте:
3082 // Размеры окна:
3083 x := max(min(RenderPanel.Width, gMapInfo.Width) div ScaleSz, 1);
3084 y := max(min(RenderPanel.Height, gMapInfo.Height) div ScaleSz, 1);
3085 // Левый верхний угол:
3086 aX := XX + ((-MapOffset.X) div ScaleSz);
3087 aY := 1 + ((-MapOffset.Y) div ScaleSz);
3088 // Правый нижний угол:
3089 aX2 := aX + x - 1;
3090 aY2 := aY + y - 1;
3092 e_DrawFillQuad(aX, aY, aX2, aY2, 127, 192, 127, 127, B_BLEND);
3093 e_DrawQuad(aX, aY, aX2, aY2, 255, 0, 0);
3094 end;
3095 end; // Мини-карта
3097 e_EndRender();
3098 RenderPanel.SwapBuffers();
3099 end;
3101 procedure TMainForm.FormResize(Sender: TObject);
3102 begin
3103 e_SetViewPort(0, 0, RenderPanel.Width, RenderPanel.Height);
3105 sbHorizontal.Min := Min(gMapInfo.Width - RenderPanel.Width, -RenderPanel.Width div 2);
3106 sbHorizontal.Max := Max(0, gMapInfo.Width - RenderPanel.Width div 2);
3107 sbVertical.Min := Min(gMapInfo.Height - RenderPanel.Height, -RenderPanel.Height div 2);
3108 sbVertical.Max := Max(0, gMapInfo.Height - RenderPanel.Height div 2);
3110 MapOffset.X := -sbHorizontal.Position;
3111 MapOffset.Y := -sbVertical.Position;
3112 end;
3114 procedure SelectNextObject(X, Y: Integer; ObjectType: Byte; ID: DWORD);
3116 j, j_max: Integer;
3117 res: Boolean;
3118 begin
3119 j_max := 0; // shut up compiler
3120 case ObjectType of
3121 OBJECT_PANEL:
3122 begin
3123 res := (gPanels <> nil) and
3124 PanelInShownLayer(gPanels[ID].PanelType) and
3125 g_CollidePoint(X, Y, gPanels[ID].X, gPanels[ID].Y,
3126 gPanels[ID].Width,
3127 gPanels[ID].Height);
3128 j_max := Length(gPanels) - 1;
3129 end;
3131 OBJECT_ITEM:
3132 begin
3133 res := (gItems <> nil) and
3134 LayerEnabled[LAYER_ITEMS] and
3135 g_CollidePoint(X, Y, gItems[ID].X, gItems[ID].Y,
3136 ItemSize[gItems[ID].ItemType][0],
3137 ItemSize[gItems[ID].ItemType][1]);
3138 j_max := Length(gItems) - 1;
3139 end;
3141 OBJECT_MONSTER:
3142 begin
3143 res := (gMonsters <> nil) and
3144 LayerEnabled[LAYER_MONSTERS] and
3145 g_CollidePoint(X, Y, gMonsters[ID].X, gMonsters[ID].Y,
3146 MonsterSize[gMonsters[ID].MonsterType].Width,
3147 MonsterSize[gMonsters[ID].MonsterType].Height);
3148 j_max := Length(gMonsters) - 1;
3149 end;
3151 OBJECT_AREA:
3152 begin
3153 res := (gAreas <> nil) and
3154 LayerEnabled[LAYER_AREAS] and
3155 g_CollidePoint(X, Y, gAreas[ID].X, gAreas[ID].Y,
3156 AreaSize[gAreas[ID].AreaType].Width,
3157 AreaSize[gAreas[ID].AreaType].Height);
3158 j_max := Length(gAreas) - 1;
3159 end;
3161 OBJECT_TRIGGER:
3162 begin
3163 res := (gTriggers <> nil) and
3164 LayerEnabled[LAYER_TRIGGERS] and
3165 g_CollidePoint(X, Y, gTriggers[ID].X, gTriggers[ID].Y,
3166 gTriggers[ID].Width,
3167 gTriggers[ID].Height);
3168 j_max := Length(gTriggers) - 1;
3169 end;
3171 else
3172 res := False;
3173 end;
3175 if not res then
3176 Exit;
3178 // Перебор ID: от ID-1 до 0; потом от High до ID+1:
3179 j := ID;
3181 while True do
3182 begin
3183 Dec(j);
3185 if j < 0 then
3186 j := j_max;
3187 if j = Integer(ID) then
3188 Break;
3190 case ObjectType of
3191 OBJECT_PANEL:
3192 res := PanelInShownLayer(gPanels[j].PanelType) and
3193 g_CollidePoint(X, Y, gPanels[j].X, gPanels[j].Y,
3194 gPanels[j].Width,
3195 gPanels[j].Height);
3196 OBJECT_ITEM:
3197 res := (gItems[j].ItemType <> ITEM_NONE) and
3198 g_CollidePoint(X, Y, gItems[j].X, gItems[j].Y,
3199 ItemSize[gItems[j].ItemType][0],
3200 ItemSize[gItems[j].ItemType][1]);
3201 OBJECT_MONSTER:
3202 res := (gMonsters[j].MonsterType <> MONSTER_NONE) and
3203 g_CollidePoint(X, Y, gMonsters[j].X, gMonsters[j].Y,
3204 MonsterSize[gMonsters[j].MonsterType].Width,
3205 MonsterSize[gMonsters[j].MonsterType].Height);
3206 OBJECT_AREA:
3207 res := (gAreas[j].AreaType <> AREA_NONE) and
3208 g_CollidePoint(X, Y, gAreas[j].X, gAreas[j].Y,
3209 AreaSize[gAreas[j].AreaType].Width,
3210 AreaSize[gAreas[j].AreaType].Height);
3211 OBJECT_TRIGGER:
3212 res := (gTriggers[j].TriggerType <> TRIGGER_NONE) and
3213 g_CollidePoint(X, Y, gTriggers[j].X, gTriggers[j].Y,
3214 gTriggers[j].Width,
3215 gTriggers[j].Height);
3216 else
3217 res := False;
3218 end;
3220 if res then
3221 begin
3222 SetLength(SelectedObjects, 1);
3224 SelectedObjects[0].ObjectType := ObjectType;
3225 SelectedObjects[0].ID := j;
3226 SelectedObjects[0].Live := True;
3228 FillProperty();
3229 Break;
3230 end;
3231 end;
3232 end;
3234 procedure TMainForm.RenderPanelMouseDown(Sender: TObject;
3235 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3237 i: Integer;
3238 Rect: TRectWH;
3239 c1, c2, c3, c4: Boolean;
3240 item: TItem;
3241 area: TArea;
3242 monster: TMonster;
3243 IDArray: DWArray;
3244 begin
3245 MainForm.ActiveControl := RenderPanel;
3246 RenderPanel.SetFocus();
3248 RenderPanelMouseMove(RenderPanel, Shift, X, Y);
3250 if Button = mbLeft then // Left Mouse Button
3251 begin
3252 // Двигаем карту с помощью мыши и мини-карты:
3253 if ShowMap and
3254 g_CollidePoint(X, Y,
3255 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3257 max(gMapInfo.Width div (16 div Scale), 1),
3258 max(gMapInfo.Height div (16 div Scale), 1) ) then
3259 begin
3260 MoveMap(X, Y);
3261 MouseAction := MOUSEACTION_MOVEMAP;
3263 else // Ставим предмет/монстра/область:
3264 if (pcObjects.ActivePageIndex in [1, 2, 3]) and
3265 (not (ssShift in Shift)) then
3266 begin
3267 case pcObjects.ActivePageIndex of
3269 if lbItemList.ItemIndex = -1 then
3270 ErrorMessageBox(_lc[I_MSG_CHOOSE_ITEM])
3271 else
3272 begin
3273 item.ItemType := lbItemList.ItemIndex + ITEM_MEDKIT_SMALL;
3274 if item.ItemType >= ITEM_WEAPON_KASTET then
3275 item.ItemType := item.ItemType + 2;
3276 item.X := MousePos.X-MapOffset.X;
3277 item.Y := MousePos.Y-MapOffset.Y;
3279 if not (ssCtrl in Shift) then
3280 begin
3281 item.X := item.X - (ItemSize[item.ItemType][0] div 2);
3282 item.Y := item.Y - ItemSize[item.ItemType][1];
3283 end;
3285 item.OnlyDM := cbOnlyDM.Checked;
3286 item.Fall := cbFall.Checked;
3287 Undo_Add(OBJECT_ITEM, AddItem(item));
3288 end;
3290 if lbMonsterList.ItemIndex = -1 then
3291 ErrorMessageBox(_lc[I_MSG_CHOOSE_MONSTER])
3292 else
3293 begin
3294 monster.MonsterType := lbMonsterList.ItemIndex + MONSTER_DEMON;
3295 monster.X := MousePos.X-MapOffset.X;
3296 monster.Y := MousePos.Y-MapOffset.Y;
3298 if not (ssCtrl in Shift) then
3299 begin
3300 monster.X := monster.X - (MonsterSize[monster.MonsterType].Width div 2);
3301 monster.Y := monster.Y - MonsterSize[monster.MonsterType].Height;
3302 end;
3304 if rbMonsterLeft.Checked then
3305 monster.Direction := D_LEFT
3306 else
3307 monster.Direction := D_RIGHT;
3308 Undo_Add(OBJECT_MONSTER, AddMonster(monster));
3309 end;
3311 if lbAreasList.ItemIndex = -1 then
3312 ErrorMessageBox(_lc[I_MSG_CHOOSE_AREA])
3313 else
3314 if (lbAreasList.ItemIndex + 1) <> AREA_DOMFLAG then
3315 begin
3316 area.AreaType := lbAreasList.ItemIndex + AREA_PLAYERPOINT1;
3317 area.X := MousePos.X-MapOffset.X;
3318 area.Y := MousePos.Y-MapOffset.Y;
3320 if not (ssCtrl in Shift) then
3321 begin
3322 area.X := area.X - (AreaSize[area.AreaType].Width div 2);
3323 area.Y := area.Y - AreaSize[area.AreaType].Height;
3324 end;
3326 if rbAreaLeft.Checked then
3327 area.Direction := D_LEFT
3328 else
3329 area.Direction := D_RIGHT;
3330 Undo_Add(OBJECT_AREA, AddArea(area));
3331 end;
3332 end;
3334 else
3335 begin
3336 i := GetFirstSelected();
3338 // Выбираем объект под текущим:
3339 if (SelectedObjects <> nil) and
3340 (ssShift in Shift) and (i >= 0) and
3341 (SelectedObjects[i].Live) then
3342 begin
3343 if SelectedObjectCount() = 1 then
3344 SelectNextObject(X-MapOffset.X, Y-MapOffset.Y,
3345 SelectedObjects[i].ObjectType,
3346 SelectedObjects[i].ID);
3348 else
3349 begin
3350 // Рисуем область триггера "Расширитель":
3351 if DrawPressRect and (i >= 0) and
3352 (SelectedObjects[i].ObjectType = OBJECT_TRIGGER) and
3353 (gTriggers[SelectedObjects[i].ID].TriggerType in
3354 [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) then
3355 MouseAction := MOUSEACTION_DRAWPRESS
3356 else // Рисуем панель:
3357 if pcObjects.ActivePageIndex = 0 then
3358 begin
3359 if (lbPanelType.ItemIndex >= 0) then
3360 MouseAction := MOUSEACTION_DRAWPANEL
3362 else // Рисуем триггер:
3363 if (lbTriggersList.ItemIndex >= 0) then
3364 begin
3365 MouseAction := MOUSEACTION_DRAWTRIGGER;
3366 end;
3367 end;
3368 end;
3369 end; // if Button = mbLeft
3371 if Button = mbRight then // Right Mouse Button
3372 begin
3373 // Клик по мини-карте:
3374 if ShowMap and
3375 g_CollidePoint(X, Y,
3376 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3378 max(gMapInfo.Width div (16 div Scale), 1),
3379 max(gMapInfo.Height div (16 div Scale), 1) ) then
3380 begin
3381 MouseAction := MOUSEACTION_NOACTION;
3383 else // Нужно что-то выбрать мышью:
3384 if SelectFlag <> SELECTFLAG_NONE then
3385 begin
3386 case SelectFlag of
3387 SELECTFLAG_TELEPORT:
3388 // Точку назначения телепортации:
3389 with gTriggers[SelectedObjects[
3390 GetFirstSelected() ].ID].Data.TargetPoint do
3391 begin
3392 X := MousePos.X-MapOffset.X;
3393 Y := MousePos.Y-MapOffset.Y;
3394 end;
3396 SELECTFLAG_SPAWNPOINT:
3397 // Точку создания монстра:
3398 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
3399 if TriggerType = TRIGGER_SPAWNMONSTER then
3400 begin
3401 Data.MonPos.X := MousePos.X-MapOffset.X;
3402 Data.MonPos.Y := MousePos.Y-MapOffset.Y;
3404 else if TriggerType = TRIGGER_SPAWNITEM then
3405 begin // Точка создания предмета:
3406 Data.ItemPos.X := MousePos.X-MapOffset.X;
3407 Data.ItemPos.Y := MousePos.Y-MapOffset.Y;
3409 else if TriggerType = TRIGGER_SHOT then
3410 begin // Точка создания выстрела:
3411 Data.ShotPos.X := MousePos.X-MapOffset.X;
3412 Data.ShotPos.Y := MousePos.Y-MapOffset.Y;
3413 end;
3415 SELECTFLAG_DOOR:
3416 // Дверь:
3417 begin
3418 IDArray := ObjectInRect(X-MapOffset.X,
3419 Y-MapOffset.Y,
3420 2, 2, OBJECT_PANEL, True);
3421 if IDArray <> nil then
3422 begin
3423 for i := 0 to High(IDArray) do
3424 if (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3425 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR) then
3426 begin
3427 gTriggers[SelectedObjects[
3428 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3429 Break;
3430 end;
3432 else
3433 gTriggers[SelectedObjects[
3434 GetFirstSelected() ].ID].Data.PanelID := -1;
3435 end;
3437 SELECTFLAG_TEXTURE:
3438 // Панель с текстурой:
3439 begin
3440 IDArray := ObjectInRect(X-MapOffset.X,
3441 Y-MapOffset.Y,
3442 2, 2, OBJECT_PANEL, True);
3443 if IDArray <> nil then
3444 begin
3445 for i := 0 to High(IDArray) do
3446 if ((gPanels[IDArray[i]].PanelType in
3447 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3448 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3449 PANEL_STEP]) or
3450 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3451 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3452 (gPanels[IDArray[i]].TextureName <> '') then
3453 begin
3454 gTriggers[SelectedObjects[
3455 GetFirstSelected() ].ID].TexturePanel := IDArray[i];
3456 Break;
3457 end;
3459 else
3460 gTriggers[SelectedObjects[
3461 GetFirstSelected() ].ID].TexturePanel := -1;
3462 end;
3464 SELECTFLAG_LIFT:
3465 // Лифт:
3466 begin
3467 IDArray := ObjectInRect(X-MapOffset.X,
3468 Y-MapOffset.Y,
3469 2, 2, OBJECT_PANEL, True);
3470 if IDArray <> nil then
3471 begin
3472 for i := 0 to High(IDArray) do
3473 if (gPanels[IDArray[i]].PanelType = PANEL_LIFTUP) or
3474 (gPanels[IDArray[i]].PanelType = PANEL_LIFTDOWN) or
3475 (gPanels[IDArray[i]].PanelType = PANEL_LIFTLEFT) or
3476 (gPanels[IDArray[i]].PanelType = PANEL_LIFTRIGHT) then
3477 begin
3478 gTriggers[SelectedObjects[
3479 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3480 Break;
3481 end;
3483 else
3484 gTriggers[SelectedObjects[
3485 GetFirstSelected() ].ID].Data.PanelID := -1;
3486 end;
3488 SELECTFLAG_MONSTER:
3489 // Монстра:
3490 begin
3491 IDArray := ObjectInRect(X-MapOffset.X,
3492 Y-MapOffset.Y,
3493 2, 2, OBJECT_MONSTER, False);
3494 if IDArray <> nil then
3495 gTriggers[SelectedObjects[
3496 GetFirstSelected() ].ID].Data.MonsterID := IDArray[0]+1
3497 else
3498 gTriggers[SelectedObjects[
3499 GetFirstSelected() ].ID].Data.MonsterID := 0;
3500 end;
3502 SELECTFLAG_SHOTPANEL:
3503 // Панель индикации выстрела:
3504 begin
3505 if gTriggers[SelectedObjects[
3506 GetFirstSelected() ].ID].TriggerType = TRIGGER_SHOT then
3507 begin
3508 IDArray := ObjectInRect(X-MapOffset.X,
3509 Y-MapOffset.Y,
3510 2, 2, OBJECT_PANEL, True);
3511 if IDArray <> nil then
3512 begin
3513 for i := 0 to High(IDArray) do
3514 if ((gPanels[IDArray[i]].PanelType in
3515 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3516 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3517 PANEL_STEP]) or
3518 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3519 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3520 (gPanels[IDArray[i]].TextureName <> '') then
3521 begin
3522 gTriggers[SelectedObjects[
3523 GetFirstSelected() ].ID].Data.ShotPanelID := IDArray[i];
3524 Break;
3525 end;
3527 else
3528 gTriggers[SelectedObjects[
3529 GetFirstSelected() ].ID].Data.ShotPanelID := -1;
3530 end;
3531 end;
3532 end;
3534 SelectFlag := SELECTFLAG_SELECTED;
3536 else // if SelectFlag <> SELECTFLAG_NONE...
3537 begin
3538 // Что уже выбрано и не нажат Ctrl:
3539 if (SelectedObjects <> nil) and
3540 (not (ssCtrl in Shift)) then
3541 for i := 0 to High(SelectedObjects) do
3542 with SelectedObjects[i] do
3543 if Live then
3544 begin
3545 if (ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) and
3546 (SelectedObjectCount() = 1) then
3547 begin
3548 Rect := ObjectGetRect(ObjectType, ID);
3550 c1 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3551 Rect.X-2, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3552 c2 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3553 Rect.X+Rect.Width-3, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3554 c3 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3555 Rect.X+(Rect.Width div 2)-2, Rect.Y-2, 4, 4);
3556 c4 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3557 Rect.X+(Rect.Width div 2)-2, Rect.Y+Rect.Height-3, 4, 4);
3559 // Меняем размер панели или триггера:
3560 if c1 or c2 or c3 or c4 then
3561 begin
3562 MouseAction := MOUSEACTION_RESIZE;
3563 LastMovePoint := MousePos;
3565 if c1 or c2 then
3566 begin // Шире/уже
3567 ResizeType := RESIZETYPE_HORIZONTAL;
3568 if c1 then
3569 ResizeDirection := RESIZEDIR_LEFT
3570 else
3571 ResizeDirection := RESIZEDIR_RIGHT;
3572 RenderPanel.Cursor := crSizeWE;
3574 else
3575 begin // Выше/ниже
3576 ResizeType := RESIZETYPE_VERTICAL;
3577 if c3 then
3578 ResizeDirection := RESIZEDIR_UP
3579 else
3580 ResizeDirection := RESIZEDIR_DOWN;
3581 RenderPanel.Cursor := crSizeNS;
3582 end;
3584 Break;
3585 end;
3586 end;
3588 // Перемещаем панель или триггер:
3589 if ObjectCollide(ObjectType, ID,
3590 X-MapOffset.X-1,
3591 Y-MapOffset.Y-1, 2, 2) then
3592 begin
3593 MouseAction := MOUSEACTION_MOVEOBJ;
3594 LastMovePoint := MousePos;
3596 Break;
3597 end;
3598 end;
3599 end;
3600 end; // if Button = mbRight
3602 if Button = mbMiddle then // Middle Mouse Button
3603 begin
3604 SetCapture(RenderPanel.Handle);
3605 RenderPanel.Cursor := crSize;
3606 end;
3608 MouseMDown := Button = mbMiddle;
3609 if MouseMDown then
3610 MouseMDownPos := Mouse.CursorPos;
3612 MouseRDown := Button = mbRight;
3613 if MouseRDown then
3614 MouseRDownPos := MousePos;
3616 MouseLDown := Button = mbLeft;
3617 if MouseLDown then
3618 MouseLDownPos := MousePos;
3619 end;
3621 procedure TMainForm.RenderPanelMouseUp(Sender: TObject;
3622 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3624 panel: TPanel;
3625 trigger: TTrigger;
3626 rRect: TRectWH;
3627 rSelectRect: Boolean;
3628 wWidth, wHeight: Word;
3629 TextureID: DWORD;
3631 procedure SelectObjects(ObjectType: Byte);
3633 i: Integer;
3634 IDArray: DWArray;
3635 begin
3636 IDArray := ObjectInRect(rRect.X, rRect.Y,
3637 rRect.Width, rRect.Height,
3638 ObjectType, rSelectRect);
3640 if IDArray <> nil then
3641 for i := 0 to High(IDArray) do
3642 SelectObject(ObjectType, IDArray[i], (ssCtrl in Shift) or rSelectRect);
3643 end;
3644 begin
3645 if Button = mbLeft then
3646 MouseLDown := False;
3647 if Button = mbRight then
3648 MouseRDown := False;
3649 if Button = mbMiddle then
3650 MouseMDown := False;
3652 DrawRect := nil;
3653 ResizeType := RESIZETYPE_NONE;
3654 TextureID := 0;
3656 if Button = mbLeft then // Left Mouse Button
3657 begin
3658 if MouseAction <> MOUSEACTION_NONE then
3659 begin // Было действие мышью
3660 // Мышь сдвинулась во время удержания клавиши,
3661 // либо активирован режим быстрого рисования:
3662 if ((MousePos.X <> MouseLDownPos.X) and
3663 (MousePos.Y <> MouseLDownPos.Y)) or
3664 ((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
3665 (ssCtrl in Shift)) then
3666 case MouseAction of
3667 // Рисовали панель:
3668 MOUSEACTION_DRAWPANEL:
3669 begin
3670 // Фон или передний план без текстуры - ошибка:
3671 if (lbPanelType.ItemIndex in [1, 2]) and
3672 (lbTextureList.ItemIndex = -1) then
3673 ErrorMessageBox(_lc[I_MSG_CHOOSE_TEXTURE])
3674 else // Назначаем параметры панели:
3675 begin
3676 case lbPanelType.ItemIndex of
3677 0: Panel.PanelType := PANEL_WALL;
3678 1: Panel.PanelType := PANEL_BACK;
3679 2: Panel.PanelType := PANEL_FORE;
3680 3: Panel.PanelType := PANEL_OPENDOOR;
3681 4: Panel.PanelType := PANEL_CLOSEDOOR;
3682 5: Panel.PanelType := PANEL_STEP;
3683 6: Panel.PanelType := PANEL_WATER;
3684 7: Panel.PanelType := PANEL_ACID1;
3685 8: Panel.PanelType := PANEL_ACID2;
3686 9: Panel.PanelType := PANEL_LIFTUP;
3687 10: Panel.PanelType := PANEL_LIFTDOWN;
3688 11: Panel.PanelType := PANEL_LIFTLEFT;
3689 12: Panel.PanelType := PANEL_LIFTRIGHT;
3690 13: Panel.PanelType := PANEL_BLOCKMON;
3691 end;
3693 Panel.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3694 Panel.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3695 if ssCtrl in Shift then
3696 begin
3697 wWidth := DotStep;
3698 wHeight := DotStep;
3699 if (lbTextureList.ItemIndex <> -1) and
3700 (not IsSpecialTextureSel()) then
3701 begin
3702 if not g_GetTexture(SelectedTexture(), TextureID) then
3703 g_GetTexture('NOTEXTURE', TextureID);
3704 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
3705 end;
3706 Panel.Width := wWidth;
3707 Panel.Height := wHeight;
3709 else
3710 begin
3711 Panel.Width := Abs(MousePos.X-MouseLDownPos.X);
3712 Panel.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3713 end;
3715 // Лифты, блокМон или отсутствие текстуры - пустая текстура:
3716 if (lbPanelType.ItemIndex in [9, 10, 11, 12, 13]) or
3717 (lbTextureList.ItemIndex = -1) then
3718 begin
3719 Panel.TextureHeight := 1;
3720 Panel.TextureWidth := 1;
3721 Panel.TextureName := '';
3722 Panel.TextureID := TEXTURE_SPECIAL_NONE;
3724 else // Есть текстура:
3725 begin
3726 Panel.TextureName := SelectedTexture();
3728 // Обычная текстура:
3729 if not IsSpecialTextureSel() then
3730 begin
3731 g_GetTextureSizeByName(Panel.TextureName,
3732 Panel.TextureWidth, Panel.TextureHeight);
3733 g_GetTexture(Panel.TextureName, Panel.TextureID);
3735 else // Спец.текстура:
3736 begin
3737 Panel.TextureHeight := 1;
3738 Panel.TextureWidth := 1;
3739 Panel.TextureID := SpecialTextureID(SelectedTexture());
3740 end;
3741 end;
3743 Panel.Alpha := 0;
3744 Panel.Blending := False;
3746 Undo_Add(OBJECT_PANEL, AddPanel(Panel));
3747 end;
3748 end;
3750 // Рисовали триггер:
3751 MOUSEACTION_DRAWTRIGGER:
3752 begin
3753 trigger.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3754 trigger.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3755 if ssCtrl in Shift then
3756 begin
3757 wWidth := DotStep;
3758 wHeight := DotStep;
3759 trigger.Width := wWidth;
3760 trigger.Height := wHeight;
3762 else
3763 begin
3764 trigger.Width := Abs(MousePos.X-MouseLDownPos.X);
3765 trigger.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3766 end;
3768 trigger.Enabled := True;
3769 trigger.TriggerType := lbTriggersList.ItemIndex+1;
3770 trigger.TexturePanel := -1;
3772 // Типы активации:
3773 trigger.ActivateType := 0;
3775 if clbActivationType.Checked[0] then
3776 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERCOLLIDE;
3777 if clbActivationType.Checked[1] then
3778 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERCOLLIDE;
3779 if clbActivationType.Checked[2] then
3780 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERPRESS;
3781 if clbActivationType.Checked[3] then
3782 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERPRESS;
3783 if clbActivationType.Checked[4] then
3784 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_SHOT;
3785 if clbActivationType.Checked[5] then
3786 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_NOMONSTER;
3788 // Необходимые для активации ключи:
3789 trigger.Key := 0;
3791 if clbKeys.Checked[0] then
3792 trigger.Key := Trigger.Key or KEY_RED;
3793 if clbKeys.Checked[1] then
3794 trigger.Key := Trigger.Key or KEY_GREEN;
3795 if clbKeys.Checked[2] then
3796 trigger.Key := Trigger.Key or KEY_BLUE;
3797 if clbKeys.Checked[3] then
3798 trigger.Key := Trigger.Key or KEY_REDTEAM;
3799 if clbKeys.Checked[4] then
3800 trigger.Key := Trigger.Key or KEY_BLUETEAM;
3802 // Параметры триггера:
3803 FillByte(trigger.Data.Default[0], 128, 0);
3805 case trigger.TriggerType of
3806 // Переключаемая панель:
3807 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
3808 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
3809 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
3810 begin
3811 Trigger.Data.PanelID := -1;
3812 end;
3814 // Телепортация:
3815 TRIGGER_TELEPORT:
3816 begin
3817 trigger.Data.TargetPoint.X := trigger.X-64;
3818 trigger.Data.TargetPoint.Y := trigger.Y-64;
3819 trigger.Data.d2d_teleport := True;
3820 trigger.Data.TlpDir := 0;
3821 end;
3823 // Изменение других триггеров:
3824 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
3825 TRIGGER_ONOFF:
3826 begin
3827 trigger.Data.Count := 1;
3828 end;
3830 // Звук:
3831 TRIGGER_SOUND:
3832 begin
3833 trigger.Data.Volume := 255;
3834 trigger.Data.Pan := 127;
3835 trigger.Data.PlayCount := 1;
3836 trigger.Data.Local := True;
3837 trigger.Data.SoundSwitch := False;
3838 end;
3840 // Музыка:
3841 TRIGGER_MUSIC:
3842 begin
3843 trigger.Data.MusicAction := 1;
3844 end;
3846 // Создание монстра:
3847 TRIGGER_SPAWNMONSTER:
3848 begin
3849 trigger.Data.MonType := MONSTER_ZOMBY;
3850 trigger.Data.MonPos.X := trigger.X-64;
3851 trigger.Data.MonPos.Y := trigger.Y-64;
3852 trigger.Data.MonHealth := 0;
3853 trigger.Data.MonActive := False;
3854 trigger.Data.MonCount := 1;
3855 end;
3857 // Создание предмета:
3858 TRIGGER_SPAWNITEM:
3859 begin
3860 trigger.Data.ItemType := ITEM_AMMO_BULLETS;
3861 trigger.Data.ItemPos.X := trigger.X-64;
3862 trigger.Data.ItemPos.Y := trigger.Y-64;
3863 trigger.Data.ItemOnlyDM := False;
3864 trigger.Data.ItemFalls := False;
3865 trigger.Data.ItemCount := 1;
3866 trigger.Data.ItemMax := 0;
3867 trigger.Data.ItemDelay := 0;
3868 end;
3870 // Ускорение:
3871 TRIGGER_PUSH:
3872 begin
3873 trigger.Data.PushAngle := 90;
3874 trigger.Data.PushForce := 10;
3875 trigger.Data.ResetVel := True;
3876 end;
3878 TRIGGER_SCORE:
3879 begin
3880 trigger.Data.ScoreCount := 1;
3881 trigger.Data.ScoreCon := True;
3882 trigger.Data.ScoreMsg := True;
3883 end;
3885 TRIGGER_MESSAGE:
3886 begin
3887 trigger.Data.MessageKind := 0;
3888 trigger.Data.MessageSendTo := 0;
3889 trigger.Data.MessageText := '';
3890 trigger.Data.MessageTime := 144;
3891 end;
3893 TRIGGER_DAMAGE:
3894 begin
3895 trigger.Data.DamageValue := 5;
3896 trigger.Data.DamageInterval := 12;
3897 end;
3899 TRIGGER_HEALTH:
3900 begin
3901 trigger.Data.HealValue := 5;
3902 trigger.Data.HealInterval := 36;
3903 end;
3905 TRIGGER_SHOT:
3906 begin
3907 trigger.Data.ShotType := TRIGGER_SHOT_BULLET;
3908 trigger.Data.ShotSound := True;
3909 trigger.Data.ShotPanelID := -1;
3910 trigger.Data.ShotTarget := 0;
3911 trigger.Data.ShotIntSight := 0;
3912 trigger.Data.ShotAim := TRIGGER_SHOT_AIM_DEFAULT;
3913 trigger.Data.ShotPos.X := trigger.X-64;
3914 trigger.Data.ShotPos.Y := trigger.Y-64;
3915 trigger.Data.ShotAngle := 0;
3916 trigger.Data.ShotWait := 18;
3917 trigger.Data.ShotAccuracy := 0;
3918 trigger.Data.ShotAmmo := 0;
3919 trigger.Data.ShotIntReload := 0;
3920 end;
3922 TRIGGER_EFFECT:
3923 begin
3924 trigger.Data.FXCount := 1;
3925 trigger.Data.FXType := TRIGGER_EFFECT_PARTICLE;
3926 trigger.Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
3927 trigger.Data.FXColorR := 0;
3928 trigger.Data.FXColorG := 0;
3929 trigger.Data.FXColorB := 255;
3930 trigger.Data.FXPos := TRIGGER_EFFECT_POS_CENTER;
3931 trigger.Data.FXWait := 1;
3932 trigger.Data.FXVelX := 0;
3933 trigger.Data.FXVelY := -20;
3934 trigger.Data.FXSpreadL := 5;
3935 trigger.Data.FXSpreadR := 5;
3936 trigger.Data.FXSpreadU := 4;
3937 trigger.Data.FXSpreadD := 0;
3938 end;
3939 end;
3941 Undo_Add(OBJECT_TRIGGER, AddTrigger(trigger));
3942 end;
3944 // Рисовали область триггера "Расширитель":
3945 MOUSEACTION_DRAWPRESS:
3946 with gTriggers[SelectedObjects[GetFirstSelected].ID] do
3947 begin
3948 Data.tX := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3949 Data.tY := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3950 Data.tWidth := Abs(MousePos.X-MouseLDownPos.X);
3951 Data.tHeight := Abs(MousePos.Y-MouseLDownPos.Y);
3953 DrawPressRect := False;
3954 end;
3955 end;
3957 MouseAction := MOUSEACTION_NONE;
3958 end;
3959 end // if Button = mbLeft...
3960 else if Button = mbRight then // Right Mouse Button:
3961 begin
3962 if MouseAction = MOUSEACTION_NOACTION then
3963 begin
3964 MouseAction := MOUSEACTION_NONE;
3965 Exit;
3966 end;
3968 // Объект передвинут или изменен в размере:
3969 if MouseAction in [MOUSEACTION_MOVEOBJ, MOUSEACTION_RESIZE] then
3970 begin
3971 RenderPanel.Cursor := crDefault;
3972 MouseAction := MOUSEACTION_NONE;
3973 FillProperty();
3974 Exit;
3975 end;
3977 // Еще не все выбрали:
3978 if SelectFlag <> SELECTFLAG_NONE then
3979 begin
3980 if SelectFlag = SELECTFLAG_SELECTED then
3981 SelectFlag := SELECTFLAG_NONE;
3982 FillProperty();
3983 Exit;
3984 end;
3986 // Мышь сдвинулась во время удержания клавиши:
3987 if (MousePos.X <> MouseRDownPos.X) and
3988 (MousePos.Y <> MouseRDownPos.Y) then
3989 begin
3990 rSelectRect := True;
3992 rRect.X := Min(MousePos.X, MouseRDownPos.X)-MapOffset.X;
3993 rRect.Y := Min(MousePos.Y, MouseRDownPos.Y)-MapOffset.Y;
3994 rRect.Width := Abs(MousePos.X-MouseRDownPos.X);
3995 rRect.Height := Abs(MousePos.Y-MouseRDownPos.Y);
3997 else // Мышь не сдвинулась - нет прямоугольника:
3998 begin
3999 rSelectRect := False;
4001 rRect.X := X-MapOffset.X-1;
4002 rRect.Y := Y-MapOffset.Y-1;
4003 rRect.Width := 2;
4004 rRect.Height := 2;
4005 end;
4007 // Если зажат Ctrl - выделять еще, иначе только один выделенный объект:
4008 if not (ssCtrl in Shift) then
4009 RemoveSelectFromObjects();
4011 // Выделяем всё в выбранном прямоугольнике:
4012 if (ssCtrl in Shift) and (ssAlt in Shift) then
4013 begin
4014 SelectObjects(OBJECT_PANEL);
4015 SelectObjects(OBJECT_ITEM);
4016 SelectObjects(OBJECT_MONSTER);
4017 SelectObjects(OBJECT_AREA);
4018 SelectObjects(OBJECT_TRIGGER);
4020 else
4021 SelectObjects(pcObjects.ActivePageIndex+1);
4023 FillProperty();
4026 else // Middle Mouse Button
4027 begin
4028 RenderPanel.Cursor := crDefault;
4029 ReleaseCapture();
4030 end;
4031 end;
4033 procedure TMainForm.RenderPanelPaint(Sender: TObject);
4034 begin
4035 Draw();
4036 end;
4038 function TMainForm.RenderMousePos(): Types.TPoint;
4039 begin
4040 Result := RenderPanel.ScreenToClient(Mouse.CursorPos);
4041 end;
4043 procedure TMainForm.RecountSelectedObjects();
4044 begin
4045 if SelectedObjectCount() = 0 then
4046 StatusBar.Panels[0].Text := ''
4047 else
4048 StatusBar.Panels[0].Text := Format(_lc[I_CAP_STAT_SELECTED], [SelectedObjectCount()]);
4049 end;
4051 procedure TMainForm.RenderPanelMouseMove(Sender: TObject;
4052 Shift: TShiftState; X, Y: Integer);
4054 sX, sY: Integer;
4055 dWidth, dHeight: Integer;
4056 _id: Integer;
4057 TextureID: DWORD;
4058 wWidth, wHeight: Word;
4059 begin
4060 _id := GetFirstSelected();
4061 TextureID := 0;
4063 // Рисуем панель с текстурой, сетка - размеры текстуры:
4064 if (MouseAction = MOUSEACTION_DRAWPANEL) and
4065 (lbPanelType.ItemIndex in [0..8]) and
4066 (lbTextureList.ItemIndex <> -1) and
4067 (not IsSpecialTextureSel()) then
4068 begin
4069 sX := StrToIntDef(lTextureWidth.Caption, DotStep);
4070 sY := StrToIntDef(lTextureHeight.Caption, DotStep);
4072 else
4073 // Меняем размер панели с текстурой, сетка - размеры текстуры:
4074 if (MouseAction = MOUSEACTION_RESIZE) and
4075 ( (SelectedObjects[_id].ObjectType = OBJECT_PANEL) and
4076 IsTexturedPanel(gPanels[SelectedObjects[_id].ID].PanelType) and
4077 (gPanels[SelectedObjects[_id].ID].TextureName <> '') and
4078 (not IsSpecialTexture(gPanels[SelectedObjects[_id].ID].TextureName)) ) then
4079 begin
4080 sX := gPanels[SelectedObjects[_id].ID].TextureWidth;
4081 sY := gPanels[SelectedObjects[_id].ID].TextureHeight;
4083 else
4084 // Выравнивание по сетке:
4085 if SnapToGrid then
4086 begin
4087 sX := DotStep;
4088 sY := DotStep;
4090 else // Нет выравнивания по сетке:
4091 begin
4092 sX := 1;
4093 sY := 1;
4094 end;
4096 // Новая позиция мыши:
4097 if MouseLDown then
4098 begin // Зажата левая кнопка мыши
4099 MousePos.X := (Round((X-MouseLDownPos.X)/sX)*sX)+MouseLDownPos.X;
4100 MousePos.Y := (Round((Y-MouseLDownPos.Y)/sY)*sY)+MouseLDownPos.Y;
4102 else
4103 if MouseRDown then
4104 begin // Зажата правая кнопка мыши
4105 MousePos.X := (Round((X-MouseRDownPos.X)/sX)*sX)+MouseRDownPos.X;
4106 MousePos.Y := (Round((Y-MouseRDownPos.Y)/sY)*sY)+MouseRDownPos.Y;
4108 else
4109 begin // Кнопки мыши не зажаты
4110 MousePos.X := Round((-MapOffset.X + X) / sX) * sX + MapOffset.X;
4111 MousePos.Y := Round((-MapOffset.Y + Y) / sY) * sY + MapOffset.Y;
4112 end;
4114 // Зажата только правая кнопка мыши:
4115 if (not MouseLDown) and (MouseRDown) and (not MouseMDown) then
4116 begin
4117 // Рисуем прямоугольник выделения:
4118 if MouseAction = MOUSEACTION_NONE then
4119 begin
4120 if DrawRect = nil then
4121 New(DrawRect);
4122 DrawRect.Top := MouseRDownPos.y;
4123 DrawRect.Left := MouseRDownPos.x;
4124 DrawRect.Bottom := MousePos.y;
4125 DrawRect.Right := MousePos.x;
4127 else
4128 // Двигаем выделенные объекты:
4129 if MouseAction = MOUSEACTION_MOVEOBJ then
4130 begin
4131 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
4132 MousePos.X-LastMovePoint.X,
4133 MousePos.Y-LastMovePoint.Y);
4135 else
4136 // Меняем размер выделенного объекта:
4137 if MouseAction = MOUSEACTION_RESIZE then
4138 begin
4139 if (SelectedObjectCount = 1) and
4140 (SelectedObjects[GetFirstSelected].Live) then
4141 begin
4142 dWidth := MousePos.X-LastMovePoint.X;
4143 dHeight := MousePos.Y-LastMovePoint.Y;
4145 case ResizeType of
4146 RESIZETYPE_VERTICAL: dWidth := 0;
4147 RESIZETYPE_HORIZONTAL: dHeight := 0;
4148 end;
4150 case ResizeDirection of
4151 RESIZEDIR_UP: dHeight := -dHeight;
4152 RESIZEDIR_LEFT: dWidth := -dWidth;
4153 end;
4155 if ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
4156 SelectedObjects[GetFirstSelected].ID,
4157 dWidth, dHeight, ResizeDirection) then
4158 LastMovePoint := MousePos;
4159 end;
4160 end;
4161 end;
4163 // Зажата только левая кнопка мыши:
4164 if (not MouseRDown) and (MouseLDown) and (not MouseMDown) then
4165 begin
4166 // Рисуем прямоугольник планирования панели:
4167 if MouseAction in [MOUSEACTION_DRAWPANEL,
4168 MOUSEACTION_DRAWTRIGGER,
4169 MOUSEACTION_DRAWPRESS] then
4170 begin
4171 if DrawRect = nil then
4172 New(DrawRect);
4173 if ssCtrl in Shift then
4174 begin
4175 wWidth := DotStep;
4176 wHeight := DotStep;
4177 if (lbTextureList.ItemIndex <> -1) and (not IsSpecialTextureSel()) and
4178 (MouseAction = MOUSEACTION_DRAWPANEL) then
4179 begin
4180 if not g_GetTexture(SelectedTexture(), TextureID) then
4181 g_GetTexture('NOTEXTURE', TextureID);
4182 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
4183 end;
4184 DrawRect.Top := MouseLDownPos.y;
4185 DrawRect.Left := MouseLDownPos.x;
4186 DrawRect.Bottom := DrawRect.Top + wHeight;
4187 DrawRect.Right := DrawRect.Left + wWidth;
4189 else
4190 begin
4191 DrawRect.Top := MouseLDownPos.y;
4192 DrawRect.Left := MouseLDownPos.x;
4193 DrawRect.Bottom := MousePos.y;
4194 DrawRect.Right := MousePos.x;
4195 end;
4197 else // Двигаем карту:
4198 if MouseAction = MOUSEACTION_MOVEMAP then
4199 begin
4200 MoveMap(X, Y);
4201 end;
4202 end;
4204 // Only Middle Mouse Button is pressed
4205 if (not MouseLDown) and (not MouseRDown) and (MouseMDown) then
4206 begin
4207 MapOffset.X := -EnsureRange(-MapOffset.X + MouseMDownPos.X - Mouse.CursorPos.X,
4208 sbHorizontal.Min, sbHorizontal.Max);
4209 sbHorizontal.Position := -MapOffset.X;
4210 MapOffset.Y := -EnsureRange(-MapOffset.Y + MouseMDownPos.Y - Mouse.CursorPos.Y,
4211 sbVertical.Min, sbVertical.Max);
4212 sbVertical.Position := -MapOffset.Y;
4213 MouseMDownPos := Mouse.CursorPos;
4214 end;
4216 // Клавиши мыши не зажаты:
4217 if (not MouseRDown) and (not MouseLDown) then
4218 DrawRect := nil;
4220 // Строка состояния - координаты мыши:
4221 StatusBar.Panels[1].Text := Format('(%d:%d)',
4222 [MousePos.X-MapOffset.X, MousePos.Y-MapOffset.Y]);
4223 end;
4225 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
4226 begin
4227 CanClose := MessageBox(0, PChar(_lc[I_MSG_EXIT_PROMT]),
4228 PChar(_lc[I_MSG_EXIT]),
4229 MB_ICONQUESTION or MB_YESNO or
4230 MB_DEFBUTTON1) = idYes;
4231 end;
4233 procedure TMainForm.aExitExecute(Sender: TObject);
4234 begin
4235 Close();
4236 end;
4238 procedure TMainForm.FormDestroy(Sender: TObject);
4240 config: TConfig;
4241 i: Integer;
4242 begin
4243 config := TConfig.CreateFile(CfgFileName);
4245 if WindowState <> wsMaximized then
4246 begin
4247 config.WriteInt('Editor', 'XPos', Left);
4248 config.WriteInt('Editor', 'YPos', Top);
4249 config.WriteInt('Editor', 'Width', Width);
4250 config.WriteInt('Editor', 'Height', Height);
4252 else
4253 begin
4254 config.WriteInt('Editor', 'XPos', RestoredLeft);
4255 config.WriteInt('Editor', 'YPos', RestoredTop);
4256 config.WriteInt('Editor', 'Width', RestoredWidth);
4257 config.WriteInt('Editor', 'Height', RestoredHeight);
4258 end;
4259 config.WriteBool('Editor', 'Maximize', WindowState = wsMaximized);
4260 config.WriteBool('Editor', 'Minimap', ShowMap);
4261 config.WriteInt('Editor', 'PanelProps', PanelProps.ClientWidth);
4262 config.WriteInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
4263 config.WriteBool('Editor', 'DotEnable', DotEnable);
4264 config.WriteInt('Editor', 'DotStep', DotStep);
4265 config.WriteStr('Editor', 'LastOpenDir', OpenDialog.InitialDir);
4266 config.WriteStr('Editor', 'LastSaveDir', SaveDialog.InitialDir);
4267 config.WriteBool('Editor', 'EdgeShow', drEdge[3] < 255);
4268 config.WriteInt('Editor', 'EdgeColor', gColorEdge);
4269 config.WriteInt('Editor', 'EdgeAlpha', gAlphaEdge);
4270 config.WriteInt('Editor', 'LineAlpha', gAlphaTriggerLine);
4271 config.WriteInt('Editor', 'TriggerAlpha', gAlphaTriggerArea);
4272 config.WriteInt('Editor', 'MonsterRectAlpha', gAlphaMonsterRect);
4273 config.WriteInt('Editor', 'AreaRectAlpha', gAlphaAreaRect);
4275 for i := 0 to RecentCount-1 do
4276 if i < RecentFiles.Count then
4277 config.WriteStr('RecentFiles', IntToStr(i+1), RecentFiles[i])
4278 else
4279 config.WriteStr('RecentFiles', IntToStr(i+1), '');
4280 RecentFiles.Free();
4282 config.SaveFile(CfgFileName);
4283 config.Free();
4285 slInvalidTextures.Free;
4286 end;
4288 procedure TMainForm.FormDropFiles(Sender: TObject;
4289 const FileNames: array of String);
4290 begin
4291 if Length(FileNames) <> 1 then
4292 Exit;
4294 OpenMapFile(FileNames[0]);
4295 end;
4297 procedure TMainForm.RenderPanelResize(Sender: TObject);
4298 begin
4299 if MainForm.Visible then
4300 MainForm.Resize();
4301 end;
4303 procedure TMainForm.Splitter1Moved(Sender: TObject);
4304 begin
4305 FormResize(Sender);
4306 end;
4308 procedure TMainForm.MapTestCheck(Sender: TObject);
4309 begin
4310 if MapTestProcess <> nil then
4311 begin
4312 if MapTestProcess.Running = false then
4313 begin
4314 if MapTestProcess.ExitCode <> 0 then
4315 Application.MessageBox(PChar(_lc[I_MSG_EXEC_ERROR]), 'FIXME', MB_OK or MB_ICONERROR);
4316 SysUtils.DeleteFile(MapTestFile);
4317 MapTestFile := '';
4318 FreeAndNil(MapTestProcess);
4319 tbTestMap.Enabled := True;
4320 end;
4321 end;
4322 end;
4324 procedure TMainForm.aMapOptionsExecute(Sender: TObject);
4326 ResName: String;
4327 begin
4328 MapOptionsForm.ShowModal();
4330 ResName := OpenedMap;
4331 while (Pos(':\', ResName) > 0) do
4332 Delete(ResName, 1, Pos(':\', ResName) + 1);
4334 UpdateCaption(gMapInfo.Name, ExtractFileName(OpenedWAD), ResName);
4335 end;
4337 procedure TMainForm.aAboutExecute(Sender: TObject);
4338 begin
4339 AboutForm.ShowModal();
4340 end;
4342 procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
4344 dx, dy, i: Integer;
4345 FileName: String;
4346 ok: Boolean;
4347 begin
4348 if (not EditingProperties) then
4349 begin
4350 if ssCtrl in Shift then
4351 begin
4352 case Chr(Key) of
4353 '1': ContourEnabled[LAYER_BACK] := not ContourEnabled[LAYER_BACK];
4354 '2': ContourEnabled[LAYER_WALLS] := not ContourEnabled[LAYER_WALLS];
4355 '3': ContourEnabled[LAYER_FOREGROUND] := not ContourEnabled[LAYER_FOREGROUND];
4356 '4': ContourEnabled[LAYER_STEPS] := not ContourEnabled[LAYER_STEPS];
4357 '5': ContourEnabled[LAYER_WATER] := not ContourEnabled[LAYER_WATER];
4358 '6': ContourEnabled[LAYER_ITEMS] := not ContourEnabled[LAYER_ITEMS];
4359 '7': ContourEnabled[LAYER_MONSTERS] := not ContourEnabled[LAYER_MONSTERS];
4360 '8': ContourEnabled[LAYER_AREAS] := not ContourEnabled[LAYER_AREAS];
4361 '9': ContourEnabled[LAYER_TRIGGERS] := not ContourEnabled[LAYER_TRIGGERS];
4362 '0':
4363 begin
4364 ok := False;
4365 for i := Low(ContourEnabled) to High(ContourEnabled) do
4366 if ContourEnabled[i] then
4367 ok := True;
4368 for i := Low(ContourEnabled) to High(ContourEnabled) do
4369 ContourEnabled[i] := not ok
4373 else
4374 begin
4375 case Chr(key) of
4376 '1': SwitchLayer(LAYER_BACK);
4377 '2': SwitchLayer(LAYER_WALLS);
4378 '3': SwitchLayer(LAYER_FOREGROUND);
4379 '4': SwitchLayer(LAYER_STEPS);
4380 '5': SwitchLayer(LAYER_WATER);
4381 '6': SwitchLayer(LAYER_ITEMS);
4382 '7': SwitchLayer(LAYER_MONSTERS);
4383 '8': SwitchLayer(LAYER_AREAS);
4384 '9': SwitchLayer(LAYER_TRIGGERS);
4385 '0': tbShowClick(tbShow);
4387 end;
4389 if Key = Ord('V') then
4390 begin // Поворот монстров и областей:
4391 if (SelectedObjects <> nil) then
4392 begin
4393 for i := 0 to High(SelectedObjects) do
4394 if (SelectedObjects[i].Live) then
4395 begin
4396 if (SelectedObjects[i].ObjectType = OBJECT_MONSTER) then
4397 begin
4398 g_ChangeDir(gMonsters[SelectedObjects[i].ID].Direction);
4400 else
4401 if (SelectedObjects[i].ObjectType = OBJECT_AREA) then
4402 begin
4403 g_ChangeDir(gAreas[SelectedObjects[i].ID].Direction);
4404 end;
4405 end;
4407 else
4408 begin
4409 if pcObjects.ActivePage = tsMonsters then
4410 begin
4411 if rbMonsterLeft.Checked then
4412 rbMonsterRight.Checked := True
4413 else
4414 rbMonsterLeft.Checked := True;
4415 end;
4416 if pcObjects.ActivePage = tsAreas then
4417 begin
4418 if rbAreaLeft.Checked then
4419 rbAreaRight.Checked := True
4420 else
4421 rbAreaLeft.Checked := True;
4422 end;
4423 end;
4424 end;
4426 if not (ssCtrl in Shift) then
4427 begin
4428 // Быстрое превью карты:
4429 if Key = Ord('E') then
4430 begin
4431 if PreviewMode = 0 then
4432 PreviewMode := 2;
4433 end;
4435 // Вертикальный скролл карты:
4436 with sbVertical do
4437 begin
4438 if Key = Ord('W') then
4439 begin
4440 dy := Position;
4441 if ssShift in Shift then Position := EnsureRange(Position - DotStep * 4, Min, Max)
4442 else Position := EnsureRange(Position - DotStep, Min, Max);
4443 MapOffset.Y := -Position;
4444 dy -= Position;
4446 if (MouseLDown or MouseRDown) then
4447 begin
4448 if DrawRect <> nil then
4449 begin
4450 Inc(MouseLDownPos.y, dy);
4451 Inc(MouseRDownPos.y, dy);
4452 end;
4453 Inc(LastMovePoint.Y, dy);
4454 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4455 end;
4456 end;
4458 if Key = Ord('S') then
4459 begin
4460 dy := Position;
4461 if ssShift in Shift then Position := EnsureRange(Position + DotStep * 4, Min, Max)
4462 else Position := EnsureRange(Position + DotStep, Min, Max);
4463 MapOffset.Y := -Position;
4464 dy -= Position;
4466 if (MouseLDown or MouseRDown) then
4467 begin
4468 if DrawRect <> nil then
4469 begin
4470 Inc(MouseLDownPos.y, dy);
4471 Inc(MouseRDownPos.y, dy);
4472 end;
4473 Inc(LastMovePoint.Y, dy);
4474 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4475 end;
4476 end;
4477 end;
4479 // Горизонтальный скролл карты:
4480 with sbHorizontal do
4481 begin
4482 if Key = Ord('A') then
4483 begin
4484 dx := Position;
4485 if ssShift in Shift then Position := EnsureRange(Position - DotStep * 4, Min, Max)
4486 else Position := EnsureRange(Position - DotStep, Min, Max);
4487 MapOffset.X := -Position;
4488 dx -= Position;
4490 if (MouseLDown or MouseRDown) then
4491 begin
4492 if DrawRect <> nil then
4493 begin
4494 Inc(MouseLDownPos.x, dx);
4495 Inc(MouseRDownPos.x, dx);
4496 end;
4497 Inc(LastMovePoint.X, dx);
4498 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4499 end;
4500 end;
4502 if Key = Ord('D') then
4503 begin
4504 dx := Position;
4505 if ssShift in Shift then Position := EnsureRange(Position + DotStep * 4, Min, Max)
4506 else Position := EnsureRange(Position + DotStep, Min, Max);
4507 MapOffset.X := -Position;
4508 dx -= Position;
4510 if (MouseLDown or MouseRDown) then
4511 begin
4512 if DrawRect <> nil then
4513 begin
4514 Inc(MouseLDownPos.x, dx);
4515 Inc(MouseRDownPos.x, dx);
4516 end;
4517 Inc(LastMovePoint.X, dx);
4518 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4519 end;
4520 end;
4521 end;
4523 else // ssCtrl in Shift
4524 begin
4525 if ssShift in Shift then
4526 begin
4527 // Вставка по абсолютному смещению:
4528 if Key = Ord('V') then
4529 aPasteObjectExecute(Sender);
4530 end;
4531 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4532 end;
4533 end;
4535 // Удалить выделенные объекты:
4536 if (Key = VK_DELETE) and (SelectedObjects <> nil) and
4537 RenderPanel.Focused() then
4538 DeleteSelectedObjects();
4540 // Снять выделение:
4541 if (Key = VK_ESCAPE) and (SelectedObjects <> nil) then
4542 RemoveSelectFromObjects();
4544 // Передвинуть объекты:
4545 if MainForm.ActiveControl = RenderPanel then
4546 begin
4547 dx := 0;
4548 dy := 0;
4550 if Key = VK_NUMPAD4 then
4551 dx := IfThen(ssAlt in Shift, -1, -DotStep);
4552 if Key = VK_NUMPAD6 then
4553 dx := IfThen(ssAlt in Shift, 1, DotStep);
4554 if Key = VK_NUMPAD8 then
4555 dy := IfThen(ssAlt in Shift, -1, -DotStep);
4556 if Key = VK_NUMPAD5 then
4557 dy := IfThen(ssAlt in Shift, 1, DotStep);
4559 if (dx <> 0) or (dy <> 0) then
4560 begin
4561 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift, dx, dy);
4562 Key := 0;
4563 end;
4564 end;
4566 if ssCtrl in Shift then
4567 begin
4568 // Выбор панели с текстурой для триггера
4569 if Key = Ord('T') then
4570 begin
4571 DrawPressRect := False;
4572 if SelectFlag = SELECTFLAG_TEXTURE then
4573 begin
4574 SelectFlag := SELECTFLAG_NONE;
4575 Exit;
4576 end;
4577 vleObjectProperty.FindRow(_lc[I_PROP_TR_TEXTURE_PANEL], i);
4578 if i > 0 then
4579 SelectFlag := SELECTFLAG_TEXTURE;
4580 end;
4582 if Key = Ord('D') then
4583 begin
4584 SelectFlag := SELECTFLAG_NONE;
4585 if DrawPressRect then
4586 begin
4587 DrawPressRect := False;
4588 Exit;
4589 end;
4590 i := -1;
4592 // Выбор области воздействия, в зависимости от типа триггера
4593 vleObjectProperty.FindRow(_lc[I_PROP_TR_EX_AREA], i);
4594 if i > 0 then
4595 begin
4596 DrawPressRect := True;
4597 Exit;
4598 end;
4599 vleObjectProperty.FindRow(_lc[I_PROP_TR_DOOR_PANEL], i);
4600 if i <= 0 then
4601 vleObjectProperty.FindRow(_lc[I_PROP_TR_TRAP_PANEL], i);
4602 if i > 0 then
4603 begin
4604 SelectFlag := SELECTFLAG_DOOR;
4605 Exit;
4606 end;
4607 vleObjectProperty.FindRow(_lc[I_PROP_TR_LIFT_PANEL], i);
4608 if i > 0 then
4609 begin
4610 SelectFlag := SELECTFLAG_LIFT;
4611 Exit;
4612 end;
4613 vleObjectProperty.FindRow(_lc[I_PROP_TR_TELEPORT_TO], i);
4614 if i > 0 then
4615 begin
4616 SelectFlag := SELECTFLAG_TELEPORT;
4617 Exit;
4618 end;
4619 vleObjectProperty.FindRow(_lc[I_PROP_TR_SPAWN_TO], i);
4620 if i > 0 then
4621 begin
4622 SelectFlag := SELECTFLAG_SPAWNPOINT;
4623 Exit;
4624 end;
4626 // Выбор основного параметра, в зависимости от типа триггера
4627 vleObjectProperty.FindRow(_lc[I_PROP_TR_NEXT_MAP], i);
4628 if i > 0 then
4629 begin
4630 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
4631 SelectMapForm.Caption := _lc[I_CAP_SELECT];
4632 SelectMapForm.GetMaps(FileName);
4634 if SelectMapForm.ShowModal() = mrOK then
4635 begin
4636 vleObjectProperty.Cells[1, i] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
4637 bApplyProperty.Click();
4638 end;
4639 Exit;
4640 end;
4641 vleObjectProperty.FindRow(_lc[I_PROP_TR_SOUND_NAME], i);
4642 if i <= 0 then
4643 vleObjectProperty.FindRow(_lc[I_PROP_TR_MUSIC_NAME], i);
4644 if i > 0 then
4645 begin
4646 AddSoundForm.OKFunction := nil;
4647 AddSoundForm.lbResourcesList.MultiSelect := False;
4648 AddSoundForm.SetResource := vleObjectProperty.Cells[1, i];
4650 if (AddSoundForm.ShowModal() = mrOk) then
4651 begin
4652 vleObjectProperty.Cells[1, i] := AddSoundForm.ResourceName;
4653 bApplyProperty.Click();
4654 end;
4655 Exit;
4656 end;
4657 vleObjectProperty.FindRow(_lc[I_PROP_TR_PUSH_ANGLE], i);
4658 if i <= 0 then
4659 vleObjectProperty.FindRow(_lc[I_PROP_TR_MESSAGE_TEXT], i);
4660 if i > 0 then
4661 begin
4662 vleObjectProperty.Row := i;
4663 vleObjectProperty.SetFocus();
4664 Exit;
4665 end;
4666 end;
4667 end;
4668 end;
4670 procedure TMainForm.aOptimizeExecute(Sender: TObject);
4671 begin
4672 RemoveSelectFromObjects();
4673 MapOptimizationForm.ShowModal();
4674 end;
4676 procedure TMainForm.aCheckMapExecute(Sender: TObject);
4677 begin
4678 MapCheckForm.ShowModal();
4679 end;
4681 procedure TMainForm.bbAddTextureClick(Sender: TObject);
4682 begin
4683 AddTextureForm.lbResourcesList.MultiSelect := True;
4684 AddTextureForm.ShowModal();
4685 end;
4687 procedure TMainForm.lbTextureListClick(Sender: TObject);
4689 TextureID: DWORD;
4690 TextureWidth, TextureHeight: Word;
4691 begin
4692 TextureID := 0;
4693 TextureWidth := 0;
4694 TextureHeight := 0;
4695 if (lbTextureList.ItemIndex <> -1) and
4696 (not IsSpecialTextureSel()) then
4697 begin
4698 if g_GetTexture(SelectedTexture(), TextureID) then
4699 begin
4700 g_GetTextureSizeByID(TextureID, TextureWidth, TextureHeight);
4702 lTextureWidth.Caption := IntToStr(TextureWidth);
4703 lTextureHeight.Caption := IntToStr(TextureHeight);
4704 end else
4705 begin
4706 lTextureWidth.Caption := _lc[I_NOT_ACCESSIBLE];
4707 lTextureHeight.Caption := _lc[I_NOT_ACCESSIBLE];
4708 end;
4710 else
4711 begin
4712 lTextureWidth.Caption := '';
4713 lTextureHeight.Caption := '';
4714 end;
4715 end;
4717 procedure TMainForm.lbTextureListDrawItem(Control: TWinControl; Index: Integer;
4718 ARect: TRect; State: TOwnerDrawState);
4719 begin
4720 with Control as TListBox do
4721 begin
4722 if LCLType.odSelected in State then
4723 begin
4724 Canvas.Brush.Color := clHighlight;
4725 Canvas.Font.Color := clHighlightText;
4726 end else
4727 if (Items <> nil) and (Index >= 0) then
4728 if slInvalidTextures.IndexOf(Items[Index]) > -1 then
4729 begin
4730 Canvas.Brush.Color := clRed;
4731 Canvas.Font.Color := clWhite;
4732 end;
4733 Canvas.FillRect(ARect);
4734 Canvas.TextRect(ARect, ARect.Left, ARect.Top, Items[Index]);
4735 end;
4736 end;
4738 procedure TMainForm.miReopenMapClick(Sender: TObject);
4740 FileName, Resource: String;
4741 begin
4742 if OpenedMap = '' then
4743 Exit;
4745 if MessageBox(0, PChar(_lc[I_MSG_REOPEN_MAP_PROMT]),
4746 PChar(_lc[I_MENU_FILE_REOPEN]), MB_ICONQUESTION or MB_YESNO) <> idYes then
4747 Exit;
4749 g_ProcessResourceStr(OpenedMap, @FileName, nil, @Resource);
4750 OpenMap(FileName, Resource);
4751 end;
4753 procedure TMainForm.vleObjectPropertyGetPickList(Sender: TObject;
4754 const KeyName: String; Values: TStrings);
4755 begin
4756 if vleObjectProperty.ItemProps[KeyName].EditStyle = esPickList then
4757 begin
4758 if KeyName = _lc[I_PROP_DIRECTION] then
4759 begin
4760 Values.Add(DirNames[D_LEFT]);
4761 Values.Add(DirNames[D_RIGHT]);
4763 else if KeyName = _lc[I_PROP_TR_TELEPORT_DIR] then
4764 begin
4765 Values.Add(DirNamesAdv[0]);
4766 Values.Add(DirNamesAdv[1]);
4767 Values.Add(DirNamesAdv[2]);
4768 Values.Add(DirNamesAdv[3]);
4770 else if KeyName = _lc[I_PROP_TR_MUSIC_ACT] then
4771 begin
4772 Values.Add(_lc[I_PROP_TR_MUSIC_ON]);
4773 Values.Add(_lc[I_PROP_TR_MUSIC_OFF]);
4775 else if KeyName = _lc[I_PROP_TR_MONSTER_BEHAVIOUR] then
4776 begin
4777 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_0]);
4778 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_1]);
4779 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_2]);
4780 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_3]);
4781 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_4]);
4782 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_5]);
4784 else if KeyName = _lc[I_PROP_TR_SCORE_ACT] then
4785 begin
4786 Values.Add(_lc[I_PROP_TR_SCORE_ACT_0]);
4787 Values.Add(_lc[I_PROP_TR_SCORE_ACT_1]);
4788 Values.Add(_lc[I_PROP_TR_SCORE_ACT_2]);
4789 Values.Add(_lc[I_PROP_TR_SCORE_ACT_3]);
4791 else if KeyName = _lc[I_PROP_TR_SCORE_TEAM] then
4792 begin
4793 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_0]);
4794 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_1]);
4795 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_2]);
4796 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_3]);
4798 else if KeyName = _lc[I_PROP_TR_MESSAGE_KIND] then
4799 begin
4800 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_0]);
4801 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_1]);
4803 else if KeyName = _lc[I_PROP_TR_MESSAGE_TO] then
4804 begin
4805 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_0]);
4806 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_1]);
4807 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_2]);
4808 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_3]);
4809 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_4]);
4810 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_5]);
4812 else if KeyName = _lc[I_PROP_TR_SHOT_TO] then
4813 begin
4814 Values.Add(_lc[I_PROP_TR_SHOT_TO_0]);
4815 Values.Add(_lc[I_PROP_TR_SHOT_TO_1]);
4816 Values.Add(_lc[I_PROP_TR_SHOT_TO_2]);
4817 Values.Add(_lc[I_PROP_TR_SHOT_TO_3]);
4818 Values.Add(_lc[I_PROP_TR_SHOT_TO_4]);
4819 Values.Add(_lc[I_PROP_TR_SHOT_TO_5]);
4820 Values.Add(_lc[I_PROP_TR_SHOT_TO_6]);
4822 else if KeyName = _lc[I_PROP_TR_SHOT_AIM] then
4823 begin
4824 Values.Add(_lc[I_PROP_TR_SHOT_AIM_0]);
4825 Values.Add(_lc[I_PROP_TR_SHOT_AIM_1]);
4826 Values.Add(_lc[I_PROP_TR_SHOT_AIM_2]);
4827 Values.Add(_lc[I_PROP_TR_SHOT_AIM_3]);
4829 else if KeyName = _lc[I_PROP_TR_DAMAGE_KIND] then
4830 begin
4831 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_0]);
4832 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_3]);
4833 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_4]);
4834 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_5]);
4835 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_6]);
4836 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_7]);
4837 Values.Add(_lc[I_PROP_TR_DAMAGE_KIND_8]);
4839 else if (KeyName = _lc[I_PROP_PANEL_BLEND]) or
4840 (KeyName = _lc[I_PROP_DM_ONLY]) or
4841 (KeyName = _lc[I_PROP_ITEM_FALLS]) or
4842 (KeyName = _lc[I_PROP_TR_ENABLED]) or
4843 (KeyName = _lc[I_PROP_TR_D2D]) or
4844 (KeyName = _lc[I_PROP_TR_SILENT]) or
4845 (KeyName = _lc[I_PROP_TR_TELEPORT_SILENT]) or
4846 (KeyName = _lc[I_PROP_TR_EX_RANDOM]) or
4847 (KeyName = _lc[I_PROP_TR_TEXTURE_ONCE]) or
4848 (KeyName = _lc[I_PROP_TR_TEXTURE_ANIM_ONCE]) or
4849 (KeyName = _lc[I_PROP_TR_SOUND_LOCAL]) or
4850 (KeyName = _lc[I_PROP_TR_SOUND_SWITCH]) or
4851 (KeyName = _lc[I_PROP_TR_MONSTER_ACTIVE]) or
4852 (KeyName = _lc[I_PROP_TR_PUSH_RESET]) or
4853 (KeyName = _lc[I_PROP_TR_SCORE_CON]) or
4854 (KeyName = _lc[I_PROP_TR_SCORE_MSG]) or
4855 (KeyName = _lc[I_PROP_TR_HEALTH_MAX]) or
4856 (KeyName = _lc[I_PROP_TR_SHOT_SOUND]) or
4857 (KeyName = _lc[I_PROP_TR_EFFECT_CENTER]) then
4858 begin
4859 Values.Add(BoolNames[True]);
4860 Values.Add(BoolNames[False]);
4861 end;
4862 end;
4863 end;
4865 procedure TMainForm.bApplyPropertyClick(Sender: TObject);
4867 _id, a, r, c: Integer;
4868 s: String;
4869 res: Boolean;
4870 NoTextureID: DWORD;
4871 NW, NH: Word;
4872 begin
4873 NoTextureID := 0;
4874 NW := 0;
4875 NH := 0;
4877 if SelectedObjectCount() <> 1 then
4878 Exit;
4879 if not SelectedObjects[GetFirstSelected()].Live then
4880 Exit;
4883 if not CheckProperty() then
4884 Exit;
4885 except
4886 Exit;
4887 end;
4889 _id := GetFirstSelected();
4891 r := vleObjectProperty.Row;
4892 c := vleObjectProperty.Col;
4894 case SelectedObjects[_id].ObjectType of
4895 OBJECT_PANEL:
4896 begin
4897 with gPanels[SelectedObjects[_id].ID] do
4898 begin
4899 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4900 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4901 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4902 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4904 PanelType := GetPanelType(vleObjectProperty.Values[_lc[I_PROP_PANEL_TYPE]]);
4906 // Сброс ссылки на триггеры смены текстуры:
4907 if not WordBool(PanelType and (PANEL_WALL or PANEL_FORE or PANEL_BACK)) then
4908 if gTriggers <> nil then
4909 for a := 0 to High(gTriggers) do
4910 begin
4911 if (gTriggers[a].TriggerType <> 0) and
4912 (gTriggers[a].TexturePanel = Integer(SelectedObjects[_id].ID)) then
4913 gTriggers[a].TexturePanel := -1;
4914 if (gTriggers[a].TriggerType = TRIGGER_SHOT) and
4915 (gTriggers[a].Data.ShotPanelID = Integer(SelectedObjects[_id].ID)) then
4916 gTriggers[a].Data.ShotPanelID := -1;
4917 end;
4919 // Сброс ссылки на триггеры лифта:
4920 if not WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
4921 if gTriggers <> nil then
4922 for a := 0 to High(gTriggers) do
4923 if (gTriggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
4924 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4925 gTriggers[a].Data.PanelID := -1;
4927 // Сброс ссылки на триггеры двери:
4928 if not WordBool(PanelType and (PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
4929 if gTriggers <> nil then
4930 for a := 0 to High(gTriggers) do
4931 if (gTriggers[a].TriggerType in [TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
4932 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP]) and
4933 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4934 gTriggers[a].Data.PanelID := -1;
4936 if IsTexturedPanel(PanelType) then
4937 begin // Может быть текстура
4938 if TextureName <> '' then
4939 begin // Была текстура
4940 Alpha := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]]));
4941 Blending := NameToBool(vleObjectProperty.Values[_lc[I_PROP_PANEL_BLEND]]);
4943 else // Не было
4944 begin
4945 Alpha := 0;
4946 Blending := False;
4947 end;
4949 // Новая текстура:
4950 TextureName := vleObjectProperty.Values[_lc[I_PROP_PANEL_TEX]];
4952 if TextureName <> '' then
4953 begin // Есть текстура
4954 // Обычная текстура:
4955 if not IsSpecialTexture(TextureName) then
4956 begin
4957 g_GetTextureSizeByName(TextureName,
4958 TextureWidth, TextureHeight);
4960 // Проверка кратности размеров панели:
4961 res := True;
4962 if TextureWidth <> 0 then
4963 if gPanels[SelectedObjects[_id].ID].Width mod TextureWidth <> 0 then
4964 begin
4965 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
4966 [TextureWidth]));
4967 Res := False;
4968 end;
4969 if Res and (TextureHeight <> 0) then
4970 if gPanels[SelectedObjects[_id].ID].Height mod TextureHeight <> 0 then
4971 begin
4972 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
4973 [TextureHeight]));
4974 Res := False;
4975 end;
4977 if Res then
4978 begin
4979 if not g_GetTexture(TextureName, TextureID) then
4980 // Не удалось загрузить текстуру, рисуем NOTEXTURE
4981 if g_GetTexture('NOTEXTURE', NoTextureID) then
4982 begin
4983 TextureID := TEXTURE_SPECIAL_NOTEXTURE;
4984 g_GetTextureSizeByID(NoTextureID, NW, NH);
4985 TextureWidth := NW;
4986 TextureHeight := NH;
4987 end else
4988 begin
4989 TextureID := TEXTURE_SPECIAL_NONE;
4990 TextureWidth := 1;
4991 TextureHeight := 1;
4992 end;
4994 else
4995 begin
4996 TextureName := '';
4997 TextureWidth := 1;
4998 TextureHeight := 1;
4999 TextureID := TEXTURE_SPECIAL_NONE;
5000 end;
5002 else // Спец.текстура
5003 begin
5004 TextureHeight := 1;
5005 TextureWidth := 1;
5006 TextureID := SpecialTextureID(TextureName);
5007 end;
5009 else // Нет текстуры
5010 begin
5011 TextureWidth := 1;
5012 TextureHeight := 1;
5013 TextureID := TEXTURE_SPECIAL_NONE;
5014 end;
5016 else // Не может быть текстуры
5017 begin
5018 Alpha := 0;
5019 Blending := False;
5020 TextureName := '';
5021 TextureWidth := 1;
5022 TextureHeight := 1;
5023 TextureID := TEXTURE_SPECIAL_NONE;
5024 end;
5025 end;
5026 end;
5028 OBJECT_ITEM:
5029 begin
5030 with gItems[SelectedObjects[_id].ID] do
5031 begin
5032 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
5033 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
5034 OnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
5035 Fall := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
5036 end;
5037 end;
5039 OBJECT_MONSTER:
5040 begin
5041 with gMonsters[SelectedObjects[_id].ID] do
5042 begin
5043 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
5044 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
5045 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
5046 end;
5047 end;
5049 OBJECT_AREA:
5050 begin
5051 with gAreas[SelectedObjects[_id].ID] do
5052 begin
5053 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
5054 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
5055 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
5056 end;
5057 end;
5059 OBJECT_TRIGGER:
5060 begin
5061 with gTriggers[SelectedObjects[_id].ID] do
5062 begin
5063 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
5064 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
5065 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
5066 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
5067 Enabled := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_ENABLED]]);
5068 ActivateType := StrToActivate(vleObjectProperty.Values[_lc[I_PROP_TR_ACTIVATION]]);
5069 Key := StrToKey(vleObjectProperty.Values[_lc[I_PROP_TR_KEYS]]);
5071 case TriggerType of
5072 TRIGGER_EXIT:
5073 begin
5074 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_NEXT_MAP]]);
5075 FillByte(Data.MapName[0], 16, 0);
5076 if s <> '' then
5077 Move(s[1], Data.MapName[0], Min(Length(s), 16));
5078 end;
5080 TRIGGER_TEXTURE:
5081 begin
5082 Data.ActivateOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ONCE]]);
5083 Data.AnimOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ANIM_ONCE]]);
5084 end;
5086 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
5087 begin
5088 Data.Wait := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 65535);
5089 Data.Count := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_COUNT]], 0), 65535);
5090 if Data.Count < 1 then
5091 Data.Count := 1;
5092 if TriggerType = TRIGGER_PRESS then
5093 Data.ExtRandom := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EX_RANDOM]]);
5094 end;
5096 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
5097 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP, TRIGGER_LIFTDOWN,
5098 TRIGGER_LIFT:
5099 begin
5100 Data.NoSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
5101 Data.d2d_doors := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
5102 end;
5104 TRIGGER_TELEPORT:
5105 begin
5106 Data.d2d_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
5107 Data.silent_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_SILENT]]);
5108 Data.TlpDir := NameToDirAdv(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_DIR]]);
5109 end;
5111 TRIGGER_SOUND:
5112 begin
5113 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_NAME]]);
5114 FillByte(Data.SoundName[0], 64, 0);
5115 if s <> '' then
5116 Move(s[1], Data.SoundName[0], Min(Length(s), 64));
5118 Data.Volume := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_VOLUME]], 0), 255);
5119 Data.Pan := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_PAN]], 0), 255);
5120 Data.PlayCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_COUNT]], 0), 255);
5121 Data.Local := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_LOCAL]]);
5122 Data.SoundSwitch := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_SWITCH]]);
5123 end;
5125 TRIGGER_SPAWNMONSTER:
5126 begin
5127 Data.MonType := StrToMonster(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_TYPE]]);
5128 Data.MonDir := Byte(NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]));
5129 Data.MonHealth := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 1000000);
5130 if Data.MonHealth < 0 then
5131 Data.MonHealth := 0;
5132 Data.MonActive := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_ACTIVE]]);
5133 Data.MonCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
5134 if Data.MonCount < 1 then
5135 Data.MonCount := 1;
5136 Data.MonEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
5137 Data.MonMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
5138 Data.MonDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
5139 Data.MonBehav := 0;
5140 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1] then
5141 Data.MonBehav := 1;
5142 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2] then
5143 Data.MonBehav := 2;
5144 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3] then
5145 Data.MonBehav := 3;
5146 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4] then
5147 Data.MonBehav := 4;
5148 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5] then
5149 Data.MonBehav := 5;
5150 end;
5152 TRIGGER_SPAWNITEM:
5153 begin
5154 Data.ItemType := StrToItem(vleObjectProperty.Values[_lc[I_PROP_TR_ITEM_TYPE]]);
5155 Data.ItemOnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
5156 Data.ItemFalls := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
5157 Data.ItemCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
5158 if Data.ItemCount < 1 then
5159 Data.ItemCount := 1;
5160 Data.ItemEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
5161 Data.ItemMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
5162 Data.ItemDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
5163 end;
5165 TRIGGER_MUSIC:
5166 begin
5167 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_NAME]]);
5168 FillByte(Data.MusicName[0], 64, 0);
5169 if s <> '' then
5170 Move(s[1], Data.MusicName[0], Min(Length(s), 64));
5172 if vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_ACT]] = _lc[I_PROP_TR_MUSIC_ON] then
5173 Data.MusicAction := 1
5174 else
5175 Data.MusicAction := 0;
5176 end;
5178 TRIGGER_PUSH:
5179 begin
5180 Data.PushAngle := Min(
5181 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_ANGLE]], 0), 360);
5182 Data.PushForce := Min(
5183 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_FORCE]], 0), 255);
5184 Data.ResetVel := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_RESET]]);
5185 end;
5187 TRIGGER_SCORE:
5188 begin
5189 Data.ScoreAction := 0;
5190 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_1] then
5191 Data.ScoreAction := 1
5192 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_2] then
5193 Data.ScoreAction := 2
5194 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_3] then
5195 Data.ScoreAction := 3;
5196 Data.ScoreCount := Min(Max(
5197 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
5198 Data.ScoreTeam := 0;
5199 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_1] then
5200 Data.ScoreTeam := 1
5201 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_2] then
5202 Data.ScoreTeam := 2
5203 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_3] then
5204 Data.ScoreTeam := 3;
5205 Data.ScoreCon := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_CON]]);
5206 Data.ScoreMsg := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_MSG]]);
5207 end;
5209 TRIGGER_MESSAGE:
5210 begin
5211 Data.MessageKind := 0;
5212 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_KIND]] = _lc[I_PROP_TR_MESSAGE_KIND_1] then
5213 Data.MessageKind := 1;
5215 Data.MessageSendTo := 0;
5216 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_1] then
5217 Data.MessageSendTo := 1
5218 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_2] then
5219 Data.MessageSendTo := 2
5220 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_3] then
5221 Data.MessageSendTo := 3
5222 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_4] then
5223 Data.MessageSendTo := 4
5224 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_5] then
5225 Data.MessageSendTo := 5;
5227 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TEXT]]);
5228 FillByte(Data.MessageText[0], 100, 0);
5229 if s <> '' then
5230 Move(s[1], Data.MessageText[0], Min(Length(s), 100));
5232 Data.MessageTime := Min(Max(
5233 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TIME]], 0), 0), 65535);
5234 end;
5236 TRIGGER_DAMAGE:
5237 begin
5238 Data.DamageValue := Min(Max(
5239 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_DAMAGE_VALUE]], 0), 0), 65535);
5240 Data.DamageInterval := Min(Max(
5241 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
5242 s := vleObjectProperty.Values[_lc[I_PROP_TR_DAMAGE_KIND]];
5243 if s = _lc[I_PROP_TR_DAMAGE_KIND_3] then
5244 Data.DamageKind := 3
5245 else if s = _lc[I_PROP_TR_DAMAGE_KIND_4] then
5246 Data.DamageKind := 4
5247 else if s = _lc[I_PROP_TR_DAMAGE_KIND_5] then
5248 Data.DamageKind := 5
5249 else if s = _lc[I_PROP_TR_DAMAGE_KIND_6] then
5250 Data.DamageKind := 6
5251 else if s = _lc[I_PROP_TR_DAMAGE_KIND_7] then
5252 Data.DamageKind := 7
5253 else if s = _lc[I_PROP_TR_DAMAGE_KIND_8] then
5254 Data.DamageKind := 8
5255 else
5256 Data.DamageKind := 0;
5257 end;
5259 TRIGGER_HEALTH:
5260 begin
5261 Data.HealValue := Min(Max(
5262 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 0), 65535);
5263 Data.HealInterval := Min(Max(
5264 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
5265 Data.HealMax := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH_MAX]]);
5266 Data.HealSilent := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
5267 end;
5269 TRIGGER_SHOT:
5270 begin
5271 Data.ShotType := StrToShot(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TYPE]]);
5272 Data.ShotSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SOUND]]);
5273 Data.ShotTarget := 0;
5274 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_1] then
5275 Data.ShotTarget := 1
5276 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_2] then
5277 Data.ShotTarget := 2
5278 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_3] then
5279 Data.ShotTarget := 3
5280 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_4] then
5281 Data.ShotTarget := 4
5282 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_5] then
5283 Data.ShotTarget := 5
5284 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_6] then
5285 Data.ShotTarget := 6;
5286 Data.ShotIntSight := Min(Max(
5287 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SIGHT]], 0), 0), 65535);
5288 Data.ShotAim := 0;
5289 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_1] then
5290 Data.ShotAim := 1
5291 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_2] then
5292 Data.ShotAim := 2
5293 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_3] then
5294 Data.ShotAim := 3;
5295 Data.ShotAngle := Min(
5296 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ANGLE]], 0), 360);
5297 Data.ShotWait := Min(Max(
5298 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
5299 Data.ShotAccuracy := Min(Max(
5300 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ACC]], 0), 0), 65535);
5301 Data.ShotAmmo := Min(Max(
5302 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AMMO]], 0), 0), 65535);
5303 Data.ShotIntReload := Min(Max(
5304 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_RELOAD]], 0), 0), 65535);
5305 end;
5307 TRIGGER_EFFECT:
5308 begin
5309 Data.FXCount := Min(Max(
5310 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
5311 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_PARTICLE] then
5312 begin
5313 Data.FXType := TRIGGER_EFFECT_PARTICLE;
5314 Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
5315 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SLIQUID] then
5316 Data.FXSubType := TRIGGER_EFFECT_SLIQUID
5317 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
5318 Data.FXSubType := TRIGGER_EFFECT_LLIQUID
5319 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
5320 Data.FXSubType := TRIGGER_EFFECT_DLIQUID
5321 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BLOOD] then
5322 Data.FXSubType := TRIGGER_EFFECT_BLOOD
5323 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SPARK] then
5324 Data.FXSubType := TRIGGER_EFFECT_SPARK
5325 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
5326 Data.FXSubType := TRIGGER_EFFECT_BUBBLE;
5327 end else
5328 begin
5329 Data.FXType := TRIGGER_EFFECT_ANIMATION;
5330 Data.FXSubType := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]]);
5331 end;
5332 a := Min(Max(
5333 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_COLOR]], 0), 0), $FFFFFF);
5334 Data.FXColorR := a and $FF;
5335 Data.FXColorG := (a shr 8) and $FF;
5336 Data.FXColorB := (a shr 16) and $FF;
5337 if NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_CENTER]]) then
5338 Data.FXPos := 0
5339 else
5340 Data.FXPos := 1;
5341 Data.FXWait := Min(Max(
5342 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
5343 Data.FXVelX := Min(Max(
5344 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELX]], 0), -128), 127);
5345 Data.FXVelY := Min(Max(
5346 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELY]], 0), -128), 127);
5347 Data.FXSpreadL := Min(Max(
5348 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPL]], 0), 0), 255);
5349 Data.FXSpreadR := Min(Max(
5350 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPR]], 0), 0), 255);
5351 Data.FXSpreadU := Min(Max(
5352 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPU]], 0), 0), 255);
5353 Data.FXSpreadD := Min(Max(
5354 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPD]], 0), 0), 255);
5355 end;
5356 end;
5357 end;
5358 end;
5359 end;
5361 FillProperty();
5363 vleObjectProperty.Row := r;
5364 vleObjectProperty.Col := c;
5365 end;
5367 procedure TMainForm.bbRemoveTextureClick(Sender: TObject);
5369 a, i: Integer;
5370 begin
5371 i := lbTextureList.ItemIndex;
5372 if i = -1 then
5373 Exit;
5375 if MessageBox(0, PChar(Format(_lc[I_MSG_DEL_TEXTURE_PROMT],
5376 [SelectedTexture()])),
5377 PChar(_lc[I_MSG_DEL_TEXTURE]),
5378 MB_ICONQUESTION or MB_YESNO or
5379 MB_DEFBUTTON1) <> idYes then
5380 Exit;
5382 if gPanels <> nil then
5383 for a := 0 to High(gPanels) do
5384 if (gPanels[a].PanelType <> 0) and
5385 (gPanels[a].TextureName = SelectedTexture()) then
5386 begin
5387 ErrorMessageBox(_lc[I_MSG_DEL_TEXTURE_CANT]);
5388 Exit;
5389 end;
5391 g_DeleteTexture(SelectedTexture());
5392 i := slInvalidTextures.IndexOf(lbTextureList.Items[i]);
5393 if i > -1 then
5394 slInvalidTextures.Delete(i);
5395 if lbTextureList.ItemIndex > -1 then
5396 lbTextureList.Items.Delete(lbTextureList.ItemIndex)
5397 end;
5399 procedure TMainForm.aNewMapExecute(Sender: TObject);
5400 begin
5401 if (MessageBox(0, PChar(_lc[I_MSG_CLEAR_MAP_PROMT]),
5402 PChar(_lc[I_MSG_CLEAR_MAP]),
5403 MB_ICONQUESTION or MB_YESNO or
5404 MB_DEFBUTTON1) = mrYes) then
5405 FullClear();
5406 end;
5408 procedure TMainForm.aUndoExecute(Sender: TObject);
5410 a: Integer;
5411 begin
5412 if UndoBuffer = nil then
5413 Exit;
5414 if UndoBuffer[High(UndoBuffer)] = nil then
5415 Exit;
5417 for a := 0 to High(UndoBuffer[High(UndoBuffer)]) do
5418 with UndoBuffer[High(UndoBuffer)][a] do
5419 begin
5420 case UndoType of
5421 UNDO_DELETE_PANEL:
5422 begin
5423 AddPanel(Panel^);
5424 Panel := nil;
5425 end;
5426 UNDO_DELETE_ITEM: AddItem(Item);
5427 UNDO_DELETE_AREA: AddArea(Area);
5428 UNDO_DELETE_MONSTER: AddMonster(Monster);
5429 UNDO_DELETE_TRIGGER: AddTrigger(Trigger);
5430 UNDO_ADD_PANEL: RemoveObject(AddID, OBJECT_PANEL);
5431 UNDO_ADD_ITEM: RemoveObject(AddID, OBJECT_ITEM);
5432 UNDO_ADD_AREA: RemoveObject(AddID, OBJECT_AREA);
5433 UNDO_ADD_MONSTER: RemoveObject(AddID, OBJECT_MONSTER);
5434 UNDO_ADD_TRIGGER: RemoveObject(AddID, OBJECT_TRIGGER);
5435 end;
5436 end;
5438 SetLength(UndoBuffer, Length(UndoBuffer)-1);
5440 RemoveSelectFromObjects();
5442 miUndo.Enabled := UndoBuffer <> nil;
5443 end;
5446 procedure TMainForm.aCopyObjectExecute(Sender: TObject);
5448 a, b: Integer;
5449 CopyBuffer: TCopyRecArray;
5450 str: String;
5451 ok: Boolean;
5453 function CB_Compare(I1, I2: TCopyRec): Integer;
5454 begin
5455 Result := Integer(I1.ObjectType) - Integer(I2.ObjectType);
5457 if Result = 0 then // Одного типа
5458 Result := Integer(I1.ID) - Integer(I2.ID);
5459 end;
5461 procedure QuickSortCopyBuffer(L, R: Integer);
5463 I, J: Integer;
5464 P, T: TCopyRec;
5465 begin
5466 repeat
5467 I := L;
5468 J := R;
5469 P := CopyBuffer[(L + R) shr 1];
5471 repeat
5472 while CB_Compare(CopyBuffer[I], P) < 0 do
5473 Inc(I);
5474 while CB_Compare(CopyBuffer[J], P) > 0 do
5475 Dec(J);
5477 if I <= J then
5478 begin
5479 T := CopyBuffer[I];
5480 CopyBuffer[I] := CopyBuffer[J];
5481 CopyBuffer[J] := T;
5482 Inc(I);
5483 Dec(J);
5484 end;
5485 until I > J;
5487 if L < J then
5488 QuickSortCopyBuffer(L, J);
5490 L := I;
5491 until I >= R;
5492 end;
5494 begin
5495 if SelectedObjects = nil then
5496 Exit;
5498 b := -1;
5499 CopyBuffer := nil;
5501 // Копируем объекты:
5502 for a := 0 to High(SelectedObjects) do
5503 if SelectedObjects[a].Live then
5504 with SelectedObjects[a] do
5505 begin
5506 SetLength(CopyBuffer, Length(CopyBuffer)+1);
5507 b := High(CopyBuffer);
5508 CopyBuffer[b].ID := ID;
5509 CopyBuffer[b].Panel := nil;
5511 case ObjectType of
5512 OBJECT_PANEL:
5513 begin
5514 CopyBuffer[b].ObjectType := OBJECT_PANEL;
5515 New(CopyBuffer[b].Panel);
5516 CopyBuffer[b].Panel^ := gPanels[ID];
5517 end;
5519 OBJECT_ITEM:
5520 begin
5521 CopyBuffer[b].ObjectType := OBJECT_ITEM;
5522 CopyBuffer[b].Item := gItems[ID];
5523 end;
5525 OBJECT_MONSTER:
5526 begin
5527 CopyBuffer[b].ObjectType := OBJECT_MONSTER;
5528 CopyBuffer[b].Monster := gMonsters[ID];
5529 end;
5531 OBJECT_AREA:
5532 begin
5533 CopyBuffer[b].ObjectType := OBJECT_AREA;
5534 CopyBuffer[b].Area := gAreas[ID];
5535 end;
5537 OBJECT_TRIGGER:
5538 begin
5539 CopyBuffer[b].ObjectType := OBJECT_TRIGGER;
5540 CopyBuffer[b].Trigger := gTriggers[ID];
5541 end;
5542 end;
5543 end;
5545 // Сортировка по ID:
5546 if CopyBuffer <> nil then
5547 begin
5548 QuickSortCopyBuffer(0, b);
5549 end;
5551 // Пестановка ссылок триггеров:
5552 for a := 0 to Length(CopyBuffer)-1 do
5553 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5554 begin
5555 case CopyBuffer[a].Trigger.TriggerType of
5556 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5557 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5558 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5559 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5560 begin
5561 ok := False;
5563 for b := 0 to Length(CopyBuffer)-1 do
5564 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5565 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.PanelID) then
5566 begin
5567 CopyBuffer[a].Trigger.Data.PanelID := b;
5568 ok := True;
5569 Break;
5570 end;
5572 // Этих панелей нет среди копируемых:
5573 if not ok then
5574 CopyBuffer[a].Trigger.Data.PanelID := -1;
5575 end;
5577 TRIGGER_PRESS, TRIGGER_ON,
5578 TRIGGER_OFF, TRIGGER_ONOFF:
5579 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5580 begin
5581 ok := False;
5583 for b := 0 to Length(CopyBuffer)-1 do
5584 if (CopyBuffer[b].ObjectType = OBJECT_MONSTER) and
5585 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.MonsterID-1) then
5586 begin
5587 CopyBuffer[a].Trigger.Data.MonsterID := b+1;
5588 ok := True;
5589 Break;
5590 end;
5592 // Этих монстров нет среди копируемых:
5593 if not ok then
5594 CopyBuffer[a].Trigger.Data.MonsterID := 0;
5595 end;
5597 TRIGGER_SHOT:
5598 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5599 begin
5600 ok := False;
5602 for b := 0 to Length(CopyBuffer)-1 do
5603 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5604 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.ShotPanelID) then
5605 begin
5606 CopyBuffer[a].Trigger.Data.ShotPanelID := b;
5607 ok := True;
5608 Break;
5609 end;
5611 // Этих панелей нет среди копируемых:
5612 if not ok then
5613 CopyBuffer[a].Trigger.Data.ShotPanelID := -1;
5614 end;
5615 end;
5617 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5618 begin
5619 ok := False;
5621 for b := 0 to Length(CopyBuffer)-1 do
5622 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5623 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.TexturePanel) then
5624 begin
5625 CopyBuffer[a].Trigger.TexturePanel := b;
5626 ok := True;
5627 Break;
5628 end;
5630 // Этих панелей нет среди копируемых:
5631 if not ok then
5632 CopyBuffer[a].Trigger.TexturePanel := -1;
5633 end;
5634 end;
5636 // В буфер обмена:
5637 str := CopyBufferToString(CopyBuffer);
5638 ClipBoard.AsText := str;
5640 for a := 0 to Length(CopyBuffer)-1 do
5641 if (CopyBuffer[a].ObjectType = OBJECT_PANEL) and
5642 (CopyBuffer[a].Panel <> nil) then
5643 Dispose(CopyBuffer[a].Panel);
5645 CopyBuffer := nil;
5646 end;
5648 procedure TMainForm.aPasteObjectExecute(Sender: TObject);
5650 a, h: Integer;
5651 CopyBuffer: TCopyRecArray;
5652 res, rel: Boolean;
5653 swad, ssec, sres: String;
5654 NoTextureID: DWORD;
5655 pmin: TPoint;
5656 begin
5657 CopyBuffer := nil;
5658 NoTextureID := 0;
5659 pmin.X := High(pmin.X);
5660 pmin.Y := High(pmin.Y);
5662 StringToCopyBuffer(ClipBoard.AsText, CopyBuffer, pmin);
5663 rel := not(ssShift in GetKeyShiftState());
5665 if CopyBuffer = nil then
5666 Exit;
5668 RemoveSelectFromObjects();
5670 h := High(CopyBuffer);
5671 for a := 0 to h do
5672 with CopyBuffer[a] do
5673 begin
5674 case ObjectType of
5675 OBJECT_PANEL:
5676 if Panel <> nil then
5677 begin
5678 if rel then
5679 begin
5680 Panel^.X := Panel^.X - pmin.X - MapOffset.X + 32;
5681 Panel^.Y := Panel^.Y - pmin.Y - MapOffset.Y + 32;
5682 end;
5684 Panel^.TextureID := TEXTURE_SPECIAL_NONE;
5685 Panel^.TextureWidth := 1;
5686 Panel^.TextureHeight := 1;
5688 if (Panel^.PanelType = PANEL_LIFTUP) or
5689 (Panel^.PanelType = PANEL_LIFTDOWN) or
5690 (Panel^.PanelType = PANEL_LIFTLEFT) or
5691 (Panel^.PanelType = PANEL_LIFTRIGHT) or
5692 (Panel^.PanelType = PANEL_BLOCKMON) or
5693 (Panel^.TextureName = '') then
5694 begin // Нет или не может быть текстуры:
5696 else // Есть текстура:
5697 begin
5698 // Обычная текстура:
5699 if not IsSpecialTexture(Panel^.TextureName) then
5700 begin
5701 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5703 if not res then
5704 begin
5705 g_ProcessResourceStr(Panel^.TextureName, swad, ssec, sres);
5706 AddTexture(swad, ssec, sres, True);
5707 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5708 end;
5710 if res then
5711 g_GetTextureSizeByName(Panel^.TextureName,
5712 Panel^.TextureWidth, Panel^.TextureHeight)
5713 else
5714 if g_GetTexture('NOTEXTURE', NoTextureID) then
5715 begin
5716 Panel^.TextureID := TEXTURE_SPECIAL_NOTEXTURE;
5717 g_GetTextureSizeByID(NoTextureID, Panel^.TextureWidth, Panel^.TextureHeight);
5718 end;
5720 else // Спец.текстура:
5721 begin
5722 Panel^.TextureID := SpecialTextureID(Panel^.TextureName);
5723 with MainForm.lbTextureList.Items do
5724 if IndexOf(Panel^.TextureName) = -1 then
5725 Add(Panel^.TextureName);
5726 end;
5727 end;
5729 ID := AddPanel(Panel^);
5730 Dispose(Panel);
5731 Undo_Add(OBJECT_PANEL, ID, a > 0);
5732 SelectObject(OBJECT_PANEL, ID, True);
5733 end;
5735 OBJECT_ITEM:
5736 begin
5737 if rel then
5738 begin
5739 Item.X := Item.X - pmin.X - MapOffset.X + 32;
5740 Item.Y := Item.Y - pmin.Y - MapOffset.Y + 32;
5741 end;
5743 ID := AddItem(Item);
5744 Undo_Add(OBJECT_ITEM, ID, a > 0);
5745 SelectObject(OBJECT_ITEM, ID, True);
5746 end;
5748 OBJECT_MONSTER:
5749 begin
5750 if rel then
5751 begin
5752 Monster.X := Monster.X - pmin.X - MapOffset.X + 32;
5753 Monster.Y := Monster.Y - pmin.Y - MapOffset.Y + 32;
5754 end;
5756 ID := AddMonster(Monster);
5757 Undo_Add(OBJECT_MONSTER, ID, a > 0);
5758 SelectObject(OBJECT_MONSTER, ID, True);
5759 end;
5761 OBJECT_AREA:
5762 begin
5763 if rel then
5764 begin
5765 Area.X := Area.X - pmin.X - MapOffset.X + 32;
5766 Area.Y := Area.Y - pmin.Y - MapOffset.Y + 32;
5767 end;
5769 ID := AddArea(Area);
5770 Undo_Add(OBJECT_AREA, ID, a > 0);
5771 SelectObject(OBJECT_AREA, ID, True);
5772 end;
5774 OBJECT_TRIGGER:
5775 begin
5776 if rel then
5777 with Trigger do
5778 begin
5779 X := X - pmin.X - MapOffset.X + 32;
5780 Y := Y - pmin.Y - MapOffset.Y + 32;
5782 case TriggerType of
5783 TRIGGER_TELEPORT:
5784 begin
5785 Data.TargetPoint.X :=
5786 Data.TargetPoint.X - pmin.X - MapOffset.X + 32;
5787 Data.TargetPoint.Y :=
5788 Data.TargetPoint.Y - pmin.Y - MapOffset.Y + 32;
5789 end;
5790 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
5791 begin
5792 Data.tX := Data.tX - pmin.X - MapOffset.X + 32;
5793 Data.tY := Data.tY - pmin.Y - MapOffset.Y + 32;
5794 end;
5795 TRIGGER_SPAWNMONSTER:
5796 begin
5797 Data.MonPos.X :=
5798 Data.MonPos.X - pmin.X - MapOffset.X + 32;
5799 Data.MonPos.Y :=
5800 Data.MonPos.Y - pmin.Y - MapOffset.Y + 32;
5801 end;
5802 TRIGGER_SPAWNITEM:
5803 begin
5804 Data.ItemPos.X :=
5805 Data.ItemPos.X - pmin.X - MapOffset.X + 32;
5806 Data.ItemPos.Y :=
5807 Data.ItemPos.Y - pmin.Y - MapOffset.Y + 32;
5808 end;
5809 TRIGGER_SHOT:
5810 begin
5811 Data.ShotPos.X :=
5812 Data.ShotPos.X - pmin.X - MapOffset.X + 32;
5813 Data.ShotPos.Y :=
5814 Data.ShotPos.Y - pmin.Y - MapOffset.Y + 32;
5815 end;
5816 end;
5817 end;
5819 ID := AddTrigger(Trigger);
5820 Undo_Add(OBJECT_TRIGGER, ID, a > 0);
5821 SelectObject(OBJECT_TRIGGER, ID, True);
5822 end;
5823 end;
5824 end;
5826 // Переставляем ссылки триггеров:
5827 for a := 0 to High(CopyBuffer) do
5828 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5829 begin
5830 case CopyBuffer[a].Trigger.TriggerType of
5831 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5832 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5833 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5834 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5835 gTriggers[CopyBuffer[a].ID].Data.PanelID :=
5836 CopyBuffer[CopyBuffer[a].Trigger.Data.PanelID].ID;
5838 TRIGGER_PRESS, TRIGGER_ON,
5839 TRIGGER_OFF, TRIGGER_ONOFF:
5840 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5841 gTriggers[CopyBuffer[a].ID].Data.MonsterID :=
5842 CopyBuffer[CopyBuffer[a].Trigger.Data.MonsterID-1].ID+1;
5844 TRIGGER_SHOT:
5845 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5846 gTriggers[CopyBuffer[a].ID].Data.ShotPanelID :=
5847 CopyBuffer[CopyBuffer[a].Trigger.Data.ShotPanelID].ID;
5848 end;
5850 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5851 gTriggers[CopyBuffer[a].ID].TexturePanel :=
5852 CopyBuffer[CopyBuffer[a].Trigger.TexturePanel].ID;
5853 end;
5855 CopyBuffer := nil;
5857 if h = 0 then
5858 FillProperty();
5859 end;
5861 procedure TMainForm.aCutObjectExecute(Sender: TObject);
5862 begin
5863 miCopy.Click();
5864 DeleteSelectedObjects();
5865 end;
5867 procedure TMainForm.vleObjectPropertyEditButtonClick(Sender: TObject);
5869 Key, FileName: String;
5870 b: Byte;
5871 begin
5872 Key := vleObjectProperty.Keys[vleObjectProperty.Row];
5874 if Key = _lc[I_PROP_PANEL_TYPE] then
5875 begin
5876 with ChooseTypeForm, vleObjectProperty do
5877 begin // Выбор типа панели:
5878 Caption := _lc[I_PROP_PANEL_TYPE];
5879 lbTypeSelect.Items.Clear();
5881 for b := 0 to High(PANELNAMES) do
5882 begin
5883 lbTypeSelect.Items.Add(PANELNAMES[b]);
5884 if Values[Key] = PANELNAMES[b] then
5885 lbTypeSelect.ItemIndex := b;
5886 end;
5888 if ShowModal() = mrOK then
5889 begin
5890 b := lbTypeSelect.ItemIndex;
5891 Values[Key] := PANELNAMES[b];
5892 vleObjectPropertyApply(Sender);
5893 end;
5896 else if Key = _lc[I_PROP_TR_TELEPORT_TO] then
5897 SelectFlag := SELECTFLAG_TELEPORT
5898 else if Key = _lc[I_PROP_TR_SPAWN_TO] then
5899 SelectFlag := SELECTFLAG_SPAWNPOINT
5900 else if (Key = _lc[I_PROP_TR_DOOR_PANEL]) or
5901 (Key = _lc[I_PROP_TR_TRAP_PANEL]) then
5902 SelectFlag := SELECTFLAG_DOOR
5903 else if Key = _lc[I_PROP_TR_TEXTURE_PANEL] then
5904 begin
5905 DrawPressRect := False;
5906 SelectFlag := SELECTFLAG_TEXTURE;
5908 else if Key = _lc[I_PROP_TR_SHOT_PANEL] then
5909 SelectFlag := SELECTFLAG_SHOTPANEL
5910 else if Key = _lc[I_PROP_TR_LIFT_PANEL] then
5911 SelectFlag := SELECTFLAG_LIFT
5912 else if key = _lc[I_PROP_TR_EX_MONSTER] then
5913 SelectFlag := SELECTFLAG_MONSTER
5914 else if Key = _lc[I_PROP_TR_EX_AREA] then
5915 begin
5916 SelectFlag := SELECTFLAG_NONE;
5917 DrawPressRect := True;
5919 else if Key = _lc[I_PROP_TR_NEXT_MAP] then
5920 begin // Выбор следующей карты:
5921 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
5922 SelectMapForm.Caption := _lc[I_CAP_SELECT];
5923 SelectMapForm.GetMaps(FileName);
5925 if SelectMapForm.ShowModal() = mrOK then
5926 begin
5927 vleObjectProperty.Values[Key] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
5928 vleObjectPropertyApply(Sender);
5929 end;
5931 else if (Key = _lc[I_PROP_TR_SOUND_NAME]) or
5932 (Key = _lc[I_PROP_TR_MUSIC_NAME]) then
5933 begin // Выбор файла звука/музыки:
5934 AddSoundForm.OKFunction := nil;
5935 AddSoundForm.lbResourcesList.MultiSelect := False;
5936 AddSoundForm.SetResource := vleObjectProperty.Values[Key];
5938 if (AddSoundForm.ShowModal() = mrOk) then
5939 begin
5940 vleObjectProperty.Values[Key] := AddSoundForm.ResourceName;
5941 vleObjectPropertyApply(Sender);
5942 end;
5944 else if Key = _lc[I_PROP_TR_ACTIVATION] then
5945 with ActivationTypeForm, vleObjectProperty do
5946 begin // Выбор типов активации:
5947 cbPlayerCollide.Checked := Pos('PC', Values[Key]) > 0;
5948 cbMonsterCollide.Checked := Pos('MC', Values[Key]) > 0;
5949 cbPlayerPress.Checked := Pos('PP', Values[Key]) > 0;
5950 cbMonsterPress.Checked := Pos('MP', Values[Key]) > 0;
5951 cbShot.Checked := Pos('SH', Values[Key]) > 0;
5952 cbNoMonster.Checked := Pos('NM', Values[Key]) > 0;
5954 if ShowModal() = mrOK then
5955 begin
5956 b := 0;
5957 if cbPlayerCollide.Checked then
5958 b := ACTIVATE_PLAYERCOLLIDE;
5959 if cbMonsterCollide.Checked then
5960 b := b or ACTIVATE_MONSTERCOLLIDE;
5961 if cbPlayerPress.Checked then
5962 b := b or ACTIVATE_PLAYERPRESS;
5963 if cbMonsterPress.Checked then
5964 b := b or ACTIVATE_MONSTERPRESS;
5965 if cbShot.Checked then
5966 b := b or ACTIVATE_SHOT;
5967 if cbNoMonster.Checked then
5968 b := b or ACTIVATE_NOMONSTER;
5970 Values[Key] := ActivateToStr(b);
5971 vleObjectPropertyApply(Sender);
5972 end;
5974 else if Key = _lc[I_PROP_TR_KEYS] then
5975 with KeysForm, vleObjectProperty do
5976 begin // Выбор необходимых ключей:
5977 cbRedKey.Checked := Pos('RK', Values[Key]) > 0;
5978 cbGreenKey.Checked := Pos('GK', Values[Key]) > 0;
5979 cbBlueKey.Checked := Pos('BK', Values[Key]) > 0;
5980 cbRedTeam.Checked := Pos('RT', Values[Key]) > 0;
5981 cbBlueTeam.Checked := Pos('BT', Values[Key]) > 0;
5983 if ShowModal() = mrOK then
5984 begin
5985 b := 0;
5986 if cbRedKey.Checked then
5987 b := KEY_RED;
5988 if cbGreenKey.Checked then
5989 b := b or KEY_GREEN;
5990 if cbBlueKey.Checked then
5991 b := b or KEY_BLUE;
5992 if cbRedTeam.Checked then
5993 b := b or KEY_REDTEAM;
5994 if cbBlueTeam.Checked then
5995 b := b or KEY_BLUETEAM;
5997 Values[Key] := KeyToStr(b);
5998 vleObjectPropertyApply(Sender);
5999 end;
6001 else if Key = _lc[I_PROP_TR_FX_TYPE] then
6002 with ChooseTypeForm, vleObjectProperty do
6003 begin // Выбор типа эффекта:
6004 Caption := _lc[I_CAP_FX_TYPE];
6005 lbTypeSelect.Items.Clear();
6007 for b := EFFECT_NONE to EFFECT_FIRE do
6008 lbTypeSelect.Items.Add(EffectToStr(b));
6010 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]);
6012 if ShowModal() = mrOK then
6013 begin
6014 b := lbTypeSelect.ItemIndex;
6015 Values[Key] := EffectToStr(b);
6016 vleObjectPropertyApply(Sender);
6017 end;
6019 else if Key = _lc[I_PROP_TR_MONSTER_TYPE] then
6020 with ChooseTypeForm, vleObjectProperty do
6021 begin // Выбор типа монстра:
6022 Caption := _lc[I_CAP_MONSTER_TYPE];
6023 lbTypeSelect.Items.Clear();
6025 for b := MONSTER_DEMON to MONSTER_MAN do
6026 lbTypeSelect.Items.Add(MonsterToStr(b));
6028 lbTypeSelect.ItemIndex := StrToMonster(Values[Key]) - MONSTER_DEMON;
6030 if ShowModal() = mrOK then
6031 begin
6032 b := lbTypeSelect.ItemIndex + MONSTER_DEMON;
6033 Values[Key] := MonsterToStr(b);
6034 vleObjectPropertyApply(Sender);
6035 end;
6037 else if Key = _lc[I_PROP_TR_ITEM_TYPE] then
6038 with ChooseTypeForm, vleObjectProperty do
6039 begin // Выбор типа предмета:
6040 Caption := _lc[I_CAP_ITEM_TYPE];
6041 lbTypeSelect.Items.Clear();
6043 for b := ITEM_MEDKIT_SMALL to ITEM_KEY_BLUE do
6044 lbTypeSelect.Items.Add(ItemToStr(b));
6045 lbTypeSelect.Items.Add(ItemToStr(ITEM_BOTTLE));
6046 lbTypeSelect.Items.Add(ItemToStr(ITEM_HELMET));
6047 lbTypeSelect.Items.Add(ItemToStr(ITEM_JETPACK));
6048 lbTypeSelect.Items.Add(ItemToStr(ITEM_INVIS));
6049 lbTypeSelect.Items.Add(ItemToStr(ITEM_WEAPON_FLAMETHROWER));
6050 lbTypeSelect.Items.Add(ItemToStr(ITEM_AMMO_FUELCAN));
6052 b := StrToItem(Values[Key]);
6053 if b >= ITEM_BOTTLE then
6054 b := b - 2;
6055 lbTypeSelect.ItemIndex := b - ITEM_MEDKIT_SMALL;
6057 if ShowModal() = mrOK then
6058 begin
6059 b := lbTypeSelect.ItemIndex + ITEM_MEDKIT_SMALL;
6060 if b >= ITEM_WEAPON_KASTET then
6061 b := b + 2;
6062 Values[Key] := ItemToStr(b);
6063 vleObjectPropertyApply(Sender);
6064 end;
6066 else if Key = _lc[I_PROP_TR_SHOT_TYPE] then
6067 with ChooseTypeForm, vleObjectProperty do
6068 begin // Выбор типа предмета:
6069 Caption := _lc[I_PROP_TR_SHOT_TYPE];
6070 lbTypeSelect.Items.Clear();
6072 for b := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
6073 lbTypeSelect.Items.Add(ShotToStr(b));
6075 lbTypeSelect.ItemIndex := StrToShot(Values[Key]);
6077 if ShowModal() = mrOK then
6078 begin
6079 b := lbTypeSelect.ItemIndex;
6080 Values[Key] := ShotToStr(b);
6081 vleObjectPropertyApply(Sender);
6082 end;
6084 else if Key = _lc[I_PROP_TR_EFFECT_TYPE] then
6085 with ChooseTypeForm, vleObjectProperty do
6086 begin // Выбор типа эффекта:
6087 Caption := _lc[I_CAP_FX_TYPE];
6088 lbTypeSelect.Items.Clear();
6090 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_PARTICLE]);
6091 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_ANIMATION]);
6092 if Values[Key] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
6093 lbTypeSelect.ItemIndex := 1
6094 else
6095 lbTypeSelect.ItemIndex := 0;
6097 if ShowModal() = mrOK then
6098 begin
6099 b := lbTypeSelect.ItemIndex;
6100 if b = 0 then
6101 Values[Key] := _lc[I_PROP_TR_EFFECT_PARTICLE]
6102 else
6103 Values[Key] := _lc[I_PROP_TR_EFFECT_ANIMATION];
6104 vleObjectPropertyApply(Sender);
6105 end;
6107 else if Key = _lc[I_PROP_TR_EFFECT_SUBTYPE] then
6108 with ChooseTypeForm, vleObjectProperty do
6109 begin // Выбор подтипа эффекта:
6110 Caption := _lc[I_CAP_FX_TYPE];
6111 lbTypeSelect.Items.Clear();
6113 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
6114 begin
6115 for b := EFFECT_TELEPORT to EFFECT_FIRE do
6116 lbTypeSelect.Items.Add(EffectToStr(b));
6118 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]) - 1;
6119 end else
6120 begin
6121 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SLIQUID]);
6122 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_LLIQUID]);
6123 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_DLIQUID]);
6124 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BLOOD]);
6125 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SPARK]);
6126 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BUBBLE]);
6127 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SLIQUID;
6128 if Values[Key] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
6129 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_LLIQUID;
6130 if Values[Key] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
6131 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_DLIQUID;
6132 if Values[Key] = _lc[I_PROP_TR_EFFECT_BLOOD] then
6133 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BLOOD;
6134 if Values[Key] = _lc[I_PROP_TR_EFFECT_SPARK] then
6135 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SPARK;
6136 if Values[Key] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
6137 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BUBBLE;
6138 end;
6140 if ShowModal() = mrOK then
6141 begin
6142 b := lbTypeSelect.ItemIndex;
6144 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
6145 Values[Key] := EffectToStr(b + 1)
6146 else begin
6147 Values[Key] := _lc[I_PROP_TR_EFFECT_SLIQUID];
6148 if b = TRIGGER_EFFECT_LLIQUID then
6149 Values[Key] := _lc[I_PROP_TR_EFFECT_LLIQUID];
6150 if b = TRIGGER_EFFECT_DLIQUID then
6151 Values[Key] := _lc[I_PROP_TR_EFFECT_DLIQUID];
6152 if b = TRIGGER_EFFECT_BLOOD then
6153 Values[Key] := _lc[I_PROP_TR_EFFECT_BLOOD];
6154 if b = TRIGGER_EFFECT_SPARK then
6155 Values[Key] := _lc[I_PROP_TR_EFFECT_SPARK];
6156 if b = TRIGGER_EFFECT_BUBBLE then
6157 Values[Key] := _lc[I_PROP_TR_EFFECT_BUBBLE];
6158 end;
6160 vleObjectPropertyApply(Sender);
6161 end;
6163 else if Key = _lc[I_PROP_TR_EFFECT_COLOR] then
6164 with vleObjectProperty do
6165 begin // Выбор цвета эффекта:
6166 ColorDialog.Color := StrToIntDef(Values[Key], 0);
6167 if ColorDialog.Execute then
6168 begin
6169 Values[Key] := IntToStr(ColorDialog.Color);
6170 vleObjectPropertyApply(Sender);
6171 end;
6173 else if Key = _lc[I_PROP_PANEL_TEX] then
6174 begin // Смена текстуры:
6175 vleObjectProperty.Values[Key] := SelectedTexture();
6176 vleObjectPropertyApply(Sender);
6177 end;
6178 end;
6180 procedure TMainForm.vleObjectPropertyApply(Sender: TObject);
6181 begin
6182 // hack to prevent empty ID in list
6183 RenderPanel.SetFocus();
6184 bApplyProperty.Click();
6185 vleObjectProperty.SetFocus();
6186 end;
6188 procedure TMainForm.aSaveMapExecute(Sender: TObject);
6190 FileName, Section, Res: String;
6191 begin
6192 if OpenedMap = '' then
6193 begin
6194 aSaveMapAsExecute(nil);
6195 Exit;
6196 end;
6198 g_ProcessResourceStr(OpenedMap, FileName, Section, Res);
6200 SaveMap(FileName+':\'+Res);
6201 end;
6203 procedure TMainForm.aOpenMapExecute(Sender: TObject);
6204 begin
6205 OpenDialog.Filter := _lc[I_FILE_FILTER_ALL];
6207 if OpenDialog.Execute() then
6208 begin
6209 OpenMapFile(OpenDialog.FileName);
6210 OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
6211 end;
6212 end;
6214 procedure TMainForm.OpenMapFile(FileName: String);
6215 begin
6216 if (Pos('.ini', LowerCase(ExtractFileName(FileName))) > 0) then
6217 begin // INI карты:
6218 FullClear();
6220 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
6221 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
6222 pLoadProgress.Show();
6224 OpenedMap := '';
6225 OpenedWAD := '';
6227 LoadMapOld(FileName);
6229 MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(FileName)]);
6231 pLoadProgress.Hide();
6232 MainForm.FormResize(Self);
6234 else // Карты из WAD:
6235 begin
6236 OpenMap(FileName, '');
6237 end;
6238 end;
6240 procedure TMainForm.FormActivate(Sender: TObject);
6242 lang: Integer;
6243 config: TConfig;
6244 begin
6245 MainForm.ActiveControl := RenderPanel;
6247 // Язык:
6248 if gLanguage = '' then
6249 begin
6250 lang := SelectLanguageForm.ShowModal();
6251 case lang of
6252 1: gLanguage := LANGUAGE_ENGLISH;
6253 else gLanguage := LANGUAGE_RUSSIAN;
6254 end;
6256 config := TConfig.CreateFile(CfgFileName);
6257 config.WriteStr('Editor', 'Language', gLanguage);
6258 config.SaveFile(CfgFileName);
6259 config.Free();
6260 end;
6262 //e_WriteLog('Read language file', MSG_NOTIFY);
6263 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
6264 g_Language_Set(gLanguage);
6265 end;
6267 procedure TMainForm.aDeleteMap(Sender: TObject);
6269 res: Integer;
6270 FileName: String;
6271 MapName: String;
6272 begin
6273 OpenDialog.Filter := _lc[I_FILE_FILTER_WAD];
6275 if not OpenDialog.Execute() then
6276 Exit;
6278 FileName := OpenDialog.FileName;
6279 SelectMapForm.Caption := _lc[I_CAP_REMOVE];
6280 SelectMapForm.lbMapList.Items.Clear();
6281 SelectMapForm.GetMaps(FileName);
6283 if SelectMapForm.ShowModal() <> mrOK then
6284 Exit;
6286 MapName := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
6287 if MessageBox(0, PChar(Format(_lc[I_MSG_DELETE_MAP_PROMT], [MapName, OpenDialog.FileName])), PChar(_lc[I_MSG_DELETE_MAP]), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2) <> mrYes then
6288 Exit;
6290 g_DeleteResource(FileName, '', MapName, res);
6291 if res <> 0 then
6292 begin
6293 MessageBox(0, PChar('Cant delete map res=' + IntToStr(res)), PChar('Map not deleted!'), MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
6294 Exit
6295 end;
6297 MessageBox(
6299 PChar(Format(_lc[I_MSG_MAP_DELETED_PROMT], [MapName])),
6300 PChar(_lc[I_MSG_MAP_DELETED]),
6301 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1
6304 // Удалили текущую карту - сохранять по старому ее нельзя:
6305 if OpenedMap = (FileName + ':\' + MapName) then
6306 begin
6307 OpenedMap := '';
6308 OpenedWAD := '';
6309 MainForm.Caption := FormCaption
6311 end;
6313 procedure TMainForm.vleObjectPropertyKeyDown(Sender: TObject;
6314 var Key: Word; Shift: TShiftState);
6315 begin
6316 if Key = VK_RETURN then
6317 vleObjectPropertyApply(Sender);
6318 end;
6320 procedure MovePanel(var ID: DWORD; MoveType: Byte);
6322 _id, a: Integer;
6323 tmp: TPanel;
6324 begin
6325 if (ID = 0) and (MoveType = 0) then
6326 Exit;
6327 if (ID = DWORD(High(gPanels))) and (MoveType <> 0) then
6328 Exit;
6329 if (ID > DWORD(High(gPanels))) then
6330 Exit;
6332 _id := Integer(ID);
6334 if MoveType = 0 then // to Back
6335 begin
6336 if gTriggers <> nil then
6337 for a := 0 to High(gTriggers) do
6338 with gTriggers[a] do
6339 begin
6340 if TriggerType = TRIGGER_NONE then
6341 Continue;
6343 if TexturePanel = _id then
6344 TexturePanel := 0
6345 else
6346 if (TexturePanel >= 0) and (TexturePanel < _id) then
6347 Inc(TexturePanel);
6349 case TriggerType of
6350 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6351 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6352 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6353 if Data.PanelID = _id then
6354 Data.PanelID := 0
6355 else
6356 if (Data.PanelID >= 0) and (Data.PanelID < _id) then
6357 Inc(Data.PanelID);
6359 TRIGGER_SHOT:
6360 if Data.ShotPanelID = _id then
6361 Data.ShotPanelID := 0
6362 else
6363 if (Data.ShotPanelID >= 0) and (Data.ShotPanelID < _id) then
6364 Inc(Data.ShotPanelID);
6365 end;
6366 end;
6368 tmp := gPanels[_id];
6370 for a := _id downto 1 do
6371 gPanels[a] := gPanels[a-1];
6373 gPanels[0] := tmp;
6375 ID := 0;
6377 else // to Front
6378 begin
6379 if gTriggers <> nil then
6380 for a := 0 to High(gTriggers) do
6381 with gTriggers[a] do
6382 begin
6383 if TriggerType = TRIGGER_NONE then
6384 Continue;
6386 if TexturePanel = _id then
6387 TexturePanel := High(gPanels)
6388 else
6389 if TexturePanel > _id then
6390 Dec(TexturePanel);
6392 case TriggerType of
6393 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6394 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6395 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6396 if Data.PanelID = _id then
6397 Data.PanelID := High(gPanels)
6398 else
6399 if Data.PanelID > _id then
6400 Dec(Data.PanelID);
6402 TRIGGER_SHOT:
6403 if Data.ShotPanelID = _id then
6404 Data.ShotPanelID := High(gPanels)
6405 else
6406 if Data.ShotPanelID > _id then
6407 Dec(Data.ShotPanelID);
6408 end;
6409 end;
6411 tmp := gPanels[_id];
6413 for a := _id to High(gPanels)-1 do
6414 gPanels[a] := gPanels[a+1];
6416 gPanels[High(gPanels)] := tmp;
6418 ID := High(gPanels);
6419 end;
6420 end;
6422 procedure TMainForm.aMoveToBack(Sender: TObject);
6424 a: Integer;
6425 begin
6426 if SelectedObjects = nil then
6427 Exit;
6429 for a := 0 to High(SelectedObjects) do
6430 with SelectedObjects[a] do
6431 if Live and (ObjectType = OBJECT_PANEL) then
6432 begin
6433 SelectedObjects[0] := SelectedObjects[a];
6434 SetLength(SelectedObjects, 1);
6435 MovePanel(ID, 0);
6436 FillProperty();
6437 Break;
6438 end;
6439 end;
6441 procedure TMainForm.aMoveToFore(Sender: TObject);
6443 a: Integer;
6444 begin
6445 if SelectedObjects = nil then
6446 Exit;
6448 for a := 0 to High(SelectedObjects) do
6449 with SelectedObjects[a] do
6450 if Live and (ObjectType = OBJECT_PANEL) then
6451 begin
6452 SelectedObjects[0] := SelectedObjects[a];
6453 SetLength(SelectedObjects, 1);
6454 MovePanel(ID, 1);
6455 FillProperty();
6456 Break;
6457 end;
6458 end;
6460 procedure TMainForm.aSaveMapAsExecute(Sender: TObject);
6462 idx: Integer;
6463 begin
6464 SaveDialog.Filter := _lc[I_FILE_FILTER_WAD];
6466 if not SaveDialog.Execute() then
6467 Exit;
6469 SaveMapForm.GetMaps(SaveDialog.FileName, True);
6471 if SaveMapForm.ShowModal() <> mrOK then
6472 Exit;
6474 SaveDialog.InitialDir := ExtractFileDir(SaveDialog.FileName);
6475 OpenedMap := SaveDialog.FileName+':\'+SaveMapForm.eMapName.Text;
6476 OpenedWAD := SaveDialog.FileName;
6478 idx := RecentFiles.IndexOf(OpenedMap);
6479 // Такая карта уже недавно открывалась:
6480 if idx >= 0 then
6481 RecentFiles.Delete(idx);
6482 RecentFiles.Insert(0, OpenedMap);
6483 RefreshRecentMenu;
6485 SaveMap(OpenedMap);
6487 gMapInfo.FileName := SaveDialog.FileName;
6488 gMapInfo.MapName := SaveMapForm.eMapName.Text;
6489 UpdateCaption(gMapInfo.Name, ExtractFileName(gMapInfo.FileName), gMapInfo.MapName);
6490 end;
6492 procedure TMainForm.aSelectAllExecute(Sender: TObject);
6494 a: Integer;
6495 begin
6496 RemoveSelectFromObjects();
6498 case pcObjects.ActivePageIndex+1 of
6499 OBJECT_PANEL:
6500 if gPanels <> nil then
6501 for a := 0 to High(gPanels) do
6502 if gPanels[a].PanelType <> PANEL_NONE then
6503 SelectObject(OBJECT_PANEL, a, True);
6504 OBJECT_ITEM:
6505 if gItems <> nil then
6506 for a := 0 to High(gItems) do
6507 if gItems[a].ItemType <> ITEM_NONE then
6508 SelectObject(OBJECT_ITEM, a, True);
6509 OBJECT_MONSTER:
6510 if gMonsters <> nil then
6511 for a := 0 to High(gMonsters) do
6512 if gMonsters[a].MonsterType <> MONSTER_NONE then
6513 SelectObject(OBJECT_MONSTER, a, True);
6514 OBJECT_AREA:
6515 if gAreas <> nil then
6516 for a := 0 to High(gAreas) do
6517 if gAreas[a].AreaType <> AREA_NONE then
6518 SelectObject(OBJECT_AREA, a, True);
6519 OBJECT_TRIGGER:
6520 if gTriggers <> nil then
6521 for a := 0 to High(gTriggers) do
6522 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6523 SelectObject(OBJECT_TRIGGER, a, True);
6524 end;
6526 RecountSelectedObjects();
6527 end;
6529 procedure TMainForm.tbGridOnClick(Sender: TObject);
6530 begin
6531 DotEnable := not DotEnable;
6532 (Sender as TToolButton).Down := DotEnable;
6533 end;
6535 procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean);
6536 var f: AnsiString;
6537 begin
6538 // FIXME: this is a shitty hack
6539 if not gDataLoaded then
6540 begin
6541 e_WriteLog('Init OpenGL', MSG_NOTIFY);
6542 e_InitGL();
6543 e_WriteLog('Loading data', MSG_NOTIFY);
6544 LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
6545 e_WriteLog('Loading more data', MSG_NOTIFY);
6546 LoadData();
6547 e_WriteLog('Loading even more data', MSG_NOTIFY);
6548 gDataLoaded := True;
6549 MainForm.FormResize(nil);
6550 end;
6551 Draw();
6552 if StartMap <> '' then
6553 begin
6554 f := StartMap;
6555 StartMap := '';
6556 OpenMap(f, '');
6557 end;
6558 end;
6560 procedure TMainForm.miMapPreviewClick(Sender: TObject);
6561 begin
6562 if PreviewMode = 2 then
6563 Exit;
6565 if PreviewMode = 0 then
6566 begin
6567 Splitter2.Visible := False;
6568 Splitter1.Visible := False;
6569 StatusBar.Visible := False;
6570 PanelObjs.Visible := False;
6571 PanelProps.Visible := False;
6572 MainToolBar.Visible := False;
6573 sbHorizontal.Visible := False;
6574 sbVertical.Visible := False;
6576 else
6577 begin
6578 StatusBar.Visible := True;
6579 PanelObjs.Visible := True;
6580 PanelProps.Visible := True;
6581 Splitter2.Visible := True;
6582 Splitter1.Visible := True;
6583 MainToolBar.Visible := True;
6584 sbHorizontal.Visible := True;
6585 sbVertical.Visible := True;
6586 end;
6588 PreviewMode := PreviewMode xor 1;
6589 (Sender as TMenuItem).Checked := PreviewMode > 0;
6591 FormResize(Self);
6592 end;
6594 procedure TMainForm.miLayer1Click(Sender: TObject);
6595 begin
6596 SwitchLayer(LAYER_BACK);
6597 end;
6599 procedure TMainForm.miLayer2Click(Sender: TObject);
6600 begin
6601 SwitchLayer(LAYER_WALLS);
6602 end;
6604 procedure TMainForm.miLayer3Click(Sender: TObject);
6605 begin
6606 SwitchLayer(LAYER_FOREGROUND);
6607 end;
6609 procedure TMainForm.miLayer4Click(Sender: TObject);
6610 begin
6611 SwitchLayer(LAYER_STEPS);
6612 end;
6614 procedure TMainForm.miLayer5Click(Sender: TObject);
6615 begin
6616 SwitchLayer(LAYER_WATER);
6617 end;
6619 procedure TMainForm.miLayer6Click(Sender: TObject);
6620 begin
6621 SwitchLayer(LAYER_ITEMS);
6622 end;
6624 procedure TMainForm.miLayer7Click(Sender: TObject);
6625 begin
6626 SwitchLayer(LAYER_MONSTERS);
6627 end;
6629 procedure TMainForm.miLayer8Click(Sender: TObject);
6630 begin
6631 SwitchLayer(LAYER_AREAS);
6632 end;
6634 procedure TMainForm.miLayer9Click(Sender: TObject);
6635 begin
6636 SwitchLayer(LAYER_TRIGGERS);
6637 end;
6639 procedure TMainForm.tbShowClick(Sender: TObject);
6641 a: Integer;
6642 b: Boolean;
6643 begin
6644 b := True;
6645 for a := 0 to High(LayerEnabled) do
6646 b := b and LayerEnabled[a];
6648 b := not b;
6650 ShowLayer(LAYER_BACK, b);
6651 ShowLayer(LAYER_WALLS, b);
6652 ShowLayer(LAYER_FOREGROUND, b);
6653 ShowLayer(LAYER_STEPS, b);
6654 ShowLayer(LAYER_WATER, b);
6655 ShowLayer(LAYER_ITEMS, b);
6656 ShowLayer(LAYER_MONSTERS, b);
6657 ShowLayer(LAYER_AREAS, b);
6658 ShowLayer(LAYER_TRIGGERS, b);
6659 end;
6661 procedure TMainForm.miMiniMapClick(Sender: TObject);
6662 begin
6663 SwitchMap();
6664 end;
6666 procedure TMainForm.miSwitchGridClick(Sender: TObject);
6667 begin
6668 if DotStep = DotStepOne then
6669 DotStep := DotStepTwo
6670 else
6671 DotStep := DotStepOne;
6673 MousePos.X := (MousePos.X div DotStep) * DotStep;
6674 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6675 end;
6677 procedure TMainForm.miShowEdgesClick(Sender: TObject);
6678 begin
6679 ShowEdges();
6680 end;
6682 procedure TMainForm.miSnapToGridClick(Sender: TObject);
6683 begin
6684 SnapToGrid := not SnapToGrid;
6686 MousePos.X := (MousePos.X div DotStep) * DotStep;
6687 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6689 miSnapToGrid.Checked := SnapToGrid;
6690 end;
6692 procedure TMainForm.minexttabClick(Sender: TObject);
6693 begin
6694 if pcObjects.ActivePageIndex < pcObjects.PageCount-1 then
6695 pcObjects.ActivePageIndex := pcObjects.ActivePageIndex+1
6696 else
6697 pcObjects.ActivePageIndex := 0;
6698 end;
6700 procedure TMainForm.miSaveMiniMapClick(Sender: TObject);
6701 begin
6702 SaveMiniMapForm.ShowModal();
6703 end;
6705 procedure TMainForm.bClearTextureClick(Sender: TObject);
6706 begin
6707 lbTextureList.ItemIndex := -1;
6708 lTextureWidth.Caption := '';
6709 lTextureHeight.Caption := '';
6710 end;
6712 procedure TMainForm.miPackMapClick(Sender: TObject);
6713 begin
6714 PackMapForm.ShowModal();
6715 end;
6717 procedure TMainForm.miMapTestSettingsClick(Sender: TObject);
6718 begin
6719 MapTestForm.ShowModal();
6720 end;
6722 type SSArray = array of String;
6724 function ParseString (Str: AnsiString): SSArray;
6725 function GetStr (var Str: AnsiString): AnsiString;
6726 var a, b: Integer;
6727 begin
6728 Result := '';
6729 if Str[1] = '"' then
6730 for b := 1 to Length(Str) do
6731 if (b = Length(Str)) or (Str[b + 1] = '"') then
6732 begin
6733 Result := Copy(Str, 2, b - 1);
6734 Delete(Str, 1, b + 1);
6735 Str := Trim(Str);
6736 Exit;
6737 end;
6738 for a := 1 to Length(Str) do
6739 if (a = Length(Str)) or (Str[a + 1] = ' ') then
6740 begin
6741 Result := Copy(Str, 1, a);
6742 Delete(Str, 1, a + 1);
6743 Str := Trim(Str);
6744 Exit;
6745 end;
6746 end;
6747 begin
6748 Result := nil;
6749 Str := Trim(Str);
6750 while Str <> '' do
6751 begin
6752 SetLength(Result, Length(Result)+1);
6753 Result[High(Result)] := GetStr(Str);
6754 end;
6755 end;
6757 procedure TMainForm.miTestMapClick(Sender: TObject);
6759 newWAD, oldWAD, tempMap, ext: String;
6760 args: SSArray;
6761 opt: LongWord;
6762 time, i: Integer;
6763 proc: TProcessUTF8;
6764 res: Boolean;
6765 begin
6766 // Ignore while map testing in progress
6767 if MapTestProcess <> nil then
6768 Exit;
6770 // Сохраняем временную карту:
6771 time := 0;
6772 repeat
6773 newWAD := ExtractFilePath(TestD2dExe) + Format('maps/temp%.4d', [time]);
6774 Inc(time);
6775 until not FileExists(newWAD);
6776 if OpenedMap <> '' then
6777 begin
6778 oldWad := g_ExtractWadName(OpenedMap);
6779 newWad := newWad + ExtractFileExt(oldWad);
6780 if CopyFile(oldWad, newWad) = false then
6781 e_WriteLog('MapTest: unable to copy [' + oldWad + '] to [' + newWad + ']', MSG_WARNING)
6783 else
6784 begin
6785 newWad := newWad + '.wad'
6786 end;
6787 tempMap := newWAD + ':\' + TEST_MAP_NAME;
6788 SaveMap(tempMap);
6789 tempMap := ExtractRelativePath(ExtractFilePath(TestD2dExe) + 'maps/', tempMap);
6791 // Опции игры:
6792 opt := 32 + 64;
6793 if TestOptionsTwoPlayers then
6794 opt := opt + 1;
6795 if TestOptionsTeamDamage then
6796 opt := opt + 2;
6797 if TestOptionsAllowExit then
6798 opt := opt + 4;
6799 if TestOptionsWeaponStay then
6800 opt := opt + 8;
6801 if TestOptionsMonstersDM then
6802 opt := opt + 16;
6804 // Запускаем:
6805 proc := TProcessUTF8.Create(nil);
6806 proc.Executable := TestD2dExe;
6807 proc.Parameters.Add('-map');
6808 proc.Parameters.Add(tempMap);
6809 proc.Parameters.Add('-gm');
6810 proc.Parameters.Add(TestGameMode);
6811 proc.Parameters.Add('-limt');
6812 proc.Parameters.Add(TestLimTime);
6813 proc.Parameters.Add('-lims');
6814 proc.Parameters.Add(TestLimScore);
6815 proc.Parameters.Add('-opt');
6816 proc.Parameters.Add(IntToStr(opt));
6817 proc.Parameters.Add('--debug');
6818 if TestMapOnce then
6819 proc.Parameters.Add('--close');
6821 args := ParseString(TestD2DArgs);
6822 for i := 0 to High(args) do
6823 proc.Parameters.Add(args[i]);
6825 res := True;
6827 proc.Execute();
6828 except
6829 res := False;
6830 end;
6831 if res then
6832 begin
6833 tbTestMap.Enabled := False;
6834 MapTestFile := newWAD;
6835 MapTestProcess := proc;
6837 else
6838 begin
6839 Application.MessageBox(PChar(_lc[I_MSG_EXEC_ERROR]), 'FIXME', MB_OK or MB_ICONERROR);
6840 SysUtils.DeleteFile(newWAD);
6841 proc.Free();
6842 end;
6843 end;
6845 procedure TMainForm.sbVerticalScroll(Sender: TObject;
6846 ScrollCode: TScrollCode; var ScrollPos: Integer);
6847 begin
6848 MapOffset.Y := -sbVertical.Position;
6849 end;
6851 procedure TMainForm.sbHorizontalScroll(Sender: TObject;
6852 ScrollCode: TScrollCode; var ScrollPos: Integer);
6853 begin
6854 MapOffset.X := -sbHorizontal.Position;
6855 end;
6857 procedure TMainForm.miOpenWadMapClick(Sender: TObject);
6858 begin
6859 if OpenedWAD <> '' then
6860 begin
6861 OpenMap(OpenedWAD, '');
6862 end;
6863 end;
6865 procedure TMainForm.selectall1Click(Sender: TObject);
6867 a: Integer;
6868 begin
6869 RemoveSelectFromObjects();
6871 if gPanels <> nil then
6872 for a := 0 to High(gPanels) do
6873 if gPanels[a].PanelType <> PANEL_NONE then
6874 SelectObject(OBJECT_PANEL, a, True);
6876 if gItems <> nil then
6877 for a := 0 to High(gItems) do
6878 if gItems[a].ItemType <> ITEM_NONE then
6879 SelectObject(OBJECT_ITEM, a, True);
6881 if gMonsters <> nil then
6882 for a := 0 to High(gMonsters) do
6883 if gMonsters[a].MonsterType <> MONSTER_NONE then
6884 SelectObject(OBJECT_MONSTER, a, True);
6886 if gAreas <> nil then
6887 for a := 0 to High(gAreas) do
6888 if gAreas[a].AreaType <> AREA_NONE then
6889 SelectObject(OBJECT_AREA, a, True);
6891 if gTriggers <> nil then
6892 for a := 0 to High(gTriggers) do
6893 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6894 SelectObject(OBJECT_TRIGGER, a, True);
6896 RecountSelectedObjects();
6897 end;
6899 procedure TMainForm.Splitter1CanResize(Sender: TObject;
6900 var NewSize: Integer; var Accept: Boolean);
6901 begin
6902 Accept := (NewSize > 140);
6903 end;
6905 procedure TMainForm.Splitter2CanResize(Sender: TObject;
6906 var NewSize: Integer; var Accept: Boolean);
6907 begin
6908 Accept := (NewSize > 110);
6909 end;
6911 procedure TMainForm.vleObjectPropertyEnter(Sender: TObject);
6912 begin
6913 EditingProperties := True;
6914 end;
6916 procedure TMainForm.vleObjectPropertyExit(Sender: TObject);
6917 begin
6918 EditingProperties := False;
6919 end;
6921 procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
6922 begin
6923 // Объекты передвигались:
6924 if MainForm.ActiveControl = RenderPanel then
6925 begin
6926 if (Key = VK_NUMPAD4) or
6927 (Key = VK_NUMPAD6) or
6928 (Key = VK_NUMPAD8) or
6929 (Key = VK_NUMPAD5) or
6930 (Key = Ord('V')) then
6931 FillProperty();
6932 end;
6933 // Быстрое превью карты:
6934 if Key = Ord('E') then
6935 begin
6936 if PreviewMode = 2 then
6937 PreviewMode := 0;
6938 end;
6939 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
6940 end;
6942 end.