[93] | 1 | unit Main;
|
---|
| 2 | interface
|
---|
| 3 | uses
|
---|
| 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 5 | Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
|
---|
| 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;
|
---|
| 12 |
|
---|
| 13 | type
|
---|
| 14 | TForm_Main = class(TForm)
|
---|
| 15 | saved: TSaveDialog;
|
---|
| 16 | opend: TOpenDialog;
|
---|
| 17 | statbar: TStatusBar;
|
---|
| 18 | MenuImages: TImageList;
|
---|
| 19 | DockTop: TTBDock;
|
---|
| 20 | MainMenu: TTBToolbar;
|
---|
| 21 | menu_main: TTBSubmenuItem;
|
---|
| 22 | menu_loadfile: TTBItem;
|
---|
| 23 | menu_sep1: TTBSeparatorItem;
|
---|
| 24 | menu_settings: TTBItem;
|
---|
| 25 | menu_sep4: TTBSeparatorItem;
|
---|
| 26 | menu_exit: TTBItem;
|
---|
| 27 | menu_convert: TTBSubmenuItem;
|
---|
| 28 | menu_createdb: TTBItem;
|
---|
| 29 | menu_createlvl: TTBItem;
|
---|
| 30 | menu_tools: TTBSubmenuItem;
|
---|
| 31 | menu_preview: TTBItem;
|
---|
| 32 | menu_binedit: TTBItem;
|
---|
| 33 | menu_rawedit: TTBItem;
|
---|
| 34 | menu_txmpreplace: TTBItem;
|
---|
| 35 | menu_extractor: TTBItem;
|
---|
| 36 | menu_filecompare: TTBItem;
|
---|
| 37 | menu_levelstructedit: TTBItem;
|
---|
| 38 | menu_view: TTBSubmenuItem;
|
---|
| 39 | menu_windows_cascade: TTBItem;
|
---|
| 40 | menu_windows_tile: TTBItem;
|
---|
| 41 | menu_windows_closeall: TTBItem;
|
---|
| 42 | menu_sep3: TTBSeparatorItem;
|
---|
| 43 | menu_windows_next: TTBItem;
|
---|
| 44 | menu_windows_previous: TTBItem;
|
---|
| 45 | menu_sep2: TTBSeparatorItem;
|
---|
| 46 | menu_About: TTBItem;
|
---|
| 47 | Toolbar: TTBToolbar;
|
---|
| 48 | tbOpen: TTBItem;
|
---|
| 49 | DockLeft: TTBDock;
|
---|
| 50 | DockRight: TTBDock;
|
---|
| 51 | DockBottom: TTBDock;
|
---|
| 52 | MDIToolbar: TTBToolbar;
|
---|
| 53 | TBControlItem1: TTBControlItem;
|
---|
| 54 | MDITab: TMDITab;
|
---|
| 55 | menu_toolbars: TTBSubmenuItem;
|
---|
| 56 | menu_view_mdibar: TTBItem;
|
---|
| 57 | menu_view_statusbar: TTBItem;
|
---|
| 58 | menu_view_toolbar: TTBItem;
|
---|
| 59 | tb_separator1: TTBSeparatorItem;
|
---|
| 60 | tb_preview: TTBItem;
|
---|
| 61 | tb_structure: TTBItem;
|
---|
| 62 | tb_compare: TTBItem;
|
---|
| 63 | tb_extractor: TTBItem;
|
---|
| 64 | tb_txmpreplacer: TTBItem;
|
---|
| 65 | tb_rawedit: TTBItem;
|
---|
| 66 | tb_datedit: TTBItem;
|
---|
| 67 | menu_windows_tilevert: TTBItem;
|
---|
| 68 | tb_meta: TTBItem;
|
---|
| 69 | menu_meta: TTBItem;
|
---|
| 70 | TBSeparatorItem1: TTBSeparatorItem;
|
---|
| 71 | tb_db2dat: TTBItem;
|
---|
| 72 | tb_dat2db: TTBItem;
|
---|
| 73 | menu_loaddb: TTBItem;
|
---|
| 74 | tb_opendb: TTBItem;
|
---|
| 75 | Images_Close: TImageList;
|
---|
| 76 | menu_conns: TTBSubmenuItem;
|
---|
| 77 | menu_windows: TTBSubmenuItem;
|
---|
| 78 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 79 | procedure FormResize(Sender: TObject);
|
---|
| 80 | procedure FormCreate(Sender: TObject);
|
---|
| 81 | procedure ActivateTools(active: Boolean);
|
---|
| 82 | procedure UpdateStatBar;
|
---|
| 83 | procedure UpdateConLists;
|
---|
| 84 | procedure LoadFile(typedb: Boolean);
|
---|
| 85 | function TryCloseAll: Boolean;
|
---|
| 86 | procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer;
|
---|
| 87 | const Rect: TRect; Active: Boolean);
|
---|
| 88 | procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
| 89 | Shift: TShiftState; X, Y: Integer);
|
---|
| 90 | procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
| 91 | Y: Integer);
|
---|
| 92 | procedure ToolbarDockChanged(Sender: TObject);
|
---|
| 93 | procedure CreateConnection(filename: String);
|
---|
| 94 |
|
---|
| 95 | procedure menu_loadfileClick(Sender: TObject);
|
---|
| 96 | procedure menu_loaddbClick(Sender: TObject);
|
---|
| 97 | procedure menu_settingsClick(Sender: TObject);
|
---|
| 98 | procedure menu_exitClick(Sender: TObject);
|
---|
| 99 |
|
---|
| 100 | procedure menu_createlvlClick(Sender: TObject);
|
---|
| 101 | procedure menu_createdbClick(Sender: TObject);
|
---|
| 102 |
|
---|
| 103 | procedure menu_bineditClick(Sender: TObject);
|
---|
| 104 | procedure menu_filecompareClick(Sender: TObject);
|
---|
| 105 | procedure menu_raweditClick(Sender: TObject);
|
---|
| 106 | procedure menu_extractorClick(Sender: TObject);
|
---|
| 107 | procedure menu_txmpreplaceClick(Sender: TObject);
|
---|
| 108 | procedure menu_previewClick(Sender: TObject);
|
---|
| 109 | 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);
|
---|
| 114 | procedure menu_windows_tileClick(Sender: TObject);
|
---|
| 115 | procedure menu_windows_closeallClick(Sender: TObject);
|
---|
| 116 | procedure menu_windows_previousClick(Sender: TObject);
|
---|
| 117 | procedure menu_windows_nextClick(Sender: TObject);
|
---|
| 118 | procedure menu_conns_itemClick(Sender: TObject);
|
---|
| 119 | procedure menu_windows_itemClick(Sender: TObject);
|
---|
| 120 | procedure menu_view_mdibarClick(Sender: TObject);
|
---|
| 121 | procedure menu_view_statusbarClick(Sender: TObject);
|
---|
| 122 | procedure menu_view_toolbarClick(Sender: TObject);
|
---|
| 123 |
|
---|
| 124 | procedure menu_AboutClick(Sender: TObject);
|
---|
| 125 |
|
---|
| 126 | procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
|
---|
| 127 | private
|
---|
| 128 | ConnectionManager: TConnectionManager;
|
---|
| 129 | public
|
---|
| 130 | procedure DefaultHandler(var Message); override;
|
---|
| 131 | end;
|
---|
| 132 |
|
---|
| 133 | var
|
---|
| 134 | Form_Main: TForm_Main;
|
---|
| 135 |
|
---|
| 136 | implementation
|
---|
| 137 |
|
---|
| 138 | {$R *.dfm}
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | procedure ShowOpenMsg(msg: TStatusMessages);
|
---|
| 142 | begin
|
---|
| 143 | case msg of
|
---|
| 144 | SM_AlreadyOpened: ShowMessage('File already opened.');
|
---|
| 145 | SM_FileNotFound: ShowMessage('File not found.');
|
---|
| 146 | SM_UnknownExtension: ShowMessage('Unknown extension.');
|
---|
| 147 | SM_IncompatibleFile: ShowMessage('Incompatible file format.');
|
---|
| 148 | SM_UnknownError: ShowMessage('Unknown error.');
|
---|
| 149 | end;
|
---|
| 150 | end;
|
---|
| 151 |
|
---|
| 152 | procedure TForm_Main.CreateConnection(filename: String);
|
---|
| 153 | var
|
---|
| 154 | RepMsg: TStatusMessages;
|
---|
| 155 | begin
|
---|
| 156 | ConnectionManager.OpenConnection(filename, RepMsg);
|
---|
| 157 | ShowOpenMsg(RepMsg);
|
---|
| 158 | if RepMsg = SM_OK then
|
---|
| 159 | begin
|
---|
| 160 | UpdateStatBar;
|
---|
| 161 | end;
|
---|
| 162 | end;
|
---|
| 163 |
|
---|
| 164 | { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
|
---|
| 165 | procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
|
---|
| 166 | var
|
---|
| 167 | strings: TStringList;
|
---|
| 168 | begin
|
---|
| 169 | if (Msg.CopyDataStruct.dwData = SecondInstMsgId) and (SecondInstMsgId <> 0) then
|
---|
| 170 | begin
|
---|
| 171 | Application.BringToFront;
|
---|
| 172 |
|
---|
| 173 | strings := TStringList.Create;
|
---|
| 174 | strings.Text := ParamBlobToStr(Msg.CopyDataStruct.lpData);
|
---|
| 175 | if strings.Count = 2 then
|
---|
| 176 | begin
|
---|
| 177 | if strings.Strings[0] = 'opf' then
|
---|
| 178 | begin
|
---|
| 179 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
| 180 | end
|
---|
| 181 | else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') then
|
---|
| 182 | begin
|
---|
| 183 | CreateConnection(strings.Strings[1]);
|
---|
| 184 | end;
|
---|
| 185 | end;
|
---|
| 186 | end
|
---|
| 187 | else
|
---|
| 188 | inherited;
|
---|
| 189 | end;
|
---|
| 190 |
|
---|
| 191 | {----------------------------------------------------------------------------}
|
---|
| 192 | { Wir überschreiben den DefaultHandler, der alle Nachrichten zuerst bekommt, }
|
---|
| 193 | { damit wir auf die Nachricht mit der ID SecondInstMsgId reagieren können. }
|
---|
| 194 | { (Dies ist notwendig, da wir jetzt noch nicht wissen welchen Wert }
|
---|
| 195 | { die ID haben wird, weswegen wir keine statische Message-Prozedure, }
|
---|
| 196 | { so wie bei WM_COPYDATA, schreiben können.) }
|
---|
| 197 | {----------------------------------------------------------------------------}
|
---|
| 198 | procedure TForm_Main.DefaultHandler(var Message);
|
---|
| 199 | begin
|
---|
| 200 | if TMessage(Message).Msg = SecondInstMsgId then
|
---|
| 201 | { Eine zweite Instanz hat uns nach dem Handle gefragt }
|
---|
| 202 | { Es wird in die Message-Queue des Threads gepostet. }
|
---|
| 203 | PostThreadMessage(TMessage(Message).WParam, SecondInstMsgId, Handle, 0)
|
---|
| 204 | else
|
---|
| 205 | inherited;
|
---|
| 206 | end;
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | procedure TForm_Main.FormCreate(Sender: TObject);
|
---|
| 211 | var
|
---|
| 212 | RepMsg: TStatusMessages;
|
---|
| 213 | begin
|
---|
| 214 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 215 | Self.FormResize(Self);
|
---|
| 216 |
|
---|
| 217 | ConnectionManager := TConnectionManager.Create;
|
---|
| 218 | ConnectionManager.OnCoonnectionListChanged := UpdateConLists;
|
---|
| 219 |
|
---|
| 220 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
| 221 | begin
|
---|
| 222 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) +
|
---|
| 223 | '\oniunpacker.ini');
|
---|
| 224 | Reset(AppSettingsFile);
|
---|
| 225 | Read(AppSettingsFile, AppSettings);
|
---|
| 226 | CloseFile(AppSettingsFile);
|
---|
| 227 | end
|
---|
| 228 | else
|
---|
| 229 | begin
|
---|
| 230 | AppSettings.DatPath := ExtractFilepath(Application.EXEname);
|
---|
| 231 | AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract';
|
---|
| 232 | AppSettings.FilenumbersAsHex := False;
|
---|
| 233 | AppSettings.CharSet := DEFAULT_CHARSET;
|
---|
| 234 | AppSettings.HideUnusedData := False;
|
---|
| 235 | end;
|
---|
| 236 |
|
---|
| 237 | if MidStr(ParamStr(1), 1, 3) = 'opf' then
|
---|
| 238 | begin
|
---|
| 239 | ShowMessage('Load OPF-File: ' + ParamStr(2));
|
---|
| 240 | end
|
---|
| 241 | else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then
|
---|
| 242 | begin
|
---|
| 243 | CreateConnection(ParamStr(2));
|
---|
| 244 | end;
|
---|
| 245 | UpdateStatBar;
|
---|
| 246 | end;
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | procedure TForm_Main.FormResize(Sender: TObject);
|
---|
| 252 | begin
|
---|
| 253 | statbar.Panels.Items[0].Width := Self.Width - 200;
|
---|
| 254 | MDITab.Width := Self.Width - 20;
|
---|
| 255 | end;
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
|
---|
| 261 | TabIndex: Integer; const Rect: TRect; Active: Boolean);
|
---|
| 262 | var
|
---|
| 263 | x, y: Integer;
|
---|
| 264 | iconindex: Integer;
|
---|
| 265 | caption: String;
|
---|
| 266 | begin
|
---|
| 267 | iconindex := TMDITab(Control).Glyphs[TabIndex];
|
---|
| 268 | caption := TMDITab(Control).Captions[TabIndex];
|
---|
| 269 | if active then
|
---|
| 270 | begin
|
---|
| 271 | Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
|
---|
| 272 | y := Rect.Top + 1;
|
---|
| 273 | end else
|
---|
| 274 | y := Rect.Top;
|
---|
| 275 | if iconindex >= 0 then
|
---|
| 276 | begin
|
---|
| 277 | TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
|
---|
| 278 | x := Rect.Left + 26;
|
---|
| 279 | end else
|
---|
| 280 | x := Rect.Left + 4;
|
---|
| 281 | Control.Canvas.TextOut(x, y + 2, caption);
|
---|
| 282 | if active then
|
---|
| 283 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 0)
|
---|
| 284 | else
|
---|
| 285 | Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 1);
|
---|
| 286 | end;
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 | procedure TForm_Main.MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
| 290 | Y: Integer);
|
---|
| 291 | var
|
---|
| 292 | pt: TPoint;
|
---|
| 293 | tabIndex: Integer;
|
---|
| 294 | hint: String;
|
---|
| 295 | begin
|
---|
| 296 | pt.X := X;
|
---|
| 297 | pt.Y := Y;
|
---|
| 298 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
| 299 | hint := '';
|
---|
| 300 |
|
---|
| 301 | if tabIndex >= 0 then
|
---|
| 302 | begin
|
---|
| 303 | if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
|
---|
| 304 | begin
|
---|
| 305 | if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then
|
---|
| 306 | hint := 'Connection: ' +
|
---|
| 307 | ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10
|
---|
| 308 | else
|
---|
| 309 | hint := 'Connection: none' + #13+#10;
|
---|
| 310 | if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then
|
---|
| 311 | hint := hint + 'Selected File: ' +
|
---|
| 312 | TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName
|
---|
| 313 | else
|
---|
| 314 | hint := hint + 'Selected File: none';
|
---|
| 315 | end
|
---|
| 316 | else
|
---|
| 317 | hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
|
---|
| 318 | if hint <> MDITab.Hint then
|
---|
| 319 | begin
|
---|
| 320 | MDITab.Hint := hint;
|
---|
| 321 | MDITab.ShowHint := True;
|
---|
| 322 | end;
|
---|
| 323 | end
|
---|
| 324 | else
|
---|
| 325 | begin
|
---|
| 326 | MDITab.ShowHint := False;
|
---|
| 327 | MDITab.Hint := '';
|
---|
| 328 | end;
|
---|
| 329 | end;
|
---|
| 330 |
|
---|
| 331 | procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
| 332 | Shift: TShiftState; X, Y: Integer);
|
---|
| 333 | var
|
---|
| 334 | pt: TPoint;
|
---|
| 335 | tabIndex: Integer;
|
---|
| 336 | tabRect: TRect;
|
---|
| 337 | tabX, tabY, tabWidth: Integer;
|
---|
| 338 | begin
|
---|
| 339 | pt.X := X;
|
---|
| 340 | pt.Y := Y;
|
---|
| 341 | tabIndex := MDITab.GetTabAtPos(pt);
|
---|
| 342 |
|
---|
| 343 | // if (Button = mbRight) and (tabIndex >= 0) then
|
---|
| 344 | // MDITab.MDIChildren[tabIndex].Close;
|
---|
| 345 |
|
---|
| 346 | if (Button = mbLeft) and (tabIndex >= 0) then
|
---|
| 347 | begin
|
---|
| 348 | tabrect := MDITab.TabRect(tabIndex);
|
---|
| 349 | tabX := X - tabrect.Left;
|
---|
| 350 | tabY := Y - tabrect.Top;
|
---|
| 351 | tabwidth := tabrect.Right - tabrect.Left;
|
---|
| 352 | if (tabY >= 4) and (tabY <= 17) then
|
---|
| 353 | if (tabX >= tabwidth - 19) and (tabX <= tabwidth - 7) then
|
---|
| 354 | MDITab.MDIChildren[tabIndex].Close;
|
---|
| 355 | end;
|
---|
| 356 | end;
|
---|
| 357 |
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 |
|
---|
| 361 | procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 362 | begin
|
---|
| 363 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini');
|
---|
| 364 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
|
---|
| 365 | Reset(AppSettingsFile)
|
---|
| 366 | else
|
---|
| 367 | Rewrite(AppSettingsFile);
|
---|
| 368 | Write(AppSettingsFile, AppSettings);
|
---|
| 369 | CloseFile(AppSettingsFile);
|
---|
| 370 | Action := caFree;
|
---|
| 371 | end;
|
---|
| 372 |
|
---|
| 373 |
|
---|
| 374 |
|
---|
| 375 | procedure TForm_Main.ActivateTools(active: Boolean);
|
---|
| 376 | begin
|
---|
| 377 | menu_tools.Enabled := active;
|
---|
| 378 | tb_preview.Enabled := active;
|
---|
| 379 | tb_datedit.Enabled := active;
|
---|
| 380 | tb_rawedit.Enabled := active;
|
---|
| 381 | tb_txmpreplacer.Enabled := active;
|
---|
| 382 | tb_extractor.Enabled := active;
|
---|
| 383 | // tb_compare.Enabled := active;
|
---|
| 384 | // tb_structure.Enabled := active;
|
---|
| 385 | end;
|
---|
| 386 |
|
---|
| 387 | procedure TForm_Main.UpdateStatBar;
|
---|
| 388 | begin
|
---|
| 389 | if Length(DataConnections) > 0 then
|
---|
| 390 | begin
|
---|
| 391 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 392 | ActivateTools(True);
|
---|
| 393 | statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
|
---|
| 394 | end
|
---|
| 395 | else
|
---|
| 396 | begin
|
---|
| 397 | Self.Caption := 'Oni Un/Packer ' + version;
|
---|
| 398 | statbar.Panels.Items[0].Text := '';
|
---|
| 399 | statbar.Panels.Items[1].Text := 'Connections: -';
|
---|
| 400 | statbar.Panels.Items[2].Text := '';
|
---|
| 401 | ActivateTools(False);
|
---|
| 402 | end;
|
---|
| 403 | menu_conns.Enabled := Length(DataConnections) > 0;
|
---|
| 404 | end;
|
---|
| 405 |
|
---|
| 406 |
|
---|
| 407 |
|
---|
| 408 |
|
---|
| 409 | procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
|
---|
| 410 | var
|
---|
| 411 | toolbar: TTBToolbar;
|
---|
| 412 | position: TTBDockPosition;
|
---|
| 413 | mode: TTBItemDisplayMode;
|
---|
| 414 | i: Integer;
|
---|
| 415 | isEnabled: Boolean;
|
---|
| 416 | begin
|
---|
| 417 | toolbar := TTBToolbar(Sender);
|
---|
| 418 | if toolbar.Floating then
|
---|
| 419 | mode := nbdmImageAndText
|
---|
| 420 | else begin
|
---|
| 421 | position := toolbar.CurrentDock.Position;
|
---|
| 422 | if position in [dpLeft, dpRight] then
|
---|
| 423 | mode := nbdmDefault
|
---|
| 424 | else
|
---|
| 425 | mode := nbdmImageAndText;
|
---|
| 426 | end;
|
---|
| 427 | for i := 0 to toolbar.Items.Count - 1 do
|
---|
| 428 | toolbar.Items.Items[i].DisplayMode := mode;
|
---|
| 429 | end;
|
---|
| 430 |
|
---|
| 431 | function TForm_Main.TryCloseAll: Boolean;
|
---|
| 432 | begin
|
---|
| 433 | menu_windows_closeallClick(Self);
|
---|
| 434 | Application.ProcessMessages;
|
---|
| 435 | if MDITab.MDIChildCount = 0 then
|
---|
| 436 | Result := True
|
---|
| 437 | else
|
---|
| 438 | Result := False;
|
---|
| 439 | end;
|
---|
| 440 |
|
---|
| 441 |
|
---|
| 442 | procedure TForm_Main.UpdateConLists;
|
---|
| 443 | var
|
---|
| 444 | i: Integer;
|
---|
| 445 | entry: TTBItem;
|
---|
| 446 | begin
|
---|
| 447 | if MDITab.MDIChildCount > 0 then
|
---|
| 448 | for i := 0 to MDITab.MDIChildCount - 1 do
|
---|
| 449 | if MDITab.MDIChildren[i] is TForm_ToolTemplate then
|
---|
| 450 | TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
|
---|
| 451 |
|
---|
| 452 | menu_conns.Clear;
|
---|
| 453 | if ConnectionManager.Count > 0 then
|
---|
| 454 | begin
|
---|
| 455 | for i := 0 to ConnectionManager.Count - 1 do
|
---|
| 456 | begin
|
---|
| 457 | entry := TTBItem.Create(menu_conns);
|
---|
| 458 | entry.Caption := ExtractFileName(DataConnections[i].FileName);
|
---|
| 459 | entry.Name := 'menu_conn_' + IntToStr(i);
|
---|
| 460 | entry.OnClick := menu_conns_itemClick;
|
---|
| 461 | menu_conns.Add(entry);
|
---|
| 462 | entry := nil;
|
---|
| 463 | end;
|
---|
| 464 | end;
|
---|
| 465 | end;
|
---|
| 466 |
|
---|
| 467 |
|
---|
| 468 | procedure TForm_Main.LoadFile(typedb: Boolean);
|
---|
| 469 | var
|
---|
| 470 | ext: String;
|
---|
| 471 | begin
|
---|
| 472 | opend.InitialDir := AppSettings.DatPath;
|
---|
| 473 | opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
|
---|
| 474 | if typedb then
|
---|
| 475 | opend.FilterIndex := 3
|
---|
| 476 | else
|
---|
| 477 | opend.FilterIndex := 2;
|
---|
| 478 | if opend.Execute then
|
---|
| 479 | begin
|
---|
| 480 | ext := ExtractFileExt(opend.FileName);
|
---|
| 481 | if ext = '.dat' then
|
---|
| 482 | 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');
|
---|
| 489 | AppSettings.DatPath := ExtractFilepath(opend.FileName);
|
---|
| 490 | end;
|
---|
| 491 | UpdateStatBar;
|
---|
| 492 | end;
|
---|
| 493 |
|
---|
| 494 |
|
---|
| 495 | {#################################}
|
---|
| 496 | {##### Main-Menu-Handlers #####}
|
---|
| 497 | {#################################}
|
---|
| 498 | procedure TForm_Main.menu_loaddbClick(Sender: TObject);
|
---|
| 499 | begin
|
---|
| 500 | LoadFile(True);
|
---|
| 501 | end;
|
---|
| 502 |
|
---|
| 503 | procedure TForm_Main.menu_loadfileClick(Sender: TObject);
|
---|
| 504 | begin
|
---|
| 505 | LoadFile(False);
|
---|
| 506 | end;
|
---|
| 507 |
|
---|
| 508 |
|
---|
| 509 | procedure TForm_Main.menu_settingsClick(Sender: TObject);
|
---|
| 510 | begin
|
---|
| 511 | Form_Settings.Visible := True;
|
---|
| 512 | Self.Enabled := False;
|
---|
| 513 | end;
|
---|
| 514 |
|
---|
| 515 |
|
---|
| 516 | procedure TForm_Main.menu_exitClick(Sender: TObject);
|
---|
| 517 | begin
|
---|
| 518 | Self.Close;
|
---|
| 519 | end;
|
---|
| 520 |
|
---|
| 521 |
|
---|
| 522 | {####################################}
|
---|
| 523 | {##### Converters-Menu-Handlers #####}
|
---|
| 524 | {####################################}
|
---|
| 525 | procedure TForm_Main.menu_createdbClick(Sender: TObject);
|
---|
| 526 | begin
|
---|
| 527 | ShowMessage('Not yet usable');
|
---|
| 528 | {
|
---|
| 529 | opend.Filter := 'Oni-Dat-Files|*.dat';
|
---|
| 530 | saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
| 531 | saved.DefaultExt := 'oldb';
|
---|
| 532 | if opend.Execute then
|
---|
| 533 | if saved.Execute then
|
---|
| 534 | Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
|
---|
| 535 | }
|
---|
| 536 | end;
|
---|
| 537 |
|
---|
| 538 |
|
---|
| 539 | procedure TForm_Main.menu_createlvlClick(Sender: TObject);
|
---|
| 540 | begin
|
---|
| 541 | ShowMessage('Not yet usable');
|
---|
| 542 | {
|
---|
| 543 | opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
|
---|
| 544 | saved.Filter := 'Oni-Dat-Files|*.dat';
|
---|
| 545 | saved.DefaultExt := 'dat';
|
---|
| 546 | if opend.Execute then
|
---|
| 547 | if saved.Execute then
|
---|
| 548 | Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
|
---|
| 549 | }
|
---|
| 550 | end;
|
---|
| 551 |
|
---|
| 552 |
|
---|
| 553 | {#################################}
|
---|
| 554 | {##### Tools-Menu-Handlers #####}
|
---|
| 555 | {#################################}
|
---|
| 556 | procedure TForm_Main.menu_previewClick(Sender: TObject);
|
---|
| 557 | begin
|
---|
| 558 | open_child('preview', nil, -1);
|
---|
| 559 | end;
|
---|
| 560 |
|
---|
| 561 | procedure TForm_Main.menu_bineditClick(Sender: TObject);
|
---|
| 562 | begin
|
---|
| 563 | open_child('binedit', nil, -1);
|
---|
| 564 | end;
|
---|
| 565 |
|
---|
| 566 | procedure TForm_Main.menu_raweditClick(Sender: TObject);
|
---|
| 567 | begin
|
---|
| 568 | open_child('rawedit', nil, -1);
|
---|
| 569 | end;
|
---|
| 570 |
|
---|
| 571 | procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
|
---|
| 572 | begin
|
---|
| 573 | open_child('txmpreplace', nil, -1);
|
---|
| 574 | end;
|
---|
| 575 |
|
---|
| 576 | procedure TForm_Main.menu_extractorClick(Sender: TObject);
|
---|
| 577 | begin
|
---|
| 578 | open_child('extractor', nil, -1);
|
---|
| 579 | end;
|
---|
| 580 |
|
---|
| 581 | procedure TForm_Main.menu_metaClick(Sender: TObject);
|
---|
| 582 | begin
|
---|
| 583 | ShowMessage('TBD');
|
---|
| 584 | end;
|
---|
| 585 |
|
---|
| 586 | procedure TForm_Main.menu_filecompareClick(Sender: TObject);
|
---|
| 587 | begin
|
---|
| 588 | open_child('compare', nil, -1);
|
---|
| 589 | end;
|
---|
| 590 |
|
---|
| 591 |
|
---|
| 592 | {#################################}
|
---|
| 593 | {##### View-Menu-Handlers #####}
|
---|
| 594 | {#################################}
|
---|
| 595 | procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
|
---|
| 596 | begin
|
---|
| 597 | Self.Cascade;
|
---|
| 598 | end;
|
---|
| 599 |
|
---|
| 600 | procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
|
---|
| 601 | begin
|
---|
| 602 | Self.TileMode := tbVertical;
|
---|
| 603 | Self.Tile;
|
---|
| 604 | end;
|
---|
| 605 |
|
---|
| 606 | procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
|
---|
| 607 | begin
|
---|
| 608 | Self.TileMode := tbHorizontal;
|
---|
| 609 | Self.Tile;
|
---|
| 610 | end;
|
---|
| 611 |
|
---|
| 612 | procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
|
---|
| 613 | begin
|
---|
| 614 | MDITab.CloseAll;
|
---|
| 615 | end;
|
---|
| 616 |
|
---|
| 617 | procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
|
---|
| 618 | begin
|
---|
| 619 | if MDIChildCount > 1 then
|
---|
| 620 | if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
|
---|
| 621 | MDITab.MDIChildren[0].BringToFront
|
---|
| 622 | else
|
---|
| 623 | MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
|
---|
| 624 | end;
|
---|
| 625 |
|
---|
| 626 | procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
|
---|
| 627 | begin
|
---|
| 628 | if MDIChildCount > 1 then
|
---|
| 629 | if MDITab.TabIndex = 0 then
|
---|
| 630 | MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
|
---|
| 631 | else
|
---|
| 632 | MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
|
---|
| 633 | end;
|
---|
| 634 |
|
---|
| 635 |
|
---|
| 636 | {##################################}
|
---|
| 637 | {##### Windows-Menu-Handlers #####}
|
---|
| 638 | {##################################}
|
---|
| 639 | procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
|
---|
| 640 | var
|
---|
| 641 | name: String;
|
---|
| 642 | begin
|
---|
| 643 | name := TTBItem(Sender).Name;
|
---|
| 644 | end;
|
---|
| 645 |
|
---|
| 646 |
|
---|
| 647 |
|
---|
| 648 | {######################################}
|
---|
| 649 | {##### Connections-Menu-Handlers #####}
|
---|
| 650 | {######################################}
|
---|
| 651 | procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
|
---|
| 652 | var
|
---|
| 653 | name: String;
|
---|
| 654 | i: Integer;
|
---|
| 655 | begin
|
---|
| 656 | name := TTBItem(Sender).Caption;
|
---|
| 657 | if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
|
---|
| 658 | name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
|
---|
| 659 | begin
|
---|
| 660 | for i := 0 to High(DataConnections) do
|
---|
| 661 | if ExtractFileName(DataConnections[i].FileName) = name then
|
---|
| 662 | begin
|
---|
| 663 | CloseDataConnection(DataConnections[i]);
|
---|
| 664 | Break;
|
---|
| 665 | end;
|
---|
| 666 | end;
|
---|
| 667 | UpdateStatBar;
|
---|
| 668 | end;
|
---|
| 669 |
|
---|
| 670 |
|
---|
| 671 | {###################################}
|
---|
| 672 | {##### Toolbars-Menu-Handlers #####}
|
---|
| 673 | {###################################}
|
---|
| 674 | procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
|
---|
| 675 | begin
|
---|
| 676 | menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
|
---|
| 677 | Toolbar.Visible := menu_view_toolbar.Checked;
|
---|
| 678 | end;
|
---|
| 679 |
|
---|
| 680 | procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
|
---|
| 681 | begin
|
---|
| 682 | menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
|
---|
| 683 | statbar.Visible := menu_view_statusbar.Checked;
|
---|
| 684 | end;
|
---|
| 685 |
|
---|
| 686 | procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
|
---|
| 687 | begin
|
---|
| 688 | menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
|
---|
| 689 | mditoolbar.Visible := menu_view_mdibar.Checked;
|
---|
| 690 | end;
|
---|
| 691 |
|
---|
| 692 |
|
---|
| 693 |
|
---|
| 694 | procedure TForm_Main.menu_AboutClick(Sender: TObject);
|
---|
| 695 | begin
|
---|
| 696 | ShowMessage('Will be implemented later ;)');
|
---|
| 697 | end;
|
---|
| 698 |
|
---|
| 699 |
|
---|
| 700 |
|
---|
| 701 |
|
---|
| 702 |
|
---|
| 703 | function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
|
---|
| 704 | var
|
---|
| 705 | toolform: TForm_ToolTemplate;
|
---|
| 706 | i: Integer;
|
---|
| 707 | tag: Integer;
|
---|
| 708 | caption_end: String;
|
---|
| 709 | iconindex: Integer;
|
---|
| 710 | begin
|
---|
| 711 | Result := nil;
|
---|
| 712 |
|
---|
| 713 | tag := 1;
|
---|
| 714 | if MDIChildCount > 0 then
|
---|
| 715 | for i := 0 to MDIChildCount - 1 do
|
---|
| 716 | if MDIChildren[i].Tag >= tag then
|
---|
| 717 | tag := MDIChildren[i].Tag + 1;
|
---|
| 718 |
|
---|
| 719 | iconindex := -1;
|
---|
| 720 | caption_end := IntToStr(tag) + ' ';
|
---|
| 721 |
|
---|
| 722 | if window_context = 'binedit' then
|
---|
| 723 | begin
|
---|
| 724 | toolform := TForm_BinEdit.Create(Self);
|
---|
| 725 | toolform.Caption := 'Binary .dat-Editor ' + caption_end;
|
---|
| 726 | iconindex := 5;
|
---|
| 727 | end;
|
---|
| 728 | if window_context = 'extractor' then
|
---|
| 729 | begin
|
---|
| 730 | toolform := TForm_Extractor.Create(Self);
|
---|
| 731 | toolform.Caption := 'Extractor ' + caption_end;
|
---|
| 732 | iconindex := 8;
|
---|
| 733 | 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;
|
---|
| 751 | end;
|
---|
| 752 |
|
---|
| 753 | if Assigned(toolform) then
|
---|
| 754 | begin
|
---|
| 755 | toolform.Name := window_context + IntToStr(tag);
|
---|
| 756 | toolform.Tag := tag;
|
---|
| 757 | MDITab.AddTab(TForm(toolform), iconindex);
|
---|
| 758 | toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
|
---|
| 759 | if (fileid > -1) and (connection <> nil) then
|
---|
| 760 | begin
|
---|
| 761 | toolform.SelectFileID(connection, fileid);
|
---|
| 762 | end;
|
---|
| 763 | Result := toolform;
|
---|
| 764 | end;
|
---|
| 765 | end;
|
---|
| 766 |
|
---|
| 767 | end.
|
---|