diff --git a/src/editor/f_main.pas b/src/editor/f_main.pas
index eb7dfdd4fe2877a77d8e5fab92beb419ccbd5349..2bd2fc6bff2a770560fb6b3fad4685fe6ea8e50d 100644 (file)
--- a/src/editor/f_main.pas
+++ b/src/editor/f_main.pas
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormResize(Sender: TObject);
procedure FormWindowStateChange(Sender: TObject);
+ procedure miRecentFileExecute(Sender: TObject);
procedure miMacRecentClearClick(Sender: TObject);
procedure miMacZoomClick(Sender: TObject);
procedure lbTextureListClick(Sender: TObject);
f_mapoptions, g_basic, f_about, f_mapoptimization,
f_mapcheck, f_addresource_texture, g_textures,
f_activationtype, f_keys, wadreader, fileutil,
- MAPREADER, f_selectmap, f_savemap, WADEDITOR, MAPDEF,
+ MAPREADER, f_selectmap, f_savemap, WADEDITOR, WADSTRUCT, MAPDEF,
g_map, f_saveminimap, f_addresource, CONFIG, f_packmap,
f_addresource_sound, f_choosetype,
- g_language, ClipBrd, g_resources, g_options;
+ g_language, ClipBrd, g_options;
const
UNDO_DELETE_PANEL = 1;
type
TUndoRec = record
- UndoType: Byte;
- case Byte of
+ case UndoType: Byte of
UNDO_DELETE_PANEL: (Panel: ^TPanel);
UNDO_DELETE_ITEM: (Item: TItem);
UNDO_DELETE_AREA: (Area: TArea);
end;
TCopyRec = record
- ObjectType: Byte;
ID: Cardinal;
- case Byte of
+ case ObjectType: Byte of
OBJECT_PANEL: (Panel: ^TPanel);
OBJECT_ITEM: (Item: TItem);
OBJECT_AREA: (Area: TArea);
//Закончились вспомогательные процедуры
//----------------------------------------
-type
- TRecentHandler = class
- private
- FForm: TMainForm;
- FPath: String;
- public
- constructor Create (form: TMainForm; path: String);
- procedure Execute (Sender: TObject);
- end;
-
-constructor TRecentHandler.Create (form: TMainForm; path: String);
-begin
- Assert(form <> nil);
- FForm := form;
- FPath := path;
-end;
-
-procedure TRecentHandler.Execute (Sender: TObject);
- var fn: AnsiString;
+procedure TMainForm.miRecentFileExecute (Sender: TObject);
+var
+ s, fn: AnsiString;
begin
- fn := g_ExtractWadName(FPath);
+ s := RecentFiles[(Sender as TMenuItem).Tag];
+ fn := g_ExtractWadName(s);
if FileExists(fn) then
- OpenMap(fn, g_ExtractFilePathName(FPath))
+ OpenMap(fn, g_ExtractFilePathName(s))
else
Application.MessageBox('', 'File not available anymore', MB_OK);
-// if Application.MessageBox(PChar(MsgMsgDelRecentPromt), PChar(MsgMsgDelRecent), MB_ICONQUESTION or MB_YESNO) = idYes then
+// if Application.MessageBox(PChar(MsgMsgDelRecentPrompt), PChar(MsgMsgDelRecent), MB_ICONQUESTION or MB_YESNO) = idYes then
// begin
// RecentFiles.Delete(n);
// RefreshRecentMenu();
end;
procedure TMainForm.RefillRecentMenu (menu: TMenuItem; start: Integer; fmt: AnsiString);
- var i: Integer; MI: TMenuItem; cb: TMethod; h: TRecentHandler; s: AnsiString;
+ var i: Integer; MI: TMenuItem; s: AnsiString;
begin
Assert(menu <> nil);
Assert(start >= 0);
Assert(start <= menu.Count);
- // clear all recent entries from menu
+ // clear all the recent entries from menu
i := start;
while i < menu.Count do
begin
MI := menu.Items[i];
- cb := TMethod(MI.OnClick);
- if cb.Code = @TRecentHandler.Execute then
+ if @MI.OnClick <> @TMainForm.miRecentFileExecute then
+ i += 1
+ else
begin
- // this is recent menu entry
- // remove it and free callback handler
- h := TRecentHandler(cb.Data);
menu.Delete(i);
- MI.Free();
- h.Free();
- end
- else
- Inc(i);
+ MI.Destroy();
+ end;
end;
// fill with a new ones
- for i := 0 to RecentFiles.Count - 1 do
+ for i := 0 to RecentFiles.Count-1 do
begin
- s := RecentFiles[i];
- h := TRecentHandler.Create(self, s);
MI := TMenuItem.Create(menu);
- MI.Caption := Format(fmt, [i + 1, g_ExtractWadNameNoPath(s), g_ExtractFilePathName(s)]);
- MI.OnClick := h.Execute;
- menu.Insert(start + i, MI);
+ s := RecentFiles[i];
+ MI.Caption := Format(fmt, [i+1, g_ExtractWadNameNoPath(s), g_ExtractFilePathName(s)]);
+ MI.OnClick := miRecentFileExecute;
+ MI.Tag := i;
+ menu.Insert(start + i, MI); // transfers ownership
end;
end;
begin
// Reconstruct Windows-like recent list
start := miMenuFile.IndexOf(miWinRecent);
- if start < 0 then start := miMenuFile.Count else start := start + 1;
+ if start < 0 then start := miMenuFile.Count else start += 1;
RefillRecentMenu(miMenuFile, start, '%0:d %1:s:%2:s');
miWinRecent.Enabled := False;
miWinRecent.Visible := RecentFiles.Count = 0;
cwdt, chgt: Byte;
spc: ShortInt;
ID: DWORD;
+ wad: TWADEditor_1;
cfgdata: Pointer;
cfglen: Integer;
config: TConfig;
begin
+ cfgdata := nil;
+ cfglen := 0;
ID := 0;
- g_ReadResource(GameWad, 'FONTS', cfgres, cfgdata, cfglen);
- if cfgdata <> nil then
+
+ wad := TWADEditor_1.Create;
+ if wad.ReadFile(GameWad) then
+ wad.GetResource('FONTS', cfgres, cfgdata, cfglen);
+ wad.Free();
+
+ if cfglen <> 0 then
begin
if not g_CreateTextureWAD('FONT_STD', GameWad + ':FONTS\' + texture) then
e_WriteLog('ERROR ERROR ERROR', MSG_WARNING);
spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
if g_GetTexture('FONT_STD', ID) then
- e_TextureFontBuild(ID, FontID, cwdt, chgt, spc - 2);
+ e_TextureFontBuild(ID, FontID, cwdt, chgt, spc-2);
config.Free();
- FreeMem(cfgdata)
end
else
- begin
- e_WriteLog('Could not load FONT_STD', MSG_WARNING)
- end
+ e_WriteLog('Could not load FONT_STD', MSG_WARNING);
+
+ if cfglen <> 0 then FreeMem(cfgdata);
end;
procedure TMainForm.FormCreate(Sender: TObject);
s := config.ReadStr('Editor', 'Language', '');
gLanguage := s;
- Compress := config.ReadBool('Editor', 'Compress', True);
- Backup := config.ReadBool('Editor', 'Backup', True);
-
TestGameMode := config.ReadStr('TestRun', 'GameMode', 'DM');
TestLimTime := config.ReadStr('TestRun', 'LimTime', '0');
TestLimScore := config.ReadStr('TestRun', 'LimScore', '0');
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
- CanClose := Application.MessageBox(PChar(MsgMsgExitPromt),
+ CanClose := Application.MessageBox(PChar(MsgMsgExitPrompt),
PChar(MsgMsgExit),
MB_ICONQUESTION or MB_YESNO or
MB_DEFBUTTON1) = idYes;
end
end;
- if Key = Ord('V') then
+ if Key = Ord('I') then
begin // Поворот монстров и областей:
if (SelectedObjects <> nil) then
begin
if OpenedMap = '' then
Exit;
- if Application.MessageBox(PChar(MsgMsgReopenMapPromt),
+ if Application.MessageBox(PChar(MsgMsgReopenMapPrompt),
PChar(MsgMenuFileReopen), MB_ICONQUESTION or MB_YESNO) <> idYes then
Exit;
if i = -1 then
Exit;
- if Application.MessageBox(PChar(Format(MsgMsgDelTexturePromt,
+ if Application.MessageBox(PChar(Format(MsgMsgDelTexturePrompt,
[SelectedTexture()])),
PChar(MsgMsgDelTexture),
MB_ICONQUESTION or MB_YESNO or
procedure TMainForm.aNewMapExecute(Sender: TObject);
begin
- if Application.MessageBox(PChar(MsgMsgClearMapPromt), PChar(MsgMsgClearMap), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON1) = mrYes then
+ if Application.MessageBox(PChar(MsgMsgClearMapPrompt), PChar(MsgMsgClearMap), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON1) = mrYes then
FullClear();
end;
QuickSortCopyBuffer(0, b);
end;
-// Ð\9fестановка ссылок триггеров:
+// Ð\9fостановка ссылок триггеров:
for a := 0 to Length(CopyBuffer)-1 do
if CopyBuffer[a].ObjectType = OBJECT_TRIGGER then
begin
h := High(CopyBuffer);
RemoveSelectFromObjects();
- xadj := -pmin.X - Floor((MapOffset.X - 32) / DotStep) * DotStep;
- yadj := -pmin.Y - Floor((MapOffset.Y - 32) / DotStep) * DotStep;
+ if h > 0 then
+ begin
+ xadj := Floor((-pmin.X - MapOffset.X + 32) / DotStep) * DotStep;
+ yadj := Floor((-pmin.Y - MapOffset.Y + 32) / DotStep) * DotStep;
+ end
+ else
+ begin
+ xadj := DotStep;
+ yadj := DotStep;
+ end;
for a := 0 to h do
with CopyBuffer[a] do
procedure TMainForm.aDeleteMap(Sender: TObject);
var
- res: Integer;
- FileName: String;
- MapName: String;
+ WAD: TWADEditor_1;
+ MapList: SArray;
+ MapName: Char16;
+ a: Integer;
+ str: String;
begin
OpenDialog.Filter := MsgFileFilterWad;
if not OpenDialog.Execute() then
Exit;
- FileName := OpenDialog.FileName;
- SelectMapForm.Caption := MsgCapRemove;
- SelectMapForm.lbMapList.Items.Clear();
- SelectMapForm.GetMaps(FileName);
+ WAD := TWADEditor_1.Create();
- if SelectMapForm.ShowModal() <> mrOK then
+ if not WAD.ReadFile(OpenDialog.FileName) then
+ begin
+ WAD.Free();
Exit;
+ end;
- MapName := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
- if Application.MessageBox(PChar(Format(MsgMsgDeleteMapPromt, [MapName, OpenDialog.FileName])), PChar(MsgMsgDeleteMap), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2) <> mrYes then
- Exit;
+ WAD.CreateImage();
+
+ MapList := WAD.GetResourcesList('');
+
+ SelectMapForm.Caption := MsgCapRemove;
+ SelectMapForm.lbMapList.Items.Clear();
+
+ if MapList <> nil then
+ for a := 0 to High(MapList) do
+ SelectMapForm.lbMapList.Items.Add(win2utf(MapList[a]));
- g_DeleteResource(FileName, '', MapName, res);
- if res <> 0 then
+ if (SelectMapForm.ShowModal() = mrOK) then
begin
- Application.MessageBox(PChar('Cant delete map res=' + IntToStr(res)), PChar('Map not deleted!'), MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1);
- Exit
- end;
+ str := SelectMapForm.lbMapList.Items[SelectMapForm.lbMapList.ItemIndex];
+ MapName := '';
+ Move(str[1], MapName[0], Min(16, Length(str)));
+
+ if Application.MessageBox(PChar(Format(MsgMsgDeleteMapPrompt, [MapName, OpenDialog.FileName])), PChar(MsgMsgDeleteMap), MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2) <> mrYes then
+ Exit;
+
+ WAD.RemoveResource('', utf2win(MapName));
- Application.MessageBox(
- PChar(Format(MsgMsgMapDeletedPromt, [MapName])),
- PChar(MsgMsgMapDeleted),
- MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1
- );
+ Application.MessageBox(
+ PChar(Format(MsgMsgMapDeletedPrompt, [MapName])),
+ PChar(MsgMsgMapDeleted),
+ MB_ICONINFORMATION or MB_OK or MB_DEFBUTTON1
+ );
+
+ WAD.SaveTo(OpenDialog.FileName);
// Удалили текущую карту - сохранять по старому ее нельзя:
- if OpenedMap = (FileName + ':\' + MapName) then
- begin
- OpenedMap := '';
- OpenedWAD := '';
- MainForm.Caption := FormCaption
- end
+ if OpenedMap = (OpenDialog.FileName+':\'+MapName) then
+ begin
+ OpenedMap := '';
+ OpenedWAD := '';
+ MainForm.Caption := FormCaption;
+ end;
+ end;
+
+ WAD.Free();
end;
procedure TMainForm.vleObjectPropertyKeyDown(Sender: TObject;