void GeorefConfigDialog::load_world_file_cb(void) { const QStringList selection = this->world_file_selector->get_selected_files_full_paths(); if (0 == selection.size()) { return; } WorldFile wfile; const WorldFile::ReadStatus answer = wfile.read_file(selection.at(0)); switch (answer) { case WorldFile::ReadStatus::OpenError: Dialog::error(tr("The World file you requested could not be opened for reading."), this); break; case WorldFile::ReadStatus::ReadError: Dialog::error(tr("Unexpected end of file reading World file."), this); break; case WorldFile::ReadStatus::Success: this->set_widget_values(wfile); break; default: qDebug() << SG_PREFIX_E << "Unhandled read status" << (int) answer; break; } }
/** * Adds collision quads for the world boundary walls. Prevents player from leaving * the world node area. */ void WorldNode::SetupWorldCollWalls(const WorldFile& grid) { // add boundary walls to quad list // world left side for(int row = 0; row < grid.GetHeight(); row++) { D3DXVECTOR3 p1( 0.0f, 0.0f, (float)row ); D3DXVECTOR3 p2( 0.0f, kWorldScale, (float)row ); D3DXVECTOR3 p3( 0.0f, kWorldScale, (float)row+kWorldScale ); D3DXVECTOR3 p4( 0.0f, 0.0f, (float)row+kWorldScale ); D3DXVECTOR3 n; D3DXVec3Cross(&n, &(p2-p1), &(p3-p1)); m_vCollQuads.push_back( CollQuad(p1, p2, p3, p4, n) ); } // world right side for(int row = 0; row < grid.GetHeight(); row++) { D3DXVECTOR3 p1( (float)grid.GetWidth(), 0.0f, (float)row ); D3DXVECTOR3 p2( (float)grid.GetWidth(), 0.0f, (float)row+kWorldScale ); D3DXVECTOR3 p3( (float)grid.GetWidth(), kWorldScale, (float)row+kWorldScale ); D3DXVECTOR3 p4( (float)grid.GetWidth(), kWorldScale, (float)row ); D3DXVECTOR3 n; D3DXVec3Cross(&n, &(p2-p1), &(p3-p1)); m_vCollQuads.push_back( CollQuad(p1, p2, p3, p4, n) ); } // world lower side for(int col = 0; col < grid.GetWidth(); col++) { D3DXVECTOR3 p1( (float)col, 0.0f, 0.0f ); D3DXVECTOR3 p2( (float)col+kWorldScale, 0.0f, 0.0f ); D3DXVECTOR3 p3( (float)col+kWorldScale, kWorldScale, 0.0f ); D3DXVECTOR3 p4( (float)col, kWorldScale, 0.0f ); D3DXVECTOR3 n; D3DXVec3Cross(&n, &(p2-p1), &(p3-p1)); m_vCollQuads.push_back( CollQuad(p1, p2, p3, p4, n) ); } // world upper side for(int col = 0; col < grid.GetWidth(); col++) { D3DXVECTOR3 p1( (float)col, 0.0f, (float)grid.GetHeight() ); D3DXVECTOR3 p2( (float)col, kWorldScale, (float)grid.GetHeight() ); D3DXVECTOR3 p3( (float)col+kWorldScale, kWorldScale, (float)grid.GetHeight() ); D3DXVECTOR3 p4( (float)col+kWorldScale, 0.0f, (float)grid.GetHeight() ); D3DXVECTOR3 n; D3DXVec3Cross(&n, &(p2-p1), &(p3-p1)); m_vCollQuads.push_back( CollQuad(p1, p2, p3, p4, n) ); } }
/** Auto attempt to read the world file associated with the image used for the georef. Based on simple file name conventions. Only attempted if the preference is on. */ static void maybe_read_world_file(FileSelectorWidget * file_selector, void * user_data) { if (!user_data) { return; } GeorefConfigDialog * dialog = (GeorefConfigDialog *) user_data; if (!Preferences::get_param_value(PREFERENCES_NAMESPACE_IO "georef_auto_read_world_file").u.val_bool) { return; } const QString file_full_path = file_selector->get_selected_file_full_path(); if (file_full_path.isEmpty()) { return; } const int len = file_full_path.length(); const bool upper = file_full_path[len - 1].isUpper(); WorldFile wfile; /* Naming convention 1: .jpg -> .jpgw */ { const QString world_file_full_path = file_full_path + (upper ? "W" : "w"); qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 1:" << world_file_full_path; if (WorldFile::ReadStatus::Success == wfile.read_file(world_file_full_path)) { dialog->set_widget_values(wfile); qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 1: success"; return; } } /* Naming convention 2: .jpg -> .jgw */ { if (len > 3) { QString world_file_full_path = file_full_path; const QChar last_char = file_full_path[len - 1]; world_file_full_path[len - 2] = last_char; world_file_full_path[len - 1] = upper ? 'W' : 'w'; qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 2:" << world_file_full_path; if (WorldFile::ReadStatus::Success == wfile.read_file(world_file_full_path)) { dialog->set_widget_values(wfile); qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 2: success"; return; } } } /* Naming convention 3: always .wld */ { if (len > 3) { QString world_file_full_path = file_full_path; world_file_full_path.chop(3); if (upper) { world_file_full_path.append("WLD"); } else { world_file_full_path.append("wld"); } qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 3:" << world_file_full_path; if (WorldFile::ReadStatus::Success == wfile.read_file(world_file_full_path)) { dialog->set_widget_values(wfile); qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 3: success"; return; } } } }
Minimap::Minimap(IDirect3DDevice9* pd3dDevice, WorldFile& worldFile) : m_Ok(false) , m_WorldFile(worldFile) , m_pMinimapTexture(NULL) , m_pMinimapMask(NULL) , m_pMinimapFrame(NULL) , m_pMinimapSaveStateBlock(NULL) { HRESULT hr; UINT const w = UINT(worldFile.GetWidth()); UINT const h = UINT(worldFile.GetHeight()); hr = pd3dDevice->CreateTexture(w, h, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pMinimapTexture, NULL); // hr = FindAndLoadTexture(pd3dDevice, L"Map256x256.bmp", &m_pMinimapTexture); if (FAILED(hr)) { return; } D3DLOCKED_RECT lockedRect = { 0 }; hr = m_pMinimapTexture->LockRect(0, &lockedRect, NULL, 0); if (FAILED(hr)) { return; } for (UINT y = 0; y < h; ++y) { DWORD* const pRow = (DWORD*) ((BYTE*)lockedRect.pBits + lockedRect.Pitch * (w-1 - y)); for (UINT x = 0; x < w; ++x) { switch(worldFile(y, x)) { case WorldFile::INVALID_CELL: pRow[x] = 0xFFFF0000; // Red break; case WorldFile::OCCUPIED_CELL: pRow[x] = D3DCOLOR_XRGB(160, 100, 100); break; default: pRow[x] = D3DCOLOR_XRGB(160, 180, 100); break; } } } m_pMinimapTexture->UnlockRect(0); hr = FindAndLoadTexture(pd3dDevice, L"Circle256x256.tga", &m_pMinimapMask); if (FAILED(hr)) { return; } hr = FindAndLoadTexture(pd3dDevice, L"MinimapFrame256x256.tga", &m_pMinimapFrame); if (FAILED(hr)) { return; } hr = pd3dDevice->CreateStateBlock(D3DSBT_ALL, &m_pMinimapSaveStateBlock); if (FAILED(hr)) { PrintfError(L"Error creating minimap's save state block."); return; } m_Ok = true; }