diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 5b1012f5f..9db87855b 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -1099,6 +1099,19 @@ public: static int PopupColorPicker(CEditor *pEditor, CUIRect View, void *pContext); static int PopupEntities(CEditor *pEditor, CUIRect View, void *pContext); + struct SMessagePopupContext + { + static constexpr float POPUP_MAX_WIDTH = 200.0f; + static constexpr float POPUP_FONT_SIZE = 10.0f; + char m_aMessage[256]; + ColorRGBA m_TextColor; + + void DefaultColor(class ITextRender *pTextRender); + void ErrorColor(); + }; + static int PopupMessage(CEditor *pEditor, CUIRect View, void *pContext); + void ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext); + static void CallbackOpenMap(const char *pFileName, int StorageType, void *pUser); static void CallbackAppendMap(const char *pFileName, int StorageType, void *pUser); static void CallbackSaveMap(const char *pFileName, int StorageType, void *pUser); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 843509761..fe001b64a 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1870,3 +1870,34 @@ int CEditor::PopupEntities(CEditor *pEditor, CUIRect View, void *pContext) return 0; } + +void CEditor::SMessagePopupContext::DefaultColor(ITextRender *pTextRender) +{ + m_TextColor = pTextRender->DefaultTextColor(); +} + +void CEditor::SMessagePopupContext::ErrorColor() +{ + m_TextColor = ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f); +} + +int CEditor::PopupMessage(CEditor *pEditor, CUIRect View, void *pContext) +{ + SMessagePopupContext *pMessagePopup = static_cast(pContext); + + CTextCursor Cursor; + pEditor->TextRender()->SetCursor(&Cursor, View.x, View.y, SMessagePopupContext::POPUP_FONT_SIZE, TEXTFLAG_RENDER); + Cursor.m_LineWidth = View.w; + pEditor->TextRender()->TextColor(pMessagePopup->m_TextColor); + pEditor->TextRender()->TextEx(&Cursor, pMessagePopup->m_aMessage, -1); + pEditor->TextRender()->TextColor(pEditor->TextRender()->DefaultTextColor()); + + return 0; +} + +void CEditor::ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext) +{ + const float TextWidth = minimum(TextRender()->TextWidth(nullptr, SMessagePopupContext::POPUP_FONT_SIZE, pContext->m_aMessage, -1, -1.0f), SMessagePopupContext::POPUP_MAX_WIDTH); + const int LineCount = TextRender()->TextLineCount(nullptr, SMessagePopupContext::POPUP_FONT_SIZE, pContext->m_aMessage, TextWidth); + UiInvokePopupMenu(pContext, 0, X, Y, TextWidth + 10.0f, LineCount * SMessagePopupContext::POPUP_FONT_SIZE + 10.0f, PopupMessage, pContext); +}