ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Main.pas
(Generate patch)

Comparing:
oup/rewrite/Main.pas (file contents), Revision 93 by alloc, Thu Jan 18 17:15:59 2007 UTC vs.
oup/current/Main.pas (file contents), Revision 224 by alloc, Mon Jun 18 14:49:24 2007 UTC

# Line 6 | Line 6 | uses
6    MPHexEditor, ToolWin, ImgList, Tabs,
7    MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
8    Data, TypeDefs, ConnectionManager,
9 < //  Functions, Exporters, DataStructures,
10 <  Settings, {Helper_LevelDB, }
11 <  Template, BinEdit, Extractor, Preview, RawEdit, TxmpReplace;
9 >  Functions, Settings,
10 >  RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
11 >  _BaseTemplate, _TemplateFile, _TemplateFileList;
12  
13   type
14    TForm_Main = class(TForm)
# Line 91 | Line 91 | type
91        Y: Integer);
92      procedure ToolbarDockChanged(Sender: TObject);
93      procedure CreateConnection(filename: String);
94 +    function CheckConnectionCloseable(index: Integer): Boolean;
95  
96      procedure menu_loadfileClick(Sender: TObject);
97      procedure menu_loaddbClick(Sender: TObject);
# Line 107 | Line 108 | type
108      procedure menu_txmpreplaceClick(Sender: TObject);
109      procedure menu_previewClick(Sender: TObject);
110      procedure menu_metaClick(Sender: TObject);
110    function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
111  
112      procedure menu_windows_cascadeClick(Sender: TObject);
113      procedure menu_windows_tilevertClick(Sender: TObject);
# Line 125 | Line 125 | type
125  
126      procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
127    private
128    ConnectionManager: TConnectionManager;
128    public
129 +    function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload;
130 +    function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload;
131 +    function open_child(window_context: String): TForm_BaseTemplate; overload;
132      procedure DefaultHandler(var Message); override;
133    end;
134  
# Line 135 | Line 137 | var
137  
138   implementation
139  
140 + uses
141 +  LevelDB, MetaEditor;
142 +
143   {$R *.dfm}
144  
145  
# Line 153 | Line 158 | procedure TForm_Main.CreateConnection(fi
158   var
159    RepMsg: TStatusMessages;
160   begin
161 <  ConnectionManager.OpenConnection(filename, RepMsg);
161 >  ConManager.OpenConnection(filename, RepMsg);
162    ShowOpenMsg(RepMsg);
163    if RepMsg = SM_OK then
164    begin
165      UpdateStatBar;
166 +    UpdateConLists;
167 +  end;
168 + end;
169 +
170 + function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
171 + var
172 +  i: Integer;
173 +  toolform: TForm_BaseTemplate;
174 + begin
175 +  Result := True;
176 +  if MDITab.MDIChildCount > 0 then
177 +  begin
178 +    for i := 0 to MDITab.MDIChildCount - 1 do
179 +    begin
180 +      if MDITab.MDIChildren[i] is TForm_BaseTemplate then
181 +      begin
182 +        toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
183 +        if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
184 +        begin
185 +          if not toolform.Closeable then
186 +          begin
187 +            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
188 +            Result := False;
189 +          end;
190 +        end;
191 +      end;
192 +    end;
193    end;
194   end;
195  
196 +
197   { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
198   procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
199   var
# Line 208 | Line 241 | end;
241  
242  
243   procedure TForm_Main.FormCreate(Sender: TObject);
211 var
212  RepMsg: TStatusMessages;
244   begin
245    Self.Caption := 'Oni Un/Packer ' + version;
246    Self.FormResize(Self);
247  
248 <  ConnectionManager := TConnectionManager.Create;
218 <  ConnectionManager.OnCoonnectionListChanged := UpdateConLists;
248 >  ConManager.OnCoonnectionListChanged := UpdateConLists;
249  
250    if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
251    begin
# Line 227 | Line 257 | begin
257    end
258    else
259    begin
260 +    ShowMessage('Warning!' + #13#10 +
261 +                'It seems like this is the first time you OUP.' + #13#10 +
262 +                'I do not take any responsibility for messed up data files' + #13+#10 +
263 +                'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!');
264      AppSettings.DatPath        := ExtractFilepath(Application.EXEname);
265      AppSettings.ExtractPath    := ExtractFilepath(Application.EXEname) + '\extract';
232    AppSettings.FilenumbersAsHex := False;
266      AppSettings.CharSet        := DEFAULT_CHARSET;
267      AppSettings.HideUnusedData := False;
268    end;
# Line 292 | Line 325 | var
325    pt: TPoint;
326    tabIndex: Integer;
327    hint: String;
328 +  tool: TForm_BaseTemplate;
329   begin
330    pt.X := X;
331    pt.Y := Y;
# Line 300 | Line 334 | begin
334  
335    if tabIndex >= 0 then
336    begin
337 <    if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
337 >    if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
338      begin
339 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then
339 >      tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
340 >      if tool.ConnectionID > -1 then
341          hint := 'Connection: ' +
342 <              ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10
342 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
343        else
344 <        hint := 'Connection: none' + #13+#10;
345 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then
346 <        hint := hint + 'Selected File: ' +
347 <              TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName
348 <      else
349 <        hint := hint + 'Selected File: none';
344 >        hint := 'Connection: none';
345 >      if tool is TForm_TemplateFile then
346 >      begin
347 >        if TForm_TemplateFile(tool).SelectedFile.ID > -1 then
348 >          hint := hint + #13+#10 + 'Selected File: ' +
349 >                FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' +
350 >                TForm_TemplateFile(tool).SelectedFile.Name + '.' +
351 >                TForm_TemplateFile(tool).SelectedFile.Extension
352 >        else
353 >          hint := hint + #13+#10 + 'Selected File: none';
354 >      end;
355      end
356      else
357        hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
# Line 380 | Line 420 | begin
420    tb_rawedit.Enabled := active;
421    tb_txmpreplacer.Enabled := active;
422    tb_extractor.Enabled := active;
423 +  tb_meta.Enabled := active;
424   //  tb_compare.Enabled := active;
425   //  tb_structure.Enabled := active;
426   end;
427  
428   procedure TForm_Main.UpdateStatBar;
429   begin
430 <  if Length(DataConnections) > 0 then
430 >  if ConManager.Count > 0 then
431    begin
432      Self.Caption      := 'Oni Un/Packer ' + version;
433      ActivateTools(True);
434 <    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
434 >    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
435    end
436    else
437    begin
# Line 400 | Line 441 | begin
441      statbar.Panels.Items[2].Text := '';
442      ActivateTools(False);
443    end;
444 <  menu_conns.Enabled := Length(DataConnections) > 0;
444 >  menu_conns.Enabled := ConManager.Count > 0;
445   end;
446  
447  
# Line 412 | Line 453 | var
453    position: TTBDockPosition;
454    mode: TTBItemDisplayMode;
455    i: Integer;
415  isEnabled: Boolean;
456   begin
457    toolbar := TTBToolbar(Sender);
458    if toolbar.Floating then
# Line 446 | Line 486 | var
486   begin
487    if MDITab.MDIChildCount > 0 then
488      for i := 0 to MDITab.MDIChildCount - 1 do
489 <      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
490 <        TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
489 >      if MDITab.MDIChildren[i] is TForm_BaseTemplate then
490 >        TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
491  
492    menu_conns.Clear;
493 <  if ConnectionManager.Count > 0 then
493 >  if ConManager.Count > 0 then
494    begin
495 <    for i := 0 to ConnectionManager.Count - 1 do
495 >    for i := 0 to ConManager.Count - 1 do
496      begin
497        entry := TTBItem.Create(menu_conns);
498 <      entry.Caption := ExtractFileName(DataConnections[i].FileName);
498 >      entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
499        entry.Name := 'menu_conn_' + IntToStr(i);
500        entry.OnClick := menu_conns_itemClick;
501        menu_conns.Add(entry);
# Line 467 | Line 507 | end;
507  
508   procedure TForm_Main.LoadFile(typedb: Boolean);
509   var
510 <  ext: String;
510 >  i: Integer;
511   begin
512    opend.InitialDir := AppSettings.DatPath;
513    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
# Line 477 | Line 517 | begin
517      opend.FilterIndex := 2;
518    if opend.Execute then
519    begin
520 <    ext := ExtractFileExt(opend.FileName);
521 <    if ext = '.dat' then
522 <    begin
483 <      CreateConnection(opend.FileName);
484 <    end else if ext = '.oldb' then
485 <    begin
486 <      CreateConnection(opend.FileName);
487 <    end else
488 <      ShowMessage('Incompatible file');
520 >    if opend.Files.Count > 0 then
521 >      for i := 0 to opend.Files.Count - 1 do
522 >        CreateConnection(opend.Files.Strings[i]);
523      AppSettings.DatPath := ExtractFilepath(opend.FileName);
524    end;
525    UpdateStatBar;
# Line 524 | Line 558 | end;
558   {####################################}
559   procedure TForm_Main.menu_createdbClick(Sender: TObject);
560   begin
527  ShowMessage('Not yet usable');
528 {
561    opend.Filter     := 'Oni-Dat-Files|*.dat';
562    saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
563    saved.DefaultExt := 'oldb';
564    if opend.Execute then
565      if saved.Execute then
566        Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
535 }
567   end;
568  
569  
570   procedure TForm_Main.menu_createlvlClick(Sender: TObject);
571   begin
541  ShowMessage('Not yet usable');
542 {
572    opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
573    saved.Filter     := 'Oni-Dat-Files|*.dat';
574    saved.DefaultExt := 'dat';
575    if opend.Execute then
576      if saved.Execute then
577        Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
549 }
578   end;
579  
580  
# Line 555 | Line 583 | end;
583   {#################################}
584   procedure TForm_Main.menu_previewClick(Sender: TObject);
585   begin
586 <  open_child('preview', nil, -1);
586 >  open_child('preview');
587   end;
588  
589   procedure TForm_Main.menu_bineditClick(Sender: TObject);
590   begin
591 <  open_child('binedit', nil, -1);
591 >  open_child('binedit');
592   end;
593  
594   procedure TForm_Main.menu_raweditClick(Sender: TObject);
595   begin
596 <  open_child('rawedit', nil, -1);
596 >  open_child('rawedit');
597   end;
598  
599   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
600   begin
601 <  open_child('txmpreplace', nil, -1);
601 >  open_child('txmpreplace');
602   end;
603  
604   procedure TForm_Main.menu_extractorClick(Sender: TObject);
605   begin
606 <  open_child('extractor', nil, -1);
606 >  open_child('extractor');
607   end;
608  
609   procedure TForm_Main.menu_metaClick(Sender: TObject);
610   begin
611 <  ShowMessage('TBD');
611 >  open_child('meta');
612   end;
613  
614   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
615   begin
616 <  open_child('compare', nil, -1);
616 >  open_child('compare');
617   end;
618  
619  
# Line 651 | Line 679 | end;
679   procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
680   var
681    name: String;
682 <  i: Integer;
682 >  index: Integer;
683 >  RepMsg: TStatusMessages;
684   begin
685 <  name := TTBItem(Sender).Caption;
685 >  index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
686 >  name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
687    if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
688          name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
689    begin
690 <    for i := 0 to High(DataConnections) do
691 <      if ExtractFileName(DataConnections[i].FileName) = name then
692 <      begin
693 <        CloseDataConnection(DataConnections[i]);
664 <        Break;
665 <      end;
690 >    CheckConnectionCloseable(index);
691 >    ConManager.CloseConnectionByIndex(index, RepMsg);
692 >    ShowOpenMsg(RepMsg);
693 >    UpdateConLists;
694    end;
695    UpdateStatBar;
696   end;
# Line 700 | Line 728 | end;
728  
729  
730  
731 < function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
731 > function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
732 > type
733 >  TTemplate = class of TForm_BaseTemplate;
734 >  TTool = record
735 >      name: String;
736 >      icon: Integer;
737 >      caption: String;
738 >      classt: TTemplate;
739 >  end;
740 > const
741 >  Tools: array[0..5] of TTool = (
742 >    (name: 'binedit';     icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
743 >    (name: 'extractor';   icon: 8; caption: 'Extractor';          classt: TForm_Extractor),
744 >    (name: 'preview';     icon: 4; caption: 'Preview-Window';     classt: TForm_Preview),
745 >    (name: 'rawedit';     icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
746 >    (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer';      classt: TForm_TxmpReplace),
747 >    (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
748 >  );
749   var
750 <  toolform:    TForm_ToolTemplate;
750 >  toolform:    TForm_BaseTemplate;
751    i:           Integer;
752    tag:         Integer;
708  caption_end: String;
753    iconindex:   Integer;
754   begin
755    Result := nil;
# Line 717 | Line 761 | begin
761          tag := MDIChildren[i].Tag + 1;
762  
763    iconindex := -1;
720  caption_end := IntToStr(tag) + '       ';
764  
765 <  if window_context = 'binedit' then
766 <  begin
767 <    toolform         := TForm_BinEdit.Create(Self);
768 <    toolform.Caption := 'Binary .dat-Editor ' + caption_end;
769 <    iconindex        := 5;
770 <  end;
771 <  if window_context = 'extractor' then
772 <  begin
773 <    toolform         := TForm_Extractor.Create(Self);
774 <    toolform.Caption := 'Extractor ' + caption_end;
775 <    iconindex        := 8;
776 <  end;
734 <  if window_context = 'preview' then
735 <  begin
736 <    toolform         := TForm_Preview.Create(Self);
737 <    toolform.Caption := 'Preview-Window ' + caption_end;
738 <    iconindex        := 4;
739 <  end;
740 <  if window_context = 'rawedit' then
741 <  begin
742 <    toolform         := TForm_RawEdit.Create(Self);
743 <    toolform.Caption := 'Binary .raw-Editor ' + caption_end;
744 <    iconindex        := 6;
745 <  end;
746 <  if window_context = 'txmpreplace' then
747 <  begin
748 <    toolform         := TForm_TxmpReplace.Create(Application);
749 <    toolform.Caption := 'TXMP Replacer ' + caption_end;
750 <    iconindex        := 7;
765 >  toolform := nil;
766 >
767 >  for i := 0 to High(Tools) do
768 >    if Tools[i].name = window_context then
769 >      Break;
770 >  if i < Length(Tools) then
771 >  begin
772 >    toolform         := TTemplate(Tools[i].classt).Create(Self);
773 >    toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + '       ';
774 >    iconindex        := Tools[i].icon;
775 >  end else begin
776 >    ShowMessage('WindowContext not found!');
777    end;
778  
779    if Assigned(toolform) then
# Line 756 | Line 782 | begin
782      toolform.Tag     := tag;
783      MDITab.AddTab(TForm(toolform), iconindex);
784      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
785 <    if (fileid > -1) and (connection <> nil) then
785 >    if Connection > -1 then
786      begin
787 <      toolform.SelectFileID(connection, fileid);
787 >      toolform.SelectConnection(connection);
788 >      if (FileID > -1) and (toolform is TForm_TemplateFile) then
789 >        TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
790      end;
791      Result := toolform;
792    end;
793   end;
794  
795 + function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
796 + begin
797 +  open_child(window_context, Connection, -1);
798 + end;
799 +
800 + function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
801 + begin
802 +  open_child(window_context, -1, -1);
803 + end;
804 +
805   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)