DEADSOFTWARE

a810a63637c87848381a1c051228b1cfd91a1f7c
[d2df-editor.git] / src / editor / f_main.pas
1 unit f_main;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics,
9 Controls, Forms, Dialogs, StdCtrls, Buttons,
10 ComCtrls, ValEdit, Types, Menus, ExtCtrls,
11 CheckLst, Grids, OpenGLContext, utils, UTF8Process;
13 type
15 { TMainForm }
17 TMainForm = class(TForm)
18 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 // Редактор свойств объектов:
128 vleObjectProperty: TValueListEditor;
130 // Панель объектов - вкладки:
131 PanelObjs: TPanel;
132 pcObjects: TPageControl;
133 // Вкладка "Панели":
134 tsPanels: TTabSheet;
135 lbTextureList: TListBox;
136 // Панель настройки текстур:
137 PanelTextures: TPanel;
138 LabelTxW: TLabel;
139 lTextureWidth: TLabel;
140 LabelTxH: TLabel;
141 lTextureHeight: TLabel;
142 cbPreview: TCheckBox;
143 bbAddTexture: TBitBtn;
144 bbRemoveTexture: TBitBtn;
145 bClearTexture: TButton;
146 // Панель типов панелей:
147 PanelPanelType: TPanel;
148 lbPanelType: TListBox;
149 // Вкладка "Предметы":
150 tsItems: TTabSheet;
151 lbItemList: TListBox;
152 cbOnlyDM: TCheckBox;
153 cbFall: TCheckBox;
154 // Вкладка "Монстры":
155 tsMonsters: TTabSheet;
156 lbMonsterList: TListBox;
157 rbMonsterLeft: TRadioButton;
158 rbMonsterRight: TRadioButton;
159 // Вкладка "Области":
160 tsAreas: TTabSheet;
161 lbAreasList: TListBox;
162 rbAreaLeft: TRadioButton;
163 rbAreaRight: TRadioButton;
164 // Вкладка "Триггеры":
165 tsTriggers: TTabSheet;
166 lbTriggersList: TListBox;
167 clbActivationType: TCheckListBox;
168 clbKeys: TCheckListBox;
170 // Остальные панели
171 Splitter1: TSplitter;
172 Splitter2: TSplitter;
173 StatusBar: TStatusBar;
175 // Специальные объекты:
176 ImageList: TImageList;
177 ilToolbar: TImageList;
178 OpenDialog: TOpenDialog;
179 SaveDialog: TSaveDialog;
180 selectall1: TMenuItem;
181 ColorDialog: TColorDialog;
183 procedure aAboutExecute(Sender: TObject);
184 procedure aCheckMapExecute(Sender: TObject);
185 procedure aMoveToFore(Sender: TObject);
186 procedure aMoveToBack(Sender: TObject);
187 procedure aCopyObjectExecute(Sender: TObject);
188 procedure aCutObjectExecute(Sender: TObject);
189 procedure aEditorOptionsExecute(Sender: TObject);
190 procedure aExitExecute(Sender: TObject);
191 procedure aMapOptionsExecute(Sender: TObject);
192 procedure aNewMapExecute(Sender: TObject);
193 procedure aOpenMapExecute(Sender: TObject);
194 procedure aOptimizeExecute(Sender: TObject);
195 procedure aPasteObjectExecute(Sender: TObject);
196 procedure aSelectAllExecute(Sender: TObject);
197 procedure aSaveMapExecute(Sender: TObject);
198 procedure aSaveMapAsExecute(Sender: TObject);
199 procedure aUndoExecute(Sender: TObject);
200 procedure aDeleteMap(Sender: TObject);
201 procedure bApplyPropertyClick(Sender: TObject);
202 procedure bbAddTextureClick(Sender: TObject);
203 procedure bbRemoveTextureClick(Sender: TObject);
204 procedure FormActivate(Sender: TObject);
205 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
206 procedure FormCreate(Sender: TObject);
207 procedure FormDestroy(Sender: TObject);
208 procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
209 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
210 procedure FormResize(Sender: TObject);
211 procedure lbTextureListClick(Sender: TObject);
212 procedure lbTextureListDrawItem(Control: TWinControl; Index: Integer;
213 ARect: TRect; State: TOwnerDrawState);
214 procedure miReopenMapClick(Sender: TObject);
215 procedure RenderPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
216 procedure RenderPanelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
217 procedure RenderPanelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
218 procedure RenderPanelPaint(Sender: TObject);
219 procedure RenderPanelResize(Sender: TObject);
220 procedure Splitter1Moved(Sender: TObject);
221 procedure vleObjectPropertyEditButtonClick(Sender: TObject);
222 procedure vleObjectPropertyApply(Sender: TObject);
223 procedure vleObjectPropertyGetPickList(Sender: TObject; const KeyName: String; Values: TStrings);
224 procedure vleObjectPropertyKeyDown(Sender: TObject; var Key: Word;
225 Shift: TShiftState);
226 procedure tbGridOnClick(Sender: TObject);
227 procedure miMapPreviewClick(Sender: TObject);
228 procedure miLayer1Click(Sender: TObject);
229 procedure miLayer2Click(Sender: TObject);
230 procedure miLayer3Click(Sender: TObject);
231 procedure miLayer4Click(Sender: TObject);
232 procedure miLayer5Click(Sender: TObject);
233 procedure miLayer6Click(Sender: TObject);
234 procedure miLayer7Click(Sender: TObject);
235 procedure miLayer8Click(Sender: TObject);
236 procedure miLayer9Click(Sender: TObject);
237 procedure tbShowClick(Sender: TObject);
238 procedure miSnapToGridClick(Sender: TObject);
239 procedure miMiniMapClick(Sender: TObject);
240 procedure miSwitchGridClick(Sender: TObject);
241 procedure miShowEdgesClick(Sender: TObject);
242 procedure minexttabClick(Sender: TObject);
243 procedure miSaveMiniMapClick(Sender: TObject);
244 procedure bClearTextureClick(Sender: TObject);
245 procedure miPackMapClick(Sender: TObject);
246 procedure aRecentFileExecute(Sender: TObject);
247 procedure miMapTestSettingsClick(Sender: TObject);
248 procedure miTestMapClick(Sender: TObject);
249 procedure sbVerticalScroll(Sender: TObject; ScrollCode: TScrollCode;
250 var ScrollPos: Integer);
251 procedure sbHorizontalScroll(Sender: TObject; ScrollCode: TScrollCode;
252 var ScrollPos: Integer);
253 procedure miOpenWadMapClick(Sender: TObject);
254 procedure selectall1Click(Sender: TObject);
255 procedure Splitter1CanResize(Sender: TObject; var NewSize: Integer;
256 var Accept: Boolean);
257 procedure Splitter2CanResize(Sender: TObject; var NewSize: Integer;
258 var Accept: Boolean);
259 procedure vleObjectPropertyEnter(Sender: TObject);
260 procedure vleObjectPropertyExit(Sender: TObject);
261 procedure FormKeyUp(Sender: TObject; var Key: Word;
262 Shift: TShiftState);
263 private
264 procedure Draw();
265 procedure OnIdle(Sender: TObject; var Done: Boolean);
266 public
267 procedure RefreshRecentMenu();
268 procedure OpenMapFile(FileName: String);
269 function RenderMousePos(): TPoint;
270 procedure RecountSelectedObjects();
271 end;
273 const
274 LAYER_BACK = 0;
275 LAYER_WALLS = 1;
276 LAYER_FOREGROUND = 2;
277 LAYER_STEPS = 3;
278 LAYER_WATER = 4;
279 LAYER_ITEMS = 5;
280 LAYER_MONSTERS = 6;
281 LAYER_AREAS = 7;
282 LAYER_TRIGGERS = 8;
284 TEST_MAP_NAME = '$$$_TEST_$$$';
285 LANGUAGE_FILE_NAME = '_Editor.txt';
287 var
288 MainForm: TMainForm;
289 EditorDir: String;
290 OpenedMap: String;
291 OpenedWAD: String;
293 DotColor: TColor;
294 DotEnable: Boolean;
295 DotStep: Byte;
296 DotStepOne, DotStepTwo: Byte;
297 DotSize: Byte;
298 DrawTexturePanel: Boolean;
299 DrawPanelSize: Boolean;
300 BackColor: TColor;
301 PreviewColor: TColor;
302 UseCheckerboard: Boolean;
303 Scale: Byte;
304 RecentCount: Integer;
305 RecentFiles: TStringList;
306 slInvalidTextures: TStringList;
308 TestGameMode: String;
309 TestLimTime: String;
310 TestLimScore: String;
311 TestOptionsTwoPlayers: Boolean;
312 TestOptionsTeamDamage: Boolean;
313 TestOptionsAllowExit: Boolean;
314 TestOptionsWeaponStay: Boolean;
315 TestOptionsMonstersDM: Boolean;
316 TestD2dExe: String;
317 TestMapOnce: Boolean;
319 LayerEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
320 (True, True, True, True, True, True, True, True, True);
321 PreviewMode: Byte = 0;
322 gLanguage: String;
324 FormCaption: String;
327 procedure OpenMap(FileName: String; mapN: String);
328 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
329 procedure RemoveSelectFromObjects();
330 procedure ChangeShownProperty(Name: String; NewValue: String);
332 implementation
334 uses
335 f_options, e_graphics, e_log, GL, Math,
336 f_mapoptions, g_basic, f_about, f_mapoptimization,
337 f_mapcheck, f_addresource_texture, g_textures,
338 f_activationtype, f_keys,
339 MAPREADER, f_selectmap, f_savemap, WADEDITOR, WADSTRUCT, MAPDEF,
340 g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
341 f_addresource_sound, f_maptest, f_choosetype,
342 g_language, f_selectlang, ClipBrd;
344 const
345 UNDO_DELETE_PANEL = 1;
346 UNDO_DELETE_ITEM = 2;
347 UNDO_DELETE_AREA = 3;
348 UNDO_DELETE_MONSTER = 4;
349 UNDO_DELETE_TRIGGER = 5;
350 UNDO_ADD_PANEL = 6;
351 UNDO_ADD_ITEM = 7;
352 UNDO_ADD_AREA = 8;
353 UNDO_ADD_MONSTER = 9;
354 UNDO_ADD_TRIGGER = 10;
355 UNDO_MOVE_PANEL = 11;
356 UNDO_MOVE_ITEM = 12;
357 UNDO_MOVE_AREA = 13;
358 UNDO_MOVE_MONSTER = 14;
359 UNDO_MOVE_TRIGGER = 15;
360 UNDO_RESIZE_PANEL = 16;
361 UNDO_RESIZE_TRIGGER = 17;
363 MOUSEACTION_NONE = 0;
364 MOUSEACTION_DRAWPANEL = 1;
365 MOUSEACTION_DRAWTRIGGER = 2;
366 MOUSEACTION_MOVEOBJ = 3;
367 MOUSEACTION_RESIZE = 4;
368 MOUSEACTION_MOVEMAP = 5;
369 MOUSEACTION_DRAWPRESS = 6;
370 MOUSEACTION_NOACTION = 7;
372 RESIZETYPE_NONE = 0;
373 RESIZETYPE_VERTICAL = 1;
374 RESIZETYPE_HORIZONTAL = 2;
376 RESIZEDIR_NONE = 0;
377 RESIZEDIR_DOWN = 1;
378 RESIZEDIR_UP = 2;
379 RESIZEDIR_RIGHT = 3;
380 RESIZEDIR_LEFT = 4;
382 SELECTFLAG_NONE = 0;
383 SELECTFLAG_TELEPORT = 1;
384 SELECTFLAG_DOOR = 2;
385 SELECTFLAG_TEXTURE = 3;
386 SELECTFLAG_LIFT = 4;
387 SELECTFLAG_MONSTER = 5;
388 SELECTFLAG_SPAWNPOINT = 6;
389 SELECTFLAG_SHOTPANEL = 7;
390 SELECTFLAG_SELECTED = 8;
392 RECENT_FILES_MENU_START = 12;
394 CLIPBOARD_SIG = 'DF:ED';
396 type
397 TUndoRec = record
398 UndoType: Byte;
399 case Byte of
400 UNDO_DELETE_PANEL: (Panel: ^TPanel);
401 UNDO_DELETE_ITEM: (Item: TItem);
402 UNDO_DELETE_AREA: (Area: TArea);
403 UNDO_DELETE_MONSTER: (Monster: TMonster);
404 UNDO_DELETE_TRIGGER: (Trigger: TTrigger);
405 UNDO_ADD_PANEL,
406 UNDO_ADD_ITEM,
407 UNDO_ADD_AREA,
408 UNDO_ADD_MONSTER,
409 UNDO_ADD_TRIGGER: (AddID: DWORD);
410 UNDO_MOVE_PANEL,
411 UNDO_MOVE_ITEM,
412 UNDO_MOVE_AREA,
413 UNDO_MOVE_MONSTER,
414 UNDO_MOVE_TRIGGER: (MoveID: DWORD; dX, dY: Integer);
415 UNDO_RESIZE_PANEL,
416 UNDO_RESIZE_TRIGGER: (ResizeID: DWORD; dW, dH: Integer);
417 end;
419 TCopyRec = record
420 ObjectType: Byte;
421 ID: Cardinal;
422 case Byte of
423 OBJECT_PANEL: (Panel: ^TPanel);
424 OBJECT_ITEM: (Item: TItem);
425 OBJECT_AREA: (Area: TArea);
426 OBJECT_MONSTER: (Monster: TMonster);
427 OBJECT_TRIGGER: (Trigger: TTrigger);
428 end;
430 TCopyRecArray = Array of TCopyRec;
432 var
433 gEditorFont: DWORD;
434 gDataLoaded: Boolean = False;
435 ShowMap: Boolean = False;
436 DrawRect: PRect = nil;
437 SnapToGrid: Boolean = True;
439 MousePos: Types.TPoint;
440 LastMovePoint: Types.TPoint;
441 MouseLDown: Boolean;
442 MouseRDown: Boolean;
443 MouseLDownPos: Types.TPoint;
444 MouseRDownPos: Types.TPoint;
445 WASDOffset: TPoint;
447 SelectFlag: Byte = SELECTFLAG_NONE;
448 MouseAction: Byte = MOUSEACTION_NONE;
449 ResizeType: Byte = RESIZETYPE_NONE;
450 ResizeDirection: Byte = RESIZEDIR_NONE;
452 DrawPressRect: Boolean = False;
453 EditingProperties: Boolean = False;
455 UndoBuffer: Array of Array of TUndoRec = nil;
458 {$R *.lfm}
460 //----------------------------------------
461 //Далее идут вспомогательные процедуры
462 //----------------------------------------
464 function NameToBool(Name: String): Boolean;
465 begin
466 if Name = BoolNames[True] then
467 Result := True
468 else
469 Result := False;
470 end;
472 function NameToDir(Name: String): TDirection;
473 begin
474 if Name = DirNames[D_LEFT] then
475 Result := D_LEFT
476 else
477 Result := D_RIGHT;
478 end;
480 function NameToDirAdv(Name: String): Byte;
481 begin
482 if Name = DirNamesAdv[1] then
483 Result := 1
484 else
485 if Name = DirNamesAdv[2] then
486 Result := 2
487 else
488 if Name = DirNamesAdv[3] then
489 Result := 3
490 else
491 Result := 0;
492 end;
494 function ActivateToStr(ActivateType: Byte): String;
495 begin
496 Result := '';
498 if ByteBool(ACTIVATE_PLAYERCOLLIDE and ActivateType) then
499 Result := Result + '+PC';
500 if ByteBool(ACTIVATE_MONSTERCOLLIDE and ActivateType) then
501 Result := Result + '+MC';
502 if ByteBool(ACTIVATE_PLAYERPRESS and ActivateType) then
503 Result := Result + '+PP';
504 if ByteBool(ACTIVATE_MONSTERPRESS and ActivateType) then
505 Result := Result + '+MP';
506 if ByteBool(ACTIVATE_SHOT and ActivateType) then
507 Result := Result + '+SH';
508 if ByteBool(ACTIVATE_NOMONSTER and ActivateType) then
509 Result := Result + '+NM';
511 if (Result <> '') and (Result[1] = '+') then
512 Delete(Result, 1, 1);
513 end;
515 function StrToActivate(Str: String): Byte;
516 begin
517 Result := 0;
519 if Pos('PC', Str) > 0 then
520 Result := ACTIVATE_PLAYERCOLLIDE;
521 if Pos('MC', Str) > 0 then
522 Result := Result or ACTIVATE_MONSTERCOLLIDE;
523 if Pos('PP', Str) > 0 then
524 Result := Result or ACTIVATE_PLAYERPRESS;
525 if Pos('MP', Str) > 0 then
526 Result := Result or ACTIVATE_MONSTERPRESS;
527 if Pos('SH', Str) > 0 then
528 Result := Result or ACTIVATE_SHOT;
529 if Pos('NM', Str) > 0 then
530 Result := Result or ACTIVATE_NOMONSTER;
531 end;
533 function KeyToStr(Key: Byte): String;
534 begin
535 Result := '';
537 if ByteBool(KEY_RED and Key) then
538 Result := Result + '+RK';
539 if ByteBool(KEY_GREEN and Key) then
540 Result := Result + '+GK';
541 if ByteBool(KEY_BLUE and Key) then
542 Result := Result + '+BK';
543 if ByteBool(KEY_REDTEAM and Key) then
544 Result := Result + '+RT';
545 if ByteBool(KEY_BLUETEAM and Key) then
546 Result := Result + '+BT';
548 if (Result <> '') and (Result[1] = '+') then
549 Delete(Result, 1, 1);
550 end;
552 function StrToKey(Str: String): Byte;
553 begin
554 Result := 0;
556 if Pos('RK', Str) > 0 then
557 Result := KEY_RED;
558 if Pos('GK', Str) > 0 then
559 Result := Result or KEY_GREEN;
560 if Pos('BK', Str) > 0 then
561 Result := Result or KEY_BLUE;
562 if Pos('RT', Str) > 0 then
563 Result := Result or KEY_REDTEAM;
564 if Pos('BT', Str) > 0 then
565 Result := Result or KEY_BLUETEAM;
566 end;
568 function EffectToStr(Effect: Byte): String;
569 begin
570 if Effect in [EFFECT_TELEPORT..EFFECT_FIRE] then
571 Result := EffectNames[Effect]
572 else
573 Result := EffectNames[EFFECT_NONE];
574 end;
576 function StrToEffect(Str: String): Byte;
577 var
578 i: Integer;
579 begin
580 Result := EFFECT_NONE;
581 for i := EFFECT_TELEPORT to EFFECT_FIRE do
582 if EffectNames[i] = Str then
583 begin
584 Result := i;
585 Exit;
586 end;
587 end;
589 function MonsterToStr(MonType: Byte): String;
590 begin
591 if MonType in [MONSTER_DEMON..MONSTER_MAN] then
592 Result := MonsterNames[MonType]
593 else
594 Result := MonsterNames[MONSTER_ZOMBY];
595 end;
597 function StrToMonster(Str: String): Byte;
598 var
599 i: Integer;
600 begin
601 Result := MONSTER_ZOMBY;
602 for i := MONSTER_DEMON to MONSTER_MAN do
603 if MonsterNames[i] = Str then
604 begin
605 Result := i;
606 Exit;
607 end;
608 end;
610 function ItemToStr(ItemType: Byte): String;
611 begin
612 if ItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX] then
613 Result := ItemNames[ItemType]
614 else
615 Result := ItemNames[ITEM_AMMO_BULLETS];
616 end;
618 function StrToItem(Str: String): Byte;
619 var
620 i: Integer;
621 begin
622 Result := ITEM_AMMO_BULLETS;
623 for i := ITEM_MEDKIT_SMALL to ITEM_MAX do
624 if ItemNames[i] = Str then
625 begin
626 Result := i;
627 Exit;
628 end;
629 end;
631 function ShotToStr(ShotType: Byte): String;
632 begin
633 if ShotType in [TRIGGER_SHOT_PISTOL..TRIGGER_SHOT_MAX] then
634 Result := ShotNames[ShotType]
635 else
636 Result := ShotNames[TRIGGER_SHOT_PISTOL];
637 end;
639 function StrToShot(Str: String): Byte;
640 var
641 i: Integer;
642 begin
643 Result := TRIGGER_SHOT_PISTOL;
644 for i := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
645 if ShotNames[i] = Str then
646 begin
647 Result := i;
648 Exit;
649 end;
650 end;
652 function SelectedObjectCount(): Word;
653 var
654 a: Integer;
655 begin
656 Result := 0;
658 if SelectedObjects = nil then
659 Exit;
661 for a := 0 to High(SelectedObjects) do
662 if SelectedObjects[a].Live then
663 Result := Result + 1;
664 end;
666 function GetFirstSelected(): Integer;
667 var
668 a: Integer;
669 begin
670 Result := -1;
672 if SelectedObjects = nil then
673 Exit;
675 for a := 0 to High(SelectedObjects) do
676 if SelectedObjects[a].Live then
677 begin
678 Result := a;
679 Exit;
680 end;
681 end;
683 function Normalize16(x: Integer): Integer;
684 begin
685 Result := (x div 16) * 16;
686 end;
688 procedure MoveMap(X, Y: Integer);
689 var
690 rx, ry, ScaleSz: Integer;
691 begin
692 with MainForm.RenderPanel do
693 begin
694 ScaleSz := 16 div Scale;
695 // Размер видимой части карты:
696 rx := min(Normalize16(Width), Normalize16(gMapInfo.Width)) div 2;
697 ry := min(Normalize16(Height), Normalize16(gMapInfo.Height)) div 2;
698 // Место клика на мини-карте:
699 MapOffset.X := X - (Width-max(gMapInfo.Width div ScaleSz, 1)-1);
700 MapOffset.Y := Y - 1;
701 // Это же место на "большой" карте:
702 MapOffset.X := MapOffset.X * ScaleSz;
703 MapOffset.Y := MapOffset.Y * ScaleSz;
704 // Левый верхний угол новой видимой части карты:
705 MapOffset.X := MapOffset.X - rx;
706 MapOffset.Y := MapOffset.Y - ry;
707 // Выход за границы:
708 if MapOffset.X < 0 then
709 MapOffset.X := 0;
710 if MapOffset.Y < 0 then
711 MapOffset.Y := 0;
712 if MapOffset.X > MainForm.sbHorizontal.Max then
713 MapOffset.X := MainForm.sbHorizontal.Max;
714 if MapOffset.Y > MainForm.sbVertical.Max then
715 MapOffset.Y := MainForm.sbVertical.Max;
716 // Кратно 16:
717 MapOffset.X := Normalize16(MapOffset.X);
718 MapOffset.Y := Normalize16(MapOffset.Y);
719 end;
721 MainForm.sbHorizontal.Position := MapOffset.X;
722 MainForm.sbVertical.Position := MapOffset.Y;
724 MapOffset.X := -MapOffset.X;
725 MapOffset.Y := -MapOffset.Y;
727 MainForm.Resize();
728 end;
730 function IsTexturedPanel(PanelType: Word): Boolean;
731 begin
732 Result := WordBool(PanelType and (PANEL_WALL or PANEL_BACK or PANEL_FORE or
733 PANEL_STEP or PANEL_OPENDOOR or PANEL_CLOSEDOOR or
734 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2));
735 end;
737 procedure FillProperty();
738 var
739 _id: DWORD;
740 str: String;
741 begin
742 MainForm.vleObjectProperty.Strings.Clear();
743 MainForm.RecountSelectedObjects();
745 // Отображаем свойства если выделен только один объект:
746 if SelectedObjectCount() <> 1 then
747 Exit;
749 _id := GetFirstSelected();
750 if not SelectedObjects[_id].Live then
751 Exit;
753 with MainForm.vleObjectProperty do
754 with ItemProps[InsertRow(_lc[I_PROP_ID], IntToStr(SelectedObjects[_id].ID), True)] do
755 begin
756 EditStyle := esSimple;
757 ReadOnly := True;
758 end;
760 case SelectedObjects[0].ObjectType of
761 OBJECT_PANEL:
762 begin
763 with MainForm.vleObjectProperty,
764 gPanels[SelectedObjects[_id].ID] do
765 begin
766 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
767 begin
768 EditStyle := esSimple;
769 MaxLength := 5;
770 end;
772 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
773 begin
774 EditStyle := esSimple;
775 MaxLength := 5;
776 end;
778 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
779 begin
780 EditStyle := esSimple;
781 MaxLength := 5;
782 end;
784 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
785 begin
786 EditStyle := esSimple;
787 MaxLength := 5;
788 end;
790 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TYPE], GetPanelName(PanelType), True)] do
791 begin
792 EditStyle := esEllipsis;
793 ReadOnly := True;
794 end;
796 if IsTexturedPanel(PanelType) then
797 begin // Может быть текстура
798 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TEX], TextureName, True)] do
799 begin
800 EditStyle := esEllipsis;
801 ReadOnly := True;
802 end;
804 if TextureName <> '' then
805 begin // Есть текстура
806 with ItemProps[InsertRow(_lc[I_PROP_PANEL_ALPHA], IntToStr(Alpha), True)] do
807 begin
808 EditStyle := esSimple;
809 MaxLength := 3;
810 end;
812 with ItemProps[InsertRow(_lc[I_PROP_PANEL_BLEND], BoolNames[Blending], True)] do
813 begin
814 EditStyle := esPickList;
815 ReadOnly := True;
816 end;
817 end;
818 end;
819 end;
820 end;
822 OBJECT_ITEM:
823 begin
824 with MainForm.vleObjectProperty,
825 gItems[SelectedObjects[_id].ID] do
826 begin
827 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
828 begin
829 EditStyle := esSimple;
830 MaxLength := 5;
831 end;
833 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
834 begin
835 EditStyle := esSimple;
836 MaxLength := 5;
837 end;
839 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[OnlyDM], True)] do
840 begin
841 EditStyle := esPickList;
842 ReadOnly := True;
843 end;
845 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Fall], True)] do
846 begin
847 EditStyle := esPickList;
848 ReadOnly := True;
849 end;
850 end;
851 end;
853 OBJECT_MONSTER:
854 begin
855 with MainForm.vleObjectProperty,
856 gMonsters[SelectedObjects[_id].ID] do
857 begin
858 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
859 begin
860 EditStyle := esSimple;
861 MaxLength := 5;
862 end;
864 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
865 begin
866 EditStyle := esSimple;
867 MaxLength := 5;
868 end;
870 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
871 begin
872 EditStyle := esPickList;
873 ReadOnly := True;
874 end;
875 end;
876 end;
878 OBJECT_AREA:
879 begin
880 with MainForm.vleObjectProperty,
881 gAreas[SelectedObjects[_id].ID] do
882 begin
883 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
884 begin
885 EditStyle := esSimple;
886 MaxLength := 5;
887 end;
889 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
890 begin
891 EditStyle := esSimple;
892 MaxLength := 5;
893 end;
895 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
896 begin
897 EditStyle := esPickList;
898 ReadOnly := True;
899 end;
900 end;
901 end;
903 OBJECT_TRIGGER:
904 begin
905 with MainForm.vleObjectProperty,
906 gTriggers[SelectedObjects[_id].ID] do
907 begin
908 with ItemProps[InsertRow(_lc[I_PROP_TR_TYPE], GetTriggerName(TriggerType), True)] do
909 begin
910 EditStyle := esSimple;
911 ReadOnly := True;
912 end;
914 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
915 begin
916 EditStyle := esSimple;
917 MaxLength := 5;
918 end;
920 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
921 begin
922 EditStyle := esSimple;
923 MaxLength := 5;
924 end;
926 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
927 begin
928 EditStyle := esSimple;
929 MaxLength := 5;
930 end;
932 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
933 begin
934 EditStyle := esSimple;
935 MaxLength := 5;
936 end;
938 with ItemProps[InsertRow(_lc[I_PROP_TR_ENABLED], BoolNames[Enabled], True)] do
939 begin
940 EditStyle := esPickList;
941 ReadOnly := True;
942 end;
944 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_PANEL], IntToStr(TexturePanel), True)] do
945 begin
946 EditStyle := esEllipsis;
947 ReadOnly := True;
948 end;
950 with ItemProps[InsertRow(_lc[I_PROP_TR_ACTIVATION], ActivateToStr(ActivateType), True)] do
951 begin
952 EditStyle := esEllipsis;
953 ReadOnly := True;
954 end;
956 with ItemProps[InsertRow(_lc[I_PROP_TR_KEYS], KeyToStr(Key), True)] do
957 begin
958 EditStyle := esEllipsis;
959 ReadOnly := True;
960 end;
962 case TriggerType of
963 TRIGGER_EXIT:
964 begin
965 str := win2utf(Data.MapName);
966 with ItemProps[InsertRow(_lc[I_PROP_TR_NEXT_MAP], str, True)] do
967 begin
968 EditStyle := esEllipsis;
969 ReadOnly := True;
970 end;
971 end;
973 TRIGGER_TELEPORT:
974 begin
975 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_TO], Format('(%d:%d)', [Data.TargetPoint.X, Data.TargetPoint.Y]), True)] do
976 begin
977 EditStyle := esEllipsis;
978 ReadOnly := True;
979 end;
981 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_teleport], True)] do
982 begin
983 EditStyle := esPickList;
984 ReadOnly := True;
985 end;
987 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_SILENT], BoolNames[Data.silent_teleport], True)] do
988 begin
989 EditStyle := esPickList;
990 ReadOnly := True;
991 end;
993 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_DIR], DirNamesAdv[Data.TlpDir], True)] do
994 begin
995 EditStyle := esPickList;
996 ReadOnly := True;
997 end;
998 end;
1000 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR,
1001 TRIGGER_DOOR, TRIGGER_DOOR5:
1002 begin
1003 with ItemProps[InsertRow(_lc[I_PROP_TR_DOOR_PANEL], IntToStr(Data.PanelID), True)] do
1004 begin
1005 EditStyle := esEllipsis;
1006 ReadOnly := True;
1007 end;
1009 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1010 begin
1011 EditStyle := esPickList;
1012 ReadOnly := True;
1013 end;
1015 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1016 begin
1017 EditStyle := esPickList;
1018 ReadOnly := True;
1019 end;
1020 end;
1022 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1023 begin
1024 with ItemProps[InsertRow(_lc[I_PROP_TR_TRAP_PANEL], IntToStr(Data.PanelID), True)] do
1025 begin
1026 EditStyle := esEllipsis;
1027 ReadOnly := True;
1028 end;
1030 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1031 begin
1032 EditStyle := esPickList;
1033 ReadOnly := True;
1034 end;
1036 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1037 begin
1038 EditStyle := esPickList;
1039 ReadOnly := True;
1040 end;
1041 end;
1043 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
1044 TRIGGER_ONOFF:
1045 begin
1046 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_AREA],
1047 Format('(%d:%d %d:%d)', [Data.tX, Data.tY, Data.tWidth, Data.tHeight]), True)] do
1048 begin
1049 EditStyle := esEllipsis;
1050 ReadOnly := True;
1051 end;
1053 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.Wait), True)] do
1054 begin
1055 EditStyle := esSimple;
1056 MaxLength := 5;
1057 end;
1059 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_COUNT], IntToStr(Data.Count), True)] do
1060 begin
1061 EditStyle := esSimple;
1062 MaxLength := 5;
1063 end;
1065 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_MONSTER], IntToStr(Data.MonsterID-1), True)] do
1066 begin
1067 EditStyle := esEllipsis;
1068 ReadOnly := True;
1069 end;
1071 if TriggerType = TRIGGER_PRESS then
1072 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_RANDOM], BoolNames[Data.ExtRandom], True)] do
1073 begin
1074 EditStyle := esPickList;
1075 ReadOnly := True;
1076 end;
1077 end;
1079 TRIGGER_SECRET:
1082 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
1083 begin
1084 with ItemProps[InsertRow(_lc[I_PROP_TR_LIFT_PANEL], IntToStr(Data.PanelID), True)] do
1085 begin
1086 EditStyle := esEllipsis;
1087 ReadOnly := True;
1088 end;
1090 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1091 begin
1092 EditStyle := esPickList;
1093 ReadOnly := True;
1094 end;
1096 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1097 begin
1098 EditStyle := esPickList;
1099 ReadOnly := True;
1100 end;
1101 end;
1103 TRIGGER_TEXTURE:
1104 begin
1105 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ONCE], BoolNames[Data.ActivateOnce], True)] do
1106 begin
1107 EditStyle := esPickList;
1108 ReadOnly := True;
1109 end;
1111 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ANIM_ONCE], BoolNames[Data.AnimOnce], True)] do
1112 begin
1113 EditStyle := esPickList;
1114 ReadOnly := True;
1115 end;
1116 end;
1118 TRIGGER_SOUND:
1119 begin
1120 str := win2utf(Data.SoundName);
1121 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_NAME], str, True)] do
1122 begin
1123 EditStyle := esEllipsis;
1124 ReadOnly := True;
1125 end;
1127 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_VOLUME], IntToStr(Data.Volume), True)] do
1128 begin
1129 EditStyle := esSimple;
1130 MaxLength := 3;
1131 end;
1133 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_PAN], IntToStr(Data.Pan), True)] do
1134 begin
1135 EditStyle := esSimple;
1136 MaxLength := 3;
1137 end;
1139 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_COUNT], IntToStr(Data.PlayCount), True)] do
1140 begin
1141 EditStyle := esSimple;
1142 MaxLength := 3;
1143 end;
1145 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_LOCAL], BoolNames[Data.Local], True)] do
1146 begin
1147 EditStyle := esPickList;
1148 ReadOnly := True;
1149 end;
1151 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_SWITCH], BoolNames[Data.SoundSwitch], True)] do
1152 begin
1153 EditStyle := esPickList;
1154 ReadOnly := True;
1155 end;
1156 end;
1158 TRIGGER_SPAWNMONSTER:
1159 begin
1160 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_TYPE], MonsterToStr(Data.MonType), True)] do
1161 begin
1162 EditStyle := esEllipsis;
1163 ReadOnly := True;
1164 end;
1166 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1167 Format('(%d:%d)', [Data.MonPos.X, Data.MonPos.Y]), True)] do
1168 begin
1169 EditStyle := esEllipsis;
1170 ReadOnly := True;
1171 end;
1173 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[TDirection(Data.MonDir)], True)] do
1174 begin
1175 EditStyle := esPickList;
1176 ReadOnly := True;
1177 end;
1179 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.MonHealth), True)] do
1180 begin
1181 EditStyle := esSimple;
1182 MaxLength := 5;
1183 end;
1185 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_ACTIVE], BoolNames[Data.MonActive], True)] do
1186 begin
1187 EditStyle := esPickList;
1188 ReadOnly := True;
1189 end;
1191 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.MonCount), True)] do
1192 begin
1193 EditStyle := esSimple;
1194 MaxLength := 5;
1195 end;
1197 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.MonEffect), True)] do
1198 begin
1199 EditStyle := esEllipsis;
1200 ReadOnly := True;
1201 end;
1203 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.MonMax), True)] do
1204 begin
1205 EditStyle := esSimple;
1206 MaxLength := 5;
1207 end;
1209 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.MonDelay), True)] do
1210 begin
1211 EditStyle := esSimple;
1212 MaxLength := 5;
1213 end;
1215 case Data.MonBehav of
1216 1: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1];
1217 2: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2];
1218 3: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3];
1219 4: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4];
1220 5: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5];
1221 else str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_0];
1222 end;
1223 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_BEHAVIOUR], str, True)] do
1224 begin
1225 EditStyle := esPickList;
1226 ReadOnly := True;
1227 end;
1228 end;
1230 TRIGGER_SPAWNITEM:
1231 begin
1232 with ItemProps[InsertRow(_lc[I_PROP_TR_ITEM_TYPE], ItemToStr(Data.ItemType), True)] do
1233 begin
1234 EditStyle := esEllipsis;
1235 ReadOnly := True;
1236 end;
1238 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1239 Format('(%d:%d)', [Data.ItemPos.X, Data.ItemPos.Y]), True)] do
1240 begin
1241 EditStyle := esEllipsis;
1242 ReadOnly := True;
1243 end;
1245 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[Data.ItemOnlyDM], True)] do
1246 begin
1247 EditStyle := esPickList;
1248 ReadOnly := True;
1249 end;
1251 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Data.ItemFalls], True)] do
1252 begin
1253 EditStyle := esPickList;
1254 ReadOnly := True;
1255 end;
1257 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ItemCount), True)] do
1258 begin
1259 EditStyle := esSimple;
1260 MaxLength := 5;
1261 end;
1263 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.ItemEffect), True)] do
1264 begin
1265 EditStyle := esEllipsis;
1266 ReadOnly := True;
1267 end;
1269 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.ItemMax), True)] do
1270 begin
1271 EditStyle := esSimple;
1272 MaxLength := 5;
1273 end;
1275 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.ItemDelay), True)] do
1276 begin
1277 EditStyle := esSimple;
1278 MaxLength := 5;
1279 end;
1280 end;
1282 TRIGGER_MUSIC:
1283 begin
1284 str := win2utf(Data.MusicName);
1285 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_NAME], str, True)] do
1286 begin
1287 EditStyle := esEllipsis;
1288 ReadOnly := True;
1289 end;
1291 if Data.MusicAction = 1 then
1292 str := _lc[I_PROP_TR_MUSIC_ON]
1293 else
1294 str := _lc[I_PROP_TR_MUSIC_OFF];
1296 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_ACT], str, True)] do
1297 begin
1298 EditStyle := esPickList;
1299 ReadOnly := True;
1300 end;
1301 end;
1303 TRIGGER_PUSH:
1304 begin
1305 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_ANGLE], IntToStr(Data.PushAngle), True)] do
1306 begin
1307 EditStyle := esSimple;
1308 MaxLength := 4;
1309 end;
1310 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_FORCE], IntToStr(Data.PushForce), True)] do
1311 begin
1312 EditStyle := esSimple;
1313 MaxLength := 4;
1314 end;
1315 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_RESET], BoolNames[Data.ResetVel], True)] do
1316 begin
1317 EditStyle := esPickList;
1318 ReadOnly := True;
1319 end;
1320 end;
1322 TRIGGER_SCORE:
1323 begin
1324 case Data.ScoreAction of
1325 1: str := _lc[I_PROP_TR_SCORE_ACT_1];
1326 2: str := _lc[I_PROP_TR_SCORE_ACT_2];
1327 3: str := _lc[I_PROP_TR_SCORE_ACT_3];
1328 else str := _lc[I_PROP_TR_SCORE_ACT_0];
1329 end;
1330 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_ACT], str, True)] do
1331 begin
1332 EditStyle := esPickList;
1333 ReadOnly := True;
1334 end;
1335 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ScoreCount), True)] do
1336 begin
1337 EditStyle := esSimple;
1338 MaxLength := 3;
1339 end;
1340 case Data.ScoreTeam of
1341 1: str := _lc[I_PROP_TR_SCORE_TEAM_1];
1342 2: str := _lc[I_PROP_TR_SCORE_TEAM_2];
1343 3: str := _lc[I_PROP_TR_SCORE_TEAM_3];
1344 else str := _lc[I_PROP_TR_SCORE_TEAM_0];
1345 end;
1346 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_TEAM], str, True)] do
1347 begin
1348 EditStyle := esPickList;
1349 ReadOnly := True;
1350 end;
1351 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_CON], BoolNames[Data.ScoreCon], True)] do
1352 begin
1353 EditStyle := esPickList;
1354 ReadOnly := True;
1355 end;
1356 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_MSG], BoolNames[Data.ScoreMsg], True)] do
1357 begin
1358 EditStyle := esPickList;
1359 ReadOnly := True;
1360 end;
1361 end;
1363 TRIGGER_MESSAGE:
1364 begin
1365 case Data.MessageKind of
1366 1: str := _lc[I_PROP_TR_MESSAGE_KIND_1];
1367 else str := _lc[I_PROP_TR_MESSAGE_KIND_0];
1368 end;
1369 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_KIND], str, True)] do
1370 begin
1371 EditStyle := esPickList;
1372 ReadOnly := True;
1373 end;
1374 case Data.MessageSendTo of
1375 1: str := _lc[I_PROP_TR_MESSAGE_TO_1];
1376 2: str := _lc[I_PROP_TR_MESSAGE_TO_2];
1377 3: str := _lc[I_PROP_TR_MESSAGE_TO_3];
1378 4: str := _lc[I_PROP_TR_MESSAGE_TO_4];
1379 5: str := _lc[I_PROP_TR_MESSAGE_TO_5];
1380 else str := _lc[I_PROP_TR_MESSAGE_TO_0];
1381 end;
1382 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TO], str, True)] do
1383 begin
1384 EditStyle := esPickList;
1385 ReadOnly := True;
1386 end;
1387 str := win2utf(Data.MessageText);
1388 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TEXT], str, True)] do
1389 begin
1390 EditStyle := esSimple;
1391 MaxLength := 100;
1392 end;
1393 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TIME], IntToStr(Data.MessageTime), True)] do
1394 begin
1395 EditStyle := esSimple;
1396 MaxLength := 5;
1397 end;
1398 end;
1400 TRIGGER_DAMAGE:
1401 begin
1402 with ItemProps[InsertRow(_lc[I_PROP_TR_DAMAGE_VALUE], IntToStr(Data.DamageValue), True)] do
1403 begin
1404 EditStyle := esSimple;
1405 MaxLength := 5;
1406 end;
1407 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.DamageInterval), True)] do
1408 begin
1409 EditStyle := esSimple;
1410 MaxLength := 5;
1411 end;
1412 end;
1414 TRIGGER_HEALTH:
1415 begin
1416 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.HealValue), True)] do
1417 begin
1418 EditStyle := esSimple;
1419 MaxLength := 5;
1420 end;
1421 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.HealInterval), True)] do
1422 begin
1423 EditStyle := esSimple;
1424 MaxLength := 5;
1425 end;
1426 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH_MAX], BoolNames[Data.HealMax], True)] do
1427 begin
1428 EditStyle := esPickList;
1429 ReadOnly := True;
1430 end;
1431 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.HealSilent], True)] do
1432 begin
1433 EditStyle := esPickList;
1434 ReadOnly := True;
1435 end;
1436 end;
1438 TRIGGER_SHOT:
1439 begin
1440 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TYPE], ShotToStr(Data.ShotType), True)] do
1441 begin
1442 EditStyle := esEllipsis;
1443 ReadOnly := True;
1444 end;
1446 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SOUND], BoolNames[Data.ShotSound], True)] do
1447 begin
1448 EditStyle := esPickList;
1449 ReadOnly := True;
1450 end;
1452 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_PANEL], IntToStr(Data.ShotPanelID), True)] do
1453 begin
1454 EditStyle := esEllipsis;
1455 ReadOnly := True;
1456 end;
1458 case Data.ShotTarget of
1459 1: str := _lc[I_PROP_TR_SHOT_TO_1];
1460 2: str := _lc[I_PROP_TR_SHOT_TO_2];
1461 3: str := _lc[I_PROP_TR_SHOT_TO_3];
1462 4: str := _lc[I_PROP_TR_SHOT_TO_4];
1463 5: str := _lc[I_PROP_TR_SHOT_TO_5];
1464 6: str := _lc[I_PROP_TR_SHOT_TO_6];
1465 else str := _lc[I_PROP_TR_SHOT_TO_0];
1466 end;
1467 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TO], str, True)] do
1468 begin
1469 EditStyle := esPickList;
1470 ReadOnly := True;
1471 end;
1473 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SIGHT], IntToStr(Data.ShotIntSight), True)] do
1474 begin
1475 EditStyle := esSimple;
1476 MaxLength := 3;
1477 end;
1479 case Data.ShotAim of
1480 1: str := _lc[I_PROP_TR_SHOT_AIM_1];
1481 2: str := _lc[I_PROP_TR_SHOT_AIM_2];
1482 3: str := _lc[I_PROP_TR_SHOT_AIM_3];
1483 else str := _lc[I_PROP_TR_SHOT_AIM_0];
1484 end;
1485 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AIM], str, True)-1] do
1486 begin
1487 EditStyle := esPickList;
1488 ReadOnly := True;
1489 end;
1491 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1492 Format('(%d:%d)', [Data.ShotPos.X, Data.ShotPos.Y]), True)] do
1493 begin
1494 EditStyle := esEllipsis;
1495 ReadOnly := True;
1496 end;
1498 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ANGLE], IntToStr(Data.ShotAngle), True)] do
1499 begin
1500 EditStyle := esSimple;
1501 MaxLength := 4;
1502 end;
1504 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.ShotWait), True)] do
1505 begin
1506 EditStyle := esSimple;
1507 MaxLength := 5;
1508 end;
1510 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ACC], IntToStr(Data.ShotAccuracy), True)] do
1511 begin
1512 EditStyle := esSimple;
1513 MaxLength := 5;
1514 end;
1516 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AMMO], IntToStr(Data.ShotAmmo), True)] do
1517 begin
1518 EditStyle := esSimple;
1519 MaxLength := 5;
1520 end;
1522 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_RELOAD], IntToStr(Data.ShotIntReload), True)] do
1523 begin
1524 EditStyle := esSimple;
1525 MaxLength := 4;
1526 end;
1527 end;
1529 TRIGGER_EFFECT:
1530 begin
1531 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.FXCount), True)] do
1532 begin
1533 EditStyle := esSimple;
1534 MaxLength := 3;
1535 end;
1537 if Data.FXType = 0 then
1538 str := _lc[I_PROP_TR_EFFECT_PARTICLE]
1539 else
1540 str := _lc[I_PROP_TR_EFFECT_ANIMATION];
1541 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_TYPE], str, True)] do
1542 begin
1543 EditStyle := esEllipsis;
1544 ReadOnly := True;
1545 end;
1547 str := '';
1548 if Data.FXType = 0 then
1549 case Data.FXSubType of
1550 TRIGGER_EFFECT_SLIQUID:
1551 str := _lc[I_PROP_TR_EFFECT_SLIQUID];
1552 TRIGGER_EFFECT_LLIQUID:
1553 str := _lc[I_PROP_TR_EFFECT_LLIQUID];
1554 TRIGGER_EFFECT_DLIQUID:
1555 str := _lc[I_PROP_TR_EFFECT_DLIQUID];
1556 TRIGGER_EFFECT_BLOOD:
1557 str := _lc[I_PROP_TR_EFFECT_BLOOD];
1558 TRIGGER_EFFECT_SPARK:
1559 str := _lc[I_PROP_TR_EFFECT_SPARK];
1560 TRIGGER_EFFECT_BUBBLE:
1561 str := _lc[I_PROP_TR_EFFECT_BUBBLE];
1562 end;
1563 if Data.FXType = 1 then
1564 begin
1565 if (Data.FXSubType = 0) or (Data.FXSubType > EFFECT_FIRE) then
1566 Data.FXSubType := EFFECT_TELEPORT;
1567 str := EffectToStr(Data.FXSubType);
1568 end;
1569 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SUBTYPE], str, True)] do
1570 begin
1571 EditStyle := esEllipsis;
1572 ReadOnly := True;
1573 end;
1575 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_COLOR], IntToStr(Data.FXColorR or (Data.FXColorG shl 8) or (Data.FXColorB shl 16)), True)] do
1576 begin
1577 EditStyle := esEllipsis;
1578 ReadOnly := True;
1579 end;
1581 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_CENTER], BoolNames[Data.FXPos = 0], True)] do
1582 begin
1583 EditStyle := esPickList;
1584 ReadOnly := True;
1585 end;
1587 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.FXWait), True)] do
1588 begin
1589 EditStyle := esSimple;
1590 MaxLength := 5;
1591 end;
1593 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELX], IntToStr(Data.FXVelX), True)] do
1594 begin
1595 EditStyle := esSimple;
1596 MaxLength := 4;
1597 end;
1599 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELY], IntToStr(Data.FXVelY), True)] do
1600 begin
1601 EditStyle := esSimple;
1602 MaxLength := 4;
1603 end;
1605 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPL], IntToStr(Data.FXSpreadL), True)] do
1606 begin
1607 EditStyle := esSimple;
1608 MaxLength := 3;
1609 end;
1611 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPR], IntToStr(Data.FXSpreadR), True)] do
1612 begin
1613 EditStyle := esSimple;
1614 MaxLength := 3;
1615 end;
1617 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPU], IntToStr(Data.FXSpreadU), True)] do
1618 begin
1619 EditStyle := esSimple;
1620 MaxLength := 3;
1621 end;
1623 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPD], IntToStr(Data.FXSpreadD), True)] do
1624 begin
1625 EditStyle := esSimple;
1626 MaxLength := 3;
1627 end;
1628 end;
1629 end; //case TriggerType
1630 end;
1631 end; // OBJECT_TRIGGER:
1632 end;
1633 end;
1635 procedure ChangeShownProperty(Name: String; NewValue: String);
1636 var
1637 row: Integer;
1638 begin
1639 if SelectedObjectCount() <> 1 then
1640 Exit;
1641 if not SelectedObjects[GetFirstSelected()].Live then
1642 Exit;
1644 // Есть ли такой ключ:
1645 if MainForm.vleObjectProperty.FindRow(Name, row) then
1646 begin
1647 MainForm.vleObjectProperty.Values[Name] := NewValue;
1648 end;
1649 end;
1651 procedure SelectObject(fObjectType: Byte; fID: DWORD; Multi: Boolean);
1652 var
1653 a: Integer;
1654 b: Boolean;
1655 begin
1656 if Multi then
1657 begin
1658 b := False;
1660 // Уже выделен - убираем:
1661 if SelectedObjects <> nil then
1662 for a := 0 to High(SelectedObjects) do
1663 with SelectedObjects[a] do
1664 if Live and (ID = fID) and
1665 (ObjectType = fObjectType) then
1666 begin
1667 Live := False;
1668 b := True;
1669 end;
1671 if b then
1672 Exit;
1674 SetLength(SelectedObjects, Length(SelectedObjects)+1);
1676 with SelectedObjects[High(SelectedObjects)] do
1677 begin
1678 ObjectType := fObjectType;
1679 ID := fID;
1680 Live := True;
1681 end;
1682 end
1683 else // not Multi
1684 begin
1685 SetLength(SelectedObjects, 1);
1687 with SelectedObjects[0] do
1688 begin
1689 ObjectType := fObjectType;
1690 ID := fID;
1691 Live := True;
1692 end;
1693 end;
1695 MainForm.miCopy.Enabled := True;
1696 MainForm.miCut.Enabled := True;
1698 if fObjectType = OBJECT_PANEL then
1699 begin
1700 MainForm.miToFore.Enabled := True;
1701 MainForm.miToBack.Enabled := True;
1702 end;
1703 end;
1705 procedure RemoveSelectFromObjects();
1706 begin
1707 SelectedObjects := nil;
1708 DrawPressRect := False;
1709 MouseLDown := False;
1710 MouseRDown := False;
1711 MouseAction := MOUSEACTION_NONE;
1712 SelectFlag := SELECTFLAG_NONE;
1713 ResizeType := RESIZETYPE_NONE;
1714 ResizeDirection := RESIZEDIR_NONE;
1716 MainForm.vleObjectProperty.Strings.Clear();
1718 MainForm.miCopy.Enabled := False;
1719 MainForm.miCut.Enabled := False;
1720 MainForm.miToFore.Enabled := False;
1721 MainForm.miToBack.Enabled := False;
1722 end;
1724 procedure DeleteSelectedObjects();
1725 var
1726 i, a, ii: Integer;
1727 b: Boolean;
1728 begin
1729 if SelectedObjects = nil then
1730 Exit;
1732 b := False;
1733 i := 0;
1735 for a := 0 to High(SelectedObjects) do
1736 with SelectedObjects[a] do
1737 if Live then
1738 begin
1739 if not b then
1740 begin
1741 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1742 i := High(UndoBuffer);
1743 b := True;
1744 end;
1746 SetLength(UndoBuffer[i], Length(UndoBuffer[i])+1);
1747 ii := High(UndoBuffer[i]);
1749 case ObjectType of
1750 OBJECT_PANEL:
1751 begin
1752 UndoBuffer[i, ii].UndoType := UNDO_DELETE_PANEL;
1753 New(UndoBuffer[i, ii].Panel);
1754 UndoBuffer[i, ii].Panel^ := gPanels[ID];
1755 end;
1756 OBJECT_ITEM:
1757 begin
1758 UndoBuffer[i, ii].UndoType := UNDO_DELETE_ITEM;
1759 UndoBuffer[i, ii].Item := gItems[ID];
1760 end;
1761 OBJECT_AREA:
1762 begin
1763 UndoBuffer[i, ii].UndoType := UNDO_DELETE_AREA;
1764 UndoBuffer[i, ii].Area := gAreas[ID];
1765 end;
1766 OBJECT_TRIGGER:
1767 begin
1768 UndoBuffer[i, ii].UndoType := UNDO_DELETE_TRIGGER;
1769 UndoBuffer[i, ii].Trigger := gTriggers[ID];
1770 end;
1771 end;
1773 RemoveObject(ID, ObjectType);
1774 end;
1776 RemoveSelectFromObjects();
1778 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1779 end;
1781 procedure Undo_Add(ObjectType: Byte; ID: DWORD; Group: Boolean = False);
1782 var
1783 i, ii: Integer;
1784 begin
1785 if (not Group) or (Length(UndoBuffer) = 0) then
1786 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1787 SetLength(UndoBuffer[High(UndoBuffer)], Length(UndoBuffer[High(UndoBuffer)])+1);
1788 i := High(UndoBuffer);
1789 ii := High(UndoBuffer[i]);
1791 case ObjectType of
1792 OBJECT_PANEL:
1793 UndoBuffer[i, ii].UndoType := UNDO_ADD_PANEL;
1794 OBJECT_ITEM:
1795 UndoBuffer[i, ii].UndoType := UNDO_ADD_ITEM;
1796 OBJECT_MONSTER:
1797 UndoBuffer[i, ii].UndoType := UNDO_ADD_MONSTER;
1798 OBJECT_AREA:
1799 UndoBuffer[i, ii].UndoType := UNDO_ADD_AREA;
1800 OBJECT_TRIGGER:
1801 UndoBuffer[i, ii].UndoType := UNDO_ADD_TRIGGER;
1802 end;
1804 UndoBuffer[i, ii].AddID := ID;
1806 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1807 end;
1809 procedure FullClear();
1810 begin
1811 RemoveSelectFromObjects();
1812 ClearMap();
1813 LoadSky(gMapInfo.SkyName);
1814 UndoBuffer := nil;
1815 slInvalidTextures.Clear();
1816 MapCheckForm.lbErrorList.Clear();
1817 MapCheckForm.mErrorDescription.Clear();
1819 MainForm.miUndo.Enabled := False;
1820 MainForm.sbHorizontal.Position := 0;
1821 MainForm.sbVertical.Position := 0;
1822 MainForm.FormResize(nil);
1823 MainForm.Caption := FormCaption;
1824 OpenedMap := '';
1825 OpenedWAD := '';
1826 end;
1828 procedure ErrorMessageBox(str: String);
1829 begin
1830 MessageBox(0, PChar(str), PChar(_lc[I_MSG_ERROR]),
1831 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
1832 end;
1834 function CheckProperty(): Boolean;
1835 var
1836 _id: Integer;
1837 begin
1838 Result := False;
1840 _id := GetFirstSelected();
1842 if SelectedObjects[_id].ObjectType = OBJECT_PANEL then
1843 with gPanels[SelectedObjects[_id].ID] do
1844 begin
1845 if TextureWidth <> 0 then
1846 if StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 1) mod TextureWidth <> 0 then
1847 begin
1848 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
1849 [TextureWidth]));
1850 Exit;
1851 end;
1853 if TextureHeight <> 0 then
1854 if StrToIntDef(Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]), 1) mod TextureHeight <> 0 then
1855 begin
1856 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
1857 [TextureHeight]));
1858 Exit;
1859 end;
1861 if IsTexturedPanel(PanelType) and (TextureName <> '') then
1862 if not (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]], -1) in [0..255]) then
1863 begin
1864 ErrorMessageBox(_lc[I_MSG_WRONG_ALPHA]);
1865 Exit;
1866 end;
1867 end;
1869 if SelectedObjects[_id].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
1870 if (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 0) <= 0) or
1871 (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]], 0) <= 0) then
1872 begin
1873 ErrorMessageBox(_lc[I_MSG_WRONG_SIZE]);
1874 Exit;
1875 end;
1877 if (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_X]]) = '') or
1878 (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_Y]]) = '') then
1879 begin
1880 ErrorMessageBox(_lc[I_MSG_WRONG_XY]);
1881 Exit;
1882 end;
1884 Result := True;
1885 end;
1887 procedure SelectTexture(ID: Integer);
1888 begin
1889 MainForm.lbTextureList.ItemIndex := ID;
1890 MainForm.lbTextureListClick(nil);
1891 end;
1893 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
1894 var
1895 a, FrameLen: Integer;
1896 ok: Boolean;
1897 FileName: String;
1898 ResourceName: String;
1899 FullResourceName: String;
1900 SectionName: String;
1901 Data: Pointer;
1902 Width, Height: Word;
1903 fn: String;
1904 begin
1905 Data := nil;
1906 FrameLen := 0;
1907 Width := 0;
1908 Height := 0;
1910 if aSection = '..' then
1911 SectionName := ''
1912 else
1913 SectionName := aSection;
1915 if aWAD = '' then
1916 aWAD := _lc[I_WAD_SPECIAL_MAP];
1918 if aWAD = _lc[I_WAD_SPECIAL_MAP] then
1919 begin // Файл карты
1920 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
1921 //FileName := EditorDir+'maps\'+ExtractFileName(fn);
1922 FileName := fn;
1923 ResourceName := ':'+SectionName+'\'+aTex;
1924 end
1925 else
1926 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1927 begin // Спец. текстуры
1928 FileName := '';
1929 ResourceName := aTex;
1930 end
1931 else
1932 begin // Внешний WAD
1933 FileName := EditorDir+'wads/'+aWAD;
1934 ResourceName := aWAD+':'+SectionName+'\'+aTex;
1935 end;
1937 ok := True;
1939 // Есть ли уже такая текстура:
1940 for a := 0 to MainForm.lbTextureList.Items.Count-1 do
1941 if ResourceName = MainForm.lbTextureList.Items[a] then
1942 begin
1943 if not silent then
1944 ErrorMessageBox(Format(_lc[I_MSG_TEXTURE_ALREADY],
1945 [ResourceName]));
1946 ok := False;
1947 end;
1949 // Название ресурса <= 64 символов:
1950 if Length(ResourceName) > 64 then
1951 begin
1952 if not silent then
1953 ErrorMessageBox(Format(_lc[I_MSG_RES_NAME_64],
1954 [ResourceName]));
1955 ok := False;
1956 end;
1958 if ok then
1959 begin
1960 a := -1;
1961 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1962 begin
1963 a := MainForm.lbTextureList.Items.Add(ResourceName);
1964 if not silent then
1965 SelectTexture(a);
1966 Result := True;
1967 Exit;
1968 end;
1970 FullResourceName := FileName+':'+SectionName+'\'+aTex;
1972 if IsAnim(FullResourceName) then
1973 begin // Аним. текстура
1974 GetFrame(FullResourceName, Data, FrameLen, Width, Height);
1976 if not g_CreateTextureMemorySize(Data, FrameLen, ResourceName, 0, 0, Width, Height, 1) then
1977 ok := False;
1978 a := MainForm.lbTextureList.Items.Add(ResourceName);
1979 end
1980 else // Обычная текстура
1981 begin
1982 if not g_CreateTextureWAD(ResourceName, FullResourceName) then
1983 ok := False;
1984 a := MainForm.lbTextureList.Items.Add(ResourceName);
1985 end;
1986 if (not ok) and (slInvalidTextures.IndexOf(ResourceName) = -1) then
1987 begin
1988 slInvalidTextures.Add(ResourceName);
1989 ok := True;
1990 end;
1991 if (a > -1) and (not silent) then
1992 SelectTexture(a);
1993 end;
1995 Result := ok;
1996 end;
1998 procedure UpdateCaption(sMap, sFile, sRes: String);
1999 begin
2000 with MainForm do
2001 if (sFile = '') and (sRes = '') and (sMap = '') then
2002 Caption := FormCaption
2003 else
2004 if sMap = '' then
2005 Caption := Format('%s - %s:%s', [FormCaption, sFile, sRes])
2006 else
2007 if (sFile <> '') and (sRes <> '') then
2008 Caption := Format('%s - %s (%s:%s)', [FormCaption, sMap, sFile, sRes])
2009 else
2010 Caption := Format('%s - %s', [FormCaption, sMap]);
2011 end;
2013 procedure OpenMap(FileName: String; mapN: String);
2014 var
2015 MapName: String;
2016 idx: Integer;
2017 begin
2018 SelectMapForm.Caption := _lc[I_CAP_OPEN];
2019 SelectMapForm.GetMaps(FileName);
2021 if (FileName = OpenedWAD) and
2022 (OpenedMap <> '') then
2023 begin
2024 MapName := OpenedMap;
2025 while (Pos(':\', MapName) > 0) do
2026 Delete(MapName, 1, Pos(':\', MapName) + 1);
2028 idx := SelectMapForm.lbMapList.Items.IndexOf(MapName);
2029 SelectMapForm.lbMapList.ItemIndex := idx;
2030 end
2031 else
2032 if SelectMapForm.lbMapList.Count > 0 then
2033 SelectMapForm.lbMapList.ItemIndex := 0
2034 else
2035 SelectMapForm.lbMapList.ItemIndex := -1;
2037 if mapN = '' then
2038 idx := -1
2039 else
2040 idx := SelectMapForm.lbMapList.Items.IndexOf(mapN);
2042 if idx < 0 then
2043 begin
2044 if (SelectMapForm.ShowModal() = mrOK) and
2045 (SelectMapForm.lbMapList.ItemIndex <> -1) then
2046 idx := SelectMapForm.lbMapList.ItemIndex
2047 else
2048 Exit;
2049 end;
2051 MapName := SelectMapForm.lbMapList.Items[idx];
2053 with MainForm do
2054 begin
2055 FullClear();
2057 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
2058 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
2059 pLoadProgress.Show();
2061 OpenedMap := FileName+':\'+MapName;
2062 OpenedWAD := FileName;
2064 idx := RecentFiles.IndexOf(OpenedMap);
2065 // Такая карта уже недавно открывалась:
2066 if idx >= 0 then
2067 RecentFiles.Delete(idx);
2068 RecentFiles.Insert(0, OpenedMap);
2069 RefreshRecentMenu();
2071 LoadMap(OpenedMap);
2073 pLoadProgress.Hide();
2074 FormResize(nil);
2076 lbTextureList.Sorted := True;
2077 lbTextureList.Sorted := False;
2079 UpdateCaption(gMapInfo.Name, ExtractFileName(FileName), MapName);
2080 end;
2081 end;
2083 procedure MoveSelectedObjects(Wall, alt: Boolean; dx, dy: Integer);
2084 var
2085 okX, okY: Boolean;
2086 a: Integer;
2087 begin
2088 if SelectedObjects = nil then
2089 Exit;
2091 okX := True;
2092 okY := True;
2094 if Wall then
2095 for a := 0 to High(SelectedObjects) do
2096 if SelectedObjects[a].Live then
2097 begin
2098 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, dx, 0) then
2099 okX := False;
2101 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, 0, dy) then
2102 okY := False;
2104 if (not okX) or (not okY) then
2105 Break;
2106 end;
2108 if okX or okY then
2109 begin
2110 for a := 0 to High(SelectedObjects) do
2111 if SelectedObjects[a].Live then
2112 begin
2113 if okX then
2114 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, dx, 0);
2116 if okY then
2117 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, 0, dy);
2119 if alt and (SelectedObjects[a].ObjectType = OBJECT_TRIGGER) then
2120 begin
2121 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_PRESS,
2122 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
2123 begin // Двигаем зону Расширителя
2124 if okX then
2125 gTriggers[SelectedObjects[a].ID].Data.tX := gTriggers[SelectedObjects[a].ID].Data.tX+dx;
2126 if okY then
2127 gTriggers[SelectedObjects[a].ID].Data.tY := gTriggers[SelectedObjects[a].ID].Data.tY+dy;
2128 end;
2130 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_TELEPORT] then
2131 begin // Двигаем точку назначения Телепорта
2132 if okX then
2133 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X+dx;
2134 if okY then
2135 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y+dy;
2136 end;
2138 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNMONSTER] then
2139 begin // Двигаем точку создания монстра
2140 if okX then
2141 gTriggers[SelectedObjects[a].ID].Data.MonPos.X := gTriggers[SelectedObjects[a].ID].Data.MonPos.X+dx;
2142 if okY then
2143 gTriggers[SelectedObjects[a].ID].Data.MonPos.Y := gTriggers[SelectedObjects[a].ID].Data.MonPos.Y+dy;
2144 end;
2146 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNITEM] then
2147 begin // Двигаем точку создания предмета
2148 if okX then
2149 gTriggers[SelectedObjects[a].ID].Data.ItemPos.X := gTriggers[SelectedObjects[a].ID].Data.ItemPos.X+dx;
2150 if okY then
2151 gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y := gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y+dy;
2152 end;
2154 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SHOT] then
2155 begin // Двигаем точку создания выстрела
2156 if okX then
2157 gTriggers[SelectedObjects[a].ID].Data.ShotPos.X := gTriggers[SelectedObjects[a].ID].Data.ShotPos.X+dx;
2158 if okY then
2159 gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y := gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y+dy;
2160 end;
2161 end;
2162 end;
2164 LastMovePoint := MousePos;
2165 end;
2166 end;
2168 procedure ShowLayer(Layer: Byte; show: Boolean);
2169 begin
2170 LayerEnabled[Layer] := show;
2172 case Layer of
2173 LAYER_BACK:
2174 begin
2175 MainForm.miLayer1.Checked := show;
2176 MainForm.miLayerP1.Checked := show;
2177 end;
2178 LAYER_WALLS:
2179 begin
2180 MainForm.miLayer2.Checked := show;
2181 MainForm.miLayerP2.Checked := show;
2182 end;
2183 LAYER_FOREGROUND:
2184 begin
2185 MainForm.miLayer3.Checked := show;
2186 MainForm.miLayerP3.Checked := show;
2187 end;
2188 LAYER_STEPS:
2189 begin
2190 MainForm.miLayer4.Checked := show;
2191 MainForm.miLayerP4.Checked := show;
2192 end;
2193 LAYER_WATER:
2194 begin
2195 MainForm.miLayer5.Checked := show;
2196 MainForm.miLayerP5.Checked := show;
2197 end;
2198 LAYER_ITEMS:
2199 begin
2200 MainForm.miLayer6.Checked := show;
2201 MainForm.miLayerP6.Checked := show;
2202 end;
2203 LAYER_MONSTERS:
2204 begin
2205 MainForm.miLayer7.Checked := show;
2206 MainForm.miLayerP7.Checked := show;
2207 end;
2208 LAYER_AREAS:
2209 begin
2210 MainForm.miLayer8.Checked := show;
2211 MainForm.miLayerP8.Checked := show;
2212 end;
2213 LAYER_TRIGGERS:
2214 begin
2215 MainForm.miLayer9.Checked := show;
2216 MainForm.miLayerP9.Checked := show;
2217 end;
2218 end;
2220 RemoveSelectFromObjects();
2221 end;
2223 procedure SwitchLayer(Layer: Byte);
2224 begin
2225 ShowLayer(Layer, not LayerEnabled[Layer]);
2226 end;
2228 procedure SwitchMap();
2229 begin
2230 ShowMap := not ShowMap;
2231 MainForm.tbShowMap.Down := ShowMap;
2232 end;
2234 procedure ShowEdges();
2235 begin
2236 if drEdge[3] < 255 then
2237 drEdge[3] := 255
2238 else
2239 drEdge[3] := gAlphaEdge;
2240 end;
2242 function SelectedTexture(): String;
2243 begin
2244 if MainForm.lbTextureList.ItemIndex <> -1 then
2245 Result := MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]
2246 else
2247 Result := '';
2248 end;
2250 function IsSpecialTextureSel(): Boolean;
2251 begin
2252 Result := (MainForm.lbTextureList.ItemIndex <> -1) and
2253 IsSpecialTexture(MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]);
2254 end;
2256 function CopyBufferToString(var CopyBuf: TCopyRecArray): String;
2257 var
2258 i, j: Integer;
2259 Res: String;
2261 procedure AddInt(x: Integer);
2262 begin
2263 Res := Res + IntToStr(x) + ' ';
2264 end;
2266 begin
2267 Result := '';
2269 if Length(CopyBuf) = 0 then
2270 Exit;
2272 Res := CLIPBOARD_SIG + ' ';
2274 for i := 0 to High(CopyBuf) do
2275 begin
2276 if (CopyBuf[i].ObjectType = OBJECT_PANEL) and
2277 (CopyBuf[i].Panel = nil) then
2278 Continue;
2280 // Тип объекта:
2281 AddInt(CopyBuf[i].ObjectType);
2282 Res := Res + '; ';
2284 // Свойства объекта:
2285 case CopyBuf[i].ObjectType of
2286 OBJECT_PANEL:
2287 with CopyBuf[i].Panel^ do
2288 begin
2289 AddInt(PanelType);
2290 AddInt(X);
2291 AddInt(Y);
2292 AddInt(Width);
2293 AddInt(Height);
2294 Res := Res + '"' + TextureName + '" ';
2295 AddInt(Alpha);
2296 AddInt(IfThen(Blending, 1, 0));
2297 end;
2299 OBJECT_ITEM:
2300 with CopyBuf[i].Item do
2301 begin
2302 AddInt(ItemType);
2303 AddInt(X);
2304 AddInt(Y);
2305 AddInt(IfThen(OnlyDM, 1, 0));
2306 AddInt(IfThen(Fall, 1, 0));
2307 end;
2309 OBJECT_MONSTER:
2310 with CopyBuf[i].Monster do
2311 begin
2312 AddInt(MonsterType);
2313 AddInt(X);
2314 AddInt(Y);
2315 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2316 end;
2318 OBJECT_AREA:
2319 with CopyBuf[i].Area do
2320 begin
2321 AddInt(AreaType);
2322 AddInt(X);
2323 AddInt(Y);
2324 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2325 end;
2327 OBJECT_TRIGGER:
2328 with CopyBuf[i].Trigger do
2329 begin
2330 AddInt(TriggerType);
2331 AddInt(X);
2332 AddInt(Y);
2333 AddInt(Width);
2334 AddInt(Height);
2335 AddInt(ActivateType);
2336 AddInt(Key);
2337 AddInt(IfThen(Enabled, 1, 0));
2338 AddInt(TexturePanel);
2340 for j := 0 to 127 do
2341 AddInt(Data.Default[j]);
2342 end;
2343 end;
2344 end;
2346 Result := Res;
2347 end;
2349 procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray;
2350 var pmin: TPoint);
2351 var
2352 i, j, t: Integer;
2354 function GetNext(): String;
2355 var
2356 p: Integer;
2358 begin
2359 if Str[1] = '"' then
2360 begin
2361 Delete(Str, 1, 1);
2362 p := Pos('"', Str);
2364 if p = 0 then
2365 begin
2366 Result := Str;
2367 Str := '';
2368 end
2369 else
2370 begin
2371 Result := Copy(Str, 1, p-1);
2372 Delete(Str, 1, p);
2373 Str := Trim(Str);
2374 end;
2375 end
2376 else
2377 begin
2378 p := Pos(' ', Str);
2380 if p = 0 then
2381 begin
2382 Result := Str;
2383 Str := '';
2384 end
2385 else
2386 begin
2387 Result := Copy(Str, 1, p-1);
2388 Delete(Str, 1, p);
2389 Str := Trim(Str);
2390 end;
2391 end;
2392 end;
2394 begin
2395 Str := Trim(Str);
2397 if GetNext() <> CLIPBOARD_SIG then
2398 Exit;
2400 while Str <> '' do
2401 begin
2402 // Тип объекта:
2403 t := StrToIntDef(GetNext(), 0);
2405 if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or
2406 (GetNext() <> ';') then
2407 begin // Что-то не то => пропускаем:
2408 t := Pos(';', Str);
2409 Delete(Str, 1, t);
2410 Str := Trim(Str);
2412 Continue;
2413 end;
2415 i := Length(CopyBuf);
2416 SetLength(CopyBuf, i + 1);
2418 CopyBuf[i].ObjectType := t;
2419 CopyBuf[i].Panel := nil;
2421 // Свойства объекта:
2422 case t of
2423 OBJECT_PANEL:
2424 begin
2425 New(CopyBuf[i].Panel);
2427 with CopyBuf[i].Panel^ do
2428 begin
2429 PanelType := StrToIntDef(GetNext(), PANEL_WALL);
2430 X := StrToIntDef(GetNext(), 0);
2431 Y := StrToIntDef(GetNext(), 0);
2432 pmin.X := Min(X, pmin.X);
2433 pmin.Y := Min(Y, pmin.Y);
2434 Width := StrToIntDef(GetNext(), 16);
2435 Height := StrToIntDef(GetNext(), 16);
2436 TextureName := GetNext();
2437 Alpha := StrToIntDef(GetNext(), 0);
2438 Blending := (GetNext() = '1');
2439 end;
2440 end;
2442 OBJECT_ITEM:
2443 with CopyBuf[i].Item do
2444 begin
2445 ItemType := StrToIntDef(GetNext(), ITEM_MEDKIT_SMALL);
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 OnlyDM := (GetNext() = '1');
2451 Fall := (GetNext() = '1');
2452 end;
2454 OBJECT_MONSTER:
2455 with CopyBuf[i].Monster do
2456 begin
2457 MonsterType := StrToIntDef(GetNext(), MONSTER_DEMON);
2458 X := StrToIntDef(GetNext(), 0);
2459 Y := StrToIntDef(GetNext(), 0);
2460 pmin.X := Min(X, pmin.X);
2461 pmin.Y := Min(Y, pmin.Y);
2463 if GetNext() = '1' then
2464 Direction := D_LEFT
2465 else
2466 Direction := D_RIGHT;
2467 end;
2469 OBJECT_AREA:
2470 with CopyBuf[i].Area do
2471 begin
2472 AreaType := StrToIntDef(GetNext(), AREA_PLAYERPOINT1);
2473 X := StrToIntDef(GetNext(), 0);
2474 Y := StrToIntDef(GetNext(), 0);
2475 pmin.X := Min(X, pmin.X);
2476 pmin.Y := Min(Y, pmin.Y);
2477 if GetNext() = '1' then
2478 Direction := D_LEFT
2479 else
2480 Direction := D_RIGHT;
2481 end;
2483 OBJECT_TRIGGER:
2484 with CopyBuf[i].Trigger do
2485 begin
2486 TriggerType := StrToIntDef(GetNext(), TRIGGER_EXIT);
2487 X := StrToIntDef(GetNext(), 0);
2488 Y := StrToIntDef(GetNext(), 0);
2489 pmin.X := Min(X, pmin.X);
2490 pmin.Y := Min(Y, pmin.Y);
2491 Width := StrToIntDef(GetNext(), 16);
2492 Height := StrToIntDef(GetNext(), 16);
2493 ActivateType := StrToIntDef(GetNext(), 0);
2494 Key := StrToIntDef(GetNext(), 0);
2495 Enabled := (GetNext() = '1');
2496 TexturePanel := StrToIntDef(GetNext(), 0);
2498 for j := 0 to 127 do
2499 Data.Default[j] := StrToIntDef(GetNext(), 0);
2501 case TriggerType of
2502 TRIGGER_TELEPORT:
2503 begin
2504 pmin.X := Min(Data.TargetPoint.X, pmin.X);
2505 pmin.Y := Min(Data.TargetPoint.Y, pmin.Y);
2506 end;
2507 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
2508 begin
2509 pmin.X := Min(Data.tX, pmin.X);
2510 pmin.Y := Min(Data.tY, pmin.Y);
2511 end;
2512 TRIGGER_SPAWNMONSTER:
2513 begin
2514 pmin.X := Min(Data.MonPos.X, pmin.X);
2515 pmin.Y := Min(Data.MonPos.Y, pmin.Y);
2516 end;
2517 TRIGGER_SPAWNITEM:
2518 begin
2519 pmin.X := Min(Data.ItemPos.X, pmin.X);
2520 pmin.Y := Min(Data.ItemPos.Y, pmin.Y);
2521 end;
2522 TRIGGER_SHOT:
2523 begin
2524 pmin.X := Min(Data.ShotPos.X, pmin.X);
2525 pmin.Y := Min(Data.ShotPos.Y, pmin.Y);
2526 end;
2527 end;
2528 end;
2529 end;
2530 end;
2531 end;
2533 //----------------------------------------
2534 //Закончились вспомогательные процедуры
2535 //----------------------------------------
2537 procedure TMainForm.RefreshRecentMenu();
2538 var
2539 i: Integer;
2540 MI: TMenuItem;
2541 begin
2542 // Лишние запомненные карты:
2543 while RecentFiles.Count > RecentCount do
2544 RecentFiles.Delete(RecentFiles.Count-1);
2546 // Лишние строки меню:
2547 while MainMenu.Items[0].Count > RECENT_FILES_MENU_START do
2548 MainMenu.Items[0].Delete(MainMenu.Items[0].Count-1);
2550 // Отделение списка карт от строки "Выход":
2551 if RecentFiles.Count > 0 then
2552 begin
2553 MI := TMenuItem.Create(MainMenu.Items[0]);
2554 MI.Caption := '-';
2555 MainMenu.Items[0].Add(MI);
2556 end;
2558 // Добавление в меню списка запомненных карт:
2559 for i := 0 to RecentFiles.Count-1 do
2560 begin
2561 MI := TMenuItem.Create(MainMenu.Items[0]);
2562 MI.Caption := IntToStr(i+1) + ' ' + RecentFiles[i];
2563 MI.OnClick := aRecentFileExecute;
2564 MainMenu.Items[0].Add(MI);
2565 end;
2566 end;
2568 procedure TMainForm.aRecentFileExecute(Sender: TObject);
2569 var
2570 n, pw: Integer;
2571 s, fn: String;
2572 b: Boolean;
2573 begin
2574 s := LowerCase((Sender as TMenuItem).Caption);
2575 Delete(s, Pos('&', s), 1);
2576 s := Trim(Copy(s, 1, 2));
2577 n := StrToIntDef(s, 0) - 1;
2579 if (n < 0) or (n >= RecentFiles.Count) then
2580 Exit;
2582 s := RecentFiles[n];
2583 pw := Pos('.wad:\', LowerCase(s));
2584 b := False;
2586 if pw > 0 then
2587 begin // Map name included
2588 fn := Copy(s, 1, pw + 3);
2589 Delete(s, 1, pw + 5);
2590 if (FileExists(fn)) then
2591 begin
2592 OpenMap(fn, s);
2593 b := True;
2594 end;
2595 end
2596 else // Only wad name
2597 if (FileExists(s)) then
2598 begin
2599 OpenMap(s, '');
2600 b := True;
2601 end;
2603 if (not b) and (MessageBox(0, PChar(_lc[I_MSG_DEL_RECENT_PROMT]),
2604 PChar(_lc[I_MSG_DEL_RECENT]), MB_ICONQUESTION or MB_YESNO) = idYes) then
2605 begin
2606 RecentFiles.Delete(n);
2607 RefreshRecentMenu();
2608 end;
2609 end;
2611 procedure TMainForm.aEditorOptionsExecute(Sender: TObject);
2612 begin
2613 OptionsForm.ShowModal();
2614 end;
2616 procedure LoadStdFont(cfgres, texture: string; var FontID: DWORD);
2617 var
2618 cwdt, chgt: Byte;
2619 spc: ShortInt;
2620 ID: DWORD;
2621 wad: TWADEditor_1;
2622 cfgdata: Pointer;
2623 cfglen: Integer;
2624 config: TConfig;
2625 begin
2626 cfgdata := nil;
2627 cfglen := 0;
2628 ID := 0;
2630 wad := TWADEditor_1.Create;
2631 if wad.ReadFile(EditorDir+'data/Game.wad') then
2632 wad.GetResource('FONTS', cfgres, cfgdata, cfglen);
2633 wad.Free();
2635 if cfglen <> 0 then
2636 begin
2637 if not g_CreateTextureWAD('FONT_STD', EditorDir+'data/Game.wad:FONTS\'+texture) then
2638 e_WriteLog('ERROR ERROR ERROR', MSG_WARNING);
2640 config := TConfig.CreateMem(cfgdata, cfglen);
2641 cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
2642 chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
2643 spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
2645 if g_GetTexture('FONT_STD', ID) then
2646 e_TextureFontBuild(ID, FontID, cwdt, chgt, spc-2);
2648 config.Free();
2649 end
2650 else
2651 e_WriteLog('Could not load FONT_STD', MSG_WARNING);
2653 if cfglen <> 0 then FreeMem(cfgdata);
2654 end;
2656 procedure TMainForm.FormCreate(Sender: TObject);
2657 var
2658 config: TConfig;
2659 i: Integer;
2660 s: String;
2661 begin
2662 Randomize();
2664 EditorDir := ExtractFilePath(Application.ExeName);
2666 e_InitLog(EditorDir+'Editor.log', WM_NEWFILE);
2668 slInvalidTextures := TStringList.Create;
2670 ShowLayer(LAYER_BACK, True);
2671 ShowLayer(LAYER_WALLS, True);
2672 ShowLayer(LAYER_FOREGROUND, True);
2673 ShowLayer(LAYER_STEPS, True);
2674 ShowLayer(LAYER_WATER, True);
2675 ShowLayer(LAYER_ITEMS, True);
2676 ShowLayer(LAYER_MONSTERS, True);
2677 ShowLayer(LAYER_AREAS, True);
2678 ShowLayer(LAYER_TRIGGERS, True);
2680 ClearMap();
2682 FormCaption := MainForm.Caption;
2683 OpenedMap := '';
2684 OpenedWAD := '';
2686 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
2688 if config.ReadInt('Editor', 'XPos', -1) = -1 then
2689 Position := poDesktopCenter
2690 else begin
2691 Left := config.ReadInt('Editor', 'XPos', Left);
2692 Top := config.ReadInt('Editor', 'YPos', Top);
2693 Width := config.ReadInt('Editor', 'Width', Width);
2694 Height := config.ReadInt('Editor', 'Height', Height);
2695 end;
2696 if config.ReadBool('Editor', 'Maximize', False) then
2697 WindowState := wsMaximized;
2698 ShowMap := config.ReadBool('Editor', 'Minimap', False);
2699 PanelProps.Width := config.ReadInt('Editor', 'PanelProps', PanelProps.ClientWidth);
2700 Splitter1.Left := PanelProps.Left;
2701 PanelObjs.Height := config.ReadInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
2702 Splitter2.Top := PanelObjs.Top;
2703 StatusBar.Top := PanelObjs.BoundsRect.Bottom;
2704 DotEnable := config.ReadBool('Editor', 'DotEnable', True);
2705 DotColor := config.ReadInt('Editor', 'DotColor', $FFFFFF);
2706 DotStepOne := config.ReadInt('Editor', 'DotStepOne', 16);
2707 DotStepTwo := config.ReadInt('Editor', 'DotStepTwo', 8);
2708 DotStep := config.ReadInt('Editor', 'DotStep', DotStepOne);
2709 DrawTexturePanel := config.ReadBool('Editor', 'DrawTexturePanel', True);
2710 DrawPanelSize := config.ReadBool('Editor', 'DrawPanelSize', True);
2711 BackColor := config.ReadInt('Editor', 'BackColor', $7F6040);
2712 PreviewColor := config.ReadInt('Editor', 'PreviewColor', $00FF00);
2713 UseCheckerboard := config.ReadBool('Editor', 'UseCheckerboard', True);
2714 gColorEdge := config.ReadInt('Editor', 'EdgeColor', COLOR_EDGE);
2715 gAlphaEdge := config.ReadInt('Editor', 'EdgeAlpha', ALPHA_EDGE);
2716 if gAlphaEdge = 255 then
2717 gAlphaEdge := ALPHA_EDGE;
2718 drEdge[0] := GetRValue(gColorEdge);
2719 drEdge[1] := GetGValue(gColorEdge);
2720 drEdge[2] := GetBValue(gColorEdge);
2721 if not config.ReadBool('Editor', 'EdgeShow', True) then
2722 drEdge[3] := 255
2723 else
2724 drEdge[3] := gAlphaEdge;
2725 gAlphaTriggerLine := config.ReadInt('Editor', 'LineAlpha', ALPHA_LINE);
2726 if gAlphaTriggerLine = 255 then
2727 gAlphaTriggerLine := ALPHA_LINE;
2728 gAlphaTriggerArea := config.ReadInt('Editor', 'TriggerAlpha', ALPHA_AREA);
2729 if gAlphaTriggerArea = 255 then
2730 gAlphaTriggerArea := ALPHA_AREA;
2731 gAlphaMonsterRect := config.ReadInt('Editor', 'MonsterRectAlpha', 0);
2732 gAlphaAreaRect := config.ReadInt('Editor', 'AreaRectAlpha', 0);
2733 if config.ReadInt('Editor', 'Scale', 0) = 1 then
2734 Scale := 2
2735 else
2736 Scale := 1;
2737 if config.ReadInt('Editor', 'DotSize', 0) = 1 then
2738 DotSize := 2
2739 else
2740 DotSize := 1;
2741 OpenDialog.InitialDir := config.ReadStr('Editor', 'LastOpenDir', EditorDir);
2742 SaveDialog.InitialDir := config.ReadStr('Editor', 'LastSaveDir', EditorDir);
2744 s := config.ReadStr('Editor', 'Language', '');
2745 gLanguage := s;
2747 RecentCount := config.ReadInt('Editor', 'RecentCount', 5);
2748 if RecentCount > 10 then
2749 RecentCount := 10;
2750 if RecentCount < 2 then
2751 RecentCount := 2;
2753 RecentFiles := TStringList.Create();
2754 for i := 0 to RecentCount-1 do
2755 begin
2756 s := config.ReadStr('RecentFiles', IntToStr(i+1), '');
2757 if s <> '' then
2758 RecentFiles.Add(s);
2759 end;
2760 RefreshRecentMenu();
2762 config.Free();
2764 tbShowMap.Down := ShowMap;
2765 tbGridOn.Down := DotEnable;
2766 pcObjects.ActivePageIndex := 0;
2767 Application.Title := _lc[I_EDITOR_TITLE];
2769 Application.OnIdle := OnIdle;
2770 end;
2772 procedure PrintBlack(X, Y: Integer; Text: string; FontID: DWORD);
2773 begin
2774 // NOTE: all the font printing routines assume CP1251
2775 e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0);
2776 end;
2778 procedure TMainForm.Draw();
2779 var
2780 x, y: Integer;
2781 a, b: Integer;
2782 ID, PID: DWORD;
2783 Width, Height: Word;
2784 Rect: TRectWH;
2785 ObjCount: Word;
2786 aX, aY, aX2, aY2, XX, ScaleSz: Integer;
2787 begin
2788 ID := 0;
2789 PID := 0;
2790 Width := 0;
2791 Height := 0;
2793 e_BeginRender();
2795 e_Clear(GL_COLOR_BUFFER_BIT,
2796 GetRValue(BackColor)/255,
2797 GetGValue(BackColor)/255,
2798 GetBValue(BackColor)/255);
2800 DrawMap();
2802 ObjCount := SelectedObjectCount();
2804 // Обводим выделенные объекты красной рамкой:
2805 if ObjCount > 0 then
2806 begin
2807 for a := 0 to High(SelectedObjects) do
2808 if SelectedObjects[a].Live then
2809 begin
2810 Rect := ObjectGetRect(SelectedObjects[a].ObjectType, SelectedObjects[a].ID);
2812 with Rect do
2813 begin
2814 e_DrawQuad(X+MapOffset.X, Y+MapOffset.Y,
2815 X+MapOffset.X+Width-1, Y+MapOffset.Y+Height-1,
2816 255, 0, 0);
2818 // Рисуем точки изменения размеров:
2819 if (ObjCount = 1) and
2820 (SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) then
2821 begin
2822 e_DrawPoint(5, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2823 e_DrawPoint(5, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2824 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 255, 255);
2825 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 255, 255);
2827 e_DrawPoint(3, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2828 e_DrawPoint(3, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2829 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 0, 0);
2830 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 0, 0);
2831 end;
2832 end;
2833 end;
2834 end;
2836 // Рисуем сетку:
2837 if DotEnable and (PreviewMode = 0) then
2838 begin
2839 if DotSize = 2 then
2840 a := -1
2841 else
2842 a := 0;
2844 for x := 0 to (RenderPanel.Width div DotStep) do
2845 for y := 0 to (RenderPanel.Height div DotStep) do
2846 e_DrawPoint(DotSize, x*DotStep + a, y*DotStep + a,
2847 GetRValue(DotColor),
2848 GetGValue(DotColor),
2849 GetBValue(DotColor));
2850 end;
2852 // Превью текстуры:
2853 if (lbTextureList.ItemIndex <> -1) and (cbPreview.Checked) and
2854 (not IsSpecialTextureSel()) and (PreviewMode = 0) then
2855 begin
2856 if not g_GetTexture(SelectedTexture(), ID) then
2857 g_GetTexture('NOTEXTURE', ID);
2858 g_GetTextureSizeByID(ID, Width, Height);
2859 if UseCheckerboard then
2860 begin
2861 if g_GetTexture('PREVIEW', PID) then
2862 e_DrawFill(PID, RenderPanel.Width-Width, RenderPanel.Height-Height, Width div 16 + 1, Height div 16 + 1, 0, True, False);
2863 end else
2864 e_DrawFillQuad(RenderPanel.Width-Width-2, RenderPanel.Height-Height-2,
2865 RenderPanel.Width-1, RenderPanel.Height-1,
2866 GetRValue(PreviewColor), GetGValue(PreviewColor), GetBValue(PreviewColor), 0);
2867 e_Draw(ID, RenderPanel.Width-Width, RenderPanel.Height-Height, 0, True, False);
2868 end;
2870 // Подсказка при выборе точки Телепорта:
2871 if SelectFlag = SELECTFLAG_TELEPORT then
2872 begin
2873 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
2874 if Data.d2d_teleport then
2875 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2876 MousePos.X+16, MousePos.Y-1,
2877 0, 0, 255)
2878 else
2879 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+AreaSize[AREA_DMPOINT].Width-1,
2880 MousePos.Y+AreaSize[AREA_DMPOINT].Height-1, 255, 255, 255);
2882 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2883 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2884 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_TELEPORT], gEditorFont);
2885 end;
2887 // Подсказка при выборе точки появления:
2888 if SelectFlag = SELECTFLAG_SPAWNPOINT then
2889 begin
2890 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2891 MousePos.X+16, MousePos.Y-1,
2892 0, 0, 255);
2893 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2894 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2895 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_SPAWN], gEditorFont);
2896 end;
2898 // Подсказка при выборе панели двери:
2899 if SelectFlag = SELECTFLAG_DOOR then
2900 begin
2901 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2902 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2903 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_DOOR], gEditorFont);
2904 end;
2906 // Подсказка при выборе панели с текстурой:
2907 if SelectFlag = SELECTFLAG_TEXTURE then
2908 begin
2909 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 192, 192, 192, 127);
2910 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 255, 255, 255);
2911 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_TEXTURE], gEditorFont);
2912 end;
2914 // Подсказка при выборе панели индикации выстрела:
2915 if SelectFlag = SELECTFLAG_SHOTPANEL then
2916 begin
2917 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 192, 192, 192, 127);
2918 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 255, 255, 255);
2919 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_SHOT], gEditorFont);
2920 end;
2922 // Подсказка при выборе панели лифта:
2923 if SelectFlag = SELECTFLAG_LIFT then
2924 begin
2925 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2926 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2927 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_LIFT], gEditorFont);
2928 end;
2930 // Подсказка при выборе монстра:
2931 if SelectFlag = SELECTFLAG_MONSTER then
2932 begin
2933 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 192, 192, 192, 127);
2934 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 255, 255, 255);
2935 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_MONSTER], gEditorFont);
2936 end;
2938 // Подсказка при выборе области воздействия:
2939 if DrawPressRect then
2940 begin
2941 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 192, 192, 192, 127);
2942 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 255, 255, 255);
2943 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_EXT_AREA], gEditorFont);
2944 end;
2946 // Рисуем текстуры, если чертим панель:
2947 if (MouseAction = MOUSEACTION_DRAWPANEL) and (DrawTexturePanel) and
2948 (lbTextureList.ItemIndex <> -1) and (DrawRect <> nil) and
2949 (lbPanelType.ItemIndex in [0..8]) and not IsSpecialTextureSel() then
2950 begin
2951 if not g_GetTexture(SelectedTexture(), ID) then
2952 g_GetTexture('NOTEXTURE', ID);
2953 g_GetTextureSizeByID(ID, Width, Height);
2954 with DrawRect^ do
2955 if (Abs(Right-Left) >= Width) and (Abs(Bottom-Top) >= Height) then
2956 e_DrawFill(ID, Min(Left, Right), Min(Top, Bottom), Abs(Right-Left) div Width,
2957 Abs(Bottom-Top) div Height, 64, True, False);
2958 end;
2960 // Прямоугольник выделения:
2961 if DrawRect <> nil then
2962 with DrawRect^ do
2963 e_DrawQuad(Left, Top, Right-1, Bottom-1, 255, 255, 255);
2965 // Чертим мышью панель/триггер или меняем мышью их размер:
2966 if (((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
2967 not(ssCtrl in GetKeyShiftState())) or (MouseAction = MOUSEACTION_RESIZE)) and
2968 (DrawPanelSize) then
2969 begin
2970 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 192, 192, 192, 127);
2971 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 255, 255, 255);
2973 if MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER] then
2974 begin // Чертим новый
2975 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH],
2976 [Abs(MousePos.X-MouseLDownPos.X)]), gEditorFont);
2977 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(_glc[I_HINT_HEIGHT],
2978 [Abs(MousePos.Y-MouseLDownPos.Y)]), gEditorFont);
2979 end
2980 else // Растягиваем существующий
2981 if SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
2982 begin
2983 if SelectedObjects[GetFirstSelected].ObjectType = OBJECT_PANEL then
2984 begin
2985 Width := gPanels[SelectedObjects[GetFirstSelected].ID].Width;
2986 Height := gPanels[SelectedObjects[GetFirstSelected].ID].Height;
2987 end
2988 else
2989 begin
2990 Width := gTriggers[SelectedObjects[GetFirstSelected].ID].Width;
2991 Height := gTriggers[SelectedObjects[GetFirstSelected].ID].Height;
2992 end;
2994 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH], [Width]),
2995 gEditorFont);
2996 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(_glc[I_HINT_HEIGHT], [Height]),
2997 gEditorFont);
2998 end;
2999 end;
3001 // Ближайшая к курсору мыши точка на сетке:
3002 e_DrawPoint(3, MousePos.X, MousePos.Y, 0, 0, 255);
3004 // Мини-карта:
3005 if ShowMap then
3006 begin
3007 // Сколько пикселов карты в 1 пикселе мини-карты:
3008 ScaleSz := 16 div Scale;
3009 // Размеры мини-карты:
3010 aX := max(gMapInfo.Width div ScaleSz, 1);
3011 aY := max(gMapInfo.Height div ScaleSz, 1);
3012 // X-координата на RenderPanel нулевой x-координаты карты:
3013 XX := RenderPanel.Width - aX - 1;
3014 // Рамка карты:
3015 e_DrawFillQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 0, 0, 0, 0);
3016 e_DrawQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 197, 197, 197);
3018 if gPanels <> nil then
3019 begin
3020 // Рисуем панели:
3021 for a := 0 to High(gPanels) do
3022 with gPanels[a] do
3023 if PanelType <> 0 then
3024 begin
3025 // Левый верхний угол:
3026 aX := XX + (X div ScaleSz);
3027 aY := 1 + (Y div ScaleSz);
3028 // Размеры:
3029 aX2 := max(Width div ScaleSz, 1);
3030 aY2 := max(Height div ScaleSz, 1);
3031 // Правый нижний угол:
3032 aX2 := aX + aX2 - 1;
3033 aY2 := aY + aY2 - 1;
3035 case PanelType of
3036 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3037 PANEL_WATER: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3038 PANEL_ACID1: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3039 PANEL_ACID2: e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3040 PANEL_STEP: e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3041 PANEL_LIFTUP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3042 PANEL_LIFTDOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3043 PANEL_LIFTLEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3044 PANEL_LIFTRIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3045 PANEL_OPENDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 100, 220, 92, 0);
3046 PANEL_CLOSEDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 212, 184, 64, 0);
3047 PANEL_BLOCKMON: e_DrawFillQuad(aX, aY, aX2, aY2, 192, 0, 192, 0);
3048 end;
3049 end;
3051 // Рисуем красным выделенные панели:
3052 if SelectedObjects <> nil then
3053 for b := 0 to High(SelectedObjects) do
3054 with SelectedObjects[b] do
3055 if Live and (ObjectType = OBJECT_PANEL) then
3056 with gPanels[SelectedObjects[b].ID] do
3057 if PanelType and not(PANEL_BACK or PANEL_FORE) <> 0 then
3058 begin
3059 // Левый верхний угол:
3060 aX := XX + (X div ScaleSz);
3061 aY := 1 + (Y div ScaleSz);
3062 // Размеры:
3063 aX2 := max(Width div ScaleSz, 1);
3064 aY2 := max(Height div ScaleSz, 1);
3065 // Правый нижний угол:
3066 aX2 := aX + aX2 - 1;
3067 aY2 := aY + aY2 - 1;
3069 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0)
3070 end;
3071 end;
3073 if (gMapInfo.Width > RenderPanel.Width) or
3074 (gMapInfo.Height > RenderPanel.Height) then
3075 begin
3076 // Окно, показывающее текущее положение экрана на карте:
3077 // Размеры окна:
3078 x := max(min(RenderPanel.Width, gMapInfo.Width) div ScaleSz, 1);
3079 y := max(min(RenderPanel.Height, gMapInfo.Height) div ScaleSz, 1);
3080 // Левый верхний угол:
3081 aX := XX + ((-MapOffset.X) div ScaleSz);
3082 aY := 1 + ((-MapOffset.Y) div ScaleSz);
3083 // Правый нижний угол:
3084 aX2 := aX + x - 1;
3085 aY2 := aY + y - 1;
3087 e_DrawFillQuad(aX, aY, aX2, aY2, 127, 192, 127, 127, B_BLEND);
3088 e_DrawQuad(aX, aY, aX2, aY2, 255, 0, 0);
3089 end;
3090 end; // Мини-карта
3092 e_EndRender();
3093 RenderPanel.SwapBuffers();
3094 end;
3096 procedure TMainForm.FormResize(Sender: TObject);
3097 begin
3098 e_SetViewPort(0, 0, RenderPanel.Width, RenderPanel.Height);
3100 if gMapInfo.Width >= RenderPanel.Width then
3101 sbHorizontal.Max := Normalize16(gMapInfo.Width-RenderPanel.Width+16)
3102 else
3103 sbHorizontal.Max := 0;
3105 if gMapInfo.Height >= RenderPanel.Height then
3106 sbVertical.Max := Normalize16(gMapInfo.Height-RenderPanel.Height+16)
3107 else
3108 sbVertical.Max := 0;
3110 MapOffset.X := -Normalize16(sbHorizontal.Position);
3111 MapOffset.Y := -Normalize16(sbVertical.Position);
3112 end;
3114 procedure SelectNextObject(X, Y: Integer; ObjectType: Byte; ID: DWORD);
3115 var
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);
3236 var
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,
3256 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;
3262 end
3263 else // Ставим предмет/монстра/область:
3264 if (pcObjects.ActivePageIndex in [1, 2, 3]) and
3265 (not (ssShift in Shift)) then
3266 begin
3267 case pcObjects.ActivePageIndex of
3268 1:
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;
3289 2:
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;
3310 3:
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;
3333 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);
3347 end
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
3361 end
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,
3377 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;
3382 end
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;
3403 end
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;
3408 end
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;
3431 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;
3458 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;
3482 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;
3526 end
3527 else
3528 gTriggers[SelectedObjects[
3529 GetFirstSelected() ].ID].Data.ShotPanelID := -1;
3530 end;
3531 end;
3532 end;
3534 SelectFlag := SELECTFLAG_SELECTED;
3535 end
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;
3573 end
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 MouseRDown := Button = mbRight;
3603 if MouseRDown then
3604 MouseRDownPos := MousePos;
3606 MouseLDown := Button = mbLeft;
3607 if MouseLDown then
3608 MouseLDownPos := MousePos;
3609 end;
3611 procedure TMainForm.RenderPanelMouseUp(Sender: TObject;
3612 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3613 var
3614 panel: TPanel;
3615 trigger: TTrigger;
3616 rRect: TRectWH;
3617 rSelectRect: Boolean;
3618 wWidth, wHeight: Word;
3619 TextureID: DWORD;
3621 procedure SelectObjects(ObjectType: Byte);
3622 var
3623 i: Integer;
3624 IDArray: DWArray;
3625 begin
3626 IDArray := ObjectInRect(rRect.X, rRect.Y,
3627 rRect.Width, rRect.Height,
3628 ObjectType, rSelectRect);
3630 if IDArray <> nil then
3631 for i := 0 to High(IDArray) do
3632 SelectObject(ObjectType, IDArray[i], (ssCtrl in Shift) or rSelectRect);
3633 end;
3634 begin
3635 if Button = mbLeft then
3636 MouseLDown := False;
3637 if Button = mbRight then
3638 MouseRDown := False;
3640 DrawRect := nil;
3641 ResizeType := RESIZETYPE_NONE;
3642 TextureID := 0;
3644 if Button = mbLeft then // Left Mouse Button
3645 begin
3646 if MouseAction <> MOUSEACTION_NONE then
3647 begin // Было действие мышью
3648 // Мышь сдвинулась во время удержания клавиши,
3649 // либо активирован режим быстрого рисования:
3650 if ((MousePos.X <> MouseLDownPos.X) and
3651 (MousePos.Y <> MouseLDownPos.Y)) or
3652 ((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
3653 (ssCtrl in Shift)) then
3654 case MouseAction of
3655 // Рисовали панель:
3656 MOUSEACTION_DRAWPANEL:
3657 begin
3658 // Фон или передний план без текстуры - ошибка:
3659 if (lbPanelType.ItemIndex in [1, 2]) and
3660 (lbTextureList.ItemIndex = -1) then
3661 ErrorMessageBox(_lc[I_MSG_CHOOSE_TEXTURE])
3662 else // Назначаем параметры панели:
3663 begin
3664 case lbPanelType.ItemIndex of
3665 0: Panel.PanelType := PANEL_WALL;
3666 1: Panel.PanelType := PANEL_BACK;
3667 2: Panel.PanelType := PANEL_FORE;
3668 3: Panel.PanelType := PANEL_OPENDOOR;
3669 4: Panel.PanelType := PANEL_CLOSEDOOR;
3670 5: Panel.PanelType := PANEL_STEP;
3671 6: Panel.PanelType := PANEL_WATER;
3672 7: Panel.PanelType := PANEL_ACID1;
3673 8: Panel.PanelType := PANEL_ACID2;
3674 9: Panel.PanelType := PANEL_LIFTUP;
3675 10: Panel.PanelType := PANEL_LIFTDOWN;
3676 11: Panel.PanelType := PANEL_LIFTLEFT;
3677 12: Panel.PanelType := PANEL_LIFTRIGHT;
3678 13: Panel.PanelType := PANEL_BLOCKMON;
3679 end;
3681 Panel.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3682 Panel.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3683 if ssCtrl in Shift then
3684 begin
3685 wWidth := DotStep;
3686 wHeight := DotStep;
3687 if (lbTextureList.ItemIndex <> -1) and
3688 (not IsSpecialTextureSel()) then
3689 begin
3690 if not g_GetTexture(SelectedTexture(), TextureID) then
3691 g_GetTexture('NOTEXTURE', TextureID);
3692 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
3693 end;
3694 Panel.Width := wWidth;
3695 Panel.Height := wHeight;
3696 end
3697 else
3698 begin
3699 Panel.Width := Abs(MousePos.X-MouseLDownPos.X);
3700 Panel.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3701 end;
3703 // Лифты, блокМон или отсутствие текстуры - пустая текстура:
3704 if (lbPanelType.ItemIndex in [9, 10, 11, 12, 13]) or
3705 (lbTextureList.ItemIndex = -1) then
3706 begin
3707 Panel.TextureHeight := 1;
3708 Panel.TextureWidth := 1;
3709 Panel.TextureName := '';
3710 Panel.TextureID := TEXTURE_SPECIAL_NONE;
3711 end
3712 else // Есть текстура:
3713 begin
3714 Panel.TextureName := SelectedTexture();
3716 // Обычная текстура:
3717 if not IsSpecialTextureSel() then
3718 begin
3719 g_GetTextureSizeByName(Panel.TextureName,
3720 Panel.TextureWidth, Panel.TextureHeight);
3721 g_GetTexture(Panel.TextureName, Panel.TextureID);
3722 end
3723 else // Спец.текстура:
3724 begin
3725 Panel.TextureHeight := 1;
3726 Panel.TextureWidth := 1;
3727 Panel.TextureID := SpecialTextureID(SelectedTexture());
3728 end;
3729 end;
3731 Panel.Alpha := 0;
3732 Panel.Blending := False;
3734 Undo_Add(OBJECT_PANEL, AddPanel(Panel));
3735 end;
3736 end;
3738 // Рисовали триггер:
3739 MOUSEACTION_DRAWTRIGGER:
3740 begin
3741 trigger.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3742 trigger.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3743 if ssCtrl in Shift then
3744 begin
3745 wWidth := DotStep;
3746 wHeight := DotStep;
3747 trigger.Width := wWidth;
3748 trigger.Height := wHeight;
3749 end
3750 else
3751 begin
3752 trigger.Width := Abs(MousePos.X-MouseLDownPos.X);
3753 trigger.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3754 end;
3756 trigger.Enabled := True;
3757 trigger.TriggerType := lbTriggersList.ItemIndex+1;
3758 trigger.TexturePanel := -1;
3760 // Типы активации:
3761 trigger.ActivateType := 0;
3763 if clbActivationType.Checked[0] then
3764 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERCOLLIDE;
3765 if clbActivationType.Checked[1] then
3766 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERCOLLIDE;
3767 if clbActivationType.Checked[2] then
3768 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERPRESS;
3769 if clbActivationType.Checked[3] then
3770 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERPRESS;
3771 if clbActivationType.Checked[4] then
3772 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_SHOT;
3773 if clbActivationType.Checked[5] then
3774 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_NOMONSTER;
3776 // Необходимые для активации ключи:
3777 trigger.Key := 0;
3779 if clbKeys.Checked[0] then
3780 trigger.Key := Trigger.Key or KEY_RED;
3781 if clbKeys.Checked[1] then
3782 trigger.Key := Trigger.Key or KEY_GREEN;
3783 if clbKeys.Checked[2] then
3784 trigger.Key := Trigger.Key or KEY_BLUE;
3785 if clbKeys.Checked[3] then
3786 trigger.Key := Trigger.Key or KEY_REDTEAM;
3787 if clbKeys.Checked[4] then
3788 trigger.Key := Trigger.Key or KEY_BLUETEAM;
3790 // Параметры триггера:
3791 FillByte(trigger.Data.Default[0], 128, 0);
3793 case trigger.TriggerType of
3794 // Переключаемая панель:
3795 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
3796 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
3797 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
3798 begin
3799 Trigger.Data.PanelID := -1;
3800 end;
3802 // Телепортация:
3803 TRIGGER_TELEPORT:
3804 begin
3805 trigger.Data.TargetPoint.X := trigger.X-64;
3806 trigger.Data.TargetPoint.Y := trigger.Y-64;
3807 trigger.Data.d2d_teleport := True;
3808 trigger.Data.TlpDir := 0;
3809 end;
3811 // Изменение других триггеров:
3812 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
3813 TRIGGER_ONOFF:
3814 begin
3815 trigger.Data.Count := 1;
3816 end;
3818 // Звук:
3819 TRIGGER_SOUND:
3820 begin
3821 trigger.Data.Volume := 255;
3822 trigger.Data.Pan := 127;
3823 trigger.Data.PlayCount := 1;
3824 trigger.Data.Local := True;
3825 trigger.Data.SoundSwitch := False;
3826 end;
3828 // Музыка:
3829 TRIGGER_MUSIC:
3830 begin
3831 trigger.Data.MusicAction := 1;
3832 end;
3834 // Создание монстра:
3835 TRIGGER_SPAWNMONSTER:
3836 begin
3837 trigger.Data.MonType := MONSTER_ZOMBY;
3838 trigger.Data.MonPos.X := trigger.X-64;
3839 trigger.Data.MonPos.Y := trigger.Y-64;
3840 trigger.Data.MonHealth := 0;
3841 trigger.Data.MonActive := False;
3842 trigger.Data.MonCount := 1;
3843 end;
3845 // Создание предмета:
3846 TRIGGER_SPAWNITEM:
3847 begin
3848 trigger.Data.ItemType := ITEM_AMMO_BULLETS;
3849 trigger.Data.ItemPos.X := trigger.X-64;
3850 trigger.Data.ItemPos.Y := trigger.Y-64;
3851 trigger.Data.ItemOnlyDM := False;
3852 trigger.Data.ItemFalls := False;
3853 trigger.Data.ItemCount := 1;
3854 trigger.Data.ItemMax := 0;
3855 trigger.Data.ItemDelay := 0;
3856 end;
3858 // Ускорение:
3859 TRIGGER_PUSH:
3860 begin
3861 trigger.Data.PushAngle := 90;
3862 trigger.Data.PushForce := 10;
3863 trigger.Data.ResetVel := True;
3864 end;
3866 TRIGGER_SCORE:
3867 begin
3868 trigger.Data.ScoreCount := 1;
3869 trigger.Data.ScoreCon := True;
3870 trigger.Data.ScoreMsg := True;
3871 end;
3873 TRIGGER_MESSAGE:
3874 begin
3875 trigger.Data.MessageKind := 0;
3876 trigger.Data.MessageSendTo := 0;
3877 trigger.Data.MessageText := '';
3878 trigger.Data.MessageTime := 144;
3879 end;
3881 TRIGGER_DAMAGE:
3882 begin
3883 trigger.Data.DamageValue := 5;
3884 trigger.Data.DamageInterval := 12;
3885 end;
3887 TRIGGER_HEALTH:
3888 begin
3889 trigger.Data.HealValue := 5;
3890 trigger.Data.HealInterval := 36;
3891 end;
3893 TRIGGER_SHOT:
3894 begin
3895 trigger.Data.ShotType := TRIGGER_SHOT_BULLET;
3896 trigger.Data.ShotSound := True;
3897 trigger.Data.ShotPanelID := -1;
3898 trigger.Data.ShotTarget := 0;
3899 trigger.Data.ShotIntSight := 0;
3900 trigger.Data.ShotAim := TRIGGER_SHOT_AIM_DEFAULT;
3901 trigger.Data.ShotPos.X := trigger.X-64;
3902 trigger.Data.ShotPos.Y := trigger.Y-64;
3903 trigger.Data.ShotAngle := 0;
3904 trigger.Data.ShotWait := 18;
3905 trigger.Data.ShotAccuracy := 0;
3906 trigger.Data.ShotAmmo := 0;
3907 trigger.Data.ShotIntReload := 0;
3908 end;
3910 TRIGGER_EFFECT:
3911 begin
3912 trigger.Data.FXCount := 1;
3913 trigger.Data.FXType := TRIGGER_EFFECT_PARTICLE;
3914 trigger.Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
3915 trigger.Data.FXColorR := 0;
3916 trigger.Data.FXColorG := 0;
3917 trigger.Data.FXColorB := 255;
3918 trigger.Data.FXPos := TRIGGER_EFFECT_POS_CENTER;
3919 trigger.Data.FXWait := 1;
3920 trigger.Data.FXVelX := 0;
3921 trigger.Data.FXVelY := -20;
3922 trigger.Data.FXSpreadL := 5;
3923 trigger.Data.FXSpreadR := 5;
3924 trigger.Data.FXSpreadU := 4;
3925 trigger.Data.FXSpreadD := 0;
3926 end;
3927 end;
3929 Undo_Add(OBJECT_TRIGGER, AddTrigger(trigger));
3930 end;
3932 // Рисовали область триггера "Расширитель":
3933 MOUSEACTION_DRAWPRESS:
3934 with gTriggers[SelectedObjects[GetFirstSelected].ID] do
3935 begin
3936 Data.tX := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3937 Data.tY := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3938 Data.tWidth := Abs(MousePos.X-MouseLDownPos.X);
3939 Data.tHeight := Abs(MousePos.Y-MouseLDownPos.Y);
3941 DrawPressRect := False;
3942 end;
3943 end;
3945 MouseAction := MOUSEACTION_NONE;
3946 end;
3947 end // if Button = mbLeft...
3948 else // Right Mouse Button:
3949 begin
3950 if MouseAction = MOUSEACTION_NOACTION then
3951 begin
3952 MouseAction := MOUSEACTION_NONE;
3953 Exit;
3954 end;
3956 // Объект передвинут или изменен в размере:
3957 if MouseAction in [MOUSEACTION_MOVEOBJ, MOUSEACTION_RESIZE] then
3958 begin
3959 MouseAction := MOUSEACTION_NONE;
3960 FillProperty();
3961 Exit;
3962 end;
3964 // Еще не все выбрали:
3965 if SelectFlag <> SELECTFLAG_NONE then
3966 begin
3967 if SelectFlag = SELECTFLAG_SELECTED then
3968 SelectFlag := SELECTFLAG_NONE;
3969 FillProperty();
3970 Exit;
3971 end;
3973 // Мышь сдвинулась во время удержания клавиши:
3974 if (MousePos.X <> MouseRDownPos.X) and
3975 (MousePos.Y <> MouseRDownPos.Y) then
3976 begin
3977 rSelectRect := True;
3979 rRect.X := Min(MousePos.X, MouseRDownPos.X)-MapOffset.X;
3980 rRect.Y := Min(MousePos.Y, MouseRDownPos.Y)-MapOffset.Y;
3981 rRect.Width := Abs(MousePos.X-MouseRDownPos.X);
3982 rRect.Height := Abs(MousePos.Y-MouseRDownPos.Y);
3983 end
3984 else // Мышь не сдвинулась - нет прямоугольника:
3985 begin
3986 rSelectRect := False;
3988 rRect.X := X-MapOffset.X-1;
3989 rRect.Y := Y-MapOffset.Y-1;
3990 rRect.Width := 2;
3991 rRect.Height := 2;
3992 end;
3994 // Если зажат Ctrl - выделять еще, иначе только один выделенный объект:
3995 if not (ssCtrl in Shift) then
3996 RemoveSelectFromObjects();
3998 // Выделяем всё в выбранном прямоугольнике:
3999 if (ssCtrl in Shift) and (ssAlt in Shift) then
4000 begin
4001 SelectObjects(OBJECT_PANEL);
4002 SelectObjects(OBJECT_ITEM);
4003 SelectObjects(OBJECT_MONSTER);
4004 SelectObjects(OBJECT_AREA);
4005 SelectObjects(OBJECT_TRIGGER);
4006 end
4007 else
4008 SelectObjects(pcObjects.ActivePageIndex+1);
4010 FillProperty();
4011 end;
4012 end;
4014 procedure TMainForm.RenderPanelPaint(Sender: TObject);
4015 begin
4016 Draw();
4017 end;
4019 function TMainForm.RenderMousePos(): Types.TPoint;
4020 begin
4021 Result := RenderPanel.ScreenToClient(Mouse.CursorPos);
4022 end;
4024 procedure TMainForm.RecountSelectedObjects();
4025 begin
4026 if SelectedObjectCount() = 0 then
4027 StatusBar.Panels[0].Text := ''
4028 else
4029 StatusBar.Panels[0].Text := Format(_lc[I_CAP_STAT_SELECTED], [SelectedObjectCount()]);
4030 end;
4032 procedure TMainForm.RenderPanelMouseMove(Sender: TObject;
4033 Shift: TShiftState; X, Y: Integer);
4034 var
4035 sX, sY: Integer;
4036 dWidth, dHeight: Integer;
4037 _id: Integer;
4038 TextureID: DWORD;
4039 wWidth, wHeight: Word;
4040 begin
4041 _id := GetFirstSelected();
4042 TextureID := 0;
4044 // Рисуем панель с текстурой, сетка - размеры текстуры:
4045 if (MouseAction = MOUSEACTION_DRAWPANEL) and
4046 (lbPanelType.ItemIndex in [0..8]) and
4047 (lbTextureList.ItemIndex <> -1) and
4048 (not IsSpecialTextureSel()) then
4049 begin
4050 sX := StrToIntDef(lTextureWidth.Caption, DotStep);
4051 sY := StrToIntDef(lTextureHeight.Caption, DotStep);
4052 end
4053 else
4054 // Меняем размер панели с текстурой, сетка - размеры текстуры:
4055 if (MouseAction = MOUSEACTION_RESIZE) and
4056 ( (SelectedObjects[_id].ObjectType = OBJECT_PANEL) and
4057 IsTexturedPanel(gPanels[SelectedObjects[_id].ID].PanelType) and
4058 (gPanels[SelectedObjects[_id].ID].TextureName <> '') and
4059 (not IsSpecialTexture(gPanels[SelectedObjects[_id].ID].TextureName)) ) then
4060 begin
4061 sX := gPanels[SelectedObjects[_id].ID].TextureWidth;
4062 sY := gPanels[SelectedObjects[_id].ID].TextureHeight;
4063 end
4064 else
4065 // Выравнивание по сетке:
4066 if SnapToGrid then
4067 begin
4068 sX := DotStep;
4069 sY := DotStep;
4070 end
4071 else // Нет выравнивания по сетке:
4072 begin
4073 sX := 1;
4074 sY := 1;
4075 end;
4077 // Новая позиция мыши:
4078 if MouseLDown then
4079 begin // Зажата левая кнопка мыши
4080 MousePos.X := (Round((X-MouseLDownPos.X)/sX)*sX)+MouseLDownPos.X;
4081 MousePos.Y := (Round((Y-MouseLDownPos.Y)/sY)*sY)+MouseLDownPos.Y;
4082 end
4083 else
4084 if MouseRDown then
4085 begin // Зажата правая кнопка мыши
4086 MousePos.X := (Round((X-MouseRDownPos.X)/sX)*sX)+MouseRDownPos.X;
4087 MousePos.Y := (Round((Y-MouseRDownPos.Y)/sY)*sY)+MouseRDownPos.Y;
4088 end
4089 else
4090 begin // Кнопки мыши не зажаты
4091 MousePos.X := (Round(X/sX)*sX);
4092 MousePos.Y := (Round(Y/sY)*sY);
4093 end;
4095 // Изменение размера закончилось - ставим обычный курсор:
4096 if ResizeType = RESIZETYPE_NONE then
4097 RenderPanel.Cursor := crDefault;
4099 // Зажата только правая кнопка мыши:
4100 if (not MouseLDown) and (MouseRDown) then
4101 begin
4102 // Рисуем прямоугольник выделения:
4103 if MouseAction = MOUSEACTION_NONE then
4104 begin
4105 if DrawRect = nil then
4106 New(DrawRect);
4107 DrawRect.Top := MouseRDownPos.y;
4108 DrawRect.Left := MouseRDownPos.x;
4109 DrawRect.Bottom := MousePos.y;
4110 DrawRect.Right := MousePos.x;
4111 end
4112 else
4113 // Двигаем выделенные объекты:
4114 if MouseAction = MOUSEACTION_MOVEOBJ then
4115 begin
4116 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
4117 MousePos.X-LastMovePoint.X+WASDOffset.X,
4118 MousePos.Y-LastMovePoint.Y+WASDOffset.Y);
4119 WASDOffset.X := 0;
4120 WASDOffset.Y := 0;
4121 end
4122 else
4123 // Меняем размер выделенного объекта:
4124 if MouseAction = MOUSEACTION_RESIZE then
4125 begin
4126 if (SelectedObjectCount = 1) and
4127 (SelectedObjects[GetFirstSelected].Live) then
4128 begin
4129 dWidth := MousePos.X-LastMovePoint.X+WASDOffset.X;
4130 dHeight := MousePos.Y-LastMovePoint.Y+WASDOffset.Y;
4131 WASDOffset.X := 0;
4132 WASDOffset.Y := 0;
4134 case ResizeType of
4135 RESIZETYPE_VERTICAL: dWidth := 0;
4136 RESIZETYPE_HORIZONTAL: dHeight := 0;
4137 end;
4139 case ResizeDirection of
4140 RESIZEDIR_UP: dHeight := -dHeight;
4141 RESIZEDIR_LEFT: dWidth := -dWidth;
4142 end;
4144 ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
4145 SelectedObjects[GetFirstSelected].ID,
4146 dWidth, dHeight, ResizeDirection);
4148 LastMovePoint := MousePos;
4149 end;
4150 end;
4151 end;
4153 // Зажата только левая кнопка мыши:
4154 if (not MouseRDown) and (MouseLDown) then
4155 begin
4156 // Рисуем прямоугольник планирования панели:
4157 if MouseAction in [MOUSEACTION_DRAWPANEL,
4158 MOUSEACTION_DRAWTRIGGER,
4159 MOUSEACTION_DRAWPRESS] then
4160 begin
4161 if DrawRect = nil then
4162 New(DrawRect);
4163 if ssCtrl in Shift then
4164 begin
4165 wWidth := DotStep;
4166 wHeight := DotStep;
4167 if (lbTextureList.ItemIndex <> -1) and (not IsSpecialTextureSel()) and
4168 (MouseAction = MOUSEACTION_DRAWPANEL) then
4169 begin
4170 if not g_GetTexture(SelectedTexture(), TextureID) then
4171 g_GetTexture('NOTEXTURE', TextureID);
4172 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
4173 end;
4174 DrawRect.Top := MouseLDownPos.y;
4175 DrawRect.Left := MouseLDownPos.x;
4176 DrawRect.Bottom := DrawRect.Top + wHeight;
4177 DrawRect.Right := DrawRect.Left + wWidth;
4178 end
4179 else
4180 begin
4181 DrawRect.Top := MouseLDownPos.y;
4182 DrawRect.Left := MouseLDownPos.x;
4183 DrawRect.Bottom := MousePos.y;
4184 DrawRect.Right := MousePos.x;
4185 end;
4186 end
4187 else // Двигаем карту:
4188 if MouseAction = MOUSEACTION_MOVEMAP then
4189 begin
4190 MoveMap(X, Y);
4191 end;
4192 end;
4194 // Клавиши мыши не зажаты:
4195 if (not MouseRDown) and (not MouseLDown) then
4196 DrawRect := nil;
4198 // Строка состояния - координаты мыши:
4199 StatusBar.Panels[1].Text := Format('(%d:%d)',
4200 [MousePos.X-MapOffset.X, MousePos.Y-MapOffset.Y]);
4201 end;
4203 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
4204 begin
4205 CanClose := MessageBox(0, PChar(_lc[I_MSG_EXIT_PROMT]),
4206 PChar(_lc[I_MSG_EXIT]),
4207 MB_ICONQUESTION or MB_YESNO or
4208 MB_DEFBUTTON1) = idYes;
4209 end;
4211 procedure TMainForm.aExitExecute(Sender: TObject);
4212 begin
4213 Close();
4214 end;
4216 procedure TMainForm.FormDestroy(Sender: TObject);
4217 var
4218 config: TConfig;
4219 i: Integer;
4220 begin
4221 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
4223 if WindowState <> wsMaximized then
4224 begin
4225 config.WriteInt('Editor', 'XPos', Left);
4226 config.WriteInt('Editor', 'YPos', Top);
4227 config.WriteInt('Editor', 'Width', Width);
4228 config.WriteInt('Editor', 'Height', Height);
4229 end
4230 else
4231 begin
4232 config.WriteInt('Editor', 'XPos', RestoredLeft);
4233 config.WriteInt('Editor', 'YPos', RestoredTop);
4234 config.WriteInt('Editor', 'Width', RestoredWidth);
4235 config.WriteInt('Editor', 'Height', RestoredHeight);
4236 end;
4237 config.WriteBool('Editor', 'Maximize', WindowState = wsMaximized);
4238 config.WriteBool('Editor', 'Minimap', ShowMap);
4239 config.WriteInt('Editor', 'PanelProps', PanelProps.ClientWidth);
4240 config.WriteInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
4241 config.WriteBool('Editor', 'DotEnable', DotEnable);
4242 config.WriteInt('Editor', 'DotStep', DotStep);
4243 config.WriteStr('Editor', 'LastOpenDir', OpenDialog.InitialDir);
4244 config.WriteStr('Editor', 'LastSaveDir', SaveDialog.InitialDir);
4245 config.WriteBool('Editor', 'EdgeShow', drEdge[3] < 255);
4246 config.WriteInt('Editor', 'EdgeColor', gColorEdge);
4247 config.WriteInt('Editor', 'EdgeAlpha', gAlphaEdge);
4248 config.WriteInt('Editor', 'LineAlpha', gAlphaTriggerLine);
4249 config.WriteInt('Editor', 'TriggerAlpha', gAlphaTriggerArea);
4250 config.WriteInt('Editor', 'MonsterRectAlpha', gAlphaMonsterRect);
4251 config.WriteInt('Editor', 'AreaRectAlpha', gAlphaAreaRect);
4253 for i := 0 to RecentCount-1 do
4254 if i < RecentFiles.Count then
4255 config.WriteStr('RecentFiles', IntToStr(i+1), RecentFiles[i])
4256 else
4257 config.WriteStr('RecentFiles', IntToStr(i+1), '');
4258 RecentFiles.Free();
4260 config.SaveFile(EditorDir+'Editor.cfg');
4261 config.Free();
4263 slInvalidTextures.Free;
4264 end;
4266 procedure TMainForm.FormDropFiles(Sender: TObject;
4267 const FileNames: array of String);
4268 begin
4269 if Length(FileNames) <> 1 then
4270 Exit;
4272 OpenMapFile(FileNames[0]);
4273 end;
4275 procedure TMainForm.RenderPanelResize(Sender: TObject);
4276 begin
4277 if MainForm.Visible then
4278 MainForm.Resize();
4279 end;
4281 procedure TMainForm.Splitter1Moved(Sender: TObject);
4282 begin
4283 FormResize(Sender);
4284 end;
4286 procedure TMainForm.aMapOptionsExecute(Sender: TObject);
4287 var
4288 ResName: String;
4289 begin
4290 MapOptionsForm.ShowModal();
4292 ResName := OpenedMap;
4293 while (Pos(':\', ResName) > 0) do
4294 Delete(ResName, 1, Pos(':\', ResName) + 1);
4296 UpdateCaption(gMapInfo.Name, ExtractFileName(OpenedWAD), ResName);
4297 end;
4299 procedure TMainForm.aAboutExecute(Sender: TObject);
4300 begin
4301 AboutForm.ShowModal();
4302 end;
4304 procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
4305 Shift: TShiftState);
4306 var
4307 dx, dy, i: Integer;
4308 FileName: String;
4309 begin
4310 if (not EditingProperties) then
4311 begin
4312 if Key = Ord('1') then
4313 SwitchLayer(LAYER_BACK);
4314 if Key = Ord('2') then
4315 SwitchLayer(LAYER_WALLS);
4316 if Key = Ord('3') then
4317 SwitchLayer(LAYER_FOREGROUND);
4318 if Key = Ord('4') then
4319 SwitchLayer(LAYER_STEPS);
4320 if Key = Ord('5') then
4321 SwitchLayer(LAYER_WATER);
4322 if Key = Ord('6') then
4323 SwitchLayer(LAYER_ITEMS);
4324 if Key = Ord('7') then
4325 SwitchLayer(LAYER_MONSTERS);
4326 if Key = Ord('8') then
4327 SwitchLayer(LAYER_AREAS);
4328 if Key = Ord('9') then
4329 SwitchLayer(LAYER_TRIGGERS);
4330 if Key = Ord('0') then
4331 tbShowClick(tbShow);
4333 if Key = Ord('V') then
4334 begin // Поворот монстров и областей:
4335 if (SelectedObjects <> nil) then
4336 begin
4337 for i := 0 to High(SelectedObjects) do
4338 if (SelectedObjects[i].Live) then
4339 begin
4340 if (SelectedObjects[i].ObjectType = OBJECT_MONSTER) then
4341 begin
4342 g_ChangeDir(gMonsters[SelectedObjects[i].ID].Direction);
4343 end
4344 else
4345 if (SelectedObjects[i].ObjectType = OBJECT_AREA) then
4346 begin
4347 g_ChangeDir(gAreas[SelectedObjects[i].ID].Direction);
4348 end;
4349 end;
4350 end
4351 else
4352 begin
4353 if pcObjects.ActivePage = tsMonsters then
4354 begin
4355 if rbMonsterLeft.Checked then
4356 rbMonsterRight.Checked := True
4357 else
4358 rbMonsterLeft.Checked := True;
4359 end;
4360 if pcObjects.ActivePage = tsAreas then
4361 begin
4362 if rbAreaLeft.Checked then
4363 rbAreaRight.Checked := True
4364 else
4365 rbAreaLeft.Checked := True;
4366 end;
4367 end;
4368 end;
4370 if not (ssCtrl in Shift) then
4371 begin
4372 // Быстрое превью карты:
4373 if Key = Ord('E') then
4374 begin
4375 if PreviewMode = 0 then
4376 PreviewMode := 2;
4377 end;
4379 // Вертикальный скролл карты:
4380 with sbVertical do
4381 begin
4382 if Key = Ord('W') then
4383 begin
4384 if (MouseLDown or MouseRDown) and (Position >= DotStep) then
4385 begin
4386 Dec(WASDOffset.Y, DotStep);
4387 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4388 end;
4389 Position := IfThen(Position > DotStep, Position-DotStep, 0);
4390 MapOffset.Y := -Round(Position/16) * 16;
4391 end;
4393 if Key = Ord('S') then
4394 begin
4395 if (MouseLDown or MouseRDown) and (Position+DotStep <= Max) then
4396 begin
4397 Inc(WASDOffset.Y, DotStep);
4398 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4399 end;
4400 Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
4401 MapOffset.Y := -Round(Position/16) * 16;
4402 end;
4403 end;
4405 // Горизонтальный скролл карты:
4406 with sbHorizontal do
4407 begin
4408 if Key = Ord('A') then
4409 begin
4410 if (MouseLDown or MouseRDown) and (Position >= DotStep) then
4411 begin
4412 Dec(WASDOffset.X, DotStep);
4413 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4414 end;
4415 Position := IfThen(Position > DotStep, Position-DotStep, 0);
4416 MapOffset.X := -Round(Position/16) * 16;
4417 end;
4419 if Key = Ord('D') then
4420 begin
4421 if (MouseLDown or MouseRDown) and (Position+DotStep <= Max) then
4422 begin
4423 Inc(WASDOffset.X, DotStep);
4424 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4425 end;
4426 Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
4427 MapOffset.X := -Round(Position/16) * 16;
4428 end;
4429 end;
4430 end
4431 else // ssCtrl in Shift
4432 begin
4433 if ssShift in Shift then
4434 begin
4435 // Вставка по абсолютному смещению:
4436 if Key = Ord('V') then
4437 aPasteObjectExecute(Sender);
4438 end;
4439 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4440 end;
4441 end;
4443 // Удалить выделенные объекты:
4444 if (Key = VK_DELETE) and (SelectedObjects <> nil) and
4445 RenderPanel.Focused() then
4446 DeleteSelectedObjects();
4448 // Снять выделение:
4449 if (Key = VK_ESCAPE) and (SelectedObjects <> nil) then
4450 RemoveSelectFromObjects();
4452 // Передвинуть объекты:
4453 if MainForm.ActiveControl = RenderPanel then
4454 begin
4455 dx := 0;
4456 dy := 0;
4458 if Key = VK_NUMPAD4 then
4459 dx := IfThen(ssAlt in Shift, -1, -DotStep);
4460 if Key = VK_NUMPAD6 then
4461 dx := IfThen(ssAlt in Shift, 1, DotStep);
4462 if Key = VK_NUMPAD8 then
4463 dy := IfThen(ssAlt in Shift, -1, -DotStep);
4464 if Key = VK_NUMPAD5 then
4465 dy := IfThen(ssAlt in Shift, 1, DotStep);
4467 if (dx <> 0) or (dy <> 0) then
4468 begin
4469 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift, dx, dy);
4470 Key := 0;
4471 end;
4472 end;
4474 if ssCtrl in Shift then
4475 begin
4476 // Выбор панели с текстурой для триггера
4477 if Key = Ord('T') then
4478 begin
4479 DrawPressRect := False;
4480 if SelectFlag = SELECTFLAG_TEXTURE then
4481 begin
4482 SelectFlag := SELECTFLAG_NONE;
4483 Exit;
4484 end;
4485 vleObjectProperty.FindRow(_lc[I_PROP_TR_TEXTURE_PANEL], i);
4486 if i > 0 then
4487 SelectFlag := SELECTFLAG_TEXTURE;
4488 end;
4490 if Key = Ord('D') then
4491 begin
4492 SelectFlag := SELECTFLAG_NONE;
4493 if DrawPressRect then
4494 begin
4495 DrawPressRect := False;
4496 Exit;
4497 end;
4498 i := -1;
4500 // Выбор области воздействия, в зависимости от типа триггера
4501 vleObjectProperty.FindRow(_lc[I_PROP_TR_EX_AREA], i);
4502 if i > 0 then
4503 begin
4504 DrawPressRect := True;
4505 Exit;
4506 end;
4507 vleObjectProperty.FindRow(_lc[I_PROP_TR_DOOR_PANEL], i);
4508 if i <= 0 then
4509 vleObjectProperty.FindRow(_lc[I_PROP_TR_TRAP_PANEL], i);
4510 if i > 0 then
4511 begin
4512 SelectFlag := SELECTFLAG_DOOR;
4513 Exit;
4514 end;
4515 vleObjectProperty.FindRow(_lc[I_PROP_TR_LIFT_PANEL], i);
4516 if i > 0 then
4517 begin
4518 SelectFlag := SELECTFLAG_LIFT;
4519 Exit;
4520 end;
4521 vleObjectProperty.FindRow(_lc[I_PROP_TR_TELEPORT_TO], i);
4522 if i > 0 then
4523 begin
4524 SelectFlag := SELECTFLAG_TELEPORT;
4525 Exit;
4526 end;
4527 vleObjectProperty.FindRow(_lc[I_PROP_TR_SPAWN_TO], i);
4528 if i > 0 then
4529 begin
4530 SelectFlag := SELECTFLAG_SPAWNPOINT;
4531 Exit;
4532 end;
4534 // Выбор основного параметра, в зависимости от типа триггера
4535 vleObjectProperty.FindRow(_lc[I_PROP_TR_NEXT_MAP], i);
4536 if i > 0 then
4537 begin
4538 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
4539 SelectMapForm.Caption := _lc[I_CAP_SELECT];
4540 SelectMapForm.GetMaps(FileName);
4542 if SelectMapForm.ShowModal() = mrOK then
4543 begin
4544 vleObjectProperty.Cells[1, i] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
4545 bApplyProperty.Click();
4546 end;
4547 Exit;
4548 end;
4549 vleObjectProperty.FindRow(_lc[I_PROP_TR_SOUND_NAME], i);
4550 if i <= 0 then
4551 vleObjectProperty.FindRow(_lc[I_PROP_TR_MUSIC_NAME], i);
4552 if i > 0 then
4553 begin
4554 AddSoundForm.OKFunction := nil;
4555 AddSoundForm.lbResourcesList.MultiSelect := False;
4556 AddSoundForm.SetResource := vleObjectProperty.Cells[1, i];
4558 if (AddSoundForm.ShowModal() = mrOk) then
4559 begin
4560 vleObjectProperty.Cells[1, i] := AddSoundForm.ResourceName;
4561 bApplyProperty.Click();
4562 end;
4563 Exit;
4564 end;
4565 vleObjectProperty.FindRow(_lc[I_PROP_TR_PUSH_ANGLE], i);
4566 if i <= 0 then
4567 vleObjectProperty.FindRow(_lc[I_PROP_TR_MESSAGE_TEXT], i);
4568 if i > 0 then
4569 begin
4570 vleObjectProperty.Row := i;
4571 vleObjectProperty.SetFocus();
4572 Exit;
4573 end;
4574 end;
4575 end;
4576 end;
4578 procedure TMainForm.aOptimizeExecute(Sender: TObject);
4579 begin
4580 RemoveSelectFromObjects();
4581 MapOptimizationForm.ShowModal();
4582 end;
4584 procedure TMainForm.aCheckMapExecute(Sender: TObject);
4585 begin
4586 MapCheckForm.ShowModal();
4587 end;
4589 procedure TMainForm.bbAddTextureClick(Sender: TObject);
4590 begin
4591 AddTextureForm.lbResourcesList.MultiSelect := True;
4592 AddTextureForm.ShowModal();
4593 end;
4595 procedure TMainForm.lbTextureListClick(Sender: TObject);
4596 var
4597 TextureID: DWORD;
4598 TextureWidth, TextureHeight: Word;
4599 begin
4600 TextureID := 0;
4601 TextureWidth := 0;
4602 TextureHeight := 0;
4603 if (lbTextureList.ItemIndex <> -1) and
4604 (not IsSpecialTextureSel()) then
4605 begin
4606 if g_GetTexture(SelectedTexture(), TextureID) then
4607 begin
4608 g_GetTextureSizeByID(TextureID, TextureWidth, TextureHeight);
4610 lTextureWidth.Caption := IntToStr(TextureWidth);
4611 lTextureHeight.Caption := IntToStr(TextureHeight);
4612 end else
4613 begin
4614 lTextureWidth.Caption := _lc[I_NOT_ACCESSIBLE];
4615 lTextureHeight.Caption := _lc[I_NOT_ACCESSIBLE];
4616 end;
4617 end
4618 else
4619 begin
4620 lTextureWidth.Caption := '';
4621 lTextureHeight.Caption := '';
4622 end;
4623 end;
4625 procedure TMainForm.lbTextureListDrawItem(Control: TWinControl; Index: Integer;
4626 ARect: TRect; State: TOwnerDrawState);
4627 begin
4628 with Control as TListBox do
4629 begin
4630 if LCLType.odSelected in State then
4631 begin
4632 Canvas.Brush.Color := clHighlight;
4633 Canvas.Font.Color := clHighlightText;
4634 end else
4635 if (Items <> nil) and (Index >= 0) then
4636 if slInvalidTextures.IndexOf(Items[Index]) > -1 then
4637 begin
4638 Canvas.Brush.Color := clRed;
4639 Canvas.Font.Color := clWhite;
4640 end;
4641 Canvas.FillRect(ARect);
4642 Canvas.TextRect(ARect, ARect.Left, ARect.Top, Items[Index]);
4643 end;
4644 end;
4646 procedure TMainForm.miReopenMapClick(Sender: TObject);
4647 var
4648 FileName, Resource: String;
4649 begin
4650 if OpenedMap = '' then
4651 Exit;
4653 if MessageBox(0, PChar(_lc[I_MSG_REOPEN_MAP_PROMT]),
4654 PChar(_lc[I_MENU_FILE_REOPEN]), MB_ICONQUESTION or MB_YESNO) <> idYes then
4655 Exit;
4657 g_ProcessResourceStr(OpenedMap, @FileName, nil, @Resource);
4658 OpenMap(FileName, Resource);
4659 end;
4661 procedure TMainForm.vleObjectPropertyGetPickList(Sender: TObject;
4662 const KeyName: String; Values: TStrings);
4663 begin
4664 if vleObjectProperty.ItemProps[KeyName].EditStyle = esPickList then
4665 begin
4666 if KeyName = _lc[I_PROP_DIRECTION] then
4667 begin
4668 Values.Add(DirNames[D_LEFT]);
4669 Values.Add(DirNames[D_RIGHT]);
4670 end
4671 else if KeyName = _lc[I_PROP_TR_TELEPORT_DIR] then
4672 begin
4673 Values.Add(DirNamesAdv[0]);
4674 Values.Add(DirNamesAdv[1]);
4675 Values.Add(DirNamesAdv[2]);
4676 Values.Add(DirNamesAdv[3]);
4677 end
4678 else if KeyName = _lc[I_PROP_TR_MUSIC_ACT] then
4679 begin
4680 Values.Add(_lc[I_PROP_TR_MUSIC_ON]);
4681 Values.Add(_lc[I_PROP_TR_MUSIC_OFF]);
4682 end
4683 else if KeyName = _lc[I_PROP_TR_MONSTER_BEHAVIOUR] then
4684 begin
4685 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_0]);
4686 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_1]);
4687 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_2]);
4688 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_3]);
4689 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_4]);
4690 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_5]);
4691 end
4692 else if KeyName = _lc[I_PROP_TR_SCORE_ACT] then
4693 begin
4694 Values.Add(_lc[I_PROP_TR_SCORE_ACT_0]);
4695 Values.Add(_lc[I_PROP_TR_SCORE_ACT_1]);
4696 Values.Add(_lc[I_PROP_TR_SCORE_ACT_2]);
4697 Values.Add(_lc[I_PROP_TR_SCORE_ACT_3]);
4698 end
4699 else if KeyName = _lc[I_PROP_TR_SCORE_TEAM] then
4700 begin
4701 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_0]);
4702 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_1]);
4703 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_2]);
4704 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_3]);
4705 end
4706 else if KeyName = _lc[I_PROP_TR_MESSAGE_KIND] then
4707 begin
4708 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_0]);
4709 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_1]);
4710 end
4711 else if KeyName = _lc[I_PROP_TR_MESSAGE_TO] then
4712 begin
4713 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_0]);
4714 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_1]);
4715 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_2]);
4716 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_3]);
4717 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_4]);
4718 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_5]);
4719 end
4720 else if KeyName = _lc[I_PROP_TR_SHOT_TO] then
4721 begin
4722 Values.Add(_lc[I_PROP_TR_SHOT_TO_0]);
4723 Values.Add(_lc[I_PROP_TR_SHOT_TO_1]);
4724 Values.Add(_lc[I_PROP_TR_SHOT_TO_2]);
4725 Values.Add(_lc[I_PROP_TR_SHOT_TO_3]);
4726 Values.Add(_lc[I_PROP_TR_SHOT_TO_4]);
4727 Values.Add(_lc[I_PROP_TR_SHOT_TO_5]);
4728 Values.Add(_lc[I_PROP_TR_SHOT_TO_6]);
4729 end
4730 else if KeyName = _lc[I_PROP_TR_SHOT_AIM] then
4731 begin
4732 Values.Add(_lc[I_PROP_TR_SHOT_AIM_0]);
4733 Values.Add(_lc[I_PROP_TR_SHOT_AIM_1]);
4734 Values.Add(_lc[I_PROP_TR_SHOT_AIM_2]);
4735 Values.Add(_lc[I_PROP_TR_SHOT_AIM_3]);
4736 end
4737 else if (KeyName = _lc[I_PROP_PANEL_BLEND]) or
4738 (KeyName = _lc[I_PROP_DM_ONLY]) or
4739 (KeyName = _lc[I_PROP_ITEM_FALLS]) or
4740 (KeyName = _lc[I_PROP_TR_ENABLED]) or
4741 (KeyName = _lc[I_PROP_TR_D2D]) or
4742 (KeyName = _lc[I_PROP_TR_SILENT]) or
4743 (KeyName = _lc[I_PROP_TR_TELEPORT_SILENT]) or
4744 (KeyName = _lc[I_PROP_TR_EX_RANDOM]) or
4745 (KeyName = _lc[I_PROP_TR_TEXTURE_ONCE]) or
4746 (KeyName = _lc[I_PROP_TR_TEXTURE_ANIM_ONCE]) or
4747 (KeyName = _lc[I_PROP_TR_SOUND_LOCAL]) or
4748 (KeyName = _lc[I_PROP_TR_SOUND_SWITCH]) or
4749 (KeyName = _lc[I_PROP_TR_MONSTER_ACTIVE]) or
4750 (KeyName = _lc[I_PROP_TR_PUSH_RESET]) or
4751 (KeyName = _lc[I_PROP_TR_SCORE_CON]) or
4752 (KeyName = _lc[I_PROP_TR_SCORE_MSG]) or
4753 (KeyName = _lc[I_PROP_TR_HEALTH_MAX]) or
4754 (KeyName = _lc[I_PROP_TR_SHOT_SOUND]) or
4755 (KeyName = _lc[I_PROP_TR_EFFECT_CENTER]) then
4756 begin
4757 Values.Add(BoolNames[True]);
4758 Values.Add(BoolNames[False]);
4759 end;
4760 end;
4761 end;
4763 procedure TMainForm.bApplyPropertyClick(Sender: TObject);
4764 var
4765 _id, a, r, c: Integer;
4766 s: String;
4767 res: Boolean;
4768 NoTextureID: DWORD;
4769 NW, NH: Word;
4770 begin
4771 NoTextureID := 0;
4772 NW := 0;
4773 NH := 0;
4775 if SelectedObjectCount() <> 1 then
4776 Exit;
4777 if not SelectedObjects[GetFirstSelected()].Live then
4778 Exit;
4780 try
4781 if not CheckProperty() then
4782 Exit;
4783 except
4784 Exit;
4785 end;
4787 _id := GetFirstSelected();
4789 r := vleObjectProperty.Row;
4790 c := vleObjectProperty.Col;
4792 case SelectedObjects[_id].ObjectType of
4793 OBJECT_PANEL:
4794 begin
4795 with gPanels[SelectedObjects[_id].ID] do
4796 begin
4797 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4798 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4799 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4800 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4802 PanelType := GetPanelType(vleObjectProperty.Values[_lc[I_PROP_PANEL_TYPE]]);
4804 // Сброс ссылки на триггеры смены текстуры:
4805 if not WordBool(PanelType and (PANEL_WALL or PANEL_FORE or PANEL_BACK)) then
4806 if gTriggers <> nil then
4807 for a := 0 to High(gTriggers) do
4808 begin
4809 if (gTriggers[a].TriggerType <> 0) and
4810 (gTriggers[a].TexturePanel = Integer(SelectedObjects[_id].ID)) then
4811 gTriggers[a].TexturePanel := -1;
4812 if (gTriggers[a].TriggerType = TRIGGER_SHOT) and
4813 (gTriggers[a].Data.ShotPanelID = Integer(SelectedObjects[_id].ID)) then
4814 gTriggers[a].Data.ShotPanelID := -1;
4815 end;
4817 // Сброс ссылки на триггеры лифта:
4818 if not WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
4819 if gTriggers <> nil then
4820 for a := 0 to High(gTriggers) do
4821 if (gTriggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
4822 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4823 gTriggers[a].Data.PanelID := -1;
4825 // Сброс ссылки на триггеры двери:
4826 if not WordBool(PanelType and (PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
4827 if gTriggers <> nil then
4828 for a := 0 to High(gTriggers) do
4829 if (gTriggers[a].TriggerType in [TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
4830 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP]) and
4831 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4832 gTriggers[a].Data.PanelID := -1;
4834 if IsTexturedPanel(PanelType) then
4835 begin // Может быть текстура
4836 if TextureName <> '' then
4837 begin // Была текстура
4838 Alpha := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]]));
4839 Blending := NameToBool(vleObjectProperty.Values[_lc[I_PROP_PANEL_BLEND]]);
4840 end
4841 else // Не было
4842 begin
4843 Alpha := 0;
4844 Blending := False;
4845 end;
4847 // Новая текстура:
4848 TextureName := vleObjectProperty.Values[_lc[I_PROP_PANEL_TEX]];
4850 if TextureName <> '' then
4851 begin // Есть текстура
4852 // Обычная текстура:
4853 if not IsSpecialTexture(TextureName) then
4854 begin
4855 g_GetTextureSizeByName(TextureName,
4856 TextureWidth, TextureHeight);
4858 // Проверка кратности размеров панели:
4859 res := True;
4860 if TextureWidth <> 0 then
4861 if gPanels[SelectedObjects[_id].ID].Width mod TextureWidth <> 0 then
4862 begin
4863 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
4864 [TextureWidth]));
4865 Res := False;
4866 end;
4867 if Res and (TextureHeight <> 0) then
4868 if gPanels[SelectedObjects[_id].ID].Height mod TextureHeight <> 0 then
4869 begin
4870 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
4871 [TextureHeight]));
4872 Res := False;
4873 end;
4875 if Res then
4876 begin
4877 if not g_GetTexture(TextureName, TextureID) then
4878 // Не удалось загрузить текстуру, рисуем NOTEXTURE
4879 if g_GetTexture('NOTEXTURE', NoTextureID) then
4880 begin
4881 TextureID := TEXTURE_SPECIAL_NOTEXTURE;
4882 g_GetTextureSizeByID(NoTextureID, NW, NH);
4883 TextureWidth := NW;
4884 TextureHeight := NH;
4885 end else
4886 begin
4887 TextureID := TEXTURE_SPECIAL_NONE;
4888 TextureWidth := 1;
4889 TextureHeight := 1;
4890 end;
4891 end
4892 else
4893 begin
4894 TextureName := '';
4895 TextureWidth := 1;
4896 TextureHeight := 1;
4897 TextureID := TEXTURE_SPECIAL_NONE;
4898 end;
4899 end
4900 else // Спец.текстура
4901 begin
4902 TextureHeight := 1;
4903 TextureWidth := 1;
4904 TextureID := SpecialTextureID(TextureName);
4905 end;
4906 end
4907 else // Нет текстуры
4908 begin
4909 TextureWidth := 1;
4910 TextureHeight := 1;
4911 TextureID := TEXTURE_SPECIAL_NONE;
4912 end;
4913 end
4914 else // Не может быть текстуры
4915 begin
4916 Alpha := 0;
4917 Blending := False;
4918 TextureName := '';
4919 TextureWidth := 1;
4920 TextureHeight := 1;
4921 TextureID := TEXTURE_SPECIAL_NONE;
4922 end;
4923 end;
4924 end;
4926 OBJECT_ITEM:
4927 begin
4928 with gItems[SelectedObjects[_id].ID] do
4929 begin
4930 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4931 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4932 OnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
4933 Fall := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
4934 end;
4935 end;
4937 OBJECT_MONSTER:
4938 begin
4939 with gMonsters[SelectedObjects[_id].ID] do
4940 begin
4941 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4942 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4943 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
4944 end;
4945 end;
4947 OBJECT_AREA:
4948 begin
4949 with gAreas[SelectedObjects[_id].ID] do
4950 begin
4951 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4952 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4953 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
4954 end;
4955 end;
4957 OBJECT_TRIGGER:
4958 begin
4959 with gTriggers[SelectedObjects[_id].ID] do
4960 begin
4961 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4962 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4963 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4964 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4965 Enabled := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_ENABLED]]);
4966 ActivateType := StrToActivate(vleObjectProperty.Values[_lc[I_PROP_TR_ACTIVATION]]);
4967 Key := StrToKey(vleObjectProperty.Values[_lc[I_PROP_TR_KEYS]]);
4969 case TriggerType of
4970 TRIGGER_EXIT:
4971 begin
4972 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_NEXT_MAP]]);
4973 FillByte(Data.MapName[0], 16, 0);
4974 if s <> '' then
4975 Move(s[1], Data.MapName[0], Min(Length(s), 16));
4976 end;
4978 TRIGGER_TEXTURE:
4979 begin
4980 Data.ActivateOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ONCE]]);
4981 Data.AnimOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ANIM_ONCE]]);
4982 end;
4984 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
4985 begin
4986 Data.Wait := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 65535);
4987 Data.Count := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_COUNT]], 0), 65535);
4988 if Data.Count < 1 then
4989 Data.Count := 1;
4990 if TriggerType = TRIGGER_PRESS then
4991 Data.ExtRandom := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EX_RANDOM]]);
4992 end;
4994 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
4995 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP, TRIGGER_LIFTDOWN,
4996 TRIGGER_LIFT:
4997 begin
4998 Data.NoSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
4999 Data.d2d_doors := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
5000 end;
5002 TRIGGER_TELEPORT:
5003 begin
5004 Data.d2d_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
5005 Data.silent_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_SILENT]]);
5006 Data.TlpDir := NameToDirAdv(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_DIR]]);
5007 end;
5009 TRIGGER_SOUND:
5010 begin
5011 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_NAME]]);
5012 FillByte(Data.SoundName[0], 64, 0);
5013 if s <> '' then
5014 Move(s[1], Data.SoundName[0], Min(Length(s), 64));
5016 Data.Volume := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_VOLUME]], 0), 255);
5017 Data.Pan := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_PAN]], 0), 255);
5018 Data.PlayCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_COUNT]], 0), 255);
5019 Data.Local := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_LOCAL]]);
5020 Data.SoundSwitch := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_SWITCH]]);
5021 end;
5023 TRIGGER_SPAWNMONSTER:
5024 begin
5025 Data.MonType := StrToMonster(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_TYPE]]);
5026 Data.MonDir := Byte(NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]));
5027 Data.MonHealth := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 1000000);
5028 if Data.MonHealth < 0 then
5029 Data.MonHealth := 0;
5030 Data.MonActive := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_ACTIVE]]);
5031 Data.MonCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
5032 if Data.MonCount < 1 then
5033 Data.MonCount := 1;
5034 Data.MonEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
5035 Data.MonMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
5036 Data.MonDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
5037 Data.MonBehav := 0;
5038 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1] then
5039 Data.MonBehav := 1;
5040 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2] then
5041 Data.MonBehav := 2;
5042 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3] then
5043 Data.MonBehav := 3;
5044 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4] then
5045 Data.MonBehav := 4;
5046 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5] then
5047 Data.MonBehav := 5;
5048 end;
5050 TRIGGER_SPAWNITEM:
5051 begin
5052 Data.ItemType := StrToItem(vleObjectProperty.Values[_lc[I_PROP_TR_ITEM_TYPE]]);
5053 Data.ItemOnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
5054 Data.ItemFalls := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
5055 Data.ItemCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
5056 if Data.ItemCount < 1 then
5057 Data.ItemCount := 1;
5058 Data.ItemEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
5059 Data.ItemMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
5060 Data.ItemDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
5061 end;
5063 TRIGGER_MUSIC:
5064 begin
5065 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_NAME]]);
5066 FillByte(Data.MusicName[0], 64, 0);
5067 if s <> '' then
5068 Move(s[1], Data.MusicName[0], Min(Length(s), 64));
5070 if vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_ACT]] = _lc[I_PROP_TR_MUSIC_ON] then
5071 Data.MusicAction := 1
5072 else
5073 Data.MusicAction := 2;
5074 end;
5076 TRIGGER_PUSH:
5077 begin
5078 Data.PushAngle := Min(
5079 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_ANGLE]], 0), 360);
5080 Data.PushForce := Min(
5081 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_FORCE]], 0), 255);
5082 Data.ResetVel := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_RESET]]);
5083 end;
5085 TRIGGER_SCORE:
5086 begin
5087 Data.ScoreAction := 0;
5088 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_1] then
5089 Data.ScoreAction := 1
5090 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_2] then
5091 Data.ScoreAction := 2
5092 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_3] then
5093 Data.ScoreAction := 3;
5094 Data.ScoreCount := Min(Max(
5095 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
5096 Data.ScoreTeam := 0;
5097 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_1] then
5098 Data.ScoreTeam := 1
5099 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_2] then
5100 Data.ScoreTeam := 2
5101 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_3] then
5102 Data.ScoreTeam := 3;
5103 Data.ScoreCon := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_CON]]);
5104 Data.ScoreMsg := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_MSG]]);
5105 end;
5107 TRIGGER_MESSAGE:
5108 begin
5109 Data.MessageKind := 0;
5110 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_KIND]] = _lc[I_PROP_TR_MESSAGE_KIND_1] then
5111 Data.MessageKind := 1;
5113 Data.MessageSendTo := 0;
5114 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_1] then
5115 Data.MessageSendTo := 1
5116 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_2] then
5117 Data.MessageSendTo := 2
5118 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_3] then
5119 Data.MessageSendTo := 3
5120 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_4] then
5121 Data.MessageSendTo := 4
5122 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_5] then
5123 Data.MessageSendTo := 5;
5125 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TEXT]]);
5126 FillByte(Data.MessageText[0], 100, 0);
5127 if s <> '' then
5128 Move(s[1], Data.MessageText[0], Min(Length(s), 100));
5130 Data.MessageTime := Min(Max(
5131 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TIME]], 0), 0), 65535);
5132 end;
5134 TRIGGER_DAMAGE:
5135 begin
5136 Data.DamageValue := Min(Max(
5137 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_DAMAGE_VALUE]], 0), 0), 65535);
5138 Data.DamageInterval := Min(Max(
5139 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
5140 end;
5142 TRIGGER_HEALTH:
5143 begin
5144 Data.HealValue := Min(Max(
5145 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 0), 65535);
5146 Data.HealInterval := Min(Max(
5147 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
5148 Data.HealMax := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH_MAX]]);
5149 Data.HealSilent := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
5150 end;
5152 TRIGGER_SHOT:
5153 begin
5154 Data.ShotType := StrToShot(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TYPE]]);
5155 Data.ShotSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SOUND]]);
5156 Data.ShotTarget := 0;
5157 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_1] then
5158 Data.ShotTarget := 1
5159 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_2] then
5160 Data.ShotTarget := 2
5161 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_3] then
5162 Data.ShotTarget := 3
5163 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_4] then
5164 Data.ShotTarget := 4
5165 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_5] then
5166 Data.ShotTarget := 5
5167 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_6] then
5168 Data.ShotTarget := 6;
5169 Data.ShotIntSight := Min(Max(
5170 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SIGHT]], 0), 0), 65535);
5171 Data.ShotAim := 0;
5172 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_1] then
5173 Data.ShotAim := 1
5174 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_2] then
5175 Data.ShotAim := 2
5176 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_3] then
5177 Data.ShotAim := 3;
5178 Data.ShotAngle := Min(
5179 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ANGLE]], 0), 360);
5180 Data.ShotWait := Min(Max(
5181 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
5182 Data.ShotAccuracy := Min(Max(
5183 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ACC]], 0), 0), 65535);
5184 Data.ShotAmmo := Min(Max(
5185 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AMMO]], 0), 0), 65535);
5186 Data.ShotIntReload := Min(Max(
5187 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_RELOAD]], 0), 0), 65535);
5188 end;
5190 TRIGGER_EFFECT:
5191 begin
5192 Data.FXCount := Min(Max(
5193 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
5194 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_PARTICLE] then
5195 begin
5196 Data.FXType := TRIGGER_EFFECT_PARTICLE;
5197 Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
5198 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SLIQUID] then
5199 Data.FXSubType := TRIGGER_EFFECT_SLIQUID
5200 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
5201 Data.FXSubType := TRIGGER_EFFECT_LLIQUID
5202 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
5203 Data.FXSubType := TRIGGER_EFFECT_DLIQUID
5204 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BLOOD] then
5205 Data.FXSubType := TRIGGER_EFFECT_BLOOD
5206 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SPARK] then
5207 Data.FXSubType := TRIGGER_EFFECT_SPARK
5208 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
5209 Data.FXSubType := TRIGGER_EFFECT_BUBBLE;
5210 end else
5211 begin
5212 Data.FXType := TRIGGER_EFFECT_ANIMATION;
5213 Data.FXSubType := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]]);
5214 end;
5215 a := Min(Max(
5216 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_COLOR]], 0), 0), $FFFFFF);
5217 Data.FXColorR := a and $FF;
5218 Data.FXColorG := (a shr 8) and $FF;
5219 Data.FXColorB := (a shr 16) and $FF;
5220 if NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_CENTER]]) then
5221 Data.FXPos := 0
5222 else
5223 Data.FXPos := 1;
5224 Data.FXWait := Min(Max(
5225 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
5226 Data.FXVelX := Min(Max(
5227 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELX]], 0), -128), 127);
5228 Data.FXVelY := Min(Max(
5229 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELY]], 0), -128), 127);
5230 Data.FXSpreadL := Min(Max(
5231 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPL]], 0), 0), 255);
5232 Data.FXSpreadR := Min(Max(
5233 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPR]], 0), 0), 255);
5234 Data.FXSpreadU := Min(Max(
5235 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPU]], 0), 0), 255);
5236 Data.FXSpreadD := Min(Max(
5237 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPD]], 0), 0), 255);
5238 end;
5239 end;
5240 end;
5241 end;
5242 end;
5244 FillProperty();
5246 vleObjectProperty.Row := r;
5247 vleObjectProperty.Col := c;
5248 end;
5250 procedure TMainForm.bbRemoveTextureClick(Sender: TObject);
5251 var
5252 a, i: Integer;
5253 begin
5254 i := lbTextureList.ItemIndex;
5255 if i = -1 then
5256 Exit;
5258 if MessageBox(0, PChar(Format(_lc[I_MSG_DEL_TEXTURE_PROMT],
5259 [SelectedTexture()])),
5260 PChar(_lc[I_MSG_DEL_TEXTURE]),
5261 MB_ICONQUESTION or MB_YESNO or
5262 MB_DEFBUTTON1) <> idYes then
5263 Exit;
5265 if gPanels <> nil then
5266 for a := 0 to High(gPanels) do
5267 if (gPanels[a].PanelType <> 0) and
5268 (gPanels[a].TextureName = SelectedTexture()) then
5269 begin
5270 ErrorMessageBox(_lc[I_MSG_DEL_TEXTURE_CANT]);
5271 Exit;
5272 end;
5274 g_DeleteTexture(SelectedTexture());
5275 i := slInvalidTextures.IndexOf(lbTextureList.Items[i]);
5276 if i > -1 then
5277 slInvalidTextures.Delete(i);
5278 if lbTextureList.ItemIndex > -1 then
5279 lbTextureList.Items.Delete(lbTextureList.ItemIndex)
5280 end;
5282 procedure TMainForm.aNewMapExecute(Sender: TObject);
5283 begin
5284 if (MessageBox(0, PChar(_lc[I_MSG_CLEAR_MAP_PROMT]),
5285 PChar(_lc[I_MSG_CLEAR_MAP]),
5286 MB_ICONQUESTION or MB_YESNO or
5287 MB_DEFBUTTON1) = mrYes) then
5288 FullClear();
5289 end;
5291 procedure TMainForm.aUndoExecute(Sender: TObject);
5292 var
5293 a: Integer;
5294 begin
5295 if UndoBuffer = nil then
5296 Exit;
5297 if UndoBuffer[High(UndoBuffer)] = nil then
5298 Exit;
5300 for a := 0 to High(UndoBuffer[High(UndoBuffer)]) do
5301 with UndoBuffer[High(UndoBuffer)][a] do
5302 begin
5303 case UndoType of
5304 UNDO_DELETE_PANEL:
5305 begin
5306 AddPanel(Panel^);
5307 Panel := nil;
5308 end;
5309 UNDO_DELETE_ITEM: AddItem(Item);
5310 UNDO_DELETE_AREA: AddArea(Area);
5311 UNDO_DELETE_MONSTER: AddMonster(Monster);
5312 UNDO_DELETE_TRIGGER: AddTrigger(Trigger);
5313 UNDO_ADD_PANEL: RemoveObject(AddID, OBJECT_PANEL);
5314 UNDO_ADD_ITEM: RemoveObject(AddID, OBJECT_ITEM);
5315 UNDO_ADD_AREA: RemoveObject(AddID, OBJECT_AREA);
5316 UNDO_ADD_MONSTER: RemoveObject(AddID, OBJECT_MONSTER);
5317 UNDO_ADD_TRIGGER: RemoveObject(AddID, OBJECT_TRIGGER);
5318 end;
5319 end;
5321 SetLength(UndoBuffer, Length(UndoBuffer)-1);
5323 RemoveSelectFromObjects();
5325 miUndo.Enabled := UndoBuffer <> nil;
5326 end;
5329 procedure TMainForm.aCopyObjectExecute(Sender: TObject);
5330 var
5331 a, b: Integer;
5332 CopyBuffer: TCopyRecArray;
5333 str: String;
5334 ok: Boolean;
5336 function CB_Compare(I1, I2: TCopyRec): Integer;
5337 begin
5338 Result := Integer(I1.ObjectType) - Integer(I2.ObjectType);
5340 if Result = 0 then // Одного типа
5341 Result := Integer(I1.ID) - Integer(I2.ID);
5342 end;
5344 procedure QuickSortCopyBuffer(L, R: Integer);
5345 var
5346 I, J: Integer;
5347 P, T: TCopyRec;
5348 begin
5349 repeat
5350 I := L;
5351 J := R;
5352 P := CopyBuffer[(L + R) shr 1];
5354 repeat
5355 while CB_Compare(CopyBuffer[I], P) < 0 do
5356 Inc(I);
5357 while CB_Compare(CopyBuffer[J], P) > 0 do
5358 Dec(J);
5360 if I <= J then
5361 begin
5362 T := CopyBuffer[I];
5363 CopyBuffer[I] := CopyBuffer[J];
5364 CopyBuffer[J] := T;
5365 Inc(I);
5366 Dec(J);
5367 end;
5368 until I > J;
5370 if L < J then
5371 QuickSortCopyBuffer(L, J);
5373 L := I;
5374 until I >= R;
5375 end;
5377 begin
5378 if SelectedObjects = nil then
5379 Exit;
5381 b := -1;
5382 CopyBuffer := nil;
5384 // Копируем объекты:
5385 for a := 0 to High(SelectedObjects) do
5386 if SelectedObjects[a].Live then
5387 with SelectedObjects[a] do
5388 begin
5389 SetLength(CopyBuffer, Length(CopyBuffer)+1);
5390 b := High(CopyBuffer);
5391 CopyBuffer[b].ID := ID;
5392 CopyBuffer[b].Panel := nil;
5394 case ObjectType of
5395 OBJECT_PANEL:
5396 begin
5397 CopyBuffer[b].ObjectType := OBJECT_PANEL;
5398 New(CopyBuffer[b].Panel);
5399 CopyBuffer[b].Panel^ := gPanels[ID];
5400 end;
5402 OBJECT_ITEM:
5403 begin
5404 CopyBuffer[b].ObjectType := OBJECT_ITEM;
5405 CopyBuffer[b].Item := gItems[ID];
5406 end;
5408 OBJECT_MONSTER:
5409 begin
5410 CopyBuffer[b].ObjectType := OBJECT_MONSTER;
5411 CopyBuffer[b].Monster := gMonsters[ID];
5412 end;
5414 OBJECT_AREA:
5415 begin
5416 CopyBuffer[b].ObjectType := OBJECT_AREA;
5417 CopyBuffer[b].Area := gAreas[ID];
5418 end;
5420 OBJECT_TRIGGER:
5421 begin
5422 CopyBuffer[b].ObjectType := OBJECT_TRIGGER;
5423 CopyBuffer[b].Trigger := gTriggers[ID];
5424 end;
5425 end;
5426 end;
5428 // Сортировка по ID:
5429 if CopyBuffer <> nil then
5430 begin
5431 QuickSortCopyBuffer(0, b);
5432 end;
5434 // Пестановка ссылок триггеров:
5435 for a := 0 to Length(CopyBuffer)-1 do
5436 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5437 begin
5438 case CopyBuffer[a].Trigger.TriggerType of
5439 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5440 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5441 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5442 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5443 begin
5444 ok := False;
5446 for b := 0 to Length(CopyBuffer)-1 do
5447 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5448 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.PanelID) then
5449 begin
5450 CopyBuffer[a].Trigger.Data.PanelID := b;
5451 ok := True;
5452 Break;
5453 end;
5455 // Этих панелей нет среди копируемых:
5456 if not ok then
5457 CopyBuffer[a].Trigger.Data.PanelID := -1;
5458 end;
5460 TRIGGER_PRESS, TRIGGER_ON,
5461 TRIGGER_OFF, TRIGGER_ONOFF:
5462 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5463 begin
5464 ok := False;
5466 for b := 0 to Length(CopyBuffer)-1 do
5467 if (CopyBuffer[b].ObjectType = OBJECT_MONSTER) and
5468 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.MonsterID-1) then
5469 begin
5470 CopyBuffer[a].Trigger.Data.MonsterID := b+1;
5471 ok := True;
5472 Break;
5473 end;
5475 // Этих монстров нет среди копируемых:
5476 if not ok then
5477 CopyBuffer[a].Trigger.Data.MonsterID := 0;
5478 end;
5480 TRIGGER_SHOT:
5481 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5482 begin
5483 ok := False;
5485 for b := 0 to Length(CopyBuffer)-1 do
5486 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5487 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.ShotPanelID) then
5488 begin
5489 CopyBuffer[a].Trigger.Data.ShotPanelID := b;
5490 ok := True;
5491 Break;
5492 end;
5494 // Этих панелей нет среди копируемых:
5495 if not ok then
5496 CopyBuffer[a].Trigger.Data.ShotPanelID := -1;
5497 end;
5498 end;
5500 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5501 begin
5502 ok := False;
5504 for b := 0 to Length(CopyBuffer)-1 do
5505 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5506 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.TexturePanel) then
5507 begin
5508 CopyBuffer[a].Trigger.TexturePanel := b;
5509 ok := True;
5510 Break;
5511 end;
5513 // Этих панелей нет среди копируемых:
5514 if not ok then
5515 CopyBuffer[a].Trigger.TexturePanel := -1;
5516 end;
5517 end;
5519 // В буфер обмена:
5520 str := CopyBufferToString(CopyBuffer);
5521 ClipBoard.AsText := str;
5523 for a := 0 to Length(CopyBuffer)-1 do
5524 if (CopyBuffer[a].ObjectType = OBJECT_PANEL) and
5525 (CopyBuffer[a].Panel <> nil) then
5526 Dispose(CopyBuffer[a].Panel);
5528 CopyBuffer := nil;
5529 end;
5531 procedure TMainForm.aPasteObjectExecute(Sender: TObject);
5532 var
5533 a, h: Integer;
5534 CopyBuffer: TCopyRecArray;
5535 res, rel: Boolean;
5536 swad, ssec, sres: String;
5537 NoTextureID: DWORD;
5538 pmin: TPoint;
5539 begin
5540 CopyBuffer := nil;
5541 NoTextureID := 0;
5542 pmin.X := High(pmin.X);
5543 pmin.Y := High(pmin.Y);
5545 StringToCopyBuffer(ClipBoard.AsText, CopyBuffer, pmin);
5546 rel := not(ssShift in GetKeyShiftState());
5548 if CopyBuffer = nil then
5549 Exit;
5551 RemoveSelectFromObjects();
5553 h := High(CopyBuffer);
5554 for a := 0 to h do
5555 with CopyBuffer[a] do
5556 begin
5557 case ObjectType of
5558 OBJECT_PANEL:
5559 if Panel <> nil then
5560 begin
5561 if rel then
5562 begin
5563 Panel^.X := Panel^.X - pmin.X - MapOffset.X + 32;
5564 Panel^.Y := Panel^.Y - pmin.Y - MapOffset.Y + 32;
5565 end;
5567 Panel^.TextureID := TEXTURE_SPECIAL_NONE;
5568 Panel^.TextureWidth := 1;
5569 Panel^.TextureHeight := 1;
5571 if (Panel^.PanelType = PANEL_LIFTUP) or
5572 (Panel^.PanelType = PANEL_LIFTDOWN) or
5573 (Panel^.PanelType = PANEL_LIFTLEFT) or
5574 (Panel^.PanelType = PANEL_LIFTRIGHT) or
5575 (Panel^.PanelType = PANEL_BLOCKMON) or
5576 (Panel^.TextureName = '') then
5577 begin // Нет или не может быть текстуры:
5578 end
5579 else // Есть текстура:
5580 begin
5581 // Обычная текстура:
5582 if not IsSpecialTexture(Panel^.TextureName) then
5583 begin
5584 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5586 if not res then
5587 begin
5588 g_ProcessResourceStr(Panel^.TextureName, swad, ssec, sres);
5589 AddTexture(swad, ssec, sres, True);
5590 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5591 end;
5593 if res then
5594 g_GetTextureSizeByName(Panel^.TextureName,
5595 Panel^.TextureWidth, Panel^.TextureHeight)
5596 else
5597 if g_GetTexture('NOTEXTURE', NoTextureID) then
5598 begin
5599 Panel^.TextureID := TEXTURE_SPECIAL_NOTEXTURE;
5600 g_GetTextureSizeByID(NoTextureID, Panel^.TextureWidth, Panel^.TextureHeight);
5601 end;
5602 end
5603 else // Спец.текстура:
5604 begin
5605 Panel^.TextureID := SpecialTextureID(Panel^.TextureName);
5606 with MainForm.lbTextureList.Items do
5607 if IndexOf(Panel^.TextureName) = -1 then
5608 Add(Panel^.TextureName);
5609 end;
5610 end;
5612 ID := AddPanel(Panel^);
5613 Dispose(Panel);
5614 Undo_Add(OBJECT_PANEL, ID, a > 0);
5615 SelectObject(OBJECT_PANEL, ID, True);
5616 end;
5618 OBJECT_ITEM:
5619 begin
5620 if rel then
5621 begin
5622 Item.X := Item.X - pmin.X - MapOffset.X + 32;
5623 Item.Y := Item.Y - pmin.Y - MapOffset.Y + 32;
5624 end;
5626 ID := AddItem(Item);
5627 Undo_Add(OBJECT_ITEM, ID, a > 0);
5628 SelectObject(OBJECT_ITEM, ID, True);
5629 end;
5631 OBJECT_MONSTER:
5632 begin
5633 if rel then
5634 begin
5635 Monster.X := Monster.X - pmin.X - MapOffset.X + 32;
5636 Monster.Y := Monster.Y - pmin.Y - MapOffset.Y + 32;
5637 end;
5639 ID := AddMonster(Monster);
5640 Undo_Add(OBJECT_MONSTER, ID, a > 0);
5641 SelectObject(OBJECT_MONSTER, ID, True);
5642 end;
5644 OBJECT_AREA:
5645 begin
5646 if rel then
5647 begin
5648 Area.X := Area.X - pmin.X - MapOffset.X + 32;
5649 Area.Y := Area.Y - pmin.Y - MapOffset.Y + 32;
5650 end;
5652 ID := AddArea(Area);
5653 Undo_Add(OBJECT_AREA, ID, a > 0);
5654 SelectObject(OBJECT_AREA, ID, True);
5655 end;
5657 OBJECT_TRIGGER:
5658 begin
5659 if rel then
5660 with Trigger do
5661 begin
5662 X := X - pmin.X - MapOffset.X + 32;
5663 Y := Y - pmin.Y - MapOffset.Y + 32;
5665 case TriggerType of
5666 TRIGGER_TELEPORT:
5667 begin
5668 Data.TargetPoint.X :=
5669 Data.TargetPoint.X - pmin.X - MapOffset.X + 32;
5670 Data.TargetPoint.Y :=
5671 Data.TargetPoint.Y - pmin.Y - MapOffset.Y + 32;
5672 end;
5673 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
5674 begin
5675 Data.tX := Data.tX - pmin.X - MapOffset.X + 32;
5676 Data.tY := Data.tY - pmin.Y - MapOffset.Y + 32;
5677 end;
5678 TRIGGER_SPAWNMONSTER:
5679 begin
5680 Data.MonPos.X :=
5681 Data.MonPos.X - pmin.X - MapOffset.X + 32;
5682 Data.MonPos.Y :=
5683 Data.MonPos.Y - pmin.Y - MapOffset.Y + 32;
5684 end;
5685 TRIGGER_SPAWNITEM:
5686 begin
5687 Data.ItemPos.X :=
5688 Data.ItemPos.X - pmin.X - MapOffset.X + 32;
5689 Data.ItemPos.Y :=
5690 Data.ItemPos.Y - pmin.Y - MapOffset.Y + 32;
5691 end;
5692 TRIGGER_SHOT:
5693 begin
5694 Data.ShotPos.X :=
5695 Data.ShotPos.X - pmin.X - MapOffset.X + 32;
5696 Data.ShotPos.Y :=
5697 Data.ShotPos.Y - pmin.Y - MapOffset.Y + 32;
5698 end;
5699 end;
5700 end;
5702 ID := AddTrigger(Trigger);
5703 Undo_Add(OBJECT_TRIGGER, ID, a > 0);
5704 SelectObject(OBJECT_TRIGGER, ID, True);
5705 end;
5706 end;
5707 end;
5709 // Переставляем ссылки триггеров:
5710 for a := 0 to High(CopyBuffer) do
5711 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5712 begin
5713 case CopyBuffer[a].Trigger.TriggerType of
5714 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5715 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5716 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5717 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5718 gTriggers[CopyBuffer[a].ID].Data.PanelID :=
5719 CopyBuffer[CopyBuffer[a].Trigger.Data.PanelID].ID;
5721 TRIGGER_PRESS, TRIGGER_ON,
5722 TRIGGER_OFF, TRIGGER_ONOFF:
5723 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5724 gTriggers[CopyBuffer[a].ID].Data.MonsterID :=
5725 CopyBuffer[CopyBuffer[a].Trigger.Data.MonsterID-1].ID+1;
5727 TRIGGER_SHOT:
5728 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5729 gTriggers[CopyBuffer[a].ID].Data.ShotPanelID :=
5730 CopyBuffer[CopyBuffer[a].Trigger.Data.ShotPanelID].ID;
5731 end;
5733 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5734 gTriggers[CopyBuffer[a].ID].TexturePanel :=
5735 CopyBuffer[CopyBuffer[a].Trigger.TexturePanel].ID;
5736 end;
5738 CopyBuffer := nil;
5740 if h = 0 then
5741 FillProperty();
5742 end;
5744 procedure TMainForm.aCutObjectExecute(Sender: TObject);
5745 begin
5746 miCopy.Click();
5747 DeleteSelectedObjects();
5748 end;
5750 procedure TMainForm.vleObjectPropertyEditButtonClick(Sender: TObject);
5751 var
5752 Key, FileName: String;
5753 b: Byte;
5754 begin
5755 Key := vleObjectProperty.Keys[vleObjectProperty.Row];
5757 if Key = _lc[I_PROP_PANEL_TYPE] then
5758 begin
5759 with ChooseTypeForm, vleObjectProperty do
5760 begin // Выбор типа панели:
5761 Caption := _lc[I_PROP_PANEL_TYPE];
5762 lbTypeSelect.Items.Clear();
5764 for b := 0 to High(PANELNAMES) do
5765 begin
5766 lbTypeSelect.Items.Add(PANELNAMES[b]);
5767 if Values[Key] = PANELNAMES[b] then
5768 lbTypeSelect.ItemIndex := b;
5769 end;
5771 if ShowModal() = mrOK then
5772 begin
5773 b := lbTypeSelect.ItemIndex;
5774 Values[Key] := PANELNAMES[b];
5775 vleObjectPropertyApply(Sender);
5776 end;
5777 end
5778 end
5779 else if Key = _lc[I_PROP_TR_TELEPORT_TO] then
5780 SelectFlag := SELECTFLAG_TELEPORT
5781 else if Key = _lc[I_PROP_TR_SPAWN_TO] then
5782 SelectFlag := SELECTFLAG_SPAWNPOINT
5783 else if (Key = _lc[I_PROP_TR_DOOR_PANEL]) or
5784 (Key = _lc[I_PROP_TR_TRAP_PANEL]) then
5785 SelectFlag := SELECTFLAG_DOOR
5786 else if Key = _lc[I_PROP_TR_TEXTURE_PANEL] then
5787 begin
5788 DrawPressRect := False;
5789 SelectFlag := SELECTFLAG_TEXTURE;
5790 end
5791 else if Key = _lc[I_PROP_TR_SHOT_PANEL] then
5792 SelectFlag := SELECTFLAG_SHOTPANEL
5793 else if Key = _lc[I_PROP_TR_LIFT_PANEL] then
5794 SelectFlag := SELECTFLAG_LIFT
5795 else if key = _lc[I_PROP_TR_EX_MONSTER] then
5796 SelectFlag := SELECTFLAG_MONSTER
5797 else if Key = _lc[I_PROP_TR_EX_AREA] then
5798 begin
5799 SelectFlag := SELECTFLAG_NONE;
5800 DrawPressRect := True;
5801 end
5802 else if Key = _lc[I_PROP_TR_NEXT_MAP] then
5803 begin // Выбор следующей карты:
5804 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
5805 SelectMapForm.Caption := _lc[I_CAP_SELECT];
5806 SelectMapForm.GetMaps(FileName);
5808 if SelectMapForm.ShowModal() = mrOK then
5809 begin
5810 vleObjectProperty.Values[Key] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
5811 vleObjectPropertyApply(Sender);
5812 end;
5813 end
5814 else if (Key = _lc[I_PROP_TR_SOUND_NAME]) or
5815 (Key = _lc[I_PROP_TR_MUSIC_NAME]) then
5816 begin // Выбор файла звука/музыки:
5817 AddSoundForm.OKFunction := nil;
5818 AddSoundForm.lbResourcesList.MultiSelect := False;
5819 AddSoundForm.SetResource := vleObjectProperty.Values[Key];
5821 if (AddSoundForm.ShowModal() = mrOk) then
5822 begin
5823 vleObjectProperty.Values[Key] := AddSoundForm.ResourceName;
5824 vleObjectPropertyApply(Sender);
5825 end;
5826 end
5827 else if Key = _lc[I_PROP_TR_ACTIVATION] then
5828 with ActivationTypeForm, vleObjectProperty do
5829 begin // Выбор типов активации:
5830 cbPlayerCollide.Checked := Pos('PC', Values[Key]) > 0;
5831 cbMonsterCollide.Checked := Pos('MC', Values[Key]) > 0;
5832 cbPlayerPress.Checked := Pos('PP', Values[Key]) > 0;
5833 cbMonsterPress.Checked := Pos('MP', Values[Key]) > 0;
5834 cbShot.Checked := Pos('SH', Values[Key]) > 0;
5835 cbNoMonster.Checked := Pos('NM', Values[Key]) > 0;
5837 if ShowModal() = mrOK then
5838 begin
5839 b := 0;
5840 if cbPlayerCollide.Checked then
5841 b := ACTIVATE_PLAYERCOLLIDE;
5842 if cbMonsterCollide.Checked then
5843 b := b or ACTIVATE_MONSTERCOLLIDE;
5844 if cbPlayerPress.Checked then
5845 b := b or ACTIVATE_PLAYERPRESS;
5846 if cbMonsterPress.Checked then
5847 b := b or ACTIVATE_MONSTERPRESS;
5848 if cbShot.Checked then
5849 b := b or ACTIVATE_SHOT;
5850 if cbNoMonster.Checked then
5851 b := b or ACTIVATE_NOMONSTER;
5853 Values[Key] := ActivateToStr(b);
5854 vleObjectPropertyApply(Sender);
5855 end;
5856 end
5857 else if Key = _lc[I_PROP_TR_KEYS] then
5858 with KeysForm, vleObjectProperty do
5859 begin // Выбор необходимых ключей:
5860 cbRedKey.Checked := Pos('RK', Values[Key]) > 0;
5861 cbGreenKey.Checked := Pos('GK', Values[Key]) > 0;
5862 cbBlueKey.Checked := Pos('BK', Values[Key]) > 0;
5863 cbRedTeam.Checked := Pos('RT', Values[Key]) > 0;
5864 cbBlueTeam.Checked := Pos('BT', Values[Key]) > 0;
5866 if ShowModal() = mrOK then
5867 begin
5868 b := 0;
5869 if cbRedKey.Checked then
5870 b := KEY_RED;
5871 if cbGreenKey.Checked then
5872 b := b or KEY_GREEN;
5873 if cbBlueKey.Checked then
5874 b := b or KEY_BLUE;
5875 if cbRedTeam.Checked then
5876 b := b or KEY_REDTEAM;
5877 if cbBlueTeam.Checked then
5878 b := b or KEY_BLUETEAM;
5880 Values[Key] := KeyToStr(b);
5881 vleObjectPropertyApply(Sender);
5882 end;
5883 end
5884 else if Key = _lc[I_PROP_TR_FX_TYPE] then
5885 with ChooseTypeForm, vleObjectProperty do
5886 begin // Выбор типа эффекта:
5887 Caption := _lc[I_CAP_FX_TYPE];
5888 lbTypeSelect.Items.Clear();
5890 for b := EFFECT_NONE to EFFECT_FIRE do
5891 lbTypeSelect.Items.Add(EffectToStr(b));
5893 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]);
5895 if ShowModal() = mrOK then
5896 begin
5897 b := lbTypeSelect.ItemIndex;
5898 Values[Key] := EffectToStr(b);
5899 vleObjectPropertyApply(Sender);
5900 end;
5901 end
5902 else if Key = _lc[I_PROP_TR_MONSTER_TYPE] then
5903 with ChooseTypeForm, vleObjectProperty do
5904 begin // Выбор типа монстра:
5905 Caption := _lc[I_CAP_MONSTER_TYPE];
5906 lbTypeSelect.Items.Clear();
5908 for b := MONSTER_DEMON to MONSTER_MAN do
5909 lbTypeSelect.Items.Add(MonsterToStr(b));
5911 lbTypeSelect.ItemIndex := StrToMonster(Values[Key]) - MONSTER_DEMON;
5913 if ShowModal() = mrOK then
5914 begin
5915 b := lbTypeSelect.ItemIndex + MONSTER_DEMON;
5916 Values[Key] := MonsterToStr(b);
5917 vleObjectPropertyApply(Sender);
5918 end;
5919 end
5920 else if Key = _lc[I_PROP_TR_ITEM_TYPE] then
5921 with ChooseTypeForm, vleObjectProperty do
5922 begin // Выбор типа предмета:
5923 Caption := _lc[I_CAP_ITEM_TYPE];
5924 lbTypeSelect.Items.Clear();
5926 for b := ITEM_MEDKIT_SMALL to ITEM_KEY_BLUE do
5927 lbTypeSelect.Items.Add(ItemToStr(b));
5928 lbTypeSelect.Items.Add(ItemToStr(ITEM_BOTTLE));
5929 lbTypeSelect.Items.Add(ItemToStr(ITEM_HELMET));
5930 lbTypeSelect.Items.Add(ItemToStr(ITEM_JETPACK));
5931 lbTypeSelect.Items.Add(ItemToStr(ITEM_INVIS));
5932 lbTypeSelect.Items.Add(ItemToStr(ITEM_WEAPON_FLAMETHROWER));
5933 lbTypeSelect.Items.Add(ItemToStr(ITEM_AMMO_FUELCAN));
5935 b := StrToItem(Values[Key]);
5936 if b >= ITEM_BOTTLE then
5937 b := b - 2;
5938 lbTypeSelect.ItemIndex := b - ITEM_MEDKIT_SMALL;
5940 if ShowModal() = mrOK then
5941 begin
5942 b := lbTypeSelect.ItemIndex + ITEM_MEDKIT_SMALL;
5943 if b >= ITEM_WEAPON_KASTET then
5944 b := b + 2;
5945 Values[Key] := ItemToStr(b);
5946 vleObjectPropertyApply(Sender);
5947 end;
5948 end
5949 else if Key = _lc[I_PROP_TR_SHOT_TYPE] then
5950 with ChooseTypeForm, vleObjectProperty do
5951 begin // Выбор типа предмета:
5952 Caption := _lc[I_PROP_TR_SHOT_TYPE];
5953 lbTypeSelect.Items.Clear();
5955 for b := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
5956 lbTypeSelect.Items.Add(ShotToStr(b));
5958 lbTypeSelect.ItemIndex := StrToShot(Values[Key]);
5960 if ShowModal() = mrOK then
5961 begin
5962 b := lbTypeSelect.ItemIndex;
5963 Values[Key] := ShotToStr(b);
5964 vleObjectPropertyApply(Sender);
5965 end;
5966 end
5967 else if Key = _lc[I_PROP_TR_EFFECT_TYPE] then
5968 with ChooseTypeForm, vleObjectProperty do
5969 begin // Выбор типа эффекта:
5970 Caption := _lc[I_CAP_FX_TYPE];
5971 lbTypeSelect.Items.Clear();
5973 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_PARTICLE]);
5974 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_ANIMATION]);
5975 if Values[Key] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5976 lbTypeSelect.ItemIndex := 1
5977 else
5978 lbTypeSelect.ItemIndex := 0;
5980 if ShowModal() = mrOK then
5981 begin
5982 b := lbTypeSelect.ItemIndex;
5983 if b = 0 then
5984 Values[Key] := _lc[I_PROP_TR_EFFECT_PARTICLE]
5985 else
5986 Values[Key] := _lc[I_PROP_TR_EFFECT_ANIMATION];
5987 vleObjectPropertyApply(Sender);
5988 end;
5989 end
5990 else if Key = _lc[I_PROP_TR_EFFECT_SUBTYPE] then
5991 with ChooseTypeForm, vleObjectProperty do
5992 begin // Выбор подтипа эффекта:
5993 Caption := _lc[I_CAP_FX_TYPE];
5994 lbTypeSelect.Items.Clear();
5996 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5997 begin
5998 for b := EFFECT_TELEPORT to EFFECT_FIRE do
5999 lbTypeSelect.Items.Add(EffectToStr(b));
6001 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]) - 1;
6002 end else
6003 begin
6004 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SLIQUID]);
6005 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_LLIQUID]);
6006 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_DLIQUID]);
6007 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BLOOD]);
6008 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SPARK]);
6009 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BUBBLE]);
6010 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SLIQUID;
6011 if Values[Key] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
6012 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_LLIQUID;
6013 if Values[Key] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
6014 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_DLIQUID;
6015 if Values[Key] = _lc[I_PROP_TR_EFFECT_BLOOD] then
6016 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BLOOD;
6017 if Values[Key] = _lc[I_PROP_TR_EFFECT_SPARK] then
6018 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SPARK;
6019 if Values[Key] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
6020 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BUBBLE;
6021 end;
6023 if ShowModal() = mrOK then
6024 begin
6025 b := lbTypeSelect.ItemIndex;
6027 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
6028 Values[Key] := EffectToStr(b + 1)
6029 else begin
6030 Values[Key] := _lc[I_PROP_TR_EFFECT_SLIQUID];
6031 if b = TRIGGER_EFFECT_LLIQUID then
6032 Values[Key] := _lc[I_PROP_TR_EFFECT_LLIQUID];
6033 if b = TRIGGER_EFFECT_DLIQUID then
6034 Values[Key] := _lc[I_PROP_TR_EFFECT_DLIQUID];
6035 if b = TRIGGER_EFFECT_BLOOD then
6036 Values[Key] := _lc[I_PROP_TR_EFFECT_BLOOD];
6037 if b = TRIGGER_EFFECT_SPARK then
6038 Values[Key] := _lc[I_PROP_TR_EFFECT_SPARK];
6039 if b = TRIGGER_EFFECT_BUBBLE then
6040 Values[Key] := _lc[I_PROP_TR_EFFECT_BUBBLE];
6041 end;
6043 vleObjectPropertyApply(Sender);
6044 end;
6045 end
6046 else if Key = _lc[I_PROP_TR_EFFECT_COLOR] then
6047 with vleObjectProperty do
6048 begin // Выбор цвета эффекта:
6049 ColorDialog.Color := StrToIntDef(Values[Key], 0);
6050 if ColorDialog.Execute then
6051 begin
6052 Values[Key] := IntToStr(ColorDialog.Color);
6053 vleObjectPropertyApply(Sender);
6054 end;
6055 end
6056 else if Key = _lc[I_PROP_PANEL_TEX] then
6057 begin // Смена текстуры:
6058 vleObjectProperty.Values[Key] := SelectedTexture();
6059 vleObjectPropertyApply(Sender);
6060 end;
6061 end;
6063 procedure TMainForm.vleObjectPropertyApply(Sender: TObject);
6064 begin
6065 // hack to prevent empty ID in list
6066 RenderPanel.SetFocus();
6067 bApplyProperty.Click();
6068 vleObjectProperty.SetFocus();
6069 end;
6071 procedure TMainForm.aSaveMapExecute(Sender: TObject);
6072 var
6073 FileName, Section, Res: String;
6074 begin
6075 if OpenedMap = '' then
6076 begin
6077 aSaveMapAsExecute(nil);
6078 Exit;
6079 end;
6081 g_ProcessResourceStr(OpenedMap, FileName, Section, Res);
6083 SaveMap(FileName+':\'+Res);
6084 end;
6086 procedure TMainForm.aOpenMapExecute(Sender: TObject);
6087 begin
6088 OpenDialog.Filter := _lc[I_FILE_FILTER_ALL];
6090 if OpenDialog.Execute() then
6091 begin
6092 OpenMapFile(OpenDialog.FileName);
6093 OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
6094 end;
6095 end;
6097 procedure TMainForm.OpenMapFile(FileName: String);
6098 begin
6099 if (Pos('.ini', LowerCase(ExtractFileName(FileName))) > 0) then
6100 begin // INI карты:
6101 FullClear();
6103 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
6104 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
6105 pLoadProgress.Show();
6107 OpenedMap := '';
6108 OpenedWAD := '';
6110 LoadMapOld(FileName);
6112 MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(FileName)]);
6114 pLoadProgress.Hide();
6115 MainForm.FormResize(Self);
6116 end
6117 else // Карты из WAD:
6118 begin
6119 OpenMap(FileName, '');
6120 end;
6121 end;
6123 procedure TMainForm.FormActivate(Sender: TObject);
6124 var
6125 lang: Integer;
6126 config: TConfig;
6127 begin
6128 MainForm.ActiveControl := RenderPanel;
6130 // Язык:
6131 if gLanguage = '' then
6132 begin
6133 lang := SelectLanguageForm.ShowModal();
6134 case lang of
6135 1: gLanguage := LANGUAGE_ENGLISH;
6136 else gLanguage := LANGUAGE_RUSSIAN;
6137 end;
6139 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
6140 config.WriteStr('Editor', 'Language', gLanguage);
6141 config.SaveFile(EditorDir+'Editor.cfg');
6142 config.Free();
6143 end;
6145 //e_WriteLog('Read language file', MSG_NOTIFY);
6146 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
6147 g_Language_Set(gLanguage);
6148 end;
6150 procedure TMainForm.aDeleteMap(Sender: TObject);
6151 var
6152 WAD: TWADEditor_1;
6153 MapList: SArray;
6154 MapName: Char16;
6155 a: Integer;
6156 str: String;
6157 begin
6158 OpenDialog.Filter := _lc[I_FILE_FILTER_WAD];
6160 if not OpenDialog.Execute() then
6161 Exit;
6163 WAD := TWADEditor_1.Create();
6165 if not WAD.ReadFile(OpenDialog.FileName) then
6166 begin
6167 WAD.Free();
6168 Exit;
6169 end;
6171 WAD.CreateImage();
6173 MapList := WAD.GetResourcesList('');
6175 SelectMapForm.Caption := _lc[I_CAP_REMOVE];
6176 SelectMapForm.lbMapList.Items.Clear();
6178 if MapList <> nil then
6179 for a := 0 to High(MapList) do
6180 SelectMapForm.lbMapList.Items.Add(win2utf(MapList[a]));
6182 if (SelectMapForm.ShowModal() = mrOK) then
6183 begin
6184 str := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
6185 MapName := '';
6186 Move(str[1], MapName[0], Min(16, Length(str)));
6188 if MessageBox(0, PChar(Format(_lc[I_MSG_DELETE_MAP_PROMT],
6189 [MapName, OpenDialog.FileName])),
6190 PChar(_lc[I_MSG_DELETE_MAP]),
6191 MB_ICONQUESTION or MB_YESNO or
6192 MB_DEFBUTTON2) <> mrYes then
6193 Exit;
6195 WAD.RemoveResource('', utf2win(MapName));
6197 MessageBox(0, PChar(Format(_lc[I_MSG_MAP_DELETED_PROMT],
6198 [MapName])),
6199 PChar(_lc[I_MSG_MAP_DELETED]),
6200 MB_ICONINFORMATION or MB_OK or
6201 MB_DEFBUTTON1);
6203 WAD.SaveTo(OpenDialog.FileName);
6205 // Удалили текущую карту - сохранять по старому ее нельзя:
6206 if OpenedMap = (OpenDialog.FileName+':\'+MapName) then
6207 begin
6208 OpenedMap := '';
6209 OpenedWAD := '';
6210 MainForm.Caption := FormCaption;
6211 end;
6212 end;
6214 WAD.Free();
6215 end;
6217 procedure TMainForm.vleObjectPropertyKeyDown(Sender: TObject;
6218 var Key: Word; Shift: TShiftState);
6219 begin
6220 if Key = VK_RETURN then
6221 vleObjectPropertyApply(Sender);
6222 end;
6224 procedure MovePanel(var ID: DWORD; MoveType: Byte);
6225 var
6226 _id, a: Integer;
6227 tmp: TPanel;
6228 begin
6229 if (ID = 0) and (MoveType = 0) then
6230 Exit;
6231 if (ID = DWORD(High(gPanels))) and (MoveType <> 0) then
6232 Exit;
6233 if (ID > DWORD(High(gPanels))) then
6234 Exit;
6236 _id := Integer(ID);
6238 if MoveType = 0 then // to Back
6239 begin
6240 if gTriggers <> nil then
6241 for a := 0 to High(gTriggers) do
6242 with gTriggers[a] do
6243 begin
6244 if TriggerType = TRIGGER_NONE then
6245 Continue;
6247 if TexturePanel = _id then
6248 TexturePanel := 0
6249 else
6250 if (TexturePanel >= 0) and (TexturePanel < _id) then
6251 Inc(TexturePanel);
6253 case TriggerType of
6254 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6255 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6256 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6257 if Data.PanelID = _id then
6258 Data.PanelID := 0
6259 else
6260 if (Data.PanelID >= 0) and (Data.PanelID < _id) then
6261 Inc(Data.PanelID);
6263 TRIGGER_SHOT:
6264 if Data.ShotPanelID = _id then
6265 Data.ShotPanelID := 0
6266 else
6267 if (Data.ShotPanelID >= 0) and (Data.ShotPanelID < _id) then
6268 Inc(Data.ShotPanelID);
6269 end;
6270 end;
6272 tmp := gPanels[_id];
6274 for a := _id downto 1 do
6275 gPanels[a] := gPanels[a-1];
6277 gPanels[0] := tmp;
6279 ID := 0;
6280 end
6281 else // to Front
6282 begin
6283 if gTriggers <> nil then
6284 for a := 0 to High(gTriggers) do
6285 with gTriggers[a] do
6286 begin
6287 if TriggerType = TRIGGER_NONE then
6288 Continue;
6290 if TexturePanel = _id then
6291 TexturePanel := High(gPanels)
6292 else
6293 if TexturePanel > _id then
6294 Dec(TexturePanel);
6296 case TriggerType of
6297 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6298 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6299 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6300 if Data.PanelID = _id then
6301 Data.PanelID := High(gPanels)
6302 else
6303 if Data.PanelID > _id then
6304 Dec(Data.PanelID);
6306 TRIGGER_SHOT:
6307 if Data.ShotPanelID = _id then
6308 Data.ShotPanelID := High(gPanels)
6309 else
6310 if Data.ShotPanelID > _id then
6311 Dec(Data.ShotPanelID);
6312 end;
6313 end;
6315 tmp := gPanels[_id];
6317 for a := _id to High(gPanels)-1 do
6318 gPanels[a] := gPanels[a+1];
6320 gPanels[High(gPanels)] := tmp;
6322 ID := High(gPanels);
6323 end;
6324 end;
6326 procedure TMainForm.aMoveToBack(Sender: TObject);
6327 var
6328 a: Integer;
6329 begin
6330 if SelectedObjects = nil then
6331 Exit;
6333 for a := 0 to High(SelectedObjects) do
6334 with SelectedObjects[a] do
6335 if Live and (ObjectType = OBJECT_PANEL) then
6336 begin
6337 SelectedObjects[0] := SelectedObjects[a];
6338 SetLength(SelectedObjects, 1);
6339 MovePanel(ID, 0);
6340 FillProperty();
6341 Break;
6342 end;
6343 end;
6345 procedure TMainForm.aMoveToFore(Sender: TObject);
6346 var
6347 a: Integer;
6348 begin
6349 if SelectedObjects = nil then
6350 Exit;
6352 for a := 0 to High(SelectedObjects) do
6353 with SelectedObjects[a] do
6354 if Live and (ObjectType = OBJECT_PANEL) then
6355 begin
6356 SelectedObjects[0] := SelectedObjects[a];
6357 SetLength(SelectedObjects, 1);
6358 MovePanel(ID, 1);
6359 FillProperty();
6360 Break;
6361 end;
6362 end;
6364 procedure TMainForm.aSaveMapAsExecute(Sender: TObject);
6365 var
6366 idx: Integer;
6367 begin
6368 SaveDialog.Filter := _lc[I_FILE_FILTER_WAD];
6370 if not SaveDialog.Execute() then
6371 Exit;
6373 SaveMapForm.GetMaps(SaveDialog.FileName, True);
6375 if SaveMapForm.ShowModal() <> mrOK then
6376 Exit;
6378 SaveDialog.InitialDir := ExtractFileDir(SaveDialog.FileName);
6379 OpenedMap := SaveDialog.FileName+':\'+SaveMapForm.eMapName.Text;
6380 OpenedWAD := SaveDialog.FileName;
6382 idx := RecentFiles.IndexOf(OpenedMap);
6383 // Такая карта уже недавно открывалась:
6384 if idx >= 0 then
6385 RecentFiles.Delete(idx);
6386 RecentFiles.Insert(0, OpenedMap);
6387 RefreshRecentMenu;
6389 SaveMap(OpenedMap);
6391 gMapInfo.FileName := SaveDialog.FileName;
6392 gMapInfo.MapName := SaveMapForm.eMapName.Text;
6393 UpdateCaption(gMapInfo.Name, ExtractFileName(gMapInfo.FileName), gMapInfo.MapName);
6394 end;
6396 procedure TMainForm.aSelectAllExecute(Sender: TObject);
6397 var
6398 a: Integer;
6399 begin
6400 RemoveSelectFromObjects();
6402 case pcObjects.ActivePageIndex+1 of
6403 OBJECT_PANEL:
6404 if gPanels <> nil then
6405 for a := 0 to High(gPanels) do
6406 if gPanels[a].PanelType <> PANEL_NONE then
6407 SelectObject(OBJECT_PANEL, a, True);
6408 OBJECT_ITEM:
6409 if gItems <> nil then
6410 for a := 0 to High(gItems) do
6411 if gItems[a].ItemType <> ITEM_NONE then
6412 SelectObject(OBJECT_ITEM, a, True);
6413 OBJECT_MONSTER:
6414 if gMonsters <> nil then
6415 for a := 0 to High(gMonsters) do
6416 if gMonsters[a].MonsterType <> MONSTER_NONE then
6417 SelectObject(OBJECT_MONSTER, a, True);
6418 OBJECT_AREA:
6419 if gAreas <> nil then
6420 for a := 0 to High(gAreas) do
6421 if gAreas[a].AreaType <> AREA_NONE then
6422 SelectObject(OBJECT_AREA, a, True);
6423 OBJECT_TRIGGER:
6424 if gTriggers <> nil then
6425 for a := 0 to High(gTriggers) do
6426 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6427 SelectObject(OBJECT_TRIGGER, a, True);
6428 end;
6430 RecountSelectedObjects();
6431 end;
6433 procedure TMainForm.tbGridOnClick(Sender: TObject);
6434 begin
6435 DotEnable := not DotEnable;
6436 (Sender as TToolButton).Down := DotEnable;
6437 end;
6439 procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean);
6440 begin
6441 // FIXME: this is a shitty hack
6442 if not gDataLoaded then
6443 begin
6444 e_WriteLog('Init OpenGL', MSG_NOTIFY);
6445 e_InitGL();
6446 e_WriteLog('Loading data', MSG_NOTIFY);
6447 LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
6448 e_WriteLog('Loading more data', MSG_NOTIFY);
6449 LoadData();
6450 e_WriteLog('Loading even more data', MSG_NOTIFY);
6451 gDataLoaded := True;
6452 MainForm.FormResize(nil);
6453 end;
6454 Draw();
6455 end;
6457 procedure TMainForm.miMapPreviewClick(Sender: TObject);
6458 begin
6459 if PreviewMode = 2 then
6460 Exit;
6462 if PreviewMode = 0 then
6463 begin
6464 Splitter2.Visible := False;
6465 Splitter1.Visible := False;
6466 StatusBar.Visible := False;
6467 PanelObjs.Visible := False;
6468 PanelProps.Visible := False;
6469 MainToolBar.Visible := False;
6470 sbHorizontal.Visible := False;
6471 sbVertical.Visible := False;
6472 end
6473 else
6474 begin
6475 StatusBar.Visible := True;
6476 PanelObjs.Visible := True;
6477 PanelProps.Visible := True;
6478 Splitter2.Visible := True;
6479 Splitter1.Visible := True;
6480 MainToolBar.Visible := True;
6481 sbHorizontal.Visible := True;
6482 sbVertical.Visible := True;
6483 end;
6485 PreviewMode := PreviewMode xor 1;
6486 (Sender as TMenuItem).Checked := PreviewMode > 0;
6488 FormResize(Self);
6489 end;
6491 procedure TMainForm.miLayer1Click(Sender: TObject);
6492 begin
6493 SwitchLayer(LAYER_BACK);
6494 end;
6496 procedure TMainForm.miLayer2Click(Sender: TObject);
6497 begin
6498 SwitchLayer(LAYER_WALLS);
6499 end;
6501 procedure TMainForm.miLayer3Click(Sender: TObject);
6502 begin
6503 SwitchLayer(LAYER_FOREGROUND);
6504 end;
6506 procedure TMainForm.miLayer4Click(Sender: TObject);
6507 begin
6508 SwitchLayer(LAYER_STEPS);
6509 end;
6511 procedure TMainForm.miLayer5Click(Sender: TObject);
6512 begin
6513 SwitchLayer(LAYER_WATER);
6514 end;
6516 procedure TMainForm.miLayer6Click(Sender: TObject);
6517 begin
6518 SwitchLayer(LAYER_ITEMS);
6519 end;
6521 procedure TMainForm.miLayer7Click(Sender: TObject);
6522 begin
6523 SwitchLayer(LAYER_MONSTERS);
6524 end;
6526 procedure TMainForm.miLayer8Click(Sender: TObject);
6527 begin
6528 SwitchLayer(LAYER_AREAS);
6529 end;
6531 procedure TMainForm.miLayer9Click(Sender: TObject);
6532 begin
6533 SwitchLayer(LAYER_TRIGGERS);
6534 end;
6536 procedure TMainForm.tbShowClick(Sender: TObject);
6537 var
6538 a: Integer;
6539 b: Boolean;
6540 begin
6541 b := True;
6542 for a := 0 to High(LayerEnabled) do
6543 b := b and LayerEnabled[a];
6545 b := not b;
6547 ShowLayer(LAYER_BACK, b);
6548 ShowLayer(LAYER_WALLS, b);
6549 ShowLayer(LAYER_FOREGROUND, b);
6550 ShowLayer(LAYER_STEPS, b);
6551 ShowLayer(LAYER_WATER, b);
6552 ShowLayer(LAYER_ITEMS, b);
6553 ShowLayer(LAYER_MONSTERS, b);
6554 ShowLayer(LAYER_AREAS, b);
6555 ShowLayer(LAYER_TRIGGERS, b);
6556 end;
6558 procedure TMainForm.miMiniMapClick(Sender: TObject);
6559 begin
6560 SwitchMap();
6561 end;
6563 procedure TMainForm.miSwitchGridClick(Sender: TObject);
6564 begin
6565 if DotStep = DotStepOne then
6566 DotStep := DotStepTwo
6567 else
6568 DotStep := DotStepOne;
6570 MousePos.X := (MousePos.X div DotStep) * DotStep;
6571 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6572 end;
6574 procedure TMainForm.miShowEdgesClick(Sender: TObject);
6575 begin
6576 ShowEdges();
6577 end;
6579 procedure TMainForm.miSnapToGridClick(Sender: TObject);
6580 begin
6581 SnapToGrid := not SnapToGrid;
6583 MousePos.X := (MousePos.X div DotStep) * DotStep;
6584 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6586 miSnapToGrid.Checked := SnapToGrid;
6587 end;
6589 procedure TMainForm.minexttabClick(Sender: TObject);
6590 begin
6591 if pcObjects.ActivePageIndex < pcObjects.PageCount-1 then
6592 pcObjects.ActivePageIndex := pcObjects.ActivePageIndex+1
6593 else
6594 pcObjects.ActivePageIndex := 0;
6595 end;
6597 procedure TMainForm.miSaveMiniMapClick(Sender: TObject);
6598 begin
6599 SaveMiniMapForm.ShowModal();
6600 end;
6602 procedure TMainForm.bClearTextureClick(Sender: TObject);
6603 begin
6604 lbTextureList.ItemIndex := -1;
6605 lTextureWidth.Caption := '';
6606 lTextureHeight.Caption := '';
6607 end;
6609 procedure TMainForm.miPackMapClick(Sender: TObject);
6610 begin
6611 PackMapForm.ShowModal();
6612 end;
6614 procedure TMainForm.miMapTestSettingsClick(Sender: TObject);
6615 begin
6616 MapTestForm.ShowModal();
6617 end;
6619 procedure TMainForm.miTestMapClick(Sender: TObject);
6620 var
6621 cmd, mapWAD, mapToRun, tempWAD: String;
6622 opt: LongWord;
6623 time: Integer;
6624 proc: TProcessUTF8;
6625 res: Boolean;
6626 begin
6627 mapToRun := '';
6628 if OpenedMap <> '' then
6629 begin
6630 // Указываем текущую карту для теста:
6631 g_ProcessResourceStr(OpenedMap, @mapWAD, nil, @mapToRun);
6632 mapToRun := mapWAD + ':\' + mapToRun;
6633 mapToRun := ExtractRelativePath(ExtractFilePath(TestD2dExe) + 'maps/', mapToRun);
6634 end;
6635 // Сохраняем временную карту:
6636 time := 0;
6637 repeat
6638 mapWAD := ExtractFilePath(TestD2dExe) + Format('maps/temp%.4d.wad', [time]);
6639 Inc(time);
6640 until not FileExists(mapWAD);
6641 tempWAD := mapWAD + ':\' + TEST_MAP_NAME;
6642 SaveMap(tempWAD);
6644 tempWAD := ExtractRelativePath(ExtractFilePath(TestD2dExe) + 'maps/', tempWAD);
6645 // Если карта не была открыта, указываем временную в качестве текущей:
6646 if mapToRun = '' then
6647 mapToRun := tempWAD;
6649 // Опции игры:
6650 opt := 32 + 64;
6651 if TestOptionsTwoPlayers then
6652 opt := opt + 1;
6653 if TestOptionsTeamDamage then
6654 opt := opt + 2;
6655 if TestOptionsAllowExit then
6656 opt := opt + 4;
6657 if TestOptionsWeaponStay then
6658 opt := opt + 8;
6659 if TestOptionsMonstersDM then
6660 opt := opt + 16;
6662 // Составляем командную строку:
6663 cmd := '-map "' + mapToRun + '"';
6664 cmd := cmd + ' -testmap "' + tempWAD + '"';
6665 cmd := cmd + ' -gm ' + TestGameMode;
6666 cmd := cmd + ' -limt ' + TestLimTime;
6667 cmd := cmd + ' -lims ' + TestLimScore;
6668 cmd := cmd + ' -opt ' + IntToStr(opt);
6670 if TestMapOnce then
6671 cmd := cmd + ' --close';
6673 cmd := cmd + ' --debug';
6675 // Запускаем:
6676 proc := TProcessUTF8.Create(nil);
6677 proc.Executable := TestD2dExe;
6678 proc.Parameters.Add(cmd);
6679 res := True;
6680 try
6681 proc.Execute();
6682 except
6683 res := False;
6684 end;
6685 if res then
6686 begin
6687 Application.Minimize();
6688 proc.WaitOnExit();
6689 end;
6690 if (not res) or (proc.ExitCode < 0) then
6691 begin
6692 MessageBox(0, 'FIXME',
6693 PChar(_lc[I_MSG_EXEC_ERROR]),
6694 MB_OK or MB_ICONERROR);
6695 end;
6696 proc.Free();
6698 SysUtils.DeleteFile(mapWAD);
6699 Application.Restore();
6700 end;
6702 procedure TMainForm.sbVerticalScroll(Sender: TObject;
6703 ScrollCode: TScrollCode; var ScrollPos: Integer);
6704 begin
6705 MapOffset.Y := -Normalize16(sbVertical.Position);
6706 end;
6708 procedure TMainForm.sbHorizontalScroll(Sender: TObject;
6709 ScrollCode: TScrollCode; var ScrollPos: Integer);
6710 begin
6711 MapOffset.X := -Normalize16(sbHorizontal.Position);
6712 end;
6714 procedure TMainForm.miOpenWadMapClick(Sender: TObject);
6715 begin
6716 if OpenedWAD <> '' then
6717 begin
6718 OpenMap(OpenedWAD, '');
6719 end;
6720 end;
6722 procedure TMainForm.selectall1Click(Sender: TObject);
6723 var
6724 a: Integer;
6725 begin
6726 RemoveSelectFromObjects();
6728 if gPanels <> nil then
6729 for a := 0 to High(gPanels) do
6730 if gPanels[a].PanelType <> PANEL_NONE then
6731 SelectObject(OBJECT_PANEL, a, True);
6733 if gItems <> nil then
6734 for a := 0 to High(gItems) do
6735 if gItems[a].ItemType <> ITEM_NONE then
6736 SelectObject(OBJECT_ITEM, a, True);
6738 if gMonsters <> nil then
6739 for a := 0 to High(gMonsters) do
6740 if gMonsters[a].MonsterType <> MONSTER_NONE then
6741 SelectObject(OBJECT_MONSTER, a, True);
6743 if gAreas <> nil then
6744 for a := 0 to High(gAreas) do
6745 if gAreas[a].AreaType <> AREA_NONE then
6746 SelectObject(OBJECT_AREA, a, True);
6748 if gTriggers <> nil then
6749 for a := 0 to High(gTriggers) do
6750 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6751 SelectObject(OBJECT_TRIGGER, a, True);
6753 RecountSelectedObjects();
6754 end;
6756 procedure TMainForm.Splitter1CanResize(Sender: TObject;
6757 var NewSize: Integer; var Accept: Boolean);
6758 begin
6759 Accept := (NewSize > 140);
6760 end;
6762 procedure TMainForm.Splitter2CanResize(Sender: TObject;
6763 var NewSize: Integer; var Accept: Boolean);
6764 begin
6765 Accept := (NewSize > 110);
6766 end;
6768 procedure TMainForm.vleObjectPropertyEnter(Sender: TObject);
6769 begin
6770 EditingProperties := True;
6771 end;
6773 procedure TMainForm.vleObjectPropertyExit(Sender: TObject);
6774 begin
6775 EditingProperties := False;
6776 end;
6778 procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
6779 Shift: TShiftState);
6780 begin
6781 // Объекты передвигались:
6782 if MainForm.ActiveControl = RenderPanel then
6783 begin
6784 if (Key = VK_NUMPAD4) or
6785 (Key = VK_NUMPAD6) or
6786 (Key = VK_NUMPAD8) or
6787 (Key = VK_NUMPAD5) or
6788 (Key = Ord('V')) then
6789 FillProperty();
6790 end;
6791 // Быстрое превью карты:
6792 if Key = Ord('E') then
6793 begin
6794 if PreviewMode = 2 then
6795 PreviewMode := 0;
6796 end;
6797 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
6798 end;
6800 end.