UINT32 ProcessLoadSaveScreenMessageBoxResult() { FDLG_LIST *curr, *temp; gfRenderWorld = TRUE; RemoveMessageBox(); if( gfIllegalName ) { fEnteringLoadSaveScreen = TRUE; RemoveFileDialog(); MarkWorldDirty(); return gfMessageBoxResult ? LOADSAVE_SCREEN : EDIT_SCREEN; } if( gfDeleteFile ) { if( gfMessageBoxResult ) { //delete file INT32 x; curr = FileList; for( x = 0; x < iCurrFileShown && x < iTotalFiles && curr; x++ ) { curr = curr->pNext; } if( curr ) { if( gfReadOnly ) { FileClearAttributes( gszCurrFilename ); gfReadOnly = FALSE; } FileDelete( gszCurrFilename ); //File is deleted so redo the text fields so they show the //next file in the list. temp = curr->pNext; if( !temp ) temp = curr->pPrev; if( !temp ) wcscpy( gzFilename, L"" ); else swprintf( gzFilename, L"%S", temp->FileInfo.zFileName ); if( ValidFilename() ) { SetInputFieldStringWith16BitString( 0, gzFilename ); } else { SetInputFieldStringWith16BitString( 0, L"" ); wcscpy( gzFilename, L"" ); } RemoveFromFDlgList( &FileList, curr ); iTotalFiles--; if( !iTotalFiles ) { gfNoFiles = TRUE; if( iCurrentAction == ACTION_LOAD_MAP ) DisableButton( iFileDlgButtons[0] ); } if( iCurrFileShown >= iTotalFiles ) iCurrFileShown--; if( iCurrFileShown < iTopFileShown ) iTopFileShown -= 8; if( iTopFileShown < 0 ) iTopFileShown = 0; } } MarkWorldDirty(); RenderWorld(); gfDeleteFile = FALSE; iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN; } if(gfLoadError || gfSaveError)//dnl ch37 200909 { MarkWorldDirty(); RenderWorld(); fEnteringLoadSaveScreen = TRUE; return(gfMessageBoxResult ? LOADSAVE_SCREEN : EDIT_SCREEN); } if( gfReadOnly ) { //file is readonly. Result will determine if the file dialog stays up. fEnteringLoadSaveScreen = TRUE; RemoveFileDialog(); return gfMessageBoxResult ? LOADSAVE_SCREEN : EDIT_SCREEN; } if( gfFileExists ) { if( gfMessageBoxResult ) { //okay to overwrite file RemoveFileDialog(); gbCurrentFileIOStatus = INITIATE_MAP_SAVE; return LOADSAVE_SCREEN; } fEnteringLoadSaveScreen = TRUE; RemoveFileDialog(); return(LOADSAVE_SCREEN);//dnl ch36 210909 } // Assert( 0 ); return LOADSAVE_SCREEN; }
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 ; }
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 ; }