| 1 | unit Main; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | interface | 
 
 
 
 
 | 4 |  | 
 
 
 
 
 | 5 | uses | 
 
 
 
 
 | 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 
 
 
 
 
 | 7 | Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids, | 
 
 
 
 
 | 8 | MPHexEditor, ToolWin, ImgList, Tabs, | 
 
 
 
 
 | 9 | MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, | 
 
 
 
 
 | 10 | Code_Functions, Data, Code_DataStructures, Code_OniDataClass, | 
 
 
 
 
 | 11 | Helper_LevelDB, Code_Exporters, Settings, Tool_Template, | 
 
 
 
 
 | 12 | Tool_BinEdit, Tool_Extractor, Tool_Preview, Tool_RawEdit, Tool_TxmpReplace; | 
 
 
 
 
 | 13 |  | 
 
 
 
 
 | 14 | type | 
 
 
 
 
 | 15 | TForm_Main = class(TForm) | 
 
 
 
 
 | 16 | saved:      TSaveDialog; | 
 
 
 
 
 | 17 | opend:      TOpenDialog; | 
 
 
 
 
 | 18 | statbar:    TStatusBar; | 
 
 
 
 
 | 19 | MenuImages: TImageList; | 
 
 
 
 
 | 20 | DockTop:    TTBDock; | 
 
 
 
 
 | 21 | MainMenu:   TTBToolbar; | 
 
 
 
 
 | 22 | menu_main:  TTBSubmenuItem; | 
 
 
 
 
 | 23 | menu_loadfile: TTBItem; | 
 
 
 
 
 | 24 | menu_sep1:  TTBSeparatorItem; | 
 
 
 
 
 | 25 | menu_settings: TTBItem; | 
 
 
 
 
 | 26 | menu_sep4:  TTBSeparatorItem; | 
 
 
 
 
 | 27 | menu_exit:  TTBItem; | 
 
 
 
 
 | 28 | menu_convert: TTBSubmenuItem; | 
 
 
 
 
 | 29 | menu_createdb: TTBItem; | 
 
 
 
 
 | 30 | menu_createlvl: TTBItem; | 
 
 
 
 
 | 31 | menu_tools: TTBSubmenuItem; | 
 
 
 
 
 | 32 | menu_preview: TTBItem; | 
 
 
 
 
 | 33 | menu_binedit: TTBItem; | 
 
 
 
 
 | 34 | menu_rawedit: TTBItem; | 
 
 
 
 
 | 35 | menu_txmpreplace: TTBItem; | 
 
 
 
 
 | 36 | menu_extractor: TTBItem; | 
 
 
 
 
 | 37 | menu_filecompare: TTBItem; | 
 
 
 
 
 | 38 | menu_levelstructedit: TTBItem; | 
 
 
 
 
 | 39 | menu_windows: TTBSubmenuItem; | 
 
 
 
 
 | 40 | menu_windows_cascade: TTBItem; | 
 
 
 
 
 | 41 | menu_windows_tile: TTBItem; | 
 
 
 
 
 | 42 | menu_windows_closeall: TTBItem; | 
 
 
 
 
 | 43 | menu_sep3:  TTBSeparatorItem; | 
 
 
 
 
 | 44 | menu_windows_next: TTBItem; | 
 
 
 
 
 | 45 | menu_windows_previous: TTBItem; | 
 
 
 
 
 | 46 | menu_sep2:  TTBSeparatorItem; | 
 
 
 
 
 | 47 | menu_About: TTBItem; | 
 
 
 
 
 | 48 | Toolbar:    TTBToolbar; | 
 
 
 
 
 | 49 | tbOpen:     TTBItem; | 
 
 
 
 
 | 50 | DockLeft:   TTBDock; | 
 
 
 
 
 | 51 | DockRight:  TTBDock; | 
 
 
 
 
 | 52 | DockBottom: TTBDock; | 
 
 
 
 
 | 53 | MDIToolbar: TTBToolbar; | 
 
 
 
 
 | 54 | TBControlItem1: TTBControlItem; | 
 
 
 
 
 | 55 | MDITab:     TMDITab; | 
 
 
 
 
 | 56 | menu_view:  TTBSubmenuItem; | 
 
 
 
 
 | 57 | menu_view_mdibar: TTBItem; | 
 
 
 
 
 | 58 | menu_view_statusbar: TTBItem; | 
 
 
 
 
 | 59 | menu_view_toolbar: TTBItem; | 
 
 
 
 
 | 60 | tb_separator1: TTBSeparatorItem; | 
 
 
 
 
 | 61 | tb_preview: TTBItem; | 
 
 
 
 
 | 62 | tb_structure: TTBItem; | 
 
 
 
 
 | 63 | tb_compare: TTBItem; | 
 
 
 
 
 | 64 | tb_extractor: TTBItem; | 
 
 
 
 
 | 65 | tb_txmpreplacer: TTBItem; | 
 
 
 
 
 | 66 | tb_rawedit: TTBItem; | 
 
 
 
 
 | 67 | tb_datedit: TTBItem; | 
 
 
 
 
 | 68 | function TryCloseAll: Boolean; | 
 
 
 
 
 | 69 | procedure menu_AboutClick(Sender: TObject); | 
 
 
 
 
 | 70 | procedure menu_settingsClick(Sender: TObject); | 
 
 
 
 
 | 71 | procedure menu_filecompareClick(Sender: TObject); | 
 
 
 
 
 | 72 | procedure menu_raweditClick(Sender: TObject); | 
 
 
 
 
 | 73 | procedure menu_createlvlClick(Sender: TObject); | 
 
 
 
 
 | 74 | procedure menu_extractorClick(Sender: TObject); | 
 
 
 
 
 | 75 | procedure menu_createdbClick(Sender: TObject); | 
 
 
 
 
 | 76 | procedure menu_windows_previousClick(Sender: TObject); | 
 
 
 
 
 | 77 | procedure menu_windows_nextClick(Sender: TObject); | 
 
 
 
 
 | 78 | procedure menu_windows_tileClick(Sender: TObject); | 
 
 
 
 
 | 79 | function open_child(window_context: String; fileid: Integer): Boolean; | 
 
 
 
 
 | 80 | procedure menu_windows_closeallClick(Sender: TObject); | 
 
 
 
 
 | 81 | procedure menu_windows_cascadeClick(Sender: TObject); | 
 
 
 
 
 | 82 | procedure menu_bineditClick(Sender: TObject); | 
 
 
 
 
 | 83 | procedure menu_loadfileClick(Sender: TObject); | 
 
 
 
 
 | 84 | procedure menu_txmpreplaceClick(Sender: TObject); | 
 
 
 
 
 | 85 | procedure menu_exitClick(Sender: TObject); | 
 
 
 
 
 | 86 | procedure menu_previewClick(Sender: TObject); | 
 
 
 
 
 | 87 | procedure FormClose(Sender: TObject; var Action: TCloseAction); | 
 
 
 
 
 | 88 | procedure FormResize(Sender: TObject); | 
 
 
 
 
 | 89 | procedure FormCreate(Sender: TObject); | 
 
 
 
 
 | 90 | procedure UpdateStatBar; | 
 
 
 
 
 | 91 | procedure menu_view_mdibarClick(Sender: TObject); | 
 
 
 
 
 | 92 | procedure menu_view_statusbarClick(Sender: TObject); | 
 
 
 
 
 | 93 | procedure menu_view_toolbarClick(Sender: TObject); | 
 
 
 
 
 | 94 | procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer; | 
 
 
 
 
 | 95 | const Rect: TRect; Active: Boolean); | 
 
 
 
 
 | 96 | procedure ActivateTools(active: Boolean); | 
 
 
 
 
 | 97 | procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton; | 
 
 
 
 
 | 98 | Shift: TShiftState; X, Y: Integer); | 
 
 
 
 
 | 99 | private | 
 
 
 
 
 | 100 | public | 
 
 
 
 
 | 101 | end; | 
 
 
 
 
 | 102 |  | 
 
 
 
 
 | 103 | var | 
 
 
 
 
 | 104 | Form_Main: TForm_Main; | 
 
 
 
 
 | 105 |  | 
 
 
 
 
 | 106 | implementation | 
 
 
 
 
 | 107 |  | 
 
 
 
 
 | 108 | {$R *.dfm} | 
 
 
 
 
 | 109 |  | 
 
 
 
 
 | 110 |  | 
 
 
 
 
 | 111 |  | 
 
 
 
 
 | 112 | procedure TForm_Main.FormCreate(Sender: TObject); | 
 
 
 
 
 | 113 | begin | 
 
 
 
 
 | 114 | Self.Caption := 'Oni Un/Packer ' + version; | 
 
 
 
 
 | 115 | Self.FormResize(Self); | 
 
 
 
 
 | 116 |  | 
 
 
 
 
 | 117 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then | 
 
 
 
 
 | 118 | begin | 
 
 
 
 
 | 119 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + | 
 
 
 
 
 | 120 | '\oniunpacker.ini'); | 
 
 
 
 
 | 121 | Reset(AppSettingsFile); | 
 
 
 
 
 | 122 | Read(AppSettingsFile, AppSettings); | 
 
 
 
 
 | 123 | CloseFile(AppSettingsFile); | 
 
 
 
 
 | 124 | end | 
 
 
 
 
 | 125 | else | 
 
 
 
 
 | 126 | begin | 
 
 
 
 
 | 127 | AppSettings.DatPath     := 'D:\Spiele\Oni\GameDataFolder'; | 
 
 
 
 
 | 128 | AppSettings.ExtractPath := 'C:\Dokumente und Einstellungen\Administrator\Desktop'; | 
 
 
 
 
 | 129 | AppSettings.FilenumbersAsHex := False; | 
 
 
 
 
 | 130 | AppSettings.CharSet     := DEFAULT_CHARSET; | 
 
 
 
 
 | 131 | AppSettings.HideUnusedData := False; | 
 
 
 
 
 | 132 | end; | 
 
 
 
 
 | 133 |  | 
 
 
 
 
 | 134 | if MidStr(ParamStr(1), 1, 3) = 'opf' then | 
 
 
 
 
 | 135 | begin | 
 
 
 
 
 | 136 | ShowMessage('Load OPF-File: ' + ParamStr(2)); | 
 
 
 
 
 | 137 | end | 
 
 
 
 
 | 138 | else if MidStr(ParamStr(1), 1, 4) = 'oldb' then | 
 
 
 
 
 | 139 | begin | 
 
 
 
 
 | 140 | if not CreateDataConnection(ParamStr(2), ODB_ADB) then | 
 
 
 
 
 | 141 | ShowMessage('Error while loading the file:' + CrLf + ParamStr( | 
 
 
 
 
 | 142 | 2) + CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?'); | 
 
 
 
 
 | 143 | end | 
 
 
 
 
 | 144 | else if MidStr(ParamStr(1), 1, 3) = 'dat' then | 
 
 
 
 
 | 145 | begin | 
 
 
 
 
 | 146 | if not CreateDataConnection(ParamStr(2), ODB_Dat) then | 
 
 
 
 
 | 147 | ShowMessage('Error while loading the file:' + CrLf + ParamStr( | 
 
 
 
 
 | 148 | 2) + CrLf + 'Perhaps not an Oni-.dat-file?'); | 
 
 
 
 
 | 149 | end; | 
 
 
 
 
 | 150 | UpdateStatBar; | 
 
 
 
 
 | 151 | end; | 
 
 
 
 
 | 152 |  | 
 
 
 
 
 | 153 |  | 
 
 
 
 
 | 154 |  | 
 
 
 
 
 | 155 |  | 
 
 
 
 
 | 156 | procedure TForm_Main.FormResize(Sender: TObject); | 
 
 
 
 
 | 157 | const | 
 
 
 
 
 | 158 | MinWidth: Integer  = 750; | 
 
 
 
 
 | 159 | MinHeight: Integer = 500; | 
 
 
 
 
 | 160 | begin | 
 
 
 
 
 | 161 | if Self.Width < MinWidth then | 
 
 
 
 
 | 162 | Self.Width := MinWidth; | 
 
 
 
 
 | 163 | if Self.Height < MinHeight then | 
 
 
 
 
 | 164 | Self.Height := MinHeight; | 
 
 
 
 
 | 165 | statbar.Panels.Items[0].Width := Self.Width - 200; | 
 
 
 
 
 | 166 | MDITab.Width := Self.Width - 20; | 
 
 
 
 
 | 167 | end; | 
 
 
 
 
 | 168 |  | 
 
 
 
 
 | 169 |  | 
 
 
 
 
 | 170 |  | 
 
 
 
 
 | 171 |  | 
 
 
 
 
 | 172 | procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl; | 
 
 
 
 
 | 173 | TabIndex: Integer; const Rect: TRect; Active: Boolean); | 
 
 
 
 
 | 174 | var | 
 
 
 
 
 | 175 | x, y: Integer; | 
 
 
 
 
 | 176 | iconindex: Integer; | 
 
 
 
 
 | 177 | caption: String; | 
 
 
 
 
 | 178 | begin | 
 
 
 
 
 | 179 | iconindex := TMDITab(Control).Glyphs[TabIndex]; | 
 
 
 
 
 | 180 | caption := TMDITab(Control).Captions[TabIndex]; | 
 
 
 
 
 | 181 | if active then | 
 
 
 
 
 | 182 | begin | 
 
 
 
 
 | 183 | Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic]; | 
 
 
 
 
 | 184 | y := Rect.Top + 1; | 
 
 
 
 
 | 185 | end else | 
 
 
 
 
 | 186 | y := Rect.Top; | 
 
 
 
 
 | 187 | if iconindex >= 0 then | 
 
 
 
 
 | 188 | begin | 
 
 
 
 
 | 189 | TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex); | 
 
 
 
 
 | 190 | x := Rect.Left + 26; | 
 
 
 
 
 | 191 | end else | 
 
 
 
 
 | 192 | x := Rect.Left + 4; | 
 
 
 
 
 | 193 | Control.Canvas.TextOut(x, y + 2, caption); | 
 
 
 
 
 | 194 | end; | 
 
 
 
 
 | 195 |  | 
 
 
 
 
 | 196 |  | 
 
 
 
 
 | 197 |  | 
 
 
 
 
 | 198 |  | 
 
 
 
 
 | 199 |  | 
 
 
 
 
 | 200 |  | 
 
 
 
 
 | 201 | procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton; | 
 
 
 
 
 | 202 | Shift: TShiftState; X, Y: Integer); | 
 
 
 
 
 | 203 | var | 
 
 
 
 
 | 204 | pt: TPoint; | 
 
 
 
 
 | 205 | index: Integer; | 
 
 
 
 
 | 206 | begin | 
 
 
 
 
 | 207 | pt.X := X; | 
 
 
 
 
 | 208 | pt.Y := Y; | 
 
 
 
 
 | 209 | index := MDITab.GetTabAtPos(pt); | 
 
 
 
 
 | 210 | if (Button = mbRight) and (index >= 0) then | 
 
 
 
 
 | 211 | MDITab.MDIChildren[index].Close; | 
 
 
 
 
 | 212 | end; | 
 
 
 
 
 | 213 |  | 
 
 
 
 
 | 214 | procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction); | 
 
 
 
 
 | 215 | begin | 
 
 
 
 
 | 216 | AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini'); | 
 
 
 
 
 | 217 | if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then | 
 
 
 
 
 | 218 | Reset(AppSettingsFile) | 
 
 
 
 
 | 219 | else | 
 
 
 
 
 | 220 | Rewrite(AppSettingsFile); | 
 
 
 
 
 | 221 | Write(AppSettingsFile, AppSettings); | 
 
 
 
 
 | 222 | CloseFile(AppSettingsFile); | 
 
 
 
 
 | 223 | Action := caFree; | 
 
 
 
 
 | 224 | end; | 
 
 
 
 
 | 225 |  | 
 
 
 
 
 | 226 |  | 
 
 
 
 
 | 227 |  | 
 
 
 
 
 | 228 | procedure TForm_Main.ActivateTools(active: Boolean); | 
 
 
 
 
 | 229 | begin | 
 
 
 
 
 | 230 | menu_tools.Enabled := active; | 
 
 
 
 
 | 231 | tb_preview.Enabled := active; | 
 
 
 
 
 | 232 | tb_datedit.Enabled := active; | 
 
 
 
 
 | 233 | tb_rawedit.Enabled := active; | 
 
 
 
 
 | 234 | tb_txmpreplacer.Enabled := active; | 
 
 
 
 
 | 235 | tb_extractor.Enabled := active; | 
 
 
 
 
 | 236 | //  tb_compare.Enabled := active; | 
 
 
 
 
 | 237 | //  tb_structure.Enabled := active; | 
 
 
 
 
 | 238 | end; | 
 
 
 
 
 | 239 |  | 
 
 
 
 
 | 240 | procedure TForm_Main.UpdateStatBar; | 
 
 
 
 
 | 241 | begin | 
 
 
 
 
 | 242 | if Assigned(OniDataConnection) then | 
 
 
 
 
 | 243 | begin | 
 
 
 
 
 | 244 | Self.Caption      := 'Oni Un/Packer ' + version + ' (' + ExtractFileName( | 
 
 
 
 
 | 245 | OniDataConnection.FileName) + ')'; | 
 
 
 
 
 | 246 | ActivateTools(True); | 
 
 
 
 
 | 247 | statbar.Panels.Items[1].Text := 'Files: ' + IntToStr(OniDataConnection.GetFilesCount); | 
 
 
 
 
 | 248 | statbar.Panels.Items[2].Text := | 
 
 
 
 
 | 249 | 'Extensions: ' + IntToStr(Length(OniDataConnection.GetExtensionsList)); | 
 
 
 
 
 | 250 | case OniDataConnection.Backend of | 
 
 
 
 
 | 251 | ODB_Dat: | 
 
 
 
 
 | 252 | begin | 
 
 
 
 
 | 253 | statbar.Panels.Items[0].Text := '.dat loaded: ' + OniDataConnection.FileName; | 
 
 
 
 
 | 254 | end; | 
 
 
 
 
 | 255 | ODB_ADB: | 
 
 
 
 
 | 256 | begin | 
 
 
 
 
 | 257 | statbar.Panels.Items[0].Text := 'OLDB loaded: ' + OniDataConnection.FileName; | 
 
 
 
 
 | 258 | end; | 
 
 
 
 
 | 259 | else | 
 
 
 
 
 | 260 | Self.Caption      := 'Oni Un/Packer ' + version; | 
 
 
 
 
 | 261 | statbar.Panels.Items[0].Text := 'Nothing loaded'; | 
 
 
 
 
 | 262 | statbar.Panels.Items[1].Text := 'Files: -'; | 
 
 
 
 
 | 263 | statbar.Panels.Items[2].Text := 'Extensions: -'; | 
 
 
 
 
 | 264 | ActivateTools(False); | 
 
 
 
 
 | 265 | end; | 
 
 
 
 
 | 266 | end | 
 
 
 
 
 | 267 | else | 
 
 
 
 
 | 268 | begin | 
 
 
 
 
 | 269 | Self.Caption      := 'Oni Un/Packer ' + version; | 
 
 
 
 
 | 270 | statbar.Panels.Items[0].Text := 'Nothing loaded'; | 
 
 
 
 
 | 271 | statbar.Panels.Items[1].Text := 'Files: -'; | 
 
 
 
 
 | 272 | statbar.Panels.Items[2].Text := 'Extensions: -'; | 
 
 
 
 
 | 273 | ActivateTools(False); | 
 
 
 
 
 | 274 | end; | 
 
 
 
 
 | 275 | end; | 
 
 
 
 
 | 276 |  | 
 
 
 
 
 | 277 |  | 
 
 
 
 
 | 278 |  | 
 
 
 
 
 | 279 |  | 
 
 
 
 
 | 280 | function TForm_Main.TryCloseAll: Boolean; | 
 
 
 
 
 | 281 | begin | 
 
 
 
 
 | 282 | menu_windows_closeallClick(Self); | 
 
 
 
 
 | 283 | Application.ProcessMessages; | 
 
 
 
 
 | 284 | if MDITab.MDIChildCount = 0 then | 
 
 
 
 
 | 285 | Result := True | 
 
 
 
 
 | 286 | else | 
 
 
 
 
 | 287 | Result := False; | 
 
 
 
 
 | 288 | end; | 
 
 
 
 
 | 289 |  | 
 
 
 
 
 | 290 |  | 
 
 
 
 
 | 291 | {#################################} | 
 
 
 
 
 | 292 | {##### Main-Menu-Handlers    #####} | 
 
 
 
 
 | 293 | {#################################} | 
 
 
 
 
 | 294 | procedure TForm_Main.menu_loadfileClick(Sender: TObject); | 
 
 
 
 
 | 295 | var | 
 
 
 
 
 | 296 | ext: String; | 
 
 
 
 
 | 297 | begin | 
 
 
 
 
 | 298 | if TryCloseAll then | 
 
 
 
 
 | 299 | begin | 
 
 
 
 
 | 300 | CloseDataConnection; | 
 
 
 
 
 | 301 | opend.InitialDir := AppSettings.DatPath; | 
 
 
 
 
 | 302 | opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*'; | 
 
 
 
 
 | 303 | if opend.Execute then | 
 
 
 
 
 | 304 | begin | 
 
 
 
 
 | 305 | ext := ExtractFileExt(opend.FileName); | 
 
 
 
 
 | 306 | if ext = '.dat' then | 
 
 
 
 
 | 307 | begin | 
 
 
 
 
 | 308 | if not CreateDataConnection(opend.FileName, ODB_Dat) then | 
 
 
 
 
 | 309 | ShowMessage('Error while loading the file:' + CrLf + opend.FileName + | 
 
 
 
 
 | 310 | CrLf + 'Perhaps not an Oni-.dat-file?'); | 
 
 
 
 
 | 311 | end else if ext = '.oldb' then | 
 
 
 
 
 | 312 | begin | 
 
 
 
 
 | 313 | if not CreateDataConnection(opend.FileName, ODB_ADB) then | 
 
 
 
 
 | 314 | ShowMessage('Error while loading the file:' + CrLf + opend.FileName + | 
 
 
 
 
 | 315 | CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?'); | 
 
 
 
 
 | 316 | end else | 
 
 
 
 
 | 317 | ShowMessage('Incompatible file'); | 
 
 
 
 
 | 318 | AppSettings.DatPath := ExtractFilepath(opend.FileName); | 
 
 
 
 
 | 319 | end; | 
 
 
 
 
 | 320 | end; | 
 
 
 
 
 | 321 | UpdateStatBar; | 
 
 
 
 
 | 322 | end; | 
 
 
 
 
 | 323 |  | 
 
 
 
 
 | 324 |  | 
 
 
 
 
 | 325 |  | 
 
 
 
 
 | 326 |  | 
 
 
 
 
 | 327 | procedure TForm_Main.menu_settingsClick(Sender: TObject); | 
 
 
 
 
 | 328 | begin | 
 
 
 
 
 | 329 | Form_Settings.Visible := True; | 
 
 
 
 
 | 330 | Self.Enabled   := False; | 
 
 
 
 
 | 331 | end; | 
 
 
 
 
 | 332 |  | 
 
 
 
 
 | 333 |  | 
 
 
 
 
 | 334 |  | 
 
 
 
 
 | 335 |  | 
 
 
 
 
 | 336 | procedure TForm_Main.menu_exitClick(Sender: TObject); | 
 
 
 
 
 | 337 | begin | 
 
 
 
 
 | 338 | Self.Close; | 
 
 
 
 
 | 339 | end; | 
 
 
 
 
 | 340 |  | 
 
 
 
 
 | 341 | {####################################} | 
 
 
 
 
 | 342 | {##### Converters-Menu-Handlers #####} | 
 
 
 
 
 | 343 | {####################################} | 
 
 
 
 
 | 344 | procedure TForm_Main.menu_createdbClick(Sender: TObject); | 
 
 
 
 
 | 345 | begin | 
 
 
 
 
 | 346 | if Assigned(OniDataConnection) then | 
 
 
 
 
 | 347 | if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' + | 
 
 
 
 
 | 348 | 'Do you want to close it to continue?'), PChar('Close file?'), | 
 
 
 
 
 | 349 | MB_YESNO + MB_ICONQUESTION) = ID_NO then | 
 
 
 
 
 | 350 | Exit | 
 
 
 
 
 | 351 | else begin | 
 
 
 
 
 | 352 | if TryCloseAll then | 
 
 
 
 
 | 353 | begin | 
 
 
 
 
 | 354 | CloseDataConnection; | 
 
 
 
 
 | 355 | UpdateStatBar; | 
 
 
 
 
 | 356 | end else | 
 
 
 
 
 | 357 | Exit; | 
 
 
 
 
 | 358 | end; | 
 
 
 
 
 | 359 | opend.Filter     := 'Oni-Dat-Files|*.dat'; | 
 
 
 
 
 | 360 | saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb'; | 
 
 
 
 
 | 361 | saved.DefaultExt := 'oldb'; | 
 
 
 
 
 | 362 | if opend.Execute then | 
 
 
 
 
 | 363 | if saved.Execute then | 
 
 
 
 
 | 364 | Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName); | 
 
 
 
 
 | 365 | end; | 
 
 
 
 
 | 366 |  | 
 
 
 
 
 | 367 |  | 
 
 
 
 
 | 368 |  | 
 
 
 
 
 | 369 |  | 
 
 
 
 
 | 370 | procedure TForm_Main.menu_createlvlClick(Sender: TObject); | 
 
 
 
 
 | 371 | begin | 
 
 
 
 
 | 372 | if Assigned(OniDataConnection) then | 
 
 
 
 
 | 373 | if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' + | 
 
 
 
 
 | 374 | 'Do you want to close it to continue?'), PChar('Close file?'), | 
 
 
 
 
 | 375 | MB_YESNO + MB_ICONQUESTION) = ID_NO then | 
 
 
 
 
 | 376 | Exit | 
 
 
 
 
 | 377 | else begin | 
 
 
 
 
 | 378 | if TryCloseAll then | 
 
 
 
 
 | 379 | begin | 
 
 
 
 
 | 380 | CloseDataConnection; | 
 
 
 
 
 | 381 | UpdateStatBar; | 
 
 
 
 
 | 382 | end else | 
 
 
 
 
 | 383 | Exit; | 
 
 
 
 
 | 384 | end; | 
 
 
 
 
 | 385 | opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb'; | 
 
 
 
 
 | 386 | saved.Filter     := 'Oni-Dat-Files|*.dat'; | 
 
 
 
 
 | 387 | saved.DefaultExt := 'dat'; | 
 
 
 
 
 | 388 | if opend.Execute then | 
 
 
 
 
 | 389 | if saved.Execute then | 
 
 
 
 
 | 390 | Form_LevelDB.CreateLevel(opend.FileName, saved.FileName); | 
 
 
 
 
 | 391 | end; | 
 
 
 
 
 | 392 |  | 
 
 
 
 
 | 393 | {#################################} | 
 
 
 
 
 | 394 | {##### Tools-Menu-Handlers   #####} | 
 
 
 
 
 | 395 | {#################################} | 
 
 
 
 
 | 396 | procedure TForm_Main.menu_previewClick(Sender: TObject); | 
 
 
 
 
 | 397 | begin | 
 
 
 
 
 | 398 | open_child('preview', -1); | 
 
 
 
 
 | 399 | end; | 
 
 
 
 
 | 400 |  | 
 
 
 
 
 | 401 |  | 
 
 
 
 
 | 402 | procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject); | 
 
 
 
 
 | 403 | begin | 
 
 
 
 
 | 404 | open_child('txmpreplace', -1); | 
 
 
 
 
 | 405 | end; | 
 
 
 
 
 | 406 |  | 
 
 
 
 
 | 407 |  | 
 
 
 
 
 | 408 | procedure TForm_Main.menu_bineditClick(Sender: TObject); | 
 
 
 
 
 | 409 | begin | 
 
 
 
 
 | 410 | open_child('binedit', -1); | 
 
 
 
 
 | 411 | end; | 
 
 
 
 
 | 412 |  | 
 
 
 
 
 | 413 |  | 
 
 
 
 
 | 414 | procedure TForm_Main.menu_raweditClick(Sender: TObject); | 
 
 
 
 
 | 415 | begin | 
 
 
 
 
 | 416 | open_child('rawedit', -1); | 
 
 
 
 
 | 417 | end; | 
 
 
 
 
 | 418 |  | 
 
 
 
 
 | 419 |  | 
 
 
 
 
 | 420 | procedure TForm_Main.menu_extractorClick(Sender: TObject); | 
 
 
 
 
 | 421 | begin | 
 
 
 
 
 | 422 | open_child('extractor', -1); | 
 
 
 
 
 | 423 | end; | 
 
 
 
 
 | 424 |  | 
 
 
 
 
 | 425 |  | 
 
 
 
 
 | 426 | procedure TForm_Main.menu_filecompareClick(Sender: TObject); | 
 
 
 
 
 | 427 | begin | 
 
 
 
 
 | 428 | open_child('compare', -1); | 
 
 
 
 
 | 429 | end; | 
 
 
 
 
 | 430 |  | 
 
 
 
 
 | 431 |  | 
 
 
 
 
 | 432 | {#################################} | 
 
 
 
 
 | 433 | {#####   View-Menu-Handlers  #####} | 
 
 
 
 
 | 434 | {#################################} | 
 
 
 
 
 | 435 | procedure TForm_Main.menu_view_mdibarClick(Sender: TObject); | 
 
 
 
 
 | 436 | begin | 
 
 
 
 
 | 437 | menu_view_mdibar.Checked := not menu_view_mdibar.Checked; | 
 
 
 
 
 | 438 | mditoolbar.Visible := menu_view_mdibar.Checked; | 
 
 
 
 
 | 439 | end; | 
 
 
 
 
 | 440 |  | 
 
 
 
 
 | 441 |  | 
 
 
 
 
 | 442 |  | 
 
 
 
 
 | 443 |  | 
 
 
 
 
 | 444 | procedure TForm_Main.menu_view_statusbarClick(Sender: TObject); | 
 
 
 
 
 | 445 | begin | 
 
 
 
 
 | 446 | menu_view_statusbar.Checked := not menu_view_statusbar.Checked; | 
 
 
 
 
 | 447 | statbar.Visible := menu_view_statusbar.Checked; | 
 
 
 
 
 | 448 | end; | 
 
 
 
 
 | 449 |  | 
 
 
 
 
 | 450 |  | 
 
 
 
 
 | 451 |  | 
 
 
 
 
 | 452 |  | 
 
 
 
 
 | 453 | procedure TForm_Main.menu_view_toolbarClick(Sender: TObject); | 
 
 
 
 
 | 454 | begin | 
 
 
 
 
 | 455 | menu_view_toolbar.Checked := not menu_view_toolbar.Checked; | 
 
 
 
 
 | 456 | Toolbar.Visible := menu_view_toolbar.Checked; | 
 
 
 
 
 | 457 | end; | 
 
 
 
 
 | 458 |  | 
 
 
 
 
 | 459 |  | 
 
 
 
 
 | 460 |  | 
 
 
 
 
 | 461 | {#################################} | 
 
 
 
 
 | 462 | {#####  Window-Menu-Handlers #####} | 
 
 
 
 
 | 463 | {#################################} | 
 
 
 
 
 | 464 | procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject); | 
 
 
 
 
 | 465 | begin | 
 
 
 
 
 | 466 | Self.Cascade; | 
 
 
 
 
 | 467 | end; | 
 
 
 
 
 | 468 |  | 
 
 
 
 
 | 469 |  | 
 
 
 
 
 | 470 |  | 
 
 
 
 
 | 471 | procedure TForm_Main.menu_windows_tileClick(Sender: TObject); | 
 
 
 
 
 | 472 | begin | 
 
 
 
 
 | 473 | Self.TileMode := tbHorizontal; | 
 
 
 
 
 | 474 | Self.Tile; | 
 
 
 
 
 | 475 | end; | 
 
 
 
 
 | 476 |  | 
 
 
 
 
 | 477 |  | 
 
 
 
 
 | 478 |  | 
 
 
 
 
 | 479 | procedure TForm_Main.menu_windows_closeallClick(Sender: TObject); | 
 
 
 
 
 | 480 | begin | 
 
 
 
 
 | 481 | MDITab.CloseAll; | 
 
 
 
 
 | 482 | end; | 
 
 
 
 
 | 483 |  | 
 
 
 
 
 | 484 |  | 
 
 
 
 
 | 485 |  | 
 
 
 
 
 | 486 | procedure TForm_Main.menu_windows_nextClick(Sender: TObject); | 
 
 
 
 
 | 487 | begin | 
 
 
 
 
 | 488 | if MDIChildCount > 1 then | 
 
 
 
 
 | 489 | if MDITab.TabIndex = MDITab.MDIChildCount - 1 then | 
 
 
 
 
 | 490 | MDITab.MDIChildren[0].BringToFront | 
 
 
 
 
 | 491 | else | 
 
 
 
 
 | 492 | MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront; | 
 
 
 
 
 | 493 | end; | 
 
 
 
 
 | 494 |  | 
 
 
 
 
 | 495 |  | 
 
 
 
 
 | 496 |  | 
 
 
 
 
 | 497 | procedure TForm_Main.menu_windows_previousClick(Sender: TObject); | 
 
 
 
 
 | 498 | begin | 
 
 
 
 
 | 499 | if MDIChildCount > 1 then | 
 
 
 
 
 | 500 | if MDITab.TabIndex = 0 then | 
 
 
 
 
 | 501 | MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront | 
 
 
 
 
 | 502 | else | 
 
 
 
 
 | 503 | MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront; | 
 
 
 
 
 | 504 | end; | 
 
 
 
 
 | 505 |  | 
 
 
 
 
 | 506 |  | 
 
 
 
 
 | 507 |  | 
 
 
 
 
 | 508 |  | 
 
 
 
 
 | 509 |  | 
 
 
 
 
 | 510 |  | 
 
 
 
 
 | 511 | procedure TForm_Main.menu_AboutClick(Sender: TObject); | 
 
 
 
 
 | 512 | begin | 
 
 
 
 
 | 513 | ShowMessage('Will be implemented later ;)'); | 
 
 
 
 
 | 514 | end; | 
 
 
 
 
 | 515 |  | 
 
 
 
 
 | 516 |  | 
 
 
 
 
 | 517 |  | 
 
 
 
 
 | 518 |  | 
 
 
 
 
 | 519 | function TForm_Main.open_child(window_context: String; fileid: Integer): Boolean; | 
 
 
 
 
 | 520 | var | 
 
 
 
 
 | 521 | toolform: TForm_ToolTemplate; | 
 
 
 
 
 | 522 | i:       Integer; | 
 
 
 
 
 | 523 | tag:     Integer; | 
 
 
 
 
 | 524 | iconindex: Integer; | 
 
 
 
 
 | 525 | begin | 
 
 
 
 
 | 526 | Result := True; | 
 
 
 
 
 | 527 |  | 
 
 
 
 
 | 528 | tag := 1; | 
 
 
 
 
 | 529 | if MDIChildCount > 0 then | 
 
 
 
 
 | 530 | for i := 0 to MDIChildCount - 1 do | 
 
 
 
 
 | 531 | if MDIChildren[i].Tag >= tag then | 
 
 
 
 
 | 532 | tag := MDIChildren[i].Tag + 1; | 
 
 
 
 
 | 533 |  | 
 
 
 
 
 | 534 | iconindex := -1; | 
 
 
 
 
 | 535 |  | 
 
 
 
 
 | 536 | if window_context = 'binedit' then | 
 
 
 
 
 | 537 | begin | 
 
 
 
 
 | 538 | toolform         := TForm_BinEdit.Create(Self); | 
 
 
 
 
 | 539 | toolform.Caption := 'Binary .dat-Editor ' + IntToStr(tag); | 
 
 
 
 
 | 540 | iconindex        := 0; | 
 
 
 
 
 | 541 | end; | 
 
 
 
 
 | 542 | if window_context = 'extractor' then | 
 
 
 
 
 | 543 | begin | 
 
 
 
 
 | 544 | toolform         := TForm_Extractor.Create(Self); | 
 
 
 
 
 | 545 | toolform.Caption := 'Extractor ' + IntToStr(tag); | 
 
 
 
 
 | 546 | end; | 
 
 
 
 
 | 547 | if window_context = 'preview' then | 
 
 
 
 
 | 548 | begin | 
 
 
 
 
 | 549 | toolform         := TForm_Preview.Create(Self); | 
 
 
 
 
 | 550 | toolform.Caption := 'Preview-Window ' + IntToStr(tag); | 
 
 
 
 
 | 551 | end; | 
 
 
 
 
 | 552 | if window_context = 'rawedit' then | 
 
 
 
 
 | 553 | begin | 
 
 
 
 
 | 554 | toolform         := TForm_RawEdit.Create(Self); | 
 
 
 
 
 | 555 | toolform.Caption := 'Binary .raw-Editor ' + IntToStr(tag); | 
 
 
 
 
 | 556 | end; | 
 
 
 
 
 | 557 | if window_context = 'txmpreplace' then | 
 
 
 
 
 | 558 | begin | 
 
 
 
 
 | 559 | toolform         := TForm_TxmpReplace.Create(Application); | 
 
 
 
 
 | 560 | toolform.Caption := 'TXMP Replacer ' + IntToStr(tag); | 
 
 
 
 
 | 561 | end; | 
 
 
 
 
 | 562 |  | 
 
 
 
 
 | 563 | if Assigned(toolform) then | 
 
 
 
 
 | 564 | begin | 
 
 
 
 
 | 565 | toolform.Name    := window_context + IntToStr(tag); | 
 
 
 
 
 | 566 | toolform.Tag     := tag; | 
 
 
 
 
 | 567 | MDITab.AddTab(TForm(toolform), iconindex); | 
 
 
 
 
 | 568 | if fileid > -1 then | 
 
 
 
 
 | 569 | toolform.SelectFileID(fileid); | 
 
 
 
 
 | 570 | end; | 
 
 
 
 
 | 571 | end; | 
 
 
 
 
 | 572 |  | 
 
 
 
 
 | 573 | end. |