void* FX_OpenFolder(const FX_CHAR* path) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ std::unique_ptr<CFindFileDataA> pData(new CFindFileDataA); pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), FindExInfoStandard, &pData->m_FindData, FindExSearchNameMatch, nullptr, 0); if (pData->m_Handle == INVALID_HANDLE_VALUE) return nullptr; pData->m_bEnd = FALSE; return pData.release(); #else DIR* dir = opendir(path); return dir; #endif }
BOOTIL_EXPORT int FindFiles( String::List* files, String::List* folders, const BString & strFind, bool bUpUpFolders ) { WIN32_FIND_DATAA FindFileData; HANDLE hFind; unsigned int iFiles = 0; hFind = FindFirstFileExA( strFind.c_str(), FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0 ); while ( hFind != INVALID_HANDLE_VALUE ) { BString strName = FindFileData.cFileName; if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && folders ) { bool bInclude = true; if ( bUpUpFolders || ( ( strName != "." ) && ( strName != ".." ) ) ) { folders->push_back( strName ); iFiles++; } } else if ( files ) { files->push_back( strName ); iFiles++; } if ( !FindNextFileA( hFind, &FindFileData ) ) { break; } } FindClose( hFind ); return iFiles; }
int ms_factory_load_plugins(MSFactory *factory, const char *dir){ int num=0; #if defined(_WIN32) && !defined(_WIN32_WCE) WIN32_FIND_DATA FileData; HANDLE hSearch; char szDirPath[1024]; #ifdef UNICODE wchar_t wszDirPath[1024]; #endif char szPluginFile[1024]; BOOL fFinished = FALSE; const char *tmp = NULL; BOOL debug = FALSE; #ifndef MS2_WINDOWS_UNIVERSAL tmp = getenv("DEBUG"); #endif debug = (tmp != NULL && atoi(tmp) == 1); snprintf(szDirPath, sizeof(szDirPath), "%s", dir); // Start searching for .dll files in the current directory. #ifdef MS2_WINDOWS_DESKTOP snprintf(szDirPath, sizeof(szDirPath), "%s\\*.dll", dir); #else snprintf(szDirPath, sizeof(szDirPath), "%s\\libms*.dll", dir); #endif #ifdef UNICODE mbstowcs(wszDirPath, szDirPath, sizeof(wszDirPath)); hSearch = FindFirstFileExW(wszDirPath, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0); #else hSearch = FindFirstFileExA(szDirPath, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0); #endif if (hSearch == INVALID_HANDLE_VALUE) { ms_message("no plugin (*.dll) found in [%s] [%d].", szDirPath, (int)GetLastError()); return 0; } snprintf(szDirPath, sizeof(szDirPath), "%s", dir); while (!fFinished) { /* load library */ #ifdef MS2_WINDOWS_DESKTOP UINT em=0; #endif HINSTANCE os_handle; #ifdef UNICODE wchar_t wszPluginFile[2048]; char filename[512]; wcstombs(filename, FileData.cFileName, sizeof(filename)); snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, filename); mbstowcs(wszPluginFile, szPluginFile, sizeof(wszPluginFile)); #else snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, FileData.cFileName); #endif #ifdef MS2_WINDOWS_DESKTOP if (!debug) em = SetErrorMode (SEM_FAILCRITICALERRORS); #ifdef UNICODE os_handle = LoadLibraryExW(wszPluginFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); #else os_handle = LoadLibraryExA(szPluginFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); #endif if (os_handle==NULL) { ms_message("Fail to load plugin %s with altered search path: error %i",szPluginFile,(int)GetLastError()); #ifdef UNICODE os_handle = LoadLibraryExW(wszPluginFile, NULL, 0); #else os_handle = LoadLibraryExA(szPluginFile, NULL, 0); #endif } if (!debug) SetErrorMode (em); #else os_handle = LoadPackagedLibrary(wszPluginFile, 0); #endif if (os_handle==NULL) ms_error("Fail to load plugin %s: error %i", szPluginFile, (int)GetLastError()); else{ init_func_t initroutine; char szPluginName[256]; char szMethodName[256]; char *minus; #ifdef UNICODE snprintf(szPluginName, sizeof(szPluginName), "%s", filename); #else snprintf(szPluginName, sizeof(szPluginName), "%s", FileData.cFileName); #endif /*on mingw, dll names might be libsomething-3.dll. We must skip the -X.dll stuff*/ minus=strchr(szPluginName,'-'); if (minus) *minus='\0'; else szPluginName[strlen(szPluginName)-4]='\0'; /*remove .dll*/ snprintf(szMethodName, sizeof(szMethodName), "%s_init", szPluginName); initroutine = (init_func_t) GetProcAddress (os_handle, szMethodName); if (initroutine!=NULL){ initroutine(factory); ms_message("Plugin loaded (%s)", szPluginFile); // Add this new loaded plugin to the list (useful for FreeLibrary at the end) factory->ms_plugins_loaded_list=ms_list_append(factory->ms_plugins_loaded_list,os_handle); num++; }else{ ms_warning("Could not locate init routine of plugin %s. Should be %s", szPluginFile, szMethodName); } } if (!FindNextFile(hSearch, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES){ fFinished = TRUE; } else { ms_error("couldn't find next plugin dll."); fFinished = TRUE; } } } /* Close the search handle. */ FindClose(hSearch); #elif defined(HAVE_DLOPEN) char plugin_name[64]; DIR *ds; MSList *loaded_plugins = NULL; struct dirent *de; char *ext; char *fullpath; ds=opendir(dir); if (ds==NULL){ ms_message("Cannot open directory %s: %s",dir,strerror(errno)); return -1; } while( (de=readdir(ds))!=NULL){ if ( #ifndef __QNX__ (de->d_type==DT_REG || de->d_type==DT_UNKNOWN || de->d_type==DT_LNK) && #endif (ext=strstr(de->d_name,PLUGINS_EXT))!=NULL) { void *handle; snprintf(plugin_name, MIN(sizeof(plugin_name), ext - de->d_name + 1), "%s", de->d_name); if (ms_list_find_custom(loaded_plugins, (MSCompareFunc)strcmp, plugin_name) != NULL) continue; loaded_plugins = ms_list_append(loaded_plugins, ms_strdup(plugin_name)); fullpath=ms_strdup_printf("%s/%s",dir,de->d_name); ms_message("Loading plugin %s...",fullpath); if ( (handle=dlopen(fullpath,RTLD_NOW))==NULL){ ms_warning("Fail to load plugin %s : %s",fullpath,dlerror()); }else { char *initroutine_name=ms_malloc0(strlen(de->d_name)+10); char *p; void *initroutine=NULL; strcpy(initroutine_name,de->d_name); p=strstr(initroutine_name,PLUGINS_EXT); if (p!=NULL){ strcpy(p,"_init"); initroutine=dlsym(handle,initroutine_name); } #ifdef __APPLE__ if (initroutine==NULL){ /* on macosx: library name are libxxxx.1.2.3.dylib */ /* -> MUST remove the .1.2.3 */ p=strstr(initroutine_name,"."); if (p!=NULL) { strcpy(p,"_init"); initroutine=dlsym(handle,initroutine_name); } } #endif if (initroutine!=NULL){ init_func_t func=(init_func_t)initroutine; func(factory); ms_message("Plugin loaded (%s)", fullpath); num++; }else{ ms_warning("Could not locate init routine of plugin %s",de->d_name); } ms_free(initroutine_name); } ms_free(fullpath); } } ms_list_for_each(loaded_plugins, ms_free); ms_list_free(loaded_plugins); closedir(ds); #else ms_warning("no loadable plugin support: plugins cannot be loaded."); num=-1; #endif return num; }
void scanDir (std::string path, std::list<FileProcess> &files) { // Prime the queue std::list<std::string> dir_queue; dir_queue.push_back(path); #if defined(_WIN32) while (dir_queue.size()) { std::string dir = dir_queue.back(); dir_queue.pop_back(); std::string dir_path = dir + SEP "*"; WIN32_FIND_DATAA FindFileData; HANDLE find_file = FindFirstFileExA(dir_path.c_str(), FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0 ); if (find_file == INVALID_HANDLE_VALUE) return; do { // Skip invisible files if (FindFileData.cFileName[0] != '.') { if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { dir_queue.push_back(dir + SEP + FindFileData.cFileName); } else { FileProcess f; f.file = FindFileData.cFileName; f.path = dir; struct stat buf; int s = ::stat( (f.path + SEP + f.file).c_str(), &buf); f.time = buf.st_ctime; files.push_back(f); } } } while (FindNextFileA(find_file, &FindFileData)); } #else while (dir_queue.size()) { std::string dir = dir_queue.back(); dir_queue.pop_back(); // Build the name list struct dirent **namelist = NULL; int n = scandir(dir.c_str(), &namelist, NULL, NULL); // Process and free the name list for (int i = 0; i < n; ++i) { // Skip invisible files if (namelist[i]->d_name[0] != '.') { if (namelist[i]->d_type == DT_DIR) { dir_queue.push_back(dir + SEP + namelist[i]->d_name); } else { FileProcess f; f.file = namelist[i]->d_name; f.path = dir; struct stat buf; int s = ::stat( (f.path + SEP + f.file).c_str(), &buf); f.time = buf.st_ctime; files.push_back(f); } } ::free(namelist[i]); } if (namelist) ::free(namelist); } #endif }
void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, PHYSFS_EnumFilesCallback callback, const char *origdir, void *callbackdata) { const int unicode = (pFindFirstFileW != NULL) && (pFindNextFileW != NULL); HANDLE dir = INVALID_HANDLE_VALUE; WIN32_FIND_DATA ent; WIN32_FIND_DATAW entw; size_t len = strlen(dirname); char *searchPath = NULL; WCHAR *wSearchPath = NULL; char *utf8 = NULL; /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */ searchPath = (char *)__PHYSFS_smallAlloc(len + 3); if (searchPath == NULL) return; /* Copy current dirname */ strcpy(searchPath, dirname); /* if there's no '\\' at the end of the path, stick one in there. */ if (searchPath[len - 1] != '\\') { searchPath[len++] = '\\'; searchPath[len] = '\0'; } /* if */ /* Append the "*" to the end of the string */ strcat(searchPath, "*"); UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath); if (wSearchPath == NULL) return; /* oh well. */ if (unicode) dir = pFindFirstFileW(wSearchPath, &entw); else { const int len = (int)(wStrLen(wSearchPath) + 1); char *cp = (char *)__PHYSFS_smallAlloc(len); if (cp != NULL) { WideCharToMultiByte(CP_ACP, 0, wSearchPath, len, cp, len, 0, 0); //dir = FindFirstFileA(cp, &ent); dir = FindFirstFileExA(cp, FindExInfoStandard, &ent, FindExSearchNameMatch, NULL, 0); __PHYSFS_smallFree(cp); } /* if */ } /* else */ __PHYSFS_smallFree(wSearchPath); __PHYSFS_smallFree(searchPath); if (dir == INVALID_HANDLE_VALUE) return; if (unicode) { do { const DWORD attr = entw.dwFileAttributes; const DWORD tag = entw.dwReserved0; const WCHAR *fn = entw.cFileName; if ((fn[0] == '.') && (fn[1] == '\0')) continue; if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0')) continue; if ((omitSymLinks) && (isSymlinkAttrs(attr, tag))) continue; utf8 = unicodeToUtf8Heap(fn); if (utf8 != NULL) { callback(callbackdata, origdir, utf8); allocator.Free(utf8); } /* if */ } while (pFindNextFileW(dir, &entw) != 0); } /* if */ else /* ANSI fallback. */ { do { const DWORD attr = ent.dwFileAttributes; const DWORD tag = ent.dwReserved0; const char *fn = ent.cFileName; if ((fn[0] == '.') && (fn[1] == '\0')) continue; if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0')) continue; if ((omitSymLinks) && (isSymlinkAttrs(attr, tag))) continue; utf8 = codepageToUtf8Heap(fn); if (utf8 != NULL) { callback(callbackdata, origdir, utf8); allocator.Free(utf8); } /* if */ } while (FindNextFileA(dir, &ent) != 0); } /* else */ FindClose(dir); } /* __PHYSFS_platformEnumerateFiles */
Menu::Menu(unique_ptr<Game> & game) : mGame(game), mCameraChangeTime(30 * 60), mDistBetweenButtons(68), mVisible(true), mPage(Page::Main), mLoadSaveGameName("") { // Load config mConfig.Load("config.cfg"); mLocalization.Load(mGame->GetLocalizationPath() + "menu.loc"); // load background scene mScene = mGame->GetEngine()->GetSceneFactory()->LoadScene("data/maps/menu.scene"); // create gui scene mGUIScene = mGame->GetEngine()->CreateGUIScene(); // create camera mpCamera = make_unique<GameCamera>(mGUIScene); mCameraPos1 = mScene->FindChild("Camera"); mCameraPos2 = mScene->FindChild("Camera2"); mpCamera->mCamera->Attach(mCameraPos1); mCameraFadeActionDone = false; mCameraInitialPosition = Vector3(0, 0, 0); mCameraAnimationNewOffset = Vector3(0.5, 0.5, 0.5); auto soundSystem = mGame->GetEngine()->GetSoundSystem(); mPickSound = soundSystem->LoadSound2D("data/sounds/menupick.ogg"); mMusic = soundSystem->LoadMusic3D("data/music/menu.ogg"); mMusic->SetPosition(mScene->FindChild("Radio")->GetPosition()); mMusic->SetRolloffFactor(0.1); mMusic->SetRoomRolloffFactor(0.1); const float buttonHeight = 30; const float buttonWidth = 128; const float buttonXOffset = 10; auto renderer = mGame->GetEngine()->GetRenderer(); // load textures auto texTab = renderer->GetTexture("data/gui/menu/tab.tga"); auto texButton = renderer->GetTexture("data/gui/menu/button.tga"); auto texSmallButton = renderer->GetTexture("data/gui/menu/button.tga"); // Setup mCanvas = mGUIScene->CreateRect(0, 0, 0, 0, nullptr); { // Main mGUIMainButtonsCanvas = mGUIScene->CreateRect(20, ruVirtualScreenHeight - 4.0 * mDistBetweenButtons, buttonWidth + 2 * buttonXOffset, buttonHeight * 8.5, texTab, pGUIProp->mBackColor); mGUIMainButtonsCanvas->Attach(mCanvas); { mContinueGameButton = mGUIScene->CreateButton(buttonXOffset, 5, buttonWidth, buttonHeight, texButton, mLocalization.GetString("continueButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mContinueGameButton->Attach(mGUIMainButtonsCanvas); mContinueGameButton->AddAction(GUIAction::OnClick, [this] { OnContinueGameClick(); }); mStartButton = mGUIScene->CreateButton(buttonXOffset, 5 + 0.5f * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("startButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mStartButton->Attach(mGUIMainButtonsCanvas); mStartButton->AddAction(GUIAction::OnClick, [this] { OnStartNewGameClick(); }); mSaveGameButton = mGUIScene->CreateButton(buttonXOffset, 5 + 1.0f * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("saveButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mSaveGameButton->Attach(mGUIMainButtonsCanvas); mSaveGameButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::SaveGame); FillListOfSaveFiles(); }); mLoadGameButton = mGUIScene->CreateButton(buttonXOffset, 5 + 1.5f * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("loadButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mLoadGameButton->Attach(mGUIMainButtonsCanvas); mLoadGameButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::LoadGame); FillListOfSaveFiles(); }); mOptionsButton = mGUIScene->CreateButton(buttonXOffset, 5 + 2.0f * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("optionsButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mOptionsButton->Attach(mGUIMainButtonsCanvas); mOptionsButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::Options); }); mAuthorsButton = mGUIScene->CreateButton(buttonXOffset, 5 + 2.5f * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("authorsButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mAuthorsButton->Attach(mGUIMainButtonsCanvas); mAuthorsButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::Authors); }); mExitButton = mGUIScene->CreateButton(buttonXOffset, 5 + 3.0f * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("exitButton"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mExitButton->Attach(mGUIMainButtonsCanvas); mExitButton->AddAction(GUIAction::OnClick, [this] { OnExitGameClick(); }); } const int aTabX = 200; const int aTabY = ruVirtualScreenHeight - 4.0 * mDistBetweenButtons; const int aTabWidth = buttonWidth * 4; const int aTabHeight = buttonHeight * 8.5; // Modal window mModalWindow = make_unique<ModalWindow>(mGUIScene, aTabX, aTabY, aTabWidth, aTabHeight, texTab, texButton, pGUIProp->mBackColor); mModalWindow->AttachTo(mCanvas); // Page title mWindowText = mGUIScene->CreateText(" ", aTabX, aTabY - 21, aTabWidth, 32, pGUIProp->mFont, Vector3(255, 255, 255), TextAlignment::Left); mWindowText->Attach(mCanvas); // Product name mCaption = mGUIScene->CreateText("The Mine", 20, aTabY - 21, aTabWidth * 1.5f, 32, pGUIProp->mFont, Vector3(255, 255, 255), TextAlignment::Left); mCaption->Attach(mCanvas); // Options mGUIOptionsCanvas = mGUIScene->CreateRect(aTabX, aTabY, aTabWidth, aTabHeight, texTab, pGUIProp->mBackColor); mGUIOptionsCanvas->Attach(mCanvas); { const int yOffset = (aTabHeight - 2 * mDistBetweenButtons) / 2; mGUIOptionsCommonButton = mGUIScene->CreateButton((aTabWidth - buttonWidth) / 2, yOffset, buttonWidth, buttonHeight, texButton, mLocalization.GetString("commonSettings"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mGUIOptionsCommonButton->Attach(mGUIOptionsCanvas); mGUIOptionsCommonButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::OptionsCommon); }); mGUIOptionsControlsButton = mGUIScene->CreateButton((aTabWidth - buttonWidth) / 2, yOffset + 0.5 * mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("controls"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mGUIOptionsControlsButton->Attach(mGUIOptionsCanvas); mGUIOptionsControlsButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::OptionsKeys); }); mGUIOptionsGraphicsButton = mGUIScene->CreateButton((aTabWidth - buttonWidth) / 2, yOffset + mDistBetweenButtons, buttonWidth, buttonHeight, texButton, mLocalization.GetString("graphics"), pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mGUIOptionsGraphicsButton->Attach(mGUIOptionsCanvas); mGUIOptionsGraphicsButton->AddAction(GUIAction::OnClick, [this] { SetPage(Page::OptionsGraphics); }); } // Options: Keys mOptionsKeysCanvas = mGUIScene->CreateRect(aTabX, aTabY, aTabWidth, aTabHeight, texTab, pGUIProp->mBackColor); mGUIOptionsCanvas->Attach(mCanvas); mOptionsKeysCanvas->SetVisible(false); { // First column float x = 40, y = 10; mMoveForwardKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("forward")); mMoveForwardKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mMoveBackwardKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("backward")); mMoveBackwardKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mStrafeLeftKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("strafeLeft")); mStrafeLeftKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mStrafeRightKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("strafeRight")); mStrafeRightKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mJumpKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("jump")); mJumpKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mFlashLightKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("flashLight")); mFlashLightKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mRunKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("run")); mRunKey->AttachTo(mOptionsKeysCanvas); // Second column x += 150; y = 10; mInventoryKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("inventory")); mInventoryKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mUseKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("use")); mUseKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mQuickLoadKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("quickLoad")); mQuickLoadKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mQuickSaveKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("quickSave")); mQuickSaveKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mStealthKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("stealth")); mStealthKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mLookLeftKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("lookLeft")); mLookLeftKey->AttachTo(mOptionsKeysCanvas); y += 32 * 1.1f; mLookRightKey = make_unique<WaitKeyButton>(mGame, mGUIScene, x, y, texSmallButton, mLocalization.GetString("lookRight")); mLookRightKey->AttachTo(mOptionsKeysCanvas); } // Options: Graphics mOptionsGraphicsCanvas = mGUIScene->CreateRect(aTabX, aTabY, buttonWidth * 5.5, aTabHeight, texTab, pGUIProp->mBackColor); mOptionsGraphicsCanvas->Attach(mCanvas); mOptionsGraphicsCanvas->SetVisible(false); { float x = 30, y = 10; mFXAAButton = make_unique<RadioButton>(mGUIScene, x, y, texButton, mLocalization.GetString("fxaa")); mFXAAButton->AttachTo(mOptionsGraphicsCanvas); mFPSButton = make_unique<RadioButton>(mGUIScene, x, y + 0.5 * mDistBetweenButtons, texButton, mLocalization.GetString("showFPS")); mFPSButton->AttachTo(mOptionsGraphicsCanvas); mSpotShadowsButton = make_unique<RadioButton>(mGUIScene, x, y + mDistBetweenButtons, texButton, mLocalization.GetString("spotLightShadows")); mSpotShadowsButton->AttachTo(mOptionsGraphicsCanvas); mPointShadowsButton = make_unique<RadioButton>(mGUIScene, x, y + 1.5 * mDistBetweenButtons, texButton, mLocalization.GetString("pointLightShadows")); mPointShadowsButton->AttachTo(mOptionsGraphicsCanvas); mHDRButton = make_unique<RadioButton>(mGUIScene, x, y + 2.0 * mDistBetweenButtons, texButton, mLocalization.GetString("hdr")); mHDRButton->AttachTo(mOptionsGraphicsCanvas); mParallaxButton = make_unique<RadioButton>(mGUIScene, x, y + 2.5 * mDistBetweenButtons, texButton, mLocalization.GetString("parallax")); mParallaxButton->AttachTo(mOptionsGraphicsCanvas); mVolumetricFogButton = make_unique<RadioButton>(mGUIScene, x, y + 3.0 * mDistBetweenButtons, texButton, mLocalization.GetString("volumetricFog")); mVolumetricFogButton->AttachTo(mOptionsGraphicsCanvas); // next column x += 170; mDynamicDirectionalLightShadows = make_unique<RadioButton>(mGUIScene, x, y, texButton, mLocalization.GetString("dynamicDirectionalLightShadows")); mDynamicDirectionalLightShadows->AttachTo(mOptionsGraphicsCanvas); mBloom = make_unique<RadioButton>(mGUIScene, x, y + 0.5 * mDistBetweenButtons, texButton, mLocalization.GetString("bloom")); mBloom->AttachTo(mOptionsGraphicsCanvas); mSoftParticles = make_unique<RadioButton>(mGUIScene, x, y + 1.0 * mDistBetweenButtons, texButton, mLocalization.GetString("softParticles")); mSoftParticles->AttachTo(mOptionsGraphicsCanvas); mVSync = make_unique<RadioButton>(mGUIScene, x, y + 1.5 * mDistBetweenButtons, texButton, mLocalization.GetString("vsync")); mVSync->AttachTo(mOptionsGraphicsCanvas); // mVSync->OnChange += [this] { mSettingsApplied->SetText(mLocalization.GetString("settingsNotApplied")); mSettingsApplied->SetColor(Vector3(255, 0, 0)); }; // next column x += 170; mResolutionList = make_unique<ScrollList>(mGUIScene, x, y, texButton, mLocalization.GetString("resolution")); mResolutionList->AttachTo(mOptionsGraphicsCanvas); auto videoModes = mGame->GetEngine()->GetRenderer()->GetVideoModeList(); for(auto videoMode : videoModes) { mResolutionList->AddValue(StringBuilder() << videoMode.mWidth << "x" << videoMode.mHeight << "@" << videoMode.mRefreshRate); } mResolutionList->OnChange += [this] { mSettingsApplied->SetText(mLocalization.GetString("settingsNotApplied")); mSettingsApplied->SetColor(Vector3(255, 0, 0)); }; mWindowMode = make_unique<ScrollList>(mGUIScene, x, y + 0.5 * mDistBetweenButtons, texButton, mLocalization.GetString("windowMode")); mWindowMode->AttachTo(mOptionsGraphicsCanvas); mWindowMode->AddValue(mLocalization.GetString("windowed")); mWindowMode->AddValue(mLocalization.GetString("fullscreen")); mWindowMode->AddValue(mLocalization.GetString("borderless")); mWindowMode->OnChange += [this] { mSettingsApplied->SetText(mLocalization.GetString("settingsNotApplied")); mSettingsApplied->SetColor(Vector3(255, 0, 0)); }; mTextureFiltering = make_unique<ScrollList>(mGUIScene, x, y + 1.0 * mDistBetweenButtons, texButton, mLocalization.GetString("filtering")); mTextureFiltering->AttachTo(mOptionsGraphicsCanvas); mTextureFiltering->AddValue(mLocalization.GetString("trilinear")); for(int i = 1; i <= mGame->GetEngine()->GetRenderer()->GetMaxIsotropyDegree(); ++i) { mTextureFiltering->AddValue(StringBuilder() << mLocalization.GetString("anisotropic") << " x" << i); } mSpotLightShadowMapSize = make_unique<ScrollList>(mGUIScene, x, y + 1.5 * mDistBetweenButtons, texButton, mLocalization.GetString("spotLightShadowMap")); mSpotLightShadowMapSize->AttachTo(mOptionsGraphicsCanvas); for(int i = 256; i <= 2048; i *= 2) { mSpotLightShadowMapSize->AddValue(StringBuilder() << i << " x " << i); } mPointLightShadowMapSize = make_unique<ScrollList>(mGUIScene, x, y + 2.0 * mDistBetweenButtons, texButton, mLocalization.GetString("pointLightShadowMap")); mPointLightShadowMapSize->AttachTo(mOptionsGraphicsCanvas); for(int i = 128; i <= 1024; i *= 2) { mPointLightShadowMapSize->AddValue(StringBuilder() << i << " x " << i); } mDirectionalLightShadowMapSize = make_unique<ScrollList>(mGUIScene, x, y + 2.5 * mDistBetweenButtons, texButton, mLocalization.GetString("directionalLightShadowMap")); mDirectionalLightShadowMapSize->AttachTo(mOptionsGraphicsCanvas); for(int i = 1024; i <= 4096; i *= 2) { mDirectionalLightShadowMapSize->AddValue(StringBuilder() << i << " x " << i); } mSettingsApplied = mGUIScene->CreateText(mLocalization.GetString("settingsApplied"), x, y + 3.1 * mDistBetweenButtons, aTabWidth - 30, aTabHeight - 30, pGUIProp->mFont, Vector3(0, 255, 0), TextAlignment::Left); mSettingsApplied->Attach(mOptionsGraphicsCanvas); } // Authors mAuthorsBackground = mGUIScene->CreateRect(aTabX, aTabY, aTabWidth, aTabHeight, texTab, pGUIProp->mBackColor); mAuthorsBackground->Attach(mCanvas); { mGUIAuthorsText = mGUIScene->CreateText(mLocalization.GetString("authorsText"), 15, 15, aTabWidth - 30, aTabHeight - 30, pGUIProp->mFont, Vector3(255, 255, 255), TextAlignment::Left); mGUIAuthorsText->Attach(mAuthorsBackground); } // Save Game mSaveGameCanvas = mGUIScene->CreateRect(aTabX, aTabY, aTabWidth, aTabHeight, texTab, pGUIProp->mBackColor); mSaveGameCanvas->Attach(mCanvas); { float y = 10; for(int i = 0; i < mSaveLoadSlotCount; i++) { mSaveGameSlot[i] = mGUIScene->CreateButton(20, y, buttonWidth, buttonHeight, texButton, "Empty slot", pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mSaveGameSlot[i]->Attach(mSaveGameCanvas); mSaveGameSlot[i]->AddAction(GUIAction::OnClick, [this] { OnCreateSaveClick(); }); mSaveGameFileTime[i] = mGUIScene->CreateText(" ", buttonWidth + 30, y, 160, buttonHeight, pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Left); mSaveGameFileTime[i]->Attach(mSaveGameCanvas); y += 1.1f * buttonHeight; } } // Load Game mLoadGameCanvas = mGUIScene->CreateRect(aTabX, aTabY, aTabWidth, aTabHeight, texTab, pGUIProp->mBackColor); mLoadGameCanvas->Attach(mCanvas); { float y = 10; for(int i = 0; i < mSaveLoadSlotCount; i++) { mLoadGameSlot[i] = mGUIScene->CreateButton(20, y, buttonWidth, buttonHeight, texButton, "Empty slot", pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Center); mLoadGameSlot[i]->Attach(mLoadGameCanvas); mLoadGameSlot[i]->AddAction(GUIAction::OnClick, [this] { OnLoadSaveClick(); }); mLoadGameFileTime[i] = mGUIScene->CreateText(" ", buttonWidth + 30, y, 160, buttonHeight, pGUIProp->mFont, pGUIProp->mForeColor, TextAlignment::Left); mLoadGameFileTime[i]->Attach(mLoadGameCanvas); y += 1.1f * buttonHeight; } } // Options: Common mOptionsCommonCanvas = mGUIScene->CreateRect(aTabX, aTabY, aTabWidth, aTabHeight, texTab, pGUIProp->mBackColor); mOptionsCommonCanvas->Attach(mCanvas); mOptionsCommonCanvas->SetVisible(false); { const int yOffset = (aTabHeight - 1.5 * mDistBetweenButtons) / 2; int xOffset = 20; mFOVSlider = make_unique<Slider>(mGUIScene, xOffset, yOffset - 0.5f * mDistBetweenButtons, 55, 90, 1.0f, renderer->GetTexture("data/gui/menu/smallbutton.tga"), mLocalization.GetString("fov")); mFOVSlider->AttachTo(mOptionsCommonCanvas); mMasterVolume = make_unique<Slider>(mGUIScene, xOffset, yOffset, 0, 100, 2.5f, renderer->GetTexture("data/gui/menu/smallbutton.tga"), mLocalization.GetString("masterVolume")); mMasterVolume->AttachTo(mOptionsCommonCanvas); mMasterVolume->SetChangeAction([this] { mGame->GetEngine()->GetSoundSystem()->SetMasterVolume(mMasterVolume->GetValue() / 100.0f); }); mMusicVolume = make_unique<Slider>(mGUIScene, xOffset, yOffset + 0.5f * mDistBetweenButtons, 0, 100, 2.5f, renderer->GetTexture("data/gui/menu/smallbutton.tga"), mLocalization.GetString("musicVolume")); mMusicVolume->AttachTo(mOptionsCommonCanvas); mMusicVolume->SetChangeAction([this] { OnMusicVolumeChange(); }); mMouseSensivity = make_unique<Slider>(mGUIScene, xOffset, yOffset + 1.0f * mDistBetweenButtons, 0, 100, 2.5f, renderer->GetTexture("data/gui/menu/smallbutton.tga"), mLocalization.GetString("mouseSens")); mMouseSensivity->AttachTo(mOptionsCommonCanvas); mMouseSensivity->SetChangeAction([this] { mGame->SetMouseSensitivity(mMouseSensivity->GetValue() / 100.0f); }); mLanguage = make_unique<ScrollList>(mGUIScene, xOffset, yOffset + 1.5 * mDistBetweenButtons, texButton, mLocalization.GetString("language")); mLanguage->AttachTo(mOptionsCommonCanvas); mLanguage->OnChange += [this] { mConfig.SetString("languagePath", StringBuilder("data/lang/") << mLanguage->GetValueString(mLanguage->GetCurrentValue()) << "/"); }; mLangSettingsApplied = mGUIScene->CreateText(mLocalization.GetString("langChange"), 20, 3.3 * mDistBetweenButtons, aTabWidth - 30, aTabHeight - 30, pGUIProp->mFont, Vector3(255, 0, 0), TextAlignment::Left); mLangSettingsApplied->Attach(mOptionsCommonCanvas); xOffset += 300; mMouseInversionX = make_unique<RadioButton>(mGUIScene, xOffset, yOffset - 0.5 * mDistBetweenButtons, texButton, mLocalization.GetString("mouseInvX")); mMouseInversionX->AttachTo(mOptionsCommonCanvas); mMouseInversionY = make_unique<RadioButton>(mGUIScene, xOffset, yOffset, texButton, mLocalization.GetString("mouseInvY")); mMouseInversionY->AttachTo(mOptionsCommonCanvas); int current = 0, i = 0; WIN32_FIND_DATAA fi; HANDLE h = FindFirstFileExA("data/lang/*.*", FindExInfoStandard, &fi, FindExSearchLimitToDirectories, NULL, 0); if(h != INVALID_HANDLE_VALUE) { do { if(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { string v = fi.cFileName; if(v != "." && v != "..") { mLanguage->AddValue(v); if(mConfig.GetString("languagePath").rfind(v) != string::npos) { current = i; } ++i; } } } while(FindNextFileA(h, &fi)); FindClose(h); } mLanguage->SetCurrentValue(current); } } mGame->GetEngine()->GetSoundSystem()->SetReverbPreset(ReverbPreset::Auditorium); SetAuthorsPageVisible(false); SetPage(Page::Main); ReadConfig(); }
void FileWatcher::recurseDirectory(const std::string& dir, std::list<std::string>& output, const std::string& wildcard) { #ifdef WIN32 WIN32_FIND_DATAA find = {}; HANDLE findHandle = FindFirstFileExA((dir + "\\*").c_str(), FindExInfoStandard, &find, FindExSearchNameMatch, NULL, 0); if (findHandle == INVALID_HANDLE_VALUE) return; do { std::string name = find.cFileName; if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (name != "." && name != "..") recurseDirectory(dir + '\\' + name, output, wildcard); } else { if (wildcmp(wildcard.c_str(), name.c_str())) { if (dir == ".") output.push_back(name); else output.push_back(dir + '\\' + name); } } if (!FindNextFileA(findHandle, &find)) break; } while (findHandle != INVALID_HANDLE_VALUE); #else DIR* dp; if ((dp = opendir(dir.c_str())) == nullptr) return; dirent* ent; while ((ent = readdir(dp))) { std::string name = ent->d_name; if (!(ent->d_type & (DT_DIR | DT_LNK))) { if (wildcmp(wildcard.c_str(), name.c_str())) { if (dir == ".") output.push_back(name); else output.push_back(dir + '/' + name); } continue; } if (name == "." || name == "..") continue; std::string path = dir + '/' + name; recurseDirectory(path, output, wildcard); } closedir(dp); #endif }