From 7b70a1c62cf70d65e7912ff0d42b62388c09ff13 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 8 Sep 2021 01:53:25 +0200 Subject: [PATCH] Add fonticon autocomplete for chat --- src/Components/Modules/ServerInfo.cpp | 4 ++-- src/Components/Modules/ServerInfo.hpp | 2 +- src/Components/Modules/TextRenderer.cpp | 14 ++++++++++++++ src/Game/Functions.cpp | 3 ++- src/Game/Functions.hpp | 7 +++++-- src/Game/Structs.hpp | 18 ++++++++++++++++++ 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index c5b8ffe9..04f08bb5 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -71,10 +71,10 @@ namespace Components } } - void ServerInfo::DrawScoreboardInfo(void* a1) + void ServerInfo::DrawScoreboardInfo(int localClientNum) { Game::Font_s* font = Game::R_RegisterFont("fonts/bigfont", 0); - void* cxt = Game::UI_GetContext(a1); + void* cxt = Game::ScrPlace_GetActivePlacement(localClientNum); std::string addressText = Network::Address(*Game::connectedHost).getString(); if (addressText == "0.0.0.0:0" || addressText == "loopback") addressText = "Listen Server"; diff --git a/src/Components/Modules/ServerInfo.hpp b/src/Components/Modules/ServerInfo.hpp index 8fceb827..36dd8cf7 100644 --- a/src/Components/Modules/ServerInfo.hpp +++ b/src/Components/Modules/ServerInfo.hpp @@ -36,7 +36,7 @@ namespace Components static const char* GetPlayerText(unsigned int index, int column); static void SelectPlayer(unsigned int index); - static void DrawScoreboardInfo(void* a1); + static void DrawScoreboardInfo(int localClientNum); static void DrawScoreboardStub(); }; } diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 8b7953c7..ba10f9e0 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -245,6 +245,20 @@ namespace Components void TextRenderer::Field_Draw_Say(const int localClientNum, Game::field_t* edit, const int x, const int y, const int horzAlign, const int vertAlign) { Game::Field_Draw(localClientNum, edit, x, y, horzAlign, vertAlign); + + auto& autocompleteContext = autocompleteContextArray[FONT_ICON_ACI_CHAT]; + UpdateAutocompleteContext(autocompleteContext, edit, Game::cls->consoleFont); + if (autocompleteContext.autocompleteActive) + { + auto* screenPlacement = Game::ScrPlace_GetActivePlacement(localClientNum); + auto xx = static_cast(x); + auto yy = static_cast(y); + auto ww = 0.0f; + auto hh = 0.0f; + Game::ScrPlace_ApplyRect(screenPlacement, &xx, &yy, &ww, &hh, horzAlign, vertAlign); + yy += static_cast(2 * Game::R_TextHeight(Game::cls->consoleFont)); + DrawAutocomplete(autocompleteContext, std::floor(xx), std::floor(yy), Game::cls->consoleFont); + } } float TextRenderer::GetMonospaceWidth(Game::Font_s* font, int rendererFlags) diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 0d4281b7..33bd1995 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -323,9 +323,10 @@ namespace Game UI_UpdateArenas_t UI_UpdateArenas = UI_UpdateArenas_t(0x4A95B0); UI_SortArenas_t UI_SortArenas = UI_SortArenas_t(0x630AE0); UI_DrawHandlePic_t UI_DrawHandlePic = UI_DrawHandlePic_t(0x4D0EA0); - UI_GetContext_t UI_GetContext = UI_GetContext_t(0x4F8940); + ScrPlace_GetActivePlacement_t ScrPlace_GetActivePlacement = ScrPlace_GetActivePlacement_t(0x4F8940); UI_TextWidth_t UI_TextWidth = UI_TextWidth_t(0x6315C0); UI_DrawText_t UI_DrawText = UI_DrawText_t(0x49C0D0); + ScrPlace_ApplyRect_t ScrPlace_ApplyRect = ScrPlace_ApplyRect_t(0x454E20); Win_GetLanguage_t Win_GetLanguage = Win_GetLanguage_t(0x45CBA0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 9a3f2cc9..41d6723f 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -759,14 +759,17 @@ namespace Game typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material); extern UI_DrawHandlePic_t UI_DrawHandlePic; - typedef void* (__cdecl * UI_GetContext_t)(void*); - extern UI_GetContext_t UI_GetContext; + typedef ScreenPlacement* (__cdecl * ScrPlace_GetActivePlacement_t)(int localClientNum); + extern ScrPlace_GetActivePlacement_t ScrPlace_GetActivePlacement; typedef int(__cdecl * UI_TextWidth_t)(const char *text, int maxChars, Font_s *font, float scale); extern UI_TextWidth_t UI_TextWidth; typedef void(__cdecl * UI_DrawText_t)(void* scrPlace, const char *text, int maxChars, Font_s *font, float x, float y, int horzAlign, int vertAlign, float scale, const float *color, int style); extern UI_DrawText_t UI_DrawText; + + typedef void(__cdecl* ScrPlace_ApplyRect_t)(ScreenPlacement* a1, float* x, float* y, float* w, float* h, int horzAlign, int vertAlign); + extern ScrPlace_ApplyRect_t ScrPlace_ApplyRect; typedef const char * (__cdecl * Win_GetLanguage_t)(); extern Win_GetLanguage_t Win_GetLanguage; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index f3aa7eb0..23244457 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -5413,6 +5413,24 @@ namespace Game float fontHeight; }; + struct ScreenPlacement + { + float scaleVirtualToReal[2]; + float scaleVirtualToFull[2]; + float scaleRealToVirtual[2]; + float realViewportPosition[2]; + float realViewportSize[2]; + float virtualViewableMin[2]; + float virtualViewableMax[2]; + float realViewableMin[2]; + float realViewableMax[2]; + float virtualAdjustableMin[2]; + float virtualAdjustableMax[2]; + float realAdjustableMin[2]; + float realAdjustableMax[2]; + float subScreenLeft; + }; + #pragma endregion #ifndef IDA