From 2240ad2966140d8bd3a74ecff6bbc8fa3f61abf1 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 19 Jul 2022 18:22:44 +0200 Subject: [PATCH 01/72] Fix spelling --- src/game/client/prediction/entities/character.cpp | 2 +- src/game/client/prediction/entities/character.h | 2 +- src/game/client/prediction/entity.h | 2 +- src/game/client/prediction/gameworld.cpp | 2 +- src/game/server/entities/character.cpp | 2 +- src/game/server/entities/character.h | 2 +- src/game/server/entity.h | 4 ++-- src/game/server/gameworld.cpp | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index b395546a45d..493e0f2518b 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -580,7 +580,7 @@ void CCharacter::Tick() m_PrevPos = m_Core.m_Pos; } -void CCharacter::TickDefered() +void CCharacter::TickDeferred() { m_Core.Move(); m_Core.Quantize(); diff --git a/src/game/client/prediction/entities/character.h b/src/game/client/prediction/entities/character.h index 2c17cc93418..26528fcf748 100644 --- a/src/game/client/prediction/entities/character.h +++ b/src/game/client/prediction/entities/character.h @@ -37,7 +37,7 @@ class CCharacter : public CEntity static const int ms_PhysSize = 28; void Tick() override; - void TickDefered() override; + void TickDeferred() override; bool IsGrounded(); diff --git a/src/game/client/prediction/entity.h b/src/game/client/prediction/entity.h index ad23c4c9aa3..d89b3aa781b 100644 --- a/src/game/client/prediction/entity.h +++ b/src/game/client/prediction/entity.h @@ -53,7 +53,7 @@ class CEntity void Destroy() { delete this; } virtual void Tick() {} - virtual void TickDefered() {} + virtual void TickDeferred() {} bool GameLayerClipped(vec2 CheckPos); float m_ProximityRadius; diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index 1f197747f4c..8868c357c3d 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -199,7 +199,7 @@ void CGameWorld::Tick() for(; pEnt;) { m_pNextTraverseEntity = pEnt->m_pNextTypeEntity; - pEnt->TickDefered(); + pEnt->TickDeferred(); pEnt->m_SnapTicks++; pEnt = m_pNextTraverseEntity; } diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 507bd1c630c..19d7db7e825 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -764,7 +764,7 @@ void CCharacter::Tick() m_PrevPos = m_Core.m_Pos; } -void CCharacter::TickDefered() +void CCharacter::TickDeferred() { // advance the dummy { diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index d69d4265216..4e05d48af61 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -34,7 +34,7 @@ class CCharacter : public CEntity void Reset() override; void Destroy() override; void Tick() override; - void TickDefered() override; + void TickDeferred() override; void TickPaused() override; void Snap(int SnappingClient) override; void SwapClients(int Client1, int Client2) override; diff --git a/src/game/server/entity.h b/src/game/server/entity.h index 086711298c9..c897a9073be 100644 --- a/src/game/server/entity.h +++ b/src/game/server/entity.h @@ -94,10 +94,10 @@ class CEntity virtual void Tick() {} /* - Function: TickDefered + Function: TickDeferred Called after all entities Tick() function has been called. */ - virtual void TickDefered() {} + virtual void TickDeferred() {} /* Function: TickPaused diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 054e4b36f7c..6569c2fa388 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -280,7 +280,7 @@ void CGameWorld::Tick() for(; pEnt;) { m_pNextTraverseEntity = pEnt->m_pNextTypeEntity; - pEnt->TickDefered(); + pEnt->TickDeferred(); pEnt = m_pNextTraverseEntity; } } From 88c4b693014e054ed4b7e921597e024fd323b0ee Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 19 Jul 2022 18:34:49 +0200 Subject: [PATCH 02/72] Add an option to remove weak hook & bounce --- datasrc/network.py | 4 ++-- src/engine/shared/config_variables.h | 2 ++ src/game/client/gameclient.cpp | 6 ++++++ src/game/client/gameclient.h | 2 ++ .../client/prediction/entities/character.cpp | 16 ++++++++++++++-- .../client/prediction/entities/character.h | 1 + src/game/client/prediction/entity.h | 1 + src/game/client/prediction/gameworld.cpp | 11 +++++++++++ src/game/client/prediction/gameworld.h | 1 + src/game/gamecore.cpp | 8 +++++++- src/game/gamecore.h | 3 ++- src/game/server/entities/character.cpp | 19 +++++++++++++++++-- src/game/server/entities/character.h | 1 + src/game/server/entity.h | 7 +++++++ src/game/server/gamecontroller.cpp | 2 ++ src/game/server/gameworld.cpp | 11 +++++++++++ 16 files changed, 87 insertions(+), 8 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 14dbf74e594..0a8dbd42220 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -26,7 +26,7 @@ ] GameInfoFlags2 = [ "ALLOW_X_SKINS", "GAMETYPE_CITY", "GAMETYPE_FDDRACE", "ENTITIES_FDDRACE", "HUD_HEALTH_ARMOR", "HUD_AMMO", - "HUD_DDRACE", + "HUD_DDRACE", "NO_WEAK_HOOK_AND_BOUNCE" ] ExPlayerFlags = ["AFK", "PAUSED", "SPEC"] ProjectileFlags = ["CLIENTID_BIT{}".format(i) for i in range(8)] + [ @@ -64,7 +64,7 @@ enum { - GAMEINFO_CURVERSION=7, + GAMEINFO_CURVERSION=8, }; ''' diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index e5a13a3f920..d26376d8281 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -285,6 +285,8 @@ MACRO_CONFIG_INT(SvOldLaser, sv_old_laser, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAM MACRO_CONFIG_INT(SvSlashMe, sv_slash_me, 0, 0, 1, CFGFLAG_SERVER, "Whether /me is active on the server or not") MACRO_CONFIG_INT(SvRejoinTeam0, sv_rejoin_team_0, 1, 0, 1, CFGFLAG_SERVER, "Make a team automatically rejoin team 0 after finish (only if not locked)") +MACRO_CONFIG_INT(SvNoWeakHookAndBounce, sv_no_weak_hook_and_bounce, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAME, "Whether to use an alternative calculation for world ticks, that makes hook and bounce behave like all players have strong.") + MACRO_CONFIG_INT(ClReconnectTimeout, cl_reconnect_timeout, 120, 0, 600, CFGFLAG_CLIENT | CFGFLAG_SAVE, "How many seconds to wait before reconnecting (after timeout, 0 for off)") MACRO_CONFIG_INT(ClReconnectFull, cl_reconnect_full, 5, 0, 600, CFGFLAG_CLIENT | CFGFLAG_SAVE, "How many seconds to wait before reconnecting (when server is full, 0 for off)") diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 69ac47be072..5bdb9b39480 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1067,6 +1067,7 @@ static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize, Info.m_HudHealthArmor = true; Info.m_HudAmmo = true; Info.m_HudDDRace = false; + Info.m_NoWeakHookAndBounce = false; if(Version >= 0) { @@ -1118,6 +1119,10 @@ static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize, Info.m_HudAmmo = Flags2 & GAMEINFOFLAG2_HUD_AMMO; Info.m_HudDDRace = Flags2 & GAMEINFOFLAG2_HUD_DDRACE; } + if(Version >= 8) + { + Info.m_NoWeakHookAndBounce = Flags2 & GAMEINFOFLAG2_NO_WEAK_HOOK_AND_BOUNCE; + } return Info; } @@ -2265,6 +2270,7 @@ void CGameClient::UpdatePrediction() m_GameWorld.m_WorldConfig.m_PredictFreeze = g_Config.m_ClPredictFreeze; m_GameWorld.m_WorldConfig.m_PredictWeapons = AntiPingWeapons(); m_GameWorld.m_WorldConfig.m_BugDDRaceInput = m_GameInfo.m_BugDDRaceInput; + m_GameWorld.m_WorldConfig.m_NoWeakHookAndBounce = m_GameInfo.m_NoWeakHookAndBounce; // always update default tune zone, even without character if(!m_GameWorld.m_WorldConfig.m_UseTuneZones) diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 9d68d5f5065..b3b3004437c 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -94,6 +94,8 @@ class CGameInfo bool m_HudHealthArmor; bool m_HudAmmo; bool m_HudDDRace; + + bool m_NoWeakHookAndBounce; }; class CSnapEntities diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index 493e0f2518b..7c7d5d84a54 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -561,12 +561,24 @@ void CCharacter::ResetInput() m_LatestPrevInput = m_LatestInput = m_Input; } -void CCharacter::Tick() +void CCharacter::PreTick() { DDRaceTick(); m_Core.m_Input = m_Input; - m_Core.Tick(true); + m_Core.Tick(true, !m_pGameWorld->m_WorldConfig.m_NoWeakHookAndBounce); +} + +void CCharacter::Tick() +{ + if(m_pGameWorld->m_WorldConfig.m_NoWeakHookAndBounce) + { + m_Core.TickDeferred(); + } + else + { + PreTick(); + } // handle Weapons HandleWeapons(); diff --git a/src/game/client/prediction/entities/character.h b/src/game/client/prediction/entities/character.h index 26528fcf748..ffaf12c2e65 100644 --- a/src/game/client/prediction/entities/character.h +++ b/src/game/client/prediction/entities/character.h @@ -36,6 +36,7 @@ class CCharacter : public CEntity //character's size static const int ms_PhysSize = 28; + void PreTick() override; void Tick() override; void TickDeferred() override; diff --git a/src/game/client/prediction/entity.h b/src/game/client/prediction/entity.h index d89b3aa781b..1083c6d335c 100644 --- a/src/game/client/prediction/entity.h +++ b/src/game/client/prediction/entity.h @@ -52,6 +52,7 @@ class CEntity float GetProximityRadius() const { return m_ProximityRadius; } void Destroy() { delete this; } + virtual void PreTick() {} virtual void Tick() {} virtual void TickDeferred() {} diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index 8868c357c3d..20f4f7fe67a 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -187,6 +187,17 @@ bool distCompare(std::pair a, std::pair b) void CGameWorld::Tick() { // update all objects + if(m_WorldConfig.m_NoWeakHookAndBounce) + { + for(auto *pEnt : m_apFirstEntityTypes) + for(; pEnt;) + { + m_pNextTraverseEntity = pEnt->m_pNextTypeEntity; + pEnt->PreTick(); + pEnt = m_pNextTraverseEntity; + } + } + for(auto *pEnt : m_apFirstEntityTypes) for(; pEnt;) { diff --git a/src/game/client/prediction/gameworld.h b/src/game/client/prediction/gameworld.h index f7fecd9aa13..aca7c8ff941 100644 --- a/src/game/client/prediction/gameworld.h +++ b/src/game/client/prediction/gameworld.h @@ -77,6 +77,7 @@ class CGameWorld bool m_IsSolo; bool m_UseTuneZones; bool m_BugDDRaceInput; + bool m_NoWeakHookAndBounce; } m_WorldConfig; bool m_IsValidCopy; diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index d2cdc26ea55..fc29f420378 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -116,7 +116,7 @@ void CCharacterCore::Reset() m_Input.m_TargetY = -1; } -void CCharacterCore::Tick(bool UseInput) +void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) { m_MoveRestrictions = m_pCollision->GetMoveRestrictions(UseInput ? IsSwitchActiveCb : 0, this, m_Pos); m_TriggeredEvents = 0; @@ -387,6 +387,12 @@ void CCharacterCore::Tick(bool UseInput) } } + if(DoDeferredTick) + TickDeferred(); +} + +void CCharacterCore::TickDeferred() +{ if(m_pWorld) { for(int i = 0; i < MAX_CLIENTS; i++) diff --git a/src/game/gamecore.h b/src/game/gamecore.h index 8faf9dd1ba8..41bcd2abc34 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -269,7 +269,8 @@ class CCharacterCore void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr, std::map> *pTeleOuts = nullptr); void Reset(); - void Tick(bool UseInput); + void TickDeferred(); + void Tick(bool UseInput, bool DoDeferredTick = true); void Move(); void Read(const CNetObj_CharacterCore *pObjCore); diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 19d7db7e825..9e72f656f0e 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -712,7 +712,7 @@ void CCharacter::ResetInput() m_LatestPrevInput = m_LatestInput = m_Input; } -void CCharacter::Tick() +void CCharacter::PreTick() { if(m_StartTime > Server()->Tick()) { @@ -738,7 +738,22 @@ void CCharacter::Tick() Antibot()->OnCharacterTick(m_pPlayer->GetCID()); m_Core.m_Input = m_Input; - m_Core.Tick(true); + m_Core.Tick(true, !g_Config.m_SvNoWeakHookAndBounce); +} + +void CCharacter::Tick() +{ + if(g_Config.m_SvNoWeakHookAndBounce) + { + if(m_Paused) + return; + + m_Core.TickDeferred(); + } + else + { + PreTick(); + } if(!m_PrevInput.m_Hook && m_Input.m_Hook && !(m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_PLAYER)) { diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 4e05d48af61..b6e9b7616f7 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -33,6 +33,7 @@ class CCharacter : public CEntity void Reset() override; void Destroy() override; + void PreTick() override; void Tick() override; void TickDeferred() override; void TickPaused() override; diff --git a/src/game/server/entity.h b/src/game/server/entity.h index c897a9073be..b918f00c4c6 100644 --- a/src/game/server/entity.h +++ b/src/game/server/entity.h @@ -86,6 +86,13 @@ class CEntity */ virtual void Reset() {} + /* + Function: PreTick + Called to progress the entity before the next tick. + Can be used to prepare variables for all clients before the next tick is executed. + */ + virtual void PreTick() {} + /* Function: Tick Called to progress the entity to the next tick. Updates diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 527e25c0acc..9f20a155465 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -605,6 +605,8 @@ void IGameController::Snap(int SnappingClient) GAMEINFOFLAG_ENTITIES_RACE | GAMEINFOFLAG_RACE; pGameInfoEx->m_Flags2 = GAMEINFOFLAG2_HUD_DDRACE; + if(g_Config.m_SvNoWeakHookAndBounce) + pGameInfoEx->m_Flags2 |= GAMEINFOFLAG2_NO_WEAK_HOOK_AND_BOUNCE; pGameInfoEx->m_Version = GAMEINFO_CURVERSION; if(Server()->IsSixup(SnappingClient)) diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 6569c2fa388..f3dcc616e72 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -268,6 +268,17 @@ void CGameWorld::Tick() if(GameServer()->m_pController->IsForceBalanced()) GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Teams have been balanced"); // update all objects + if(g_Config.m_SvNoWeakHookAndBounce) + { + for(auto *pEnt : m_apFirstEntityTypes) + for(; pEnt;) + { + m_pNextTraverseEntity = pEnt->m_pNextTypeEntity; + pEnt->PreTick(); + pEnt = m_pNextTraverseEntity; + } + } + for(auto *pEnt : m_apFirstEntityTypes) for(; pEnt;) { From c696d93e41f76f0bddd3d54021c847253c8d789f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 3 Aug 2022 23:26:42 +0200 Subject: [PATCH 03/72] Add documentation for `IServer::GetClientVersion` --- src/engine/server.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/engine/server.h b/src/engine/server.h index 25239785664..3f53cbc1624 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -60,6 +60,16 @@ class IServer : public IInterface virtual void SetClientDDNetVersion(int ClientID, int DDNetVersion) = 0; virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) const = 0; + /** + * Returns the version of the client with the given client ID. + * + * @param ClientID the client ID, which must be between 0 and + * MAX_CLIENTS - 1, or equal to SERVER_DEMO_CLIENT for server demos. + * + * @return The version of the client with the given client ID. + * For server demos this is always the latest client version. + * On errors, VERSION_NONE is returned. + */ virtual int GetClientVersion(int ClientID) const = 0; virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0; From b1e4d60fae4628fde2501722a0ca4d1f78ea1cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 4 Aug 2022 23:39:40 +0200 Subject: [PATCH 04/72] Fix buffer-overflow in editor on shift-clicking brush 1. Open any map, including an empty one. 2. Select a brush, e.g. size 2x2. 3. Shift click to repeat the brush over a larger area, e.g. 10x10. 4. This causes a buffer-overflow / crash with ASAN: ``` ================================================================= ==4826==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6060000f5040 at pc 0x55db7d0aa743 bp 0x7fffe4e191f0 sp 0x7fffe4e191e0 READ of size 4 at 0x6060000f5040 thread T0 0 0x55db7d0aa742 in CLayerTiles::GetTile(int, int) src/game/editor/layer_tiles.cpp:50 1 0x55db7d0d23e1 in CLayerTiles::FillSelection(bool, CLayer*, CUIRect) src/game/editor/layer_tiles.cpp:437 2 0x55db7cf196e9 in CEditor::DoMapEditor(CUIRect) src/game/editor/editor.cpp:2641 3 0x55db7cfa7755 in CEditor::Render() src/game/editor/editor.cpp:5747 4 0x55db7cfd2a56 in CEditor::OnRender() src/game/editor/editor.cpp:6437 5 0x55db7c23e02d in CClient::Run() src/engine/client/client.cpp:3374 6 0x55db7c2a9f7b in main src/engine/client/client.cpp:4762 0x6060000f5040 is located 0 bytes to the right of 64-byte region [0x6060000f5000,0x6060000f5040) allocated by thread T0 here: 0 0x7f9b21db5787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107 1 0x55db7d0a9a86 in CLayerTiles::CLayerTiles(int, int) src/game/editor/layer_tiles.cpp:39 2 0x55db7d0cf0ed in CLayerTiles::BrushGrab(CLayerGroup*, CUIRect) src/game/editor/layer_tiles.cpp:387 3 0x55db7cf18191 in CEditor::DoMapEditor(CUIRect) src/game/editor/editor.cpp:2612 4 0x55db7cfa7755 in CEditor::Render() src/game/editor/editor.cpp:5747 5 0x55db7cfd2a56 in CEditor::OnRender() src/game/editor/editor.cpp:6437 6 0x55db7c23e02d in CClient::Run() src/engine/client/client.cpp:3374 SUMMARY: AddressSanitizer: heap-buffer-overflow src/game/editor/layer_tiles.cpp:50 in CLayerTiles::GetTile(int, int) Shadow bytes around the buggy address: 0x0c0c800169b0: 00 00 00 fa fa fa fa fa 00 00 00 00 00 00 00 fa 0x0c0c800169c0: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa 0x0c0c800169d0: fd fd fd fd fd fd fd fa fa fa fa fa fd fd fd fd 0x0c0c800169e0: fd fd fd fd fa fa fa fa fd fd fd fd fd fd fd fa 0x0c0c800169f0: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa =>0x0c0c80016a00: 00 00 00 00 00 00 00 00[fa]fa fa fa fd fd fd fd 0x0c0c80016a10: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa 0x0c0c80016a20: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa 0x0c0c80016a30: fd fd fd fd fd fd fd fa fa fa fa fa fd fd fd fd 0x0c0c80016a40: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa 0x0c0c80016a50: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==4826==ABORTING ``` --- src/game/editor/layer_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 1db119bc9c2..bc1ab3f1db9 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -434,7 +434,7 @@ void CLayerTiles::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect) continue; bool HasTile = GetTile(fx, fy).m_Index; - if(!Empty && pLt->GetTile(x, y).m_Index == TILE_THROUGH_CUT) + if(!Empty && pLt->GetTile(x % pLt->m_Width, y % pLt->m_Height).m_Index == TILE_THROUGH_CUT) { if(m_Game && m_pEditor->m_Map.m_pFrontLayer) { From a41f1c1def0a7a2940508c7df3cc559303486dde Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Sat, 6 Aug 2022 02:06:40 +0200 Subject: [PATCH 05/72] Fix shift-leftclick-drag with empty selection to delete (fixes #5705) --- src/game/editor/editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index ac556a6ab8b..b565070366d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2637,8 +2637,8 @@ void CEditor::DoMapEditor(CUIRect View) size_t BrushIndex = k; if(m_Brush.m_vpLayers.size() != NumEditLayers) BrushIndex = 0; - if(BrushIndex < m_Brush.m_vpLayers.size()) - apEditLayers[k]->FillSelection(m_Brush.IsEmpty(), m_Brush.m_vpLayers[BrushIndex], r); + CLayer *pBrush = m_Brush.IsEmpty() ? nullptr : m_Brush.m_vpLayers[BrushIndex]; + apEditLayers[k]->FillSelection(m_Brush.IsEmpty(), pBrush, r); } } else From 526861f924bb611e08a682d4b056ee186d8f7873 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Mon, 8 Aug 2022 16:09:39 +0200 Subject: [PATCH 06/72] Update language files, remove half-translated graphics warning Thanks to cheeser0613 for report --- data/languages/arabic.txt | 3 - data/languages/belarusian.txt | 3 - data/languages/bosnian.txt | 3 - data/languages/brazilian_portuguese.txt | 3 - data/languages/bulgarian.txt | 3 - data/languages/catalan.txt | 3 - data/languages/chuvash.txt | 3 - data/languages/czech.txt | 3 - data/languages/danish.txt | 3 - data/languages/dutch.txt | 3 - data/languages/esperanto.txt | 961 ++++++++++++------------ data/languages/finnish.txt | 3 - data/languages/french.txt | 87 ++- data/languages/german.txt | 4 +- data/languages/greek.txt | 3 - data/languages/hungarian.txt | 3 - data/languages/italian.txt | 3 - data/languages/japanese.txt | 3 - data/languages/korean.txt | 3 - data/languages/kyrgyz.txt | 3 - data/languages/norwegian.txt | 3 - data/languages/persian.txt | 3 - data/languages/polish.txt | 3 - data/languages/portuguese.txt | 3 - data/languages/romanian.txt | 3 - data/languages/russian.txt | 4 +- data/languages/serbian.txt | 3 - data/languages/serbian_cyrillic.txt | 3 - data/languages/simplified_chinese.txt | 3 - data/languages/slovak.txt | 3 - data/languages/spanish.txt | 3 - data/languages/swedish.txt | 3 - data/languages/traditional_chinese.txt | 3 - data/languages/turkish.txt | 3 - data/languages/ukrainian.txt | 3 - src/engine/client/graphics_threaded.cpp | 2 +- 36 files changed, 524 insertions(+), 627 deletions(-) diff --git a/data/languages/arabic.txt b/data/languages/arabic.txt index 9363572a811..6919cf38b72 100644 --- a/data/languages/arabic.txt +++ b/data/languages/arabic.txt @@ -1237,9 +1237,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/belarusian.txt b/data/languages/belarusian.txt index 7d845cadb5c..9720b234eef 100644 --- a/data/languages/belarusian.txt +++ b/data/languages/belarusian.txt @@ -697,9 +697,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/bosnian.txt b/data/languages/bosnian.txt index d7e71da9e2c..aa467acb2e5 100644 --- a/data/languages/bosnian.txt +++ b/data/languages/bosnian.txt @@ -1105,9 +1105,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Existing Player == diff --git a/data/languages/brazilian_portuguese.txt b/data/languages/brazilian_portuguese.txt index d73928e48f1..1cbbf024ac1 100644 --- a/data/languages/brazilian_portuguese.txt +++ b/data/languages/brazilian_portuguese.txt @@ -1500,9 +1500,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/bulgarian.txt b/data/languages/bulgarian.txt index bdcb7b996fc..b5b899aab83 100644 --- a/data/languages/bulgarian.txt +++ b/data/languages/bulgarian.txt @@ -694,9 +694,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/catalan.txt b/data/languages/catalan.txt index f16ee4f28d8..799e4fcd76d 100644 --- a/data/languages/catalan.txt +++ b/data/languages/catalan.txt @@ -1360,9 +1360,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/chuvash.txt b/data/languages/chuvash.txt index 42380122319..3cb33c70390 100644 --- a/data/languages/chuvash.txt +++ b/data/languages/chuvash.txt @@ -697,9 +697,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/czech.txt b/data/languages/czech.txt index 991131b6e5a..10013c8004a 100644 --- a/data/languages/czech.txt +++ b/data/languages/czech.txt @@ -1250,9 +1250,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/danish.txt b/data/languages/danish.txt index fa7e3f8a742..816caeb7288 100644 --- a/data/languages/danish.txt +++ b/data/languages/danish.txt @@ -1248,9 +1248,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/dutch.txt b/data/languages/dutch.txt index 05ac5ce5066..b3ba97d403f 100644 --- a/data/languages/dutch.txt +++ b/data/languages/dutch.txt @@ -1409,9 +1409,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/esperanto.txt b/data/languages/esperanto.txt index 7b65b9153aa..04921af0eef 100644 --- a/data/languages/esperanto.txt +++ b/data/languages/esperanto.txt @@ -1,26 +1,5 @@ ##### translated strings ##### -Successfully saved the replay! -== - -Saving ddnet-settings.cfg failed -== - -Replay feature is disabled! -== - -The width of texture %s is not divisible by %d, or the height is not divisible by %d, which might cause visual bugs. -== - - unsupported -== - -The format of texture %s is not RGBA which will cause visual bugs. -== - -Preparing demo playback -== - Connected == Konektita @@ -30,18 +9,6 @@ Loading map file from storage Loading DDNet Client == Ŝargas DDNet -Initializing components -== - -Initializing assets -== - -Initializing map logic -== - -Sending initial client info -== - Warning == Averto @@ -57,15 +24,9 @@ Chat -Page %d- == -Paĝo %d- -Debug mode enabled. Press Ctrl+Shift+D to disable debug mode. -== - Game paused == Paŭzata ludo -Sudden Death -== - Warmup == Trejnado @@ -87,39 +48,18 @@ Vote yes Vote no == Voĉdoni ne -Position: -== - Speed: == Rapideco: -Angle: -== - Spectate == Spekti Free-View == Libera vidado -Server best: -== - -Personal best: -== - -Uploading map data to GPU -== - -Reset -== - News == Novaĵoj -Demos -== - Internet == Internet @@ -153,27 +93,9 @@ Connecting to Abort == Nuligi -Trying to determine UDP connectivity... -== - -UDP seems to be filtered. -== - -UDP and TCP IP addresses seem to be different. Try disabling VPN, proxy or network accelerators. -== - -No answer from server yet. -== - Downloading map == Elŝutas mapon -Getting game info -== - -Requesting to join the game -== - Disconnected == Malkonektita @@ -183,42 +105,6 @@ Ok Reconnect in %d sec == Rekonektiĝos post %d sek -The server is running a non-standard tuning on a pure game type. -== - -Delete demo -== - -Are you sure that you want to delete the demo? -== - -Rename demo -== - -Render demo -== - -Replace video -== - -File already exists, do you want to overwrite it? -== - -Remove friend -== - -Are you sure that you want to remove the player from your friends list? -== - -Sound error -== - -The audio device couldn't be initialised. -== - -Password incorrect -== - Try again == Reprovi @@ -243,15 +129,6 @@ Are you sure that you want to disconnect your dummy? Welcome to DDNet == Bonvenon en DDNet -DDraceNetwork is a cooperative online game where the goal is for you and your group of tees to reach the finish line of the map. As a newcomer you should start on Novice servers, which host the easiest maps. Consider the ping to choose a server close to you. -== - -Use k key to kill (restart), q to pause and watch other players. See settings for other key binds. -== - -It's recommended that you check the settings to adjust them to your liking before joining a server. -== - Please enter your nickname below. == Bonvolu tajpi vian kromnomon. @@ -300,21 +177,9 @@ Country / Region Error == Eraro -Unable to delete the demo -== - -Unable to rename the demo -== - New name: == Nova nomo: -Destination file already exist -== - -Error loading demo -== - Show chat == Montri la diskutejon @@ -324,21 +189,12 @@ Use sounds Speed == Rapideco -Show ingame HUD -== - -Video name: -== - Join Tutorial Server == Aliĝi al la lernila servilo Skip Tutorial == Pasi la lernilo -Show DDNet map finishes in server browser -== - transmits your player name to info2.ddnet.tw == sendas vian ludantnomon al info2.ddnet.tw @@ -348,9 +204,6 @@ Nickname Theme == Temo -Loading menu images -== - AFR == AFR @@ -414,69 +267,27 @@ Refreshing... Connect == Konektiĝi -Server filter -== - -Has people playing -== - Count players only == Nur nombri ludantojn -Server not full -== - Show friends only == Nur montri amikojn No password == Neniu pasvorto -Strict gametype filter -== - Game types: == Ludtipoj: -Player country: -== - -Filter connecting players -== - -Indicate map finish -== - -Unfinished map -== - Countries == Landoj -Types -== - -Reset filter -== - -Server details -== - Favorite == Favorati -Leak IP -== - -Scoreboard -== - Friends == Amikoj -Remove -== - Name == Nomo @@ -489,9 +300,6 @@ Add Friend Filter == Filtri -Info -== - Select a name == Elekti nomon @@ -504,72 +312,15 @@ Remove chat Close == Fermi -Demofile: %s -== - -Loading demo files -== - -Parent Folder -== - Folder == Dosierujo -Invalid Demo -== - -Demo details -== - -Created: -== - -Type: -== - -Length: -== - Version: == Versio: -Markers: -== - Map: == Mapo: -Size: -== - -%.2f MiB -== - -%.2f KiB -== - -Crc: -== - -Netversion: -== - -Demo -== - -Markers -== - -Length -== - -Date -== - -Fetch Info -== - Open == Malfermi @@ -577,30 +328,18 @@ Open Play == Legi -Demos directory -== - Delete == Forigi Rename == Renomigi -Render -== - Connect Dummy == Konektigi pupon Connecting dummy == Pupo konektas -Stop record -== - -Record demo -== - Join red == Aliĝi al ruĝa taemo @@ -616,66 +355,508 @@ Kill Pause == Paŭzi -Player options -== Ludantaj agordoj +Player options +== Ludantaj agordoj + +Player +== Ludanto + +Address +== Retadreso + +Ping +== Latenco + +Version +== Versio + +Game info +== Ludaj informoj + +Game type +== Ludtipo + +Map +== Mapo + +MOTD +== MDLT + +Change settings +== Ŝanĝi agordojn + +Kick player +== Elirigi ludanton + +Move player to spectators +== Movi ludanton al spektantoj + +Force vote +== Forci voĉdonon + +Vote description: +== Voĉdona priskribo: + +Vote command: +== Voĉdona komando: + +Add +== Aldoni + +Time +== Tempo + +Dummy settings +== Agordoj de la pupo + +Skins +== Haŭtoj + +Skin Database +== Datumbazo de haŭtoj + +Skins directory +== Dosierujo de haŭtoj + +Move left +== Movi maldekstren + +Move right +== Movi dekstren + +Jump +== Salti + +Fire +== Pafi + +Hook +== Hoki + +Show others +== Montri aliaj + +Show all +== Montri ĉiuj + +Hammer +== Martelo + +Pistol +== Pistolo + +Laser +== Lasero + +Mouse +== Muso + +Weapon +== Batalilo + +Dummy +== Pupo + +Screen +== Ekrano + +default +== defaŭlta + +auto +== aŭtomata + +Language +== Lingvo + +General +== Ĝenerala + +Appearance +== Aspekto + +Graphics +== Grafikoj + +Sound +== Sono + +DDNet +== DDNet + +Assets +== Bildoj + +DDNet Client needs to be restarted to complete update! +== Vi devas relanci DDNet por kompletigi la ĝisdatigon. + +You must restart the game for all settings to take effect. +== Vi devas relanci la ludon por aktivigi ĉiujn agordojn. + +Show dummy actions +== Montri la agojn de la pupo + +Team message +== Mesaĝo de teamo + +Friend message +== Mesaĝo de amiko + +Normal message +== Normala mesaĝo + +Preview +== Antaŭrigardilo + +A Tee +== Tejo + +DDNet %s is available: +== DDNet %s estas disponebla: + +Update now +== Ĝisdatigi nun + +Updating... +== Ĝisdatiĝas... + +Check now +== Kontroli nun + +Discord +== Diskordo + +https://ddnet.tw/discord +== https://ddnet.tw/discord + +Learn +== Lerni + +https://wiki.ddnet.tw/ +== https://wiki.ddnet.tw/ + +Tutorial +== Lernilo + +Website +== Retejo + +Settings +== Agordoj + +Stop server +== Halti servilon + +Run server +== Lanci servilon + +Editor +== Redaktilo + +[Start menu] +Play +== Ludi + +DDNet %s is out! +== DDNet %s estas disponebla! + +Downloading %s: +== Elŝutas %s: + +Restart +== Relanci + +Spectators +== Spektantoj + +Red team +== Ruĝa teamo + +Blue team +== Blua teamo + +Follow +== Sekvi + +Deaths +== Mortoj + +1 new mention +== 1 nova mencio + +%d new mentions +== %d novaj mencioj + +9+ new mentions +== 9+ novaj mencioj + +Successfully saved the replay! +== + +Saving ddnet-settings.cfg failed +== + +Replay feature is disabled! +== + +The width of texture %s is not divisible by %d, or the height is not divisible by %d, which might cause visual bugs. +== + +The format of texture %s is not RGBA which will cause visual bugs. +== + +Preparing demo playback +== + +Initializing components +== + +Initializing assets +== + +Initializing map logic +== + +Sending initial client info +== + +Debug mode enabled. Press Ctrl+Shift+D to disable debug mode. +== + +Sudden Death +== + +Position: +== + +Angle: +== + +Server best: +== + +Personal best: +== + +Uploading map data to GPU +== + +Reset +== + +Demos +== + +Trying to determine UDP connectivity... +== + +UDP seems to be filtered. +== + +UDP and TCP IP addresses seem to be different. Try disabling VPN, proxy or network accelerators. +== + +No answer from server yet. +== + +Getting game info +== + +Requesting to join the game +== + +The server is running a non-standard tuning on a pure game type. +== + +Delete demo +== + +Are you sure that you want to delete the demo? +== + +Rename demo +== + +Render demo +== + +Replace video +== + +File already exists, do you want to overwrite it? +== + +Remove friend +== + +Are you sure that you want to remove the player from your friends list? +== + +Sound error +== + +The audio device couldn't be initialised. +== + +Password incorrect +== + +DDraceNetwork is a cooperative online game where the goal is for you and your group of tees to reach the finish line of the map. As a newcomer you should start on Novice servers, which host the easiest maps. Consider the ping to choose a server close to you. +== + +Use k key to kill (restart), q to pause and watch other players. See settings for other key binds. +== + +It's recommended that you check the settings to adjust them to your liking before joining a server. +== + +Unable to delete the demo +== + +Unable to rename the demo +== + +Destination file already exist +== + +Error loading demo +== + +Show ingame HUD +== + +Video name: +== + +Show DDNet map finishes in server browser +== + +Loading menu images +== + +Server filter +== + +Has people playing +== + +Server not full +== + +Strict gametype filter +== + +Player country: +== + +Filter connecting players +== + +Indicate map finish +== + +Unfinished map +== + +Types +== + +Reset filter +== + +Server details +== + +Leak IP +== + +Scoreboard +== + +Remove +== + +Info +== + +Demofile: %s +== + +Loading demo files +== + +Parent Folder +== + +Invalid Demo +== + +Demo details +== + +Created: +== + +Type: +== + +Length: +== -Player -== Ludanto +Markers: +== -Address -== Retadreso +Size: +== -Ping -== Latenco +%.2f MiB +== -Version -== Versio +%.2f KiB +== -Game info -== Ludaj informoj +Crc: +== -Game type -== Ludtipo +Netversion: +== -Map -== Mapo +Demo +== -Score limit +Markers == -Time limit +Length == -MOTD -== MDLT +Date +== -Change settings -== Ŝanĝi agordojn +Fetch Info +== -Kick player -== Elirigi ludanton +Demos directory +== -Move player to spectators -== Movi ludanton al spektantoj +Render +== -Force vote -== Forci voĉdonon +Stop record +== -Vote description: -== Voĉdona priskribo: +Record demo +== -Vote command: -== Voĉdona komando: +Score limit +== -Add -== Aldoni +Time limit +== Loading ghost files == -Time -== Tempo - Reload == @@ -739,9 +920,6 @@ Automatically create statboard csv Max CSVs == -Dummy settings -== Agordoj de la pupo - Your skin == @@ -775,33 +953,9 @@ Body Feet == -Skins -== Haŭtoj - -Skin Database -== Datumbazo de haŭtoj - -Skins directory -== Dosierujo de haŭtoj - Loading skin files == -Move left -== Movi maldekstren - -Move right -== Movi dekstren - -Jump -== Salti - -Fire -== Pafi - -Hook -== Hoki - Hook collisions == @@ -814,12 +968,6 @@ Zoom out Default zoom == -Show others -== Montri aliaj - -Show all -== Montri ĉiuj - Toggle dyncam == @@ -835,21 +983,12 @@ Dummy copy Hammerfly dummy == -Hammer -== Martelo - -Pistol -== Pistolo - Shotgun == Grenade == -Laser -== Lasero - Next weapon == @@ -945,9 +1084,6 @@ Controller Axis #%d Controls == -Mouse -== Muso - Ingame mouse sens. == @@ -960,18 +1096,12 @@ Controller Movement == -Weapon -== Batalilo - Reset to defaults == Voting == -Dummy -== Pupo - Miscellaneous == @@ -1002,9 +1132,6 @@ V-Sync may cause delay == -Screen -== Ekrano - FSAA samples == @@ -1023,18 +1150,12 @@ UI Color Renderer == -default -== defaŭlta - custom == Graphics cards == -auto -== aŭtomata - Play background music == @@ -1083,33 +1204,6 @@ Map sound volume Background music volume == -Language -== Lingvo - -General -== Ĝenerala - -Appearance -== Aspekto - -Graphics -== Grafikoj - -Sound -== Sono - -DDNet -== DDNet - -Assets -== Bildoj - -DDNet Client needs to be restarted to complete update! -== Vi devas relanci DDNet por kompletigi la ĝisdatigon. - -You must restart the game for all settings to take effect. -== Vi devas relanci la ludon por aktivigi ĉiujn agordojn. - Hue == @@ -1164,9 +1258,6 @@ Show DDRace HUD Show jumps indicator == -Show dummy actions -== Montri la agojn de la pupo - Show player position == @@ -1200,21 +1291,9 @@ System message Highlighted message == -Team message -== Mesaĝo de teamo - -Friend message -== Mesaĝo de amiko - -Normal message -== Normala mesaĝo - Client message == -Preview -== Antaŭrigardilo - Name plates size == @@ -1260,9 +1339,6 @@ Nothing hookable Something hookable == -A Tee -== Tejo - Normal Color == @@ -1365,24 +1441,12 @@ Run on join Chat command (e.g. showall 1) == -DDNet %s is available: -== DDNet %s estas disponebla: - -Update now -== Ĝisdatigi nun - -Updating... -== Ĝisdatiĝas... - DDNet Client updated! == No updates available == -Check now -== Kontroli nun - Entities == @@ -1401,58 +1465,15 @@ Loading assets Assets directory == -Discord -== Diskordo - -https://ddnet.tw/discord -== https://ddnet.tw/discord - -Learn -== Lerni - -https://wiki.ddnet.tw/ -== https://wiki.ddnet.tw/ - -Tutorial -== Lernilo - Can't find a Tutorial server == -Website -== Retejo - -Settings -== Agordoj - -Stop server -== Halti servilon - -Run server -== Lanci servilon - Server executable not found, can't run server == -Editor -== Redaktilo - -[Start menu] -Play -== Ludi - -DDNet %s is out! -== DDNet %s estas disponebla! - -Downloading %s: -== Elŝutas %s: - Update failed! Check log... == -Restart -== Relanci - Loading race demo files == @@ -1462,9 +1483,6 @@ Time limit: %d min Round == -Spectators -== Spektantoj - Game over == @@ -1501,24 +1519,12 @@ Red team wins! Blue team wins! == -Red team -== Ruĝa teamo - -Blue team -== Blua teamo - Loading sound files == -Follow -== Sekvi - Frags == -Deaths -== Mortoj - Suicides == @@ -1539,12 +1545,3 @@ Best Grabs == - -1 new mention -== 1 nova mencio - -%d new mentions -== %d novaj mencioj - -9+ new mentions -== 9+ novaj mencioj diff --git a/data/languages/finnish.txt b/data/languages/finnish.txt index 6071d9685a4..6426d1eee57 100644 --- a/data/languages/finnish.txt +++ b/data/languages/finnish.txt @@ -1238,9 +1238,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/french.txt b/data/languages/french.txt index 59d2faed007..7de291623d7 100644 --- a/data/languages/french.txt +++ b/data/languages/french.txt @@ -1474,21 +1474,57 @@ Highlight Color Extras == Extras -Preparing demo playback -== - Connected == Connecté +Initializing assets +== Initialisation des assets + +Getting game info +== Obtention des informations de la partie + +Requesting to join the game +== Demande de rejoindre la partie + +Loading skin files +== Chargement des fichiers de skin + +Appearance +== Apparence + +Show health, shields and ammo +== Monter la vie, bouclier et les munitions + +DDRace HUD +== HUD DDRace + +Show DDRace HUD +== Montrer l'HUD DDrace + +Show jumps indicator +== Montrer l'indicateur de sauts + +Hook collision line +== Ligne de collision du grapin + +A Tee +== Un Tee + +Loading assets +== Chargement des assets + +Loading sound files +== Chargement des fichiers sonores + +Preparing demo playback +== + Loading map file from storage == Initializing components == -Initializing assets -== Initialisation des assets - Initializing map logic == @@ -1498,15 +1534,6 @@ Sending initial client info Uploading map data to GPU == -Getting game info -== Obtention des informations de la partie - -Requesting to join the game -== Demande de rejoindre la partie - -Sending intial client info -== - Loading menu images == @@ -1516,39 +1543,18 @@ Loading demo files Loading ghost files == -Loading skin files -== Chargement des fichiers de skin - -Appearance -== Apparence - Name Plate == Hook Collisions == -Show health, shields and ammo -== Monter la vie, bouclier et les munitions - -DDRace HUD -== HUD DDRace - Show client IDs in scoreboard == -Show DDRace HUD -== Montrer l'HUD DDrace - -Show jumps indicator -== Montrer l'indicateur de sauts - Show hook strength indicator == -Hook collision line -== Ligne de collision du grapin - Hook collision line width == @@ -1567,14 +1573,5 @@ Nothing hookable Something hookable == -A Tee -== Un Tee - -Loading assets -== Chargement des assets - Loading race demo files == - -Loading sound files -== Chargement des fichiers sonores diff --git a/data/languages/german.txt b/data/languages/german.txt index e7cad3b1790..80d4e7a3cbf 100644 --- a/data/languages/german.txt +++ b/data/languages/german.txt @@ -1544,9 +1544,6 @@ Getting game info Requesting to join the game == Frage an dem Spiel beizutreten -Sending intial client info -== Sende initiale Client-Info - Loading menu images == Lade Menü-Bilder @@ -1573,3 +1570,4 @@ Loading race demo files Loading sound files == Lade Sound-Dateien + diff --git a/data/languages/greek.txt b/data/languages/greek.txt index 0eb636b8d9d..f7379972e79 100644 --- a/data/languages/greek.txt +++ b/data/languages/greek.txt @@ -700,9 +700,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/hungarian.txt b/data/languages/hungarian.txt index 4cb64a2d30c..2f5202c3df4 100644 --- a/data/languages/hungarian.txt +++ b/data/languages/hungarian.txt @@ -1474,9 +1474,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/italian.txt b/data/languages/italian.txt index e5a40a23efd..db343a68102 100644 --- a/data/languages/italian.txt +++ b/data/languages/italian.txt @@ -1266,9 +1266,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/japanese.txt b/data/languages/japanese.txt index 49694f09403..a2b2ab18b83 100644 --- a/data/languages/japanese.txt +++ b/data/languages/japanese.txt @@ -1292,9 +1292,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/korean.txt b/data/languages/korean.txt index 2e9a0f8a87c..8bded83fb7d 100644 --- a/data/languages/korean.txt +++ b/data/languages/korean.txt @@ -1490,9 +1490,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/kyrgyz.txt b/data/languages/kyrgyz.txt index 1a4d032159b..d5d4a8fa9be 100644 --- a/data/languages/kyrgyz.txt +++ b/data/languages/kyrgyz.txt @@ -691,9 +691,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/norwegian.txt b/data/languages/norwegian.txt index 863957b9981..b398b4b7424 100644 --- a/data/languages/norwegian.txt +++ b/data/languages/norwegian.txt @@ -1249,9 +1249,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Are you sure that you want to disconnect and switch to a different server? == diff --git a/data/languages/persian.txt b/data/languages/persian.txt index fca3ce156fe..d4e873382c4 100644 --- a/data/languages/persian.txt +++ b/data/languages/persian.txt @@ -861,9 +861,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - The server is running a non-standard tuning on a pure game type. == diff --git a/data/languages/polish.txt b/data/languages/polish.txt index c0ee64a0e08..097c1a238ec 100644 --- a/data/languages/polish.txt +++ b/data/languages/polish.txt @@ -1401,9 +1401,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/portuguese.txt b/data/languages/portuguese.txt index 93dda3e087b..9513c37c46e 100644 --- a/data/languages/portuguese.txt +++ b/data/languages/portuguese.txt @@ -1046,9 +1046,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Render demo == diff --git a/data/languages/romanian.txt b/data/languages/romanian.txt index 22477769b7e..9b60545e686 100644 --- a/data/languages/romanian.txt +++ b/data/languages/romanian.txt @@ -706,9 +706,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/russian.txt b/data/languages/russian.txt index e04b131a7e4..0fd776062bc 100644 --- a/data/languages/russian.txt +++ b/data/languages/russian.txt @@ -1491,9 +1491,6 @@ Getting game info Requesting to join the game == Запрашивается подключение к игре -Sending intial client info -== Отправка начальных данных о клиенте - Loading menu images == Загрузка изображений меню @@ -1565,3 +1562,4 @@ Loading race demo files Loading sound files == Загрузка звуковых файлов + diff --git a/data/languages/serbian.txt b/data/languages/serbian.txt index 7ff8dda73fc..89ae4c52080 100644 --- a/data/languages/serbian.txt +++ b/data/languages/serbian.txt @@ -713,9 +713,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/serbian_cyrillic.txt b/data/languages/serbian_cyrillic.txt index cca0340dd1c..d6dcf1197c4 100644 --- a/data/languages/serbian_cyrillic.txt +++ b/data/languages/serbian_cyrillic.txt @@ -1220,9 +1220,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Existing Player == diff --git a/data/languages/simplified_chinese.txt b/data/languages/simplified_chinese.txt index 91406f191c0..9b20f68732a 100644 --- a/data/languages/simplified_chinese.txt +++ b/data/languages/simplified_chinese.txt @@ -1510,9 +1510,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/slovak.txt b/data/languages/slovak.txt index 37e0dad7c54..d73e0e4235f 100644 --- a/data/languages/slovak.txt +++ b/data/languages/slovak.txt @@ -697,9 +697,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Reconnect in %d sec == diff --git a/data/languages/spanish.txt b/data/languages/spanish.txt index 97f5a7503b1..2f467ca6eaa 100644 --- a/data/languages/spanish.txt +++ b/data/languages/spanish.txt @@ -1497,9 +1497,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/swedish.txt b/data/languages/swedish.txt index 61e4ea58039..4efc910717f 100644 --- a/data/languages/swedish.txt +++ b/data/languages/swedish.txt @@ -1342,9 +1342,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Join Tutorial Server == diff --git a/data/languages/traditional_chinese.txt b/data/languages/traditional_chinese.txt index 815dad4e788..56c0cb237e5 100644 --- a/data/languages/traditional_chinese.txt +++ b/data/languages/traditional_chinese.txt @@ -1499,9 +1499,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Loading menu images == diff --git a/data/languages/turkish.txt b/data/languages/turkish.txt index acff86f84ea..06f59fccf1d 100644 --- a/data/languages/turkish.txt +++ b/data/languages/turkish.txt @@ -1146,9 +1146,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Existing Player == diff --git a/data/languages/ukrainian.txt b/data/languages/ukrainian.txt index c5c4dfbae69..c9dd894be1a 100644 --- a/data/languages/ukrainian.txt +++ b/data/languages/ukrainian.txt @@ -1325,9 +1325,6 @@ Getting game info Requesting to join the game == -Sending intial client info -== - Join Tutorial Server == diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 9212bc431d8..06077473188 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -675,7 +675,7 @@ int CGraphics_Threaded::LoadPNG(CImageInfo *pImg, const char *pFilename, int Sto First = false; } } - str_append(Warning.m_aWarningMsg, Localize(" unsupported"), sizeof(Warning.m_aWarningMsg)); + str_append(Warning.m_aWarningMsg, " unsupported", sizeof(Warning.m_aWarningMsg)); m_vWarnings.emplace_back(Warning); } } From 614a5b35bc4c58b06f9d564c97c8a0e90375e5bb Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Mon, 8 Aug 2022 16:37:17 +0200 Subject: [PATCH 07/72] Easter egg --- data/languages/arabic.txt | 3 +++ data/languages/belarusian.txt | 3 +++ data/languages/bosnian.txt | 3 +++ data/languages/brazilian_portuguese.txt | 3 +++ data/languages/bulgarian.txt | 3 +++ data/languages/catalan.txt | 3 +++ data/languages/chuvash.txt | 3 +++ data/languages/czech.txt | 3 +++ data/languages/danish.txt | 3 +++ data/languages/dutch.txt | 3 +++ data/languages/esperanto.txt | 3 +++ data/languages/finnish.txt | 3 +++ data/languages/french.txt | 3 +++ data/languages/german.txt | 2 ++ data/languages/greek.txt | 3 +++ data/languages/hungarian.txt | 3 +++ data/languages/italian.txt | 3 +++ data/languages/japanese.txt | 3 +++ data/languages/korean.txt | 3 +++ data/languages/kyrgyz.txt | 3 +++ data/languages/norwegian.txt | 3 +++ data/languages/persian.txt | 3 +++ data/languages/polish.txt | 3 +++ data/languages/portuguese.txt | 3 +++ data/languages/romanian.txt | 3 +++ data/languages/russian.txt | 2 ++ data/languages/serbian.txt | 3 +++ data/languages/serbian_cyrillic.txt | 3 +++ data/languages/simplified_chinese.txt | 3 +++ data/languages/slovak.txt | 3 +++ data/languages/spanish.txt | 3 +++ data/languages/swedish.txt | 3 +++ data/languages/traditional_chinese.txt | 3 +++ data/languages/turkish.txt | 3 +++ data/languages/ukrainian.txt | 3 +++ src/game/client/gameclient.cpp | 2 +- 36 files changed, 104 insertions(+), 1 deletion(-) diff --git a/data/languages/arabic.txt b/data/languages/arabic.txt index 6919cf38b72..8721eb1e20a 100644 --- a/data/languages/arabic.txt +++ b/data/languages/arabic.txt @@ -1195,6 +1195,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/belarusian.txt b/data/languages/belarusian.txt index 9720b234eef..d974a7947d6 100644 --- a/data/languages/belarusian.txt +++ b/data/languages/belarusian.txt @@ -631,6 +631,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/bosnian.txt b/data/languages/bosnian.txt index aa467acb2e5..c23fdb4b7c5 100644 --- a/data/languages/bosnian.txt +++ b/data/languages/bosnian.txt @@ -1057,6 +1057,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/brazilian_portuguese.txt b/data/languages/brazilian_portuguese.txt index 1cbbf024ac1..cdeee32a2cb 100644 --- a/data/languages/brazilian_portuguese.txt +++ b/data/languages/brazilian_portuguese.txt @@ -1479,6 +1479,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/bulgarian.txt b/data/languages/bulgarian.txt index b5b899aab83..a35340c752a 100644 --- a/data/languages/bulgarian.txt +++ b/data/languages/bulgarian.txt @@ -628,6 +628,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/catalan.txt b/data/languages/catalan.txt index 799e4fcd76d..76f4e17e968 100644 --- a/data/languages/catalan.txt +++ b/data/languages/catalan.txt @@ -1318,6 +1318,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/chuvash.txt b/data/languages/chuvash.txt index 3cb33c70390..e3e0af38e0f 100644 --- a/data/languages/chuvash.txt +++ b/data/languages/chuvash.txt @@ -631,6 +631,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/czech.txt b/data/languages/czech.txt index 10013c8004a..dfd41acb2e9 100644 --- a/data/languages/czech.txt +++ b/data/languages/czech.txt @@ -1208,6 +1208,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/danish.txt b/data/languages/danish.txt index 816caeb7288..71090f7635f 100644 --- a/data/languages/danish.txt +++ b/data/languages/danish.txt @@ -1206,6 +1206,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/dutch.txt b/data/languages/dutch.txt index b3ba97d403f..9dfd9644ac3 100644 --- a/data/languages/dutch.txt +++ b/data/languages/dutch.txt @@ -1367,6 +1367,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/esperanto.txt b/data/languages/esperanto.txt index 04921af0eef..41d3e96f535 100644 --- a/data/languages/esperanto.txt +++ b/data/languages/esperanto.txt @@ -608,6 +608,9 @@ The format of texture %s is not RGBA which will cause visual bugs. Preparing demo playback == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/finnish.txt b/data/languages/finnish.txt index 6426d1eee57..f918be4771c 100644 --- a/data/languages/finnish.txt +++ b/data/languages/finnish.txt @@ -1196,6 +1196,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/french.txt b/data/languages/french.txt index 7de291623d7..4cf9d2f4d19 100644 --- a/data/languages/french.txt +++ b/data/languages/french.txt @@ -1522,6 +1522,9 @@ Preparing demo playback Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/german.txt b/data/languages/german.txt index 80d4e7a3cbf..40c2fb22b33 100644 --- a/data/languages/german.txt +++ b/data/languages/german.txt @@ -1571,3 +1571,5 @@ Loading race demo files Loading sound files == Lade Sound-Dateien +Why are you slowmo replaying to read this? +== Warum spielst du das Replay in Slow-Motion um das zu lesen? diff --git a/data/languages/greek.txt b/data/languages/greek.txt index f7379972e79..e1b2887296b 100644 --- a/data/languages/greek.txt +++ b/data/languages/greek.txt @@ -637,6 +637,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/hungarian.txt b/data/languages/hungarian.txt index 2f5202c3df4..5c51307fc34 100644 --- a/data/languages/hungarian.txt +++ b/data/languages/hungarian.txt @@ -1453,6 +1453,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/italian.txt b/data/languages/italian.txt index db343a68102..8705b362b64 100644 --- a/data/languages/italian.txt +++ b/data/languages/italian.txt @@ -1224,6 +1224,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/japanese.txt b/data/languages/japanese.txt index a2b2ab18b83..0c1219bf0a7 100644 --- a/data/languages/japanese.txt +++ b/data/languages/japanese.txt @@ -1250,6 +1250,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/korean.txt b/data/languages/korean.txt index 8bded83fb7d..8574d4bbbe2 100644 --- a/data/languages/korean.txt +++ b/data/languages/korean.txt @@ -1469,6 +1469,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/kyrgyz.txt b/data/languages/kyrgyz.txt index d5d4a8fa9be..391c49752c1 100644 --- a/data/languages/kyrgyz.txt +++ b/data/languages/kyrgyz.txt @@ -628,6 +628,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/norwegian.txt b/data/languages/norwegian.txt index b398b4b7424..ac29688a1d4 100644 --- a/data/languages/norwegian.txt +++ b/data/languages/norwegian.txt @@ -1207,6 +1207,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/persian.txt b/data/languages/persian.txt index d4e873382c4..0b11f3c39e1 100644 --- a/data/languages/persian.txt +++ b/data/languages/persian.txt @@ -813,6 +813,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/polish.txt b/data/languages/polish.txt index 097c1a238ec..e68a1c1411e 100644 --- a/data/languages/polish.txt +++ b/data/languages/polish.txt @@ -1359,6 +1359,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/portuguese.txt b/data/languages/portuguese.txt index 9513c37c46e..fcd8df1f53d 100644 --- a/data/languages/portuguese.txt +++ b/data/languages/portuguese.txt @@ -995,6 +995,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/romanian.txt b/data/languages/romanian.txt index 9b60545e686..26f0136d06d 100644 --- a/data/languages/romanian.txt +++ b/data/languages/romanian.txt @@ -643,6 +643,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/russian.txt b/data/languages/russian.txt index 0fd776062bc..ff731a664cb 100644 --- a/data/languages/russian.txt +++ b/data/languages/russian.txt @@ -1563,3 +1563,5 @@ Loading race demo files Loading sound files == Загрузка звуковых файлов +Why are you slowmo replaying to read this? +== diff --git a/data/languages/serbian.txt b/data/languages/serbian.txt index 89ae4c52080..9d440a39080 100644 --- a/data/languages/serbian.txt +++ b/data/languages/serbian.txt @@ -650,6 +650,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/serbian_cyrillic.txt b/data/languages/serbian_cyrillic.txt index d6dcf1197c4..07dac2e05e4 100644 --- a/data/languages/serbian_cyrillic.txt +++ b/data/languages/serbian_cyrillic.txt @@ -1175,6 +1175,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/simplified_chinese.txt b/data/languages/simplified_chinese.txt index 9b20f68732a..69344eabcd6 100644 --- a/data/languages/simplified_chinese.txt +++ b/data/languages/simplified_chinese.txt @@ -1489,6 +1489,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/slovak.txt b/data/languages/slovak.txt index d73e0e4235f..a97aa1bfe6d 100644 --- a/data/languages/slovak.txt +++ b/data/languages/slovak.txt @@ -631,6 +631,9 @@ Loading map file from storage Loading DDNet Client == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/spanish.txt b/data/languages/spanish.txt index 2f467ca6eaa..ba886f9ef1b 100644 --- a/data/languages/spanish.txt +++ b/data/languages/spanish.txt @@ -1476,6 +1476,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/swedish.txt b/data/languages/swedish.txt index 4efc910717f..14adf85d80e 100644 --- a/data/languages/swedish.txt +++ b/data/languages/swedish.txt @@ -1300,6 +1300,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/traditional_chinese.txt b/data/languages/traditional_chinese.txt index 56c0cb237e5..05ce45cb056 100644 --- a/data/languages/traditional_chinese.txt +++ b/data/languages/traditional_chinese.txt @@ -1478,6 +1478,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/turkish.txt b/data/languages/turkish.txt index 06f59fccf1d..5a848a718a0 100644 --- a/data/languages/turkish.txt +++ b/data/languages/turkish.txt @@ -1098,6 +1098,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/data/languages/ukrainian.txt b/data/languages/ukrainian.txt index c9dd894be1a..3ca12f474ef 100644 --- a/data/languages/ukrainian.txt +++ b/data/languages/ukrainian.txt @@ -1283,6 +1283,9 @@ Connected Loading map file from storage == +Why are you slowmo replaying to read this? +== + Initializing components == diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 69ac47be072..7295c38e550 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -267,7 +267,7 @@ void CGameClient::OnInit() if(m_Menus.IsInit()) { char aBuff[256]; - str_format(aBuff, std::size(aBuff), "%s [%d/%d]", Localize("Initializing components"), (CompCounter + 1), (int)ComponentCount()); + str_format(aBuff, std::size(aBuff), "%s [%d/%d]", CompCounter == 40 ? Localize("Why are you slowmo replaying to read this?") : Localize("Initializing components"), (CompCounter + 1), (int)ComponentCount()); m_Menus.RenderLoading(pLoadingDDNetCaption, aBuff, 1 + SkippedComps); SkippedComps = 0; } From 20bfdba7fc78db7e6e38e42d5a94c36848c14b76 Mon Sep 17 00:00:00 2001 From: Cheeser0613 <54943099+Cheeser0613@users.noreply.github.com> Date: Mon, 8 Aug 2022 23:15:11 +0800 Subject: [PATCH 08/72] Update simplified_chinese.txt --- data/languages/simplified_chinese.txt | 85 ++++++++++++++------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/data/languages/simplified_chinese.txt b/data/languages/simplified_chinese.txt index 69344eabcd6..fdfe5396959 100644 --- a/data/languages/simplified_chinese.txt +++ b/data/languages/simplified_chinese.txt @@ -26,6 +26,7 @@ # 2022-06-16 cheeser0613 # 2022-06-27 cheeser0613 # 2022-07-04 cheeser0613 +# 2022-08-08 cheeser0613 ##### /authors ##### ##### translated strings ##### @@ -1418,13 +1419,13 @@ Ingame controller mode == 游戏内控制器瞄准模式 Ingame controller sens. -== 类比摇杆灵敏度(游戏) +== 摇杆灵敏度(游戏) UI controller sens. -== 类比摇杆灵敏度(界面) +== 摇杆灵敏度(界面) Controller jitter tolerance -== 类比摇杆错位容错 +== 摇杆死区 No controller found. Plug in a controller and restart the game. == 未检测到任何控制器。请尝试重新连接控制器并重启游戏。 @@ -1439,16 +1440,16 @@ Aim bind == 操作轴绑定 Controller Axis #%d -== 类比摇杆 #%d +== 摇杆 #%d Mouse -== 滑鼠 +== 鼠标 Ingame mouse sens. -== 滑鼠灵敏度(游戏) +== 鼠标灵敏度(游戏) UI mouse sens. -== 滑鼠灵敏度(界面) +== 鼠标灵敏度(界面) Controller == 控制器 @@ -1481,106 +1482,106 @@ Extras == 其他 Preparing demo playback -== +== 正在准备回放 Connected -== +== 连接成功 Loading map file from storage -== +== 正在从硬盘中加载地图文件 Why are you slowmo replaying to read this? -== +== 所以你为什么要慢速回放来看这个 Initializing components -== +== 正在初始化游戏引擎 Initializing assets -== +== 正在初始化资源 Initializing map logic -== +== 正在初始化地图逻辑 Sending initial client info -== +== 正在发送初始客户端信息 Uploading map data to GPU -== +== 正在将地图数据传输至显卡 Getting game info -== +== 正在获取游戏信息 Requesting to join the game -== +== 正在请求加入游戏 Loading menu images -== +== 正在加载主菜单图片 Loading demo files -== +== 正在加载回放文件 Loading ghost files -== +== 正在加载影子文件 Loading skin files -== +== 正在加载皮肤文件 Appearance -== +== 游戏界面 Name Plate -== +== 昵称板块 Hook Collisions -== +== 瞄准辅助 Show health, shields and ammo -== +== 显示生命、护甲与弹药栏 DDRace HUD -== +== DDRace HUD Show client IDs in scoreboard -== +== 显示客户端 IDs (计分板中) Show DDRace HUD -== +== 显示 DDRace HUD Show jumps indicator -== +== 显示可跳跃次数 Show hook strength indicator -== +== 显示对其他玩家的钩索强度 Hook collision line -== +== 瞄准辅助线 Hook collision line width -== +== 辅助线宽度 Hook collision line opacity -== +== 辅助线不透明度 Colors of the hook collision line, in case of a possible collision with: -== +== 辅助线颜色(当瞄准以下实体物时): Your movements are not taken into account when calculating the line colors -== +== 移动所造成的瞄准偏移将不计入考量 Nothing hookable -== +== 未瞄准任何实体物 Something hookable -== +== 可钩索的方块 A Tee -== +== 其他玩家 Loading assets -== +== 正在加载资源 Loading race demo files -== +== 正在加载回放文件 Loading sound files -== +== 正在加载声音文件 From 1a0ba4e5b69edeb1ab81f0888744540dfacbd9f8 Mon Sep 17 00:00:00 2001 From: Cheeser0613 <54943099+Cheeser0613@users.noreply.github.com> Date: Mon, 8 Aug 2022 23:16:05 +0800 Subject: [PATCH 09/72] Update traditional_chinese.txt --- data/languages/traditional_chinese.txt | 81 +++++++++++++------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/data/languages/traditional_chinese.txt b/data/languages/traditional_chinese.txt index 05ce45cb056..00927369b9c 100644 --- a/data/languages/traditional_chinese.txt +++ b/data/languages/traditional_chinese.txt @@ -15,6 +15,7 @@ # 2022-05-14 cheeser0613 # 2022-06-16 cheeser0613 # 2022-06-27 cheeser0613 +# 2022-08-08 cheeser0613 ##### /authors ##### ##### translated strings ##### @@ -1288,7 +1289,7 @@ Show local player's key presses == 顯示周圍玩家的按鍵輸入 Settings file -== 設定文件 +== 設定檔案 Config directory == 配置目錄 (cfg) @@ -1407,13 +1408,13 @@ Ingame controller mode == 游戲内控制器瞄準模式 Ingame controller sens. -== 類比搖桿靈敏度(游戲) +== 搖桿靈敏度(游戲) UI controller sens. -== 類比遙感靈敏度(界面) +== 搖桿靈敏度(界面) Controller jitter tolerance -== 類比搖桿錯位容錯 +== 搖桿錯位容錯 No controller found. Plug in a controller and restart the game. == 未檢測到任何控制器。請重試重新連接控制器並重啓游戲。 @@ -1428,7 +1429,7 @@ Aim bind == 操作軸綁定 Controller Axis #%d -== 類比搖桿 #%d +== 搖桿 #%d Mouse == 滑鼠 @@ -1470,106 +1471,106 @@ Extras == 其他 Preparing demo playback -== +== 正在準備回放 Connected -== +== 連接成功 Loading map file from storage -== +== 正在從硬盤中加載地圖檔案 Why are you slowmo replaying to read this? -== +== 所以你爲什麽要慢速回放來看這個 Initializing components -== +== 正在初始化游戲引擎 Initializing assets -== +== 正在初始化材質 Initializing map logic -== +== 正在初始化地圖邏輯 Sending initial client info -== +== 正在發送初始客戶端資訊 Uploading map data to GPU -== +== 正在將地圖數據傳輸至顯卡 Getting game info -== +== 正在獲取游戲資訊 Requesting to join the game -== +== 正在請求加入游戲 Loading menu images -== +== 正在加載主菜單圖片 Loading demo files -== +== 正在加載回放檔案 Loading ghost files -== +== 正在加載影子檔案 Loading skin files -== +== 正在加載外觀檔案 Appearance -== +== 游戲界面 Name Plate -== +== 匿稱板塊 Hook Collisions -== +== 瞄準輔助 Show health, shields and ammo -== +== 顯示生命、護甲與彈藥欄 DDRace HUD -== +== DDRace HUD Show client IDs in scoreboard -== +== 顯示客戶端 IDs (計分板中) Show DDRace HUD -== +== 顯示 DDRace HUD Show jumps indicator -== +== 顯示跳躍次數 Show hook strength indicator -== +== 顯示對其他玩家的鈎索强度 Hook collision line -== +== 瞄準輔助綫 Hook collision line width -== +== 輔助綫寬度 Hook collision line opacity -== +== 輔助綫不透明度 Colors of the hook collision line, in case of a possible collision with: -== +== 輔助綫顔色(當瞄準以下實體物時): Your movements are not taken into account when calculating the line colors -== +== 移動所造成的瞄準偏移將不計入考量 Nothing hookable -== +== 未瞄準任何實體物 Something hookable -== +== 可鈎索的方塊 A Tee -== +== 其他玩家 Loading assets -== +== 正在加載材質 Loading race demo files -== +== 正在加載回放檔案 Loading sound files -== +== 正在加載聲音檔案 From b99b861e1cd9f2729633b6dcccc20e3b35ab21e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 8 Aug 2022 22:30:14 +0200 Subject: [PATCH 10/72] Extract common expression into `CalcHashID` function --- src/engine/shared/snapshot.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/engine/shared/snapshot.cpp b/src/engine/shared/snapshot.cpp index 9dc755d5142..a94164bcf48 100644 --- a/src/engine/shared/snapshot.cpp +++ b/src/engine/shared/snapshot.cpp @@ -156,6 +156,11 @@ enum HASHLIST_SIZE = 256, }; +inline size_t CalcHashID(int Key) +{ + return ((Key >> 12) & 0xf0) | (Key & 0xf); +} + static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot) { for(int i = 0; i < HASHLIST_SIZE; i++) @@ -164,7 +169,7 @@ static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot) for(int i = 0; i < pSnapshot->NumItems(); i++) { int Key = pSnapshot->GetItem(i)->Key(); - int HashID = ((Key >> 12) & 0xf0) | (Key & 0xf); + size_t HashID = CalcHashID(Key); if(pHashlist[HashID].m_Num != 64) { pHashlist[HashID].m_aIndex[pHashlist[HashID].m_Num] = i; @@ -176,7 +181,7 @@ static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot) static int GetItemIndexHashed(int Key, const CItemList *pHashlist) { - int HashID = ((Key >> 12) & 0xf0) | (Key & 0xf); + size_t HashID = CalcHashID(Key); for(int i = 0; i < pHashlist[HashID].m_Num; i++) { if(pHashlist[HashID].m_aKeys[i] == Key) From 573aedc32336dcaf1d769630a8776f1b787e579f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 8 Aug 2022 22:31:48 +0200 Subject: [PATCH 11/72] Extract magic constant 64 into `HASHLIST_BUCKET_SIZE` --- src/engine/shared/snapshot.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/engine/shared/snapshot.cpp b/src/engine/shared/snapshot.cpp index a94164bcf48..54d6800338e 100644 --- a/src/engine/shared/snapshot.cpp +++ b/src/engine/shared/snapshot.cpp @@ -144,16 +144,17 @@ bool CSnapshot::IsValid(size_t ActualSize) const // CSnapshotDelta -struct CItemList +enum { - int m_Num; - int m_aKeys[64]; - int m_aIndex[64]; + HASHLIST_SIZE = 256, + HASHLIST_BUCKET_SIZE = 64, }; -enum +struct CItemList { - HASHLIST_SIZE = 256, + int m_Num; + int m_aKeys[HASHLIST_BUCKET_SIZE]; + int m_aIndex[HASHLIST_BUCKET_SIZE]; }; inline size_t CalcHashID(int Key) @@ -170,7 +171,7 @@ static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot) { int Key = pSnapshot->GetItem(i)->Key(); size_t HashID = CalcHashID(Key); - if(pHashlist[HashID].m_Num != 64) + if(pHashlist[HashID].m_Num < HASHLIST_BUCKET_SIZE) { pHashlist[HashID].m_aIndex[pHashlist[HashID].m_Num] = i; pHashlist[HashID].m_aKeys[pHashlist[HashID].m_Num] = Key; From 243ab7c2f04e8ad0cba86cf96da6df06918a8888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 8 Aug 2022 23:21:45 +0200 Subject: [PATCH 12/72] Use djb2 for snapshot item hashlist The previous hash function was heavily biased towards the hash buckets 64-79, making those buckets overflow faster, which results in snapshot CRC errors and lags. Using the djb2 hash yields an almost even distribution over the entire range of values. http://www.cse.yorku.ca/~oz/hash.html --- src/engine/shared/snapshot.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine/shared/snapshot.cpp b/src/engine/shared/snapshot.cpp index 54d6800338e..8f4100314a1 100644 --- a/src/engine/shared/snapshot.cpp +++ b/src/engine/shared/snapshot.cpp @@ -159,7 +159,11 @@ struct CItemList inline size_t CalcHashID(int Key) { - return ((Key >> 12) & 0xf0) | (Key & 0xf); + // djb2 (http://www.cse.yorku.ca/~oz/hash.html) + unsigned Hash = 5381; + for(unsigned Shift = 0; Shift < sizeof(int); Shift++) + Hash = ((Hash << 5) + Hash) + ((Key >> (Shift * 8)) & 0xFF); + return Hash % HASHLIST_SIZE; } static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot) From bc865ab087b7cbf0181a6d28bc166a090324fc3a Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 9 Aug 2022 17:44:09 +0200 Subject: [PATCH 13/72] Check transparency even for negative alpha --- src/game/client/components/maplayers.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 6c21603af28..b4add3538a0 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -1414,7 +1414,8 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, Rot = Channels.b / 180.0f * pi; } - bool NeedsFlush = QuadsRenderCount == gs_GraphicsMaxQuadsRenderCount || !(Color.a > 0); + const bool IsFullyTransparent = Color.a <= 0; + bool NeedsFlush = QuadsRenderCount == gs_GraphicsMaxQuadsRenderCount || IsFullyTransparent; if(NeedsFlush) { @@ -1422,14 +1423,14 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, s_vQuadRenderInfo.data(), QuadsRenderCount, CurQuadOffset); QuadsRenderCount = 0; CurQuadOffset = i; - if(Color.a == 0) + if(IsFullyTransparent) { // since this quad is ignored, the offset is the next quad ++CurQuadOffset; } } - if(Color.a > 0) + if(!IsFullyTransparent) { SQuadRenderInfo &QInfo = s_vQuadRenderInfo[QuadsRenderCount++]; QInfo.m_Color = Color; From 1e6fd6320434a3afcc4bfa9724e715c294d9683e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:27:42 +0200 Subject: [PATCH 14/72] Rename variables `id` to `KeyID` --- src/game/client/components/binds.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp index aaee3153ad3..df0c11f19c4 100644 --- a/src/game/client/components/binds.cpp +++ b/src/game/client/components/binds.cpp @@ -289,18 +289,18 @@ void CBinds::ConDumpBinds(IConsole::IResult *pResult, void *pUserData) const char *pKeyName = pResult->GetString(0); int Modifier; - int id = pBinds->GetBindSlot(pKeyName, &Modifier); - if(!id) + int KeyID = pBinds->GetBindSlot(pKeyName, &Modifier); + if(!KeyID) { str_format(aBuf, sizeof(aBuf), "key '%s' not found", pKeyName); pBinds->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf, gs_BindPrintColor); } else { - if(!pBinds->m_aapKeyBindings[Modifier][id]) - str_format(aBuf, sizeof(aBuf), "%s (%d) is not bound", pKeyName, id); + if(!pBinds->m_aapKeyBindings[Modifier][KeyID]) + str_format(aBuf, sizeof(aBuf), "%s (%d) is not bound", pKeyName, KeyID); else - str_format(aBuf, sizeof(aBuf), "%s (%d) = %s", pKeyName, id, pBinds->m_aapKeyBindings[Modifier][id]); + str_format(aBuf, sizeof(aBuf), "%s (%d) = %s", pKeyName, KeyID, pBinds->m_aapKeyBindings[Modifier][KeyID]); pBinds->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf, gs_BindPrintColor); } @@ -327,9 +327,9 @@ void CBinds::ConUnbind(IConsole::IResult *pResult, void *pUserData) CBinds *pBinds = (CBinds *)pUserData; const char *pKeyName = pResult->GetString(0); int Modifier; - int id = pBinds->GetBindSlot(pKeyName, &Modifier); + int KeyID = pBinds->GetBindSlot(pKeyName, &Modifier); - if(!id) + if(!KeyID) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "key %s not found", pKeyName); @@ -337,7 +337,7 @@ void CBinds::ConUnbind(IConsole::IResult *pResult, void *pUserData) return; } - pBinds->Bind(id, "", false, Modifier); + pBinds->Bind(KeyID, "", false, Modifier); } void CBinds::ConUnbindAll(IConsole::IResult *pResult, void *pUserData) From 05af632524fd4927944ec23ee9bd418455e652a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:34:52 +0200 Subject: [PATCH 15/72] Rename variables `v` to `Value` --- src/game/server/gamecontext.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 69c82c737b8..6155a097887 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2598,9 +2598,9 @@ void CGameContext::ConTuneDump(IConsole::IResult *pResult, void *pUserData) char aBuf[256]; for(int i = 0; i < pSelf->Tuning()->Num(); i++) { - float v; - pSelf->Tuning()->Get(i, &v); - str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->ms_apNames[i], v); + float Value; + pSelf->Tuning()->Get(i, &Value); + str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->ms_apNames[i], Value); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } } @@ -2635,9 +2635,9 @@ void CGameContext::ConTuneDumpZone(IConsole::IResult *pResult, void *pUserData) { for(int i = 0; i < pSelf->TuningList()[List].Num(); i++) { - float v; - pSelf->TuningList()[List].Get(i, &v); - str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, pSelf->TuningList()[List].ms_apNames[i], v); + float Value; + pSelf->TuningList()[List].Get(i, &Value); + str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, pSelf->TuningList()[List].ms_apNames[i], Value); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } } From 62445ac0067b3a0a094ad65bf574bc08cab6253a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:54:55 +0200 Subject: [PATCH 16/72] Remove unused `HermiteBasis1` function --- src/game/gamecore.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index fc29f420378..9b9396efbb8 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -48,11 +48,6 @@ bool CTuningParams::Get(const char *pName, float *pValue) const return false; } -float HermiteBasis1(float v) -{ - return 2 * v * v * v - 3 * v * v + 1; -} - float VelocityRamp(float Value, float Start, float Range, float Curvature) { if(Value < Start) From 1e10cd3c7dd88402b78c08eb3db80be86273214b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:59:52 +0200 Subject: [PATCH 17/72] Optimize conditional expression --- src/game/gamecore.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 9b9396efbb8..cdfe1dbf72e 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -117,12 +117,7 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) m_TriggeredEvents = 0; // get ground state - bool Grounded = false; - if(m_pCollision->CheckPoint(m_Pos.x + PhysicalSize() / 2, m_Pos.y + PhysicalSize() / 2 + 5)) - Grounded = true; - if(m_pCollision->CheckPoint(m_Pos.x - PhysicalSize() / 2, m_Pos.y + PhysicalSize() / 2 + 5)) - Grounded = true; - + const bool Grounded = m_pCollision->CheckPoint(m_Pos.x + PhysicalSize() / 2, m_Pos.y + PhysicalSize() / 2 + 5) || m_pCollision->CheckPoint(m_Pos.x - PhysicalSize() / 2, m_Pos.y + PhysicalSize() / 2 + 5); vec2 TargetDirection = normalize(vec2(m_Input.m_TargetX, m_Input.m_TargetY)); m_Vel.y += m_Tuning.m_Gravity; From a8e3ac1184c94912844ecf14a0ab9924aa6c3dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 17:42:23 +0200 Subject: [PATCH 18/72] Minor refactoring: use `int64_t` instead of `long long` --- src/game/client/components/console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index ba311759bf7..25f92c738d5 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -448,7 +448,7 @@ CGameConsole::~CGameConsole() float CGameConsole::TimeNow() { - static long long s_TimeStart = time_get(); + static int64_t s_TimeStart = time_get(); return float(time_get() - s_TimeStart) / float(time_freq()); } From d003cc6ee26f521c29d8bdc742a277eed359af90 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Tue, 9 Aug 2022 23:42:20 +0200 Subject: [PATCH 19/72] Use current backlog page instead of old (fixes #5719) Better fix by Robyt3 --- src/game/client/components/console.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 25f92c738d5..33aea863b61 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -760,10 +760,8 @@ void CGameConsole::OnRender() } static int s_LastActivePage = pConsole->m_BacklogCurPage; - if(pConsole->m_BacklogCurPage == INT_MAX) - s_LastActivePage = INT_MAX; int TotalPages = 1; - for(int Page = 0; Page <= s_LastActivePage; ++Page, OffsetY = 0.0f) + for(int Page = 0; Page <= maximum(s_LastActivePage, pConsole->m_BacklogCurPage); ++Page, OffsetY = 0.0f) { while(pEntry) { From ca31b495a9ddfa4d28483c51259f82de2462d8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:28:03 +0200 Subject: [PATCH 20/72] Rename `dump_binds` command to `binds`, fix typo in description --- src/game/client/components/binds.cpp | 4 ++-- src/game/client/components/binds.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp index df0c11f19c4..fbabf181dba 100644 --- a/src/game/client/components/binds.cpp +++ b/src/game/client/components/binds.cpp @@ -254,7 +254,7 @@ void CBinds::OnConsoleInit() pConfigManager->RegisterCallback(ConfigSaveCallback, this); Console()->Register("bind", "s[key] r[command]", CFGFLAG_CLIENT, ConBind, this, "Bind key to execute the command"); - Console()->Register("dump_binds", "?s[key]", CFGFLAG_CLIENT, ConDumpBinds, this, "Print command executed by this keybindind or all binds"); + Console()->Register("binds", "?s[key]", CFGFLAG_CLIENT, ConBinds, this, "Print command executed by this keybinding or all binds"); Console()->Register("unbind", "s[key]", CFGFLAG_CLIENT, ConUnbind, this, "Unbind key"); Console()->Register("unbindall", "", CFGFLAG_CLIENT, ConUnbindAll, this, "Unbind all keys"); @@ -280,7 +280,7 @@ void CBinds::ConBind(IConsole::IResult *pResult, void *pUserData) pBinds->Bind(KeyID, pResult->GetString(1), false, Modifier); } -void CBinds::ConDumpBinds(IConsole::IResult *pResult, void *pUserData) +void CBinds::ConBinds(IConsole::IResult *pResult, void *pUserData) { CBinds *pBinds = (CBinds *)pUserData; if(pResult->NumArguments() == 1) diff --git a/src/game/client/components/binds.h b/src/game/client/components/binds.h index 268df2d27e6..300d671bf43 100644 --- a/src/game/client/components/binds.h +++ b/src/game/client/components/binds.h @@ -15,7 +15,7 @@ class CBinds : public CComponent int GetKeyID(const char *pKeyName); static void ConBind(IConsole::IResult *pResult, void *pUserData); - static void ConDumpBinds(IConsole::IResult *pResult, void *pUserData); + static void ConBinds(IConsole::IResult *pResult, void *pUserData); static void ConUnbind(IConsole::IResult *pResult, void *pUserData); static void ConUnbindAll(IConsole::IResult *pResult, void *pUserData); class IConsole *GetConsole() const { return Console(); } From 43fdeb8468a1353c5818fd2c28972a515da4de9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:34:07 +0200 Subject: [PATCH 21/72] Rename `tune_dump` to `tunes`, improve descriptions --- src/game/client/gameclient.cpp | 4 ++-- src/game/server/gamecontext.cpp | 6 +++--- src/game/server/gamecontext.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 796f66ba14b..07f15fa87f9 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -164,8 +164,8 @@ void CGameClient::OnConsoleInit() // register server dummy commands for tab completion Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value"); - Console()->Register("tune_reset", "", CFGFLAG_SERVER, 0, 0, "Reset tuning"); - Console()->Register("tune_dump", "", CFGFLAG_SERVER, 0, 0, "Dump tuning"); + Console()->Register("tune_reset", "", CFGFLAG_SERVER, 0, 0, "Reset all tuning variables to defaults"); + Console()->Register("tunes", "", CFGFLAG_SERVER, 0, 0, "List all tuning variables and their values"); Console()->Register("change_map", "?r[map]", CFGFLAG_SERVER, 0, 0, "Change map"); Console()->Register("restart", "?i[seconds]", CFGFLAG_SERVER, 0, 0, "Restart in x seconds"); Console()->Register("broadcast", "r[message]", CFGFLAG_SERVER, 0, 0, "Broadcast message"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 6155a097887..413c446c028 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2592,7 +2592,7 @@ void CGameContext::ConTuneReset(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "Tuning reset"); } -void CGameContext::ConTuneDump(IConsole::IResult *pResult, void *pUserData) +void CGameContext::ConTunes(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; char aBuf[256]; @@ -3142,8 +3142,8 @@ void CGameContext::OnConsoleInit() Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value"); Console()->Register("toggle_tune", "s[tuning] i[value 1] i[value 2]", CFGFLAG_SERVER | CFGFLAG_GAME, ConToggleTuneParam, this, "Toggle tune variable"); - Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Reset tuning"); - Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "Dump tuning"); + Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Reset all tuning variables to defaults"); + Console()->Register("tunes", "", CFGFLAG_SERVER, ConTunes, this, "List all tuning variables and their values"); Console()->Register("tune_zone", "i[zone] s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneZone, this, "Tune in zone a variable to value"); Console()->Register("tune_zone_dump", "i[zone]", CFGFLAG_SERVER, ConTuneDumpZone, this, "Dump zone tuning in zone x"); Console()->Register("tune_zone_reset", "?i[zone]", CFGFLAG_SERVER, ConTuneResetZone, this, "reset zone tuning in zone x or in all zones"); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index c2f4b8263b1..6e5172ddfe6 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -90,7 +90,7 @@ class CGameContext : public IGameServer static void ConTuneParam(IConsole::IResult *pResult, void *pUserData); static void ConToggleTuneParam(IConsole::IResult *pResult, void *pUserData); static void ConTuneReset(IConsole::IResult *pResult, void *pUserData); - static void ConTuneDump(IConsole::IResult *pResult, void *pUserData); + static void ConTunes(IConsole::IResult *pResult, void *pUserData); static void ConTuneZone(IConsole::IResult *pResult, void *pUserData); static void ConTuneDumpZone(IConsole::IResult *pResult, void *pUserData); static void ConTuneResetZone(IConsole::IResult *pResult, void *pUserData); From 54aff0228653eb837f3400a1f18eab38814693b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:41:00 +0200 Subject: [PATCH 22/72] Add success/error message to `dump_(local|remote)_console` commands --- src/game/client/components/console.cpp | 33 +++++++++++++++++--------- src/game/client/components/console.h | 1 + 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 33aea863b61..70d77024bd3 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -83,9 +83,15 @@ CGameConsole::CInstance::CInstance(int Type) m_Type = Type; if(Type == CGameConsole::CONSOLETYPE_LOCAL) + { + m_pName = "local_console"; m_CompletionFlagmask = CFGFLAG_CLIENT; + } else + { + m_pName = "remote_console"; m_CompletionFlagmask = CFGFLAG_SERVER; + } m_aCompletionBuffer[0] = 0; m_CompletionUsed = false; @@ -922,23 +928,28 @@ void CGameConsole::Toggle(int Type) void CGameConsole::Dump(int Type) { CInstance *pConsole = Type == CONSOLETYPE_REMOTE ? &m_RemoteConsole : &m_LocalConsole; + char aBuf[IO_MAX_PATH_LENGTH + 64]; char aFilename[IO_MAX_PATH_LENGTH]; - char aDate[20]; - - str_timestamp(aDate, sizeof(aDate)); - str_format(aFilename, sizeof(aFilename), "dumps/%s_dump_%s.txt", Type == CONSOLETYPE_REMOTE ? "remote_console" : "local_console", aDate); - IOHANDLE io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); - if(io) + str_timestamp(aBuf, sizeof(aBuf)); + str_format(aFilename, sizeof(aFilename), "dumps/%s_dump_%s.txt", pConsole->m_pName, aBuf); + IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); + if(File) { pConsole->m_BacklogLock.lock(); for(CInstance::CBacklogEntry *pEntry = pConsole->m_Backlog.First(); pEntry; pEntry = pConsole->m_Backlog.Next(pEntry)) { - io_write(io, pEntry->m_aText, str_length(pEntry->m_aText)); - io_write_newline(io); + io_write(File, pEntry->m_aText, str_length(pEntry->m_aText)); + io_write_newline(File); } pConsole->m_BacklogLock.unlock(); - io_close(io); + io_close(File); + str_format(aBuf, sizeof(aBuf), "%s contents were written to '%s'", pConsole->m_pName, aFilename); + } + else + { + str_format(aBuf, sizeof(aBuf), "Failed to open '%s'", aFilename); } + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); } void CGameConsole::ConToggleLocalConsole(IConsole::IResult *pResult, void *pUserData) @@ -1014,8 +1025,8 @@ void CGameConsole::OnConsoleInit() Console()->Register("toggle_remote_console", "", CFGFLAG_CLIENT, ConToggleRemoteConsole, this, "Toggle remote console"); Console()->Register("clear_local_console", "", CFGFLAG_CLIENT, ConClearLocalConsole, this, "Clear local console"); Console()->Register("clear_remote_console", "", CFGFLAG_CLIENT, ConClearRemoteConsole, this, "Clear remote console"); - Console()->Register("dump_local_console", "", CFGFLAG_CLIENT, ConDumpLocalConsole, this, "Dump local console"); - Console()->Register("dump_remote_console", "", CFGFLAG_CLIENT, ConDumpRemoteConsole, this, "Dump remote console"); + Console()->Register("dump_local_console", "", CFGFLAG_CLIENT, ConDumpLocalConsole, this, "Write local console contents to a text file"); + Console()->Register("dump_remote_console", "", CFGFLAG_CLIENT, ConDumpRemoteConsole, this, "Write remote console contents to a text file"); Console()->Register("console_page_up", "", CFGFLAG_CLIENT, ConConsolePageUp, this, "Previous page in console"); Console()->Register("console_page_down", "", CFGFLAG_CLIENT, ConConsolePageDown, this, "Next page in console"); diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index 833ded971de..248c19543a4 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -38,6 +38,7 @@ class CGameConsole : public CComponent char *m_pHistoryEntry; CLineInput m_Input; + const char *m_pName; int m_Type; int m_CompletionEnumerationCount; int m_BacklogCurPage; From 46ec2e0a24a27dbfb12e80c2688a0d466f5c87c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:43:20 +0200 Subject: [PATCH 23/72] Print incorrect tuning parameter name on error --- src/game/server/gamecontext.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 413c446c028..36574cfaf9b 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2552,15 +2552,18 @@ void CGameContext::ConTuneParam(IConsole::IResult *pResult, void *pUserData) const char *pParamName = pResult->GetString(0); float NewValue = pResult->GetFloat(1); + char aBuf[256]; if(pSelf->Tuning()->Set(pParamName, NewValue)) { - char aBuf[256]; str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); pSelf->SendTuningParams(-1); } else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "No such tuning parameter"); + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); + } } void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserData) @@ -2569,9 +2572,11 @@ void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserDat const char *pParamName = pResult->GetString(0); float OldValue; + char aBuf[256]; if(!pSelf->Tuning()->Get(pParamName, &OldValue)) { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "No such tuning parameter"); + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); return; } @@ -2579,7 +2584,6 @@ void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserDat pSelf->Tuning()->Set(pParamName, NewValue); - char aBuf[256]; str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); pSelf->SendTuningParams(-1); @@ -2614,15 +2618,17 @@ void CGameContext::ConTuneZone(IConsole::IResult *pResult, void *pUserData) if(List >= 0 && List < NUM_TUNEZONES) { + char aBuf[256]; if(pSelf->TuningList()[List].Set(pParamName, NewValue)) { - char aBuf[256]; str_format(aBuf, sizeof(aBuf), "%s in zone %d changed to %.2f", pParamName, List, NewValue); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); pSelf->SendTuningParams(-1, List); } else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "No such tuning parameter"); + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + } + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } } From e3bb8bc37079c8a152b1548a076fb92ca752eb91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:47:04 +0200 Subject: [PATCH 24/72] Allow `tune_reset` to reset a single tune Extend `tune_reset` so a single tuning value can be reset to default. For example `tune_reset player_collision` will reset just the `player_collision` tuning, whereas `tune_reset` will reset all to defaults like before. --- src/game/client/gameclient.cpp | 2 +- src/game/server/gamecontext.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 07f15fa87f9..5d8debd9d48 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -164,7 +164,7 @@ void CGameClient::OnConsoleInit() // register server dummy commands for tab completion Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value"); - Console()->Register("tune_reset", "", CFGFLAG_SERVER, 0, 0, "Reset all tuning variables to defaults"); + Console()->Register("tune_reset", "?s[tuning]", CFGFLAG_SERVER, 0, 0, "Reset all or one tuning variable to default"); Console()->Register("tunes", "", CFGFLAG_SERVER, 0, 0, "List all tuning variables and their values"); Console()->Register("change_map", "?r[map]", CFGFLAG_SERVER, 0, 0, "Change map"); Console()->Register("restart", "?i[seconds]", CFGFLAG_SERVER, 0, 0, "Restart in x seconds"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 36574cfaf9b..120898ecbda 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2592,8 +2592,28 @@ void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserDat void CGameContext::ConTuneReset(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - pSelf->ResetTuning(); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "Tuning reset"); + if(pResult->NumArguments()) + { + const char *pParamName = pResult->GetString(0); + float DefaultValue = 0.0f; + char aBuf[256]; + CTuningParams TuningParams; + if(TuningParams.Get(pParamName, &DefaultValue) && pSelf->Tuning()->Set(pParamName, DefaultValue)) + { + str_format(aBuf, sizeof(aBuf), "%s reset to %.2f", pParamName, DefaultValue); + pSelf->SendTuningParams(-1); + } + else + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + } + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); + } + else + { + pSelf->ResetTuning(); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "Tuning reset"); + } } void CGameContext::ConTunes(IConsole::IResult *pResult, void *pUserData) @@ -3148,7 +3168,7 @@ void CGameContext::OnConsoleInit() Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value"); Console()->Register("toggle_tune", "s[tuning] i[value 1] i[value 2]", CFGFLAG_SERVER | CFGFLAG_GAME, ConToggleTuneParam, this, "Toggle tune variable"); - Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Reset all tuning variables to defaults"); + Console()->Register("tune_reset", "?s[tuning]", CFGFLAG_SERVER, ConTuneReset, this, "Reset all or one tuning variable to default"); Console()->Register("tunes", "", CFGFLAG_SERVER, ConTunes, this, "List all tuning variables and their values"); Console()->Register("tune_zone", "i[zone] s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneZone, this, "Tune in zone a variable to value"); Console()->Register("tune_zone_dump", "i[zone]", CFGFLAG_SERVER, ConTuneDumpZone, this, "Dump zone tuning in zone x"); From 56d6290734deccf79cf251a9a3ae0a22cc24437c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:49:05 +0200 Subject: [PATCH 25/72] Print the actual tuning value after setting it Get the actual tuning value after setting it, as the value that was applied may differ due to overflow or rounding errors. --- src/game/server/gamecontext.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 120898ecbda..c3edf2e97f0 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2553,7 +2553,7 @@ void CGameContext::ConTuneParam(IConsole::IResult *pResult, void *pUserData) float NewValue = pResult->GetFloat(1); char aBuf[256]; - if(pSelf->Tuning()->Set(pParamName, NewValue)) + if(pSelf->Tuning()->Set(pParamName, NewValue) && pSelf->Tuning()->Get(pParamName, &NewValue)) { str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); @@ -2583,6 +2583,7 @@ void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserDat float NewValue = fabs(OldValue - pResult->GetFloat(1)) < 0.0001f ? pResult->GetFloat(2) : pResult->GetFloat(1); pSelf->Tuning()->Set(pParamName, NewValue); + pSelf->Tuning()->Get(pParamName, &NewValue); str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); @@ -2598,7 +2599,7 @@ void CGameContext::ConTuneReset(IConsole::IResult *pResult, void *pUserData) float DefaultValue = 0.0f; char aBuf[256]; CTuningParams TuningParams; - if(TuningParams.Get(pParamName, &DefaultValue) && pSelf->Tuning()->Set(pParamName, DefaultValue)) + if(TuningParams.Get(pParamName, &DefaultValue) && pSelf->Tuning()->Set(pParamName, DefaultValue) && pSelf->Tuning()->Get(pParamName, &DefaultValue)) { str_format(aBuf, sizeof(aBuf), "%s reset to %.2f", pParamName, DefaultValue); pSelf->SendTuningParams(-1); @@ -2639,7 +2640,7 @@ void CGameContext::ConTuneZone(IConsole::IResult *pResult, void *pUserData) if(List >= 0 && List < NUM_TUNEZONES) { char aBuf[256]; - if(pSelf->TuningList()[List].Set(pParamName, NewValue)) + if(pSelf->TuningList()[List].Set(pParamName, NewValue) && pSelf->TuningList()[List].Get(pParamName, &NewValue)) { str_format(aBuf, sizeof(aBuf), "%s in zone %d changed to %.2f", pParamName, List, NewValue); pSelf->SendTuningParams(-1, List); From 85a41f46dc657e581c504d4457cd33a912110bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:52:20 +0200 Subject: [PATCH 26/72] Allow `tune` command to list current tuning parameter value Extend `tune` so the current value of a given tuning variable is printed if no new value is given, so it works like commands in the console. For example `tune player_collision` will print the current value of the variable, whereas `tune player_collision 0` will change the value like before. --- src/game/client/gameclient.cpp | 2 +- src/game/server/gamecontext.cpp | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 5d8debd9d48..a0098ba8514 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -163,7 +163,7 @@ void CGameClient::OnConsoleInit() Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself to restart"); // register server dummy commands for tab completion - Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value"); + Console()->Register("tune", "s[tuning] ?i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value or show current value"); Console()->Register("tune_reset", "?s[tuning]", CFGFLAG_SERVER, 0, 0, "Reset all or one tuning variable to default"); Console()->Register("tunes", "", CFGFLAG_SERVER, 0, 0, "List all tuning variables and their values"); Console()->Register("change_map", "?r[map]", CFGFLAG_SERVER, 0, 0, "Change map"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index c3edf2e97f0..baa456dd338 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2550,20 +2550,34 @@ void CGameContext::ConTuneParam(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; const char *pParamName = pResult->GetString(0); - float NewValue = pResult->GetFloat(1); char aBuf[256]; - if(pSelf->Tuning()->Set(pParamName, NewValue) && pSelf->Tuning()->Get(pParamName, &NewValue)) + if(pResult->NumArguments() == 2) { - str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); - pSelf->SendTuningParams(-1); + float NewValue = pResult->GetFloat(1); + if(pSelf->Tuning()->Set(pParamName, NewValue) && pSelf->Tuning()->Get(pParamName, &NewValue)) + { + str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); + pSelf->SendTuningParams(-1); + } + else + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + } } else { - str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); + float Value; + if(pSelf->Tuning()->Get(pParamName, &Value)) + { + str_format(aBuf, sizeof(aBuf), "%s %.2f", pParamName, Value); + } + else + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + } } + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserData) @@ -3167,7 +3181,7 @@ void CGameContext::OnConsoleInit() m_pEngine = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); - Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value"); + Console()->Register("tune", "s[tuning] ?i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value or show current value"); Console()->Register("toggle_tune", "s[tuning] i[value 1] i[value 2]", CFGFLAG_SERVER | CFGFLAG_GAME, ConToggleTuneParam, this, "Toggle tune variable"); Console()->Register("tune_reset", "?s[tuning]", CFGFLAG_SERVER, ConTuneReset, this, "Reset all or one tuning variable to default"); Console()->Register("tunes", "", CFGFLAG_SERVER, ConTunes, this, "List all tuning variables and their values"); From 680abb6405be4b9b0bf088a2e0d3b5604aaffba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 17:05:28 +0200 Subject: [PATCH 27/72] Encapsulate `CTuningParams::ms_apNames` with `CTuningParams::Name` --- src/game/client/components/debughud.cpp | 2 +- src/game/gamecore.cpp | 4 ++-- src/game/gamecore.h | 5 +++-- src/game/server/gamecontext.cpp | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/game/client/components/debughud.cpp b/src/game/client/components/debughud.cpp index 21507f3228c..2d4cb8d3957 100644 --- a/src/game/client/components/debughud.cpp +++ b/src/game/client/components/debughud.cpp @@ -119,7 +119,7 @@ void CDebugHud::RenderTuning() TextRender()->Text(0x0, x - w, y + Count * 6, 5, aBuf, -1.0f); x += 5.0f; - TextRender()->Text(0x0, x, y + Count * 6, 5, CTuningParams::ms_apNames[i], -1.0f); + TextRender()->Text(0x0, x, y + Count * 6, 5, CTuningParams::Name(i), -1.0f); Count++; } diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index cdfe1dbf72e..d3bdb5bcd02 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -34,7 +34,7 @@ bool CTuningParams::Get(int Index, float *pValue) const bool CTuningParams::Set(const char *pName, float Value) { for(int i = 0; i < Num(); i++) - if(str_comp_nocase(pName, ms_apNames[i]) == 0) + if(str_comp_nocase(pName, Name(i)) == 0) return Set(i, Value); return false; } @@ -42,7 +42,7 @@ bool CTuningParams::Set(const char *pName, float Value) bool CTuningParams::Get(const char *pName, float *pValue) const { for(int i = 0; i < Num(); i++) - if(str_comp_nocase(pName, ms_apNames[i]) == 0) + if(str_comp_nocase(pName, Name(i)) == 0) return Get(i, pValue); return false; diff --git a/src/game/gamecore.h b/src/game/gamecore.h index 41bcd2abc34..411a624e959 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -40,6 +40,8 @@ class CTuneParam class CTuningParams { + static const char *ms_apNames[]; + public: CTuningParams() { @@ -49,8 +51,6 @@ class CTuningParams #undef MACRO_TUNING_PARAM } - static const char *ms_apNames[]; - #define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) CTuneParam m_##Name; #include "tuning.h" #undef MACRO_TUNING_PARAM @@ -63,6 +63,7 @@ class CTuningParams bool Set(const char *pName, float Value); bool Get(int Index, float *pValue) const; bool Get(const char *pName, float *pValue) const; + static const char *Name(int Index) { return ms_apNames[Index]; } }; inline void StrToInts(int *pInts, int Num, const char *pStr) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index baa456dd338..628d1e60674 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2639,7 +2639,7 @@ void CGameContext::ConTunes(IConsole::IResult *pResult, void *pUserData) { float Value; pSelf->Tuning()->Get(i, &Value); - str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->ms_apNames[i], Value); + str_format(aBuf, sizeof(aBuf), "%s %.2f", CTuningParams::Name(i), Value); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } } @@ -2678,7 +2678,7 @@ void CGameContext::ConTuneDumpZone(IConsole::IResult *pResult, void *pUserData) { float Value; pSelf->TuningList()[List].Get(i, &Value); - str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, pSelf->TuningList()[List].ms_apNames[i], Value); + str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, CTuningParams::Name(i), Value); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } } From f3eb93b83ad3a9ea6351a71e29a71a48c5e4a030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 17:26:57 +0200 Subject: [PATCH 28/72] Extend `IConsole::PossibleCommands`, add index to callback `PossibleCommands` now passes the item index to the callback and returns the total number of items. Add `EmptyPossibleCommandCallback` as default parameter. --- src/engine/console.h | 6 ++++-- src/engine/shared/console.cpp | 9 +++++++-- src/engine/shared/console.h | 2 +- src/game/client/components/console.cpp | 16 ++++++---------- src/game/client/components/console.h | 5 ++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/engine/console.h b/src/engine/console.h index 1a7e41d6d93..c7cbe15d489 100644 --- a/src/engine/console.h +++ b/src/engine/console.h @@ -82,14 +82,16 @@ class IConsole : public IInterface typedef void (*FTeeHistorianCommandCallback)(int ClientID, int FlagMask, const char *pCmd, IResult *pResult, void *pUser); typedef void (*FPrintCallback)(const char *pStr, void *pUser, ColorRGBA PrintColor); - typedef void (*FPossibleCallback)(const char *pCmd, void *pUser); + typedef void (*FPossibleCallback)(int Index, const char *pCmd, void *pUser); typedef void (*FCommandCallback)(IResult *pResult, void *pUserData); typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData); + static void EmptyPossibleCommandCallback(int Index, const char *pCmd, void *pUser) {} + virtual void Init() = 0; virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const = 0; virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) = 0; - virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) = 0; + virtual int PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback = EmptyPossibleCommandCallback, void *pUser = nullptr) = 0; virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0; virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) = 0; diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index ff7dd27f0c3..618f2f27b4c 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -551,16 +551,21 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo } } -void CConsole::PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) +int CConsole::PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) { + int Index = 0; for(CCommand *pCommand = m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext) { if(pCommand->m_Flags & FlagMask && pCommand->m_Temp == Temp) { if(str_find_nocase(pCommand->m_pName, pStr)) - pfnCallback(pCommand->m_pName, pUser); + { + pfnCallback(Index, pCommand->m_pName, pUser); + Index++; + } } } + return Index; } CConsole::CCommand *CConsole::FindCommand(const char *pName, int FlagMask) diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index 47fd4b3f07a..45ce408d687 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -196,7 +196,7 @@ class CConsole : public IConsole void Init() override; const CCommandInfo *FirstCommandInfo(int AccessLevel, int FlagMask) const override; const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) override; - void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) override; + int PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) override; void ParseArguments(int NumArgs, const char **ppArguments) override; void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) override; diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 70d77024bd3..69d1c426c77 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -161,12 +161,11 @@ void CGameConsole::CInstance::ExecuteLine(const char *pLine) } } -void CGameConsole::CInstance::PossibleCommandsCompleteCallback(const char *pStr, void *pUser) +void CGameConsole::CInstance::PossibleCommandsCompleteCallback(int Index, const char *pStr, void *pUser) { CGameConsole::CInstance *pInstance = (CGameConsole::CInstance *)pUser; - if(pInstance->m_CompletionChosen == pInstance->m_CompletionEnumerationCount) + if(pInstance->m_CompletionChosen == Index) pInstance->m_Input.Set(pStr); - pInstance->m_CompletionEnumerationCount++; } void CGameConsole::CInstance::OnInput(IInput::CEvent Event) @@ -335,16 +334,13 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) m_CompletionChosen--; else if(!m_ReverseTAB) m_CompletionChosen++; - m_CompletionEnumerationCount = 0; - m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this); - + int CompletionEnumerationCount = m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this); m_CompletionUsed = true; // handle wrapping - if(m_CompletionEnumerationCount && (m_CompletionChosen >= m_CompletionEnumerationCount || m_CompletionChosen < 0)) + if(CompletionEnumerationCount && (m_CompletionChosen >= CompletionEnumerationCount || m_CompletionChosen < 0)) { - m_CompletionChosen = (m_CompletionChosen + m_CompletionEnumerationCount) % m_CompletionEnumerationCount; - m_CompletionEnumerationCount = 0; + m_CompletionChosen = (m_CompletionChosen + CompletionEnumerationCount) % CompletionEnumerationCount; m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this); } } @@ -487,7 +483,7 @@ struct CRenderInfo float m_Width; }; -void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser) +void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser) { CRenderInfo *pInfo = static_cast(pUser); diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index 248c19543a4..e658b02546d 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -40,7 +40,6 @@ class CGameConsole : public CComponent CLineInput m_Input; const char *m_pName; int m_Type; - int m_CompletionEnumerationCount; int m_BacklogCurPage; CGameConsole *m_pGameConsole; @@ -74,7 +73,7 @@ class CGameConsole : public CComponent void PrintLine(const char *pLine, int Len, ColorRGBA PrintColor); const char *GetString() const { return m_Input.GetString(); } - static void PossibleCommandsCompleteCallback(const char *pStr, void *pUser); + static void PossibleCommandsCompleteCallback(int Index, const char *pStr, void *pUser); }; class IConsole *m_pConsole; @@ -106,7 +105,7 @@ class CGameConsole : public CComponent void Toggle(int Type); void Dump(int Type); - static void PossibleCommandsRenderCallback(const char *pStr, void *pUser); + static void PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser); static void ConToggleLocalConsole(IConsole::IResult *pResult, void *pUserData); static void ConToggleRemoteConsole(IConsole::IResult *pResult, void *pUserData); static void ConClearLocalConsole(IConsole::IResult *pResult, void *pUserData); From 047c88d797e1edc86ddb58a492db204a588c01d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 17:40:16 +0200 Subject: [PATCH 29/72] Refactor console completion input handling according to upstream --- src/game/client/components/console.cpp | 54 ++++++++++++-------------- src/game/client/components/console.h | 3 +- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 69d1c426c77..79112ae1b9a 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -94,10 +94,8 @@ CGameConsole::CInstance::CInstance(int Type) } m_aCompletionBuffer[0] = 0; - m_CompletionUsed = false; m_CompletionChosen = -1; - m_CompletionRenderOffset = 0.0f; - m_ReverseTAB = false; + Reset(); m_aUser[0] = '\0'; m_UserGot = false; @@ -137,6 +135,11 @@ void CGameConsole::CInstance::ClearHistory() m_pHistoryEntry = 0; } +void CGameConsole::CInstance::Reset() +{ + m_CompletionRenderOffset = 0.0f; +} + void CGameConsole::CInstance::ExecuteLine(const char *pLine) { if(m_Type == CGameConsole::CONSOLETYPE_LOCAL) @@ -330,18 +333,20 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) { if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed()) { - if(m_ReverseTAB && m_CompletionUsed) - m_CompletionChosen--; - else if(!m_ReverseTAB) - m_CompletionChosen++; - int CompletionEnumerationCount = m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this); - m_CompletionUsed = true; - - // handle wrapping - if(CompletionEnumerationCount && (m_CompletionChosen >= CompletionEnumerationCount || m_CompletionChosen < 0)) + const int Direction = m_pGameConsole->m_pClient->Input()->KeyIsPressed(KEY_LSHIFT) || m_pGameConsole->m_pClient->Input()->KeyIsPressed(KEY_RSHIFT) ? -1 : 1; + const bool UseTempCommands = m_Type == CGameConsole::CONSOLETYPE_REMOTE && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(); + const int CompletionEnumerationCount = m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, UseTempCommands); + if(CompletionEnumerationCount) + { + if(m_CompletionChosen == -1 && Direction < 0) + m_CompletionChosen = 0; + m_CompletionChosen = (m_CompletionChosen + Direction + CompletionEnumerationCount) % CompletionEnumerationCount; + m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, UseTempCommands, PossibleCommandsCompleteCallback, this); + } + else if(m_CompletionChosen != -1) { - m_CompletionChosen = (m_CompletionChosen + CompletionEnumerationCount) % CompletionEnumerationCount; - m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this); + m_CompletionChosen = -1; + Reset(); } } } @@ -369,16 +374,6 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) m_BacklogCurPage = 0; m_pGameConsole->m_HasSelection = false; } - else if(Event.m_Key == KEY_LSHIFT) - { - m_ReverseTAB = true; - Handled = true; - } - } - if(Event.m_Flags & IInput::FLAG_RELEASE && Event.m_Key == KEY_LSHIFT) - { - m_ReverseTAB = false; - Handled = true; } if(!Handled) @@ -386,17 +381,17 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) if(Event.m_Flags & (IInput::FLAG_PRESS | IInput::FLAG_TEXT)) { - if((Event.m_Key != KEY_TAB) && (Event.m_Key != KEY_LSHIFT)) + if(Event.m_Key != KEY_TAB && Event.m_Key != KEY_LSHIFT && Event.m_Key != KEY_RSHIFT) { - m_CompletionUsed = false; m_CompletionChosen = -1; str_copy(m_aCompletionBuffer, m_Input.GetString()); - m_CompletionRenderOffset = 0.0f; + + Reset(); } // find the current command { - char aBuf[64] = {0}; + char aBuf[sizeof(m_aCommandName)] = {0}; const char *pSrc = GetString(); int i = 0; for(; i < (int)sizeof(aBuf) - 1 && *pSrc && *pSrc != ' '; i++, pSrc++) @@ -463,6 +458,7 @@ CGameConsole::CInstance *CGameConsole::CurrentConsole() void CGameConsole::OnReset() { + m_RemoteConsole.Reset(); } // only defined for 0<=t<=1 @@ -622,7 +618,7 @@ void CGameConsole::OnRender() CRenderInfo Info; Info.m_pSelf = this; - Info.m_WantedCompletion = pConsole->m_CompletionUsed ? pConsole->m_CompletionChosen : -1; + Info.m_WantedCompletion = pConsole->m_CompletionChosen; Info.m_EnumCount = 0; Info.m_Offset = pConsole->m_CompletionRenderOffset; Info.m_Width = Screen.w; diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index e658b02546d..431b2ddcef3 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -45,11 +45,9 @@ class CGameConsole : public CComponent CGameConsole *m_pGameConsole; char m_aCompletionBuffer[128]; - bool m_CompletionUsed; int m_CompletionChosen; int m_CompletionFlagmask; float m_CompletionRenderOffset; - bool m_ReverseTAB; char m_aUser[32]; bool m_UserGot; @@ -66,6 +64,7 @@ class CGameConsole : public CComponent void ClearBacklog(); void ClearBacklogYOffsets(); void ClearHistory(); + void Reset(); void ExecuteLine(const char *pLine); From 6af8f465264a6de14eec3e9034d8b0db0feb9f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 17:41:28 +0200 Subject: [PATCH 30/72] Add `CTuningParams::PossibleTunings` to find tune params by name --- src/game/gamecore.cpp | 14 ++++++++++++++ src/game/gamecore.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index d3bdb5bcd02..0342ba9c1d5 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -48,6 +48,20 @@ bool CTuningParams::Get(const char *pName, float *pValue) const return false; } +int CTuningParams::PossibleTunings(const char *pStr, IConsole::FPossibleCallback pfnCallback, void *pUser) +{ + int Index = 0; + for(int i = 0; i < Num(); i++) + { + if(str_find_nocase(Name(i), pStr)) + { + pfnCallback(Index, Name(i), pUser); + Index++; + } + } + return Index; +} + float VelocityRamp(float Value, float Start, float Range, float Curvature) { if(Value < Start) diff --git a/src/game/gamecore.h b/src/game/gamecore.h index 411a624e959..03047c7a48d 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -64,6 +65,7 @@ class CTuningParams bool Get(int Index, float *pValue) const; bool Get(const char *pName, float *pValue) const; static const char *Name(int Index) { return ms_apNames[Index]; } + int PossibleTunings(const char *pStr, IConsole::FPossibleCallback pfnCallback = IConsole::EmptyPossibleCommandCallback, void *pUser = nullptr); }; inline void StrToInts(int *pInts, int Num, const char *pStr) From 33bb576202c752d2974f7048a86f59bd4d309522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 18:03:04 +0200 Subject: [PATCH 31/72] Show completion options for tune params in console Currently supports `tune`, `tune_reset` and `toggle_tune`. For `tune_zone` the tune name is the second argument, so this is more difficult to handle. --- src/game/client/components/console.cpp | 131 +++++++++++++++++++------ src/game/client/components/console.h | 3 + 2 files changed, 104 insertions(+), 30 deletions(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 79112ae1b9a..a12ffead481 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -76,6 +76,13 @@ void CConsoleLogger::OnConsoleDeletion() m_pConsole = nullptr; } +// TODO: support "tune_zone", which has tuning as second argument +static const char *gs_apTuningCommands[] = {"tune ", "tune_reset ", "toggle_tune "}; +static bool IsTuningCommandPrefix(const char *pStr) +{ + return std::any_of(std::begin(gs_apTuningCommands), std::end(gs_apTuningCommands), [pStr](auto *pCmd) { return str_startswith_nocase(pStr, pCmd); }); +} + CGameConsole::CInstance::CInstance(int Type) { m_pHistoryEntry = 0x0; @@ -95,6 +102,8 @@ CGameConsole::CInstance::CInstance(int Type) m_aCompletionBuffer[0] = 0; m_CompletionChosen = -1; + m_aCompletionBufferArgument[0] = 0; + m_CompletionChosenArgument = -1; Reset(); m_aUser[0] = '\0'; @@ -171,6 +180,26 @@ void CGameConsole::CInstance::PossibleCommandsCompleteCallback(int Index, const pInstance->m_Input.Set(pStr); } +void CGameConsole::CInstance::PossibleArgumentsCompleteCallback(int Index, const char *pStr, void *pUser) +{ + CGameConsole::CInstance *pInstance = (CGameConsole::CInstance *)pUser; + if(pInstance->m_CompletionChosenArgument == Index) + { + // get command + char aBuf[512]; + const char *pSrc = pInstance->GetString(); + size_t i = 0; + for(; i < sizeof(aBuf) - 2 && pSrc[i] && pSrc[i] != ' '; i++) + aBuf[i] = pSrc[i]; + aBuf[i++] = ' '; + aBuf[i] = '\0'; + + // append argument + str_append(aBuf, pStr, sizeof(aBuf)); + pInstance->m_Input.Set(aBuf); + } +} + void CGameConsole::CInstance::OnInput(IInput::CEvent Event) { bool Handled = false; @@ -331,9 +360,11 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) } else if(Event.m_Key == KEY_TAB) { + const int Direction = m_pGameConsole->m_pClient->Input()->KeyIsPressed(KEY_LSHIFT) || m_pGameConsole->m_pClient->Input()->KeyIsPressed(KEY_RSHIFT) ? -1 : 1; + + // command completion if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed()) { - const int Direction = m_pGameConsole->m_pClient->Input()->KeyIsPressed(KEY_LSHIFT) || m_pGameConsole->m_pClient->Input()->KeyIsPressed(KEY_RSHIFT) ? -1 : 1; const bool UseTempCommands = m_Type == CGameConsole::CONSOLETYPE_REMOTE && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(); const int CompletionEnumerationCount = m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, UseTempCommands); if(CompletionEnumerationCount) @@ -349,6 +380,28 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) Reset(); } } + + // argument completion (tuning, ...) + if(m_Type == CGameConsole::CONSOLETYPE_REMOTE && m_pGameConsole->Client()->RconAuthed()) + { + const bool TuningCompletion = IsTuningCommandPrefix(GetString()); + if(TuningCompletion) + { + int CompletionEnumerationCount = m_pGameConsole->m_pClient->m_aTuning[g_Config.m_ClDummy].PossibleTunings(m_aCompletionBufferArgument); + if(CompletionEnumerationCount) + { + if(m_CompletionChosenArgument == -1 && Direction < 0) + m_CompletionChosenArgument = 0; + m_CompletionChosenArgument = (m_CompletionChosenArgument + Direction + CompletionEnumerationCount) % CompletionEnumerationCount; + m_pGameConsole->m_pClient->m_aTuning[g_Config.m_ClDummy].PossibleTunings(m_aCompletionBufferArgument, PossibleArgumentsCompleteCallback, this); + } + else if(m_CompletionChosenArgument != -1) + { + m_CompletionChosenArgument = -1; + Reset(); + } + } + } } else if(Event.m_Key == KEY_PAGEUP) { @@ -386,6 +439,15 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) m_CompletionChosen = -1; str_copy(m_aCompletionBuffer, m_Input.GetString()); + for(const auto *pCmd : gs_apTuningCommands) + { + if(str_startswith_nocase(m_Input.GetString(), pCmd)) + { + m_CompletionChosenArgument = -1; + str_copy(m_aCompletionBufferArgument, &m_Input.GetString()[str_length(pCmd)]); + } + } + Reset(); } @@ -393,10 +455,10 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) { char aBuf[sizeof(m_aCommandName)] = {0}; const char *pSrc = GetString(); - int i = 0; - for(; i < (int)sizeof(aBuf) - 1 && *pSrc && *pSrc != ' '; i++, pSrc++) - aBuf[i] = *pSrc; - aBuf[i] = 0; + size_t i = 0; + for(; i < sizeof(aBuf) - 1 && pSrc[i] && pSrc[i] != ' '; i++) + aBuf[i] = pSrc[i]; + aBuf[i] = '\0'; const IConsole::CCommandInfo *pCommand = m_pGameConsole->m_pConsole->GetCommandInfo(aBuf, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands()); @@ -468,7 +530,7 @@ static float ConsoleScaleFunc(float t) return sinf(acosf(1.0f - t)); } -struct CRenderInfo +struct CCompletionOptionRenderInfo { CGameConsole *m_pSelf; CTextCursor m_Cursor; @@ -481,7 +543,7 @@ struct CRenderInfo void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser) { - CRenderInfo *pInfo = static_cast(pUser); + CCompletionOptionRenderInfo *pInfo = static_cast(pUser); if(pInfo->m_EnumCount == pInfo->m_WantedCompletion) { @@ -616,15 +678,8 @@ void CGameConsole::OnRender() float x = 3; float y = ConsoleHeight - RowHeight - 5.0f; - CRenderInfo Info; - Info.m_pSelf = this; - Info.m_WantedCompletion = pConsole->m_CompletionChosen; - Info.m_EnumCount = 0; - Info.m_Offset = pConsole->m_CompletionRenderOffset; - Info.m_Width = Screen.w; - Info.m_pCurrentCmd = pConsole->m_aCompletionBuffer; - TextRender()->SetCursor(&Info.m_Cursor, x + Info.m_Offset, y + RowHeight + 2.0f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END); - Info.m_Cursor.m_LineWidth = std::numeric_limits::max(); + const float InitialX = x; + const float InitialY = y; // render prompt CTextCursor Cursor; @@ -704,24 +759,40 @@ void CGameConsole::OnRender() Input()->SetEditingPosition(Marker.m_X, Marker.m_Y + Marker.m_FontSize); // render possible commands - if(m_ConsoleType == CONSOLETYPE_LOCAL || Client()->RconAuthed()) + if((m_ConsoleType == CONSOLETYPE_LOCAL || Client()->RconAuthed()) && pConsole->m_Input.GetString()[0]) { - if(pConsole->m_Input.GetString()[0] != 0) + CCompletionOptionRenderInfo Info; + Info.m_pSelf = this; + Info.m_WantedCompletion = pConsole->m_CompletionChosen; + Info.m_EnumCount = 0; + Info.m_Offset = pConsole->m_CompletionRenderOffset; + Info.m_Width = Screen.w; + Info.m_pCurrentCmd = pConsole->m_aCompletionBuffer; + TextRender()->SetCursor(&Info.m_Cursor, InitialX + Info.m_Offset, InitialY + RowHeight + 2.0f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END); + Info.m_Cursor.m_LineWidth = std::numeric_limits::max(); + m_pConsole->PossibleCommands(Info.m_pCurrentCmd, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL && Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info); + pConsole->m_CompletionRenderOffset = Info.m_Offset; + + if(Info.m_EnumCount <= 0 && pConsole->m_IsCommand) { - m_pConsole->PossibleCommands(pConsole->m_aCompletionBuffer, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL && Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info); - pConsole->m_CompletionRenderOffset = Info.m_Offset; + const bool TuningCompletion = IsTuningCommandPrefix(Info.m_pCurrentCmd); + if(TuningCompletion) + { + Info.m_WantedCompletion = pConsole->m_CompletionChosenArgument; + Info.m_EnumCount = 0; + Info.m_pCurrentCmd = pConsole->m_aCompletionBufferArgument; + m_pClient->m_aTuning[g_Config.m_ClDummy].PossibleTunings(Info.m_pCurrentCmd, PossibleCommandsRenderCallback, &Info); + pConsole->m_CompletionRenderOffset = Info.m_Offset; + } - if(Info.m_EnumCount <= 0) + if(Info.m_EnumCount <= 0 && pConsole->m_IsCommand) { - if(pConsole->m_IsCommand) - { - char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "Help: %s ", pConsole->m_aCommandHelp); - TextRender()->TextEx(&Info.m_Cursor, aBuf, -1); - TextRender()->TextColor(0.75f, 0.75f, 0.75f, 1); - str_format(aBuf, sizeof(aBuf), "Usage: %s %s", pConsole->m_aCommandName, pConsole->m_aCommandParams); - TextRender()->TextEx(&Info.m_Cursor, aBuf, -1); - } + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "Help: %s ", pConsole->m_aCommandHelp); + TextRender()->TextEx(&Info.m_Cursor, aBuf, -1); + TextRender()->TextColor(0.75f, 0.75f, 0.75f, 1); + str_format(aBuf, sizeof(aBuf), "Usage: %s %s", pConsole->m_aCommandName, pConsole->m_aCommandParams); + TextRender()->TextEx(&Info.m_Cursor, aBuf, -1); } } } diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index 431b2ddcef3..e13f34472b3 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -46,6 +46,8 @@ class CGameConsole : public CComponent char m_aCompletionBuffer[128]; int m_CompletionChosen; + char m_aCompletionBufferArgument[128]; + int m_CompletionChosenArgument; int m_CompletionFlagmask; float m_CompletionRenderOffset; @@ -73,6 +75,7 @@ class CGameConsole : public CComponent const char *GetString() const { return m_Input.GetString(); } static void PossibleCommandsCompleteCallback(int Index, const char *pStr, void *pUser); + static void PossibleArgumentsCompleteCallback(int Index, const char *pStr, void *pUser); }; class IConsole *m_pConsole; From e99f7ab106eed165735d1279d40725d4631be685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 11 Aug 2022 19:30:29 +0200 Subject: [PATCH 32/72] Extract `StrCopyUntilSpace` and use existing `str_*` functions Minor refactoring to reduce duplicate code. Eventually this method could be extended to handle completion for other arguments except the first one. --- src/game/client/components/console.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index a12ffead481..978f3e6cbb4 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -180,6 +180,12 @@ void CGameConsole::CInstance::PossibleCommandsCompleteCallback(int Index, const pInstance->m_Input.Set(pStr); } +static void StrCopyUntilSpace(char *pDest, size_t DestSize, const char *pSrc) +{ + const char *pSpace = str_find(pSrc, " "); + str_copy(pDest, pSrc, minimum(pSpace ? pSpace - pSrc + 1 : 1, DestSize)); +} + void CGameConsole::CInstance::PossibleArgumentsCompleteCallback(int Index, const char *pStr, void *pUser) { CGameConsole::CInstance *pInstance = (CGameConsole::CInstance *)pUser; @@ -187,12 +193,8 @@ void CGameConsole::CInstance::PossibleArgumentsCompleteCallback(int Index, const { // get command char aBuf[512]; - const char *pSrc = pInstance->GetString(); - size_t i = 0; - for(; i < sizeof(aBuf) - 2 && pSrc[i] && pSrc[i] != ' '; i++) - aBuf[i] = pSrc[i]; - aBuf[i++] = ' '; - aBuf[i] = '\0'; + StrCopyUntilSpace(aBuf, sizeof(aBuf), pInstance->GetString()); + str_append(aBuf, " ", sizeof(aBuf)); // append argument str_append(aBuf, pStr, sizeof(aBuf)); @@ -453,13 +455,8 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) // find the current command { - char aBuf[sizeof(m_aCommandName)] = {0}; - const char *pSrc = GetString(); - size_t i = 0; - for(; i < sizeof(aBuf) - 1 && pSrc[i] && pSrc[i] != ' '; i++) - aBuf[i] = pSrc[i]; - aBuf[i] = '\0'; - + char aBuf[sizeof(m_aCommandName)]; + StrCopyUntilSpace(aBuf, sizeof(aBuf), GetString()); const IConsole::CCommandInfo *pCommand = m_pGameConsole->m_pConsole->GetCommandInfo(aBuf, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands()); if(pCommand) From 8e0a935d5cd97d7b9ba5dd985a383d179e1813d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 13:58:07 +0200 Subject: [PATCH 33/72] Combine `CGraph::ScaleMin` and `ScaleMax` into `Scale` As the methods are always called at the same time, they can be combined. This also improves the performance, as the array only needs to be iterated once. --- src/engine/client/client.cpp | 32 ++++++++----------------- src/engine/client/client.h | 4 +--- src/game/client/components/debughud.cpp | 6 ++--- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 823005dcd55..f57dab6128f 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -89,25 +89,16 @@ void CGraph::Init(float Min, float Max) m_Index = 0; } -void CGraph::ScaleMax() +void CGraph::Scale() { - int i = 0; - m_Max = m_MaxRange; - for(i = 0; i < MAX_VALUES; i++) - { - if(m_aValues[i] > m_Max) - m_Max = m_aValues[i]; - } -} - -void CGraph::ScaleMin() -{ - int i = 0; m_Min = m_MinRange; - for(i = 0; i < MAX_VALUES; i++) + m_Max = m_MaxRange; + for(auto Value : m_aValues) { - if(m_aValues[i] < m_Min) - m_Min = m_aValues[i]; + if(Value > m_Max) + m_Max = Value; + else if(Value < m_Min) + m_Min = Value; } } @@ -1143,14 +1134,11 @@ void CClient::DebugRender() float sp = Graphics()->ScreenWidth() / 100.0f; float x = Graphics()->ScreenWidth() - w - sp; - m_FpsGraph.ScaleMax(); - m_FpsGraph.ScaleMin(); + m_FpsGraph.Scale(); m_FpsGraph.Render(Graphics(), m_DebugFont, x, sp * 5, w, h, "FPS"); - m_InputtimeMarginGraph.ScaleMin(); - m_InputtimeMarginGraph.ScaleMax(); + m_InputtimeMarginGraph.Scale(); m_InputtimeMarginGraph.Render(Graphics(), m_DebugFont, x, sp * 5 + h + sp, w, h, "Prediction Margin"); - m_GametimeMarginGraph.ScaleMin(); - m_GametimeMarginGraph.ScaleMax(); + m_GametimeMarginGraph.Scale(); m_GametimeMarginGraph.Render(Graphics(), m_DebugFont, x, sp * 5 + h + sp + h + sp, w, h, "Gametime Margin"); } } diff --git a/src/engine/client/client.h b/src/engine/client/client.h index e808389e087..fe8fb807778 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -56,9 +56,7 @@ class CGraph void Init(float Min, float Max); - void ScaleMax(); - void ScaleMin(); - + void Scale(); void Add(float v, float r, float g, float b); bool InsertAt(int i, float v, float r, float g, float b); void Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float x, float y, float w, float h, const char *pDescription); diff --git a/src/game/client/components/debughud.cpp b/src/game/client/components/debughud.cpp index 2d4cb8d3957..e5ad458d25a 100644 --- a/src/game/client/components/debughud.cpp +++ b/src/game/client/components/debughud.cpp @@ -162,8 +162,7 @@ void CDebugHud::RenderTuning() } pv = RampedSpeed; } - m_RampGraph.ScaleMin(); - m_RampGraph.ScaleMax(); + m_RampGraph.Scale(); m_ZoomedInGraph.Init(0.0f, 0.0f); pv = 1; @@ -189,8 +188,7 @@ void CDebugHud::RenderTuning() } pv = RampedSpeed; } - m_ZoomedInGraph.ScaleMin(); - m_ZoomedInGraph.ScaleMax(); + m_ZoomedInGraph.Scale(); } char aBuf[128]; str_format(aBuf, sizeof(aBuf), "Velspeed.X*Ramp in Bps (Velspeed %d to %d)", StepSizeRampGraph / 32, 128 * StepSizeRampGraph / 32); From b314db5454d22fd19e4c039d1e73fbe2a878e6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 14:01:46 +0200 Subject: [PATCH 34/72] Use `CGraph::MAX_VALUES` instead of magic value in debughud --- src/game/client/components/debughud.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/debughud.cpp b/src/game/client/components/debughud.cpp index e5ad458d25a..665656add32 100644 --- a/src/game/client/components/debughud.cpp +++ b/src/game/client/components/debughud.cpp @@ -144,8 +144,7 @@ void CDebugHud::RenderTuning() m_RampGraph.Init(0.0f, 0.0f); m_SpeedTurningPoint = 0; float pv = 1; - // CGraph must be fed with exactly 128 values. - for(int i = 0; i < 128; i++) + for(size_t i = 0; i < CGraph::MAX_VALUES; i++) { // This is a calculation of the speed values per second on the X axis, from 270 to 34560 in steps of 270 float Speed = (i + 1) * StepSizeRampGraph; @@ -167,7 +166,7 @@ void CDebugHud::RenderTuning() m_ZoomedInGraph.Init(0.0f, 0.0f); pv = 1; MiddleOfZoomedInGraph = m_SpeedTurningPoint; - for(int i = 0; i < 128; i++) + for(size_t i = 0; i < CGraph::MAX_VALUES; i++) { // This is a calculation of the speed values per second on the X axis, from (MiddleOfZoomedInGraph - 64 * StepSize) to (MiddleOfZoomedInGraph + 64 * StepSize) float Speed = MiddleOfZoomedInGraph - 64 * StepSizeZoomedInGraph + i * StepSizeZoomedInGraph; From 3daa177830e4155489325c06e0b111f31f1bda81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 14:08:30 +0200 Subject: [PATCH 35/72] Remove restriction for `CGraph::MAX_VALUES` to be a power of two By using `% MAX_VALUES` instead of `& (MAX_VALUES - 1)` to wrap the index. Both work the same, but the latter only does for powers of two. --- src/engine/client/client.cpp | 6 +++--- src/engine/client/client.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index f57dab6128f..8329de8913b 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -104,7 +104,7 @@ void CGraph::Scale() void CGraph::Add(float v, float r, float g, float b) { - m_Index = (m_Index + 1) & (MAX_VALUES - 1); + m_Index = (m_Index + 1) % MAX_VALUES; m_aValues[m_Index] = v; m_aColors[m_Index][0] = r; m_aColors[m_Index][1] = g; @@ -149,8 +149,8 @@ void CGraph::Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, { float a0 = (i - 1) / (float)MAX_VALUES; float a1 = i / (float)MAX_VALUES; - int i0 = (m_Index + i - 1) & (MAX_VALUES - 1); - int i1 = (m_Index + i) & (MAX_VALUES - 1); + int i0 = (m_Index + i - 1) % MAX_VALUES; + int i1 = (m_Index + i) % MAX_VALUES; float v0 = (m_aValues[i0] - m_Min) / (m_Max - m_Min); float v1 = (m_aValues[i1] - m_Min) / (m_Max - m_Min); diff --git a/src/engine/client/client.h b/src/engine/client/client.h index fe8fb807778..4620e7b98f3 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -44,7 +44,6 @@ class CGraph public: enum { - // restrictions: Must be power of two MAX_VALUES = 128, }; From 44ca1f0d7b6a2bfe109bfa6e36aba4635e6b8a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 14:10:40 +0200 Subject: [PATCH 36/72] Use `size_t` for indices, replace unused return value with assert The return value of `CGraph::InsertAt` was not checked. All uses of the function pass a correct index, so the return value is replaced with an assertion. --- src/engine/client/client.cpp | 16 ++++++---------- src/engine/client/client.h | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 8329de8913b..96ff1950a57 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -111,17 +111,13 @@ void CGraph::Add(float v, float r, float g, float b) m_aColors[m_Index][2] = b; } -bool CGraph::InsertAt(int i, float v, float r, float g, float b) +void CGraph::InsertAt(size_t Index, float v, float r, float g, float b) { - if(i < 0 || i > MAX_VALUES - 1) - { - return false; - } - m_aValues[i] = v; - m_aColors[i][0] = r; - m_aColors[i][1] = g; - m_aColors[i][2] = b; - return true; + dbg_assert(Index < MAX_VALUES, "Index out of bounds"); + m_aValues[Index] = v; + m_aColors[Index][0] = r; + m_aColors[Index][1] = g; + m_aColors[Index][2] = b; } void CGraph::Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float x, float y, float w, float h, const char *pDescription) diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 4620e7b98f3..9c56db1f3e4 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -51,13 +51,13 @@ class CGraph float m_MinRange, m_MaxRange; float m_aValues[MAX_VALUES]; float m_aColors[MAX_VALUES][3]; - int m_Index; + size_t m_Index; void Init(float Min, float Max); void Scale(); void Add(float v, float r, float g, float b); - bool InsertAt(int i, float v, float r, float g, float b); + void InsertAt(size_t Index, float v, float r, float g, float b); void Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float x, float y, float w, float h, const char *pDescription); }; From 11e60d32f0e19bb70bf10a88f997cf792334c696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 14:11:56 +0200 Subject: [PATCH 37/72] Reuse `CGraph::InsertAt` in `Add` to reduce duplicate code --- src/engine/client/client.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 96ff1950a57..abce4a654c2 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -105,10 +105,7 @@ void CGraph::Scale() void CGraph::Add(float v, float r, float g, float b) { m_Index = (m_Index + 1) % MAX_VALUES; - m_aValues[m_Index] = v; - m_aColors[m_Index][0] = r; - m_aColors[m_Index][1] = g; - m_aColors[m_Index][2] = b; + InsertAt(m_Index, v, r, g, b); } void CGraph::InsertAt(size_t Index, float v, float r, float g, float b) From 8c88005a423a9af51c411daebc469542254d3e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 14:14:08 +0200 Subject: [PATCH 38/72] Rename variables `Array` to `aLineItems` / `aColorVertices` --- src/engine/client/client.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index abce4a654c2..2f40589f8c3 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -134,10 +134,10 @@ void CGraph::Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, IGraphics::CLineItem LineItem(x, y + h / 2, x + w, y + h / 2); pGraphics->LinesDraw(&LineItem, 1); pGraphics->SetColor(0.5f, 0.5f, 0.5f, 0.75f); - IGraphics::CLineItem Array[2] = { + IGraphics::CLineItem aLineItems[2] = { IGraphics::CLineItem(x, y + (h * 3) / 4, x + w, y + (h * 3) / 4), IGraphics::CLineItem(x, y + h / 4, x + w, y + h / 4)}; - pGraphics->LinesDraw(Array, 2); + pGraphics->LinesDraw(aLineItems, 2); for(int i = 1; i < MAX_VALUES; i++) { float a0 = (i - 1) / (float)MAX_VALUES; @@ -148,10 +148,10 @@ void CGraph::Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float v0 = (m_aValues[i0] - m_Min) / (m_Max - m_Min); float v1 = (m_aValues[i1] - m_Min) / (m_Max - m_Min); - IGraphics::CColorVertex ArrayV[2] = { + IGraphics::CColorVertex aColorVertices[2] = { IGraphics::CColorVertex(0, m_aColors[i0][0], m_aColors[i0][1], m_aColors[i0][2], 0.75f), IGraphics::CColorVertex(1, m_aColors[i1][0], m_aColors[i1][1], m_aColors[i1][2], 0.75f)}; - pGraphics->SetColorVertex(ArrayV, 2); + pGraphics->SetColorVertex(aColorVertices, 2); IGraphics::CLineItem LineItem2(x + a0 * w, y + h - v0 * h, x + a1 * w, y + h - v1 * h); pGraphics->LinesDraw(&LineItem2, 1); } From 967c92f5d63e8746abb91a90cc8d5a46544b2325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 14:23:50 +0200 Subject: [PATCH 39/72] Encapsulate `CGraph` member variables Make the member variables private and add `SetMin` to replace a usage of the member variables in `CDebugHud`. For completeness/symmetry, `SetMax` is also added. --- src/engine/client/client.cpp | 12 +++++++++++- src/engine/client/client.h | 4 ++++ src/game/client/components/debughud.cpp | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 2f40589f8c3..b7c2af9d4c4 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -83,10 +83,20 @@ static const ColorRGBA gs_ClientNetworkPrintColor{0.7f, 1, 0.7f, 1.0f}; static const ColorRGBA gs_ClientNetworkErrPrintColor{1.0f, 0.25f, 0.25f, 1.0f}; void CGraph::Init(float Min, float Max) +{ + SetMin(Min); + SetMax(Max); + m_Index = 0; +} + +void CGraph::SetMin(float Min) { m_MinRange = m_Min = Min; +} + +void CGraph::SetMax(float Max) +{ m_MaxRange = m_Max = Max; - m_Index = 0; } void CGraph::Scale() diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 9c56db1f3e4..3b10f5a4bff 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -47,13 +47,17 @@ class CGraph MAX_VALUES = 128, }; +private: float m_Min, m_Max; float m_MinRange, m_MaxRange; float m_aValues[MAX_VALUES]; float m_aColors[MAX_VALUES][3]; size_t m_Index; +public: void Init(float Min, float Max); + void SetMin(float Min); + void SetMax(float Max); void Scale(); void Add(float v, float r, float g, float b); diff --git a/src/game/client/components/debughud.cpp b/src/game/client/components/debughud.cpp index 665656add32..66a9754d7f5 100644 --- a/src/game/client/components/debughud.cpp +++ b/src/game/client/components/debughud.cpp @@ -183,7 +183,7 @@ void CDebugHud::RenderTuning() } if(i == 0) { - m_ZoomedInGraph.m_Min = m_ZoomedInGraph.m_MinRange = RampedSpeed; + m_ZoomedInGraph.SetMin(RampedSpeed); } pv = RampedSpeed; } From 237fdc76db383ea20fe1d9452566e5ff9b6f2d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Jul 2022 13:16:12 +0200 Subject: [PATCH 40/72] Move `CRenderTools::DrawCircle` to `IGraphics::DrawCircle` As this method does not depend on any game components it is be moved to the engine graphics interface. --- src/engine/client/graphics_threaded.cpp | 32 +++++++++++++++++++++++++ src/engine/client/graphics_threaded.h | 2 ++ src/engine/graphics.h | 2 ++ src/game/client/components/emoticon.cpp | 11 +++------ src/game/client/components/emoticon.h | 2 -- src/game/client/components/menus.cpp | 4 ++-- src/game/client/render.cpp | 32 ------------------------- src/game/client/render.h | 2 -- src/game/editor/editor.cpp | 2 +- src/game/editor/layer_sounds.cpp | 4 ++-- 10 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 06077473188..b80a1e771eb 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -1237,6 +1237,38 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe } } +void CGraphics_Threaded::DrawCircle(float x, float y, float r, int Segments) +{ + IGraphics::CFreeformItem Array[32]; + int NumItems = 0; + float FSegments = (float)Segments; + for(int i = 0; i < Segments; i += 2) + { + float a1 = i / FSegments * 2 * pi; + float a2 = (i + 1) / FSegments * 2 * pi; + float a3 = (i + 2) / FSegments * 2 * pi; + float Ca1 = cosf(a1); + float Ca2 = cosf(a2); + float Ca3 = cosf(a3); + float Sa1 = sinf(a1); + float Sa2 = sinf(a2); + float Sa3 = sinf(a3); + + Array[NumItems++] = IGraphics::CFreeformItem( + x, y, + x + Ca1 * r, y + Sa1 * r, + x + Ca3 * r, y + Sa3 * r, + x + Ca2 * r, y + Sa2 * r); + if(NumItems == 32) + { + QuadsDrawFreeform(Array, 32); + NumItems = 0; + } + } + if(NumItems) + QuadsDrawFreeform(Array, NumItems); +} + void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset) { if(NumIndicesOffset == 0) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 1bb3614bb73..f470cae3662 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -1127,6 +1127,8 @@ class CGraphics_Threaded : public IEngineGraphics void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) override; void QuadsText(float x, float y, float Size, const char *pText) override; + void DrawCircle(float x, float y, float r, int Segments) override; + const GL_STexCoord *GetCurTextureCoordinates() override { return m_aTexture; diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 24a236e5443..f13e3dee188 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -442,6 +442,8 @@ class IGraphics : public IInterface virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0; virtual void QuadsText(float x, float y, float Size, const char *pText) = 0; + virtual void DrawCircle(float x, float y, float r, int Segments) = 0; + struct CColorVertex { int m_Index; diff --git a/src/game/client/components/emoticon.cpp b/src/game/client/components/emoticon.cpp index 9f9421552eb..3c99c5a4fee 100644 --- a/src/game/client/components/emoticon.cpp +++ b/src/game/client/components/emoticon.cpp @@ -58,11 +58,6 @@ bool CEmoticon::OnCursorMove(float x, float y, IInput::ECursorType CursorType) return true; } -void CEmoticon::DrawCircle(float x, float y, float r, int Segments) -{ - RenderTools()->DrawCircle(x, y, r, Segments); -} - void CEmoticon::OnRender() { if(!m_Active) @@ -107,7 +102,7 @@ void CEmoticon::OnRender() Graphics()->TextureClear(); Graphics()->QuadsBegin(); Graphics()->SetColor(0, 0, 0, 0.3f); - DrawCircle(Screen.w / 2, Screen.h / 2, 190.0f, 64); + Graphics()->DrawCircle(Screen.w / 2, Screen.h / 2, 190.0f, 64); Graphics()->QuadsEnd(); Graphics()->WrapClamp(); @@ -138,7 +133,7 @@ void CEmoticon::OnRender() Graphics()->TextureClear(); Graphics()->QuadsBegin(); Graphics()->SetColor(1.0, 1.0, 1.0, 0.3f); - DrawCircle(Screen.w / 2, Screen.h / 2, 100.0f, 64); + Graphics()->DrawCircle(Screen.w / 2, Screen.h / 2, 100.0f, 64); Graphics()->QuadsEnd(); CTeeRenderInfo *pTeeInfo = &m_pClient->m_aClients[m_pClient->m_aLocalIDs[g_Config.m_ClDummy]].m_RenderInfo; @@ -162,7 +157,7 @@ void CEmoticon::OnRender() Graphics()->TextureClear(); Graphics()->QuadsBegin(); Graphics()->SetColor(0, 0, 0, 0.3f); - DrawCircle(Screen.w / 2, Screen.h / 2, 30.0f, 64); + Graphics()->DrawCircle(Screen.w / 2, Screen.h / 2, 30.0f, 64); Graphics()->QuadsEnd(); } else diff --git a/src/game/client/components/emoticon.h b/src/game/client/components/emoticon.h index ed9f10a0124..aec896cfa90 100644 --- a/src/game/client/components/emoticon.h +++ b/src/game/client/components/emoticon.h @@ -7,8 +7,6 @@ class CEmoticon : public CComponent { - void DrawCircle(float x, float y, float r, int Segments); - bool m_WasActive; bool m_Active; diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 4c909efe5ea..d72e5304ced 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1242,9 +1242,9 @@ void CMenus::RenderColorPicker() Graphics()->TextureClear(); Graphics()->QuadsBegin(); Graphics()->SetColor(MarkerOutline); - RenderTools()->DrawCircle(MarkerX, MarkerY, 4.5f, 32); + Graphics()->DrawCircle(MarkerX, MarkerY, 4.5f, 32); Graphics()->SetColor(color_cast(PickerColorHSV)); - RenderTools()->DrawCircle(MarkerX, MarkerY, 3.5f, 32); + Graphics()->DrawCircle(MarkerX, MarkerY, 3.5f, 32); Graphics()->QuadsEnd(); // Marker Hue Area diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp index 825e7bbc057..e1223f008e5 100644 --- a/src/game/client/render.cpp +++ b/src/game/client/render.cpp @@ -529,38 +529,6 @@ void CRenderTools::DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 Col DrawRect4(pRect->x, pRect->y, pRect->w, pRect->h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding); } -void CRenderTools::DrawCircle(float x, float y, float r, int Segments) -{ - IGraphics::CFreeformItem Array[32]; - int NumItems = 0; - float FSegments = (float)Segments; - for(int i = 0; i < Segments; i += 2) - { - float a1 = i / FSegments * 2 * pi; - float a2 = (i + 1) / FSegments * 2 * pi; - float a3 = (i + 2) / FSegments * 2 * pi; - float Ca1 = cosf(a1); - float Ca2 = cosf(a2); - float Ca3 = cosf(a3); - float Sa1 = sinf(a1); - float Sa2 = sinf(a2); - float Sa3 = sinf(a3); - - Array[NumItems++] = IGraphics::CFreeformItem( - x, y, - x + Ca1 * r, y + Sa1 * r, - x + Ca3 * r, y + Sa3 * r, - x + Ca2 * r, y + Sa2 * r); - if(NumItems == 32) - { - Graphics()->QuadsDrawFreeform(Array, 32); - NumItems = 0; - } - } - if(NumItems) - Graphics()->QuadsDrawFreeform(Array, NumItems); -} - void CRenderTools::GetRenderTeeAnimScaleAndBaseSize(CAnimState *pAnim, CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize) { AnimScale = pInfo->m_Size * 1.0f / 64.0f; diff --git a/src/game/client/render.h b/src/game/client/render.h index bc63d031b1c..704cf0d082b 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -117,8 +117,6 @@ class CRenderTools void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding); void DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding); - void DrawCircle(float x, float y, float r, int Segments); - // larger rendering methods void GetRenderTeeBodySize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height); void GetRenderTeeFeetSize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height); diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index b565070366d..7ab5251e15e 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2936,7 +2936,7 @@ void CEditor::DoMapEditor(CUIRect View) Graphics()->TextureClear(); Graphics()->QuadsBegin(); Graphics()->SetColor(0, 0, 1, 0.3f); - RenderTools()->DrawCircle(m_WorldOffsetX, m_WorldOffsetY - 3.0f, 20.0f, 32); + Graphics()->DrawCircle(m_WorldOffsetX, m_WorldOffsetY - 3.0f, 20.0f, 32); Graphics()->QuadsEnd(); } } diff --git a/src/game/editor/layer_sounds.cpp b/src/game/editor/layer_sounds.cpp index 8c78f36f464..b25663c0773 100644 --- a/src/game/editor/layer_sounds.cpp +++ b/src/game/editor/layer_sounds.cpp @@ -40,12 +40,12 @@ void CLayerSounds::Render(bool Tileset) { case CSoundShape::SHAPE_CIRCLE: { - m_pEditor->RenderTools()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, + m_pEditor->Graphics()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, Source.m_Shape.m_Circle.m_Radius, 32); float Falloff = ((float)Source.m_Falloff / 255.0f); if(Falloff > 0.0f) - m_pEditor->RenderTools()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, + m_pEditor->Graphics()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, Source.m_Shape.m_Circle.m_Radius * Falloff, 32); break; } From 9ad097da4d4c55ecc8dff172ef3052090fc3419c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Jul 2022 13:26:42 +0200 Subject: [PATCH 41/72] Refactor `DrawCircle`: - improve argument names - remove duplicate computation by adding `SegmentsAngle` - rename variable `Array` to `aItems` - use `std::size` and `size_t` - remove unnecessary temporary variables --- src/engine/client/graphics_threaded.cpp | 37 ++++++++++--------------- src/engine/client/graphics_threaded.h | 2 +- src/engine/graphics.h | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index b80a1e771eb..813ea8101ab 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -1237,36 +1237,29 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe } } -void CGraphics_Threaded::DrawCircle(float x, float y, float r, int Segments) +void CGraphics_Threaded::DrawCircle(float CenterX, float CenterY, float Radius, int Segments) { - IGraphics::CFreeformItem Array[32]; - int NumItems = 0; - float FSegments = (float)Segments; + IGraphics::CFreeformItem aItems[32]; + size_t NumItems = 0; + const float SegmentsAngle = 2 * pi / Segments; for(int i = 0; i < Segments; i += 2) { - float a1 = i / FSegments * 2 * pi; - float a2 = (i + 1) / FSegments * 2 * pi; - float a3 = (i + 2) / FSegments * 2 * pi; - float Ca1 = cosf(a1); - float Ca2 = cosf(a2); - float Ca3 = cosf(a3); - float Sa1 = sinf(a1); - float Sa2 = sinf(a2); - float Sa3 = sinf(a3); - - Array[NumItems++] = IGraphics::CFreeformItem( - x, y, - x + Ca1 * r, y + Sa1 * r, - x + Ca3 * r, y + Sa3 * r, - x + Ca2 * r, y + Sa2 * r); - if(NumItems == 32) + const float a1 = i * SegmentsAngle; + const float a2 = (i + 1) * SegmentsAngle; + const float a3 = (i + 2) * SegmentsAngle; + aItems[NumItems++] = IGraphics::CFreeformItem( + CenterX, CenterY, + CenterX + cosf(a1) * Radius, CenterY + sinf(a1) * Radius, + CenterX + cosf(a3) * Radius, CenterY + sinf(a3) * Radius, + CenterX + cosf(a2) * Radius, CenterY + sinf(a2) * Radius); + if(NumItems == std::size(aItems)) { - QuadsDrawFreeform(Array, 32); + QuadsDrawFreeform(aItems, std::size(aItems)); NumItems = 0; } } if(NumItems) - QuadsDrawFreeform(Array, NumItems); + QuadsDrawFreeform(aItems, NumItems); } void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index f470cae3662..8362d36ecc8 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -1127,7 +1127,7 @@ class CGraphics_Threaded : public IEngineGraphics void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) override; void QuadsText(float x, float y, float Size, const char *pText) override; - void DrawCircle(float x, float y, float r, int Segments) override; + void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) override; const GL_STexCoord *GetCurTextureCoordinates() override { diff --git a/src/engine/graphics.h b/src/engine/graphics.h index f13e3dee188..a434d9c06a4 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -442,7 +442,7 @@ class IGraphics : public IInterface virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0; virtual void QuadsText(float x, float y, float Size, const char *pText) = 0; - virtual void DrawCircle(float x, float y, float r, int Segments) = 0; + virtual void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) = 0; struct CColorVertex { From 7b20009980e559221441c94329ee4f294bb9c62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 26 Jul 2022 21:17:29 +0200 Subject: [PATCH 42/72] Move `CUI::CORNER_*` enum to `IGraphics::CORNER_*` Entirely automatic replacement in preparation for moving rect drawing methods from `CRenderTools` to `IGraphics`. --- src/engine/graphics.h | 15 ++++ src/game/client/components/chat.cpp | 2 +- src/game/client/components/console.cpp | 2 +- src/game/client/components/hud.cpp | 14 ++-- src/game/client/components/menus.cpp | 74 +++++++++--------- src/game/client/components/menus.h | 4 +- src/game/client/components/menus_browser.cpp | 46 +++++------ src/game/client/components/menus_demo.cpp | 40 +++++----- src/game/client/components/menus_ingame.cpp | 40 +++++----- src/game/client/components/menus_settings.cpp | 76 +++++++++---------- .../components/menus_settings_assets.cpp | 8 +- src/game/client/components/menus_start.cpp | 30 ++++---- src/game/client/components/motd.cpp | 2 +- src/game/client/components/scoreboard.cpp | 20 ++--- src/game/client/components/spectator.cpp | 12 +-- src/game/client/components/statboard.cpp | 4 +- src/game/client/components/tooltips.cpp | 2 +- src/game/client/components/voting.cpp | 8 +- src/game/client/ui.h | 16 ---- src/game/client/ui_ex.cpp | 16 ++-- src/game/client/ui_ex.h | 4 +- src/game/editor/editor.cpp | 66 ++++++++-------- src/game/editor/editor.h | 4 +- src/game/editor/layer_sounds.cpp | 4 +- src/game/editor/popups.cpp | 4 +- 25 files changed, 256 insertions(+), 257 deletions(-) diff --git a/src/engine/graphics.h b/src/engine/graphics.h index a434d9c06a4..d77b7df448d 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -442,6 +442,21 @@ class IGraphics : public IInterface virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0; virtual void QuadsText(float x, float y, float Size, const char *pText) = 0; + enum + { + CORNER_NONE = 0, + CORNER_TL = 1, + CORNER_TR = 2, + CORNER_BL = 4, + CORNER_BR = 8, + + CORNER_T = CORNER_TL | CORNER_TR, + CORNER_B = CORNER_BL | CORNER_BR, + CORNER_R = CORNER_TR | CORNER_BR, + CORNER_L = CORNER_TL | CORNER_BL, + + CORNER_ALL = CORNER_T | CORNER_B + }; virtual void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) = 0; struct CColorVertex diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index a7d4ce0b48e..8be0ca1efa9 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -1153,7 +1153,7 @@ void CChat::OnPrepareLines() { float Height = m_aLines[r].m_aYOffset[OffsetType]; Graphics()->SetColor(1, 1, 1, 1); - m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, (AppendCursor.m_LongestLineWidth - TextBegin) + RealMsgPaddingX * 1.5f, Height, MESSAGE_ROUNDING, CUI::CORNER_ALL); + m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, (AppendCursor.m_LongestLineWidth - TextBegin) + RealMsgPaddingX * 1.5f, Height, MESSAGE_ROUNDING, IGraphics::CORNER_ALL); } TextRender()->SetRenderFlags(CurRenderFlags); diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 978f3e6cbb4..49864bf7177 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -545,7 +545,7 @@ void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, v if(pInfo->m_EnumCount == pInfo->m_WantedCompletion) { float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1, -1.0f); - pInfo->m_pSelf->RenderTools()->DrawRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, ColorRGBA(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f), CUI::CORNER_ALL, pInfo->m_Cursor.m_FontSize / 3.f); + pInfo->m_pSelf->RenderTools()->DrawRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, ColorRGBA(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f), IGraphics::CORNER_ALL, pInfo->m_Cursor.m_FontSize / 3.f); // scroll when out of sight if(pInfo->m_Cursor.m_X < 3.0f) diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 7dcbf7e95c6..64e3ba89604 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -206,7 +206,7 @@ void CHud::RenderScoreHud() Graphics()->SetColor(1.0f, 0.0f, 0.0f, 0.25f); else Graphics()->SetColor(0.0f, 0.0f, 1.0f, 0.25f); - m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split, ScoreSingleBoxHeight, 5.0f, CUI::CORNER_L); + m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split, ScoreSingleBoxHeight, 5.0f, IGraphics::CORNER_L); } Graphics()->TextureClear(); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -386,7 +386,7 @@ void CHud::RenderScoreHud() Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f); else Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.25f); - m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split - PosSize, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split + PosSize, ScoreSingleBoxHeight, 5.0f, CUI::CORNER_L); + m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split - PosSize, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split + PosSize, ScoreSingleBoxHeight, 5.0f, IGraphics::CORNER_L); } Graphics()->TextureClear(); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -578,7 +578,7 @@ void CHud::RenderVoting() if((!g_Config.m_ClShowVotesAfterVoting && !m_pClient->m_Scoreboard.Active() && m_pClient->m_Voting.TakenChoice()) || !m_pClient->m_Voting.IsVoting() || Client()->State() == IClient::STATE_DEMOPLAYBACK) return; - RenderTools()->DrawRect(-10, 60 - 2, 100 + 10 + 4 + 5, 46, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawRect(-10, 60 - 2, 100 + 10 + 4 + 5, 46, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_ALL, 5.0f); TextRender()->TextColor(1, 1, 1, 1); @@ -1288,7 +1288,7 @@ void CHud::RenderDummyActions() StartY -= 56; } - RenderTools()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_L, 5.0f); + RenderTools()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_L, 5.0f); float y = StartY + 2; float x = StartX + 2; @@ -1358,7 +1358,7 @@ void CHud::RenderMovementInformation(const int ClientID) StartY -= 56; } - RenderTools()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_L, 5.0f); + RenderTools()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_L, 5.0f); CNetObj_Character *pCharacter = &m_pClient->m_Snap.m_aCharacters[ClientID].m_Cur; const float TicksPerSecond = 50.0f; @@ -1480,7 +1480,7 @@ void CHud::RenderMovementInformation(const int ClientID) void CHud::RenderSpectatorHud() { // draw the box - RenderTools()->DrawRect(m_Width - 180.0f, m_Height - 15.0f, 180.0f, 15.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_TL, 5.0f); + RenderTools()->DrawRect(m_Width - 180.0f, m_Height - 15.0f, 180.0f, 15.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_TL, 5.0f); // draw the text char aBuf[128]; @@ -1494,7 +1494,7 @@ void CHud::RenderLocalTime(float x) return; // draw the box - RenderTools()->DrawRect(x - 30.0f, 0.0f, 25.0f, 12.5f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_B, 3.75f); + RenderTools()->DrawRect(x - 30.0f, 0.0f, 25.0f, 12.5f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_B, 3.75f); // draw the text char aTimeStr[6]; diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index d72e5304ced..6c0b4ae187f 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -188,7 +188,7 @@ int CMenus::DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f * UI()->ButtonColorMul(pID)), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); CUIRect Temp; pRect->HMargin(1.0f, &Temp); UI()->DoLabel(&Temp, pText, Temp.h * CUI::ms_FontmodHeight, TEXTALIGN_CENTER); @@ -279,9 +279,9 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe int CMenus::DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { if(Checked == 2) - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 0.98f, 0.5f, 0.55f), CUI::CORNER_T, 5.0f); + RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 0.98f, 0.5f, 0.55f), IGraphics::CORNER_T, 5.0f); else if(Checked) - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_T, 5.0f); + RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_T, 5.0f); CUIRect t; pRect->VSplitLeft(5.0f, 0, &t); UI()->DoLabel(&t, pText, pRect->h * CUI::ms_FontmodHeight, TEXTALIGN_LEFT); @@ -298,7 +298,7 @@ int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const c t.VSplitLeft(5.0f, 0, &t); c.Margin(2.0f, &c); - RenderTools()->DrawUIRect(&c, ColorRGBA(1, 1, 1, 0.25f * UI()->ButtonColorMul(pID)), CUI::CORNER_ALL, 3.0f); + RenderTools()->DrawUIRect(&c, ColorRGBA(1, 1, 1, 0.25f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 3.0f); const bool Checkable = *pBoxText == 'X'; SLabelProperties Props; @@ -408,7 +408,7 @@ ColorHSLA CMenus::DoLine_ColorPicker(CButtonContainer *pResetID, const float Lin Button.HSplitTop(2.0f, 0x0, &Button); Button.HSplitBottom(2.0f, &Button, 0x0); - if(DoButton_Menu(pResetID, Localize("Reset"), 0, &Button, 0, CUI::CORNER_ALL, 8.0f, 0, vec4(1, 1, 1, 0.5f), vec4(1, 1, 1, 0.25f), 1, true)) + if(DoButton_Menu(pResetID, Localize("Reset"), 0, &Button, 0, IGraphics::CORNER_ALL, 8.0f, 0, vec4(1, 1, 1, 0.5f), vec4(1, 1, 1, 0.25f), 1, true)) { ColorHSLA HSL = color_cast(DefaultColor); *pColorValue = HSL.Pack(false); @@ -476,7 +476,7 @@ int CMenus::DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool if(ms_ValueSelectorTextMode && s_pLastTextpID == pID) { static float s_NumberBoxID = 0; - UIEx()->DoEditBox(&s_NumberBoxID, pRect, s_aNumStr, sizeof(s_aNumStr), 10.0f, &s_NumberBoxID, false, CUI::CORNER_ALL); + UIEx()->DoEditBox(&s_NumberBoxID, pRect, s_aNumStr, sizeof(s_aNumStr), 10.0f, &s_NumberBoxID, false, IGraphics::CORNER_ALL); UI()->SetActiveItem(&s_NumberBoxID); @@ -556,7 +556,7 @@ int CMenus::DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool else str_format(aBuf, sizeof(aBuf), "%d", Current); } - RenderTools()->DrawUIRect(pRect, *pColor, CUI::CORNER_ALL, Round); + RenderTools()->DrawUIRect(pRect, *pColor, IGraphics::CORNER_ALL, Round); UI()->DoLabel(pRect, aBuf, 10, TEXTALIGN_CENTER); } @@ -688,7 +688,7 @@ int CMenus::RenderMenubar(CUIRect r) pHomeButtonColorHover = &HomeButtonColorAlertHover; } - if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_HOME], pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover, 10.0f, 0)) + if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_HOME], pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover, 10.0f, 0)) { m_ShowStart = true; m_DoubleClickIndex = -1; @@ -704,7 +704,7 @@ int CMenus::RenderMenubar(CUIRect r) { Box.VSplitLeft(100.0f, &Button, &Box); static CButtonContainer s_NewsButton; - if(DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage == PAGE_NEWS, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_NEWS])) + if(DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage == PAGE_NEWS, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_NEWS])) { NewPage = PAGE_NEWS; m_DoubleClickIndex = -1; @@ -714,7 +714,7 @@ int CMenus::RenderMenubar(CUIRect r) { Box.VSplitLeft(100.0f, &Button, &Box); static CButtonContainer s_DemosButton; - if(DoButton_MenuTab(&s_DemosButton, Localize("Demos"), m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_DEMOS])) + if(DoButton_MenuTab(&s_DemosButton, Localize("Demos"), m_ActivePage == PAGE_DEMOS, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_DEMOS])) { DemolistPopulate(); NewPage = PAGE_DEMOS; @@ -725,7 +725,7 @@ int CMenus::RenderMenubar(CUIRect r) { Box.VSplitLeft(100.0f, &Button, &Box); static CButtonContainer s_InternetButton; - if(DoButton_MenuTab(&s_InternetButton, Localize("Internet"), m_ActivePage == PAGE_INTERNET, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_INTERNET])) + if(DoButton_MenuTab(&s_InternetButton, Localize("Internet"), m_ActivePage == PAGE_INTERNET, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_INTERNET])) { if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); @@ -735,7 +735,7 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitLeft(100.0f, &Button, &Box); static CButtonContainer s_LanButton; - if(DoButton_MenuTab(&s_LanButton, Localize("LAN"), m_ActivePage == PAGE_LAN, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_LAN])) + if(DoButton_MenuTab(&s_LanButton, Localize("LAN"), m_ActivePage == PAGE_LAN, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_LAN])) { if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_LAN) ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); @@ -745,7 +745,7 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitLeft(100.0f, &Button, &Box); static CButtonContainer s_FavoritesButton; - if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage == PAGE_FAVORITES, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_FAVORITES])) + if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage == PAGE_FAVORITES, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_FAVORITES])) { if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_FAVORITES) ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); @@ -755,7 +755,7 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitLeft(90.0f, &Button, &Box); static CButtonContainer s_DDNetButton; - if(DoButton_MenuTab(&s_DDNetButton, "DDNet", m_ActivePage == PAGE_DDNET, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_DDNET])) + if(DoButton_MenuTab(&s_DDNetButton, "DDNet", m_ActivePage == PAGE_DDNET, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_DDNET])) { if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_DDNET) { @@ -768,7 +768,7 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitLeft(90.0f, &Button, &Box); static CButtonContainer s_KoGButton; - if(DoButton_MenuTab(&s_KoGButton, "KoG", m_ActivePage == PAGE_KOG, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_KOG])) + if(DoButton_MenuTab(&s_KoGButton, "KoG", m_ActivePage == PAGE_KOG, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_KOG])) { if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_KOG) { @@ -785,7 +785,7 @@ int CMenus::RenderMenubar(CUIRect r) // online menus Box.VSplitLeft(90.0f, &Button, &Box); static CButtonContainer s_GameButton; - if(DoButton_MenuTab(&s_GameButton, Localize("Game"), m_ActivePage == PAGE_GAME, &Button, CUI::CORNER_TL)) + if(DoButton_MenuTab(&s_GameButton, Localize("Game"), m_ActivePage == PAGE_GAME, &Button, IGraphics::CORNER_TL)) NewPage = PAGE_GAME; Box.VSplitLeft(90.0f, &Button, &Box); @@ -816,7 +816,7 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitLeft(100.0f, &Button, &Box); Box.VSplitLeft(4.0f, 0, &Box); static CButtonContainer s_CallVoteButton; - if(DoButton_MenuTab(&s_CallVoteButton, Localize("Call vote"), m_ActivePage == PAGE_CALLVOTE, &Button, CUI::CORNER_TR)) + if(DoButton_MenuTab(&s_CallVoteButton, Localize("Call vote"), m_ActivePage == PAGE_CALLVOTE, &Button, IGraphics::CORNER_TR)) { NewPage = PAGE_CALLVOTE; m_ControlPageOpening = true; @@ -829,7 +829,7 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitRight(33.0f, &Box, &Button); static CButtonContainer s_QuitButton; ColorRGBA QuitColor(1, 0, 0, 0.5f); - if(DoButton_MenuTab(&s_QuitButton, "\xEF\x80\x91", 0, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_QUIT], NULL, NULL, &QuitColor, 10.0f, 0)) + if(DoButton_MenuTab(&s_QuitButton, "\xEF\x80\x91", 0, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_QUIT], NULL, NULL, &QuitColor, 10.0f, 0)) { if(m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) { @@ -845,13 +845,13 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitRight(33.0f, &Box, &Button); static CButtonContainer s_SettingsButton; - if(DoButton_MenuTab(&s_SettingsButton, "\xEF\x80\x93", m_ActivePage == PAGE_SETTINGS, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SETTINGS], NULL, NULL, NULL, 10.0f, 0)) + if(DoButton_MenuTab(&s_SettingsButton, "\xEF\x80\x93", m_ActivePage == PAGE_SETTINGS, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SETTINGS], NULL, NULL, NULL, 10.0f, 0)) NewPage = PAGE_SETTINGS; Box.VSplitRight(10.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button); static CButtonContainer s_EditorButton; - if(DoButton_MenuTab(&s_EditorButton, "\xEF\x81\x84", 0, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_EDITOR], NULL, NULL, NULL, 10.0f, 0)) + if(DoButton_MenuTab(&s_EditorButton, "\xEF\x81\x84", 0, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_EDITOR], NULL, NULL, NULL, 10.0f, 0)) { g_Config.m_ClEditor = 1; } @@ -862,14 +862,14 @@ int CMenus::RenderMenubar(CUIRect r) Box.VSplitRight(33.0f, &Box, &Button); static CButtonContainer s_DemoButton; - if(DoButton_MenuTab(&s_DemoButton, "\xEE\x84\xB1", m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON], NULL, NULL, NULL, 10.0f, 0)) + if(DoButton_MenuTab(&s_DemoButton, "\xEE\x84\xB1", m_ActivePage == PAGE_DEMOS, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON], NULL, NULL, NULL, 10.0f, 0)) NewPage = PAGE_DEMOS; Box.VSplitRight(10.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button); static CButtonContainer s_ServerButton; - if(DoButton_MenuTab(&s_ServerButton, "\xEF\x95\xBD", m_ActivePage == g_Config.m_UiPage, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SERVER], NULL, NULL, NULL, 10.0f, 0)) + if(DoButton_MenuTab(&s_ServerButton, "\xEF\x95\xBD", m_ActivePage == g_Config.m_UiPage, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SERVER], NULL, NULL, NULL, 10.0f, 0)) NewPage = g_Config.m_UiPage; } @@ -922,7 +922,7 @@ void CMenus::RenderLoading(const char *pCaption, const char *pContent, int Incre Graphics()->BlendNormal(); Graphics()->TextureClear(); - RenderTools()->DrawUIRect(&Box, ColorRGBA{0, 0, 0, 0.50f}, CUI::CORNER_ALL, 15.0f); + RenderTools()->DrawUIRect(&Box, ColorRGBA{0, 0, 0, 0.50f}, IGraphics::CORNER_ALL, 15.0f); CUIRect Part; @@ -940,7 +940,7 @@ void CMenus::RenderLoading(const char *pCaption, const char *pContent, int Incre UI()->DoLabel(&Part, pContent, 20.0f, TEXTALIGN_CENTER); if(RenderLoadingBar) - RenderTools()->DrawRect(Box.x + 40, Box.y + Box.h - 75, (Box.w - 80) * Percent, 25, ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawRect(Box.x + 40, Box.y + Box.h - 75, (Box.w - 80) * Percent, 25, ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f), IGraphics::CORNER_ALL, 5.0f); Client()->UpdateAndSwap(); } @@ -949,7 +949,7 @@ void CMenus::RenderNews(CUIRect MainView) { g_Config.m_UiUnreadNews = false; - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.HSplitTop(15.0f, 0, &MainView); MainView.VSplitLeft(15.0f, 0, &MainView); @@ -1158,14 +1158,14 @@ void CMenus::RenderColorPicker() rgb = color_cast(ColorHSVA(PickerColorHSV.x, 1.0f, 1.0f)); vec4 BR(rgb.r, rgb.g, rgb.b, 1.0f); - RenderTools()->DrawUIRect4(&ColorsArea, TL, TR, BL, BR, CUI::CORNER_NONE, 0.0f); + RenderTools()->DrawUIRect4(&ColorsArea, TL, TR, BL, BR, IGraphics::CORNER_NONE, 0.0f); TL = vec4(0.0f, 0.0f, 0.0f, 0.0f); TR = vec4(0.0f, 0.0f, 0.0f, 0.0f); BL = vec4(0.0f, 0.0f, 0.0f, 1.0f); BR = vec4(0.0f, 0.0f, 0.0f, 1.0f); - RenderTools()->DrawUIRect4(&ColorsArea, TL, TR, BL, BR, CUI::CORNER_NONE, 0.0f); + RenderTools()->DrawUIRect4(&ColorsArea, TL, TR, BL, BR, IGraphics::CORNER_NONE, 0.0f); // Hue Area static const float s_aColorIndices[7][3] = { @@ -1188,7 +1188,7 @@ void CMenus::RenderColorPicker() BL = vec4(s_aColorIndices[j + 1][0], s_aColorIndices[j + 1][1], s_aColorIndices[j + 1][2], 1.0f); HuePartialArea.y = HueArea.y + HuePickerOffset * j; - RenderTools()->DrawUIRect4(&HuePartialArea, TL, TL, BL, BL, CUI::CORNER_NONE, 0.0f); + RenderTools()->DrawUIRect4(&HuePartialArea, TL, TL, BL, BL, IGraphics::CORNER_NONE, 0.0f); } //Editboxes Area @@ -1215,7 +1215,7 @@ void CMenus::RenderColorPicker() // TODO : ALPHA SUPPORT //static int ALPHAID = 0; UI()->DoLabel(&ALPHARect, "A: 255", 10, TEXTALIGN_CENTER); - RenderTools()->DrawUIRect(&ALPHARect, ColorRGBA(0, 0, 0, 0.65f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&ALPHARect, ColorRGBA(0, 0, 0, 0.65f), IGraphics::CORNER_ALL, 5.0f); // Logic float PickerX, PickerY; @@ -1257,9 +1257,9 @@ void CMenus::RenderColorPicker() const float HMOColor = PickerColorHSV.x > 0.75f ? 1.0f : 0.0f; ColorRGBA HueMarkerOutline(HMOColor, HMOColor, HMOColor, 1); - RenderTools()->DrawUIRect(&HueMarker, HueMarkerOutline, CUI::CORNER_ALL, 1.2f); + RenderTools()->DrawUIRect(&HueMarker, HueMarkerOutline, IGraphics::CORNER_ALL, 1.2f); HueMarker.Margin(1.2f, &HueMarker); - RenderTools()->DrawUIRect(&HueMarker, HueMarkerColor, CUI::CORNER_ALL, 1.2f); + RenderTools()->DrawUIRect(&HueMarker, HueMarkerColor, IGraphics::CORNER_ALL, 1.2f); ms_ColorPicker.m_HSVColor = PickerColorHSV.Pack(false); *ms_ColorPicker.m_pColor = color_cast(PickerColorHSV).Pack(false); @@ -1618,7 +1618,7 @@ int CMenus::Render() Box.Margin(150.0f, &Box); // render the box - RenderTools()->DrawUIRect(&Box, BgColor, CUI::CORNER_ALL, 15.0f); + RenderTools()->DrawUIRect(&Box, BgColor, IGraphics::CORNER_ALL, 15.0f); Box.HSplitTop(20.f, &Part, &Box); Box.HSplitTop(24.f, &Part, &Box); @@ -1826,9 +1826,9 @@ int CMenus::Render() Box.HSplitTop(20.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); Part.VMargin(40.0f, &Part); - RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 5.0f); Part.w = maximum(10.0f, (Part.w * Client()->MapDownloadAmount()) / Client()->MapDownloadTotalsize()); - RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), IGraphics::CORNER_ALL, 5.0f); } } else if(m_Popup == POPUP_LANGUAGE) @@ -2075,14 +2075,14 @@ int CMenus::Render() Part.VSplitLeft(5.0f, 0, &Part); Part.VSplitLeft(ButtonSize, &Button, &Part); static CButtonContainer s_SlowDownButton; - if(DoButton_Sprite(&s_SlowDownButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_SLOWER, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_SlowDownButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_SLOWER, 0, &Button, IGraphics::CORNER_ALL)) DecDemoSpeed = true; // fastforward Part.VSplitLeft(5.0f, 0, &Part); Part.VSplitLeft(ButtonSize, &Button, &Part); static CButtonContainer s_FastForwardButton; - if(DoButton_Sprite(&s_FastForwardButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_FASTER, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_FastForwardButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_FASTER, 0, &Button, IGraphics::CORNER_ALL)) IncDemoSpeed = true; // speed meter @@ -2227,7 +2227,7 @@ int CMenus::Render() static float s_Offset = 0.0f; SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = Client()->PlayerName(); - UIEx()->DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &s_Offset, false, CUI::CORNER_ALL, EditProps); + UIEx()->DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps); } else if(m_Popup == POPUP_POINTS) { diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 4c6975f1814..59e7ad8c921 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -85,7 +85,7 @@ class CMenus : public CComponent int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect); int DoButton_Sprite(CButtonContainer *pButtonContainer, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners); int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active); - int DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = nullptr, int Corners = CUI::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1, bool CheckForActiveColorPicker = false); + int DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = nullptr, int Corners = IGraphics::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1, bool CheckForActiveColorPicker = false); int DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator = nullptr, const ColorRGBA *pDefaultColor = nullptr, const ColorRGBA *pActiveColor = nullptr, const ColorRGBA *pHoverColor = nullptr, float EdgeRounding = 10, int AlignVertically = 1); int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect); @@ -110,7 +110,7 @@ class CMenus : public CComponent // new gui with gui elements template - int DoButtonMenu(CUIElement &UIElement, const void *pID, T &&GetTextLambda, int Checked, const CUIRect *pRect, bool HintRequiresStringCheck, bool HintCanChangePositionOrSize = false, int Corners = CUI::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1) + int DoButtonMenu(CUIElement &UIElement, const void *pID, T &&GetTextLambda, int Checked, const CUIRect *pRect, bool HintRequiresStringCheck, bool HintCanChangePositionOrSize = false, int Corners = IGraphics::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1) { CUIRect Text = *pRect; Text.HMargin(pRect->h >= 20.0f ? 2.0f : 1.0f, &Text); diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index a6dd54ef264..4bb9343b39c 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -59,7 +59,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) View.HSplitBottom(70.0f, &View, &Status); // split of the scrollbar - RenderTools()->DrawUIRect(&Headers, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_T, 5.0f); + RenderTools()->DrawUIRect(&Headers, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); Headers.VSplitRight(20.0f, &Headers, 0); struct CColumn @@ -286,13 +286,13 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) { CUIRect r = Row; r.Margin(0.5f, &r); - RenderTools()->DrawUIElRect(*pItem->m_pUIElement->Get(0), &r, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIElRect(*pItem->m_pUIElement->Get(0), &r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } else if(UI()->MouseHovered(&Row)) { CUIRect r = Row; r.Margin(0.5f, &r); - RenderTools()->DrawUIElRect(*pItem->m_pUIElement->Get(1), &r, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIElRect(*pItem->m_pUIElement->Get(1), &r, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); } if(UI()->DoButtonLogic(pItem, Selected, &Row)) @@ -494,7 +494,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } } - //RenderTools()->DrawUIRect(&Status, ms_ColorTabbarActive, CUI::CORNER_B, 5.0f); + //RenderTools()->DrawUIRect(&Status, ms_ColorTabbarActive, IGraphics::CORNER_B, 5.0f); Status.Margin(5.0f, &Status); CUIRect SearchInfoAndAddr, ServersAndConnect, Status3; @@ -549,7 +549,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } static int s_ClearButton = 0; static float s_Offset = 0.0f; - if(UIEx()->DoClearableEditBox(&g_Config.m_BrFilterString, &s_ClearButton, &QuickSearch, g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString), 12.0f, &s_Offset, false, CUI::CORNER_ALL, EditProps)) + if(UIEx()->DoClearableEditBox(&g_Config.m_BrFilterString, &s_ClearButton, &QuickSearch, g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps)) Client()->ServerBrowserUpdate(); } @@ -576,7 +576,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) static float s_Offset = 0.0f; if(Input()->KeyPress(KEY_X) && (Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) && Input()->ModifierIsPressed()) UI()->SetActiveItem(&g_Config.m_BrExcludeString); - if(UIEx()->DoClearableEditBox(&g_Config.m_BrExcludeString, &s_ClearButton, &QuickExclude, g_Config.m_BrExcludeString, sizeof(g_Config.m_BrExcludeString), 12.0f, &s_Offset, false, CUI::CORNER_ALL)) + if(UIEx()->DoClearableEditBox(&g_Config.m_BrExcludeString, &s_ClearButton, &QuickExclude, g_Config.m_BrExcludeString, sizeof(g_Config.m_BrExcludeString), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL)) Client()->ServerBrowserUpdate(); } @@ -631,7 +631,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) return m_aLocalStringHelper; }; - if(DoButtonMenu(m_RefreshButton, &s_RefreshButton, Func, 0, &ButtonRefresh, true, false, CUI::CORNER_ALL) || Input()->KeyPress(KEY_F5) || (Input()->KeyPress(KEY_R) && Input()->ModifierIsPressed())) + if(DoButtonMenu(m_RefreshButton, &s_RefreshButton, Func, 0, &ButtonRefresh, true, false, IGraphics::CORNER_ALL) || Input()->KeyPress(KEY_F5) || (Input()->KeyPress(KEY_R) && Input()->ModifierIsPressed())) { if(g_Config.m_UiPage == PAGE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); @@ -657,7 +657,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) static int s_JoinButton = 0; if(DoButtonMenu( - m_ConnectButton, &s_JoinButton, []() -> const char * { return Localize("Connect"); }, 0, &ButtonConnect, false, false, CUI::CORNER_ALL, 5, 0, vec4(0.7f, 1, 0.7f, 0.1f), vec4(0.7f, 1, 0.7f, 0.2f)) || + m_ConnectButton, &s_JoinButton, []() -> const char * { return Localize("Connect"); }, 0, &ButtonConnect, false, false, IGraphics::CORNER_ALL, 5, 0, vec4(0.7f, 1, 0.7f, 0.1f), vec4(0.7f, 1, 0.7f, 0.2f)) || m_EnterPressed) { if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) @@ -680,9 +680,9 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) // server filter ServerFilter.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFilter); - RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_T, 4.0f); + RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); - RenderTools()->DrawUIRect(&ServerFilter, ColorRGBA(0, 0, 0, 0.15f), CUI::CORNER_B, 4.0f); + RenderTools()->DrawUIRect(&ServerFilter, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); UI()->DoLabel(&FilterHeader, Localize("Server filter"), FontSize + 2.0f, TEXTALIGN_CENTER); CUIRect Button, Button2; @@ -797,20 +797,20 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); ServerFilter.HSplitTop(120.0f, &ServerFilter, 0); - RenderTools()->DrawUIRect(&ServerFilter, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&ServerFilter, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); Button.VSplitMid(&Button, &Button2); static int s_ActivePage = 0; static CButtonContainer s_CountriesButton; - if(DoButton_MenuTab(&s_CountriesButton, Localize("Countries"), s_ActivePage == 0, &Button, CUI::CORNER_TL)) + if(DoButton_MenuTab(&s_CountriesButton, Localize("Countries"), s_ActivePage == 0, &Button, IGraphics::CORNER_TL)) { s_ActivePage = 0; } static CButtonContainer s_TypesButton; - if(DoButton_MenuTab(&s_TypesButton, Localize("Types"), s_ActivePage == 1, &Button2, CUI::CORNER_TR)) + if(DoButton_MenuTab(&s_TypesButton, Localize("Types"), s_ActivePage == 1, &Button2, IGraphics::CORNER_TR)) { s_ActivePage = 1; } @@ -1047,8 +1047,8 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) CTextCursor Cursor; const float FontSize = 12.0f; ServerDetails.HSplitTop(ms_ListheaderHeight, &ServerHeader, &ServerDetails); - RenderTools()->DrawUIRect(&ServerHeader, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_T, 4.0f); - RenderTools()->DrawUIRect(&ServerDetails, ColorRGBA(0, 0, 0, 0.15f), CUI::CORNER_B, 4.0f); + RenderTools()->DrawUIRect(&ServerHeader, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); + RenderTools()->DrawUIRect(&ServerDetails, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); UI()->DoLabel(&ServerHeader, Localize("Server details"), FontSize + 2.0f, TEXTALIGN_CENTER); if(pSelectedServer) @@ -1159,7 +1159,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) ColorRGBA Color = pSelectedServer->m_aClients[i].m_FriendState == IFriends::FRIEND_NO ? ColorRGBA(1.0f, 1.0f, 1.0f, (i % 2 + 1) * 0.05f) : ColorRGBA(0.5f, 1.0f, 0.5f, 0.15f + (i % 2 + 1) * 0.05f); - RenderTools()->DrawUIRect(&Name, Color, CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&Name, Color, IGraphics::CORNER_ALL, 4.0f); Name.VSplitLeft(5.0f, 0, &Name); Name.VSplitLeft(34.0f, &Score, &Name); Name.VSplitRight(34.0f, &Name, &Flag); @@ -1266,7 +1266,7 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) // header ServerFriends.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFriends); - RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_T, 4.0f); + RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); RenderTools()->DrawUIRect(&ServerFriends, ColorRGBA(0, 0, 0, 0.15f), 0, 4.0f); UI()->DoLabel(&FilterHeader, Localize("Friends"), FontSize + 4.0f, TEXTALIGN_CENTER); CUIRect Button, List; @@ -1291,14 +1291,14 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) Item.m_Rect.Margin(1.5f, &Item.m_Rect); CUIRect OnState; Item.m_Rect.VSplitRight(30.0f, &Item.m_Rect, &OnState); - RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.1f), CUI::CORNER_L, 4.0f); + RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.1f), IGraphics::CORNER_L, 4.0f); Item.m_Rect.VMargin(2.5f, &Item.m_Rect); Item.m_Rect.HSplitTop(12.0f, &Item.m_Rect, &Button); UI()->DoLabel(&Item.m_Rect, Friend.m_pFriendInfo->m_aName, FontSize, TEXTALIGN_LEFT); UI()->DoLabel(&Button, Friend.m_pFriendInfo->m_aClan, FontSize, TEXTALIGN_LEFT); - RenderTools()->DrawUIRect(&OnState, Friend.m_NumFound ? ColorRGBA(0.0f, 1.0f, 0.0f, 0.25f) : ColorRGBA(1.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_R, 4.0f); + RenderTools()->DrawUIRect(&OnState, Friend.m_NumFound ? ColorRGBA(0.0f, 1.0f, 0.0f, 0.25f) : ColorRGBA(1.0f, 0.0f, 0.0f, 0.25f), IGraphics::CORNER_R, 4.0f); OnState.HMargin((OnState.h - FontSize) / 3, &OnState); OnState.VMargin(5.0f, &OnState); char aBuf[64]; @@ -1397,7 +1397,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) CUIRect ServerList, ToolBox; // background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); // create server list, status box, tab bar and tool box area @@ -1413,7 +1413,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) // tool box { - RenderTools()->DrawUIRect(&ToolBox, ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&ToolBox, ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f), IGraphics::CORNER_ALL, 4.0f); if(ToolboxPage == 0) RenderServerbrowserFilters(ToolBox); @@ -1438,7 +1438,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) ms_ColorTabbarInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f); static CButtonContainer s_FiltersTab; - if(DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage == 0, &TabButton0, CUI::CORNER_BL, NULL, NULL, NULL, NULL, 4.0f)) + if(DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage == 0, &TabButton0, IGraphics::CORNER_BL, NULL, NULL, NULL, NULL, 4.0f)) ToolboxPage = 0; static CButtonContainer s_InfoTab; @@ -1446,7 +1446,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) ToolboxPage = 1; static CButtonContainer s_FriendsTab; - if(DoButton_MenuTab(&s_FriendsTab, Localize("Friends"), ToolboxPage == 2, &TabButton2, CUI::CORNER_BR, NULL, NULL, NULL, NULL, 4.0f)) + if(DoButton_MenuTab(&s_FriendsTab, Localize("Friends"), ToolboxPage == 2, &TabButton2, IGraphics::CORNER_BR, NULL, NULL, NULL, NULL, 4.0f)) ToolboxPage = 2; ms_ColorTabbarActive = Active; diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 9179ce54d35..7bbe2a69e3d 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -29,7 +29,7 @@ using namespace std::chrono_literals; int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, (Checked ? 0.10f : 0.5f) * UI()->ButtonColorMul(pID)), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, (Checked ? 0.10f : 0.5f) * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); UI()->DoLabel(pRect, pText, 14.0f, TEXTALIGN_CENTER); return UI()->DoButtonLogic(pID, Checked, pRect); } @@ -86,7 +86,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) Box.Margin(150.0f, &Box); // render the box - RenderTools()->DrawUIRect(&Box, ColorRGBA(0, 0, 0, 0.5f), CUI::CORNER_ALL, 15.0f); + RenderTools()->DrawUIRect(&Box, ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, 15.0f); Box.HSplitTop(20.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); @@ -256,7 +256,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) MainView.VSplitLeft(50.0f, 0, &MainView); MainView.VSplitLeft(450.0f, &MainView, 0); - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_T, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_T, 10.0f); MainView.Margin(5.0f, &MainView); @@ -277,13 +277,13 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) char aBuffer[128]; // draw seek bar - RenderTools()->DrawUIRect(&SeekBar, ColorRGBA(0, 0, 0, 0.5f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&SeekBar, ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, 5.0f); // draw filled bar float Amount = CurrentTick / (float)TotalTicks; CUIRect FilledBar = SeekBar; FilledBar.w = 10.0f + (FilledBar.w - 10.0f) * Amount; - RenderTools()->DrawUIRect(&FilledBar, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&FilledBar, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 5.0f); // draw markers for(int i = 0; i < pInfo->m_NumTimelineMarkers; i++) @@ -393,7 +393,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) // combined play and pause button ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_PlayPauseButton; - if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, pInfo->m_Paused ? SPRITE_DEMOBUTTON_PLAY : SPRITE_DEMOBUTTON_PAUSE, false, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, pInfo->m_Paused ? SPRITE_DEMOBUTTON_PLAY : SPRITE_DEMOBUTTON_PAUSE, false, &Button, IGraphics::CORNER_ALL)) { if(pInfo->m_Paused) { @@ -410,7 +410,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_ResetButton; - if(DoButton_Sprite(&s_ResetButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_STOP, false, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_ResetButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_STOP, false, &Button, IGraphics::CORNER_ALL)) { DemoPlayer()->Pause(); DemoPlayer()->SeekPercent(0.0f); @@ -420,14 +420,14 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SlowDownButton; - if(DoButton_Sprite(&s_SlowDownButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_SLOWER, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_SlowDownButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_SLOWER, 0, &Button, IGraphics::CORNER_ALL)) DecreaseDemoSpeed = true; // fastforward ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_FastForwardButton; - if(DoButton_Sprite(&s_FastForwardButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_FASTER, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_FastForwardButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_FASTER, 0, &Button, IGraphics::CORNER_ALL)) IncreaseDemoSpeed = true; // speed meter @@ -440,21 +440,21 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) ButtonBar.VSplitLeft(Margins * 10, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SliceBeginButton; - if(DoButton_Sprite(&s_SliceBeginButton, IMAGE_DEMOBUTTONS2, SPRITE_DEMOBUTTON_SLICE_BEGIN, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_SliceBeginButton, IMAGE_DEMOBUTTONS2, SPRITE_DEMOBUTTON_SLICE_BEGIN, 0, &Button, IGraphics::CORNER_ALL)) Client()->DemoSliceBegin(); // slice end button ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SliceEndButton; - if(DoButton_Sprite(&s_SliceEndButton, IMAGE_DEMOBUTTONS2, SPRITE_DEMOBUTTON_SLICE_END, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_SliceEndButton, IMAGE_DEMOBUTTONS2, SPRITE_DEMOBUTTON_SLICE_END, 0, &Button, IGraphics::CORNER_ALL)) Client()->DemoSliceEnd(); // slice save button ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SliceSaveButton; - if(DoButton_Sprite(&s_SliceSaveButton, IMAGE_FILEICONS, SPRITE_FILE_DEMO2, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_SliceSaveButton, IMAGE_FILEICONS, SPRITE_FILE_DEMO2, 0, &Button, IGraphics::CORNER_ALL)) { str_copy(m_aCurrentDemoFile, m_vDemos[m_DemolistSelectedIndex].m_aFilename); m_aDemoPlayerPopupHint[0] = '\0'; @@ -475,7 +475,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) ButtonBar.VSplitRight(ButtonbarHeight, &ButtonBar, &Button); static CButtonContainer s_KeyboardShortcutsButton; int Sprite = g_Config.m_ClDemoKeyboardShortcuts ? SPRITE_DEMOBUTTON_SHORTCUTS_ENABLED : SPRITE_DEMOBUTTON_SHORTCUTS_DISABLED; - if(DoButton_Sprite(&s_KeyboardShortcutsButton, IMAGE_DEMOBUTTONS2, Sprite, 0, &Button, CUI::CORNER_ALL)) + if(DoButton_Sprite(&s_KeyboardShortcutsButton, IMAGE_DEMOBUTTONS2, Sprite, 0, &Button, IGraphics::CORNER_ALL)) { g_Config.m_ClDemoKeyboardShortcuts ^= 1; } @@ -524,7 +524,7 @@ void CMenus::UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHe if(!LogicOnly) { // background - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.15f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_ALL, 5.0f); } View.VSplitRight(20.0f, &View, &Scroll); @@ -710,13 +710,13 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected, //selected_index = i; CUIRect r = Item.m_Rect; r.Margin(1.5f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } else if(UI()->MouseInside(&HitRect) && !NoHoverEffects) { CUIRect r = Item.m_Rect; r.Margin(1.5f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); } return Item; @@ -866,7 +866,7 @@ void CMenus::RenderDemoList(CUIRect MainView) } // render background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); #if defined(CONF_VIDEORECORDER) @@ -900,7 +900,7 @@ void CMenus::RenderDemoList(CUIRect MainView) // render demo info MainView.VMargin(5.0f, &MainView); MainView.HSplitBottom(5.0f, &MainView, 0); - RenderTools()->DrawUIRect(&MainView, ColorRGBA(0, 0, 0, 0.15f), CUI::CORNER_B, 4.0f); + RenderTools()->DrawUIRect(&MainView, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_vDemos[m_DemolistSelectedIndex].m_Valid) { CUIRect Left, Right, Labels; @@ -1115,13 +1115,13 @@ void CMenus::RenderDemoList(CUIRect MainView) { CUIRect Rect = Row; Rect.Margin(0.5f, &Rect); - RenderTools()->DrawUIRect(&Rect, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&Rect, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } else if(UI()->MouseHovered(&Row)) { CUIRect Rect = Row; Rect.Margin(0.5f, &Rect); - RenderTools()->DrawUIRect(&Rect, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&Rect, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); } if(UI()->DoButtonLogic(Item.m_aName, Selected, &Row)) diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 5b15fd56201..14ad6b9f1c7 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -38,7 +38,7 @@ void CMenus::RenderGame(CUIRect MainView) { CUIRect Button, ButtonBar, ButtonBar2; MainView.HSplitTop(45.0f, &ButtonBar, &MainView); - RenderTools()->DrawUIRect(&ButtonBar, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&ButtonBar, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); // button bar ButtonBar.HSplitTop(10.0f, 0, &ButtonBar); @@ -70,7 +70,7 @@ void CMenus::RenderGame(CUIRect MainView) static CButtonContainer s_DummyButton; if(!Client()->DummyAllowed()) { - DoButton_Menu(&s_DummyButton, Localize("Connect Dummy"), 1, &Button, nullptr, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(1.0f, 0.5f, 0.5f, 0.75f), vec4(1, 0.5f, 0.5f, 0.5f)); + DoButton_Menu(&s_DummyButton, Localize("Connect Dummy"), 1, &Button, nullptr, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(1.0f, 0.5f, 0.5f, 0.75f), vec4(1, 0.5f, 0.5f, 0.5f)); } else if(DummyConnecting) { @@ -209,11 +209,11 @@ void CMenus::RenderGame(CUIRect MainView) void CMenus::RenderPlayers(CUIRect MainView) { CUIRect Button, Button2, ButtonBar, Options, Player; - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); // player options MainView.Margin(10.0f, &Options); - RenderTools()->DrawUIRect(&Options, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&Options, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 10.0f); Options.Margin(10.0f, &Options); Options.HSplitTop(50.0f, &Button, &Options); UI()->DoLabel(&Button, Localize("Player options"), 34.0f, TEXTALIGN_LEFT); @@ -278,7 +278,7 @@ void CMenus::RenderPlayers(CUIRect MainView) continue; if(Count % 2 == 1) - RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 10.0f); Item.m_Rect.VSplitRight(300.0f, &Player, &Item.m_Rect); // player info @@ -359,7 +359,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) Client()->GetServerInfo(&CurrentServerInfo); // render background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); CUIRect View, ServerInfo, GameInfo, Motd; @@ -374,7 +374,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) // serverinfo View.HSplitTop(View.h / 2 - 5.0f, &ServerInfo, &Motd); ServerInfo.VSplitLeft(View.w / 2 - 5.0f, &ServerInfo, &GameInfo); - RenderTools()->DrawUIRect(&ServerInfo, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&ServerInfo, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); ServerInfo.Margin(5.0f, &ServerInfo); @@ -418,7 +418,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) // gameinfo GameInfo.VSplitLeft(10.0f, 0x0, &GameInfo); - RenderTools()->DrawUIRect(&GameInfo, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&GameInfo, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); GameInfo.Margin(5.0f, &GameInfo); @@ -451,7 +451,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) // motd Motd.HSplitTop(10.0f, 0, &Motd); - RenderTools()->DrawUIRect(&Motd, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&Motd, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); Motd.Margin(5.0f, &Motd); y = 0.0f; x = 5.0f; @@ -567,7 +567,7 @@ void CMenus::RenderServerControl(CUIRect MainView) MainView.HSplitTop(20.0f, &Bottom, &MainView); RenderTools()->DrawUIRect(&Bottom, ms_ColorTabbarActive, 0, 10.0f); MainView.HSplitTop(20.0f, &TabBar, &MainView); - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); if(Client()->RconAuthed()) @@ -633,7 +633,7 @@ void CMenus::RenderServerControl(CUIRect MainView) EditProps.m_SelectText = true; } EditProps.m_pEmptyText = Localize("Search"); - UIEx()->DoClearableEditBox(&m_aFilterString, &s_ClearButton, &QuickSearch, m_aFilterString, sizeof(m_aFilterString), 14.0f, &s_Offset, false, CUI::CORNER_ALL, EditProps); + UIEx()->DoClearableEditBox(&m_aFilterString, &s_ClearButton, &QuickSearch, m_aFilterString, sizeof(m_aFilterString), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps); } Bottom.VSplitRight(120.0f, &Bottom, &Button); @@ -680,7 +680,7 @@ void CMenus::RenderServerControl(CUIRect MainView) static float s_Offset = 0.0f; if(Input()->KeyPress(KEY_R) && Input()->ModifierIsPressed()) UI()->SetActiveItem(&m_aCallvoteReason); - UIEx()->DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, CUI::CORNER_ALL); + UIEx()->DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL); // extended features (only available when authed in rcon) if(Client()->RconAuthed()) @@ -751,11 +751,11 @@ void CMenus::RenderServerControl(CUIRect MainView) Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(250.0f, &Button, &Bottom); static float s_OffsetDesc = 0.0f; - UIEx()->DoEditBox(&s_aVoteDescription, &Button, s_aVoteDescription, sizeof(s_aVoteDescription), 14.0f, &s_OffsetDesc, false, CUI::CORNER_ALL); + UIEx()->DoEditBox(&s_aVoteDescription, &Button, s_aVoteDescription, sizeof(s_aVoteDescription), 14.0f, &s_OffsetDesc, false, IGraphics::CORNER_ALL); Bottom.VMargin(20.0f, &Button); static float s_OffsetCmd = 0.0f; - UIEx()->DoEditBox(&s_aVoteCommand, &Button, s_aVoteCommand, sizeof(s_aVoteCommand), 14.0f, &s_OffsetCmd, false, CUI::CORNER_ALL); + UIEx()->DoEditBox(&s_aVoteCommand, &Button, s_aVoteCommand, sizeof(s_aVoteCommand), 14.0f, &s_OffsetCmd, false, IGraphics::CORNER_ALL); } } } @@ -769,7 +769,7 @@ void CMenus::RenderInGameNetwork(CUIRect MainView) int Page = g_Config.m_UiPage; int NewPage = -1; - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); Box.HSplitTop(5.0f, &MainView, &MainView); Box.HSplitTop(24.0f, &Box, &MainView); @@ -815,7 +815,7 @@ void CMenus::RenderInGameNetwork(CUIRect MainView) Box.VSplitLeft(110.0f, &Button, &Box); static CButtonContainer s_KoGButton; - if(DoButton_MenuTab(&s_KoGButton, "KoG", Page == PAGE_KOG, &Button, CUI::CORNER_BR)) + if(DoButton_MenuTab(&s_KoGButton, "KoG", Page == PAGE_KOG, &Button, IGraphics::CORNER_BR)) { if(Page != PAGE_KOG) { @@ -920,7 +920,7 @@ void CMenus::DeleteGhostItem(int Index) void CMenus::RenderGhost(CUIRect MainView) { // render background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.HSplitTop(10.0f, 0, &MainView); MainView.HSplitBottom(5.0f, &MainView, 0); @@ -934,7 +934,7 @@ void CMenus::RenderGhost(CUIRect MainView) View.HSplitBottom(28.0f, &View, &Status); // split of the scrollbar - RenderTools()->DrawUIRect(&Headers, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_T, 5.0f); + RenderTools()->DrawUIRect(&Headers, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); Headers.VSplitRight(20.0f, &Headers, 0); struct CColumn @@ -1011,7 +1011,7 @@ void CMenus::RenderGhost(CUIRect MainView) { CUIRect r = Row; r.Margin(1.5f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } if(UI()->DoButtonLogic(pItem, 0, &Row)) @@ -1080,7 +1080,7 @@ void CMenus::RenderGhost(CUIRect MainView) if(NewSelected != -1) s_SelectedIndex = NewSelected; - RenderTools()->DrawUIRect(&Status, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_B, 5.0f); + RenderTools()->DrawUIRect(&Status, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_B, 5.0f); Status.Margin(5.0f, &Status); CUIRect Button; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 29c82b0a156..eca7d7d6132 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -327,7 +327,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) static float s_OffsetName = 0.0f; SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = pNameFallback; - if(UIEx()->DoEditBox(pName, &Button, pName, sizeof(g_Config.m_PlayerName), 14.0f, &s_OffsetName, false, CUI::CORNER_ALL, EditProps)) + if(UIEx()->DoEditBox(pName, &Button, pName, sizeof(g_Config.m_PlayerName), 14.0f, &s_OffsetName, false, IGraphics::CORNER_ALL, EditProps)) { SetNeedSendInfo(); } @@ -564,7 +564,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) EyesLabel.HSplitTop(10.0f, 0, &EyesLabel); } Highlight = (m_Dummy) ? g_Config.m_ClDummyDefaultEyes == CurrentEyeEmote : g_Config.m_ClPlayerDefaultEyes == CurrentEyeEmote; - if(DoButton_Menu(&s_aEyeButtons[CurrentEyeEmote], "", 0, &EyesTee, 0, CUI::CORNER_ALL, 10.0f, 0.0f, vec4(1, 1, 1, 0.5f + Highlight * 0.25f), vec4(1, 1, 1, 0.25f + Highlight * 0.25f))) + if(DoButton_Menu(&s_aEyeButtons[CurrentEyeEmote], "", 0, &EyesTee, 0, IGraphics::CORNER_ALL, 10.0f, 0.0f, vec4(1, 1, 1, 0.5f + Highlight * 0.25f), vec4(1, 1, 1, 0.25f + Highlight * 0.25f))) { if(m_Dummy) { @@ -587,7 +587,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) static int s_ClearButton = 0; SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = "default"; - if(UIEx()->DoClearableEditBox(pSkinName, &s_ClearButton, &Label, pSkinName, sizeof(g_Config.m_ClPlayerSkin), 14.0f, &s_OffsetSkin, false, CUI::CORNER_ALL, EditProps)) + if(UIEx()->DoClearableEditBox(pSkinName, &s_ClearButton, &Label, pSkinName, sizeof(g_Config.m_ClPlayerSkin), 14.0f, &s_OffsetSkin, false, IGraphics::CORNER_ALL, EditProps)) { SetNeedSendInfo(); } @@ -740,7 +740,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) EditPropsSearch.m_SelectText = true; } EditPropsSearch.m_pEmptyText = Localize("Search"); - if(UIEx()->DoClearableEditBox(&g_Config.m_ClSkinFilterString, &s_ClearButtonSearch, &QuickSearch, g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString), 14.0f, &s_Offset, false, CUI::CORNER_ALL, EditPropsSearch)) + if(UIEx()->DoClearableEditBox(&g_Config.m_ClSkinFilterString, &s_ClearButtonSearch, &QuickSearch, g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditPropsSearch)) s_InitSkinlist = true; } @@ -773,7 +773,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT)); 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 | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE); static CButtonContainer s_SkinRefreshButtonID; - if(DoButton_Menu(&s_SkinRefreshButtonID, "\xEF\x80\x9E", 0, &RefreshButton, nullptr, CUI::CORNER_ALL, 5, 0, vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4(1, 1, 1, 0.5f), 0)) + if(DoButton_Menu(&s_SkinRefreshButtonID, "\xEF\x80\x9E", 0, &RefreshButton, nullptr, IGraphics::CORNER_ALL, 5, 0, vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4(1, 1, 1, 0.5f), 0)) { // reset render flags for possible loading screen TextRender()->SetRenderFlags(0); @@ -971,7 +971,7 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View) UIEx()->DoScrollbarOption(&g_Config.m_InpControllerTolerance, &g_Config.m_InpControllerTolerance, &Button, Localize("Controller jitter tolerance"), 0, 50); View.HSplitTop(Spacing, 0, &View); - RenderTools()->DrawUIRect(&View, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&View, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); DoJoystickAxisPicker(View); } else @@ -1014,7 +1014,7 @@ void CMenus::DoJoystickAxisPicker(CUIRect View) View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Row, &View); - RenderTools()->DrawUIRect(&Row, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&Row, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); // Device label Row.VSplitLeft(DeviceLabelWidth, &Button, &Row); @@ -1062,18 +1062,18 @@ void CMenus::DoJoystickBar(const CUIRect *pRect, float Current, float Tolerance, CUIRect Rail; pRect->HMargin(4.0f, &Rail); - RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, Active ? 0.25f : 0.125f), CUI::CORNER_ALL, Rail.h / 2.0f); + RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, Active ? 0.25f : 0.125f), IGraphics::CORNER_ALL, Rail.h / 2.0f); CUIRect ToleranceArea = Rail; ToleranceArea.w *= Tolerance; ToleranceArea.x += (Rail.w - ToleranceArea.w) / 2.0f; ColorRGBA ToleranceColor = Active ? ColorRGBA(0.8f, 0.35f, 0.35f, 1.0f) : ColorRGBA(0.7f, 0.5f, 0.5f, 1.0f); - RenderTools()->DrawUIRect(&ToleranceArea, ToleranceColor, CUI::CORNER_ALL, ToleranceArea.h / 2.0f); + RenderTools()->DrawUIRect(&ToleranceArea, ToleranceColor, IGraphics::CORNER_ALL, ToleranceArea.h / 2.0f); CUIRect Slider = Handle; Slider.HMargin(4.0f, &Slider); ColorRGBA SliderColor = Active ? ColorRGBA(0.95f, 0.95f, 0.95f, 1.0f) : ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f); - RenderTools()->DrawUIRect(&Slider, SliderColor, CUI::CORNER_ALL, Slider.h / 2.0f); + RenderTools()->DrawUIRect(&Slider, SliderColor, IGraphics::CORNER_ALL, Slider.h / 2.0f); } void CMenus::RenderSettingsControls(CUIRect MainView) @@ -1124,7 +1124,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { MouseSettings.VMargin(5.0f, &MouseSettings); MouseSettings.HSplitTop(80.0f, &MouseSettings, &JoystickSettings); - RenderTools()->DrawUIRect(&MouseSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&MouseSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); MouseSettings.VMargin(10.0f, &MouseSettings); TextRender()->Text(0, MouseSettings.x, MouseSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Mouse"), -1.0f); @@ -1145,7 +1145,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { JoystickSettings.HSplitTop(Margin, 0, &JoystickSettings); JoystickSettings.HSplitTop(s_JoystickSettingsHeight, &JoystickSettings, &MovementSettings); - RenderTools()->DrawUIRect(&JoystickSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&JoystickSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); JoystickSettings.VMargin(Margin, &JoystickSettings); TextRender()->Text(0, JoystickSettings.x, JoystickSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Controller"), -1.0f); @@ -1158,7 +1158,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { MovementSettings.HSplitTop(Margin, 0, &MovementSettings); MovementSettings.HSplitTop(365.0f, &MovementSettings, &WeaponSettings); - RenderTools()->DrawUIRect(&MovementSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&MovementSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); MovementSettings.VMargin(Margin, &MovementSettings); TextRender()->Text(0, MovementSettings.x, MovementSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Movement"), -1.0f); @@ -1171,7 +1171,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { WeaponSettings.HSplitTop(Margin, 0, &WeaponSettings); WeaponSettings.HSplitTop(190.0f, &WeaponSettings, &ResetButton); - RenderTools()->DrawUIRect(&WeaponSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&WeaponSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); WeaponSettings.VMargin(Margin, &WeaponSettings); TextRender()->Text(0, WeaponSettings.x, WeaponSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Weapon"), -1.0f); @@ -1184,7 +1184,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { ResetButton.HSplitTop(Margin, 0, &ResetButton); ResetButton.HSplitTop(40.0f, &ResetButton, 0); - RenderTools()->DrawUIRect(&ResetButton, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&ResetButton, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); ResetButton.HMargin(10.0f, &ResetButton); ResetButton.VMargin(30.0f, &ResetButton); ResetButton.HSplitTop(20.0f, &ResetButton, 0); @@ -1211,7 +1211,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { VotingSettings.VMargin(5.0f, &VotingSettings); VotingSettings.HSplitTop(80.0f, &VotingSettings, &ChatSettings); - RenderTools()->DrawUIRect(&VotingSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&VotingSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); VotingSettings.VMargin(Margin, &VotingSettings); TextRender()->Text(0, VotingSettings.x, VotingSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Voting"), -1.0f); @@ -1224,7 +1224,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { ChatSettings.HSplitTop(Margin, 0, &ChatSettings); ChatSettings.HSplitTop(145.0f, &ChatSettings, &DummySettings); - RenderTools()->DrawUIRect(&ChatSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&ChatSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); ChatSettings.VMargin(Margin, &ChatSettings); TextRender()->Text(0, ChatSettings.x, ChatSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Chat"), -1.0f); @@ -1237,7 +1237,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { DummySettings.HSplitTop(Margin, 0, &DummySettings); DummySettings.HSplitTop(100.0f, &DummySettings, &MiscSettings); - RenderTools()->DrawUIRect(&DummySettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&DummySettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); DummySettings.VMargin(Margin, &DummySettings); TextRender()->Text(0, DummySettings.x, DummySettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Dummy"), -1.0f); @@ -1250,7 +1250,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { MiscSettings.HSplitTop(Margin, 0, &MiscSettings); MiscSettings.HSplitTop(300.0f, &MiscSettings, 0); - RenderTools()->DrawUIRect(&MiscSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawUIRect(&MiscSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); MiscSettings.VMargin(Margin, &MiscSettings); TextRender()->Text(0, MiscSettings.x, MiscSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Miscellaneous"), -1.0f); @@ -1293,7 +1293,7 @@ int CMenus::RenderDropDown(int &CurDropDownState, CUIRect *pRect, int CurSelecti { CUIRect Button; pRect->HSplitTop(24.0f, &Button, pRect); - if(DoButton_MenuTab(pButtonContainer, CurSelection > -1 ? pStr[CurSelection] : "", 0, &Button, CUI::CORNER_ALL, NULL, NULL, NULL, NULL, 4.0f)) + if(DoButton_MenuTab(pButtonContainer, CurSelection > -1 ? pStr[CurSelection] : "", 0, &Button, IGraphics::CORNER_ALL, NULL, NULL, NULL, NULL, 4.0f)) CurDropDownState = 1; CUIRect DropDownIcon = Button; @@ -1976,11 +1976,11 @@ void CMenus::RenderSettings(CUIRect MainView) // render background CUIRect Temp, TabBar, RestartWarning; MainView.VSplitRight(120.0f, &MainView, &TabBar); - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); + RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); MainView.HSplitBottom(15.0f, &MainView, &RestartWarning); TabBar.HSplitTop(50.0f, &Temp, &TabBar); - RenderTools()->DrawUIRect(&Temp, ms_ColorTabbarActive, CUI::CORNER_BR, 10.0f); + RenderTools()->DrawUIRect(&Temp, ms_ColorTabbarActive, IGraphics::CORNER_BR, 10.0f); MainView.HSplitTop(10.0f, 0, &MainView); @@ -2006,7 +2006,7 @@ void CMenus::RenderSettings(CUIRect MainView) { TabBar.HSplitTop(10, &Button, &TabBar); TabBar.HSplitTop(26, &Button, &TabBar); - if(DoButton_MenuTab(&s_aTabButtons[i], apTabs[i], g_Config.m_UiSettingsPage == i, &Button, CUI::CORNER_R, &m_aAnimatorsSettingsTab[i])) + if(DoButton_MenuTab(&s_aTabButtons[i], apTabs[i], g_Config.m_UiSettingsPage == i, &Button, IGraphics::CORNER_R, &m_aAnimatorsSettingsTab[i])) g_Config.m_UiSettingsPage = i; } @@ -2090,8 +2090,8 @@ ColorHSLA CMenus::RenderHSLColorPicker(const CUIRect *pRect, unsigned int *pColo CUIRect Rect; pRect->Margin(OutlineSize, &Rect); - RenderTools()->DrawUIRect(pRect, Outline, CUI::CORNER_ALL, 4.0f); - RenderTools()->DrawUIRect(&Rect, RGBColor, CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(pRect, Outline, IGraphics::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&Rect, RGBColor, IGraphics::CORNER_ALL, 4.0f); if(UI()->DoButtonLogic(pColor, 0, pRect)) { @@ -2139,7 +2139,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool { const float SizeBorder = 5.0f; Graphics()->SetColor(ColorRGBA(0.15f, 0.15f, 0.15f, 1)); - int TmpCont = RenderTools()->CreateRoundRectQuadContainer(Preview.x - SizeBorder / 2.0f, Preview.y - SizeBorder / 2.0f, Preview.w + SizeBorder, Preview.h + SizeBorder, 4.0f + SizeBorder / 2.0f, CUI::CORNER_ALL); + int TmpCont = RenderTools()->CreateRoundRectQuadContainer(Preview.x - SizeBorder / 2.0f, Preview.y - SizeBorder / 2.0f, Preview.w + SizeBorder, Preview.h + SizeBorder, 4.0f + SizeBorder / 2.0f, IGraphics::CORNER_ALL); Graphics()->RenderQuadContainer(TmpCont, -1); Graphics()->DeleteQuadContainer(TmpCont); } @@ -2147,7 +2147,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool if(ClampedLight) RenderColorHSLA = RenderColorHSLA.UnclampLighting(); Graphics()->SetColor(color_cast(RenderColorHSLA)); - int TmpCont = RenderTools()->CreateRoundRectQuadContainer(Preview.x, Preview.y, Preview.w, Preview.h, 4.0f, CUI::CORNER_ALL); + int TmpCont = RenderTools()->CreateRoundRectQuadContainer(Preview.x, Preview.y, Preview.w, Preview.h, 4.0f, IGraphics::CORNER_ALL); Graphics()->RenderQuadContainer(TmpCont, -1); Graphics()->DeleteQuadContainer(TmpCont); @@ -2410,7 +2410,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool Button.VSplitLeft(10.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); - RenderTools()->DrawUIRect(&Button, ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), CUI::CORNER_ALL, 1.0f); + RenderTools()->DrawUIRect(&Button, ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 1.0f); CUIRect Rail; Button.Margin(2.0f, &Rail); @@ -2486,7 +2486,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) static CButtonContainer s_aPageTabs[NUMBER_OF_APPEARANCE_TABS] = {}; - if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_HUD], Localize("HUD"), s_CurTab == APPEARANCE_TAB_HUD, &Page1Tab, CUI::CORNER_L, NULL, NULL, NULL, NULL, 4)) + if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_HUD], Localize("HUD"), s_CurTab == APPEARANCE_TAB_HUD, &Page1Tab, IGraphics::CORNER_L, NULL, NULL, NULL, NULL, 4)) s_CurTab = APPEARANCE_TAB_HUD; if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_CHAT], Localize("Chat"), s_CurTab == APPEARANCE_TAB_CHAT, &Page2Tab, 0, NULL, NULL, NULL, NULL, 4)) s_CurTab = APPEARANCE_TAB_CHAT; @@ -2496,7 +2496,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) s_CurTab = APPEARANCE_TAB_HOOK_COLLISION; if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_KILL_MESSAGES], Localize("Kill Messages"), s_CurTab == APPEARANCE_TAB_KILL_MESSAGES, &Page5Tab, 0, NULL, NULL, NULL, NULL, 4)) s_CurTab = APPEARANCE_TAB_KILL_MESSAGES; - if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_LASER], Localize("Laser"), s_CurTab == APPEARANCE_TAB_LASER, &Page6Tab, CUI::CORNER_R, NULL, NULL, NULL, NULL, 4)) + if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_LASER], Localize("Laser"), s_CurTab == APPEARANCE_TAB_LASER, &Page6Tab, IGraphics::CORNER_R, NULL, NULL, NULL, NULL, 4)) s_CurTab = APPEARANCE_TAB_LASER; MainView.HSplitTop(10.0f, 0x0, &MainView); // Margin @@ -2644,7 +2644,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section = RightView; Section.Margin(SectionMargin, &Section); - RenderTools()->DrawUIRect(&Section, ColorRGBA(1, 1, 1, 0.1f), CUI::CORNER_ALL, 8.0f); + RenderTools()->DrawUIRect(&Section, ColorRGBA(1, 1, 1, 0.1f), IGraphics::CORNER_ALL, 8.0f); Section.HSplitTop(10.0f, 0x0, &Section); // Margin @@ -2696,32 +2696,32 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) { str_format(aLineBuilder, sizeof(aLineBuilder), "*** '%s' entered and joined the game", aBuf); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, CUI::CORNER_ALL); + RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; } str_format(aLineBuilder, sizeof(aLineBuilder), "%sRandom Tee: Hey, how are you %s?", g_Config.m_ClShowIDs ? " 7: " : "", aBuf); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, CUI::CORNER_ALL); + RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; str_format(aLineBuilder, sizeof(aLineBuilder), "%sYour Teammate: Let's speedrun this!", g_Config.m_ClShowIDs ? "11: " : ""); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, CUI::CORNER_ALL); + RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; str_format(aLineBuilder, sizeof(aLineBuilder), "%s%sFriend: Hello there", g_Config.m_ClMessageFriend ? "♥ " : "", g_Config.m_ClShowIDs ? " 8: " : ""); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, CUI::CORNER_ALL); + RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; str_format(aLineBuilder, sizeof(aLineBuilder), "%sSpammer [6]: Hey fools, I'm spamming here!", g_Config.m_ClShowIDs ? " 9: " : ""); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, CUI::CORNER_ALL); + RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; Width = TextRender()->TextWidth(0, RealFontSize, "*** Echo command executed", -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, CUI::CORNER_ALL); + RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); Graphics()->QuadsEnd(); @@ -3206,7 +3206,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) Button.VSplitLeft(5.0f, 0, &Button); SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = Localize("Chat command (e.g. showall 1)"); - UIEx()->DoEditBox(g_Config.m_ClRunOnJoin, &Button, g_Config.m_ClRunOnJoin, sizeof(g_Config.m_ClRunOnJoin), 14.0f, &s_RunOnJoin, false, CUI::CORNER_ALL, EditProps); + UIEx()->DoEditBox(g_Config.m_ClRunOnJoin, &Button, g_Config.m_ClRunOnJoin, sizeof(g_Config.m_ClRunOnJoin), 14.0f, &s_RunOnJoin, false, IGraphics::CORNER_ALL, EditProps); // Updater #if defined(CONF_AUTOUPDATE) { diff --git a/src/game/client/components/menus_settings_assets.cpp b/src/game/client/components/menus_settings_assets.cpp index a388a1fda52..86b66609693 100644 --- a/src/game/client/components/menus_settings_assets.cpp +++ b/src/game/client/components/menus_settings_assets.cpp @@ -396,7 +396,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView) static CButtonContainer s_aPageTabs[NUMBER_OF_ASSETS_TABS] = {}; - if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_ENTITIES], Localize("Entities"), s_CurCustomTab == ASSETS_TAB_ENTITIES, &Page1Tab, CUI::CORNER_L, NULL, NULL, NULL, NULL, 4)) + if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_ENTITIES], Localize("Entities"), s_CurCustomTab == ASSETS_TAB_ENTITIES, &Page1Tab, IGraphics::CORNER_L, NULL, NULL, NULL, NULL, 4)) s_CurCustomTab = ASSETS_TAB_ENTITIES; if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_GAME], Localize("Game"), s_CurCustomTab == ASSETS_TAB_GAME, &Page2Tab, 0, NULL, NULL, NULL, NULL, 4)) s_CurCustomTab = ASSETS_TAB_GAME; @@ -406,7 +406,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView) s_CurCustomTab = ASSETS_TAB_PARTICLES; if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_HUD], Localize("HUD"), s_CurCustomTab == ASSETS_TAB_HUD, &Page5Tab, 0, NULL, NULL, NULL, NULL, 4)) s_CurCustomTab = ASSETS_TAB_HUD; - if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_EXTRAS], Localize("Extras"), s_CurCustomTab == ASSETS_TAB_EXTRAS, &Page6Tab, CUI::CORNER_R, NULL, NULL, NULL, NULL, 4)) + if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_EXTRAS], Localize("Extras"), s_CurCustomTab == ASSETS_TAB_EXTRAS, &Page6Tab, IGraphics::CORNER_R, NULL, NULL, NULL, NULL, 4)) s_CurCustomTab = ASSETS_TAB_EXTRAS; auto LoadStartTime = time_get_nanoseconds(); @@ -659,7 +659,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView) EditProps.m_SelectText = true; } EditProps.m_pEmptyText = Localize("Search"); - if(UIEx()->DoClearableEditBox(&s_aFilterString[s_CurCustomTab], &s_ClearButton, &QuickSearch, s_aFilterString[s_CurCustomTab], sizeof(s_aFilterString[0]), 14.0f, &s_Offset, false, CUI::CORNER_ALL, EditProps)) + if(UIEx()->DoClearableEditBox(&s_aFilterString[s_CurCustomTab], &s_ClearButton, &QuickSearch, s_aFilterString[s_CurCustomTab], sizeof(s_aFilterString[0]), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps)) gs_aInitCustomList[s_CurCustomTab] = true; } @@ -696,7 +696,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView) TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT)); 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 | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE); static CButtonContainer s_AssetsReloadBtnID; - if(DoButton_Menu(&s_AssetsReloadBtnID, "\xEF\x80\x9E", 0, &ReloadButton, nullptr, CUI::CORNER_ALL, 5, 0, vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4(1, 1, 1, 0.5f), 0)) + if(DoButton_Menu(&s_AssetsReloadBtnID, "\xEF\x80\x9E", 0, &ReloadButton, nullptr, IGraphics::CORNER_ALL, 5, 0, vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4(1, 1, 1, 0.5f), 0)) { ClearCustomItems(s_CurCustomTab); } diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index e21a4f23e32..7d84da18af7 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -42,7 +42,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) ExtMenu.HSplitBottom(20.0f, &ExtMenu, &Button); static CButtonContainer s_DiscordButton; - if(DoButton_Menu(&s_DiscordButton, Localize("Discord"), 0, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) + if(DoButton_Menu(&s_DiscordButton, Localize("Discord"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { if(!open_link(Localize("https://ddnet.tw/discord"))) { @@ -54,7 +54,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) ExtMenu.HSplitBottom(5.0f, &ExtMenu, 0); // little space ExtMenu.HSplitBottom(20.0f, &ExtMenu, &Button); static CButtonContainer s_LearnButton; - if(DoButton_Menu(&s_LearnButton, Localize("Learn"), 0, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) + if(DoButton_Menu(&s_LearnButton, Localize("Learn"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { if(!open_link(Localize("https://wiki.ddnet.tw/"))) { @@ -67,7 +67,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) ExtMenu.HSplitBottom(20.0f, &ExtMenu, &Button); static CButtonContainer s_TutorialButton; static float s_JoinTutorialTime = 0.0f; - if(DoButton_Menu(&s_TutorialButton, Localize("Tutorial"), 0, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || + if(DoButton_Menu(&s_TutorialButton, Localize("Tutorial"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (s_JoinTutorialTime != 0.0f && Client()->LocalTime() >= s_JoinTutorialTime)) { const char *pAddr = ServerBrowser()->GetTutorialServer(); @@ -92,7 +92,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) ExtMenu.HSplitBottom(5.0f, &ExtMenu, 0); // little space ExtMenu.HSplitBottom(20.0f, &ExtMenu, &Button); static CButtonContainer s_WebsiteButton; - if(DoButton_Menu(&s_WebsiteButton, Localize("Website"), 0, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) + if(DoButton_Menu(&s_WebsiteButton, Localize("Website"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { if(!open_link("https://ddnet.tw/")) { @@ -104,7 +104,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) ExtMenu.HSplitBottom(5.0f, &ExtMenu, 0); // little space ExtMenu.HSplitBottom(20.0f, &ExtMenu, &Button); static CButtonContainer s_NewsButton; - if(DoButton_Menu(&s_NewsButton, Localize("News"), 0, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), g_Config.m_UiUnreadNews ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || CheckHotKey(KEY_N)) + if(DoButton_Menu(&s_NewsButton, Localize("News"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), g_Config.m_UiUnreadNews ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || CheckHotKey(KEY_N)) NewPage = PAGE_NEWS; CUIRect Menu; @@ -113,7 +113,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) Menu.HSplitBottom(40.0f, &Menu, &Button); static CButtonContainer s_QuitButton; - if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || m_EscapePressed || CheckHotKey(KEY_Q)) + if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || m_EscapePressed || CheckHotKey(KEY_Q)) { if(m_EscapePressed || m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) { @@ -128,13 +128,13 @@ void CMenus::RenderStartMenu(CUIRect MainView) Menu.HSplitBottom(100.0f, &Menu, 0); Menu.HSplitBottom(40.0f, &Menu, &Button); static CButtonContainer s_SettingsButton; - if(DoButton_Menu(&s_SettingsButton, Localize("Settings"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "settings" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || CheckHotKey(KEY_S)) + if(DoButton_Menu(&s_SettingsButton, Localize("Settings"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "settings" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || CheckHotKey(KEY_S)) NewPage = PAGE_SETTINGS; Menu.HSplitBottom(5.0f, &Menu, 0); // little space Menu.HSplitBottom(40.0f, &Menu, &Button); static CButtonContainer s_LocalServerButton; - if(DoButton_Menu(&s_LocalServerButton, m_ServerProcess.Process ? Localize("Stop server") : Localize("Run server"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "local_server" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_ServerProcess.Process ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (CheckHotKey(KEY_R) && Input()->KeyPress(KEY_R))) + if(DoButton_Menu(&s_LocalServerButton, m_ServerProcess.Process ? Localize("Stop server") : Localize("Run server"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "local_server" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_ServerProcess.Process ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (CheckHotKey(KEY_R) && Input()->KeyPress(KEY_R))) { if(m_ServerProcess.Process) { @@ -166,7 +166,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) Menu.HSplitBottom(5.0f, &Menu, 0); // little space Menu.HSplitBottom(40.0f, &Menu, &Button); static CButtonContainer s_MapEditorButton; - if(DoButton_Menu(&s_MapEditorButton, Localize("Editor"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "editor" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_pClient->Editor()->HasUnsavedData() ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (!EditorHotkeyWasPressed && Client()->LocalTime() - EditorHotKeyChecktime < 0.1f && CheckHotKey(KEY_E))) + if(DoButton_Menu(&s_MapEditorButton, Localize("Editor"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "editor" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_pClient->Editor()->HasUnsavedData() ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (!EditorHotkeyWasPressed && Client()->LocalTime() - EditorHotKeyChecktime < 0.1f && CheckHotKey(KEY_E))) { g_Config.m_ClEditor = 1; Input()->MouseModeRelative(); @@ -181,7 +181,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) Menu.HSplitBottom(5.0f, &Menu, 0); // little space Menu.HSplitBottom(40.0f, &Menu, &Button); static CButtonContainer s_DemoButton; - if(DoButton_Menu(&s_DemoButton, Localize("Demos"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "demos" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || CheckHotKey(KEY_D)) + if(DoButton_Menu(&s_DemoButton, Localize("Demos"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "demos" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || CheckHotKey(KEY_D)) { NewPage = PAGE_DEMOS; } @@ -189,7 +189,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) Menu.HSplitBottom(5.0f, &Menu, 0); // little space Menu.HSplitBottom(40.0f, &Menu, &Button); static CButtonContainer s_PlayButton; - if(DoButton_Menu(&s_PlayButton, Localize("Play", "Start menu"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "play_game" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || m_EnterPressed || CheckHotKey(KEY_P)) + if(DoButton_Menu(&s_PlayButton, Localize("Play", "Start menu"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "play_game" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f)) || m_EnterPressed || CheckHotKey(KEY_P)) { NewPage = g_Config.m_UiPage >= PAGE_INTERNET && g_Config.m_UiPage <= PAGE_KOG ? g_Config.m_UiPage : PAGE_DDNET; } @@ -243,7 +243,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) Part.VSplitLeft(100.0f, &Update, NULL); static CButtonContainer s_VersionUpdate; - if(DoButton_Menu(&s_VersionUpdate, Localize("Update now"), 0, &Update, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) + if(DoButton_Menu(&s_VersionUpdate, Localize("Update now"), 0, &Update, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { Updater()->InitiateUpdate(); } @@ -254,7 +254,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) Part.VSplitLeft(50.0f, &Restart, &Part); static CButtonContainer s_VersionUpdate; - if(DoButton_Menu(&s_VersionUpdate, Localize("Restart"), 0, &Restart, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) + if(DoButton_Menu(&s_VersionUpdate, Localize("Restart"), 0, &Restart, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { Client()->Restart(); } @@ -265,9 +265,9 @@ void CMenus::RenderStartMenu(CUIRect MainView) Part.VSplitLeft(100.0f, &ProgressBar, &Percent); ProgressBar.y += 2.0f; ProgressBar.HMargin(1.0f, &ProgressBar); - RenderTools()->DrawUIRect(&ProgressBar, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&ProgressBar, vec4(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 5.0f); ProgressBar.w = clamp((float)Updater()->GetCurrentPercent(), 10.0f, 100.0f); - RenderTools()->DrawUIRect(&ProgressBar, vec4(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&ProgressBar, vec4(1.0f, 1.0f, 1.0f, 0.5f), IGraphics::CORNER_ALL, 5.0f); } #elif defined(CONF_INFORM_UPDATE) if(str_comp(Client()->LatestVersion(), "0") != 0) diff --git a/src/game/client/components/motd.cpp b/src/game/client/components/motd.cpp index abb8381551c..6fecd704a43 100644 --- a/src/game/client/components/motd.cpp +++ b/src/game/client/components/motd.cpp @@ -41,7 +41,7 @@ void CMotd::OnRender() float x = Width / 2 - w / 2; float y = 150.0f; - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), CUI::CORNER_ALL, 40.0f); + RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 40.0f); TextRender()->Text(0, x + 40.0f, y + 40.0f, 32.0f, m_aServerMotd, w - 80.0f); } diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index c04d4de94fd..d166cb68038 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -57,7 +57,7 @@ void CScoreboard::RenderGoals(float x, float y, float w) { float h = 50.0f; - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 10.0f); // render goals if(m_pClient->m_Snap.m_pGameInfoObj) @@ -87,7 +87,7 @@ void CScoreboard::RenderGoals(float x, float y, float w) void CScoreboard::RenderSpectators(float x, float y, float w, float h) { // background - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 10.0f); // Headline y += 10.0f; @@ -168,11 +168,11 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch { int Corners; if(upper16 || upper32 || upper24) - Corners = CUI::CORNER_R; + Corners = IGraphics::CORNER_R; else if(lower16 || lower32 || lower24) - Corners = CUI::CORNER_L; + Corners = IGraphics::CORNER_L; else - Corners = CUI::CORNER_ALL; + Corners = IGraphics::CORNER_ALL; RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners, 17.0f); } @@ -358,9 +358,9 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch ColorRGBA Color = color_cast(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f)); int Corners = 0; if(OldDDTeam != DDTeam) - Corners |= CUI::CORNER_TL | CUI::CORNER_TR; + Corners |= IGraphics::CORNER_TL | IGraphics::CORNER_TR; if(NextDDTeam != DDTeam) - Corners |= CUI::CORNER_BL | CUI::CORNER_BR; + Corners |= IGraphics::CORNER_BL | IGraphics::CORNER_BR; RenderTools()->DrawRect(x - 10.0f, y, w, LineHeight + Spacing, Color, Corners, RoundRadius); if(NextDDTeam != DDTeam) @@ -393,7 +393,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch // background so it's easy to find the local player or the followed one in spectator mode if((!m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_Local) || (m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW && pInfo->m_Local) || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)) { - RenderTools()->DrawRect(x, y, w - 20.0f, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, RoundRadius); + RenderTools()->DrawRect(x, y, w - 20.0f, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, RoundRadius); } // score @@ -565,10 +565,10 @@ void CScoreboard::RenderRecordingNotification(float x) float w = TextRender()->TextWidth(0, 20.0f, aBuf, -1, -1.0f); // draw the box - RenderTools()->DrawRect(x, 0.0f, w + 60.0f, 50.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), CUI::CORNER_B, 15.0f); + RenderTools()->DrawRect(x, 0.0f, w + 60.0f, 50.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_B, 15.0f); // draw the red dot - RenderTools()->DrawRect(x + 20, 15.0f, 20.0f, 20.0f, ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f), CUI::CORNER_ALL, 10.0f); + RenderTools()->DrawRect(x + 20, 15.0f, 20.0f, 20.0f, ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f), IGraphics::CORNER_ALL, 10.0f); TextRender()->Text(0, x + 50.0f, (50.f - 20.f) / 2.f, 20.0f, aBuf, -1.0f); } diff --git a/src/game/client/components/spectator.cpp b/src/game/client/components/spectator.cpp index 7f7cae080ce..d3c398c6080 100644 --- a/src/game/client/components/spectator.cpp +++ b/src/game/client/components/spectator.cpp @@ -243,7 +243,7 @@ void CSpectator::OnRender() Graphics()->MapScreen(0, 0, Width, Height); - RenderTools()->DrawRect(Width / 2.0f - ObjWidth, Height / 2.0f - 300.0f, ObjWidth * 2, 600.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f), CUI::CORNER_ALL, 20.0f); + RenderTools()->DrawRect(Width / 2.0f - ObjWidth, Height / 2.0f - 300.0f, ObjWidth * 2, 600.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f), IGraphics::CORNER_ALL, 20.0f); // clamp mouse position to selector area m_SelectorMouse.x = clamp(m_SelectorMouse.x, -(ObjWidth - 20.0f), ObjWidth - 20.0f); @@ -253,12 +253,12 @@ void CSpectator::OnRender() if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FREEVIEW) || m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW) { - RenderTools()->DrawRect(Width / 2.0f - (ObjWidth - 20.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 20.0f); + RenderTools()->DrawRect(Width / 2.0f - (ObjWidth - 20.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 20.0f); } if(Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FOLLOW) { - RenderTools()->DrawRect(Width / 2.0f - (ObjWidth - 310.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 20.0f); + RenderTools()->DrawRect(Width / 2.0f - (ObjWidth - 310.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 20.0f); } if(m_SelectorMouse.x >= -(ObjWidth - 20.0f) && m_SelectorMouse.x <= -(ObjWidth - 290 + 10.0f) && @@ -334,9 +334,9 @@ void CSpectator::OnRender() ColorRGBA Color = color_cast(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f)); int Corners = 0; if(OldDDTeam != DDTeam) - Corners |= CUI::CORNER_TL | CUI::CORNER_TR; + Corners |= IGraphics::CORNER_TL | IGraphics::CORNER_TR; if(NextDDTeam != DDTeam) - Corners |= CUI::CORNER_BL | CUI::CORNER_BR; + Corners |= IGraphics::CORNER_BL | IGraphics::CORNER_BR; RenderTools()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, Color, Corners, RoundRadius); } @@ -344,7 +344,7 @@ void CSpectator::OnRender() if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == m_pClient->m_Snap.m_apInfoByDDTeamName[i]->m_ClientID) || (Client()->State() != IClient::STATE_DEMOPLAYBACK && m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == m_pClient->m_Snap.m_apInfoByDDTeamName[i]->m_ClientID)) { - RenderTools()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, RoundRadius); + RenderTools()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, RoundRadius); } Selected = false; diff --git a/src/game/client/components/statboard.cpp b/src/game/client/components/statboard.cpp index 93e63ffae5d..93fcc7e3e10 100644 --- a/src/game/client/components/statboard.cpp +++ b/src/game/client/components/statboard.cpp @@ -189,7 +189,7 @@ void CStatboard::RenderGlobalStats() Graphics()->MapScreen(0, 0, StatboardWidth, StatboardHeight); - RenderTools()->DrawRect(x - 10.f, y - 10.f, StatboardContentWidth, StatboardContentHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), CUI::CORNER_ALL, 17.0f); + RenderTools()->DrawRect(x - 10.f, y - 10.f, StatboardContentWidth, StatboardContentHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 17.0f); float tw; int px = 325; @@ -267,7 +267,7 @@ void CStatboard::RenderGlobalStats() if(m_pClient->m_Snap.m_LocalClientID == pInfo->m_ClientID || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)) { // background so it's easy to find the local player - RenderTools()->DrawRect(x - 10, y + ContentLineOffset / 2, StatboardContentWidth, LineHeight - ContentLineOffset, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_NONE, 0.0f); + RenderTools()->DrawRect(x - 10, y + ContentLineOffset / 2, StatboardContentWidth, LineHeight - ContentLineOffset, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_NONE, 0.0f); } CTeeRenderInfo Teeinfo = m_pClient->m_aClients[pInfo->m_ClientID].m_RenderInfo; diff --git a/src/game/client/components/tooltips.cpp b/src/game/client/components/tooltips.cpp index b33af1714d8..3f3821c0693 100644 --- a/src/game/client/components/tooltips.cpp +++ b/src/game/client/components/tooltips.cpp @@ -106,7 +106,7 @@ void CTooltips::OnRender() Rect.y = clamp(UI()->MouseY() - Rect.h / 2.0f, MARGIN, pScreen->h - Rect.h - MARGIN); } - RenderTools()->DrawUIRect(&Rect, ColorRGBA(0.2, 0.2, 0.2, 0.80f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&Rect, ColorRGBA(0.2, 0.2, 0.2, 0.80f), IGraphics::CORNER_ALL, 5.0f); Rect.Margin(2.0f, &Rect); UI()->DoLabel(&Rect, Tooltip.m_pText, 14.0f, TEXTALIGN_LEFT); Tooltip.m_OnScreen = false; diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index 2e7e133e75a..c762922fbcb 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -304,13 +304,13 @@ void CVoting::OnRender() void CVoting::RenderBars(CUIRect Bars, bool Text) { - RenderTools()->DrawUIRect(&Bars, ColorRGBA(0.8f, 0.8f, 0.8f, 0.5f), CUI::CORNER_ALL, Bars.h / 3); + RenderTools()->DrawUIRect(&Bars, ColorRGBA(0.8f, 0.8f, 0.8f, 0.5f), IGraphics::CORNER_ALL, Bars.h / 3); CUIRect Splitter = Bars; Splitter.x = Splitter.x + Splitter.w / 2; Splitter.w = Splitter.h / 2.0f; Splitter.x -= Splitter.w / 2; - RenderTools()->DrawUIRect(&Splitter, ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f), CUI::CORNER_ALL, Splitter.h / 4); + RenderTools()->DrawUIRect(&Splitter, ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f), IGraphics::CORNER_ALL, Splitter.h / 4); if(m_Total) { @@ -319,7 +319,7 @@ void CVoting::RenderBars(CUIRect Bars, bool Text) { CUIRect YesArea = Bars; YesArea.w *= m_Yes / (float)m_Total; - RenderTools()->DrawUIRect(&YesArea, ColorRGBA(0.2f, 0.9f, 0.2f, 0.85f), CUI::CORNER_ALL, Bars.h / 3); + RenderTools()->DrawUIRect(&YesArea, ColorRGBA(0.2f, 0.9f, 0.2f, 0.85f), IGraphics::CORNER_ALL, Bars.h / 3); if(Text) { @@ -337,7 +337,7 @@ void CVoting::RenderBars(CUIRect Bars, bool Text) CUIRect NoArea = Bars; NoArea.w *= m_No / (float)m_Total; NoArea.x = (Bars.x + Bars.w) - NoArea.w; - RenderTools()->DrawUIRect(&NoArea, ColorRGBA(0.9f, 0.2f, 0.2f, 0.85f), CUI::CORNER_ALL, Bars.h / 3); + RenderTools()->DrawUIRect(&NoArea, ColorRGBA(0.9f, 0.2f, 0.2f, 0.85f), IGraphics::CORNER_ALL, Bars.h / 3); if(Text) { diff --git a/src/game/client/ui.h b/src/game/client/ui.h index bb5e08a6974..6ec75489824 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -241,22 +241,6 @@ class CUI void OnWindowResize(); void OnLanguageChange(); - enum - { - CORNER_NONE = 0, - CORNER_TL = 1, - CORNER_TR = 2, - CORNER_BL = 4, - CORNER_BR = 8, - - CORNER_T = CORNER_TL | CORNER_TR, - CORNER_B = CORNER_BL | CORNER_BR, - CORNER_R = CORNER_TR | CORNER_BR, - CORNER_L = CORNER_TL | CORNER_BL, - - CORNER_ALL = CORNER_T | CORNER_B - }; - void SetEnabled(bool Enabled) { m_Enabled = Enabled; } bool Enabled() const { return m_Enabled; } void Update(float MouseX, float MouseY, float MouseWorldX, float MouseWorldY); diff --git a/src/game/client/ui_ex.cpp b/src/game/client/ui_ex.cpp index 323019a5d63..2c14f8add1f 100644 --- a/src/game/client/ui_ex.cpp +++ b/src/game/client/ui_ex.cpp @@ -107,7 +107,7 @@ float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) } // render - RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, Rail.w / 2.0f); + RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.w / 2.0f); float ColorSlider; if(UI()->CheckActiveItem(pID)) @@ -117,7 +117,7 @@ float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) else ColorSlider = 0.8f; - RenderTools()->DrawUIRect(&Handle, ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), CUI::CORNER_ALL, Handle.w / 2.0f); + RenderTools()->DrawUIRect(&Handle, ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.w / 2.0f); return ReturnValue; } @@ -192,13 +192,13 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, CUIRect Slider; Handle.VMargin(-2.0f, &Slider); Slider.HMargin(-3.0f, &Slider); - RenderTools()->DrawUIRect(&Slider, ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&Slider, ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 5.0f); Slider.Margin(2.0f, &Slider); - RenderTools()->DrawUIRect(&Slider, *pColorInner, CUI::CORNER_ALL, 3.0f); + RenderTools()->DrawUIRect(&Slider, *pColorInner, IGraphics::CORNER_ALL, 3.0f); } else { - RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, Rail.h / 2.0f); + RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.h / 2.0f); float ColorSlider; if(UI()->CheckActiveItem(pID)) @@ -208,7 +208,7 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, else ColorSlider = 0.8f; - RenderTools()->DrawUIRect(&Handle, ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), CUI::CORNER_ALL, Handle.h / 2.0f); + RenderTools()->DrawUIRect(&Handle, ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.h / 2.0f); } return ReturnValue; @@ -705,10 +705,10 @@ bool CUIEx::DoClearableEditBox(const void *pID, const void *pClearID, const CUIR CUIRect EditBox; CUIRect ClearButton; pRect->VSplitRight(15.0f, &EditBox, &ClearButton); - bool ReturnValue = DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, pOffset, Hidden, Corners & ~CUI::CORNER_R, Properties); + bool ReturnValue = DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, pOffset, Hidden, Corners & ~IGraphics::CORNER_R, Properties); 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); - RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~CUI::CORNER_L, 3.0f); + RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~IGraphics::CORNER_L, 3.0f); SLabelProperties Props; Props.m_AlignVertically = 0; diff --git a/src/game/client/ui_ex.h b/src/game/client/ui_ex.h index 87196ae71a0..782fdbe6286 100644 --- a/src/game/client/ui_ex.h +++ b/src/game/client/ui_ex.h @@ -121,8 +121,8 @@ class CUIEx void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, unsigned Flags = 0u); void DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char **ppLabels, int NumLabels, const IScrollbarScale *pScale = &ms_LinearScrollbarScale); - bool DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = CUI::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); - bool DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = CUI::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); + bool DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); + bool DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); }; #endif diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 7ab5251e15e..18b2aa7b905 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -374,7 +374,7 @@ int CEditor::DoButton_Editor_Common(const void *pID, const char *pText, int Chec int CEditor::DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int AlignVert) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_ALL, 3.0f); + RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); CUIRect NewRect = *pRect; SLabelProperties Props; Props.m_AlignVertically = AlignVert; @@ -389,7 +389,7 @@ int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const float Alpha = UI()->HotItem() == pID ? 1.0f : 0.75f; ColorRGBA Color = ColorRGBA(BaseColor.r * Bright, BaseColor.g * Bright, BaseColor.b * Bright, Alpha); - RenderTools()->DrawUIRect(pRect, Color, CUI::CORNER_ALL, 3.0f); + RenderTools()->DrawUIRect(pRect, Color, IGraphics::CORNER_ALL, 3.0f); UI()->DoLabel(pRect, pText, 10.f, TEXTALIGN_CENTER); Checked %= 2; return DoButton_Editor_Common(pID, pText, Checked, pRect, 0, pToolTip); @@ -398,7 +398,7 @@ int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const int CEditor::DoButton_File(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { if(Checked) - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_ALL, 3.0f); + RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); CUIRect t = *pRect; t.VMargin(5.0f, &t); @@ -409,7 +409,7 @@ int CEditor::DoButton_File(const void *pID, const char *pText, int Checked, cons int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { CUIRect r = *pRect; - RenderTools()->DrawUIRect(&r, ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f), CUI::CORNER_T, 3.0f); + RenderTools()->DrawUIRect(&r, ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f), IGraphics::CORNER_T, 3.0f); r = *pRect; r.VMargin(5.0f, &r); @@ -420,7 +420,7 @@ int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, cons int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { if(UI()->HotItem() == pID || Checked) - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_ALL, 3.0f); + RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); CUIRect t = *pRect; t.VMargin(5.0f, &t); @@ -430,7 +430,7 @@ int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_T, 5.0f); + RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_T, 5.0f); CUIRect NewRect = *pRect; UI()->DoLabel(&NewRect, pText, 10, TEXTALIGN_CENTER); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); @@ -448,14 +448,14 @@ int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const int CEditor::DoButton_ButtonInc(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_R, 3.0f); + RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_R, 3.0f); UI()->DoLabel(pRect, pText ? pText : "+", 10, TEXTALIGN_CENTER); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_ButtonDec(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_L, 3.0f); + RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_L, 3.0f); UI()->DoLabel(pRect, pText ? pText : "-", 10, TEXTALIGN_CENTER); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -925,7 +925,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) // zoom group TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_ZoomOutButton = 0; - if(DoButton_Ex(&s_ZoomOutButton, "ZO", 0, &Button, 0, "[NumPad-] Zoom out", CUI::CORNER_L)) + if(DoButton_Ex(&s_ZoomOutButton, "ZO", 0, &Button, 0, "[NumPad-] Zoom out", IGraphics::CORNER_L)) m_ZoomLevel += 50; TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); @@ -939,7 +939,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_ZoomInButton = 0; - if(DoButton_Ex(&s_ZoomInButton, "ZI", 0, &Button, 0, "[NumPad+] Zoom in", CUI::CORNER_R)) + if(DoButton_Ex(&s_ZoomInButton, "ZI", 0, &Button, 0, "[NumPad+] Zoom in", IGraphics::CORNER_R)) m_ZoomLevel -= 50; TB_Top.VSplitLeft(5.0f, nullptr, &TB_Top); @@ -951,7 +951,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) // flip buttons TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_FlipXButton = 0; - if(DoButton_Ex(&s_FlipXButton, "X/X", Enabled, &Button, 0, "[N] Flip brush horizontal", CUI::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_Ex(&s_FlipXButton, "X/X", Enabled, &Button, 0, "[N] Flip brush horizontal", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushFlipX(); @@ -959,7 +959,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_FlipyButton = 0; - if(DoButton_Ex(&s_FlipyButton, "Y/Y", Enabled, &Button, 0, "[M] Flip brush vertical", CUI::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_Ex(&s_FlipyButton, "Y/Y", Enabled, &Button, 0, "[M] Flip brush vertical", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushFlipY(); @@ -981,7 +981,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_CcwButton = 0; - if(DoButton_Ex(&s_CcwButton, "CCW", Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", CUI::CORNER_L) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_Ex(&s_CcwButton, "CCW", Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushRotate(-s_RotationAmount / 360.0f * pi * 2); @@ -989,7 +989,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_CwButton = 0; - if(DoButton_Ex(&s_CwButton, "CW", Enabled, &Button, 0, "[T] Rotates the brush clockwise", CUI::CORNER_R) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_Ex(&s_CwButton, "CW", Enabled, &Button, 0, "[T] Rotates the brush clockwise", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushRotate(s_RotationAmount / 360.0f * pi * 2); @@ -1003,7 +1003,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) { TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_AnimFasterButton = 0; - if(DoButton_Ex(&s_AnimFasterButton, "A+", 0, &Button, 0, "Increase animation speed", CUI::CORNER_L)) + if(DoButton_Ex(&s_AnimFasterButton, "A+", 0, &Button, 0, "Increase animation speed", IGraphics::CORNER_L)) m_AnimateSpeed += 0.5f; TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); @@ -1013,7 +1013,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_AnimSlowerButton = 0; - if(DoButton_Ex(&s_AnimSlowerButton, "A-", 0, &Button, 0, "Decrease animation speed", CUI::CORNER_R)) + if(DoButton_Ex(&s_AnimSlowerButton, "A-", 0, &Button, 0, "Decrease animation speed", IGraphics::CORNER_R)) { if(m_AnimateSpeed > 0.5f) m_AnimateSpeed -= 0.5f; @@ -1027,7 +1027,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) { TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_GridIncreaseButton = 0; - if(DoButton_Ex(&s_GridIncreaseButton, "G-", 0, &Button, 0, "Decrease grid", CUI::CORNER_L)) + if(DoButton_Ex(&s_GridIncreaseButton, "G-", 0, &Button, 0, "Decrease grid", IGraphics::CORNER_L)) { if(m_GridFactor > 1) m_GridFactor--; @@ -1041,7 +1041,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_GridDecreaseButton = 0; - if(DoButton_Ex(&s_GridDecreaseButton, "G+", 0, &Button, 0, "Increase grid", CUI::CORNER_R)) + if(DoButton_Ex(&s_GridDecreaseButton, "G+", 0, &Button, 0, "Increase grid", IGraphics::CORNER_R)) { if(m_GridFactor < 15) m_GridFactor++; @@ -1076,7 +1076,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) if(pT) { TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom); - if(DoButton_Ex(&s_BorderBut, "Border", 0, &Button, 0, "Place tiles in a 2-tile wide border at the edges of the layer", CUI::CORNER_ALL)) + if(DoButton_Ex(&s_BorderBut, "Border", 0, &Button, 0, "Place tiles in a 2-tile wide border at the edges of the layer", IGraphics::CORNER_ALL)) { m_PopupEventType = POPEVENT_PLACE_BORDER_TILES; m_PopupEventActivated = true; @@ -1124,7 +1124,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom); static int s_ModifierButton = 0; - if(DoButton_Ex(&s_ModifierButton, pButtonName, 0, &Button, 0, aBuf, CUI::CORNER_ALL) || (ModPressed && Input()->KeyPress(KEY_A))) + if(DoButton_Ex(&s_ModifierButton, pButtonName, 0, &Button, 0, aBuf, IGraphics::CORNER_ALL) || (ModPressed && Input()->KeyPress(KEY_A))) { static int s_ModifierPopupID = 0; if(!UiPopupExists(&s_ModifierPopupID)) @@ -3137,7 +3137,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_vpImages[pProps[i].m_Value]->m_aName); float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, CUI::CORNER_ALL, FontSize)) + if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL, FontSize)) PopupSelectImageInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); int r = PopupSelectImageResult(); @@ -3189,7 +3189,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_vpSounds[pProps[i].m_Value]->m_aName); float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, CUI::CORNER_ALL, FontSize)) + if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL, FontSize)) PopupSelectSoundInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); int r = PopupSelectSoundResult(); @@ -3208,7 +3208,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_vpImages[pProps[i].m_Min]->m_AutoMapper.GetConfigName(pProps[i].m_Value)); float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, CUI::CORNER_ALL, FontSize)) + if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL, FontSize)) PopupSelectConfigAutoMapInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); int r = PopupSelectConfigAutoMapResult(); @@ -3320,7 +3320,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) { LayersBox.HSplitTop(12.0f, &Slot, &LayersBox); Slot.VSplitLeft(12, &VisibleToggle, &Slot); - if(DoButton_Ex(&m_Map.m_vpGroups[g]->m_Visible, m_Map.m_vpGroups[g]->m_Visible ? "V" : "H", m_Map.m_vpGroups[g]->m_Collapse ? 1 : 0, &VisibleToggle, 0, "Toggle group visibility", CUI::CORNER_L, 10.0f, 0)) + if(DoButton_Ex(&m_Map.m_vpGroups[g]->m_Visible, m_Map.m_vpGroups[g]->m_Visible ? "V" : "H", m_Map.m_vpGroups[g]->m_Collapse ? 1 : 0, &VisibleToggle, 0, "Toggle group visibility", IGraphics::CORNER_L, 10.0f, 0)) m_Map.m_vpGroups[g]->m_Visible = !m_Map.m_vpGroups[g]->m_Visible; str_format(aBuf, sizeof(aBuf), "#%d %s", g, m_Map.m_vpGroups[g]->m_aName); @@ -3328,7 +3328,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) while(TextRender()->TextWidth(nullptr, FontSize, aBuf, -1, -1.0f) > Slot.w) FontSize--; if(int Result = DoButton_Ex(&m_Map.m_vpGroups[g], aBuf, g == m_SelectedGroup, &Slot, - BUTTON_CONTEXT, m_Map.m_vpGroups[g]->m_Collapse ? "Select group. Shift click to select all layers. Double click to expand." : "Select group. Shift click to select all layers. Double click to collapse.", CUI::CORNER_R, FontSize)) + BUTTON_CONTEXT, m_Map.m_vpGroups[g]->m_Collapse ? "Select group. Shift click to select all layers. Double click to expand." : "Select group. Shift click to select all layers. Double click to collapse.", IGraphics::CORNER_R, FontSize)) { if(g != m_SelectedGroup) SelectLayer(0, g); @@ -3371,7 +3371,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) Slot.VSplitLeft(12.0f, nullptr, &Button); Button.VSplitLeft(15, &VisibleToggle, &Button); - if(DoButton_Ex(&m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible, m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible ? "V" : "H", 0, &VisibleToggle, 0, "Toggle layer visibility", CUI::CORNER_L, 10.0f, 0)) + if(DoButton_Ex(&m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible, m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible ? "V" : "H", 0, &VisibleToggle, 0, "Toggle layer visibility", IGraphics::CORNER_L, 10.0f, 0)) m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible = !m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible; if(m_Map.m_vpGroups[g]->m_vpLayers[i]->m_aName[0]) @@ -3423,7 +3423,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) Checked += 6; } if(int Result = DoButton_Ex(m_Map.m_vpGroups[g]->m_vpLayers[i], aBuf, Checked, &Button, - BUTTON_CONTEXT, "Select layer. Shift click to select multiple.", CUI::CORNER_R, FontSize)) + BUTTON_CONTEXT, "Select layer. Shift click to select multiple.", IGraphics::CORNER_R, FontSize)) { static CLayerPopupContext s_LayerPopupContext = {}; if(Result == 1) @@ -3561,7 +3561,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) LayersBox.HSplitTop(12.0f, &Slot, &LayersBox); static int s_NewGroupButton = 0; - if(DoButton_Editor(&s_NewGroupButton, "Add group", 0, &Slot, CUI::CORNER_R, "Adds a new group")) + if(DoButton_Editor(&s_NewGroupButton, "Add group", 0, &Slot, IGraphics::CORNER_R, "Adds a new group")) { m_Map.NewGroup(); m_SelectedGroup = m_Map.m_vpGroups.size() - 1; @@ -4353,7 +4353,7 @@ void CEditor::RenderFileDialog() RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.25f), 0, 0); View.VMargin(150.0f, &View); View.HMargin(50.0f, &View); - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.75f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.75f), IGraphics::CORNER_ALL, 5.0f); View.Margin(10.0f, &View); CUIRect Title, FileBox, FileBoxLabel, ButtonBar, Scroll, PathBox; @@ -4371,7 +4371,7 @@ void CEditor::RenderFileDialog() View.VSplitRight(20.0f, &View, &Scroll); // title - RenderTools()->DrawUIRect(&Title, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 4.0f); + RenderTools()->DrawUIRect(&Title, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); Title.VMargin(10.0f, &Title); UI()->DoLabel(&Title, m_pFileDialogTitle, 12.0f, TEXTALIGN_LEFT); @@ -4411,14 +4411,14 @@ void CEditor::RenderFileDialog() UI()->DoLabel(&FileBoxLabel, "Search:", 10.0f, TEXTALIGN_LEFT); str_copy(m_aFileDialogPrevSearchText, m_aFileDialogSearchText, sizeof(m_aFileDialogPrevSearchText)); static float s_SearchBoxID = 0; - DoEditBox(&s_SearchBoxID, &FileBox, m_aFileDialogSearchText, sizeof(m_aFileDialogSearchText), 10.0f, &s_SearchBoxID, false, CUI::CORNER_L); + DoEditBox(&s_SearchBoxID, &FileBox, m_aFileDialogSearchText, sizeof(m_aFileDialogSearchText), 10.0f, &s_SearchBoxID, false, IGraphics::CORNER_L); if(m_FileDialogOpening) UI()->SetActiveItem(&s_SearchBoxID); // clearSearchbox button { static int s_ClearButton = 0; - RenderTools()->DrawUIRect(&ClearBox, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(&s_ClearButton)), CUI::CORNER_R, 3.0f); + RenderTools()->DrawUIRect(&ClearBox, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(&s_ClearButton)), IGraphics::CORNER_R, 3.0f); UI()->DoLabel(&ClearBox, "×", 10.0f, TEXTALIGN_CENTER); if(UI()->DoButtonLogic(&s_ClearButton, 0, &ClearBox)) { @@ -5392,7 +5392,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd Button.VSplitLeft(70.0f, nullptr, &Button); Button.VSplitLeft(180.0f, &Button, nullptr); static int s_ClearButton = 0; - DoClearableEditBox(&m_CommandBox, &s_ClearButton, &Button, m_aSettingsCommand, sizeof(m_aSettingsCommand), 12.0f, &m_CommandBox, false, CUI::CORNER_ALL); + DoClearableEditBox(&m_CommandBox, &s_ClearButton, &Button, m_aSettingsCommand, sizeof(m_aSettingsCommand), 12.0f, &m_CommandBox, false, IGraphics::CORNER_ALL); if(!ShowServerSettingsEditorLast) // Just activated UI()->SetActiveItem(&m_CommandBox); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 0c0ec15af16..46ca7290b63 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -1021,7 +1021,7 @@ class CEditor : public IEditor int DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip = nullptr); - bool DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = CUI::CORNER_ALL); + bool DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL); bool DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners); void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness); @@ -1033,7 +1033,7 @@ class CEditor : public IEditor bool UiPopupExists(void *pID); bool UiPopupOpen(); - int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree = false, bool IsHex = false, int corners = CUI::CORNER_ALL, ColorRGBA *pColor = nullptr); + int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree = false, bool IsHex = false, int corners = IGraphics::CORNER_ALL, ColorRGBA *pColor = nullptr); static int PopupGroup(CEditor *pEditor, CUIRect View, void *pContext); diff --git a/src/game/editor/layer_sounds.cpp b/src/game/editor/layer_sounds.cpp index b25663c0773..5d65316ea76 100644 --- a/src/game/editor/layer_sounds.cpp +++ b/src/game/editor/layer_sounds.cpp @@ -54,12 +54,12 @@ void CLayerSounds::Render(bool Tileset) float Width = fx2f(Source.m_Shape.m_Rectangle.m_Width); float Height = fx2f(Source.m_Shape.m_Rectangle.m_Height); m_pEditor->RenderTools()->DrawRoundRectExt(fx2f(Source.m_Position.x) + OffsetX - Width / 2, fx2f(Source.m_Position.y) + OffsetY - Height / 2, - Width, Height, 0.0f, CUI::CORNER_NONE); + Width, Height, 0.0f, IGraphics::CORNER_NONE); float Falloff = ((float)Source.m_Falloff / 255.0f); if(Falloff > 0.0f) m_pEditor->RenderTools()->DrawRoundRectExt(fx2f(Source.m_Position.x) + OffsetX - Falloff * Width / 2, fx2f(Source.m_Position.y) + OffsetY - Falloff * Height / 2, - Width * Falloff, Height * Falloff, 0.0f, CUI::CORNER_NONE); + Width * Falloff, Height * Falloff, 0.0f, IGraphics::CORNER_NONE); break; } } diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 42648aab409..84159e058a4 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -72,9 +72,9 @@ void CEditor::UiDoPopupMenu() UI()->SetActiveItem(&s_UiPopups[i].m_pId); } - int Corners = CUI::CORNER_ALL; + int Corners = IGraphics::CORNER_ALL; if(s_UiPopups[i].m_IsMenu) - Corners = CUI::CORNER_R | CUI::CORNER_B; + Corners = IGraphics::CORNER_R | IGraphics::CORNER_B; CUIRect r = s_UiPopups[i].m_Rect; RenderTools()->DrawUIRect(&r, ColorRGBA(0.5f, 0.5f, 0.5f, 0.75f), Corners, 3.0f); From 2a21cd6eabe27b58a0e0ad57e300b0794eabcf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Jul 2022 22:27:35 +0200 Subject: [PATCH 43/72] Move all `DrawRect*` methods from `CRenderTools` to `IGraphics` As the methods do not depend on any game components they are moved to the engine graphics interface. --- src/engine/client/graphics_threaded.cpp | 326 +++++++++++++++++ src/engine/client/graphics_threaded.h | 5 + src/engine/graphics.h | 5 + src/game/client/components/chat.cpp | 2 +- src/game/client/components/console.cpp | 2 +- src/game/client/components/hud.cpp | 14 +- src/game/client/components/menus.cpp | 2 +- src/game/client/components/menus.h | 2 +- src/game/client/components/menus_settings.cpp | 16 +- src/game/client/components/motd.cpp | 2 +- src/game/client/components/scoreboard.cpp | 14 +- src/game/client/components/spectator.cpp | 10 +- src/game/client/components/statboard.cpp | 4 +- src/game/client/render.cpp | 332 +----------------- src/game/client/render.h | 8 - src/game/editor/layer_sounds.cpp | 4 +- 16 files changed, 375 insertions(+), 373 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 813ea8101ab..adde5a6777c 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -1237,6 +1237,332 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe } } +void CGraphics_Threaded::DrawRectExt(float x, float y, float w, float h, float r, int Corners) +{ + int NumItems = 0; + const int Num = 8; + + IGraphics::CFreeformItem ArrayF[Num * 4]; + + for(int i = 0; i < Num; i += 2) + { + float a1 = i / (float)Num * pi / 2; + float a2 = (i + 1) / (float)Num * pi / 2; + float a3 = (i + 2) / (float)Num * pi / 2; + float Ca1 = cosf(a1); + float Ca2 = cosf(a2); + float Ca3 = cosf(a3); + float Sa1 = sinf(a1); + float Sa2 = sinf(a2); + float Sa3 = sinf(a3); + + if(Corners & 1) // TL + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + r, y + r, + x + (1 - Ca1) * r, y + (1 - Sa1) * r, + x + (1 - Ca3) * r, y + (1 - Sa3) * r, + x + (1 - Ca2) * r, y + (1 - Sa2) * r); + + if(Corners & 2) // TR + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + w - r, y + r, + x + w - r + Ca1 * r, y + (1 - Sa1) * r, + x + w - r + Ca3 * r, y + (1 - Sa3) * r, + x + w - r + Ca2 * r, y + (1 - Sa2) * r); + + if(Corners & 4) // BL + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + r, y + h - r, + x + (1 - Ca1) * r, y + h - r + Sa1 * r, + x + (1 - Ca3) * r, y + h - r + Sa3 * r, + x + (1 - Ca2) * r, y + h - r + Sa2 * r); + + if(Corners & 8) // BR + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + w - r, y + h - r, + x + w - r + Ca1 * r, y + h - r + Sa1 * r, + x + w - r + Ca3 * r, y + h - r + Sa3 * r, + x + w - r + Ca2 * r, y + h - r + Sa2 * r); + } + QuadsDrawFreeform(ArrayF, NumItems); + + CQuadItem ArrayQ[9]; + NumItems = 0; + ArrayQ[NumItems++] = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center + ArrayQ[NumItems++] = CQuadItem(x + r, y, w - r * 2, r); // top + ArrayQ[NumItems++] = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom + ArrayQ[NumItems++] = CQuadItem(x, y + r, r, h - r * 2); // left + ArrayQ[NumItems++] = CQuadItem(x + w - r, y + r, r, h - r * 2); // right + + if(!(Corners & 1)) + ArrayQ[NumItems++] = CQuadItem(x, y, r, r); // TL + if(!(Corners & 2)) + ArrayQ[NumItems++] = CQuadItem(x + w, y, -r, r); // TR + if(!(Corners & 4)) + ArrayQ[NumItems++] = CQuadItem(x, y + h, r, -r); // BL + if(!(Corners & 8)) + ArrayQ[NumItems++] = CQuadItem(x + w, y + h, -r, -r); // BR + + QuadsDrawTL(ArrayQ, NumItems); +} + +void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) +{ + if(Corners == 0 || r == 0.0f) + { + SetColor4(ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight); + CQuadItem ItemQ = CQuadItem(x, y, w, h); + QuadsDrawTL(&ItemQ, 1); + return; + } + + int Num = 8; + for(int i = 0; i < Num; i += 2) + { + float a1 = i / (float)Num * pi / 2; + float a2 = (i + 1) / (float)Num * pi / 2; + float a3 = (i + 2) / (float)Num * pi / 2; + float Ca1 = cosf(a1); + float Ca2 = cosf(a2); + float Ca3 = cosf(a3); + float Sa1 = sinf(a1); + float Sa2 = sinf(a2); + float Sa3 = sinf(a3); + + if(Corners & 1) // TL + { + SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x + r, y + r, + x + (1 - Ca1) * r, y + (1 - Sa1) * r, + x + (1 - Ca3) * r, y + (1 - Sa3) * r, + x + (1 - Ca2) * r, y + (1 - Sa2) * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 2) // TR + { + SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x + w - r, y + r, + x + w - r + Ca1 * r, y + (1 - Sa1) * r, + x + w - r + Ca3 * r, y + (1 - Sa3) * r, + x + w - r + Ca2 * r, y + (1 - Sa2) * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 4) // BL + { + SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x + r, y + h - r, + x + (1 - Ca1) * r, y + h - r + Sa1 * r, + x + (1 - Ca3) * r, y + h - r + Sa3 * r, + x + (1 - Ca2) * r, y + h - r + Sa2 * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 8) // BR + { + SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x + w - r, y + h - r, + x + w - r + Ca1 * r, y + h - r + Sa1 * r, + x + w - r + Ca3 * r, y + h - r + Sa3 * r, + x + w - r + Ca2 * r, y + h - r + Sa2 * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 16) // ITL + { + SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x, y, + x + (1 - Ca1) * r, y - r + Sa1 * r, + x + (1 - Ca3) * r, y - r + Sa3 * r, + x + (1 - Ca2) * r, y - r + Sa2 * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 32) // ITR + { + SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x + w, y, + x + w - r + Ca1 * r, y - r + Sa1 * r, + x + w - r + Ca3 * r, y - r + Sa3 * r, + x + w - r + Ca2 * r, y - r + Sa2 * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 64) // IBL + { + SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x, y + h, + x + (1 - Ca1) * r, y + h + (1 - Sa1) * r, + x + (1 - Ca3) * r, y + h + (1 - Sa3) * r, + x + (1 - Ca2) * r, y + h + (1 - Sa2) * r); + QuadsDrawFreeform(&ItemF, 1); + } + + if(Corners & 128) // IBR + { + SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); + IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( + x + w, y + h, + x + w - r + Ca1 * r, y + h + (1 - Sa1) * r, + x + w - r + Ca3 * r, y + h + (1 - Sa3) * r, + x + w - r + Ca2 * r, y + h + (1 - Sa2) * r); + QuadsDrawFreeform(&ItemF, 1); + } + } + + SetColor4(ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight); + CQuadItem ItemQ = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center + QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorTopLeft, ColorTopRight, ColorTopLeft, ColorTopRight); + ItemQ = CQuadItem(x + r, y, w - r * 2, r); // top + QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorBottomLeft, ColorBottomRight, ColorBottomLeft, ColorBottomRight); + ItemQ = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom + QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorTopLeft, ColorTopLeft, ColorBottomLeft, ColorBottomLeft); + ItemQ = CQuadItem(x, y + r, r, h - r * 2); // left + QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorTopRight, ColorTopRight, ColorBottomRight, ColorBottomRight); + ItemQ = CQuadItem(x + w - r, y + r, r, h - r * 2); // right + QuadsDrawTL(&ItemQ, 1); + + if(!(Corners & 1)) + { + SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); + ItemQ = CQuadItem(x, y, r, r); // TL + QuadsDrawTL(&ItemQ, 1); + } + if(!(Corners & 2)) + { + SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); + ItemQ = CQuadItem(x + w, y, -r, r); // TR + QuadsDrawTL(&ItemQ, 1); + } + if(!(Corners & 4)) + { + SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); + ItemQ = CQuadItem(x, y + h, r, -r); // BL + QuadsDrawTL(&ItemQ, 1); + } + if(!(Corners & 8)) + { + SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); + ItemQ = CQuadItem(x + w, y + h, -r, -r); // BR + QuadsDrawTL(&ItemQ, 1); + } +} + +int CGraphics_Threaded::CreateRectQuadContainer(float x, float y, float w, float h, float r, int Corners) +{ + int ContainerIndex = CreateQuadContainer(false); + + if(Corners == 0 || r == 0.0f) + { + CQuadItem ItemQ = CQuadItem(x, y, w, h); + QuadContainerAddQuads(ContainerIndex, &ItemQ, 1); + QuadContainerUpload(ContainerIndex); + QuadContainerChangeAutomaticUpload(ContainerIndex, true); + return ContainerIndex; + } + + IGraphics::CFreeformItem ArrayF[32]; + int NumItems = 0; + int Num = 8; + for(int i = 0; i < Num; i += 2) + { + float a1 = i / (float)Num * pi / 2; + float a2 = (i + 1) / (float)Num * pi / 2; + float a3 = (i + 2) / (float)Num * pi / 2; + float Ca1 = cosf(a1); + float Ca2 = cosf(a2); + float Ca3 = cosf(a3); + float Sa1 = sinf(a1); + float Sa2 = sinf(a2); + float Sa3 = sinf(a3); + + if(Corners & 1) // TL + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + r, y + r, + x + (1 - Ca1) * r, y + (1 - Sa1) * r, + x + (1 - Ca3) * r, y + (1 - Sa3) * r, + x + (1 - Ca2) * r, y + (1 - Sa2) * r); + + if(Corners & 2) // TR + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + w - r, y + r, + x + w - r + Ca1 * r, y + (1 - Sa1) * r, + x + w - r + Ca3 * r, y + (1 - Sa3) * r, + x + w - r + Ca2 * r, y + (1 - Sa2) * r); + + if(Corners & 4) // BL + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + r, y + h - r, + x + (1 - Ca1) * r, y + h - r + Sa1 * r, + x + (1 - Ca3) * r, y + h - r + Sa3 * r, + x + (1 - Ca2) * r, y + h - r + Sa2 * r); + + if(Corners & 8) // BR + ArrayF[NumItems++] = IGraphics::CFreeformItem( + x + w - r, y + h - r, + x + w - r + Ca1 * r, y + h - r + Sa1 * r, + x + w - r + Ca3 * r, y + h - r + Sa3 * r, + x + w - r + Ca2 * r, y + h - r + Sa2 * r); + } + + if(NumItems > 0) + QuadContainerAddQuads(ContainerIndex, ArrayF, NumItems); + + CQuadItem ArrayQ[9]; + NumItems = 0; + ArrayQ[NumItems++] = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center + ArrayQ[NumItems++] = CQuadItem(x + r, y, w - r * 2, r); // top + ArrayQ[NumItems++] = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom + ArrayQ[NumItems++] = CQuadItem(x, y + r, r, h - r * 2); // left + ArrayQ[NumItems++] = CQuadItem(x + w - r, y + r, r, h - r * 2); // right + + if(!(Corners & 1)) + ArrayQ[NumItems++] = CQuadItem(x, y, r, r); // TL + if(!(Corners & 2)) + ArrayQ[NumItems++] = CQuadItem(x + w, y, -r, r); // TR + if(!(Corners & 4)) + ArrayQ[NumItems++] = CQuadItem(x, y + h, r, -r); // BL + if(!(Corners & 8)) + ArrayQ[NumItems++] = CQuadItem(x + w, y + h, -r, -r); // BR + + if(NumItems > 0) + QuadContainerAddQuads(ContainerIndex, ArrayQ, NumItems); + + QuadContainerUpload(ContainerIndex); + QuadContainerChangeAutomaticUpload(ContainerIndex, true); + + return ContainerIndex; +} + +void CGraphics_Threaded::DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) +{ + TextureClear(); + QuadsBegin(); + SetColor(Color); + DrawRectExt(x, y, w, h, Rounding, Corners); + QuadsEnd(); +} + +void CGraphics_Threaded::DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) +{ + TextureClear(); + QuadsBegin(); + DrawRectExt4(x, y, w, h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Rounding, Corners); + QuadsEnd(); +} + void CGraphics_Threaded::DrawCircle(float CenterX, float CenterY, float Radius, int Segments) { IGraphics::CFreeformItem aItems[32]; diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 8362d36ecc8..5941314037c 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -1127,6 +1127,11 @@ class CGraphics_Threaded : public IEngineGraphics void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) override; void QuadsText(float x, float y, float Size, const char *pText) override; + void DrawRectExt(float x, float y, float w, float h, float r, int Corners) override; + void DrawRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) override; + int CreateRectQuadContainer(float x, float y, float w, float h, float r, int Corners) override; + void DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) override; + void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) override; void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) override; const GL_STexCoord *GetCurTextureCoordinates() override diff --git a/src/engine/graphics.h b/src/engine/graphics.h index d77b7df448d..c84524f8bfd 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -457,6 +457,11 @@ class IGraphics : public IInterface CORNER_ALL = CORNER_T | CORNER_B }; + virtual void DrawRectExt(float x, float y, float w, float h, float r, int Corners) = 0; + virtual void DrawRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) = 0; + virtual int CreateRectQuadContainer(float x, float y, float w, float h, float r, int Corners) = 0; + virtual void DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) = 0; + virtual void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) = 0; virtual void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) = 0; struct CColorVertex diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 8be0ca1efa9..a9625598d4b 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -1153,7 +1153,7 @@ void CChat::OnPrepareLines() { float Height = m_aLines[r].m_aYOffset[OffsetType]; Graphics()->SetColor(1, 1, 1, 1); - m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, (AppendCursor.m_LongestLineWidth - TextBegin) + RealMsgPaddingX * 1.5f, Height, MESSAGE_ROUNDING, IGraphics::CORNER_ALL); + m_aLines[r].m_QuadContainerIndex = Graphics()->CreateRectQuadContainer(Begin, y, (AppendCursor.m_LongestLineWidth - TextBegin) + RealMsgPaddingX * 1.5f, Height, MESSAGE_ROUNDING, IGraphics::CORNER_ALL); } TextRender()->SetRenderFlags(CurRenderFlags); diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 49864bf7177..a91fc4980c8 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -545,7 +545,7 @@ void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, v if(pInfo->m_EnumCount == pInfo->m_WantedCompletion) { float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1, -1.0f); - pInfo->m_pSelf->RenderTools()->DrawRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, ColorRGBA(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f), IGraphics::CORNER_ALL, pInfo->m_Cursor.m_FontSize / 3.f); + pInfo->m_pSelf->Graphics()->DrawRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, ColorRGBA(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f), IGraphics::CORNER_ALL, pInfo->m_Cursor.m_FontSize / 3.f); // scroll when out of sight if(pInfo->m_Cursor.m_X < 3.0f) diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 64e3ba89604..fb359b9c428 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -206,7 +206,7 @@ void CHud::RenderScoreHud() Graphics()->SetColor(1.0f, 0.0f, 0.0f, 0.25f); else Graphics()->SetColor(0.0f, 0.0f, 1.0f, 0.25f); - m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split, ScoreSingleBoxHeight, 5.0f, IGraphics::CORNER_L); + m_aScoreInfo[t].m_RoundRectQuadContainerIndex = Graphics()->CreateRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split, ScoreSingleBoxHeight, 5.0f, IGraphics::CORNER_L); } Graphics()->TextureClear(); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -386,7 +386,7 @@ void CHud::RenderScoreHud() Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f); else Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.25f); - m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split - PosSize, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split + PosSize, ScoreSingleBoxHeight, 5.0f, IGraphics::CORNER_L); + m_aScoreInfo[t].m_RoundRectQuadContainerIndex = Graphics()->CreateRectQuadContainer(m_Width - ScoreWidthMax - ImageSize - 2 * Split - PosSize, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split + PosSize, ScoreSingleBoxHeight, 5.0f, IGraphics::CORNER_L); } Graphics()->TextureClear(); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -578,7 +578,7 @@ void CHud::RenderVoting() if((!g_Config.m_ClShowVotesAfterVoting && !m_pClient->m_Scoreboard.Active() && m_pClient->m_Voting.TakenChoice()) || !m_pClient->m_Voting.IsVoting() || Client()->State() == IClient::STATE_DEMOPLAYBACK) return; - RenderTools()->DrawRect(-10, 60 - 2, 100 + 10 + 4 + 5, 46, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_ALL, 5.0f); + Graphics()->DrawRect(-10, 60 - 2, 100 + 10 + 4 + 5, 46, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_ALL, 5.0f); TextRender()->TextColor(1, 1, 1, 1); @@ -1288,7 +1288,7 @@ void CHud::RenderDummyActions() StartY -= 56; } - RenderTools()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_L, 5.0f); + Graphics()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_L, 5.0f); float y = StartY + 2; float x = StartX + 2; @@ -1358,7 +1358,7 @@ void CHud::RenderMovementInformation(const int ClientID) StartY -= 56; } - RenderTools()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_L, 5.0f); + Graphics()->DrawRect(StartX, StartY, BoxWidth, BoxHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_L, 5.0f); CNetObj_Character *pCharacter = &m_pClient->m_Snap.m_aCharacters[ClientID].m_Cur; const float TicksPerSecond = 50.0f; @@ -1480,7 +1480,7 @@ void CHud::RenderMovementInformation(const int ClientID) void CHud::RenderSpectatorHud() { // draw the box - RenderTools()->DrawRect(m_Width - 180.0f, m_Height - 15.0f, 180.0f, 15.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_TL, 5.0f); + Graphics()->DrawRect(m_Width - 180.0f, m_Height - 15.0f, 180.0f, 15.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_TL, 5.0f); // draw the text char aBuf[128]; @@ -1494,7 +1494,7 @@ void CHud::RenderLocalTime(float x) return; // draw the box - RenderTools()->DrawRect(x - 30.0f, 0.0f, 25.0f, 12.5f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_B, 3.75f); + Graphics()->DrawRect(x - 30.0f, 0.0f, 25.0f, 12.5f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_B, 3.75f); // draw the text char aTimeStr[6]; diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 6c0b4ae187f..d4867a34f68 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -940,7 +940,7 @@ void CMenus::RenderLoading(const char *pCaption, const char *pContent, int Incre UI()->DoLabel(&Part, pContent, 20.0f, TEXTALIGN_CENTER); if(RenderLoadingBar) - RenderTools()->DrawRect(Box.x + 40, Box.y + Box.h - 75, (Box.w - 80) * Percent, 25, ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f), IGraphics::CORNER_ALL, 5.0f); + Graphics()->DrawRect(Box.x + 40, Box.y + Box.h - 75, (Box.w - 80) * Percent, 25, ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f), IGraphics::CORNER_ALL, 5.0f); Client()->UpdateAndSwap(); } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 59e7ad8c921..02138b125db 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -162,7 +162,7 @@ class CMenus : public CComponent Graphics()->SetColor(Color); CUIElement::SUIElementRect &NewRect = *UIElement.Get(i); - NewRect.m_UIRectQuadContainer = RenderTools()->CreateRoundRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, r, Corners); + NewRect.m_UIRectQuadContainer = Graphics()->CreateRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, r, Corners); NewRect.m_X = pRect->x; NewRect.m_Y = pRect->y; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index eca7d7d6132..caba8bb737a 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -2139,7 +2139,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool { const float SizeBorder = 5.0f; Graphics()->SetColor(ColorRGBA(0.15f, 0.15f, 0.15f, 1)); - int TmpCont = RenderTools()->CreateRoundRectQuadContainer(Preview.x - SizeBorder / 2.0f, Preview.y - SizeBorder / 2.0f, Preview.w + SizeBorder, Preview.h + SizeBorder, 4.0f + SizeBorder / 2.0f, IGraphics::CORNER_ALL); + int TmpCont = Graphics()->CreateRectQuadContainer(Preview.x - SizeBorder / 2.0f, Preview.y - SizeBorder / 2.0f, Preview.w + SizeBorder, Preview.h + SizeBorder, 4.0f + SizeBorder / 2.0f, IGraphics::CORNER_ALL); Graphics()->RenderQuadContainer(TmpCont, -1); Graphics()->DeleteQuadContainer(TmpCont); } @@ -2147,7 +2147,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool if(ClampedLight) RenderColorHSLA = RenderColorHSLA.UnclampLighting(); Graphics()->SetColor(color_cast(RenderColorHSLA)); - int TmpCont = RenderTools()->CreateRoundRectQuadContainer(Preview.x, Preview.y, Preview.w, Preview.h, 4.0f, IGraphics::CORNER_ALL); + int TmpCont = Graphics()->CreateRectQuadContainer(Preview.x, Preview.y, Preview.w, Preview.h, 4.0f, IGraphics::CORNER_ALL); Graphics()->RenderQuadContainer(TmpCont, -1); Graphics()->DeleteQuadContainer(TmpCont); @@ -2696,32 +2696,32 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) { str_format(aLineBuilder, sizeof(aLineBuilder), "*** '%s' entered and joined the game", aBuf); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); + Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; } str_format(aLineBuilder, sizeof(aLineBuilder), "%sRandom Tee: Hey, how are you %s?", g_Config.m_ClShowIDs ? " 7: " : "", aBuf); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); + Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; str_format(aLineBuilder, sizeof(aLineBuilder), "%sYour Teammate: Let's speedrun this!", g_Config.m_ClShowIDs ? "11: " : ""); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); + Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; str_format(aLineBuilder, sizeof(aLineBuilder), "%s%sFriend: Hello there", g_Config.m_ClMessageFriend ? "♥ " : "", g_Config.m_ClShowIDs ? " 8: " : ""); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); + Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; str_format(aLineBuilder, sizeof(aLineBuilder), "%sSpammer [6]: Hey fools, I'm spamming here!", g_Config.m_ClShowIDs ? " 9: " : ""); Width = TextRender()->TextWidth(0, RealFontSize, aLineBuilder, -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); + Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; Width = TextRender()->TextWidth(0, RealFontSize, "*** Echo command executed", -1, -1); - RenderTools()->DrawRoundRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); + Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); Graphics()->QuadsEnd(); diff --git a/src/game/client/components/motd.cpp b/src/game/client/components/motd.cpp index 6fecd704a43..d38e38439b5 100644 --- a/src/game/client/components/motd.cpp +++ b/src/game/client/components/motd.cpp @@ -41,7 +41,7 @@ void CMotd::OnRender() float x = Width / 2 - w / 2; float y = 150.0f; - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 40.0f); + Graphics()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 40.0f); TextRender()->Text(0, x + 40.0f, y + 40.0f, 32.0f, m_aServerMotd, w - 80.0f); } diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index d166cb68038..886e128ae3f 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -57,7 +57,7 @@ void CScoreboard::RenderGoals(float x, float y, float w) { float h = 50.0f; - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 10.0f); + Graphics()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 10.0f); // render goals if(m_pClient->m_Snap.m_pGameInfoObj) @@ -87,7 +87,7 @@ void CScoreboard::RenderGoals(float x, float y, float w) void CScoreboard::RenderSpectators(float x, float y, float w, float h) { // background - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 10.0f); + Graphics()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 10.0f); // Headline y += 10.0f; @@ -173,7 +173,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch Corners = IGraphics::CORNER_L; else Corners = IGraphics::CORNER_ALL; - RenderTools()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners, 17.0f); + Graphics()->DrawRect(x, y, w, h, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners, 17.0f); } char aBuf[128] = {0}; @@ -361,7 +361,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch Corners |= IGraphics::CORNER_TL | IGraphics::CORNER_TR; if(NextDDTeam != DDTeam) Corners |= IGraphics::CORNER_BL | IGraphics::CORNER_BR; - RenderTools()->DrawRect(x - 10.0f, y, w, LineHeight + Spacing, Color, Corners, RoundRadius); + Graphics()->DrawRect(x - 10.0f, y, w, LineHeight + Spacing, Color, Corners, RoundRadius); if(NextDDTeam != DDTeam) { @@ -393,7 +393,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch // background so it's easy to find the local player or the followed one in spectator mode if((!m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_Local) || (m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW && pInfo->m_Local) || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)) { - RenderTools()->DrawRect(x, y, w - 20.0f, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, RoundRadius); + Graphics()->DrawRect(x, y, w - 20.0f, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, RoundRadius); } // score @@ -565,10 +565,10 @@ void CScoreboard::RenderRecordingNotification(float x) float w = TextRender()->TextWidth(0, 20.0f, aBuf, -1, -1.0f); // draw the box - RenderTools()->DrawRect(x, 0.0f, w + 60.0f, 50.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_B, 15.0f); + Graphics()->DrawRect(x, 0.0f, w + 60.0f, 50.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_B, 15.0f); // draw the red dot - RenderTools()->DrawRect(x + 20, 15.0f, 20.0f, 20.0f, ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f), IGraphics::CORNER_ALL, 10.0f); + Graphics()->DrawRect(x + 20, 15.0f, 20.0f, 20.0f, ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f), IGraphics::CORNER_ALL, 10.0f); TextRender()->Text(0, x + 50.0f, (50.f - 20.f) / 2.f, 20.0f, aBuf, -1.0f); } diff --git a/src/game/client/components/spectator.cpp b/src/game/client/components/spectator.cpp index d3c398c6080..0741a9c1e52 100644 --- a/src/game/client/components/spectator.cpp +++ b/src/game/client/components/spectator.cpp @@ -243,7 +243,7 @@ void CSpectator::OnRender() Graphics()->MapScreen(0, 0, Width, Height); - RenderTools()->DrawRect(Width / 2.0f - ObjWidth, Height / 2.0f - 300.0f, ObjWidth * 2, 600.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f), IGraphics::CORNER_ALL, 20.0f); + Graphics()->DrawRect(Width / 2.0f - ObjWidth, Height / 2.0f - 300.0f, ObjWidth * 2, 600.0f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f), IGraphics::CORNER_ALL, 20.0f); // clamp mouse position to selector area m_SelectorMouse.x = clamp(m_SelectorMouse.x, -(ObjWidth - 20.0f), ObjWidth - 20.0f); @@ -253,12 +253,12 @@ void CSpectator::OnRender() if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FREEVIEW) || m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW) { - RenderTools()->DrawRect(Width / 2.0f - (ObjWidth - 20.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 20.0f); + Graphics()->DrawRect(Width / 2.0f - (ObjWidth - 20.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 20.0f); } if(Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FOLLOW) { - RenderTools()->DrawRect(Width / 2.0f - (ObjWidth - 310.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 20.0f); + Graphics()->DrawRect(Width / 2.0f - (ObjWidth - 310.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 20.0f); } if(m_SelectorMouse.x >= -(ObjWidth - 20.0f) && m_SelectorMouse.x <= -(ObjWidth - 290 + 10.0f) && @@ -337,14 +337,14 @@ void CSpectator::OnRender() Corners |= IGraphics::CORNER_TL | IGraphics::CORNER_TR; if(NextDDTeam != DDTeam) Corners |= IGraphics::CORNER_BL | IGraphics::CORNER_BR; - RenderTools()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, Color, Corners, RoundRadius); + Graphics()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, Color, Corners, RoundRadius); } OldDDTeam = DDTeam; if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == m_pClient->m_Snap.m_apInfoByDDTeamName[i]->m_ClientID) || (Client()->State() != IClient::STATE_DEMOPLAYBACK && m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == m_pClient->m_Snap.m_apInfoByDDTeamName[i]->m_ClientID)) { - RenderTools()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, RoundRadius); + Graphics()->DrawRect(Width / 2.0f + x - 10.0f + BoxOffset, Height / 2.0f + y + BoxMove, 270.0f - BoxOffset, LineHeight, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, RoundRadius); } Selected = false; diff --git a/src/game/client/components/statboard.cpp b/src/game/client/components/statboard.cpp index 93fcc7e3e10..f802b904912 100644 --- a/src/game/client/components/statboard.cpp +++ b/src/game/client/components/statboard.cpp @@ -189,7 +189,7 @@ void CStatboard::RenderGlobalStats() Graphics()->MapScreen(0, 0, StatboardWidth, StatboardHeight); - RenderTools()->DrawRect(x - 10.f, y - 10.f, StatboardContentWidth, StatboardContentHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 17.0f); + Graphics()->DrawRect(x - 10.f, y - 10.f, StatboardContentWidth, StatboardContentHeight, ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), IGraphics::CORNER_ALL, 17.0f); float tw; int px = 325; @@ -267,7 +267,7 @@ void CStatboard::RenderGlobalStats() if(m_pClient->m_Snap.m_LocalClientID == pInfo->m_ClientID || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)) { // background so it's easy to find the local player - RenderTools()->DrawRect(x - 10, y + ContentLineOffset / 2, StatboardContentWidth, LineHeight - ContentLineOffset, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_NONE, 0.0f); + Graphics()->DrawRect(x - 10, y + ContentLineOffset / 2, StatboardContentWidth, LineHeight - ContentLineOffset, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_NONE, 0.0f); } CTeeRenderInfo Teeinfo = m_pClient->m_aClients[pInfo->m_ClientID].m_RenderInfo; diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp index e1223f008e5..5d1f951b35d 100644 --- a/src/game/client/render.cpp +++ b/src/game/client/render.cpp @@ -167,315 +167,6 @@ int CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float X, float return Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1); } -void CRenderTools::DrawRoundRectExt(float x, float y, float w, float h, float r, int Corners) -{ - int NumItems = 0; - const int Num = 8; - - IGraphics::CFreeformItem ArrayF[Num * 4]; - - for(int i = 0; i < Num; i += 2) - { - float a1 = i / (float)Num * pi / 2; - float a2 = (i + 1) / (float)Num * pi / 2; - float a3 = (i + 2) / (float)Num * pi / 2; - float Ca1 = cosf(a1); - float Ca2 = cosf(a2); - float Ca3 = cosf(a3); - float Sa1 = sinf(a1); - float Sa2 = sinf(a2); - float Sa3 = sinf(a3); - - if(Corners & 1) // TL - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + r, y + r, - x + (1 - Ca1) * r, y + (1 - Sa1) * r, - x + (1 - Ca3) * r, y + (1 - Sa3) * r, - x + (1 - Ca2) * r, y + (1 - Sa2) * r); - - if(Corners & 2) // TR - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + w - r, y + r, - x + w - r + Ca1 * r, y + (1 - Sa1) * r, - x + w - r + Ca3 * r, y + (1 - Sa3) * r, - x + w - r + Ca2 * r, y + (1 - Sa2) * r); - - if(Corners & 4) // BL - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + r, y + h - r, - x + (1 - Ca1) * r, y + h - r + Sa1 * r, - x + (1 - Ca3) * r, y + h - r + Sa3 * r, - x + (1 - Ca2) * r, y + h - r + Sa2 * r); - - if(Corners & 8) // BR - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + w - r, y + h - r, - x + w - r + Ca1 * r, y + h - r + Sa1 * r, - x + w - r + Ca3 * r, y + h - r + Sa3 * r, - x + w - r + Ca2 * r, y + h - r + Sa2 * r); - } - Graphics()->QuadsDrawFreeform(ArrayF, NumItems); - - IGraphics::CQuadItem ArrayQ[9]; - NumItems = 0; - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + r, y, w - r * 2, r); // top - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom - ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y + r, r, h - r * 2); // left - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + w - r, y + r, r, h - r * 2); // right - - if(!(Corners & 1)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y, r, r); // TL - if(!(Corners & 2)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + w, y, -r, r); // TR - if(!(Corners & 4)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y + h, r, -r); // BL - if(!(Corners & 8)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + w, y + h, -r, -r); // BR - - Graphics()->QuadsDrawTL(ArrayQ, NumItems); -} - -void CRenderTools::DrawRoundRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) -{ - if(Corners == 0 || r == 0.0f) - { - Graphics()->SetColor4(ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight); - IGraphics::CQuadItem ItemQ = IGraphics::CQuadItem(x, y, w, h); - Graphics()->QuadsDrawTL(&ItemQ, 1); - return; - } - - int Num = 8; - for(int i = 0; i < Num; i += 2) - { - float a1 = i / (float)Num * pi / 2; - float a2 = (i + 1) / (float)Num * pi / 2; - float a3 = (i + 2) / (float)Num * pi / 2; - float Ca1 = cosf(a1); - float Ca2 = cosf(a2); - float Ca3 = cosf(a3); - float Sa1 = sinf(a1); - float Sa2 = sinf(a2); - float Sa3 = sinf(a3); - - if(Corners & 1) // TL - { - Graphics()->SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x + r, y + r, - x + (1 - Ca1) * r, y + (1 - Sa1) * r, - x + (1 - Ca3) * r, y + (1 - Sa3) * r, - x + (1 - Ca2) * r, y + (1 - Sa2) * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 2) // TR - { - Graphics()->SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x + w - r, y + r, - x + w - r + Ca1 * r, y + (1 - Sa1) * r, - x + w - r + Ca3 * r, y + (1 - Sa3) * r, - x + w - r + Ca2 * r, y + (1 - Sa2) * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 4) // BL - { - Graphics()->SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x + r, y + h - r, - x + (1 - Ca1) * r, y + h - r + Sa1 * r, - x + (1 - Ca3) * r, y + h - r + Sa3 * r, - x + (1 - Ca2) * r, y + h - r + Sa2 * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 8) // BR - { - Graphics()->SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x + w - r, y + h - r, - x + w - r + Ca1 * r, y + h - r + Sa1 * r, - x + w - r + Ca3 * r, y + h - r + Sa3 * r, - x + w - r + Ca2 * r, y + h - r + Sa2 * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 16) // ITL - { - Graphics()->SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x, y, - x + (1 - Ca1) * r, y - r + Sa1 * r, - x + (1 - Ca3) * r, y - r + Sa3 * r, - x + (1 - Ca2) * r, y - r + Sa2 * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 32) // ITR - { - Graphics()->SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x + w, y, - x + w - r + Ca1 * r, y - r + Sa1 * r, - x + w - r + Ca3 * r, y - r + Sa3 * r, - x + w - r + Ca2 * r, y - r + Sa2 * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 64) // IBL - { - Graphics()->SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x, y + h, - x + (1 - Ca1) * r, y + h + (1 - Sa1) * r, - x + (1 - Ca3) * r, y + h + (1 - Sa3) * r, - x + (1 - Ca2) * r, y + h + (1 - Sa2) * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - - if(Corners & 128) // IBR - { - Graphics()->SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); - IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( - x + w, y + h, - x + w - r + Ca1 * r, y + h + (1 - Sa1) * r, - x + w - r + Ca3 * r, y + h + (1 - Sa3) * r, - x + w - r + Ca2 * r, y + h + (1 - Sa2) * r); - Graphics()->QuadsDrawFreeform(&ItemF, 1); - } - } - - Graphics()->SetColor4(ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight); - IGraphics::CQuadItem ItemQ = IGraphics::CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center - Graphics()->QuadsDrawTL(&ItemQ, 1); - Graphics()->SetColor4(ColorTopLeft, ColorTopRight, ColorTopLeft, ColorTopRight); - ItemQ = IGraphics::CQuadItem(x + r, y, w - r * 2, r); // top - Graphics()->QuadsDrawTL(&ItemQ, 1); - Graphics()->SetColor4(ColorBottomLeft, ColorBottomRight, ColorBottomLeft, ColorBottomRight); - ItemQ = IGraphics::CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom - Graphics()->QuadsDrawTL(&ItemQ, 1); - Graphics()->SetColor4(ColorTopLeft, ColorTopLeft, ColorBottomLeft, ColorBottomLeft); - ItemQ = IGraphics::CQuadItem(x, y + r, r, h - r * 2); // left - Graphics()->QuadsDrawTL(&ItemQ, 1); - Graphics()->SetColor4(ColorTopRight, ColorTopRight, ColorBottomRight, ColorBottomRight); - ItemQ = IGraphics::CQuadItem(x + w - r, y + r, r, h - r * 2); // right - Graphics()->QuadsDrawTL(&ItemQ, 1); - - if(!(Corners & 1)) - { - Graphics()->SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); - ItemQ = IGraphics::CQuadItem(x, y, r, r); // TL - Graphics()->QuadsDrawTL(&ItemQ, 1); - } - if(!(Corners & 2)) - { - Graphics()->SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); - ItemQ = IGraphics::CQuadItem(x + w, y, -r, r); // TR - Graphics()->QuadsDrawTL(&ItemQ, 1); - } - if(!(Corners & 4)) - { - Graphics()->SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); - ItemQ = IGraphics::CQuadItem(x, y + h, r, -r); // BL - Graphics()->QuadsDrawTL(&ItemQ, 1); - } - if(!(Corners & 8)) - { - Graphics()->SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); - ItemQ = IGraphics::CQuadItem(x + w, y + h, -r, -r); // BR - Graphics()->QuadsDrawTL(&ItemQ, 1); - } -} - -int CRenderTools::CreateRoundRectQuadContainer(float x, float y, float w, float h, float r, int Corners) -{ - int ContainerIndex = Graphics()->CreateQuadContainer(false); - - if(Corners == 0 || r == 0.0f) - { - IGraphics::CQuadItem ItemQ = IGraphics::CQuadItem(x, y, w, h); - Graphics()->QuadContainerAddQuads(ContainerIndex, &ItemQ, 1); - Graphics()->QuadContainerUpload(ContainerIndex); - Graphics()->QuadContainerChangeAutomaticUpload(ContainerIndex, true); - return ContainerIndex; - } - - IGraphics::CFreeformItem ArrayF[32]; - int NumItems = 0; - int Num = 8; - for(int i = 0; i < Num; i += 2) - { - float a1 = i / (float)Num * pi / 2; - float a2 = (i + 1) / (float)Num * pi / 2; - float a3 = (i + 2) / (float)Num * pi / 2; - float Ca1 = cosf(a1); - float Ca2 = cosf(a2); - float Ca3 = cosf(a3); - float Sa1 = sinf(a1); - float Sa2 = sinf(a2); - float Sa3 = sinf(a3); - - if(Corners & 1) // TL - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + r, y + r, - x + (1 - Ca1) * r, y + (1 - Sa1) * r, - x + (1 - Ca3) * r, y + (1 - Sa3) * r, - x + (1 - Ca2) * r, y + (1 - Sa2) * r); - - if(Corners & 2) // TR - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + w - r, y + r, - x + w - r + Ca1 * r, y + (1 - Sa1) * r, - x + w - r + Ca3 * r, y + (1 - Sa3) * r, - x + w - r + Ca2 * r, y + (1 - Sa2) * r); - - if(Corners & 4) // BL - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + r, y + h - r, - x + (1 - Ca1) * r, y + h - r + Sa1 * r, - x + (1 - Ca3) * r, y + h - r + Sa3 * r, - x + (1 - Ca2) * r, y + h - r + Sa2 * r); - - if(Corners & 8) // BR - ArrayF[NumItems++] = IGraphics::CFreeformItem( - x + w - r, y + h - r, - x + w - r + Ca1 * r, y + h - r + Sa1 * r, - x + w - r + Ca3 * r, y + h - r + Sa3 * r, - x + w - r + Ca2 * r, y + h - r + Sa2 * r); - } - - if(NumItems > 0) - Graphics()->QuadContainerAddQuads(ContainerIndex, ArrayF, NumItems); - - IGraphics::CQuadItem ArrayQ[9]; - NumItems = 0; - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + r, y, w - r * 2, r); // top - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom - ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y + r, r, h - r * 2); // left - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + w - r, y + r, r, h - r * 2); // right - - if(!(Corners & 1)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y, r, r); // TL - if(!(Corners & 2)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + w, y, -r, r); // TR - if(!(Corners & 4)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y + h, r, -r); // BL - if(!(Corners & 8)) - ArrayQ[NumItems++] = IGraphics::CQuadItem(x + w, y + h, -r, -r); // BR - - if(NumItems > 0) - Graphics()->QuadContainerAddQuads(ContainerIndex, ArrayQ, NumItems); - - Graphics()->QuadContainerUpload(ContainerIndex); - Graphics()->QuadContainerChangeAutomaticUpload(ContainerIndex, true); - - return ContainerIndex; -} - void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding) { bool NeedsRecreate = false; @@ -494,7 +185,7 @@ void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIR ElUIRect.m_QuadColor = Color; Graphics()->SetColor(Color); - ElUIRect.m_UIRectQuadContainer = CreateRoundRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, Rounding, Corners); + ElUIRect.m_UIRectQuadContainer = Graphics()->CreateRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, Rounding, Corners); Graphics()->SetColor(1, 1, 1, 1); } @@ -502,31 +193,14 @@ void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIR Graphics()->RenderQuadContainer(ElUIRect.m_UIRectQuadContainer, -1); } -void CRenderTools::DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) -{ - Graphics()->TextureClear(); - Graphics()->QuadsBegin(); - Graphics()->SetColor(Color); - DrawRoundRectExt(x, y, w, h, Rounding, Corners); - Graphics()->QuadsEnd(); -} - void CRenderTools::DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding) { - DrawRect(pRect->x, pRect->y, pRect->w, pRect->h, Color, Corners, Rounding); -} - -void CRenderTools::DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) -{ - Graphics()->TextureClear(); - Graphics()->QuadsBegin(); - DrawRoundRectExt4(x, y, w, h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Rounding, Corners); - Graphics()->QuadsEnd(); + Graphics()->DrawRect(pRect->x, pRect->y, pRect->w, pRect->h, Color, Corners, Rounding); } void CRenderTools::DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) { - DrawRect4(pRect->x, pRect->y, pRect->w, pRect->h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding); + Graphics()->DrawRect4(pRect->x, pRect->y, pRect->w, pRect->h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding); } void CRenderTools::GetRenderTeeAnimScaleAndBaseSize(CAnimState *pAnim, CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize) diff --git a/src/game/client/render.h b/src/game/client/render.h index 704cf0d082b..e68beb89066 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -105,16 +105,8 @@ class CRenderTools int QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height); // rects - void DrawRoundRectExt(float x, float y, float w, float h, float r, int Corners); - void DrawRoundRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners); - - int CreateRoundRectQuadContainer(float x, float y, float w, float h, float r, int Corners); - void DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding); - - void DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding); void DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding); - void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding); void DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding); // larger rendering methods diff --git a/src/game/editor/layer_sounds.cpp b/src/game/editor/layer_sounds.cpp index 5d65316ea76..279be18b1e1 100644 --- a/src/game/editor/layer_sounds.cpp +++ b/src/game/editor/layer_sounds.cpp @@ -53,12 +53,12 @@ void CLayerSounds::Render(bool Tileset) { float Width = fx2f(Source.m_Shape.m_Rectangle.m_Width); float Height = fx2f(Source.m_Shape.m_Rectangle.m_Height); - m_pEditor->RenderTools()->DrawRoundRectExt(fx2f(Source.m_Position.x) + OffsetX - Width / 2, fx2f(Source.m_Position.y) + OffsetY - Height / 2, + m_pEditor->Graphics()->DrawRectExt(fx2f(Source.m_Position.x) + OffsetX - Width / 2, fx2f(Source.m_Position.y) + OffsetY - Height / 2, Width, Height, 0.0f, IGraphics::CORNER_NONE); float Falloff = ((float)Source.m_Falloff / 255.0f); if(Falloff > 0.0f) - m_pEditor->RenderTools()->DrawRoundRectExt(fx2f(Source.m_Position.x) + OffsetX - Falloff * Width / 2, fx2f(Source.m_Position.y) + OffsetY - Falloff * Height / 2, + m_pEditor->Graphics()->DrawRectExt(fx2f(Source.m_Position.x) + OffsetX - Falloff * Width / 2, fx2f(Source.m_Position.y) + OffsetY - Falloff * Height / 2, Width * Falloff, Height * Falloff, 0.0f, IGraphics::CORNER_NONE); break; } From 3b1ef5642b06a31245ee0766f197b20f09fd0824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Jul 2022 22:49:09 +0200 Subject: [PATCH 44/72] Refactor `DrawRect*` methods: - use `CORNER_*` constants and add missing constants - fix array variable names - use `size_t` - extract duplicate computation into constant - use `ColorRGBA` instead of `vec4` --- src/engine/client/graphics_threaded.cpp | 214 +++++++++++++----------- src/engine/client/graphics_threaded.h | 8 +- src/engine/graphics.h | 20 ++- 3 files changed, 131 insertions(+), 111 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index adde5a6777c..fd52ba48610 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -975,12 +975,12 @@ void CGraphics_Threaded::SetColor(float r, float g, float b, float a) } } -void CGraphics_Threaded::SetColor(ColorRGBA rgb) +void CGraphics_Threaded::SetColor(ColorRGBA Color) { - SetColor(rgb.r, rgb.g, rgb.b, rgb.a); + SetColor(Color.r, Color.g, Color.b, Color.a); } -void CGraphics_Threaded::SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight) +void CGraphics_Threaded::SetColor4(ColorRGBA TopLeft, ColorRGBA TopRight, ColorRGBA BottomLeft, ColorRGBA BottomRight) { dbg_assert(m_Drawing != 0, "called Graphics()->SetColor without begin"); CColorVertex Array[4] = { @@ -1239,16 +1239,16 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe void CGraphics_Threaded::DrawRectExt(float x, float y, float w, float h, float r, int Corners) { - int NumItems = 0; - const int Num = 8; - - IGraphics::CFreeformItem ArrayF[Num * 4]; + const int NumSegments = 8; + const float SegmentsAngle = pi / 2 / NumSegments; + IGraphics::CFreeformItem aFreeform[NumSegments * 4]; + size_t NumItems = 0; - for(int i = 0; i < Num; i += 2) + for(int i = 0; i < NumSegments; i += 2) { - float a1 = i / (float)Num * pi / 2; - float a2 = (i + 1) / (float)Num * pi / 2; - float a3 = (i + 2) / (float)Num * pi / 2; + float a1 = i * SegmentsAngle; + float a2 = (i + 1) * SegmentsAngle; + float a3 = (i + 2) * SegmentsAngle; float Ca1 = cosf(a1); float Ca2 = cosf(a2); float Ca3 = cosf(a3); @@ -1256,57 +1256,57 @@ void CGraphics_Threaded::DrawRectExt(float x, float y, float w, float h, float r float Sa2 = sinf(a2); float Sa3 = sinf(a3); - if(Corners & 1) // TL - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_TL) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + r, y + r, x + (1 - Ca1) * r, y + (1 - Sa1) * r, x + (1 - Ca3) * r, y + (1 - Sa3) * r, x + (1 - Ca2) * r, y + (1 - Sa2) * r); - if(Corners & 2) // TR - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_TR) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + w - r, y + r, x + w - r + Ca1 * r, y + (1 - Sa1) * r, x + w - r + Ca3 * r, y + (1 - Sa3) * r, x + w - r + Ca2 * r, y + (1 - Sa2) * r); - if(Corners & 4) // BL - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_BL) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + r, y + h - r, x + (1 - Ca1) * r, y + h - r + Sa1 * r, x + (1 - Ca3) * r, y + h - r + Sa3 * r, x + (1 - Ca2) * r, y + h - r + Sa2 * r); - if(Corners & 8) // BR - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_BR) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + w - r, y + h - r, x + w - r + Ca1 * r, y + h - r + Sa1 * r, x + w - r + Ca3 * r, y + h - r + Sa3 * r, x + w - r + Ca2 * r, y + h - r + Sa2 * r); } - QuadsDrawFreeform(ArrayF, NumItems); + QuadsDrawFreeform(aFreeform, NumItems); - CQuadItem ArrayQ[9]; + CQuadItem aQuads[9]; NumItems = 0; - ArrayQ[NumItems++] = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center - ArrayQ[NumItems++] = CQuadItem(x + r, y, w - r * 2, r); // top - ArrayQ[NumItems++] = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom - ArrayQ[NumItems++] = CQuadItem(x, y + r, r, h - r * 2); // left - ArrayQ[NumItems++] = CQuadItem(x + w - r, y + r, r, h - r * 2); // right + aQuads[NumItems++] = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center + aQuads[NumItems++] = CQuadItem(x + r, y, w - r * 2, r); // top + aQuads[NumItems++] = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom + aQuads[NumItems++] = CQuadItem(x, y + r, r, h - r * 2); // left + aQuads[NumItems++] = CQuadItem(x + w - r, y + r, r, h - r * 2); // right - if(!(Corners & 1)) - ArrayQ[NumItems++] = CQuadItem(x, y, r, r); // TL - if(!(Corners & 2)) - ArrayQ[NumItems++] = CQuadItem(x + w, y, -r, r); // TR - if(!(Corners & 4)) - ArrayQ[NumItems++] = CQuadItem(x, y + h, r, -r); // BL - if(!(Corners & 8)) - ArrayQ[NumItems++] = CQuadItem(x + w, y + h, -r, -r); // BR + if(!(Corners & CORNER_TL)) + aQuads[NumItems++] = CQuadItem(x, y, r, r); + if(!(Corners & CORNER_TR)) + aQuads[NumItems++] = CQuadItem(x + w, y, -r, r); + if(!(Corners & CORNER_BL)) + aQuads[NumItems++] = CQuadItem(x, y + h, r, -r); + if(!(Corners & CORNER_BR)) + aQuads[NumItems++] = CQuadItem(x + w, y + h, -r, -r); - QuadsDrawTL(ArrayQ, NumItems); + QuadsDrawTL(aQuads, NumItems); } -void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) +void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, float r, int Corners) { if(Corners == 0 || r == 0.0f) { @@ -1316,12 +1316,13 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C return; } - int Num = 8; - for(int i = 0; i < Num; i += 2) + const int NumSegments = 8; + const float SegmentsAngle = pi / 2 / NumSegments; + for(int i = 0; i < NumSegments; i += 2) { - float a1 = i / (float)Num * pi / 2; - float a2 = (i + 1) / (float)Num * pi / 2; - float a3 = (i + 2) / (float)Num * pi / 2; + float a1 = i * SegmentsAngle; + float a2 = (i + 1) * SegmentsAngle; + float a3 = (i + 2) * SegmentsAngle; float Ca1 = cosf(a1); float Ca2 = cosf(a2); float Ca3 = cosf(a3); @@ -1329,9 +1330,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C float Sa2 = sinf(a2); float Sa3 = sinf(a3); - if(Corners & 1) // TL + if(Corners & CORNER_TL) { - SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); + SetColor(ColorTopLeft); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x + r, y + r, x + (1 - Ca1) * r, y + (1 - Sa1) * r, @@ -1340,9 +1341,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 2) // TR + if(Corners & CORNER_TR) { - SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); + SetColor(ColorTopRight); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x + w - r, y + r, x + w - r + Ca1 * r, y + (1 - Sa1) * r, @@ -1351,9 +1352,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 4) // BL + if(Corners & CORNER_BL) { - SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); + SetColor(ColorBottomLeft); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x + r, y + h - r, x + (1 - Ca1) * r, y + h - r + Sa1 * r, @@ -1362,9 +1363,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 8) // BR + if(Corners & CORNER_BR) { - SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); + SetColor(ColorBottomRight); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x + w - r, y + h - r, x + w - r + Ca1 * r, y + h - r + Sa1 * r, @@ -1373,9 +1374,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 16) // ITL + if(Corners & CORNER_ITL) { - SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); + SetColor(ColorTopLeft); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x, y, x + (1 - Ca1) * r, y - r + Sa1 * r, @@ -1384,9 +1385,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 32) // ITR + if(Corners & CORNER_ITR) { - SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); + SetColor(ColorTopRight); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x + w, y, x + w - r + Ca1 * r, y - r + Sa1 * r, @@ -1395,9 +1396,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 64) // IBL + if(Corners & CORNER_IBL) { - SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); + SetColor(ColorBottomLeft); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x, y + h, x + (1 - Ca1) * r, y + h + (1 - Sa1) * r, @@ -1406,9 +1407,9 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C QuadsDrawFreeform(&ItemF, 1); } - if(Corners & 128) // IBR + if(Corners & CORNER_IBR) { - SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); + SetColor(ColorBottomRight); IGraphics::CFreeformItem ItemF = IGraphics::CFreeformItem( x + w, y + h, x + w - r + Ca1 * r, y + h + (1 - Sa1) * r, @@ -1421,41 +1422,48 @@ void CGraphics_Threaded::DrawRectExt4(float x, float y, float w, float h, vec4 C SetColor4(ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight); CQuadItem ItemQ = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorTopLeft, ColorTopRight, ColorTopLeft, ColorTopRight); ItemQ = CQuadItem(x + r, y, w - r * 2, r); // top QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorBottomLeft, ColorBottomRight, ColorBottomLeft, ColorBottomRight); ItemQ = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorTopLeft, ColorTopLeft, ColorBottomLeft, ColorBottomLeft); ItemQ = CQuadItem(x, y + r, r, h - r * 2); // left QuadsDrawTL(&ItemQ, 1); + SetColor4(ColorTopRight, ColorTopRight, ColorBottomRight, ColorBottomRight); ItemQ = CQuadItem(x + w - r, y + r, r, h - r * 2); // right QuadsDrawTL(&ItemQ, 1); - if(!(Corners & 1)) + if(!(Corners & CORNER_TL)) { - SetColor(ColorTopLeft.r, ColorTopLeft.g, ColorTopLeft.b, ColorTopLeft.a); - ItemQ = CQuadItem(x, y, r, r); // TL + SetColor(ColorTopLeft); + ItemQ = CQuadItem(x, y, r, r); QuadsDrawTL(&ItemQ, 1); } - if(!(Corners & 2)) + + if(!(Corners & CORNER_TR)) { - SetColor(ColorTopRight.r, ColorTopRight.g, ColorTopRight.b, ColorTopRight.a); - ItemQ = CQuadItem(x + w, y, -r, r); // TR + SetColor(ColorTopRight); + ItemQ = CQuadItem(x + w, y, -r, r); QuadsDrawTL(&ItemQ, 1); } - if(!(Corners & 4)) + + if(!(Corners & CORNER_BL)) { - SetColor(ColorBottomLeft.r, ColorBottomLeft.g, ColorBottomLeft.b, ColorBottomLeft.a); - ItemQ = CQuadItem(x, y + h, r, -r); // BL + SetColor(ColorBottomLeft); + ItemQ = CQuadItem(x, y + h, r, -r); QuadsDrawTL(&ItemQ, 1); } - if(!(Corners & 8)) + + if(!(Corners & CORNER_BR)) { - SetColor(ColorBottomRight.r, ColorBottomRight.g, ColorBottomRight.b, ColorBottomRight.a); - ItemQ = CQuadItem(x + w, y + h, -r, -r); // BR + SetColor(ColorBottomRight); + ItemQ = CQuadItem(x + w, y + h, -r, -r); QuadsDrawTL(&ItemQ, 1); } } @@ -1473,14 +1481,16 @@ int CGraphics_Threaded::CreateRectQuadContainer(float x, float y, float w, float return ContainerIndex; } - IGraphics::CFreeformItem ArrayF[32]; - int NumItems = 0; - int Num = 8; - for(int i = 0; i < Num; i += 2) + const int NumSegments = 8; + const float SegmentsAngle = pi / 2 / NumSegments; + IGraphics::CFreeformItem aFreeform[NumSegments * 4]; + size_t NumItems = 0; + + for(int i = 0; i < NumSegments; i += 2) { - float a1 = i / (float)Num * pi / 2; - float a2 = (i + 1) / (float)Num * pi / 2; - float a3 = (i + 2) / (float)Num * pi / 2; + float a1 = i * SegmentsAngle; + float a2 = (i + 1) * SegmentsAngle; + float a3 = (i + 2) * SegmentsAngle; float Ca1 = cosf(a1); float Ca2 = cosf(a2); float Ca3 = cosf(a3); @@ -1488,29 +1498,29 @@ int CGraphics_Threaded::CreateRectQuadContainer(float x, float y, float w, float float Sa2 = sinf(a2); float Sa3 = sinf(a3); - if(Corners & 1) // TL - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_TL) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + r, y + r, x + (1 - Ca1) * r, y + (1 - Sa1) * r, x + (1 - Ca3) * r, y + (1 - Sa3) * r, x + (1 - Ca2) * r, y + (1 - Sa2) * r); - if(Corners & 2) // TR - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_TR) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + w - r, y + r, x + w - r + Ca1 * r, y + (1 - Sa1) * r, x + w - r + Ca3 * r, y + (1 - Sa3) * r, x + w - r + Ca2 * r, y + (1 - Sa2) * r); - if(Corners & 4) // BL - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_BL) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + r, y + h - r, x + (1 - Ca1) * r, y + h - r + Sa1 * r, x + (1 - Ca3) * r, y + h - r + Sa3 * r, x + (1 - Ca2) * r, y + h - r + Sa2 * r); - if(Corners & 8) // BR - ArrayF[NumItems++] = IGraphics::CFreeformItem( + if(Corners & CORNER_BR) + aFreeform[NumItems++] = IGraphics::CFreeformItem( x + w - r, y + h - r, x + w - r + Ca1 * r, y + h - r + Sa1 * r, x + w - r + Ca3 * r, y + h - r + Sa3 * r, @@ -1518,27 +1528,27 @@ int CGraphics_Threaded::CreateRectQuadContainer(float x, float y, float w, float } if(NumItems > 0) - QuadContainerAddQuads(ContainerIndex, ArrayF, NumItems); + QuadContainerAddQuads(ContainerIndex, aFreeform, NumItems); - CQuadItem ArrayQ[9]; + CQuadItem aQuads[9]; NumItems = 0; - ArrayQ[NumItems++] = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center - ArrayQ[NumItems++] = CQuadItem(x + r, y, w - r * 2, r); // top - ArrayQ[NumItems++] = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom - ArrayQ[NumItems++] = CQuadItem(x, y + r, r, h - r * 2); // left - ArrayQ[NumItems++] = CQuadItem(x + w - r, y + r, r, h - r * 2); // right - - if(!(Corners & 1)) - ArrayQ[NumItems++] = CQuadItem(x, y, r, r); // TL - if(!(Corners & 2)) - ArrayQ[NumItems++] = CQuadItem(x + w, y, -r, r); // TR - if(!(Corners & 4)) - ArrayQ[NumItems++] = CQuadItem(x, y + h, r, -r); // BL - if(!(Corners & 8)) - ArrayQ[NumItems++] = CQuadItem(x + w, y + h, -r, -r); // BR + aQuads[NumItems++] = CQuadItem(x + r, y + r, w - r * 2, h - r * 2); // center + aQuads[NumItems++] = CQuadItem(x + r, y, w - r * 2, r); // top + aQuads[NumItems++] = CQuadItem(x + r, y + h - r, w - r * 2, r); // bottom + aQuads[NumItems++] = CQuadItem(x, y + r, r, h - r * 2); // left + aQuads[NumItems++] = CQuadItem(x + w - r, y + r, r, h - r * 2); // right + + if(!(Corners & CORNER_TL)) + aQuads[NumItems++] = CQuadItem(x, y, r, r); + if(!(Corners & CORNER_TR)) + aQuads[NumItems++] = CQuadItem(x + w, y, -r, r); + if(!(Corners & CORNER_BL)) + aQuads[NumItems++] = CQuadItem(x, y + h, r, -r); + if(!(Corners & CORNER_BR)) + aQuads[NumItems++] = CQuadItem(x + w, y + h, -r, -r); if(NumItems > 0) - QuadContainerAddQuads(ContainerIndex, ArrayQ, NumItems); + QuadContainerAddQuads(ContainerIndex, aQuads, NumItems); QuadContainerUpload(ContainerIndex); QuadContainerChangeAutomaticUpload(ContainerIndex, true); @@ -1555,7 +1565,7 @@ void CGraphics_Threaded::DrawRect(float x, float y, float w, float h, ColorRGBA QuadsEnd(); } -void CGraphics_Threaded::DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) +void CGraphics_Threaded::DrawRect4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) { TextureClear(); QuadsBegin(); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 5941314037c..b8b1fb8bb9a 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -1015,8 +1015,8 @@ class CGraphics_Threaded : public IEngineGraphics void SetColorVertex(const CColorVertex *pArray, int Num) override; void SetColor(float r, float g, float b, float a) override; - void SetColor(ColorRGBA rgb) override; - void SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight) override; + void SetColor(ColorRGBA Color) override; + void SetColor4(ColorRGBA TopLeft, ColorRGBA TopRight, ColorRGBA BottomLeft, ColorRGBA BottomRight) override; // go through all vertices and change their color (only works for quads) void ChangeColorOfCurrentQuadVertices(float r, float g, float b, float a) override; @@ -1128,10 +1128,10 @@ class CGraphics_Threaded : public IEngineGraphics void QuadsText(float x, float y, float Size, const char *pText) override; void DrawRectExt(float x, float y, float w, float h, float r, int Corners) override; - void DrawRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) override; + void DrawRectExt4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, float r, int Corners) override; int CreateRectQuadContainer(float x, float y, float w, float h, float r, int Corners) override; void DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) override; - void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) override; + void DrawRect4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) override; void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) override; const GL_STexCoord *GetCurTextureCoordinates() override diff --git a/src/engine/graphics.h b/src/engine/graphics.h index c84524f8bfd..9f0e6d68f55 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -449,19 +449,29 @@ class IGraphics : public IInterface CORNER_TR = 2, CORNER_BL = 4, CORNER_BR = 8, + CORNER_ITL = 16, + CORNER_ITR = 32, + CORNER_IBL = 64, + CORNER_IBR = 128, CORNER_T = CORNER_TL | CORNER_TR, CORNER_B = CORNER_BL | CORNER_BR, CORNER_R = CORNER_TR | CORNER_BR, CORNER_L = CORNER_TL | CORNER_BL, - CORNER_ALL = CORNER_T | CORNER_B + CORNER_IT = CORNER_ITL | CORNER_ITR, + CORNER_IB = CORNER_IBL | CORNER_IBR, + CORNER_IR = CORNER_ITR | CORNER_IBR, + CORNER_IL = CORNER_ITL | CORNER_IBL, + + CORNER_ALL = CORNER_T | CORNER_B, + CORNER_INV_ALL = CORNER_IT | CORNER_IB }; virtual void DrawRectExt(float x, float y, float w, float h, float r, int Corners) = 0; - virtual void DrawRectExt4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, float r, int Corners) = 0; + virtual void DrawRectExt4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, float r, int Corners) = 0; virtual int CreateRectQuadContainer(float x, float y, float w, float h, float r, int Corners) = 0; virtual void DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) = 0; - virtual void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) = 0; + virtual void DrawRect4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) = 0; virtual void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) = 0; struct CColorVertex @@ -474,8 +484,8 @@ class IGraphics : public IInterface }; virtual void SetColorVertex(const CColorVertex *pArray, int Num) = 0; virtual void SetColor(float r, float g, float b, float a) = 0; - virtual void SetColor(ColorRGBA rgb) = 0; - virtual void SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight) = 0; + virtual void SetColor(ColorRGBA Color) = 0; + virtual void SetColor4(ColorRGBA TopLeft, ColorRGBA TopRight, ColorRGBA BottomLeft, ColorRGBA BottomRight) = 0; virtual void ChangeColorOfCurrentQuadVertices(float r, float g, float b, float a) = 0; virtual void ChangeColorOfQuadVertices(int QuadOffset, unsigned char r, unsigned char g, unsigned char b, unsigned char a) = 0; From 4005b82743febdb1f80a633c0a457c3f551c62c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Jul 2022 23:35:00 +0200 Subject: [PATCH 45/72] Move `CRenderTools::DrawUIElRect` to `CUIElement::SUIElementRect::Draw` This method draws a particular UI element rectangle so it should be a member method. --- src/game/client/components/menus_browser.cpp | 4 +-- src/game/client/render.cpp | 26 ---------------- src/game/client/render.h | 1 - src/game/client/ui.cpp | 31 +++++++++++++++++++- src/game/client/ui.h | 6 ++++ 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 4bb9343b39c..89ead1f265f 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -286,13 +286,13 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) { CUIRect r = Row; r.Margin(0.5f, &r); - RenderTools()->DrawUIElRect(*pItem->m_pUIElement->Get(0), &r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); + pItem->m_pUIElement->Get(0)->Draw(&r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } else if(UI()->MouseHovered(&Row)) { CUIRect r = Row; r.Margin(0.5f, &r); - RenderTools()->DrawUIElRect(*pItem->m_pUIElement->Get(1), &r, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); + pItem->m_pUIElement->Get(0)->Draw(&r, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); } if(UI()->DoButtonLogic(pItem, Selected, &Row)) diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp index 5d1f951b35d..24759507ae1 100644 --- a/src/game/client/render.cpp +++ b/src/game/client/render.cpp @@ -167,32 +167,6 @@ int CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float X, float return Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1); } -void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding) -{ - bool NeedsRecreate = false; - if(ElUIRect.m_UIRectQuadContainer == -1 || ElUIRect.m_X != pRect->x || ElUIRect.m_Y != pRect->y || ElUIRect.m_Width != pRect->w || ElUIRect.m_Height != pRect->h || mem_comp(&ElUIRect.m_QuadColor, &Color, sizeof(Color)) != 0) - { - if(ElUIRect.m_UIRectQuadContainer != -1) - Graphics()->DeleteQuadContainer(ElUIRect.m_UIRectQuadContainer); - NeedsRecreate = true; - } - if(NeedsRecreate) - { - ElUIRect.m_X = pRect->x; - ElUIRect.m_Y = pRect->y; - ElUIRect.m_Width = pRect->w; - ElUIRect.m_Height = pRect->h; - ElUIRect.m_QuadColor = Color; - - Graphics()->SetColor(Color); - ElUIRect.m_UIRectQuadContainer = Graphics()->CreateRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, Rounding, Corners); - Graphics()->SetColor(1, 1, 1, 1); - } - - Graphics()->TextureClear(); - Graphics()->RenderQuadContainer(ElUIRect.m_UIRectQuadContainer, -1); -} - void CRenderTools::DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding) { Graphics()->DrawRect(pRect->x, pRect->y, pRect->w, pRect->h, Color, Corners, Rounding); diff --git a/src/game/client/render.h b/src/game/client/render.h index e68beb89066..1fef91abc64 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -105,7 +105,6 @@ class CRenderTools int QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height); // rects - void DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding); void DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding); void DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding); diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index ab094e97a27..1866223cf0d 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -12,15 +12,18 @@ void CUIElement::Init(CUI *pUI, int RequestedRectCount) { + m_pUI = pUI; pUI->AddUIElement(this); if(RequestedRectCount > 0) - m_vUIRects.resize(RequestedRectCount); + InitRects(RequestedRectCount); } void CUIElement::InitRects(int RequestedRectCount) { dbg_assert(m_vUIRects.empty(), "UI rects can only be initialized once, create another ui element instead."); m_vUIRects.resize(RequestedRectCount); + for(auto &Rect : m_vUIRects) + Rect.m_pParent = this; } CUIElement::SUIElementRect::SUIElementRect() { Reset(); } @@ -40,6 +43,32 @@ void CUIElement::SUIElementRect::Reset() m_QuadColor = ColorRGBA(-1, -1, -1, -1); } +void CUIElement::SUIElementRect::Draw(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding) +{ + bool NeedsRecreate = false; + if(m_UIRectQuadContainer == -1 || m_X != pRect->x || m_Y != pRect->y || m_Width != pRect->w || m_Height != pRect->h || mem_comp(&m_QuadColor, &Color, sizeof(Color)) != 0) + { + if(m_UIRectQuadContainer != -1) + m_pParent->UI()->Graphics()->DeleteQuadContainer(m_UIRectQuadContainer); + NeedsRecreate = true; + } + if(NeedsRecreate) + { + m_X = pRect->x; + m_Y = pRect->y; + m_Width = pRect->w; + m_Height = pRect->h; + m_QuadColor = Color; + + m_pParent->UI()->Graphics()->SetColor(Color); + m_UIRectQuadContainer = m_pParent->UI()->Graphics()->CreateRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, Rounding, Corners); + m_pParent->UI()->Graphics()->SetColor(1, 1, 1, 1); + } + + m_pParent->UI()->Graphics()->TextureClear(); + m_pParent->UI()->Graphics()->RenderQuadContainer(m_UIRectQuadContainer, -1); +} + /******************************************************** UI *********************************************************/ diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 6ec75489824..4be2a42f12a 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -126,11 +126,15 @@ class CUIElement { friend class CUI; + CUI *m_pUI; + CUIElement(CUI *pUI, int RequestedRectCount) { Init(pUI, RequestedRectCount); } public: struct SUIElementRect { + CUIElement *m_pParent; + public: int m_UIRectQuadContainer; int m_UITextContainer; @@ -152,9 +156,11 @@ class CUIElement ColorRGBA m_QuadColor; void Reset(); + void Draw(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding); }; protected: + CUI *UI() const { return m_pUI; } std::vector m_vUIRects; // used for marquees or other user implemented things From b50309dd5cf2614f69232f3bc0f634388464d956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 8 Jul 2022 17:56:06 +0200 Subject: [PATCH 46/72] Move `CUIRect` class into its own files --- CMakeLists.txt | 2 + src/game/client/ui.cpp | 165 ----------------------------------- src/game/client/ui.h | 97 +-------------------- src/game/client/ui_rect.cpp | 168 ++++++++++++++++++++++++++++++++++++ src/game/client/ui_rect.h | 101 ++++++++++++++++++++++ 5 files changed, 273 insertions(+), 260 deletions(-) create mode 100644 src/game/client/ui_rect.cpp create mode 100644 src/game/client/ui_rect.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 97b8728c37c..39709e37f13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2103,6 +2103,8 @@ if(CLIENT) ui.h ui_ex.cpp ui_ex.h + ui_rect.cpp + ui_rect.h ) set_src(GAME_EDITOR GLOB src/game/editor auto_map.cpp diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 1866223cf0d..d7ce4d4a72e 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -297,171 +297,6 @@ void CUI::UpdateClipping() } } -void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing) const -{ - CUIRect r = *this; - const float Cut = r.h / 2; - const float HalfSpacing = Spacing / 2; - - if(pTop) - { - pTop->x = r.x; - pTop->y = r.y; - pTop->w = r.w; - pTop->h = Cut - HalfSpacing; - } - - if(pBottom) - { - pBottom->x = r.x; - pBottom->y = r.y + Cut + HalfSpacing; - pBottom->w = r.w; - pBottom->h = r.h - Cut - HalfSpacing; - } -} - -void CUIRect::HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const -{ - CUIRect r = *this; - - if(pTop) - { - pTop->x = r.x; - pTop->y = r.y; - pTop->w = r.w; - pTop->h = Cut; - } - - if(pBottom) - { - pBottom->x = r.x; - pBottom->y = r.y + Cut; - pBottom->w = r.w; - pBottom->h = r.h - Cut; - } -} - -void CUIRect::HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const -{ - CUIRect r = *this; - - if(pTop) - { - pTop->x = r.x; - pTop->y = r.y; - pTop->w = r.w; - pTop->h = r.h - Cut; - } - - if(pBottom) - { - pBottom->x = r.x; - pBottom->y = r.y + r.h - Cut; - pBottom->w = r.w; - pBottom->h = Cut; - } -} - -void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing) const -{ - CUIRect r = *this; - const float Cut = r.w / 2; - const float HalfSpacing = Spacing / 2; - - if(pLeft) - { - pLeft->x = r.x; - pLeft->y = r.y; - pLeft->w = Cut - HalfSpacing; - pLeft->h = r.h; - } - - if(pRight) - { - pRight->x = r.x + Cut + HalfSpacing; - pRight->y = r.y; - pRight->w = r.w - Cut - HalfSpacing; - pRight->h = r.h; - } -} - -void CUIRect::VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const -{ - CUIRect r = *this; - - if(pLeft) - { - pLeft->x = r.x; - pLeft->y = r.y; - pLeft->w = Cut; - pLeft->h = r.h; - } - - if(pRight) - { - pRight->x = r.x + Cut; - pRight->y = r.y; - pRight->w = r.w - Cut; - pRight->h = r.h; - } -} - -void CUIRect::VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const -{ - CUIRect r = *this; - - if(pLeft) - { - pLeft->x = r.x; - pLeft->y = r.y; - pLeft->w = r.w - Cut; - pLeft->h = r.h; - } - - if(pRight) - { - pRight->x = r.x + r.w - Cut; - pRight->y = r.y; - pRight->w = Cut; - pRight->h = r.h; - } -} - -void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const -{ - CUIRect r = *this; - - pOtherRect->x = r.x + Cut; - pOtherRect->y = r.y + Cut; - pOtherRect->w = r.w - 2 * Cut; - pOtherRect->h = r.h - 2 * Cut; -} - -void CUIRect::VMargin(float Cut, CUIRect *pOtherRect) const -{ - CUIRect r = *this; - - pOtherRect->x = r.x + Cut; - pOtherRect->y = r.y; - pOtherRect->w = r.w - 2 * Cut; - pOtherRect->h = r.h; -} - -void CUIRect::HMargin(float Cut, CUIRect *pOtherRect) const -{ - CUIRect r = *this; - - pOtherRect->x = r.x; - pOtherRect->y = r.y + Cut; - pOtherRect->w = r.w; - pOtherRect->h = r.h - 2 * Cut; -} - -bool CUIRect::Inside(float x_, float y_) const -{ - return x_ >= this->x && x_ < this->x + this->w && y_ >= this->y && y_ < this->y + this->h; -} - int CUI::DoButtonLogic(const void *pID, int Checked, const CUIRect *pRect) { // logic diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 4be2a42f12a..cbd5916ff4e 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -3,6 +3,8 @@ #ifndef GAME_CLIENT_UI_H #define GAME_CLIENT_UI_H +#include "ui_rect.h" + #include #include @@ -10,101 +12,6 @@ #include #include -class CUIRect -{ -public: - float x, y, w, h; - - /** - * Splits 2 CUIRect inside *this* CUIRect horizontally. You can pass null pointers. - * - * @param pTop This rect will end up taking the top half of this CUIRect. - * @param pBottom This rect will end up taking the bottom half of this CUIRect. - * @param Spacing Total size of margin between split rects. - */ - void HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing = 0.0f) const; - /** - * Splits 2 CUIRect inside *this* CUIRect. - * - * The cut parameter determines the height of the top rect, so it allows more customization than HSplitMid. - * - * This method doesn't check if Cut is bigger than *this* rect height. - * - * @param Cut The height of the pTop rect. - * @param pTop The rect that ends up at the top with a height equal to Cut. - * @param pBottom The rect that ends up at the bottom with a height equal to *this* rect minus the Cut. - */ - void HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const; - /** - * Splits 2 CUIRect inside *this* CUIRect. - * - * The cut parameter determines the height of the bottom rect, so it allows more customization than HSplitMid. - * - * This method doesn't check if Cut is bigger than *this* rect height. - * - * @param Cut The height of the pBottom rect. - * @param pTop The rect that ends up at the top with a height equal to *this* CUIRect height minus Cut. - * @param pBottom The rect that ends up at the bottom with a height equal to Cut. - */ - void HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const; - /** - * Splits 2 CUIRect inside *this* CUIRect vertically. You can pass null pointers. - * - * @param pLeft This rect will take up the left half of *this* CUIRect. - * @param pRight This rect will take up the right half of *this* CUIRect. - * @param Spacing Total size of margin between split rects. - */ - void VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing = 0.0f) const; - /** - * Splits 2 CUIRect inside *this* CUIRect. - * - * The cut parameter determines the width of the left rect, so it allows more customization than VSplitMid. - * - * This method doesn't check if Cut is bigger than *this* rect width. - * - * @param Cut The width of the pLeft rect. - * @param pLeft The rect that ends up at the left with a width equal to Cut. - * @param pRight The rect that ends up at the right with a width equal to *this* rect minus the Cut. - */ - void VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const; - /** - * Splits 2 CUIRect inside *this* CUIRect. - * - * The cut parameter determines the width of the right rect, so it allows more customization than VSplitMid. - * - * This method doesn't check if Cut is bigger than *this* rect width. - * - * @param Cut The width of the pRight rect. - * @param pLeft The rect that ends up at the left with a width equal to *this* CUIRect width minus Cut. - * @param pRight The rect that ends up at the right with a width equal to Cut. - */ - void VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const; - - /** - * Places pOtherRect inside *this* CUIRect with Cut as the margin. - * - * @param Cut The margin. - * @param pOtherRect The CUIRect to place inside *this* CUIRect. - */ - void Margin(float Cut, CUIRect *pOtherRect) const; - /** - * Places pOtherRect inside *this* CUIRect applying Cut as the margin only on the vertical axis. - * - * @param Cut The margin. - * @param pOtherRect The CUIRect to place inside *this* CUIRect - */ - void VMargin(float Cut, CUIRect *pOtherRect) const; - /** - * Places pOtherRect inside *this* CUIRect applying Cut as the margin only on the horizontal axis. - * - * @param Cut The margin. - * @param pOtherRect The CUIRect to place inside *this* CUIRect - */ - void HMargin(float Cut, CUIRect *pOtherRect) const; - - bool Inside(float x_, float y_) const; -}; - struct SUIAnimator { bool m_Active; diff --git a/src/game/client/ui_rect.cpp b/src/game/client/ui_rect.cpp new file mode 100644 index 00000000000..b9e14306722 --- /dev/null +++ b/src/game/client/ui_rect.cpp @@ -0,0 +1,168 @@ +/* (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 "ui_rect.h" + +void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing) const +{ + CUIRect r = *this; + const float Cut = r.h / 2; + const float HalfSpacing = Spacing / 2; + + if(pTop) + { + pTop->x = r.x; + pTop->y = r.y; + pTop->w = r.w; + pTop->h = Cut - HalfSpacing; + } + + if(pBottom) + { + pBottom->x = r.x; + pBottom->y = r.y + Cut + HalfSpacing; + pBottom->w = r.w; + pBottom->h = r.h - Cut - HalfSpacing; + } +} + +void CUIRect::HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const +{ + CUIRect r = *this; + + if(pTop) + { + pTop->x = r.x; + pTop->y = r.y; + pTop->w = r.w; + pTop->h = Cut; + } + + if(pBottom) + { + pBottom->x = r.x; + pBottom->y = r.y + Cut; + pBottom->w = r.w; + pBottom->h = r.h - Cut; + } +} + +void CUIRect::HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const +{ + CUIRect r = *this; + + if(pTop) + { + pTop->x = r.x; + pTop->y = r.y; + pTop->w = r.w; + pTop->h = r.h - Cut; + } + + if(pBottom) + { + pBottom->x = r.x; + pBottom->y = r.y + r.h - Cut; + pBottom->w = r.w; + pBottom->h = Cut; + } +} + +void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing) const +{ + CUIRect r = *this; + const float Cut = r.w / 2; + const float HalfSpacing = Spacing / 2; + + if(pLeft) + { + pLeft->x = r.x; + pLeft->y = r.y; + pLeft->w = Cut - HalfSpacing; + pLeft->h = r.h; + } + + if(pRight) + { + pRight->x = r.x + Cut + HalfSpacing; + pRight->y = r.y; + pRight->w = r.w - Cut - HalfSpacing; + pRight->h = r.h; + } +} + +void CUIRect::VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const +{ + CUIRect r = *this; + + if(pLeft) + { + pLeft->x = r.x; + pLeft->y = r.y; + pLeft->w = Cut; + pLeft->h = r.h; + } + + if(pRight) + { + pRight->x = r.x + Cut; + pRight->y = r.y; + pRight->w = r.w - Cut; + pRight->h = r.h; + } +} + +void CUIRect::VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const +{ + CUIRect r = *this; + + if(pLeft) + { + pLeft->x = r.x; + pLeft->y = r.y; + pLeft->w = r.w - Cut; + pLeft->h = r.h; + } + + if(pRight) + { + pRight->x = r.x + r.w - Cut; + pRight->y = r.y; + pRight->w = Cut; + pRight->h = r.h; + } +} + +void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const +{ + CUIRect r = *this; + + pOtherRect->x = r.x + Cut; + pOtherRect->y = r.y + Cut; + pOtherRect->w = r.w - 2 * Cut; + pOtherRect->h = r.h - 2 * Cut; +} + +void CUIRect::VMargin(float Cut, CUIRect *pOtherRect) const +{ + CUIRect r = *this; + + pOtherRect->x = r.x + Cut; + pOtherRect->y = r.y; + pOtherRect->w = r.w - 2 * Cut; + pOtherRect->h = r.h; +} + +void CUIRect::HMargin(float Cut, CUIRect *pOtherRect) const +{ + CUIRect r = *this; + + pOtherRect->x = r.x; + pOtherRect->y = r.y + Cut; + pOtherRect->w = r.w; + pOtherRect->h = r.h - 2 * Cut; +} + +bool CUIRect::Inside(float x_, float y_) const +{ + return x_ >= this->x && x_ < this->x + this->w && y_ >= this->y && y_ < this->y + this->h; +} diff --git a/src/game/client/ui_rect.h b/src/game/client/ui_rect.h new file mode 100644 index 00000000000..bbb886e5ce7 --- /dev/null +++ b/src/game/client/ui_rect.h @@ -0,0 +1,101 @@ +/* (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. */ +#ifndef GAME_CLIENT_UI_RECT_H +#define GAME_CLIENT_UI_RECT_H + +class CUIRect +{ +public: + float x, y, w, h; + + /** + * Splits 2 CUIRect inside *this* CUIRect horizontally. You can pass null pointers. + * + * @param pTop This rect will end up taking the top half of this CUIRect. + * @param pBottom This rect will end up taking the bottom half of this CUIRect. + * @param Spacing Total size of margin between split rects. + */ + void HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing = 0.0f) const; + /** + * Splits 2 CUIRect inside *this* CUIRect. + * + * The cut parameter determines the height of the top rect, so it allows more customization than HSplitMid. + * + * This method doesn't check if Cut is bigger than *this* rect height. + * + * @param Cut The height of the pTop rect. + * @param pTop The rect that ends up at the top with a height equal to Cut. + * @param pBottom The rect that ends up at the bottom with a height equal to *this* rect minus the Cut. + */ + void HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const; + /** + * Splits 2 CUIRect inside *this* CUIRect. + * + * The cut parameter determines the height of the bottom rect, so it allows more customization than HSplitMid. + * + * This method doesn't check if Cut is bigger than *this* rect height. + * + * @param Cut The height of the pBottom rect. + * @param pTop The rect that ends up at the top with a height equal to *this* CUIRect height minus Cut. + * @param pBottom The rect that ends up at the bottom with a height equal to Cut. + */ + void HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const; + /** + * Splits 2 CUIRect inside *this* CUIRect vertically. You can pass null pointers. + * + * @param pLeft This rect will take up the left half of *this* CUIRect. + * @param pRight This rect will take up the right half of *this* CUIRect. + * @param Spacing Total size of margin between split rects. + */ + void VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing = 0.0f) const; + /** + * Splits 2 CUIRect inside *this* CUIRect. + * + * The cut parameter determines the width of the left rect, so it allows more customization than VSplitMid. + * + * This method doesn't check if Cut is bigger than *this* rect width. + * + * @param Cut The width of the pLeft rect. + * @param pLeft The rect that ends up at the left with a width equal to Cut. + * @param pRight The rect that ends up at the right with a width equal to *this* rect minus the Cut. + */ + void VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const; + /** + * Splits 2 CUIRect inside *this* CUIRect. + * + * The cut parameter determines the width of the right rect, so it allows more customization than VSplitMid. + * + * This method doesn't check if Cut is bigger than *this* rect width. + * + * @param Cut The width of the pRight rect. + * @param pLeft The rect that ends up at the left with a width equal to *this* CUIRect width minus Cut. + * @param pRight The rect that ends up at the right with a width equal to Cut. + */ + void VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const; + + /** + * Places pOtherRect inside *this* CUIRect with Cut as the margin. + * + * @param Cut The margin. + * @param pOtherRect The CUIRect to place inside *this* CUIRect. + */ + void Margin(float Cut, CUIRect *pOtherRect) const; + /** + * Places pOtherRect inside *this* CUIRect applying Cut as the margin only on the vertical axis. + * + * @param Cut The margin. + * @param pOtherRect The CUIRect to place inside *this* CUIRect + */ + void VMargin(float Cut, CUIRect *pOtherRect) const; + /** + * Places pOtherRect inside *this* CUIRect applying Cut as the margin only on the horizontal axis. + * + * @param Cut The margin. + * @param pOtherRect The CUIRect to place inside *this* CUIRect + */ + void HMargin(float Cut, CUIRect *pOtherRect) const; + + bool Inside(float x_, float y_) const; +}; + +#endif From 49164dfcdf8d6b49147a9c692d5b6d09ed385a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 8 Jul 2022 18:02:26 +0200 Subject: [PATCH 47/72] Improve argument names of `CUIRect::Inside` --- src/game/client/ui_rect.cpp | 4 ++-- src/game/client/ui_rect.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/client/ui_rect.cpp b/src/game/client/ui_rect.cpp index b9e14306722..9dd97cb5db3 100644 --- a/src/game/client/ui_rect.cpp +++ b/src/game/client/ui_rect.cpp @@ -162,7 +162,7 @@ void CUIRect::HMargin(float Cut, CUIRect *pOtherRect) const pOtherRect->h = r.h - 2 * Cut; } -bool CUIRect::Inside(float x_, float y_) const +bool CUIRect::Inside(float PointX, float PointY) const { - return x_ >= this->x && x_ < this->x + this->w && y_ >= this->y && y_ < this->y + this->h; + return PointX >= x && PointX < x + w && PointY >= y && PointY < y + h; } diff --git a/src/game/client/ui_rect.h b/src/game/client/ui_rect.h index bbb886e5ce7..1cf92ed2e75 100644 --- a/src/game/client/ui_rect.h +++ b/src/game/client/ui_rect.h @@ -95,7 +95,7 @@ class CUIRect */ void HMargin(float Cut, CUIRect *pOtherRect) const; - bool Inside(float x_, float y_) const; + bool Inside(float PointX, float PointY) const; }; #endif From 680dd052d754b658f57f5d4ddff7f64ee67052de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 8 Jul 2022 18:02:56 +0200 Subject: [PATCH 48/72] Add documentation for `CUIRect::Inside` --- src/game/client/ui_rect.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/game/client/ui_rect.h b/src/game/client/ui_rect.h index 1cf92ed2e75..375247abc71 100644 --- a/src/game/client/ui_rect.h +++ b/src/game/client/ui_rect.h @@ -94,7 +94,13 @@ class CUIRect * @param pOtherRect The CUIRect to place inside *this* CUIRect */ void HMargin(float Cut, CUIRect *pOtherRect) const; - + /** + * Checks whether a point is inside *this* CUIRect. + * + * @param PointX The point's X position. + * @param PointY The point's Y position. + * @return true iff the given point is inside *this* CUIRect. + */ bool Inside(float PointX, float PointY) const; }; From 7b390808bcdb385b7a83d2231729b9cf37b75480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 8 Jul 2022 18:28:30 +0200 Subject: [PATCH 49/72] Replace `ui.h` include with `ui_rect.h`, organize other includes --- src/game/client/components/tooltips.cpp | 1 + src/game/client/components/tooltips.h | 5 +++-- src/game/client/render.h | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/game/client/components/tooltips.cpp b/src/game/client/components/tooltips.cpp index 3f3821c0693..3e4a3caf08c 100644 --- a/src/game/client/components/tooltips.cpp +++ b/src/game/client/components/tooltips.cpp @@ -1,6 +1,7 @@ #include "tooltips.h" #include +#include CTooltips::CTooltips() { diff --git a/src/game/client/components/tooltips.h b/src/game/client/components/tooltips.h index 400eb5f5c06..a56ab42d25d 100644 --- a/src/game/client/components/tooltips.h +++ b/src/game/client/components/tooltips.h @@ -1,10 +1,11 @@ #ifndef GAME_CLIENT_COMPONENTS_TOOLTIPS_H #define GAME_CLIENT_COMPONENTS_TOOLTIPS_H -#include #include -#include +#include +#include +#include #include #include diff --git a/src/game/client/render.h b/src/game/client/render.h index 1fef91abc64..66060cf1efd 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -3,12 +3,11 @@ #ifndef GAME_CLIENT_RENDER_H #define GAME_CLIENT_RENDER_H -#include "ui.h" - #include #include #include +#include class CSpeedupTile; class CSwitchTile; From 95550fd6a9c608e612343d9079a69de8a91d5c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 7 Aug 2022 18:12:07 +0200 Subject: [PATCH 50/72] Move `CRenderTools::DrawUIRect/4` to `CUIRect::Draw/4` Use `ColorRGBA` instead of `vec4` for `Draw4`. --- src/game/client/components/menus.cpp | 46 +++++++++---------- src/game/client/components/menus_browser.cpp | 30 ++++++------ src/game/client/components/menus_demo.cpp | 28 +++++------ src/game/client/components/menus_ingame.cpp | 32 ++++++------- src/game/client/components/menus_settings.cpp | 40 ++++++++-------- src/game/client/components/menus_start.cpp | 4 +- src/game/client/components/tooltips.cpp | 2 +- src/game/client/components/voting.cpp | 8 ++-- src/game/client/render.cpp | 10 ---- src/game/client/render.h | 4 -- src/game/client/ui.cpp | 1 + src/game/client/ui_ex.cpp | 16 +++---- src/game/client/ui_rect.cpp | 14 ++++++ src/game/client/ui_rect.h | 11 +++++ src/game/editor/editor.cpp | 38 +++++++-------- src/game/editor/popups.cpp | 4 +- 16 files changed, 150 insertions(+), 138 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index d4867a34f68..9fd884c4e9b 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -152,7 +152,7 @@ int CMenus::DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, if(!MouseInsideColorPicker) Color.a *= UI()->ButtonColorMul(pButtonContainer); - RenderTools()->DrawUIRect(pRect, Color, Corners, r); + pRect->Draw(Color, Corners, r); if(pImageName) { @@ -188,7 +188,7 @@ int CMenus::DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); + pRect->Draw(ColorRGBA(1, 1, 1, 0.5f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); CUIRect Temp; pRect->HMargin(1.0f, &Temp); UI()->DoLabel(&Temp, pText, Temp.h * CUI::ms_FontmodHeight, TEXTALIGN_CENTER); @@ -230,7 +230,7 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe if(pActiveColor) ColorMenuTab = *pActiveColor; - RenderTools()->DrawUIRect(&Rect, ColorMenuTab, Corners, EdgeRounding); + Rect.Draw(ColorMenuTab, Corners, EdgeRounding); } else { @@ -240,7 +240,7 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe if(pHoverColor) HoverColorMenuTab = *pHoverColor; - RenderTools()->DrawUIRect(&Rect, HoverColorMenuTab, Corners, EdgeRounding); + Rect.Draw(HoverColorMenuTab, Corners, EdgeRounding); } else { @@ -248,7 +248,7 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe if(pDefaultColor) ColorMenuTab = *pDefaultColor; - RenderTools()->DrawUIRect(&Rect, ColorMenuTab, Corners, EdgeRounding); + Rect.Draw(ColorMenuTab, Corners, EdgeRounding); } } @@ -279,9 +279,9 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe int CMenus::DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { if(Checked == 2) - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 0.98f, 0.5f, 0.55f), IGraphics::CORNER_T, 5.0f); + pRect->Draw(ColorRGBA(1, 0.98f, 0.5f, 0.55f), IGraphics::CORNER_T, 5.0f); else if(Checked) - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_T, 5.0f); + pRect->Draw(ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_T, 5.0f); CUIRect t; pRect->VSplitLeft(5.0f, 0, &t); UI()->DoLabel(&t, pText, pRect->h * CUI::ms_FontmodHeight, TEXTALIGN_LEFT); @@ -298,7 +298,7 @@ int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const c t.VSplitLeft(5.0f, 0, &t); c.Margin(2.0f, &c); - RenderTools()->DrawUIRect(&c, ColorRGBA(1, 1, 1, 0.25f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 3.0f); + c.Draw(ColorRGBA(1, 1, 1, 0.25f * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 3.0f); const bool Checkable = *pBoxText == 'X'; SLabelProperties Props; @@ -556,7 +556,7 @@ int CMenus::DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool else str_format(aBuf, sizeof(aBuf), "%d", Current); } - RenderTools()->DrawUIRect(pRect, *pColor, IGraphics::CORNER_ALL, Round); + pRect->Draw(*pColor, IGraphics::CORNER_ALL, Round); UI()->DoLabel(pRect, aBuf, 10, TEXTALIGN_CENTER); } @@ -922,7 +922,7 @@ void CMenus::RenderLoading(const char *pCaption, const char *pContent, int Incre Graphics()->BlendNormal(); Graphics()->TextureClear(); - RenderTools()->DrawUIRect(&Box, ColorRGBA{0, 0, 0, 0.50f}, IGraphics::CORNER_ALL, 15.0f); + Box.Draw(ColorRGBA{0, 0, 0, 0.50f}, IGraphics::CORNER_ALL, 15.0f); CUIRect Part; @@ -949,7 +949,7 @@ void CMenus::RenderNews(CUIRect MainView) { g_Config.m_UiUnreadNews = false; - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.HSplitTop(15.0f, 0, &MainView); MainView.VSplitLeft(15.0f, 0, &MainView); @@ -1097,7 +1097,7 @@ void CMenus::RenderColorPicker() // Render ColorRGBA BackgroundColor(0.1f, 0.1f, 0.1f, 1.0f); - RenderTools()->DrawUIRect(&PickerRect, BackgroundColor, 0, 0); + PickerRect.Draw(BackgroundColor, 0, 0); CUIRect ColorsArea, HueArea, ValuesHitbox, BottomArea, HSVHRect, HSVSRect, HSVVRect, HEXRect, ALPHARect; PickerRect.Margin(3, &ColorsArea); @@ -1135,10 +1135,10 @@ void CMenus::RenderColorPicker() ColorRGBA BlackColor(0, 0, 0, 0.5f); - RenderTools()->DrawUIRect(&HueArea, BlackColor, 0, 0); + HueArea.Draw(BlackColor, 0, 0); HueArea.Margin(1, &HueArea); - RenderTools()->DrawUIRect(&ColorsArea, BlackColor, 0, 0); + ColorsArea.Draw(BlackColor, 0, 0); ColorsArea.Margin(1, &ColorsArea); unsigned int H = ms_ColorPicker.m_HSVColor / (1 << 16); @@ -1158,14 +1158,14 @@ void CMenus::RenderColorPicker() rgb = color_cast(ColorHSVA(PickerColorHSV.x, 1.0f, 1.0f)); vec4 BR(rgb.r, rgb.g, rgb.b, 1.0f); - RenderTools()->DrawUIRect4(&ColorsArea, TL, TR, BL, BR, IGraphics::CORNER_NONE, 0.0f); + ColorsArea.Draw4(TL, TR, BL, BR, IGraphics::CORNER_NONE, 0.0f); TL = vec4(0.0f, 0.0f, 0.0f, 0.0f); TR = vec4(0.0f, 0.0f, 0.0f, 0.0f); BL = vec4(0.0f, 0.0f, 0.0f, 1.0f); BR = vec4(0.0f, 0.0f, 0.0f, 1.0f); - RenderTools()->DrawUIRect4(&ColorsArea, TL, TR, BL, BR, IGraphics::CORNER_NONE, 0.0f); + ColorsArea.Draw4(TL, TR, BL, BR, IGraphics::CORNER_NONE, 0.0f); // Hue Area static const float s_aColorIndices[7][3] = { @@ -1188,7 +1188,7 @@ void CMenus::RenderColorPicker() BL = vec4(s_aColorIndices[j + 1][0], s_aColorIndices[j + 1][1], s_aColorIndices[j + 1][2], 1.0f); HuePartialArea.y = HueArea.y + HuePickerOffset * j; - RenderTools()->DrawUIRect4(&HuePartialArea, TL, TL, BL, BL, IGraphics::CORNER_NONE, 0.0f); + HuePartialArea.Draw4(TL, TL, BL, BL, IGraphics::CORNER_NONE, 0.0f); } //Editboxes Area @@ -1215,7 +1215,7 @@ void CMenus::RenderColorPicker() // TODO : ALPHA SUPPORT //static int ALPHAID = 0; UI()->DoLabel(&ALPHARect, "A: 255", 10, TEXTALIGN_CENTER); - RenderTools()->DrawUIRect(&ALPHARect, ColorRGBA(0, 0, 0, 0.65f), IGraphics::CORNER_ALL, 5.0f); + ALPHARect.Draw(ColorRGBA(0, 0, 0, 0.65f), IGraphics::CORNER_ALL, 5.0f); // Logic float PickerX, PickerY; @@ -1257,9 +1257,9 @@ void CMenus::RenderColorPicker() const float HMOColor = PickerColorHSV.x > 0.75f ? 1.0f : 0.0f; ColorRGBA HueMarkerOutline(HMOColor, HMOColor, HMOColor, 1); - RenderTools()->DrawUIRect(&HueMarker, HueMarkerOutline, IGraphics::CORNER_ALL, 1.2f); + HueMarker.Draw(HueMarkerOutline, IGraphics::CORNER_ALL, 1.2f); HueMarker.Margin(1.2f, &HueMarker); - RenderTools()->DrawUIRect(&HueMarker, HueMarkerColor, IGraphics::CORNER_ALL, 1.2f); + HueMarker.Draw(HueMarkerColor, IGraphics::CORNER_ALL, 1.2f); ms_ColorPicker.m_HSVColor = PickerColorHSV.Pack(false); *ms_ColorPicker.m_pColor = color_cast(PickerColorHSV).Pack(false); @@ -1618,7 +1618,7 @@ int CMenus::Render() Box.Margin(150.0f, &Box); // render the box - RenderTools()->DrawUIRect(&Box, BgColor, IGraphics::CORNER_ALL, 15.0f); + Box.Draw(BgColor, IGraphics::CORNER_ALL, 15.0f); Box.HSplitTop(20.f, &Part, &Box); Box.HSplitTop(24.f, &Part, &Box); @@ -1826,9 +1826,9 @@ int CMenus::Render() Box.HSplitTop(20.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); Part.VMargin(40.0f, &Part); - RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 5.0f); + Part.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 5.0f); Part.w = maximum(10.0f, (Part.w * Client()->MapDownloadAmount()) / Client()->MapDownloadTotalsize()); - RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), IGraphics::CORNER_ALL, 5.0f); + Part.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), IGraphics::CORNER_ALL, 5.0f); } } else if(m_Popup == POPUP_LANGUAGE) diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 89ead1f265f..09ec8142f6b 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -59,7 +59,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) View.HSplitBottom(70.0f, &View, &Status); // split of the scrollbar - RenderTools()->DrawUIRect(&Headers, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); + Headers.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); Headers.VSplitRight(20.0f, &Headers, 0); struct CColumn @@ -164,7 +164,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } } - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.15f), 0, 0); + View.Draw(ColorRGBA(0, 0, 0, 0.15f), 0, 0); CUIRect Scroll; View.VSplitRight(20.0f, &View, &Scroll); @@ -494,7 +494,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } } - //RenderTools()->DrawUIRect(&Status, ms_ColorTabbarActive, IGraphics::CORNER_B, 5.0f); + //Status.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 5.0f); Status.Margin(5.0f, &Status); CUIRect SearchInfoAndAddr, ServersAndConnect, Status3; @@ -680,9 +680,9 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) // server filter ServerFilter.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFilter); - RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); + FilterHeader.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); - RenderTools()->DrawUIRect(&ServerFilter, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); + ServerFilter.Draw(ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); UI()->DoLabel(&FilterHeader, Localize("Server filter"), FontSize + 2.0f, TEXTALIGN_CENTER); CUIRect Button, Button2; @@ -797,7 +797,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); ServerFilter.HSplitTop(120.0f, &ServerFilter, 0); - RenderTools()->DrawUIRect(&ServerFilter, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + ServerFilter.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); Button.VSplitMid(&Button, &Button2); @@ -1047,8 +1047,8 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) CTextCursor Cursor; const float FontSize = 12.0f; ServerDetails.HSplitTop(ms_ListheaderHeight, &ServerHeader, &ServerDetails); - RenderTools()->DrawUIRect(&ServerHeader, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); - RenderTools()->DrawUIRect(&ServerDetails, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); + ServerHeader.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); + ServerDetails.Draw(ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); UI()->DoLabel(&ServerHeader, Localize("Server details"), FontSize + 2.0f, TEXTALIGN_CENTER); if(pSelectedServer) @@ -1159,7 +1159,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) ColorRGBA Color = pSelectedServer->m_aClients[i].m_FriendState == IFriends::FRIEND_NO ? ColorRGBA(1.0f, 1.0f, 1.0f, (i % 2 + 1) * 0.05f) : ColorRGBA(0.5f, 1.0f, 0.5f, 0.15f + (i % 2 + 1) * 0.05f); - RenderTools()->DrawUIRect(&Name, Color, IGraphics::CORNER_ALL, 4.0f); + Name.Draw(Color, IGraphics::CORNER_ALL, 4.0f); Name.VSplitLeft(5.0f, 0, &Name); Name.VSplitLeft(34.0f, &Score, &Name); Name.VSplitRight(34.0f, &Name, &Flag); @@ -1266,8 +1266,8 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) // header ServerFriends.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFriends); - RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); - RenderTools()->DrawUIRect(&ServerFriends, ColorRGBA(0, 0, 0, 0.15f), 0, 4.0f); + FilterHeader.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f); + ServerFriends.Draw(ColorRGBA(0, 0, 0, 0.15f), 0, 4.0f); UI()->DoLabel(&FilterHeader, Localize("Friends"), FontSize + 4.0f, TEXTALIGN_CENTER); CUIRect Button, List; @@ -1291,14 +1291,14 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) Item.m_Rect.Margin(1.5f, &Item.m_Rect); CUIRect OnState; Item.m_Rect.VSplitRight(30.0f, &Item.m_Rect, &OnState); - RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.1f), IGraphics::CORNER_L, 4.0f); + Item.m_Rect.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.1f), IGraphics::CORNER_L, 4.0f); Item.m_Rect.VMargin(2.5f, &Item.m_Rect); Item.m_Rect.HSplitTop(12.0f, &Item.m_Rect, &Button); UI()->DoLabel(&Item.m_Rect, Friend.m_pFriendInfo->m_aName, FontSize, TEXTALIGN_LEFT); UI()->DoLabel(&Button, Friend.m_pFriendInfo->m_aClan, FontSize, TEXTALIGN_LEFT); - RenderTools()->DrawUIRect(&OnState, Friend.m_NumFound ? ColorRGBA(0.0f, 1.0f, 0.0f, 0.25f) : ColorRGBA(1.0f, 0.0f, 0.0f, 0.25f), IGraphics::CORNER_R, 4.0f); + OnState.Draw(Friend.m_NumFound ? ColorRGBA(0.0f, 1.0f, 0.0f, 0.25f) : ColorRGBA(1.0f, 0.0f, 0.0f, 0.25f), IGraphics::CORNER_R, 4.0f); OnState.HMargin((OnState.h - FontSize) / 3, &OnState); OnState.VMargin(5.0f, &OnState); char aBuf[64]; @@ -1397,7 +1397,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) CUIRect ServerList, ToolBox; // background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); // create server list, status box, tab bar and tool box area @@ -1413,7 +1413,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) // tool box { - RenderTools()->DrawUIRect(&ToolBox, ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f), IGraphics::CORNER_ALL, 4.0f); + ToolBox.Draw(ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f), IGraphics::CORNER_ALL, 4.0f); if(ToolboxPage == 0) RenderServerbrowserFilters(ToolBox); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 7bbe2a69e3d..c7055b71bd4 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -29,14 +29,14 @@ using namespace std::chrono_literals; int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { - RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, (Checked ? 0.10f : 0.5f) * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); + pRect->Draw(ColorRGBA(1, 1, 1, (Checked ? 0.10f : 0.5f) * UI()->ButtonColorMul(pID)), IGraphics::CORNER_ALL, 5.0f); UI()->DoLabel(pRect, pText, 14.0f, TEXTALIGN_CENTER); return UI()->DoButtonLogic(pID, Checked, pRect); } int CMenus::DoButton_Sprite(CButtonContainer *pButtonContainer, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners) { - RenderTools()->DrawUIRect(pRect, ColorRGBA(1.0f, 1.0f, 1.0f, (Checked ? 0.10f : 0.5f) * UI()->ButtonColorMul(pButtonContainer)), Corners, 5.0f); + pRect->Draw(ColorRGBA(1.0f, 1.0f, 1.0f, (Checked ? 0.10f : 0.5f) * UI()->ButtonColorMul(pButtonContainer)), Corners, 5.0f); Graphics()->TextureSet(g_pData->m_aImages[ImageID].m_Id); Graphics()->QuadsBegin(); if(!Checked) @@ -86,7 +86,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) Box.Margin(150.0f, &Box); // render the box - RenderTools()->DrawUIRect(&Box, ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, 15.0f); + Box.Draw(ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, 15.0f); Box.HSplitTop(20.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); @@ -256,7 +256,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) MainView.VSplitLeft(50.0f, 0, &MainView); MainView.VSplitLeft(450.0f, &MainView, 0); - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_T, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_T, 10.0f); MainView.Margin(5.0f, &MainView); @@ -277,13 +277,13 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) char aBuffer[128]; // draw seek bar - RenderTools()->DrawUIRect(&SeekBar, ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, 5.0f); + SeekBar.Draw(ColorRGBA(0, 0, 0, 0.5f), IGraphics::CORNER_ALL, 5.0f); // draw filled bar float Amount = CurrentTick / (float)TotalTicks; CUIRect FilledBar = SeekBar; FilledBar.w = 10.0f + (FilledBar.w - 10.0f) * Amount; - RenderTools()->DrawUIRect(&FilledBar, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 5.0f); + FilledBar.Draw(ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 5.0f); // draw markers for(int i = 0; i < pInfo->m_NumTimelineMarkers; i++) @@ -524,7 +524,7 @@ void CMenus::UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHe if(!LogicOnly) { // background - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_ALL, 5.0f); + View.Draw(ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_ALL, 5.0f); } View.VSplitRight(20.0f, &View, &Scroll); @@ -710,13 +710,13 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected, //selected_index = i; CUIRect r = Item.m_Rect; r.Margin(1.5f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); + r.Draw(ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } else if(UI()->MouseInside(&HitRect) && !NoHoverEffects) { CUIRect r = Item.m_Rect; r.Margin(1.5f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); + r.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); } return Item; @@ -866,7 +866,7 @@ void CMenus::RenderDemoList(CUIRect MainView) } // render background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); #if defined(CONF_VIDEORECORDER) @@ -900,7 +900,7 @@ void CMenus::RenderDemoList(CUIRect MainView) // render demo info MainView.VMargin(5.0f, &MainView); MainView.HSplitBottom(5.0f, &MainView, 0); - RenderTools()->DrawUIRect(&MainView, ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); + MainView.Draw(ColorRGBA(0, 0, 0, 0.15f), IGraphics::CORNER_B, 4.0f); if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_vDemos[m_DemolistSelectedIndex].m_Valid) { CUIRect Left, Right, Labels; @@ -1019,7 +1019,7 @@ void CMenus::RenderDemoList(CUIRect MainView) Localize("Demo");Localize("Markers");Localize("Length");Localize("Date"); */ - RenderTools()->DrawUIRect(&Headers, ColorRGBA(0.0f, 0, 0, 0.15f), 0, 0); + Headers.Draw(ColorRGBA(0.0f, 0, 0, 0.15f), 0, 0); int NumCols = std::size(s_aCols); @@ -1115,13 +1115,13 @@ void CMenus::RenderDemoList(CUIRect MainView) { CUIRect Rect = Row; Rect.Margin(0.5f, &Rect); - RenderTools()->DrawUIRect(&Rect, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); + Rect.Draw(ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } else if(UI()->MouseHovered(&Row)) { CUIRect Rect = Row; Rect.Margin(0.5f, &Rect); - RenderTools()->DrawUIRect(&Rect, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); + Rect.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); } if(UI()->DoButtonLogic(Item.m_aName, Selected, &Row)) diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 14ad6b9f1c7..2ebb0378a77 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -38,7 +38,7 @@ void CMenus::RenderGame(CUIRect MainView) { CUIRect Button, ButtonBar, ButtonBar2; MainView.HSplitTop(45.0f, &ButtonBar, &MainView); - RenderTools()->DrawUIRect(&ButtonBar, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + ButtonBar.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); // button bar ButtonBar.HSplitTop(10.0f, 0, &ButtonBar); @@ -209,11 +209,11 @@ void CMenus::RenderGame(CUIRect MainView) void CMenus::RenderPlayers(CUIRect MainView) { CUIRect Button, Button2, ButtonBar, Options, Player; - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); // player options MainView.Margin(10.0f, &Options); - RenderTools()->DrawUIRect(&Options, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 10.0f); + Options.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 10.0f); Options.Margin(10.0f, &Options); Options.HSplitTop(50.0f, &Button, &Options); UI()->DoLabel(&Button, Localize("Player options"), 34.0f, TEXTALIGN_LEFT); @@ -278,7 +278,7 @@ void CMenus::RenderPlayers(CUIRect MainView) continue; if(Count % 2 == 1) - RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 10.0f); + Item.m_Rect.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 10.0f); Item.m_Rect.VSplitRight(300.0f, &Player, &Item.m_Rect); // player info @@ -359,7 +359,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) Client()->GetServerInfo(&CurrentServerInfo); // render background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); CUIRect View, ServerInfo, GameInfo, Motd; @@ -374,7 +374,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) // serverinfo View.HSplitTop(View.h / 2 - 5.0f, &ServerInfo, &Motd); ServerInfo.VSplitLeft(View.w / 2 - 5.0f, &ServerInfo, &GameInfo); - RenderTools()->DrawUIRect(&ServerInfo, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + ServerInfo.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); ServerInfo.Margin(5.0f, &ServerInfo); @@ -418,7 +418,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) // gameinfo GameInfo.VSplitLeft(10.0f, 0x0, &GameInfo); - RenderTools()->DrawUIRect(&GameInfo, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + GameInfo.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); GameInfo.Margin(5.0f, &GameInfo); @@ -451,7 +451,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) // motd Motd.HSplitTop(10.0f, 0, &Motd); - RenderTools()->DrawUIRect(&Motd, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + Motd.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); Motd.Margin(5.0f, &Motd); y = 0.0f; x = 5.0f; @@ -565,9 +565,9 @@ void CMenus::RenderServerControl(CUIRect MainView) // render background CUIRect Bottom, RconExtension, TabBar, Button; MainView.HSplitTop(20.0f, &Bottom, &MainView); - RenderTools()->DrawUIRect(&Bottom, ms_ColorTabbarActive, 0, 10.0f); + Bottom.Draw(ms_ColorTabbarActive, 0, 10.0f); MainView.HSplitTop(20.0f, &TabBar, &MainView); - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); if(Client()->RconAuthed()) @@ -769,7 +769,7 @@ void CMenus::RenderInGameNetwork(CUIRect MainView) int Page = g_Config.m_UiPage; int NewPage = -1; - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); Box.HSplitTop(5.0f, &MainView, &MainView); Box.HSplitTop(24.0f, &Box, &MainView); @@ -920,7 +920,7 @@ void CMenus::DeleteGhostItem(int Index) void CMenus::RenderGhost(CUIRect MainView) { // render background - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.HSplitTop(10.0f, 0, &MainView); MainView.HSplitBottom(5.0f, &MainView, 0); @@ -934,7 +934,7 @@ void CMenus::RenderGhost(CUIRect MainView) View.HSplitBottom(28.0f, &View, &Status); // split of the scrollbar - RenderTools()->DrawUIRect(&Headers, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); + Headers.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); Headers.VSplitRight(20.0f, &Headers, 0); struct CColumn @@ -975,7 +975,7 @@ void CMenus::RenderGhost(CUIRect MainView) for(int i = 0; i < NumCols; i++) DoButton_GridHeader(s_aCols[i].m_Caption, Localize(s_aCols[i].m_Caption), 0, &s_aCols[i].m_Rect); - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.15f), 0, 0); + View.Draw(ColorRGBA(0, 0, 0, 0.15f), 0, 0); CUIRect Scroll; View.VSplitRight(20.0f, &View, &Scroll); @@ -1011,7 +1011,7 @@ void CMenus::RenderGhost(CUIRect MainView) { CUIRect r = Row; r.Margin(1.5f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); + r.Draw(ColorRGBA(1, 1, 1, 0.5f), IGraphics::CORNER_ALL, 4.0f); } if(UI()->DoButtonLogic(pItem, 0, &Row)) @@ -1080,7 +1080,7 @@ void CMenus::RenderGhost(CUIRect MainView) if(NewSelected != -1) s_SelectedIndex = NewSelected; - RenderTools()->DrawUIRect(&Status, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_B, 5.0f); + Status.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_B, 5.0f); Status.Margin(5.0f, &Status); CUIRect Button; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index caba8bb737a..323d32b8da0 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -971,7 +971,7 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View) UIEx()->DoScrollbarOption(&g_Config.m_InpControllerTolerance, &g_Config.m_InpControllerTolerance, &Button, Localize("Controller jitter tolerance"), 0, 50); View.HSplitTop(Spacing, 0, &View); - RenderTools()->DrawUIRect(&View, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); + View.Draw(ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); DoJoystickAxisPicker(View); } else @@ -1014,7 +1014,7 @@ void CMenus::DoJoystickAxisPicker(CUIRect View) View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Row, &View); - RenderTools()->DrawUIRect(&Row, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); + Row.Draw(ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); // Device label Row.VSplitLeft(DeviceLabelWidth, &Button, &Row); @@ -1062,18 +1062,18 @@ void CMenus::DoJoystickBar(const CUIRect *pRect, float Current, float Tolerance, CUIRect Rail; pRect->HMargin(4.0f, &Rail); - RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, Active ? 0.25f : 0.125f), IGraphics::CORNER_ALL, Rail.h / 2.0f); + Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, Active ? 0.25f : 0.125f), IGraphics::CORNER_ALL, Rail.h / 2.0f); CUIRect ToleranceArea = Rail; ToleranceArea.w *= Tolerance; ToleranceArea.x += (Rail.w - ToleranceArea.w) / 2.0f; ColorRGBA ToleranceColor = Active ? ColorRGBA(0.8f, 0.35f, 0.35f, 1.0f) : ColorRGBA(0.7f, 0.5f, 0.5f, 1.0f); - RenderTools()->DrawUIRect(&ToleranceArea, ToleranceColor, IGraphics::CORNER_ALL, ToleranceArea.h / 2.0f); + ToleranceArea.Draw(ToleranceColor, IGraphics::CORNER_ALL, ToleranceArea.h / 2.0f); CUIRect Slider = Handle; Slider.HMargin(4.0f, &Slider); ColorRGBA SliderColor = Active ? ColorRGBA(0.95f, 0.95f, 0.95f, 1.0f) : ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f); - RenderTools()->DrawUIRect(&Slider, SliderColor, IGraphics::CORNER_ALL, Slider.h / 2.0f); + Slider.Draw(SliderColor, IGraphics::CORNER_ALL, Slider.h / 2.0f); } void CMenus::RenderSettingsControls(CUIRect MainView) @@ -1124,7 +1124,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { MouseSettings.VMargin(5.0f, &MouseSettings); MouseSettings.HSplitTop(80.0f, &MouseSettings, &JoystickSettings); - RenderTools()->DrawUIRect(&MouseSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + MouseSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); MouseSettings.VMargin(10.0f, &MouseSettings); TextRender()->Text(0, MouseSettings.x, MouseSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Mouse"), -1.0f); @@ -1145,7 +1145,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { JoystickSettings.HSplitTop(Margin, 0, &JoystickSettings); JoystickSettings.HSplitTop(s_JoystickSettingsHeight, &JoystickSettings, &MovementSettings); - RenderTools()->DrawUIRect(&JoystickSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + JoystickSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); JoystickSettings.VMargin(Margin, &JoystickSettings); TextRender()->Text(0, JoystickSettings.x, JoystickSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Controller"), -1.0f); @@ -1158,7 +1158,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { MovementSettings.HSplitTop(Margin, 0, &MovementSettings); MovementSettings.HSplitTop(365.0f, &MovementSettings, &WeaponSettings); - RenderTools()->DrawUIRect(&MovementSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + MovementSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); MovementSettings.VMargin(Margin, &MovementSettings); TextRender()->Text(0, MovementSettings.x, MovementSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Movement"), -1.0f); @@ -1171,7 +1171,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { WeaponSettings.HSplitTop(Margin, 0, &WeaponSettings); WeaponSettings.HSplitTop(190.0f, &WeaponSettings, &ResetButton); - RenderTools()->DrawUIRect(&WeaponSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + WeaponSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); WeaponSettings.VMargin(Margin, &WeaponSettings); TextRender()->Text(0, WeaponSettings.x, WeaponSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Weapon"), -1.0f); @@ -1184,7 +1184,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { ResetButton.HSplitTop(Margin, 0, &ResetButton); ResetButton.HSplitTop(40.0f, &ResetButton, 0); - RenderTools()->DrawUIRect(&ResetButton, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + ResetButton.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); ResetButton.HMargin(10.0f, &ResetButton); ResetButton.VMargin(30.0f, &ResetButton); ResetButton.HSplitTop(20.0f, &ResetButton, 0); @@ -1211,7 +1211,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { VotingSettings.VMargin(5.0f, &VotingSettings); VotingSettings.HSplitTop(80.0f, &VotingSettings, &ChatSettings); - RenderTools()->DrawUIRect(&VotingSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + VotingSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); VotingSettings.VMargin(Margin, &VotingSettings); TextRender()->Text(0, VotingSettings.x, VotingSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Voting"), -1.0f); @@ -1224,7 +1224,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { ChatSettings.HSplitTop(Margin, 0, &ChatSettings); ChatSettings.HSplitTop(145.0f, &ChatSettings, &DummySettings); - RenderTools()->DrawUIRect(&ChatSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + ChatSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); ChatSettings.VMargin(Margin, &ChatSettings); TextRender()->Text(0, ChatSettings.x, ChatSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Chat"), -1.0f); @@ -1237,7 +1237,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { DummySettings.HSplitTop(Margin, 0, &DummySettings); DummySettings.HSplitTop(100.0f, &DummySettings, &MiscSettings); - RenderTools()->DrawUIRect(&DummySettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + DummySettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); DummySettings.VMargin(Margin, &DummySettings); TextRender()->Text(0, DummySettings.x, DummySettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Dummy"), -1.0f); @@ -1250,7 +1250,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView) { MiscSettings.HSplitTop(Margin, 0, &MiscSettings); MiscSettings.HSplitTop(300.0f, &MiscSettings, 0); - RenderTools()->DrawUIRect(&MiscSettings, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); + MiscSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f); MiscSettings.VMargin(Margin, &MiscSettings); TextRender()->Text(0, MiscSettings.x, MiscSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Miscellaneous"), -1.0f); @@ -1976,11 +1976,11 @@ void CMenus::RenderSettings(CUIRect MainView) // render background CUIRect Temp, TabBar, RestartWarning; MainView.VSplitRight(120.0f, &MainView, &TabBar); - RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); + MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); MainView.HSplitBottom(15.0f, &MainView, &RestartWarning); TabBar.HSplitTop(50.0f, &Temp, &TabBar); - RenderTools()->DrawUIRect(&Temp, ms_ColorTabbarActive, IGraphics::CORNER_BR, 10.0f); + Temp.Draw(ms_ColorTabbarActive, IGraphics::CORNER_BR, 10.0f); MainView.HSplitTop(10.0f, 0, &MainView); @@ -2090,8 +2090,8 @@ ColorHSLA CMenus::RenderHSLColorPicker(const CUIRect *pRect, unsigned int *pColo CUIRect Rect; pRect->Margin(OutlineSize, &Rect); - RenderTools()->DrawUIRect(pRect, Outline, IGraphics::CORNER_ALL, 4.0f); - RenderTools()->DrawUIRect(&Rect, RGBColor, IGraphics::CORNER_ALL, 4.0f); + pRect->Draw(Outline, IGraphics::CORNER_ALL, 4.0f); + Rect.Draw(RGBColor, IGraphics::CORNER_ALL, 4.0f); if(UI()->DoButtonLogic(pColor, 0, pRect)) { @@ -2410,7 +2410,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool Button.VSplitLeft(10.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); - RenderTools()->DrawUIRect(&Button, ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 1.0f); + Button.Draw(ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 1.0f); CUIRect Rail; Button.Margin(2.0f, &Rail); @@ -2644,7 +2644,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section = RightView; Section.Margin(SectionMargin, &Section); - RenderTools()->DrawUIRect(&Section, ColorRGBA(1, 1, 1, 0.1f), IGraphics::CORNER_ALL, 8.0f); + Section.Draw(ColorRGBA(1, 1, 1, 0.1f), IGraphics::CORNER_ALL, 8.0f); Section.HSplitTop(10.0f, 0x0, &Section); // Margin diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index 7d84da18af7..f1f436af781 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -265,9 +265,9 @@ void CMenus::RenderStartMenu(CUIRect MainView) Part.VSplitLeft(100.0f, &ProgressBar, &Percent); ProgressBar.y += 2.0f; ProgressBar.HMargin(1.0f, &ProgressBar); - RenderTools()->DrawUIRect(&ProgressBar, vec4(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 5.0f); + ProgressBar.Draw(vec4(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, 5.0f); ProgressBar.w = clamp((float)Updater()->GetCurrentPercent(), 10.0f, 100.0f); - RenderTools()->DrawUIRect(&ProgressBar, vec4(1.0f, 1.0f, 1.0f, 0.5f), IGraphics::CORNER_ALL, 5.0f); + ProgressBar.Draw(vec4(1.0f, 1.0f, 1.0f, 0.5f), IGraphics::CORNER_ALL, 5.0f); } #elif defined(CONF_INFORM_UPDATE) if(str_comp(Client()->LatestVersion(), "0") != 0) diff --git a/src/game/client/components/tooltips.cpp b/src/game/client/components/tooltips.cpp index 3e4a3caf08c..ff699095245 100644 --- a/src/game/client/components/tooltips.cpp +++ b/src/game/client/components/tooltips.cpp @@ -107,7 +107,7 @@ void CTooltips::OnRender() Rect.y = clamp(UI()->MouseY() - Rect.h / 2.0f, MARGIN, pScreen->h - Rect.h - MARGIN); } - RenderTools()->DrawUIRect(&Rect, ColorRGBA(0.2, 0.2, 0.2, 0.80f), IGraphics::CORNER_ALL, 5.0f); + Rect.Draw(ColorRGBA(0.2, 0.2, 0.2, 0.80f), IGraphics::CORNER_ALL, 5.0f); Rect.Margin(2.0f, &Rect); UI()->DoLabel(&Rect, Tooltip.m_pText, 14.0f, TEXTALIGN_LEFT); Tooltip.m_OnScreen = false; diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index c762922fbcb..aa387aea923 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -304,13 +304,13 @@ void CVoting::OnRender() void CVoting::RenderBars(CUIRect Bars, bool Text) { - RenderTools()->DrawUIRect(&Bars, ColorRGBA(0.8f, 0.8f, 0.8f, 0.5f), IGraphics::CORNER_ALL, Bars.h / 3); + Bars.Draw(ColorRGBA(0.8f, 0.8f, 0.8f, 0.5f), IGraphics::CORNER_ALL, Bars.h / 3); CUIRect Splitter = Bars; Splitter.x = Splitter.x + Splitter.w / 2; Splitter.w = Splitter.h / 2.0f; Splitter.x -= Splitter.w / 2; - RenderTools()->DrawUIRect(&Splitter, ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f), IGraphics::CORNER_ALL, Splitter.h / 4); + Splitter.Draw(ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f), IGraphics::CORNER_ALL, Splitter.h / 4); if(m_Total) { @@ -319,7 +319,7 @@ void CVoting::RenderBars(CUIRect Bars, bool Text) { CUIRect YesArea = Bars; YesArea.w *= m_Yes / (float)m_Total; - RenderTools()->DrawUIRect(&YesArea, ColorRGBA(0.2f, 0.9f, 0.2f, 0.85f), IGraphics::CORNER_ALL, Bars.h / 3); + YesArea.Draw(ColorRGBA(0.2f, 0.9f, 0.2f, 0.85f), IGraphics::CORNER_ALL, Bars.h / 3); if(Text) { @@ -337,7 +337,7 @@ void CVoting::RenderBars(CUIRect Bars, bool Text) CUIRect NoArea = Bars; NoArea.w *= m_No / (float)m_Total; NoArea.x = (Bars.x + Bars.w) - NoArea.w; - RenderTools()->DrawUIRect(&NoArea, ColorRGBA(0.9f, 0.2f, 0.2f, 0.85f), IGraphics::CORNER_ALL, Bars.h / 3); + NoArea.Draw(ColorRGBA(0.9f, 0.2f, 0.2f, 0.85f), IGraphics::CORNER_ALL, Bars.h / 3); if(Text) { diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp index 24759507ae1..371834f73da 100644 --- a/src/game/client/render.cpp +++ b/src/game/client/render.cpp @@ -167,16 +167,6 @@ int CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float X, float return Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1); } -void CRenderTools::DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding) -{ - Graphics()->DrawRect(pRect->x, pRect->y, pRect->w, pRect->h, Color, Corners, Rounding); -} - -void CRenderTools::DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding) -{ - Graphics()->DrawRect4(pRect->x, pRect->y, pRect->w, pRect->h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding); -} - void CRenderTools::GetRenderTeeAnimScaleAndBaseSize(CAnimState *pAnim, CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize) { AnimScale = pInfo->m_Size * 1.0f / 64.0f; diff --git a/src/game/client/render.h b/src/game/client/render.h index 66060cf1efd..fe9dda43b6a 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -103,10 +103,6 @@ class CRenderTools int QuadContainerAddSprite(int QuadContainerIndex, float Width, float Height); int QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height); - // rects - void DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding); - void DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding); - // larger rendering methods void GetRenderTeeBodySize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height); void GetRenderTeeFeetSize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height); diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index d7ce4d4a72e..45b6f53e2ca 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -80,6 +80,7 @@ void CUI::Init(IInput *pInput, IGraphics *pGraphics, ITextRender *pTextRender) m_pInput = pInput; m_pGraphics = pGraphics; m_pTextRender = pTextRender; + CUIRect::Init(m_pGraphics); } CUI::CUI() diff --git a/src/game/client/ui_ex.cpp b/src/game/client/ui_ex.cpp index 2c14f8add1f..64a6d4ac264 100644 --- a/src/game/client/ui_ex.cpp +++ b/src/game/client/ui_ex.cpp @@ -107,7 +107,7 @@ float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) } // render - RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.w / 2.0f); + Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.w / 2.0f); float ColorSlider; if(UI()->CheckActiveItem(pID)) @@ -117,7 +117,7 @@ float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) else ColorSlider = 0.8f; - RenderTools()->DrawUIRect(&Handle, ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.w / 2.0f); + Handle.Draw(ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.w / 2.0f); return ReturnValue; } @@ -192,13 +192,13 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, CUIRect Slider; Handle.VMargin(-2.0f, &Slider); Slider.HMargin(-3.0f, &Slider); - RenderTools()->DrawUIRect(&Slider, ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 5.0f); + Slider.Draw(ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 5.0f); Slider.Margin(2.0f, &Slider); - RenderTools()->DrawUIRect(&Slider, *pColorInner, IGraphics::CORNER_ALL, 3.0f); + Slider.Draw(*pColorInner, IGraphics::CORNER_ALL, 3.0f); } else { - RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.h / 2.0f); + Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.h / 2.0f); float ColorSlider; if(UI()->CheckActiveItem(pID)) @@ -208,7 +208,7 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, else ColorSlider = 0.8f; - RenderTools()->DrawUIRect(&Handle, ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.h / 2.0f); + Handle.Draw(ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.h / 2.0f); } return ReturnValue; @@ -525,7 +525,7 @@ bool CUIEx::DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigne } CUIRect Textbox = *pRect; - RenderTools()->DrawUIRect(&Textbox, ColorRGBA(1, 1, 1, 0.5f), Corners, 3.0f); + Textbox.Draw(ColorRGBA(1, 1, 1, 0.5f), Corners, 3.0f); Textbox.Margin(2.0f, &Textbox); const char *pDisplayStr = pStr; @@ -708,7 +708,7 @@ bool CUIEx::DoClearableEditBox(const void *pID, const void *pClearID, const CUIR bool ReturnValue = DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, pOffset, Hidden, Corners & ~IGraphics::CORNER_R, Properties); 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); - RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~IGraphics::CORNER_L, 3.0f); + ClearButton.Draw(ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~IGraphics::CORNER_L, 3.0f); SLabelProperties Props; Props.m_AlignVertically = 0; diff --git a/src/game/client/ui_rect.cpp b/src/game/client/ui_rect.cpp index 9dd97cb5db3..f9d0eb3aa6f 100644 --- a/src/game/client/ui_rect.cpp +++ b/src/game/client/ui_rect.cpp @@ -2,6 +2,10 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include "ui_rect.h" +#include + +IGraphics *CUIRect::s_pGraphics = nullptr; + void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing) const { CUIRect r = *this; @@ -166,3 +170,13 @@ bool CUIRect::Inside(float PointX, float PointY) const { return PointX >= x && PointX < x + w && PointY >= y && PointY < y + h; } + +void CUIRect::Draw(ColorRGBA Color, int Corners, float Rounding) const +{ + s_pGraphics->DrawRect(x, y, w, h, Color, Corners, Rounding); +} + +void CUIRect::Draw4(ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) const +{ + s_pGraphics->DrawRect4(x, y, w, h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding); +} diff --git a/src/game/client/ui_rect.h b/src/game/client/ui_rect.h index 375247abc71..5fb964e656d 100644 --- a/src/game/client/ui_rect.h +++ b/src/game/client/ui_rect.h @@ -3,9 +3,17 @@ #ifndef GAME_CLIENT_UI_RECT_H #define GAME_CLIENT_UI_RECT_H +#include + +class IGraphics; + class CUIRect { + static IGraphics *s_pGraphics; + public: + static void Init(IGraphics *pGraphics) { s_pGraphics = pGraphics; } + float x, y, w, h; /** @@ -102,6 +110,9 @@ class CUIRect * @return true iff the given point is inside *this* CUIRect. */ bool Inside(float PointX, float PointY) const; + + void Draw(ColorRGBA Color, int Corners, float Rounding) const; + void Draw4(ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) const; }; #endif diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 18b2aa7b905..af0c3d4e40a 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -374,7 +374,7 @@ int CEditor::DoButton_Editor_Common(const void *pID, const char *pText, int Chec int CEditor::DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int AlignVert) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); + pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); CUIRect NewRect = *pRect; SLabelProperties Props; Props.m_AlignVertically = AlignVert; @@ -389,7 +389,7 @@ int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const float Alpha = UI()->HotItem() == pID ? 1.0f : 0.75f; ColorRGBA Color = ColorRGBA(BaseColor.r * Bright, BaseColor.g * Bright, BaseColor.b * Bright, Alpha); - RenderTools()->DrawUIRect(pRect, Color, IGraphics::CORNER_ALL, 3.0f); + pRect->Draw(Color, IGraphics::CORNER_ALL, 3.0f); UI()->DoLabel(pRect, pText, 10.f, TEXTALIGN_CENTER); Checked %= 2; return DoButton_Editor_Common(pID, pText, Checked, pRect, 0, pToolTip); @@ -398,7 +398,7 @@ int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const int CEditor::DoButton_File(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { if(Checked) - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); + pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); CUIRect t = *pRect; t.VMargin(5.0f, &t); @@ -409,7 +409,7 @@ int CEditor::DoButton_File(const void *pID, const char *pText, int Checked, cons int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { CUIRect r = *pRect; - RenderTools()->DrawUIRect(&r, ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f), IGraphics::CORNER_T, 3.0f); + r.Draw(ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f), IGraphics::CORNER_T, 3.0f); r = *pRect; r.VMargin(5.0f, &r); @@ -420,7 +420,7 @@ int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, cons int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { if(UI()->HotItem() == pID || Checked) - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); + pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_ALL, 3.0f); CUIRect t = *pRect; t.VMargin(5.0f, &t); @@ -430,7 +430,7 @@ int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_T, 5.0f); + pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_T, 5.0f); CUIRect NewRect = *pRect; UI()->DoLabel(&NewRect, pText, 10, TEXTALIGN_CENTER); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); @@ -438,7 +438,7 @@ int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize, int AlignVert) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), Corners, 3.0f); + pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f); CUIRect NewRect = *pRect; SLabelProperties Props; Props.m_AlignVertically = AlignVert; @@ -448,21 +448,21 @@ int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const int CEditor::DoButton_ButtonInc(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_R, 3.0f); + pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_R, 3.0f); UI()->DoLabel(pRect, pText ? pText : "+", 10, TEXTALIGN_CENTER); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_ButtonDec(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), IGraphics::CORNER_L, 3.0f); + pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_L, 3.0f); UI()->DoLabel(pRect, pText ? pText : "-", 10, TEXTALIGN_CENTER); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip) { - RenderTools()->DrawUIRect(pRect, *pColor, 0, 0.0f); + pRect->Draw(*pColor, 0, 0.0f); return DoButton_Editor_Common(pID, nullptr, 0, pRect, 0, pToolTip); } @@ -631,7 +631,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in str_format(aBuf, sizeof(aBuf), "#%06X", Current); else str_format(aBuf, sizeof(aBuf), "%d", Current); - RenderTools()->DrawUIRect(pRect, pColor ? *pColor : GetButtonColor(pID, 0), Corners, 5.0f); + pRect->Draw(pColor ? *pColor : GetButtonColor(pID, 0), Corners, 5.0f); UI()->DoLabel(pRect, aBuf, 10, TEXTALIGN_CENTER); } @@ -3153,11 +3153,11 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * Shifter.VSplitMid(&Left, &Up, 2.0f); Left.VSplitLeft(10.0f, &Left, &Shifter); Shifter.VSplitRight(10.0f, &Shifter, &Right); - RenderTools()->DrawUIRect(&Shifter, ColorRGBA(1, 1, 1, 0.5f), 0, 0.0f); + Shifter.Draw(ColorRGBA(1, 1, 1, 0.5f), 0, 0.0f); UI()->DoLabel(&Shifter, "X", 10.0f, TEXTALIGN_CENTER); Up.VSplitLeft(10.0f, &Up, &Shifter); Shifter.VSplitRight(10.0f, &Shifter, &Down); - RenderTools()->DrawUIRect(&Shifter, ColorRGBA(1, 1, 1, 0.5f), 0, 0.0f); + Shifter.Draw(ColorRGBA(1, 1, 1, 0.5f), 0, 0.0f); UI()->DoLabel(&Shifter, "Y", 10.0f, TEXTALIGN_CENTER); if(DoButton_ButtonDec(&pIDs[i], "-", 0, &Left, 0, "Left")) { @@ -3235,7 +3235,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * str_format(aBuf, sizeof(aBuf), "%d", CurValue); float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - RenderTools()->DrawUIRect(&Shifter, Color, 0, 5.0f); + Shifter.Draw(Color, 0, 5.0f); UI()->DoLabel(&Shifter, aBuf, FontSize, TEXTALIGN_CENTER); if(DoButton_ButtonDec((char *)&pIDs[i] + 1, nullptr, 0, &Dec, 0, "Previous Envelope")) @@ -4350,10 +4350,10 @@ void CEditor::RenderFileDialog() CUIRect Preview; float Width = View.w, Height = View.h; - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.25f), 0, 0); + View.Draw(ColorRGBA(0, 0, 0, 0.25f), 0, 0); View.VMargin(150.0f, &View); View.HMargin(50.0f, &View); - RenderTools()->DrawUIRect(&View, ColorRGBA(0, 0, 0, 0.75f), IGraphics::CORNER_ALL, 5.0f); + View.Draw(ColorRGBA(0, 0, 0, 0.75f), IGraphics::CORNER_ALL, 5.0f); View.Margin(10.0f, &View); CUIRect Title, FileBox, FileBoxLabel, ButtonBar, Scroll, PathBox; @@ -4371,7 +4371,7 @@ void CEditor::RenderFileDialog() View.VSplitRight(20.0f, &View, &Scroll); // title - RenderTools()->DrawUIRect(&Title, ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); + Title.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 4.0f); Title.VMargin(10.0f, &Title); UI()->DoLabel(&Title, m_pFileDialogTitle, 12.0f, TEXTALIGN_LEFT); @@ -4418,7 +4418,7 @@ void CEditor::RenderFileDialog() // clearSearchbox button { static int s_ClearButton = 0; - RenderTools()->DrawUIRect(&ClearBox, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(&s_ClearButton)), IGraphics::CORNER_R, 3.0f); + ClearBox.Draw(ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(&s_ClearButton)), IGraphics::CORNER_R, 3.0f); UI()->DoLabel(&ClearBox, "×", 10.0f, TEXTALIGN_CENTER); if(UI()->DoButtonLogic(&s_ClearButton, 0, &ClearBox)) { @@ -4945,7 +4945,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) ColorRGBA(0.7f, 1, 0.7f, 0.5f); } - RenderTools()->DrawUIRect(&Shifter, EnvColor, 0, 0.0f); + Shifter.Draw(EnvColor, 0, 0.0f); UI()->DoLabel(&Shifter, aBuf, 10.0f, TEXTALIGN_CENTER); static int s_PrevButton = 0; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 84159e058a4..22bea04d3b4 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -77,9 +77,9 @@ void CEditor::UiDoPopupMenu() Corners = IGraphics::CORNER_R | IGraphics::CORNER_B; CUIRect r = s_UiPopups[i].m_Rect; - RenderTools()->DrawUIRect(&r, ColorRGBA(0.5f, 0.5f, 0.5f, 0.75f), Corners, 3.0f); + r.Draw(ColorRGBA(0.5f, 0.5f, 0.5f, 0.75f), Corners, 3.0f); r.Margin(1.0f, &r); - RenderTools()->DrawUIRect(&r, ColorRGBA(0, 0, 0, 0.75f), Corners, 3.0f); + r.Draw(ColorRGBA(0, 0, 0, 0.75f), Corners, 3.0f); r.Margin(4.0f, &r); if(s_UiPopups[i].m_pfnFunc(this, r, s_UiPopups[i].m_pContext)) From 51fb3e9a2254f73a5bf9bc38c96c31269cc23d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 7 Aug 2022 22:03:34 +0200 Subject: [PATCH 51/72] Merge `CUIEx` class into `CUI` There is no need to separate the UI in two classes anymore, as the dependency on `CRenderTools` has been removed. --- CMakeLists.txt | 2 - src/game/client/components/menus.cpp | 16 +- src/game/client/components/menus.h | 5 - src/game/client/components/menus_browser.cpp | 16 +- src/game/client/components/menus_demo.cpp | 6 +- src/game/client/components/menus_ingame.cpp | 10 +- src/game/client/components/menus_settings.cpp | 72 +- .../components/menus_settings_assets.cpp | 2 +- src/game/client/gameclient.cpp | 2 +- src/game/client/ui.cpp | 702 ++++++++++++++++- src/game/client/ui.h | 110 ++- src/game/client/ui_ex.cpp | 724 ------------------ src/game/client/ui_ex.h | 128 ---- src/game/editor/editor.cpp | 22 +- src/game/editor/editor.h | 3 - src/game/editor/popups.cpp | 6 +- 16 files changed, 875 insertions(+), 951 deletions(-) delete mode 100644 src/game/client/ui_ex.cpp delete mode 100644 src/game/client/ui_ex.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 39709e37f13..49e2f0e60b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2101,8 +2101,6 @@ if(CLIENT) skin.h ui.cpp ui.h - ui_ex.cpp - ui_ex.h ui_rect.cpp ui_rect.h ) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 9fd884c4e9b..4e28328bdfe 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -476,7 +476,7 @@ int CMenus::DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool if(ms_ValueSelectorTextMode && s_pLastTextpID == pID) { static float s_NumberBoxID = 0; - UIEx()->DoEditBox(&s_NumberBoxID, pRect, s_aNumStr, sizeof(s_aNumStr), 10.0f, &s_NumberBoxID, false, IGraphics::CORNER_ALL); + UI()->DoEditBox(&s_NumberBoxID, pRect, s_aNumStr, sizeof(s_aNumStr), 10.0f, &s_NumberBoxID, false, IGraphics::CORNER_ALL); UI()->SetActiveItem(&s_NumberBoxID); @@ -982,7 +982,7 @@ void CMenus::OnInit() if(g_Config.m_ClSkipStartMenu) m_ShowStart = false; - UIEx()->Init(UI(), Kernel(), RenderTools(), m_aInputEvents, &m_NumInputEvents); + UI()->InitInputs(m_aInputEvents, &m_NumInputEvents); m_RefreshButton.Init(UI(), -1); m_ConnectButton.Init(UI(), -1); @@ -1272,7 +1272,7 @@ int CMenus::Render() CUIRect Screen = *UI()->Screen(); UI()->MapScreen(); - UIEx()->ResetMouseSlow(); + UI()->ResetMouseSlow(); static int s_Frame = 0; if(s_Frame == 0) @@ -1763,7 +1763,7 @@ int CMenus::Render() TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Password"), 18.0f, TEXTALIGN_LEFT); static float s_Offset = 0.0f; - UIEx()->DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &s_Offset, true); + UI()->DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &s_Offset, true); } else if(m_Popup == POPUP_CONNECTING) { @@ -1990,7 +1990,7 @@ int CMenus::Render() TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("New name:"), 18.0f, TEXTALIGN_LEFT); static float s_Offset = 0.0f; - UIEx()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset); + UI()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset); } #if defined(CONF_VIDEORECORDER) else if(m_Popup == POPUP_RENDER_DEMO) @@ -2113,7 +2113,7 @@ int CMenus::Render() TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Video name:"), 18.0f, TEXTALIGN_LEFT); static float s_Offset = 0.0f; - UIEx()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset); + UI()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset); } else if(m_Popup == POPUP_REPLACE_VIDEO) { @@ -2227,7 +2227,7 @@ int CMenus::Render() static float s_Offset = 0.0f; SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = Client()->PlayerName(); - UIEx()->DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps); + UI()->DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps); } else if(m_Popup == POPUP_POINTS) { @@ -2428,7 +2428,7 @@ bool CMenus::OnCursorMove(float x, float y, IInput::ECursorType CursorType) if(!m_MenuActive) return false; - UIEx()->ConvertMouseMove(&x, &y, CursorType); + UI()->ConvertMouseMove(&x, &y, CursorType); m_MousePos.x = clamp(m_MousePos.x + x, 0.f, (float)Graphics()->WindowWidth()); m_MousePos.y = clamp(m_MousePos.y + y, 0.f, (float)Graphics()->WindowHeight()); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 02138b125db..a3476aae4af 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -78,10 +77,6 @@ class CMenus : public CComponent char m_aLocalStringHelper[1024]; - CUIEx m_UIEx; - - CUIEx *UIEx() { return &m_UIEx; } - int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect); int DoButton_Sprite(CButtonContainer *pButtonContainer, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners); int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active); diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 09ec8142f6b..8c85802ae6b 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -186,7 +186,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) static float s_ScrollValue = 0; - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(Input()->KeyPress(KEY_TAB) && m_pClient->m_GameConsole.IsClosed()) { @@ -549,7 +549,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } static int s_ClearButton = 0; static float s_Offset = 0.0f; - if(UIEx()->DoClearableEditBox(&g_Config.m_BrFilterString, &s_ClearButton, &QuickSearch, g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps)) + if(UI()->DoClearableEditBox(&g_Config.m_BrFilterString, &s_ClearButton, &QuickSearch, g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps)) Client()->ServerBrowserUpdate(); } @@ -576,7 +576,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) static float s_Offset = 0.0f; if(Input()->KeyPress(KEY_X) && (Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) && Input()->ModifierIsPressed()) UI()->SetActiveItem(&g_Config.m_BrExcludeString); - if(UIEx()->DoClearableEditBox(&g_Config.m_BrExcludeString, &s_ClearButton, &QuickExclude, g_Config.m_BrExcludeString, sizeof(g_Config.m_BrExcludeString), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL)) + if(UI()->DoClearableEditBox(&g_Config.m_BrExcludeString, &s_ClearButton, &QuickExclude, g_Config.m_BrExcludeString, sizeof(g_Config.m_BrExcludeString), 12.0f, &s_Offset, false, IGraphics::CORNER_ALL)) Client()->ServerBrowserUpdate(); } @@ -610,7 +610,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) ServerAddr.VSplitLeft(SearchExcludeAddrStrMax + 5.0f + ExcludeSearchIconMax + 5.0f, NULL, &ServerAddr); static int s_ClearButton = 0; static float s_Offset = 0.0f; - UIEx()->DoClearableEditBox(&g_Config.m_UiServerAddress, &s_ClearButton, &ServerAddr, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 12.0f, &s_Offset); + UI()->DoClearableEditBox(&g_Config.m_UiServerAddress, &s_ClearButton, &ServerAddr, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 12.0f, &s_Offset); // button area ButtonArea = ConnectButtons; @@ -721,7 +721,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) Button.VSplitRight(60.0f, 0, &Button); ServerFilter.HSplitTop(3.0f, 0, &ServerFilter); static float s_OffsetGametype = 0.0f; - if(UIEx()->DoEditBox(&g_Config.m_BrFilterGametype, &Button, g_Config.m_BrFilterGametype, sizeof(g_Config.m_BrFilterGametype), FontSize, &s_OffsetGametype)) + if(UI()->DoEditBox(&g_Config.m_BrFilterGametype, &Button, g_Config.m_BrFilterGametype, sizeof(g_Config.m_BrFilterGametype), FontSize, &s_OffsetGametype)) Client()->ServerBrowserUpdate(); // server address @@ -730,7 +730,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) UI()->DoLabel(&Button, Localize("Server address:"), FontSize, TEXTALIGN_LEFT); Button.VSplitRight(60.0f, 0, &Button); static float s_OffsetAddr = 0.0f; - if(UIEx()->DoEditBox(&g_Config.m_BrFilterServerAddress, &Button, g_Config.m_BrFilterServerAddress, sizeof(g_Config.m_BrFilterServerAddress), FontSize, &s_OffsetAddr)) + if(UI()->DoEditBox(&g_Config.m_BrFilterServerAddress, &Button, g_Config.m_BrFilterServerAddress, sizeof(g_Config.m_BrFilterServerAddress), FontSize, &s_OffsetAddr)) Client()->ServerBrowserUpdate(); // player country @@ -1358,7 +1358,7 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) Button.VSplitLeft(80.0f, 0, &Button); static char s_aName[MAX_NAME_LENGTH] = {0}; static float s_OffsetName = 0.0f; - UIEx()->DoEditBox(&s_aName, &Button, s_aName, sizeof(s_aName), FontSize + 2, &s_OffsetName); + UI()->DoEditBox(&s_aName, &Button, s_aName, sizeof(s_aName), FontSize + 2, &s_OffsetName); ServerFriends.HSplitTop(3.0f, 0, &ServerFriends); ServerFriends.HSplitTop(19.0f, &Button, &ServerFriends); @@ -1367,7 +1367,7 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) Button.VSplitLeft(80.0f, 0, &Button); static char s_aClan[MAX_CLAN_LENGTH] = {0}; static float s_OffsetClan = 0.0f; - UIEx()->DoEditBox(&s_aClan, &Button, s_aClan, sizeof(s_aClan), FontSize + 2, &s_OffsetClan); + UI()->DoEditBox(&s_aClan, &Button, s_aClan, sizeof(s_aClan), FontSize + 2, &s_OffsetClan); ServerFriends.HSplitTop(3.0f, 0, &ServerFriends); ServerFriends.HSplitTop(20.0f, &Button, &ServerFriends); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index c7055b71bd4..69410fc553b 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -160,7 +160,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("New name:"), 18.0f, TEXTALIGN_LEFT); static float s_Offset = 0.0f; - if(UIEx()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset)) + if(UI()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset)) { m_aDemoPlayerPopupHint[0] = '\0'; } @@ -563,7 +563,7 @@ void CMenus::UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHe if(Num == 0) gs_ListBoxScrollValue = 0; else - gs_ListBoxScrollValue = UIEx()->DoScrollbarV(pID, &Scroll, gs_ListBoxScrollValue); + gs_ListBoxScrollValue = UI()->DoScrollbarV(pID, &Scroll, gs_ListBoxScrollValue); // the list gs_ListBoxView = gs_ListBoxOriginalView; @@ -1078,7 +1078,7 @@ void CMenus::RenderDemoList(CUIRect MainView) ListBox.VSplitRight(20.0f, &ListBox, &Scroll); static float s_ScrollValue = 0; - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); int PreviousIndex = m_DemolistSelectedIndex; HandleListInputs(ListBox, s_ScrollValue, 3.0f, &m_ScrollOffset, s_aCols[0].m_Rect.h, m_DemolistSelectedIndex, m_vDemos.size()); diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 2ebb0378a77..8c20c73bc42 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -633,7 +633,7 @@ void CMenus::RenderServerControl(CUIRect MainView) EditProps.m_SelectText = true; } EditProps.m_pEmptyText = Localize("Search"); - UIEx()->DoClearableEditBox(&m_aFilterString, &s_ClearButton, &QuickSearch, m_aFilterString, sizeof(m_aFilterString), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps); + UI()->DoClearableEditBox(&m_aFilterString, &s_ClearButton, &QuickSearch, m_aFilterString, sizeof(m_aFilterString), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps); } Bottom.VSplitRight(120.0f, &Bottom, &Button); @@ -680,7 +680,7 @@ void CMenus::RenderServerControl(CUIRect MainView) static float s_Offset = 0.0f; if(Input()->KeyPress(KEY_R) && Input()->ModifierIsPressed()) UI()->SetActiveItem(&m_aCallvoteReason); - UIEx()->DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL); + UI()->DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL); // extended features (only available when authed in rcon) if(Client()->RconAuthed()) @@ -751,11 +751,11 @@ void CMenus::RenderServerControl(CUIRect MainView) Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(250.0f, &Button, &Bottom); static float s_OffsetDesc = 0.0f; - UIEx()->DoEditBox(&s_aVoteDescription, &Button, s_aVoteDescription, sizeof(s_aVoteDescription), 14.0f, &s_OffsetDesc, false, IGraphics::CORNER_ALL); + UI()->DoEditBox(&s_aVoteDescription, &Button, s_aVoteDescription, sizeof(s_aVoteDescription), 14.0f, &s_OffsetDesc, false, IGraphics::CORNER_ALL); Bottom.VMargin(20.0f, &Button); static float s_OffsetCmd = 0.0f; - UIEx()->DoEditBox(&s_aVoteCommand, &Button, s_aVoteCommand, sizeof(s_aVoteCommand), 14.0f, &s_OffsetCmd, false, IGraphics::CORNER_ALL); + UI()->DoEditBox(&s_aVoteCommand, &Button, s_aVoteCommand, sizeof(s_aVoteCommand), 14.0f, &s_OffsetCmd, false, IGraphics::CORNER_ALL); } } } @@ -981,7 +981,7 @@ void CMenus::RenderGhost(CUIRect MainView) View.VSplitRight(20.0f, &View, &Scroll); static float s_ScrollValue = 0; - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); int NumGhosts = m_vGhosts.size(); static int s_SelectedIndex = 0; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 323d32b8da0..e9649071835 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -163,7 +163,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Max demos"), "∞"); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); Right.HSplitTop(20.0f, &Button, &Right); - g_Config.m_ClAutoDemoMax = static_cast(UIEx()->DoScrollbarH(&g_Config.m_ClAutoDemoMax, &Button, g_Config.m_ClAutoDemoMax / 1000.0f) * 1000.0f + 0.1f); + g_Config.m_ClAutoDemoMax = static_cast(UI()->DoScrollbarH(&g_Config.m_ClAutoDemoMax, &Button, g_Config.m_ClAutoDemoMax / 1000.0f) * 1000.0f + 0.1f); Right.HSplitTop(SliderGroupMargin, 0, &Right); Right.HSplitTop(20.0f, &Button, &Right); @@ -177,7 +177,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Max Screenshots"), "∞"); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); Right.HSplitTop(20.0f, &Button, &Right); - g_Config.m_ClAutoScreenshotMax = static_cast(UIEx()->DoScrollbarH(&g_Config.m_ClAutoScreenshotMax, &Button, g_Config.m_ClAutoScreenshotMax / 1000.0f) * 1000.0f + 0.1f); + g_Config.m_ClAutoScreenshotMax = static_cast(UI()->DoScrollbarH(&g_Config.m_ClAutoScreenshotMax, &Button, g_Config.m_ClAutoScreenshotMax / 1000.0f) * 1000.0f + 0.1f); } Left.HSplitTop(10.0f, 0, &Left); @@ -188,7 +188,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Refresh Rate"), "∞"); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); Left.HSplitTop(20.0f, &Button, &Left); - g_Config.m_ClRefreshRate = static_cast(UIEx()->DoScrollbarH(&g_Config.m_ClRefreshRate, &Button, g_Config.m_ClRefreshRate / 10000.0f) * 10000.0f + 0.1f); + g_Config.m_ClRefreshRate = static_cast(UI()->DoScrollbarH(&g_Config.m_ClRefreshRate, &Button, g_Config.m_ClRefreshRate / 10000.0f) * 10000.0f + 0.1f); Left.HSplitTop(15.0f, 0, &Left); CUIRect SettingsButton; @@ -256,7 +256,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); Right.HSplitTop(20.0f, &Button, &Right); g_Config.m_ClAutoStatboardScreenshotMax = - static_cast(UIEx()->DoScrollbarH(&g_Config.m_ClAutoStatboardScreenshotMax, + static_cast(UI()->DoScrollbarH(&g_Config.m_ClAutoStatboardScreenshotMax, &Button, g_Config.m_ClAutoStatboardScreenshotMax / 1000.0f) * 1000.0f + @@ -282,7 +282,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); Right.HSplitTop(20.0f, &Button, &Right); g_Config.m_ClAutoCSVMax = - static_cast(UIEx()->DoScrollbarH(&g_Config.m_ClAutoCSVMax, + static_cast(UI()->DoScrollbarH(&g_Config.m_ClAutoCSVMax, &Button, g_Config.m_ClAutoCSVMax / 1000.0f) * 1000.0f + @@ -327,7 +327,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) static float s_OffsetName = 0.0f; SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = pNameFallback; - if(UIEx()->DoEditBox(pName, &Button, pName, sizeof(g_Config.m_PlayerName), 14.0f, &s_OffsetName, false, IGraphics::CORNER_ALL, EditProps)) + if(UI()->DoEditBox(pName, &Button, pName, sizeof(g_Config.m_PlayerName), 14.0f, &s_OffsetName, false, IGraphics::CORNER_ALL, EditProps)) { SetNeedSendInfo(); } @@ -341,7 +341,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) str_format(aBuf, sizeof(aBuf), "%s:", Localize("Clan")); UI()->DoLabel(&Label, aBuf, 14.0f, TEXTALIGN_LEFT); static float s_OffsetClan = 0.0f; - if(UIEx()->DoEditBox(pClan, &Button, pClan, sizeof(g_Config.m_PlayerClan), 14.0f, &s_OffsetClan)) + if(UI()->DoEditBox(pClan, &Button, pClan, sizeof(g_Config.m_PlayerClan), 14.0f, &s_OffsetClan)) { SetNeedSendInfo(); } @@ -501,7 +501,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) { static int s_ClearButton = 0; static float s_Offset = 0.0f; - UIEx()->DoClearableEditBox(g_Config.m_ClSkinPrefix, &s_ClearButton, &SkinPrefixLabel, g_Config.m_ClSkinPrefix, sizeof(g_Config.m_ClSkinPrefix), 14.0f, &s_Offset); + UI()->DoClearableEditBox(g_Config.m_ClSkinPrefix, &s_ClearButton, &SkinPrefixLabel, g_Config.m_ClSkinPrefix, sizeof(g_Config.m_ClSkinPrefix), 14.0f, &s_Offset); } SkinPrefix.HSplitTop(2.0f, 0, &SkinPrefix); @@ -587,7 +587,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) static int s_ClearButton = 0; SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = "default"; - if(UIEx()->DoClearableEditBox(pSkinName, &s_ClearButton, &Label, pSkinName, sizeof(g_Config.m_ClPlayerSkin), 14.0f, &s_OffsetSkin, false, IGraphics::CORNER_ALL, EditProps)) + if(UI()->DoClearableEditBox(pSkinName, &s_ClearButton, &Label, pSkinName, sizeof(g_Config.m_ClPlayerSkin), 14.0f, &s_OffsetSkin, false, IGraphics::CORNER_ALL, EditProps)) { SetNeedSendInfo(); } @@ -740,7 +740,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) EditPropsSearch.m_SelectText = true; } EditPropsSearch.m_pEmptyText = Localize("Search"); - if(UIEx()->DoClearableEditBox(&g_Config.m_ClSkinFilterString, &s_ClearButtonSearch, &QuickSearch, g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditPropsSearch)) + if(UI()->DoClearableEditBox(&g_Config.m_ClSkinFilterString, &s_ClearButtonSearch, &QuickSearch, g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditPropsSearch)) s_InitSkinlist = true; } @@ -952,23 +952,23 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View) View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Button, &View); const char *apLabels[] = {Localize("Relative", "Ingame controller mode"), Localize("Absolute", "Ingame controller mode")}; - UIEx()->DoScrollbarOptionLabeled(&g_Config.m_InpControllerAbsolute, &g_Config.m_InpControllerAbsolute, &Button, Localize("Ingame controller mode"), apLabels, std::size(apLabels)); + UI()->DoScrollbarOptionLabeled(&g_Config.m_InpControllerAbsolute, &g_Config.m_InpControllerAbsolute, &Button, Localize("Ingame controller mode"), apLabels, std::size(apLabels)); } if(!g_Config.m_InpControllerAbsolute) { View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Button, &View); - UIEx()->DoScrollbarOption(&g_Config.m_InpControllerSens, &g_Config.m_InpControllerSens, &Button, Localize("Ingame controller sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE); + UI()->DoScrollbarOption(&g_Config.m_InpControllerSens, &g_Config.m_InpControllerSens, &Button, Localize("Ingame controller sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_OPTION_NOCLAMPVALUE); } View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Button, &View); - UIEx()->DoScrollbarOption(&g_Config.m_UiControllerSens, &g_Config.m_UiControllerSens, &Button, Localize("UI controller sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE); + UI()->DoScrollbarOption(&g_Config.m_UiControllerSens, &g_Config.m_UiControllerSens, &Button, Localize("UI controller sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_OPTION_NOCLAMPVALUE); View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Button, &View); - UIEx()->DoScrollbarOption(&g_Config.m_InpControllerTolerance, &g_Config.m_InpControllerTolerance, &Button, Localize("Controller jitter tolerance"), 0, 50); + UI()->DoScrollbarOption(&g_Config.m_InpControllerTolerance, &g_Config.m_InpControllerTolerance, &Button, Localize("Controller jitter tolerance"), 0, 50); View.HSplitTop(Spacing, 0, &View); View.Draw(ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), IGraphics::CORNER_ALL, 5.0f); @@ -1133,12 +1133,12 @@ void CMenus::RenderSettingsControls(CUIRect MainView) CUIRect Button; MouseSettings.HSplitTop(20.0f, &Button, &MouseSettings); - UIEx()->DoScrollbarOption(&g_Config.m_InpMousesens, &g_Config.m_InpMousesens, &Button, Localize("Ingame mouse sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE); + UI()->DoScrollbarOption(&g_Config.m_InpMousesens, &g_Config.m_InpMousesens, &Button, Localize("Ingame mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_OPTION_NOCLAMPVALUE); MouseSettings.HSplitTop(2.0f, 0, &MouseSettings); MouseSettings.HSplitTop(20.0f, &Button, &MouseSettings); - UIEx()->DoScrollbarOption(&g_Config.m_UiMousesens, &g_Config.m_UiMousesens, &Button, Localize("UI mouse sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE); + UI()->DoScrollbarOption(&g_Config.m_UiMousesens, &g_Config.m_UiMousesens, &Button, Localize("UI mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_OPTION_NOCLAMPVALUE); } // joystick settings @@ -1507,7 +1507,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) else str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Refresh Rate"), "∞"); UI()->DoLabel(&Label, aBuf, 14.0f, TEXTALIGN_LEFT); - int NewRefreshRate = static_cast(UIEx()->DoScrollbarH(&g_Config.m_GfxRefreshRate, &Button, (minimum(g_Config.m_GfxRefreshRate, 1000)) / 1000.0f) * 1000.0f + 0.1f); + int NewRefreshRate = static_cast(UI()->DoScrollbarH(&g_Config.m_GfxRefreshRate, &Button, (minimum(g_Config.m_GfxRefreshRate, 1000)) / 1000.0f) * 1000.0f + 0.1f); if(g_Config.m_GfxRefreshRate <= 1000 || NewRefreshRate < 1000) g_Config.m_GfxRefreshRate = NewRefreshRate; @@ -1796,7 +1796,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) UI()->DoLabel(&Button, Localize("Sample rate"), 14.0f, TEXTALIGN_LEFT); Button.VSplitLeft(190.0f, 0, &Button); static float s_Offset = 0.0f; - UIEx()->DoEditBox(&g_Config.m_SndRate, &Button, aBuf, sizeof(aBuf), 14.0f, &s_Offset); + UI()->DoEditBox(&g_Config.m_SndRate, &Button, aBuf, sizeof(aBuf), 14.0f, &s_Offset); g_Config.m_SndRate = maximum(1, str_toint(aBuf)); m_NeedRestartSound = !s_SndEnable || s_SndRate != g_Config.m_SndRate; } @@ -1807,7 +1807,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(190.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Sound volume"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_SndVolume = (int)(UIEx()->DoScrollbarH(&g_Config.m_SndVolume, &Button, g_Config.m_SndVolume / 100.0f) * 100.0f); + g_Config.m_SndVolume = (int)(UI()->DoScrollbarH(&g_Config.m_SndVolume, &Button, g_Config.m_SndVolume / 100.0f) * 100.0f); } // volume slider game sounds @@ -1816,7 +1816,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(190.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Game sound volume"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_SndGameSoundVolume = (int)(UIEx()->DoScrollbarH(&g_Config.m_SndGameSoundVolume, &Button, g_Config.m_SndGameSoundVolume / 100.0f) * 100.0f); + g_Config.m_SndGameSoundVolume = (int)(UI()->DoScrollbarH(&g_Config.m_SndGameSoundVolume, &Button, g_Config.m_SndGameSoundVolume / 100.0f) * 100.0f); } // volume slider gui sounds @@ -1825,7 +1825,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(190.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Chat sound volume"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_SndChatSoundVolume = (int)(UIEx()->DoScrollbarH(&g_Config.m_SndChatSoundVolume, &Button, g_Config.m_SndChatSoundVolume / 100.0f) * 100.0f); + g_Config.m_SndChatSoundVolume = (int)(UI()->DoScrollbarH(&g_Config.m_SndChatSoundVolume, &Button, g_Config.m_SndChatSoundVolume / 100.0f) * 100.0f); } // volume slider map sounds @@ -1834,7 +1834,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(190.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Map sound volume"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_SndMapSoundVolume = (int)(UIEx()->DoScrollbarH(&g_Config.m_SndMapSoundVolume, &Button, g_Config.m_SndMapSoundVolume / 100.0f) * 100.0f); + g_Config.m_SndMapSoundVolume = (int)(UI()->DoScrollbarH(&g_Config.m_SndMapSoundVolume, &Button, g_Config.m_SndMapSoundVolume / 100.0f) * 100.0f); } // volume slider background music @@ -1843,7 +1843,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(190.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Background music volume"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_SndBackgroundMusicVolume = (int)(UIEx()->DoScrollbarH(&g_Config.m_SndBackgroundMusicVolume, &Button, g_Config.m_SndBackgroundMusicVolume / 100.0f) * 100.0f); + g_Config.m_SndBackgroundMusicVolume = (int)(UI()->DoScrollbarH(&g_Config.m_SndBackgroundMusicVolume, &Button, g_Config.m_SndBackgroundMusicVolume / 100.0f) * 100.0f); } } @@ -2451,7 +2451,7 @@ ColorHSLA CMenus::RenderHSLScrollbars(CUIRect *pRect, unsigned int *pColor, bool ColorInner = color_cast(ColorHSLA(CurColorPureHSLA.r, *apComponent[1], LightVal, *apComponent[3])); } - *apComponent[i] = UIEx()->DoScrollbarH(&((char *)pColor)[i], &Button, *apComponent[i], &ColorInner); + *apComponent[i] = UI()->DoScrollbarH(&((char *)pColor)[i], &Button, *apComponent[i], &ColorInner); } *pColor = Color.Pack(Alpha); @@ -2589,7 +2589,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section.HSplitTop(LineSize, &Button, &Section); str_format(aBuf, sizeof(aBuf), "%s: %i%%", Localize("Opacity of freeze bars inside freeze"), g_Config.m_ClFreezeBarsAlphaInsideFreeze); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); - g_Config.m_ClFreezeBarsAlphaInsideFreeze = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClFreezeBarsAlphaInsideFreeze, &Button, g_Config.m_ClFreezeBarsAlphaInsideFreeze / 100.0f) * 100.0f); + g_Config.m_ClFreezeBarsAlphaInsideFreeze = (int)(UI()->DoScrollbarH(&g_Config.m_ClFreezeBarsAlphaInsideFreeze, &Button, g_Config.m_ClFreezeBarsAlphaInsideFreeze / 100.0f) * 100.0f); } else { @@ -2833,7 +2833,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section.HSplitTop(LineSize, &Button, &Section); str_format(aBuf, sizeof(aBuf), "%s: %i", Localize("Name plates size"), g_Config.m_ClNameplatesSize); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); - g_Config.m_ClNameplatesSize = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClNameplatesSize, &Button, g_Config.m_ClNameplatesSize / 100.0f) * 100.0f + 0.1f); + g_Config.m_ClNameplatesSize = (int)(UI()->DoScrollbarH(&g_Config.m_ClNameplatesSize, &Button, g_Config.m_ClNameplatesSize / 100.0f) * 100.0f + 0.1f); } DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClNameplatesClan, Localize("Show clan above name plates"), &g_Config.m_ClNameplatesClan, &Section, LineSize); @@ -2843,7 +2843,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section.HSplitTop(LineSize, &Button, &Section); str_format(aBuf, sizeof(aBuf), "%s: %i", Localize("Clan plates size"), g_Config.m_ClNameplatesClanSize); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); - g_Config.m_ClNameplatesClanSize = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClNameplatesClanSize, &Button, g_Config.m_ClNameplatesClanSize / 100.0f) * 100.0f + 0.1f); + g_Config.m_ClNameplatesClanSize = (int)(UI()->DoScrollbarH(&g_Config.m_ClNameplatesClanSize, &Button, g_Config.m_ClNameplatesClanSize / 100.0f) * 100.0f + 0.1f); } else { @@ -2889,7 +2889,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section.HSplitTop(LineSize, &Button, &Section); str_format(aBuf, sizeof(aBuf), "%s: %i", Localize("Hook collision line width"), g_Config.m_ClHookCollSize); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); - g_Config.m_ClHookCollSize = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClHookCollSize, &Button, g_Config.m_ClHookCollSize / 20.0f) * 20.0f); + g_Config.m_ClHookCollSize = (int)(UI()->DoScrollbarH(&g_Config.m_ClHookCollSize, &Button, g_Config.m_ClHookCollSize / 20.0f) * 20.0f); } { @@ -2897,7 +2897,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Section.HSplitTop(LineSize, &Button, &Section); str_format(aBuf, sizeof(aBuf), "%s: %i%%", Localize("Hook collision line opacity"), g_Config.m_ClHookCollAlpha); UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_LEFT); - g_Config.m_ClHookCollAlpha = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClHookCollAlpha, &Button, g_Config.m_ClHookCollAlpha / 100.0f) * 100.0f); + g_Config.m_ClHookCollAlpha = (int)(UI()->DoScrollbarH(&g_Config.m_ClHookCollAlpha, &Button, g_Config.m_ClHookCollAlpha / 100.0f) * 100.0f); } static CButtonContainer s_HookCollNoCollResetID, s_HookCollHookableCollResetID, s_HookCollTeeCollResetID; @@ -3001,7 +3001,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) str_format(aBuf, sizeof(aBuf), Localize("Default length: %d"), g_Config.m_ClReplayLength); UI()->DoLabel(&Label, aBuf, 14.0f, TEXTALIGN_LEFT); - int NewValue = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClReplayLength, &Button, (minimum(g_Config.m_ClReplayLength, 600) - 10) / 590.0f) * 590.0f) + 10; + int NewValue = (int)(UI()->DoScrollbarH(&g_Config.m_ClReplayLength, &Button, (minimum(g_Config.m_ClReplayLength, 600) - 10) / 590.0f) * 590.0f) + 10; if(g_Config.m_ClReplayLength < 600 || NewValue < 600) g_Config.m_ClReplayLength = minimum(NewValue, 600); } @@ -3041,7 +3041,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(120.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Overlay entities"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_ClOverlayEntities = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClOverlayEntities, &Button, g_Config.m_ClOverlayEntities / 100.0f) * 100.0f); + g_Config.m_ClOverlayEntities = (int)(UI()->DoScrollbarH(&g_Config.m_ClOverlayEntities, &Button, g_Config.m_ClOverlayEntities / 100.0f) * 100.0f); } { @@ -3050,7 +3050,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) Button.VSplitLeft(50.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Size"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_ClTextEntitiesSize = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClTextEntitiesSize, &Button, g_Config.m_ClTextEntitiesSize / 100.0f) * 100.0f); + g_Config.m_ClTextEntitiesSize = (int)(UI()->DoScrollbarH(&g_Config.m_ClTextEntitiesSize, &Button, g_Config.m_ClTextEntitiesSize / 100.0f) * 100.0f); if(DoButton_CheckBox(&g_Config.m_ClTextEntities, Localize("Show text entities"), g_Config.m_ClTextEntities, &LeftLeft)) { @@ -3064,7 +3064,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) Button.VSplitLeft(50.0f, &Label, &Button); UI()->DoLabel(&Label, Localize("Opacity"), 14.0f, TEXTALIGN_LEFT); - g_Config.m_ClShowOthersAlpha = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClShowOthersAlpha, &Button, g_Config.m_ClShowOthersAlpha / 100.0f) * 100.0f); + g_Config.m_ClShowOthersAlpha = (int)(UI()->DoScrollbarH(&g_Config.m_ClShowOthersAlpha, &Button, g_Config.m_ClShowOthersAlpha / 100.0f) * 100.0f); if(DoButton_CheckBox(&g_Config.m_ClShowOthers, Localize("Show others"), g_Config.m_ClShowOthers == SHOW_OTHERS_ON, &LeftLeft)) { @@ -3093,7 +3093,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) char aBuf[256]; str_format(aBuf, sizeof(aBuf), "%s: %i", Localize("Default zoom"), g_Config.m_ClDefaultZoom); UI()->DoLabel(&Label, aBuf, 14.0f, TEXTALIGN_LEFT); - g_Config.m_ClDefaultZoom = static_cast(UIEx()->DoScrollbarH(&g_Config.m_ClDefaultZoom, &Button, g_Config.m_ClDefaultZoom / 20.0f) * 20.0f + 0.1f); + g_Config.m_ClDefaultZoom = static_cast(UI()->DoScrollbarH(&g_Config.m_ClDefaultZoom, &Button, g_Config.m_ClDefaultZoom / 20.0f) * 20.0f + 0.1f); Right.HSplitTop(20.0f, &Button, &Right); if(DoButton_CheckBox(&g_Config.m_ClAntiPing, Localize("AntiPing"), g_Config.m_ClAntiPing, &Button)) @@ -3164,7 +3164,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) Background.VSplitLeft(100.0f, &Label, &TempLabel); UI()->DoLabel(&Label, Localize("Map"), 14.0f, TEXTALIGN_LEFT); static float s_Map = 0.0f; - UIEx()->DoEditBox(g_Config.m_ClBackgroundEntities, &TempLabel, g_Config.m_ClBackgroundEntities, sizeof(g_Config.m_ClBackgroundEntities), 14.0f, &s_Map); + UI()->DoEditBox(g_Config.m_ClBackgroundEntities, &TempLabel, g_Config.m_ClBackgroundEntities, sizeof(g_Config.m_ClBackgroundEntities), 14.0f, &s_Map); Left.HSplitTop(20.0f, &Button, &Left); bool UseCurrentMap = str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0; @@ -3206,7 +3206,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) Button.VSplitLeft(5.0f, 0, &Button); SUIExEditBoxProperties EditProps; EditProps.m_pEmptyText = Localize("Chat command (e.g. showall 1)"); - UIEx()->DoEditBox(g_Config.m_ClRunOnJoin, &Button, g_Config.m_ClRunOnJoin, sizeof(g_Config.m_ClRunOnJoin), 14.0f, &s_RunOnJoin, false, IGraphics::CORNER_ALL, EditProps); + UI()->DoEditBox(g_Config.m_ClRunOnJoin, &Button, g_Config.m_ClRunOnJoin, sizeof(g_Config.m_ClRunOnJoin), 14.0f, &s_RunOnJoin, false, IGraphics::CORNER_ALL, EditProps); // Updater #if defined(CONF_AUTOUPDATE) { diff --git a/src/game/client/components/menus_settings_assets.cpp b/src/game/client/components/menus_settings_assets.cpp index 86b66609693..472b781e6da 100644 --- a/src/game/client/components/menus_settings_assets.cpp +++ b/src/game/client/components/menus_settings_assets.cpp @@ -659,7 +659,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView) EditProps.m_SelectText = true; } EditProps.m_pEmptyText = Localize("Search"); - if(UIEx()->DoClearableEditBox(&s_aFilterString[s_CurCustomTab], &s_ClearButton, &QuickSearch, s_aFilterString[s_CurCustomTab], sizeof(s_aFilterString[0]), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps)) + if(UI()->DoClearableEditBox(&s_aFilterString[s_CurCustomTab], &s_ClearButton, &QuickSearch, s_aFilterString[s_CurCustomTab], sizeof(s_aFilterString[0]), 14.0f, &s_Offset, false, IGraphics::CORNER_ALL, EditProps)) gs_aInitCustomList[s_CurCustomTab] = true; } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index a0098ba8514..0a93d6b0d20 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -228,7 +228,7 @@ void CGameClient::OnInit() m_pGraphics->AddWindowResizeListener(OnWindowResizeCB, this); // propagate pointers - m_UI.Init(Input(), Graphics(), TextRender()); + m_UI.Init(Kernel()); m_RenderTools.Init(Graphics(), TextRender()); int64_t Start = time_get(); diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 45b6f53e2ca..5b72d97f748 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -3,11 +3,15 @@ #include "ui.h" #include +#include + #include #include #include #include +#include + #include void CUIElement::Init(CUI *pUI, int RequestedRectCount) @@ -73,16 +77,25 @@ void CUIElement::SUIElementRect::Draw(const CUIRect *pRect, ColorRGBA Color, int UI *********************************************************/ +const CLinearScrollbarScale CUI::ms_LinearScrollbarScale; +const CLogarithmicScrollbarScale CUI::ms_LogarithmicScrollbarScale(25); float CUI::ms_FontmodHeight = 0.8f; -void CUI::Init(IInput *pInput, IGraphics *pGraphics, ITextRender *pTextRender) +void CUI::Init(IKernel *pKernel) { - m_pInput = pInput; - m_pGraphics = pGraphics; - m_pTextRender = pTextRender; + m_pGraphics = pKernel->RequestInterface(); + m_pInput = pKernel->RequestInterface(); + m_pTextRender = pKernel->RequestInterface(); + InitInputs(m_pInput->GetEventsRaw(), m_pInput->GetEventCountRaw()); CUIRect::Init(m_pGraphics); } +void CUI::InitInputs(IInput::CEvent *pInputEventsArray, int *pInputEventCount) +{ + m_pInputEventsArray = pInputEventsArray; + m_pInputEventCount = pInputEventCount; +} + CUI::CUI() { m_Enabled = true; @@ -213,6 +226,10 @@ void CUI::ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) dbg_break(); break; } + + if(m_MouseSlow) + Factor *= 0.05f; + *pX *= Factor; *pY *= Factor; } @@ -551,3 +568,680 @@ void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRe { DoLabelStreamed(RectEl, pRect->x, pRect->y, pRect->w, pRect->h, pText, Size, Align, MaxWidth, AlignVertically, StopAtEnd, StrLen, pReadCursor); } + +bool CUI::DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners, const SUIExEditBoxProperties &Properties) +{ + const bool Inside = MouseHovered(pRect); + bool ReturnValue = false; + bool UpdateOffset = false; + + auto &&SetHasSelection = [&](bool HasSelection) { + m_HasSelection = HasSelection; + m_pSelItem = m_HasSelection ? pID : nullptr; + }; + + auto &&SelectAllText = [&]() { + m_CurSelStart = 0; + int StrLen = str_length(pStr); + TextRender()->UTF8OffToDecodedOff(pStr, StrLen, m_CurSelEnd); + SetHasSelection(true); + m_CurCursor = StrLen; + }; + + if(LastActiveItem() == pID) + { + if(m_HasSelection && m_pSelItem != pID) + { + SetHasSelection(false); + } + + m_CurCursor = minimum(str_length(pStr), m_CurCursor); + + bool IsShiftPressed = Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT); + bool IsModPressed = Input()->ModifierIsPressed(); + + if(Enabled() && !IsShiftPressed && IsModPressed && Input()->KeyPress(KEY_V)) + { + const char *pText = Input()->GetClipboardText(); + if(pText) + { + int OffsetL = clamp(m_CurCursor, 0, str_length(pStr)); + int OffsetR = OffsetL; + + if(m_HasSelection) + { + int SelLeft = minimum(m_CurSelStart, m_CurSelEnd); + int SelRight = maximum(m_CurSelStart, m_CurSelEnd); + int UTF8SelLeft = -1; + int UTF8SelRight = -1; + if(TextRender()->SelectionToUTF8OffSets(pStr, SelLeft, SelRight, UTF8SelLeft, UTF8SelRight)) + { + OffsetL = UTF8SelLeft; + OffsetR = UTF8SelRight; + SetHasSelection(false); + } + } + + std::string NewStr(pStr, OffsetL); + + int WrittenChars = 0; + + const char *pIt = pText; + while(*pIt) + { + const char *pTmp = pIt; + int Character = str_utf8_decode(&pTmp); + if(Character == -1 || Character == 0) + break; + + if(Character == '\r' || Character == '\n') + { + NewStr.append(1, ' '); + ++WrittenChars; + } + else + { + NewStr.append(pIt, (std::intptr_t)(pTmp - pIt)); + WrittenChars += (int)(std::intptr_t)(pTmp - pIt); + } + + pIt = pTmp; + } + + NewStr.append(pStr + OffsetR); + + str_copy(pStr, NewStr.c_str(), StrSize); + + m_CurCursor = OffsetL + WrittenChars; + ReturnValue = true; + } + } + + if(Enabled() && !IsShiftPressed && IsModPressed && (Input()->KeyPress(KEY_C) || Input()->KeyPress(KEY_X))) + { + if(m_HasSelection) + { + int SelLeft = minimum(m_CurSelStart, m_CurSelEnd); + int SelRight = maximum(m_CurSelStart, m_CurSelEnd); + int UTF8SelLeft = -1; + int UTF8SelRight = -1; + if(TextRender()->SelectionToUTF8OffSets(pStr, SelLeft, SelRight, UTF8SelLeft, UTF8SelRight)) + { + std::string NewStr(&pStr[UTF8SelLeft], UTF8SelRight - UTF8SelLeft); + Input()->SetClipboardText(NewStr.c_str()); + if(Input()->KeyPress(KEY_X)) + { + NewStr = std::string(pStr, UTF8SelLeft) + std::string(pStr + UTF8SelRight); + str_copy(pStr, NewStr.c_str(), StrSize); + SetHasSelection(false); + if(m_CurCursor > UTF8SelLeft) + m_CurCursor = maximum(0, m_CurCursor - (UTF8SelRight - UTF8SelLeft)); + else + m_CurCursor = UTF8SelLeft; + } + } + } + else + Input()->SetClipboardText(pStr); + } + + if(Properties.m_SelectText || (Enabled() && !IsShiftPressed && IsModPressed && Input()->KeyPress(KEY_A))) + { + SelectAllText(); + } + + if(Enabled() && !IsShiftPressed && IsModPressed && Input()->KeyPress(KEY_U)) + { + pStr[0] = '\0'; + m_CurCursor = 0; + SetHasSelection(false); + ReturnValue = true; + } + + for(int i = 0; i < *m_pInputEventCount; i++) + { + int LastCursor = m_CurCursor; + int Len, NumChars; + str_utf8_stats(pStr, StrSize, StrSize, &Len, &NumChars); + int32_t ManipulateChanges = CLineInput::Manipulate(m_pInputEventsArray[i], pStr, StrSize, StrSize, &Len, &m_CurCursor, &NumChars, m_HasSelection ? CLineInput::LINE_INPUT_MODIFY_DONT_DELETE : 0, IsModPressed ? KEY_LCTRL : 0); + ReturnValue |= (ManipulateChanges & (CLineInput::LINE_INPUT_CHANGE_STRING | CLineInput::LINE_INPUT_CHANGE_CHARACTERS_DELETE)) != 0; + + // if cursor changed, reset selection + if(ManipulateChanges != 0) + { + if(m_HasSelection && (ManipulateChanges & (CLineInput::LINE_INPUT_CHANGE_STRING | CLineInput::LINE_INPUT_CHANGE_CHARACTERS_DELETE)) != 0) + { + int OffsetL = 0; + int OffsetR = 0; + + bool IsReverseSel = m_CurSelStart > m_CurSelEnd; + + int ExtraNew = 0; + int ExtraOld = 0; + // selection correction from added chars + if(IsReverseSel) + { + TextRender()->UTF8OffToDecodedOff(pStr, m_CurCursor, ExtraNew); + TextRender()->UTF8OffToDecodedOff(pStr, LastCursor, ExtraOld); + } + + int SelLeft = minimum(m_CurSelStart, m_CurSelEnd); + int SelRight = maximum(m_CurSelStart, m_CurSelEnd); + int UTF8SelLeft = -1; + int UTF8SelRight = -1; + if(TextRender()->SelectionToUTF8OffSets(pStr, SelLeft + (ExtraNew - ExtraOld), SelRight + (ExtraNew - ExtraOld), UTF8SelLeft, UTF8SelRight)) + { + OffsetL = UTF8SelLeft; + OffsetR = UTF8SelRight; + SetHasSelection(false); + } + + std::string NewStr(pStr, OffsetL); + + NewStr.append(pStr + OffsetR); + + str_copy(pStr, NewStr.c_str(), StrSize); + + if(!IsReverseSel) + m_CurCursor = clamp(m_CurCursor - (UTF8SelRight - UTF8SelLeft), 0, NewStr.length()); + } + + if(IsShiftPressed && (ManipulateChanges & CLineInput::LINE_INPUT_CHANGE_STRING) == 0) + { + int CursorPosDecoded = -1; + int LastCursorPosDecoded = -1; + + if(!m_HasSelection) + { + m_CurSelStart = -1; + m_CurSelEnd = -1; + } + + if(TextRender()->UTF8OffToDecodedOff(pStr, m_CurCursor, CursorPosDecoded)) + { + if(TextRender()->UTF8OffToDecodedOff(pStr, LastCursor, LastCursorPosDecoded)) + { + if(!m_HasSelection) + { + m_CurSelStart = LastCursorPosDecoded; + m_CurSelEnd = LastCursorPosDecoded; + } + m_CurSelEnd += (CursorPosDecoded - LastCursorPosDecoded); + } + } + if(m_CurSelStart == m_CurSelEnd) + SetHasSelection(false); + else + SetHasSelection(true); + } + else + { + if(m_HasSelection && (ManipulateChanges & CLineInput::LINE_INPUT_CHANGE_CURSOR) != 0) + { + if(m_CurSelStart < m_CurSelEnd) + { + if(m_CurCursor >= LastCursor) + m_CurCursor = LastCursor; + else + TextRender()->DecodedOffToUTF8Off(pStr, m_CurSelStart, m_CurCursor); + } + else + { + if(m_CurCursor <= LastCursor) + m_CurCursor = LastCursor; + else + TextRender()->DecodedOffToUTF8Off(pStr, m_CurSelStart, m_CurCursor); + } + } + SetHasSelection(false); + } + } + } + } + + if(Inside) + { + SetHotItem(pID); + } + + CUIRect Textbox = *pRect; + Textbox.Draw(ColorRGBA(1, 1, 1, 0.5f), Corners, 3.0f); + Textbox.Margin(2.0f, &Textbox); + + const char *pDisplayStr = pStr; + char aStars[128]; + + if(Hidden) + { + unsigned s = str_length(pDisplayStr); + if(s >= sizeof(aStars)) + s = sizeof(aStars) - 1; + for(unsigned int i = 0; i < s; ++i) + aStars[i] = '*'; + aStars[s] = 0; + pDisplayStr = aStars; + } + + char aDispEditingText[128 + IInput::INPUT_TEXT_SIZE + 2] = {0}; + int DispCursorPos = m_CurCursor; + if(LastActiveItem() == pID && Input()->GetIMEEditingTextLength() > -1) + { + int EditingTextCursor = Input()->GetEditingCursor(); + str_copy(aDispEditingText, pDisplayStr); + char aEditingText[IInput::INPUT_TEXT_SIZE + 2]; + if(Hidden) + { + // Do not show editing text in password field + str_copy(aEditingText, "[*]"); + EditingTextCursor = 1; + } + else + { + str_format(aEditingText, sizeof(aEditingText), "[%s]", Input()->GetIMEEditingText()); + } + int NewTextLen = str_length(aEditingText); + int CharsLeft = (int)sizeof(aDispEditingText) - str_length(aDispEditingText) - 1; + int FillCharLen = minimum(NewTextLen, CharsLeft); + for(int i = str_length(aDispEditingText) - 1; i >= m_CurCursor; i--) + aDispEditingText[i + FillCharLen] = aDispEditingText[i]; + for(int i = 0; i < FillCharLen; i++) + aDispEditingText[m_CurCursor + i] = aEditingText[i]; + DispCursorPos = m_CurCursor + EditingTextCursor + 1; + pDisplayStr = aDispEditingText; + UpdateOffset = true; + } + + bool IsEmptyText = false; + if(pDisplayStr[0] == '\0') + { + pDisplayStr = Properties.m_pEmptyText; + IsEmptyText = true; + TextRender()->TextColor(1, 1, 1, 0.75f); + } + + DispCursorPos = minimum(DispCursorPos, str_length(pDisplayStr)); + + bool JustGotActive = false; + if(CheckActiveItem(pID)) + { + if(!MouseButton(0)) + { + SetActiveItem(nullptr); + } + } + else if(HotItem() == pID) + { + if(MouseButton(0)) + { + if(LastActiveItem() != pID) + JustGotActive = true; + SetActiveItem(pID); + } + } + + // check if the text has to be moved + if(LastActiveItem() == pID && !JustGotActive && (UpdateOffset || *m_pInputEventCount)) + { + float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits::max()); + if(w - *pOffset > Textbox.w) + { + // move to the left + float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, std::numeric_limits::max()); + do + { + *pOffset += minimum(wt - *pOffset - Textbox.w, Textbox.w / 3); + } while(w - *pOffset > Textbox.w + 0.0001f); + } + else if(w - *pOffset < 0.0f) + { + // move to the right + do + { + *pOffset = maximum(0.0f, *pOffset - Textbox.w / 3); + } while(w - *pOffset < -0.0001f); + } + } + ClipEnable(pRect); + Textbox.x -= *pOffset; + + CTextCursor SelCursor; + TextRender()->SetCursor(&SelCursor, 0, 0, 16, 0); + + bool HasMouseSel = false; + if(LastActiveItem() == pID) + { + if(!m_MouseIsPress && MouseButtonClicked(0)) + { + m_MouseIsPress = true; + m_MousePressX = MouseX(); + m_MousePressY = MouseY(); + } + } + + if(m_MouseIsPress) + { + m_MouseCurX = MouseX(); + m_MouseCurY = MouseY(); + } + HasMouseSel = m_MouseIsPress && !IsEmptyText; + if(m_MouseIsPress && MouseButtonReleased(0)) + { + m_MouseIsPress = false; + } + + if(LastActiveItem() == pID) + { + int CursorPos = -1; + TextRender()->UTF8OffToDecodedOff(pDisplayStr, DispCursorPos, CursorPos); + + SelCursor.m_CursorMode = HasMouseSel ? TEXT_CURSOR_CURSOR_MODE_CALCULATE : TEXT_CURSOR_CURSOR_MODE_SET; + SelCursor.m_CursorCharacter = CursorPos; + SelCursor.m_CalculateSelectionMode = HasMouseSel ? TEXT_CURSOR_SELECTION_MODE_CALCULATE : (m_HasSelection ? TEXT_CURSOR_SELECTION_MODE_SET : TEXT_CURSOR_SELECTION_MODE_NONE); + SelCursor.m_PressMouseX = m_MousePressX; + SelCursor.m_PressMouseY = m_MousePressY; + SelCursor.m_ReleaseMouseX = m_MouseCurX; + SelCursor.m_ReleaseMouseY = m_MouseCurY; + SelCursor.m_SelectionStart = m_CurSelStart; + SelCursor.m_SelectionEnd = m_CurSelEnd; + } + + SLabelProperties Props; + Props.m_pSelCursor = &SelCursor; + Props.m_EnableWidthCheck = IsEmptyText; + DoLabel(&Textbox, pDisplayStr, FontSize, TEXTALIGN_LEFT, Props); + + if(LastActiveItem() == pID) + { + if(SelCursor.m_CalculateSelectionMode == TEXT_CURSOR_SELECTION_MODE_CALCULATE) + { + m_CurSelStart = SelCursor.m_SelectionStart; + m_CurSelEnd = SelCursor.m_SelectionEnd; + SetHasSelection(m_CurSelStart != m_CurSelEnd); + } + if(SelCursor.m_CursorMode == TEXT_CURSOR_CURSOR_MODE_CALCULATE) + { + TextRender()->DecodedOffToUTF8Off(pDisplayStr, SelCursor.m_CursorCharacter, DispCursorPos); + m_CurCursor = DispCursorPos; + } + } + + TextRender()->TextColor(1, 1, 1, 1); + + // set the ime cursor + if(LastActiveItem() == pID && !JustGotActive) + { + float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits::max()); + Textbox.x += w; + Input()->SetEditingPosition(Textbox.x, Textbox.y + FontSize); + } + + ClipDisable(); + + return ReturnValue; +} + +bool CUI::DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners, const SUIExEditBoxProperties &Properties) +{ + CUIRect EditBox; + CUIRect ClearButton; + pRect->VSplitRight(15.0f, &EditBox, &ClearButton); + bool ReturnValue = DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, pOffset, Hidden, Corners & ~IGraphics::CORNER_R, Properties); + + 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); + ClearButton.Draw(ColorRGBA(1, 1, 1, 0.33f * ButtonColorMul(pClearID)), Corners & ~IGraphics::CORNER_L, 3.0f); + + SLabelProperties Props; + Props.m_AlignVertically = 0; + DoLabel(&ClearButton, "×", ClearButton.h * CUI::ms_FontmodHeight, TEXTALIGN_CENTER, Props); + TextRender()->SetRenderFlags(0); + if(DoButtonLogic(pClearID, 0, &ClearButton)) + { + pStr[0] = 0; + SetActiveItem(pID); + ReturnValue = true; + } + return ReturnValue; +} + +float CUI::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) +{ + Current = clamp(Current, 0.0f, 1.0f); + + // layout + CUIRect Rail; + pRect->Margin(5.0f, &Rail); + + CUIRect Handle; + Rail.HSplitTop(clamp(33.0f, Rail.w, Rail.h / 3.0f), &Handle, 0); + Handle.y = Rail.y + (Rail.h - Handle.h) * Current; + + // logic + static float s_OffsetY; + const bool InsideRail = MouseHovered(&Rail); + const bool InsideHandle = MouseHovered(&Handle); + bool Grabbed = false; // whether to apply the offset + + if(CheckActiveItem(pID)) + { + if(MouseButton(0)) + { + Grabbed = true; + if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) + m_MouseSlow = true; + } + else + { + SetActiveItem(nullptr); + } + } + else if(HotItem() == pID) + { + if(MouseButton(0)) + { + SetActiveItem(pID); + s_OffsetY = MouseY() - Handle.y; + Grabbed = true; + } + } + else if(MouseButtonClicked(0) && !InsideHandle && InsideRail) + { + SetActiveItem(pID); + s_OffsetY = Handle.h / 2.0f; + Grabbed = true; + } + + if(InsideHandle) + { + SetHotItem(pID); + } + + float ReturnValue = Current; + if(Grabbed) + { + const float Min = Rail.y; + const float Max = Rail.h - Handle.h; + const float Cur = MouseY() - s_OffsetY; + ReturnValue = clamp((Cur - Min) / Max, 0.0f, 1.0f); + } + + // render + Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.w / 2.0f); + + float ColorSlider; + if(CheckActiveItem(pID)) + ColorSlider = 0.9f; + else if(HotItem() == pID) + ColorSlider = 1.0f; + else + ColorSlider = 0.8f; + + Handle.Draw(ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.w / 2.0f); + + return ReturnValue; +} + +float CUI::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner) +{ + Current = clamp(Current, 0.0f, 1.0f); + + // layout + CUIRect Rail; + if(pColorInner) + Rail = *pRect; + else + pRect->HMargin(5.0f, &Rail); + + CUIRect Handle; + Rail.VSplitLeft(pColorInner ? 8.0f : clamp(33.0f, Rail.h, Rail.w / 3.0f), &Handle, 0); + Handle.x += (Rail.w - Handle.w) * Current; + + // logic + static float s_OffsetX; + const bool InsideRail = MouseHovered(&Rail); + const bool InsideHandle = MouseHovered(&Handle); + bool Grabbed = false; // whether to apply the offset + + if(CheckActiveItem(pID)) + { + if(MouseButton(0)) + { + Grabbed = true; + if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) + m_MouseSlow = true; + } + else + { + SetActiveItem(nullptr); + } + } + else if(HotItem() == pID) + { + if(MouseButton(0)) + { + SetActiveItem(pID); + s_OffsetX = MouseX() - Handle.x; + Grabbed = true; + } + } + else if(MouseButtonClicked(0) && !InsideHandle && InsideRail) + { + SetActiveItem(pID); + s_OffsetX = Handle.w / 2.0f; + Grabbed = true; + } + + if(InsideHandle) + { + SetHotItem(pID); + } + + float ReturnValue = Current; + if(Grabbed) + { + const float Min = Rail.x; + const float Max = Rail.w - Handle.w; + const float Cur = MouseX() - s_OffsetX; + ReturnValue = clamp((Cur - Min) / Max, 0.0f, 1.0f); + } + + // render + if(pColorInner) + { + CUIRect Slider; + Handle.VMargin(-2.0f, &Slider); + Slider.HMargin(-3.0f, &Slider); + Slider.Draw(ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 5.0f); + Slider.Margin(2.0f, &Slider); + Slider.Draw(*pColorInner, IGraphics::CORNER_ALL, 3.0f); + } + else + { + Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.h / 2.0f); + + float ColorSlider; + if(CheckActiveItem(pID)) + ColorSlider = 0.9f; + else if(HotItem() == pID) + ColorSlider = 1.0f; + else + ColorSlider = 0.8f; + + Handle.Draw(ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.h / 2.0f); + } + + return ReturnValue; +} + +void CUI::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale, unsigned Flags) +{ + const bool Infinite = Flags & CUI::SCROLLBAR_OPTION_INFINITE; + const bool NoClampValue = Flags & CUI::SCROLLBAR_OPTION_NOCLAMPVALUE; + dbg_assert(!(Infinite && NoClampValue), "cannot combine SCROLLBAR_OPTION_INFINITE and SCROLLBAR_OPTION_NOCLAMPVALUE"); + + int Value = *pOption; + if(Infinite) + { + Min += 1; + Max += 1; + if(Value == 0) + Value = Max; + } + + char aBufMax[256]; + str_format(aBufMax, sizeof(aBufMax), "%s: %i", pStr, Max); + char aBuf[256]; + if(!Infinite || Value != Max) + str_format(aBuf, sizeof(aBuf), "%s: %i", pStr, Value); + else + str_format(aBuf, sizeof(aBuf), "%s: ∞", pStr); + + if(NoClampValue) + { + // clamp the value internally for the scrollbar + Value = clamp(Value, Min, Max); + } + + float FontSize = pRect->h * CUI::ms_FontmodHeight * 0.8f; + float VSplitVal = 10.0f + maximum(TextRender()->TextWidth(0, FontSize, aBuf, -1, std::numeric_limits::max()), TextRender()->TextWidth(0, FontSize, aBufMax, -1, std::numeric_limits::max())); + + CUIRect Label, ScrollBar; + pRect->VSplitLeft(VSplitVal, &Label, &ScrollBar); + DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); + + Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, Min, Max)), Min, Max); + if(Infinite) + { + if(Value == Max) + Value = 0; + } + else if(NoClampValue) + { + if((Value == Min && *pOption < Min) || (Value == Max && *pOption > Max)) + Value = *pOption; // use previous out of range value instead if the scrollbar is at the edge + } + + *pOption = Value; +} + +void CUI::DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char **ppLabels, int NumLabels, const IScrollbarScale *pScale) +{ + const int Max = NumLabels - 1; + int Value = clamp(*pOption, 0, Max); + + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "%s: %s", pStr, ppLabels[Value]); + + float FontSize = pRect->h * CUI::ms_FontmodHeight * 0.8f; + + CUIRect Label, ScrollBar; + pRect->VSplitRight(60.0f, &Label, &ScrollBar); + Label.VSplitRight(10.0f, &Label, 0); + DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); + + Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, 0, Max)), 0, Max); + + if(HotItem() != pID && !CheckActiveItem(pID) && MouseHovered(pRect) && MouseButtonClicked(0)) + Value = (Value + 1) % NumLabels; + + *pOption = clamp(Value, 0, Max); +} diff --git a/src/game/client/ui.h b/src/game/client/ui.h index cbd5916ff4e..4415d0f5e86 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -12,6 +12,9 @@ #include #include +class IGraphics; +class IKernel; + struct SUIAnimator { bool m_Active; @@ -27,6 +30,63 @@ struct SUIAnimator float m_HOffset; }; +class IScrollbarScale +{ +public: + virtual float ToRelative(int AbsoluteValue, int Min, int Max) const = 0; + virtual int ToAbsolute(float RelativeValue, int Min, int Max) const = 0; +}; +class CLinearScrollbarScale : public IScrollbarScale +{ +public: + float ToRelative(int AbsoluteValue, int Min, int Max) const override + { + return (AbsoluteValue - Min) / (float)(Max - Min); + } + int ToAbsolute(float RelativeValue, int Min, int Max) const override + { + return round_to_int(RelativeValue * (Max - Min) + Min + 0.1f); + } +}; +class CLogarithmicScrollbarScale : public IScrollbarScale +{ +private: + int m_MinAdjustment; + +public: + CLogarithmicScrollbarScale(int MinAdjustment) + { + m_MinAdjustment = maximum(MinAdjustment, 1); // must be at least 1 to support Min == 0 with logarithm + } + float ToRelative(int AbsoluteValue, int Min, int Max) const override + { + if(Min < m_MinAdjustment) + { + AbsoluteValue += m_MinAdjustment; + Min += m_MinAdjustment; + Max += m_MinAdjustment; + } + return (log(AbsoluteValue) - log(Min)) / (float)(log(Max) - log(Min)); + } + int ToAbsolute(float RelativeValue, int Min, int Max) const override + { + int ResultAdjustment = 0; + if(Min < m_MinAdjustment) + { + Min += m_MinAdjustment; + Max += m_MinAdjustment; + ResultAdjustment = -m_MinAdjustment; + } + return round_to_int(exp(RelativeValue * (log(Max) - log(Min)) + log(Min))) + ResultAdjustment; + } +}; + +struct SUIExEditBoxProperties +{ + bool m_SelectText = false; + const char *m_pEmptyText = ""; +}; + class CUI; class CUIElement @@ -120,27 +180,47 @@ class CUI float m_MouseWorldX, m_MouseWorldY; // in world space unsigned m_MouseButtons; unsigned m_LastMouseButtons; + bool m_MouseSlow = false; + + IInput::CEvent *m_pInputEventsArray; + int *m_pInputEventCount; + + bool m_MouseIsPress = false; + bool m_HasSelection = false; + + int m_MousePressX = 0; + int m_MousePressY = 0; + int m_MouseCurX = 0; + int m_MouseCurY = 0; + int m_CurSelStart = 0; + int m_CurSelEnd = 0; + const void *m_pSelItem = nullptr; + + int m_CurCursor = 0; CUIRect m_Screen; std::vector m_vClips; void UpdateClipping(); - class IInput *m_pInput; - class IGraphics *m_pGraphics; - class ITextRender *m_pTextRender; + IGraphics *m_pGraphics; + IInput *m_pInput; + ITextRender *m_pTextRender; std::vector m_vpOwnUIElements; // ui elements maintained by CUI class std::vector m_vpUIElements; public: + static const CLinearScrollbarScale ms_LinearScrollbarScale; + static const CLogarithmicScrollbarScale ms_LogarithmicScrollbarScale; + static float ms_FontmodHeight; - // TODO: Refactor: Fill this in - void Init(class IInput *pInput, class IGraphics *pGraphics, class ITextRender *pTextRender); - class IInput *Input() const { return m_pInput; } - class IGraphics *Graphics() const { return m_pGraphics; } - class ITextRender *TextRender() const { return m_pTextRender; } + void Init(IKernel *pKernel); + void InitInputs(IInput::CEvent *pInputEventsArray, int *pInputEventCount); + IGraphics *Graphics() const { return m_pGraphics; } + IInput *Input() const { return m_pInput; } + ITextRender *TextRender() const { return m_pTextRender; } CUI(); ~CUI(); @@ -208,6 +288,7 @@ class CUI bool MouseInsideClip() const { return !IsClipped() || MouseInside(ClipArea()); } bool MouseHovered(const CUIRect *pRect) const { return MouseInside(pRect) && MouseInsideClip(); } void ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const; + void ResetMouseSlow() { m_MouseSlow = false; } float ButtonColorMulActive() { return 0.5f; } float ButtonColorMulHot() { return 1.5f; } @@ -232,6 +313,19 @@ class CUI void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen = -1, class CTextCursor *pReadCursor = nullptr); void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, float x, float y, float w, float h, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = nullptr); void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = nullptr); + + bool DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); + bool DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); + + enum + { + SCROLLBAR_OPTION_INFINITE = 1, + SCROLLBAR_OPTION_NOCLAMPVALUE = 2, + }; + float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current); + float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner = nullptr); + void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, unsigned Flags = 0u); + void DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char **ppLabels, int NumLabels, const IScrollbarScale *pScale = &ms_LinearScrollbarScale); }; #endif diff --git a/src/game/client/ui_ex.cpp b/src/game/client/ui_ex.cpp deleted file mode 100644 index 64a6d4ac264..00000000000 --- a/src/game/client/ui_ex.cpp +++ /dev/null @@ -1,724 +0,0 @@ -#include "ui_ex.h" - -#include - -#include -#include - -#include - -#include -#include - -#include - -const CLinearScrollbarScale CUIEx::ms_LinearScrollbarScale; -const CLogarithmicScrollbarScale CUIEx::ms_LogarithmicScrollbarScale(25); - -CUIEx::CUIEx() -{ - m_MouseSlow = false; -} - -void CUIEx::Init(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools, IInput::CEvent *pInputEventsArray, int *pInputEventCount) -{ - m_pUI = pUI; - m_pKernel = pKernel; - m_pRenderTools = pRenderTools; - m_pInputEventsArray = pInputEventsArray; - m_pInputEventCount = pInputEventCount; - - m_pInput = Kernel()->RequestInterface(); - m_pGraphics = Kernel()->RequestInterface(); - m_pTextRender = Kernel()->RequestInterface(); -} - -void CUIEx::ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const -{ - UI()->ConvertMouseMove(pX, pY, CursorType); - - if(m_MouseSlow) - { - const float SlowMouseFactor = 0.05f; - *pX *= SlowMouseFactor; - *pY *= SlowMouseFactor; - } -} - -float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) -{ - Current = clamp(Current, 0.0f, 1.0f); - - // layout - CUIRect Rail; - pRect->Margin(5.0f, &Rail); - - CUIRect Handle; - Rail.HSplitTop(clamp(33.0f, Rail.w, Rail.h / 3.0f), &Handle, 0); - Handle.y = Rail.y + (Rail.h - Handle.h) * Current; - - // logic - static float s_OffsetY; - const bool InsideRail = UI()->MouseHovered(&Rail); - const bool InsideHandle = UI()->MouseHovered(&Handle); - bool Grabbed = false; // whether to apply the offset - - if(UI()->CheckActiveItem(pID)) - { - if(UI()->MouseButton(0)) - { - Grabbed = true; - if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) - m_MouseSlow = true; - } - else - { - UI()->SetActiveItem(nullptr); - } - } - else if(UI()->HotItem() == pID) - { - if(UI()->MouseButton(0)) - { - UI()->SetActiveItem(pID); - s_OffsetY = UI()->MouseY() - Handle.y; - Grabbed = true; - } - } - else if(UI()->MouseButtonClicked(0) && !InsideHandle && InsideRail) - { - UI()->SetActiveItem(pID); - s_OffsetY = Handle.h / 2.0f; - Grabbed = true; - } - - if(InsideHandle) - { - UI()->SetHotItem(pID); - } - - float ReturnValue = Current; - if(Grabbed) - { - const float Min = Rail.y; - const float Max = Rail.h - Handle.h; - const float Cur = UI()->MouseY() - s_OffsetY; - ReturnValue = clamp((Cur - Min) / Max, 0.0f, 1.0f); - } - - // render - Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.w / 2.0f); - - float ColorSlider; - if(UI()->CheckActiveItem(pID)) - ColorSlider = 0.9f; - else if(UI()->HotItem() == pID) - ColorSlider = 1.0f; - else - ColorSlider = 0.8f; - - Handle.Draw(ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.w / 2.0f); - - return ReturnValue; -} - -float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner) -{ - Current = clamp(Current, 0.0f, 1.0f); - - // layout - CUIRect Rail; - if(pColorInner) - Rail = *pRect; - else - pRect->HMargin(5.0f, &Rail); - - CUIRect Handle; - Rail.VSplitLeft(pColorInner ? 8.0f : clamp(33.0f, Rail.h, Rail.w / 3.0f), &Handle, 0); - Handle.x += (Rail.w - Handle.w) * Current; - - // logic - static float s_OffsetX; - const bool InsideRail = UI()->MouseHovered(&Rail); - const bool InsideHandle = UI()->MouseHovered(&Handle); - bool Grabbed = false; // whether to apply the offset - - if(UI()->CheckActiveItem(pID)) - { - if(UI()->MouseButton(0)) - { - Grabbed = true; - if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) - m_MouseSlow = true; - } - else - { - UI()->SetActiveItem(nullptr); - } - } - else if(UI()->HotItem() == pID) - { - if(UI()->MouseButton(0)) - { - UI()->SetActiveItem(pID); - s_OffsetX = UI()->MouseX() - Handle.x; - Grabbed = true; - } - } - else if(UI()->MouseButtonClicked(0) && !InsideHandle && InsideRail) - { - UI()->SetActiveItem(pID); - s_OffsetX = Handle.w / 2.0f; - Grabbed = true; - } - - if(InsideHandle) - { - UI()->SetHotItem(pID); - } - - float ReturnValue = Current; - if(Grabbed) - { - const float Min = Rail.x; - const float Max = Rail.w - Handle.w; - const float Cur = UI()->MouseX() - s_OffsetX; - ReturnValue = clamp((Cur - Min) / Max, 0.0f, 1.0f); - } - - // render - if(pColorInner) - { - CUIRect Slider; - Handle.VMargin(-2.0f, &Slider); - Slider.HMargin(-3.0f, &Slider); - Slider.Draw(ColorRGBA(0.15f, 0.15f, 0.15f, 1.0f), IGraphics::CORNER_ALL, 5.0f); - Slider.Margin(2.0f, &Slider); - Slider.Draw(*pColorInner, IGraphics::CORNER_ALL, 3.0f); - } - else - { - Rail.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), IGraphics::CORNER_ALL, Rail.h / 2.0f); - - float ColorSlider; - if(UI()->CheckActiveItem(pID)) - ColorSlider = 0.9f; - else if(UI()->HotItem() == pID) - ColorSlider = 1.0f; - else - ColorSlider = 0.8f; - - Handle.Draw(ColorRGBA(ColorSlider, ColorSlider, ColorSlider, 1.0f), IGraphics::CORNER_ALL, Handle.h / 2.0f); - } - - return ReturnValue; -} - -void CUIEx::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale, unsigned Flags) -{ - const bool Infinite = Flags & CUIEx::SCROLLBAR_OPTION_INFINITE; - const bool NoClampValue = Flags & CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE; - dbg_assert(!(Infinite && NoClampValue), "cannot combine SCROLLBAR_OPTION_INFINITE and SCROLLBAR_OPTION_NOCLAMPVALUE"); - - int Value = *pOption; - if(Infinite) - { - Min += 1; - Max += 1; - if(Value == 0) - Value = Max; - } - - char aBufMax[256]; - str_format(aBufMax, sizeof(aBufMax), "%s: %i", pStr, Max); - char aBuf[256]; - if(!Infinite || Value != Max) - str_format(aBuf, sizeof(aBuf), "%s: %i", pStr, Value); - else - str_format(aBuf, sizeof(aBuf), "%s: ∞", pStr); - - if(NoClampValue) - { - // clamp the value internally for the scrollbar - Value = clamp(Value, Min, Max); - } - - float FontSize = pRect->h * CUI::ms_FontmodHeight * 0.8f; - float VSplitVal = 10.0f + maximum(TextRender()->TextWidth(0, FontSize, aBuf, -1, std::numeric_limits::max()), TextRender()->TextWidth(0, FontSize, aBufMax, -1, std::numeric_limits::max())); - - CUIRect Label, ScrollBar; - pRect->VSplitLeft(VSplitVal, &Label, &ScrollBar); - UI()->DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); - - Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, Min, Max)), Min, Max); - if(Infinite) - { - if(Value == Max) - Value = 0; - } - else if(NoClampValue) - { - if((Value == Min && *pOption < Min) || (Value == Max && *pOption > Max)) - Value = *pOption; // use previous out of range value instead if the scrollbar is at the edge - } - - *pOption = Value; -} - -void CUIEx::DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char **ppLabels, int NumLabels, const IScrollbarScale *pScale) -{ - const int Max = NumLabels - 1; - int Value = clamp(*pOption, 0, Max); - - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "%s: %s", pStr, ppLabels[Value]); - - float FontSize = pRect->h * CUI::ms_FontmodHeight * 0.8f; - - CUIRect Label, ScrollBar; - pRect->VSplitRight(60.0f, &Label, &ScrollBar); - Label.VSplitRight(10.0f, &Label, 0); - UI()->DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); - - Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, 0, Max)), 0, Max); - - if(UI()->HotItem() != pID && !UI()->CheckActiveItem(pID) && UI()->MouseHovered(pRect) && UI()->MouseButtonClicked(0)) - Value = (Value + 1) % NumLabels; - - *pOption = clamp(Value, 0, Max); -} - -bool CUIEx::DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners, const SUIExEditBoxProperties &Properties) -{ - const bool Inside = UI()->MouseHovered(pRect); - bool ReturnValue = false; - bool UpdateOffset = false; - - auto &&SetHasSelection = [&](bool HasSelection) { - m_HasSelection = HasSelection; - m_pSelItem = m_HasSelection ? pID : nullptr; - }; - - auto &&SelectAllText = [&]() { - m_CurSelStart = 0; - int StrLen = str_length(pStr); - TextRender()->UTF8OffToDecodedOff(pStr, StrLen, m_CurSelEnd); - SetHasSelection(true); - m_CurCursor = StrLen; - }; - - if(UI()->LastActiveItem() == pID) - { - if(m_HasSelection && m_pSelItem != pID) - { - SetHasSelection(false); - } - - m_CurCursor = minimum(str_length(pStr), m_CurCursor); - - const bool Enabled = UI()->Enabled(); - bool IsShiftPressed = Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT); - bool IsModPressed = Input()->ModifierIsPressed(); - - if(Enabled && !IsShiftPressed && IsModPressed && Input()->KeyPress(KEY_V)) - { - const char *pText = Input()->GetClipboardText(); - if(pText) - { - int OffsetL = clamp(m_CurCursor, 0, str_length(pStr)); - int OffsetR = OffsetL; - - if(m_HasSelection) - { - int SelLeft = minimum(m_CurSelStart, m_CurSelEnd); - int SelRight = maximum(m_CurSelStart, m_CurSelEnd); - int UTF8SelLeft = -1; - int UTF8SelRight = -1; - if(TextRender()->SelectionToUTF8OffSets(pStr, SelLeft, SelRight, UTF8SelLeft, UTF8SelRight)) - { - OffsetL = UTF8SelLeft; - OffsetR = UTF8SelRight; - SetHasSelection(false); - } - } - - std::string NewStr(pStr, OffsetL); - - int WrittenChars = 0; - - const char *pIt = pText; - while(*pIt) - { - const char *pTmp = pIt; - int Character = str_utf8_decode(&pTmp); - if(Character == -1 || Character == 0) - break; - - if(Character == '\r' || Character == '\n') - { - NewStr.append(1, ' '); - ++WrittenChars; - } - else - { - NewStr.append(pIt, (std::intptr_t)(pTmp - pIt)); - WrittenChars += (int)(std::intptr_t)(pTmp - pIt); - } - - pIt = pTmp; - } - - NewStr.append(pStr + OffsetR); - - str_copy(pStr, NewStr.c_str(), StrSize); - - m_CurCursor = OffsetL + WrittenChars; - ReturnValue = true; - } - } - - if(Enabled && !IsShiftPressed && IsModPressed && (Input()->KeyPress(KEY_C) || Input()->KeyPress(KEY_X))) - { - if(m_HasSelection) - { - int SelLeft = minimum(m_CurSelStart, m_CurSelEnd); - int SelRight = maximum(m_CurSelStart, m_CurSelEnd); - int UTF8SelLeft = -1; - int UTF8SelRight = -1; - if(TextRender()->SelectionToUTF8OffSets(pStr, SelLeft, SelRight, UTF8SelLeft, UTF8SelRight)) - { - std::string NewStr(&pStr[UTF8SelLeft], UTF8SelRight - UTF8SelLeft); - Input()->SetClipboardText(NewStr.c_str()); - if(Input()->KeyPress(KEY_X)) - { - NewStr = std::string(pStr, UTF8SelLeft) + std::string(pStr + UTF8SelRight); - str_copy(pStr, NewStr.c_str(), StrSize); - SetHasSelection(false); - if(m_CurCursor > UTF8SelLeft) - m_CurCursor = maximum(0, m_CurCursor - (UTF8SelRight - UTF8SelLeft)); - else - m_CurCursor = UTF8SelLeft; - } - } - } - else - Input()->SetClipboardText(pStr); - } - - if(Properties.m_SelectText || (Enabled && !IsShiftPressed && IsModPressed && Input()->KeyPress(KEY_A))) - { - SelectAllText(); - } - - if(Enabled && !IsShiftPressed && IsModPressed && Input()->KeyPress(KEY_U)) - { - pStr[0] = '\0'; - m_CurCursor = 0; - SetHasSelection(false); - ReturnValue = true; - } - - for(int i = 0; i < *m_pInputEventCount; i++) - { - int LastCursor = m_CurCursor; - int Len, NumChars; - str_utf8_stats(pStr, StrSize, StrSize, &Len, &NumChars); - int32_t ManipulateChanges = CLineInput::Manipulate(m_pInputEventsArray[i], pStr, StrSize, StrSize, &Len, &m_CurCursor, &NumChars, m_HasSelection ? CLineInput::LINE_INPUT_MODIFY_DONT_DELETE : 0, IsModPressed ? KEY_LCTRL : 0); - ReturnValue |= (ManipulateChanges & (CLineInput::LINE_INPUT_CHANGE_STRING | CLineInput::LINE_INPUT_CHANGE_CHARACTERS_DELETE)) != 0; - - // if cursor changed, reset selection - if(ManipulateChanges != 0) - { - if(m_HasSelection && (ManipulateChanges & (CLineInput::LINE_INPUT_CHANGE_STRING | CLineInput::LINE_INPUT_CHANGE_CHARACTERS_DELETE)) != 0) - { - int OffsetL = 0; - int OffsetR = 0; - - bool IsReverseSel = m_CurSelStart > m_CurSelEnd; - - int ExtraNew = 0; - int ExtraOld = 0; - // selection correction from added chars - if(IsReverseSel) - { - TextRender()->UTF8OffToDecodedOff(pStr, m_CurCursor, ExtraNew); - TextRender()->UTF8OffToDecodedOff(pStr, LastCursor, ExtraOld); - } - - int SelLeft = minimum(m_CurSelStart, m_CurSelEnd); - int SelRight = maximum(m_CurSelStart, m_CurSelEnd); - int UTF8SelLeft = -1; - int UTF8SelRight = -1; - if(TextRender()->SelectionToUTF8OffSets(pStr, SelLeft + (ExtraNew - ExtraOld), SelRight + (ExtraNew - ExtraOld), UTF8SelLeft, UTF8SelRight)) - { - OffsetL = UTF8SelLeft; - OffsetR = UTF8SelRight; - SetHasSelection(false); - } - - std::string NewStr(pStr, OffsetL); - - NewStr.append(pStr + OffsetR); - - str_copy(pStr, NewStr.c_str(), StrSize); - - if(!IsReverseSel) - m_CurCursor = clamp(m_CurCursor - (UTF8SelRight - UTF8SelLeft), 0, NewStr.length()); - } - - if(IsShiftPressed && (ManipulateChanges & CLineInput::LINE_INPUT_CHANGE_STRING) == 0) - { - int CursorPosDecoded = -1; - int LastCursorPosDecoded = -1; - - if(!m_HasSelection) - { - m_CurSelStart = -1; - m_CurSelEnd = -1; - } - - if(TextRender()->UTF8OffToDecodedOff(pStr, m_CurCursor, CursorPosDecoded)) - { - if(TextRender()->UTF8OffToDecodedOff(pStr, LastCursor, LastCursorPosDecoded)) - { - if(!m_HasSelection) - { - m_CurSelStart = LastCursorPosDecoded; - m_CurSelEnd = LastCursorPosDecoded; - } - m_CurSelEnd += (CursorPosDecoded - LastCursorPosDecoded); - } - } - if(m_CurSelStart == m_CurSelEnd) - SetHasSelection(false); - else - SetHasSelection(true); - } - else - { - if(m_HasSelection && (ManipulateChanges & CLineInput::LINE_INPUT_CHANGE_CURSOR) != 0) - { - if(m_CurSelStart < m_CurSelEnd) - { - if(m_CurCursor >= LastCursor) - m_CurCursor = LastCursor; - else - TextRender()->DecodedOffToUTF8Off(pStr, m_CurSelStart, m_CurCursor); - } - else - { - if(m_CurCursor <= LastCursor) - m_CurCursor = LastCursor; - else - TextRender()->DecodedOffToUTF8Off(pStr, m_CurSelStart, m_CurCursor); - } - } - SetHasSelection(false); - } - } - } - } - - if(Inside) - { - UI()->SetHotItem(pID); - } - - CUIRect Textbox = *pRect; - Textbox.Draw(ColorRGBA(1, 1, 1, 0.5f), Corners, 3.0f); - Textbox.Margin(2.0f, &Textbox); - - const char *pDisplayStr = pStr; - char aStars[128]; - - if(Hidden) - { - unsigned s = str_length(pDisplayStr); - if(s >= sizeof(aStars)) - s = sizeof(aStars) - 1; - for(unsigned int i = 0; i < s; ++i) - aStars[i] = '*'; - aStars[s] = 0; - pDisplayStr = aStars; - } - - char aDispEditingText[128 + IInput::INPUT_TEXT_SIZE + 2] = {0}; - int DispCursorPos = m_CurCursor; - if(UI()->LastActiveItem() == pID && Input()->GetIMEEditingTextLength() > -1) - { - int EditingTextCursor = Input()->GetEditingCursor(); - str_copy(aDispEditingText, pDisplayStr); - char aEditingText[IInput::INPUT_TEXT_SIZE + 2]; - if(Hidden) - { - // Do not show editing text in password field - str_copy(aEditingText, "[*]"); - EditingTextCursor = 1; - } - else - { - str_format(aEditingText, sizeof(aEditingText), "[%s]", Input()->GetIMEEditingText()); - } - int NewTextLen = str_length(aEditingText); - int CharsLeft = (int)sizeof(aDispEditingText) - str_length(aDispEditingText) - 1; - int FillCharLen = minimum(NewTextLen, CharsLeft); - for(int i = str_length(aDispEditingText) - 1; i >= m_CurCursor; i--) - aDispEditingText[i + FillCharLen] = aDispEditingText[i]; - for(int i = 0; i < FillCharLen; i++) - aDispEditingText[m_CurCursor + i] = aEditingText[i]; - DispCursorPos = m_CurCursor + EditingTextCursor + 1; - pDisplayStr = aDispEditingText; - UpdateOffset = true; - } - - bool IsEmptyText = false; - if(pDisplayStr[0] == '\0') - { - pDisplayStr = Properties.m_pEmptyText; - IsEmptyText = true; - TextRender()->TextColor(1, 1, 1, 0.75f); - } - - DispCursorPos = minimum(DispCursorPos, str_length(pDisplayStr)); - - bool JustGotActive = false; - if(UI()->CheckActiveItem(pID)) - { - if(!UI()->MouseButton(0)) - { - UI()->SetActiveItem(nullptr); - } - } - else if(UI()->HotItem() == pID) - { - if(UI()->MouseButton(0)) - { - if(UI()->LastActiveItem() != pID) - JustGotActive = true; - UI()->SetActiveItem(pID); - } - } - - // check if the text has to be moved - if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || *m_pInputEventCount)) - { - float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits::max()); - if(w - *pOffset > Textbox.w) - { - // move to the left - float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, std::numeric_limits::max()); - do - { - *pOffset += minimum(wt - *pOffset - Textbox.w, Textbox.w / 3); - } while(w - *pOffset > Textbox.w + 0.0001f); - } - else if(w - *pOffset < 0.0f) - { - // move to the right - do - { - *pOffset = maximum(0.0f, *pOffset - Textbox.w / 3); - } while(w - *pOffset < -0.0001f); - } - } - UI()->ClipEnable(pRect); - Textbox.x -= *pOffset; - - CTextCursor SelCursor; - TextRender()->SetCursor(&SelCursor, 0, 0, 16, 0); - - bool HasMouseSel = false; - if(UI()->LastActiveItem() == pID) - { - if(!m_MouseIsPress && UI()->MouseButtonClicked(0)) - { - m_MouseIsPress = true; - m_MousePressX = UI()->MouseX(); - m_MousePressY = UI()->MouseY(); - } - } - - if(m_MouseIsPress) - { - m_MouseCurX = UI()->MouseX(); - m_MouseCurY = UI()->MouseY(); - } - HasMouseSel = m_MouseIsPress && !IsEmptyText; - if(m_MouseIsPress && UI()->MouseButtonReleased(0)) - { - m_MouseIsPress = false; - } - - if(UI()->LastActiveItem() == pID) - { - int CursorPos = -1; - TextRender()->UTF8OffToDecodedOff(pDisplayStr, DispCursorPos, CursorPos); - - SelCursor.m_CursorMode = HasMouseSel ? TEXT_CURSOR_CURSOR_MODE_CALCULATE : TEXT_CURSOR_CURSOR_MODE_SET; - SelCursor.m_CursorCharacter = CursorPos; - SelCursor.m_CalculateSelectionMode = HasMouseSel ? TEXT_CURSOR_SELECTION_MODE_CALCULATE : (m_HasSelection ? TEXT_CURSOR_SELECTION_MODE_SET : TEXT_CURSOR_SELECTION_MODE_NONE); - SelCursor.m_PressMouseX = m_MousePressX; - SelCursor.m_PressMouseY = m_MousePressY; - SelCursor.m_ReleaseMouseX = m_MouseCurX; - SelCursor.m_ReleaseMouseY = m_MouseCurY; - SelCursor.m_SelectionStart = m_CurSelStart; - SelCursor.m_SelectionEnd = m_CurSelEnd; - } - - SLabelProperties Props; - Props.m_pSelCursor = &SelCursor; - Props.m_EnableWidthCheck = IsEmptyText; - UI()->DoLabel(&Textbox, pDisplayStr, FontSize, TEXTALIGN_LEFT, Props); - - if(UI()->LastActiveItem() == pID) - { - if(SelCursor.m_CalculateSelectionMode == TEXT_CURSOR_SELECTION_MODE_CALCULATE) - { - m_CurSelStart = SelCursor.m_SelectionStart; - m_CurSelEnd = SelCursor.m_SelectionEnd; - SetHasSelection(m_CurSelStart != m_CurSelEnd); - } - if(SelCursor.m_CursorMode == TEXT_CURSOR_CURSOR_MODE_CALCULATE) - { - TextRender()->DecodedOffToUTF8Off(pDisplayStr, SelCursor.m_CursorCharacter, DispCursorPos); - m_CurCursor = DispCursorPos; - } - } - - TextRender()->TextColor(1, 1, 1, 1); - - // set the ime cursor - if(UI()->LastActiveItem() == pID && !JustGotActive) - { - float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits::max()); - Textbox.x += w; - Input()->SetEditingPosition(Textbox.x, Textbox.y + FontSize); - } - - UI()->ClipDisable(); - - return ReturnValue; -} - -bool CUIEx::DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners, const SUIExEditBoxProperties &Properties) -{ - CUIRect EditBox; - CUIRect ClearButton; - pRect->VSplitRight(15.0f, &EditBox, &ClearButton); - bool ReturnValue = DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, pOffset, Hidden, Corners & ~IGraphics::CORNER_R, Properties); - - 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); - ClearButton.Draw(ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~IGraphics::CORNER_L, 3.0f); - - SLabelProperties Props; - Props.m_AlignVertically = 0; - UI()->DoLabel(&ClearButton, "×", ClearButton.h * CUI::ms_FontmodHeight, TEXTALIGN_CENTER, Props); - TextRender()->SetRenderFlags(0); - if(UI()->DoButtonLogic(pClearID, 0, &ClearButton)) - { - pStr[0] = 0; - UI()->SetActiveItem(pID); - ReturnValue = true; - } - return ReturnValue; -} diff --git a/src/game/client/ui_ex.h b/src/game/client/ui_ex.h deleted file mode 100644 index 782fdbe6286..00000000000 --- a/src/game/client/ui_ex.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef GAME_CLIENT_UI_EX_H -#define GAME_CLIENT_UI_EX_H - -#include -#include - -class CRenderTools; -class IGraphics; -class IKernel; -class ITextRender; - -class IScrollbarScale -{ -public: - virtual float ToRelative(int AbsoluteValue, int Min, int Max) const = 0; - virtual int ToAbsolute(float RelativeValue, int Min, int Max) const = 0; -}; -class CLinearScrollbarScale : public IScrollbarScale -{ -public: - float ToRelative(int AbsoluteValue, int Min, int Max) const override - { - return (AbsoluteValue - Min) / (float)(Max - Min); - } - int ToAbsolute(float RelativeValue, int Min, int Max) const override - { - return round_to_int(RelativeValue * (Max - Min) + Min + 0.1f); - } -}; -class CLogarithmicScrollbarScale : public IScrollbarScale -{ -private: - int m_MinAdjustment; - -public: - CLogarithmicScrollbarScale(int MinAdjustment) - { - m_MinAdjustment = maximum(MinAdjustment, 1); // must be at least 1 to support Min == 0 with logarithm - } - float ToRelative(int AbsoluteValue, int Min, int Max) const override - { - if(Min < m_MinAdjustment) - { - AbsoluteValue += m_MinAdjustment; - Min += m_MinAdjustment; - Max += m_MinAdjustment; - } - return (log(AbsoluteValue) - log(Min)) / (float)(log(Max) - log(Min)); - } - int ToAbsolute(float RelativeValue, int Min, int Max) const override - { - int ResultAdjustment = 0; - if(Min < m_MinAdjustment) - { - Min += m_MinAdjustment; - Max += m_MinAdjustment; - ResultAdjustment = -m_MinAdjustment; - } - return round_to_int(exp(RelativeValue * (log(Max) - log(Min)) + log(Min))) + ResultAdjustment; - } -}; - -struct SUIExEditBoxProperties -{ - bool m_SelectText = false; - const char *m_pEmptyText = ""; -}; - -class CUIEx -{ - CUI *m_pUI; - IInput *m_pInput; - ITextRender *m_pTextRender; - IKernel *m_pKernel; - IGraphics *m_pGraphics; - CRenderTools *m_pRenderTools; - - IInput::CEvent *m_pInputEventsArray; - int *m_pInputEventCount; - - bool m_MouseIsPress = false; - bool m_HasSelection = false; - - int m_MousePressX = 0; - int m_MousePressY = 0; - int m_MouseCurX = 0; - int m_MouseCurY = 0; - bool m_MouseSlow; - int m_CurSelStart = 0; - int m_CurSelEnd = 0; - const void *m_pSelItem = nullptr; - - int m_CurCursor = 0; - -protected: - CUI *UI() const { return m_pUI; } - IInput *Input() const { return m_pInput; } - ITextRender *TextRender() const { return m_pTextRender; } - IKernel *Kernel() const { return m_pKernel; } - IGraphics *Graphics() const { return m_pGraphics; } - CRenderTools *RenderTools() const { return m_pRenderTools; } - -public: - static const CLinearScrollbarScale ms_LinearScrollbarScale; - static const CLogarithmicScrollbarScale ms_LogarithmicScrollbarScale; - - CUIEx(); - - void Init(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools, IInput::CEvent *pInputEventsArray, int *pInputEventCount); - - void ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const; - void ResetMouseSlow() { m_MouseSlow = false; } - - enum - { - SCROLLBAR_OPTION_INFINITE = 1, - SCROLLBAR_OPTION_NOCLAMPVALUE = 2, - }; - float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current); - float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner = nullptr); - void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, unsigned Flags = 0u); - void DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char **ppLabels, int NumLabels, const IScrollbarScale *pScale = &ms_LinearScrollbarScale); - - bool DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); - bool DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {}); -}; - -#endif diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index af0c3d4e40a..263610eb53e 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -294,14 +294,14 @@ bool CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned St { if(UI()->LastActiveItem() == pID) m_EditBoxActive = 2; - return UIEx()->DoEditBox(pID, pRect, pStr, StrSize, FontSize, pOffset, Hidden, Corners); + return UI()->DoEditBox(pID, pRect, pStr, StrSize, FontSize, pOffset, Hidden, Corners); } bool CEditor::DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners) { if(UI()->LastActiveItem() == pID) m_EditBoxActive = 2; - return UIEx()->DoClearableEditBox(pID, pClearID, pRect, pStr, StrSize, FontSize, pOffset, Hidden, Corners); + return UI()->DoClearableEditBox(pID, pClearID, pRect, pStr, StrSize, FontSize, pOffset, Hidden, Corners); } ColorRGBA CEditor::GetButtonColor(const void *pID, int Checked) @@ -3281,7 +3281,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) { CUIRect Scroll; LayersBox.VSplitRight(20.0f, &LayersBox, &Scroll); - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(UI()->MouseInside(&Scroll) || UI()->MouseInside(&LayersBox)) { @@ -3968,7 +3968,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) { CUIRect Scroll; ToolBox.VSplitRight(20.0f, &ToolBox, &Scroll); - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(UI()->MouseInside(&Scroll) || UI()->MouseInside(&ToolBox)) { @@ -4182,7 +4182,7 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View) { CUIRect Scroll; ToolBox.VSplitRight(20.0f, &ToolBox, &Scroll); - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(UI()->MouseInside(&Scroll) || UI()->MouseInside(&ToolBox)) { @@ -4434,7 +4434,7 @@ void CEditor::RenderFileDialog() m_FileDialogOpening = false; int Num = (int)(View.h / 17.0f) + 1; - m_FileDialogScrollValue = UIEx()->DoScrollbarV(&m_FileDialogScrollValue, &Scroll, m_FileDialogScrollValue); + m_FileDialogScrollValue = UI()->DoScrollbarV(&m_FileDialogScrollValue, &Scroll, m_FileDialogScrollValue); int ScrollNum = 0; for(size_t i = 0; i < m_vFileList.size(); i++) @@ -5501,7 +5501,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd { CUIRect Scroll; ListBox.VSplitRight(20.0f, &ListBox, &Scroll); - s_ScrollValue = UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(UI()->MouseInside(&Scroll) || UI()->MouseInside(&ListBox)) { @@ -6317,12 +6317,10 @@ void CEditor::Init() m_pTextRender = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); m_pSound = Kernel()->RequestInterface(); - m_UI.Init(m_pInput, m_pGraphics, m_pTextRender); + m_UI.Init(Kernel()); m_RenderTools.Init(m_pGraphics, m_pTextRender); m_Map.m_pEditor = this; - UIEx()->Init(UI(), Kernel(), RenderTools(), Input()->GetEventsRaw(), Input()->GetEventCountRaw()); - m_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); m_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); m_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); @@ -6376,8 +6374,8 @@ void CEditor::OnUpdate() float MouseRelX = 0.0f, MouseRelY = 0.0f; IInput::ECursorType CursorType = Input()->CursorRelative(&MouseRelX, &MouseRelY); if(CursorType != IInput::CURSOR_NONE) - UIEx()->ConvertMouseMove(&MouseRelX, &MouseRelY, CursorType); - UIEx()->ResetMouseSlow(); + UI()->ConvertMouseMove(&MouseRelX, &MouseRelY, CursorType); + UI()->ResetMouseSlow(); m_MouseDeltaX += MouseRelX; m_MouseDeltaY += MouseRelY; diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 46ca7290b63..a4df6e923a3 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -685,7 +684,6 @@ class CEditor : public IEditor class IStorage *m_pStorage; CRenderTools m_RenderTools; CUI m_UI; - CUIEx m_UIEx; bool m_EditorWasUsedBefore = false; @@ -709,7 +707,6 @@ class CEditor : public IEditor class ITextRender *TextRender() { return m_pTextRender; } class IStorage *Storage() { return m_pStorage; } CUI *UI() { return &m_UI; } - CUIEx *UIEx() { return &m_UIEx; } CRenderTools *RenderTools() { return &m_RenderTools; } CEditor() : diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 22bea04d3b4..a5578db3941 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1232,7 +1232,7 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View, void *pContext) { CUIRect Scroll; ButtonBar.VSplitRight(20.0f, &ButtonBar, &Scroll); - s_ScrollValue = pEditor->UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = pEditor->UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(pEditor->UI()->MouseInside(&Scroll) || pEditor->UI()->MouseInside(&ButtonBar)) { @@ -1340,7 +1340,7 @@ int CEditor::PopupSelectSound(CEditor *pEditor, CUIRect View, void *pContext) { CUIRect Scroll; ButtonBar.VSplitRight(20.0f, &ButtonBar, &Scroll); - s_ScrollValue = pEditor->UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = pEditor->UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(pEditor->UI()->MouseInside(&Scroll) || pEditor->UI()->MouseInside(&ButtonBar)) { @@ -1483,7 +1483,7 @@ int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View, void *pCon { CUIRect Scroll; View.VSplitRight(20.0f, &View, &Scroll); - s_ScrollValue = pEditor->UIEx()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); + s_ScrollValue = pEditor->UI()->DoScrollbarV(&s_ScrollValue, &Scroll, s_ScrollValue); if(pEditor->UI()->MouseInside(&View) || pEditor->UI()->MouseInside(&Scroll)) { From 0aa46b54eabeaa9224ea83432a61cb413bc1a651 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 12 Aug 2022 22:38:13 +0200 Subject: [PATCH 52/72] small fix for #5729 --- src/game/client/components/freezebars.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/components/freezebars.cpp b/src/game/client/components/freezebars.cpp index 8a0f5270ed4..5ceaf4f8949 100644 --- a/src/game/client/components/freezebars.cpp +++ b/src/game/client/components/freezebars.cpp @@ -11,7 +11,7 @@ void CFreezeBars::RenderFreezeBar(const int ClientID) // pCharacter contains the predicted character for local players or the last snap for players who are spectated CCharacterCore *pCharacter = &m_pClient->m_aClients[ClientID].m_Predicted; - if(pCharacter->m_FreezeEnd <= 0.0f || pCharacter->m_FreezeStart == 0 || !m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo || (pCharacter->m_IsInFreeze && g_Config.m_ClFreezeBarsAlphaInsideFreeze == 0)) + if(pCharacter->m_FreezeEnd <= 0.0f || pCharacter->m_FreezeStart == 0 || pCharacter->m_FreezeEnd <= pCharacter->m_FreezeStart || !m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo || (pCharacter->m_IsInFreeze && g_Config.m_ClFreezeBarsAlphaInsideFreeze == 0)) { return; } From 780c4db7ddd58565e31820c9734cc972ce051f8e Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Sat, 13 Aug 2022 15:43:38 +0200 Subject: [PATCH 53/72] do an int check for m_FreezeEnd instad of float, becuase it is int --- src/game/client/components/freezebars.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/components/freezebars.cpp b/src/game/client/components/freezebars.cpp index 5ceaf4f8949..817be51129d 100644 --- a/src/game/client/components/freezebars.cpp +++ b/src/game/client/components/freezebars.cpp @@ -11,7 +11,7 @@ void CFreezeBars::RenderFreezeBar(const int ClientID) // pCharacter contains the predicted character for local players or the last snap for players who are spectated CCharacterCore *pCharacter = &m_pClient->m_aClients[ClientID].m_Predicted; - if(pCharacter->m_FreezeEnd <= 0.0f || pCharacter->m_FreezeStart == 0 || pCharacter->m_FreezeEnd <= pCharacter->m_FreezeStart || !m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo || (pCharacter->m_IsInFreeze && g_Config.m_ClFreezeBarsAlphaInsideFreeze == 0)) + if(pCharacter->m_FreezeEnd <= 0 || pCharacter->m_FreezeStart == 0 || pCharacter->m_FreezeEnd <= pCharacter->m_FreezeStart || !m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo || (pCharacter->m_IsInFreeze && g_Config.m_ClFreezeBarsAlphaInsideFreeze == 0)) { return; } From 45a20ff2772d4dd739ec9ac01c890b001620d36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 14 Aug 2022 12:38:08 +0200 Subject: [PATCH 54/72] Only load and unload normal tile layer data if necessary --- src/game/editor/io.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index 3b441fc28d4..30f7afdc6bc 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -677,7 +677,6 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag pLayer = pTiles; pGroup->AddLayer(pTiles); - void *pData = DataFile.GetData(pTilemapItem->m_Data); pTiles->m_Image = pTilemapItem->m_Image; pTiles->m_Game = pTilemapItem->m_Flags & TILESLAYERFLAG_GAME; @@ -814,6 +813,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag } else // regular tile layer or game layer { + void *pData = DataFile.GetData(pTilemapItem->m_Data); unsigned int Size = DataFile.GetDataSize(pTilemapItem->m_Data); if(Size >= (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTile)) { @@ -828,9 +828,8 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag } } } + DataFile.UnloadData(pTilemapItem->m_Data); } - - DataFile.UnloadData(pTilemapItem->m_Data); } else if(pLayerItem->m_Type == LAYERTYPE_QUADS) { From 813522f1fc3b71c9480d530ecbbae7f594ca71b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 14 Aug 2022 12:49:13 +0200 Subject: [PATCH 55/72] Add/use temporary variables to improve readability --- src/game/editor/io.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index 30f7afdc6bc..b0d722c05a4 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -700,14 +700,15 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag TILE_TELECHECKOUT, TILE_TELEINWEAPON, TILE_TELEINHOOK}; - mem_copy(((CLayerTele *)pTiles)->m_pTeleTile, pTeleData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTeleTile)); + CTeleTile *pLayerTeleTiles = ((CLayerTele *)pTiles)->m_pTeleTile; + mem_copy(pLayerTeleTiles, pTeleData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTeleTile)); for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { pTiles->m_pTiles[i].m_Index = 0; for(int TilesRep : s_aTilesRep) { - if(((CLayerTele *)pTiles)->m_pTeleTile[i].m_Type == TilesRep) + if(pLayerTeleTiles[i].m_Type == TilesRep) pTiles->m_pTiles[i].m_Index = TilesRep; } } @@ -721,11 +722,12 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag if(Size >= (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSpeedupTile)) { - mem_copy(((CLayerSpeedup *)pTiles)->m_pSpeedupTile, pSpeedupData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSpeedupTile)); + CSpeedupTile *pLayerSpeedupTiles = ((CLayerSpeedup *)pTiles)->m_pSpeedupTile; + mem_copy(pLayerSpeedupTiles, pSpeedupData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSpeedupTile)); for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { - if(((CLayerSpeedup *)pTiles)->m_pSpeedupTile[i].m_Force > 0) + if(pLayerSpeedupTiles[i].m_Force > 0) pTiles->m_pTiles[i].m_Index = TILE_BOOST; else pTiles->m_pTiles[i].m_Index = 0; @@ -767,7 +769,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag TILE_ALLOW_TELE_GUN, TILE_ALLOW_BLUE_TELE_GUN}; CSwitchTile *pLayerSwitchTiles = ((CLayerSwitch *)pTiles)->m_pSwitchTile; - mem_copy(((CLayerSwitch *)pTiles)->m_pSwitchTile, pSwitchData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSwitchTile)); + mem_copy(pLayerSwitchTiles, pSwitchData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSwitchTile)); for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { @@ -799,7 +801,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag if(Size >= (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTuneTile)) { CTuneTile *pLayerTuneTiles = ((CLayerTune *)pTiles)->m_pTuneTile; - mem_copy(((CLayerTune *)pTiles)->m_pTuneTile, pTuneData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTuneTile)); + mem_copy(pLayerTuneTiles, pTuneData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTuneTile)); for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { From 1a2b52c0f5f630634e98daac4475e8bc9fa40842 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Wed, 3 Aug 2022 09:42:20 +0200 Subject: [PATCH 56/72] Update hungarian language file (by Cellegen) --- data/languages/hungarian.txt | 224 +++++++++++++++++------------------ 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/data/languages/hungarian.txt b/data/languages/hungarian.txt index 5c51307fc34..14fd6325a90 100644 --- a/data/languages/hungarian.txt +++ b/data/languages/hungarian.txt @@ -4,7 +4,7 @@ #modified by: # Boti. # Cellegen -# bencie +# bencie ##### /authors ##### ##### translated strings ##### @@ -187,10 +187,10 @@ Game over == Játék vége Game type -== Játék fajtája +== Játékmód Game types: -== Játék fajtái: +== Játékmódok: General == Általános @@ -302,10 +302,10 @@ Player == Játékos Player options -== Játékos beállításai +== Játékosok kezelése Players -== Játékos +== Játékosok Please balance teams! == Kérlek egyenlítsd ki a csapatokat! @@ -494,7 +494,7 @@ New name: == Új Név: Sat. -== telítettség +== Telítettség Internet == Internet @@ -587,7 +587,7 @@ Type: == Típus: Dummy settings -== Másolat Beállításai +== Másolat beállításai AntiPing == Antiping @@ -647,7 +647,7 @@ Enable team chat sound == Csapat chat hang engedélyezése Show other players' hook collision lines -== Játékosok horogvonalaik mutatása +== Játékosok horog érintkező vonalainak mutatása Deaths == Halálok @@ -683,7 +683,7 @@ Play background music == Háttérzene lejátszása Follow -== Követni +== Követés Reset == Alap @@ -695,13 +695,13 @@ Team message == Csapat üzenet Automatically create statboard csv -== Magától készítsen csv pontszámtáblát +== Magától készítsen CSV pontszámtáblát Save the best demo of each race == Mentse el a legjobb demót minden versenynél Show tiles layers from BG map -== Block-ok mutatása a háttérben +== Blokkok mutatása a háttérben Are you sure that you want to disconnect? == Biztos, hogy le akarsz csatlakozni? @@ -722,7 +722,7 @@ Frags == Zászlók AntiPing: predict other players -== Antiping: más játékosokra +== Antiping: játékosok előre kiszámolása Show other players' key presses == Mutassa a játékosok mozgását nyilakkal @@ -743,7 +743,7 @@ Updating... == Frissítés... Overlay entities -== Entitás jelenése +== Entitás láthatósága Messages == Üzenetek @@ -794,7 +794,7 @@ Strict gametype filter == Szigorú játékmód szűrő Try fast HTTP map download first -== Próbálja meg a gyors HTTP letöltést először +== Próbáljon elősször gyors HTTP letöltést Use DDRace Scoreboard == DDRace pontszámtábla használata @@ -833,10 +833,10 @@ Exclude == Kizárás Enable highlighted chat sound -== kiemelt chat hang lejátszása +== Kiemelt chat hang lejátszása AntiPing: predict weapons -== Antiping: fegyvereknél +== Antiping: fegyverek előre kiszámolása DDNet Client updated! == DDNet Kliens frissítve van! @@ -848,7 +848,7 @@ Switch weapon when out of ammo == Fegyver váltása, ha elfogy a lőszer AntiPing: predict grenade paths -== Antiping: gránátoknál +== Antiping: gránátok útjainak előre kiszámolása Demo == Demó @@ -860,13 +860,13 @@ Friend message == Baráti üzenet Fat skins (DDFat) -== Nagy skinek (DDFat) +== Nagy karakterek (DDFat) may cause delay -== Késleltetést okozhat +== késleltetést okozhat Unfinished map -== befejezetlen pálya +== Befejezetlen pálya Deactivate == Deaktiválás @@ -890,7 +890,7 @@ Save == Mentés Vanilla skins only -== Csak vanilla skinek +== Csak alap karakterek Date == Idő @@ -902,10 +902,10 @@ transmits your player name to info2.ddnet.tw == továbbítja a játékosnevedet az info2.ddnet.tw oldalra Reload -== újratöltés +== Újratöltés Hammerfly dummy -== Másolat Kalapács +== Másolat kalapácsolás Downloading %s: == Letöltés %s: @@ -926,10 +926,10 @@ Video name: == Videó neve: Connect Dummy -== Másolat Csatlakoztatása +== Másolat Csatlakozása Disconnect Dummy -== Másolat Lecsatlakoztatása +== Másolat Lecsatlakozása Filter connecting players == Csatlakozók szűrése @@ -986,7 +986,7 @@ Use high DPI == Magas DPI használata Update failed! Check log... -== Frissítés sikertelen! nézd meg a logot... +== Frissítés sikertelen! nézd meg a log-ot... Toggle dyncam == Dinamikus kamera @@ -1016,13 +1016,13 @@ Markers: == 1 új értesítés DDraceNetwork is a cooperative online game where the goal is for you and your group of tees to reach the finish line of the map. As a newcomer you should start on Novice servers, which host the easiest maps. Consider the ping to choose a server close to you. -== A DDraceNetwork együttműködésen alapuló online játékként tekinthető, ahol a cél az, hogy te és egy csapat Tee elérje a célvonalat. Ha újonc vagy, a kezdő (Novice) szervereket ajánljuk, ahol a legegyszerűbb versenyeket tároljuk. A lehető legkisebb ping választása alapján válassz egy szervert. +== A DDraceNetwork egy együttműködésen alapuló online játék, ahol a cél az, hogy te és a Tee csapatod elérje a célvonalat. Ha újonc vagy, a kezdő (Novice) szervereket ajánljuk, ahol a legegyszerűbb versenyeket tároljuk. Legkisebb ping választása alapján válassz egy szervert. It's recommended that you check the settings to adjust them to your liking before joining a server. -== Ajánlott, hogy ellenőrizd a beállításokat, hogy a kedvedhez igazítsd őket, mielőtt csatlakoznál egy szerverhez. (Tipp: szűrők) +== Ajánlott, hogy le ellenőrizd a beállításokat, hogy a kedvedre igazítsd őket, mielőtt csatlakoznál egy szerverhez. (Tipp: szűrők) Please enter your nickname below. -== Írja be lent a becenevét. +== Kérjük írja le a becenevét lent. 9+ new mentions == 9+ új értesítés @@ -1049,28 +1049,28 @@ Length == Hossz Are you sure that you want to disconnect your dummy? -== Biztos, hogy kiakarod léptetni a másolatod? +== Biztos vagy benne, hogy a másolatod lecsatlakozzon? Saving ddnet-settings.cfg failed -== Nem sikerült elmenteni ddnet-settings.cfg fájlt +== Nem sikerült elmenteni a ddnet-settings.cfg fájlt Warning == Figyelmeztetés Debug mode enabled. Press Ctrl+Shift+D to disable debug mode. -== Debug mód bekapcsolva. nyomd meg a Ctrl+Shift+D billentyű kombinációt a kikapcsolásához +== Debug mód bekapcsolva. Nyomd meg a Ctrl+Shift+D billentyűparancsot, hogy kikapcsold. Use k key to kill (restart), q to pause and watch other players. See settings for other key binds. -== Használd a k gombot az újraéledéshez, q betű a megfigyeléshez. nézd meg a beállításokat a többi bindért. +== Használd a K gombot az újraéledéshez, Q betű a megfigyeléshez. Nézd meg a beállításokat a többi bind-ért. Existing Player -== Létező Játékos +== Létező játékos Your nickname '%s' is already used (%d points). Do you still want to use it? == A Neved '%s' már használva volt (%d ponttal). Biztosan szeretnéd használni? Checking for existing player with your name -== Keresés már létező játékos után a neveddel +== Keresés létező játékos után a neveddel Country / Region == Ország / Régió @@ -1094,16 +1094,16 @@ Theme == %d játékos Demos directory -== Demók Helye +== Demók helye Smooth Dynamic Camera -== Egyenletes dinamikus kamera +== Sima dinamikus kamera Skip the main menu == Főmenü kihagyása Themes directory -== Témák Helye +== Témák helye Download skins == Karakterek letöltése @@ -1112,28 +1112,28 @@ Skin prefix == Karakter prefix Skin Database -== Karakter Adatbázis +== Karakter adatbázis Skins directory -== Karakterek Helye +== Karakterek helye Game sound volume -== Játék Hangerő +== Játék hangerő Chat sound volume -== Chat Hangerő +== Chat hangerő Background music volume == Háttérzene hangerő Assets -== Kinézet +== Galléria Use old chat style == Régi chat stílus használata Client message -== Kliens Üzenet +== Kliens üzenet Show others (own team only) == Mások mutatása (csak csapatok) @@ -1182,22 +1182,22 @@ Race == Verseny Auto -== Autómatikus +== Automatikus Replay == Visszajátszás The width of texture %s is not divisible by %d, or the height is not divisible by %d, which might cause visual bugs. -== A Struktúra Szélessége %s nem osztható %d al, vagy a magasság nem osztható %d al, ami vizuális hibákhoz vezethet. +== Ennek a Textúrának szélessége, vagy magassága (%s) nem megfelelően osztható el ezzel a számmal: (%d), ami vizuális hibákhoz vezethet. (Méretek máshogyan fognak kinézni és a teljesítményt is ronthatja.) Getting server list from master server -== Szerverlista lekérése +== Szerverlista lekérése a fő szerverekről Leak IP -== IP Mutatása +== IP mutatása Chat command -== Chat Parancs +== Chat parancs Dummy == Másolat @@ -1206,16 +1206,16 @@ Windowed == Ablak Windowed borderless -== Keretnélküli Ablak +== Keretnélküli ablak Desktop fullscreen -== Asztalos Teljesképernyő +== Asztalos teljesképernyő Laser Outline Color -== Lézer Körvonal Szín +== Lézer külső vonalának színe Laser Inner Color -== Lézer Belső Szín +== Lézer belső vonalának színe Preview == Előnézet @@ -1224,10 +1224,10 @@ Background == Háttér Entities Background color -== Entitás Háttér Szín +== Entitás háttérkép színe Regular Background Color -== Átlagos Háttér Szín +== Alap háttérkép színe Are you sure that you want to disconnect and switch to a different server? == Biztos, hogy kilépsz és váltasz egy másik szerverre? @@ -1272,10 +1272,10 @@ https://wiki.ddnet.tw/ == https://wiki.ddnet.tw/ The format of texture %s is not RGBA which will cause visual bugs. -== A %s textúra formátuma nem RGBA, ami vizuális hibákat okozhat. +== A %s textúra formátuma nem RGBA, ami vizuális hibákat okozhat. (Nem megfelelően lesz elosztva a kép színvilága.) Join Tutorial Server -== Belépés a Bemutató Szerverre +== Belépés egy Bemutató szerverre Skip Tutorial == Bemutató átugrása @@ -1287,22 +1287,22 @@ Config directory == Konfigurációs fájl helye Windowed fullscreen -== Ablakos Teljesképernyő +== Ablakos teljesképernyő Run on join == Futtatás belépéskor Chat command (e.g. showall 1) -== Chat parancs (például showall 1) +== Chat parancs (például: "showall 1") Toggle to edit your dummy settings -== Átkapcsolás a másolatod beállításainak szerkesztéséhez +== Átváltát a másolatod beállításaira. Choose default eyes when joining a server -== Alapértelmezett szemek kiválasztása, amikor egy szerverre csatlakozol +== Alapértelmezett szemek kiválasztása, amikor egy szerverre csatlakozol. Allows maps to render with more detail -== Engedélyezi, pályákat részletesebben jelenítse meg +== Engedélyezi, hogy a pályákat részletesebben jelenítse meg. Renderer == Renderelő @@ -1320,25 +1320,25 @@ auto == automatikus When you cross the start line, show a ghost tee replicating the movements of your best time -== Amikor átléped a rajtvonalat, mutat egy szellemjátákost amely megismétli a legjobb időd mozdulatait +== Amikor elkezdesz egy versenyt, rekordjaid alapján replikál egy szellemet, ami a legjobb időd alapján mozdul. Opacity == Átlátszóság Adjust the opacity of entities belonging to other teams, such as tees and nameplates -== Más csapatokhoz tartozó entitások átláthatóságának beállítása, például játékosok és névtáblák +== Más csapatokhoz tartozó entitások, mint például játékosok és névtáblák átláthatóságának beállítása. Quads are used for background decoration -== A quadok háttérdekorációért használhatóak +== A kép keretek háttérképként lesznek használva. (Egy csak olyan keretekre vonatkozik, aminek a para x és y tengelye 0.) Tries to predict other entities to give a feel of low latency -== Megpróbálja megjósolni más entitásokat, hogy az alacsony késleltetés érzetét keltse +== A kliens megpróbálja előre kiszámítani az entitásokat, hogy alacsony késleltetést produkáljon. Tutorial == Bemutató Can't find a Tutorial server -== Nem található bemutató szerver +== Nem található Bemutató szerver Super == Szuper @@ -1362,7 +1362,7 @@ UDP seems to be filtered. == Az UDP szűrve van. UDP and TCP IP addresses seem to be different. Try disabling VPN, proxy or network accelerators. -== Az UDP és a TCP IP címek külömböznek. Próbáld meg kikapcsolni a VPN-ed, proxy-dat, vagy hálózati gyorsítódat. +== Az UDP és a TCP IP címek különböznek. Próbáld meg kikapcsolni a VPN-ed, proxy-d, vagy hálózati gyorsítód. No answer from server yet. == Még nincs válasz a szervertől. @@ -1377,7 +1377,7 @@ Controller %d: %s == Kontroller %d: %s Click to cycle through all available controllers. -== Kattints, hogy az elérhető kontrollerek között váltogass. +== Kattints, hogy váltogass az elérhető kontrollerek között. [Ingame controller mode] Relative @@ -1400,7 +1400,7 @@ Controller jitter tolerance == Kontroller jitter tolerancia No controller found. Plug in a controller and restart the game. -== Nem találtunk kontrollert. Dugj be egy kontrollert, majd indítsd újra a játékot. +== Nem találtunk kontrollert. Csatlakoztass egy kontrollert, majd indítsd újra a klienst. Device == Eszköz @@ -1415,10 +1415,10 @@ Mouse == Egér Ingame mouse sens. -== Játékbeli egér érzékenység +== Játékbeli egér érzékenysége UI mouse sens. -== UI egér érzékenység +== UI egér érzékenysége Controller == Kontroller @@ -1433,7 +1433,7 @@ Show player speed == Játékos sebességének mutatása Show player target angle -== Játékos célszög mutatása +== Játékos célszögének mutatása Normal Color == Normális szín @@ -1445,115 +1445,115 @@ Extras == Extrák Preparing demo playback -== +== Demó visszajátszás előkészítése Connected -== +== Csatlakozva Loading map file from storage -== - -Why are you slowmo replaying to read this? -== +== Pálya betöltése a tárolóban Initializing components -== +== Komponensek inicializálása Initializing assets -== +== Galléria inicializálása Initializing map logic -== +== Pálya logika inicializálása Sending initial client info -== +== Szükséges kliens infó küldése Uploading map data to GPU -== +== Pálya feltöltése a GPU-ra Getting game info -== +== Játék infó beszerzése Requesting to join the game -== +== Kérvényezés játék csatlakozására Loading menu images -== +== Menü képek betöltése Loading demo files -== +== Demó filterek betöltése Loading ghost files -== +== Szellem fájlok betöltése Loading skin files -== +== Karakter fájlok betöltése Aim bind -== +== Célzás bind Appearance -== +== Kinézet Name Plate -== +== Névtábla Hook Collisions -== +== Horog érintkező Show health, shields and ammo -== +== Mutassa az életet, a pajzsot és a töltényt DDRace HUD -== +== DDRace HUD Show client IDs in scoreboard -== +== Mutassa a kliensek ID-ét a pontszámtáblán Show DDRace HUD -== +== Mutassa a DDRace HUD-ot (Speciális HUD) Show jumps indicator -== +== Ugrás indikátor mutatása Show freeze bars -== +== Lefagyaztás töltő csík mutatása Opacity of freeze bars inside freeze -== +== Láthatósága a töltő csíknak, mikor levan fagyaztva a Tee Show hook strength indicator -== +== Horog erősségi indikátor mutatása Hook collision line -== +== Horog érintkező vonal indikátora Hook collision line width -== +== Horog érintkező vonal szélessége Hook collision line opacity -== +== Horog érintkező vonal láthatósága Colors of the hook collision line, in case of a possible collision with: -== +== Horog érintkező vonal színe, ez a szín jelenik meg, mikor: Your movements are not taken into account when calculating the line colors -== +== A mozgásaid, illetve mások mozgása nem fogja befolyásolni a vonal színének kiszámítását. Nothing hookable -== +== Semmi sem akadhat meg a horgon Something hookable -== +== Meg akadhat valami a horgon A Tee -== +== Egy Tee akadhat meg a horgon Loading assets -== +== Galléria betöltése Loading race demo files -== +== Verseny demó fájlok betöltése Loading sound files +== Hang fájlok betöltése + +Why are you slowmo replaying to read this? == From 33e54729b1306fa747408a15b9f54f759d8d19dd Mon Sep 17 00:00:00 2001 From: archimede67 Date: Mon, 15 Aug 2022 13:03:23 +0200 Subject: [PATCH 57/72] Update french.txt --- data/languages/french.txt | 43 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/data/languages/french.txt b/data/languages/french.txt index 4cf9d2f4d19..bd049f0e545 100644 --- a/data/languages/french.txt +++ b/data/languages/french.txt @@ -23,6 +23,7 @@ # Nouaa 2022-05-14 23:00:00 # Chairn 2022-06-16 19:00:00 # Sucre 2022-07-19 20:36:00 +# archimede67 2022-08-15 13:02:00 ##### /authors ##### @@ -1517,64 +1518,64 @@ Loading sound files == Chargement des fichiers sonores Preparing demo playback -== +== Préparation de la lecture de la demo Loading map file from storage -== +== Chargement de la map depuis le stockage Why are you slowmo replaying to read this? -== +== Pourquoi rejoues-tu en slow-motion pour lire ça? Initializing components -== +== Initialisation des composants Initializing map logic -== +== Initialisation de la logique de la map Sending initial client info -== +== Envoi des informations initiales du client Uploading map data to GPU -== +== Téléchargement des données de la map vers le GPU Loading menu images -== +== Chargement des images de menu Loading demo files -== +== Chargement des fichiers de demo Loading ghost files -== +== Chargement des fichiers de fantôme Name Plate -== +== Plaque de nom Hook Collisions -== +== Collisions du grappin Show client IDs in scoreboard -== +== Afficher les IDs des clients dans le tableau des scores Show hook strength indicator -== +== Afficher l'indicateur de force du grappin Hook collision line width -== +== Largeur de la ligne de collision du grappin Hook collision line opacity -== +== Opacité de la ligne de collision du grappin Colors of the hook collision line, in case of a possible collision with: -== +== Couleurs de la ligne de collision du grappin, dans le cas d'une collision possible avec : Your movements are not taken into account when calculating the line colors -== +== Vos mouvements ne sont pas pris en compte lors du calcul des couleurs de la ligne Nothing hookable -== +== Rien d'accrochable Something hookable -== +== Quelque chose d'accrochable Loading race demo files -== +== Chargement des fichiers de demo de la course From 301355d588d4c6c98a9e87ea56829920d413a900 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 6 May 2022 14:24:46 +0300 Subject: [PATCH 58/72] engine/server.h: Remove outdated comment --- src/engine/server.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/server.h b/src/engine/server.h index 3f53cbc1624..3dead98ca7b 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -270,8 +270,6 @@ class IGameServer : public IInterface virtual void OnInit() = 0; virtual void OnConsoleInit() = 0; virtual void OnMapChange(char *pNewMapName, int MapNameSize) = 0; - - // FullShutdown is true if the program is about to exit (not if the map is changed) virtual void OnShutdown() = 0; virtual void OnTick() = 0; From ec16daa4b4fc2a1bfa57b68e1da6ee868b24e45a Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Thu, 19 May 2022 23:29:15 +0300 Subject: [PATCH 59/72] CCharacter: Drop non-const IsAlive() getter --- src/game/server/entities/character.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index b6e9b7616f7..3eee2451afe 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -231,7 +231,6 @@ class CCharacter : public CEntity void SetWeaponGot(int Type, bool Value) { m_Core.m_aWeapons[Type].m_Got = Value; } int GetWeaponAmmo(int Type) { return m_Core.m_aWeapons[Type].m_Ammo; } void SetWeaponAmmo(int Type, int Value) { m_Core.m_aWeapons[Type].m_Ammo = Value; } - bool IsAlive() { return m_Alive; } void SetNinjaActivationDir(vec2 ActivationDir) { m_Core.m_Ninja.m_ActivationDir = ActivationDir; } void SetNinjaActivationTick(int ActivationTick) { m_Core.m_Ninja.m_ActivationTick = ActivationTick; } void SetNinjaCurrentMoveTime(int CurrentMoveTime) { m_Core.m_Ninja.m_CurrentMoveTime = CurrentMoveTime; } From 8ac84948c5292bace3e7c35443b28db4e86af586 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 27 May 2022 02:17:01 +0300 Subject: [PATCH 60/72] Extract server main() to its own file Also extract CServerLogger to own files. --- CMakeLists.txt | 3 + src/engine/server/main.cpp | 196 ++++++++++++++++++++++++ src/engine/server/server.cpp | 227 +--------------------------- src/engine/server/server.h | 1 + src/engine/server/server_logger.cpp | 42 +++++ src/engine/server/server_logger.h | 23 +++ 6 files changed, 268 insertions(+), 224 deletions(-) create mode 100644 src/engine/server/main.cpp create mode 100644 src/engine/server/server_logger.cpp create mode 100644 src/engine/server/server_logger.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 49e2f0e60b6..c8b11ba58c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2283,12 +2283,15 @@ if(SERVER) databases/connection_pool.h databases/mysql.cpp databases/sqlite.cpp + main.cpp name_ban.cpp name_ban.h register.cpp register.h server.cpp server.h + server_logger.cpp + server_logger.h sql_string_helpers.cpp sql_string_helpers.h upnp.cpp diff --git a/src/engine/server/main.cpp b/src/engine/server/main.cpp new file mode 100644 index 00000000000..1d1b37e46a1 --- /dev/null +++ b/src/engine/server/main.cpp @@ -0,0 +1,196 @@ + +#define _WIN32_WINNT 0x0501 + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#if defined(CONF_FAMILY_WINDOWS) +#define WIN32_LEAN_AND_MEAN +#include +#endif + +#include + +volatile sig_atomic_t InterruptSignaled = 0; + +bool IsInterrupted() +{ + return InterruptSignaled; +} + +void HandleSigIntTerm(int Param) +{ + InterruptSignaled = 1; + + // Exit the next time a signal is received + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); +} + +int main(int argc, const char **argv) +{ + CCmdlineFix CmdlineFix(&argc, &argv); + bool Silent = false; + + for(int i = 1; i < argc; i++) + { + if(str_comp("-s", argv[i]) == 0 || str_comp("--silent", argv[i]) == 0) + { + Silent = true; +#if defined(CONF_FAMILY_WINDOWS) + ShowWindow(GetConsoleWindow(), SW_HIDE); +#endif + break; + } + } + + std::vector> vpLoggers; +#if defined(CONF_PLATFORM_ANDROID) + vpLoggers.push_back(std::shared_ptr(log_logger_android())); +#else + if(!Silent) + { + vpLoggers.push_back(std::shared_ptr(log_logger_stdout())); + } +#endif + std::shared_ptr pFutureFileLogger = std::make_shared(); + vpLoggers.push_back(pFutureFileLogger); + std::shared_ptr pFutureConsoleLogger = std::make_shared(); + vpLoggers.push_back(pFutureConsoleLogger); + std::shared_ptr pFutureAssertionLogger = std::make_shared(); + vpLoggers.push_back(pFutureAssertionLogger); + log_set_global_logger(log_logger_collection(std::move(vpLoggers)).release()); + + if(secure_random_init() != 0) + { + dbg_msg("secure", "could not initialize secure RNG"); + return -1; + } + if(MysqlInit() != 0) + { + dbg_msg("mysql", "failed to initialize MySQL library"); + return -1; + } + + signal(SIGINT, HandleSigIntTerm); + signal(SIGTERM, HandleSigIntTerm); + +#if defined(CONF_EXCEPTION_HANDLING) + init_exception_handler(); +#endif + + CServer *pServer = CreateServer(); + IKernel *pKernel = IKernel::Create(); + + // create the components + IEngine *pEngine = CreateEngine("DDNet", pFutureConsoleLogger, 2); + IEngineMap *pEngineMap = CreateEngineMap(); + IGameServer *pGameServer = CreateGameServer(); + IConsole *pConsole = CreateConsole(CFGFLAG_SERVER | CFGFLAG_ECON); + IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_SERVER, argc, argv); + IConfigManager *pConfigManager = CreateConfigManager(); + IEngineAntibot *pEngineAntibot = CreateEngineAntibot(); + + pFutureAssertionLogger->Set(CreateAssertionLogger(pStorage, GAME_NAME)); +#if defined(CONF_EXCEPTION_HANDLING) + char aBuf[IO_MAX_PATH_LENGTH]; + char aBufName[IO_MAX_PATH_LENGTH]; + char aDate[64]; + str_timestamp(aDate, sizeof(aDate)); + str_format(aBufName, sizeof(aBufName), "dumps/" GAME_NAME "-Server_crash_log_%d_%s.RTP", pid(), aDate); + pStorage->GetCompletePath(IStorage::TYPE_SAVE, aBufName, aBuf, sizeof(aBuf)); + set_exception_handler_log_file(aBuf); +#endif + + { + bool RegisterFail = false; + + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pServer); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngine); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineMap); // register as both + RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineMap), false); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pGameServer); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfigManager); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineAntibot); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineAntibot), false); + + if(RegisterFail) + { + delete pKernel; + return -1; + } + } + + pEngine->Init(); + pConfigManager->Init(); + pConsole->Init(); + + // register all console commands + pServer->RegisterCommands(); + + // execute autoexec file + IOHANDLE File = pStorage->OpenFile(AUTOEXEC_SERVER_FILE, IOFLAG_READ, IStorage::TYPE_ALL); + if(File) + { + io_close(File); + pConsole->ExecuteFile(AUTOEXEC_SERVER_FILE); + } + else // fallback + { + pConsole->ExecuteFile(AUTOEXEC_FILE); + } + + // parse the command line arguments + if(argc > 1) + pConsole->ParseArguments(argc - 1, &argv[1]); + + pConsole->Register("sv_test_cmds", "", CFGFLAG_SERVER, CServer::ConTestingCommands, pConsole, "Turns testing commands aka cheats on/off (setting only works in initial config)"); + pConsole->Register("sv_rescue", "", CFGFLAG_SERVER, CServer::ConRescue, pConsole, "Allow /rescue command so players can teleport themselves out of freeze (setting only works in initial config)"); + + log_set_loglevel((LEVEL)g_Config.m_Loglevel); + if(g_Config.m_Logfile[0]) + { + IOHANDLE Logfile = io_open(g_Config.m_Logfile, IOFLAG_WRITE); + if(Logfile) + { + pFutureFileLogger->Set(log_logger_file(Logfile)); + } + else + { + dbg_msg("client", "failed to open '%s' for logging", g_Config.m_Logfile); + } + } + pEngine->SetAdditionalLogger(std::make_unique(pServer)); + + // run the server + dbg_msg("server", "starting..."); + int Ret = pServer->Run(); + + MysqlUninit(); + secure_random_uninit(); + + // free + delete pKernel; + + return Ret; +} diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index afe3fb89880..be97c16c587 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1,8 +1,6 @@ /* (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. */ -#define _WIN32_WINNT 0x0501 - #include "server.h" #include @@ -16,7 +14,6 @@ #include #include -#include #include #include #include @@ -38,7 +35,6 @@ // DDRace #include -#include #include #include @@ -46,14 +42,7 @@ #include "databases/connection_pool.h" #include "register.h" -#if defined(CONF_FAMILY_WINDOWS) -#define WIN32_LEAN_AND_MEAN -#include -#endif - -#include - -volatile sig_atomic_t InterruptSignaled = 0; +extern bool IsInterrupted(); CSnapIDPool::CSnapIDPool() { @@ -275,57 +264,6 @@ void CServerBan::ConBanRegionRange(IConsole::IResult *pResult, void *pUser) ConBanRange(pResult, static_cast(pServerBan)); } -class CServerLogger : public ILogger -{ - CServer *m_pServer; - std::mutex m_PendingLock; - std::vector m_vPending; - std::thread::id m_MainThread; - -public: - CServerLogger(CServer *pServer) : - m_pServer(pServer), - m_MainThread(std::this_thread::get_id()) - { - dbg_assert(pServer != nullptr, "server pointer must not be null"); - } - void Log(const CLogMessage *pMessage) override; - // Must be called from the main thread! - void OnServerDeletion(); -}; - -void CServerLogger::Log(const CLogMessage *pMessage) -{ - m_PendingLock.lock(); - if(m_MainThread == std::this_thread::get_id()) - { - if(!m_vPending.empty()) - { - if(m_pServer) - { - for(const auto &Message : m_vPending) - { - m_pServer->SendLogLine(&Message); - } - } - m_vPending.clear(); - } - m_PendingLock.unlock(); - m_pServer->SendLogLine(pMessage); - } - else - { - m_vPending.push_back(*pMessage); - m_PendingLock.unlock(); - } -} - -void CServerLogger::OnServerDeletion() -{ - dbg_assert(m_MainThread == std::this_thread::get_id(), "CServerLogger::OnServerDeletion not called from the main thread"); - m_pServer = nullptr; -} - // Not thread-safe! class CRconClientLogger : public ILogger { @@ -2887,7 +2825,7 @@ int CServer::Run() PacketWaiting = x > 0 ? net_socket_read_wait(m_NetServer.Socket(), x) : true; } - if(InterruptSignaled) + if(IsInterrupted()) { Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "interrupted"); break; @@ -3763,166 +3701,7 @@ void CServer::SnapSetStaticsize(int ItemType, int Size) m_SnapshotDelta.SetStaticsize(ItemType, Size); } -static CServer *CreateServer() { return new CServer(); } - -void HandleSigIntTerm(int Param) -{ - InterruptSignaled = 1; - - // Exit the next time a signal is received - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); -} - -int main(int argc, const char **argv) -{ - CCmdlineFix CmdlineFix(&argc, &argv); - bool Silent = false; - - for(int i = 1; i < argc; i++) - { - if(str_comp("-s", argv[i]) == 0 || str_comp("--silent", argv[i]) == 0) - { - Silent = true; -#if defined(CONF_FAMILY_WINDOWS) - ShowWindow(GetConsoleWindow(), SW_HIDE); -#endif - break; - } - } - - std::vector> vpLoggers; -#if defined(CONF_PLATFORM_ANDROID) - vpLoggers.push_back(std::shared_ptr(log_logger_android())); -#else - if(!Silent) - { - vpLoggers.push_back(std::shared_ptr(log_logger_stdout())); - } -#endif - std::shared_ptr pFutureFileLogger = std::make_shared(); - vpLoggers.push_back(pFutureFileLogger); - std::shared_ptr pFutureConsoleLogger = std::make_shared(); - vpLoggers.push_back(pFutureConsoleLogger); - std::shared_ptr pFutureAssertionLogger = std::make_shared(); - vpLoggers.push_back(pFutureAssertionLogger); - log_set_global_logger(log_logger_collection(std::move(vpLoggers)).release()); - - if(secure_random_init() != 0) - { - dbg_msg("secure", "could not initialize secure RNG"); - return -1; - } - if(MysqlInit() != 0) - { - dbg_msg("mysql", "failed to initialize MySQL library"); - return -1; - } - - signal(SIGINT, HandleSigIntTerm); - signal(SIGTERM, HandleSigIntTerm); - -#if defined(CONF_EXCEPTION_HANDLING) - init_exception_handler(); -#endif - - CServer *pServer = CreateServer(); - IKernel *pKernel = IKernel::Create(); - - // create the components - IEngine *pEngine = CreateEngine("DDNet", pFutureConsoleLogger, 2); - IEngineMap *pEngineMap = CreateEngineMap(); - IGameServer *pGameServer = CreateGameServer(); - IConsole *pConsole = CreateConsole(CFGFLAG_SERVER | CFGFLAG_ECON); - IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_SERVER, argc, argv); - IConfigManager *pConfigManager = CreateConfigManager(); - IEngineAntibot *pEngineAntibot = CreateEngineAntibot(); - - pFutureAssertionLogger->Set(CreateAssertionLogger(pStorage, GAME_NAME)); -#if defined(CONF_EXCEPTION_HANDLING) - char aBuf[IO_MAX_PATH_LENGTH]; - char aBufName[IO_MAX_PATH_LENGTH]; - char aDate[64]; - str_timestamp(aDate, sizeof(aDate)); - str_format(aBufName, sizeof(aBufName), "dumps/" GAME_NAME "-Server_crash_log_%d_%s.RTP", pid(), aDate); - pStorage->GetCompletePath(IStorage::TYPE_SAVE, aBufName, aBuf, sizeof(aBuf)); - set_exception_handler_log_file(aBuf); -#endif - - { - bool RegisterFail = false; - - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pServer); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngine); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineMap); // register as both - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineMap), false); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pGameServer); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfigManager); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineAntibot); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineAntibot), false); - - if(RegisterFail) - { - delete pKernel; - return -1; - } - } - - pEngine->Init(); - pConfigManager->Init(); - pConsole->Init(); - - // register all console commands - pServer->RegisterCommands(); - - // execute autoexec file - IOHANDLE File = pStorage->OpenFile(AUTOEXEC_SERVER_FILE, IOFLAG_READ, IStorage::TYPE_ALL); - if(File) - { - io_close(File); - pConsole->ExecuteFile(AUTOEXEC_SERVER_FILE); - } - else // fallback - { - pConsole->ExecuteFile(AUTOEXEC_FILE); - } - - // parse the command line arguments - if(argc > 1) - pConsole->ParseArguments(argc - 1, &argv[1]); - - pConsole->Register("sv_test_cmds", "", CFGFLAG_SERVER, CServer::ConTestingCommands, pConsole, "Turns testing commands aka cheats on/off (setting only works in initial config)"); - pConsole->Register("sv_rescue", "", CFGFLAG_SERVER, CServer::ConRescue, pConsole, "Allow /rescue command so players can teleport themselves out of freeze (setting only works in initial config)"); - - log_set_loglevel((LEVEL)g_Config.m_Loglevel); - if(g_Config.m_Logfile[0]) - { - IOHANDLE Logfile = io_open(g_Config.m_Logfile, IOFLAG_WRITE); - if(Logfile) - { - pFutureFileLogger->Set(log_logger_file(Logfile)); - } - else - { - dbg_msg("client", "failed to open '%s' for logging", g_Config.m_Logfile); - } - } - pEngine->SetAdditionalLogger(std::make_unique(pServer)); - - // run the server - dbg_msg("server", "starting..."); - int Ret = pServer->Run(); - - MysqlUninit(); - secure_random_uninit(); - - // free - delete pKernel; - - return Ret; -} +CServer *CreateServer() { return new CServer(); } // DDRace diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 6f417c85838..7ba34816fc7 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -487,4 +487,5 @@ class CServer : public IServer #endif }; +extern CServer *CreateServer(); #endif diff --git a/src/engine/server/server_logger.cpp b/src/engine/server/server_logger.cpp new file mode 100644 index 00000000000..d8de13b9e76 --- /dev/null +++ b/src/engine/server/server_logger.cpp @@ -0,0 +1,42 @@ +#include "server_logger.h" + +#include "server.h" + +CServerLogger::CServerLogger(CServer *pServer) : + m_pServer(pServer), + m_MainThread(std::this_thread::get_id()) +{ + dbg_assert(pServer != nullptr, "server pointer must not be null"); +} + +void CServerLogger::Log(const CLogMessage *pMessage) +{ + m_PendingLock.lock(); + if(m_MainThread == std::this_thread::get_id()) + { + if(!m_vPending.empty()) + { + if(m_pServer) + { + for(const auto &Message : m_vPending) + { + m_pServer->SendLogLine(&Message); + } + } + m_vPending.clear(); + } + m_PendingLock.unlock(); + m_pServer->SendLogLine(pMessage); + } + else + { + m_vPending.push_back(*pMessage); + m_PendingLock.unlock(); + } +} + +void CServerLogger::OnServerDeletion() +{ + dbg_assert(m_MainThread == std::this_thread::get_id(), "CServerLogger::OnServerDeletion not called from the main thread"); + m_pServer = nullptr; +} diff --git a/src/engine/server/server_logger.h b/src/engine/server/server_logger.h new file mode 100644 index 00000000000..86406d3c0b0 --- /dev/null +++ b/src/engine/server/server_logger.h @@ -0,0 +1,23 @@ +#ifndef ENGINE_SERVER_SERVER_LOGGER_H +#define ENGINE_SERVER_SERVER_LOGGER_H +#include + +#include + +class CServer; + +class CServerLogger : public ILogger +{ + CServer *m_pServer = nullptr; + std::mutex m_PendingLock; + std::vector m_vPending; + std::thread::id m_MainThread; + +public: + CServerLogger(CServer *pServer); + void Log(const CLogMessage *pMessage) override; + // Must be called from the main thread! + void OnServerDeletion(); +}; + +#endif // ENGINE_SERVER_SERVER_LOGGER_H From 670f2841949e738912d49d2764fe27c1d8d6e3fe Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 27 May 2022 02:21:14 +0300 Subject: [PATCH 61/72] Use GAME_NAME definition for engine initialization --- src/engine/server/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/server/main.cpp b/src/engine/server/main.cpp index 1d1b37e46a1..68d3458d6eb 100644 --- a/src/engine/server/main.cpp +++ b/src/engine/server/main.cpp @@ -101,7 +101,7 @@ int main(int argc, const char **argv) IKernel *pKernel = IKernel::Create(); // create the components - IEngine *pEngine = CreateEngine("DDNet", pFutureConsoleLogger, 2); + IEngine *pEngine = CreateEngine(GAME_NAME, pFutureConsoleLogger, 2); IEngineMap *pEngineMap = CreateEngineMap(); IGameServer *pGameServer = CreateGameServer(); IConsole *pConsole = CreateConsole(CFGFLAG_SERVER | CFGFLAG_ECON); From 6daeeaa06cdac1eec3c192ba8e6b43c5d14a67ec Mon Sep 17 00:00:00 2001 From: Rafael Fontenelle Date: Mon, 15 Aug 2022 10:11:47 -0300 Subject: [PATCH 62/72] Update brazilian_portuguese.txt --- data/languages/brazilian_portuguese.txt | 80 ++++++++++++------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/data/languages/brazilian_portuguese.txt b/data/languages/brazilian_portuguese.txt index cdeee32a2cb..5dc12c5ebc7 100644 --- a/data/languages/brazilian_portuguese.txt +++ b/data/languages/brazilian_portuguese.txt @@ -1,4 +1,4 @@ -##### authors ##### +##### authors ##### #originally created by: # slinack #modified by: @@ -63,7 +63,7 @@ All == Todos Are you sure that you want to delete the demo? -== Tem certeza que deseja deletar o demo? +== Tem certeza que deseja deletar a demo? Are you sure that you want to quit? == Você tem certeza que deseja sair? @@ -135,7 +135,7 @@ Delete demo == Deletar demo Demo details -== Detalhes do demo +== Detalhes da demo Demofile: %s == Demo: %s @@ -487,10 +487,10 @@ Type == Tipo Unable to delete the demo -== Não foi possível deletar o demo +== Não foi possível deletar a demo Unable to rename the demo -== Não foi possível renomear o demo +== Não foi possível renomear a demo Use sounds == Usar sons @@ -1471,106 +1471,106 @@ Extras == Extras Preparing demo playback -== +== Preparando reprodução da demo Connected -== +== Conectado Loading map file from storage -== +== Carregando arquivo de mapa do armazenamento Why are you slowmo replaying to read this? -== +== Por que você está respondendo em câmera lenta para ler isso? Initializing components -== +== Inicializando componentes Initializing assets -== +== Inicializando ativos Initializing map logic -== +== Inicializando lógica de mapa Sending initial client info -== +== Enviando info iniciais do cliente Uploading map data to GPU -== +== Carregando dados de mapa para GPU Getting game info -== +== Obtendo info do jogo Requesting to join the game -== +== Solicitando entrada no jogo Loading menu images -== +== Carregando imagens de menu Loading demo files -== +== Carregando arquivos de demo Loading ghost files -== +== Carregando arquivos de fantasma Loading skin files -== +== Carregando arquivos de skins Appearance -== +== Aparência Name Plate -== +== Placa de nome Hook Collisions -== +== Colisões de gancho Show health, shields and ammo -== +== Mostrar saúde, escudos e munição DDRace HUD -== +== HUD do DDRace Show client IDs in scoreboard -== +== Mostrar IDs de cliente no placar Show DDRace HUD -== +== Mostrar HUD do DDRace Show jumps indicator -== +== Mostrar indicador de pulos Show hook strength indicator -== +== Mostrar indicador de força do gancho Hook collision line -== +== Linha de colisão do gancho Hook collision line width -== +== Largura da linha de colisão do gancho Hook collision line opacity -== +== Opacidade da linha de colisão do gancho Colors of the hook collision line, in case of a possible collision with: -== +== Cores da linha de colisão do gancho, no caso de uma possível colisão com: Your movements are not taken into account when calculating the line colors -== +== Seus movimentos não são levados em conta ao calcular as cores de linha Nothing hookable -== +== Nada enganchável Something hookable -== +== Alguma coisa enganchável A Tee -== +== Um tee Loading assets -== +== Carregando ativos Loading race demo files -== +== Carregando arquivos de demo de corrida Loading sound files -== +== Carregando arquivos de som From 82c86cec6bca64ac4479cf2679b99e684288751a Mon Sep 17 00:00:00 2001 From: archimede67 Date: Mon, 15 Aug 2022 16:36:02 +0200 Subject: [PATCH 63/72] Better words --- data/languages/french.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/languages/french.txt b/data/languages/french.txt index bd049f0e545..c75b0078c5c 100644 --- a/data/languages/french.txt +++ b/data/languages/french.txt @@ -1536,7 +1536,7 @@ Sending initial client info == Envoi des informations initiales du client Uploading map data to GPU -== Téléchargement des données de la map vers le GPU +== Transfert des données de la map vers le GPU Loading menu images == Chargement des images de menu @@ -1578,4 +1578,4 @@ Something hookable == Quelque chose d'accrochable Loading race demo files -== Chargement des fichiers de demo de la course +== Chargement des fichiers de demo de course From f0c74f72baf7d179f1795d4c208f056139327a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 10 Aug 2022 23:00:25 +0200 Subject: [PATCH 64/72] Smooth console completion scrolling --- src/game/client/components/console.cpp | 41 ++++++++++++++++---------- src/game/client/components/console.h | 1 + src/game/client/ui.cpp | 31 +++++++++++++++++++ src/game/client/ui.h | 4 +++ 4 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index a91fc4980c8..cec8bea2068 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -147,6 +147,7 @@ void CGameConsole::CInstance::ClearHistory() void CGameConsole::CInstance::Reset() { m_CompletionRenderOffset = 0.0f; + m_CompletionRenderOffsetChange = 0.0f; } void CGameConsole::CInstance::ExecuteLine(const char *pLine) @@ -533,25 +534,29 @@ struct CCompletionOptionRenderInfo CTextCursor m_Cursor; const char *m_pCurrentCmd; int m_WantedCompletion; - int m_EnumCount; float m_Offset; + float *m_pOffsetChange; float m_Width; + float m_TotalWidth; }; void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser) { CCompletionOptionRenderInfo *pInfo = static_cast(pUser); - if(pInfo->m_EnumCount == pInfo->m_WantedCompletion) + if(Index == pInfo->m_WantedCompletion) { - float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1, -1.0f); - pInfo->m_pSelf->Graphics()->DrawRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, ColorRGBA(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f), IGraphics::CORNER_ALL, pInfo->m_Cursor.m_FontSize / 3.f); + float TextWidth = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1, -1.0f); + const CUIRect Rect = {pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, TextWidth + 5.f, pInfo->m_Cursor.m_FontSize + 4.f}; + Rect.Draw(ColorRGBA(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f), IGraphics::CORNER_ALL, pInfo->m_Cursor.m_FontSize / 3.f); // scroll when out of sight - if(pInfo->m_Cursor.m_X < 3.0f) - pInfo->m_Offset = 0.0f; - else if(pInfo->m_Cursor.m_X + tw > pInfo->m_Width) - pInfo->m_Offset -= pInfo->m_Width / 2; + const bool MoveLeft = Rect.x - *pInfo->m_pOffsetChange < 0.0f; + const bool MoveRight = Rect.x + Rect.w - *pInfo->m_pOffsetChange > pInfo->m_Width; + if(MoveLeft && !MoveRight) + *pInfo->m_pOffsetChange -= -Rect.x + pInfo->m_Width / 4.0f; + else if(!MoveLeft && MoveRight) + *pInfo->m_pOffsetChange += Rect.x + Rect.w - pInfo->m_Width + pInfo->m_Width / 4.0f; pInfo->m_pSelf->TextRender()->TextColor(0.05f, 0.05f, 0.05f, 1); pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1); @@ -576,8 +581,8 @@ void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, v } } - pInfo->m_EnumCount++; pInfo->m_Cursor.m_X += 7.0f; + pInfo->m_TotalWidth = pInfo->m_Cursor.m_X + pInfo->m_Offset; } void CGameConsole::OnRender() @@ -761,28 +766,30 @@ void CGameConsole::OnRender() CCompletionOptionRenderInfo Info; Info.m_pSelf = this; Info.m_WantedCompletion = pConsole->m_CompletionChosen; - Info.m_EnumCount = 0; Info.m_Offset = pConsole->m_CompletionRenderOffset; + Info.m_pOffsetChange = &pConsole->m_CompletionRenderOffsetChange; Info.m_Width = Screen.w; + Info.m_TotalWidth = 0.0f; Info.m_pCurrentCmd = pConsole->m_aCompletionBuffer; - TextRender()->SetCursor(&Info.m_Cursor, InitialX + Info.m_Offset, InitialY + RowHeight + 2.0f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END); + TextRender()->SetCursor(&Info.m_Cursor, InitialX - Info.m_Offset, InitialY + RowHeight + 2.0f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END); Info.m_Cursor.m_LineWidth = std::numeric_limits::max(); - m_pConsole->PossibleCommands(Info.m_pCurrentCmd, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL && Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info); + const int NumCommands = m_pConsole->PossibleCommands(Info.m_pCurrentCmd, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL && Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info); pConsole->m_CompletionRenderOffset = Info.m_Offset; - if(Info.m_EnumCount <= 0 && pConsole->m_IsCommand) + if(NumCommands <= 0 && pConsole->m_IsCommand) { const bool TuningCompletion = IsTuningCommandPrefix(Info.m_pCurrentCmd); + int NumArguments = 0; if(TuningCompletion) { Info.m_WantedCompletion = pConsole->m_CompletionChosenArgument; - Info.m_EnumCount = 0; + Info.m_TotalWidth = 0.0f; Info.m_pCurrentCmd = pConsole->m_aCompletionBufferArgument; - m_pClient->m_aTuning[g_Config.m_ClDummy].PossibleTunings(Info.m_pCurrentCmd, PossibleCommandsRenderCallback, &Info); + NumArguments = m_pClient->m_aTuning[g_Config.m_ClDummy].PossibleTunings(Info.m_pCurrentCmd, PossibleCommandsRenderCallback, &Info); pConsole->m_CompletionRenderOffset = Info.m_Offset; } - if(Info.m_EnumCount <= 0 && pConsole->m_IsCommand) + if(NumArguments <= 0 && pConsole->m_IsCommand) { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "Help: %s ", pConsole->m_aCommandHelp); @@ -792,6 +799,8 @@ void CGameConsole::OnRender() TextRender()->TextEx(&Info.m_Cursor, aBuf, -1); } } + + UI()->DoSmoothScrollLogic(&pConsole->m_CompletionRenderOffset, &pConsole->m_CompletionRenderOffsetChange, Info.m_Width, Info.m_TotalWidth); } pConsole->m_BacklogLock.lock(); diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index e13f34472b3..17f52d94007 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -50,6 +50,7 @@ class CGameConsole : public CComponent int m_CompletionChosenArgument; int m_CompletionFlagmask; float m_CompletionRenderOffset; + float m_CompletionRenderOffsetChange; char m_aUser[32]; bool m_UserGot; diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 5b72d97f748..f167410029d 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -83,6 +84,7 @@ float CUI::ms_FontmodHeight = 0.8f; void CUI::Init(IKernel *pKernel) { + m_pClient = pKernel->RequestInterface(); m_pGraphics = pKernel->RequestInterface(); m_pInput = pKernel->RequestInterface(); m_pTextRender = pKernel->RequestInterface(); @@ -372,6 +374,35 @@ int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float * return 1; } +void CUI::DoSmoothScrollLogic(float *pScrollOffset, float *pScrollOffsetChange, float ViewPortSize, float TotalSize, float ScrollSpeed) +{ + // instant scrolling if distance too long + if(absolute(*pScrollOffsetChange) > ViewPortSize) + { + *pScrollOffset += *pScrollOffsetChange; + *pScrollOffsetChange = 0.0f; + } + // smooth scrolling + if(*pScrollOffsetChange) + { + const float Delta = *pScrollOffsetChange * clamp(Client()->RenderFrameTime() * ScrollSpeed, 0.0f, 1.0f); + *pScrollOffset += Delta; + *pScrollOffsetChange -= Delta; + } + // clamp to first item + if(*pScrollOffset < 0.0f) + { + *pScrollOffset = 0.0f; + *pScrollOffsetChange = 0.0f; + } + // clamp to last item + if(TotalSize > ViewPortSize && *pScrollOffset > TotalSize - ViewPortSize) + { + *pScrollOffset = TotalSize - ViewPortSize; + *pScrollOffsetChange = 0.0f; + } +} + float CUI::DoTextLabel(float x, float y, float w, float h, const char *pText, float Size, int Align, const SLabelProperties &LabelProps) { float AlignedSize = 0; diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 4415d0f5e86..9c314fe4a50 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -12,6 +12,7 @@ #include #include +class IClient; class IGraphics; class IKernel; @@ -203,6 +204,7 @@ class CUI std::vector m_vClips; void UpdateClipping(); + IClient *m_pClient; IGraphics *m_pGraphics; IInput *m_pInput; ITextRender *m_pTextRender; @@ -218,6 +220,7 @@ class CUI void Init(IKernel *pKernel); void InitInputs(IInput::CEvent *pInputEventsArray, int *pInputEventCount); + IClient *Client() const { return m_pClient; } IGraphics *Graphics() const { return m_pGraphics; } IInput *Input() const { return m_pInput; } ITextRender *TextRender() const { return m_pTextRender; } @@ -306,6 +309,7 @@ class CUI int DoButtonLogic(const void *pID, int Checked, const CUIRect *pRect); int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY); + void DoSmoothScrollLogic(float *pScrollOffset, float *pScrollOffsetChange, float ViewPortSize, float TotalSize, float ScrollSpeed = 10.0f); float DoTextLabel(float x, float y, float w, float h, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}); void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}); From f0b0d4c163aa51f8c999abd75f25a609074331f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 16 Aug 2022 17:35:47 +0200 Subject: [PATCH 65/72] Improve "couldn't open..." error messages by listing target --- src/game/client/components/countryflags.cpp | 7 +++++-- src/game/client/components/menus_demo.cpp | 2 +- src/game/client/components/menus_settings.cpp | 20 +++++++++++-------- .../components/menus_settings_assets.cpp | 2 +- src/game/client/components/menus_start.cpp | 15 ++++++++------ 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/game/client/components/countryflags.cpp b/src/game/client/components/countryflags.cpp index c1f10c6fba8..9f222ddf7bf 100644 --- a/src/game/client/components/countryflags.cpp +++ b/src/game/client/components/countryflags.cpp @@ -15,10 +15,13 @@ void CCountryFlags::LoadCountryflagsIndexfile() { - IOHANDLE File = Storage()->OpenFile("countryflags/index.txt", IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL); + const char *pFilename = "countryflags/index.txt"; + IOHANDLE File = Storage()->OpenFile(pFilename, IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL); if(!File) { - Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", "couldn't open index file"); + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "couldn't open index file '%s'", pFilename); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf); return; } diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 69410fc553b..adac73fc81b 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -1260,7 +1260,7 @@ void CMenus::RenderDemoList(CUIRect MainView) Storage()->CreateFolder("demos", IStorage::TYPE_SAVE); if(!open_file(aBuf)) { - dbg_msg("menus", "couldn't open file"); + dbg_msg("menus", "couldn't open file '%s'", aBuf); } } diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index e9649071835..70c1780525d 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -201,7 +201,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) Storage()->GetCompletePath(IStorage::TYPE_SAVE, CONFIG_FILE, aBuf, sizeof(aBuf)); if(!open_file(aBuf)) { - dbg_msg("menus", "couldn't open file"); + dbg_msg("menus", "couldn't open file '%s'", aBuf); } } @@ -216,7 +216,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) Storage()->GetCompletePath(IStorage::TYPE_SAVE, "", aBuf, sizeof(aBuf)); if(!open_file(aBuf)) { - dbg_msg("menus", "couldn't open file"); + dbg_msg("menus", "couldn't open file '%s'", aBuf); } } @@ -233,7 +233,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) Storage()->CreateFolder("themes", IStorage::TYPE_SAVE); if(!open_file(aBuf)) { - dbg_msg("menus", "couldn't open file"); + dbg_msg("menus", "couldn't open file '%s'", aBuf); } } @@ -749,9 +749,10 @@ void CMenus::RenderSettingsTee(CUIRect MainView) static CButtonContainer s_SkinDBDirID; if(DoButton_Menu(&s_SkinDBDirID, Localize("Skin Database"), 0, &SkinDB)) { - if(!open_link("https://ddnet.tw/skins/")) + const char *pLink = "https://ddnet.tw/skins/"; + if(!open_link(pLink)) { - dbg_msg("menus", "couldn't open link"); + dbg_msg("menus", "couldn't open link '%s'", pLink); } } @@ -766,7 +767,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) Storage()->CreateFolder("skins", IStorage::TYPE_SAVE); if(!open_file(aBuf)) { - dbg_msg("menus", "couldn't open file"); + dbg_msg("menus", "couldn't open file '%s'", aBuf); } } @@ -1863,10 +1864,13 @@ class CLanguage void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, std::vector &vLanguages) { - IOHANDLE File = pStorage->OpenFile("languages/index.txt", IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL); + const char *pFilename = "languages/index.txt"; + IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL); if(!File) { - pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "couldn't open index file"); + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "couldn't open index file '%s'", pFilename); + pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf); return; } diff --git a/src/game/client/components/menus_settings_assets.cpp b/src/game/client/components/menus_settings_assets.cpp index 472b781e6da..f851b0315b7 100644 --- a/src/game/client/components/menus_settings_assets.cpp +++ b/src/game/client/components/menus_settings_assets.cpp @@ -689,7 +689,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView) Storage()->CreateFolder(aBufFull, IStorage::TYPE_SAVE); if(!open_file(aBuf)) { - dbg_msg("menus", "couldn't open file"); + dbg_msg("menus", "couldn't open file '%s'", aBuf); } } diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index f1f436af781..bdae8ec6979 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -44,9 +44,10 @@ void CMenus::RenderStartMenu(CUIRect MainView) static CButtonContainer s_DiscordButton; if(DoButton_Menu(&s_DiscordButton, Localize("Discord"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { - if(!open_link(Localize("https://ddnet.tw/discord"))) + const char *pLink = Localize("https://ddnet.tw/discord"); + if(!open_link(pLink)) { - dbg_msg("menus", "couldn't open link"); + dbg_msg("menus", "couldn't open link '%s'", pLink); } m_DoubleClickIndex = -1; } @@ -56,9 +57,10 @@ void CMenus::RenderStartMenu(CUIRect MainView) static CButtonContainer s_LearnButton; if(DoButton_Menu(&s_LearnButton, Localize("Learn"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { - if(!open_link(Localize("https://wiki.ddnet.tw/"))) + const char *pLink = Localize("https://wiki.ddnet.tw/"); + if(!open_link(pLink)) { - dbg_msg("menus", "couldn't open link"); + dbg_msg("menus", "couldn't open link '%s'", pLink); } m_DoubleClickIndex = -1; } @@ -94,9 +96,10 @@ void CMenus::RenderStartMenu(CUIRect MainView) static CButtonContainer s_WebsiteButton; if(DoButton_Menu(&s_WebsiteButton, Localize("Website"), 0, &Button, 0, IGraphics::CORNER_ALL, 5.0f, 0.0f, vec4(0.0f, 0.0f, 0.0f, 0.5f), vec4(0.0f, 0.0f, 0.0f, 0.25f))) { - if(!open_link("https://ddnet.tw/")) + const char *pLink = "https://ddnet.tw/"; + if(!open_link(pLink)) { - dbg_msg("menus", "couldn't open link"); + dbg_msg("menus", "couldn't open link '%s'", pLink); } m_DoubleClickIndex = -1; } From d35a6747e52c83a92b8ab5c42c5bfedd8b57db5e Mon Sep 17 00:00:00 2001 From: CHaBek <44938972+cwh7435@users.noreply.github.com> Date: Wed, 17 Aug 2022 11:06:34 +0900 Subject: [PATCH 66/72] Update Korean translations by CHaBek --- data/languages/korean.txt | 71 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/data/languages/korean.txt b/data/languages/korean.txt index 8574d4bbbe2..949b9a30ef8 100644 --- a/data/languages/korean.txt +++ b/data/languages/korean.txt @@ -10,6 +10,7 @@ # 2022-05-16 CHaBek # 2022-06-17 CHaBek # 2022-07-05 CHaBek +# 2022-08-17 CHaBek ##### /authors ##### ##### translated strings ##### @@ -1461,106 +1462,106 @@ Extras == 기타 Preparing demo playback -== +== 데모 재생 준비 중 Connected -== +== 연결됨 Loading map file from storage -== +== 저장공간에서 맵 파일 로딩 중 Why are you slowmo replaying to read this? -== +== 왜 이것을 슬로우 모션으로 보려고 하십니까? Initializing components -== +== 구성요소 초기화 중 Initializing assets -== +== 에셋 초기화 중 Initializing map logic -== +== 맵 로직 초기화 중 Sending initial client info -== +== 초기 클라이언트 정보 전송 중 Uploading map data to GPU -== +== 맵 데이터를 GPU에 업로드 중 Getting game info -== +== 게임 정보 가져오는 중 Requesting to join the game -== +== 게임 참가 요청 중 Loading menu images -== +== 메뉴 이미지 로딩 중 Loading demo files -== +== 데모 파일 로딩 중 Loading ghost files -== +== 고스트 파일 로딩 중 Loading skin files -== +== 스킨 파일 로딩 중 Appearance -== +== 표시 Name Plate -== +== 이름 표시 Hook Collisions -== +== 갈고리 보조선 Show health, shields and ammo -== +== 체력과 방패, 탄약 표시 DDRace HUD -== +== DDRace HUD Show client IDs in scoreboard -== +== 점수판에 클라이언트 ID 표시 Show DDRace HUD -== +== DDRace HUD 표시 Show jumps indicator -== +== 점프 상태 표시 Show hook strength indicator -== +== 갈고리 세기 표시 Hook collision line -== +== 갈고리 보조선 Hook collision line width -== +== 갈고리 보조선 폭 Hook collision line opacity -== +== 갈고리 보조선 불투명도 Colors of the hook collision line, in case of a possible collision with: -== +== 갈고리 보조선 색상: Your movements are not taken into account when calculating the line colors -== +== 색상 계산에 이동은 고려하지 않습니다. Nothing hookable -== +== 갈고리 불가 Something hookable -== +== 갈고리 가능 A Tee -== +== Tee 대상 Loading assets -== +== 에셋 로딩 중 Loading race demo files -== +== 레이스 데모 파일 로딩 중 Loading sound files -== +== 소리 파일 로딩 중 From b580b83d318696b3f7ef757b29ab03730da7ef41 Mon Sep 17 00:00:00 2001 From: Patiga Date: Thu, 18 Aug 2022 12:51:22 +0200 Subject: [PATCH 67/72] List symlinks in list_dir This functionality was lost in 082e26d5b In my case I have a lot of symlinks in the maps folder (Downloads, ddnet-maps, map_archive) --- src/base/system.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index 2067d3d3d70..a7e94447bb2 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -2095,7 +2095,7 @@ void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user) { WideCharToMultiByte(CP_UTF8, 0, finddata.cFileName, -1, buffer2, sizeof(buffer2), NULL, NULL); str_copy(buffer + length, buffer2, (int)sizeof(buffer) - length); - if(cb(buffer2, (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0, type, user)) + if(cb(buffer2, (finddata.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY || FILE_ATTRIBUTE_REPARSE_POINT)) != 0, type, user)) break; } while(FindNextFileW(handle, &finddata)); @@ -2115,7 +2115,7 @@ void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user) while((entry = readdir(d)) != NULL) { str_copy(buffer + length, entry->d_name, (int)sizeof(buffer) - length); - if(cb(entry->d_name, entry->d_type == DT_UNKNOWN ? fs_is_dir(buffer) : entry->d_type == DT_DIR, type, user)) + if(cb(entry->d_name, entry->d_type == DT_UNKNOWN ? fs_is_dir(buffer) : entry->d_type == DT_DIR || entry->d_type == DT_LNK, type, user)) break; } @@ -2155,7 +2155,7 @@ void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int t info.m_TimeCreated = filetime_to_unixtime(&finddata.ftCreationTime); info.m_TimeModified = filetime_to_unixtime(&finddata.ftLastWriteTime); - if(cb(&info, (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0, type, user)) + if(cb(&info, (finddata.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY || FILE_ATTRIBUTE_REPARSE_POINT)) != 0, type, user)) break; } while(FindNextFileW(handle, &finddata)); @@ -2184,7 +2184,7 @@ void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int t info.m_TimeCreated = created; info.m_TimeModified = modified; - if(cb(&info, entry->d_type == DT_UNKNOWN ? fs_is_dir(buffer) : entry->d_type == DT_DIR, type, user)) + if(cb(&info, entry->d_type == DT_UNKNOWN ? fs_is_dir(buffer) : entry->d_type == DT_DIR || entry->d_type == DT_LNK, type, user)) break; } From 29a3baaa75dc5733a4fe37b3adaf5204ebb6a277 Mon Sep 17 00:00:00 2001 From: Corantin H Date: Thu, 18 Aug 2022 01:07:16 +0200 Subject: [PATCH 68/72] Editor: added the possibility to duplicate layers --- src/game/editor/editor.cpp | 18 +++++++++++++++++- src/game/editor/editor.h | 24 +++++++++++++++++++++++- src/game/editor/layer_quads.cpp | 12 ++++++++++++ src/game/editor/layer_sounds.cpp | 12 ++++++++++++ src/game/editor/layer_tiles.cpp | 32 ++++++++++++++++++++++++++++++++ src/game/editor/popups.cpp | 15 +++++++++++++++ 6 files changed, 111 insertions(+), 2 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 263610eb53e..cd73cbd5665 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -212,6 +212,17 @@ void CLayerGroup::DeleteLayer(int Index) m_pMap->m_Modified = true; } +void CLayerGroup::DuplicateLayer(int Index) +{ + if(Index < 0 || Index >= (int)m_vpLayers.size()) + return; + + auto *pDup = m_vpLayers[Index]->Duplicate(); + m_vpLayers.insert(m_vpLayers.begin() + Index + 1, pDup); + + m_pMap->m_Modified = true; +} + void CLayerGroup::GetSize(float *pWidth, float *pHeight) const { *pWidth = 0; @@ -745,6 +756,11 @@ int CEditor::FindSelectedQuadIndex(int Index) const return -1; } +bool CEditor::IsSpecialLayer(const CLayer *pLayer) const +{ + return m_Map.m_pGameLayer == pLayer || m_Map.m_pTeleLayer == pLayer || m_Map.m_pSpeedupLayer == pLayer || m_Map.m_pFrontLayer == pLayer || m_Map.m_pSwitchLayer == pLayer || m_Map.m_pTuneLayer == pLayer; +} + void CEditor::CallbackOpenMap(const char *pFileName, int StorageType, void *pUser) { CEditor *pEditor = (CEditor *)pUser; @@ -3480,7 +3496,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) else s_LayerPopupContext.m_vpLayers.clear(); - UiInvokePopupMenu(&s_LayerPopupContext, 0, UI()->MouseX(), UI()->MouseY(), 120, 300, PopupLayer, &s_LayerPopupContext); + UiInvokePopupMenu(&s_LayerPopupContext, 0, UI()->MouseX(), UI()->MouseY(), 120, 320, PopupLayer, &s_LayerPopupContext); } } diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index a4df6e923a3..604aa7ec2aa 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -127,6 +127,17 @@ class CLayer m_BrushRefCount = 0; } + CLayer(const CLayer &Other) + { + str_copy(m_aName, Other.m_aName, sizeof(m_aName)); + m_Flags = Other.m_Flags; + m_pEditor = Other.m_pEditor; + m_Type = Other.m_Type; + m_BrushRefCount = 0; + m_Visible = true; + m_Readonly = false; + } + virtual ~CLayer() { } @@ -147,6 +158,8 @@ class CLayer virtual void ModifyEnvelopeIndex(INDEX_MODIFY_FUNC pfnFunc) {} virtual void ModifySoundIndex(INDEX_MODIFY_FUNC pfnFunc) {} + virtual CLayer *Duplicate() const = 0; + virtual void GetSize(float *pWidth, float *pHeight) { *pWidth = 0; @@ -159,7 +172,6 @@ class CLayer bool m_Readonly; bool m_Visible; - int m_BrushRefCount; }; @@ -198,6 +210,7 @@ class CLayerGroup void GetSize(float *pWidth, float *pHeight) const; void DeleteLayer(int Index); + void DuplicateLayer(int Index); int SwapLayers(int Index0, int Index1); bool IsEmpty() const @@ -554,6 +567,7 @@ class CLayerTiles : public CLayer public: CLayerTiles(int w, int h); + CLayerTiles(const CLayerTiles &Other); ~CLayerTiles(); virtual CTile GetTile(int x, int y); @@ -580,6 +594,8 @@ class CLayerTiles : public CLayer void BrushFlipY() override; void BrushRotate(float Amount) override; + CLayer *Duplicate() const override; + virtual void ShowInfo(); int RenderProperties(CUIRect *pToolbox) override; @@ -637,6 +653,7 @@ class CLayerQuads : public CLayer { public: CLayerQuads(); + CLayerQuads(const CLayerQuads &Other); ~CLayerQuads(); void Render(bool QuadPicker = false) override; @@ -655,6 +672,7 @@ class CLayerQuads : public CLayer void ModifyEnvelopeIndex(INDEX_MODIFY_FUNC pfnFunc) override; void GetSize(float *pWidth, float *pHeight) override; + CLayer *Duplicate() const override; int m_Image; std::vector m_vQuads; @@ -842,6 +860,7 @@ class CEditor : public IEditor void DeleteSelectedQuads(); bool IsQuadSelected(int Index) const; int FindSelectedQuadIndex(int Index) const; + bool IsSpecialLayer(const CLayer *pLayer) const; float ScaleFontSize(char *pText, int TextSize, float FontSize, int Width); int DoProperties(CUIRect *pToolbox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color = ColorRGBA(1, 1, 1, 0.5f)); @@ -1318,6 +1337,7 @@ class CLayerSounds : public CLayer { public: CLayerSounds(); + CLayerSounds(const CLayerSounds &Other); ~CLayerSounds(); void Render(bool Tileset = false) override; @@ -1332,6 +1352,8 @@ class CLayerSounds : public CLayer void ModifyEnvelopeIndex(INDEX_MODIFY_FUNC pfnFunc) override; void ModifySoundIndex(INDEX_MODIFY_FUNC pfnFunc) override; + CLayer *Duplicate() const override; + int m_Sound; std::vector m_vSources; }; diff --git a/src/game/editor/layer_quads.cpp b/src/game/editor/layer_quads.cpp index 67774d21e81..c5854e95ced 100644 --- a/src/game/editor/layer_quads.cpp +++ b/src/game/editor/layer_quads.cpp @@ -14,6 +14,13 @@ CLayerQuads::CLayerQuads() m_Image = -1; } +CLayerQuads::CLayerQuads(const CLayerQuads &Other) : + CLayer(Other) +{ + m_Image = Other.m_Image; + m_vQuads = Other.m_vQuads; +} + CLayerQuads::~CLayerQuads() = default; void CLayerQuads::Render(bool QuadPicker) @@ -255,3 +262,8 @@ void CLayerQuads::ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func) Func(&Quad.m_ColorEnv); } } + +CLayer *CLayerQuads::Duplicate() const +{ + return new CLayerQuads(*this); +} diff --git a/src/game/editor/layer_sounds.cpp b/src/game/editor/layer_sounds.cpp index 279be18b1e1..5937d2f61c0 100644 --- a/src/game/editor/layer_sounds.cpp +++ b/src/game/editor/layer_sounds.cpp @@ -12,6 +12,13 @@ CLayerSounds::CLayerSounds() m_Sound = -1; } +CLayerSounds::CLayerSounds(const CLayerSounds &Other) : + CLayer(Other) +{ + m_Sound = Other.m_Sound; + m_vSources = Other.m_vSources; +} + CLayerSounds::~CLayerSounds() = default; void CLayerSounds::Render(bool Tileset) @@ -219,3 +226,8 @@ void CLayerSounds::ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func) Func(&Source.m_PosEnv); } } + +CLayer *CLayerSounds::Duplicate() const +{ + return new CLayerSounds(*this); +} diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index bc1ab3f1db9..98f74ec8145 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -40,6 +40,33 @@ CLayerTiles::CLayerTiles(int w, int h) mem_zero(m_pTiles, (size_t)m_Width * m_Height * sizeof(CTile)); } +CLayerTiles::CLayerTiles(const CLayerTiles &Other) : + CLayer(Other) +{ + m_Width = Other.m_Width; + m_Height = Other.m_Height; + m_pTiles = new CTile[m_Width * m_Height]; + mem_copy(m_pTiles, Other.m_pTiles, (size_t)m_Width * m_Height * sizeof(CTile)); + + m_Image = Other.m_Image; + m_Texture = Other.m_Texture; + m_Game = Other.m_Game; + m_Color = Other.m_Color; + m_ColorEnv = Other.m_ColorEnv; + m_ColorEnvOffset = Other.m_ColorEnvOffset; + + m_AutoMapperConfig = Other.m_AutoMapperConfig; + m_Seed = Other.m_Seed; + m_AutoAutoMap = Other.m_AutoAutoMap; + m_Tele = Other.m_Tele; + m_Speedup = Other.m_Speedup; + m_Front = Other.m_Front; + m_Switch = Other.m_Switch; + m_Tune = Other.m_Tune; + + mem_copy(m_aFileName, Other.m_aFileName, IO_MAX_PATH_LENGTH); +} + CLayerTiles::~CLayerTiles() { delete[] m_pTiles; @@ -571,6 +598,11 @@ void CLayerTiles::BrushRotate(float Amount) } } +CLayer *CLayerTiles::Duplicate() const +{ + return new CLayerTiles(*this); +} + void CLayerTiles::Resize(int NewW, int NewH) { CTile *pNewData = new CTile[NewW * NewH]; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index a5578db3941..3b6b2971650 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -397,6 +397,21 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View, void *pContext) return CLayerTiles::RenderCommonProperties(pPopup->m_CommonPropState, pEditor, &View, pPopup->m_vpLayers); } + // duplicate layer button + CUIRect DupButton; + static int s_DuplicationButton = 0; + View.HSplitBottom(4.0f, &View, nullptr); + View.HSplitBottom(12.0f, &View, &DupButton); + + if(!pEditor->IsSpecialLayer(pEditor->GetSelectedLayer(0))) + { + if(pEditor->DoButton_Editor(&s_DuplicationButton, "Duplicate layer", 0, &DupButton, 0, "Duplicates the layer")) + { + pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->DuplicateLayer(pEditor->m_vSelectedLayers[0]); + return 1; + } + } + // don't allow deletion of game layer if(pEditor->m_Map.m_pGameLayer != pEditor->GetSelectedLayer(0) && pEditor->DoButton_Editor(&s_DeleteButton, "Delete layer", 0, &Button, 0, "Deletes the layer")) From d1b8d53619e62f67c25ff820ae8e13bb7b51464e Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sat, 20 Aug 2022 13:39:51 +0200 Subject: [PATCH 69/72] Auto refresh skins when changing related settings --- src/game/client/components/menus.h | 2 ++ src/game/client/components/menus_settings.cpp | 26 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index a3476aae4af..38d0eac7a48 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -103,6 +103,8 @@ class CMenus : public CComponent void RenderColorPicker(); + void RefreshSkins(); + // new gui with gui elements template int DoButtonMenu(CUIElement &UIElement, const void *pID, T &&GetTextLambda, int Checked, const CUIRect *pRect, bool HintRequiresStringCheck, bool HintCanChangePositionOrSize = false, int Corners = IGraphics::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1) diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 70c1780525d..e851fe17908 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -409,6 +409,18 @@ struct CUISkin bool operator==(const char *pOther) const { return !str_comp_nocase(m_pSkin->m_aName, pOther); } }; +void CMenus::RefreshSkins() +{ + auto SkinStartLoadTime = time_get_nanoseconds(); + m_pClient->m_Skins.Refresh([&](int) { + // if skin refreshing takes to long, swap to a loading screen + if(time_get_nanoseconds() - SkinStartLoadTime > 500ms) + { + RenderLoading(Localize("Loading skin files"), "", 0, false); + } + }); +} + void CMenus::RenderSettingsTee(CUIRect MainView) { CUIRect Button, Label, Dummy, DummyLabel, SkinList, QuickSearch, QuickSearchClearButton, SkinDB, SkinPrefix, SkinPrefixLabel, DirectoryButton, RefreshButton, Eyes, EyesLabel, EyesTee, EyesRight; @@ -470,6 +482,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView) if(DoButton_CheckBox(&g_Config.m_ClDownloadSkins, Localize("Download skins"), g_Config.m_ClDownloadSkins, &DummyLabel)) { g_Config.m_ClDownloadSkins ^= 1; + RefreshSkins(); + s_InitSkinlist = true; } Dummy.HSplitTop(20.0f, &DummyLabel, &Dummy); @@ -477,6 +491,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView) if(DoButton_CheckBox(&g_Config.m_ClDownloadCommunitySkins, Localize("Download community skins"), g_Config.m_ClDownloadCommunitySkins, &DummyLabel)) { g_Config.m_ClDownloadCommunitySkins ^= 1; + RefreshSkins(); + s_InitSkinlist = true; } Dummy.HSplitTop(20.0f, &DummyLabel, &Dummy); @@ -484,6 +500,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) if(DoButton_CheckBox(&g_Config.m_ClVanillaSkinsOnly, Localize("Vanilla skins only"), g_Config.m_ClVanillaSkinsOnly, &DummyLabel)) { g_Config.m_ClVanillaSkinsOnly ^= 1; + RefreshSkins(); s_InitSkinlist = true; } @@ -779,14 +796,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) // reset render flags for possible loading screen TextRender()->SetRenderFlags(0); TextRender()->SetCurFont(NULL); - auto SkinStartLoadTime = time_get_nanoseconds(); - m_pClient->m_Skins.Refresh([&](int) { - // if skin refreshing takes to long, swap to a loading screen - if(time_get_nanoseconds() - SkinStartLoadTime > 500ms) - { - RenderLoading(Localize("Loading skin files"), "", 0, false); - } - }); + RefreshSkins(); s_InitSkinlist = true; if(Client()->State() >= IClient::STATE_ONLINE) { From 6e5c5cba8f0a37ead58e9971aacba0d2a2afd150 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sat, 20 Aug 2022 14:39:25 +0200 Subject: [PATCH 70/72] Filter vanilla only skins at loading already --- src/game/client/components/menus_settings.cpp | 4 ---- src/game/client/components/skins.cpp | 5 +++-- src/game/client/skin.h | 2 -- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index e851fe17908..aec4f933321 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -668,10 +668,6 @@ void CMenus::RenderSettingsTee(CUIRect MainView) if((pSkinToBeSelected->m_aName[0] == 'x' && pSkinToBeSelected->m_aName[1] == '_')) continue; - // vanilla skins only - if(g_Config.m_ClVanillaSkinsOnly && !pSkinToBeSelected->m_IsVanilla) - continue; - if(pSkinToBeSelected == 0) continue; diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 0230199391f..c9af05e10b5 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -65,6 +65,9 @@ int CSkins::SkinScan(const char *pName, int IsDir, int DirType, void *pUser) str_copy(aNameWithoutPng, pName); aNameWithoutPng[str_length(aNameWithoutPng) - 4] = 0; + if(g_Config.m_ClVanillaSkinsOnly && !IsVanillaSkin(aNameWithoutPng)) + return 0; + // Don't add duplicate skins (one from user's config directory, other from // client itself) for(int i = 0; i < pSelf->Num(); i++) @@ -154,7 +157,6 @@ int CSkins::LoadSkin(const char *pName, CImageInfo &Info) } CSkin Skin; - Skin.m_IsVanilla = IsVanillaSkin(pName); Skin.m_OriginalSkin.m_Body = Graphics()->LoadSpriteTexture(Info, &g_pData->m_aSprites[SPRITE_TEE_BODY]); Skin.m_OriginalSkin.m_BodyOutline = Graphics()->LoadSpriteTexture(Info, &g_pData->m_aSprites[SPRITE_TEE_BODY_OUTLINE]); Skin.m_OriginalSkin.m_Feet = Graphics()->LoadSpriteTexture(Info, &g_pData->m_aSprites[SPRITE_TEE_FOOT]); @@ -355,7 +357,6 @@ void CSkins::Refresh(TSkinLoadedCBFunc &&SkinLoadedFunc) { Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load skins. folder='skins/'"); CSkin DummySkin; - DummySkin.m_IsVanilla = true; str_copy(DummySkin.m_aName, "dummy"); DummySkin.m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f); m_vSkins.push_back(DummySkin); diff --git a/src/game/client/skin.h b/src/game/client/skin.h index a8dd188a64e..e4034182955 100644 --- a/src/game/client/skin.h +++ b/src/game/client/skin.h @@ -8,8 +8,6 @@ // do this better and nicer struct CSkin { - bool m_IsVanilla; - struct SSkinTextures { IGraphics::CTextureHandle m_Body; From ec55212c5255d88ac15edd165be982638998149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 20 Aug 2022 15:57:43 +0200 Subject: [PATCH 71/72] Fix symlink handling of `fs_listdir` On Windows, the check was incorrectly using logical or instead of bitwise or. Checking for the flag `FILE_ATTRIBUTE_REPARSE_POINT` is not necessary, as the `FILE_ATTRIBUTE_DIRECTORY` will correctly be set when the target of a symbolic link is a directory. This otherwise causes symbolic links to files to be incorrectly handled as directories. On Linux, the minor performance optimization of using `entry->d_type` is reverted and `fs_is_dir` is used instead. This internally uses `stat`, which correctly returns the attributes for the symbolic link targets. --- src/base/system.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index a7e94447bb2..16433c26edd 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -2095,7 +2095,7 @@ void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user) { WideCharToMultiByte(CP_UTF8, 0, finddata.cFileName, -1, buffer2, sizeof(buffer2), NULL, NULL); str_copy(buffer + length, buffer2, (int)sizeof(buffer) - length); - if(cb(buffer2, (finddata.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY || FILE_ATTRIBUTE_REPARSE_POINT)) != 0, type, user)) + if(cb(buffer2, (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0, type, user)) break; } while(FindNextFileW(handle, &finddata)); @@ -2115,7 +2115,7 @@ void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user) while((entry = readdir(d)) != NULL) { str_copy(buffer + length, entry->d_name, (int)sizeof(buffer) - length); - if(cb(entry->d_name, entry->d_type == DT_UNKNOWN ? fs_is_dir(buffer) : entry->d_type == DT_DIR || entry->d_type == DT_LNK, type, user)) + if(cb(entry->d_name, fs_is_dir(buffer), type, user)) break; } @@ -2155,7 +2155,7 @@ void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int t info.m_TimeCreated = filetime_to_unixtime(&finddata.ftCreationTime); info.m_TimeModified = filetime_to_unixtime(&finddata.ftLastWriteTime); - if(cb(&info, (finddata.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY || FILE_ATTRIBUTE_REPARSE_POINT)) != 0, type, user)) + if(cb(&info, (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0, type, user)) break; } while(FindNextFileW(handle, &finddata)); @@ -2184,7 +2184,7 @@ void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int t info.m_TimeCreated = created; info.m_TimeModified = modified; - if(cb(&info, entry->d_type == DT_UNKNOWN ? fs_is_dir(buffer) : entry->d_type == DT_DIR || entry->d_type == DT_LNK, type, user)) + if(cb(&info, fs_is_dir(buffer), type, user)) break; } From 21fe945ca7ccc144e11c1a3869ae286ae81b701a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 20 Aug 2022 20:54:25 +0200 Subject: [PATCH 72/72] Make file link absolute, add `fs_is_relative_path` This fixes links not opening for relative paths, as links like `file://temp/skins` cannot be resolved by the shell. --- CMakeLists.txt | 2 +- src/base/system.cpp | 24 +++++++++++++++++++++++- src/base/system.h | 9 +++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8b11ba58c9..9ecc33c3c77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -721,7 +721,7 @@ endif() if(TARGET_OS STREQUAL "windows") set(PLATFORM_CLIENT) set(PLATFORM_CLIENT_LIBS opengl32 winmm) - set(PLATFORM_LIBS version ws2_32) # Windows sockets + set(PLATFORM_LIBS shlwapi version ws2_32) # Windows sockets elseif(TARGET_OS STREQUAL "mac") find_library(CARBON Carbon) find_library(COCOA Cocoa) diff --git a/src/base/system.cpp b/src/base/system.cpp index a7e94447bb2..331855cedb2 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #include #else #error NOT IMPLEMENTED @@ -2309,6 +2310,17 @@ int fs_is_dir(const char *path) #endif } +int fs_is_relative_path(const char *path) +{ +#if defined(CONF_FAMILY_WINDOWS) + WCHAR wPath[IO_MAX_PATH_LENGTH]; + MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, std::size(wPath)); + return PathIsRelativeW(wPath) ? 1 : 0; +#else + return path[0] == '/' ? 0 : 1; // yes, it's that simple +#endif +} + int fs_chdir(const char *path) { if(fs_is_dir(path)) @@ -3866,8 +3878,18 @@ int open_file(const char *path) #if defined(CONF_PLATFORM_MACOS) return open_link(path); #else + // Create a file link so the path can contain forward and + // backward slashes. But the file link must be absolute. char buf[512]; - str_format(buf, sizeof(buf), "file://%s", path); + char workingDir[IO_MAX_PATH_LENGTH]; + if(fs_is_relative_path(path)) + { + fs_getcwd(workingDir, sizeof(workingDir)); + str_append(workingDir, "/", sizeof(workingDir)); + } + else + workingDir[0] = '\0'; + str_format(buf, sizeof(buf), "file://%s%s", workingDir, path); return open_link(buf); #endif } diff --git a/src/base/system.h b/src/base/system.h index a20aac9559d..379a7b04445 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1821,6 +1821,15 @@ int fs_storage_path(const char *appname, char *path, int max); */ int fs_is_dir(const char *path); +/* + Function: fs_is_relative_path + Checks whether a given path is relative or absolute. + + Returns: + Returns 1 if relative, 0 if absolute. +*/ +int fs_is_relative_path(const char *path); + /* Function: fs_chdir Changes current working directory