Push placement text notification queue
This commit is contained in:
parent
db0a39f64a
commit
df5b7960b2
@ -5,8 +5,6 @@
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
|
||||
|
||||
|
||||
// Define a structure to represent notifications
|
||||
struct Notification {
|
||||
std::string message;
|
||||
@ -97,6 +95,7 @@ void Engine::LoadResource() {
|
||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
||||
LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false);
|
||||
LoadTexture(m_textureStartMenu, TEXTURE_PATH "startmenu.png", false);
|
||||
|
||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||
@ -147,7 +146,6 @@ void Engine::KillNotification(Player killer, Player killed) {
|
||||
DisplayNotification(message);
|
||||
}
|
||||
|
||||
|
||||
void Engine::DisplayNotification(std::string message) {
|
||||
|
||||
if (message.length() > 45) {
|
||||
@ -163,17 +161,21 @@ void Engine::DisplayNotification(std::string message) {
|
||||
|
||||
// Add a method to process the notification queue
|
||||
void Engine::ProcessNotificationQueue() {
|
||||
//PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f);
|
||||
//float fPosX = (Width() / 100.0f) * scaleX;
|
||||
//float fPosY = Height() - (Height() * 0.05) * scaleY;
|
||||
|
||||
m_textureFont.Bind();
|
||||
|
||||
auto [scaleX, scaleY] = GetScale();
|
||||
|
||||
unsigned int xOffset = static_cast<unsigned int>((BASE_WIDTH - BASE_WIDTH * 0.26f) * scaleX);
|
||||
unsigned int yOffset = static_cast<unsigned int>((BASE_HEIGHT - (BASE_HEIGHT / 2.2f)) * scaleY);
|
||||
float xOffset = (Width() / 1.5f) * scaleX;
|
||||
float yOffset = (Height() / 1.2f) * scaleY;
|
||||
|
||||
for (auto it = notifications.begin(); it != notifications.end(); ) {
|
||||
float timeSinceDisplay = m_time - it->displayStartTime;
|
||||
|
||||
unsigned int y = yOffset - static_cast<unsigned int>(20.0f * scaleX * (it - notifications.begin()));
|
||||
float y = yOffset - (20.0f * scaleX * (it - notifications.begin()));
|
||||
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@ -212,21 +214,20 @@ void Engine::ProcessNotificationQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Engine::DisplayCrosshair() {
|
||||
m_textureCrosshair.Bind();
|
||||
static const int crossSize = 32;
|
||||
glLoadIdentity();
|
||||
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(crossSize, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(crossSize, crossSize);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, crossSize);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(crossSize, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(crossSize, crossSize);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, crossSize);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
@ -247,8 +248,8 @@ void Engine::DisplayPovGun() {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
float scaleX = static_cast<float>(Width()) / BASE_WIDTH;
|
||||
float scaleY = static_cast<float>(Height()) / BASE_HEIGHT;
|
||||
float scaleX = (Width()) / BASE_WIDTH;
|
||||
float scaleY = (Height()) / BASE_HEIGHT;
|
||||
float baseXOffset = 0.4958 * BASE_WIDTH;
|
||||
float baseWidth = 0.4688 * BASE_WIDTH;
|
||||
float baseHeight = 0.5787 * BASE_HEIGHT;
|
||||
@ -310,6 +311,33 @@ void Engine::DisplayHud(int timer) {
|
||||
glEnd();
|
||||
|
||||
|
||||
float centerX = Width() / 2.0f;
|
||||
float centerY = Height() / 2.0f;
|
||||
float quadWidth = 200.0f;
|
||||
float quadHeight = fBackHeight;
|
||||
|
||||
float thickness = quadHeight / 2.5;
|
||||
float xOffset = quadWidth * 2;
|
||||
float yOffset = quadWidth;
|
||||
|
||||
// Top Quad (unchanged)
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(centerX - quadWidth + xOffset, (centerY - thickness) + 1.5f * thickness - yOffset); // Bottom-left
|
||||
glVertex2f(centerX + quadWidth + xOffset, (centerY - thickness) + 1.5f * thickness - yOffset); // Bottom-right
|
||||
glVertex2f(centerX + quadWidth + xOffset, (centerY - thickness) + 2.5f * thickness - yOffset); // Top-right
|
||||
glVertex2f(centerX - quadWidth + xOffset, (centerY - thickness) + 2.5f * thickness - yOffset); // Top-left
|
||||
glEnd();
|
||||
|
||||
// Adjusted Bottom Quad (moved down by an additional thickness)
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(centerX - quadWidth + xOffset, centerY - 1.5f * thickness - yOffset); // Bottom-left
|
||||
glVertex2f(centerX + quadWidth + xOffset, centerY - 1.5f * thickness - yOffset); // Bottom-right
|
||||
glVertex2f(centerX + quadWidth + xOffset, centerY - 0.5f * thickness - yOffset); // Top-right
|
||||
glVertex2f(centerX - quadWidth + xOffset, centerY - 0.5f * thickness - yOffset); // Top-left
|
||||
glEnd();
|
||||
|
||||
// HP Bar
|
||||
float fBarWidth = (Width() / 4.0f) * scaleX;
|
||||
float fBarHeight = (Height() / 25.0f) * scaleY;
|
||||
@ -404,7 +432,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
ss.str("");
|
||||
fPosY -= charSize;
|
||||
|
||||
float fPosYJump = static_cast<unsigned int>((Height() - (Height() * 0.9f)) * scaleY);
|
||||
float fPosYJump = ((Height() - (Height() * 0.9f)) * scaleY);
|
||||
fPosY = fPosYJump;
|
||||
fPosY -= charSize;
|
||||
|
||||
@ -431,6 +459,50 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
PrintText(fPosX, fPosYJump, ss.str());
|
||||
}
|
||||
|
||||
void Engine::DisplaySingleOrMultiplayerMenu() {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
// Create a low opacity white background with border radius
|
||||
float fBackPosX = 0.0f;
|
||||
float fBackPosY = 0.0f;
|
||||
float fBackWidth = (Width() / 4.0f);
|
||||
float fBackHeight = (Height() / 5.5f);
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fBackPosX, fBackPosY);
|
||||
glVertex2f(fBackPosX + fBackWidth, fBackPosY);
|
||||
glVertex2f(fBackPosX + fBackWidth, fBackPosY + fBackHeight);
|
||||
glVertex2f(fBackPosX, fBackPosY + fBackHeight);
|
||||
glEnd();
|
||||
|
||||
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
||||
// Setter le blend function, tout ce qui sera noir sera transparent
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
@ -526,7 +598,7 @@ int Engine::GetCountdown(float elapsedTime) {
|
||||
}
|
||||
if (m_countdown < m_time)
|
||||
Stop();
|
||||
if(!m_stopcountdown)
|
||||
if (!m_stopcountdown)
|
||||
m_time += elapsedTime;
|
||||
return m_countdown - (int)m_time;
|
||||
}
|
||||
@ -626,9 +698,9 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
ProcessNotificationQueue();
|
||||
DrawHud(elapsedTime, bloc);
|
||||
DisplayPovGun();
|
||||
ProcessNotificationQueue();
|
||||
|
||||
static bool fell = false;
|
||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
||||
|
@ -52,6 +52,7 @@ private:
|
||||
void DisplayCurrentItem();
|
||||
void DisplayHud(int timer);
|
||||
void DisplayInfo(float elapsedTime, BlockType bloc);
|
||||
void DisplaySingleOrMultiplayerMenu();
|
||||
void DrawHud(float elapsedTime, BlockType bloc);
|
||||
void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
|
||||
|
||||
@ -63,11 +64,12 @@ private:
|
||||
World m_world = World();
|
||||
WorldRenderer m_wrenderer = WorldRenderer();
|
||||
|
||||
Texture m_textureSkybox;
|
||||
Texture m_textureFont;
|
||||
Texture m_textureCrosshair;
|
||||
Texture m_textureFont;
|
||||
Texture m_textureGun;
|
||||
Texture m_texturePovGun;
|
||||
Texture m_textureSkybox;
|
||||
Texture m_textureStartMenu;
|
||||
|
||||
Skybox m_skybox;
|
||||
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
||||
|
BIN
SQCSim2021/media/textures/StartMenu.png
Normal file
BIN
SQCSim2021/media/textures/StartMenu.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
SQCSim2021/media/textures/Titre.png
Normal file
BIN
SQCSim2021/media/textures/Titre.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
Loading…
x
Reference in New Issue
Block a user