void LoadSaveScreenEntry() { fEnteringLoadSaveScreen = FALSE; gbCurrentFileIOStatus = IOSTATUS_NONE; gfReadOnly = FALSE; gfFileExists = FALSE; gfLoadError = FALSE; gfIllegalName = FALSE; gfDeleteFile = FALSE; gfNoFiles = FALSE; // setup filename dialog box // (*.dat and *.map) as file filter // If user clicks on a filename in the window, then turn off string focus and re-init the string with the new name. // If user hits ENTER or presses OK, then continue with the file loading/saving if( FileList ) TrashFDlgList( FileList ); iTopFileShown = iTotalFiles = 0; if( GetFileFirst("MAPS\\*.dat", &FileInfo) ) { FileList = AddToFDlgList( FileList, &FileInfo ); iTotalFiles++; while( GetFileNext(&FileInfo) ) { FileList = AddToFDlgList( FileList, &FileInfo ); iTotalFiles++; } GetFileClose(&FileInfo); } swprintf( zOrigName, L"%s Map (*.dat)", iCurrentAction == ACTION_SAVE_MAP ? L"Save" : L"Load" ); swprintf( gzFilename, L"%S", gubFilename ); CreateFileDialog( zOrigName ); if( !iTotalFiles ) { gfNoFiles = TRUE; if( iCurrentAction == ACTION_LOAD_MAP ) DisableButton( iFileDlgButtons[0] ); } iLastFileClicked = -1; iLastClickTime = 0; }
UINT32 LoadSaveScreenHandle(void) { FDLG_LIST *FListNode; INT32 x; InputAtom DialogEvent; if( fEnteringLoadSaveScreen ) { LoadSaveScreenEntry(); } if( gbCurrentFileIOStatus ) //loading or saving map { UINT32 uiScreen; uiScreen = ProcessFileIO(); if( uiScreen == EDIT_SCREEN && gbCurrentFileIOStatus == LOADING_MAP ) RemoveProgressBar( 0 ); return uiScreen; } if( gubMessageBoxStatus ) { if( MessageBoxHandled() ) return ProcessLoadSaveScreenMessageBoxResult(); return LOADSAVE_SCREEN; } //handle all key input. while( DequeueEvent(&DialogEvent) ) { if( !HandleTextInput(&DialogEvent) && (DialogEvent.usEvent == KEY_DOWN || DialogEvent.usEvent == KEY_REPEAT) ) { HandleMainKeyEvents( &DialogEvent ); } } HandleMouseWheelEvents();//dnl ch36 150909 DrawFileDialog(); // Skip to first filename to show FListNode = FileList; for(x=0;x<iTopFileShown && x<iTotalFiles && FListNode != NULL;x++) { FListNode = FListNode->pNext; } // Show up to 8 filenames in the window SetFont( FONT12POINT1 ); if( gfNoFiles ) { SetFontForeground( FONT_LTRED ); SetFontBackground( 142 ); mprintf( iScreenWidthOffset + 226, iScreenHeightOffset + 126, L"NO FILES IN \\MAPS DIRECTORY" ); } else for(x=iTopFileShown;x<(iTopFileShown+8) && x<iTotalFiles && FListNode != NULL; x++) { if( !EditingText() && x == iCurrFileShown ) { SetFontForeground( FONT_GRAY2 ); SetFontBackground( FONT_METALGRAY ); } else { SetFontForeground( FONT_BLACK ); SetFontBackground( 142 ); } mprintf( iScreenWidthOffset + 186,(iScreenHeightOffset + 73+ (x-iTopFileShown)*15 ), L"%S", FListNode->FileInfo.zFileName); FListNode = FListNode->pNext; } RenderAllTextFields(); InvalidateScreen(); ExecuteBaseDirtyRectQueue(); EndFrameBufferRender(); switch( iFDlgState ) { case DIALOG_CANCEL: RemoveFileDialog(); fEnteringLoadSaveScreen = TRUE; return EDIT_SCREEN; case DIALOG_DELETE: sprintf( gszCurrFilename, "MAPS\\%S", gzFilename ); if( GetFileFirst(gszCurrFilename, &FileInfo) ) { CHAR16 str[40]; if( FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_HIDDEN|FILE_IS_SYSTEM) ) { swprintf( str, L" Delete READ-ONLY file %s? ", gzFilename ); gfReadOnly = TRUE; } else swprintf( str, L" Delete file %s? ", gzFilename ); gfDeleteFile = TRUE; CreateMessageBox( str ); } return LOADSAVE_SCREEN; case DIALOG_SAVE://dnl ch37 230909 { if(!ExtractFilenameFromFields()) { CreateMessageBox(L" Illegal filename. Try another filename? "); gfIllegalName = TRUE; iFDlgState = DIALOG_NONE; return(LOADSAVE_SCREEN); } sprintf(gszCurrFilename, "MAPS\\%S", gzFilename); gfFileExists = FALSE; #ifndef USE_VFS gfReadOnly = FALSE; if(FileExists(gszCurrFilename)) { gfFileExists = TRUE; if(GetFileFirst(gszCurrFilename, &FileInfo)) { if(FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_DIRECTORY|FILE_IS_HIDDEN|FILE_IS_SYSTEM|FILE_IS_OFFLINE|FILE_IS_TEMPORARY)) gfReadOnly = TRUE; GetFileClose(&FileInfo); } } #else gfReadOnly = TRUE; vfs::CProfileStack* st = getVFS()->getProfileStack(); vfs::CProfileStack::Iterator it = st->begin(); while(!it.end()) { vfs::CVirtualProfile* prof = it.value(); if(prof->cWritable == true) { gfReadOnly = FALSE; vfs::Path const& path = gszCurrFilename; vfs::IBaseFile *file = prof->getFile(path); if(file) { gfFileExists = TRUE; if(file->implementsWritable() == false) gfReadOnly = TRUE; } break; } it.next(); } #endif if(gfReadOnly) { CreateMessageBox(L" File is read only! Choose a different name? "); return( LOADSAVE_SCREEN); } else if(gfFileExists) { CreateMessageBox(L" File exists, Overwrite? "); return(LOADSAVE_SCREEN); } RemoveFileDialog(); gbCurrentFileIOStatus = INITIATE_MAP_SAVE; return(LOADSAVE_SCREEN); } case DIALOG_LOAD: if( !ExtractFilenameFromFields() ) { CreateMessageBox( L" Illegal filename. Try another filename? " ); gfIllegalName = TRUE; iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN; } RemoveFileDialog(); CreateProgressBar( 0, iScreenWidthOffset + 118, iScreenHeightOffset + 183, iScreenWidthOffset + 522, iScreenHeightOffset + 202 ); DefineProgressBarPanel( 0, 65, 79, 94, iScreenWidthOffset + 100, iScreenHeightOffset + 155, iScreenWidthOffset + 540, iScreenHeightOffset + 235 ); swprintf( zOrigName, L"Loading map: %s", gzFilename ); SetProgressBarTitle( 0, zOrigName, BLOCKFONT2, FONT_RED, FONT_NEARBLACK ); gbCurrentFileIOStatus = INITIATE_MAP_LOAD; return LOADSAVE_SCREEN ; default: iFDlgState = DIALOG_NONE; } iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN ; }
void LoadSaveScreenEntry() { fEnteringLoadSaveScreen = FALSE; gbCurrentFileIOStatus = IOSTATUS_NONE; gfReadOnly = FALSE; gfFileExists = FALSE; gfLoadError = FALSE; gfIllegalName = FALSE; gfDeleteFile = FALSE; gfNoFiles = FALSE; gfSaveError = FALSE;//dnl ch37 200909 // setup filename dialog box // (*.dat and *.map) as file filter // If user clicks on a filename in the window, then turn off string focus and re-init the string with the new name. // If user hits ENTER or presses OK, then continue with the file loading/saving if(FileList) { TrashFDlgList(FileList); FileList = NULL; } iTopFileShown = iTotalFiles = 0; #ifdef USE_VFS//dnl ch37 300909 FDLG_LIST* TempFileList = NULL; vfs::CProfileStack* st = getVFS()->getProfileStack(); vfs::CProfileStack::Iterator it = st->begin(); while(!it.end()) { TempFileList = NULL; vfs::CVirtualProfile* prof = it.value(); memset(&FileInfo, 0, sizeof(GETFILESTRUCT)); strcpy(FileInfo.zFileName, "< "); strcat(FileInfo.zFileName, prof->cName.utf8().c_str()); strcat(FileInfo.zFileName, " >"); FileInfo.zFileName[FILENAME_BUFLEN] = 0; FileInfo.uiFileAttribs = FILE_IS_DIRECTORY; if(iCurrentAction == ACTION_SAVE_MAP && prof->cWritable == false) { it.next(); continue; } TempFileList = AddToFDlgList(TempFileList, &FileInfo); iTotalFiles++; vfs::CVirtualProfile::FileIterator fit = prof->files(L"MAPS/*"); while(!fit.end()) { vfs::String fname = fit.value()->getName().c_str(); memset(&FileInfo, 0, sizeof(GETFILESTRUCT)); strcpy(FileInfo.zFileName, fname.utf8().c_str()); FileInfo.uiFileSize = fname.length(); FileInfo.uiFileAttribs = (fit.value()->implementsWritable() ? FILE_IS_NORMAL : FILE_IS_READONLY); if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) { TempFileList = AddToFDlgList(TempFileList, &FileInfo); iTotalFiles++; } fit.next(); } if(TempFileList) { while(TempFileList->pPrev) TempFileList = TempFileList->pPrev; if(FileList) { while(FileList->pNext) FileList = FileList->pNext; FileList->pNext = TempFileList; TempFileList->pPrev = FileList; } else FileList = TempFileList; } it.next(); } while(FileList->pPrev) FileList = FileList->pPrev; #else if(GetFileFirst("MAPS\\*.dat", &FileInfo)) { if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) { FileList = AddToFDlgList(FileList, &FileInfo); iTotalFiles++; } while(GetFileNext(&FileInfo)) { if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) { FileList = AddToFDlgList(FileList, &FileInfo); iTotalFiles++; } } GetFileClose(&FileInfo); } #endif swprintf( zOrigName, L"%s Map (*.dat)", iCurrentAction == ACTION_SAVE_MAP ? L"Save" : L"Load" ); swprintf( gzFilename, L"%S", gubFilename ); CreateFileDialog( zOrigName ); if( !iTotalFiles ) { gfNoFiles = TRUE; if( iCurrentAction == ACTION_LOAD_MAP ) DisableButton( iFileDlgButtons[0] ); } iLastFileClicked = -1; iLastClickTime = 0; }
UINT32 LoadSaveScreenHandle(void) { FDLG_LIST *FListNode; INT32 x; InputAtom DialogEvent; if( fEnteringLoadSaveScreen ) { LoadSaveScreenEntry(); } if( gbCurrentFileIOStatus ) //loading or saving map { UINT32 uiScreen; uiScreen = ProcessFileIO(); if( uiScreen == EDIT_SCREEN && gbCurrentFileIOStatus == LOADING_MAP ) RemoveProgressBar( 0 ); return uiScreen; } if( gubMessageBoxStatus ) { if( MessageBoxHandled() ) return ProcessLoadSaveScreenMessageBoxResult(); return LOADSAVE_SCREEN; } //handle all key input. while( DequeueEvent(&DialogEvent) ) { if( !HandleTextInput(&DialogEvent) && (DialogEvent.usEvent == KEY_DOWN || DialogEvent.usEvent == KEY_REPEAT) ) { HandleMainKeyEvents( &DialogEvent ); } } DrawFileDialog(); // Skip to first filename to show FListNode = FileList; for(x=0; x<iTopFileShown && x<iTotalFiles && FListNode != NULL; x++) { FListNode = FListNode->pNext; } // Show up to 8 filenames in the window SetFont( FONT12POINT1 ); if( gfNoFiles ) { SetFontForeground( FONT_LTRED ); SetFontBackground( 142 ); mprintf( 226, 126, L"NO FILES IN \\MAPS DIRECTORY" ); } else for(x=iTopFileShown; x<(iTopFileShown+8) && x<iTotalFiles && FListNode != NULL; x++) { if( !EditingText() && x == iCurrFileShown ) { SetFontForeground( FONT_GRAY2 ); SetFontBackground( FONT_METALGRAY ); } else { SetFontForeground( FONT_BLACK ); SetFontBackground( 142 ); } mprintf( 186,(73+ (x-iTopFileShown)*15 ), L"%S", FListNode->FileInfo.zFileName); FListNode = FListNode->pNext; } RenderAllTextFields(); InvalidateScreen(); ExecuteBaseDirtyRectQueue(); EndFrameBufferRender(); switch( iFDlgState ) { case DIALOG_CANCEL: RemoveFileDialog(); fEnteringLoadSaveScreen = TRUE; return EDIT_SCREEN; case DIALOG_DELETE: sprintf( gszCurrFilename, "MAPS\\%S", gzFilename ); if( GetFileFirst(gszCurrFilename, &FileInfo) ) { UINT16 str[40]; if( FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_HIDDEN|FILE_IS_SYSTEM) ) { swprintf( str, L" Delete READ-ONLY file %s? ", gzFilename ); gfReadOnly = TRUE; } else swprintf( str, L" Delete file %s? ", gzFilename ); gfDeleteFile = TRUE; CreateMessageBox( str ); } return LOADSAVE_SCREEN; case DIALOG_SAVE: if( !ExtractFilenameFromFields() ) { CreateMessageBox( L" Illegal filename. Try another filename? " ); gfIllegalName = TRUE; iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN; } sprintf( gszCurrFilename, "MAPS\\%S", gzFilename ); if ( FileExists( gszCurrFilename ) ) { gfFileExists = TRUE; gfReadOnly = FALSE; if( GetFileFirst(gszCurrFilename, &FileInfo) ) { if( FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_DIRECTORY|FILE_IS_HIDDEN|FILE_IS_SYSTEM|FILE_IS_OFFLINE|FILE_IS_TEMPORARY) ) gfReadOnly = TRUE; GetFileClose(&FileInfo); } if( gfReadOnly ) CreateMessageBox( L" File is read only! Choose a different name? " ); else CreateMessageBox( L" File exists, Overwrite? " ); return( LOADSAVE_SCREEN ); } RemoveFileDialog(); gbCurrentFileIOStatus = INITIATE_MAP_SAVE; return LOADSAVE_SCREEN ; case DIALOG_LOAD: if( !ExtractFilenameFromFields() ) { CreateMessageBox( L" Illegal filename. Try another filename? " ); gfIllegalName = TRUE; iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN; } RemoveFileDialog(); CreateProgressBar( 0, 118, 183, 522, 202 ); DefineProgressBarPanel( 0, 65, 79, 94, 100, 155, 540, 235 ); swprintf( zOrigName, L"Loading map: %s", gzFilename ); SetProgressBarTitle( 0, zOrigName, BLOCKFONT2, FONT_RED, FONT_NEARBLACK ); gbCurrentFileIOStatus = INITIATE_MAP_LOAD; return LOADSAVE_SCREEN ; default: iFDlgState = DIALOG_NONE; } iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN ; }
BOOLEAN InitTileCache( ) { UINT32 cnt; GETFILESTRUCT FileInfo; INT16 sFiles = 0; gpTileCache = (TILE_CACHE_ELEMENT *)MemAlloc( sizeof( TILE_CACHE_ELEMENT ) * guiMaxTileCacheSize ); // Zero entries for ( cnt = 0; cnt < guiMaxTileCacheSize; cnt++ ) { gpTileCache[ cnt ].pImagery = NULL; gpTileCache[ cnt ].sStructRefID = -1; } guiCurTileCacheSize = 0; // OK, look for JSD files in the tile cache directory and // load any we find.... if( GetFileFirst("TILECACHE\\*.jsd", &FileInfo) ) { while( GetFileNext(&FileInfo) ) { sFiles++; } GetFileClose(&FileInfo); } // Allocate memory... if ( sFiles > 0 ) { cnt = 0; guiNumTileCacheStructs = sFiles; gpTileCacheStructInfo = (TILE_CACHE_STRUCT *)MemAlloc( sizeof( TILE_CACHE_STRUCT ) * sFiles ); // Loop through and set filenames if( GetFileFirst("TILECACHE\\*.jsd", &FileInfo) ) { while( GetFileNext(&FileInfo) ) { sprintf( gpTileCacheStructInfo[ cnt ].Filename, "TILECACHE\\%s", FileInfo.zFileName ); // Get root name GetRootName( gpTileCacheStructInfo[ cnt ].zRootName, gpTileCacheStructInfo[ cnt ].Filename ); // Load struc data.... gpTileCacheStructInfo[ cnt ].pStructureFileRef = LoadStructureFile( gpTileCacheStructInfo[ cnt ].Filename ); #ifdef JA2TESTVERSION if ( gpTileCacheStructInfo[ cnt ].pStructureFileRef == NULL ) { SET_ERROR( "Cannot load tilecache JSD: %s", gpTileCacheStructInfo[ cnt ].Filename ); } #endif if ( _stricmp( gpTileCacheStructInfo[ cnt ].zRootName, "l_dead1" ) == 0 ) { giDefaultStructIndex = cnt; } cnt++; } GetFileClose(&FileInfo); } } return( TRUE ); }