DEADSOFTWARE

Cleanup: Eliminate warnings and hints
[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, LMessages, SysUtils, Variants, Classes, Graphics,
9 Controls, Forms, Dialogs, ImgList, StdCtrls, Buttons,
10 ComCtrls, ValEdit, Types, ToolWin, Menus, ExtCtrls,
11 CheckLst, Grids, OpenGLContext, utils;
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 miSaveMiniMap: TMenuItem;
30 miDeleteMap: TMenuItem;
31 miPackMap: TMenuItem;
32 miLine2: TMenuItem;
33 miExit: TMenuItem;
34 // "Правка":
35 miMenuEdit: TMenuItem;
36 miUndo: TMenuItem;
37 miLine3: TMenuItem;
38 miCopy: TMenuItem;
39 miCut: TMenuItem;
40 miPaste: TMenuItem;
41 miLine4: TMenuItem;
42 miSelectAll: TMenuItem;
43 miLine5: TMenuItem;
44 miToFore: TMenuItem;
45 miToBack: TMenuItem;
46 // "Инструменты":
47 miMenuTools: TMenuItem;
48 miSnapToGrid: TMenuItem;
49 miMiniMap: TMenuItem;
50 miSwitchGrid: TMenuItem;
51 miShowEdges: TMenuItem;
52 miLayers: TMenuItem;
53 miLayer1: TMenuItem;
54 miLayer2: TMenuItem;
55 miLayer3: TMenuItem;
56 miLayer4: TMenuItem;
57 miLayer5: TMenuItem;
58 miLayer6: TMenuItem;
59 miLayer7: TMenuItem;
60 miLayer8: TMenuItem;
61 miLayer9: TMenuItem;
62 // "Сервис":
63 miMenuService: TMenuItem;
64 miCheckMap: TMenuItem;
65 miOptimmization: TMenuItem;
66 miMapPreview: TMenuItem;
67 miTestMap: TMenuItem;
68 // "Настройка":
69 miMenuSettings: TMenuItem;
70 miMapOptions: TMenuItem;
71 miLine6: TMenuItem;
72 miOptions: TMenuItem;
73 miLine7: TMenuItem;
74 miMapTestSettings: TMenuItem;
75 // "Справка":
76 miMenuHelp: TMenuItem;
77 miAbout: TMenuItem;
78 // Скрытый пункт меню для Ctrl+Tab:
79 miHidden1: TMenuItem;
80 minexttab: TMenuItem;
82 // Панель инструментов:
83 MainToolBar: TToolBar;
84 pbLoad: TProgressBar;
85 pLoadProgress: TPanel;
86 RenderPanel: TOpenGLControl;
87 tbNewMap: TToolButton;
88 tbOpenMap: TToolButton;
89 tbSaveMap: TToolButton;
90 tbOpenWadMap: TToolButton;
91 tbLine1: TToolButton;
92 tbShowMap: TToolButton;
93 tbLine2: TToolButton;
94 tbShow: TToolButton;
95 tbLine3: TToolButton;
96 tbGridOn: TToolButton;
97 tbGrid: TToolButton;
98 tbLine4: TToolButton;
99 tbTestMap: TToolButton;
100 // Всплывающее меню для кнопки слоев:
101 pmShow: TPopupMenu;
102 miLayerP1: TMenuItem;
103 miLayerP2: TMenuItem;
104 miLayerP3: TMenuItem;
105 miLayerP4: TMenuItem;
106 miLayerP5: TMenuItem;
107 miLayerP6: TMenuItem;
108 miLayerP7: TMenuItem;
109 miLayerP8: TMenuItem;
110 miLayerP9: TMenuItem;
111 // Всплывающее меню для кнопки теста карты:
112 pmMapTest: TPopupMenu;
113 miMapTestPMSet: TMenuItem;
115 // Панель карты:
116 PanelMap: TPanel;
117 // Полосы прокрутки:
118 sbHorizontal: TScrollBar;
119 sbVertical: TScrollBar;
121 // Панель свойств:
122 PanelProps: TPanel;
123 // Панель применения свойств:
124 PanelPropApply: TPanel;
125 bApplyProperty: TButton;
126 // Редактор свойств объектов:
127 vleObjectProperty: TValueListEditor;
129 // Панель объектов - вкладки:
130 PanelObjs: TPanel;
131 pcObjects: TPageControl;
132 // Вкладка "Панели":
133 tsPanels: TTabSheet;
134 lbTextureList: TListBox;
135 // Панель настройки текстур:
136 PanelTextures: TPanel;
137 LabelTxW: TLabel;
138 lTextureWidth: TLabel;
139 LabelTxH: TLabel;
140 lTextureHeight: TLabel;
141 cbPreview: TCheckBox;
142 bbAddTexture: TBitBtn;
143 bbRemoveTexture: TBitBtn;
144 bClearTexture: TButton;
145 // Панель типов панелей:
146 PanelPanelType: TPanel;
147 lbPanelType: TListBox;
148 // Вкладка "Предметы":
149 tsItems: TTabSheet;
150 lbItemList: TListBox;
151 cbOnlyDM: TCheckBox;
152 cbFall: TCheckBox;
153 // Вкладка "Монстры":
154 tsMonsters: TTabSheet;
155 lbMonsterList: TListBox;
156 rbMonsterLeft: TRadioButton;
157 rbMonsterRight: TRadioButton;
158 // Вкладка "Области":
159 tsAreas: TTabSheet;
160 lbAreasList: TListBox;
161 rbAreaLeft: TRadioButton;
162 rbAreaRight: TRadioButton;
163 // Вкладка "Триггеры":
164 tsTriggers: TTabSheet;
165 lbTriggersList: TListBox;
166 clbActivationType: TCheckListBox;
167 clbKeys: TCheckListBox;
169 // Остальные панели
170 Splitter1: TSplitter;
171 Splitter2: TSplitter;
172 StatusBar: TStatusBar;
174 // Специальные объекты:
175 ImageList: TImageList;
176 ilToolbar: TImageList;
177 OpenDialog: TOpenDialog;
178 SaveDialog: TSaveDialog;
179 selectall1: TMenuItem;
180 ColorDialog: TColorDialog;
182 procedure aAboutExecute(Sender: TObject);
183 procedure aCheckMapExecute(Sender: TObject);
184 procedure aMoveToFore(Sender: TObject);
185 procedure aMoveToBack(Sender: TObject);
186 procedure aCopyObjectExecute(Sender: TObject);
187 procedure aCutObjectExecute(Sender: TObject);
188 procedure aEditorOptionsExecute(Sender: TObject);
189 procedure aExitExecute(Sender: TObject);
190 procedure aMapOptionsExecute(Sender: TObject);
191 procedure aNewMapExecute(Sender: TObject);
192 procedure aOpenMapExecute(Sender: TObject);
193 procedure aOptimizeExecute(Sender: TObject);
194 procedure aPasteObjectExecute(Sender: TObject);
195 procedure aSelectAllExecute(Sender: TObject);
196 procedure aSaveMapExecute(Sender: TObject);
197 procedure aSaveMapAsExecute(Sender: TObject);
198 procedure aUndoExecute(Sender: TObject);
199 procedure aDeleteMap(Sender: TObject);
200 procedure bApplyPropertyClick(Sender: TObject);
201 procedure bbAddTextureClick(Sender: TObject);
202 procedure bbRemoveTextureClick(Sender: TObject);
203 procedure FormActivate(Sender: TObject);
204 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
205 procedure FormCreate(Sender: TObject);
206 procedure FormDestroy(Sender: TObject);
207 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
208 procedure FormResize(Sender: TObject);
209 procedure lbTextureListClick(Sender: TObject);
210 procedure RenderPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
211 procedure RenderPanelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
212 procedure RenderPanelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
213 procedure RenderPanelPaint(Sender: TObject);
214 procedure RenderPanelResize(Sender: TObject);
215 procedure vleObjectPropertyEditButtonClick(Sender: TObject);
216 procedure vleObjectPropertyGetPickList(Sender: TObject; const KeyName: String; Values: TStrings);
217 procedure vleObjectPropertyKeyDown(Sender: TObject; var Key: Word;
218 Shift: TShiftState);
219 procedure tbGridOnClick(Sender: TObject);
220 procedure miMapPreviewClick(Sender: TObject);
221 procedure miLayer1Click(Sender: TObject);
222 procedure miLayer2Click(Sender: TObject);
223 procedure miLayer3Click(Sender: TObject);
224 procedure miLayer4Click(Sender: TObject);
225 procedure miLayer5Click(Sender: TObject);
226 procedure miLayer6Click(Sender: TObject);
227 procedure miLayer7Click(Sender: TObject);
228 procedure miLayer8Click(Sender: TObject);
229 procedure miLayer9Click(Sender: TObject);
230 procedure tbShowClick(Sender: TObject);
231 procedure miSnapToGridClick(Sender: TObject);
232 procedure miMiniMapClick(Sender: TObject);
233 procedure miSwitchGridClick(Sender: TObject);
234 procedure miShowEdgesClick(Sender: TObject);
235 procedure minexttabClick(Sender: TObject);
236 procedure miSaveMiniMapClick(Sender: TObject);
237 procedure bClearTextureClick(Sender: TObject);
238 procedure miPackMapClick(Sender: TObject);
239 procedure aRecentFileExecute(Sender: TObject);
240 procedure miMapTestSettingsClick(Sender: TObject);
241 procedure miTestMapClick(Sender: TObject);
242 procedure sbVerticalScroll(Sender: TObject; ScrollCode: TScrollCode;
243 var ScrollPos: Integer);
244 procedure sbHorizontalScroll(Sender: TObject; ScrollCode: TScrollCode;
245 var ScrollPos: Integer);
246 procedure miOpenWadMapClick(Sender: TObject);
247 procedure selectall1Click(Sender: TObject);
248 procedure Splitter1CanResize(Sender: TObject; var NewSize: Integer;
249 var Accept: Boolean);
250 procedure Splitter2CanResize(Sender: TObject; var NewSize: Integer;
251 var Accept: Boolean);
252 procedure vleObjectPropertyEnter(Sender: TObject);
253 procedure vleObjectPropertyExit(Sender: TObject);
254 procedure FormKeyUp(Sender: TObject; var Key: Word;
255 Shift: TShiftState);
256 private
257 procedure Draw();
258 procedure OnIdle(Sender: TObject; var Done: Boolean);
259 public
260 procedure RefreshRecentMenu();
261 { procedure lbTextureListDrawItem(Control: TWinControl; Index: Integer;
262 Rect: TRect; State: TOwnerDrawState); }
263 end;
265 const
266 LAYER_BACK = 0;
267 LAYER_WALLS = 1;
268 LAYER_FOREGROUND = 2;
269 LAYER_STEPS = 3;
270 LAYER_WATER = 4;
271 LAYER_ITEMS = 5;
272 LAYER_MONSTERS = 6;
273 LAYER_AREAS = 7;
274 LAYER_TRIGGERS = 8;
276 TEST_MAP_NAME = '$$$_TEST_$$$';
277 LANGUAGE_FILE_NAME = '_Editor.txt';
279 var
280 MainForm: TMainForm;
281 EditorDir: String;
282 OpenedMap: String;
283 OpenedWAD: String;
285 DotColor: TColor;
286 DotEnable: Boolean;
287 DotStep: Byte;
288 DotStepOne, DotStepTwo: Byte;
289 DotSize: Byte;
290 DrawTexturePanel: Boolean;
291 DrawPanelSize: Boolean;
292 BackColor: TColor;
293 PreviewColor: TColor;
294 Scale: Byte;
295 RecentCount: Integer;
296 RecentFiles: TStringList;
297 slInvalidTextures: TStringList;
299 TestGameMode: String;
300 TestLimTime: String;
301 TestLimScore: String;
302 TestOptionsTwoPlayers: Boolean;
303 TestOptionsTeamDamage: Boolean;
304 TestOptionsAllowExit: Boolean;
305 TestOptionsWeaponStay: Boolean;
306 TestOptionsMonstersDM: Boolean;
307 TestD2dExe: String;
308 TestMapOnce: Boolean;
310 LayerEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
311 (True, True, True, True, True, True, True, True, True);
312 PreviewMode: Boolean = False;
313 gLanguage: String;
315 FormCaption: String;
318 procedure OpenMap(FileName: String; mapN: String);
319 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
320 procedure RemoveSelectFromObjects();
321 procedure ChangeShownProperty(Name: String; NewValue: String);
323 implementation
325 uses
326 f_options, e_graphics, e_log, GL, GLExt, Math,
327 f_mapoptions, g_basic, f_about, f_mapoptimization,
328 f_mapcheck, f_addresource_texture, g_textures,
329 f_activationtype, f_keys, MAPWRITER, MAPSTRUCT,
330 MAPREADER, f_selectmap, f_savemap, WADEDITOR, WADSTRUCT, MAPDEF,
331 g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
332 f_addresource_sound, f_maptest, f_choosetype,
333 g_language, f_selectlang, ClipBrd;
335 const
336 UNDO_DELETE_PANEL = 1;
337 UNDO_DELETE_ITEM = 2;
338 UNDO_DELETE_AREA = 3;
339 UNDO_DELETE_MONSTER = 4;
340 UNDO_DELETE_TRIGGER = 5;
341 UNDO_ADD_PANEL = 6;
342 UNDO_ADD_ITEM = 7;
343 UNDO_ADD_AREA = 8;
344 UNDO_ADD_MONSTER = 9;
345 UNDO_ADD_TRIGGER = 10;
346 UNDO_MOVE_PANEL = 11;
347 UNDO_MOVE_ITEM = 12;
348 UNDO_MOVE_AREA = 13;
349 UNDO_MOVE_MONSTER = 14;
350 UNDO_MOVE_TRIGGER = 15;
351 UNDO_RESIZE_PANEL = 16;
352 UNDO_RESIZE_TRIGGER = 17;
354 MOUSEACTION_NONE = 0;
355 MOUSEACTION_DRAWPANEL = 1;
356 MOUSEACTION_DRAWTRIGGER = 2;
357 MOUSEACTION_MOVEOBJ = 3;
358 MOUSEACTION_RESIZE = 4;
359 MOUSEACTION_MOVEMAP = 5;
360 MOUSEACTION_DRAWPRESS = 6;
361 MOUSEACTION_NOACTION = 7;
363 RESIZETYPE_NONE = 0;
364 RESIZETYPE_VERTICAL = 1;
365 RESIZETYPE_HORIZONTAL = 2;
367 RESIZEDIR_NONE = 0;
368 RESIZEDIR_DOWN = 1;
369 RESIZEDIR_UP = 2;
370 RESIZEDIR_RIGHT = 3;
371 RESIZEDIR_LEFT = 4;
373 SELECTFLAG_NONE = 0;
374 SELECTFLAG_TELEPORT = 1;
375 SELECTFLAG_DOOR = 2;
376 SELECTFLAG_TEXTURE = 3;
377 SELECTFLAG_LIFT = 4;
378 SELECTFLAG_MONSTER = 5;
379 SELECTFLAG_SPAWNPOINT = 6;
380 SELECTFLAG_SHOTPANEL = 7;
381 SELECTFLAG_SELECTED = 8;
383 RECENT_FILES_MENU_START = 11;
385 CLIPBOARD_SIG = 'DF:ED';
387 type
388 TUndoRec = record
389 UndoType: Byte;
390 case Byte of
391 UNDO_DELETE_PANEL: (Panel: ^TPanel);
392 UNDO_DELETE_ITEM: (Item: TItem);
393 UNDO_DELETE_AREA: (Area: TArea);
394 UNDO_DELETE_MONSTER: (Monster: TMonster);
395 UNDO_DELETE_TRIGGER: (Trigger: TTrigger);
396 UNDO_ADD_PANEL,
397 UNDO_ADD_ITEM,
398 UNDO_ADD_AREA,
399 UNDO_ADD_MONSTER,
400 UNDO_ADD_TRIGGER: (AddID: DWORD);
401 UNDO_MOVE_PANEL,
402 UNDO_MOVE_ITEM,
403 UNDO_MOVE_AREA,
404 UNDO_MOVE_MONSTER,
405 UNDO_MOVE_TRIGGER: (MoveID: DWORD; dX, dY: Integer);
406 UNDO_RESIZE_PANEL,
407 UNDO_RESIZE_TRIGGER: (ResizeID: DWORD; dW, dH: Integer);
408 end;
410 TCopyRec = record
411 ObjectType: Byte;
412 ID: Cardinal;
413 case Byte of
414 OBJECT_PANEL: (Panel: ^TPanel);
415 OBJECT_ITEM: (Item: TItem);
416 OBJECT_AREA: (Area: TArea);
417 OBJECT_MONSTER: (Monster: TMonster);
418 OBJECT_TRIGGER: (Trigger: TTrigger);
419 end;
421 TCopyRecArray = Array of TCopyRec;
423 var
424 gEditorFont: DWORD;
425 gDataLoaded: Boolean = False;
426 ShowMap: Boolean = False;
427 DrawRect: PRect = nil;
428 SnapToGrid: Boolean = True;
430 MousePos: Types.TPoint;
431 LastMovePoint: Types.TPoint;
432 MouseLDown: Boolean;
433 MouseRDown: Boolean;
434 MouseLDownPos: Types.TPoint;
435 MouseRDownPos: Types.TPoint;
437 SelectFlag: Byte = SELECTFLAG_NONE;
438 MouseAction: Byte = MOUSEACTION_NONE;
439 ResizeType: Byte = RESIZETYPE_NONE;
440 ResizeDirection: Byte = RESIZEDIR_NONE;
442 DrawPressRect: Boolean = False;
443 EditingProperties: Boolean = False;
445 UndoBuffer: Array of Array of TUndoRec = nil;
448 {$R *.lfm}
450 //----------------------------------------
451 //Далее идут вспомогательные процедуры
452 //----------------------------------------
454 function NameToBool(Name: String): Boolean;
455 begin
456 if Name = BoolNames[True] then
457 Result := True
458 else
459 Result := False;
460 end;
462 function NameToDir(Name: String): TDirection;
463 begin
464 if Name = DirNames[D_LEFT] then
465 Result := D_LEFT
466 else
467 Result := D_RIGHT;
468 end;
470 function NameToDirAdv(Name: String): Byte;
471 begin
472 if Name = DirNamesAdv[1] then
473 Result := 1
474 else
475 if Name = DirNamesAdv[2] then
476 Result := 2
477 else
478 if Name = DirNamesAdv[3] then
479 Result := 3
480 else
481 Result := 0;
482 end;
484 function ActivateToStr(ActivateType: Byte): String;
485 begin
486 Result := '';
488 if ByteBool(ACTIVATE_PLAYERCOLLIDE and ActivateType) then
489 Result := Result + '+PC';
490 if ByteBool(ACTIVATE_MONSTERCOLLIDE and ActivateType) then
491 Result := Result + '+MC';
492 if ByteBool(ACTIVATE_PLAYERPRESS and ActivateType) then
493 Result := Result + '+PP';
494 if ByteBool(ACTIVATE_MONSTERPRESS and ActivateType) then
495 Result := Result + '+MP';
496 if ByteBool(ACTIVATE_SHOT and ActivateType) then
497 Result := Result + '+SH';
498 if ByteBool(ACTIVATE_NOMONSTER and ActivateType) then
499 Result := Result + '+NM';
501 if (Result <> '') and (Result[1] = '+') then
502 Delete(Result, 1, 1);
503 end;
505 function StrToActivate(Str: String): Byte;
506 begin
507 Result := 0;
509 if Pos('PC', Str) > 0 then
510 Result := ACTIVATE_PLAYERCOLLIDE;
511 if Pos('MC', Str) > 0 then
512 Result := Result or ACTIVATE_MONSTERCOLLIDE;
513 if Pos('PP', Str) > 0 then
514 Result := Result or ACTIVATE_PLAYERPRESS;
515 if Pos('MP', Str) > 0 then
516 Result := Result or ACTIVATE_MONSTERPRESS;
517 if Pos('SH', Str) > 0 then
518 Result := Result or ACTIVATE_SHOT;
519 if Pos('NM', Str) > 0 then
520 Result := Result or ACTIVATE_NOMONSTER;
521 end;
523 function KeyToStr(Key: Byte): String;
524 begin
525 Result := '';
527 if ByteBool(KEY_RED and Key) then
528 Result := Result + '+RK';
529 if ByteBool(KEY_GREEN and Key) then
530 Result := Result + '+GK';
531 if ByteBool(KEY_BLUE and Key) then
532 Result := Result + '+BK';
533 if ByteBool(KEY_REDTEAM and Key) then
534 Result := Result + '+RT';
535 if ByteBool(KEY_BLUETEAM and Key) then
536 Result := Result + '+BT';
538 if (Result <> '') and (Result[1] = '+') then
539 Delete(Result, 1, 1);
540 end;
542 function StrToKey(Str: String): Byte;
543 begin
544 Result := 0;
546 if Pos('RK', Str) > 0 then
547 Result := KEY_RED;
548 if Pos('GK', Str) > 0 then
549 Result := Result or KEY_GREEN;
550 if Pos('BK', Str) > 0 then
551 Result := Result or KEY_BLUE;
552 if Pos('RT', Str) > 0 then
553 Result := Result or KEY_REDTEAM;
554 if Pos('BT', Str) > 0 then
555 Result := Result or KEY_BLUETEAM;
556 end;
558 function EffectToStr(Effect: Byte): String;
559 begin
560 if Effect in [EFFECT_TELEPORT..EFFECT_FIRE] then
561 Result := EffectNames[Effect]
562 else
563 Result := EffectNames[EFFECT_NONE];
564 end;
566 function StrToEffect(Str: String): Byte;
567 var
568 i: Integer;
569 begin
570 Result := EFFECT_NONE;
571 for i := EFFECT_TELEPORT to EFFECT_FIRE do
572 if EffectNames[i] = Str then
573 begin
574 Result := i;
575 Exit;
576 end;
577 end;
579 function MonsterToStr(MonType: Byte): String;
580 begin
581 if MonType in [MONSTER_DEMON..MONSTER_MAN] then
582 Result := MonsterNames[MonType]
583 else
584 Result := MonsterNames[MONSTER_ZOMBY];
585 end;
587 function StrToMonster(Str: String): Byte;
588 var
589 i: Integer;
590 begin
591 Result := MONSTER_ZOMBY;
592 for i := MONSTER_DEMON to MONSTER_MAN do
593 if MonsterNames[i] = Str then
594 begin
595 Result := i;
596 Exit;
597 end;
598 end;
600 function ItemToStr(ItemType: Byte): String;
601 begin
602 if ItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX] then
603 Result := ItemNames[ItemType]
604 else
605 Result := ItemNames[ITEM_AMMO_BULLETS];
606 end;
608 function StrToItem(Str: String): Byte;
609 var
610 i: Integer;
611 begin
612 Result := ITEM_AMMO_BULLETS;
613 for i := ITEM_MEDKIT_SMALL to ITEM_MAX do
614 if ItemNames[i] = Str then
615 begin
616 Result := i;
617 Exit;
618 end;
619 end;
621 function ShotToStr(ShotType: Byte): String;
622 begin
623 if ShotType in [TRIGGER_SHOT_PISTOL..TRIGGER_SHOT_MAX] then
624 Result := ShotNames[ShotType]
625 else
626 Result := ShotNames[TRIGGER_SHOT_PISTOL];
627 end;
629 function StrToShot(Str: String): Byte;
630 var
631 i: Integer;
632 begin
633 Result := TRIGGER_SHOT_PISTOL;
634 for i := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
635 if ShotNames[i] = Str then
636 begin
637 Result := i;
638 Exit;
639 end;
640 end;
642 function SelectedObjectCount(): Word;
643 var
644 a: Integer;
645 begin
646 Result := 0;
648 if SelectedObjects = nil then
649 Exit;
651 for a := 0 to High(SelectedObjects) do
652 if SelectedObjects[a].Live then
653 Result := Result + 1;
654 end;
656 function GetFirstSelected(): Integer;
657 var
658 a: Integer;
659 begin
660 Result := -1;
662 if SelectedObjects = nil then
663 Exit;
665 for a := 0 to High(SelectedObjects) do
666 if SelectedObjects[a].Live then
667 begin
668 Result := a;
669 Exit;
670 end;
671 end;
673 function Normalize16(x: Integer): Integer;
674 begin
675 Result := (x div 16) * 16;
676 end;
678 procedure MoveMap(X, Y: Integer);
679 var
680 rx, ry, ScaleSz: Integer;
681 begin
682 with MainForm.RenderPanel do
683 begin
684 ScaleSz := 16 div Scale;
685 // Размер видимой части карты:
686 rx := min(Normalize16(Width), Normalize16(gMapInfo.Width)) div 2;
687 ry := min(Normalize16(Height), Normalize16(gMapInfo.Height)) div 2;
688 // Место клика на мини-карте:
689 MapOffset.X := X - (Width-max(gMapInfo.Width div ScaleSz, 1)-1);
690 MapOffset.Y := Y - 1;
691 // Это же место на "большой" карте:
692 MapOffset.X := MapOffset.X * ScaleSz;
693 MapOffset.Y := MapOffset.Y * ScaleSz;
694 // Левый верхний угол новой видимой части карты:
695 MapOffset.X := MapOffset.X - rx;
696 MapOffset.Y := MapOffset.Y - ry;
697 // Выход за границы:
698 if MapOffset.X < 0 then
699 MapOffset.X := 0;
700 if MapOffset.Y < 0 then
701 MapOffset.Y := 0;
702 if MapOffset.X > MainForm.sbHorizontal.Max then
703 MapOffset.X := MainForm.sbHorizontal.Max;
704 if MapOffset.Y > MainForm.sbVertical.Max then
705 MapOffset.Y := MainForm.sbVertical.Max;
706 // Кратно 16:
707 MapOffset.X := Normalize16(MapOffset.X);
708 MapOffset.Y := Normalize16(MapOffset.Y);
709 end;
711 MainForm.sbHorizontal.Position := MapOffset.X;
712 MainForm.sbVertical.Position := MapOffset.Y;
714 MapOffset.X := -MapOffset.X;
715 MapOffset.Y := -MapOffset.Y;
717 MainForm.Resize();
718 end;
720 function IsTexturedPanel(PanelType: Word): Boolean;
721 begin
722 Result := WordBool(PanelType and (PANEL_WALL or PANEL_BACK or PANEL_FORE or
723 PANEL_STEP or PANEL_OPENDOOR or PANEL_CLOSEDOOR or
724 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2));
725 end;
727 procedure FillProperty();
728 var
729 _id: DWORD;
730 str: String;
731 begin
732 MainForm.vleObjectProperty.Strings.Clear();
734 // Отображаем свойства если выделен только один объект:
735 if SelectedObjectCount() <> 1 then
736 Exit;
738 _id := GetFirstSelected();
739 if not SelectedObjects[_id].Live then
740 Exit;
742 with MainForm.vleObjectProperty do
743 with ItemProps[InsertRow(_lc[I_PROP_ID], IntToStr(SelectedObjects[_id].ID), True)] do
744 begin
745 EditStyle := esSimple;
746 ReadOnly := True;
747 end;
749 case SelectedObjects[0].ObjectType of
750 OBJECT_PANEL:
751 begin
752 with MainForm.vleObjectProperty,
753 gPanels[SelectedObjects[_id].ID] do
754 begin
755 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
756 begin
757 EditStyle := esSimple;
758 MaxLength := 5;
759 end;
761 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
762 begin
763 EditStyle := esSimple;
764 MaxLength := 5;
765 end;
767 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
768 begin
769 EditStyle := esSimple;
770 MaxLength := 5;
771 end;
773 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
774 begin
775 EditStyle := esSimple;
776 MaxLength := 5;
777 end;
779 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TYPE], GetPanelName(PanelType), True)] do
780 begin
781 EditStyle := esEllipsis;
782 ReadOnly := True;
783 end;
785 if IsTexturedPanel(PanelType) then
786 begin // Может быть текстура
787 with ItemProps[InsertRow(_lc[I_PROP_PANEL_TEX], TextureName, True)] do
788 begin
789 EditStyle := esEllipsis;
790 ReadOnly := True;
791 end;
793 if TextureName <> '' then
794 begin // Есть текстура
795 with ItemProps[InsertRow(_lc[I_PROP_PANEL_ALPHA], IntToStr(Alpha), True)] do
796 begin
797 EditStyle := esSimple;
798 MaxLength := 3;
799 end;
801 with ItemProps[InsertRow(_lc[I_PROP_PANEL_BLEND], BoolNames[Blending], True)] do
802 begin
803 EditStyle := esPickList;
804 ReadOnly := True;
805 end;
806 end;
807 end;
808 end;
809 end;
811 OBJECT_ITEM:
812 begin
813 with MainForm.vleObjectProperty,
814 gItems[SelectedObjects[_id].ID] do
815 begin
816 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
817 begin
818 EditStyle := esSimple;
819 MaxLength := 5;
820 end;
822 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
823 begin
824 EditStyle := esSimple;
825 MaxLength := 5;
826 end;
828 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[OnlyDM], True)] do
829 begin
830 EditStyle := esPickList;
831 ReadOnly := True;
832 end;
834 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Fall], True)] do
835 begin
836 EditStyle := esPickList;
837 ReadOnly := True;
838 end;
839 end;
840 end;
842 OBJECT_MONSTER:
843 begin
844 with MainForm.vleObjectProperty,
845 gMonsters[SelectedObjects[_id].ID] do
846 begin
847 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
848 begin
849 EditStyle := esSimple;
850 MaxLength := 5;
851 end;
853 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
854 begin
855 EditStyle := esSimple;
856 MaxLength := 5;
857 end;
859 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
860 begin
861 EditStyle := esPickList;
862 ReadOnly := True;
863 end;
864 end;
865 end;
867 OBJECT_AREA:
868 begin
869 with MainForm.vleObjectProperty,
870 gAreas[SelectedObjects[_id].ID] do
871 begin
872 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
873 begin
874 EditStyle := esSimple;
875 MaxLength := 5;
876 end;
878 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
879 begin
880 EditStyle := esSimple;
881 MaxLength := 5;
882 end;
884 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[Direction], True)] do
885 begin
886 EditStyle := esPickList;
887 ReadOnly := True;
888 end;
889 end;
890 end;
892 OBJECT_TRIGGER:
893 begin
894 with MainForm.vleObjectProperty,
895 gTriggers[SelectedObjects[_id].ID] do
896 begin
897 with ItemProps[InsertRow(_lc[I_PROP_TR_TYPE], GetTriggerName(TriggerType), True)] do
898 begin
899 EditStyle := esSimple;
900 ReadOnly := True;
901 end;
903 with ItemProps[InsertRow(_lc[I_PROP_X], IntToStr(X), True)] do
904 begin
905 EditStyle := esSimple;
906 MaxLength := 5;
907 end;
909 with ItemProps[InsertRow(_lc[I_PROP_Y], IntToStr(Y), True)] do
910 begin
911 EditStyle := esSimple;
912 MaxLength := 5;
913 end;
915 with ItemProps[InsertRow(_lc[I_PROP_WIDTH], IntToStr(Width), True)] do
916 begin
917 EditStyle := esSimple;
918 MaxLength := 5;
919 end;
921 with ItemProps[InsertRow(_lc[I_PROP_HEIGHT], IntToStr(Height), True)] do
922 begin
923 EditStyle := esSimple;
924 MaxLength := 5;
925 end;
927 with ItemProps[InsertRow(_lc[I_PROP_TR_ENABLED], BoolNames[Enabled], True)] do
928 begin
929 EditStyle := esPickList;
930 ReadOnly := True;
931 end;
933 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_PANEL], IntToStr(TexturePanel), True)] do
934 begin
935 EditStyle := esEllipsis;
936 ReadOnly := True;
937 end;
939 with ItemProps[InsertRow(_lc[I_PROP_TR_ACTIVATION], ActivateToStr(ActivateType), True)] do
940 begin
941 EditStyle := esEllipsis;
942 ReadOnly := True;
943 end;
945 with ItemProps[InsertRow(_lc[I_PROP_TR_KEYS], KeyToStr(Key), True)] do
946 begin
947 EditStyle := esEllipsis;
948 ReadOnly := True;
949 end;
951 case TriggerType of
952 TRIGGER_EXIT:
953 begin
954 with ItemProps[InsertRow(_lc[I_PROP_TR_NEXT_MAP], Data.MapName, True)] do
955 begin
956 EditStyle := esEllipsis;
957 ReadOnly := True;
958 end;
959 end;
961 TRIGGER_TELEPORT:
962 begin
963 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_TO], Format('(%d:%d)', [Data.TargetPoint.X, Data.TargetPoint.Y]), True)] do
964 begin
965 EditStyle := esEllipsis;
966 ReadOnly := True;
967 end;
969 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_teleport], True)] do
970 begin
971 EditStyle := esPickList;
972 ReadOnly := True;
973 end;
975 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_SILENT], BoolNames[Data.silent_teleport], True)] do
976 begin
977 EditStyle := esPickList;
978 ReadOnly := True;
979 end;
981 with ItemProps[InsertRow(_lc[I_PROP_TR_TELEPORT_DIR], DirNamesAdv[Data.TlpDir], True)] do
982 begin
983 EditStyle := esPickList;
984 ReadOnly := True;
985 end;
986 end;
988 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR,
989 TRIGGER_DOOR, TRIGGER_DOOR5:
990 begin
991 with ItemProps[InsertRow(_lc[I_PROP_TR_DOOR_PANEL], IntToStr(Data.PanelID), True)] do
992 begin
993 EditStyle := esEllipsis;
994 ReadOnly := True;
995 end;
997 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
998 begin
999 EditStyle := esPickList;
1000 ReadOnly := True;
1001 end;
1003 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1004 begin
1005 EditStyle := esPickList;
1006 ReadOnly := True;
1007 end;
1008 end;
1010 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1011 begin
1012 with ItemProps[InsertRow(_lc[I_PROP_TR_TRAP_PANEL], IntToStr(Data.PanelID), True)] do
1013 begin
1014 EditStyle := esEllipsis;
1015 ReadOnly := True;
1016 end;
1018 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1019 begin
1020 EditStyle := esPickList;
1021 ReadOnly := True;
1022 end;
1024 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1025 begin
1026 EditStyle := esPickList;
1027 ReadOnly := True;
1028 end;
1029 end;
1031 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
1032 TRIGGER_ONOFF:
1033 begin
1034 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_AREA],
1035 Format('(%d:%d %d:%d)', [Data.tX, Data.tY, Data.tWidth, Data.tHeight]), True)] do
1036 begin
1037 EditStyle := esEllipsis;
1038 ReadOnly := True;
1039 end;
1041 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.Wait), True)] do
1042 begin
1043 EditStyle := esSimple;
1044 MaxLength := 5;
1045 end;
1047 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_COUNT], IntToStr(Data.Count), True)] do
1048 begin
1049 EditStyle := esSimple;
1050 MaxLength := 5;
1051 end;
1053 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_MONSTER], IntToStr(Data.MonsterID-1), True)] do
1054 begin
1055 EditStyle := esEllipsis;
1056 ReadOnly := True;
1057 end;
1059 if TriggerType = TRIGGER_PRESS then
1060 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_RANDOM], BoolNames[Data.ExtRandom], True)] do
1061 begin
1062 EditStyle := esPickList;
1063 ReadOnly := True;
1064 end;
1065 end;
1067 TRIGGER_SECRET:
1070 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
1071 begin
1072 with ItemProps[InsertRow(_lc[I_PROP_TR_LIFT_PANEL], IntToStr(Data.PanelID), True)] do
1073 begin
1074 EditStyle := esEllipsis;
1075 ReadOnly := True;
1076 end;
1078 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.NoSound], True)] do
1079 begin
1080 EditStyle := esPickList;
1081 ReadOnly := True;
1082 end;
1084 with ItemProps[InsertRow(_lc[I_PROP_TR_D2D], BoolNames[Data.d2d_doors], True)] do
1085 begin
1086 EditStyle := esPickList;
1087 ReadOnly := True;
1088 end;
1089 end;
1091 TRIGGER_TEXTURE:
1092 begin
1093 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ONCE], BoolNames[Data.ActivateOnce], True)] do
1094 begin
1095 EditStyle := esPickList;
1096 ReadOnly := True;
1097 end;
1099 with ItemProps[InsertRow(_lc[I_PROP_TR_TEXTURE_ANIM_ONCE], BoolNames[Data.AnimOnce], True)] do
1100 begin
1101 EditStyle := esPickList;
1102 ReadOnly := True;
1103 end;
1104 end;
1106 TRIGGER_SOUND:
1107 begin
1108 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_NAME], Data.SoundName, True)] do
1109 begin
1110 EditStyle := esEllipsis;
1111 ReadOnly := True;
1112 end;
1114 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_VOLUME], IntToStr(Data.Volume), True)] do
1115 begin
1116 EditStyle := esSimple;
1117 MaxLength := 3;
1118 end;
1120 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_PAN], IntToStr(Data.Pan), True)] do
1121 begin
1122 EditStyle := esSimple;
1123 MaxLength := 3;
1124 end;
1126 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_COUNT], IntToStr(Data.PlayCount), True)] do
1127 begin
1128 EditStyle := esSimple;
1129 MaxLength := 3;
1130 end;
1132 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_LOCAL], BoolNames[Data.Local], True)] do
1133 begin
1134 EditStyle := esPickList;
1135 ReadOnly := True;
1136 end;
1138 with ItemProps[InsertRow(_lc[I_PROP_TR_SOUND_SWITCH], BoolNames[Data.SoundSwitch], True)] do
1139 begin
1140 EditStyle := esPickList;
1141 ReadOnly := True;
1142 end;
1143 end;
1145 TRIGGER_SPAWNMONSTER:
1146 begin
1147 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_TYPE], MonsterToStr(Data.MonType), True)] do
1148 begin
1149 EditStyle := esEllipsis;
1150 ReadOnly := True;
1151 end;
1153 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1154 Format('(%d:%d)', [Data.MonPos.X, Data.MonPos.Y]), True)] do
1155 begin
1156 EditStyle := esEllipsis;
1157 ReadOnly := True;
1158 end;
1160 with ItemProps[InsertRow(_lc[I_PROP_DIRECTION], DirNames[TDirection(Data.MonDir)], True)] do
1161 begin
1162 EditStyle := esPickList;
1163 ReadOnly := True;
1164 end;
1166 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.MonHealth), True)] do
1167 begin
1168 EditStyle := esSimple;
1169 MaxLength := 5;
1170 end;
1172 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_ACTIVE], BoolNames[Data.MonActive], True)] do
1173 begin
1174 EditStyle := esPickList;
1175 ReadOnly := True;
1176 end;
1178 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.MonCount), True)] do
1179 begin
1180 EditStyle := esSimple;
1181 MaxLength := 5;
1182 end;
1184 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.MonEffect), True)] do
1185 begin
1186 EditStyle := esEllipsis;
1187 ReadOnly := True;
1188 end;
1190 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.MonMax), True)] do
1191 begin
1192 EditStyle := esSimple;
1193 MaxLength := 5;
1194 end;
1196 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.MonDelay), True)] do
1197 begin
1198 EditStyle := esSimple;
1199 MaxLength := 5;
1200 end;
1202 case Data.MonBehav of
1203 1: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1];
1204 2: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2];
1205 3: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3];
1206 4: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4];
1207 5: str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5];
1208 else str := _lc[I_PROP_TR_MONSTER_BEHAVIOUR_0];
1209 end;
1210 with ItemProps[InsertRow(_lc[I_PROP_TR_MONSTER_BEHAVIOUR], str, True)] do
1211 begin
1212 EditStyle := esPickList;
1213 ReadOnly := True;
1214 end;
1215 end;
1217 TRIGGER_SPAWNITEM:
1218 begin
1219 with ItemProps[InsertRow(_lc[I_PROP_TR_ITEM_TYPE], ItemToStr(Data.ItemType), True)] do
1220 begin
1221 EditStyle := esEllipsis;
1222 ReadOnly := True;
1223 end;
1225 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1226 Format('(%d:%d)', [Data.ItemPos.X, Data.ItemPos.Y]), True)] do
1227 begin
1228 EditStyle := esEllipsis;
1229 ReadOnly := True;
1230 end;
1232 with ItemProps[InsertRow(_lc[I_PROP_DM_ONLY], BoolNames[Data.ItemOnlyDM], True)] do
1233 begin
1234 EditStyle := esPickList;
1235 ReadOnly := True;
1236 end;
1238 with ItemProps[InsertRow(_lc[I_PROP_ITEM_FALLS], BoolNames[Data.ItemFalls], True)] do
1239 begin
1240 EditStyle := esPickList;
1241 ReadOnly := True;
1242 end;
1244 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ItemCount), True)] do
1245 begin
1246 EditStyle := esSimple;
1247 MaxLength := 5;
1248 end;
1250 with ItemProps[InsertRow(_lc[I_PROP_TR_FX_TYPE], EffectToStr(Data.ItemEffect), True)] do
1251 begin
1252 EditStyle := esEllipsis;
1253 ReadOnly := True;
1254 end;
1256 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_MAX], IntToStr(Data.ItemMax), True)] do
1257 begin
1258 EditStyle := esSimple;
1259 MaxLength := 5;
1260 end;
1262 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_DELAY], IntToStr(Data.ItemDelay), True)] do
1263 begin
1264 EditStyle := esSimple;
1265 MaxLength := 5;
1266 end;
1267 end;
1269 TRIGGER_MUSIC:
1270 begin
1271 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_NAME], Data.MusicName, True)] do
1272 begin
1273 EditStyle := esEllipsis;
1274 ReadOnly := True;
1275 end;
1277 if Data.MusicAction = 1 then
1278 str := _lc[I_PROP_TR_MUSIC_ON]
1279 else
1280 str := _lc[I_PROP_TR_MUSIC_OFF];
1282 with ItemProps[InsertRow(_lc[I_PROP_TR_MUSIC_ACT], str, True)] do
1283 begin
1284 EditStyle := esPickList;
1285 ReadOnly := True;
1286 end;
1287 end;
1289 TRIGGER_PUSH:
1290 begin
1291 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_ANGLE], IntToStr(Data.PushAngle), True)] do
1292 begin
1293 EditStyle := esSimple;
1294 MaxLength := 4;
1295 end;
1296 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_FORCE], IntToStr(Data.PushForce), True)] do
1297 begin
1298 EditStyle := esSimple;
1299 MaxLength := 4;
1300 end;
1301 with ItemProps[InsertRow(_lc[I_PROP_TR_PUSH_RESET], BoolNames[Data.ResetVel], True)] do
1302 begin
1303 EditStyle := esPickList;
1304 ReadOnly := True;
1305 end;
1306 end;
1308 TRIGGER_SCORE:
1309 begin
1310 case Data.ScoreAction of
1311 1: str := _lc[I_PROP_TR_SCORE_ACT_1];
1312 2: str := _lc[I_PROP_TR_SCORE_ACT_2];
1313 3: str := _lc[I_PROP_TR_SCORE_ACT_3];
1314 else str := _lc[I_PROP_TR_SCORE_ACT_0];
1315 end;
1316 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_ACT], str, True)] do
1317 begin
1318 EditStyle := esPickList;
1319 ReadOnly := True;
1320 end;
1321 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.ScoreCount), True)] do
1322 begin
1323 EditStyle := esSimple;
1324 MaxLength := 3;
1325 end;
1326 case Data.ScoreTeam of
1327 1: str := _lc[I_PROP_TR_SCORE_TEAM_1];
1328 2: str := _lc[I_PROP_TR_SCORE_TEAM_2];
1329 3: str := _lc[I_PROP_TR_SCORE_TEAM_3];
1330 else str := _lc[I_PROP_TR_SCORE_TEAM_0];
1331 end;
1332 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_TEAM], str, True)] do
1333 begin
1334 EditStyle := esPickList;
1335 ReadOnly := True;
1336 end;
1337 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_CON], BoolNames[Data.ScoreCon], True)] do
1338 begin
1339 EditStyle := esPickList;
1340 ReadOnly := True;
1341 end;
1342 with ItemProps[InsertRow(_lc[I_PROP_TR_SCORE_MSG], BoolNames[Data.ScoreMsg], True)] do
1343 begin
1344 EditStyle := esPickList;
1345 ReadOnly := True;
1346 end;
1347 end;
1349 TRIGGER_MESSAGE:
1350 begin
1351 case Data.MessageKind of
1352 1: str := _lc[I_PROP_TR_MESSAGE_KIND_1];
1353 else str := _lc[I_PROP_TR_MESSAGE_KIND_0];
1354 end;
1355 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_KIND], str, True)] do
1356 begin
1357 EditStyle := esPickList;
1358 ReadOnly := True;
1359 end;
1360 case Data.MessageSendTo of
1361 1: str := _lc[I_PROP_TR_MESSAGE_TO_1];
1362 2: str := _lc[I_PROP_TR_MESSAGE_TO_2];
1363 3: str := _lc[I_PROP_TR_MESSAGE_TO_3];
1364 4: str := _lc[I_PROP_TR_MESSAGE_TO_4];
1365 5: str := _lc[I_PROP_TR_MESSAGE_TO_5];
1366 else str := _lc[I_PROP_TR_MESSAGE_TO_0];
1367 end;
1368 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TO], str, True)] do
1369 begin
1370 EditStyle := esPickList;
1371 ReadOnly := True;
1372 end;
1373 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TEXT], Data.MessageText, True)] do
1374 begin
1375 EditStyle := esSimple;
1376 MaxLength := 100;
1377 end;
1378 with ItemProps[InsertRow(_lc[I_PROP_TR_MESSAGE_TIME], IntToStr(Data.MessageTime), True)] do
1379 begin
1380 EditStyle := esSimple;
1381 MaxLength := 5;
1382 end;
1383 end;
1385 TRIGGER_DAMAGE:
1386 begin
1387 with ItemProps[InsertRow(_lc[I_PROP_TR_DAMAGE_VALUE], IntToStr(Data.DamageValue), True)] do
1388 begin
1389 EditStyle := esSimple;
1390 MaxLength := 5;
1391 end;
1392 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.DamageInterval), True)] do
1393 begin
1394 EditStyle := esSimple;
1395 MaxLength := 5;
1396 end;
1397 end;
1399 TRIGGER_HEALTH:
1400 begin
1401 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH], IntToStr(Data.HealValue), True)] do
1402 begin
1403 EditStyle := esSimple;
1404 MaxLength := 5;
1405 end;
1406 with ItemProps[InsertRow(_lc[I_PROP_TR_INTERVAL], IntToStr(Data.HealInterval), True)] do
1407 begin
1408 EditStyle := esSimple;
1409 MaxLength := 5;
1410 end;
1411 with ItemProps[InsertRow(_lc[I_PROP_TR_HEALTH_MAX], BoolNames[Data.HealMax], True)] do
1412 begin
1413 EditStyle := esPickList;
1414 ReadOnly := True;
1415 end;
1416 with ItemProps[InsertRow(_lc[I_PROP_TR_SILENT], BoolNames[Data.HealSilent], True)] do
1417 begin
1418 EditStyle := esPickList;
1419 ReadOnly := True;
1420 end;
1421 end;
1423 TRIGGER_SHOT:
1424 begin
1425 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TYPE], ShotToStr(Data.ShotType), True)] do
1426 begin
1427 EditStyle := esEllipsis;
1428 ReadOnly := True;
1429 end;
1431 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SOUND], BoolNames[Data.ShotSound], True)] do
1432 begin
1433 EditStyle := esPickList;
1434 ReadOnly := True;
1435 end;
1437 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_PANEL], IntToStr(Data.ShotPanelID), True)] do
1438 begin
1439 EditStyle := esEllipsis;
1440 ReadOnly := True;
1441 end;
1443 case Data.ShotTarget of
1444 1: str := _lc[I_PROP_TR_SHOT_TO_1];
1445 2: str := _lc[I_PROP_TR_SHOT_TO_2];
1446 3: str := _lc[I_PROP_TR_SHOT_TO_3];
1447 4: str := _lc[I_PROP_TR_SHOT_TO_4];
1448 5: str := _lc[I_PROP_TR_SHOT_TO_5];
1449 6: str := _lc[I_PROP_TR_SHOT_TO_6];
1450 else str := _lc[I_PROP_TR_SHOT_TO_0];
1451 end;
1452 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_TO], str, True)] do
1453 begin
1454 EditStyle := esPickList;
1455 ReadOnly := True;
1456 end;
1458 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_SIGHT], IntToStr(Data.ShotIntSight), True)] do
1459 begin
1460 EditStyle := esSimple;
1461 MaxLength := 3;
1462 end;
1464 case Data.ShotAim of
1465 1: str := _lc[I_PROP_TR_SHOT_AIM_1];
1466 2: str := _lc[I_PROP_TR_SHOT_AIM_2];
1467 3: str := _lc[I_PROP_TR_SHOT_AIM_3];
1468 else str := _lc[I_PROP_TR_SHOT_AIM_0];
1469 end;
1470 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AIM], str, True)-1] do
1471 begin
1472 EditStyle := esPickList;
1473 ReadOnly := True;
1474 end;
1476 with ItemProps[InsertRow(_lc[I_PROP_TR_SPAWN_TO],
1477 Format('(%d:%d)', [Data.ShotPos.X, Data.ShotPos.Y]), True)] do
1478 begin
1479 EditStyle := esEllipsis;
1480 ReadOnly := True;
1481 end;
1483 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ANGLE], IntToStr(Data.ShotAngle), True)] do
1484 begin
1485 EditStyle := esSimple;
1486 MaxLength := 4;
1487 end;
1489 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.ShotWait), True)] do
1490 begin
1491 EditStyle := esSimple;
1492 MaxLength := 5;
1493 end;
1495 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_ACC], IntToStr(Data.ShotAccuracy), True)] do
1496 begin
1497 EditStyle := esSimple;
1498 MaxLength := 5;
1499 end;
1501 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_AMMO], IntToStr(Data.ShotAmmo), True)] do
1502 begin
1503 EditStyle := esSimple;
1504 MaxLength := 5;
1505 end;
1507 with ItemProps[InsertRow(_lc[I_PROP_TR_SHOT_RELOAD], IntToStr(Data.ShotIntReload), True)] do
1508 begin
1509 EditStyle := esSimple;
1510 MaxLength := 4;
1511 end;
1512 end;
1514 TRIGGER_EFFECT:
1515 begin
1516 with ItemProps[InsertRow(_lc[I_PROP_TR_COUNT], IntToStr(Data.FXCount), True)] do
1517 begin
1518 EditStyle := esSimple;
1519 MaxLength := 3;
1520 end;
1522 if Data.FXType = 0 then
1523 str := _lc[I_PROP_TR_EFFECT_PARTICLE]
1524 else
1525 str := _lc[I_PROP_TR_EFFECT_ANIMATION];
1526 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_TYPE], str, True)] do
1527 begin
1528 EditStyle := esEllipsis;
1529 ReadOnly := True;
1530 end;
1532 str := '';
1533 if Data.FXType = 0 then
1534 case Data.FXSubType of
1535 TRIGGER_EFFECT_SLIQUID:
1536 str := _lc[I_PROP_TR_EFFECT_SLIQUID];
1537 TRIGGER_EFFECT_LLIQUID:
1538 str := _lc[I_PROP_TR_EFFECT_LLIQUID];
1539 TRIGGER_EFFECT_DLIQUID:
1540 str := _lc[I_PROP_TR_EFFECT_DLIQUID];
1541 TRIGGER_EFFECT_BLOOD:
1542 str := _lc[I_PROP_TR_EFFECT_BLOOD];
1543 TRIGGER_EFFECT_SPARK:
1544 str := _lc[I_PROP_TR_EFFECT_SPARK];
1545 TRIGGER_EFFECT_BUBBLE:
1546 str := _lc[I_PROP_TR_EFFECT_BUBBLE];
1547 end;
1548 if Data.FXType = 1 then
1549 begin
1550 if (Data.FXSubType = 0) or (Data.FXSubType > EFFECT_FIRE) then
1551 Data.FXSubType := EFFECT_TELEPORT;
1552 str := EffectToStr(Data.FXSubType);
1553 end;
1554 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SUBTYPE], str, True)] do
1555 begin
1556 EditStyle := esEllipsis;
1557 ReadOnly := True;
1558 end;
1560 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_COLOR], IntToStr(Data.FXColorR or (Data.FXColorG shl 8) or (Data.FXColorB shl 16)), True)] do
1561 begin
1562 EditStyle := esEllipsis;
1563 ReadOnly := True;
1564 end;
1566 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_CENTER], BoolNames[Data.FXPos = 0], True)] do
1567 begin
1568 EditStyle := esPickList;
1569 ReadOnly := True;
1570 end;
1572 with ItemProps[InsertRow(_lc[I_PROP_TR_EX_DELAY], IntToStr(Data.FXWait), True)] do
1573 begin
1574 EditStyle := esSimple;
1575 MaxLength := 5;
1576 end;
1578 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELX], IntToStr(Data.FXVelX), True)] do
1579 begin
1580 EditStyle := esSimple;
1581 MaxLength := 4;
1582 end;
1584 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_VELY], IntToStr(Data.FXVelY), True)] do
1585 begin
1586 EditStyle := esSimple;
1587 MaxLength := 4;
1588 end;
1590 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPL], IntToStr(Data.FXSpreadL), True)] do
1591 begin
1592 EditStyle := esSimple;
1593 MaxLength := 3;
1594 end;
1596 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPR], IntToStr(Data.FXSpreadR), True)] do
1597 begin
1598 EditStyle := esSimple;
1599 MaxLength := 3;
1600 end;
1602 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPU], IntToStr(Data.FXSpreadU), True)] do
1603 begin
1604 EditStyle := esSimple;
1605 MaxLength := 3;
1606 end;
1608 with ItemProps[InsertRow(_lc[I_PROP_TR_EFFECT_SPD], IntToStr(Data.FXSpreadD), True)] do
1609 begin
1610 EditStyle := esSimple;
1611 MaxLength := 3;
1612 end;
1613 end;
1614 end; //case TriggerType
1615 end;
1616 end; // OBJECT_TRIGGER:
1617 end;
1618 end;
1620 procedure ChangeShownProperty(Name: String; NewValue: String);
1621 var
1622 row: Integer;
1623 begin
1624 if SelectedObjectCount() <> 1 then
1625 Exit;
1626 if not SelectedObjects[GetFirstSelected()].Live then
1627 Exit;
1629 // Есть ли такой ключ:
1630 if MainForm.vleObjectProperty.FindRow(Name, row) then
1631 begin
1632 MainForm.vleObjectProperty.Values[Name] := NewValue;
1633 end;
1634 end;
1636 procedure SelectObject(fObjectType: Byte; fID: DWORD; Multi: Boolean);
1637 var
1638 a: Integer;
1639 b: Boolean;
1640 begin
1641 if Multi then
1642 begin
1643 b := False;
1645 // Уже выделен - убираем:
1646 if SelectedObjects <> nil then
1647 for a := 0 to High(SelectedObjects) do
1648 with SelectedObjects[a] do
1649 if Live and (ID = fID) and
1650 (ObjectType = fObjectType) then
1651 begin
1652 Live := False;
1653 b := True;
1654 end;
1656 if b then
1657 Exit;
1659 SetLength(SelectedObjects, Length(SelectedObjects)+1);
1661 with SelectedObjects[High(SelectedObjects)] do
1662 begin
1663 ObjectType := fObjectType;
1664 ID := fID;
1665 Live := True;
1666 end;
1667 end
1668 else // not Multi
1669 begin
1670 SetLength(SelectedObjects, 1);
1672 with SelectedObjects[0] do
1673 begin
1674 ObjectType := fObjectType;
1675 ID := fID;
1676 Live := True;
1677 end;
1678 end;
1680 MainForm.miCopy.Enabled := True;
1681 MainForm.miCut.Enabled := True;
1683 if fObjectType = OBJECT_PANEL then
1684 begin
1685 MainForm.miToFore.Enabled := True;
1686 MainForm.miToBack.Enabled := True;
1687 end;
1688 end;
1690 procedure RemoveSelectFromObjects();
1691 begin
1692 SelectedObjects := nil;
1693 DrawPressRect := False;
1694 MouseLDown := False;
1695 MouseRDown := False;
1696 MouseAction := MOUSEACTION_NONE;
1697 SelectFlag := SELECTFLAG_NONE;
1698 ResizeType := RESIZETYPE_NONE;
1699 ResizeDirection := RESIZEDIR_NONE;
1701 MainForm.vleObjectProperty.Strings.Clear();
1703 MainForm.miCopy.Enabled := False;
1704 MainForm.miCut.Enabled := False;
1705 MainForm.miToFore.Enabled := False;
1706 MainForm.miToBack.Enabled := False;
1707 end;
1709 procedure DeleteSelectedObjects();
1710 var
1711 i, a, ii: Integer;
1712 b: Boolean;
1713 begin
1714 if SelectedObjects = nil then
1715 Exit;
1717 b := False;
1718 i := 0;
1720 for a := 0 to High(SelectedObjects) do
1721 with SelectedObjects[a] do
1722 if Live then
1723 begin
1724 if not b then
1725 begin
1726 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1727 i := High(UndoBuffer);
1728 b := True;
1729 end;
1731 SetLength(UndoBuffer[i], Length(UndoBuffer[i])+1);
1732 ii := High(UndoBuffer[i]);
1734 case ObjectType of
1735 OBJECT_PANEL:
1736 begin
1737 UndoBuffer[i, ii].UndoType := UNDO_DELETE_PANEL;
1738 New(UndoBuffer[i, ii].Panel);
1739 UndoBuffer[i, ii].Panel^ := gPanels[ID];
1740 end;
1741 OBJECT_ITEM:
1742 begin
1743 UndoBuffer[i, ii].UndoType := UNDO_DELETE_ITEM;
1744 UndoBuffer[i, ii].Item := gItems[ID];
1745 end;
1746 OBJECT_AREA:
1747 begin
1748 UndoBuffer[i, ii].UndoType := UNDO_DELETE_AREA;
1749 UndoBuffer[i, ii].Area := gAreas[ID];
1750 end;
1751 OBJECT_TRIGGER:
1752 begin
1753 UndoBuffer[i, ii].UndoType := UNDO_DELETE_TRIGGER;
1754 UndoBuffer[i, ii].Trigger := gTriggers[ID];
1755 end;
1756 end;
1758 RemoveObject(ID, ObjectType);
1759 end;
1761 RemoveSelectFromObjects();
1763 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1764 end;
1766 procedure Undo_Add(ObjectType: Byte; ID: DWORD; Group: Boolean = False);
1767 var
1768 i, ii: Integer;
1769 begin
1770 if (not Group) or (Length(UndoBuffer) = 0) then
1771 SetLength(UndoBuffer, Length(UndoBuffer)+1);
1772 SetLength(UndoBuffer[High(UndoBuffer)], Length(UndoBuffer[High(UndoBuffer)])+1);
1773 i := High(UndoBuffer);
1774 ii := High(UndoBuffer[i]);
1776 case ObjectType of
1777 OBJECT_PANEL:
1778 UndoBuffer[i, ii].UndoType := UNDO_ADD_PANEL;
1779 OBJECT_ITEM:
1780 UndoBuffer[i, ii].UndoType := UNDO_ADD_ITEM;
1781 OBJECT_MONSTER:
1782 UndoBuffer[i, ii].UndoType := UNDO_ADD_MONSTER;
1783 OBJECT_AREA:
1784 UndoBuffer[i, ii].UndoType := UNDO_ADD_AREA;
1785 OBJECT_TRIGGER:
1786 UndoBuffer[i, ii].UndoType := UNDO_ADD_TRIGGER;
1787 end;
1789 UndoBuffer[i, ii].AddID := ID;
1791 MainForm.miUndo.Enabled := UndoBuffer <> nil;
1792 end;
1794 procedure FullClear();
1795 begin
1796 RemoveSelectFromObjects();
1797 ClearMap();
1798 LoadSky(gMapInfo.SkyName);
1799 UndoBuffer := nil;
1800 slInvalidTextures.Clear();
1801 MapCheckForm.lbErrorList.Clear();
1802 MapCheckForm.mErrorDescription.Clear();
1804 MainForm.miUndo.Enabled := False;
1805 MainForm.sbHorizontal.Position := 0;
1806 MainForm.sbVertical.Position := 0;
1807 MainForm.FormResize(nil);
1808 MainForm.Caption := FormCaption;
1809 OpenedMap := '';
1810 OpenedWAD := '';
1811 end;
1813 procedure ErrorMessageBox(str: String);
1814 begin
1815 MessageBox(0, PChar(str), PChar(_lc[I_MSG_ERROR]),
1816 MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
1817 end;
1819 function CheckProperty(): Boolean;
1820 var
1821 _id: Integer;
1822 begin
1823 Result := False;
1825 _id := GetFirstSelected();
1827 if SelectedObjects[_id].ObjectType = OBJECT_PANEL then
1828 with gPanels[SelectedObjects[_id].ID] do
1829 begin
1830 if TextureWidth <> 0 then
1831 if StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 1) mod TextureWidth <> 0 then
1832 begin
1833 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
1834 [TextureWidth]));
1835 Exit;
1836 end;
1838 if TextureHeight <> 0 then
1839 if StrToIntDef(Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]), 1) mod TextureHeight <> 0 then
1840 begin
1841 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
1842 [TextureHeight]));
1843 Exit;
1844 end;
1846 if IsTexturedPanel(PanelType) and (TextureName <> '') then
1847 if not (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]], -1) in [0..255]) then
1848 begin
1849 ErrorMessageBox(_lc[I_MSG_WRONG_ALPHA]);
1850 Exit;
1851 end;
1852 end;
1854 if SelectedObjects[_id].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
1855 if (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_WIDTH]], 0) <= 0) or
1856 (StrToIntDef(MainForm.vleObjectProperty.Values[_lc[I_PROP_HEIGHT]], 0) <= 0) then
1857 begin
1858 ErrorMessageBox(_lc[I_MSG_WRONG_SIZE]);
1859 Exit;
1860 end;
1862 if (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_X]]) = '') or
1863 (Trim(MainForm.vleObjectProperty.Values[_lc[I_PROP_Y]]) = '') then
1864 begin
1865 ErrorMessageBox(_lc[I_MSG_WRONG_XY]);
1866 Exit;
1867 end;
1869 Result := True;
1870 end;
1872 procedure SelectTexture(ID: Integer);
1873 begin
1874 MainForm.lbTextureList.ItemIndex := ID;
1875 MainForm.lbTextureListClick(nil);
1876 end;
1878 function AddTexture(aWAD, aSection, aTex: String; silent: Boolean): Boolean;
1879 var
1880 a, FrameLen: Integer;
1881 ok: Boolean;
1882 FileName: String;
1883 ResourceName: String;
1884 UResourceName: String;
1885 FullResourceName: String;
1886 SectionName: String;
1887 Data: Pointer;
1888 Width, Height: Word;
1889 fn: String;
1890 begin
1891 if aSection = '..' then
1892 SectionName := ''
1893 else
1894 SectionName := aSection;
1896 if aWAD = _lc[I_WAD_SPECIAL_MAP] then
1897 begin // Файл карты
1898 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
1899 //FileName := EditorDir+'maps\'+ExtractFileName(fn);
1900 FileName := fn;
1901 ResourceName := ':'+SectionName+'\'+aTex;
1902 end
1903 else
1904 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1905 begin // Спец. текстуры
1906 FileName := '';
1907 ResourceName := aTex;
1908 end
1909 else
1910 begin // Внешний WAD
1911 FileName := EditorDir+'wads/'+aWAD;
1912 ResourceName := aWAD+':'+SectionName+'\'+aTex;
1913 end;
1915 ok := True;
1916 UResourceName := win2utf(ResourceName);
1918 // Есть ли уже такая текстура:
1919 for a := 0 to MainForm.lbTextureList.Items.Count-1 do
1920 if UResourceName = MainForm.lbTextureList.Items[a] then
1921 begin
1922 if not silent then
1923 ErrorMessageBox(Format(_lc[I_MSG_TEXTURE_ALREADY],
1924 [UResourceName]));
1925 ok := False;
1926 end;
1928 // Название ресурса <= 64 символов:
1929 if Length(ResourceName) > 64 then
1930 begin
1931 if not silent then
1932 ErrorMessageBox(Format(_lc[I_MSG_RES_NAME_64],
1933 [UResourceName]));
1934 ok := False;
1935 end;
1937 if ok then
1938 begin
1939 a := -1;
1940 if aWAD = _lc[I_WAD_SPECIAL_TEXS] then
1941 begin
1942 a := MainForm.lbTextureList.Items.Add(UResourceName);
1943 if not silent then
1944 SelectTexture(a);
1945 Result := True;
1946 Exit;
1947 end;
1949 FullResourceName := FileName+':'+SectionName+'\'+aTex;
1951 if IsAnim(FullResourceName) then
1952 begin // Аним. текстура
1953 GetFrame(FullResourceName, Data, FrameLen, Width, Height);
1955 if g_CreateTextureMemorySize(Data, FrameLen, ResourceName, 0, 0, Width, Height, 1) then
1956 a := MainForm.lbTextureList.Items.Add(UResourceName);
1957 end
1958 else // Обычная текстура
1959 begin
1960 if g_CreateTextureWAD(ResourceName, FullResourceName) then
1961 a := MainForm.lbTextureList.Items.Add(UResourceName);
1962 end;
1963 if (a > -1) and (not silent) then
1964 SelectTexture(a);
1965 end;
1967 Result := ok;
1968 end;
1970 procedure UpdateCaption(sMap, sFile, sRes: String);
1971 begin
1972 with MainForm do
1973 if (sFile = '') and (sRes = '') and (sMap = '') then
1974 Caption := FormCaption
1975 else
1976 if sMap = '' then
1977 Caption := Format('%s - %s:%s', [FormCaption, sFile, sRes])
1978 else
1979 if (sFile <> '') and (sRes <> '') then
1980 Caption := Format('%s - %s (%s:%s)', [FormCaption, sMap, sFile, sRes])
1981 else
1982 Caption := Format('%s - %s', [FormCaption, sMap]);
1983 end;
1985 procedure OpenMap(FileName: String; mapN: String);
1986 var
1987 MapName: String;
1988 idx: Integer;
1989 begin
1990 SelectMapForm.GetMaps(FileName);
1992 if (FileName = OpenedWAD) and
1993 (OpenedMap <> '') then
1994 begin
1995 MapName := OpenedMap;
1996 while (Pos(':\', MapName) > 0) do
1997 Delete(MapName, 1, Pos(':\', MapName) + 1);
1999 idx := SelectMapForm.lbMapList.Items.IndexOf(MapName);
2000 SelectMapForm.lbMapList.ItemIndex := idx;
2001 end
2002 else
2003 if SelectMapForm.lbMapList.Count > 0 then
2004 SelectMapForm.lbMapList.ItemIndex := 0
2005 else
2006 SelectMapForm.lbMapList.ItemIndex := -1;
2008 if mapN = '' then
2009 idx := -1
2010 else
2011 idx := SelectMapForm.lbMapList.Items.IndexOf(mapN);
2013 if idx < 0 then
2014 begin
2015 if (SelectMapForm.ShowModal() = mrOK) and
2016 (SelectMapForm.lbMapList.ItemIndex <> -1) then
2017 idx := SelectMapForm.lbMapList.ItemIndex
2018 else
2019 Exit;
2020 end;
2022 MapName := SelectMapForm.lbMapList.Items[idx];
2024 with MainForm do
2025 begin
2026 FullClear();
2028 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
2029 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
2030 pLoadProgress.Show();
2032 OpenedMap := FileName+':\'+MapName;
2033 OpenedWAD := FileName;
2035 idx := RecentFiles.IndexOf(OpenedMap);
2036 // Такая карта уже недавно открывалась:
2037 if idx >= 0 then
2038 RecentFiles.Delete(idx);
2039 RecentFiles.Insert(0, OpenedMap);
2040 RefreshRecentMenu();
2042 LoadMap(OpenedMap);
2044 pLoadProgress.Hide();
2045 FormResize(nil);
2047 lbTextureList.Sorted := True;
2048 lbTextureList.Sorted := False;
2050 UpdateCaption(gMapInfo.Name, ExtractFileName(FileName), MapName);
2051 end;
2052 end;
2054 procedure MoveSelectedObjects(Wall, alt: Boolean; dx, dy: Integer);
2055 var
2056 okX, okY: Boolean;
2057 a: Integer;
2058 begin
2059 if SelectedObjects = nil then
2060 Exit;
2062 okX := True;
2063 okY := True;
2065 if Wall then
2066 for a := 0 to High(SelectedObjects) do
2067 if SelectedObjects[a].Live then
2068 begin
2069 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, dx, 0) then
2070 okX := False;
2072 if ObjectCollideLevel(SelectedObjects[a].ID, SelectedObjects[a].ObjectType, 0, dy) then
2073 okY := False;
2075 if (not okX) or (not okY) then
2076 Break;
2077 end;
2079 if okX or okY then
2080 begin
2081 for a := 0 to High(SelectedObjects) do
2082 if SelectedObjects[a].Live then
2083 begin
2084 if okX then
2085 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, dx, 0);
2087 if okY then
2088 MoveObject(SelectedObjects[a].ObjectType, SelectedObjects[a].ID, 0, dy);
2090 if alt and (SelectedObjects[a].ObjectType = OBJECT_TRIGGER) then
2091 begin
2092 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_PRESS,
2093 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
2094 begin // Двигаем зону Расширителя
2095 if okX then
2096 gTriggers[SelectedObjects[a].ID].Data.tX := gTriggers[SelectedObjects[a].ID].Data.tX+dx;
2097 if okY then
2098 gTriggers[SelectedObjects[a].ID].Data.tY := gTriggers[SelectedObjects[a].ID].Data.tY+dy;
2099 end;
2101 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_TELEPORT] then
2102 begin // Двигаем точку назначения Телепорта
2103 if okX then
2104 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.X+dx;
2105 if okY then
2106 gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y := gTriggers[SelectedObjects[a].ID].Data.TargetPoint.Y+dy;
2107 end;
2109 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNMONSTER] then
2110 begin // Двигаем точку создания монстра
2111 if okX then
2112 gTriggers[SelectedObjects[a].ID].Data.MonPos.X := gTriggers[SelectedObjects[a].ID].Data.MonPos.X+dx;
2113 if okY then
2114 gTriggers[SelectedObjects[a].ID].Data.MonPos.Y := gTriggers[SelectedObjects[a].ID].Data.MonPos.Y+dy;
2115 end;
2117 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SPAWNITEM] then
2118 begin // Двигаем точку создания предмета
2119 if okX then
2120 gTriggers[SelectedObjects[a].ID].Data.ItemPos.X := gTriggers[SelectedObjects[a].ID].Data.ItemPos.X+dx;
2121 if okY then
2122 gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y := gTriggers[SelectedObjects[a].ID].Data.ItemPos.Y+dy;
2123 end;
2125 if gTriggers[SelectedObjects[a].ID].TriggerType in [TRIGGER_SHOT] then
2126 begin // Двигаем точку создания выстрела
2127 if okX then
2128 gTriggers[SelectedObjects[a].ID].Data.ShotPos.X := gTriggers[SelectedObjects[a].ID].Data.ShotPos.X+dx;
2129 if okY then
2130 gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y := gTriggers[SelectedObjects[a].ID].Data.ShotPos.Y+dy;
2131 end;
2132 end;
2133 end;
2135 LastMovePoint := MousePos;
2136 end;
2137 end;
2139 procedure ShowLayer(Layer: Byte; show: Boolean);
2140 begin
2141 LayerEnabled[Layer] := show;
2143 case Layer of
2144 LAYER_BACK:
2145 begin
2146 MainForm.miLayer1.Checked := show;
2147 MainForm.miLayerP1.Checked := show;
2148 end;
2149 LAYER_WALLS:
2150 begin
2151 MainForm.miLayer2.Checked := show;
2152 MainForm.miLayerP2.Checked := show;
2153 end;
2154 LAYER_FOREGROUND:
2155 begin
2156 MainForm.miLayer3.Checked := show;
2157 MainForm.miLayerP3.Checked := show;
2158 end;
2159 LAYER_STEPS:
2160 begin
2161 MainForm.miLayer4.Checked := show;
2162 MainForm.miLayerP4.Checked := show;
2163 end;
2164 LAYER_WATER:
2165 begin
2166 MainForm.miLayer5.Checked := show;
2167 MainForm.miLayerP5.Checked := show;
2168 end;
2169 LAYER_ITEMS:
2170 begin
2171 MainForm.miLayer6.Checked := show;
2172 MainForm.miLayerP6.Checked := show;
2173 end;
2174 LAYER_MONSTERS:
2175 begin
2176 MainForm.miLayer7.Checked := show;
2177 MainForm.miLayerP7.Checked := show;
2178 end;
2179 LAYER_AREAS:
2180 begin
2181 MainForm.miLayer8.Checked := show;
2182 MainForm.miLayerP8.Checked := show;
2183 end;
2184 LAYER_TRIGGERS:
2185 begin
2186 MainForm.miLayer9.Checked := show;
2187 MainForm.miLayerP9.Checked := show;
2188 end;
2189 end;
2191 RemoveSelectFromObjects();
2192 end;
2194 procedure SwitchLayer(Layer: Byte);
2195 begin
2196 ShowLayer(Layer, not LayerEnabled[Layer]);
2197 end;
2199 procedure SwitchMap();
2200 begin
2201 ShowMap := not ShowMap;
2202 MainForm.tbShowMap.Down := ShowMap;
2203 end;
2205 procedure ShowEdges();
2206 begin
2207 if drEdge[3] < 255 then
2208 drEdge[3] := 255
2209 else
2210 drEdge[3] := gAlphaEdge;
2211 end;
2213 function SelectedTexture(): String;
2214 begin
2215 if MainForm.lbTextureList.ItemIndex <> -1 then
2216 Result := utf2win(MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex])
2217 else
2218 Result := '';
2219 end;
2221 function IsSpecialTextureSel(): Boolean;
2222 begin
2223 Result := (MainForm.lbTextureList.ItemIndex <> -1) and
2224 IsSpecialTexture(utf2win(MainForm.lbTextureList.Items[MainForm.lbTextureList.ItemIndex]));
2225 end;
2227 function CopyBufferToString(var CopyBuf: TCopyRecArray): String;
2228 var
2229 i, j: Integer;
2230 Res: String;
2232 procedure AddInt(x: Integer);
2233 begin
2234 Res := Res + IntToStr(x) + ' ';
2235 end;
2237 begin
2238 Result := '';
2240 if Length(CopyBuf) = 0 then
2241 Exit;
2243 Res := CLIPBOARD_SIG + ' ';
2245 for i := 0 to High(CopyBuf) do
2246 begin
2247 if (CopyBuf[i].ObjectType = OBJECT_PANEL) and
2248 (CopyBuf[i].Panel = nil) then
2249 Continue;
2251 // Тип объекта:
2252 AddInt(CopyBuf[i].ObjectType);
2253 Res := Res + '; ';
2255 // Свойства объекта:
2256 case CopyBuf[i].ObjectType of
2257 OBJECT_PANEL:
2258 with CopyBuf[i].Panel^ do
2259 begin
2260 AddInt(PanelType);
2261 AddInt(X);
2262 AddInt(Y);
2263 AddInt(Width);
2264 AddInt(Height);
2265 Res := Res + '"' + TextureName + '" ';
2266 AddInt(Alpha);
2267 AddInt(IfThen(Blending, 1, 0));
2268 end;
2270 OBJECT_ITEM:
2271 with CopyBuf[i].Item do
2272 begin
2273 AddInt(ItemType);
2274 AddInt(X);
2275 AddInt(Y);
2276 AddInt(IfThen(OnlyDM, 1, 0));
2277 AddInt(IfThen(Fall, 1, 0));
2278 end;
2280 OBJECT_MONSTER:
2281 with CopyBuf[i].Monster do
2282 begin
2283 AddInt(MonsterType);
2284 AddInt(X);
2285 AddInt(Y);
2286 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2287 end;
2289 OBJECT_AREA:
2290 with CopyBuf[i].Area do
2291 begin
2292 AddInt(AreaType);
2293 AddInt(X);
2294 AddInt(Y);
2295 AddInt(IfThen(Direction = D_LEFT, 1, 0));
2296 end;
2298 OBJECT_TRIGGER:
2299 with CopyBuf[i].Trigger do
2300 begin
2301 AddInt(TriggerType);
2302 AddInt(X);
2303 AddInt(Y);
2304 AddInt(Width);
2305 AddInt(Height);
2306 AddInt(ActivateType);
2307 AddInt(Key);
2308 AddInt(IfThen(Enabled, 1, 0));
2309 AddInt(TexturePanel);
2311 for j := 0 to 127 do
2312 AddInt(Data.Default[j]);
2313 end;
2314 end;
2315 end;
2317 Result := Res;
2318 end;
2320 procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray);
2321 var
2322 i, j, t: Integer;
2324 function GetNext(): String;
2325 var
2326 p: Integer;
2328 begin
2329 if Str[1] = '"' then
2330 begin
2331 Delete(Str, 1, 1);
2332 p := Pos('"', Str);
2334 if p = 0 then
2335 begin
2336 Result := Str;
2337 Str := '';
2338 end
2339 else
2340 begin
2341 Result := Copy(Str, 1, p-1);
2342 Delete(Str, 1, p);
2343 Str := Trim(Str);
2344 end;
2345 end
2346 else
2347 begin
2348 p := Pos(' ', Str);
2350 if p = 0 then
2351 begin
2352 Result := Str;
2353 Str := '';
2354 end
2355 else
2356 begin
2357 Result := Copy(Str, 1, p-1);
2358 Delete(Str, 1, p);
2359 Str := Trim(Str);
2360 end;
2361 end;
2362 end;
2364 begin
2365 Str := Trim(Str);
2367 if GetNext() <> CLIPBOARD_SIG then
2368 Exit;
2370 while Str <> '' do
2371 begin
2372 // Тип объекта:
2373 t := StrToIntDef(GetNext(), 0);
2375 if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or
2376 (GetNext() <> ';') then
2377 begin // Что-то не то => пропускаем:
2378 t := Pos(';', Str);
2379 Delete(Str, 1, t);
2380 Str := Trim(Str);
2382 Continue;
2383 end;
2385 i := Length(CopyBuf);
2386 SetLength(CopyBuf, i + 1);
2388 CopyBuf[i].ObjectType := t;
2389 CopyBuf[i].Panel := nil;
2391 // Свойства объекта:
2392 case t of
2393 OBJECT_PANEL:
2394 begin
2395 New(CopyBuf[i].Panel);
2397 with CopyBuf[i].Panel^ do
2398 begin
2399 PanelType := StrToIntDef(GetNext(), PANEL_WALL);
2400 X := StrToIntDef(GetNext(), 0);
2401 Y := StrToIntDef(GetNext(), 0);
2402 Width := StrToIntDef(GetNext(), 16);
2403 Height := StrToIntDef(GetNext(), 16);
2404 TextureName := GetNext();
2405 Alpha := StrToIntDef(GetNext(), 0);
2406 Blending := (GetNext() = '1');
2407 end;
2408 end;
2410 OBJECT_ITEM:
2411 with CopyBuf[i].Item do
2412 begin
2413 ItemType := StrToIntDef(GetNext(), ITEM_MEDKIT_SMALL);
2414 X := StrToIntDef(GetNext(), 0);
2415 Y := StrToIntDef(GetNext(), 0);
2416 OnlyDM := (GetNext() = '1');
2417 Fall := (GetNext() = '1');
2418 end;
2420 OBJECT_MONSTER:
2421 with CopyBuf[i].Monster do
2422 begin
2423 MonsterType := StrToIntDef(GetNext(), MONSTER_DEMON);
2424 X := StrToIntDef(GetNext(), 0);
2425 Y := StrToIntDef(GetNext(), 0);
2427 if GetNext() = '1' then
2428 Direction := D_LEFT
2429 else
2430 Direction := D_RIGHT;
2431 end;
2433 OBJECT_AREA:
2434 with CopyBuf[i].Area do
2435 begin
2436 AreaType := StrToIntDef(GetNext(), AREA_PLAYERPOINT1);
2437 X := StrToIntDef(GetNext(), 0);
2438 Y := StrToIntDef(GetNext(), 0);
2439 if GetNext() = '1' then
2440 Direction := D_LEFT
2441 else
2442 Direction := D_RIGHT;
2443 end;
2445 OBJECT_TRIGGER:
2446 with CopyBuf[i].Trigger do
2447 begin
2448 TriggerType := StrToIntDef(GetNext(), TRIGGER_EXIT);
2449 X := StrToIntDef(GetNext(), 0);
2450 Y := StrToIntDef(GetNext(), 0);
2451 Width := StrToIntDef(GetNext(), 16);
2452 Height := StrToIntDef(GetNext(), 16);
2453 ActivateType := StrToIntDef(GetNext(), 0);
2454 Key := StrToIntDef(GetNext(), 0);
2455 Enabled := (GetNext() = '1');
2456 TexturePanel := StrToIntDef(GetNext(), 0);
2458 for j := 0 to 127 do
2459 Data.Default[j] := StrToIntDef(GetNext(), 0);
2460 end;
2461 end;
2462 end;
2463 end;
2465 //----------------------------------------
2466 //Закончились вспомогательные процедуры
2467 //----------------------------------------
2469 procedure TMainForm.RefreshRecentMenu();
2470 var
2471 i: Integer;
2472 MI: TMenuItem;
2473 begin
2474 // Лишние запомненные карты:
2475 while RecentFiles.Count > RecentCount do
2476 RecentFiles.Delete(RecentFiles.Count-1);
2478 // Лишние строки меню:
2479 while MainMenu.Items[0].Count > RECENT_FILES_MENU_START do
2480 MainMenu.Items[0].Delete(MainMenu.Items[0].Count-1);
2482 // Отделение списка карт от строки "Выход":
2483 if RecentFiles.Count > 0 then
2484 begin
2485 MI := TMenuItem.Create(MainMenu.Items[0]);
2486 MI.Caption := '-';
2487 MainMenu.Items[0].Add(MI);
2488 end;
2490 // Добавление в меню списка запомненных карт:
2491 for i := 0 to RecentFiles.Count-1 do
2492 begin
2493 MI := TMenuItem.Create(MainMenu.Items[0]);
2494 MI.Caption := IntToStr(i+1) + ' ' + RecentFiles[i];
2495 MI.OnClick := aRecentFileExecute;
2496 MainMenu.Items[0].Add(MI);
2497 end;
2498 end;
2500 procedure TMainForm.aRecentFileExecute(Sender: TObject);
2501 var
2502 n, pw: Integer;
2503 s, fn: String;
2504 begin
2505 s := LowerCase((Sender as TMenuItem).Caption);
2506 Delete(s, Pos('&', s), 1);
2507 s := Trim(Copy(s, 1, 2));
2508 n := StrToIntDef(s, 0) - 1;
2510 if (n < 0) or (n >= RecentFiles.Count) then
2511 Exit;
2513 s := RecentFiles[n];
2514 pw := Pos('.wad:\', LowerCase(s));
2516 if pw > 0 then
2517 begin // Map name included
2518 fn := Copy(s, 1, pw + 3);
2519 Delete(s, 1, pw + 5);
2520 if (FileExists(fn)) then
2521 OpenMap(fn, s);
2522 end
2523 else // Only wad name
2524 if (FileExists(s)) then
2525 OpenMap(s, '');
2526 end;
2528 procedure TMainForm.aEditorOptionsExecute(Sender: TObject);
2529 begin
2530 OptionsForm.ShowModal();
2531 end;
2533 procedure LoadStdFont(cfgres, texture: string; var FontID: DWORD);
2534 var
2535 cwdt, chgt: Byte;
2536 spc: ShortInt;
2537 ID: DWORD;
2538 wad: TWADEditor_1;
2539 cfgdata: Pointer;
2540 cfglen: Integer;
2541 config: TConfig;
2542 begin
2543 cfglen := 0;
2545 wad := TWADEditor_1.Create;
2546 if wad.ReadFile(EditorDir+'data/Game.wad') then
2547 wad.GetResource('FONTS', cfgres, cfgdata, cfglen);
2548 wad.Free();
2550 if cfglen <> 0 then
2551 begin
2552 if not g_CreateTextureWAD('FONT_STD', EditorDir+'data/Game.wad:FONTS\'+texture) then
2553 e_WriteLog('ERROR ERROR ERROR', MSG_WARNING);
2555 config := TConfig.CreateMem(cfgdata, cfglen);
2556 cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
2557 chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
2558 spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
2560 if g_GetTexture('FONT_STD', ID) then
2561 e_TextureFontBuild(ID, FontID, cwdt, chgt, spc-2);
2563 config.Free();
2564 end
2565 else
2566 e_WriteLog('Could not load FONT_STD', MSG_WARNING);
2568 if cfglen <> 0 then FreeMem(cfgdata);
2569 end;
2571 procedure TMainForm.FormCreate(Sender: TObject);
2572 var
2573 config: TConfig;
2574 i: Integer;
2575 s: String;
2576 begin
2577 Randomize();
2579 EditorDir := ExtractFilePath(Application.ExeName);
2581 e_InitLog(EditorDir+'Editor.log', WM_NEWFILE);
2583 slInvalidTextures := TStringList.Create;
2585 ShowLayer(LAYER_BACK, True);
2586 ShowLayer(LAYER_WALLS, True);
2587 ShowLayer(LAYER_FOREGROUND, True);
2588 ShowLayer(LAYER_STEPS, True);
2589 ShowLayer(LAYER_WATER, True);
2590 ShowLayer(LAYER_ITEMS, True);
2591 ShowLayer(LAYER_MONSTERS, True);
2592 ShowLayer(LAYER_AREAS, True);
2593 ShowLayer(LAYER_TRIGGERS, True);
2595 ClearMap();
2597 FormCaption := MainForm.Caption;
2598 OpenedMap := '';
2599 OpenedWAD := '';
2601 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
2603 if config.ReadInt('Editor', 'XPos', -1) = -1 then
2604 Position := poDesktopCenter
2605 else begin
2606 Left := config.ReadInt('Editor', 'XPos', Left);
2607 Top := config.ReadInt('Editor', 'YPos', Top);
2608 Width := config.ReadInt('Editor', 'Width', Width);
2609 Height := config.ReadInt('Editor', 'Height', Height);
2610 end;
2611 if config.ReadBool('Editor', 'Maximize', False) then
2612 WindowState := wsMaximized;
2613 ShowMap := config.ReadBool('Editor', 'Minimap', False);
2614 PanelProps.Width := config.ReadInt('Editor', 'PanelProps', PanelProps.ClientWidth);
2615 Splitter1.Left := PanelProps.Left;
2616 PanelObjs.Height := config.ReadInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
2617 Splitter2.Top := PanelObjs.Top;
2618 StatusBar.Top := PanelObjs.BoundsRect.Bottom;
2619 DotEnable := config.ReadBool('Editor', 'DotEnable', True);
2620 DotColor := config.ReadInt('Editor', 'DotColor', $FFFFFF);
2621 DotStepOne := config.ReadInt('Editor', 'DotStepOne', 16);
2622 DotStepTwo := config.ReadInt('Editor', 'DotStepTwo', 8);
2623 DotStep := config.ReadInt('Editor', 'DotStep', DotStepOne);
2624 DrawTexturePanel := config.ReadBool('Editor', 'DrawTexturePanel', True);
2625 DrawPanelSize := config.ReadBool('Editor', 'DrawPanelSize', True);
2626 BackColor := config.ReadInt('Editor', 'BackColor', $7F6040);
2627 PreviewColor := config.ReadInt('Editor', 'PreviewColor', $00FF00);
2628 gColorEdge := config.ReadInt('Editor', 'EdgeColor', COLOR_EDGE);
2629 gAlphaEdge := config.ReadInt('Editor', 'EdgeAlpha', ALPHA_EDGE);
2630 if gAlphaEdge = 255 then
2631 gAlphaEdge := ALPHA_EDGE;
2632 drEdge[0] := GetRValue(gColorEdge);
2633 drEdge[1] := GetGValue(gColorEdge);
2634 drEdge[2] := GetBValue(gColorEdge);
2635 if not config.ReadBool('Editor', 'EdgeShow', True) then
2636 drEdge[3] := 255
2637 else
2638 drEdge[3] := gAlphaEdge;
2639 gAlphaTriggerLine := config.ReadInt('Editor', 'LineAlpha', ALPHA_LINE);
2640 if gAlphaTriggerLine = 255 then
2641 gAlphaTriggerLine := ALPHA_LINE;
2642 gAlphaTriggerArea := config.ReadInt('Editor', 'TriggerAlpha', ALPHA_AREA);
2643 if gAlphaTriggerArea = 255 then
2644 gAlphaTriggerArea := ALPHA_AREA;
2645 if config.ReadInt('Editor', 'Scale', 0) = 1 then
2646 Scale := 2
2647 else
2648 Scale := 1;
2649 if config.ReadInt('Editor', 'DotSize', 0) = 1 then
2650 DotSize := 2
2651 else
2652 DotSize := 1;
2653 OpenDialog.InitialDir := config.ReadStr('Editor', 'LastOpenDir', EditorDir);
2654 SaveDialog.InitialDir := config.ReadStr('Editor', 'LastSaveDir', EditorDir);
2656 s := config.ReadStr('Editor', 'Language', '');
2657 gLanguage := s;
2659 RecentCount := config.ReadInt('Editor', 'RecentCount', 5);
2660 if RecentCount > 10 then
2661 RecentCount := 10;
2662 if RecentCount < 2 then
2663 RecentCount := 2;
2665 RecentFiles := TStringList.Create();
2666 for i := 0 to RecentCount-1 do
2667 begin
2668 s := config.ReadStr('RecentFiles', IntToStr(i+1), '');
2669 if s <> '' then
2670 RecentFiles.Add(s);
2671 end;
2672 RefreshRecentMenu();
2674 config.Free();
2676 tbShowMap.Down := ShowMap;
2677 tbGridOn.Down := DotEnable;
2678 pcObjects.ActivePageIndex := 0;
2679 Application.Title := _lc[I_EDITOR_TITLE];
2681 Application.OnIdle := OnIdle;
2682 end;
2684 procedure PrintBlack(X, Y: Integer; Text: string; FontID: DWORD);
2685 begin
2686 // NOTE: all the font printing routines assume CP1251
2687 e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0);
2688 end;
2690 procedure TMainForm.Draw();
2691 var
2692 x, y: Integer;
2693 a, b: Integer;
2694 ID, PID: DWORD;
2695 Width, Height: Word;
2696 Rect: TRectWH;
2697 ObjCount: Word;
2698 aX, aY, aX2, aY2, XX, ScaleSz: Integer;
2699 begin
2700 e_BeginRender();
2702 e_Clear(GL_COLOR_BUFFER_BIT,
2703 GetRValue(BackColor)/255,
2704 GetGValue(BackColor)/255,
2705 GetBValue(BackColor)/255);
2707 DrawMap();
2709 ObjCount := SelectedObjectCount();
2711 // Обводим выделенные объекты красной рамкой:
2712 if ObjCount > 0 then
2713 begin
2714 for a := 0 to High(SelectedObjects) do
2715 if SelectedObjects[a].Live then
2716 begin
2717 Rect := ObjectGetRect(SelectedObjects[a].ObjectType, SelectedObjects[a].ID);
2719 with Rect do
2720 begin
2721 e_DrawQuad(X+MapOffset.X, Y+MapOffset.Y,
2722 X+MapOffset.X+Width-1, Y+MapOffset.Y+Height-1,
2723 255, 0, 0);
2725 // Рисуем точки изменения размеров:
2726 if (ObjCount = 1) and
2727 (SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) then
2728 begin
2729 e_DrawPoint(5, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2730 e_DrawPoint(5, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 255, 255);
2731 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 255, 255);
2732 e_DrawPoint(5, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 255, 255);
2734 e_DrawPoint(3, X+MapOffset.X, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2735 e_DrawPoint(3, X+MapOffset.X+Width-1, Y+MapOffset.Y+(Height div 2), 255, 0, 0);
2736 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y, 255, 0, 0);
2737 e_DrawPoint(3, X+MapOffset.X+(Width div 2), Y+MapOffset.Y+Height-1, 255, 0, 0);
2738 end;
2739 end;
2740 end;
2741 end;
2743 // Рисуем сетку:
2744 if DotEnable and (not PreviewMode) then
2745 begin
2746 if DotSize = 2 then
2747 a := -1
2748 else
2749 a := 0;
2751 for x := 0 to (RenderPanel.Width div DotStep) do
2752 for y := 0 to (RenderPanel.Height div DotStep) do
2753 e_DrawPoint(DotSize, x*DotStep + a, y*DotStep + a,
2754 GetRValue(DotColor),
2755 GetGValue(DotColor),
2756 GetBValue(DotColor));
2757 end;
2759 // Превью текстуры:
2760 if (lbTextureList.ItemIndex <> -1) and (cbPreview.Checked) and
2761 (not IsSpecialTextureSel()) and (not PreviewMode) then
2762 begin
2763 if not g_GetTexture(SelectedTexture(), ID) then
2764 g_GetTexture('NOTEXTURE', ID);
2765 g_GetTextureSizeByID(ID, Width, Height);
2766 if g_GetTexture('PREVIEW', PID) then
2767 e_DrawFill(PID, RenderPanel.Width-Width, RenderPanel.Height-Height, Width div 16 + 1, Height div 16 + 1, 0, True, False);
2768 e_Draw(ID, RenderPanel.Width-Width, RenderPanel.Height-Height, 0, True, False);
2769 end;
2771 // Подсказка при выборе точки Телепорта:
2772 if SelectFlag = SELECTFLAG_TELEPORT then
2773 begin
2774 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
2775 if Data.d2d_teleport then
2776 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2777 MousePos.X+16, MousePos.Y-1,
2778 0, 0, 255)
2779 else
2780 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+AreaSize[AREA_DMPOINT].Width-1,
2781 MousePos.Y+AreaSize[AREA_DMPOINT].Height-1, 255, 255, 255);
2783 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2784 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2785 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_TELEPORT], gEditorFont);
2786 end;
2788 // Подсказка при выборе точки появления:
2789 if SelectFlag = SELECTFLAG_SPAWNPOINT then
2790 begin
2791 e_DrawLine(2, MousePos.X-16, MousePos.Y-1,
2792 MousePos.X+16, MousePos.Y-1,
2793 0, 0, 255);
2794 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2795 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2796 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_SPAWN], gEditorFont);
2797 end;
2799 // Подсказка при выборе панели двери:
2800 if SelectFlag = SELECTFLAG_DOOR then
2801 begin
2802 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2803 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2804 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_DOOR], gEditorFont);
2805 end;
2807 // Подсказка при выборе панели с текстурой:
2808 if SelectFlag = SELECTFLAG_TEXTURE then
2809 begin
2810 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 192, 192, 192, 127);
2811 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+196, MousePos.Y+18, 255, 255, 255);
2812 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_TEXTURE], gEditorFont);
2813 end;
2815 // Подсказка при выборе панели индикации выстрела:
2816 if SelectFlag = SELECTFLAG_SHOTPANEL then
2817 begin
2818 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 192, 192, 192, 127);
2819 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+316, MousePos.Y+18, 255, 255, 255);
2820 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_SHOT], gEditorFont);
2821 end;
2823 // Подсказка при выборе панели лифта:
2824 if SelectFlag = SELECTFLAG_LIFT then
2825 begin
2826 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 192, 192, 192, 127);
2827 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+180, MousePos.Y+18, 255, 255, 255);
2828 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_PANEL_LIFT], gEditorFont);
2829 end;
2831 // Подсказка при выборе монстра:
2832 if SelectFlag = SELECTFLAG_MONSTER then
2833 begin
2834 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 192, 192, 192, 127);
2835 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+120, MousePos.Y+18, 255, 255, 255);
2836 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_MONSTER], gEditorFont);
2837 end;
2839 // Подсказка при выборе области воздействия:
2840 if DrawPressRect then
2841 begin
2842 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 192, 192, 192, 127);
2843 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+204, MousePos.Y+18, 255, 255, 255);
2844 PrintBlack(MousePos.X+2, MousePos.Y+2, _glc[I_HINT_EXT_AREA], gEditorFont);
2845 end;
2847 // Рисуем текстуры, если чертим панель:
2848 if (MouseAction = MOUSEACTION_DRAWPANEL) and (DrawTexturePanel) and
2849 (lbTextureList.ItemIndex <> -1) and (DrawRect <> nil) and
2850 (lbPanelType.ItemIndex in [0..8]) and not IsSpecialTextureSel() then
2851 begin
2852 if not g_GetTexture(SelectedTexture(), ID) then
2853 g_GetTexture('NOTEXTURE', ID);
2854 g_GetTextureSizeByID(ID, Width, Height);
2855 with DrawRect^ do
2856 e_DrawFill(ID, Min(Left, Right), Min(Top, Bottom), Abs(Right-Left) div Width,
2857 Abs(Bottom-Top) div Height, 0, True, False);
2858 end;
2860 // Прямоугольник выделения:
2861 if DrawRect <> nil then
2862 with DrawRect^ do
2863 e_DrawQuad(Left, Top, Right-1, Bottom-1, 255, 255, 255);
2865 // Чертим мышью панель/триггер или меняем мышью их размер:
2866 if (MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER, MOUSEACTION_RESIZE]) and
2867 (DrawPanelSize) then
2868 begin
2869 e_DrawFillQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 192, 192, 192, 127);
2870 e_DrawQuad(MousePos.X, MousePos.Y, MousePos.X+88, MousePos.Y+33, 255, 255, 255);
2872 if MouseAction in [MOUSEACTION_DRAWPANEL, MOUSEACTION_DRAWTRIGGER] then
2873 begin // Чертим новый
2874 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH],
2875 [Abs(MousePos.X-MouseLDownPos.X)]), gEditorFont);
2876 PrintBlack(MousePos.X+2, MousePos.Y+14, Format(_glc[I_HINT_HEIGHT],
2877 [Abs(MousePos.Y-MouseLDownPos.Y)]), gEditorFont);
2878 end
2879 else // Растягиваем существующий
2880 if SelectedObjects[GetFirstSelected].ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER] then
2881 begin
2882 if SelectedObjects[GetFirstSelected].ObjectType = OBJECT_PANEL then
2883 begin
2884 Width := gPanels[SelectedObjects[GetFirstSelected].ID].Width;
2885 Height := gPanels[SelectedObjects[GetFirstSelected].ID].Height;
2886 end
2887 else
2888 begin
2889 Width := gTriggers[SelectedObjects[GetFirstSelected].ID].Width;
2890 Height := gTriggers[SelectedObjects[GetFirstSelected].ID].Height;
2891 end;
2893 PrintBlack(MousePos.X+2, MousePos.Y+2, Format(_glc[I_HINT_WIDTH], [Width]),
2894 gEditorFont);
2895 PrintBlack(MousePos.X+2, MousePos.Y+14, Format(_glc[I_HINT_HEIGHT], [Height]),
2896 gEditorFont);
2897 end;
2898 end;
2900 // Ближайшая к курсору мыши точка на сетке:
2901 e_DrawPoint(3, MousePos.X, MousePos.Y, 0, 0, 255);
2903 // Мини-карта:
2904 if ShowMap then
2905 begin
2906 // Сколько пикселов карты в 1 пикселе мини-карты:
2907 ScaleSz := 16 div Scale;
2908 // Размеры мини-карты:
2909 aX := max(gMapInfo.Width div ScaleSz, 1);
2910 aY := max(gMapInfo.Height div ScaleSz, 1);
2911 // X-координата на RenderPanel нулевой x-координаты карты:
2912 XX := RenderPanel.Width - aX - 1;
2913 // Рамка карты:
2914 e_DrawFillQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 0, 0, 0, 0);
2915 e_DrawQuad(XX-1, 0, RenderPanel.Width-1, aY+1, 197, 197, 197);
2917 if gPanels <> nil then
2918 begin
2919 // Рисуем панели:
2920 for a := 0 to High(gPanels) do
2921 with gPanels[a] do
2922 if PanelType <> 0 then
2923 begin
2924 // Левый верхний угол:
2925 aX := XX + (X div ScaleSz);
2926 aY := 1 + (Y div ScaleSz);
2927 // Размеры:
2928 aX2 := max(Width div ScaleSz, 1);
2929 aY2 := max(Height div ScaleSz, 1);
2930 // Правый нижний угол:
2931 aX2 := aX + aX2 - 1;
2932 aY2 := aY + aY2 - 1;
2934 case PanelType of
2935 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
2936 PANEL_WATER: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
2937 PANEL_ACID1: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
2938 PANEL_ACID2: e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
2939 PANEL_STEP: e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
2940 PANEL_LIFTUP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
2941 PANEL_LIFTDOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
2942 PANEL_LIFTLEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
2943 PANEL_LIFTRIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
2944 PANEL_OPENDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 100, 220, 92, 0);
2945 PANEL_CLOSEDOOR: e_DrawFillQuad(aX, aY, aX2, aY2, 212, 184, 64, 0);
2946 PANEL_BLOCKMON: e_DrawFillQuad(aX, aY, aX2, aY2, 192, 0, 192, 0);
2947 end;
2948 end;
2950 // Рисуем красным выделенные панели:
2951 if SelectedObjects <> nil then
2952 for b := 0 to High(SelectedObjects) do
2953 with SelectedObjects[b] do
2954 if Live and (ObjectType = OBJECT_PANEL) then
2955 with gPanels[SelectedObjects[b].ID] do
2956 if PanelType and not(PANEL_BACK or PANEL_FORE) <> 0 then
2957 begin
2958 // Левый верхний угол:
2959 aX := XX + (X div ScaleSz);
2960 aY := 1 + (Y div ScaleSz);
2961 // Размеры:
2962 aX2 := max(Width div ScaleSz, 1);
2963 aY2 := max(Height div ScaleSz, 1);
2964 // Правый нижний угол:
2965 aX2 := aX + aX2 - 1;
2966 aY2 := aY + aY2 - 1;
2968 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0)
2969 end;
2970 end;
2972 if (gMapInfo.Width > RenderPanel.Width) or
2973 (gMapInfo.Height > RenderPanel.Height) then
2974 begin
2975 // Окно, показывающее текущее положение экрана на карте:
2976 // Размеры окна:
2977 x := max(min(RenderPanel.Width, gMapInfo.Width) div ScaleSz, 1);
2978 y := max(min(RenderPanel.Height, gMapInfo.Height) div ScaleSz, 1);
2979 // Левый верхний угол:
2980 aX := XX + ((-MapOffset.X) div ScaleSz);
2981 aY := 1 + ((-MapOffset.Y) div ScaleSz);
2982 // Правый нижний угол:
2983 aX2 := aX + x - 1;
2984 aY2 := aY + y - 1;
2986 e_DrawFillQuad(aX, aY, aX2, aY2, 127, 192, 127, 127, B_BLEND);
2987 e_DrawQuad(aX, aY, aX2, aY2, 255, 0, 0);
2988 end;
2989 end; // Мини-карта
2991 e_EndRender();
2992 RenderPanel.SwapBuffers();
2993 end;
2995 procedure TMainForm.FormResize(Sender: TObject);
2996 begin
2997 e_SetViewPort(0, 0, RenderPanel.Width, RenderPanel.Height);
2999 if gMapInfo.Width >= RenderPanel.Width then
3000 sbHorizontal.Max := Normalize16(gMapInfo.Width-RenderPanel.Width+16)
3001 else
3002 sbHorizontal.Max := 0;
3004 if gMapInfo.Height >= RenderPanel.Height then
3005 sbVertical.Max := Normalize16(gMapInfo.Height-RenderPanel.Height+16)
3006 else
3007 sbVertical.Max := 0;
3009 MapOffset.X := -Normalize16(sbHorizontal.Position);
3010 MapOffset.Y := -Normalize16(sbVertical.Position);
3011 end;
3013 procedure SelectNextObject(X, Y: Integer; ObjectType: Byte; ID: DWORD);
3014 var
3015 j, j_max: Integer;
3016 res: Boolean;
3017 begin
3018 j_max := 0; // shut up compiler
3019 case ObjectType of
3020 OBJECT_PANEL:
3021 begin
3022 res := (gPanels <> nil) and
3023 PanelInShownLayer(gPanels[ID].PanelType) and
3024 g_CollidePoint(X, Y, gPanels[ID].X, gPanels[ID].Y,
3025 gPanels[ID].Width,
3026 gPanels[ID].Height);
3027 j_max := Length(gPanels) - 1;
3028 end;
3030 OBJECT_ITEM:
3031 begin
3032 res := (gItems <> nil) and
3033 LayerEnabled[LAYER_ITEMS] and
3034 g_CollidePoint(X, Y, gItems[ID].X, gItems[ID].Y,
3035 ItemSize[gItems[ID].ItemType][0],
3036 ItemSize[gItems[ID].ItemType][1]);
3037 j_max := Length(gItems) - 1;
3038 end;
3040 OBJECT_MONSTER:
3041 begin
3042 res := (gMonsters <> nil) and
3043 LayerEnabled[LAYER_MONSTERS] and
3044 g_CollidePoint(X, Y, gMonsters[ID].X, gMonsters[ID].Y,
3045 MonsterSize[gMonsters[ID].MonsterType].Width,
3046 MonsterSize[gMonsters[ID].MonsterType].Height);
3047 j_max := Length(gMonsters) - 1;
3048 end;
3050 OBJECT_AREA:
3051 begin
3052 res := (gAreas <> nil) and
3053 LayerEnabled[LAYER_AREAS] and
3054 g_CollidePoint(X, Y, gAreas[ID].X, gAreas[ID].Y,
3055 AreaSize[gAreas[ID].AreaType].Width,
3056 AreaSize[gAreas[ID].AreaType].Height);
3057 j_max := Length(gAreas) - 1;
3058 end;
3060 OBJECT_TRIGGER:
3061 begin
3062 res := (gTriggers <> nil) and
3063 LayerEnabled[LAYER_TRIGGERS] and
3064 g_CollidePoint(X, Y, gTriggers[ID].X, gTriggers[ID].Y,
3065 gTriggers[ID].Width,
3066 gTriggers[ID].Height);
3067 j_max := Length(gTriggers) - 1;
3068 end;
3070 else
3071 res := False;
3072 end;
3074 if not res then
3075 Exit;
3077 // Перебор ID: от ID-1 до 0; потом от High до ID+1:
3078 j := ID;
3080 while True do
3081 begin
3082 Dec(j);
3084 if j < 0 then
3085 j := j_max;
3086 if j = Integer(ID) then
3087 Break;
3089 case ObjectType of
3090 OBJECT_PANEL:
3091 res := PanelInShownLayer(gPanels[j].PanelType) and
3092 g_CollidePoint(X, Y, gPanels[j].X, gPanels[j].Y,
3093 gPanels[j].Width,
3094 gPanels[j].Height);
3095 OBJECT_ITEM:
3096 res := (gItems[j].ItemType <> ITEM_NONE) and
3097 g_CollidePoint(X, Y, gItems[j].X, gItems[j].Y,
3098 ItemSize[gItems[j].ItemType][0],
3099 ItemSize[gItems[j].ItemType][1]);
3100 OBJECT_MONSTER:
3101 res := (gMonsters[j].MonsterType <> MONSTER_NONE) and
3102 g_CollidePoint(X, Y, gMonsters[j].X, gMonsters[j].Y,
3103 MonsterSize[gMonsters[j].MonsterType].Width,
3104 MonsterSize[gMonsters[j].MonsterType].Height);
3105 OBJECT_AREA:
3106 res := (gAreas[j].AreaType <> AREA_NONE) and
3107 g_CollidePoint(X, Y, gAreas[j].X, gAreas[j].Y,
3108 AreaSize[gAreas[j].AreaType].Width,
3109 AreaSize[gAreas[j].AreaType].Height);
3110 OBJECT_TRIGGER:
3111 res := (gTriggers[j].TriggerType <> TRIGGER_NONE) and
3112 g_CollidePoint(X, Y, gTriggers[j].X, gTriggers[j].Y,
3113 gTriggers[j].Width,
3114 gTriggers[j].Height);
3115 else
3116 res := False;
3117 end;
3119 if res then
3120 begin
3121 SetLength(SelectedObjects, 1);
3123 SelectedObjects[0].ObjectType := ObjectType;
3124 SelectedObjects[0].ID := j;
3125 SelectedObjects[0].Live := True;
3127 FillProperty();
3128 Break;
3129 end;
3130 end;
3131 end;
3133 procedure TMainForm.RenderPanelMouseDown(Sender: TObject;
3134 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3135 var
3136 i: Integer;
3137 Rect: TRectWH;
3138 c1, c2, c3, c4: Boolean;
3139 item: TItem;
3140 area: TArea;
3141 monster: TMonster;
3142 IDArray: DWArray;
3143 begin
3144 MainForm.ActiveControl := RenderPanel;
3145 RenderPanel.SetFocus();
3147 RenderPanelMouseMove(RenderPanel, Shift, X, Y);
3149 if Button = mbLeft then // Left Mouse Button
3150 begin
3151 // Двигаем карту с помощью мыши и мини-карты:
3152 if ShowMap and
3153 g_CollidePoint(X, Y,
3154 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3155 1,
3156 max(gMapInfo.Width div (16 div Scale), 1),
3157 max(gMapInfo.Height div (16 div Scale), 1) ) then
3158 begin
3159 MoveMap(X, Y);
3160 MouseAction := MOUSEACTION_MOVEMAP;
3161 end
3162 else // Ставим предмет/монстра/область:
3163 if (pcObjects.ActivePageIndex in [1, 2, 3]) and
3164 (not (ssShift in Shift)) then
3165 begin
3166 case pcObjects.ActivePageIndex of
3167 1:
3168 if lbItemList.ItemIndex = -1 then
3169 ErrorMessageBox(_lc[I_MSG_CHOOSE_ITEM])
3170 else
3171 begin
3172 item.ItemType := lbItemList.ItemIndex + ITEM_MEDKIT_SMALL;
3173 if item.ItemType >= ITEM_WEAPON_KASTET then
3174 item.ItemType := item.ItemType + 2;
3175 item.X := MousePos.X-MapOffset.X;
3176 item.Y := MousePos.Y-MapOffset.Y;
3178 if not (ssCtrl in Shift) then
3179 begin
3180 item.X := item.X - (ItemSize[item.ItemType][0] div 2);
3181 item.Y := item.Y - ItemSize[item.ItemType][1];
3182 end;
3184 item.OnlyDM := cbOnlyDM.Checked;
3185 item.Fall := cbFall.Checked;
3186 Undo_Add(OBJECT_ITEM, AddItem(item));
3187 end;
3188 2:
3189 if lbMonsterList.ItemIndex = -1 then
3190 ErrorMessageBox(_lc[I_MSG_CHOOSE_MONSTER])
3191 else
3192 begin
3193 monster.MonsterType := lbMonsterList.ItemIndex + MONSTER_DEMON;
3194 monster.X := MousePos.X-MapOffset.X;
3195 monster.Y := MousePos.Y-MapOffset.Y;
3197 if not (ssCtrl in Shift) then
3198 begin
3199 monster.X := monster.X - (MonsterSize[monster.MonsterType].Width div 2);
3200 monster.Y := monster.Y - MonsterSize[monster.MonsterType].Height;
3201 end;
3203 if rbMonsterLeft.Checked then
3204 monster.Direction := D_LEFT
3205 else
3206 monster.Direction := D_RIGHT;
3207 Undo_Add(OBJECT_MONSTER, AddMonster(monster));
3208 end;
3209 3:
3210 if lbAreasList.ItemIndex = -1 then
3211 ErrorMessageBox(_lc[I_MSG_CHOOSE_AREA])
3212 else
3213 if (lbAreasList.ItemIndex + 1) <> AREA_DOMFLAG then
3214 begin
3215 area.AreaType := lbAreasList.ItemIndex + AREA_PLAYERPOINT1;
3216 area.X := MousePos.X-MapOffset.X;
3217 area.Y := MousePos.Y-MapOffset.Y;
3219 if not (ssCtrl in Shift) then
3220 begin
3221 area.X := area.X - (AreaSize[area.AreaType].Width div 2);
3222 area.Y := area.Y - AreaSize[area.AreaType].Height;
3223 end;
3225 if rbAreaLeft.Checked then
3226 area.Direction := D_LEFT
3227 else
3228 area.Direction := D_RIGHT;
3229 Undo_Add(OBJECT_AREA, AddArea(area));
3230 end;
3231 end;
3232 end
3233 else
3234 begin
3235 i := GetFirstSelected();
3237 // Выбираем объект под текущим:
3238 if (SelectedObjects <> nil) and
3239 (ssShift in Shift) and (i >= 0) and
3240 (SelectedObjects[i].Live) then
3241 begin
3242 if SelectedObjectCount() = 1 then
3243 SelectNextObject(X-MapOffset.X, Y-MapOffset.Y,
3244 SelectedObjects[i].ObjectType,
3245 SelectedObjects[i].ID);
3246 end
3247 else
3248 begin
3249 // Рисуем область триггера "Расширитель":
3250 if DrawPressRect and (i >= 0) and
3251 (SelectedObjects[i].ObjectType = OBJECT_TRIGGER) and
3252 (gTriggers[SelectedObjects[i].ID].TriggerType in
3253 [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) then
3254 MouseAction := MOUSEACTION_DRAWPRESS
3255 else // Рисуем панель:
3256 if pcObjects.ActivePageIndex = 0 then
3257 begin
3258 if (lbPanelType.ItemIndex >= 0) then
3259 MouseAction := MOUSEACTION_DRAWPANEL
3260 end
3261 else // Рисуем триггер:
3262 if (lbTriggersList.ItemIndex >= 0) then
3263 begin
3264 MouseAction := MOUSEACTION_DRAWTRIGGER;
3265 end;
3266 end;
3267 end;
3268 end; // if Button = mbLeft
3270 if Button = mbRight then // Right Mouse Button
3271 begin
3272 // Клик по мини-карте:
3273 if ShowMap and
3274 g_CollidePoint(X, Y,
3275 RenderPanel.Width-max(gMapInfo.Width div (16 div Scale), 1)-1,
3276 1,
3277 max(gMapInfo.Width div (16 div Scale), 1),
3278 max(gMapInfo.Height div (16 div Scale), 1) ) then
3279 begin
3280 MouseAction := MOUSEACTION_NOACTION;
3281 end
3282 else // Нужно что-то выбрать мышью:
3283 if SelectFlag <> SELECTFLAG_NONE then
3284 begin
3285 case SelectFlag of
3286 SELECTFLAG_TELEPORT:
3287 // Точку назначения телепортации:
3288 with gTriggers[SelectedObjects[
3289 GetFirstSelected() ].ID].Data.TargetPoint do
3290 begin
3291 X := MousePos.X-MapOffset.X;
3292 Y := MousePos.Y-MapOffset.Y;
3293 end;
3295 SELECTFLAG_SPAWNPOINT:
3296 // Точку создания монстра:
3297 with gTriggers[SelectedObjects[GetFirstSelected()].ID] do
3298 if TriggerType = TRIGGER_SPAWNMONSTER then
3299 begin
3300 Data.MonPos.X := MousePos.X-MapOffset.X;
3301 Data.MonPos.Y := MousePos.Y-MapOffset.Y;
3302 end
3303 else if TriggerType = TRIGGER_SPAWNITEM then
3304 begin // Точка создания предмета:
3305 Data.ItemPos.X := MousePos.X-MapOffset.X;
3306 Data.ItemPos.Y := MousePos.Y-MapOffset.Y;
3307 end
3308 else if TriggerType = TRIGGER_SHOT then
3309 begin // Точка создания выстрела:
3310 Data.ShotPos.X := MousePos.X-MapOffset.X;
3311 Data.ShotPos.Y := MousePos.Y-MapOffset.Y;
3312 end;
3314 SELECTFLAG_DOOR:
3315 // Дверь:
3316 begin
3317 IDArray := ObjectInRect(X-MapOffset.X,
3318 Y-MapOffset.Y,
3319 2, 2, OBJECT_PANEL, True);
3320 if IDArray <> nil then
3321 begin
3322 for i := 0 to High(IDArray) do
3323 if (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3324 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR) then
3325 begin
3326 gTriggers[SelectedObjects[
3327 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3328 Break;
3329 end;
3330 end
3331 else
3332 gTriggers[SelectedObjects[
3333 GetFirstSelected() ].ID].Data.PanelID := -1;
3334 end;
3336 SELECTFLAG_TEXTURE:
3337 // Панель с текстурой:
3338 begin
3339 IDArray := ObjectInRect(X-MapOffset.X,
3340 Y-MapOffset.Y,
3341 2, 2, OBJECT_PANEL, True);
3342 if IDArray <> nil then
3343 begin
3344 for i := 0 to High(IDArray) do
3345 if ((gPanels[IDArray[i]].PanelType in
3346 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3347 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3348 PANEL_STEP]) or
3349 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3350 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3351 (gPanels[IDArray[i]].TextureName <> '') then
3352 begin
3353 gTriggers[SelectedObjects[
3354 GetFirstSelected() ].ID].TexturePanel := IDArray[i];
3355 Break;
3356 end;
3357 end
3358 else
3359 gTriggers[SelectedObjects[
3360 GetFirstSelected() ].ID].TexturePanel := -1;
3361 end;
3363 SELECTFLAG_LIFT:
3364 // Лифт:
3365 begin
3366 IDArray := ObjectInRect(X-MapOffset.X,
3367 Y-MapOffset.Y,
3368 2, 2, OBJECT_PANEL, True);
3369 if IDArray <> nil then
3370 begin
3371 for i := 0 to High(IDArray) do
3372 if (gPanels[IDArray[i]].PanelType = PANEL_LIFTUP) or
3373 (gPanels[IDArray[i]].PanelType = PANEL_LIFTDOWN) or
3374 (gPanels[IDArray[i]].PanelType = PANEL_LIFTLEFT) or
3375 (gPanels[IDArray[i]].PanelType = PANEL_LIFTRIGHT) then
3376 begin
3377 gTriggers[SelectedObjects[
3378 GetFirstSelected() ].ID].Data.PanelID := IDArray[i];
3379 Break;
3380 end;
3381 end
3382 else
3383 gTriggers[SelectedObjects[
3384 GetFirstSelected() ].ID].Data.PanelID := -1;
3385 end;
3387 SELECTFLAG_MONSTER:
3388 // Монстра:
3389 begin
3390 IDArray := ObjectInRect(X-MapOffset.X,
3391 Y-MapOffset.Y,
3392 2, 2, OBJECT_MONSTER, False);
3393 if IDArray <> nil then
3394 gTriggers[SelectedObjects[
3395 GetFirstSelected() ].ID].Data.MonsterID := IDArray[0]+1
3396 else
3397 gTriggers[SelectedObjects[
3398 GetFirstSelected() ].ID].Data.MonsterID := 0;
3399 end;
3401 SELECTFLAG_SHOTPANEL:
3402 // Панель индикации выстрела:
3403 begin
3404 if gTriggers[SelectedObjects[
3405 GetFirstSelected() ].ID].TriggerType = TRIGGER_SHOT then
3406 begin
3407 IDArray := ObjectInRect(X-MapOffset.X,
3408 Y-MapOffset.Y,
3409 2, 2, OBJECT_PANEL, True);
3410 if IDArray <> nil then
3411 begin
3412 for i := 0 to High(IDArray) do
3413 if ((gPanels[IDArray[i]].PanelType in
3414 [PANEL_WALL, PANEL_BACK, PANEL_FORE,
3415 PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
3416 PANEL_STEP]) or
3417 (gPanels[IDArray[i]].PanelType = PANEL_OPENDOOR) or
3418 (gPanels[IDArray[i]].PanelType = PANEL_CLOSEDOOR)) and
3419 (gPanels[IDArray[i]].TextureName <> '') then
3420 begin
3421 gTriggers[SelectedObjects[
3422 GetFirstSelected() ].ID].Data.ShotPanelID := IDArray[i];
3423 Break;
3424 end;
3425 end
3426 else
3427 gTriggers[SelectedObjects[
3428 GetFirstSelected() ].ID].Data.ShotPanelID := -1;
3429 end;
3430 end;
3431 end;
3433 SelectFlag := SELECTFLAG_SELECTED;
3434 end
3435 else // if SelectFlag <> SELECTFLAG_NONE...
3436 begin
3437 // Что уже выбрано и не нажат Ctrl:
3438 if (SelectedObjects <> nil) and
3439 (not (ssCtrl in Shift)) then
3440 for i := 0 to High(SelectedObjects) do
3441 with SelectedObjects[i] do
3442 if Live then
3443 begin
3444 if (ObjectType in [OBJECT_PANEL, OBJECT_TRIGGER]) and
3445 (SelectedObjectCount() = 1) then
3446 begin
3447 Rect := ObjectGetRect(ObjectType, ID);
3449 c1 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3450 Rect.X-2, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3451 c2 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3452 Rect.X+Rect.Width-3, Rect.Y+(Rect.Height div 2)-2, 4, 4);
3453 c3 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3454 Rect.X+(Rect.Width div 2)-2, Rect.Y-2, 4, 4);
3455 c4 := g_Collide(X-MapOffset.X-1, Y-MapOffset.Y-1, 2, 2,
3456 Rect.X+(Rect.Width div 2)-2, Rect.Y+Rect.Height-3, 4, 4);
3458 // Меняем размер панели или триггера:
3459 if c1 or c2 or c3 or c4 then
3460 begin
3461 MouseAction := MOUSEACTION_RESIZE;
3462 LastMovePoint := MousePos;
3464 if c1 or c2 then
3465 begin // Шире/уже
3466 ResizeType := RESIZETYPE_HORIZONTAL;
3467 if c1 then
3468 ResizeDirection := RESIZEDIR_LEFT
3469 else
3470 ResizeDirection := RESIZEDIR_RIGHT;
3471 RenderPanel.Cursor := crSizeWE;
3472 end
3473 else
3474 begin // Выше/ниже
3475 ResizeType := RESIZETYPE_VERTICAL;
3476 if c3 then
3477 ResizeDirection := RESIZEDIR_UP
3478 else
3479 ResizeDirection := RESIZEDIR_DOWN;
3480 RenderPanel.Cursor := crSizeNS;
3481 end;
3483 Break;
3484 end;
3485 end;
3487 // Перемещаем панель или триггер:
3488 if ObjectCollide(ObjectType, ID,
3489 X-MapOffset.X-1,
3490 Y-MapOffset.Y-1, 2, 2) then
3491 begin
3492 MouseAction := MOUSEACTION_MOVEOBJ;
3493 LastMovePoint := MousePos;
3495 Break;
3496 end;
3497 end;
3498 end;
3499 end; // if Button = mbRight
3501 MouseRDown := Button = mbRight;
3502 if MouseRDown then
3503 MouseRDownPos := MousePos;
3505 MouseLDown := Button = mbLeft;
3506 if MouseLDown then
3507 MouseLDownPos := MousePos;
3508 end;
3510 procedure TMainForm.RenderPanelMouseUp(Sender: TObject;
3511 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3512 var
3513 panel: TPanel;
3514 trigger: TTrigger;
3515 i: Integer;
3516 IDArray: DWArray;
3517 rRect: TRectWH;
3518 rSelectRect: Boolean;
3519 begin
3520 if Button = mbLeft then
3521 MouseLDown := False;
3522 if Button = mbRight then
3523 MouseRDown := False;
3525 DrawRect := nil;
3526 ResizeType := RESIZETYPE_NONE;
3528 if Button = mbLeft then // Left Mouse Button
3529 begin
3530 if MouseAction <> MOUSEACTION_NONE then
3531 begin // Было действие мышью
3532 // Мышь сдвинулась во время удержания клавиши:
3533 if (MousePos.X <> MouseLDownPos.X) and
3534 (MousePos.Y <> MouseLDownPos.Y) then
3535 case MouseAction of
3536 // Рисовали панель:
3537 MOUSEACTION_DRAWPANEL:
3538 begin
3539 // Фон или передний план без текстуры - ошибка:
3540 if (lbPanelType.ItemIndex in [1, 2]) and
3541 (lbTextureList.ItemIndex = -1) then
3542 ErrorMessageBox(_lc[I_MSG_CHOOSE_TEXTURE])
3543 else // Назначаем параметры панели:
3544 begin
3545 case lbPanelType.ItemIndex of
3546 0: Panel.PanelType := PANEL_WALL;
3547 1: Panel.PanelType := PANEL_BACK;
3548 2: Panel.PanelType := PANEL_FORE;
3549 3: Panel.PanelType := PANEL_OPENDOOR;
3550 4: Panel.PanelType := PANEL_CLOSEDOOR;
3551 5: Panel.PanelType := PANEL_STEP;
3552 6: Panel.PanelType := PANEL_WATER;
3553 7: Panel.PanelType := PANEL_ACID1;
3554 8: Panel.PanelType := PANEL_ACID2;
3555 9: Panel.PanelType := PANEL_LIFTUP;
3556 10: Panel.PanelType := PANEL_LIFTDOWN;
3557 11: Panel.PanelType := PANEL_LIFTLEFT;
3558 12: Panel.PanelType := PANEL_LIFTRIGHT;
3559 13: Panel.PanelType := PANEL_BLOCKMON;
3560 end;
3562 Panel.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3563 Panel.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3564 Panel.Width := Abs(MousePos.X-MouseLDownPos.X);
3565 Panel.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3567 // Лифты, блокМон или отсутствие текстуры - пустая текстура:
3568 if (lbPanelType.ItemIndex in [9, 10, 11, 12, 13]) or
3569 (lbTextureList.ItemIndex = -1) then
3570 begin
3571 Panel.TextureHeight := 1;
3572 Panel.TextureWidth := 1;
3573 Panel.TextureName := '';
3574 Panel.TextureID := TEXTURE_SPECIAL_NONE;
3575 end
3576 else // Есть текстура:
3577 begin
3578 Panel.TextureName := SelectedTexture();
3580 // Обычная текстура:
3581 if not IsSpecialTextureSel() then
3582 begin
3583 g_GetTextureSizeByName(Panel.TextureName,
3584 Panel.TextureWidth, Panel.TextureHeight);
3585 g_GetTexture(Panel.TextureName, Panel.TextureID);
3586 end
3587 else // Спец.текстура:
3588 begin
3589 Panel.TextureHeight := 1;
3590 Panel.TextureWidth := 1;
3591 Panel.TextureID := SpecialTextureID(SelectedTexture());
3592 end;
3593 end;
3595 Panel.Alpha := 0;
3596 Panel.Blending := False;
3598 Undo_Add(OBJECT_PANEL, AddPanel(Panel));
3599 end;
3600 end;
3602 // Рисовали триггер:
3603 MOUSEACTION_DRAWTRIGGER:
3604 begin
3605 trigger.X := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3606 trigger.Y := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3607 trigger.Width := Abs(MousePos.X-MouseLDownPos.X);
3608 trigger.Height := Abs(MousePos.Y-MouseLDownPos.Y);
3610 trigger.Enabled := True;
3611 trigger.TriggerType := lbTriggersList.ItemIndex+1;
3612 trigger.TexturePanel := -1;
3614 // Типы активации:
3615 trigger.ActivateType := 0;
3617 if clbActivationType.Checked[0] then
3618 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERCOLLIDE;
3619 if clbActivationType.Checked[1] then
3620 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERCOLLIDE;
3621 if clbActivationType.Checked[2] then
3622 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_PLAYERPRESS;
3623 if clbActivationType.Checked[3] then
3624 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_MONSTERPRESS;
3625 if clbActivationType.Checked[4] then
3626 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_SHOT;
3627 if clbActivationType.Checked[5] then
3628 trigger.ActivateType := Trigger.ActivateType or ACTIVATE_NOMONSTER;
3630 // Необходимые для активации ключи:
3631 trigger.Key := 0;
3633 if clbKeys.Checked[0] then
3634 trigger.Key := Trigger.Key or KEY_RED;
3635 if clbKeys.Checked[1] then
3636 trigger.Key := Trigger.Key or KEY_GREEN;
3637 if clbKeys.Checked[2] then
3638 trigger.Key := Trigger.Key or KEY_BLUE;
3639 if clbKeys.Checked[3] then
3640 trigger.Key := Trigger.Key or KEY_REDTEAM;
3641 if clbKeys.Checked[4] then
3642 trigger.Key := Trigger.Key or KEY_BLUETEAM;
3644 // Параметры триггера:
3645 FillByte(trigger.Data.Default[0], 128, 0);
3647 case trigger.TriggerType of
3648 // Переключаемая панель:
3649 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
3650 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
3651 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
3652 begin
3653 Trigger.Data.PanelID := -1;
3654 end;
3656 // Телепортация:
3657 TRIGGER_TELEPORT:
3658 begin
3659 trigger.Data.TargetPoint.X := trigger.X-64;
3660 trigger.Data.TargetPoint.Y := trigger.Y-64;
3661 trigger.Data.d2d_teleport := True;
3662 trigger.Data.TlpDir := 0;
3663 end;
3665 // Изменение других триггеров:
3666 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
3667 TRIGGER_ONOFF:
3668 begin
3669 trigger.Data.Count := 1;
3670 end;
3672 // Звук:
3673 TRIGGER_SOUND:
3674 begin
3675 trigger.Data.Volume := 255;
3676 trigger.Data.Pan := 127;
3677 trigger.Data.PlayCount := 1;
3678 trigger.Data.Local := True;
3679 trigger.Data.SoundSwitch := False;
3680 end;
3682 // Музыка:
3683 TRIGGER_MUSIC:
3684 begin
3685 trigger.Data.MusicAction := 1;
3686 end;
3688 // Создание монстра:
3689 TRIGGER_SPAWNMONSTER:
3690 begin
3691 trigger.Data.MonType := MONSTER_ZOMBY;
3692 trigger.Data.MonPos.X := trigger.X-64;
3693 trigger.Data.MonPos.Y := trigger.Y-64;
3694 trigger.Data.MonHealth := 0;
3695 trigger.Data.MonActive := False;
3696 trigger.Data.MonCount := 1;
3697 end;
3699 // Создание предмета:
3700 TRIGGER_SPAWNITEM:
3701 begin
3702 trigger.Data.ItemType := ITEM_AMMO_BULLETS;
3703 trigger.Data.ItemPos.X := trigger.X-64;
3704 trigger.Data.ItemPos.Y := trigger.Y-64;
3705 trigger.Data.ItemOnlyDM := False;
3706 trigger.Data.ItemFalls := False;
3707 trigger.Data.ItemCount := 1;
3708 trigger.Data.ItemMax := 0;
3709 trigger.Data.ItemDelay := 0;
3710 end;
3712 // Ускорение:
3713 TRIGGER_PUSH:
3714 begin
3715 trigger.Data.PushAngle := 90;
3716 trigger.Data.PushForce := 10;
3717 trigger.Data.ResetVel := True;
3718 end;
3720 TRIGGER_SCORE:
3721 begin
3722 trigger.Data.ScoreCount := 1;
3723 trigger.Data.ScoreCon := True;
3724 trigger.Data.ScoreMsg := True;
3725 end;
3727 TRIGGER_MESSAGE:
3728 begin
3729 trigger.Data.MessageKind := 0;
3730 trigger.Data.MessageSendTo := 0;
3731 trigger.Data.MessageText := '';
3732 trigger.Data.MessageTime := 144;
3733 end;
3735 TRIGGER_DAMAGE:
3736 begin
3737 trigger.Data.DamageValue := 5;
3738 trigger.Data.DamageInterval := 12;
3739 end;
3741 TRIGGER_HEALTH:
3742 begin
3743 trigger.Data.HealValue := 5;
3744 trigger.Data.HealInterval := 36;
3745 end;
3747 TRIGGER_SHOT:
3748 begin
3749 trigger.Data.ShotType := TRIGGER_SHOT_BULLET;
3750 trigger.Data.ShotSound := True;
3751 trigger.Data.ShotPanelID := -1;
3752 trigger.Data.ShotTarget := 0;
3753 trigger.Data.ShotIntSight := 0;
3754 trigger.Data.ShotAim := TRIGGER_SHOT_AIM_DEFAULT;
3755 trigger.Data.ShotPos.X := trigger.X-64;
3756 trigger.Data.ShotPos.Y := trigger.Y-64;
3757 trigger.Data.ShotAngle := 0;
3758 trigger.Data.ShotWait := 18;
3759 trigger.Data.ShotAccuracy := 0;
3760 trigger.Data.ShotAmmo := 0;
3761 trigger.Data.ShotIntReload := 0;
3762 end;
3764 TRIGGER_EFFECT:
3765 begin
3766 trigger.Data.FXCount := 1;
3767 trigger.Data.FXType := TRIGGER_EFFECT_PARTICLE;
3768 trigger.Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
3769 trigger.Data.FXColorR := 0;
3770 trigger.Data.FXColorG := 0;
3771 trigger.Data.FXColorB := 255;
3772 trigger.Data.FXPos := TRIGGER_EFFECT_POS_CENTER;
3773 trigger.Data.FXWait := 1;
3774 trigger.Data.FXVelX := 0;
3775 trigger.Data.FXVelY := -20;
3776 trigger.Data.FXSpreadL := 5;
3777 trigger.Data.FXSpreadR := 5;
3778 trigger.Data.FXSpreadU := 4;
3779 trigger.Data.FXSpreadD := 0;
3780 end;
3781 end;
3783 Undo_Add(OBJECT_TRIGGER, AddTrigger(trigger));
3784 end;
3786 // Рисовали область триггера "Расширитель":
3787 MOUSEACTION_DRAWPRESS:
3788 with gTriggers[SelectedObjects[GetFirstSelected].ID] do
3789 begin
3790 Data.tX := Min(MousePos.X-MapOffset.X, MouseLDownPos.X-MapOffset.X);
3791 Data.tY := Min(MousePos.Y-MapOffset.Y, MouseLDownPos.Y-MapOffset.Y);
3792 Data.tWidth := Abs(MousePos.X-MouseLDownPos.X);
3793 Data.tHeight := Abs(MousePos.Y-MouseLDownPos.Y);
3795 DrawPressRect := False;
3796 end;
3797 end;
3799 MouseAction := MOUSEACTION_NONE;
3800 end;
3801 end // if Button = mbLeft...
3802 else // Right Mouse Button:
3803 begin
3804 if MouseAction = MOUSEACTION_NOACTION then
3805 begin
3806 MouseAction := MOUSEACTION_NONE;
3807 Exit;
3808 end;
3810 // Объект передвинут или изменен в размере:
3811 if MouseAction in [MOUSEACTION_MOVEOBJ, MOUSEACTION_RESIZE] then
3812 begin
3813 MouseAction := MOUSEACTION_NONE;
3814 FillProperty();
3815 Exit;
3816 end;
3818 // Еще не все выбрали:
3819 if SelectFlag <> SELECTFLAG_NONE then
3820 begin
3821 if SelectFlag = SELECTFLAG_SELECTED then
3822 SelectFlag := SELECTFLAG_NONE;
3823 FillProperty();
3824 Exit;
3825 end;
3827 // Мышь сдвинулась во время удержания клавиши:
3828 if (MousePos.X <> MouseRDownPos.X) and
3829 (MousePos.Y <> MouseRDownPos.Y) then
3830 begin
3831 rSelectRect := True;
3833 rRect.X := Min(MousePos.X, MouseRDownPos.X)-MapOffset.X;
3834 rRect.Y := Min(MousePos.Y, MouseRDownPos.Y)-MapOffset.Y;
3835 rRect.Width := Abs(MousePos.X-MouseRDownPos.X);
3836 rRect.Height := Abs(MousePos.Y-MouseRDownPos.Y);
3837 end
3838 else // Мышь не сдвинулась - нет прямоугольника:
3839 begin
3840 rSelectRect := False;
3842 rRect.X := X-MapOffset.X-1;
3843 rRect.Y := Y-MapOffset.Y-1;
3844 rRect.Width := 2;
3845 rRect.Height := 2;
3846 end;
3848 // Если зажат Ctrl - выделять еще, иначе только один выделенный объект:
3849 if not (ssCtrl in Shift) then
3850 RemoveSelectFromObjects();
3852 // Выделяем всё в выбранном прямоугольнике:
3853 IDArray := ObjectInRect(rRect.X, rRect.Y,
3854 rRect.Width, rRect.Height,
3855 pcObjects.ActivePageIndex+1, rSelectRect);
3857 if IDArray <> nil then
3858 for i := 0 to High(IDArray) do
3859 SelectObject(pcObjects.ActivePageIndex+1, IDArray[i],
3860 (ssCtrl in Shift) or rSelectRect);
3862 FillProperty();
3863 end;
3864 end;
3866 procedure TMainForm.RenderPanelPaint(Sender: TObject);
3867 begin
3868 Draw();
3869 end;
3871 procedure TMainForm.RenderPanelMouseMove(Sender: TObject;
3872 Shift: TShiftState; X, Y: Integer);
3873 var
3874 sX, sY: Integer;
3875 dWidth, dHeight: Integer;
3876 _id: Integer;
3877 begin
3878 _id := GetFirstSelected();
3880 // Рисуем панель с текстурой, сетка - размеры текстуры:
3881 if (MouseAction = MOUSEACTION_DRAWPANEL) and
3882 (lbPanelType.ItemIndex in [0..8]) and
3883 (lbTextureList.ItemIndex <> -1) and
3884 (not IsSpecialTextureSel()) then
3885 begin
3886 sX := StrToIntDef(lTextureWidth.Caption, DotStep);
3887 sY := StrToIntDef(lTextureHeight.Caption, DotStep);
3888 end
3889 else
3890 // Меняем размер панели с текстурой, сетка - размеры текстуры:
3891 if (MouseAction = MOUSEACTION_RESIZE) and
3892 ( (SelectedObjects[_id].ObjectType = OBJECT_PANEL) and
3893 IsTexturedPanel(gPanels[SelectedObjects[_id].ID].PanelType) and
3894 (gPanels[SelectedObjects[_id].ID].TextureName <> '') and
3895 (not IsSpecialTexture(gPanels[SelectedObjects[_id].ID].TextureName)) ) then
3896 begin
3897 sX := gPanels[SelectedObjects[_id].ID].TextureWidth;
3898 sY := gPanels[SelectedObjects[_id].ID].TextureHeight;
3899 end
3900 else
3901 // Выравнивание по сетке:
3902 if SnapToGrid then
3903 begin
3904 sX := DotStep;
3905 sY := DotStep;
3906 end
3907 else // Нет выравнивания по сетке:
3908 begin
3909 sX := 1;
3910 sY := 1;
3911 end;
3913 // Новая позиция мыши:
3914 if MouseLDown then
3915 begin // Зажата левая кнопка мыши
3916 MousePos.X := (Round((X-MouseLDownPos.X)/sX)*sX)+MouseLDownPos.X;
3917 MousePos.Y := (Round((Y-MouseLDownPos.Y)/sY)*sY)+MouseLDownPos.Y;
3918 end
3919 else
3920 if MouseRDown then
3921 begin // Зажата правая кнопка мыши
3922 MousePos.X := (Round((X-MouseRDownPos.X)/sX)*sX)+MouseRDownPos.X;
3923 MousePos.Y := (Round((Y-MouseRDownPos.Y)/sY)*sY)+MouseRDownPos.Y;
3924 end
3925 else
3926 begin // Кнопки мыши не зажаты
3927 MousePos.X := (Round(X/sX)*sX);
3928 MousePos.Y := (Round(Y/sY)*sY);
3929 end;
3931 // Изменение размера закончилось - ставим обычный курсор:
3932 if ResizeType = RESIZETYPE_NONE then
3933 RenderPanel.Cursor := crDefault;
3935 // Зажата только правая кнопка мыши:
3936 if (not MouseLDown) and (MouseRDown) then
3937 begin
3938 // Рисуем прямоугольник выделения:
3939 if MouseAction = MOUSEACTION_NONE then
3940 begin
3941 if DrawRect = nil then
3942 New(DrawRect);
3943 DrawRect.Top := MouseRDownPos.y;
3944 DrawRect.Left := MouseRDownPos.x;
3945 DrawRect.Bottom := MousePos.y;
3946 DrawRect.Right := MousePos.x;
3947 end
3948 else
3949 // Двигаем выделенные объекты:
3950 if MouseAction = MOUSEACTION_MOVEOBJ then
3951 begin
3952 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
3953 MousePos.X-LastMovePoint.X,
3954 MousePos.Y-LastMovePoint.Y);
3955 end
3956 else
3957 // Меняем размер выделенного объекта:
3958 if MouseAction = MOUSEACTION_RESIZE then
3959 begin
3960 if (SelectedObjectCount = 1) and
3961 (SelectedObjects[GetFirstSelected].Live) then
3962 begin
3963 dWidth := MousePos.X-LastMovePoint.X;
3964 dHeight := MousePos.Y-LastMovePoint.Y;
3966 case ResizeType of
3967 RESIZETYPE_VERTICAL: dWidth := 0;
3968 RESIZETYPE_HORIZONTAL: dHeight := 0;
3969 end;
3971 case ResizeDirection of
3972 RESIZEDIR_UP: dHeight := -dHeight;
3973 RESIZEDIR_LEFT: dWidth := -dWidth;
3974 end;
3976 ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
3977 SelectedObjects[GetFirstSelected].ID,
3978 dWidth, dHeight, ResizeDirection);
3980 LastMovePoint := MousePos;
3981 end;
3982 end;
3983 end;
3985 // Зажата только левая кнопка мыши:
3986 if (not MouseRDown) and (MouseLDown) then
3987 begin
3988 // Рисуем прямоугольник планирования панели:
3989 if MouseAction in [MOUSEACTION_DRAWPANEL,
3990 MOUSEACTION_DRAWTRIGGER,
3991 MOUSEACTION_DRAWPRESS] then
3992 begin
3993 if DrawRect = nil then
3994 New(DrawRect);
3995 DrawRect.Top := MouseLDownPos.y;
3996 DrawRect.Left := MouseLDownPos.x;
3997 DrawRect.Bottom := MousePos.y;
3998 DrawRect.Right := MousePos.x;
3999 end
4000 else // Двигаем карту:
4001 if MouseAction = MOUSEACTION_MOVEMAP then
4002 begin
4003 MoveMap(X, Y);
4004 end;
4005 end;
4007 // Клавиши мыши не зажаты:
4008 if (not MouseRDown) and (not MouseLDown) then
4009 DrawRect := nil;
4011 // Строка состояния - координаты мыши:
4012 StatusBar.Panels[1].Text := Format('(%d:%d)',
4013 [MousePos.X-MapOffset.X, MousePos.Y-MapOffset.Y]);
4014 end;
4016 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
4017 begin
4018 CanClose := MessageBox(0, PChar(_lc[I_MSG_EXIT_PROMT]),
4019 PChar(_lc[I_MSG_EXIT]),
4020 MB_ICONQUESTION or MB_YESNO or
4021 MB_DEFBUTTON1) = idYes;
4022 end;
4024 procedure TMainForm.aExitExecute(Sender: TObject);
4025 begin
4026 Close();
4027 end;
4029 procedure TMainForm.FormDestroy(Sender: TObject);
4030 var
4031 config: TConfig;
4032 i: Integer;
4033 begin
4034 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
4036 if WindowState <> wsMaximized then
4037 begin
4038 config.WriteInt('Editor', 'XPos', Left);
4039 config.WriteInt('Editor', 'YPos', Top);
4040 config.WriteInt('Editor', 'Width', Width);
4041 config.WriteInt('Editor', 'Height', Height);
4042 end;
4043 config.WriteBool('Editor', 'Maximize', WindowState = wsMaximized);
4044 config.WriteBool('Editor', 'Minimap', ShowMap);
4045 config.WriteInt('Editor', 'PanelProps', PanelProps.ClientWidth);
4046 config.WriteInt('Editor', 'PanelObjs', PanelObjs.ClientHeight);
4047 config.WriteBool('Editor', 'DotEnable', DotEnable);
4048 config.WriteInt('Editor', 'DotStep', DotStep);
4049 config.WriteStr('Editor', 'LastOpenDir', OpenDialog.InitialDir);
4050 config.WriteStr('Editor', 'LastSaveDir', SaveDialog.InitialDir);
4051 config.WriteBool('Editor', 'EdgeShow', drEdge[3] < 255);
4052 config.WriteInt('Editor', 'EdgeColor', gColorEdge);
4053 config.WriteInt('Editor', 'EdgeAlpha', gAlphaEdge);
4054 config.WriteInt('Editor', 'LineAlpha', gAlphaTriggerLine);
4055 config.WriteInt('Editor', 'TriggerAlpha', gAlphaTriggerArea);
4057 for i := 0 to RecentCount-1 do
4058 if i < RecentFiles.Count then
4059 config.WriteStr('RecentFiles', IntToStr(i+1), RecentFiles[i])
4060 else
4061 config.WriteStr('RecentFiles', IntToStr(i+1), '');
4062 RecentFiles.Free();
4064 config.SaveFile(EditorDir+'Editor.cfg');
4065 config.Free();
4067 slInvalidTextures.Free;
4068 end;
4070 procedure TMainForm.RenderPanelResize(Sender: TObject);
4071 begin
4072 if MainForm.Visible then
4073 MainForm.Resize();
4074 end;
4076 procedure TMainForm.aMapOptionsExecute(Sender: TObject);
4077 var
4078 ResName: String;
4079 begin
4080 MapOptionsForm.ShowModal();
4082 ResName := OpenedMap;
4083 while (Pos(':\', ResName) > 0) do
4084 Delete(ResName, 1, Pos(':\', ResName) + 1);
4086 UpdateCaption(gMapInfo.Name, ExtractFileName(OpenedWAD), ResName);
4087 end;
4089 procedure TMainForm.aAboutExecute(Sender: TObject);
4090 begin
4091 AboutForm.ShowModal();
4092 end;
4094 procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
4095 Shift: TShiftState);
4096 var
4097 dx, dy, i: Integer;
4098 FileName: String;
4099 begin
4100 if (not EditingProperties) then
4101 begin
4102 if Key = Ord('1') then
4103 SwitchLayer(LAYER_BACK);
4104 if Key = Ord('2') then
4105 SwitchLayer(LAYER_WALLS);
4106 if Key = Ord('3') then
4107 SwitchLayer(LAYER_FOREGROUND);
4108 if Key = Ord('4') then
4109 SwitchLayer(LAYER_STEPS);
4110 if Key = Ord('5') then
4111 SwitchLayer(LAYER_WATER);
4112 if Key = Ord('6') then
4113 SwitchLayer(LAYER_ITEMS);
4114 if Key = Ord('7') then
4115 SwitchLayer(LAYER_MONSTERS);
4116 if Key = Ord('8') then
4117 SwitchLayer(LAYER_AREAS);
4118 if Key = Ord('9') then
4119 SwitchLayer(LAYER_TRIGGERS);
4120 if Key = Ord('0') then
4121 tbShowClick(tbShow);
4123 if Key = Ord('V') then
4124 begin // Поворот монстров и областей:
4125 if (SelectedObjects <> nil) then
4126 begin
4127 for i := 0 to High(SelectedObjects) do
4128 if (SelectedObjects[i].Live) then
4129 begin
4130 if (SelectedObjects[i].ObjectType = OBJECT_MONSTER) then
4131 begin
4132 g_ChangeDir(gMonsters[SelectedObjects[i].ID].Direction);
4133 end
4134 else
4135 if (SelectedObjects[i].ObjectType = OBJECT_AREA) then
4136 begin
4137 g_ChangeDir(gAreas[SelectedObjects[i].ID].Direction);
4138 end;
4139 end;
4140 end
4141 else
4142 begin
4143 if pcObjects.ActivePage = tsMonsters then
4144 begin
4145 if rbMonsterLeft.Checked then
4146 rbMonsterRight.Checked := True
4147 else
4148 rbMonsterLeft.Checked := True;
4149 end;
4150 if pcObjects.ActivePage = tsAreas then
4151 begin
4152 if rbAreaLeft.Checked then
4153 rbAreaRight.Checked := True
4154 else
4155 rbAreaLeft.Checked := True;
4156 end;
4157 end;
4158 end;
4160 if not (ssCtrl in Shift) then
4161 begin
4162 // Вертикальный скролл карты:
4163 with sbVertical do
4164 begin
4165 if Key = Ord('W') then
4166 begin
4167 Position := IfThen(Position > DotStep, Position-DotStep, 0);
4168 MapOffset.Y := -Round(Position/16) * 16;
4169 end;
4171 if Key = Ord('S') then
4172 begin
4173 Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
4174 MapOffset.Y := -Round(Position/16) * 16;
4175 end;
4176 end;
4178 // Горизонтальный скролл карты:
4179 with sbHorizontal do
4180 begin
4181 if Key = Ord('A') then
4182 begin
4183 Position := IfThen(Position > DotStep, Position-DotStep, 0);
4184 MapOffset.X := -Round(Position/16) * 16;
4185 end;
4187 if Key = Ord('D') then
4188 begin
4189 Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
4190 MapOffset.X := -Round(Position/16) * 16;
4191 end;
4192 end;
4193 end;
4194 end;
4196 // Удалить выделенные объекты:
4197 if (Key = VK_DELETE) and (SelectedObjects <> nil) and
4198 RenderPanel.Focused() then
4199 DeleteSelectedObjects();
4201 // Снять выделение:
4202 if (Key = VK_ESCAPE) and (SelectedObjects <> nil) then
4203 RemoveSelectFromObjects();
4205 // Передвинуть объекты:
4206 if MainForm.ActiveControl = RenderPanel then
4207 begin
4208 dx := 0;
4209 dy := 0;
4211 if Key = VK_NUMPAD4 then
4212 dx := IfThen(ssAlt in Shift, -1, -DotStep);
4213 if Key = VK_NUMPAD6 then
4214 dx := IfThen(ssAlt in Shift, 1, DotStep);
4215 if Key = VK_NUMPAD8 then
4216 dy := IfThen(ssAlt in Shift, -1, -DotStep);
4217 if Key = VK_NUMPAD5 then
4218 dy := IfThen(ssAlt in Shift, 1, DotStep);
4220 if (dx <> 0) or (dy <> 0) then
4221 begin
4222 MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift, dx, dy);
4223 Key := 0;
4224 end;
4225 end;
4227 if ssCtrl in Shift then
4228 begin
4229 // Выбор панели с текстурой для триггера
4230 if Key = Ord('T') then
4231 begin
4232 DrawPressRect := False;
4233 if SelectFlag = SELECTFLAG_TEXTURE then
4234 begin
4235 SelectFlag := SELECTFLAG_NONE;
4236 Exit;
4237 end;
4238 vleObjectProperty.FindRow(_lc[I_PROP_TR_TEXTURE_PANEL], i);
4239 if i > 0 then
4240 SelectFlag := SELECTFLAG_TEXTURE;
4241 end;
4243 if Key = Ord('D') then
4244 begin
4245 SelectFlag := SELECTFLAG_NONE;
4246 if DrawPressRect then
4247 begin
4248 DrawPressRect := False;
4249 Exit;
4250 end;
4252 // Выбор области воздействия, в зависимости от типа триггера
4253 vleObjectProperty.FindRow(_lc[I_PROP_TR_EX_AREA], i);
4254 if i > 0 then
4255 begin
4256 DrawPressRect := True;
4257 Exit;
4258 end;
4259 vleObjectProperty.FindRow(_lc[I_PROP_TR_DOOR_PANEL], i);
4260 if i <= 0 then
4261 vleObjectProperty.FindRow(_lc[I_PROP_TR_TRAP_PANEL], i);
4262 if i > 0 then
4263 begin
4264 SelectFlag := SELECTFLAG_DOOR;
4265 Exit;
4266 end;
4267 vleObjectProperty.FindRow(_lc[I_PROP_TR_LIFT_PANEL], i);
4268 if i > 0 then
4269 begin
4270 SelectFlag := SELECTFLAG_LIFT;
4271 Exit;
4272 end;
4273 vleObjectProperty.FindRow(_lc[I_PROP_TR_TELEPORT_TO], i);
4274 if i > 0 then
4275 begin
4276 SelectFlag := SELECTFLAG_TELEPORT;
4277 Exit;
4278 end;
4279 vleObjectProperty.FindRow(_lc[I_PROP_TR_SPAWN_TO], i);
4280 if i > 0 then
4281 begin
4282 SelectFlag := SELECTFLAG_SPAWNPOINT;
4283 Exit;
4284 end;
4286 // Выбор основного параметра, в зависимости от типа триггера
4287 vleObjectProperty.FindRow(_lc[I_PROP_TR_NEXT_MAP], i);
4288 if i > 0 then
4289 begin
4290 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
4291 SelectMapForm.GetMaps(FileName);
4293 if SelectMapForm.ShowModal() = mrOK then
4294 begin
4295 vleObjectProperty.Cells[1, i] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
4296 bApplyProperty.Click();
4297 end;
4298 Exit;
4299 end;
4300 vleObjectProperty.FindRow(_lc[I_PROP_TR_SOUND_NAME], i);
4301 if i <= 0 then
4302 vleObjectProperty.FindRow(_lc[I_PROP_TR_MUSIC_NAME], i);
4303 if i > 0 then
4304 begin
4305 AddSoundForm.OKFunction := nil;
4306 AddSoundForm.lbResourcesList.MultiSelect := False;
4307 AddSoundForm.SetResource := utf2win(vleObjectProperty.Cells[1, i]);
4309 if (AddSoundForm.ShowModal() = mrOk) then
4310 begin
4311 vleObjectProperty.Cells[1, i] := win2utf(AddSoundForm.ResourceName);
4312 bApplyProperty.Click();
4313 end;
4314 Exit;
4315 end;
4316 vleObjectProperty.FindRow(_lc[I_PROP_TR_PUSH_ANGLE], i);
4317 if i <= 0 then
4318 vleObjectProperty.FindRow(_lc[I_PROP_TR_MESSAGE_TEXT], i);
4319 if i > 0 then
4320 begin
4321 vleObjectProperty.Row := i;
4322 vleObjectProperty.SetFocus();
4323 Exit;
4324 end;
4325 end;
4326 end;
4327 end;
4329 procedure TMainForm.aOptimizeExecute(Sender: TObject);
4330 begin
4331 RemoveSelectFromObjects();
4332 MapOptimizationForm.ShowModal();
4333 end;
4335 procedure TMainForm.aCheckMapExecute(Sender: TObject);
4336 begin
4337 MapCheckForm.ShowModal();
4338 end;
4340 procedure TMainForm.bbAddTextureClick(Sender: TObject);
4341 begin
4342 AddTextureForm.lbResourcesList.MultiSelect := True;
4343 AddTextureForm.ShowModal();
4344 end;
4346 procedure TMainForm.lbTextureListClick(Sender: TObject);
4347 var
4348 TextureID: DWORD;
4349 TextureWidth, TextureHeight: Word;
4350 begin
4351 if (lbTextureList.ItemIndex <> -1) and
4352 (not IsSpecialTextureSel()) then
4353 begin
4354 if g_GetTexture(SelectedTexture(), TextureID) then
4355 begin
4356 g_GetTextureSizeByID(TextureID, TextureWidth, TextureHeight);
4358 lTextureWidth.Caption := IntToStr(TextureWidth);
4359 lTextureHeight.Caption := IntToStr(TextureHeight);
4360 end else
4361 begin
4362 lTextureWidth.Caption := _lc[I_NOT_ACCESSIBLE];
4363 lTextureHeight.Caption := _lc[I_NOT_ACCESSIBLE];
4364 end;
4365 end
4366 else
4367 begin
4368 lTextureWidth.Caption := '';
4369 lTextureHeight.Caption := '';
4370 end;
4371 end;
4373 procedure TMainForm.vleObjectPropertyGetPickList(Sender: TObject;
4374 const KeyName: String; Values: TStrings);
4375 begin
4376 if vleObjectProperty.ItemProps[KeyName].EditStyle = esPickList then
4377 begin
4378 if KeyName = _lc[I_PROP_DIRECTION] then
4379 begin
4380 Values.Add(DirNames[D_LEFT]);
4381 Values.Add(DirNames[D_RIGHT]);
4382 end
4383 else if KeyName = _lc[I_PROP_TR_TELEPORT_DIR] then
4384 begin
4385 Values.Add(DirNamesAdv[0]);
4386 Values.Add(DirNamesAdv[1]);
4387 Values.Add(DirNamesAdv[2]);
4388 Values.Add(DirNamesAdv[3]);
4389 end
4390 else if KeyName = _lc[I_PROP_TR_MUSIC_ACT] then
4391 begin
4392 Values.Add(_lc[I_PROP_TR_MUSIC_ON]);
4393 Values.Add(_lc[I_PROP_TR_MUSIC_OFF]);
4394 end
4395 else if KeyName = _lc[I_PROP_TR_MONSTER_BEHAVIOUR] then
4396 begin
4397 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_0]);
4398 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_1]);
4399 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_2]);
4400 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_3]);
4401 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_4]);
4402 Values.Add(_lc[I_PROP_TR_MONSTER_BEHAVIOUR_5]);
4403 end
4404 else if KeyName = _lc[I_PROP_TR_SCORE_ACT] then
4405 begin
4406 Values.Add(_lc[I_PROP_TR_SCORE_ACT_0]);
4407 Values.Add(_lc[I_PROP_TR_SCORE_ACT_1]);
4408 Values.Add(_lc[I_PROP_TR_SCORE_ACT_2]);
4409 Values.Add(_lc[I_PROP_TR_SCORE_ACT_3]);
4410 end
4411 else if KeyName = _lc[I_PROP_TR_SCORE_TEAM] then
4412 begin
4413 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_0]);
4414 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_1]);
4415 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_2]);
4416 Values.Add(_lc[I_PROP_TR_SCORE_TEAM_3]);
4417 end
4418 else if KeyName = _lc[I_PROP_TR_MESSAGE_KIND] then
4419 begin
4420 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_0]);
4421 Values.Add(_lc[I_PROP_TR_MESSAGE_KIND_1]);
4422 end
4423 else if KeyName = _lc[I_PROP_TR_MESSAGE_TO] then
4424 begin
4425 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_0]);
4426 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_1]);
4427 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_2]);
4428 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_3]);
4429 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_4]);
4430 Values.Add(_lc[I_PROP_TR_MESSAGE_TO_5]);
4431 end
4432 else if KeyName = _lc[I_PROP_TR_SHOT_TO] then
4433 begin
4434 Values.Add(_lc[I_PROP_TR_SHOT_TO_0]);
4435 Values.Add(_lc[I_PROP_TR_SHOT_TO_1]);
4436 Values.Add(_lc[I_PROP_TR_SHOT_TO_2]);
4437 Values.Add(_lc[I_PROP_TR_SHOT_TO_3]);
4438 Values.Add(_lc[I_PROP_TR_SHOT_TO_4]);
4439 Values.Add(_lc[I_PROP_TR_SHOT_TO_5]);
4440 Values.Add(_lc[I_PROP_TR_SHOT_TO_6]);
4441 end
4442 else if KeyName = _lc[I_PROP_TR_SHOT_AIM] then
4443 begin
4444 Values.Add(_lc[I_PROP_TR_SHOT_AIM_0]);
4445 Values.Add(_lc[I_PROP_TR_SHOT_AIM_1]);
4446 Values.Add(_lc[I_PROP_TR_SHOT_AIM_2]);
4447 Values.Add(_lc[I_PROP_TR_SHOT_AIM_3]);
4448 end
4449 else if (KeyName = _lc[I_PROP_PANEL_BLEND]) or
4450 (KeyName = _lc[I_PROP_DM_ONLY]) or
4451 (KeyName = _lc[I_PROP_ITEM_FALLS]) or
4452 (KeyName = _lc[I_PROP_TR_ENABLED]) or
4453 (KeyName = _lc[I_PROP_TR_D2D]) or
4454 (KeyName = _lc[I_PROP_TR_SILENT]) or
4455 (KeyName = _lc[I_PROP_TR_TELEPORT_SILENT]) or
4456 (KeyName = _lc[I_PROP_TR_EX_RANDOM]) or
4457 (KeyName = _lc[I_PROP_TR_TEXTURE_ONCE]) or
4458 (KeyName = _lc[I_PROP_TR_TEXTURE_ANIM_ONCE]) or
4459 (KeyName = _lc[I_PROP_TR_SOUND_LOCAL]) or
4460 (KeyName = _lc[I_PROP_TR_SOUND_SWITCH]) or
4461 (KeyName = _lc[I_PROP_TR_MONSTER_ACTIVE]) or
4462 (KeyName = _lc[I_PROP_TR_PUSH_RESET]) or
4463 (KeyName = _lc[I_PROP_TR_SCORE_CON]) or
4464 (KeyName = _lc[I_PROP_TR_SCORE_MSG]) or
4465 (KeyName = _lc[I_PROP_TR_HEALTH_MAX]) or
4466 (KeyName = _lc[I_PROP_TR_SHOT_SOUND]) or
4467 (KeyName = _lc[I_PROP_TR_EFFECT_CENTER]) then
4468 begin
4469 Values.Add(BoolNames[True]);
4470 Values.Add(BoolNames[False]);
4471 end;
4472 end;
4473 end;
4475 procedure TMainForm.bApplyPropertyClick(Sender: TObject);
4476 var
4477 _id, a, r, c: Integer;
4478 s: String;
4479 res: Boolean;
4480 NoTextureID: DWORD;
4481 NW, NH: Word;
4482 begin
4483 if SelectedObjectCount() <> 1 then
4484 Exit;
4485 if not SelectedObjects[GetFirstSelected()].Live then
4486 Exit;
4488 try
4489 if not CheckProperty() then
4490 Exit;
4491 except
4492 Exit;
4493 end;
4495 _id := GetFirstSelected();
4497 r := vleObjectProperty.Row;
4498 c := vleObjectProperty.Col;
4500 case SelectedObjects[_id].ObjectType of
4501 OBJECT_PANEL:
4502 begin
4503 with gPanels[SelectedObjects[_id].ID] do
4504 begin
4505 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4506 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4507 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4508 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4510 PanelType := GetPanelType(vleObjectProperty.Values[_lc[I_PROP_PANEL_TYPE]]);
4512 // Сброс ссылки на триггеры смены текстуры:
4513 if not WordBool(PanelType and (PANEL_WALL or PANEL_FORE or PANEL_BACK)) then
4514 if gTriggers <> nil then
4515 for a := 0 to High(gTriggers) do
4516 begin
4517 if (gTriggers[a].TriggerType <> 0) and
4518 (gTriggers[a].TexturePanel = Integer(SelectedObjects[_id].ID)) then
4519 gTriggers[a].TexturePanel := -1;
4520 if (gTriggers[a].TriggerType = TRIGGER_SHOT) and
4521 (gTriggers[a].Data.ShotPanelID = Integer(SelectedObjects[_id].ID)) then
4522 gTriggers[a].Data.ShotPanelID := -1;
4523 end;
4525 // Сброс ссылки на триггеры лифта:
4526 if not WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
4527 if gTriggers <> nil then
4528 for a := 0 to High(gTriggers) do
4529 if (gTriggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
4530 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4531 gTriggers[a].Data.PanelID := -1;
4533 // Сброс ссылки на триггеры двери:
4534 if not WordBool(PanelType and (PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
4535 if gTriggers <> nil then
4536 for a := 0 to High(gTriggers) do
4537 if (gTriggers[a].TriggerType in [TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
4538 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP]) and
4539 (gTriggers[a].Data.PanelID = Integer(SelectedObjects[_id].ID)) then
4540 gTriggers[a].Data.PanelID := -1;
4542 if IsTexturedPanel(PanelType) then
4543 begin // Может быть текстура
4544 if TextureName <> '' then
4545 begin // Была текстура
4546 Alpha := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_PANEL_ALPHA]]));
4547 Blending := NameToBool(vleObjectProperty.Values[_lc[I_PROP_PANEL_BLEND]]);
4548 end
4549 else // Не было
4550 begin
4551 Alpha := 0;
4552 Blending := False;
4553 end;
4555 // Новая текстура:
4556 TextureName := vleObjectProperty.Values[_lc[I_PROP_PANEL_TEX]];
4558 if TextureName <> '' then
4559 begin // Есть текстура
4560 // Обычная текстура:
4561 if not IsSpecialTexture(TextureName) then
4562 begin
4563 g_GetTextureSizeByName(TextureName,
4564 TextureWidth, TextureHeight);
4566 // Проверка кратности размеров панели:
4567 res := True;
4568 if TextureWidth <> 0 then
4569 if gPanels[SelectedObjects[_id].ID].Width mod TextureWidth <> 0 then
4570 begin
4571 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXWIDTH],
4572 [TextureWidth]));
4573 Res := False;
4574 end;
4575 if Res and (TextureHeight <> 0) then
4576 if gPanels[SelectedObjects[_id].ID].Height mod TextureHeight <> 0 then
4577 begin
4578 ErrorMessageBox(Format(_lc[I_MSG_WRONG_TEXHEIGHT],
4579 [TextureHeight]));
4580 Res := False;
4581 end;
4583 if Res then
4584 begin
4585 if not g_GetTexture(TextureName, TextureID) then
4586 // Не удалось загрузить текстуру, рисуем NOTEXTURE
4587 if g_GetTexture('NOTEXTURE', NoTextureID) then
4588 begin
4589 TextureID := TEXTURE_SPECIAL_NOTEXTURE;
4590 g_GetTextureSizeByID(NoTextureID, NW, NH);
4591 TextureWidth := NW;
4592 TextureHeight := NH;
4593 end else
4594 begin
4595 TextureID := TEXTURE_SPECIAL_NONE;
4596 TextureWidth := 1;
4597 TextureHeight := 1;
4598 end;
4599 end
4600 else
4601 begin
4602 TextureName := '';
4603 TextureWidth := 1;
4604 TextureHeight := 1;
4605 TextureID := TEXTURE_SPECIAL_NONE;
4606 end;
4607 end
4608 else // Спец.текстура
4609 begin
4610 TextureHeight := 1;
4611 TextureWidth := 1;
4612 TextureID := SpecialTextureID(TextureName);
4613 end;
4614 end
4615 else // Нет текстуры
4616 begin
4617 TextureWidth := 1;
4618 TextureHeight := 1;
4619 TextureID := TEXTURE_SPECIAL_NONE;
4620 end;
4621 end
4622 else // Не может быть текстуры
4623 begin
4624 Alpha := 0;
4625 Blending := False;
4626 TextureName := '';
4627 TextureWidth := 1;
4628 TextureHeight := 1;
4629 TextureID := TEXTURE_SPECIAL_NONE;
4630 end;
4631 end;
4632 end;
4634 OBJECT_ITEM:
4635 begin
4636 with gItems[SelectedObjects[_id].ID] do
4637 begin
4638 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4639 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4640 OnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
4641 Fall := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
4642 end;
4643 end;
4645 OBJECT_MONSTER:
4646 begin
4647 with gMonsters[SelectedObjects[_id].ID] do
4648 begin
4649 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4650 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4651 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
4652 end;
4653 end;
4655 OBJECT_AREA:
4656 begin
4657 with gAreas[SelectedObjects[_id].ID] do
4658 begin
4659 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4660 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4661 Direction := NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]);
4662 end;
4663 end;
4665 OBJECT_TRIGGER:
4666 begin
4667 with gTriggers[SelectedObjects[_id].ID] do
4668 begin
4669 X := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_X]]));
4670 Y := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_Y]]));
4671 Width := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_WIDTH]]));
4672 Height := StrToInt(Trim(vleObjectProperty.Values[_lc[I_PROP_HEIGHT]]));
4673 Enabled := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_ENABLED]]);
4674 ActivateType := StrToActivate(vleObjectProperty.Values[_lc[I_PROP_TR_ACTIVATION]]);
4675 Key := StrToKey(vleObjectProperty.Values[_lc[I_PROP_TR_KEYS]]);
4677 case TriggerType of
4678 TRIGGER_EXIT:
4679 begin
4680 s := vleObjectProperty.Values[_lc[I_PROP_TR_NEXT_MAP]];
4681 FillByte(Data.MapName[0], 16, 0);
4682 if s <> '' then
4683 Move(Data.MapName[0], s[1], Min(Length(s), 16));
4684 end;
4686 TRIGGER_TEXTURE:
4687 begin
4688 Data.ActivateOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ONCE]]);
4689 Data.AnimOnce := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TEXTURE_ANIM_ONCE]]);
4690 end;
4692 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
4693 begin
4694 Data.Wait := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 65535);
4695 Data.Count := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_COUNT]], 0), 65535);
4696 if Data.Count < 1 then
4697 Data.Count := 1;
4698 if TriggerType = TRIGGER_PRESS then
4699 Data.ExtRandom := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EX_RANDOM]]);
4700 end;
4702 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
4703 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP, TRIGGER_LIFTDOWN,
4704 TRIGGER_LIFT:
4705 begin
4706 Data.NoSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
4707 Data.d2d_doors := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
4708 end;
4710 TRIGGER_TELEPORT:
4711 begin
4712 Data.d2d_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_D2D]]);
4713 Data.silent_teleport := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_SILENT]]);
4714 Data.TlpDir := NameToDirAdv(vleObjectProperty.Values[_lc[I_PROP_TR_TELEPORT_DIR]]);
4715 end;
4717 TRIGGER_SOUND:
4718 begin
4719 s := vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_NAME]];
4720 FillByte(Data.SoundName[0], 64, 0);
4721 if s <> '' then
4722 Move(Data.SoundName[0], s[1], Min(Length(s), 64));
4724 Data.Volume := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_VOLUME]], 0), 255);
4725 Data.Pan := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_PAN]], 0), 255);
4726 Data.PlayCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_COUNT]], 0), 255);
4727 Data.Local := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_LOCAL]]);
4728 Data.SoundSwitch := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SOUND_SWITCH]]);
4729 end;
4731 TRIGGER_SPAWNMONSTER:
4732 begin
4733 Data.MonType := StrToMonster(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_TYPE]]);
4734 Data.MonDir := Byte(NameToDir(vleObjectProperty.Values[_lc[I_PROP_DIRECTION]]));
4735 Data.MonHealth := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 1000000);
4736 if Data.MonHealth < 0 then
4737 Data.MonHealth := 0;
4738 Data.MonActive := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_ACTIVE]]);
4739 Data.MonCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
4740 if Data.MonCount < 1 then
4741 Data.MonCount := 1;
4742 Data.MonEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
4743 Data.MonMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
4744 Data.MonDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
4745 Data.MonBehav := 0;
4746 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_1] then
4747 Data.MonBehav := 1;
4748 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_2] then
4749 Data.MonBehav := 2;
4750 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_3] then
4751 Data.MonBehav := 3;
4752 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_4] then
4753 Data.MonBehav := 4;
4754 if vleObjectProperty.Values[_lc[I_PROP_TR_MONSTER_BEHAVIOUR]] = _lc[I_PROP_TR_MONSTER_BEHAVIOUR_5] then
4755 Data.MonBehav := 5;
4756 end;
4758 TRIGGER_SPAWNITEM:
4759 begin
4760 Data.ItemType := StrToItem(vleObjectProperty.Values[_lc[I_PROP_TR_ITEM_TYPE]]);
4761 Data.ItemOnlyDM := NameToBool(vleObjectProperty.Values[_lc[I_PROP_DM_ONLY]]);
4762 Data.ItemFalls := NameToBool(vleObjectProperty.Values[_lc[I_PROP_ITEM_FALLS]]);
4763 Data.ItemCount := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 64);
4764 if Data.ItemCount < 1 then
4765 Data.ItemCount := 1;
4766 Data.ItemEffect := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_FX_TYPE]]);
4767 Data.ItemMax := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_MAX]], 0), 65535);
4768 Data.ItemDelay := Min(StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SPAWN_DELAY]], 0), 65535);
4769 end;
4771 TRIGGER_MUSIC:
4772 begin
4773 s := vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_NAME]];
4774 FillByte(Data.MusicName[0], 64, 0);
4775 if s <> '' then
4776 Move(Data.MusicName[0], s[1], Min(Length(s), 64));
4778 if vleObjectProperty.Values[_lc[I_PROP_TR_MUSIC_ACT]] = _lc[I_PROP_TR_MUSIC_ON] then
4779 Data.MusicAction := 1
4780 else
4781 Data.MusicAction := 2;
4782 end;
4784 TRIGGER_PUSH:
4785 begin
4786 Data.PushAngle := Min(
4787 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_ANGLE]], 0), 360);
4788 Data.PushForce := Min(
4789 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_FORCE]], 0), 255);
4790 Data.ResetVel := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_PUSH_RESET]]);
4791 end;
4793 TRIGGER_SCORE:
4794 begin
4795 Data.ScoreAction := 0;
4796 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_1] then
4797 Data.ScoreAction := 1
4798 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_2] then
4799 Data.ScoreAction := 2
4800 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_ACT]] = _lc[I_PROP_TR_SCORE_ACT_3] then
4801 Data.ScoreAction := 3;
4802 Data.ScoreCount := Min(Max(
4803 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
4804 Data.ScoreTeam := 0;
4805 if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_1] then
4806 Data.ScoreTeam := 1
4807 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_2] then
4808 Data.ScoreTeam := 2
4809 else if vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_TEAM]] = _lc[I_PROP_TR_SCORE_TEAM_3] then
4810 Data.ScoreTeam := 3;
4811 Data.ScoreCon := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_CON]]);
4812 Data.ScoreMsg := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SCORE_MSG]]);
4813 end;
4815 TRIGGER_MESSAGE:
4816 begin
4817 Data.MessageKind := 0;
4818 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_KIND]] = _lc[I_PROP_TR_MESSAGE_KIND_1] then
4819 Data.MessageKind := 1;
4821 Data.MessageSendTo := 0;
4822 if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_1] then
4823 Data.MessageSendTo := 1
4824 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_2] then
4825 Data.MessageSendTo := 2
4826 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_3] then
4827 Data.MessageSendTo := 3
4828 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_4] then
4829 Data.MessageSendTo := 4
4830 else if vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TO]] = _lc[I_PROP_TR_MESSAGE_TO_5] then
4831 Data.MessageSendTo := 5;
4833 s := vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TEXT]];
4834 FillByte(Data.MessageText[0], 100, 0);
4835 if s <> '' then
4836 Move(Data.MessageText[0], s[1], Min(Length(s), 100));
4838 Data.MessageTime := Min(Max(
4839 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_MESSAGE_TIME]], 0), 0), 65535);
4840 end;
4842 TRIGGER_DAMAGE:
4843 begin
4844 Data.DamageValue := Min(Max(
4845 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_DAMAGE_VALUE]], 0), 0), 65535);
4846 Data.DamageInterval := Min(Max(
4847 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
4848 end;
4850 TRIGGER_HEALTH:
4851 begin
4852 Data.HealValue := Min(Max(
4853 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH]], 0), 0), 65535);
4854 Data.HealInterval := Min(Max(
4855 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_INTERVAL]], 0), 0), 65535);
4856 Data.HealMax := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_HEALTH_MAX]]);
4857 Data.HealSilent := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SILENT]]);
4858 end;
4860 TRIGGER_SHOT:
4861 begin
4862 Data.ShotType := StrToShot(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TYPE]]);
4863 Data.ShotSound := NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SOUND]]);
4864 Data.ShotTarget := 0;
4865 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_1] then
4866 Data.ShotTarget := 1
4867 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_2] then
4868 Data.ShotTarget := 2
4869 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_3] then
4870 Data.ShotTarget := 3
4871 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_4] then
4872 Data.ShotTarget := 4
4873 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_5] then
4874 Data.ShotTarget := 5
4875 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_TO]] = _lc[I_PROP_TR_SHOT_TO_6] then
4876 Data.ShotTarget := 6;
4877 Data.ShotIntSight := Min(Max(
4878 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_SIGHT]], 0), 0), 65535);
4879 Data.ShotAim := 0;
4880 if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_1] then
4881 Data.ShotAim := 1
4882 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_2] then
4883 Data.ShotAim := 2
4884 else if vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AIM]] = _lc[I_PROP_TR_SHOT_AIM_3] then
4885 Data.ShotAim := 3;
4886 Data.ShotAngle := Min(
4887 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ANGLE]], 0), 360);
4888 Data.ShotWait := Min(Max(
4889 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
4890 Data.ShotAccuracy := Min(Max(
4891 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_ACC]], 0), 0), 65535);
4892 Data.ShotAmmo := Min(Max(
4893 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_AMMO]], 0), 0), 65535);
4894 Data.ShotIntReload := Min(Max(
4895 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_SHOT_RELOAD]], 0), 0), 65535);
4896 end;
4898 TRIGGER_EFFECT:
4899 begin
4900 Data.FXCount := Min(Max(
4901 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_COUNT]], 0), 0), 255);
4902 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_PARTICLE] then
4903 begin
4904 Data.FXType := TRIGGER_EFFECT_PARTICLE;
4905 Data.FXSubType := TRIGGER_EFFECT_SLIQUID;
4906 if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SLIQUID] then
4907 Data.FXSubType := TRIGGER_EFFECT_SLIQUID
4908 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
4909 Data.FXSubType := TRIGGER_EFFECT_LLIQUID
4910 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
4911 Data.FXSubType := TRIGGER_EFFECT_DLIQUID
4912 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BLOOD] then
4913 Data.FXSubType := TRIGGER_EFFECT_BLOOD
4914 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_SPARK] then
4915 Data.FXSubType := TRIGGER_EFFECT_SPARK
4916 else if vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
4917 Data.FXSubType := TRIGGER_EFFECT_BUBBLE;
4918 end else
4919 begin
4920 Data.FXType := TRIGGER_EFFECT_ANIMATION;
4921 Data.FXSubType := StrToEffect(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SUBTYPE]]);
4922 end;
4923 a := Min(Max(
4924 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_COLOR]], 0), 0), $FFFFFF);
4925 Data.FXColorR := a and $FF;
4926 Data.FXColorG := (a shr 8) and $FF;
4927 Data.FXColorB := (a shr 16) and $FF;
4928 if NameToBool(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_CENTER]]) then
4929 Data.FXPos := 0
4930 else
4931 Data.FXPos := 1;
4932 Data.FXWait := Min(Max(
4933 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EX_DELAY]], 0), 0), 65535);
4934 Data.FXVelX := Min(Max(
4935 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELX]], 0), -128), 127);
4936 Data.FXVelY := Min(Max(
4937 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_VELY]], 0), -128), 127);
4938 Data.FXSpreadL := Min(Max(
4939 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPL]], 0), 0), 255);
4940 Data.FXSpreadR := Min(Max(
4941 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPR]], 0), 0), 255);
4942 Data.FXSpreadU := Min(Max(
4943 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPU]], 0), 0), 255);
4944 Data.FXSpreadD := Min(Max(
4945 StrToIntDef(vleObjectProperty.Values[_lc[I_PROP_TR_EFFECT_SPD]], 0), 0), 255);
4946 end;
4947 end;
4948 end;
4949 end;
4950 end;
4952 FillProperty();
4954 vleObjectProperty.Row := r;
4955 vleObjectProperty.Col := c;
4956 end;
4958 procedure TMainForm.bbRemoveTextureClick(Sender: TObject);
4959 var
4960 a, i: Integer;
4961 begin
4962 i := lbTextureList.ItemIndex;
4963 if i = -1 then
4964 Exit;
4966 if MessageBox(0, PChar(Format(_lc[I_MSG_DEL_TEXTURE_PROMT],
4967 [SelectedTexture()])),
4968 PChar(_lc[I_MSG_DEL_TEXTURE]),
4969 MB_ICONQUESTION or MB_YESNO or
4970 MB_DEFBUTTON1) <> idYes then
4971 Exit;
4973 if gPanels <> nil then
4974 for a := 0 to High(gPanels) do
4975 if (gPanels[a].PanelType <> 0) and
4976 (gPanels[a].TextureName = SelectedTexture()) then
4977 begin
4978 ErrorMessageBox(_lc[I_MSG_DEL_TEXTURE_CANT]);
4979 Exit;
4980 end;
4982 g_DeleteTexture(SelectedTexture());
4983 i := slInvalidTextures.IndexOf(lbTextureList.Items[i]);
4984 if i > -1 then
4985 slInvalidTextures.Delete(i);
4986 if lbTextureList.ItemIndex > -1 then
4987 lbTextureList.Items.Delete(lbTextureList.ItemIndex)
4988 end;
4990 procedure TMainForm.aNewMapExecute(Sender: TObject);
4991 begin
4992 if (MessageBox(0, PChar(_lc[I_MSG_CLEAR_MAP_PROMT]),
4993 PChar(_lc[I_MSG_CLEAR_MAP]),
4994 MB_ICONQUESTION or MB_YESNO or
4995 MB_DEFBUTTON1) = mrYes) then
4996 FullClear();
4997 end;
4999 procedure TMainForm.aUndoExecute(Sender: TObject);
5000 var
5001 a: Integer;
5002 begin
5003 if UndoBuffer = nil then
5004 Exit;
5005 if UndoBuffer[High(UndoBuffer)] = nil then
5006 Exit;
5008 for a := 0 to High(UndoBuffer[High(UndoBuffer)]) do
5009 with UndoBuffer[High(UndoBuffer)][a] do
5010 begin
5011 case UndoType of
5012 UNDO_DELETE_PANEL:
5013 begin
5014 AddPanel(Panel^);
5015 Panel := nil;
5016 end;
5017 UNDO_DELETE_ITEM: AddItem(Item);
5018 UNDO_DELETE_AREA: AddArea(Area);
5019 UNDO_DELETE_MONSTER: AddMonster(Monster);
5020 UNDO_DELETE_TRIGGER: AddTrigger(Trigger);
5021 UNDO_ADD_PANEL: RemoveObject(AddID, OBJECT_PANEL);
5022 UNDO_ADD_ITEM: RemoveObject(AddID, OBJECT_ITEM);
5023 UNDO_ADD_AREA: RemoveObject(AddID, OBJECT_AREA);
5024 UNDO_ADD_MONSTER: RemoveObject(AddID, OBJECT_MONSTER);
5025 UNDO_ADD_TRIGGER: RemoveObject(AddID, OBJECT_TRIGGER);
5026 end;
5027 end;
5029 SetLength(UndoBuffer, Length(UndoBuffer)-1);
5031 RemoveSelectFromObjects();
5033 miUndo.Enabled := UndoBuffer <> nil;
5034 end;
5037 procedure TMainForm.aCopyObjectExecute(Sender: TObject);
5038 var
5039 a, b: Integer;
5040 CopyBuffer: TCopyRecArray;
5041 str: String;
5042 ok: Boolean;
5044 function CB_Compare(I1, I2: TCopyRec): Integer;
5045 begin
5046 Result := Integer(I1.ObjectType) - Integer(I2.ObjectType);
5048 if Result = 0 then // Одного типа
5049 Result := Integer(I1.ID) - Integer(I2.ID);
5050 end;
5052 procedure QuickSortCopyBuffer(L, R: Integer);
5053 var
5054 I, J: Integer;
5055 P, T: TCopyRec;
5056 begin
5057 repeat
5058 I := L;
5059 J := R;
5060 P := CopyBuffer[(L + R) shr 1];
5062 repeat
5063 while CB_Compare(CopyBuffer[I], P) < 0 do
5064 Inc(I);
5065 while CB_Compare(CopyBuffer[J], P) > 0 do
5066 Dec(J);
5068 if I <= J then
5069 begin
5070 T := CopyBuffer[I];
5071 CopyBuffer[I] := CopyBuffer[J];
5072 CopyBuffer[J] := T;
5073 Inc(I);
5074 Dec(J);
5075 end;
5076 until I > J;
5078 if L < J then
5079 QuickSortCopyBuffer(L, J);
5081 L := I;
5082 until I >= R;
5083 end;
5085 begin
5086 if SelectedObjects = nil then
5087 Exit;
5089 b := -1;
5090 CopyBuffer := nil;
5092 // Копируем объекты:
5093 for a := 0 to High(SelectedObjects) do
5094 if SelectedObjects[a].Live then
5095 with SelectedObjects[a] do
5096 begin
5097 SetLength(CopyBuffer, Length(CopyBuffer)+1);
5098 b := High(CopyBuffer);
5099 CopyBuffer[b].ID := ID;
5100 CopyBuffer[b].Panel := nil;
5102 case ObjectType of
5103 OBJECT_PANEL:
5104 begin
5105 CopyBuffer[b].ObjectType := OBJECT_PANEL;
5106 New(CopyBuffer[b].Panel);
5107 CopyBuffer[b].Panel^ := gPanels[ID];
5108 end;
5110 OBJECT_ITEM:
5111 begin
5112 CopyBuffer[b].ObjectType := OBJECT_ITEM;
5113 CopyBuffer[b].Item := gItems[ID];
5114 end;
5116 OBJECT_MONSTER:
5117 begin
5118 CopyBuffer[b].ObjectType := OBJECT_MONSTER;
5119 CopyBuffer[b].Monster := gMonsters[ID];
5120 end;
5122 OBJECT_AREA:
5123 begin
5124 CopyBuffer[b].ObjectType := OBJECT_AREA;
5125 CopyBuffer[b].Area := gAreas[ID];
5126 end;
5128 OBJECT_TRIGGER:
5129 begin
5130 CopyBuffer[b].ObjectType := OBJECT_TRIGGER;
5131 CopyBuffer[b].Trigger := gTriggers[ID];
5132 end;
5133 end;
5134 end;
5136 // Сортировка по ID:
5137 if CopyBuffer <> nil then
5138 begin
5139 QuickSortCopyBuffer(0, b);
5140 end;
5142 // Пестановка ссылок триггеров:
5143 for a := 0 to Length(CopyBuffer)-1 do
5144 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5145 begin
5146 case CopyBuffer[a].Trigger.TriggerType of
5147 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5148 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5149 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5150 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5151 begin
5152 ok := False;
5154 for b := 0 to Length(CopyBuffer)-1 do
5155 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5156 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.PanelID) then
5157 begin
5158 CopyBuffer[a].Trigger.Data.PanelID := b;
5159 ok := True;
5160 Break;
5161 end;
5163 // Этих панелей нет среди копируемых:
5164 if not ok then
5165 CopyBuffer[a].Trigger.Data.PanelID := -1;
5166 end;
5168 TRIGGER_PRESS, TRIGGER_ON,
5169 TRIGGER_OFF, TRIGGER_ONOFF:
5170 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5171 begin
5172 ok := False;
5174 for b := 0 to Length(CopyBuffer)-1 do
5175 if (CopyBuffer[b].ObjectType = OBJECT_MONSTER) and
5176 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.MonsterID-1) then
5177 begin
5178 CopyBuffer[a].Trigger.Data.MonsterID := b+1;
5179 ok := True;
5180 Break;
5181 end;
5183 // Этих монстров нет среди копируемых:
5184 if not ok then
5185 CopyBuffer[a].Trigger.Data.MonsterID := 0;
5186 end;
5188 TRIGGER_SHOT:
5189 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5190 begin
5191 ok := False;
5193 for b := 0 to Length(CopyBuffer)-1 do
5194 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5195 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.Data.ShotPanelID) then
5196 begin
5197 CopyBuffer[a].Trigger.Data.ShotPanelID := b;
5198 ok := True;
5199 Break;
5200 end;
5202 // Этих панелей нет среди копируемых:
5203 if not ok then
5204 CopyBuffer[a].Trigger.Data.ShotPanelID := -1;
5205 end;
5206 end;
5208 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5209 begin
5210 ok := False;
5212 for b := 0 to Length(CopyBuffer)-1 do
5213 if (CopyBuffer[b].ObjectType = OBJECT_PANEL) and
5214 (Integer(CopyBuffer[b].ID) = CopyBuffer[a].Trigger.TexturePanel) then
5215 begin
5216 CopyBuffer[a].Trigger.TexturePanel := b;
5217 ok := True;
5218 Break;
5219 end;
5221 // Этих панелей нет среди копируемых:
5222 if not ok then
5223 CopyBuffer[a].Trigger.TexturePanel := -1;
5224 end;
5225 end;
5227 // В буфер обмена:
5228 str := CopyBufferToString(CopyBuffer);
5229 ClipBoard.AsText := str;
5231 for a := 0 to Length(CopyBuffer)-1 do
5232 if (CopyBuffer[a].ObjectType = OBJECT_PANEL) and
5233 (CopyBuffer[a].Panel <> nil) then
5234 Dispose(CopyBuffer[a].Panel);
5236 CopyBuffer := nil;
5237 end;
5239 procedure TMainForm.aPasteObjectExecute(Sender: TObject);
5240 var
5241 a, h: Integer;
5242 CopyBuffer: TCopyRecArray;
5243 res: Boolean;
5244 swad, ssec, sres: String;
5245 begin
5246 CopyBuffer := nil;
5248 StringToCopyBuffer(ClipBoard.AsText, CopyBuffer);
5250 if CopyBuffer = nil then
5251 Exit;
5253 RemoveSelectFromObjects();
5255 h := High(CopyBuffer);
5256 for a := 0 to h do
5257 with CopyBuffer[a] do
5258 begin
5259 case ObjectType of
5260 OBJECT_PANEL:
5261 if Panel <> nil then
5262 begin
5263 Panel^.X := Panel^.X + 16;
5264 Panel^.Y := Panel^.Y + 16;
5266 Panel^.TextureID := TEXTURE_SPECIAL_NONE;
5267 Panel^.TextureWidth := 1;
5268 Panel^.TextureHeight := 1;
5270 if (Panel^.PanelType = PANEL_LIFTUP) or
5271 (Panel^.PanelType = PANEL_LIFTDOWN) or
5272 (Panel^.PanelType = PANEL_LIFTLEFT) or
5273 (Panel^.PanelType = PANEL_LIFTRIGHT) or
5274 (Panel^.PanelType = PANEL_BLOCKMON) or
5275 (Panel^.TextureName = '') then
5276 begin // Нет или не может быть текстуры:
5277 end
5278 else // Есть текстура:
5279 begin
5280 // Обычная текстура:
5281 if not IsSpecialTexture(Panel^.TextureName) then
5282 begin
5283 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5285 if not res then
5286 begin
5287 g_ProcessResourceStr(Panel^.TextureName, swad, ssec, sres);
5288 AddTexture(swad, ssec, sres, True);
5289 res := g_GetTexture(Panel^.TextureName, Panel^.TextureID);
5290 end;
5292 if res then
5293 g_GetTextureSizeByName(Panel^.TextureName,
5294 Panel^.TextureWidth, Panel^.TextureHeight)
5295 else
5296 Panel^.TextureName := '';
5297 end
5298 else // Спец.текстура:
5299 begin
5300 Panel^.TextureID := SpecialTextureID(Panel^.TextureName);
5301 with MainForm.lbTextureList.Items do
5302 if IndexOf(win2utf(Panel^.TextureName)) = -1 then
5303 Add(win2utf(Panel^.TextureName));
5304 end;
5305 end;
5307 ID := AddPanel(Panel^);
5308 Dispose(Panel);
5309 Undo_Add(OBJECT_PANEL, ID, a > 0);
5310 SelectObject(OBJECT_PANEL, ID, True);
5311 end;
5313 OBJECT_ITEM:
5314 begin
5315 Item.X := Item.X + 16;
5316 Item.Y := Item.Y + 16;
5318 ID := AddItem(Item);
5319 Undo_Add(OBJECT_ITEM, ID, a > 0);
5320 SelectObject(OBJECT_ITEM, ID, True);
5321 end;
5323 OBJECT_MONSTER:
5324 begin
5325 Monster.X := Monster.X + 16;
5326 Monster.Y := Monster.Y + 16;
5328 ID := AddMonster(Monster);
5329 Undo_Add(OBJECT_MONSTER, ID, a > 0);
5330 SelectObject(OBJECT_MONSTER, ID, True);
5331 end;
5333 OBJECT_AREA:
5334 begin
5335 Area.X := Area.X + 16;
5336 Area.Y := Area.Y + 16;
5338 ID := AddArea(Area);
5339 Undo_Add(OBJECT_AREA, ID, a > 0);
5340 SelectObject(OBJECT_AREA, ID, True);
5341 end;
5343 OBJECT_TRIGGER:
5344 begin
5345 Trigger.X := Trigger.X + 16;
5346 Trigger.Y := Trigger.Y + 16;
5348 ID := AddTrigger(Trigger);
5349 Undo_Add(OBJECT_TRIGGER, ID, a > 0);
5350 SelectObject(OBJECT_TRIGGER, ID, True);
5351 end;
5352 end;
5353 end;
5355 // Переставляем ссылки триггеров:
5356 for a := 0 to High(CopyBuffer) do
5357 if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
5358 begin
5359 case CopyBuffer[a].Trigger.TriggerType of
5360 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5361 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5362 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5363 if CopyBuffer[a].Trigger.Data.PanelID <> -1 then
5364 gTriggers[CopyBuffer[a].ID].Data.PanelID :=
5365 CopyBuffer[CopyBuffer[a].Trigger.Data.PanelID].ID;
5367 TRIGGER_PRESS, TRIGGER_ON,
5368 TRIGGER_OFF, TRIGGER_ONOFF:
5369 if CopyBuffer[a].Trigger.Data.MonsterID <> 0 then
5370 gTriggers[CopyBuffer[a].ID].Data.MonsterID :=
5371 CopyBuffer[CopyBuffer[a].Trigger.Data.MonsterID-1].ID+1;
5373 TRIGGER_SHOT:
5374 if CopyBuffer[a].Trigger.Data.ShotPanelID <> -1 then
5375 gTriggers[CopyBuffer[a].ID].Data.ShotPanelID :=
5376 CopyBuffer[CopyBuffer[a].Trigger.Data.ShotPanelID].ID;
5377 end;
5379 if CopyBuffer[a].Trigger.TexturePanel <> -1 then
5380 gTriggers[CopyBuffer[a].ID].TexturePanel :=
5381 CopyBuffer[CopyBuffer[a].Trigger.TexturePanel].ID;
5382 end;
5384 CopyBuffer := nil;
5386 if h = 0 then
5387 FillProperty();
5388 end;
5390 procedure TMainForm.aCutObjectExecute(Sender: TObject);
5391 begin
5392 miCopy.Click();
5393 DeleteSelectedObjects();
5394 end;
5396 procedure TMainForm.vleObjectPropertyEditButtonClick(Sender: TObject);
5397 var
5398 Key, FileName: String;
5399 b: Byte;
5400 begin
5401 Key := vleObjectProperty.Keys[vleObjectProperty.Row];
5403 if Key = _lc[I_PROP_PANEL_TYPE] then
5404 begin
5405 with ChooseTypeForm, vleObjectProperty do
5406 begin // Выбор типа панели:
5407 Caption := _lc[I_PROP_PANEL_TYPE];
5408 lbTypeSelect.Items.Clear();
5410 for b := 0 to High(PANELNAMES) do
5411 begin
5412 lbTypeSelect.Items.Add(PANELNAMES[b]);
5413 if Values[Key] = PANELNAMES[b] then
5414 lbTypeSelect.ItemIndex := b;
5415 end;
5417 if ShowModal() = mrOK then
5418 begin
5419 b := lbTypeSelect.ItemIndex;
5420 Values[Key] := PANELNAMES[b];
5421 bApplyProperty.Click();
5422 end;
5423 end
5424 end
5425 else if Key = _lc[I_PROP_TR_TELEPORT_TO] then
5426 SelectFlag := SELECTFLAG_TELEPORT
5427 else if Key = _lc[I_PROP_TR_SPAWN_TO] then
5428 SelectFlag := SELECTFLAG_SPAWNPOINT
5429 else if (Key = _lc[I_PROP_TR_DOOR_PANEL]) or
5430 (Key = _lc[I_PROP_TR_TRAP_PANEL]) then
5431 SelectFlag := SELECTFLAG_DOOR
5432 else if Key = _lc[I_PROP_TR_TEXTURE_PANEL] then
5433 begin
5434 DrawPressRect := False;
5435 SelectFlag := SELECTFLAG_TEXTURE;
5436 end
5437 else if Key = _lc[I_PROP_TR_SHOT_PANEL] then
5438 SelectFlag := SELECTFLAG_SHOTPANEL
5439 else if Key = _lc[I_PROP_TR_LIFT_PANEL] then
5440 SelectFlag := SELECTFLAG_LIFT
5441 else if key = _lc[I_PROP_TR_EX_MONSTER] then
5442 SelectFlag := SELECTFLAG_MONSTER
5443 else if Key = _lc[I_PROP_TR_EX_AREA] then
5444 begin
5445 SelectFlag := SELECTFLAG_NONE;
5446 DrawPressRect := True;
5447 end
5448 else if Key = _lc[I_PROP_TR_NEXT_MAP] then
5449 begin // Выбор следующей карты:
5450 g_ProcessResourceStr(OpenedMap, @FileName, nil, nil);
5451 SelectMapForm.GetMaps(FileName);
5453 if SelectMapForm.ShowModal() = mrOK then
5454 begin
5455 vleObjectProperty.Values[Key] := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
5456 bApplyProperty.Click();
5457 end;
5458 end
5459 else if (Key = _lc[I_PROP_TR_SOUND_NAME]) or
5460 (Key = _lc[I_PROP_TR_MUSIC_NAME]) then
5461 begin // Выбор файла звука/музыки:
5462 AddSoundForm.OKFunction := nil;
5463 AddSoundForm.lbResourcesList.MultiSelect := False;
5464 AddSoundForm.SetResource := utf2win(vleObjectProperty.Values[Key]);
5466 if (AddSoundForm.ShowModal() = mrOk) then
5467 begin
5468 vleObjectProperty.Values[Key] := utf2win(AddSoundForm.ResourceName);
5469 bApplyProperty.Click();
5470 end;
5471 end
5472 else if Key = _lc[I_PROP_TR_ACTIVATION] then
5473 with ActivationTypeForm, vleObjectProperty do
5474 begin // Выбор типов активации:
5475 cbPlayerCollide.Checked := Pos('PC', Values[Key]) > 0;
5476 cbMonsterCollide.Checked := Pos('MC', Values[Key]) > 0;
5477 cbPlayerPress.Checked := Pos('PP', Values[Key]) > 0;
5478 cbMonsterPress.Checked := Pos('MP', Values[Key]) > 0;
5479 cbShot.Checked := Pos('SH', Values[Key]) > 0;
5480 cbNoMonster.Checked := Pos('NM', Values[Key]) > 0;
5482 if ShowModal() = mrOK then
5483 begin
5484 b := 0;
5485 if cbPlayerCollide.Checked then
5486 b := ACTIVATE_PLAYERCOLLIDE;
5487 if cbMonsterCollide.Checked then
5488 b := b or ACTIVATE_MONSTERCOLLIDE;
5489 if cbPlayerPress.Checked then
5490 b := b or ACTIVATE_PLAYERPRESS;
5491 if cbMonsterPress.Checked then
5492 b := b or ACTIVATE_MONSTERPRESS;
5493 if cbShot.Checked then
5494 b := b or ACTIVATE_SHOT;
5495 if cbNoMonster.Checked then
5496 b := b or ACTIVATE_NOMONSTER;
5498 Values[Key] := ActivateToStr(b);
5499 bApplyProperty.Click();
5500 end;
5501 end
5502 else if Key = _lc[I_PROP_TR_KEYS] then
5503 with KeysForm, vleObjectProperty do
5504 begin // Выбор необходимых ключей:
5505 cbRedKey.Checked := Pos('RK', Values[Key]) > 0;
5506 cbGreenKey.Checked := Pos('GK', Values[Key]) > 0;
5507 cbBlueKey.Checked := Pos('BK', Values[Key]) > 0;
5508 cbRedTeam.Checked := Pos('RT', Values[Key]) > 0;
5509 cbBlueTeam.Checked := Pos('BT', Values[Key]) > 0;
5511 if ShowModal() = mrOK then
5512 begin
5513 b := 0;
5514 if cbRedKey.Checked then
5515 b := KEY_RED;
5516 if cbGreenKey.Checked then
5517 b := b or KEY_GREEN;
5518 if cbBlueKey.Checked then
5519 b := b or KEY_BLUE;
5520 if cbRedTeam.Checked then
5521 b := b or KEY_REDTEAM;
5522 if cbBlueTeam.Checked then
5523 b := b or KEY_BLUETEAM;
5525 Values[Key] := KeyToStr(b);
5526 bApplyProperty.Click();
5527 end;
5528 end
5529 else if Key = _lc[I_PROP_TR_FX_TYPE] then
5530 with ChooseTypeForm, vleObjectProperty do
5531 begin // Выбор типа эффекта:
5532 Caption := _lc[I_CAP_FX_TYPE];
5533 lbTypeSelect.Items.Clear();
5535 for b := EFFECT_NONE to EFFECT_FIRE do
5536 lbTypeSelect.Items.Add(EffectToStr(b));
5538 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]);
5540 if ShowModal() = mrOK then
5541 begin
5542 b := lbTypeSelect.ItemIndex;
5543 Values[Key] := EffectToStr(b);
5544 bApplyProperty.Click();
5545 end;
5546 end
5547 else if Key = _lc[I_PROP_TR_MONSTER_TYPE] then
5548 with ChooseTypeForm, vleObjectProperty do
5549 begin // Выбор типа монстра:
5550 Caption := _lc[I_CAP_MONSTER_TYPE];
5551 lbTypeSelect.Items.Clear();
5553 for b := MONSTER_DEMON to MONSTER_MAN do
5554 lbTypeSelect.Items.Add(MonsterToStr(b));
5556 lbTypeSelect.ItemIndex := StrToMonster(Values[Key]) - MONSTER_DEMON;
5558 if ShowModal() = mrOK then
5559 begin
5560 b := lbTypeSelect.ItemIndex + MONSTER_DEMON;
5561 Values[Key] := MonsterToStr(b);
5562 bApplyProperty.Click();
5563 end;
5564 end
5565 else if Key = _lc[I_PROP_TR_ITEM_TYPE] then
5566 with ChooseTypeForm, vleObjectProperty do
5567 begin // Выбор типа предмета:
5568 Caption := _lc[I_CAP_ITEM_TYPE];
5569 lbTypeSelect.Items.Clear();
5571 for b := ITEM_MEDKIT_SMALL to ITEM_KEY_BLUE do
5572 lbTypeSelect.Items.Add(ItemToStr(b));
5573 lbTypeSelect.Items.Add(ItemToStr(ITEM_BOTTLE));
5574 lbTypeSelect.Items.Add(ItemToStr(ITEM_HELMET));
5575 lbTypeSelect.Items.Add(ItemToStr(ITEM_JETPACK));
5576 lbTypeSelect.Items.Add(ItemToStr(ITEM_INVIS));
5577 lbTypeSelect.Items.Add(ItemToStr(ITEM_WEAPON_FLAMETHROWER));
5578 lbTypeSelect.Items.Add(ItemToStr(ITEM_AMMO_FUELCAN));
5580 b := StrToItem(Values[Key]);
5581 if b >= ITEM_BOTTLE then
5582 b := b - 2;
5583 lbTypeSelect.ItemIndex := b - ITEM_MEDKIT_SMALL;
5585 if ShowModal() = mrOK then
5586 begin
5587 b := lbTypeSelect.ItemIndex + ITEM_MEDKIT_SMALL;
5588 if b >= ITEM_WEAPON_KASTET then
5589 b := b + 2;
5590 Values[Key] := ItemToStr(b);
5591 bApplyProperty.Click();
5592 end;
5593 end
5594 else if Key = _lc[I_PROP_TR_SHOT_TYPE] then
5595 with ChooseTypeForm, vleObjectProperty do
5596 begin // Выбор типа предмета:
5597 Caption := _lc[I_PROP_TR_SHOT_TYPE];
5598 lbTypeSelect.Items.Clear();
5600 for b := TRIGGER_SHOT_PISTOL to TRIGGER_SHOT_MAX do
5601 lbTypeSelect.Items.Add(ShotToStr(b));
5603 lbTypeSelect.ItemIndex := StrToShot(Values[Key]);
5605 if ShowModal() = mrOK then
5606 begin
5607 b := lbTypeSelect.ItemIndex;
5608 Values[Key] := ShotToStr(b);
5609 bApplyProperty.Click();
5610 end;
5611 end
5612 else if Key = _lc[I_PROP_TR_EFFECT_TYPE] then
5613 with ChooseTypeForm, vleObjectProperty do
5614 begin // Выбор типа эффекта:
5615 Caption := _lc[I_CAP_FX_TYPE];
5616 lbTypeSelect.Items.Clear();
5618 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_PARTICLE]);
5619 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_ANIMATION]);
5620 if Values[Key] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5621 lbTypeSelect.ItemIndex := 1
5622 else
5623 lbTypeSelect.ItemIndex := 0;
5625 if ShowModal() = mrOK then
5626 begin
5627 b := lbTypeSelect.ItemIndex;
5628 if b = 0 then
5629 Values[Key] := _lc[I_PROP_TR_EFFECT_PARTICLE]
5630 else
5631 Values[Key] := _lc[I_PROP_TR_EFFECT_ANIMATION];
5632 bApplyProperty.Click();
5633 end;
5634 end
5635 else if Key = _lc[I_PROP_TR_EFFECT_SUBTYPE] then
5636 with ChooseTypeForm, vleObjectProperty do
5637 begin // Выбор подтипа эффекта:
5638 Caption := _lc[I_CAP_FX_TYPE];
5639 lbTypeSelect.Items.Clear();
5641 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5642 begin
5643 for b := EFFECT_TELEPORT to EFFECT_FIRE do
5644 lbTypeSelect.Items.Add(EffectToStr(b));
5646 lbTypeSelect.ItemIndex := StrToEffect(Values[Key]) - 1;
5647 end else
5648 begin
5649 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SLIQUID]);
5650 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_LLIQUID]);
5651 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_DLIQUID]);
5652 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BLOOD]);
5653 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_SPARK]);
5654 lbTypeSelect.Items.Add(_lc[I_PROP_TR_EFFECT_BUBBLE]);
5655 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SLIQUID;
5656 if Values[Key] = _lc[I_PROP_TR_EFFECT_LLIQUID] then
5657 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_LLIQUID;
5658 if Values[Key] = _lc[I_PROP_TR_EFFECT_DLIQUID] then
5659 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_DLIQUID;
5660 if Values[Key] = _lc[I_PROP_TR_EFFECT_BLOOD] then
5661 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BLOOD;
5662 if Values[Key] = _lc[I_PROP_TR_EFFECT_SPARK] then
5663 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_SPARK;
5664 if Values[Key] = _lc[I_PROP_TR_EFFECT_BUBBLE] then
5665 lbTypeSelect.ItemIndex := TRIGGER_EFFECT_BUBBLE;
5666 end;
5668 if ShowModal() = mrOK then
5669 begin
5670 b := lbTypeSelect.ItemIndex;
5672 if Values[_lc[I_PROP_TR_EFFECT_TYPE]] = _lc[I_PROP_TR_EFFECT_ANIMATION] then
5673 Values[Key] := EffectToStr(b + 1)
5674 else begin
5675 Values[Key] := _lc[I_PROP_TR_EFFECT_SLIQUID];
5676 if b = TRIGGER_EFFECT_LLIQUID then
5677 Values[Key] := _lc[I_PROP_TR_EFFECT_LLIQUID];
5678 if b = TRIGGER_EFFECT_DLIQUID then
5679 Values[Key] := _lc[I_PROP_TR_EFFECT_DLIQUID];
5680 if b = TRIGGER_EFFECT_BLOOD then
5681 Values[Key] := _lc[I_PROP_TR_EFFECT_BLOOD];
5682 if b = TRIGGER_EFFECT_SPARK then
5683 Values[Key] := _lc[I_PROP_TR_EFFECT_SPARK];
5684 if b = TRIGGER_EFFECT_BUBBLE then
5685 Values[Key] := _lc[I_PROP_TR_EFFECT_BUBBLE];
5686 end;
5688 bApplyProperty.Click();
5689 end;
5690 end
5691 else if Key = _lc[I_PROP_TR_EFFECT_COLOR] then
5692 with vleObjectProperty do
5693 begin // Выбор цвета эффекта:
5694 ColorDialog.Color := StrToIntDef(Values[Key], 0);
5695 if ColorDialog.Execute then
5696 begin
5697 Values[Key] := IntToStr(ColorDialog.Color);
5698 bApplyProperty.Click();
5699 end;
5700 end
5701 else if Key = _lc[I_PROP_PANEL_TEX] then
5702 begin // Смена текстуры:
5703 vleObjectProperty.Values[Key] := SelectedTexture();
5704 bApplyProperty.Click();
5705 end;
5706 end;
5708 procedure TMainForm.aSaveMapExecute(Sender: TObject);
5709 var
5710 FileName, Section, Res: String;
5711 begin
5712 if OpenedMap = '' then
5713 begin
5714 aSaveMapAsExecute(nil);
5715 Exit;
5716 end;
5718 g_ProcessResourceStr(OpenedMap, FileName, Section, Res);
5720 SaveMap(FileName+':\'+Res);
5721 end;
5723 procedure TMainForm.aOpenMapExecute(Sender: TObject);
5724 begin
5725 OpenDialog.Filter := _lc[I_FILE_FILTER_ALL];
5727 if OpenDialog.Execute() then
5728 begin
5729 if (Pos('.ini', LowerCase(ExtractFileName(OpenDialog.FileName))) > 0) then
5730 begin // INI карты:
5731 FullClear();
5733 pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
5734 pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
5735 pLoadProgress.Show();
5737 OpenedMap := '';
5738 OpenedWAD := '';
5740 LoadMapOld(OpenDialog.FileName);
5742 MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(OpenDialog.FileName)]);
5744 pLoadProgress.Hide();
5745 MainForm.FormResize(Self);
5746 end
5747 else // Карты из WAD:
5748 begin
5749 OpenMap(OpenDialog.FileName, '');
5750 end;
5752 OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
5753 end;
5754 end;
5756 procedure TMainForm.FormActivate(Sender: TObject);
5757 var
5758 lang: Integer;
5759 config: TConfig;
5760 begin
5761 MainForm.ActiveControl := RenderPanel;
5763 // Язык:
5764 if gLanguage = '' then
5765 begin
5766 lang := SelectLanguageForm.ShowModal();
5767 case lang of
5768 1: gLanguage := LANGUAGE_ENGLISH;
5769 else gLanguage := LANGUAGE_RUSSIAN;
5770 end;
5772 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
5773 config.WriteStr('Editor', 'Language', gLanguage);
5774 config.SaveFile(EditorDir+'Editor.cfg');
5775 config.Free();
5776 end;
5778 //e_WriteLog('Read language file', MSG_NOTIFY);
5779 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
5780 g_Language_Set(gLanguage);
5781 end;
5783 procedure TMainForm.aDeleteMap(Sender: TObject);
5784 var
5785 WAD: TWADEditor_1;
5786 MapList: SArray;
5787 MapName: Char16;
5788 a: Integer;
5789 str: String;
5790 begin
5791 OpenDialog.Filter := _lc[I_FILE_FILTER_WAD];
5793 if not OpenDialog.Execute() then
5794 Exit;
5796 WAD := TWADEditor_1.Create();
5798 if not WAD.ReadFile(OpenDialog.FileName) then
5799 begin
5800 WAD.Free();
5801 Exit;
5802 end;
5804 WAD.CreateImage();
5806 MapList := WAD.GetResourcesList('');
5808 SelectMapForm.lbMapList.Items.Clear();
5810 if MapList <> nil then
5811 for a := 0 to High(MapList) do
5812 SelectMapForm.lbMapList.Items.Add(MapList[a]);
5814 if (SelectMapForm.ShowModal() = mrOK) then
5815 begin
5816 str := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
5817 MapName := '';
5818 Move(MapName[0], str[1], Min(16, Length(str)));
5820 if MessageBox(0, PChar(Format(_lc[I_MSG_DELETE_MAP_PROMT],
5821 [MapName, OpenDialog.FileName])),
5822 PChar(_lc[I_MSG_DELETE_MAP]),
5823 MB_ICONQUESTION or MB_YESNO or
5824 MB_DEFBUTTON2) <> mrYes then
5825 Exit;
5827 WAD.RemoveResource('', MapName);
5829 MessageBox(0, PChar(Format(_lc[I_MSG_MAP_DELETED_PROMT],
5830 [MapName])),
5831 PChar(_lc[I_MSG_MAP_DELETED]),
5832 MB_ICONINFORMATION or MB_OK or
5833 MB_DEFBUTTON1);
5835 WAD.SaveTo(OpenDialog.FileName);
5837 // Удалили текущую карту - сохранять по старому ее нельзя:
5838 if OpenedMap = (OpenDialog.FileName+':\'+MapName) then
5839 begin
5840 OpenedMap := '';
5841 OpenedWAD := '';
5842 MainForm.Caption := FormCaption;
5843 end;
5844 end;
5846 WAD.Free();
5847 end;
5849 procedure TMainForm.vleObjectPropertyKeyDown(Sender: TObject;
5850 var Key: Word; Shift: TShiftState);
5851 begin
5852 if Key = VK_RETURN then
5853 bApplyProperty.Click();
5854 end;
5856 procedure MovePanel(var ID: DWORD; MoveType: Byte);
5857 var
5858 _id, a: Integer;
5859 tmp: TPanel;
5860 begin
5861 if (ID = 0) and (MoveType = 0) then
5862 Exit;
5863 if (ID = DWORD(High(gPanels))) and (MoveType <> 0) then
5864 Exit;
5865 if (ID > DWORD(High(gPanels))) then
5866 Exit;
5868 _id := Integer(ID);
5870 if MoveType = 0 then // to Back
5871 begin
5872 if gTriggers <> nil then
5873 for a := 0 to High(gTriggers) do
5874 with gTriggers[a] do
5875 begin
5876 if TriggerType = TRIGGER_NONE then
5877 Continue;
5879 if TexturePanel = _id then
5880 TexturePanel := 0
5881 else
5882 if (TexturePanel >= 0) and (TexturePanel < _id) then
5883 Inc(TexturePanel);
5885 case TriggerType of
5886 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5887 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5888 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5889 if Data.PanelID = _id then
5890 Data.PanelID := 0
5891 else
5892 if (Data.PanelID >= 0) and (Data.PanelID < _id) then
5893 Inc(Data.PanelID);
5895 TRIGGER_SHOT:
5896 if Data.ShotPanelID = _id then
5897 Data.ShotPanelID := 0
5898 else
5899 if (Data.ShotPanelID >= 0) and (Data.ShotPanelID < _id) then
5900 Inc(Data.ShotPanelID);
5901 end;
5902 end;
5904 tmp := gPanels[_id];
5906 for a := _id downto 1 do
5907 gPanels[a] := gPanels[a-1];
5909 gPanels[0] := tmp;
5911 ID := 0;
5912 end
5913 else // to Front
5914 begin
5915 if gTriggers <> nil then
5916 for a := 0 to High(gTriggers) do
5917 with gTriggers[a] do
5918 begin
5919 if TriggerType = TRIGGER_NONE then
5920 Continue;
5922 if TexturePanel = _id then
5923 TexturePanel := High(gPanels)
5924 else
5925 if TexturePanel > _id then
5926 Dec(TexturePanel);
5928 case TriggerType of
5929 TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR,
5930 TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP,
5931 TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT:
5932 if Data.PanelID = _id then
5933 Data.PanelID := High(gPanels)
5934 else
5935 if Data.PanelID > _id then
5936 Dec(Data.PanelID);
5938 TRIGGER_SHOT:
5939 if Data.ShotPanelID = _id then
5940 Data.ShotPanelID := High(gPanels)
5941 else
5942 if Data.ShotPanelID > _id then
5943 Dec(Data.ShotPanelID);
5944 end;
5945 end;
5947 tmp := gPanels[_id];
5949 for a := _id to High(gPanels)-1 do
5950 gPanels[a] := gPanels[a+1];
5952 gPanels[High(gPanels)] := tmp;
5954 ID := High(gPanels);
5955 end;
5956 end;
5958 procedure TMainForm.aMoveToBack(Sender: TObject);
5959 var
5960 a: Integer;
5961 begin
5962 if SelectedObjects = nil then
5963 Exit;
5965 for a := 0 to High(SelectedObjects) do
5966 with SelectedObjects[a] do
5967 if Live and (ObjectType = OBJECT_PANEL) then
5968 begin
5969 SelectedObjects[0] := SelectedObjects[a];
5970 SetLength(SelectedObjects, 1);
5971 MovePanel(ID, 0);
5972 FillProperty();
5973 Break;
5974 end;
5975 end;
5977 procedure TMainForm.aMoveToFore(Sender: TObject);
5978 var
5979 a: Integer;
5980 begin
5981 if SelectedObjects = nil then
5982 Exit;
5984 for a := 0 to High(SelectedObjects) do
5985 with SelectedObjects[a] do
5986 if Live and (ObjectType = OBJECT_PANEL) then
5987 begin
5988 SelectedObjects[0] := SelectedObjects[a];
5989 SetLength(SelectedObjects, 1);
5990 MovePanel(ID, 1);
5991 FillProperty();
5992 Break;
5993 end;
5994 end;
5996 procedure TMainForm.aSaveMapAsExecute(Sender: TObject);
5997 var
5998 idx: Integer;
5999 begin
6000 SaveDialog.Filter := _lc[I_FILE_FILTER_WAD];
6002 if not SaveDialog.Execute() then
6003 Exit;
6005 SaveMapForm.GetMaps(SaveDialog.FileName, True);
6007 if SaveMapForm.ShowModal() <> mrOK then
6008 Exit;
6010 SaveDialog.InitialDir := ExtractFileDir(SaveDialog.FileName);
6011 OpenedMap := SaveDialog.FileName+':\'+SaveMapForm.eMapName.Text;
6012 OpenedWAD := SaveDialog.FileName;
6014 idx := RecentFiles.IndexOf(OpenedMap);
6015 // Такая карта уже недавно открывалась:
6016 if idx >= 0 then
6017 RecentFiles.Delete(idx);
6018 RecentFiles.Insert(0, OpenedMap);
6019 RefreshRecentMenu;
6021 SaveMap(OpenedMap);
6023 gMapInfo.FileName := SaveDialog.FileName;
6024 gMapInfo.MapName := SaveMapForm.eMapName.Text;
6025 UpdateCaption(gMapInfo.Name, ExtractFileName(gMapInfo.FileName), gMapInfo.MapName);
6026 end;
6028 procedure TMainForm.aSelectAllExecute(Sender: TObject);
6029 var
6030 a: Integer;
6031 begin
6032 RemoveSelectFromObjects();
6034 case pcObjects.ActivePageIndex+1 of
6035 OBJECT_PANEL:
6036 if gPanels <> nil then
6037 for a := 0 to High(gPanels) do
6038 if gPanels[a].PanelType <> PANEL_NONE then
6039 SelectObject(OBJECT_PANEL, a, True);
6040 OBJECT_ITEM:
6041 if gItems <> nil then
6042 for a := 0 to High(gItems) do
6043 if gItems[a].ItemType <> ITEM_NONE then
6044 SelectObject(OBJECT_ITEM, a, True);
6045 OBJECT_MONSTER:
6046 if gMonsters <> nil then
6047 for a := 0 to High(gMonsters) do
6048 if gMonsters[a].MonsterType <> MONSTER_NONE then
6049 SelectObject(OBJECT_MONSTER, a, True);
6050 OBJECT_AREA:
6051 if gAreas <> nil then
6052 for a := 0 to High(gAreas) do
6053 if gAreas[a].AreaType <> AREA_NONE then
6054 SelectObject(OBJECT_AREA, a, True);
6055 OBJECT_TRIGGER:
6056 if gTriggers <> nil then
6057 for a := 0 to High(gTriggers) do
6058 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6059 SelectObject(OBJECT_TRIGGER, a, True);
6060 end;
6061 end;
6063 procedure TMainForm.tbGridOnClick(Sender: TObject);
6064 begin
6065 DotEnable := not DotEnable;
6066 (Sender as TToolButton).Down := DotEnable;
6067 end;
6069 procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean);
6070 begin
6071 // FIXME: this is a shitty hack
6072 if not gDataLoaded then
6073 begin
6074 e_WriteLog('Init OpenGL', MSG_NOTIFY);
6075 e_InitGL();
6076 e_WriteLog('Loading data', MSG_NOTIFY);
6077 LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
6078 e_WriteLog('Loading more data', MSG_NOTIFY);
6079 LoadData();
6080 e_WriteLog('Loading even more data', MSG_NOTIFY);
6081 gDataLoaded := True;
6082 MainForm.FormResize(nil);
6083 end;
6084 Draw();
6085 end;
6087 procedure TMainForm.miMapPreviewClick(Sender: TObject);
6088 begin
6089 if not PreviewMode then
6090 begin
6091 Splitter2.Visible := False;
6092 Splitter1.Visible := False;
6093 StatusBar.Visible := False;
6094 PanelObjs.Visible := False;
6095 PanelProps.Visible := False;
6096 MainToolBar.Visible := False;
6097 sbHorizontal.Visible := False;
6098 sbVertical.Visible := False;
6099 end
6100 else
6101 begin
6102 StatusBar.Visible := True;
6103 PanelObjs.Visible := True;
6104 PanelProps.Visible := True;
6105 Splitter2.Visible := True;
6106 Splitter1.Visible := True;
6107 MainToolBar.Visible := True;
6108 sbHorizontal.Visible := True;
6109 sbVertical.Visible := True;
6110 end;
6112 PreviewMode := not PreviewMode;
6113 (Sender as TMenuItem).Checked := PreviewMode;
6115 FormResize(Self);
6116 end;
6118 procedure TMainForm.miLayer1Click(Sender: TObject);
6119 begin
6120 SwitchLayer(LAYER_BACK);
6121 end;
6123 procedure TMainForm.miLayer2Click(Sender: TObject);
6124 begin
6125 SwitchLayer(LAYER_WALLS);
6126 end;
6128 procedure TMainForm.miLayer3Click(Sender: TObject);
6129 begin
6130 SwitchLayer(LAYER_FOREGROUND);
6131 end;
6133 procedure TMainForm.miLayer4Click(Sender: TObject);
6134 begin
6135 SwitchLayer(LAYER_STEPS);
6136 end;
6138 procedure TMainForm.miLayer5Click(Sender: TObject);
6139 begin
6140 SwitchLayer(LAYER_WATER);
6141 end;
6143 procedure TMainForm.miLayer6Click(Sender: TObject);
6144 begin
6145 SwitchLayer(LAYER_ITEMS);
6146 end;
6148 procedure TMainForm.miLayer7Click(Sender: TObject);
6149 begin
6150 SwitchLayer(LAYER_MONSTERS);
6151 end;
6153 procedure TMainForm.miLayer8Click(Sender: TObject);
6154 begin
6155 SwitchLayer(LAYER_AREAS);
6156 end;
6158 procedure TMainForm.miLayer9Click(Sender: TObject);
6159 begin
6160 SwitchLayer(LAYER_TRIGGERS);
6161 end;
6163 procedure TMainForm.tbShowClick(Sender: TObject);
6164 var
6165 a: Integer;
6166 b: Boolean;
6167 begin
6168 b := True;
6169 for a := 0 to High(LayerEnabled) do
6170 b := b and LayerEnabled[a];
6172 b := not b;
6174 ShowLayer(LAYER_BACK, b);
6175 ShowLayer(LAYER_WALLS, b);
6176 ShowLayer(LAYER_FOREGROUND, b);
6177 ShowLayer(LAYER_STEPS, b);
6178 ShowLayer(LAYER_WATER, b);
6179 ShowLayer(LAYER_ITEMS, b);
6180 ShowLayer(LAYER_MONSTERS, b);
6181 ShowLayer(LAYER_AREAS, b);
6182 ShowLayer(LAYER_TRIGGERS, b);
6183 end;
6185 procedure TMainForm.miMiniMapClick(Sender: TObject);
6186 begin
6187 SwitchMap();
6188 end;
6190 procedure TMainForm.miSwitchGridClick(Sender: TObject);
6191 begin
6192 if DotStep = DotStepOne then
6193 DotStep := DotStepTwo
6194 else
6195 DotStep := DotStepOne;
6197 MousePos.X := (MousePos.X div DotStep) * DotStep;
6198 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6199 end;
6201 procedure TMainForm.miShowEdgesClick(Sender: TObject);
6202 begin
6203 ShowEdges();
6204 end;
6206 procedure TMainForm.miSnapToGridClick(Sender: TObject);
6207 begin
6208 SnapToGrid := not SnapToGrid;
6210 MousePos.X := (MousePos.X div DotStep) * DotStep;
6211 MousePos.Y := (MousePos.Y div DotStep) * DotStep;
6213 miSnapToGrid.Checked := SnapToGrid;
6214 end;
6216 procedure TMainForm.minexttabClick(Sender: TObject);
6217 begin
6218 if pcObjects.ActivePageIndex < pcObjects.PageCount-1 then
6219 pcObjects.ActivePageIndex := pcObjects.ActivePageIndex+1
6220 else
6221 pcObjects.ActivePageIndex := 0;
6222 end;
6224 procedure TMainForm.miSaveMiniMapClick(Sender: TObject);
6225 begin
6226 SaveMiniMapForm.ShowModal();
6227 end;
6229 procedure TMainForm.bClearTextureClick(Sender: TObject);
6230 begin
6231 lbTextureList.ItemIndex := -1;
6232 lTextureWidth.Caption := '';
6233 lTextureHeight.Caption := '';
6234 end;
6236 procedure TMainForm.miPackMapClick(Sender: TObject);
6237 begin
6238 PackMapForm.ShowModal();
6239 end;
6241 procedure TMainForm.miMapTestSettingsClick(Sender: TObject);
6242 begin
6243 MapTestForm.ShowModal();
6244 end;
6246 procedure TMainForm.miTestMapClick(Sender: TObject);
6247 var
6248 cmd, mapWAD, mapToRun: String;
6249 opt: LongWord;
6250 time: Integer;
6251 begin
6252 // Сохраняем временную карту:
6253 time := 0;
6254 repeat
6255 mapWAD := ExtractFilePath(TestD2dExe) + Format('maps/temp%.4d.wad', [time]);
6256 Inc(time);
6257 until not FileExists(mapWAD);
6258 mapToRun := mapWAD + ':\' + TEST_MAP_NAME;
6259 SaveMap(mapToRun);
6261 mapToRun := ExtractRelativePath(ExtractFilePath(TestD2dExe) + 'maps/', mapToRun);
6263 // Опции игры:
6264 opt := 32 + 64;
6265 if TestOptionsTwoPlayers then
6266 opt := opt + 1;
6267 if TestOptionsTeamDamage then
6268 opt := opt + 2;
6269 if TestOptionsAllowExit then
6270 opt := opt + 4;
6271 if TestOptionsWeaponStay then
6272 opt := opt + 8;
6273 if TestOptionsMonstersDM then
6274 opt := opt + 16;
6276 // Составляем командную строку:
6277 cmd := ' -map "' + mapToRun + '"';
6278 cmd := cmd + ' -gm ' + TestGameMode;
6279 cmd := cmd + ' -limt ' + TestLimTime;
6280 cmd := cmd + ' -lims ' + TestLimScore;
6281 cmd := cmd + ' -opt ' + IntToStr(opt);
6283 if TestMapOnce then
6284 cmd := cmd + ' --close';
6286 cmd := cmd + ' --debug';
6287 cmd := cmd + ' --tempdelete';
6289 // Запускаем:
6290 Application.Minimize();
6291 if ExecuteProcess(TestD2dExe, cmd) < 0 then
6292 begin
6293 MessageBox(0, 'FIXME',
6294 PChar(_lc[I_MSG_EXEC_ERROR]),
6295 MB_OK or MB_ICONERROR);
6296 end;
6298 SysUtils.DeleteFile(mapWAD);
6299 Application.Restore();
6300 end;
6302 procedure TMainForm.sbVerticalScroll(Sender: TObject;
6303 ScrollCode: TScrollCode; var ScrollPos: Integer);
6304 begin
6305 MapOffset.Y := -Normalize16(sbVertical.Position);
6306 end;
6308 procedure TMainForm.sbHorizontalScroll(Sender: TObject;
6309 ScrollCode: TScrollCode; var ScrollPos: Integer);
6310 begin
6311 MapOffset.X := -Normalize16(sbHorizontal.Position);
6312 end;
6314 procedure TMainForm.miOpenWadMapClick(Sender: TObject);
6315 begin
6316 if OpenedWAD <> '' then
6317 begin
6318 OpenMap(OpenedWAD, '');
6319 end;
6320 end;
6322 procedure TMainForm.selectall1Click(Sender: TObject);
6323 var
6324 a: Integer;
6325 begin
6326 RemoveSelectFromObjects();
6328 if gPanels <> nil then
6329 for a := 0 to High(gPanels) do
6330 if gPanels[a].PanelType <> PANEL_NONE then
6331 SelectObject(OBJECT_PANEL, a, True);
6333 if gItems <> nil then
6334 for a := 0 to High(gItems) do
6335 if gItems[a].ItemType <> ITEM_NONE then
6336 SelectObject(OBJECT_ITEM, a, True);
6338 if gMonsters <> nil then
6339 for a := 0 to High(gMonsters) do
6340 if gMonsters[a].MonsterType <> MONSTER_NONE then
6341 SelectObject(OBJECT_MONSTER, a, True);
6343 if gAreas <> nil then
6344 for a := 0 to High(gAreas) do
6345 if gAreas[a].AreaType <> AREA_NONE then
6346 SelectObject(OBJECT_AREA, a, True);
6348 if gTriggers <> nil then
6349 for a := 0 to High(gTriggers) do
6350 if gTriggers[a].TriggerType <> TRIGGER_NONE then
6351 SelectObject(OBJECT_TRIGGER, a, True);
6352 end;
6354 procedure TMainForm.Splitter1CanResize(Sender: TObject;
6355 var NewSize: Integer; var Accept: Boolean);
6356 begin
6357 Accept := (NewSize > 140);
6358 end;
6360 procedure TMainForm.Splitter2CanResize(Sender: TObject;
6361 var NewSize: Integer; var Accept: Boolean);
6362 begin
6363 Accept := (NewSize > 110);
6364 end;
6366 procedure TMainForm.vleObjectPropertyEnter(Sender: TObject);
6367 begin
6368 EditingProperties := True;
6369 end;
6371 procedure TMainForm.vleObjectPropertyExit(Sender: TObject);
6372 begin
6373 EditingProperties := False;
6374 end;
6376 procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
6377 Shift: TShiftState);
6378 begin
6379 // Объекты передвигались:
6380 if MainForm.ActiveControl = RenderPanel then
6381 begin
6382 if (Key = VK_NUMPAD4) or
6383 (Key = VK_NUMPAD6) or
6384 (Key = VK_NUMPAD8) or
6385 (Key = VK_NUMPAD5) or
6386 (Key = Ord('V')) then
6387 FillProperty();
6388 end;
6389 end;
6392 procedure TMainForm.lbTextureListDrawItem(Control: TWinControl; Index: Integer;
6393 Rect: TRect; State: LCLType.TOwnerDrawState);
6394 begin
6395 with Control as TListBox do
6396 begin
6397 if LCLType.odSelected in State then
6398 begin
6399 Canvas.Brush.Color := clHighlight;
6400 Canvas.Font.Color := clHighlightText;
6401 end else
6402 if (Items <> nil) and (Index >= 0) then
6403 if slInvalidTextures.IndexOf(Items[Index]) > -1 then
6404 begin
6405 Canvas.Brush.Color := clRed;
6406 Canvas.Font.Color := clWhite;
6407 end;
6408 Canvas.FillRect(Rect);
6409 Canvas.TextRect(Rect, Rect.Left, Rect.Top, Items[Index]);
6410 end;
6411 end;
6413 end.