diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 6df146938..4266cd35e 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -1137,6 +1137,27 @@ public: static int PopupMessage(CEditor *pEditor, CUIRect View, void *pContext); void ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext); + struct SConfirmPopupContext + { + enum EConfirmationResult + { + UNSET = 0, + CONFIRMED, + CANCELED + }; + static constexpr float POPUP_MAX_WIDTH = 200.0f; + static constexpr float POPUP_FONT_SIZE = 10.0f; + static constexpr float POPUP_BUTTON_HEIGHT = 12.0f; + static constexpr float POPUP_BUTTON_SPACING = 5.0f; + char m_aMessage[256]; + EConfirmationResult m_Result; + + SConfirmPopupContext(); + void Reset(); + }; + static int PopupConfirm(CEditor *pEditor, CUIRect View, void *pContext); + void ShowPopupConfirm(float X, float Y, SConfirmPopupContext *pContext); + struct SSelectionPopupContext { static constexpr float POPUP_MAX_WIDTH = 300.0f; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index cb6db0de3..036b1b8fb 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1895,6 +1895,55 @@ int CEditor::PopupMessage(CEditor *pEditor, CUIRect View, void *pContext) return 0; } +CEditor::SConfirmPopupContext::SConfirmPopupContext() +{ + Reset(); +} + +void CEditor::SConfirmPopupContext::Reset() +{ + m_Result = SConfirmPopupContext::UNSET; +} + +void CEditor::ShowPopupConfirm(float X, float Y, SConfirmPopupContext *pContext) +{ + const float TextWidth = minimum(TextRender()->TextWidth(nullptr, SConfirmPopupContext::POPUP_FONT_SIZE, pContext->m_aMessage, -1, -1.0f), SConfirmPopupContext::POPUP_MAX_WIDTH); + const int LineCount = TextRender()->TextLineCount(nullptr, SConfirmPopupContext::POPUP_FONT_SIZE, pContext->m_aMessage, TextWidth); + const float PopupHeight = LineCount * SConfirmPopupContext::POPUP_FONT_SIZE + SConfirmPopupContext::POPUP_BUTTON_HEIGHT + SConfirmPopupContext::POPUP_BUTTON_SPACING + 10.0f; + pContext->m_Result = SConfirmPopupContext::UNSET; + UiInvokePopupMenu(pContext, 0, X, Y, TextWidth + 10.0f, PopupHeight, PopupConfirm, pContext); +} + +int CEditor::PopupConfirm(CEditor *pEditor, CUIRect View, void *pContext) +{ + SConfirmPopupContext *pConfirmPopup = static_cast(pContext); + + CUIRect Label, ButtonBar, CancelButton, ConfirmButton; + View.HSplitBottom(SConfirmPopupContext::POPUP_BUTTON_HEIGHT, &Label, &ButtonBar); + ButtonBar.VSplitMid(&CancelButton, &ConfirmButton, SConfirmPopupContext::POPUP_BUTTON_SPACING); + + CTextCursor Cursor; + pEditor->TextRender()->SetCursor(&Cursor, Label.x, Label.y, SConfirmPopupContext::POPUP_FONT_SIZE, TEXTFLAG_RENDER); + Cursor.m_LineWidth = Label.w; + pEditor->TextRender()->TextEx(&Cursor, pConfirmPopup->m_aMessage, -1); + + static int s_CancelButton = 0; + if(pEditor->DoButton_Editor(&s_CancelButton, "Cancel", 0, &CancelButton, 0, nullptr)) + { + pConfirmPopup->m_Result = SConfirmPopupContext::CANCELED; + return 1; + } + + static int s_ConfirmButton = 0; + if(pEditor->DoButton_Editor(&s_ConfirmButton, "Confirm", 0, &ConfirmButton, 0, nullptr)) + { + pConfirmPopup->m_Result = SConfirmPopupContext::CONFIRMED; + return 1; + } + + 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);