Merge pull request #9153 from Robyt3/Editor-Curvetype-Popup

Add popup to select envelope curve type, support shift+left click
This commit is contained in:
Dennis Felsing 2024-10-17 07:15:53 +00:00 committed by GitHub
commit 74b485b397
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 6 deletions

View file

@ -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<CEditorActionEnvelopeEditPoint>(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);
}
}
}
}

View file

@ -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);

View file

@ -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<CEditor *>(pContext);
if(pEditor->m_SelectedEnvelope < 0 || pEditor->m_SelectedEnvelope >= (int)pEditor->m_Map.m_vpEnvelopes.size())
{
return CUi::POPUP_CLOSE_CURRENT;
}
std::shared_ptr<CEnvelope> 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<CEditorActionEnvelopeEditPoint>(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;
}