/** Displays all the console messages */ void displayConsoleMessages(void) { // Check if we have any messages we want to show if (!getNumberConsoleMessages() && !bConsoleDropped && !InfoMessages.size()) { return; } // scripts can disable the console if (!bConsoleDisplayEnabled && !InfoMessages.size()) { return; } iV_SetFont(font_regular); pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); pie_SetFogStatus(false); if (bConsoleDropped) { displayOldMessages(HistoryMode); } std::lock_guard<wz::mutex> lck(mtx); // Don't iterate without a lock. if (InfoMessages.size()) { auto i = InfoMessages.end() - 1; // we can only show the last one... setConsoleTextColor(i->player); int tmp = pie_GetVideoBufferWidth(); drawBlueBox(0, 0,tmp, 18); tmp -= iV_GetTextWidth(i->text.c_str()); iV_DrawFormattedText(i->text.c_str(), tmp - 6, linePitch - 2, iV_GetTextWidth(i->text.c_str()), i->JustifyType); } int TextYpos = mainConsole.topY; // Draw the blue background for the text (only in game, not lobby) if (bTextBoxActive && GetGameMode() == GS_NORMAL) { iV_TransBoxFill(mainConsole.topX - CON_BORDER_WIDTH, mainConsole.topY - mainConsole.textDepth - CON_BORDER_HEIGHT, mainConsole.topX + mainConsole.width, mainConsole.topY + (getNumberConsoleMessages() * linePitch) + CON_BORDER_HEIGHT - linePitch); } for (auto i = ActiveMessages.begin(); i != ActiveMessages.end(); ++i) { setConsoleTextColor(i->player); TextYpos = iV_DrawFormattedText(i->text.c_str(), mainConsole.topX, TextYpos, mainConsole.width, i->JustifyType); } }
/** Remove the top message on screen. This and setConsoleMessageDuration should be sufficient to allow us to put up messages that stay there until we remove them ourselves - be sure and reset message duration afterwards */ void removeTopConsoleMessage(void) { if (getNumberConsoleMessages()) { ActiveMessages.pop_front(); } }
/** Update the console messages. This function will remove messages that are overdue. */ void updateConsoleMessages(void) { // If there are no messages or we're on permanent (usually for scripts) then exit if ((!getNumberConsoleMessages() && !InfoMessages.size()) || mainConsole.permanent) { return; } for (auto i = InfoMessages.begin(); i != InfoMessages.end();) { if (realTime - i->timeAdded > messageDuration) { i = InfoMessages.erase(i); } else { ++i; } } // Time to kill all expired ones for (auto i = ActiveMessages.begin(); i != ActiveMessages.end();) { if (realTime - i->timeAdded > messageDuration) { i = ActiveMessages.erase(i); } else { ++i; } } }
/** Check if mouse is over the Active console 'window' area */ bool mouseOverConsoleBox(void) { int gotMessages = getNumberConsoleMessages(); if (gotMessages && ((UDWORD)mouseX() > mainConsole.topX) && ((UDWORD)mouseY() > mainConsole.topY) && ((UDWORD)mouseX() < mainConsole.topX + mainConsole.width) && ((UDWORD)mouseY() < (mainConsole.topY + 4 + linePitch * gotMessages))) { return true; } return false; }