DEADSOFTWARE

Two small additional fixes for Lazarus
[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 end;
272 const
273 LAYER_BACK = 0;
274 LAYER_WALLS = 1;
275 LAYER_FOREGROUND = 2;
276 LAYER_STEPS = 3;
277 LAYER_WATER = 4;
278 LAYER_ITEMS = 5;
279 LAYER_MONSTERS = 6;
280 LAYER_AREAS = 7;
281 LAYER_TRIGGERS = 8;
283 TEST_MAP_NAME = '$$$_TEST_$$$';
284 LANGUAGE_FILE_NAME = '_Editor.txt';
286 var
287 MainForm: TMainForm;
288 EditorDir: String;
289 OpenedMap: String;
290 OpenedWAD: String;
292 DotColor: TColor;
293 DotEnable: Boolean;
294 DotStep: Byte;
295 DotStepOne, DotStepTwo: Byte;
296 DotSize: Byte;
297 DrawTexturePanel: Boolean;
298 DrawPanelSize: Boolean;
299 BackColor: TColor;
300 PreviewColor: TColor;
301 UseCheckerboard: Boolean;
302 Scale: Byte;
303 RecentCount: Integer;
304 RecentFiles: TStringList;
305 slInvalidTextures: TStringList;
307 TestGameMode: String;
308 TestLimTime: String;
309 TestLimScore: String;
310 TestOptionsTwoPlayers: Boolean;
311 TestOptionsTeamDamage: Boolean;
312 TestOptionsAllowExit: Boolean;
313 TestOptionsWeaponStay: Boolean;
314 TestOptionsMonstersDM: Boolean;
315 TestD2dExe: String;
316 TestMapOnce: Boolean;
318 LayerEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
319 (True, True, True, True, True, True, True, True, True);
320 PreviewMode: Byte = 0;
321 gLanguage: String;
323 FormCaption: String;
326 procedure OpenMap(FileName: String; mapN: String);
327 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
328 procedure RemoveSelectFromObjects();
329 procedure ChangeShownProperty(Name: String; NewValue: String);
331 implementation
333 uses
334 f_options, e_graphics, e_log, GL, Math,
335 f_mapoptions, g_basic, f_about, f_mapoptimization,
336 f_mapcheck, f_addresource_texture, g_textures,
337 f_activationtype, f_keys,
338 MAPREADER, f_selectmap, f_savemap, WADEDITOR, WADSTRUCT, MAPDEF,
339 g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
340 f_addresource_sound, f_maptest, f_choosetype,
341 g_language, f_selectlang, ClipBrd;
343 const
344 UNDO_DELETE_PANEL = 1;
345 UNDO_DELETE_ITEM = 2;
346 UNDO_DELETE_AREA = 3;
347 UNDO_DELETE_MONSTER = 4;
348 UNDO_DELETE_TRIGGER = 5;
349 UNDO_ADD_PANEL = 6;
350 UNDO_ADD_ITEM = 7;
351 UNDO_ADD_AREA = 8;
352 UNDO_ADD_MONSTER = 9;
353 UNDO_ADD_TRIGGER = 10;
354 UNDO_MOVE_PANEL = 11;
355 UNDO_MOVE_ITEM = 12;
356 UNDO_MOVE_AREA = 13;
357 UNDO_MOVE_MONSTER = 14;
358 UNDO_MOVE_TRIGGER = 15;
359 UNDO_RESIZE_PANEL = 16;
360 UNDO_RESIZE_TRIGGER = 17;
362 MOUSEACTION_NONE = 0;
363 MOUSEACTION_DRAWPANEL = 1;
364 MOUSEACTION_DRAWTRIGGER = 2;
365 MOUSEACTION_MOVEOBJ = 3;
366 MOUSEACTION_RESIZE = 4;
367 MOUSEACTION_MOVEMAP = 5;
368 MOUSEACTION_DRAWPRESS = 6;
369 MOUSEACTION_NOACTION = 7;
371 RESIZETYPE_NONE = 0;
372 RESIZETYPE_VERTICAL = 1;
373 RESIZETYPE_HORIZONTAL = 2;
375 RESIZEDIR_NONE = 0;
376 RESIZEDIR_DOWN = 1;
377 RESIZEDIR_UP = 2;
378 RESIZEDIR_RIGHT = 3;
379 RESIZEDIR_LEFT = 4;
381 SELECTFLAG_NONE = 0;
382 SELECTFLAG_TELEPORT = 1;
383 SELECTFLAG_DOOR = 2;
384 SELECTFLAG_TEXTURE = 3;
385 SELECTFLAG_LIFT = 4;
386 SELECTFLAG_MONSTER = 5;
387 SELECTFLAG_SPAWNPOINT = 6;
388 SELECTFLAG_SHOTPANEL = 7;
389 SELECTFLAG_SELECTED = 8;
391 RECENT_FILES_MENU_START = 12;
393 CLIPBOARD_SIG = 'DF:ED';
395 type
396 TUndoRec = record
397 UndoType: Byte;
398 case Byte of
399 UNDO_DELETE_PANEL: (Panel: ^TPanel);
400 UNDO_DELETE_ITEM: (Item: TItem);
401 UNDO_DELETE_AREA: (Area: TArea);
402 UNDO_DELETE_MONSTER: (Monster: TMonster);
403 UNDO_DELETE_TRIGGER: (Trigger: TTrigger);
404 UNDO_ADD_PANEL,
405 UNDO_ADD_ITEM,
406 UNDO_ADD_AREA,
407 UNDO_ADD_MONSTER,
408 UNDO_ADD_TRIGGER: (AddID: DWORD);
409 UNDO_MOVE_PANEL,
410 UNDO_MOVE_ITEM,
411 UNDO_MOVE_AREA,
412 UNDO_MOVE_MONSTER,
413 UNDO_MOVE_TRIGGER: (MoveID: DWORD; dX, dY: Integer);
414 UNDO_RESIZE_PANEL,
415 UNDO_RESIZE_TRIGGER: (ResizeID: DWORD; dW, dH: Integer);
416 end;
418 TCopyRec = record
419 ObjectType: Byte;
420 ID: Cardinal;
421 case Byte of
422 OBJECT_PANEL: (Panel: ^TPanel);
423 OBJECT_ITEM: (Item: TItem);
424 OBJECT_AREA: (Area: TArea);
425 OBJECT_MONSTER: (Monster: TMonster);
426 OBJECT_TRIGGER: (Trigger: TTrigger);
427 end;
429 TCopyRecArray = Array of TCopyRec;
431 var
432 gEditorFont: DWORD;
433 gDataLoaded: Boolean = False;
434 ShowMap: Boolean = False;
435 DrawRect: PRect = nil;
436 SnapToGrid: Boolean = True;
438 MousePos: Types.TPoint;
439 LastMovePoint: Types.TPoint;
440 MouseLDown: Boolean;
441 MouseRDown: Boolean;
442 MouseLDownPos: Types.TPoint;
443 MouseRDownPos: Types.TPoint;
444 WASDOffset: TPoint;
446 SelectFlag: Byte = SELECTFLAG_NONE;
447 MouseAction: Byte = MOUSEACTION_NONE;
448 ResizeType: Byte = RESIZETYPE_NONE;
449 ResizeDirection: Byte = RESIZEDIR_NONE;
451 DrawPressRect: Boolean = False;
452 EditingProperties: Boolean = False;
454 UndoBuffer: Array of Array of TUndoRec = nil;
457 {$R *.lfm}
459 //----------------------------------------
460 //Далее идут вспомогательные процедуры
461 //----------------------------------------
463 function NameToBool(Name: String): Boolean;
464 begin
465 if Name = BoolNames[True] then
466 Result := True
467 else
468 Result := False;
469 end;
471 function NameToDir(Name: String): TDirection;
472 begin
473 if Name = DirNames[D_LEFT] then
474 Result := D_LEFT
475 else
476 Result := D_RIGHT;
477 end;
479 function NameToDirAdv(Name: String): Byte;
480 begin
481 if Name = DirNamesAdv[1] then
482 Result := 1
483 else
484 if Name = DirNamesAdv[2] then
485 Result := 2
486 else
487 if Name = DirNamesAdv[3] then
488 Result := 3
489 else
490 Result := 0;
491 end;
493 function ActivateToStr(ActivateType: Byte): String;
494 begin
495 Result := '';
497 if ByteBool(ACTIVATE_PLAYERCOLLIDE and ActivateType) then
498 Result := Result + '+PC';
499 if ByteBool(ACTIVATE_MONSTERCOLLIDE and ActivateType) then
500 Result := Result + '+MC';
501 if ByteBool(ACTIVATE_PLAYERPRESS and ActivateType) then
502 Result := Result + '+PP';
503 if ByteBool(ACTIVATE_MONSTERPRESS and ActivateType) then
504 Result := Result + '+MP';
505 if ByteBool(ACTIVATE_SHOT and ActivateType) then
506 Result := Result + '+SH';
507 if ByteBool(ACTIVATE_NOMONSTER and ActivateType) then
508 Result := Result + '+NM';
510 if (Result <> '') and (Result[1] = '+') then
511 Delete(Result, 1, 1);
512 end;
514 function StrToActivate(Str: String): Byte;
515 begin
516 Result := 0;
518 if Pos('PC', Str) > 0 then
519 Result := ACTIVATE_PLAYERCOLLIDE;
520 if Pos('MC', Str) > 0 then
521 Result := Result or ACTIVATE_MONSTERCOLLIDE;
522 if Pos('PP', Str) > 0 then
523 Result := Result or ACTIVATE_PLAYERPRESS;
524 if Pos('MP', Str) > 0 then
525 Result := Result or ACTIVATE_MONSTERPRESS;
526 if Pos('SH', Str) > 0 then
527 Result := Result or ACTIVATE_SHOT;
528 if Pos('NM', Str) > 0 then
529 Result := Result or ACTIVATE_NOMONSTER;
530 end;
532 function KeyToStr(Key: Byte): String;
533 begin
534 Result := '';
536 if ByteBool(KEY_RED and Key) then
537 Result := Result + '+RK';
538 if ByteBool(KEY_GREEN and Key) then
539 Result := Result + '+GK';
540 if ByteBool(KEY_BLUE and Key) then
541 Result := Result + '+BK';
542 if ByteBool(KEY_REDTEAM and Key) then
543 Result := Result + '+RT';
544 if ByteBool(KEY_BLUETEAM and Key) then
545 Result := Result + '+BT';
547 if (Result <> '') and (Result[1] = '+') then
548 Delete(Result, 1, 1);
549 end;
551 function StrToKey(Str: String): Byte;
552 begin
553 Result := 0;
555 if Pos('RK', Str) > 0 then
556 Result := KEY_RED;
557 if Pos('GK', Str) > 0 then
558 Result := Result or KEY_GREEN;
559 if Pos('BK', Str) > 0 then
560 Result := Result or KEY_BLUE;
561 if Pos('RT', Str) > 0 then
562 Result := Result or KEY_REDTEAM;
563 if Pos('BT', Str) > 0 then
564 Result := Result or KEY_BLUETEAM;
565 end;
567 function EffectToStr(Effect: Byte): String;
568 begin
569 if Effect in [EFFECT_TELEPORT..EFFECT_FIRE] then
570 Result := EffectNames[Effect]
571 else
572 Result := EffectNames[EFFECT_NONE];
573 end;
575 function StrToEffect(Str: String): Byte;
576 var
577 i: Integer;
578 begin
579 Result := EFFECT_NONE;
580 for i := EFFECT_TELEPORT to EFFECT_FIRE do
581 if EffectNames[i] = Str then
582 begin
583 Result := i;
584 Exit;
585 end;
586 end;
588 function MonsterToStr(MonType: Byte): String;
589 begin
590 if MonType in [MONSTER_DEMON..MONSTER_MAN] then
591 Result := MonsterNames[MonType]
592 else
593 Result := MonsterNames[MONSTER_ZOMBY];
594 end;
596 function StrToMonster(Str: String): Byte;
597 var
598 i: Integer;
599 begin
600 Result := MONSTER_ZOMBY;
601 for i := MONSTER_DEMON to MONSTER_MAN do
602 if MonsterNames[i] = Str then
603 begin
604 Result := i;
605 Exit;
606 end;
607 end;
609 function ItemToStr(ItemType: Byte): String;
610 begin
611 if ItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX] then
612 Result := ItemNames[ItemType]
613 else
614 Result := ItemNames[ITEM_AMMO_BULLETS];
615 end;
617 function StrToItem(Str: String): Byte;
618 var
619 i: Integer;
620 begin
621 Result := ITEM_AMMO_BULLETS;
622 for i := ITEM_MEDKIT_SMALL to ITEM_MAX do
623 if ItemNames[i] = Str then
624 begin
625 Result := i;
626 Exit;
627 end;
628 end;
630 function ShotToStr(ShotType: Byte): String;
631 begin
632 if ShotType in [TRIGGER_SHOT_PISTOL..TRIGGER_SHOT_MAX] then
633 Result := ShotNames[ShotType]
634 else
635 Result := ShotNames[TRIGGER_SHOT_PISTOL];
636 end;
638 function StrToShot(Str: String): Byte;
639 var
640 i: Integer;
641 begin
642 Result := TRIGGER_SHOT_PISTOL;
643 for i := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
644 if ShotNames[i] = Str then
645 begin
646 Result := i;
647 Exit;
648 end;
649 end;
651 function SelectedObjectCount(): Word;
652 var
653 a: Integer;
654 begin
655 Result := 0;
657 if SelectedObjects = nil then
658 Exit;
660 for a := 0 to High(SelectedObjects) do
661 if SelectedObjects[a].Live then
662 Result := Result + 1;
663 end;
665 function GetFirstSelected(): Integer;
666 var
667 a: Integer;
668 begin
669 Result := -1;
671 if SelectedObjects = nil then
672 Exit;
674 for a := 0 to High(SelectedObjects) do
675 if SelectedObjects[a].Live then
676 begin
677 Result := a;
678 Exit;
679 end;
680 end;
682 function Normalize16(x: Integer): Integer;
683 begin
684 Result := (x div 16) * 16;
685 end;
687 procedure MoveMap(X, Y: Integer);
688 var
689 rx, ry, ScaleSz: Integer;
690 begin
691 with MainForm.RenderPanel do
692 begin
693 ScaleSz := 16 div Scale;
694 // Размер видимой части карты:
695 rx := min(Normalize16(Width), Normalize16(gMapInfo.Width)) div 2;
696 ry := min(Normalize16(Height), Normalize16(gMapInfo.Height)) div 2;
697 // Место клика на мини-карте:
698 MapOffset.X := X - (Width-max(gMapInfo.Width div ScaleSz, 1)-1);
699 MapOffset.Y := Y - 1;
700 // Это же место на "большой" карте:
701 MapOffset.X := MapOffset.X * ScaleSz;
702 MapOffset.Y := MapOffset.Y * ScaleSz;
703 // Левый верхний угол новой видимой части карты:
704 MapOffset.X := MapOffset.X - rx;
705 MapOffset.Y := MapOffset.Y - ry;
706 // Выход за границы:
707 if MapOffset.X < 0 then
708 MapOffset.X := 0;
709 if MapOffset.Y < 0 then
710 MapOffset.Y := 0;
711 if MapOffset.X > MainForm.sbHorizontal.Max then
712 MapOffset.X := MainForm.sbHorizontal.Max;
713 if MapOffset.Y > MainForm.sbVertical.Max then
714 MapOffset.Y := MainForm.sbVertical.Max;
715 // Кратно 16:
716 MapOffset.X := Normalize16(MapOffset.X);
717 MapOffset.Y := Normalize16(MapOffset.Y);
718 end;
720 MainForm.sbHorizontal.Position := MapOffset.X;
721 MainForm.sbVertical.Position := MapOffset.Y;
723 MapOffset.X := -MapOffset.X;
724 MapOffset.Y := -MapOffset.Y;
726 MainForm.Resize();
727 end;
729 function IsTexturedPanel(PanelType: Word): Boolean;
730 begin
731 Result := WordBool(PanelType and (PANEL_WALL or PANEL_BACK or PANEL_FORE or
732 PANEL_STEP or PANEL_OPENDOOR or PANEL_CLOSEDOOR or
733 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2));
734 end;
736 procedure FillProperty();
737 var
738 _id: DWORD;
739 str: String;
740 begin
741 MainForm.vleObjectProperty.Strings.Clear();
743 // Отображаем свойства если выделен только один объект:
744 if SelectedObjectCount() <> 1 then
745 Exit;
747 _id := GetFirstSelected();
748 if not SelectedObjects[_id].Live then
749 Exit;
751 with MainForm.vleObjectProperty do
752 with ItemProps[InsertRow(_lc[I_PROP_ID], IntToStr(SelectedObjects[_id].ID), True)] do
753 begin
754 EditStyle := esSimple;
755 ReadOnly := True;
756 end;
758 case SelectedObjects[0].ObjectType of
759 OBJECT_PANEL:
760 begin
761 with MainForm.vleObjectProperty,
762 gPanels[SelectedObjects[_id].ID] do
763 begin
764 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
765 begin
766 EditStyle := esSimple;
767 MaxLength := 5;
768 end;
770 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
771 begin
772 EditStyle := esSimple;
773 MaxLength := 5;
774 end;
776 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
777 begin
778 EditStyle := esSimple;
779 MaxLength := 5;
780 end;
782 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
783 begin
784 EditStyle := esSimple;
785 MaxLength := 5;
786 end;
788 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TYPE], GetPanelName(PanelType), True)] do
789 begin
790 EditStyle := esEllipsis;
791 ReadOnly := True;
792 end;
794 if IsTexturedPanel(PanelType) then
795 begin // Может быть текстура
796 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TEX], TextureName, True)] do
797 begin
798 EditStyle := esEllipsis;
799 ReadOnly := True;
800 end;
802 if TextureName <> '' then
803 begin // Есть текстура
804 with ItemProps[InsertRow(_lc[I_PROP_PANEL_ALPHA], IntToStr(Alpha), True)] do
805 begin
806 EditStyle := esSimple;
807 MaxLength := 3;
808 end;
810 with ItemProps[InsertRow(_lc[I_PROP_PANEL_BLEND], BoolNames[Blending], True)] do
811 begin
812 EditStyle := esPickList;
813 ReadOnly := True;
814 end;
815 end;
816 end;
817 end;
818 end;
820 OBJECT_ITEM:
821 begin
822 with MainForm.vleObjectProperty,
823 gItems[SelectedObjects[_id].ID] do
824 begin
825 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
826 begin
827 EditStyle := esSimple;
828 MaxLength := 5;
829 end;
831 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
832 begin
833 EditStyle := esSimple;
834 MaxLength := 5;
835 end;
837 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[OnlyDM], True)] do
838 begin
839 EditStyle := esPickList;
840 ReadOnly := True;
841 end;
843 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Fall], True)] do
844 begin
845 EditStyle := esPickList;
846 ReadOnly := True;
847 end;
848 end;
849 end;
851 OBJECT_MONSTER:
852 begin
853 with MainForm.vleObjectProperty,
854 gMonsters[SelectedObjects[_id].ID] do
855 begin
856 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
857 begin
858 EditStyle := esSimple;
859 MaxLength := 5;
860 end;
862 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
863 begin
864 EditStyle := esSimple;
865 MaxLength := 5;
866 end;
868 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
869 begin
870 EditStyle := esPickList;
871 ReadOnly := True;
872 end;
873 end;
874 end;
876 OBJECT_AREA:
877 begin
878 with MainForm.vleObjectProperty,
879 gAreas[SelectedObjects[_id].ID] do
880 begin
881 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
882 begin
883 EditStyle := esSimple;
884 MaxLength := 5;
885 end;
887 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
888 begin
889 EditStyle := esSimple;
890 MaxLength := 5;
891 end;
893 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
894 begin
895 EditStyle := esPickList;
896 ReadOnly := True;
897 end;
898 end;
899 end;
901 OBJECT_TRIGGER:
902 begin
903 with MainForm.vleObjectProperty,
904 gTriggers[SelectedObjects[_id].ID] do
905 begin
906 with ItemProps[InsertRow(_lc[I_PROP_TR_TYPE], GetTriggerName(TriggerType), True)] do
907 begin
908 EditStyle := esSimple;
909 ReadOnly := True;
910 end;
912 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
913 begin
914 EditStyle := esSimple;
915 MaxLength := 5;
916 end;
918 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
919 begin
920 EditStyle := esSimple;
921 MaxLength := 5;
922 end;
924 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
925 begin
926 EditStyle := esSimple;
927 MaxLength := 5;
928 end;
930 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
931 begin
932 EditStyle := esSimple;
933 MaxLength := 5;
934 end;
936 with ItemProps[InsertRow(_lc[I_PROP_TR_ENABLED], BoolNames[Enabled], True)] do
937 begin
938 EditStyle := esPickList;
939 ReadOnly := True;
940 end;
942 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_PANEL], IntToStr(TexturePanel), True)] do
943 begin
944 EditStyle := esEllipsis;
945 ReadOnly := True;
946 end;
948 with ItemProps[InsertRow(_lc[I_PROP_TR_ACTIVATION], ActivateToStr(ActivateType), True)] do
949 begin
950 EditStyle := esEllipsis;
951 ReadOnly := True;
952 end;
954 with ItemProps[InsertRow(_lc[I_PROP_TR_KEYS], KeyToStr(Key), True)] do
955 begin
956 EditStyle := esEllipsis;
957 ReadOnly := True;
958 end;
960 case TriggerType of
961 TRIGGER_EXIT:
962 begin
963 str := win2utf(Data.MapName);
964 with ItemProps[InsertRow(_lc[I_PROP_TR_NEXT_MAP], str, True)] do
965 begin
966 EditStyle := esEllipsis;
967 ReadOnly := True;
968 end;
969 end;
971 TRIGGER_TELEPORT:
972 begin
973 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_TO], Format('(%d:%d)', [Data.TargetPoint.X, Data.TargetPoint.Y]), True)] do
974 begin
975 EditStyle := esEllipsis;
976 ReadOnly := True;
977 end;
979 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_teleport], True)] do
980 begin
981 EditStyle := esPickList;
982 ReadOnly := True;
983 end;
985 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_SILENT], BoolNames[Data.silent_teleport], True)] do
986 begin
987 EditStyle := esPickList;
988 ReadOnly := True;
989 end;
991 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_DIR], DirNamesAdv[Data.TlpDir], True)] do
992 begin
993 EditStyle := esPickList;
994 ReadOnly := True;
995 end;
996 end;
998 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR,
999 TRIGGER_DOOR, TRIGGER_DOOR5:
1000 begin
1001 with ItemProps[InsertRow(_lc[I_PROP_TR_DOOR_PANEL], IntToStr(Data.PanelID), True)] do
1002 begin
1003 EditStyle := esEllipsis;
1004 ReadOnly := True;
1005 end;
1007 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1008 begin
1009 EditStyle := esPickList;
1010 ReadOnly := True;
1011 end;
1013 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1014 begin
1015 EditStyle := esPickList;
1016 ReadOnly := True;
1017 end;
1018 end;
1020 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1021 begin
1022 with ItemProps[InsertRow(_lc[I_PROP_TR_TRAP_PANEL], IntToStr(Data.PanelID), True)] do
1023 begin
1024 EditStyle := esEllipsis;
1025 ReadOnly := True;
1026 end;
1028 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1029 begin
1030 EditStyle := esPickList;
1031 ReadOnly := True;
1032 end;
1034 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1035 begin
1036 EditStyle := esPickList;
1037 ReadOnly := True;
1038 end;
1039 end;
1041 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
1042 TRIGGER_ONOFF:
1043 begin
1044 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_AREA],
1045 Format('(%d:%d %d:%d)', [Data.tX, Data.tY, Data.tWidth, Data.tHeight]), True)] do
1046 begin
1047 EditStyle := esEllipsis;
1048 ReadOnly := True;
1049 end;
1051 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.Wait), True)] do
1052 begin
1053 EditStyle := esSimple;
1054 MaxLength := 5;
1055 end;
1057 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_COUNT], IntToStr(Data.Count), True)] do
1058 begin
1059 EditStyle := esSimple;
1060 MaxLength := 5;
1061 end;
1063 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_MONSTER], IntToStr(Data.MonsterID-1), True)] do
1064 begin
1065 EditStyle := esEllipsis;
1066 ReadOnly := True;
1067 end;
1069 if TriggerType = TRIGGER_PRESS then
1070 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_RANDOM], BoolNames[Data.ExtRandom], True)] do
1071 begin
1072 EditStyle := esPickList;
1073 ReadOnly := True;
1074 end;
1075 end;
1077 TRIGGER_SECRET:
1080 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
1081 begin
1082 with ItemProps[InsertRow(_lc[I_PROP_TR_LIFT_PANEL], IntToStr(Data.PanelID), True)] do
1083 begin
1084 EditStyle := esEllipsis;
1085 ReadOnly := True;
1086 end;
1088 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1089 begin
1090 EditStyle := esPickList;
1091 ReadOnly := True;
1092 end;
1094 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1095 begin
1096 EditStyle := esPickList;
1097 ReadOnly := True;
1098 end;
1099 end;
1101 TRIGGER_TEXTURE:
1102 begin
1103 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ONCE], BoolNames[Data.ActivateOnce], True)] do
1104 begin
1105 EditStyle := esPickList;
1106 ReadOnly := True;
1107 end;
1109 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ANIM_ONCE], BoolNames[Data.AnimOnce], True)] do
1110 begin
1111 EditStyle := esPickList;
1112 ReadOnly := True;
1113 end;
1114 end;
1116 TRIGGER_SOUND:
1117 begin
1118 str := win2utf(Data.SoundName);
1119 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_NAME], str, True)] do
1120 begin
1121 EditStyle := esEllipsis;
1122 ReadOnly := True;
1123 end;
1125 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_VOLUME], IntToStr(Data.Volume), True)] do
1126 begin
1127 EditStyle := esSimple;
1128 MaxLength := 3;
1129 end;
1131 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_PAN], IntToStr(Data.Pan), True)] do
1132 begin
1133 EditStyle := esSimple;
1134 MaxLength := 3;
1135 end;
1137 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_COUNT], IntToStr(Data.PlayCount), True)] do
1138 begin
1139 EditStyle := esSimple;
1140 MaxLength := 3;
1141 end;
1143 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_LOCAL], BoolNames[Data.Local], True)] do
1144 begin
1145 EditStyle := esPickList;
1146 ReadOnly := True;
1147 end;
1149 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_SWITCH], BoolNames[Data.SoundSwitch], True)] do
1150 begin
1151 EditStyle := esPickList;
1152 ReadOnly := True;
1153 end;
1154 end;
1156 TRIGGER_SPAWNMONSTER:
1157 begin
1158 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_TYPE], MonsterToStr(Data.MonType), True)] do
1159 begin
1160 EditStyle := esEllipsis;
1161 ReadOnly := True;
1162 end;
1164 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1165 Format('(%d:%d)', [Data.MonPos.X, Data.MonPos.Y]), True)] do
1166 begin
1167 EditStyle := esEllipsis;
1168 ReadOnly := True;
1169 end;
1171 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[TDirection(Data.MonDir)], True)] do
1172 begin
1173 EditStyle := esPickList;
1174 ReadOnly := True;
1175 end;
1177 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.MonHealth), True)] do
1178 begin
1179 EditStyle := esSimple;
1180 MaxLength := 5;
1181 end;
1183 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_ACTIVE], BoolNames[Data.MonActive], True)] do
1184 begin
1185 EditStyle := esPickList;
1186 ReadOnly := True;
1187 end;
1189 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.MonCount), True)] do
1190 begin
1191 EditStyle := esSimple;
1192 MaxLength := 5;
1193 end;
1195 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.MonEffect), True)] do
1196 begin
1197 EditStyle := esEllipsis;
1198 ReadOnly := True;
1199 end;
1201 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.MonMax), True)] do
1202 begin
1203 EditStyle := esSimple;
1204 MaxLength := 5;
1205 end;
1207 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.MonDelay), True)] do
1208 begin
1209 EditStyle := esSimple;
1210 MaxLength := 5;
1211 end;
1213 case Data.MonBehav of
1214 1: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1];
1215 2: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2];
1216 3: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3];
1217 4: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4];
1218 5: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5];
1219 else str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_0];
1220 end;
1221 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_BEHAVIOUR], str, True)] do
1222 begin
1223 EditStyle := esPickList;
1224 ReadOnly := True;
1225 end;
1226 end;
1228 TRIGGER_SPAWNITEM:
1229 begin
1230 with ItemProps[InsertRow(_lc[I_PROP_TR_ITEM_TYPE], ItemToStr(Data.ItemType), True)] do
1231 begin
1232 EditStyle := esEllipsis;
1233 ReadOnly := True;
1234 end;
1236 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1237 Format('(%d:%d)', [Data.ItemPos.X, Data.ItemPos.Y]), True)] do
1238 begin
1239 EditStyle := esEllipsis;
1240 ReadOnly := True;
1241 end;
1243 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[Data.ItemOnlyDM], True)] do
1244 begin
1245 EditStyle := esPickList;
1246 ReadOnly := True;
1247 end;
1249 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Data.ItemFalls], True)] do
1250 begin
1251 EditStyle := esPickList;
1252 ReadOnly := True;
1253 end;
1255 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ItemCount), True)] do
1256 begin
1257 EditStyle := esSimple;
1258 MaxLength := 5;
1259 end;
1261 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.ItemEffect), True)] do
1262 begin
1263 EditStyle := esEllipsis;
1264 ReadOnly := True;
1265 end;
1267 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.ItemMax), True)] do
1268 begin
1269 EditStyle := esSimple;
1270 MaxLength := 5;
1271 end;
1273 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.ItemDelay), True)] do
1274 begin
1275 EditStyle := esSimple;
1276 MaxLength := 5;
1277 end;
1278 end;
1280 TRIGGER_MUSIC:
1281 begin
1282 str := win2utf(Data.MusicName);
1283 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_NAME], str, True)] do
1284 begin
1285 EditStyle := esEllipsis;
1286 ReadOnly := True;
1287 end;
1289 if Data.MusicAction = 1 then
1290 str := _lc[I_PROP_TR_MUSIC_ON]
1291 else
1292 str := _lc[I_PROP_TR_MUSIC_OFF];
1294 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_ACT], str, True)] do
1295 begin
1296 EditStyle := esPickList;
1297 ReadOnly := True;
1298 end;
1299 end;
1301 TRIGGER_PUSH:
1302 begin
1303 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_ANGLE], IntToStr(Data.PushAngle), True)] do
1304 begin
1305 EditStyle := esSimple;
1306 MaxLength := 4;
1307 end;
1308 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_FORCE], IntToStr(Data.PushForce), True)] do
1309 begin
1310 EditStyle := esSimple;
1311 MaxLength := 4;
1312 end;
1313 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_RESET], BoolNames[Data.ResetVel], True)] do
1314 begin
1315 EditStyle := esPickList;
1316 ReadOnly := True;
1317 end;
1318 end;
1320 TRIGGER_SCORE:
1321 begin
1322 case Data.ScoreAction of
1323 1: str := _lc[I_PROP_TR_SCORE_ACT_1];
1324 2: str := _lc[I_PROP_TR_SCORE_ACT_2];
1325 3: str := _lc[I_PROP_TR_SCORE_ACT_3];
1326 else str := _lc[I_PROP_TR_SCORE_ACT_0];
1327 end;
1328 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_ACT], str, True)] do
1329 begin
1330 EditStyle := esPickList;
1331 ReadOnly := True;
1332 end;
1333 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ScoreCount), True)] do
1334 begin
1335 EditStyle := esSimple;
1336 MaxLength := 3;
1337 end;
1338 case Data.ScoreTeam of
1339 1: str := _lc[I_PROP_TR_SCORE_TEAM_1];
1340 2: str := _lc[I_PROP_TR_SCORE_TEAM_2];
1341 3: str := _lc[I_PROP_TR_SCORE_TEAM_3];
1342 else str := _lc[I_PROP_TR_SCORE_TEAM_0];
1343 end;
1344 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_TEAM], str, True)] do
1345 begin
1346 EditStyle := esPickList;
1347 ReadOnly := True;
1348 end;
1349 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_CON], BoolNames[Data.ScoreCon], True)] do
1350 begin
1351 EditStyle := esPickList;
1352 ReadOnly := True;
1353 end;
1354 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_MSG], BoolNames[Data.ScoreMsg], True)] do
1355 begin
1356 EditStyle := esPickList;
1357 ReadOnly := True;
1358 end;
1359 end;
1361 TRIGGER_MESSAGE:
1362 begin
1363 case Data.MessageKind of
1364 1: str := _lc[I_PROP_TR_MESSAGE_KIND_1];
1365 else str := _lc[I_PROP_TR_MESSAGE_KIND_0];
1366 end;
1367 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_KIND], str, True)] do
1368 begin
1369 EditStyle := esPickList;
1370 ReadOnly := True;
1371 end;
1372 case Data.MessageSendTo of
1373 1: str := _lc[I_PROP_TR_MESSAGE_TO_1];
1374 2: str := _lc[I_PROP_TR_MESSAGE_TO_2];
1375 3: str := _lc[I_PROP_TR_MESSAGE_TO_3];
1376 4: str := _lc[I_PROP_TR_MESSAGE_TO_4];
1377 5: str := _lc[I_PROP_TR_MESSAGE_TO_5];
1378 else str := _lc[I_PROP_TR_MESSAGE_TO_0];
1379 end;
1380 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TO], str, True)] do
1381 begin
1382 EditStyle := esPickList;
1383 ReadOnly := True;
1384 end;
1385 str := win2utf(Data.MessageText);
1386 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TEXT], str, True)] do
1387 begin
1388 EditStyle := esSimple;
1389 MaxLength := 100;
1390 end;
1391 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TIME], IntToStr(Data.MessageTime), True)] do
1392 begin
1393 EditStyle := esSimple;
1394 MaxLength := 5;
1395 end;
1396 end;
1398 TRIGGER_DAMAGE:
1399 begin
1400 with ItemProps[InsertRow(_lc[I_PROP_TR_DAMAGE_VALUE], IntToStr(Data.DamageValue), True)] do
1401 begin
1402 EditStyle := esSimple;
1403 MaxLength := 5;
1404 end;
1405 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.DamageInterval), True)] do
1406 begin
1407 EditStyle := esSimple;
1408 MaxLength := 5;
1409 end;
1410 end;
1412 TRIGGER_HEALTH:
1413 begin
1414 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.HealValue), True)] do
1415 begin
1416 EditStyle := esSimple;
1417 MaxLength := 5;
1418 end;
1419 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.HealInterval), True)] do
1420 begin
1421 EditStyle := esSimple;
1422 MaxLength := 5;
1423 end;
1424 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH_MAX], BoolNames[Data.HealMax], True)] do
1425 begin
1426 EditStyle := esPickList;
1427 ReadOnly := True;
1428 end;
1429 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.HealSilent], True)] do
1430 begin
1431 EditStyle := esPickList;
1432 ReadOnly := True;
1433 end;
1434 end;
1436 TRIGGER_SHOT:
1437 begin
1438 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TYPE], ShotToStr(Data.ShotType), True)] do
1439 begin
1440 EditStyle := esEllipsis;
1441 ReadOnly := True;
1442 end;
1444 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SOUND], BoolNames[Data.ShotSound], True)] do
1445 begin
1446 EditStyle := esPickList;
1447 ReadOnly := True;
1448 end;
1450 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_PANEL], IntToStr(Data.ShotPanelID), True)] do
1451 begin
1452 EditStyle := esEllipsis;
1453 ReadOnly := True;
1454 end;
1456 case Data.ShotTarget of
1457 1: str := _lc[I_PROP_TR_SHOT_TO_1];
1458 2: str := _lc[I_PROP_TR_SHOT_TO_2];
1459 3: str := _lc[I_PROP_TR_SHOT_TO_3];
1460 4: str := _lc[I_PROP_TR_SHOT_TO_4];
1461 5: str := _lc[I_PROP_TR_SHOT_TO_5];
1462 6: str := _lc[I_PROP_TR_SHOT_TO_6];
1463 else str := _lc[I_PROP_TR_SHOT_TO_0];
1464 end;
1465 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TO], str, True)] do
1466 begin
1467 EditStyle := esPickList;
1468 ReadOnly := True;
1469 end;
1471 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SIGHT], IntToStr(Data.ShotIntSight), True)] do
1472 begin
1473 EditStyle := esSimple;
1474 MaxLength := 3;
1475 end;
1477 case Data.ShotAim of
1478 1: str := _lc[I_PROP_TR_SHOT_AIM_1];
1479 2: str := _lc[I_PROP_TR_SHOT_AIM_2];
1480 3: str := _lc[I_PROP_TR_SHOT_AIM_3];
1481 else str := _lc[I_PROP_TR_SHOT_AIM_0];
1482 end;
1483 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AIM], str, True)-1] do
1484 begin
1485 EditStyle := esPickList;
1486 ReadOnly := True;
1487 end;
1489 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1490 Format('(%d:%d)', [Data.ShotPos.X, Data.ShotPos.Y]), True)] do
1491 begin
1492 EditStyle := esEllipsis;
1493 ReadOnly := True;
1494 end;
1496 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ANGLE], IntToStr(Data.ShotAngle), True)] do
1497 begin
1498 EditStyle := esSimple;
1499 MaxLength := 4;
1500 end;
1502 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.ShotWait), True)] do
1503 begin
1504 EditStyle := esSimple;
1505 MaxLength := 5;
1506 end;
1508 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ACC], IntToStr(Data.ShotAccuracy), True)] do
1509 begin
1510 EditStyle := esSimple;
1511 MaxLength := 5;
1512 end;
1514 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AMMO], IntToStr(Data.ShotAmmo), True)] do
1515 begin
1516 EditStyle := esSimple;
1517 MaxLength := 5;
1518 end;
1520 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_RELOAD], IntToStr(Data.ShotIntReload), True)] do
1521 begin
1522 EditStyle := esSimple;
1523 MaxLength := 4;
1524 end;
1525 end;
1527 TRIGGER_EFFECT:
1528 begin
1529 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.FXCount), True)] do
1530 begin
1531 EditStyle := esSimple;
1532 MaxLength := 3;
1533 end;
1535 if Data.FXType = 0 then
1536 str := _lc[I_PROP_TR_EFFECT_PARTICLE]
1537 else
1538 str := _lc[I_PROP_TR_EFFECT_ANIMATION];
1539 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_TYPE], str, True)] do
1540 begin
1541 EditStyle := esEllipsis;
1542 ReadOnly := True;
1543 end;
1545 str := '';
1546 if Data.FXType = 0 then
1547 case Data.FXSubType of
1548 TRIGGER_EFFECT_SLIQUID:
1549 str := _lc[I_PROP_TR_EFFECT_SLIQUID];
1550 TRIGGER_EFFECT_LLIQUID:
1551 str := _lc[I_PROP_TR_EFFECT_LLIQUID];
1552 TRIGGER_EFFECT_DLIQUID:
1553 str := _lc[I_PROP_TR_EFFECT_DLIQUID];
1554 TRIGGER_EFFECT_BLOOD:
1555 str := _lc[I_PROP_TR_EFFECT_BLOOD];
1556 TRIGGER_EFFECT_SPARK:
1557 str := _lc[I_PROP_TR_EFFECT_SPARK];
1558 TRIGGER_EFFECT_BUBBLE:
1559 str := _lc[I_PROP_TR_EFFECT_BUBBLE];
1560 end;
1561 if Data.FXType = 1 then
1562 begin
1563 if (Data.FXSubType = 0) or (Data.FXSubType > EFFECT_FIRE) then
1564 Data.FXSubType := EFFECT_TELEPORT;
1565 str := EffectToStr(Data.FXSubType);
1566 end;
1567 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SUBTYPE], str, True)] do
1568 begin
1569 EditStyle := esEllipsis;
1570 ReadOnly := True;
1571 end;
1573 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_COLOR], IntToStr(Data.FXColorR or (Data.FXColorG shl 8) or (Data.FXColorB shl 16)), True)] do
1574 begin
1575 EditStyle := esEllipsis;
1576 ReadOnly := True;
1577 end;
1579 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_CENTER], BoolNames[Data.FXPos = 0], True)] do
1580 begin
1581 EditStyle := esPickList;
1582 ReadOnly := True;
1583 end;
1585 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.FXWait), True)] do
1586 begin
1587 EditStyle := esSimple;
1588 MaxLength := 5;
1589 end;
1591 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELX], IntToStr(Data.FXVelX), True)] do
1592 begin
1593 EditStyle := esSimple;
1594 MaxLength := 4;
1595 end;
1597 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELY], IntToStr(Data.FXVelY), True)] do
1598 begin
1599 EditStyle := esSimple;
1600 MaxLength := 4;
1601 end;
1603 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPL], IntToStr(Data.FXSpreadL), True)] do
1604 begin
1605 EditStyle := esSimple;
1606 MaxLength := 3;
1607 end;
1609 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPR], IntToStr(Data.FXSpreadR), True)] do
1610 begin
1611 EditStyle := esSimple;
1612 MaxLength := 3;
1613 end;
1615 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPU], IntToStr(Data.FXSpreadU), True)] do
1616 begin
1617 EditStyle := esSimple;
1618 MaxLength := 3;
1619 end;
1621 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPD], IntToStr(Data.FXSpreadD), True)] do
1622 begin
1623 EditStyle := esSimple;
1624 MaxLength := 3;
1625 end;
1626 end;
1627 end; //case TriggerType
1628 end;
1629 end; // OBJECT_TRIGGER:
1630 end;
1631 end;
1633 procedure ChangeShownProperty(Name: String; NewValue: String);
1634 var
1635 row: Integer;
1636 begin
1637 if SelectedObjectCount() <> 1 then
1638 Exit;
1639 if not SelectedObjects[GetFirstSelected()].Live then
1640 Exit;
1642 // Есть ли такой ключ:
1643 if MainForm.vleObjectProperty.FindRow(Name, row) then
1644 begin
1645 MainForm.vleObjectProperty.Values[Name] := NewValue;
1646 end;
1647 end;
1649 procedure SelectObject(fObjectType: Byte; fID: DWORD; Multi: Boolean);
1650 var
1651 a: Integer;
1652 b: Boolean;
1653 begin
1654 if Multi then
1655 begin
1656 b := False;
1658 // Уже выделен - убираем:
1659 if SelectedObjects <> nil then
1660 for a := 0 to High(SelectedObjects) do
1661 with SelectedObjects[a] do
1662 if Live and (ID = fID) and
1663 (ObjectType = fObjectType) then
1664 begin
1665 Live := False;
1666 b := True;
1667 end;
1669 if b then
1670 Exit;
1672 SetLength(SelectedObjects, Length(SelectedObjects)+1);
1674 with SelectedObjects[High(SelectedObjects)] do
1675 begin
1676 ObjectType := fObjectType;
1677 ID := fID;
1678 Live := True;
1679 end;
1680 end
1681 else // not Multi
1682 begin
1683 SetLength(SelectedObjects, 1);
1685 with SelectedObjects[0] do
1686 begin
1687 ObjectType := fObjectType;
1688 ID := fID;
1689 Live := True;
1690 end;
1691 end;
1693 MainForm.miCopy.Enabled := True;
1694 MainForm.miCut.Enabled := True;
1696 if fObjectType = OBJECT_PANEL then
1697 begin
1698 MainForm.miToFore.Enabled := True;
1699 MainForm.miToBack.Enabled := True;
1700 end;
1701 end;
1703 procedure RemoveSelectFromObjects();
1704 begin
1705 SelectedObjects := nil;
1706 DrawPressRect := False;
1707 MouseLDown := False;
1708 MouseRDown := False;
1709 MouseAction := MOUSEACTION_NONE;
1710 SelectFlag := SELECTFLAG_NONE;
1711 ResizeType := RESIZETYPE_NONE;
1712 ResizeDirection := RESIZEDIR_NONE;
1714 MainForm.vleObjectProperty.Strings.Clear();
1716 MainForm.miCopy.Enabled := False;
1717 MainForm.miCut.Enabled := False;
1718 MainForm.miToFore.Enabled := False;
1719 MainForm.miToBack.Enabled := False;
1720 end;
1722 procedure DeleteSelectedObjects();
1723 var
1724 i, a, ii: Integer;
1725 b: Boolean;
1726 begin
1727 if SelectedObjects = nil then
1728 Exit;
1730 b := False;
1731 i := 0;
1733 for a := 0 to High(SelectedObjects) do
1734 with SelectedObjects[a] do
1735 if Live then
1736 begin
1737 if not b then
1738 begin
1739 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1740 i := High(UndoBuffer);
1741 b := True;
1742 end;
1744 SetLength(UndoBuffer[i], Length(UndoBuffer[i])+1);
1745 ii := High(UndoBuffer[i]);
1747 case ObjectType of
1748 OBJECT_PANEL:
1749 begin
1750 UndoBuffer[i, ii].UndoType := UNDO_DELETE_PANEL;
1751 New(UndoBuffer[i, ii].Panel);
1752 UndoBuffer[i, ii].Panel^ := gPanels[ID];
1753 end;
1754 OBJECT_ITEM:
1755 begin
1756 UndoBuffer[i, ii].UndoType := UNDO_DELETE_ITEM;
1757 UndoBuffer[i, ii].Item := gItems[ID];
1758 end;
1759 OBJECT_AREA:
1760 begin
1761 UndoBuffer[i, ii].UndoType := UNDO_DELETE_AREA;
1762 UndoBuffer[i, ii].Area := gAreas[ID];
1763 end;
1764 OBJECT_TRIGGER:
1765 begin
1766 UndoBuffer[i, ii].UndoType := UNDO_DELETE_TRIGGER;
1767 UndoBuffer[i, ii].Trigger := gTriggers[ID];
1768 end;
1769 end;
1771 RemoveObject(ID, ObjectType);
1772 end;
1774 RemoveSelectFromObjects();
1776 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1777 end;
1779 procedure Undo_Add(ObjectType: Byte; ID: DWORD; Group: Boolean = False);
1780 var
1781 i, ii: Integer;
1782 begin
1783 if (not Group) or (Length(UndoBuffer) = 0) then
1784 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1785 SetLength(UndoBuffer[High(UndoBuffer)], Length(UndoBuffer[High(UndoBuffer)])+1);
1786 i := High(UndoBuffer);
1787 ii := High(UndoBuffer[i]);
1789 case ObjectType of
1790 OBJECT_PANEL:
1791 UndoBuffer[i, ii].UndoType := UNDO_ADD_PANEL;
1792 OBJECT_ITEM:
1793 UndoBuffer[i, ii].UndoType := UNDO_ADD_ITEM;
1794 OBJECT_MONSTER:
1795 UndoBuffer[i, ii].UndoType := UNDO_ADD_MONSTER;
1796 OBJECT_AREA:
1797 UndoBuffer[i, ii].UndoType := UNDO_ADD_AREA;
1798 OBJECT_TRIGGER:
1799 UndoBuffer[i, ii].UndoType := UNDO_ADD_TRIGGER;
1800 end;
1802 UndoBuffer[i, ii].AddID := ID;
1804 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1805 end;
1807 procedure FullClear();
1808 begin
1809 RemoveSelectFromObjects();
1810 ClearMap();
1811 LoadSky(gMapInfo.SkyName);
1812 UndoBuffer := nil;
1813 slInvalidTextures.Clear();
1814 MapCheckForm.lbErrorList.Clear();
1815 MapCheckForm.mErrorDescription.Clear();
1817 MainForm.miUndo.Enabled := False;
1818 MainForm.sbHorizontal.Position := 0;
1819 MainForm.sbVertical.Position := 0;
1820 MainForm.FormResize(nil);
1821 MainForm.Caption := FormCaption;
1822 OpenedMap := '';
1823 OpenedWAD := '';
1824 end;
1826 procedure ErrorMessageBox(str: String);
1827 begin
1828 MessageBox(0, PChar(str), PChar(_lc[I_MSG_ERROR]),
1829 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
1830 end;
1832 function CheckProperty(): Boolean;
1833 var
1834 _id: Integer;
1835 begin
1836 Result := False;
1838 _id := GetFirstSelected();
1840 if SelectedObjects[_id].ObjectType = OBJECT_PANEL then
1841 with gPanels[SelectedObjects[_id].ID] do
1842 begin
1843 if TextureWidth <> 0 then
1844 if StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 1) mod TextureWidth <> 0 then
1845 begin
1846 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
1847 [TextureWidth]));
1848 Exit;
1849 end;
1851 if TextureHeight <> 0 then
1852 if StrToIntDef(Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]), 1) mod TextureHeight <> 0 then
1853 begin
1854 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
1855 [TextureHeight]));
1856 Exit;
1857 end;
1859 if IsTexturedPanel(PanelType) and (TextureName <> '') then
1860 if not (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]], -1) in [0..255]) then
1861 begin
1862 ErrorMessageBox(_lc[I_MSG_WRONG_ALPHA]);
1863 Exit;
1864 end;
1865 end;
1867 if SelectedObjects[_id].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
1868 if (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 0) <= 0) or
1869 (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]], 0) <= 0) then
1870 begin
1871 ErrorMessageBox(_lc[I_MSG_WRONG_SIZE]);
1872 Exit;
1873 end;
1875 if (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_X]]) = '') or
1876 (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_Y]]) = '') then
1877 begin
1878 ErrorMessageBox(_lc[I_MSG_WRONG_XY]);
1879 Exit;
1880 end;
1882 Result := True;
1883 end;
1885 procedure SelectTexture(ID: Integer);
1886 begin
1887 MainForm.lbTextureList.ItemIndex := ID;
1888 MainForm.lbTextureListClick(nil);
1889 end;
1891 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
1892 var
1893 a, FrameLen: Integer;
1894 ok: Boolean;
1895 FileName: String;
1896 ResourceName: String;
1897 FullResourceName: String;
1898 SectionName: String;
1899 Data: Pointer;
1900 Width, Height: Word;
1901 fn: String;
1902 begin
1903 Data := nil;
1904 FrameLen := 0;
1905 Width := 0;
1906 Height := 0;
1908 if aSection = '..' then
1909 SectionName := ''
1910 else
1911 SectionName := aSection;
1913 if aWAD = '' then
1914 aWAD := _lc[I_WAD_SPECIAL_MAP];
1916 if aWAD = _lc[I_WAD_SPECIAL_MAP] then
1917 begin // Файл карты
1918 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
1919 //FileName := EditorDir+'maps\'+ExtractFileName(fn);
1920 FileName := fn;
1921 ResourceName := ':'+SectionName+'\'+aTex;
1922 end
1923 else
1924 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1925 begin // Спец. текстуры
1926 FileName := '';
1927 ResourceName := aTex;
1928 end
1929 else
1930 begin // Внешний WAD
1931 FileName := EditorDir+'wads/'+aWAD;
1932 ResourceName := aWAD+':'+SectionName+'\'+aTex;
1933 end;
1935 ok := True;
1937 // Есть ли уже такая текстура:
1938 for a := 0 to MainForm.lbTextureList.Items.Count-1 do
1939 if ResourceName = MainForm.lbTextureList.Items[a] then
1940 begin
1941 if not silent then
1942 ErrorMessageBox(Format(_lc[I_MSG_TEXTURE_ALREADY],
1943 [ResourceName]));
1944 ok := False;
1945 end;
1947 // Название ресурса <= 64 символов:
1948 if Length(ResourceName) > 64 then
1949 begin
1950 if not silent then
1951 ErrorMessageBox(Format(_lc[I_MSG_RES_NAME_64],
1952 [ResourceName]));
1953 ok := False;
1954 end;
1956 if ok then
1957 begin
1958 a := -1;
1959 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1960 begin
1961 a := MainForm.lbTextureList.Items.Add(ResourceName);
1962 if not silent then
1963 SelectTexture(a);
1964 Result := True;
1965 Exit;
1966 end;
1968 FullResourceName := FileName+':'+SectionName+'\'+aTex;
1970 if IsAnim(FullResourceName) then
1971 begin // Аним. текстура
1972 GetFrame(FullResourceName, Data, FrameLen, Width, Height);
1974 if not g_CreateTextureMemorySize(Data, FrameLen, ResourceName, 0, 0, Width, Height, 1) then
1975 ok := False;
1976 a := MainForm.lbTextureList.Items.Add(ResourceName);
1977 end
1978 else // Обычная текстура
1979 begin
1980 if not g_CreateTextureWAD(ResourceName, FullResourceName) then
1981 ok := False;
1982 a := MainForm.lbTextureList.Items.Add(ResourceName);
1983 end;
1984 if (not ok) and (slInvalidTextures.IndexOf(ResourceName) = -1) then
1985 begin
1986 slInvalidTextures.Add(ResourceName);
1987 ok := True;
1988 end;
1989 if (a > -1) and (not silent) then
1990 SelectTexture(a);
1991 end;
1993 Result := ok;
1994 end;
1996 procedure UpdateCaption(sMap, sFile, sRes: String);
1997 begin
1998 with MainForm do
1999 if (sFile = '') and (sRes = '') and (sMap = '') then
2000 Caption := FormCaption
2001 else
2002 if sMap = '' then
2003 Caption := Format('%s - %s:%s', [FormCaption, sFile, sRes])
2004 else
2005 if (sFile <> '') and (sRes <> '') then
2006 Caption := Format('%s - %s (%s:%s)', [FormCaption, sMap, sFile, sRes])
2007 else
2008 Caption := Format('%s - %s', [FormCaption, sMap]);
2009 end;
2011 procedure OpenMap(FileName: String; mapN: String);
2012 var
2013 MapName: String;
2014 idx: Integer;
2015 begin
2016 SelectMapForm.Caption := _lc[I_CAP_OPEN];
2017 SelectMapForm.GetMaps(FileName);
2019 if (FileName = OpenedWAD) and
2020 (OpenedMap <> '') then
2021 begin
2022 MapName := OpenedMap;
2023 while (Pos(':\', MapName) > 0) do
2024 Delete(MapName, 1, Pos(':\', MapName) + 1);
2026 idx := SelectMapForm.lbMapList.Items.IndexOf(MapName);
2027 SelectMapForm.lbMapList.ItemIndex := idx;
2028 end
2029 else
2030 if SelectMapForm.lbMapList.Count > 0 then
2031 SelectMapForm.lbMapList.ItemIndex := 0
2032 else
2033 SelectMapForm.lbMapList.ItemIndex := -1;
2035 if mapN = '' then
2036 idx := -1
2037 else
2038 idx := SelectMapForm.lbMapList.Items.IndexOf(mapN);
2040 if idx < 0 then
2041 begin
2042 if (SelectMapForm.ShowModal() = mrOK) and
2043 (SelectMapForm.lbMapList.ItemIndex <> -1) then
2044 idx := SelectMapForm.lbMapList.ItemIndex
2045 else
2046 Exit;
2047 end;
2049 MapName := SelectMapForm.lbMapList.Items[idx];
2051 with MainForm do
2052 begin
2053 FullClear();
2055 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
2056 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
2057 pLoadProgress.Show();
2059 OpenedMap := FileName+':\'+MapName;
2060 OpenedWAD := FileName;
2062 idx := RecentFiles.IndexOf(OpenedMap);
2063 // Такая карта уже недавно открывалась:
2064 if idx >= 0 then
2065 RecentFiles.Delete(idx);
2066 RecentFiles.Insert(0, OpenedMap);
2067 RefreshRecentMenu();
2069 LoadMap(OpenedMap);
2071 pLoadProgress.Hide();
2072 FormResize(nil);
2074 lbTextureList.Sorted := True;
2075 lbTextureList.Sorted := False;
2077 UpdateCaption(gMapInfo.Name, ExtractFileName(FileName), MapName);
2078 end;
2079 end;
2081 procedure MoveSelectedObjects(Wall, alt: Boolean; dx, dy: Integer);
2082 var
2083 okX, okY: Boolean;
2084 a: Integer;
2085 begin
2086 if SelectedObjects = nil then
2087 Exit;
2089 okX := True;
2090 okY := True;
2092 if Wall then
2093 for a := 0 to High(SelectedObjects) do
2094 if SelectedObjects[a].Live then
2095 begin
2096 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, dx, 0) then
2097 okX := False;
2099 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, 0, dy) then
2100 okY := False;
2102 if (not okX) or (not okY) then
2103 Break;
2104 end;
2106 if okX or okY then
2107 begin
2108 for a := 0 to High(SelectedObjects) do
2109 if SelectedObjects[a].Live then
2110 begin
2111 if okX then
2112 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, dx, 0);
2114 if okY then
2115 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, 0, dy);
2117 if alt and (SelectedObjects[a].ObjectType = OBJECT_TRIGGER) then
2118 begin
2119 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_PRESS,
2120 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
2121 begin // Двигаем зону Расширителя
2122 if okX then
2123 gTriggers[SelectedObjects[a].ID].Data.tX := gTriggers[SelectedObjects[a].ID].Data.tX+dx;
2124 if okY then
2125 gTriggers[SelectedObjects[a].ID].Data.tY := gTriggers[SelectedObjects[a].ID].Data.tY+dy;
2126 end;
2128 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_TELEPORT] then
2129 begin // Двигаем точку назначения Телепорта
2130 if okX then
2131 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X+dx;
2132 if okY then
2133 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y+dy;
2134 end;
2136 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNMONSTER] then
2137 begin // Двигаем точку создания монстра
2138 if okX then
2139 gTriggers[SelectedObjects[a].ID].Data.MonPos.X := gTriggers[SelectedObjects[a].ID].Data.MonPos.X+dx;
2140 if okY then
2141 gTriggers[SelectedObjects[a].ID].Data.MonPos.Y := gTriggers[SelectedObjects[a].ID].Data.MonPos.Y+dy;
2142 end;
2144 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNITEM] then
2145 begin // Двигаем точку создания предмета
2146 if okX then
2147 gTriggers[SelectedObjects[a].ID].Data.ItemPos.X := gTriggers[SelectedObjects[a].ID].Data.ItemPos.X+dx;
2148 if okY then
2149 gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y := gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y+dy;
2150 end;
2152 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SHOT] then
2153 begin // Двигаем точку создания выстрела
2154 if okX then
2155 gTriggers[SelectedObjects[a].ID].Data.ShotPos.X := gTriggers[SelectedObjects[a].ID].Data.ShotPos.X+dx;
2156 if okY then
2157 gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y := gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y+dy;
2158 end;
2159 end;
2160 end;
2162 LastMovePoint := MousePos;
2163 end;
2164 end;
2166 procedure ShowLayer(Layer: Byte; show: Boolean);
2167 begin
2168 LayerEnabled[Layer] := show;
2170 case Layer of
2171 LAYER_BACK:
2172 begin
2173 MainForm.miLayer1.Checked := show;
2174 MainForm.miLayerP1.Checked := show;
2175 end;
2176 LAYER_WALLS:
2177 begin
2178 MainForm.miLayer2.Checked := show;
2179 MainForm.miLayerP2.Checked := show;
2180 end;
2181 LAYER_FOREGROUND:
2182 begin
2183 MainForm.miLayer3.Checked := show;
2184 MainForm.miLayerP3.Checked := show;
2185 end;
2186 LAYER_STEPS:
2187 begin
2188 MainForm.miLayer4.Checked := show;
2189 MainForm.miLayerP4.Checked := show;
2190 end;
2191 LAYER_WATER:
2192 begin
2193 MainForm.miLayer5.Checked := show;
2194 MainForm.miLayerP5.Checked := show;
2195 end;
2196 LAYER_ITEMS:
2197 begin
2198 MainForm.miLayer6.Checked := show;
2199 MainForm.miLayerP6.Checked := show;
2200 end;
2201 LAYER_MONSTERS:
2202 begin
2203 MainForm.miLayer7.Checked := show;
2204 MainForm.miLayerP7.Checked := show;
2205 end;
2206 LAYER_AREAS:
2207 begin
2208 MainForm.miLayer8.Checked := show;
2209 MainForm.miLayerP8.Checked := show;
2210 end;
2211 LAYER_TRIGGERS:
2212 begin
2213 MainForm.miLayer9.Checked := show;
2214 MainForm.miLayerP9.Checked := show;
2215 end;
2216 end;
2218 RemoveSelectFromObjects();
2219 end;
2221 procedure SwitchLayer(Layer: Byte);
2222 begin
2223 ShowLayer(Layer, not LayerEnabled[Layer]);
2224 end;
2226 procedure SwitchMap();
2227 begin
2228 ShowMap := not ShowMap;
2229 MainForm.tbShowMap.Down := ShowMap;
2230 end;
2232 procedure ShowEdges();
2233 begin
2234 if drEdge[3] < 255 then
2235 drEdge[3] := 255
2236 else
2237 drEdge[3] := gAlphaEdge;
2238 end;
2240 function SelectedTexture(): String;
2241 begin
2242 if MainForm.lbTextureList.ItemIndex <> -1 then
2243 Result := MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]
2244 else
2245 Result := '';
2246 end;
2248 function IsSpecialTextureSel(): Boolean;
2249 begin
2250 Result := (MainForm.lbTextureList.ItemIndex <> -1) and
2251 IsSpecialTexture(MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]);
2252 end;
2254 function CopyBufferToString(var CopyBuf: TCopyRecArray): String;
2255 var
2256 i, j: Integer;
2257 Res: String;
2259 procedure AddInt(x: Integer);
2260 begin
2261 Res := Res + IntToStr(x) + ' ';
2262 end;
2264 begin
2265 Result := '';
2267 if Length(CopyBuf) = 0 then
2268 Exit;
2270 Res := CLIPBOARD_SIG + ' ';
2272 for i := 0 to High(CopyBuf) do
2273 begin
2274 if (CopyBuf[i].ObjectType = OBJECT_PANEL) and
2275 (CopyBuf[i].Panel = nil) then
2276 Continue;
2278 // Тип объекта:
2279 AddInt(CopyBuf[i].ObjectType);
2280 Res := Res + '; ';
2282 // Свойства объекта:
2283 case CopyBuf[i].ObjectType of
2284 OBJECT_PANEL:
2285 with CopyBuf[i].Panel^ do
2286 begin
2287 AddInt(PanelType);
2288 AddInt(X);
2289 AddInt(Y);
2290 AddInt(Width);
2291 AddInt(Height);
2292 Res := Res + '"' + TextureName + '" ';
2293 AddInt(Alpha);
2294 AddInt(IfThen(Blending, 1, 0));
2295 end;
2297 OBJECT_ITEM:
2298 with CopyBuf[i].Item do
2299 begin
2300 AddInt(ItemType);
2301 AddInt(X);
2302 AddInt(Y);
2303 AddInt(IfThen(OnlyDM, 1, 0));
2304 AddInt(IfThen(Fall, 1, 0));
2305 end;
2307 OBJECT_MONSTER:
2308 with CopyBuf[i].Monster do
2309 begin
2310 AddInt(MonsterType);
2311 AddInt(X);
2312 AddInt(Y);
2313 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2314 end;
2316 OBJECT_AREA:
2317 with CopyBuf[i].Area do
2318 begin
2319 AddInt(AreaType);
2320 AddInt(X);
2321 AddInt(Y);
2322 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2323 end;
2325 OBJECT_TRIGGER:
2326 with CopyBuf[i].Trigger do
2327 begin
2328 AddInt(TriggerType);
2329 AddInt(X);
2330 AddInt(Y);
2331 AddInt(Width);
2332 AddInt(Height);
2333 AddInt(ActivateType);
2334 AddInt(Key);
2335 AddInt(IfThen(Enabled, 1, 0));
2336 AddInt(TexturePanel);
2338 for j := 0 to 127 do
2339 AddInt(Data.Default[j]);
2340 end;
2341 end;
2342 end;
2344 Result := Res;
2345 end;
2347 procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray;
2348 var pmin: TPoint);
2349 var
2350 i, j, t: Integer;
2352 function GetNext(): String;
2353 var
2354 p: Integer;
2356 begin
2357 if Str[1] = '"' then
2358 begin
2359 Delete(Str, 1, 1);
2360 p := Pos('"', Str);
2362 if p = 0 then
2363 begin
2364 Result := Str;
2365 Str := '';
2366 end
2367 else
2368 begin
2369 Result := Copy(Str, 1, p-1);
2370 Delete(Str, 1, p);
2371 Str := Trim(Str);
2372 end;
2373 end
2374 else
2375 begin
2376 p := Pos(' ', Str);
2378 if p = 0 then
2379 begin
2380 Result := Str;
2381 Str := '';
2382 end
2383 else
2384 begin
2385 Result := Copy(Str, 1, p-1);
2386 Delete(Str, 1, p);
2387 Str := Trim(Str);
2388 end;
2389 end;
2390 end;
2392 begin
2393 Str := Trim(Str);
2395 if GetNext() <> CLIPBOARD_SIG then
2396 Exit;
2398 while Str <> '' do
2399 begin
2400 // Тип объекта:
2401 t := StrToIntDef(GetNext(), 0);
2403 if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or
2404 (GetNext() <> ';') then
2405 begin // Что-то не то => пропускаем:
2406 t := Pos(';', Str);
2407 Delete(Str, 1, t);
2408 Str := Trim(Str);
2410 Continue;
2411 end;
2413 i := Length(CopyBuf);
2414 SetLength(CopyBuf, i + 1);
2416 CopyBuf[i].ObjectType := t;
2417 CopyBuf[i].Panel := nil;
2419 // Свойства объекта:
2420 case t of
2421 OBJECT_PANEL:
2422 begin
2423 New(CopyBuf[i].Panel);
2425 with CopyBuf[i].Panel^ do
2426 begin
2427 PanelType := StrToIntDef(GetNext(), PANEL_WALL);
2428 X := StrToIntDef(GetNext(), 0);
2429 Y := StrToIntDef(GetNext(), 0);
2430 pmin.X := Min(X, pmin.X);
2431 pmin.Y := Min(Y, pmin.Y);
2432 Width := StrToIntDef(GetNext(), 16);
2433 Height := StrToIntDef(GetNext(), 16);
2434 TextureName := GetNext();
2435 Alpha := StrToIntDef(GetNext(), 0);
2436 Blending := (GetNext() = '1');
2437 end;
2438 end;
2440 OBJECT_ITEM:
2441 with CopyBuf[i].Item do
2442 begin
2443 ItemType := StrToIntDef(GetNext(), ITEM_MEDKIT_SMALL);
2444 X := StrToIntDef(GetNext(), 0);
2445 Y := StrToIntDef(GetNext(), 0);
2446 pmin.X := Min(X, pmin.X);
2447 pmin.Y := Min(Y, pmin.Y);
2448 OnlyDM := (GetNext() = '1');
2449 Fall := (GetNext() = '1');
2450 end;
2452 OBJECT_MONSTER:
2453 with CopyBuf[i].Monster do
2454 begin
2455 MonsterType := StrToIntDef(GetNext(), MONSTER_DEMON);
2456 X := StrToIntDef(GetNext(), 0);
2457 Y := StrToIntDef(GetNext(), 0);
2458 pmin.X := Min(X, pmin.X);
2459 pmin.Y := Min(Y, pmin.Y);
2461 if GetNext() = '1' then
2462 Direction := D_LEFT
2463 else
2464 Direction := D_RIGHT;
2465 end;
2467 OBJECT_AREA:
2468 with CopyBuf[i].Area do
2469 begin
2470 AreaType := StrToIntDef(GetNext(), AREA_PLAYERPOINT1);
2471 X := StrToIntDef(GetNext(), 0);
2472 Y := StrToIntDef(GetNext(), 0);
2473 pmin.X := Min(X, pmin.X);
2474 pmin.Y := Min(Y, pmin.Y);
2475 if GetNext() = '1' then
2476 Direction := D_LEFT
2477 else
2478 Direction := D_RIGHT;
2479 end;
2481 OBJECT_TRIGGER:
2482 with CopyBuf[i].Trigger do
2483 begin
2484 TriggerType := StrToIntDef(GetNext(), TRIGGER_EXIT);
2485 X := StrToIntDef(GetNext(), 0);
2486 Y := StrToIntDef(GetNext(), 0);
2487 pmin.X := Min(X, pmin.X);
2488 pmin.Y := Min(Y, pmin.Y);
2489 Width := StrToIntDef(GetNext(), 16);
2490 Height := StrToIntDef(GetNext(), 16);
2491 ActivateType := StrToIntDef(GetNext(), 0);
2492 Key := StrToIntDef(GetNext(), 0);
2493 Enabled := (GetNext() = '1');
2494 TexturePanel := StrToIntDef(GetNext(), 0);
2496 for j := 0 to 127 do
2497 Data.Default[j] := StrToIntDef(GetNext(), 0);
2499 case TriggerType of
2500 TRIGGER_TELEPORT:
2501 begin
2502 pmin.X := Min(Data.TargetPoint.X, pmin.X);
2503 pmin.Y := Min(Data.TargetPoint.Y, pmin.Y);
2504 end;
2505 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
2506 begin
2507 pmin.X := Min(Data.tX, pmin.X);
2508 pmin.Y := Min(Data.tY, pmin.Y);
2509 end;
2510 TRIGGER_SPAWNMONSTER:
2511 begin
2512 pmin.X := Min(Data.MonPos.X, pmin.X);
2513 pmin.Y := Min(Data.MonPos.Y, pmin.Y);
2514 end;
2515 TRIGGER_SPAWNITEM:
2516 begin
2517 pmin.X := Min(Data.ItemPos.X, pmin.X);
2518 pmin.Y := Min(Data.ItemPos.Y, pmin.Y);
2519 end;
2520 TRIGGER_SHOT:
2521 begin
2522 pmin.X := Min(Data.ShotPos.X, pmin.X);
2523 pmin.Y := Min(Data.ShotPos.Y, pmin.Y);
2524 end;
2525 end;
2526 end;
2527 end;
2528 end;
2529 end;
2531 //----------------------------------------
2532 //Закончились вспомогательные процедуры
2533 //----------------------------------------
2535 procedure TMainForm.RefreshRecentMenu();
2536 var
2537 i: Integer;
2538 MI: TMenuItem;
2539 begin
2540 // Лишние запомненные карты:
2541 while RecentFiles.Count > RecentCount do
2542 RecentFiles.Delete(RecentFiles.Count-1);
2544 // Лишние строки меню:
2545 while MainMenu.Items[0].Count > RECENT_FILES_MENU_START do
2546 MainMenu.Items[0].Delete(MainMenu.Items[0].Count-1);
2548 // Отделение списка карт от строки "Выход":
2549 if RecentFiles.Count > 0 then
2550 begin
2551 MI := TMenuItem.Create(MainMenu.Items[0]);
2552 MI.Caption := '-';
2553 MainMenu.Items[0].Add(MI);
2554 end;
2556 // Добавление в меню списка запомненных карт:
2557 for i := 0 to RecentFiles.Count-1 do
2558 begin
2559 MI := TMenuItem.Create(MainMenu.Items[0]);
2560 MI.Caption := IntToStr(i+1) + ' ' + RecentFiles[i];
2561 MI.OnClick := aRecentFileExecute;
2562 MainMenu.Items[0].Add(MI);
2563 end;
2564 end;
2566 procedure TMainForm.aRecentFileExecute(Sender: TObject);
2567 var
2568 n, pw: Integer;
2569 s, fn: String;
2570 b: Boolean;
2571 begin
2572 s := LowerCase((Sender as TMenuItem).Caption);
2573 Delete(s, Pos('&', s), 1);
2574 s := Trim(Copy(s, 1, 2));
2575 n := StrToIntDef(s, 0) - 1;
2577 if (n < 0) or (n >= RecentFiles.Count) then
2578 Exit;
2580 s := RecentFiles[n];
2581 pw := Pos('.wad:\', LowerCase(s));
2582 b := False;
2584 if pw > 0 then
2585 begin // Map name included
2586 fn := Copy(s, 1, pw + 3);
2587 Delete(s, 1, pw + 5);
2588 if (FileExists(fn)) then
2589 begin
2590 OpenMap(fn, s);
2591 b := True;
2592 end;
2593 end
2594 else // Only wad name
2595 if (FileExists(s)) then
2596 begin
2597 OpenMap(s, '');
2598 b := True;
2599 end;
2601 if (not b) and (MessageBox(0, PChar(_lc[I_MSG_DEL_RECENT_PROMT]),
2602 PChar(_lc[I_MSG_DEL_RECENT]), MB_ICONQUESTION or MB_YESNO) = idYes) then
2603 begin
2604 RecentFiles.Delete(n);
2605 RefreshRecentMenu();
2606 end;
2607 end;
2609 procedure TMainForm.aEditorOptionsExecute(Sender: TObject);
2610 begin
2611 OptionsForm.ShowModal();
2612 end;
2614 procedure LoadStdFont(cfgres, texture: string; var FontID: DWORD);
2615 var
2616 cwdt, chgt: Byte;
2617 spc: ShortInt;
2618 ID: DWORD;
2619 wad: TWADEditor_1;
2620 cfgdata: Pointer;
2621 cfglen: Integer;
2622 config: TConfig;
2623 begin
2624 cfgdata := nil;
2625 cfglen := 0;
2626 ID := 0;
2628 wad := TWADEditor_1.Create;
2629 if wad.ReadFile(EditorDir+'data/Game.wad') then
2630 wad.GetResource('FONTS', cfgres, cfgdata, cfglen);
2631 wad.Free();
2633 if cfglen <> 0 then
2634 begin
2635 if not g_CreateTextureWAD('FONT_STD', EditorDir+'data/Game.wad:FONTS\'+texture) then
2636 e_WriteLog('ERROR ERROR ERROR', MSG_WARNING);
2638 config := TConfig.CreateMem(cfgdata, cfglen);
2639 cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
2640 chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
2641 spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
2643 if g_GetTexture('FONT_STD', ID) then
2644 e_TextureFontBuild(ID, FontID, cwdt, chgt, spc-2);
2646 config.Free();
2647 end
2648 else
2649 e_WriteLog('Could not load FONT_STD', MSG_WARNING);
2651 if cfglen <> 0 then FreeMem(cfgdata);
2652 end;
2654 procedure TMainForm.FormCreate(Sender: TObject);
2655 var
2656 config: TConfig;
2657 i: Integer;
2658 s: String;
2659 begin
2660 Randomize();
2662 EditorDir := ExtractFilePath(Application.ExeName);
2664 e_InitLog(EditorDir+'Editor.log', WM_NEWFILE);
2666 slInvalidTextures := TStringList.Create;
2668 ShowLayer(LAYER_BACK, True);
2669 ShowLayer(LAYER_WALLS, True);
2670 ShowLayer(LAYER_FOREGROUND, True);
2671 ShowLayer(LAYER_STEPS, True);
2672 ShowLayer(LAYER_WATER, True);
2673 ShowLayer(LAYER_ITEMS, True);
2674 ShowLayer(LAYER_MONSTERS, True);
2675 ShowLayer(LAYER_AREAS, True);
2676 ShowLayer(LAYER_TRIGGERS, True);
2678 ClearMap();
2680 FormCaption := MainForm.Caption;
2681 OpenedMap := '';
2682 OpenedWAD := '';
2684 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
2686 if config.ReadInt('Editor', 'XPos', -1) = -1 then
2687 Position := poDesktopCenter
2688 else begin
2689 Left := config.ReadInt('Editor', 'XPos', Left);
2690 Top := config.ReadInt('Editor', 'YPos', Top);
2691 Width := config.ReadInt('Editor', 'Width', Width);
2692 Height := config.ReadInt('Editor', 'Height', Height);
2693 end;
2694 if config.ReadBool('Editor', 'Maximize', False) then
2695 WindowState := wsMaximized;
2696 ShowMap := config.ReadBool('Editor', 'Minimap', False);
2697 PanelProps.Width := config.ReadInt('Editor', 'PanelProps', PanelProps.ClientWidth);
2698 Splitter1.Left := PanelProps.Left;
2699 PanelObjs.Height := config.ReadInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
2700 Splitter2.Top := PanelObjs.Top;
2701 StatusBar.Top := PanelObjs.BoundsRect.Bottom;
2702 DotEnable := config.ReadBool('Editor', 'DotEnable', True);
2703 DotColor := config.ReadInt('Editor', 'DotColor', $FFFFFF);
2704 DotStepOne := config.ReadInt('Editor', 'DotStepOne', 16);
2705 DotStepTwo := config.ReadInt('Editor', 'DotStepTwo', 8);
2706 DotStep := config.ReadInt('Editor', 'DotStep', DotStepOne);
2707 DrawTexturePanel := config.ReadBool('Editor', 'DrawTexturePanel', True);
2708 DrawPanelSize := config.ReadBool('Editor', 'DrawPanelSize', True);
2709 BackColor := config.ReadInt('Editor', 'BackColor', $7F6040);
2710 PreviewColor := config.ReadInt('Editor', 'PreviewColor', $00FF00);
2711 UseCheckerboard := config.ReadBool('Editor', 'UseCheckerboard', True);
2712 gColorEdge := config.ReadInt('Editor', 'EdgeColor', COLOR_EDGE);
2713 gAlphaEdge := config.ReadInt('Editor', 'EdgeAlpha', ALPHA_EDGE);
2714 if gAlphaEdge = 255 then
2715 gAlphaEdge := ALPHA_EDGE;
2716 drEdge[0] := GetRValue(gColorEdge);
2717 drEdge[1] := GetGValue(gColorEdge);
2718 drEdge[2] := GetBValue(gColorEdge);
2719 if not config.ReadBool('Editor', 'EdgeShow', True) then
2720 drEdge[3] := 255
2721 else
2722 drEdge[3] := gAlphaEdge;
2723 gAlphaTriggerLine := config.ReadInt('Editor', 'LineAlpha', ALPHA_LINE);
2724 if gAlphaTriggerLine = 255 then
2725 gAlphaTriggerLine := ALPHA_LINE;
2726 gAlphaTriggerArea := config.ReadInt('Editor', 'TriggerAlpha', ALPHA_AREA);
2727 if gAlphaTriggerArea = 255 then
2728 gAlphaTriggerArea := ALPHA_AREA;
2729 if config.ReadInt('Editor', 'Scale', 0) = 1 then
2730 Scale := 2
2731 else
2732 Scale := 1;
2733 if config.ReadInt('Editor', 'DotSize', 0) = 1 then
2734 DotSize := 2
2735 else
2736 DotSize := 1;
2737 OpenDialog.InitialDir := config.ReadStr('Editor', 'LastOpenDir', EditorDir);
2738 SaveDialog.InitialDir := config.ReadStr('Editor', 'LastSaveDir', EditorDir);
2740 s := config.ReadStr('Editor', 'Language', '');
2741 gLanguage := s;
2743 RecentCount := config.ReadInt('Editor', 'RecentCount', 5);
2744 if RecentCount > 10 then
2745 RecentCount := 10;
2746 if RecentCount < 2 then
2747 RecentCount := 2;
2749 RecentFiles := TStringList.Create();
2750 for i := 0 to RecentCount-1 do
2751 begin
2752 s := config.ReadStr('RecentFiles', IntToStr(i+1), '');
2753 if s <> '' then
2754 RecentFiles.Add(s);
2755 end;
2756 RefreshRecentMenu();
2758 config.Free();
2760 tbShowMap.Down := ShowMap;
2761 tbGridOn.Down := DotEnable;
2762 pcObjects.ActivePageIndex := 0;
2763 Application.Title := _lc[I_EDITOR_TITLE];
2765 Application.OnIdle := OnIdle;
2766 end;
2768 procedure PrintBlack(X, Y: Integer; Text: string; FontID: DWORD);
2769 begin
2770 // NOTE: all the font printing routines assume CP1251
2771 e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0);
2772 end;
2774 procedure TMainForm.Draw();
2775 var
2776 x, y: Integer;
2777 a, b: Integer;
2778 ID, PID: DWORD;
2779 Width, Height: Word;
2780 Rect: TRectWH;
2781 ObjCount: Word;
2782 aX, aY, aX2, aY2, XX, ScaleSz: Integer;
2783 begin
2784 ID := 0;
2785 PID := 0;
2786 Width := 0;
2787 Height := 0;
2789 e_BeginRender();
2791 e_Clear(GL_COLOR_BUFFER_BIT,
2792 GetRValue(BackColor)/255,
2793 GetGValue(BackColor)/255,
2794 GetBValue(BackColor)/255);
2796 DrawMap();
2798 ObjCount := SelectedObjectCount();
2800 // Обводим выделенные объекты красной рамкой:
2801 if ObjCount > 0 then
2802 begin
2803 for a := 0 to High(SelectedObjects) do
2804 if SelectedObjects[a].Live then
2805 begin
2806 Rect := ObjectGetRect(SelectedObjects[a].ObjectType, SelectedObjects[a].ID);
2808 with Rect do
2809 begin
2810 e_DrawQuad(X+MapOffset.X, Y+MapOffset.Y,
2811 X+MapOffset.X+Width-1, Y+MapOffset.Y+Height-1,
2812 255, 0, 0);
2814 // Рисуем точки изменения размеров:
2815 if (ObjCount = 1) and
2816 (SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) then
2817 begin
2818 e_DrawPoint(5, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2819 e_DrawPoint(5, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2820 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 255, 255);
2821 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 255, 255);
2823 e_DrawPoint(3, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2824 e_DrawPoint(3, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2825 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 0, 0);
2826 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 0, 0);
2827 end;
2828 end;
2829 end;
2830 end;
2832 // Рисуем сетку:
2833 if DotEnable and (PreviewMode = 0) then
2834 begin
2835 if DotSize = 2 then
2836 a := -1
2837 else
2838 a := 0;
2840 for x := 0 to (RenderPanel.Width div DotStep) do
2841 for y := 0 to (RenderPanel.Height div DotStep) do
2842 e_DrawPoint(DotSize, x*DotStep + a, y*DotStep + a,
2843 GetRValue(DotColor),
2844 GetGValue(DotColor),
2845 GetBValue(DotColor));
2846 end;
2848 // Превью текстуры:
2849 if (lbTextureList.ItemIndex <> -1) and (cbPreview.Checked) and
2850 (not IsSpecialTextureSel()) and (PreviewMode = 0) then
2851 begin
2852 if not g_GetTexture(SelectedTexture(), ID) then
2853 g_GetTexture('NOTEXTURE', ID);
2854 g_GetTextureSizeByID(ID, Width, Height);
2855 if UseCheckerboard then
2856 begin
2857 if g_GetTexture('PREVIEW', PID) then
2858 e_DrawFill(PID, RenderPanel.Width-Width, RenderPanel.Height-Height, Width div 16 + 1, Height div 16 + 1, 0, True, False);
2859 end else
2860 e_DrawFillQuad(RenderPanel.Width-Width-2, RenderPanel.Height-Height-2,
2861 RenderPanel.Width-1, RenderPanel.Height-1,
2862 GetRValue(PreviewColor), GetGValue(PreviewColor), GetBValue(PreviewColor), 0);
2863 e_Draw(ID, RenderPanel.Width-Width, RenderPanel.Height-Height, 0, True, False);
2864 end;
2866 // Подсказка при выборе точки Телепорта:
2867 if SelectFlag = SELECTFLAG_TELEPORT then
2868 begin
2869 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
2870 if Data.d2d_teleport then
2871 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2872 MousePos.X+16, MousePos.Y-1,
2873 0, 0, 255)
2874 else
2875 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+AreaSize[AREA_DMPOINT].Width-1,
2876 MousePos.Y+AreaSize[AREA_DMPOINT].Height-1, 255, 255, 255);
2878 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2879 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2880 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_TELEPORT], gEditorFont);
2881 end;
2883 // Подсказка при выборе точки появления:
2884 if SelectFlag = SELECTFLAG_SPAWNPOINT then
2885 begin
2886 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2887 MousePos.X+16, MousePos.Y-1,
2888 0, 0, 255);
2889 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2890 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2891 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_SPAWN], gEditorFont);
2892 end;
2894 // Подсказка при выборе панели двери:
2895 if SelectFlag = SELECTFLAG_DOOR then
2896 begin
2897 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2898 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2899 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_DOOR], gEditorFont);
2900 end;
2902 // Подсказка при выборе панели с текстурой:
2903 if SelectFlag = SELECTFLAG_TEXTURE then
2904 begin
2905 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 192, 192, 192, 127);
2906 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 255, 255, 255);
2907 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_TEXTURE], gEditorFont);
2908 end;
2910 // Подсказка при выборе панели индикации выстрела:
2911 if SelectFlag = SELECTFLAG_SHOTPANEL then
2912 begin
2913 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 192, 192, 192, 127);
2914 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 255, 255, 255);
2915 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_SHOT], gEditorFont);
2916 end;
2918 // Подсказка при выборе панели лифта:
2919 if SelectFlag = SELECTFLAG_LIFT then
2920 begin
2921 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2922 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2923 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_LIFT], gEditorFont);
2924 end;
2926 // Подсказка при выборе монстра:
2927 if SelectFlag = SELECTFLAG_MONSTER then
2928 begin
2929 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 192, 192, 192, 127);
2930 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 255, 255, 255);
2931 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_MONSTER], gEditorFont);
2932 end;
2934 // Подсказка при выборе области воздействия:
2935 if DrawPressRect then
2936 begin
2937 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 192, 192, 192, 127);
2938 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 255, 255, 255);
2939 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_EXT_AREA], gEditorFont);
2940 end;
2942 // Рисуем текстуры, если чертим панель:
2943 if (MouseAction = MOUSEACTION_DRAWPANEL) and (DrawTexturePanel) and
2944 (lbTextureList.ItemIndex <> -1) and (DrawRect <> nil) and
2945 (lbPanelType.ItemIndex in [0..8]) and not IsSpecialTextureSel() then
2946 begin
2947 if not g_GetTexture(SelectedTexture(), ID) then
2948 g_GetTexture('NOTEXTURE', ID);
2949 g_GetTextureSizeByID(ID, Width, Height);
2950 with DrawRect^ do
2951 if (Abs(Right-Left) >= Width) and (Abs(Bottom-Top) >= Height) then
2952 e_DrawFill(ID, Min(Left, Right), Min(Top, Bottom), Abs(Right-Left) div Width,
2953 Abs(Bottom-Top) div Height, 64, True, False);
2954 end;
2956 // Прямоугольник выделения:
2957 if DrawRect <> nil then
2958 with DrawRect^ do
2959 e_DrawQuad(Left, Top, Right-1, Bottom-1, 255, 255, 255);
2961 // Чертим мышью панель/триггер или меняем мышью их размер:
2962 if (((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
2963 not(ssCtrl in GetKeyShiftState())) or (MouseAction = MOUSEACTION_RESIZE)) and
2964 (DrawPanelSize) then
2965 begin
2966 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 192, 192, 192, 127);
2967 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 255, 255, 255);
2969 if MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER] then
2970 begin // Чертим новый
2971 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH],
2972 [Abs(MousePos.X-MouseLDownPos.X)]), gEditorFont);
2973 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(_glc[I_HINT_HEIGHT],
2974 [Abs(MousePos.Y-MouseLDownPos.Y)]), gEditorFont);
2975 end
2976 else // Растягиваем существующий
2977 if SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
2978 begin
2979 if SelectedObjects[GetFirstSelected].ObjectType = OBJECT_PANEL then
2980 begin
2981 Width := gPanels[SelectedObjects[GetFirstSelected].ID].Width;
2982 Height := gPanels[SelectedObjects[GetFirstSelected].ID].Height;
2983 end
2984 else
2985 begin
2986 Width := gTriggers[SelectedObjects[GetFirstSelected].ID].Width;
2987 Height := gTriggers[SelectedObjects[GetFirstSelected].ID].Height;
2988 end;
2990 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH], [Width]),
2991 gEditorFont);
2992 PrintBlack(MousePos.X+2, MousePos.Y+16, Format(_glc[I_HINT_HEIGHT], [Height]),
2993 gEditorFont);
2994 end;
2995 end;
2997 // Ближайшая к курсору мыши точка на сетке:
2998 e_DrawPoint(3, MousePos.X, MousePos.Y, 0, 0, 255);
3000 // Мини-карта:
3001 if ShowMap then
3002 begin
3003 // Сколько пикселов карты в 1 пикселе мини-карты:
3004 ScaleSz := 16 div Scale;
3005 // Размеры мини-карты:
3006 aX := max(gMapInfo.Width div ScaleSz, 1);
3007 aY := max(gMapInfo.Height div ScaleSz, 1);
3008 // X-координата на RenderPanel нулевой x-координаты карты:
3009 XX := RenderPanel.Width - aX - 1;
3010 // Рамка карты:
3011 e_DrawFillQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 0, 0, 0, 0);
3012 e_DrawQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 197, 197, 197);
3014 if gPanels <> nil then
3015 begin
3016 // Рисуем панели:
3017 for a := 0 to High(gPanels) do
3018 with gPanels[a] do
3019 if PanelType <> 0 then
3020 begin
3021 // Левый верхний угол:
3022 aX := XX + (X div ScaleSz);
3023 aY := 1 + (Y div ScaleSz);
3024 // Размеры:
3025 aX2 := max(Width div ScaleSz, 1);
3026 aY2 := max(Height div ScaleSz, 1);
3027 // Правый нижний угол:
3028 aX2 := aX + aX2 - 1;
3029 aY2 := aY + aY2 - 1;
3031 case PanelType of
3032 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3033 PANEL_WATER: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3034 PANEL_ACID1: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3035 PANEL_ACID2: e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3036 PANEL_STEP: e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3037 PANEL_LIFTUP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3038 PANEL_LIFTDOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3039 PANEL_LIFTLEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3040 PANEL_LIFTRIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3041 PANEL_OPENDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 100, 220, 92, 0);
3042 PANEL_CLOSEDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 212, 184, 64, 0);
3043 PANEL_BLOCKMON: e_DrawFillQuad(aX, aY, aX2, aY2, 192, 0, 192, 0);
3044 end;
3045 end;
3047 // Рисуем красным выделенные панели:
3048 if SelectedObjects <> nil then
3049 for b := 0 to High(SelectedObjects) do
3050 with SelectedObjects[b] do
3051 if Live and (ObjectType = OBJECT_PANEL) then
3052 with gPanels[SelectedObjects[b].ID] do
3053 if PanelType and not(PANEL_BACK or PANEL_FORE) <> 0 then
3054 begin
3055 // Левый верхний угол:
3056 aX := XX + (X div ScaleSz);
3057 aY := 1 + (Y div ScaleSz);
3058 // Размеры:
3059 aX2 := max(Width div ScaleSz, 1);
3060 aY2 := max(Height div ScaleSz, 1);
3061 // Правый нижний угол:
3062 aX2 := aX + aX2 - 1;
3063 aY2 := aY + aY2 - 1;
3065 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0)
3066 end;
3067 end;
3069 if (gMapInfo.Width > RenderPanel.Width) or
3070 (gMapInfo.Height > RenderPanel.Height) then
3071 begin
3072 // Окно, показывающее текущее положение экрана на карте:
3073 // Размеры окна:
3074 x := max(min(RenderPanel.Width, gMapInfo.Width) div ScaleSz, 1);
3075 y := max(min(RenderPanel.Height, gMapInfo.Height) div ScaleSz, 1);
3076 // Левый верхний угол:
3077 aX := XX + ((-MapOffset.X) div ScaleSz);
3078 aY := 1 + ((-MapOffset.Y) div ScaleSz);
3079 // Правый нижний угол:
3080 aX2 := aX + x - 1;
3081 aY2 := aY + y - 1;
3083 e_DrawFillQuad(aX, aY, aX2, aY2, 127, 192, 127, 127, B_BLEND);
3084 e_DrawQuad(aX, aY, aX2, aY2, 255, 0, 0);
3085 end;
3086 end; // Мини-карта
3088 e_EndRender();
3089 RenderPanel.SwapBuffers();
3090 end;
3092 procedure TMainForm.FormResize(Sender: TObject);
3093 begin
3094 e_SetViewPort(0, 0, RenderPanel.Width, RenderPanel.Height);
3096 if gMapInfo.Width >= RenderPanel.Width then
3097 sbHorizontal.Max := Normalize16(gMapInfo.Width-RenderPanel.Width+16)
3098 else
3099 sbHorizontal.Max := 0;
3101 if gMapInfo.Height >= RenderPanel.Height then
3102 sbVertical.Max := Normalize16(gMapInfo.Height-RenderPanel.Height+16)
3103 else
3104 sbVertical.Max := 0;
3106 MapOffset.X := -Normalize16(sbHorizontal.Position);
3107 MapOffset.Y := -Normalize16(sbVertical.Position);
3108 end;
3110 procedure SelectNextObject(X, Y: Integer; ObjectType: Byte; ID: DWORD);
3111 var
3112 j, j_max: Integer;
3113 res: Boolean;
3114 begin
3115 j_max := 0; // shut up compiler
3116 case ObjectType of
3117 OBJECT_PANEL:
3118 begin
3119 res := (gPanels <> nil) and
3120 PanelInShownLayer(gPanels[ID].PanelType) and
3121 g_CollidePoint(X, Y, gPanels[ID].X, gPanels[ID].Y,
3122 gPanels[ID].Width,
3123 gPanels[ID].Height);
3124 j_max := Length(gPanels) - 1;
3125 end;
3127 OBJECT_ITEM:
3128 begin
3129 res := (gItems <> nil) and
3130 LayerEnabled[LAYER_ITEMS] and
3131 g_CollidePoint(X, Y, gItems[ID].X, gItems[ID].Y,
3132 ItemSize[gItems[ID].ItemType][0],
3133 ItemSize[gItems[ID].ItemType][1]);
3134 j_max := Length(gItems) - 1;
3135 end;
3137 OBJECT_MONSTER:
3138 begin
3139 res := (gMonsters <> nil) and
3140 LayerEnabled[LAYER_MONSTERS] and
3141 g_CollidePoint(X, Y, gMonsters[ID].X, gMonsters[ID].Y,
3142 MonsterSize[gMonsters[ID].MonsterType].Width,
3143 MonsterSize[gMonsters[ID].MonsterType].Height);
3144 j_max := Length(gMonsters) - 1;
3145 end;
3147 OBJECT_AREA:
3148 begin
3149 res := (gAreas <> nil) and
3150 LayerEnabled[LAYER_AREAS] and
3151 g_CollidePoint(X, Y, gAreas[ID].X, gAreas[ID].Y,
3152 AreaSize[gAreas[ID].AreaType].Width,
3153 AreaSize[gAreas[ID].AreaType].Height);
3154 j_max := Length(gAreas) - 1;
3155 end;
3157 OBJECT_TRIGGER:
3158 begin
3159 res := (gTriggers <> nil) and
3160 LayerEnabled[LAYER_TRIGGERS] and
3161 g_CollidePoint(X, Y, gTriggers[ID].X, gTriggers[ID].Y,
3162 gTriggers[ID].Width,
3163 gTriggers[ID].Height);
3164 j_max := Length(gTriggers) - 1;
3165 end;
3167 else
3168 res := False;
3169 end;
3171 if not res then
3172 Exit;
3174 // Перебор ID: от ID-1 до 0; потом от High до ID+1:
3175 j := ID;
3177 while True do
3178 begin
3179 Dec(j);
3181 if j < 0 then
3182 j := j_max;
3183 if j = Integer(ID) then
3184 Break;
3186 case ObjectType of
3187 OBJECT_PANEL:
3188 res := PanelInShownLayer(gPanels[j].PanelType) and
3189 g_CollidePoint(X, Y, gPanels[j].X, gPanels[j].Y,
3190 gPanels[j].Width,
3191 gPanels[j].Height);
3192 OBJECT_ITEM:
3193 res := (gItems[j].ItemType <> ITEM_NONE) and
3194 g_CollidePoint(X, Y, gItems[j].X, gItems[j].Y,
3195 ItemSize[gItems[j].ItemType][0],
3196 ItemSize[gItems[j].ItemType][1]);
3197 OBJECT_MONSTER:
3198 res := (gMonsters[j].MonsterType <> MONSTER_NONE) and
3199 g_CollidePoint(X, Y, gMonsters[j].X, gMonsters[j].Y,
3200 MonsterSize[gMonsters[j].MonsterType].Width,
3201 MonsterSize[gMonsters[j].MonsterType].Height);
3202 OBJECT_AREA:
3203 res := (gAreas[j].AreaType <> AREA_NONE) and
3204 g_CollidePoint(X, Y, gAreas[j].X, gAreas[j].Y,
3205 AreaSize[gAreas[j].AreaType].Width,
3206 AreaSize[gAreas[j].AreaType].Height);
3207 OBJECT_TRIGGER:
3208 res := (gTriggers[j].TriggerType <> TRIGGER_NONE) and
3209 g_CollidePoint(X, Y, gTriggers[j].X, gTriggers[j].Y,
3210 gTriggers[j].Width,
3211 gTriggers[j].Height);
3212 else
3213 res := False;
3214 end;
3216 if res then
3217 begin
3218 SetLength(SelectedObjects, 1);
3220 SelectedObjects[0].ObjectType := ObjectType;
3221 SelectedObjects[0].ID := j;
3222 SelectedObjects[0].Live := True;
3224 FillProperty();
3225 Break;
3226 end;
3227 end;
3228 end;
3230 procedure TMainForm.RenderPanelMouseDown(Sender: TObject;
3231 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3232 var
3233 i: Integer;
3234 Rect: TRectWH;
3235 c1, c2, c3, c4: Boolean;
3236 item: TItem;
3237 area: TArea;
3238 monster: TMonster;
3239 IDArray: DWArray;
3240 begin
3241 MainForm.ActiveControl := RenderPanel;
3242 RenderPanel.SetFocus();
3244 RenderPanelMouseMove(RenderPanel, Shift, X, Y);
3246 if Button = mbLeft then // Left Mouse Button
3247 begin
3248 // Двигаем карту с помощью мыши и мини-карты:
3249 if ShowMap and
3250 g_CollidePoint(X, Y,
3251 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3252 1,
3253 max(gMapInfo.Width div (16 div Scale), 1),
3254 max(gMapInfo.Height div (16 div Scale), 1) ) then
3255 begin
3256 MoveMap(X, Y);
3257 MouseAction := MOUSEACTION_MOVEMAP;
3258 end
3259 else // Ставим предмет/монстра/область:
3260 if (pcObjects.ActivePageIndex in [1, 2, 3]) and
3261 (not (ssShift in Shift)) then
3262 begin
3263 case pcObjects.ActivePageIndex of
3264 1:
3265 if lbItemList.ItemIndex = -1 then
3266 ErrorMessageBox(_lc[I_MSG_CHOOSE_ITEM])
3267 else
3268 begin
3269 item.ItemType := lbItemList.ItemIndex + ITEM_MEDKIT_SMALL;
3270 if item.ItemType >= ITEM_WEAPON_KASTET then
3271 item.ItemType := item.ItemType + 2;
3272 item.X := MousePos.X-MapOffset.X;
3273 item.Y := MousePos.Y-MapOffset.Y;
3275 if not (ssCtrl in Shift) then
3276 begin
3277 item.X := item.X - (ItemSize[item.ItemType][0] div 2);
3278 item.Y := item.Y - ItemSize[item.ItemType][1];
3279 end;
3281 item.OnlyDM := cbOnlyDM.Checked;
3282 item.Fall := cbFall.Checked;
3283 Undo_Add(OBJECT_ITEM, AddItem(item));
3284 end;
3285 2:
3286 if lbMonsterList.ItemIndex = -1 then
3287 ErrorMessageBox(_lc[I_MSG_CHOOSE_MONSTER])
3288 else
3289 begin
3290 monster.MonsterType := lbMonsterList.ItemIndex + MONSTER_DEMON;
3291 monster.X := MousePos.X-MapOffset.X;
3292 monster.Y := MousePos.Y-MapOffset.Y;
3294 if not (ssCtrl in Shift) then
3295 begin
3296 monster.X := monster.X - (MonsterSize[monster.MonsterType].Width div 2);
3297 monster.Y := monster.Y - MonsterSize[monster.MonsterType].Height;
3298 end;
3300 if rbMonsterLeft.Checked then
3301 monster.Direction := D_LEFT
3302 else
3303 monster.Direction := D_RIGHT;
3304 Undo_Add(OBJECT_MONSTER, AddMonster(monster));
3305 end;
3306 3:
3307 if lbAreasList.ItemIndex = -1 then
3308 ErrorMessageBox(_lc[I_MSG_CHOOSE_AREA])
3309 else
3310 if (lbAreasList.ItemIndex + 1) <> AREA_DOMFLAG then
3311 begin
3312 area.AreaType := lbAreasList.ItemIndex + AREA_PLAYERPOINT1;
3313 area.X := MousePos.X-MapOffset.X;
3314 area.Y := MousePos.Y-MapOffset.Y;
3316 if not (ssCtrl in Shift) then
3317 begin
3318 area.X := area.X - (AreaSize[area.AreaType].Width div 2);
3319 area.Y := area.Y - AreaSize[area.AreaType].Height;
3320 end;
3322 if rbAreaLeft.Checked then
3323 area.Direction := D_LEFT
3324 else
3325 area.Direction := D_RIGHT;
3326 Undo_Add(OBJECT_AREA, AddArea(area));
3327 end;
3328 end;
3329 end
3330 else
3331 begin
3332 i := GetFirstSelected();
3334 // Выбираем объект под текущим:
3335 if (SelectedObjects <> nil) and
3336 (ssShift in Shift) and (i >= 0) and
3337 (SelectedObjects[i].Live) then
3338 begin
3339 if SelectedObjectCount() = 1 then
3340 SelectNextObject(X-MapOffset.X, Y-MapOffset.Y,
3341 SelectedObjects[i].ObjectType,
3342 SelectedObjects[i].ID);
3343 end
3344 else
3345 begin
3346 // Рисуем область триггера "Расширитель":
3347 if DrawPressRect and (i >= 0) and
3348 (SelectedObjects[i].ObjectType = OBJECT_TRIGGER) and
3349 (gTriggers[SelectedObjects[i].ID].TriggerType in
3350 [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) then
3351 MouseAction := MOUSEACTION_DRAWPRESS
3352 else // Рисуем панель:
3353 if pcObjects.ActivePageIndex = 0 then
3354 begin
3355 if (lbPanelType.ItemIndex >= 0) then
3356 MouseAction := MOUSEACTION_DRAWPANEL
3357 end
3358 else // Рисуем триггер:
3359 if (lbTriggersList.ItemIndex >= 0) then
3360 begin
3361 MouseAction := MOUSEACTION_DRAWTRIGGER;
3362 end;
3363 end;
3364 end;
3365 end; // if Button = mbLeft
3367 if Button = mbRight then // Right Mouse Button
3368 begin
3369 // Клик по мини-карте:
3370 if ShowMap and
3371 g_CollidePoint(X, Y,
3372 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3373 1,
3374 max(gMapInfo.Width div (16 div Scale), 1),
3375 max(gMapInfo.Height div (16 div Scale), 1) ) then
3376 begin
3377 MouseAction := MOUSEACTION_NOACTION;
3378 end
3379 else // Нужно что-то выбрать мышью:
3380 if SelectFlag <> SELECTFLAG_NONE then
3381 begin
3382 case SelectFlag of
3383 SELECTFLAG_TELEPORT:
3384 // Точку назначения телепортации:
3385 with gTriggers[SelectedObjects[
3386 GetFirstSelected() ].ID].Data.TargetPoint do
3387 begin
3388 X := MousePos.X-MapOffset.X;
3389 Y := MousePos.Y-MapOffset.Y;
3390 end;
3392 SELECTFLAG_SPAWNPOINT:
3393 // Точку создания монстра:
3394 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
3395 if TriggerType = TRIGGER_SPAWNMONSTER then
3396 begin
3397 Data.MonPos.X := MousePos.X-MapOffset.X;
3398 Data.MonPos.Y := MousePos.Y-MapOffset.Y;
3399 end
3400 else if TriggerType = TRIGGER_SPAWNITEM then
3401 begin // Точка создания предмета:
3402 Data.ItemPos.X := MousePos.X-MapOffset.X;
3403 Data.ItemPos.Y := MousePos.Y-MapOffset.Y;
3404 end
3405 else if TriggerType = TRIGGER_SHOT then
3406 begin // Точка создания выстрела:
3407 Data.ShotPos.X := MousePos.X-MapOffset.X;
3408 Data.ShotPos.Y := MousePos.Y-MapOffset.Y;
3409 end;
3411 SELECTFLAG_DOOR:
3412 // Дверь:
3413 begin
3414 IDArray := ObjectInRect(X-MapOffset.X,
3415 Y-MapOffset.Y,
3416 2, 2, OBJECT_PANEL, True);
3417 if IDArray <> nil then
3418 begin
3419 for i := 0 to High(IDArray) do
3420 if (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3421 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR) then
3422 begin
3423 gTriggers[SelectedObjects[
3424 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3425 Break;
3426 end;
3427 end
3428 else
3429 gTriggers[SelectedObjects[
3430 GetFirstSelected() ].ID].Data.PanelID := -1;
3431 end;
3433 SELECTFLAG_TEXTURE:
3434 // Панель с текстурой:
3435 begin
3436 IDArray := ObjectInRect(X-MapOffset.X,
3437 Y-MapOffset.Y,
3438 2, 2, OBJECT_PANEL, True);
3439 if IDArray <> nil then
3440 begin
3441 for i := 0 to High(IDArray) do
3442 if ((gPanels[IDArray[i]].PanelType in
3443 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3444 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3445 PANEL_STEP]) or
3446 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3447 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3448 (gPanels[IDArray[i]].TextureName <> '') then
3449 begin
3450 gTriggers[SelectedObjects[
3451 GetFirstSelected() ].ID].TexturePanel := IDArray[i];
3452 Break;
3453 end;
3454 end
3455 else
3456 gTriggers[SelectedObjects[
3457 GetFirstSelected() ].ID].TexturePanel := -1;
3458 end;
3460 SELECTFLAG_LIFT:
3461 // Лифт:
3462 begin
3463 IDArray := ObjectInRect(X-MapOffset.X,
3464 Y-MapOffset.Y,
3465 2, 2, OBJECT_PANEL, True);
3466 if IDArray <> nil then
3467 begin
3468 for i := 0 to High(IDArray) do
3469 if (gPanels[IDArray[i]].PanelType = PANEL_LIFTUP) or
3470 (gPanels[IDArray[i]].PanelType = PANEL_LIFTDOWN) or
3471 (gPanels[IDArray[i]].PanelType = PANEL_LIFTLEFT) or
3472 (gPanels[IDArray[i]].PanelType = PANEL_LIFTRIGHT) then
3473 begin
3474 gTriggers[SelectedObjects[
3475 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3476 Break;
3477 end;
3478 end
3479 else
3480 gTriggers[SelectedObjects[
3481 GetFirstSelected() ].ID].Data.PanelID := -1;
3482 end;
3484 SELECTFLAG_MONSTER:
3485 // Монстра:
3486 begin
3487 IDArray := ObjectInRect(X-MapOffset.X,
3488 Y-MapOffset.Y,
3489 2, 2, OBJECT_MONSTER, False);
3490 if IDArray <> nil then
3491 gTriggers[SelectedObjects[
3492 GetFirstSelected() ].ID].Data.MonsterID := IDArray[0]+1
3493 else
3494 gTriggers[SelectedObjects[
3495 GetFirstSelected() ].ID].Data.MonsterID := 0;
3496 end;
3498 SELECTFLAG_SHOTPANEL:
3499 // Панель индикации выстрела:
3500 begin
3501 if gTriggers[SelectedObjects[
3502 GetFirstSelected() ].ID].TriggerType = TRIGGER_SHOT then
3503 begin
3504 IDArray := ObjectInRect(X-MapOffset.X,
3505 Y-MapOffset.Y,
3506 2, 2, OBJECT_PANEL, True);
3507 if IDArray <> nil then
3508 begin
3509 for i := 0 to High(IDArray) do
3510 if ((gPanels[IDArray[i]].PanelType in
3511 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3512 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3513 PANEL_STEP]) or
3514 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3515 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3516 (gPanels[IDArray[i]].TextureName <> '') then
3517 begin
3518 gTriggers[SelectedObjects[
3519 GetFirstSelected() ].ID].Data.ShotPanelID := IDArray[i];
3520 Break;
3521 end;
3522 end
3523 else
3524 gTriggers[SelectedObjects[
3525 GetFirstSelected() ].ID].Data.ShotPanelID := -1;
3526 end;
3527 end;
3528 end;
3530 SelectFlag := SELECTFLAG_SELECTED;
3531 end
3532 else // if SelectFlag <> SELECTFLAG_NONE...
3533 begin
3534 // Что уже выбрано и не нажат Ctrl:
3535 if (SelectedObjects <> nil) and
3536 (not (ssCtrl in Shift)) then
3537 for i := 0 to High(SelectedObjects) do
3538 with SelectedObjects[i] do
3539 if Live then
3540 begin
3541 if (ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) and
3542 (SelectedObjectCount() = 1) then
3543 begin
3544 Rect := ObjectGetRect(ObjectType, ID);
3546 c1 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3547 Rect.X-2, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3548 c2 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3549 Rect.X+Rect.Width-3, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3550 c3 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3551 Rect.X+(Rect.Width div 2)-2, Rect.Y-2, 4, 4);
3552 c4 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3553 Rect.X+(Rect.Width div 2)-2, Rect.Y+Rect.Height-3, 4, 4);
3555 // Меняем размер панели или триггера:
3556 if c1 or c2 or c3 or c4 then
3557 begin
3558 MouseAction := MOUSEACTION_RESIZE;
3559 LastMovePoint := MousePos;
3561 if c1 or c2 then
3562 begin // Шире/уже
3563 ResizeType := RESIZETYPE_HORIZONTAL;
3564 if c1 then
3565 ResizeDirection := RESIZEDIR_LEFT
3566 else
3567 ResizeDirection := RESIZEDIR_RIGHT;
3568 RenderPanel.Cursor := crSizeWE;
3569 end
3570 else
3571 begin // Выше/ниже
3572 ResizeType := RESIZETYPE_VERTICAL;
3573 if c3 then
3574 ResizeDirection := RESIZEDIR_UP
3575 else
3576 ResizeDirection := RESIZEDIR_DOWN;
3577 RenderPanel.Cursor := crSizeNS;
3578 end;
3580 Break;
3581 end;
3582 end;
3584 // Перемещаем панель или триггер:
3585 if ObjectCollide(ObjectType, ID,
3586 X-MapOffset.X-1,
3587 Y-MapOffset.Y-1, 2, 2) then
3588 begin
3589 MouseAction := MOUSEACTION_MOVEOBJ;
3590 LastMovePoint := MousePos;
3592 Break;
3593 end;
3594 end;
3595 end;
3596 end; // if Button = mbRight
3598 MouseRDown := Button = mbRight;
3599 if MouseRDown then
3600 MouseRDownPos := MousePos;
3602 MouseLDown := Button = mbLeft;
3603 if MouseLDown then
3604 MouseLDownPos := MousePos;
3605 end;
3607 procedure TMainForm.RenderPanelMouseUp(Sender: TObject;
3608 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3609 var
3610 panel: TPanel;
3611 trigger: TTrigger;
3612 i: Integer;
3613 IDArray: DWArray;
3614 rRect: TRectWH;
3615 rSelectRect: Boolean;
3616 wWidth, wHeight: Word;
3617 TextureID: DWORD;
3618 begin
3619 if Button = mbLeft then
3620 MouseLDown := False;
3621 if Button = mbRight then
3622 MouseRDown := False;
3624 DrawRect := nil;
3625 ResizeType := RESIZETYPE_NONE;
3626 TextureID := 0;
3628 if Button = mbLeft then // Left Mouse Button
3629 begin
3630 if MouseAction <> MOUSEACTION_NONE then
3631 begin // Было действие мышью
3632 // Мышь сдвинулась во время удержания клавиши,
3633 // либо активирован режим быстрого рисования:
3634 if ((MousePos.X <> MouseLDownPos.X) and
3635 (MousePos.Y <> MouseLDownPos.Y)) or
3636 ((MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER]) and
3637 (ssCtrl in Shift)) then
3638 case MouseAction of
3639 // Рисовали панель:
3640 MOUSEACTION_DRAWPANEL:
3641 begin
3642 // Фон или передний план без текстуры - ошибка:
3643 if (lbPanelType.ItemIndex in [1, 2]) and
3644 (lbTextureList.ItemIndex = -1) then
3645 ErrorMessageBox(_lc[I_MSG_CHOOSE_TEXTURE])
3646 else // Назначаем параметры панели:
3647 begin
3648 case lbPanelType.ItemIndex of
3649 0: Panel.PanelType := PANEL_WALL;
3650 1: Panel.PanelType := PANEL_BACK;
3651 2: Panel.PanelType := PANEL_FORE;
3652 3: Panel.PanelType := PANEL_OPENDOOR;
3653 4: Panel.PanelType := PANEL_CLOSEDOOR;
3654 5: Panel.PanelType := PANEL_STEP;
3655 6: Panel.PanelType := PANEL_WATER;
3656 7: Panel.PanelType := PANEL_ACID1;
3657 8: Panel.PanelType := PANEL_ACID2;
3658 9: Panel.PanelType := PANEL_LIFTUP;
3659 10: Panel.PanelType := PANEL_LIFTDOWN;
3660 11: Panel.PanelType := PANEL_LIFTLEFT;
3661 12: Panel.PanelType := PANEL_LIFTRIGHT;
3662 13: Panel.PanelType := PANEL_BLOCKMON;
3663 end;
3665 Panel.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3666 Panel.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3667 if ssCtrl in Shift then
3668 begin
3669 wWidth := DotStep;
3670 wHeight := DotStep;
3671 if (lbTextureList.ItemIndex <> -1) and
3672 (not IsSpecialTextureSel()) then
3673 begin
3674 if not g_GetTexture(SelectedTexture(), TextureID) then
3675 g_GetTexture('NOTEXTURE', TextureID);
3676 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
3677 end;
3678 Panel.Width := wWidth;
3679 Panel.Height := wHeight;
3680 end
3681 else
3682 begin
3683 Panel.Width := Abs(MousePos.X-MouseLDownPos.X);
3684 Panel.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3685 end;
3687 // Лифты, блокМон или отсутствие текстуры - пустая текстура:
3688 if (lbPanelType.ItemIndex in [9, 10, 11, 12, 13]) or
3689 (lbTextureList.ItemIndex = -1) then
3690 begin
3691 Panel.TextureHeight := 1;
3692 Panel.TextureWidth := 1;
3693 Panel.TextureName := '';
3694 Panel.TextureID := TEXTURE_SPECIAL_NONE;
3695 end
3696 else // Есть текстура:
3697 begin
3698 Panel.TextureName := SelectedTexture();
3700 // Обычная текстура:
3701 if not IsSpecialTextureSel() then
3702 begin
3703 g_GetTextureSizeByName(Panel.TextureName,
3704 Panel.TextureWidth, Panel.TextureHeight);
3705 g_GetTexture(Panel.TextureName, Panel.TextureID);
3706 end
3707 else // Спец.текстура:
3708 begin
3709 Panel.TextureHeight := 1;
3710 Panel.TextureWidth := 1;
3711 Panel.TextureID := SpecialTextureID(SelectedTexture());
3712 end;
3713 end;
3715 Panel.Alpha := 0;
3716 Panel.Blending := False;
3718 Undo_Add(OBJECT_PANEL, AddPanel(Panel));
3719 end;
3720 end;
3722 // Рисовали триггер:
3723 MOUSEACTION_DRAWTRIGGER:
3724 begin
3725 trigger.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3726 trigger.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3727 if ssCtrl in Shift then
3728 begin
3729 wWidth := DotStep;
3730 wHeight := DotStep;
3731 trigger.Width := wWidth;
3732 trigger.Height := wHeight;
3733 end
3734 else
3735 begin
3736 trigger.Width := Abs(MousePos.X-MouseLDownPos.X);
3737 trigger.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3738 end;
3740 trigger.Enabled := True;
3741 trigger.TriggerType := lbTriggersList.ItemIndex+1;
3742 trigger.TexturePanel := -1;
3744 // Типы активации:
3745 trigger.ActivateType := 0;
3747 if clbActivationType.Checked[0] then
3748 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERCOLLIDE;
3749 if clbActivationType.Checked[1] then
3750 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERCOLLIDE;
3751 if clbActivationType.Checked[2] then
3752 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERPRESS;
3753 if clbActivationType.Checked[3] then
3754 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERPRESS;
3755 if clbActivationType.Checked[4] then
3756 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_SHOT;
3757 if clbActivationType.Checked[5] then
3758 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_NOMONSTER;
3760 // Необходимые для активации ключи:
3761 trigger.Key := 0;
3763 if clbKeys.Checked[0] then
3764 trigger.Key := Trigger.Key or KEY_RED;
3765 if clbKeys.Checked[1] then
3766 trigger.Key := Trigger.Key or KEY_GREEN;
3767 if clbKeys.Checked[2] then
3768 trigger.Key := Trigger.Key or KEY_BLUE;
3769 if clbKeys.Checked[3] then
3770 trigger.Key := Trigger.Key or KEY_REDTEAM;
3771 if clbKeys.Checked[4] then
3772 trigger.Key := Trigger.Key or KEY_BLUETEAM;
3774 // Параметры триггера:
3775 FillByte(trigger.Data.Default[0], 128, 0);
3777 case trigger.TriggerType of
3778 // Переключаемая панель:
3779 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
3780 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
3781 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
3782 begin
3783 Trigger.Data.PanelID := -1;
3784 end;
3786 // Телепортация:
3787 TRIGGER_TELEPORT:
3788 begin
3789 trigger.Data.TargetPoint.X := trigger.X-64;
3790 trigger.Data.TargetPoint.Y := trigger.Y-64;
3791 trigger.Data.d2d_teleport := True;
3792 trigger.Data.TlpDir := 0;
3793 end;
3795 // Изменение других триггеров:
3796 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
3797 TRIGGER_ONOFF:
3798 begin
3799 trigger.Data.Count := 1;
3800 end;
3802 // Звук:
3803 TRIGGER_SOUND:
3804 begin
3805 trigger.Data.Volume := 255;
3806 trigger.Data.Pan := 127;
3807 trigger.Data.PlayCount := 1;
3808 trigger.Data.Local := True;
3809 trigger.Data.SoundSwitch := False;
3810 end;
3812 // Музыка:
3813 TRIGGER_MUSIC:
3814 begin
3815 trigger.Data.MusicAction := 1;
3816 end;
3818 // Создание монстра:
3819 TRIGGER_SPAWNMONSTER:
3820 begin
3821 trigger.Data.MonType := MONSTER_ZOMBY;
3822 trigger.Data.MonPos.X := trigger.X-64;
3823 trigger.Data.MonPos.Y := trigger.Y-64;
3824 trigger.Data.MonHealth := 0;
3825 trigger.Data.MonActive := False;
3826 trigger.Data.MonCount := 1;
3827 end;
3829 // Создание предмета:
3830 TRIGGER_SPAWNITEM:
3831 begin
3832 trigger.Data.ItemType := ITEM_AMMO_BULLETS;
3833 trigger.Data.ItemPos.X := trigger.X-64;
3834 trigger.Data.ItemPos.Y := trigger.Y-64;
3835 trigger.Data.ItemOnlyDM := False;
3836 trigger.Data.ItemFalls := False;
3837 trigger.Data.ItemCount := 1;
3838 trigger.Data.ItemMax := 0;
3839 trigger.Data.ItemDelay := 0;
3840 end;
3842 // Ускорение:
3843 TRIGGER_PUSH:
3844 begin
3845 trigger.Data.PushAngle := 90;
3846 trigger.Data.PushForce := 10;
3847 trigger.Data.ResetVel := True;
3848 end;
3850 TRIGGER_SCORE:
3851 begin
3852 trigger.Data.ScoreCount := 1;
3853 trigger.Data.ScoreCon := True;
3854 trigger.Data.ScoreMsg := True;
3855 end;
3857 TRIGGER_MESSAGE:
3858 begin
3859 trigger.Data.MessageKind := 0;
3860 trigger.Data.MessageSendTo := 0;
3861 trigger.Data.MessageText := '';
3862 trigger.Data.MessageTime := 144;
3863 end;
3865 TRIGGER_DAMAGE:
3866 begin
3867 trigger.Data.DamageValue := 5;
3868 trigger.Data.DamageInterval := 12;
3869 end;
3871 TRIGGER_HEALTH:
3872 begin
3873 trigger.Data.HealValue := 5;
3874 trigger.Data.HealInterval := 36;
3875 end;
3877 TRIGGER_SHOT:
3878 begin
3879 trigger.Data.ShotType := TRIGGER_SHOT_BULLET;
3880 trigger.Data.ShotSound := True;
3881 trigger.Data.ShotPanelID := -1;
3882 trigger.Data.ShotTarget := 0;
3883 trigger.Data.ShotIntSight := 0;
3884 trigger.Data.ShotAim := TRIGGER_SHOT_AIM_DEFAULT;
3885 trigger.Data.ShotPos.X := trigger.X-64;
3886 trigger.Data.ShotPos.Y := trigger.Y-64;
3887 trigger.Data.ShotAngle := 0;
3888 trigger.Data.ShotWait := 18;
3889 trigger.Data.ShotAccuracy := 0;
3890 trigger.Data.ShotAmmo := 0;
3891 trigger.Data.ShotIntReload := 0;
3892 end;
3894 TRIGGER_EFFECT:
3895 begin
3896 trigger.Data.FXCount := 1;
3897 trigger.Data.FXType := TRIGGER_EFFECT_PARTICLE;
3898 trigger.Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
3899 trigger.Data.FXColorR := 0;
3900 trigger.Data.FXColorG := 0;
3901 trigger.Data.FXColorB := 255;
3902 trigger.Data.FXPos := TRIGGER_EFFECT_POS_CENTER;
3903 trigger.Data.FXWait := 1;
3904 trigger.Data.FXVelX := 0;
3905 trigger.Data.FXVelY := -20;
3906 trigger.Data.FXSpreadL := 5;
3907 trigger.Data.FXSpreadR := 5;
3908 trigger.Data.FXSpreadU := 4;
3909 trigger.Data.FXSpreadD := 0;
3910 end;
3911 end;
3913 Undo_Add(OBJECT_TRIGGER, AddTrigger(trigger));
3914 end;
3916 // Рисовали область триггера "Расширитель":
3917 MOUSEACTION_DRAWPRESS:
3918 with gTriggers[SelectedObjects[GetFirstSelected].ID] do
3919 begin
3920 Data.tX := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3921 Data.tY := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3922 Data.tWidth := Abs(MousePos.X-MouseLDownPos.X);
3923 Data.tHeight := Abs(MousePos.Y-MouseLDownPos.Y);
3925 DrawPressRect := False;
3926 end;
3927 end;
3929 MouseAction := MOUSEACTION_NONE;
3930 end;
3931 end // if Button = mbLeft...
3932 else // Right Mouse Button:
3933 begin
3934 if MouseAction = MOUSEACTION_NOACTION then
3935 begin
3936 MouseAction := MOUSEACTION_NONE;
3937 Exit;
3938 end;
3940 // Объект передвинут или изменен в размере:
3941 if MouseAction in [MOUSEACTION_MOVEOBJ, MOUSEACTION_RESIZE] then
3942 begin
3943 MouseAction := MOUSEACTION_NONE;
3944 FillProperty();
3945 Exit;
3946 end;
3948 // Еще не все выбрали:
3949 if SelectFlag <> SELECTFLAG_NONE then
3950 begin
3951 if SelectFlag = SELECTFLAG_SELECTED then
3952 SelectFlag := SELECTFLAG_NONE;
3953 FillProperty();
3954 Exit;
3955 end;
3957 // Мышь сдвинулась во время удержания клавиши:
3958 if (MousePos.X <> MouseRDownPos.X) and
3959 (MousePos.Y <> MouseRDownPos.Y) then
3960 begin
3961 rSelectRect := True;
3963 rRect.X := Min(MousePos.X, MouseRDownPos.X)-MapOffset.X;
3964 rRect.Y := Min(MousePos.Y, MouseRDownPos.Y)-MapOffset.Y;
3965 rRect.Width := Abs(MousePos.X-MouseRDownPos.X);
3966 rRect.Height := Abs(MousePos.Y-MouseRDownPos.Y);
3967 end
3968 else // Мышь не сдвинулась - нет прямоугольника:
3969 begin
3970 rSelectRect := False;
3972 rRect.X := X-MapOffset.X-1;
3973 rRect.Y := Y-MapOffset.Y-1;
3974 rRect.Width := 2;
3975 rRect.Height := 2;
3976 end;
3978 // Если зажат Ctrl - выделять еще, иначе только один выделенный объект:
3979 if not (ssCtrl in Shift) then
3980 RemoveSelectFromObjects();
3982 // Выделяем всё в выбранном прямоугольнике:
3983 IDArray := ObjectInRect(rRect.X, rRect.Y,
3984 rRect.Width, rRect.Height,
3985 pcObjects.ActivePageIndex+1, rSelectRect);
3987 if IDArray <> nil then
3988 for i := 0 to High(IDArray) do
3989 SelectObject(pcObjects.ActivePageIndex+1, IDArray[i],
3990 (ssCtrl in Shift) or rSelectRect);
3992 FillProperty();
3993 end;
3994 end;
3996 procedure TMainForm.RenderPanelPaint(Sender: TObject);
3997 begin
3998 Draw();
3999 end;
4001 function TMainForm.RenderMousePos(): Types.TPoint;
4002 begin
4003 Result := RenderPanel.ScreenToClient(Mouse.CursorPos);
4004 end;
4006 procedure TMainForm.RenderPanelMouseMove(Sender: TObject;
4007 Shift: TShiftState; X, Y: Integer);
4008 var
4009 sX, sY: Integer;
4010 dWidth, dHeight: Integer;
4011 _id: Integer;
4012 TextureID: DWORD;
4013 wWidth, wHeight: Word;
4014 begin
4015 _id := GetFirstSelected();
4016 TextureID := 0;
4018 // Рисуем панель с текстурой, сетка - размеры текстуры:
4019 if (MouseAction = MOUSEACTION_DRAWPANEL) and
4020 (lbPanelType.ItemIndex in [0..8]) and
4021 (lbTextureList.ItemIndex <> -1) and
4022 (not IsSpecialTextureSel()) then
4023 begin
4024 sX := StrToIntDef(lTextureWidth.Caption, DotStep);
4025 sY := StrToIntDef(lTextureHeight.Caption, DotStep);
4026 end
4027 else
4028 // Меняем размер панели с текстурой, сетка - размеры текстуры:
4029 if (MouseAction = MOUSEACTION_RESIZE) and
4030 ( (SelectedObjects[_id].ObjectType = OBJECT_PANEL) and
4031 IsTexturedPanel(gPanels[SelectedObjects[_id].ID].PanelType) and
4032 (gPanels[SelectedObjects[_id].ID].TextureName <> '') and
4033 (not IsSpecialTexture(gPanels[SelectedObjects[_id].ID].TextureName)) ) then
4034 begin
4035 sX := gPanels[SelectedObjects[_id].ID].TextureWidth;
4036 sY := gPanels[SelectedObjects[_id].ID].TextureHeight;
4037 end
4038 else
4039 // Выравнивание по сетке:
4040 if SnapToGrid then
4041 begin
4042 sX := DotStep;
4043 sY := DotStep;
4044 end
4045 else // Нет выравнивания по сетке:
4046 begin
4047 sX := 1;
4048 sY := 1;
4049 end;
4051 // Новая позиция мыши:
4052 if MouseLDown then
4053 begin // Зажата левая кнопка мыши
4054 MousePos.X := (Round((X-MouseLDownPos.X)/sX)*sX)+MouseLDownPos.X;
4055 MousePos.Y := (Round((Y-MouseLDownPos.Y)/sY)*sY)+MouseLDownPos.Y;
4056 end
4057 else
4058 if MouseRDown then
4059 begin // Зажата правая кнопка мыши
4060 MousePos.X := (Round((X-MouseRDownPos.X)/sX)*sX)+MouseRDownPos.X;
4061 MousePos.Y := (Round((Y-MouseRDownPos.Y)/sY)*sY)+MouseRDownPos.Y;
4062 end
4063 else
4064 begin // Кнопки мыши не зажаты
4065 MousePos.X := (Round(X/sX)*sX);
4066 MousePos.Y := (Round(Y/sY)*sY);
4067 end;
4069 // Изменение размера закончилось - ставим обычный курсор:
4070 if ResizeType = RESIZETYPE_NONE then
4071 RenderPanel.Cursor := crDefault;
4073 // Зажата только правая кнопка мыши:
4074 if (not MouseLDown) and (MouseRDown) then
4075 begin
4076 // Рисуем прямоугольник выделения:
4077 if MouseAction = MOUSEACTION_NONE then
4078 begin
4079 if DrawRect = nil then
4080 New(DrawRect);
4081 DrawRect.Top := MouseRDownPos.y;
4082 DrawRect.Left := MouseRDownPos.x;
4083 DrawRect.Bottom := MousePos.y;
4084 DrawRect.Right := MousePos.x;
4085 end
4086 else
4087 // Двигаем выделенные объекты:
4088 if MouseAction = MOUSEACTION_MOVEOBJ then
4089 begin
4090 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
4091 MousePos.X-LastMovePoint.X+WASDOffset.X,
4092 MousePos.Y-LastMovePoint.Y+WASDOffset.Y);
4093 WASDOffset.X := 0;
4094 WASDOffset.Y := 0;
4095 end
4096 else
4097 // Меняем размер выделенного объекта:
4098 if MouseAction = MOUSEACTION_RESIZE then
4099 begin
4100 if (SelectedObjectCount = 1) and
4101 (SelectedObjects[GetFirstSelected].Live) then
4102 begin
4103 dWidth := MousePos.X-LastMovePoint.X+WASDOffset.X;
4104 dHeight := MousePos.Y-LastMovePoint.Y+WASDOffset.Y;
4105 WASDOffset.X := 0;
4106 WASDOffset.Y := 0;
4108 case ResizeType of
4109 RESIZETYPE_VERTICAL: dWidth := 0;
4110 RESIZETYPE_HORIZONTAL: dHeight := 0;
4111 end;
4113 case ResizeDirection of
4114 RESIZEDIR_UP: dHeight := -dHeight;
4115 RESIZEDIR_LEFT: dWidth := -dWidth;
4116 end;
4118 ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
4119 SelectedObjects[GetFirstSelected].ID,
4120 dWidth, dHeight, ResizeDirection);
4122 LastMovePoint := MousePos;
4123 end;
4124 end;
4125 end;
4127 // Зажата только левая кнопка мыши:
4128 if (not MouseRDown) and (MouseLDown) then
4129 begin
4130 // Рисуем прямоугольник планирования панели:
4131 if MouseAction in [MOUSEACTION_DRAWPANEL,
4132 MOUSEACTION_DRAWTRIGGER,
4133 MOUSEACTION_DRAWPRESS] then
4134 begin
4135 if DrawRect = nil then
4136 New(DrawRect);
4137 if ssCtrl in Shift then
4138 begin
4139 wWidth := DotStep;
4140 wHeight := DotStep;
4141 if (lbTextureList.ItemIndex <> -1) and (not IsSpecialTextureSel()) and
4142 (MouseAction = MOUSEACTION_DRAWPANEL) then
4143 begin
4144 if not g_GetTexture(SelectedTexture(), TextureID) then
4145 g_GetTexture('NOTEXTURE', TextureID);
4146 g_GetTextureSizeByID(TextureID, wWidth, wHeight);
4147 end;
4148 DrawRect.Top := MouseLDownPos.y;
4149 DrawRect.Left := MouseLDownPos.x;
4150 DrawRect.Bottom := DrawRect.Top + wHeight;
4151 DrawRect.Right := DrawRect.Left + wWidth;
4152 end
4153 else
4154 begin
4155 DrawRect.Top := MouseLDownPos.y;
4156 DrawRect.Left := MouseLDownPos.x;
4157 DrawRect.Bottom := MousePos.y;
4158 DrawRect.Right := MousePos.x;
4159 end;
4160 end
4161 else // Двигаем карту:
4162 if MouseAction = MOUSEACTION_MOVEMAP then
4163 begin
4164 MoveMap(X, Y);
4165 end;
4166 end;
4168 // Клавиши мыши не зажаты:
4169 if (not MouseRDown) and (not MouseLDown) then
4170 DrawRect := nil;
4172 // Строка состояния - координаты мыши:
4173 StatusBar.Panels[1].Text := Format('(%d:%d)',
4174 [MousePos.X-MapOffset.X, MousePos.Y-MapOffset.Y]);
4175 end;
4177 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
4178 begin
4179 CanClose := MessageBox(0, PChar(_lc[I_MSG_EXIT_PROMT]),
4180 PChar(_lc[I_MSG_EXIT]),
4181 MB_ICONQUESTION or MB_YESNO or
4182 MB_DEFBUTTON1) = idYes;
4183 end;
4185 procedure TMainForm.aExitExecute(Sender: TObject);
4186 begin
4187 Close();
4188 end;
4190 procedure TMainForm.FormDestroy(Sender: TObject);
4191 var
4192 config: TConfig;
4193 i: Integer;
4194 begin
4195 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
4197 if WindowState <> wsMaximized then
4198 begin
4199 config.WriteInt('Editor', 'XPos', Left);
4200 config.WriteInt('Editor', 'YPos', Top);
4201 config.WriteInt('Editor', 'Width', Width);
4202 config.WriteInt('Editor', 'Height', Height);
4203 end
4204 else
4205 begin
4206 config.WriteInt('Editor', 'XPos', RestoredLeft);
4207 config.WriteInt('Editor', 'YPos', RestoredTop);
4208 config.WriteInt('Editor', 'Width', RestoredWidth);
4209 config.WriteInt('Editor', 'Height', RestoredHeight);
4210 end;
4211 config.WriteBool('Editor', 'Maximize', WindowState = wsMaximized);
4212 config.WriteBool('Editor', 'Minimap', ShowMap);
4213 config.WriteInt('Editor', 'PanelProps', PanelProps.ClientWidth);
4214 config.WriteInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
4215 config.WriteBool('Editor', 'DotEnable', DotEnable);
4216 config.WriteInt('Editor', 'DotStep', DotStep);
4217 config.WriteStr('Editor', 'LastOpenDir', OpenDialog.InitialDir);
4218 config.WriteStr('Editor', 'LastSaveDir', SaveDialog.InitialDir);
4219 config.WriteBool('Editor', 'EdgeShow', drEdge[3] < 255);
4220 config.WriteInt('Editor', 'EdgeColor', gColorEdge);
4221 config.WriteInt('Editor', 'EdgeAlpha', gAlphaEdge);
4222 config.WriteInt('Editor', 'LineAlpha', gAlphaTriggerLine);
4223 config.WriteInt('Editor', 'TriggerAlpha', gAlphaTriggerArea);
4225 for i := 0 to RecentCount-1 do
4226 if i < RecentFiles.Count then
4227 config.WriteStr('RecentFiles', IntToStr(i+1), RecentFiles[i])
4228 else
4229 config.WriteStr('RecentFiles', IntToStr(i+1), '');
4230 RecentFiles.Free();
4232 config.SaveFile(EditorDir+'Editor.cfg');
4233 config.Free();
4235 slInvalidTextures.Free;
4236 end;
4238 procedure TMainForm.FormDropFiles(Sender: TObject;
4239 const FileNames: array of String);
4240 begin
4241 if Length(FileNames) <> 1 then
4242 Exit;
4244 OpenMapFile(FileNames[0]);
4245 end;
4247 procedure TMainForm.RenderPanelResize(Sender: TObject);
4248 begin
4249 if MainForm.Visible then
4250 MainForm.Resize();
4251 end;
4253 procedure TMainForm.Splitter1Moved(Sender: TObject);
4254 begin
4255 FormResize(Sender);
4256 end;
4258 procedure TMainForm.aMapOptionsExecute(Sender: TObject);
4259 var
4260 ResName: String;
4261 begin
4262 MapOptionsForm.ShowModal();
4264 ResName := OpenedMap;
4265 while (Pos(':\', ResName) > 0) do
4266 Delete(ResName, 1, Pos(':\', ResName) + 1);
4268 UpdateCaption(gMapInfo.Name, ExtractFileName(OpenedWAD), ResName);
4269 end;
4271 procedure TMainForm.aAboutExecute(Sender: TObject);
4272 begin
4273 AboutForm.ShowModal();
4274 end;
4276 procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
4277 Shift: TShiftState);
4278 var
4279 dx, dy, i: Integer;
4280 FileName: String;
4281 begin
4282 if (not EditingProperties) then
4283 begin
4284 if Key = Ord('1') then
4285 SwitchLayer(LAYER_BACK);
4286 if Key = Ord('2') then
4287 SwitchLayer(LAYER_WALLS);
4288 if Key = Ord('3') then
4289 SwitchLayer(LAYER_FOREGROUND);
4290 if Key = Ord('4') then
4291 SwitchLayer(LAYER_STEPS);
4292 if Key = Ord('5') then
4293 SwitchLayer(LAYER_WATER);
4294 if Key = Ord('6') then
4295 SwitchLayer(LAYER_ITEMS);
4296 if Key = Ord('7') then
4297 SwitchLayer(LAYER_MONSTERS);
4298 if Key = Ord('8') then
4299 SwitchLayer(LAYER_AREAS);
4300 if Key = Ord('9') then
4301 SwitchLayer(LAYER_TRIGGERS);
4302 if Key = Ord('0') then
4303 tbShowClick(tbShow);
4305 if Key = Ord('V') then
4306 begin // Поворот монстров и областей:
4307 if (SelectedObjects <> nil) then
4308 begin
4309 for i := 0 to High(SelectedObjects) do
4310 if (SelectedObjects[i].Live) then
4311 begin
4312 if (SelectedObjects[i].ObjectType = OBJECT_MONSTER) then
4313 begin
4314 g_ChangeDir(gMonsters[SelectedObjects[i].ID].Direction);
4315 end
4316 else
4317 if (SelectedObjects[i].ObjectType = OBJECT_AREA) then
4318 begin
4319 g_ChangeDir(gAreas[SelectedObjects[i].ID].Direction);
4320 end;
4321 end;
4322 end
4323 else
4324 begin
4325 if pcObjects.ActivePage = tsMonsters then
4326 begin
4327 if rbMonsterLeft.Checked then
4328 rbMonsterRight.Checked := True
4329 else
4330 rbMonsterLeft.Checked := True;
4331 end;
4332 if pcObjects.ActivePage = tsAreas then
4333 begin
4334 if rbAreaLeft.Checked then
4335 rbAreaRight.Checked := True
4336 else
4337 rbAreaLeft.Checked := True;
4338 end;
4339 end;
4340 end;
4342 if not (ssCtrl in Shift) then
4343 begin
4344 // Быстрое превью карты:
4345 if Key = Ord('E') then
4346 begin
4347 if PreviewMode = 0 then
4348 PreviewMode := 2;
4349 end;
4351 // Вертикальный скролл карты:
4352 with sbVertical do
4353 begin
4354 if Key = Ord('W') then
4355 begin
4356 if (MouseLDown or MouseRDown) and (Position >= DotStep) then
4357 begin
4358 Dec(WASDOffset.Y, DotStep);
4359 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4360 end;
4361 Position := IfThen(Position > DotStep, Position-DotStep, 0);
4362 MapOffset.Y := -Round(Position/16) * 16;
4363 end;
4365 if Key = Ord('S') then
4366 begin
4367 if (MouseLDown or MouseRDown) and (Position+DotStep <= Max) then
4368 begin
4369 Inc(WASDOffset.Y, DotStep);
4370 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4371 end;
4372 Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
4373 MapOffset.Y := -Round(Position/16) * 16;
4374 end;
4375 end;
4377 // Горизонтальный скролл карты:
4378 with sbHorizontal do
4379 begin
4380 if Key = Ord('A') then
4381 begin
4382 if (MouseLDown or MouseRDown) and (Position >= DotStep) then
4383 begin
4384 Dec(WASDOffset.X, DotStep);
4385 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4386 end;
4387 Position := IfThen(Position > DotStep, Position-DotStep, 0);
4388 MapOffset.X := -Round(Position/16) * 16;
4389 end;
4391 if Key = Ord('D') then
4392 begin
4393 if (MouseLDown or MouseRDown) and (Position+DotStep <= Max) then
4394 begin
4395 Inc(WASDOffset.X, DotStep);
4396 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4397 end;
4398 Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
4399 MapOffset.X := -Round(Position/16) * 16;
4400 end;
4401 end;
4402 end
4403 else // ssCtrl in Shift
4404 begin
4405 if ssShift in Shift then
4406 begin
4407 // Вставка по абсолютному смещению:
4408 if Key = Ord('V') then
4409 aPasteObjectExecute(Sender);
4410 end;
4411 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
4412 end;
4413 end;
4415 // Удалить выделенные объекты:
4416 if (Key = VK_DELETE) and (SelectedObjects <> nil) and
4417 RenderPanel.Focused() then
4418 DeleteSelectedObjects();
4420 // Снять выделение:
4421 if (Key = VK_ESCAPE) and (SelectedObjects <> nil) then
4422 RemoveSelectFromObjects();
4424 // Передвинуть объекты:
4425 if MainForm.ActiveControl = RenderPanel then
4426 begin
4427 dx := 0;
4428 dy := 0;
4430 if Key = VK_NUMPAD4 then
4431 dx := IfThen(ssAlt in Shift, -1, -DotStep);
4432 if Key = VK_NUMPAD6 then
4433 dx := IfThen(ssAlt in Shift, 1, DotStep);
4434 if Key = VK_NUMPAD8 then
4435 dy := IfThen(ssAlt in Shift, -1, -DotStep);
4436 if Key = VK_NUMPAD5 then
4437 dy := IfThen(ssAlt in Shift, 1, DotStep);
4439 if (dx <> 0) or (dy <> 0) then
4440 begin
4441 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift, dx, dy);
4442 Key := 0;
4443 end;
4444 end;
4446 if ssCtrl in Shift then
4447 begin
4448 // Выбор панели с текстурой для триггера
4449 if Key = Ord('T') then
4450 begin
4451 DrawPressRect := False;
4452 if SelectFlag = SELECTFLAG_TEXTURE then
4453 begin
4454 SelectFlag := SELECTFLAG_NONE;
4455 Exit;
4456 end;
4457 vleObjectProperty.FindRow(_lc[I_PROP_TR_TEXTURE_PANEL], i);
4458 if i > 0 then
4459 SelectFlag := SELECTFLAG_TEXTURE;
4460 end;
4462 if Key = Ord('D') then
4463 begin
4464 SelectFlag := SELECTFLAG_NONE;
4465 if DrawPressRect then
4466 begin
4467 DrawPressRect := False;
4468 Exit;
4469 end;
4470 i := -1;
4472 // Выбор области воздействия, в зависимости от типа триггера
4473 vleObjectProperty.FindRow(_lc[I_PROP_TR_EX_AREA], i);
4474 if i > 0 then
4475 begin
4476 DrawPressRect := True;
4477 Exit;
4478 end;
4479 vleObjectProperty.FindRow(_lc[I_PROP_TR_DOOR_PANEL], i);
4480 if i <= 0 then
4481 vleObjectProperty.FindRow(_lc[I_PROP_TR_TRAP_PANEL], i);
4482 if i > 0 then
4483 begin
4484 SelectFlag := SELECTFLAG_DOOR;
4485 Exit;
4486 end;
4487 vleObjectProperty.FindRow(_lc[I_PROP_TR_LIFT_PANEL], i);
4488 if i > 0 then
4489 begin
4490 SelectFlag := SELECTFLAG_LIFT;
4491 Exit;
4492 end;
4493 vleObjectProperty.FindRow(_lc[I_PROP_TR_TELEPORT_TO], i);
4494 if i > 0 then
4495 begin
4496 SelectFlag := SELECTFLAG_TELEPORT;
4497 Exit;
4498 end;
4499 vleObjectProperty.FindRow(_lc[I_PROP_TR_SPAWN_TO], i);
4500 if i > 0 then
4501 begin
4502 SelectFlag := SELECTFLAG_SPAWNPOINT;
4503 Exit;
4504 end;
4506 // Выбор основного параметра, в зависимости от типа триггера
4507 vleObjectProperty.FindRow(_lc[I_PROP_TR_NEXT_MAP], i);
4508 if i > 0 then
4509 begin
4510 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
4511 SelectMapForm.Caption := _lc[I_CAP_SELECT];
4512 SelectMapForm.GetMaps(FileName);
4514 if SelectMapForm.ShowModal() = mrOK then
4515 begin
4516 vleObjectProperty.Cells[1, i] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
4517 bApplyProperty.Click();
4518 end;
4519 Exit;
4520 end;
4521 vleObjectProperty.FindRow(_lc[I_PROP_TR_SOUND_NAME], i);
4522 if i <= 0 then
4523 vleObjectProperty.FindRow(_lc[I_PROP_TR_MUSIC_NAME], i);
4524 if i > 0 then
4525 begin
4526 AddSoundForm.OKFunction := nil;
4527 AddSoundForm.lbResourcesList.MultiSelect := False;
4528 AddSoundForm.SetResource := vleObjectProperty.Cells[1, i];
4530 if (AddSoundForm.ShowModal() = mrOk) then
4531 begin
4532 vleObjectProperty.Cells[1, i] := AddSoundForm.ResourceName;
4533 bApplyProperty.Click();
4534 end;
4535 Exit;
4536 end;
4537 vleObjectProperty.FindRow(_lc[I_PROP_TR_PUSH_ANGLE], i);
4538 if i <= 0 then
4539 vleObjectProperty.FindRow(_lc[I_PROP_TR_MESSAGE_TEXT], i);
4540 if i > 0 then
4541 begin
4542 vleObjectProperty.Row := i;
4543 vleObjectProperty.SetFocus();
4544 Exit;
4545 end;
4546 end;
4547 end;
4548 end;
4550 procedure TMainForm.aOptimizeExecute(Sender: TObject);
4551 begin
4552 RemoveSelectFromObjects();
4553 MapOptimizationForm.ShowModal();
4554 end;
4556 procedure TMainForm.aCheckMapExecute(Sender: TObject);
4557 begin
4558 MapCheckForm.ShowModal();
4559 end;
4561 procedure TMainForm.bbAddTextureClick(Sender: TObject);
4562 begin
4563 AddTextureForm.lbResourcesList.MultiSelect := True;
4564 AddTextureForm.ShowModal();
4565 end;
4567 procedure TMainForm.lbTextureListClick(Sender: TObject);
4568 var
4569 TextureID: DWORD;
4570 TextureWidth, TextureHeight: Word;
4571 begin
4572 TextureID := 0;
4573 TextureWidth := 0;
4574 TextureHeight := 0;
4575 if (lbTextureList.ItemIndex <> -1) and
4576 (not IsSpecialTextureSel()) then
4577 begin
4578 if g_GetTexture(SelectedTexture(), TextureID) then
4579 begin
4580 g_GetTextureSizeByID(TextureID, TextureWidth, TextureHeight);
4582 lTextureWidth.Caption := IntToStr(TextureWidth);
4583 lTextureHeight.Caption := IntToStr(TextureHeight);
4584 end else
4585 begin
4586 lTextureWidth.Caption := _lc[I_NOT_ACCESSIBLE];
4587 lTextureHeight.Caption := _lc[I_NOT_ACCESSIBLE];
4588 end;
4589 end
4590 else
4591 begin
4592 lTextureWidth.Caption := '';
4593 lTextureHeight.Caption := '';
4594 end;
4595 end;
4597 procedure TMainForm.lbTextureListDrawItem(Control: TWinControl; Index: Integer;
4598 ARect: TRect; State: TOwnerDrawState);
4599 begin
4600 with Control as TListBox do
4601 begin
4602 if LCLType.odSelected in State then
4603 begin
4604 Canvas.Brush.Color := clHighlight;
4605 Canvas.Font.Color := clHighlightText;
4606 end else
4607 if (Items <> nil) and (Index >= 0) then
4608 if slInvalidTextures.IndexOf(Items[Index]) > -1 then
4609 begin
4610 Canvas.Brush.Color := clRed;
4611 Canvas.Font.Color := clWhite;
4612 end;
4613 Canvas.FillRect(ARect);
4614 Canvas.TextRect(ARect, ARect.Left, ARect.Top, Items[Index]);
4615 end;
4616 end;
4618 procedure TMainForm.miReopenMapClick(Sender: TObject);
4619 var
4620 FileName, Resource: String;
4621 begin
4622 if OpenedMap = '' then
4623 Exit;
4625 if MessageBox(0, PChar(_lc[I_MSG_REOPEN_MAP_PROMT]),
4626 PChar(_lc[I_MENU_FILE_REOPEN]), MB_ICONQUESTION or MB_YESNO) <> idYes then
4627 Exit;
4629 g_ProcessResourceStr(OpenedMap, @FileName, nil, @Resource);
4630 OpenMap(FileName, Resource);
4631 end;
4633 procedure TMainForm.vleObjectPropertyGetPickList(Sender: TObject;
4634 const KeyName: String; Values: TStrings);
4635 begin
4636 if vleObjectProperty.ItemProps[KeyName].EditStyle = esPickList then
4637 begin
4638 if KeyName = _lc[I_PROP_DIRECTION] then
4639 begin
4640 Values.Add(DirNames[D_LEFT]);
4641 Values.Add(DirNames[D_RIGHT]);
4642 end
4643 else if KeyName = _lc[I_PROP_TR_TELEPORT_DIR] then
4644 begin
4645 Values.Add(DirNamesAdv[0]);
4646 Values.Add(DirNamesAdv[1]);
4647 Values.Add(DirNamesAdv[2]);
4648 Values.Add(DirNamesAdv[3]);
4649 end
4650 else if KeyName = _lc[I_PROP_TR_MUSIC_ACT] then
4651 begin
4652 Values.Add(_lc[I_PROP_TR_MUSIC_ON]);
4653 Values.Add(_lc[I_PROP_TR_MUSIC_OFF]);
4654 end
4655 else if KeyName = _lc[I_PROP_TR_MONSTER_BEHAVIOUR] then
4656 begin
4657 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_0]);
4658 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_1]);
4659 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_2]);
4660 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_3]);
4661 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_4]);
4662 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_5]);
4663 end
4664 else if KeyName = _lc[I_PROP_TR_SCORE_ACT] then
4665 begin
4666 Values.Add(_lc[I_PROP_TR_SCORE_ACT_0]);
4667 Values.Add(_lc[I_PROP_TR_SCORE_ACT_1]);
4668 Values.Add(_lc[I_PROP_TR_SCORE_ACT_2]);
4669 Values.Add(_lc[I_PROP_TR_SCORE_ACT_3]);
4670 end
4671 else if KeyName = _lc[I_PROP_TR_SCORE_TEAM] then
4672 begin
4673 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_0]);
4674 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_1]);
4675 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_2]);
4676 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_3]);
4677 end
4678 else if KeyName = _lc[I_PROP_TR_MESSAGE_KIND] then
4679 begin
4680 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_0]);
4681 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_1]);
4682 end
4683 else if KeyName = _lc[I_PROP_TR_MESSAGE_TO] then
4684 begin
4685 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_0]);
4686 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_1]);
4687 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_2]);
4688 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_3]);
4689 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_4]);
4690 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_5]);
4691 end
4692 else if KeyName = _lc[I_PROP_TR_SHOT_TO] then
4693 begin
4694 Values.Add(_lc[I_PROP_TR_SHOT_TO_0]);
4695 Values.Add(_lc[I_PROP_TR_SHOT_TO_1]);
4696 Values.Add(_lc[I_PROP_TR_SHOT_TO_2]);
4697 Values.Add(_lc[I_PROP_TR_SHOT_TO_3]);
4698 Values.Add(_lc[I_PROP_TR_SHOT_TO_4]);
4699 Values.Add(_lc[I_PROP_TR_SHOT_TO_5]);
4700 Values.Add(_lc[I_PROP_TR_SHOT_TO_6]);
4701 end
4702 else if KeyName = _lc[I_PROP_TR_SHOT_AIM] then
4703 begin
4704 Values.Add(_lc[I_PROP_TR_SHOT_AIM_0]);
4705 Values.Add(_lc[I_PROP_TR_SHOT_AIM_1]);
4706 Values.Add(_lc[I_PROP_TR_SHOT_AIM_2]);
4707 Values.Add(_lc[I_PROP_TR_SHOT_AIM_3]);
4708 end
4709 else if (KeyName = _lc[I_PROP_PANEL_BLEND]) or
4710 (KeyName = _lc[I_PROP_DM_ONLY]) or
4711 (KeyName = _lc[I_PROP_ITEM_FALLS]) or
4712 (KeyName = _lc[I_PROP_TR_ENABLED]) or
4713 (KeyName = _lc[I_PROP_TR_D2D]) or
4714 (KeyName = _lc[I_PROP_TR_SILENT]) or
4715 (KeyName = _lc[I_PROP_TR_TELEPORT_SILENT]) or
4716 (KeyName = _lc[I_PROP_TR_EX_RANDOM]) or
4717 (KeyName = _lc[I_PROP_TR_TEXTURE_ONCE]) or
4718 (KeyName = _lc[I_PROP_TR_TEXTURE_ANIM_ONCE]) or
4719 (KeyName = _lc[I_PROP_TR_SOUND_LOCAL]) or
4720 (KeyName = _lc[I_PROP_TR_SOUND_SWITCH]) or
4721 (KeyName = _lc[I_PROP_TR_MONSTER_ACTIVE]) or
4722 (KeyName = _lc[I_PROP_TR_PUSH_RESET]) or
4723 (KeyName = _lc[I_PROP_TR_SCORE_CON]) or
4724 (KeyName = _lc[I_PROP_TR_SCORE_MSG]) or
4725 (KeyName = _lc[I_PROP_TR_HEALTH_MAX]) or
4726 (KeyName = _lc[I_PROP_TR_SHOT_SOUND]) or
4727 (KeyName = _lc[I_PROP_TR_EFFECT_CENTER]) then
4728 begin
4729 Values.Add(BoolNames[True]);
4730 Values.Add(BoolNames[False]);
4731 end;
4732 end;
4733 end;
4735 procedure TMainForm.bApplyPropertyClick(Sender: TObject);
4736 var
4737 _id, a, r, c: Integer;
4738 s: String;
4739 res: Boolean;
4740 NoTextureID: DWORD;
4741 NW, NH: Word;
4742 begin
4743 NoTextureID := 0;
4744 NW := 0;
4745 NH := 0;
4747 if SelectedObjectCount() <> 1 then
4748 Exit;
4749 if not SelectedObjects[GetFirstSelected()].Live then
4750 Exit;
4752 try
4753 if not CheckProperty() then
4754 Exit;
4755 except
4756 Exit;
4757 end;
4759 _id := GetFirstSelected();
4761 r := vleObjectProperty.Row;
4762 c := vleObjectProperty.Col;
4764 case SelectedObjects[_id].ObjectType of
4765 OBJECT_PANEL:
4766 begin
4767 with gPanels[SelectedObjects[_id].ID] do
4768 begin
4769 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4770 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4771 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4772 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4774 PanelType := GetPanelType(vleObjectProperty.Values[_lc[I_PROP_PANEL_TYPE]]);
4776 // Сброс ссылки на триггеры смены текстуры:
4777 if not WordBool(PanelType and (PANEL_WALL or PANEL_FORE or PANEL_BACK)) then
4778 if gTriggers <> nil then
4779 for a := 0 to High(gTriggers) do
4780 begin
4781 if (gTriggers[a].TriggerType <> 0) and
4782 (gTriggers[a].TexturePanel = Integer(SelectedObjects[_id].ID)) then
4783 gTriggers[a].TexturePanel := -1;
4784 if (gTriggers[a].TriggerType = TRIGGER_SHOT) and
4785 (gTriggers[a].Data.ShotPanelID = Integer(SelectedObjects[_id].ID)) then
4786 gTriggers[a].Data.ShotPanelID := -1;
4787 end;
4789 // Сброс ссылки на триггеры лифта:
4790 if not WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
4791 if gTriggers <> nil then
4792 for a := 0 to High(gTriggers) do
4793 if (gTriggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
4794 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4795 gTriggers[a].Data.PanelID := -1;
4797 // Сброс ссылки на триггеры двери:
4798 if not WordBool(PanelType and (PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
4799 if gTriggers <> nil then
4800 for a := 0 to High(gTriggers) do
4801 if (gTriggers[a].TriggerType in [TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
4802 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP]) and
4803 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4804 gTriggers[a].Data.PanelID := -1;
4806 if IsTexturedPanel(PanelType) then
4807 begin // Может быть текстура
4808 if TextureName <> '' then
4809 begin // Была текстура
4810 Alpha := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]]));
4811 Blending := NameToBool(vleObjectProperty.Values[_lc[I_PROP_PANEL_BLEND]]);
4812 end
4813 else // Не было
4814 begin
4815 Alpha := 0;
4816 Blending := False;
4817 end;
4819 // Новая текстура:
4820 TextureName := vleObjectProperty.Values[_lc[I_PROP_PANEL_TEX]];
4822 if TextureName <> '' then
4823 begin // Есть текстура
4824 // Обычная текстура:
4825 if not IsSpecialTexture(TextureName) then
4826 begin
4827 g_GetTextureSizeByName(TextureName,
4828 TextureWidth, TextureHeight);
4830 // Проверка кратности размеров панели:
4831 res := True;
4832 if TextureWidth <> 0 then
4833 if gPanels[SelectedObjects[_id].ID].Width mod TextureWidth <> 0 then
4834 begin
4835 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
4836 [TextureWidth]));
4837 Res := False;
4838 end;
4839 if Res and (TextureHeight <> 0) then
4840 if gPanels[SelectedObjects[_id].ID].Height mod TextureHeight <> 0 then
4841 begin
4842 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
4843 [TextureHeight]));
4844 Res := False;
4845 end;
4847 if Res then
4848 begin
4849 if not g_GetTexture(TextureName, TextureID) then
4850 // Не удалось загрузить текстуру, рисуем NOTEXTURE
4851 if g_GetTexture('NOTEXTURE', NoTextureID) then
4852 begin
4853 TextureID := TEXTURE_SPECIAL_NOTEXTURE;
4854 g_GetTextureSizeByID(NoTextureID, NW, NH);
4855 TextureWidth := NW;
4856 TextureHeight := NH;
4857 end else
4858 begin
4859 TextureID := TEXTURE_SPECIAL_NONE;
4860 TextureWidth := 1;
4861 TextureHeight := 1;
4862 end;
4863 end
4864 else
4865 begin
4866 TextureName := '';
4867 TextureWidth := 1;
4868 TextureHeight := 1;
4869 TextureID := TEXTURE_SPECIAL_NONE;
4870 end;
4871 end
4872 else // Спец.текстура
4873 begin
4874 TextureHeight := 1;
4875 TextureWidth := 1;
4876 TextureID := SpecialTextureID(TextureName);
4877 end;
4878 end
4879 else // Нет текстуры
4880 begin
4881 TextureWidth := 1;
4882 TextureHeight := 1;
4883 TextureID := TEXTURE_SPECIAL_NONE;
4884 end;
4885 end
4886 else // Не может быть текстуры
4887 begin
4888 Alpha := 0;
4889 Blending := False;
4890 TextureName := '';
4891 TextureWidth := 1;
4892 TextureHeight := 1;
4893 TextureID := TEXTURE_SPECIAL_NONE;
4894 end;
4895 end;
4896 end;
4898 OBJECT_ITEM:
4899 begin
4900 with gItems[SelectedObjects[_id].ID] do
4901 begin
4902 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4903 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4904 OnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
4905 Fall := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
4906 end;
4907 end;
4909 OBJECT_MONSTER:
4910 begin
4911 with gMonsters[SelectedObjects[_id].ID] do
4912 begin
4913 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4914 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4915 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
4916 end;
4917 end;
4919 OBJECT_AREA:
4920 begin
4921 with gAreas[SelectedObjects[_id].ID] do
4922 begin
4923 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4924 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4925 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
4926 end;
4927 end;
4929 OBJECT_TRIGGER:
4930 begin
4931 with gTriggers[SelectedObjects[_id].ID] do
4932 begin
4933 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4934 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4935 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4936 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4937 Enabled := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_ENABLED]]);
4938 ActivateType := StrToActivate(vleObjectProperty.Values[_lc[I_PROP_TR_ACTIVATION]]);
4939 Key := StrToKey(vleObjectProperty.Values[_lc[I_PROP_TR_KEYS]]);
4941 case TriggerType of
4942 TRIGGER_EXIT:
4943 begin
4944 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_NEXT_MAP]]);
4945 FillByte(Data.MapName[0], 16, 0);
4946 if s <> '' then
4947 Move(s[1], Data.MapName[0], Min(Length(s), 16));
4948 end;
4950 TRIGGER_TEXTURE:
4951 begin
4952 Data.ActivateOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ONCE]]);
4953 Data.AnimOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ANIM_ONCE]]);
4954 end;
4956 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
4957 begin
4958 Data.Wait := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 65535);
4959 Data.Count := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_COUNT]], 0), 65535);
4960 if Data.Count < 1 then
4961 Data.Count := 1;
4962 if TriggerType = TRIGGER_PRESS then
4963 Data.ExtRandom := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EX_RANDOM]]);
4964 end;
4966 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
4967 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP, TRIGGER_LIFTDOWN,
4968 TRIGGER_LIFT:
4969 begin
4970 Data.NoSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
4971 Data.d2d_doors := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
4972 end;
4974 TRIGGER_TELEPORT:
4975 begin
4976 Data.d2d_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
4977 Data.silent_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_SILENT]]);
4978 Data.TlpDir := NameToDirAdv(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_DIR]]);
4979 end;
4981 TRIGGER_SOUND:
4982 begin
4983 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_NAME]]);
4984 FillByte(Data.SoundName[0], 64, 0);
4985 if s <> '' then
4986 Move(s[1], Data.SoundName[0], Min(Length(s), 64));
4988 Data.Volume := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_VOLUME]], 0), 255);
4989 Data.Pan := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_PAN]], 0), 255);
4990 Data.PlayCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_COUNT]], 0), 255);
4991 Data.Local := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_LOCAL]]);
4992 Data.SoundSwitch := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_SWITCH]]);
4993 end;
4995 TRIGGER_SPAWNMONSTER:
4996 begin
4997 Data.MonType := StrToMonster(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_TYPE]]);
4998 Data.MonDir := Byte(NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]));
4999 Data.MonHealth := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 1000000);
5000 if Data.MonHealth < 0 then
5001 Data.MonHealth := 0;
5002 Data.MonActive := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_ACTIVE]]);
5003 Data.MonCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
5004 if Data.MonCount < 1 then
5005 Data.MonCount := 1;
5006 Data.MonEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
5007 Data.MonMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
5008 Data.MonDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
5009 Data.MonBehav := 0;
5010 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1] then
5011 Data.MonBehav := 1;
5012 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2] then
5013 Data.MonBehav := 2;
5014 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3] then
5015 Data.MonBehav := 3;
5016 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4] then
5017 Data.MonBehav := 4;
5018 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5] then
5019 Data.MonBehav := 5;
5020 end;
5022 TRIGGER_SPAWNITEM:
5023 begin
5024 Data.ItemType := StrToItem(vleObjectProperty.Values[_lc[I_PROP_TR_ITEM_TYPE]]);
5025 Data.ItemOnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
5026 Data.ItemFalls := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
5027 Data.ItemCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
5028 if Data.ItemCount < 1 then
5029 Data.ItemCount := 1;
5030 Data.ItemEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
5031 Data.ItemMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
5032 Data.ItemDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
5033 end;
5035 TRIGGER_MUSIC:
5036 begin
5037 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_NAME]]);
5038 FillByte(Data.MusicName[0], 64, 0);
5039 if s <> '' then
5040 Move(s[1], Data.MusicName[0], Min(Length(s), 64));
5042 if vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_ACT]] = _lc[I_PROP_TR_MUSIC_ON] then
5043 Data.MusicAction := 1
5044 else
5045 Data.MusicAction := 2;
5046 end;
5048 TRIGGER_PUSH:
5049 begin
5050 Data.PushAngle := Min(
5051 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_ANGLE]], 0), 360);
5052 Data.PushForce := Min(
5053 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_FORCE]], 0), 255);
5054 Data.ResetVel := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_RESET]]);
5055 end;
5057 TRIGGER_SCORE:
5058 begin
5059 Data.ScoreAction := 0;
5060 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_1] then
5061 Data.ScoreAction := 1
5062 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_2] then
5063 Data.ScoreAction := 2
5064 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_3] then
5065 Data.ScoreAction := 3;
5066 Data.ScoreCount := Min(Max(
5067 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
5068 Data.ScoreTeam := 0;
5069 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_1] then
5070 Data.ScoreTeam := 1
5071 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_2] then
5072 Data.ScoreTeam := 2
5073 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_3] then
5074 Data.ScoreTeam := 3;
5075 Data.ScoreCon := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_CON]]);
5076 Data.ScoreMsg := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_MSG]]);
5077 end;
5079 TRIGGER_MESSAGE:
5080 begin
5081 Data.MessageKind := 0;
5082 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_KIND]] = _lc[I_PROP_TR_MESSAGE_KIND_1] then
5083 Data.MessageKind := 1;
5085 Data.MessageSendTo := 0;
5086 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_1] then
5087 Data.MessageSendTo := 1
5088 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_2] then
5089 Data.MessageSendTo := 2
5090 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_3] then
5091 Data.MessageSendTo := 3
5092 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_4] then
5093 Data.MessageSendTo := 4
5094 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_5] then
5095 Data.MessageSendTo := 5;
5097 s := utf2win(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TEXT]]);
5098 FillByte(Data.MessageText[0], 100, 0);
5099 if s <> '' then
5100 Move(s[1], Data.MessageText[0], Min(Length(s), 100));
5102 Data.MessageTime := Min(Max(
5103 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TIME]], 0), 0), 65535);
5104 end;
5106 TRIGGER_DAMAGE:
5107 begin
5108 Data.DamageValue := Min(Max(
5109 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_DAMAGE_VALUE]], 0), 0), 65535);
5110 Data.DamageInterval := Min(Max(
5111 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
5112 end;
5114 TRIGGER_HEALTH:
5115 begin
5116 Data.HealValue := Min(Max(
5117 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 0), 65535);
5118 Data.HealInterval := Min(Max(
5119 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
5120 Data.HealMax := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH_MAX]]);
5121 Data.HealSilent := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
5122 end;
5124 TRIGGER_SHOT:
5125 begin
5126 Data.ShotType := StrToShot(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TYPE]]);
5127 Data.ShotSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SOUND]]);
5128 Data.ShotTarget := 0;
5129 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_1] then
5130 Data.ShotTarget := 1
5131 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_2] then
5132 Data.ShotTarget := 2
5133 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_3] then
5134 Data.ShotTarget := 3
5135 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_4] then
5136 Data.ShotTarget := 4
5137 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_5] then
5138 Data.ShotTarget := 5
5139 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_6] then
5140 Data.ShotTarget := 6;
5141 Data.ShotIntSight := Min(Max(
5142 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SIGHT]], 0), 0), 65535);
5143 Data.ShotAim := 0;
5144 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_1] then
5145 Data.ShotAim := 1
5146 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_2] then
5147 Data.ShotAim := 2
5148 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_3] then
5149 Data.ShotAim := 3;
5150 Data.ShotAngle := Min(
5151 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ANGLE]], 0), 360);
5152 Data.ShotWait := Min(Max(
5153 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
5154 Data.ShotAccuracy := Min(Max(
5155 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ACC]], 0), 0), 65535);
5156 Data.ShotAmmo := Min(Max(
5157 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AMMO]], 0), 0), 65535);
5158 Data.ShotIntReload := Min(Max(
5159 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_RELOAD]], 0), 0), 65535);
5160 end;
5162 TRIGGER_EFFECT:
5163 begin
5164 Data.FXCount := Min(Max(
5165 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
5166 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_PARTICLE] then
5167 begin
5168 Data.FXType := TRIGGER_EFFECT_PARTICLE;
5169 Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
5170 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SLIQUID] then
5171 Data.FXSubType := TRIGGER_EFFECT_SLIQUID
5172 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
5173 Data.FXSubType := TRIGGER_EFFECT_LLIQUID
5174 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
5175 Data.FXSubType := TRIGGER_EFFECT_DLIQUID
5176 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BLOOD] then
5177 Data.FXSubType := TRIGGER_EFFECT_BLOOD
5178 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SPARK] then
5179 Data.FXSubType := TRIGGER_EFFECT_SPARK
5180 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
5181 Data.FXSubType := TRIGGER_EFFECT_BUBBLE;
5182 end else
5183 begin
5184 Data.FXType := TRIGGER_EFFECT_ANIMATION;
5185 Data.FXSubType := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]]);
5186 end;
5187 a := Min(Max(
5188 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_COLOR]], 0), 0), $FFFFFF);
5189 Data.FXColorR := a and $FF;
5190 Data.FXColorG := (a shr 8) and $FF;
5191 Data.FXColorB := (a shr 16) and $FF;
5192 if NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_CENTER]]) then
5193 Data.FXPos := 0
5194 else
5195 Data.FXPos := 1;
5196 Data.FXWait := Min(Max(
5197 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
5198 Data.FXVelX := Min(Max(
5199 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELX]], 0), -128), 127);
5200 Data.FXVelY := Min(Max(
5201 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELY]], 0), -128), 127);
5202 Data.FXSpreadL := Min(Max(
5203 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPL]], 0), 0), 255);
5204 Data.FXSpreadR := Min(Max(
5205 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPR]], 0), 0), 255);
5206 Data.FXSpreadU := Min(Max(
5207 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPU]], 0), 0), 255);
5208 Data.FXSpreadD := Min(Max(
5209 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPD]], 0), 0), 255);
5210 end;
5211 end;
5212 end;
5213 end;
5214 end;
5216 FillProperty();
5218 vleObjectProperty.Row := r;
5219 vleObjectProperty.Col := c;
5220 end;
5222 procedure TMainForm.bbRemoveTextureClick(Sender: TObject);
5223 var
5224 a, i: Integer;
5225 begin
5226 i := lbTextureList.ItemIndex;
5227 if i = -1 then
5228 Exit;
5230 if MessageBox(0, PChar(Format(_lc[I_MSG_DEL_TEXTURE_PROMT],
5231 [SelectedTexture()])),
5232 PChar(_lc[I_MSG_DEL_TEXTURE]),
5233 MB_ICONQUESTION or MB_YESNO or
5234 MB_DEFBUTTON1) <> idYes then
5235 Exit;
5237 if gPanels <> nil then
5238 for a := 0 to High(gPanels) do
5239 if (gPanels[a].PanelType <> 0) and
5240 (gPanels[a].TextureName = SelectedTexture()) then
5241 begin
5242 ErrorMessageBox(_lc[I_MSG_DEL_TEXTURE_CANT]);
5243 Exit;
5244 end;
5246 g_DeleteTexture(SelectedTexture());
5247 i := slInvalidTextures.IndexOf(lbTextureList.Items[i]);
5248 if i > -1 then
5249 slInvalidTextures.Delete(i);
5250 if lbTextureList.ItemIndex > -1 then
5251 lbTextureList.Items.Delete(lbTextureList.ItemIndex)
5252 end;
5254 procedure TMainForm.aNewMapExecute(Sender: TObject);
5255 begin
5256 if (MessageBox(0, PChar(_lc[I_MSG_CLEAR_MAP_PROMT]),
5257 PChar(_lc[I_MSG_CLEAR_MAP]),
5258 MB_ICONQUESTION or MB_YESNO or
5259 MB_DEFBUTTON1) = mrYes) then
5260 FullClear();
5261 end;
5263 procedure TMainForm.aUndoExecute(Sender: TObject);
5264 var
5265 a: Integer;
5266 begin
5267 if UndoBuffer = nil then
5268 Exit;
5269 if UndoBuffer[High(UndoBuffer)] = nil then
5270 Exit;
5272 for a := 0 to High(UndoBuffer[High(UndoBuffer)]) do
5273 with UndoBuffer[High(UndoBuffer)][a] do
5274 begin
5275 case UndoType of
5276 UNDO_DELETE_PANEL:
5277 begin
5278 AddPanel(Panel^);
5279 Panel := nil;
5280 end;
5281 UNDO_DELETE_ITEM: AddItem(Item);
5282 UNDO_DELETE_AREA: AddArea(Area);
5283 UNDO_DELETE_MONSTER: AddMonster(Monster);
5284 UNDO_DELETE_TRIGGER: AddTrigger(Trigger);
5285 UNDO_ADD_PANEL: RemoveObject(AddID, OBJECT_PANEL);
5286 UNDO_ADD_ITEM: RemoveObject(AddID, OBJECT_ITEM);
5287 UNDO_ADD_AREA: RemoveObject(AddID, OBJECT_AREA);
5288 UNDO_ADD_MONSTER: RemoveObject(AddID, OBJECT_MONSTER);
5289 UNDO_ADD_TRIGGER: RemoveObject(AddID, OBJECT_TRIGGER);
5290 end;
5291 end;
5293 SetLength(UndoBuffer, Length(UndoBuffer)-1);
5295 RemoveSelectFromObjects();
5297 miUndo.Enabled := UndoBuffer <> nil;
5298 end;
5301 procedure TMainForm.aCopyObjectExecute(Sender: TObject);
5302 var
5303 a, b: Integer;
5304 CopyBuffer: TCopyRecArray;
5305 str: String;
5306 ok: Boolean;
5308 function CB_Compare(I1, I2: TCopyRec): Integer;
5309 begin
5310 Result := Integer(I1.ObjectType) - Integer(I2.ObjectType);
5312 if Result = 0 then // Одного типа
5313 Result := Integer(I1.ID) - Integer(I2.ID);
5314 end;
5316 procedure QuickSortCopyBuffer(L, R: Integer);
5317 var
5318 I, J: Integer;
5319 P, T: TCopyRec;
5320 begin
5321 repeat
5322 I := L;
5323 J := R;
5324 P := CopyBuffer[(L + R) shr 1];
5326 repeat
5327 while CB_Compare(CopyBuffer[I], P) < 0 do
5328 Inc(I);
5329 while CB_Compare(CopyBuffer[J], P) > 0 do
5330 Dec(J);
5332 if I <= J then
5333 begin
5334 T := CopyBuffer[I];
5335 CopyBuffer[I] := CopyBuffer[J];
5336 CopyBuffer[J] := T;
5337 Inc(I);
5338 Dec(J);
5339 end;
5340 until I > J;
5342 if L < J then
5343 QuickSortCopyBuffer(L, J);
5345 L := I;
5346 until I >= R;
5347 end;
5349 begin
5350 if SelectedObjects = nil then
5351 Exit;
5353 b := -1;
5354 CopyBuffer := nil;
5356 // Копируем объекты:
5357 for a := 0 to High(SelectedObjects) do
5358 if SelectedObjects[a].Live then
5359 with SelectedObjects[a] do
5360 begin
5361 SetLength(CopyBuffer, Length(CopyBuffer)+1);
5362 b := High(CopyBuffer);
5363 CopyBuffer[b].ID := ID;
5364 CopyBuffer[b].Panel := nil;
5366 case ObjectType of
5367 OBJECT_PANEL:
5368 begin
5369 CopyBuffer[b].ObjectType := OBJECT_PANEL;
5370 New(CopyBuffer[b].Panel);
5371 CopyBuffer[b].Panel^ := gPanels[ID];
5372 end;
5374 OBJECT_ITEM:
5375 begin
5376 CopyBuffer[b].ObjectType := OBJECT_ITEM;
5377 CopyBuffer[b].Item := gItems[ID];
5378 end;
5380 OBJECT_MONSTER:
5381 begin
5382 CopyBuffer[b].ObjectType := OBJECT_MONSTER;
5383 CopyBuffer[b].Monster := gMonsters[ID];
5384 end;
5386 OBJECT_AREA:
5387 begin
5388 CopyBuffer[b].ObjectType := OBJECT_AREA;
5389 CopyBuffer[b].Area := gAreas[ID];
5390 end;
5392 OBJECT_TRIGGER:
5393 begin
5394 CopyBuffer[b].ObjectType := OBJECT_TRIGGER;
5395 CopyBuffer[b].Trigger := gTriggers[ID];
5396 end;
5397 end;
5398 end;
5400 // Сортировка по ID:
5401 if CopyBuffer <> nil then
5402 begin
5403 QuickSortCopyBuffer(0, b);
5404 end;
5406 // Пестановка ссылок триггеров:
5407 for a := 0 to Length(CopyBuffer)-1 do
5408 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5409 begin
5410 case CopyBuffer[a].Trigger.TriggerType of
5411 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5412 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5413 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5414 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5415 begin
5416 ok := False;
5418 for b := 0 to Length(CopyBuffer)-1 do
5419 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5420 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.PanelID) then
5421 begin
5422 CopyBuffer[a].Trigger.Data.PanelID := b;
5423 ok := True;
5424 Break;
5425 end;
5427 // Этих панелей нет среди копируемых:
5428 if not ok then
5429 CopyBuffer[a].Trigger.Data.PanelID := -1;
5430 end;
5432 TRIGGER_PRESS, TRIGGER_ON,
5433 TRIGGER_OFF, TRIGGER_ONOFF:
5434 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5435 begin
5436 ok := False;
5438 for b := 0 to Length(CopyBuffer)-1 do
5439 if (CopyBuffer[b].ObjectType = OBJECT_MONSTER) and
5440 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.MonsterID-1) then
5441 begin
5442 CopyBuffer[a].Trigger.Data.MonsterID := b+1;
5443 ok := True;
5444 Break;
5445 end;
5447 // Этих монстров нет среди копируемых:
5448 if not ok then
5449 CopyBuffer[a].Trigger.Data.MonsterID := 0;
5450 end;
5452 TRIGGER_SHOT:
5453 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5454 begin
5455 ok := False;
5457 for b := 0 to Length(CopyBuffer)-1 do
5458 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5459 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.ShotPanelID) then
5460 begin
5461 CopyBuffer[a].Trigger.Data.ShotPanelID := b;
5462 ok := True;
5463 Break;
5464 end;
5466 // Этих панелей нет среди копируемых:
5467 if not ok then
5468 CopyBuffer[a].Trigger.Data.ShotPanelID := -1;
5469 end;
5470 end;
5472 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5473 begin
5474 ok := False;
5476 for b := 0 to Length(CopyBuffer)-1 do
5477 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5478 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.TexturePanel) then
5479 begin
5480 CopyBuffer[a].Trigger.TexturePanel := b;
5481 ok := True;
5482 Break;
5483 end;
5485 // Этих панелей нет среди копируемых:
5486 if not ok then
5487 CopyBuffer[a].Trigger.TexturePanel := -1;
5488 end;
5489 end;
5491 // В буфер обмена:
5492 str := CopyBufferToString(CopyBuffer);
5493 ClipBoard.AsText := str;
5495 for a := 0 to Length(CopyBuffer)-1 do
5496 if (CopyBuffer[a].ObjectType = OBJECT_PANEL) and
5497 (CopyBuffer[a].Panel <> nil) then
5498 Dispose(CopyBuffer[a].Panel);
5500 CopyBuffer := nil;
5501 end;
5503 procedure TMainForm.aPasteObjectExecute(Sender: TObject);
5504 var
5505 a, h: Integer;
5506 CopyBuffer: TCopyRecArray;
5507 res, rel: Boolean;
5508 swad, ssec, sres: String;
5509 NoTextureID: DWORD;
5510 pmin: TPoint;
5511 begin
5512 CopyBuffer := nil;
5513 NoTextureID := 0;
5514 pmin.X := High(pmin.X);
5515 pmin.Y := High(pmin.Y);
5517 StringToCopyBuffer(ClipBoard.AsText, CopyBuffer, pmin);
5518 rel := not(ssShift in GetKeyShiftState());
5520 if CopyBuffer = nil then
5521 Exit;
5523 RemoveSelectFromObjects();
5525 h := High(CopyBuffer);
5526 for a := 0 to h do
5527 with CopyBuffer[a] do
5528 begin
5529 case ObjectType of
5530 OBJECT_PANEL:
5531 if Panel <> nil then
5532 begin
5533 if rel then
5534 begin
5535 Panel^.X := Panel^.X - pmin.X - MapOffset.X + 32;
5536 Panel^.Y := Panel^.Y - pmin.Y - MapOffset.Y + 32;
5537 end;
5539 Panel^.TextureID := TEXTURE_SPECIAL_NONE;
5540 Panel^.TextureWidth := 1;
5541 Panel^.TextureHeight := 1;
5543 if (Panel^.PanelType = PANEL_LIFTUP) or
5544 (Panel^.PanelType = PANEL_LIFTDOWN) or
5545 (Panel^.PanelType = PANEL_LIFTLEFT) or
5546 (Panel^.PanelType = PANEL_LIFTRIGHT) or
5547 (Panel^.PanelType = PANEL_BLOCKMON) or
5548 (Panel^.TextureName = '') then
5549 begin // Нет или не может быть текстуры:
5550 end
5551 else // Есть текстура:
5552 begin
5553 // Обычная текстура:
5554 if not IsSpecialTexture(Panel^.TextureName) then
5555 begin
5556 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5558 if not res then
5559 begin
5560 g_ProcessResourceStr(Panel^.TextureName, swad, ssec, sres);
5561 AddTexture(swad, ssec, sres, True);
5562 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5563 end;
5565 if res then
5566 g_GetTextureSizeByName(Panel^.TextureName,
5567 Panel^.TextureWidth, Panel^.TextureHeight)
5568 else
5569 if g_GetTexture('NOTEXTURE', NoTextureID) then
5570 begin
5571 Panel^.TextureID := TEXTURE_SPECIAL_NOTEXTURE;
5572 g_GetTextureSizeByID(NoTextureID, Panel^.TextureWidth, Panel^.TextureHeight);
5573 end;
5574 end
5575 else // Спец.текстура:
5576 begin
5577 Panel^.TextureID := SpecialTextureID(Panel^.TextureName);
5578 with MainForm.lbTextureList.Items do
5579 if IndexOf(Panel^.TextureName) = -1 then
5580 Add(Panel^.TextureName);
5581 end;
5582 end;
5584 ID := AddPanel(Panel^);
5585 Dispose(Panel);
5586 Undo_Add(OBJECT_PANEL, ID, a > 0);
5587 SelectObject(OBJECT_PANEL, ID, True);
5588 end;
5590 OBJECT_ITEM:
5591 begin
5592 if rel then
5593 begin
5594 Item.X := Item.X - pmin.X - MapOffset.X + 32;
5595 Item.Y := Item.Y - pmin.Y - MapOffset.Y + 32;
5596 end;
5598 ID := AddItem(Item);
5599 Undo_Add(OBJECT_ITEM, ID, a > 0);
5600 SelectObject(OBJECT_ITEM, ID, True);
5601 end;
5603 OBJECT_MONSTER:
5604 begin
5605 if rel then
5606 begin
5607 Monster.X := Monster.X - pmin.X - MapOffset.X + 32;
5608 Monster.Y := Monster.Y - pmin.Y - MapOffset.Y + 32;
5609 end;
5611 ID := AddMonster(Monster);
5612 Undo_Add(OBJECT_MONSTER, ID, a > 0);
5613 SelectObject(OBJECT_MONSTER, ID, True);
5614 end;
5616 OBJECT_AREA:
5617 begin
5618 if rel then
5619 begin
5620 Area.X := Area.X - pmin.X - MapOffset.X + 32;
5621 Area.Y := Area.Y - pmin.Y - MapOffset.Y + 32;
5622 end;
5624 ID := AddArea(Area);
5625 Undo_Add(OBJECT_AREA, ID, a > 0);
5626 SelectObject(OBJECT_AREA, ID, True);
5627 end;
5629 OBJECT_TRIGGER:
5630 begin
5631 if rel then
5632 with Trigger do
5633 begin
5634 X := X - pmin.X - MapOffset.X + 32;
5635 Y := Y - pmin.Y - MapOffset.Y + 32;
5637 case TriggerType of
5638 TRIGGER_TELEPORT:
5639 begin
5640 Data.TargetPoint.X :=
5641 Data.TargetPoint.X - pmin.X - MapOffset.X + 32;
5642 Data.TargetPoint.Y :=
5643 Data.TargetPoint.Y - pmin.Y - MapOffset.Y + 32;
5644 end;
5645 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
5646 begin
5647 Data.tX := Data.tX - pmin.X - MapOffset.X + 32;
5648 Data.tY := Data.tY - pmin.Y - MapOffset.Y + 32;
5649 end;
5650 TRIGGER_SPAWNMONSTER:
5651 begin
5652 Data.MonPos.X :=
5653 Data.MonPos.X - pmin.X - MapOffset.X + 32;
5654 Data.MonPos.Y :=
5655 Data.MonPos.Y - pmin.Y - MapOffset.Y + 32;
5656 end;
5657 TRIGGER_SPAWNITEM:
5658 begin
5659 Data.ItemPos.X :=
5660 Data.ItemPos.X - pmin.X - MapOffset.X + 32;
5661 Data.ItemPos.Y :=
5662 Data.ItemPos.Y - pmin.Y - MapOffset.Y + 32;
5663 end;
5664 TRIGGER_SHOT:
5665 begin
5666 Data.ShotPos.X :=
5667 Data.ShotPos.X - pmin.X - MapOffset.X + 32;
5668 Data.ShotPos.Y :=
5669 Data.ShotPos.Y - pmin.Y - MapOffset.Y + 32;
5670 end;
5671 end;
5672 end;
5674 ID := AddTrigger(Trigger);
5675 Undo_Add(OBJECT_TRIGGER, ID, a > 0);
5676 SelectObject(OBJECT_TRIGGER, ID, True);
5677 end;
5678 end;
5679 end;
5681 // Переставляем ссылки триггеров:
5682 for a := 0 to High(CopyBuffer) do
5683 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5684 begin
5685 case CopyBuffer[a].Trigger.TriggerType of
5686 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5687 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5688 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5689 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5690 gTriggers[CopyBuffer[a].ID].Data.PanelID :=
5691 CopyBuffer[CopyBuffer[a].Trigger.Data.PanelID].ID;
5693 TRIGGER_PRESS, TRIGGER_ON,
5694 TRIGGER_OFF, TRIGGER_ONOFF:
5695 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5696 gTriggers[CopyBuffer[a].ID].Data.MonsterID :=
5697 CopyBuffer[CopyBuffer[a].Trigger.Data.MonsterID-1].ID+1;
5699 TRIGGER_SHOT:
5700 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5701 gTriggers[CopyBuffer[a].ID].Data.ShotPanelID :=
5702 CopyBuffer[CopyBuffer[a].Trigger.Data.ShotPanelID].ID;
5703 end;
5705 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5706 gTriggers[CopyBuffer[a].ID].TexturePanel :=
5707 CopyBuffer[CopyBuffer[a].Trigger.TexturePanel].ID;
5708 end;
5710 CopyBuffer := nil;
5712 if h = 0 then
5713 FillProperty();
5714 end;
5716 procedure TMainForm.aCutObjectExecute(Sender: TObject);
5717 begin
5718 miCopy.Click();
5719 DeleteSelectedObjects();
5720 end;
5722 procedure TMainForm.vleObjectPropertyEditButtonClick(Sender: TObject);
5723 var
5724 Key, FileName: String;
5725 b: Byte;
5726 begin
5727 Key := vleObjectProperty.Keys[vleObjectProperty.Row];
5729 if Key = _lc[I_PROP_PANEL_TYPE] then
5730 begin
5731 with ChooseTypeForm, vleObjectProperty do
5732 begin // Выбор типа панели:
5733 Caption := _lc[I_PROP_PANEL_TYPE];
5734 lbTypeSelect.Items.Clear();
5736 for b := 0 to High(PANELNAMES) do
5737 begin
5738 lbTypeSelect.Items.Add(PANELNAMES[b]);
5739 if Values[Key] = PANELNAMES[b] then
5740 lbTypeSelect.ItemIndex := b;
5741 end;
5743 if ShowModal() = mrOK then
5744 begin
5745 b := lbTypeSelect.ItemIndex;
5746 Values[Key] := PANELNAMES[b];
5747 vleObjectPropertyApply(Sender);
5748 end;
5749 end
5750 end
5751 else if Key = _lc[I_PROP_TR_TELEPORT_TO] then
5752 SelectFlag := SELECTFLAG_TELEPORT
5753 else if Key = _lc[I_PROP_TR_SPAWN_TO] then
5754 SelectFlag := SELECTFLAG_SPAWNPOINT
5755 else if (Key = _lc[I_PROP_TR_DOOR_PANEL]) or
5756 (Key = _lc[I_PROP_TR_TRAP_PANEL]) then
5757 SelectFlag := SELECTFLAG_DOOR
5758 else if Key = _lc[I_PROP_TR_TEXTURE_PANEL] then
5759 begin
5760 DrawPressRect := False;
5761 SelectFlag := SELECTFLAG_TEXTURE;
5762 end
5763 else if Key = _lc[I_PROP_TR_SHOT_PANEL] then
5764 SelectFlag := SELECTFLAG_SHOTPANEL
5765 else if Key = _lc[I_PROP_TR_LIFT_PANEL] then
5766 SelectFlag := SELECTFLAG_LIFT
5767 else if key = _lc[I_PROP_TR_EX_MONSTER] then
5768 SelectFlag := SELECTFLAG_MONSTER
5769 else if Key = _lc[I_PROP_TR_EX_AREA] then
5770 begin
5771 SelectFlag := SELECTFLAG_NONE;
5772 DrawPressRect := True;
5773 end
5774 else if Key = _lc[I_PROP_TR_NEXT_MAP] then
5775 begin // Выбор следующей карты:
5776 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
5777 SelectMapForm.Caption := _lc[I_CAP_SELECT];
5778 SelectMapForm.GetMaps(FileName);
5780 if SelectMapForm.ShowModal() = mrOK then
5781 begin
5782 vleObjectProperty.Values[Key] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
5783 vleObjectPropertyApply(Sender);
5784 end;
5785 end
5786 else if (Key = _lc[I_PROP_TR_SOUND_NAME]) or
5787 (Key = _lc[I_PROP_TR_MUSIC_NAME]) then
5788 begin // Выбор файла звука/музыки:
5789 AddSoundForm.OKFunction := nil;
5790 AddSoundForm.lbResourcesList.MultiSelect := False;
5791 AddSoundForm.SetResource := vleObjectProperty.Values[Key];
5793 if (AddSoundForm.ShowModal() = mrOk) then
5794 begin
5795 vleObjectProperty.Values[Key] := AddSoundForm.ResourceName;
5796 vleObjectPropertyApply(Sender);
5797 end;
5798 end
5799 else if Key = _lc[I_PROP_TR_ACTIVATION] then
5800 with ActivationTypeForm, vleObjectProperty do
5801 begin // Выбор типов активации:
5802 cbPlayerCollide.Checked := Pos('PC', Values[Key]) > 0;
5803 cbMonsterCollide.Checked := Pos('MC', Values[Key]) > 0;
5804 cbPlayerPress.Checked := Pos('PP', Values[Key]) > 0;
5805 cbMonsterPress.Checked := Pos('MP', Values[Key]) > 0;
5806 cbShot.Checked := Pos('SH', Values[Key]) > 0;
5807 cbNoMonster.Checked := Pos('NM', Values[Key]) > 0;
5809 if ShowModal() = mrOK then
5810 begin
5811 b := 0;
5812 if cbPlayerCollide.Checked then
5813 b := ACTIVATE_PLAYERCOLLIDE;
5814 if cbMonsterCollide.Checked then
5815 b := b or ACTIVATE_MONSTERCOLLIDE;
5816 if cbPlayerPress.Checked then
5817 b := b or ACTIVATE_PLAYERPRESS;
5818 if cbMonsterPress.Checked then
5819 b := b or ACTIVATE_MONSTERPRESS;
5820 if cbShot.Checked then
5821 b := b or ACTIVATE_SHOT;
5822 if cbNoMonster.Checked then
5823 b := b or ACTIVATE_NOMONSTER;
5825 Values[Key] := ActivateToStr(b);
5826 vleObjectPropertyApply(Sender);
5827 end;
5828 end
5829 else if Key = _lc[I_PROP_TR_KEYS] then
5830 with KeysForm, vleObjectProperty do
5831 begin // Выбор необходимых ключей:
5832 cbRedKey.Checked := Pos('RK', Values[Key]) > 0;
5833 cbGreenKey.Checked := Pos('GK', Values[Key]) > 0;
5834 cbBlueKey.Checked := Pos('BK', Values[Key]) > 0;
5835 cbRedTeam.Checked := Pos('RT', Values[Key]) > 0;
5836 cbBlueTeam.Checked := Pos('BT', Values[Key]) > 0;
5838 if ShowModal() = mrOK then
5839 begin
5840 b := 0;
5841 if cbRedKey.Checked then
5842 b := KEY_RED;
5843 if cbGreenKey.Checked then
5844 b := b or KEY_GREEN;
5845 if cbBlueKey.Checked then
5846 b := b or KEY_BLUE;
5847 if cbRedTeam.Checked then
5848 b := b or KEY_REDTEAM;
5849 if cbBlueTeam.Checked then
5850 b := b or KEY_BLUETEAM;
5852 Values[Key] := KeyToStr(b);
5853 vleObjectPropertyApply(Sender);
5854 end;
5855 end
5856 else if Key = _lc[I_PROP_TR_FX_TYPE] then
5857 with ChooseTypeForm, vleObjectProperty do
5858 begin // Выбор типа эффекта:
5859 Caption := _lc[I_CAP_FX_TYPE];
5860 lbTypeSelect.Items.Clear();
5862 for b := EFFECT_NONE to EFFECT_FIRE do
5863 lbTypeSelect.Items.Add(EffectToStr(b));
5865 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]);
5867 if ShowModal() = mrOK then
5868 begin
5869 b := lbTypeSelect.ItemIndex;
5870 Values[Key] := EffectToStr(b);
5871 vleObjectPropertyApply(Sender);
5872 end;
5873 end
5874 else if Key = _lc[I_PROP_TR_MONSTER_TYPE] then
5875 with ChooseTypeForm, vleObjectProperty do
5876 begin // Выбор типа монстра:
5877 Caption := _lc[I_CAP_MONSTER_TYPE];
5878 lbTypeSelect.Items.Clear();
5880 for b := MONSTER_DEMON to MONSTER_MAN do
5881 lbTypeSelect.Items.Add(MonsterToStr(b));
5883 lbTypeSelect.ItemIndex := StrToMonster(Values[Key]) - MONSTER_DEMON;
5885 if ShowModal() = mrOK then
5886 begin
5887 b := lbTypeSelect.ItemIndex + MONSTER_DEMON;
5888 Values[Key] := MonsterToStr(b);
5889 vleObjectPropertyApply(Sender);
5890 end;
5891 end
5892 else if Key = _lc[I_PROP_TR_ITEM_TYPE] then
5893 with ChooseTypeForm, vleObjectProperty do
5894 begin // Выбор типа предмета:
5895 Caption := _lc[I_CAP_ITEM_TYPE];
5896 lbTypeSelect.Items.Clear();
5898 for b := ITEM_MEDKIT_SMALL to ITEM_KEY_BLUE do
5899 lbTypeSelect.Items.Add(ItemToStr(b));
5900 lbTypeSelect.Items.Add(ItemToStr(ITEM_BOTTLE));
5901 lbTypeSelect.Items.Add(ItemToStr(ITEM_HELMET));
5902 lbTypeSelect.Items.Add(ItemToStr(ITEM_JETPACK));
5903 lbTypeSelect.Items.Add(ItemToStr(ITEM_INVIS));
5904 lbTypeSelect.Items.Add(ItemToStr(ITEM_WEAPON_FLAMETHROWER));
5905 lbTypeSelect.Items.Add(ItemToStr(ITEM_AMMO_FUELCAN));
5907 b := StrToItem(Values[Key]);
5908 if b >= ITEM_BOTTLE then
5909 b := b - 2;
5910 lbTypeSelect.ItemIndex := b - ITEM_MEDKIT_SMALL;
5912 if ShowModal() = mrOK then
5913 begin
5914 b := lbTypeSelect.ItemIndex + ITEM_MEDKIT_SMALL;
5915 if b >= ITEM_WEAPON_KASTET then
5916 b := b + 2;
5917 Values[Key] := ItemToStr(b);
5918 vleObjectPropertyApply(Sender);
5919 end;
5920 end
5921 else if Key = _lc[I_PROP_TR_SHOT_TYPE] then
5922 with ChooseTypeForm, vleObjectProperty do
5923 begin // Выбор типа предмета:
5924 Caption := _lc[I_PROP_TR_SHOT_TYPE];
5925 lbTypeSelect.Items.Clear();
5927 for b := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
5928 lbTypeSelect.Items.Add(ShotToStr(b));
5930 lbTypeSelect.ItemIndex := StrToShot(Values[Key]);
5932 if ShowModal() = mrOK then
5933 begin
5934 b := lbTypeSelect.ItemIndex;
5935 Values[Key] := ShotToStr(b);
5936 vleObjectPropertyApply(Sender);
5937 end;
5938 end
5939 else if Key = _lc[I_PROP_TR_EFFECT_TYPE] then
5940 with ChooseTypeForm, vleObjectProperty do
5941 begin // Выбор типа эффекта:
5942 Caption := _lc[I_CAP_FX_TYPE];
5943 lbTypeSelect.Items.Clear();
5945 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_PARTICLE]);
5946 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_ANIMATION]);
5947 if Values[Key] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5948 lbTypeSelect.ItemIndex := 1
5949 else
5950 lbTypeSelect.ItemIndex := 0;
5952 if ShowModal() = mrOK then
5953 begin
5954 b := lbTypeSelect.ItemIndex;
5955 if b = 0 then
5956 Values[Key] := _lc[I_PROP_TR_EFFECT_PARTICLE]
5957 else
5958 Values[Key] := _lc[I_PROP_TR_EFFECT_ANIMATION];
5959 vleObjectPropertyApply(Sender);
5960 end;
5961 end
5962 else if Key = _lc[I_PROP_TR_EFFECT_SUBTYPE] then
5963 with ChooseTypeForm, vleObjectProperty do
5964 begin // Выбор подтипа эффекта:
5965 Caption := _lc[I_CAP_FX_TYPE];
5966 lbTypeSelect.Items.Clear();
5968 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5969 begin
5970 for b := EFFECT_TELEPORT to EFFECT_FIRE do
5971 lbTypeSelect.Items.Add(EffectToStr(b));
5973 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]) - 1;
5974 end else
5975 begin
5976 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SLIQUID]);
5977 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_LLIQUID]);
5978 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_DLIQUID]);
5979 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BLOOD]);
5980 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SPARK]);
5981 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BUBBLE]);
5982 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SLIQUID;
5983 if Values[Key] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
5984 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_LLIQUID;
5985 if Values[Key] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
5986 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_DLIQUID;
5987 if Values[Key] = _lc[I_PROP_TR_EFFECT_BLOOD] then
5988 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BLOOD;
5989 if Values[Key] = _lc[I_PROP_TR_EFFECT_SPARK] then
5990 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SPARK;
5991 if Values[Key] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
5992 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BUBBLE;
5993 end;
5995 if ShowModal() = mrOK then
5996 begin
5997 b := lbTypeSelect.ItemIndex;
5999 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
6000 Values[Key] := EffectToStr(b + 1)
6001 else begin
6002 Values[Key] := _lc[I_PROP_TR_EFFECT_SLIQUID];
6003 if b = TRIGGER_EFFECT_LLIQUID then
6004 Values[Key] := _lc[I_PROP_TR_EFFECT_LLIQUID];
6005 if b = TRIGGER_EFFECT_DLIQUID then
6006 Values[Key] := _lc[I_PROP_TR_EFFECT_DLIQUID];
6007 if b = TRIGGER_EFFECT_BLOOD then
6008 Values[Key] := _lc[I_PROP_TR_EFFECT_BLOOD];
6009 if b = TRIGGER_EFFECT_SPARK then
6010 Values[Key] := _lc[I_PROP_TR_EFFECT_SPARK];
6011 if b = TRIGGER_EFFECT_BUBBLE then
6012 Values[Key] := _lc[I_PROP_TR_EFFECT_BUBBLE];
6013 end;
6015 vleObjectPropertyApply(Sender);
6016 end;
6017 end
6018 else if Key = _lc[I_PROP_TR_EFFECT_COLOR] then
6019 with vleObjectProperty do
6020 begin // Выбор цвета эффекта:
6021 ColorDialog.Color := StrToIntDef(Values[Key], 0);
6022 if ColorDialog.Execute then
6023 begin
6024 Values[Key] := IntToStr(ColorDialog.Color);
6025 vleObjectPropertyApply(Sender);
6026 end;
6027 end
6028 else if Key = _lc[I_PROP_PANEL_TEX] then
6029 begin // Смена текстуры:
6030 vleObjectProperty.Values[Key] := SelectedTexture();
6031 vleObjectPropertyApply(Sender);
6032 end;
6033 end;
6035 procedure TMainForm.vleObjectPropertyApply(Sender: TObject);
6036 begin
6037 // hack to prevent empty ID in list
6038 RenderPanel.SetFocus();
6039 bApplyProperty.Click();
6040 vleObjectProperty.SetFocus();
6041 end;
6043 procedure TMainForm.aSaveMapExecute(Sender: TObject);
6044 var
6045 FileName, Section, Res: String;
6046 begin
6047 if OpenedMap = '' then
6048 begin
6049 aSaveMapAsExecute(nil);
6050 Exit;
6051 end;
6053 g_ProcessResourceStr(OpenedMap, FileName, Section, Res);
6055 SaveMap(FileName+':\'+Res);
6056 end;
6058 procedure TMainForm.aOpenMapExecute(Sender: TObject);
6059 begin
6060 OpenDialog.Filter := _lc[I_FILE_FILTER_ALL];
6062 if OpenDialog.Execute() then
6063 begin
6064 OpenMapFile(OpenDialog.FileName);
6065 OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
6066 end;
6067 end;
6069 procedure TMainForm.OpenMapFile(FileName: String);
6070 begin
6071 if (Pos('.ini', LowerCase(ExtractFileName(FileName))) > 0) then
6072 begin // INI карты:
6073 FullClear();
6075 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
6076 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
6077 pLoadProgress.Show();
6079 OpenedMap := '';
6080 OpenedWAD := '';
6082 LoadMapOld(FileName);
6084 MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(FileName)]);
6086 pLoadProgress.Hide();
6087 MainForm.FormResize(Self);
6088 end
6089 else // Карты из WAD:
6090 begin
6091 OpenMap(FileName, '');
6092 end;
6093 end;
6095 procedure TMainForm.FormActivate(Sender: TObject);
6096 var
6097 lang: Integer;
6098 config: TConfig;
6099 begin
6100 MainForm.ActiveControl := RenderPanel;
6102 // Язык:
6103 if gLanguage = '' then
6104 begin
6105 lang := SelectLanguageForm.ShowModal();
6106 case lang of
6107 1: gLanguage := LANGUAGE_ENGLISH;
6108 else gLanguage := LANGUAGE_RUSSIAN;
6109 end;
6111 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
6112 config.WriteStr('Editor', 'Language', gLanguage);
6113 config.SaveFile(EditorDir+'Editor.cfg');
6114 config.Free();
6115 end;
6117 //e_WriteLog('Read language file', MSG_NOTIFY);
6118 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
6119 g_Language_Set(gLanguage);
6120 end;
6122 procedure TMainForm.aDeleteMap(Sender: TObject);
6123 var
6124 WAD: TWADEditor_1;
6125 MapList: SArray;
6126 MapName: Char16;
6127 a: Integer;
6128 str: String;
6129 begin
6130 OpenDialog.Filter := _lc[I_FILE_FILTER_WAD];
6132 if not OpenDialog.Execute() then
6133 Exit;
6135 WAD := TWADEditor_1.Create();
6137 if not WAD.ReadFile(OpenDialog.FileName) then
6138 begin
6139 WAD.Free();
6140 Exit;
6141 end;
6143 WAD.CreateImage();
6145 MapList := WAD.GetResourcesList('');
6147 SelectMapForm.Caption := _lc[I_CAP_REMOVE];
6148 SelectMapForm.lbMapList.Items.Clear();
6150 if MapList <> nil then
6151 for a := 0 to High(MapList) do
6152 SelectMapForm.lbMapList.Items.Add(win2utf(MapList[a]));
6154 if (SelectMapForm.ShowModal() = mrOK) then
6155 begin
6156 str := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
6157 MapName := '';
6158 Move(str[1], MapName[0], Min(16, Length(str)));
6160 if MessageBox(0, PChar(Format(_lc[I_MSG_DELETE_MAP_PROMT],
6161 [MapName, OpenDialog.FileName])),
6162 PChar(_lc[I_MSG_DELETE_MAP]),
6163 MB_ICONQUESTION or MB_YESNO or
6164 MB_DEFBUTTON2) <> mrYes then
6165 Exit;
6167 WAD.RemoveResource('', utf2win(MapName));
6169 MessageBox(0, PChar(Format(_lc[I_MSG_MAP_DELETED_PROMT],
6170 [MapName])),
6171 PChar(_lc[I_MSG_MAP_DELETED]),
6172 MB_ICONINFORMATION or MB_OK or
6173 MB_DEFBUTTON1);
6175 WAD.SaveTo(OpenDialog.FileName);
6177 // Удалили текущую карту - сохранять по старому ее нельзя:
6178 if OpenedMap = (OpenDialog.FileName+':\'+MapName) then
6179 begin
6180 OpenedMap := '';
6181 OpenedWAD := '';
6182 MainForm.Caption := FormCaption;
6183 end;
6184 end;
6186 WAD.Free();
6187 end;
6189 procedure TMainForm.vleObjectPropertyKeyDown(Sender: TObject;
6190 var Key: Word; Shift: TShiftState);
6191 begin
6192 if Key = VK_RETURN then
6193 vleObjectPropertyApply(Sender);
6194 end;
6196 procedure MovePanel(var ID: DWORD; MoveType: Byte);
6197 var
6198 _id, a: Integer;
6199 tmp: TPanel;
6200 begin
6201 if (ID = 0) and (MoveType = 0) then
6202 Exit;
6203 if (ID = DWORD(High(gPanels))) and (MoveType <> 0) then
6204 Exit;
6205 if (ID > DWORD(High(gPanels))) then
6206 Exit;
6208 _id := Integer(ID);
6210 if MoveType = 0 then // to Back
6211 begin
6212 if gTriggers <> nil then
6213 for a := 0 to High(gTriggers) do
6214 with gTriggers[a] do
6215 begin
6216 if TriggerType = TRIGGER_NONE then
6217 Continue;
6219 if TexturePanel = _id then
6220 TexturePanel := 0
6221 else
6222 if (TexturePanel >= 0) and (TexturePanel < _id) then
6223 Inc(TexturePanel);
6225 case TriggerType of
6226 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6227 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6228 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6229 if Data.PanelID = _id then
6230 Data.PanelID := 0
6231 else
6232 if (Data.PanelID >= 0) and (Data.PanelID < _id) then
6233 Inc(Data.PanelID);
6235 TRIGGER_SHOT:
6236 if Data.ShotPanelID = _id then
6237 Data.ShotPanelID := 0
6238 else
6239 if (Data.ShotPanelID >= 0) and (Data.ShotPanelID < _id) then
6240 Inc(Data.ShotPanelID);
6241 end;
6242 end;
6244 tmp := gPanels[_id];
6246 for a := _id downto 1 do
6247 gPanels[a] := gPanels[a-1];
6249 gPanels[0] := tmp;
6251 ID := 0;
6252 end
6253 else // to Front
6254 begin
6255 if gTriggers <> nil then
6256 for a := 0 to High(gTriggers) do
6257 with gTriggers[a] do
6258 begin
6259 if TriggerType = TRIGGER_NONE then
6260 Continue;
6262 if TexturePanel = _id then
6263 TexturePanel := High(gPanels)
6264 else
6265 if TexturePanel > _id then
6266 Dec(TexturePanel);
6268 case TriggerType of
6269 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
6270 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6271 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
6272 if Data.PanelID = _id then
6273 Data.PanelID := High(gPanels)
6274 else
6275 if Data.PanelID > _id then
6276 Dec(Data.PanelID);
6278 TRIGGER_SHOT:
6279 if Data.ShotPanelID = _id then
6280 Data.ShotPanelID := High(gPanels)
6281 else
6282 if Data.ShotPanelID > _id then
6283 Dec(Data.ShotPanelID);
6284 end;
6285 end;
6287 tmp := gPanels[_id];
6289 for a := _id to High(gPanels)-1 do
6290 gPanels[a] := gPanels[a+1];
6292 gPanels[High(gPanels)] := tmp;
6294 ID := High(gPanels);
6295 end;
6296 end;
6298 procedure TMainForm.aMoveToBack(Sender: TObject);
6299 var
6300 a: Integer;
6301 begin
6302 if SelectedObjects = nil then
6303 Exit;
6305 for a := 0 to High(SelectedObjects) do
6306 with SelectedObjects[a] do
6307 if Live and (ObjectType = OBJECT_PANEL) then
6308 begin
6309 SelectedObjects[0] := SelectedObjects[a];
6310 SetLength(SelectedObjects, 1);
6311 MovePanel(ID, 0);
6312 FillProperty();
6313 Break;
6314 end;
6315 end;
6317 procedure TMainForm.aMoveToFore(Sender: TObject);
6318 var
6319 a: Integer;
6320 begin
6321 if SelectedObjects = nil then
6322 Exit;
6324 for a := 0 to High(SelectedObjects) do
6325 with SelectedObjects[a] do
6326 if Live and (ObjectType = OBJECT_PANEL) then
6327 begin
6328 SelectedObjects[0] := SelectedObjects[a];
6329 SetLength(SelectedObjects, 1);
6330 MovePanel(ID, 1);
6331 FillProperty();
6332 Break;
6333 end;
6334 end;
6336 procedure TMainForm.aSaveMapAsExecute(Sender: TObject);
6337 var
6338 idx: Integer;
6339 begin
6340 SaveDialog.Filter := _lc[I_FILE_FILTER_WAD];
6342 if not SaveDialog.Execute() then
6343 Exit;
6345 SaveMapForm.GetMaps(SaveDialog.FileName, True);
6347 if SaveMapForm.ShowModal() <> mrOK then
6348 Exit;
6350 SaveDialog.InitialDir := ExtractFileDir(SaveDialog.FileName);
6351 OpenedMap := SaveDialog.FileName+':\'+SaveMapForm.eMapName.Text;
6352 OpenedWAD := SaveDialog.FileName;
6354 idx := RecentFiles.IndexOf(OpenedMap);
6355 // Такая карта уже недавно открывалась:
6356 if idx >= 0 then
6357 RecentFiles.Delete(idx);
6358 RecentFiles.Insert(0, OpenedMap);
6359 RefreshRecentMenu;
6361 SaveMap(OpenedMap);
6363 gMapInfo.FileName := SaveDialog.FileName;
6364 gMapInfo.MapName := SaveMapForm.eMapName.Text;
6365 UpdateCaption(gMapInfo.Name, ExtractFileName(gMapInfo.FileName), gMapInfo.MapName);
6366 end;
6368 procedure TMainForm.aSelectAllExecute(Sender: TObject);
6369 var
6370 a: Integer;
6371 begin
6372 RemoveSelectFromObjects();
6374 case pcObjects.ActivePageIndex+1 of
6375 OBJECT_PANEL:
6376 if gPanels <> nil then
6377 for a := 0 to High(gPanels) do
6378 if gPanels[a].PanelType <> PANEL_NONE then
6379 SelectObject(OBJECT_PANEL, a, True);
6380 OBJECT_ITEM:
6381 if gItems <> nil then
6382 for a := 0 to High(gItems) do
6383 if gItems[a].ItemType <> ITEM_NONE then
6384 SelectObject(OBJECT_ITEM, a, True);
6385 OBJECT_MONSTER:
6386 if gMonsters <> nil then
6387 for a := 0 to High(gMonsters) do
6388 if gMonsters[a].MonsterType <> MONSTER_NONE then
6389 SelectObject(OBJECT_MONSTER, a, True);
6390 OBJECT_AREA:
6391 if gAreas <> nil then
6392 for a := 0 to High(gAreas) do
6393 if gAreas[a].AreaType <> AREA_NONE then
6394 SelectObject(OBJECT_AREA, a, True);
6395 OBJECT_TRIGGER:
6396 if gTriggers <> nil then
6397 for a := 0 to High(gTriggers) do
6398 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6399 SelectObject(OBJECT_TRIGGER, a, True);
6400 end;
6401 end;
6403 procedure TMainForm.tbGridOnClick(Sender: TObject);
6404 begin
6405 DotEnable := not DotEnable;
6406 (Sender as TToolButton).Down := DotEnable;
6407 end;
6409 procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean);
6410 begin
6411 // FIXME: this is a shitty hack
6412 if not gDataLoaded then
6413 begin
6414 e_WriteLog('Init OpenGL', MSG_NOTIFY);
6415 e_InitGL();
6416 e_WriteLog('Loading data', MSG_NOTIFY);
6417 LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
6418 e_WriteLog('Loading more data', MSG_NOTIFY);
6419 LoadData();
6420 e_WriteLog('Loading even more data', MSG_NOTIFY);
6421 gDataLoaded := True;
6422 MainForm.FormResize(nil);
6423 end;
6424 Draw();
6425 end;
6427 procedure TMainForm.miMapPreviewClick(Sender: TObject);
6428 begin
6429 if PreviewMode = 2 then
6430 Exit;
6432 if PreviewMode = 0 then
6433 begin
6434 Splitter2.Visible := False;
6435 Splitter1.Visible := False;
6436 StatusBar.Visible := False;
6437 PanelObjs.Visible := False;
6438 PanelProps.Visible := False;
6439 MainToolBar.Visible := False;
6440 sbHorizontal.Visible := False;
6441 sbVertical.Visible := False;
6442 end
6443 else
6444 begin
6445 StatusBar.Visible := True;
6446 PanelObjs.Visible := True;
6447 PanelProps.Visible := True;
6448 Splitter2.Visible := True;
6449 Splitter1.Visible := True;
6450 MainToolBar.Visible := True;
6451 sbHorizontal.Visible := True;
6452 sbVertical.Visible := True;
6453 end;
6455 PreviewMode := PreviewMode xor 1;
6456 (Sender as TMenuItem).Checked := PreviewMode > 0;
6458 FormResize(Self);
6459 end;
6461 procedure TMainForm.miLayer1Click(Sender: TObject);
6462 begin
6463 SwitchLayer(LAYER_BACK);
6464 end;
6466 procedure TMainForm.miLayer2Click(Sender: TObject);
6467 begin
6468 SwitchLayer(LAYER_WALLS);
6469 end;
6471 procedure TMainForm.miLayer3Click(Sender: TObject);
6472 begin
6473 SwitchLayer(LAYER_FOREGROUND);
6474 end;
6476 procedure TMainForm.miLayer4Click(Sender: TObject);
6477 begin
6478 SwitchLayer(LAYER_STEPS);
6479 end;
6481 procedure TMainForm.miLayer5Click(Sender: TObject);
6482 begin
6483 SwitchLayer(LAYER_WATER);
6484 end;
6486 procedure TMainForm.miLayer6Click(Sender: TObject);
6487 begin
6488 SwitchLayer(LAYER_ITEMS);
6489 end;
6491 procedure TMainForm.miLayer7Click(Sender: TObject);
6492 begin
6493 SwitchLayer(LAYER_MONSTERS);
6494 end;
6496 procedure TMainForm.miLayer8Click(Sender: TObject);
6497 begin
6498 SwitchLayer(LAYER_AREAS);
6499 end;
6501 procedure TMainForm.miLayer9Click(Sender: TObject);
6502 begin
6503 SwitchLayer(LAYER_TRIGGERS);
6504 end;
6506 procedure TMainForm.tbShowClick(Sender: TObject);
6507 var
6508 a: Integer;
6509 b: Boolean;
6510 begin
6511 b := True;
6512 for a := 0 to High(LayerEnabled) do
6513 b := b and LayerEnabled[a];
6515 b := not b;
6517 ShowLayer(LAYER_BACK, b);
6518 ShowLayer(LAYER_WALLS, b);
6519 ShowLayer(LAYER_FOREGROUND, b);
6520 ShowLayer(LAYER_STEPS, b);
6521 ShowLayer(LAYER_WATER, b);
6522 ShowLayer(LAYER_ITEMS, b);
6523 ShowLayer(LAYER_MONSTERS, b);
6524 ShowLayer(LAYER_AREAS, b);
6525 ShowLayer(LAYER_TRIGGERS, b);
6526 end;
6528 procedure TMainForm.miMiniMapClick(Sender: TObject);
6529 begin
6530 SwitchMap();
6531 end;
6533 procedure TMainForm.miSwitchGridClick(Sender: TObject);
6534 begin
6535 if DotStep = DotStepOne then
6536 DotStep := DotStepTwo
6537 else
6538 DotStep := DotStepOne;
6540 MousePos.X := (MousePos.X div DotStep) * DotStep;
6541 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6542 end;
6544 procedure TMainForm.miShowEdgesClick(Sender: TObject);
6545 begin
6546 ShowEdges();
6547 end;
6549 procedure TMainForm.miSnapToGridClick(Sender: TObject);
6550 begin
6551 SnapToGrid := not SnapToGrid;
6553 MousePos.X := (MousePos.X div DotStep) * DotStep;
6554 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6556 miSnapToGrid.Checked := SnapToGrid;
6557 end;
6559 procedure TMainForm.minexttabClick(Sender: TObject);
6560 begin
6561 if pcObjects.ActivePageIndex < pcObjects.PageCount-1 then
6562 pcObjects.ActivePageIndex := pcObjects.ActivePageIndex+1
6563 else
6564 pcObjects.ActivePageIndex := 0;
6565 end;
6567 procedure TMainForm.miSaveMiniMapClick(Sender: TObject);
6568 begin
6569 SaveMiniMapForm.ShowModal();
6570 end;
6572 procedure TMainForm.bClearTextureClick(Sender: TObject);
6573 begin
6574 lbTextureList.ItemIndex := -1;
6575 lTextureWidth.Caption := '';
6576 lTextureHeight.Caption := '';
6577 end;
6579 procedure TMainForm.miPackMapClick(Sender: TObject);
6580 begin
6581 PackMapForm.ShowModal();
6582 end;
6584 procedure TMainForm.miMapTestSettingsClick(Sender: TObject);
6585 begin
6586 MapTestForm.ShowModal();
6587 end;
6589 procedure TMainForm.miTestMapClick(Sender: TObject);
6590 var
6591 cmd, mapWAD, mapToRun, tempWAD: String;
6592 opt: LongWord;
6593 time: Integer;
6594 proc: TProcessUTF8;
6595 res: Boolean;
6596 begin
6597 mapToRun := '';
6598 if OpenedMap <> '' then
6599 begin
6600 // Указываем текущую карту для теста:
6601 g_ProcessResourceStr(OpenedMap, @mapWAD, nil, @mapToRun);
6602 mapToRun := mapWAD + ':\' + mapToRun;
6603 mapToRun := ExtractRelativePath(ExtractFilePath(TestD2dExe) + 'maps/', mapToRun);
6604 end;
6605 // Сохраняем временную карту:
6606 time := 0;
6607 repeat
6608 mapWAD := ExtractFilePath(TestD2dExe) + Format('maps/temp%.4d.wad', [time]);
6609 Inc(time);
6610 until not FileExists(mapWAD);
6611 tempWAD := mapWAD + ':\' + TEST_MAP_NAME;
6612 SaveMap(tempWAD);
6614 tempWAD := ExtractRelativePath(ExtractFilePath(TestD2dExe) + 'maps/', tempWAD);
6615 // Если карта не была открыта, указываем временную в качестве текущей:
6616 if mapToRun = '' then
6617 mapToRun := tempWAD;
6619 // Опции игры:
6620 opt := 32 + 64;
6621 if TestOptionsTwoPlayers then
6622 opt := opt + 1;
6623 if TestOptionsTeamDamage then
6624 opt := opt + 2;
6625 if TestOptionsAllowExit then
6626 opt := opt + 4;
6627 if TestOptionsWeaponStay then
6628 opt := opt + 8;
6629 if TestOptionsMonstersDM then
6630 opt := opt + 16;
6632 // Составляем командную строку:
6633 cmd := '-map "' + mapToRun + '"';
6634 cmd := cmd + ' -testmap "' + tempWAD + '"';
6635 cmd := cmd + ' -gm ' + TestGameMode;
6636 cmd := cmd + ' -limt ' + TestLimTime;
6637 cmd := cmd + ' -lims ' + TestLimScore;
6638 cmd := cmd + ' -opt ' + IntToStr(opt);
6640 if TestMapOnce then
6641 cmd := cmd + ' --close';
6643 cmd := cmd + ' --debug';
6645 // Запускаем:
6646 proc := TProcessUTF8.Create(nil);
6647 proc.Executable := TestD2dExe;
6648 proc.Parameters.Add(cmd);
6649 res := True;
6650 try
6651 proc.Execute();
6652 except
6653 res := False;
6654 end;
6655 if res then
6656 begin
6657 Application.Minimize();
6658 proc.WaitOnExit();
6659 end;
6660 if (not res) or (proc.ExitCode < 0) then
6661 begin
6662 MessageBox(0, 'FIXME',
6663 PChar(_lc[I_MSG_EXEC_ERROR]),
6664 MB_OK or MB_ICONERROR);
6665 end;
6666 proc.Free();
6668 SysUtils.DeleteFile(mapWAD);
6669 Application.Restore();
6670 end;
6672 procedure TMainForm.sbVerticalScroll(Sender: TObject;
6673 ScrollCode: TScrollCode; var ScrollPos: Integer);
6674 begin
6675 MapOffset.Y := -Normalize16(sbVertical.Position);
6676 end;
6678 procedure TMainForm.sbHorizontalScroll(Sender: TObject;
6679 ScrollCode: TScrollCode; var ScrollPos: Integer);
6680 begin
6681 MapOffset.X := -Normalize16(sbHorizontal.Position);
6682 end;
6684 procedure TMainForm.miOpenWadMapClick(Sender: TObject);
6685 begin
6686 if OpenedWAD <> '' then
6687 begin
6688 OpenMap(OpenedWAD, '');
6689 end;
6690 end;
6692 procedure TMainForm.selectall1Click(Sender: TObject);
6693 var
6694 a: Integer;
6695 begin
6696 RemoveSelectFromObjects();
6698 if gPanels <> nil then
6699 for a := 0 to High(gPanels) do
6700 if gPanels[a].PanelType <> PANEL_NONE then
6701 SelectObject(OBJECT_PANEL, a, True);
6703 if gItems <> nil then
6704 for a := 0 to High(gItems) do
6705 if gItems[a].ItemType <> ITEM_NONE then
6706 SelectObject(OBJECT_ITEM, a, True);
6708 if gMonsters <> nil then
6709 for a := 0 to High(gMonsters) do
6710 if gMonsters[a].MonsterType <> MONSTER_NONE then
6711 SelectObject(OBJECT_MONSTER, a, True);
6713 if gAreas <> nil then
6714 for a := 0 to High(gAreas) do
6715 if gAreas[a].AreaType <> AREA_NONE then
6716 SelectObject(OBJECT_AREA, a, True);
6718 if gTriggers <> nil then
6719 for a := 0 to High(gTriggers) do
6720 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6721 SelectObject(OBJECT_TRIGGER, a, True);
6722 end;
6724 procedure TMainForm.Splitter1CanResize(Sender: TObject;
6725 var NewSize: Integer; var Accept: Boolean);
6726 begin
6727 Accept := (NewSize > 140);
6728 end;
6730 procedure TMainForm.Splitter2CanResize(Sender: TObject;
6731 var NewSize: Integer; var Accept: Boolean);
6732 begin
6733 Accept := (NewSize > 110);
6734 end;
6736 procedure TMainForm.vleObjectPropertyEnter(Sender: TObject);
6737 begin
6738 EditingProperties := True;
6739 end;
6741 procedure TMainForm.vleObjectPropertyExit(Sender: TObject);
6742 begin
6743 EditingProperties := False;
6744 end;
6746 procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
6747 Shift: TShiftState);
6748 begin
6749 // Объекты передвигались:
6750 if MainForm.ActiveControl = RenderPanel then
6751 begin
6752 if (Key = VK_NUMPAD4) or
6753 (Key = VK_NUMPAD6) or
6754 (Key = VK_NUMPAD8) or
6755 (Key = VK_NUMPAD5) or
6756 (Key = Ord('V')) then
6757 FillProperty();
6758 end;
6759 // Быстрое превью карты:
6760 if Key = Ord('E') then
6761 begin
6762 if PreviewMode = 2 then
6763 PreviewMode := 0;
6764 end;
6765 RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
6766 end;
6768 end.