![]() |
PRooFPS-dd Dev Doc 1.0
PRooFPS-dd Developer Documentation
|
#include <GUI.h>
Public Types | |
| enum class | MainMenuState { None , Main , CreateGame , JoinGame , Settings , About , Exiting } |
| enum class | InGameMenuState { None , Welcome_TeamSelect_Spectator , ServerAdmin } |
| enum class | GameInfoPage { None , FragTable , AllPlayersDebugDataServer , ServerConfig , COUNT } |
| As of v0.5, values are looped by pressing TAB in-game. More... | |
| using | ServerRestartGameCallback = std::function<void()> |
Public Member Functions | |
| void | initialize () |
| void | shutdown () |
| const MainMenuState & | getMainMenuState () const |
| const InGameMenuState & | getInGameMenuState () const |
| void | resetMenuStates (bool bExitingFromGameSession) |
| Primarily for main menu control, but shall reset any other menu as well. | |
| XHair * | getXHair () |
| Minimap * | getMinimap () |
| DeathKillEventLister * | getDeathKillEvents () |
| EventLister * | getItemPickupEvents () |
| EventLister * | getPlayerInventoryChangeEvents () |
| EventLister * | getPlayerHpChangeEvents () |
| EventLister * | getPlayerApChangeEvents () |
| EventLister * | getPlayerAmmoChangeEvents () |
| ServerEventLister * | getServerEvents () |
| void | showRespawnTimer (const Player *const pKillerPlayer) |
| void | hideRespawnTimer () |
| void | fastForwardRespawnTimer (std::chrono::milliseconds::rep byMillisecs) |
| void | updateNonDearImGuiElements () |
| PureObject3dInOutSlider & | getSlidingProof88Laugh () |
Static Public Member Functions | |
| static GUI & | getGuiInstance (PGE &pge, proofps_dd::CameraHandling &camera, proofps_dd::Config &config, proofps_dd::Maps &maps, proofps_dd::Networking &networking, std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers, const PgeObjectPool< proofps_dd::Smoke > &smokes) |
| Gets the singleton instance. | |
| static const char * | getLoggerModuleName () |
| static CConsole & | getConsole () |
| static ImVec4 | getImVec4fromPureColor (const PureColor &pureColor) |
| static void | setServerSoftRestartGameCallback (ServerRestartGameCallback cb) |
| static void | setServerHardRestartGameCallback (ServerRestartGameCallback cb) |
| static void | hideInGameMenu () |
| static void | showHideInGameTeamSelectMenu () |
| static void | showInGameTeamSelectMenu () |
| static void | showMandatoryGameModeConfigMenu () |
| static void | showMandatoryGameModeConfigMenuOnlyIfGameModeIsNotYetConfiguredForCurrentPlayer () |
| static void | showHideInGameServerAdminMenu () |
| static void | showLoadingScreen (int nProgress, const std::string &sMapFilename) |
| static void | hideLoadingScreen () |
| static bool | isLoadingScreenVisible () |
| static bool | showBgWithLogo () |
| static bool | hideBgWithLogo () |
| static void | showGameObjectives () |
| static void | hideGameObjectives () |
| static void | showAndLoopGameInfoPages () |
| static void | textForNextFrame (const std::string &s, int nPureX, int nPureY) |
| static void | textPermanent (const std::string &s, int nPureX, int nPureY) |
Static Public Attributes | |
| static constexpr char * | CVAR_GUI_MAINMENU = "gui_mainmenu" |
Private Types | |
| typedef std::function< void(const proofps_dd::PlayersTableRow &player, const std::vector< const char * > &vecHeaderLabels, const int &iColNetworkDataStart)> | CbColumnLoopForPlayerFunc |
| See explanation at GUI::drawPlayersTable(). | |
| typedef std::function< bool(const proofps_dd::PlayersTableRow &player)> | CbIsPlayerValidForCurrentRowFunc |
| See explanation at GUI::drawPlayersTable(). | |
Private Member Functions | |
| GUI () | |
| ~GUI () | |
| GUI (const GUI &)=delete | |
| GUI & | operator= (const GUI &)=delete |
| GUI (GUI &&)=delete | |
| GUI && | operator= (GUI &&)=delete |
Static Private Member Functions | |
| static void | addHintToItemByCVar (std::string &sHint, const PGEcfgVariable &cvar) |
| static float | calcContentStartY (const float &fContentHeight, const float &fRemainingSpaceY) |
| static void | drawMainMenu (const float &fRemainingSpaceY) |
| static float | drawPlayerNameInputBox () |
| static void | drawCreateGameServerMapSelection () |
| static void | drawTabCreateGameServerSettings () |
| static void | drawTabCreateGameServerTweaks () |
| static void | drawCreateGameMenu (const float &fRemainingSpaceY) |
| static void | drawJoinGameMenu (const float &fRemainingSpaceY) |
| static void | drawTabWeaponSettings () |
| static void | drawTabMiscSettings () |
| static void | showConfigApplyAndRestartDialogBox (PGEcfgVariable &cvar, const std::string &sPopupId) |
| static void | drawSettingsMenu (const float &fRemainingSpaceY) |
| static void | drawAboutMenu (const float &fRemainingSpaceY) |
| static void | drawWindowForMainMenu () |
| static void | drawRespawnTimer () |
| static void | drawXHairHoverText () |
| static void | drawXHairAboveText () |
| static void | updateXHair () |
| static void | drawCurrentPlayerInfo (const proofps_dd::Player &player) |
| static void | updateDeathKillEvents () |
| static void | updateItemPickupEvents () |
| static void | updatePlayerHpChangeEvents () |
| static void | updatePlayerApChangeEvents () |
| static void | updatePlayerAmmoChangeEvents () |
| static void | updatePlayerInventoryChangeEvents () |
| static void | updateServerEvents () |
| static void | calculatePlayerNameColWidthAndTableWidthPixels (float &fTableWidthPixels, float &fPlayerNameColWidthPixels, float fPlayerNameColReqWidthPixels, const float &fTableColIndentPixels, const float &fColsTotalWidthAfterPlayerNameCol) |
| static void | calculatePlayersTableGeometry (const std::vector< const char * > &vecHeaderLabels, const float &fTableColIndentPixels, std::vector< float > &vecColumnWidthsPixels, float &fTableStartPosX, float &fTableWidthPixels, float &fPlayerNameColWidthPixels, float &fTableHeightPixels) |
| Can be used in general to calculate several properties of a table for showing player data. | |
| static void | drawFragTable_columnLoopForPlayer (const proofps_dd::PlayersTableRow &player, const std::vector< const char * > &vecHeaderLabels, const int &iColNetworkDataStart) |
| Draws a row for the given player in the frag table. | |
| static void | drawTableCaption (const std::string &sTableCaption, const float &fStartPosY, const float &fTableStartPosX, const float &fTableWidthPixels) |
| Can be used in general to print a caption above a table, before starting to draw the table. | |
| static void | drawTableCaptionColored (const std::string &sTableCaption, const float &fStartPosY, const float &fTableStartPosX, const float &fTableWidthPixels, const ImVec4 &color) |
| Same as drawTableCaptionColored() but with extra color argument for setting text foreground color. | |
| static void | drawPlayersTable (const std::vector< const char * > &vecHeaderLabels, const float &fTableColIndentPixels, const std::vector< float > &vecColumnWidthsPixels, const float &fTableStartPosX, const float &fTableWidthPixels, const float &fPlayerNameColWidthPixels, const float &fTableHeightPixels, const int &iColNetworkDataStart, CbIsPlayerValidForCurrentRowFunc cbIsPlayerValidForCurrentRowFunc, CbColumnLoopForPlayerFunc cbColumnLoopForPlayerFunc) |
| Can be used in general to draw a players table with the specified geometry and content. | |
| static void | drawFragTable (const std::string &sCaption, const float &fStartPosY, const std::vector< const char * > &vecHeaderLabels, const int &iColNetworkDataStart) |
| Draws frag table(s) where player stats such as frags are visible. | |
| static void | drawGameObjectivesServer (const std::string &sCaption, const float &fStartPosY) |
| Server-only logic to be called for GameInfoPage::FragTable is selected by user (by TAB key as of v0.5). | |
| static void | drawGameObjectivesClient (const std::string &sCaption, const float &fStartPosY) |
| Client-only logic to be called for GameInfoPage::FragTable is selected by user (by TAB key as of v0.5). | |
| static void | drawAllPlayersDebugDataTableServer_columnLoopForPlayer (const proofps_dd::PlayersTableRow &player, const std::vector< const char * > &vecHeaderLabels, const int &iColNetworkDataStart) |
| Draws a row for the given player in the players network debug data table. | |
| static void | drawAllPlayersDebugDataServer (const int &nYPosBiasToMinimapBottom) |
| Main logic to be called for GameInfoPage::AllPlayersDebugDataServer is selected by user (by TAB key as of v0.5). | |
| static void | drawGameObjectives (const int &nYPosBiasToMinimapBottom) |
| Main logic to be called for GameInfoPage::FragTable is selected by user (by TAB key as of v0.5). | |
| static float | drawClientConnectionDebugInfo (float fThisRowY) |
| static void | drawGameServerConfig (const int &nYPosBiasToMinimapBottom) |
| Main logic to be called for GameInfoPage::ServerConfig is selected by user (by TAB key as of v0.5). | |
| static void | drawGameInfoPages () |
| static void | drawSpectatorMode (const proofps_dd::Player &player) |
| static void | handleEnterSpectatorMode (const proofps_dd::Player &player) |
| static void | handleExitSpectatorMode (const proofps_dd::Player &player) |
| static void | handleSpectatorMode (const proofps_dd::Player &player) |
| static void | drawInGameWelcomeTeamSelectSpectatorMenu (const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player >::iterator &itCurrentPlayer) |
| static void | drawInGameServerAdminMenu () |
| static void | drawInGameMenu (const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player >::iterator &itCurrentPlayer) |
| static float | getDearImGui2DposXFromPure2DposX (const float &fPureX) |
| Converts the given X position specified in PURE 2D coordinate system to an X position in ImGui's 2D coordinate system. | |
| static float | getDearImGui2DposYFromPure2DposY (const float &fPureY) |
| Converts the given Y position specified in PURE 2D coordinate system to an Y position in ImGui's 2D coordinate system. | |
| static float | getDearImGui2DposXforCenteredText (const std::string &text, const float &fImGuiX) |
| Returns a Dear ImGui X-coordinate where the cursor should be placed for printing the given text to make it appear centered. | |
| static float | getDearImGui2DposXforRightAdjustedText (const std::string &text, const float &fImGuiX) |
| Returns a Dear ImGui X-coordinate where the cursor should be placed for printing the given text to make it appear right-adjusted. | |
| static float | getDearImGui2DposXforTableCurrentCellCenteredText (const std::string &text) |
| static float | getDearImGui2DposXforTableCurrentCellRightAdjustedText (const std::string &text) |
| static float | getDearImGui2DposXforWindowCenteredText (const std::string &text) |
| static void | drawText (const float &fImGuiX, const float &fImGuiY, const std::string &text) |
| static void | drawTextShadowed (const float &fImGuiX, const float &fImGuiY, const std::string &text) |
| static void | drawTextHighlighted (const float &fImGuiX, const float &fImGuiY, const std::string &text) |
| Draws a text with a filled background rectangle behind it. | |
| static void | ImGuiTextTableCurrentCellShortenedFit (const std::string &text, size_t nAppendLastNChars=0) |
| Renders the given text in the current cell, with automatic shortening if cell width is not enough for the whole text. | |
| static void | ImGuiTextTableCurrentCellCentered (const std::string &text) |
| static void | ImGuiTextTableCurrentCellRightAdjusted (const std::string &text) |
| static void | drawDearImGuiCb () |
| Primary GUI draw function called back by PURE. | |
|
private |
See explanation at GUI::drawPlayersTable().
|
private |
See explanation at GUI::drawPlayersTable().
| using proofps_dd::GUI::ServerRestartGameCallback = std::function<void()> |
|
strong |
|
strong |
|
strong |
|
privatedelete |
|
privatedelete |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Can be used in general to calculate several properties of a table for showing player data.
After calling this function, the table can be drawn using the calculated outgoing parameters.
The width of the first column will be dynamically selected based on the length of all player names in GameMode::getPlayersTable(). This is because we always put player names in the first column of such table. Still it can happen that we need to truncate a player name, so we always keep enough horizontal space for the other columns. The width of the other columns is determined by the required width of the column labels, not by the player data in those columns.
| vecHeaderLabels | Column header labels. Size of this vector tells the number of columns in the table. |
| fTableColIndentPixels | The indentation within cells, in pixels. Requires the ImGuiTableColumnFlags_IndentEnable table flag. |
| vecColumnWidthsPixels | Out argument: for all columns, the calculated width in pixels will be placed here by the function. Shall be empty when passing in to the function. |
| fTableStartPosX | Out argument: horizontal position of the left edge of the table will be placed here by the function, in Dear ImGui coordinate system. |
| fTableWidthPixels | Out argument: as the name says, the width of the table in pixels will be placed here by the function. |
| fPlayerNameColWidthPixels | Out argument: the final calculated width of the first column, in pixels, will be placed here by the function. |
| fTableHeightPixels | Out argument: as the name says, the height of the table in pixels will be placed here by the function. For now it is fixed 80% of window height. |
|
staticprivate |
|
staticprivate |
Main logic to be called for GameInfoPage::AllPlayersDebugDataServer is selected by user (by TAB key as of v0.5).
Draws a table with all players' network debug data. Players are fetched from GameMode::getPlayersTable(). Server-side only.
Index of first column showing client network data (e.g.ping). As we don't show network data for the server player itself, we skip filling any column with column index equal to or greater than this index.
|
staticprivate |
Draws a row for the given player in the players network debug data table.
Signature must comply with CbColumnLoopForPlayerFunc.
Prerequisites:
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Primary GUI draw function called back by PURE.
PURE invokes this function every frame, AFTER rendering the 2D sticked-to-screen objects (PureObject3D::SetStickedToScreen()). Thus, calculations in this function having effect on the PURE sticked-to-screen objects, will be visible only in the next frame. So in general it is highly recommended to do ONLY Dear ImGui-specific stuff here.
If we want to update something every frame BEFORE rendering the same frame happens, I recommend doing that around PRooFPSddPGE::onGameRunning(). For example, in mainLoopConnectedShared() which is common code for server and clients.
|
staticprivate |
Draws frag table(s) where player stats such as frags are visible.
Might draw 1 or more tables depending on game mode type. Players are fetched from GameMode::getPlayersTable().
| sCaption | This separate text will be rendered above the frag table(s). |
| fStartPosY | Vertical 2D-position in Dear ImGui coordinate system where sTableCaption will be placed. The frag table is placed right below sTableCaption. |
| vecHeaderLabels | Column header labels. Size of this vector tells the number of columns in the table. |
| iColNetworkDataStart | Index of first column showing client network data (e.g. ping). Used only by server instance, ignored by client instances. Compared to client instances, the server instance shows additional column(s) in the frag table. These extra columns are for showing client network data. However, we don't show such for the server player itself, so the extra columns stay empty for the server player. |
|
staticprivate |
Draws a row for the given player in the frag table.
Signature must comply with CbColumnLoopForPlayerFunc.
Prerequisites:
|
staticprivate |
Main logic to be called for GameInfoPage::FragTable is selected by user (by TAB key as of v0.5).
Draws frag table with caption showing optional game goal status (e.g. time left). Players are fetched from GameMode::getPlayersTable(). Server and client.
|
staticprivate |
Client-only logic to be called for GameInfoPage::FragTable is selected by user (by TAB key as of v0.5).
Draws frag table with caption showing optional game goal status (e.g. time left). Players are fetched from GameMode::getPlayersTable().
|
staticprivate |
Server-only logic to be called for GameInfoPage::FragTable is selected by user (by TAB key as of v0.5).
Draws frag table with caption showing optional game goal status (e.g. time left). Players are fetched from GameMode::getPlayersTable().
|
staticprivate |
Main logic to be called for GameInfoPage::ServerConfig is selected by user (by TAB key as of v0.5).
Shows server configuration relevant for both client and server.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Can be used in general to draw a players table with the specified geometry and content.
First column always contains player names, therefore it has dynamic width based on the length of all player names. Players are fetched using GameMode::getPlayersTable().
RFR: a more abstract table drawing function could be made with slight modification: pass the rows also to this function (e.g. GameMode::getPlayersTable()) and then it could be used for anything else than players.
For some of the arguments, you can use calculatePlayersTableGeometry() for determining them before calling this function.
TODO: str_id in BeginTable() might needs to be unique for each call! Investigate!
| vecHeaderLabels | Column header labels. Size of this vector tells the number of columns in the table. |
| fTableColIndentPixels | The indentation within cells, in pixels. |
| vecColumnWidthsPixels | For all columns, the required width in pixels. |
| fTableStartPosX | Horizontal position of the left edge of the table, in Dear ImGui coordinate system. |
| fTableWidthPixels | As the name says, the width of the table in pixels. |
| fPlayerNameColWidthPixels | The width of the first column, in pixels. |
| fTableHeightPixels | As the name says, the height of the table in pixels. For now it is not used, height is automatically determined by Dear ImGui! I need this behavior so I dont need to calculate height by myself. This auto behavior is comfy so I can put multiple tables under each other without manually calculating their heights. |
| iColNetworkDataStart | Index of first column showing client network data (e.g. ping). Used only by server instance, ignored by client instances. See real use-case example in drawFragTable(). |
| cbIsPlayerValidForCurrentRowFunc | Function that decides if current player belongs to this table/row, or not. For example, if you want to display players within a specific team only, you can pass such a function that checks player's team ID and returns true or false. |
| cbColumnLoopForPlayerFunc | Function that fills in the row cells with data for the current player. It is called back in loop by this function for each player (row). This player shall iterate and fill columns within the current row using ImGui::TableSetColumnIndex() or ImGui::TableNextColumn(). |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Can be used in general to print a caption above a table, before starting to draw the table.
| sTableCaption | Text to be used as caption above the table. |
| fStartPosY | Vertical 2D-position in Dear ImGui coordinate system where the caption will be placed. |
| fTableStartPosX | Horizontal position of the left edge of the table, in Dear ImGui coordinate system. |
| fTableWidthPixels | As the name says. Together with fTableStartPosX they are used to decide if the text will also placed horizontally to fTableStartPosX, or more to the left in case of too long caption relative to screen size. |
|
staticprivate |
Same as drawTableCaptionColored() but with extra color argument for setting text foreground color.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Draws a text with a filled background rectangle behind it.
Background rectangle color is the current ImGui::GetStyle().Colors[ImGuiCol_TableHeaderBg].
Note: the drawn rectangle will be 1 px taller to the south, so if you manually position such texts close to each other vertically, it is recommended to add 1 px height when calculating the Y pos of the next row where you reposition the ImGui cursor.
|
staticprivate |
|
staticprivate |
| void proofps_dd::GUI::fastForwardRespawnTimer | ( | std::chrono::milliseconds::rep | byMillisecs | ) |
|
staticprivate |
Returns a Dear ImGui X-coordinate where the cursor should be placed for printing the given text to make it appear centered.
| text | The text to be centered. |
| fImGuiX | Dear ImGui X-coordinate where the center of the text should be. |
|
staticprivate |
Returns a Dear ImGui X-coordinate where the cursor should be placed for printing the given text to make it appear right-adjusted.
| text | The text to be right-adjusted. |
| fImGuiX | Dear ImGui X-coordinate where the center of the text should be. |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Converts the given X position specified in PURE 2D coordinate system to an X position in ImGui's 2D coordinate system.
Dear ImGui coordinates are the same as OS desktop/native coordinates which means that operating with ImGui::GetMainViewport() is different than operating with getPure().getCamera().getViewport():
| fPureX | The input X position in PURE 2D coordinate system. |
|
staticprivate |
Converts the given Y position specified in PURE 2D coordinate system to an Y position in ImGui's 2D coordinate system.
Dear ImGui coordinates are the same as OS desktop/native coordinates which means that operating with ImGui::GetMainViewport() is different than operating with getPure().getCamera().getViewport():
| fPureY | The input Y position in PURE 2D coordinate system. |
| proofps_dd::DeathKillEventLister * proofps_dd::GUI::getDeathKillEvents | ( | ) |
|
static |
|
static |
| const proofps_dd::GUI::InGameMenuState & proofps_dd::GUI::getInGameMenuState | ( | ) | const |
| proofps_dd::EventLister * proofps_dd::GUI::getItemPickupEvents | ( | ) |
| const proofps_dd::GUI::MainMenuState & proofps_dd::GUI::getMainMenuState | ( | ) | const |
| proofps_dd::Minimap * proofps_dd::GUI::getMinimap | ( | ) |
| proofps_dd::EventLister * proofps_dd::GUI::getPlayerAmmoChangeEvents | ( | ) |
| proofps_dd::EventLister * proofps_dd::GUI::getPlayerApChangeEvents | ( | ) |
| proofps_dd::EventLister * proofps_dd::GUI::getPlayerHpChangeEvents | ( | ) |
| proofps_dd::EventLister * proofps_dd::GUI::getPlayerInventoryChangeEvents | ( | ) |
| proofps_dd::ServerEventLister * proofps_dd::GUI::getServerEvents | ( | ) |
| proofps_dd::PureObject3dInOutSlider & proofps_dd::GUI::getSlidingProof88Laugh | ( | ) |
| proofps_dd::XHair * proofps_dd::GUI::getXHair | ( | ) |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Renders the given text in the current cell, with automatic shortening if cell width is not enough for the whole text.
I dont know why Dear ImGui is not always automatically shortening too long text in cells with "..." so I made this function.
However, this function is very useful especially when shortening player names, since in case of colliding player names, server appends a 3-digit unique number to the end of each player name, and we can see those numbers even if name is too long, if we set nAppendLastNChars to 3, to be able to distinguish players with too long names!
| text | The text to be rendered in current cell. |
| nAppendLastNChars | How many last characters of 'text' should be rendered in the cell after "..." if we are shortening. |
| void proofps_dd::GUI::resetMenuStates | ( | bool | bExitingFromGameSession | ) |
Primarily for main menu control, but shall reset any other menu as well.
Typical use cases:
Behavior depends on CVAR_GUI_MAINMENU as well:
|
static |
|
static |
|
staticprivate |
|
static |
|
static |
|
static |
|
static |
|
static |
| void proofps_dd::GUI::showRespawnTimer | ( | const Player *const | pKillerPlayer | ) |
|
static |
|
static |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticconstexpr |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |