diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 585e3ceef..04e1383f1 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -6781,22 +6781,30 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) CurveButton.w = CurveBar.h; CurveButton.x -= CurveButton.w / 2.0f; const void *pId = &pEnvelope->m_vPoints[i].m_Curvetype; - const char *apTypeName[] = {"N", "L", "S", "F", "M", "B"}; + static const char *const TYPE_NAMES[NUM_CURVETYPES] = {"N", "L", "S", "F", "M", "B"}; const char *pTypeName = "!?"; - if(0 <= pEnvelope->m_vPoints[i].m_Curvetype && pEnvelope->m_vPoints[i].m_Curvetype < (int)std::size(apTypeName)) - pTypeName = apTypeName[pEnvelope->m_vPoints[i].m_Curvetype]; + if(0 <= pEnvelope->m_vPoints[i].m_Curvetype && pEnvelope->m_vPoints[i].m_Curvetype < (int)std::size(TYPE_NAMES)) + pTypeName = TYPE_NAMES[pEnvelope->m_vPoints[i].m_Curvetype]; if(CurveButton.x >= View.x) { - if(DoButton_Editor(pId, pTypeName, 0, &CurveButton, 0, "Switch curve type (N = step, L = linear, S = slow, F = fast, M = smooth, B = bezier)")) + const int ButtonResult = DoButton_Editor(pId, pTypeName, 0, &CurveButton, BUTTON_CONTEXT, "Switch curve type (N = step, L = linear, S = slow, F = fast, M = smooth, B = bezier)."); + if(ButtonResult == 1) { - int PrevCurve = pEnvelope->m_vPoints[i].m_Curvetype; - pEnvelope->m_vPoints[i].m_Curvetype = (pEnvelope->m_vPoints[i].m_Curvetype + 1) % NUM_CURVETYPES; + const int PrevCurve = pEnvelope->m_vPoints[i].m_Curvetype; + const int Direction = Input()->ShiftIsPressed() ? -1 : 1; + pEnvelope->m_vPoints[i].m_Curvetype = (pEnvelope->m_vPoints[i].m_Curvetype + Direction + NUM_CURVETYPES) % NUM_CURVETYPES; m_EnvelopeEditorHistory.RecordAction(std::make_shared(this, m_SelectedEnvelope, i, 0, CEditorActionEnvelopeEditPoint::EEditType::CURVE_TYPE, PrevCurve, pEnvelope->m_vPoints[i].m_Curvetype)); m_Map.OnModify(); } + else if(ButtonResult == 2) + { + m_PopupEnvelopeSelectedPoint = i; + static SPopupMenuId s_PopupCurvetypeId; + Ui()->DoPopupMenu(&s_PopupCurvetypeId, Ui()->MouseX(), Ui()->MouseY(), 80, NUM_CURVETYPES * 14.0f + 10.0f, this, PopupEnvelopeCurvetype); + } } } } diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 4ff315561..a32c9d7ca 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -917,6 +917,8 @@ public: static CUi::EPopupMenuFunctionResult PopupEntities(void *pContext, CUIRect View, bool Active); static CUi::EPopupMenuFunctionResult PopupProofMode(void *pContext, CUIRect View, bool Active); static CUi::EPopupMenuFunctionResult PopupAnimateSettings(void *pContext, CUIRect View, bool Active); + int m_PopupEnvelopeSelectedPoint = -1; + static CUi::EPopupMenuFunctionResult PopupEnvelopeCurvetype(void *pContext, CUIRect View, bool Active); static bool CallbackOpenMap(const char *pFileName, int StorageType, void *pUser); static bool CallbackAppendMap(const char *pFileName, int StorageType, void *pUser); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 282219dfa..d293e851d 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -2881,3 +2881,44 @@ CUi::EPopupMenuFunctionResult CEditor::PopupAnimateSettings(void *pContext, CUIR return CUi::POPUP_KEEP_OPEN; } + +CUi::EPopupMenuFunctionResult CEditor::PopupEnvelopeCurvetype(void *pContext, CUIRect View, bool Active) +{ + CEditor *pEditor = static_cast(pContext); + + if(pEditor->m_SelectedEnvelope < 0 || pEditor->m_SelectedEnvelope >= (int)pEditor->m_Map.m_vpEnvelopes.size()) + { + return CUi::POPUP_CLOSE_CURRENT; + } + std::shared_ptr pEnvelope = pEditor->m_Map.m_vpEnvelopes[pEditor->m_SelectedEnvelope]; + + if(pEditor->m_PopupEnvelopeSelectedPoint < 0 || pEditor->m_PopupEnvelopeSelectedPoint >= (int)pEnvelope->m_vPoints.size()) + { + return CUi::POPUP_CLOSE_CURRENT; + } + CEnvPoint_runtime &SelectedPoint = pEnvelope->m_vPoints[pEditor->m_PopupEnvelopeSelectedPoint]; + + static const char *const TYPE_NAMES[NUM_CURVETYPES] = {"Step", "Linear", "Slow", "Fast", "Smooth", "Bezier"}; + static char s_aButtonIds[NUM_CURVETYPES] = {0}; + + for(int Type = 0; Type < NUM_CURVETYPES; Type++) + { + CUIRect Button; + View.HSplitTop(14.0f, &Button, &View); + + if(pEditor->DoButton_MenuItem(&s_aButtonIds[Type], TYPE_NAMES[Type], Type == SelectedPoint.m_Curvetype, &Button)) + { + const int PrevCurve = SelectedPoint.m_Curvetype; + if(PrevCurve != Type) + { + SelectedPoint.m_Curvetype = Type; + pEditor->m_EnvelopeEditorHistory.RecordAction(std::make_shared(pEditor, + pEditor->m_SelectedEnvelope, pEditor->m_PopupEnvelopeSelectedPoint, 0, CEditorActionEnvelopeEditPoint::EEditType::CURVE_TYPE, PrevCurve, SelectedPoint.m_Curvetype)); + pEditor->m_Map.OnModify(); + return CUi::POPUP_CLOSE_CURRENT; + } + } + } + + return CUi::POPUP_KEEP_OPEN; +}