mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
add window resize event, and fix some ui things
This commit is contained in:
parent
16894155e5
commit
2cbb8af75b
|
@ -38,6 +38,7 @@ public:
|
|||
virtual void OnConsoleInit() {};
|
||||
virtual void OnInit() {};
|
||||
virtual void OnReset() {};
|
||||
virtual void OnWindowResize() {}
|
||||
virtual void OnRender() {};
|
||||
virtual void OnRelease() {};
|
||||
virtual void OnMapLoad() {};
|
||||
|
|
|
@ -35,6 +35,16 @@ CChat::CChat()
|
|||
OnReset();
|
||||
}
|
||||
|
||||
void CChat::OnWindowResize()
|
||||
{
|
||||
for(int i = 0; i < MAX_LINES; i++)
|
||||
{
|
||||
if(m_aLines[i].m_TextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aLines[i].m_TextContainerIndex);
|
||||
m_aLines[i].m_TextContainerIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void CChat::OnReset()
|
||||
{
|
||||
for(int i = 0; i < MAX_LINES; i++)
|
||||
|
|
|
@ -94,6 +94,7 @@ public:
|
|||
|
||||
void SayChat(const char *pLine);
|
||||
|
||||
virtual void OnWindowResize();
|
||||
virtual void OnReset();
|
||||
virtual void OnConsoleInit();
|
||||
virtual void OnStateChange(int NewState, int OldState);
|
||||
|
|
|
@ -25,9 +25,46 @@ CHud::CHud()
|
|||
{
|
||||
// won't work if zero
|
||||
m_FrameTimeAvg = 0.0f;
|
||||
m_FPSTextContainerIndex = -1;
|
||||
OnReset();
|
||||
}
|
||||
|
||||
void CHud::ResetHudContainers()
|
||||
{
|
||||
if (m_aScoreInfo[0].m_OptionalNameTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[0].m_OptionalNameTextContainerIndex);
|
||||
if (m_aScoreInfo[1].m_OptionalNameTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[1].m_OptionalNameTextContainerIndex);
|
||||
|
||||
if (m_aScoreInfo[0].m_TextRankContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[0].m_TextRankContainerIndex);
|
||||
if (m_aScoreInfo[1].m_TextRankContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[1].m_TextRankContainerIndex);
|
||||
|
||||
if (m_aScoreInfo[0].m_TextScoreContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[0].m_TextScoreContainerIndex);
|
||||
if (m_aScoreInfo[1].m_TextScoreContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[1].m_TextScoreContainerIndex);
|
||||
|
||||
if (m_aScoreInfo[0].m_RoundRectQuadContainerIndex != -1)
|
||||
Graphics()->DeleteQuadContainer(m_aScoreInfo[0].m_RoundRectQuadContainerIndex);
|
||||
if (m_aScoreInfo[1].m_RoundRectQuadContainerIndex != -1)
|
||||
Graphics()->DeleteQuadContainer(m_aScoreInfo[1].m_RoundRectQuadContainerIndex);
|
||||
|
||||
m_aScoreInfo[0].Reset();
|
||||
m_aScoreInfo[1].Reset();
|
||||
|
||||
if (m_FPSTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_FPSTextContainerIndex);
|
||||
m_FPSTextContainerIndex = -1;
|
||||
}
|
||||
|
||||
void CHud::OnWindowResize()
|
||||
{
|
||||
ResetHudContainers();
|
||||
}
|
||||
|
||||
|
||||
void CHud::OnReset()
|
||||
{
|
||||
m_CheckpointDiff = 0.0f;
|
||||
|
@ -40,28 +77,7 @@ void CHud::OnReset()
|
|||
m_ServerRecord = -1.0f;
|
||||
m_PlayerRecord = -1.0f;
|
||||
|
||||
if(m_aScoreInfo[0].m_OptionalNameTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[0].m_OptionalNameTextContainerIndex);
|
||||
if(m_aScoreInfo[1].m_OptionalNameTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[1].m_OptionalNameTextContainerIndex);
|
||||
|
||||
if(m_aScoreInfo[0].m_TextRankContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[0].m_TextRankContainerIndex);
|
||||
if(m_aScoreInfo[1].m_TextRankContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[1].m_TextRankContainerIndex);
|
||||
|
||||
if(m_aScoreInfo[0].m_TextScoreContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[0].m_TextScoreContainerIndex);
|
||||
if(m_aScoreInfo[1].m_TextScoreContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aScoreInfo[1].m_TextScoreContainerIndex);
|
||||
|
||||
if(m_aScoreInfo[0].m_RoundRectQuadContainerIndex != -1)
|
||||
Graphics()->DeleteQuadContainer(m_aScoreInfo[0].m_RoundRectQuadContainerIndex);
|
||||
if(m_aScoreInfo[1].m_RoundRectQuadContainerIndex != -1)
|
||||
Graphics()->DeleteQuadContainer(m_aScoreInfo[1].m_RoundRectQuadContainerIndex);
|
||||
|
||||
m_aScoreInfo[0].Reset();
|
||||
m_aScoreInfo[1].Reset();
|
||||
ResetHudContainers();
|
||||
}
|
||||
|
||||
void CHud::OnInit()
|
||||
|
@ -80,7 +96,7 @@ void CHud::OnInit()
|
|||
RenderTools()->SelectSprite(SPRITE_FLAG_RED);
|
||||
RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 0.f, 0.f, 8.f, 16.f);
|
||||
RenderTools()->SelectSprite(SPRITE_FLAG_BLUE);
|
||||
RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 0.f, 0.f, 8.f, 16.f);
|
||||
RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 0.f, 0.f, 8.f, 16.f);
|
||||
}
|
||||
|
||||
void CHud::RenderGameTimer()
|
||||
|
@ -348,6 +364,27 @@ void CHud::RenderScoreHud()
|
|||
mem_copy(m_aScoreInfo[t].m_aScoreText, aScore[t], sizeof(m_aScoreInfo[t].m_aScoreText));
|
||||
RecreateRect = true;
|
||||
}
|
||||
|
||||
if (apPlayerInfo[t])
|
||||
{
|
||||
int ID = apPlayerInfo[t]->m_ClientID;
|
||||
if (ID >= 0 && ID < MAX_CLIENTS)
|
||||
{
|
||||
const char *pName = m_pClient->m_aClients[ID].m_aName;
|
||||
if (str_comp(pName, m_aScoreInfo[t].m_aPlayerNameText) != 0)
|
||||
RecreateRect = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aScoreInfo[t].m_aPlayerNameText[0] != 0)
|
||||
RecreateRect = true;
|
||||
}
|
||||
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d.", aPos[t]);
|
||||
if (str_comp(aBuf, m_aScoreInfo[t].m_aRankText) != 0)
|
||||
RecreateRect = true;
|
||||
}
|
||||
|
||||
static float s_TextWidth10 = TextRender()->TextWidth(0, 14.0f, "10", -1);
|
||||
|
@ -398,7 +435,7 @@ void CHud::RenderScoreHud()
|
|||
if(ID >= 0 && ID < MAX_CLIENTS)
|
||||
{
|
||||
const char *pName = m_pClient->m_aClients[ID].m_aName;
|
||||
if(str_comp(pName, m_aScoreInfo[t].m_aPlayerNameText) != 0 || RecreateRect)
|
||||
if(RecreateRect)
|
||||
{
|
||||
mem_copy(m_aScoreInfo[t].m_aPlayerNameText, pName, sizeof(m_aScoreInfo[t].m_aPlayerNameText));
|
||||
|
||||
|
@ -427,11 +464,15 @@ void CHud::RenderScoreHud()
|
|||
vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, StartY+1.0f+Info.m_Size/2+t*20));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_aScoreInfo[t].m_aPlayerNameText[0] = 0;
|
||||
}
|
||||
|
||||
// draw position
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d.", aPos[t]);
|
||||
if(str_comp(aBuf, m_aScoreInfo[t].m_aRankText) != 0 || RecreateRect)
|
||||
if(RecreateRect)
|
||||
{
|
||||
mem_copy(m_aScoreInfo[t].m_aRankText, aBuf, sizeof(m_aScoreInfo[t].m_aRankText));
|
||||
|
||||
|
@ -501,7 +542,7 @@ void CHud::RenderTextInfo()
|
|||
static float s_TextWidth00000 = TextRender()->TextWidth(0, 12.f, "00000", -1);
|
||||
static float s_TextWidth[5] = { s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000 };
|
||||
|
||||
int DigitIndex = (int)log10(FrameTime);
|
||||
int DigitIndex = (int)log10((FrameTime ? FrameTime : 1));
|
||||
if(DigitIndex > 4)
|
||||
DigitIndex = 4;
|
||||
//TextRender()->Text(0, m_Width-10-TextRender()->TextWidth(0,12,Buf,-1), 5, 12, Buf, -1);
|
||||
|
@ -509,8 +550,9 @@ void CHud::RenderTextInfo()
|
|||
CTextCursor Cursor;
|
||||
TextRender()->SetCursor(&Cursor, m_Width - 10 - s_TextWidth[DigitIndex], 5, 12, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = -1;
|
||||
static int TextContainerIndex = TextRender()->CreateTextContainer(&Cursor, "0");
|
||||
TextRender()->RecreateTextContainerSoft(&Cursor, TextContainerIndex, Buf);
|
||||
if(m_FPSTextContainerIndex == -1)
|
||||
m_FPSTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, "0");
|
||||
TextRender()->RecreateTextContainerSoft(&Cursor, m_FPSTextContainerIndex, Buf);
|
||||
STextRenderColor TColor;
|
||||
TColor.m_R = 1.f;
|
||||
TColor.m_G = 1.f;
|
||||
|
@ -521,7 +563,7 @@ void CHud::RenderTextInfo()
|
|||
TOutColor.m_G = 0.f;
|
||||
TOutColor.m_B = 0.f;
|
||||
TOutColor.m_A = 0.3f;
|
||||
TextRender()->RenderTextContainer(TextContainerIndex, &TColor, &TOutColor);
|
||||
TextRender()->RenderTextContainer(m_FPSTextContainerIndex, &TColor, &TOutColor);
|
||||
}
|
||||
if(g_Config.m_ClShowpred)
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ class CHud : public CComponent
|
|||
|
||||
int m_HudQuadContainerIndex;
|
||||
SScoreInfo m_aScoreInfo[2];
|
||||
int m_FPSTextContainerIndex;
|
||||
|
||||
void RenderCursor();
|
||||
|
||||
|
@ -63,6 +64,8 @@ class CHud : public CComponent
|
|||
public:
|
||||
CHud();
|
||||
|
||||
void ResetHudContainers();
|
||||
virtual void OnWindowResize();
|
||||
virtual void OnReset();
|
||||
virtual void OnRender();
|
||||
virtual void OnInit();
|
||||
|
|
|
@ -10,10 +10,22 @@
|
|||
#include <game/client/animstate.h>
|
||||
#include "killmessages.h"
|
||||
|
||||
void CKillMessages::OnWindowResize()
|
||||
{
|
||||
for(int i = 0; i < MAX_KILLMSGS; i++)
|
||||
{
|
||||
if(m_aKillmsgs[i].m_VictimTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aKillmsgs[i].m_VictimTextContainerIndex);
|
||||
if(m_aKillmsgs[i].m_KillerTextContainerIndex != -1)
|
||||
TextRender()->DeleteTextContainer(m_aKillmsgs[i].m_KillerTextContainerIndex);
|
||||
m_aKillmsgs[i].m_VictimTextContainerIndex = m_aKillmsgs[i].m_KillerTextContainerIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void CKillMessages::OnReset()
|
||||
{
|
||||
m_KillmsgCurrent = 0;
|
||||
for(int i = 0; i < MAX_KILLMSGS; i++)
|
||||
for (int i = 0; i < MAX_KILLMSGS; i++)
|
||||
{
|
||||
m_aKillmsgs[i].m_Tick = -100000;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
CKillMsg m_aKillmsgs[MAX_KILLMSGS];
|
||||
int m_KillmsgCurrent;
|
||||
|
||||
virtual void OnWindowResize();
|
||||
virtual void OnReset();
|
||||
virtual void OnRender();
|
||||
virtual void OnMessage(int MsgType, void *pRawMsg);
|
||||
|
|
|
@ -203,7 +203,7 @@ int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const c
|
|||
c.Margin(2.0f, &c);
|
||||
RenderTools()->DrawUIRect(&c, vec4(1,1,1,0.25f)*ButtonColorMul(pID), CUI::CORNER_ALL, 3.0f);
|
||||
|
||||
TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING);
|
||||
TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT);
|
||||
bool CheckAble = *pBoxText == 'X';
|
||||
if(CheckAble)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#include <engine/textrender.h>
|
||||
#include <engine/graphics.h>
|
||||
#include <engine/shared/config.h>
|
||||
#include <game/generated/protocol.h>
|
||||
#include <game/generated/client_data.h>
|
||||
|
@ -9,9 +10,17 @@
|
|||
#include <game/client/animstate.h>
|
||||
#include "nameplates.h"
|
||||
#include "controls.h"
|
||||
#include "camera.h"
|
||||
|
||||
#include "players.h"
|
||||
|
||||
void CNamePlates::MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup)
|
||||
{
|
||||
float Points[4];
|
||||
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX / 100.0f, pGroup->m_ParallaxY / 100.0f, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points);
|
||||
Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]);
|
||||
}
|
||||
|
||||
void CNamePlates::RenderNameplate(
|
||||
const CNetObj_Character *pPrevChar,
|
||||
const CNetObj_Character *pPlayerChar,
|
||||
|
@ -60,7 +69,12 @@ void CNamePlates::RenderNameplate(
|
|||
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = -1;
|
||||
|
||||
// create nameplates at standard zoom
|
||||
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
|
||||
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
|
||||
MapscreenToGroup(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y, Layers()->GameGroup());
|
||||
m_aNamePlates[ClientID].m_NameTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, pName);
|
||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||
}
|
||||
|
||||
if(g_Config.m_ClNameplatesClan)
|
||||
|
@ -80,7 +94,12 @@ void CNamePlates::RenderNameplate(
|
|||
TextRender()->SetCursor(&Cursor, 0, 0, FontSizeClan, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = -1;
|
||||
|
||||
// create nameplates at standard zoom
|
||||
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
|
||||
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
|
||||
MapscreenToGroup(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y, Layers()->GameGroup());
|
||||
m_aNamePlates[ClientID].m_ClanNameTextContainerIndex = TextRender()->CreateTextContainer(&Cursor, pClan);
|
||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +180,7 @@ void CNamePlates::SetPlayers(CPlayers* pPlayers)
|
|||
m_pPlayers = pPlayers;
|
||||
}
|
||||
|
||||
void CNamePlates::OnInit()
|
||||
void CNamePlates::ResetNamePlates()
|
||||
{
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
{
|
||||
|
@ -172,4 +191,15 @@ void CNamePlates::OnInit()
|
|||
|
||||
m_aNamePlates[i].Reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CNamePlates::OnWindowResize()
|
||||
{
|
||||
ResetNamePlates();
|
||||
}
|
||||
|
||||
void CNamePlates::OnInit()
|
||||
{
|
||||
ResetNamePlates();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ struct SPlayerNamePlate
|
|||
|
||||
class CNamePlates : public CComponent
|
||||
{
|
||||
void MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup);
|
||||
|
||||
void RenderNameplate(
|
||||
const CNetObj_Character *pPrevChar,
|
||||
const CNetObj_Character *pPlayerChar,
|
||||
|
@ -40,7 +42,10 @@ class CNamePlates : public CComponent
|
|||
|
||||
SPlayerNamePlate m_aNamePlates[MAX_CLIENTS];
|
||||
class CPlayers* m_pPlayers;
|
||||
|
||||
void ResetNamePlates();
|
||||
public:
|
||||
virtual void OnWindowResize();
|
||||
virtual void OnInit();
|
||||
virtual void OnRender();
|
||||
|
||||
|
|
Loading…
Reference in a new issue