diff --git a/Source/UI/Navigation/UIPrivateAirplaneWnd.h b/Source/UI/Navigation/UIPrivateAirplaneWnd.h index 3ad6162b..ee2f2604 100644 --- a/Source/UI/Navigation/UIPrivateAirplaneWnd.h +++ b/Source/UI/Navigation/UIPrivateAirplaneWnd.h @@ -14,6 +14,7 @@ public: void Slot15(int width, int height) override; void Slot19() override; void Paint() override; + int SendMsg(UIWindow* sender, int message, std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4) override; protected: /* 00B4 */ UIButtonContext* m_controls; diff --git a/Source/UI/Window/UIWindow.cpp b/Source/UI/Window/UIWindow.cpp index 7d644ac8..0b4ab1c8 100644 --- a/Source/UI/Window/UIWindow.cpp +++ b/Source/UI/Window/UIWindow.cpp @@ -135,6 +135,35 @@ int g_navigationRoadIcon; // GLOBAL: gl_24632 CTexture* g_navigationMapTexture; +// INLINED +static const char* FindColorCode(const char* text, const char* end) { + if (!text) { + return nullptr; + } + + while (text < end) { + if (*text == '^' && end - text >= 6) { + int index = 1; + while (index <= 6) { + const unsigned char digit = static_cast(text[index]); + if (!((digit >= '0' && digit <= '9') || (digit >= 'a' && digit <= 'f') || (digit >= 'A' && digit <= 'F'))) { + break; + } + + ++index; + } + + if (index > 6) { + return text; + } + } + + text = CharNextExA(static_cast(g_textCodePage), text, 0); + } + + return text; +} + // INLINED void UIWindowContext::DestroyDeferredChildren() { for (UIWindow* window : this->deferredDeletion) { @@ -893,6 +922,32 @@ int UIWindow::TextWidth( return context.Measure(text, bytes).cx; } +// OFFSET: 0x00A7D760 +// FUNCTION: fn_16955 +int UIWindow::ColoredTextWidth(const char* text, unsigned bytes, int family, int height, unsigned char bold) { + if (!text) { + return 0; + } + + if (!bytes) { + bytes = static_cast(std::strlen(text)); + if (!bytes) { + return 0; + } + } + + int width = this->TextWidth(this->m_context->fonts, this->m_context->locale, text, bytes, family, height, bold, 0); + std::uint32_t color = 0; + if (ParseColorCode(FindColorCode(text, text + bytes), color) && color) { + TextContext context(*this->geometry.surface); + context.SetFont(0, 12, 0, 0); + const int marker = context.Measure("^000000", 7).cx; + width += (3 - marker) * 2; + } + + return width; +} + // OFFSET: 0x00A84360 // FUNCTION: fn_17009 void UIWindow::DrawTextAt( @@ -2829,3 +2884,36 @@ void UIPrivateAirplaneWnd::Slot15(int, int) { this->m_buttons.push_back(button); } } + +// OFFSET: 0x005C8DA0 +// FUNCTION: fn_03628 +int UIPrivateAirplaneWnd::SendMsg( + UIWindow* sender, int message, std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4 +) { + switch (message) { + case 6: + if (argument1 == 201) { + if (!g_windowMgr.modalWindows.empty() && g_windowMgr.modalWindows.back()) { + g_windowMgr.unknown_0474 = 0xBC; + } + } else if (argument1 == 500) { + const std::string mapName = g_navigationManager.GetCurrentTargetName() + ".gat"; + g_navigationManager.RequestPrivateAirship(mapName, static_cast(argument2)); + } + break; + case 35: + for (UIBasicButton* button : this->m_buttons) { + button->SetDisabled(1); + button->Invalidate(); + } + + this->Invalidate(); + break; + case 154: + this->m_text = reinterpret_cast(argument1); + this->Invalidate(); + break; + } + + return UIFrameWnd::SendMsg(sender, message, argument1, argument2, argument3, argument4); +} diff --git a/Source/UI/Window/UIWindow.h b/Source/UI/Window/UIWindow.h index 0ff0d255..49393cc1 100644 --- a/Source/UI/Window/UIWindow.h +++ b/Source/UI/Window/UIWindow.h @@ -147,6 +147,7 @@ public: void sub_A85850(int x, int y, std::string text, int width, int align, std::uint32_t color, int arg7, int arg8, int arg9, int arg10, unsigned char bold); void FillRegion(int x, int y, int width, int height, std::uint32_t color); int TextWidth(FontCache& fonts, const TextLocale& locale, const char* text, unsigned bytes, int family, int height, unsigned char bold, unsigned char italic); + int ColoredTextWidth(const char* text, unsigned bytes, int family, int height, unsigned char bold); void DrawTextAt( FontCache& fonts, const TextLocale& locale, int x, int y, const char* text, int bytes, int family, int height, std::uint32_t color, unsigned char bold, unsigned char italic