void CNameTags::Draw() { if(!bbfont) { bbfont = new CBBFont(m_pD3DDevice, "vcpfnt"); bbfont->Initialise(); } if(!BarOldStateBlock) { m_pD3DDevice->BeginStateBlock(); m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); m_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, 1); m_pD3DDevice->SetRenderState(D3DRS_FILLMODE, 3); m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, 1); m_pD3DDevice->SetRenderState(D3DRS_WRAP0, 0); m_pD3DDevice->SetRenderState(D3DRS_CLIPPING, 1); m_pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, 0); m_pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 1); m_pD3DDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, 0); m_pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 15); m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1); m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, 5); m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, 6); m_pD3DDevice->SetRenderState(D3DRS_BLENDOP, 1); m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4); m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2); m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0); m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 4); m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2); m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0); m_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0); m_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1); m_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, 1); m_pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); m_pD3DDevice->SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE); m_pD3DDevice->SetStreamSource(0, NULL, 0); m_pD3DDevice->EndStateBlock(&BarOldStateBlock); } if(!BarNewStateBlock) { m_pD3DDevice->BeginStateBlock(); m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); m_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, 1); m_pD3DDevice->SetRenderState(D3DRS_FILLMODE, 3); m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, 1); m_pD3DDevice->SetRenderState(D3DRS_WRAP0, 0); m_pD3DDevice->SetRenderState(D3DRS_CLIPPING, 1); m_pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, 0); m_pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 1); m_pD3DDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, 0); m_pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 15); m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1); m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, 5); m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, 6); m_pD3DDevice->SetRenderState(D3DRS_BLENDOP, 1); m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4); m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2); m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0); m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 1); m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2); m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0); m_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0); m_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1); m_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, 1); m_pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); m_pD3DDevice->SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE); m_pD3DDevice->EndStateBlock(&BarNewStateBlock); } m_pD3DDevice->CaptureStateBlock(BarOldStateBlock); m_pD3DDevice->ApplyStateBlock(BarNewStateBlock); D3DXMATRIX matTransposed; D3DXMatrixTranspose(&matTransposed, (D3DXMATRIX*)&matView); matTransposed._14 = matTransposed._24 = matTransposed._34 = 0.0f; if(pNetowkManager) { CPlayerManager* pPlayerManager = pNetowkManager->GetPlayerManager(); for(int x = 0; x < MAX_PLAYERS; x++) { if(pPlayerManager->GetSlotState(x) == TRUE) { // Player is in use CRemotePlayer* Player = pPlayerManager->GetAt(x); if(Player->IsActive() && (Player->GetDistanceFromLocalPlayer() <= 80.0f)) { // Active and within reasonable distance CPlayerPed* PlayerPed = Player->GetPlayerPed(); if(PlayerPed->IsOnScreen()) { // They're onscreen // Get their position Vector3 vPos; PlayerPed->GetPosition(&vPos); // Set the matrix position matTransposed._41 = vPos.X; matTransposed._42 = vPos.Y; matTransposed._43 = vPos.Z + 1.0f; // Set the world transformation m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTransposed); // Get their health and armour // TODO: Use the player ped health/armour? float Health = Player->GetReportedHealth(); float Armour = Player->GetReportedArmour(); // Cap their health and armour if needed if(Health > 100.0f) Health = 100.0f; if(Armour > 100.0f) Armour = 100.0f; // Set the health bar offsets BarBGVertices[0].x = BarBGVertices[1].x = (0.0058f * Health) - 0.29f; // Set the health bar color BarVertices[0].c = BarVertices[1].c = BarVertices[2].c = BarVertices[3].c = HEALTH_BAR_COLOR; // Draw the health bar border m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, BarBDRVertices, sizeof(BarVertices_s)); // Draw the health bar fill m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, BarVertices, sizeof(BarVertices_s)); // Draw the health bar background m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, BarBGVertices, sizeof(BarVertices_s)); if(Armour > 0.0f) { // They have armour // Add an offset to the z position matTransposed._43 += 0.1f; // Set the world transformation m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTransposed); // Set the armour bar offsets BarBGVertices[0].x = BarBGVertices[1].x = (0.0058f * Armour) - 0.29f; // Set the armour bar color BarVertices[0].c = BarVertices[1].c = BarVertices[2].c = BarVertices[3].c = ARMOUR_BAR_COLOR; // Draw the armour bar border m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, BarBDRVertices, sizeof(BarVertices_s)); // Draw the armour bar fill m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, BarVertices, sizeof(BarVertices_s)); // Draw the armour bar background m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, BarBGVertices, sizeof(BarVertices_s)); } // Draw the name tag if(bbfont) { bbfont->Begin(); //bbfont->Draw(pPlayerManager->GetPlayerName(x), 0.285f, 0xFF000000); bbfont->Draw(pPlayerManager->GetPlayerName(x), 0.300f, Player->GetTeamColorAsARGB()); bbfont->End(); } } } } } } m_pD3DDevice->ApplyStateBlock(BarOldStateBlock); }
void TheGameLoop() { // If the game is not inited then do it now. if(!bGameInited && FileCheckSum()) { if(tSettings.bPlayOnline) { pNetGame = new CNetGame(tSettings.szConnectHost,atoi(tSettings.szConnectPort), tSettings.szNickName,tSettings.szConnectPass); } pGame->ToggleFrameLimiterState(TRUE); bGameInited = TRUE; return; } // The NetGame processing has been moved // to the Direct3DDevice::Present hook. // This is to solve alt-tab issues. // BEGIN: HEALTH BAR AND PLAYER NAME STUFF if(!pGame->IsMenuActive() && bShowNameTags) { if(!bbfont) { bbfont = new CBBFont(pD3DDevice, "vcmpfnt"); bbfont->Initialise(); } if (!HealthBarOldStateBlock) { pD3DDevice->BeginStateBlock(); pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); pD3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); pD3DDevice->SetRenderState(D3DRS_ZENABLE, 1); pD3DDevice->SetRenderState(D3DRS_FILLMODE, 3); pD3DDevice->SetRenderState(D3DRS_CULLMODE, 1); pD3DDevice->SetRenderState(D3DRS_WRAP0, 0); pD3DDevice->SetRenderState(D3DRS_CLIPPING, 1); pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, 0); pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 1); pD3DDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, 0); pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 15); pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1); pD3DDevice->SetRenderState(D3DRS_SRCBLEND, 5); pD3DDevice->SetRenderState(D3DRS_DESTBLEND, 6); pD3DDevice->SetRenderState(D3DRS_BLENDOP, 1); pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4); pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2); pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 4); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0); pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0); pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1); pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, 1); pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); pD3DDevice->SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE); pD3DDevice->SetStreamSource(0, NULL, 0); pD3DDevice->EndStateBlock(&HealthBarOldStateBlock); } if (!HealthBarNewStateBlock) { pD3DDevice->BeginStateBlock(); pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); pD3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); pD3DDevice->SetRenderState(D3DRS_ZENABLE, 1); pD3DDevice->SetRenderState(D3DRS_FILLMODE, 3); pD3DDevice->SetRenderState(D3DRS_CULLMODE, 1); pD3DDevice->SetRenderState(D3DRS_WRAP0, 0); pD3DDevice->SetRenderState(D3DRS_CLIPPING, 1); pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, 0); pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 1); pD3DDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, 0); pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 15); pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1); pD3DDevice->SetRenderState(D3DRS_SRCBLEND, 5); pD3DDevice->SetRenderState(D3DRS_DESTBLEND, 6); pD3DDevice->SetRenderState(D3DRS_BLENDOP, 1); pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4); pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2); pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 1); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0); pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0); pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1); pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, 1); pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); pD3DDevice->SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE); pD3DDevice->EndStateBlock(&HealthBarNewStateBlock); } pD3DDevice->CaptureStateBlock(HealthBarOldStateBlock); pD3DDevice->ApplyStateBlock(HealthBarNewStateBlock); D3DXMATRIX matTransposed; D3DXMatrixTranspose(&matTransposed, (D3DXMATRIX*)&matView); matTransposed._14 = matTransposed._24 = matTransposed._34 = 0.0f; if(pNetGame) { CPlayerPool* pPlayerPool = pNetGame->GetPlayerPool(); for(int x=0; x < MAX_PLAYERS; x++) { if(pPlayerPool->GetSlotState(x) == TRUE) // player is in use { CRemotePlayer* Player = pPlayerPool->GetAt(x); if( Player->IsActive() && (Player->GetDistanceFromLocalPlayer() <= 80.0f) ) // Active and within reasonable distance { CPlayerPed* PlayerPed = Player->GetPlayerPed(); if(PlayerPed->IsOnScreen()) { // They're onscreen MATRIX4X4 matPlayer; PlayerPed->GetMatrix(&matPlayer); matTransposed._41 = matPlayer.vPos.X; matTransposed._42 = matPlayer.vPos.Y; matTransposed._43 = matPlayer.vPos.Z + 1.0f; pD3DDevice->SetTransform(D3DTS_WORLD, &matTransposed); float Health = Player->GetReportedHealth(); if (Health > 100.0f) Health = 100.0f; HealthBarBGVertices[0].x = HealthBarBGVertices[1].x = (0.0058f * Health) - 0.29f; pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, HealthBarBDRVertices, sizeof(HealthBarVertices_s)); pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, HealthBarVertices, sizeof(HealthBarVertices_s)); pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, HealthBarBGVertices, sizeof(HealthBarVertices_s)); if(bbfont) { bbfont->Begin(); //bbfont->Draw(pPlayerPool->GetPlayerName(x), 0.285f, 0xFF000000); bbfont->Draw(pPlayerPool->GetPlayerName(x), 0.300f, Player->GetTeamColorAsARGB()); bbfont->End(); } } } } } } pD3DDevice->ApplyStateBlock(HealthBarOldStateBlock); // END: HEALTH BAR AND PLAYER NAME STUFF } if(!pGame->IsMenuActive()) { if((pNetGame) && GetAsyncKeyState(VK_F5)) { pGame->DisplayHud(FALSE); pScoreBoard->Draw(); } else if((pNetGame) && GetAsyncKeyState(VK_F6)) { pGame->DisplayHud(FALSE); pNetStats->Draw(); } else { pGame->DisplayHud(TRUE); if(pChatWindow) pChatWindow->Draw(); if(pCmdWindow) pCmdWindow->Draw(); } } }