| 1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
| 2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
| 3 | #ifndef GAME_CLIENT_COMPONENTS_HUD_H |
| 4 | #define GAME_CLIENT_COMPONENTS_HUD_H |
| 5 | #include <engine/client.h> |
| 6 | #include <engine/shared/protocol.h> |
| 7 | #include <engine/textrender.h> |
| 8 | |
| 9 | #include <generated/protocol.h> |
| 10 | |
| 11 | #include <game/client/component.h> |
| 12 | |
| 13 | struct SScoreInfo |
| 14 | { |
| 15 | SScoreInfo() |
| 16 | { |
| 17 | Reset(); |
| 18 | } |
| 19 | |
| 20 | void Reset() |
| 21 | { |
| 22 | m_TextRankContainerIndex.Reset(); |
| 23 | m_TextScoreContainerIndex.Reset(); |
| 24 | m_RoundRectQuadContainerIndex = -1; |
| 25 | m_OptionalNameTextContainerIndex.Reset(); |
| 26 | m_aScoreText[0] = 0; |
| 27 | m_aRankText[0] = 0; |
| 28 | m_aPlayerNameText[0] = 0; |
| 29 | m_ScoreTextWidth = 0.f; |
| 30 | m_Initialized = false; |
| 31 | } |
| 32 | |
| 33 | STextContainerIndex ; |
| 34 | STextContainerIndex m_TextScoreContainerIndex; |
| 35 | float m_ScoreTextWidth; |
| 36 | char m_aScoreText[16]; |
| 37 | char m_aRankText[16]; |
| 38 | char m_aPlayerNameText[MAX_NAME_LENGTH]; |
| 39 | int m_RoundRectQuadContainerIndex; |
| 40 | STextContainerIndex m_OptionalNameTextContainerIndex; |
| 41 | |
| 42 | bool m_Initialized; |
| 43 | }; |
| 44 | |
| 45 | class CHud : public CComponent |
| 46 | { |
| 47 | float m_Width, m_Height; |
| 48 | |
| 49 | int m_HudQuadContainerIndex; |
| 50 | SScoreInfo m_aScoreInfo[2]; |
| 51 | STextContainerIndex m_FPSTextContainerIndex; |
| 52 | STextContainerIndex m_DDRaceEffectsTextContainerIndex; |
| 53 | STextContainerIndex m_PlayerAngleTextContainerIndex; |
| 54 | float m_PlayerPrevAngle; |
| 55 | STextContainerIndex m_aPlayerSpeedTextContainers[2]; |
| 56 | float m_aPlayerPrevSpeed[2]; |
| 57 | int m_aPlayerSpeed[2]; |
| 58 | enum class ESpeedChange |
| 59 | { |
| 60 | NONE, |
| 61 | INCREASE, |
| 62 | DECREASE |
| 63 | }; |
| 64 | ESpeedChange m_aLastPlayerSpeedChange[2]; |
| 65 | STextContainerIndex m_aPlayerPositionContainers[2]; |
| 66 | float m_aPlayerPrevPosition[2]; |
| 67 | |
| 68 | void RenderCursor(); |
| 69 | |
| 70 | void RenderTextInfo(); |
| 71 | void RenderConnectionWarning(); |
| 72 | void RenderTeambalanceWarning(); |
| 73 | |
| 74 | void PrepareAmmoHealthAndArmorQuads(); |
| 75 | void RenderAmmoHealthAndArmor(const CNetObj_Character *pCharacter); |
| 76 | |
| 77 | void PreparePlayerStateQuads(); |
| 78 | void RenderPlayerState(int ClientId); |
| 79 | |
| 80 | int m_LastSpectatorCountTick; |
| 81 | void RenderSpectatorCount(); |
| 82 | void RenderDummyActions(); |
| 83 | void RenderMovementInformation(); |
| 84 | |
| 85 | void UpdateMovementInformationTextContainer(STextContainerIndex &TextContainer, float FontSize, float Value, float &PrevValue); |
| 86 | void RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, const ColorRGBA &Color, float X, float Y); |
| 87 | |
| 88 | class CMovementInformation |
| 89 | { |
| 90 | public: |
| 91 | vec2 m_Pos; |
| 92 | vec2 m_Speed; |
| 93 | float m_Angle = 0.0f; |
| 94 | }; |
| 95 | class CMovementInformation GetMovementInformation(int ClientId, int Conn) const; |
| 96 | |
| 97 | void RenderGameTimer(); |
| 98 | void RenderPauseNotification(); |
| 99 | void RenderSuddenDeath(); |
| 100 | |
| 101 | void RenderScoreHud(); |
| 102 | int m_LastLocalClientId = -1; |
| 103 | |
| 104 | void RenderSpectatorHud(); |
| 105 | void RenderWarmupTimer(); |
| 106 | void RenderLocalTime(float x); |
| 107 | |
| 108 | static constexpr float MOVEMENT_INFORMATION_LINE_HEIGHT = 8.0f; |
| 109 | |
| 110 | public: |
| 111 | CHud(); |
| 112 | int Sizeof() const override { return sizeof(*this); } |
| 113 | |
| 114 | void ResetHudContainers(); |
| 115 | void OnWindowResize() override; |
| 116 | void OnReset() override; |
| 117 | void OnRender() override; |
| 118 | void OnInit() override; |
| 119 | void OnNewSnapshot() override; |
| 120 | |
| 121 | // DDRace |
| 122 | |
| 123 | void OnMessage(int MsgType, void *pRawMsg) override; |
| 124 | void RenderNinjaBarPos(float x, float y, float Width, float Height, float Progress, float Alpha = 1.0f); |
| 125 | |
| 126 | private: |
| 127 | void RenderRecord(); |
| 128 | void RenderDDRaceEffects(); |
| 129 | float m_TimeCpDiff; |
| 130 | float m_ServerRecord; |
| 131 | float m_aPlayerRecord[NUM_DUMMIES]; |
| 132 | float m_FinishTimeDiff; |
| 133 | int m_DDRaceTime; |
| 134 | int m_FinishTimeLastReceivedTick; |
| 135 | int m_TimeCpLastReceivedTick; |
| 136 | bool m_ShowFinishTime; |
| 137 | |
| 138 | inline float GetMovementInformationBoxHeight(); |
| 139 | inline int GetDigitsIndex(int Value, int Max); |
| 140 | |
| 141 | // Quad Offsets |
| 142 | int m_aAmmoOffset[NUM_WEAPONS]; |
| 143 | int m_HealthOffset; |
| 144 | int m_EmptyHealthOffset; |
| 145 | int m_ArmorOffset; |
| 146 | int m_EmptyArmorOffset; |
| 147 | int m_aCursorOffset[NUM_WEAPONS]; |
| 148 | int m_FlagOffset; |
| 149 | int m_AirjumpOffset; |
| 150 | int m_AirjumpEmptyOffset; |
| 151 | int m_aWeaponOffset[NUM_WEAPONS]; |
| 152 | int m_EndlessJumpOffset; |
| 153 | int m_EndlessHookOffset; |
| 154 | int m_JetpackOffset; |
| 155 | int m_TeleportGrenadeOffset; |
| 156 | int m_TeleportGunOffset; |
| 157 | int m_TeleportLaserOffset; |
| 158 | int m_SoloOffset; |
| 159 | int m_CollisionDisabledOffset; |
| 160 | int m_HookHitDisabledOffset; |
| 161 | int m_HammerHitDisabledOffset; |
| 162 | int m_GunHitDisabledOffset; |
| 163 | int m_ShotgunHitDisabledOffset; |
| 164 | int m_GrenadeHitDisabledOffset; |
| 165 | int m_LaserHitDisabledOffset; |
| 166 | int m_DeepFrozenOffset; |
| 167 | int m_LiveFrozenOffset; |
| 168 | int m_DummyHammerOffset; |
| 169 | int m_DummyCopyOffset; |
| 170 | int m_PracticeModeOffset; |
| 171 | int m_Team0ModeOffset; |
| 172 | int m_LockModeOffset; |
| 173 | }; |
| 174 | |
| 175 | #endif |
| 176 | |