mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
use ValueSelector for envelope selection closes #3598
This commit is contained in:
parent
4cd2c2964f
commit
05204bbcb8
|
@ -558,7 +558,7 @@ void CEditor::RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture,
|
|||
Graphics()->QuadsEnd();
|
||||
}
|
||||
|
||||
int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree, bool IsHex, int Corners, ColorRGBA *pColor)
|
||||
int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree, bool IsHex, int Corners, ColorRGBA *pColor, bool ShowValue)
|
||||
{
|
||||
// logic
|
||||
static float s_Value;
|
||||
|
@ -662,7 +662,12 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
|
|||
// render
|
||||
char aBuf[128];
|
||||
if(pLabel[0] != '\0')
|
||||
str_format(aBuf, sizeof(aBuf), "%s %d", pLabel, Current);
|
||||
{
|
||||
if(ShowValue)
|
||||
str_format(aBuf, sizeof(aBuf), "%s %d", pLabel, Current);
|
||||
else
|
||||
str_copy(aBuf, pLabel);
|
||||
}
|
||||
else if(IsDegree)
|
||||
str_format(aBuf, sizeof(aBuf), "%d°", Current);
|
||||
else if(IsHex)
|
||||
|
@ -3206,22 +3211,32 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
|
|||
else if(pProps[i].m_Type == PROPTYPE_ENVELOPE)
|
||||
{
|
||||
CUIRect Inc, Dec;
|
||||
char aBuf[64];
|
||||
char aBuf[8];
|
||||
int CurValue = pProps[i].m_Value;
|
||||
|
||||
Shifter.VSplitRight(10.0f, &Shifter, &Inc);
|
||||
Shifter.VSplitLeft(10.0f, &Dec, &Shifter);
|
||||
|
||||
if(CurValue <= 0)
|
||||
str_copy(aBuf, "None", sizeof(aBuf));
|
||||
str_copy(aBuf, "None:", sizeof(aBuf));
|
||||
else if(m_Map.m_vpEnvelopes[CurValue - 1]->m_aName[0])
|
||||
str_format(aBuf, sizeof(aBuf), "%d: %s", CurValue, m_Map.m_vpEnvelopes[CurValue - 1]->m_aName);
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "%s:", m_Map.m_vpEnvelopes[CurValue - 1]->m_aName);
|
||||
if(!str_endswith(aBuf, ":"))
|
||||
{
|
||||
aBuf[sizeof(aBuf) - 2] = ':';
|
||||
aBuf[sizeof(aBuf) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), "%d", CurValue);
|
||||
aBuf[0] = '\0';
|
||||
|
||||
float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w);
|
||||
Shifter.Draw(Color, 0, 5.0f);
|
||||
UI()->DoLabel(&Shifter, aBuf, FontSize, TEXTALIGN_CENTER);
|
||||
int NewVal = UiDoValueSelector((char *)&pIDs[i], &Shifter, aBuf, CurValue, 0, m_Map.m_vpEnvelopes.size(), 1, 1.0f, "Set Envelope", false, false, IGraphics::CORNER_NONE);
|
||||
if(NewVal != CurValue)
|
||||
{
|
||||
*pNewVal = NewVal;
|
||||
Change = i;
|
||||
}
|
||||
|
||||
if(DoButton_ButtonDec((char *)&pIDs[i] + 1, nullptr, 0, &Dec, 0, "Previous Envelope"))
|
||||
{
|
||||
|
@ -4932,8 +4947,13 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
ColorRGBA(0.7f, 1, 0.7f, 0.5f);
|
||||
}
|
||||
|
||||
Shifter.Draw(EnvColor, IGraphics::CORNER_NONE, 0.0f);
|
||||
UI()->DoLabel(&Shifter, aBuf, 10.0f, TEXTALIGN_CENTER);
|
||||
static int s_EnvelopeSelector = 0;
|
||||
int NewValue = UiDoValueSelector(&s_EnvelopeSelector, &Shifter, aBuf, m_SelectedEnvelope + 1, 1, m_Map.m_vpEnvelopes.size(), 1, 1.0f, "Select Envelope", false, false, IGraphics::CORNER_NONE, &EnvColor, false);
|
||||
if(NewValue - 1 != m_SelectedEnvelope)
|
||||
{
|
||||
m_SelectedEnvelope = NewValue - 1;
|
||||
CurrentEnvelopeSwitched = true;
|
||||
}
|
||||
|
||||
static int s_PrevButton = 0;
|
||||
if(DoButton_ButtonDec(&s_PrevButton, nullptr, 0, &Dec, 0, "Previous Envelope"))
|
||||
|
|
|
@ -1103,7 +1103,7 @@ public:
|
|||
bool UiPopupExists(void *pID);
|
||||
bool UiPopupOpen();
|
||||
|
||||
int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree = false, bool IsHex = false, int corners = IGraphics::CORNER_ALL, ColorRGBA *pColor = nullptr);
|
||||
int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree = false, bool IsHex = false, int corners = IGraphics::CORNER_ALL, ColorRGBA *pColor = nullptr, bool ShowValue = true);
|
||||
|
||||
static int PopupGroup(CEditor *pEditor, CUIRect View, void *pContext);
|
||||
|
||||
|
|
|
@ -703,10 +703,10 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
if(Prop == PROP_POS_ENV)
|
||||
{
|
||||
int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_vpEnvelopes.size() - 1);
|
||||
int Step = (Index - pQuad->m_PosEnv) % 2;
|
||||
if(Step != 0)
|
||||
int StepDirection = Index < pQuad->m_PosEnv ? -1 : 1;
|
||||
if(StepDirection != 0)
|
||||
{
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += Step)
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += StepDirection)
|
||||
if(Index == -1 || pEditor->m_Map.m_vpEnvelopes[Index]->m_Channels == 3)
|
||||
{
|
||||
pQuad->m_PosEnv = Index;
|
||||
|
@ -719,10 +719,10 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
if(Prop == PROP_COLOR_ENV)
|
||||
{
|
||||
int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_vpEnvelopes.size() - 1);
|
||||
int Step = (Index - pQuad->m_ColorEnv) % 2;
|
||||
if(Step != 0)
|
||||
int StepDirection = Index < pQuad->m_ColorEnv ? -1 : 1;
|
||||
if(StepDirection != 0)
|
||||
{
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += Step)
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += StepDirection)
|
||||
if(Index == -1 || pEditor->m_Map.m_vpEnvelopes[Index]->m_Channels == 4)
|
||||
{
|
||||
pQuad->m_ColorEnv = Index;
|
||||
|
@ -842,10 +842,10 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
if(Prop == PROP_POS_ENV)
|
||||
{
|
||||
int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_vpEnvelopes.size() - 1);
|
||||
int Step = (Index - pSource->m_PosEnv) % 2;
|
||||
if(Step != 0)
|
||||
int StepDirection = Index < pSource->m_PosEnv ? -1 : 1;
|
||||
if(StepDirection != 0)
|
||||
{
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += Step)
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += StepDirection)
|
||||
if(Index == -1 || pEditor->m_Map.m_vpEnvelopes[Index]->m_Channels == 3)
|
||||
{
|
||||
pSource->m_PosEnv = Index;
|
||||
|
@ -858,10 +858,10 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
if(Prop == PROP_SOUND_ENV)
|
||||
{
|
||||
int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_vpEnvelopes.size() - 1);
|
||||
int Step = (Index - pSource->m_SoundEnv) % 2;
|
||||
if(Step != 0)
|
||||
int StepDirection = Index < pSource->m_SoundEnv ? -1 : 1;
|
||||
if(StepDirection != 0)
|
||||
{
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += Step)
|
||||
for(; Index >= -1 && Index < (int)pEditor->m_Map.m_vpEnvelopes.size(); Index += StepDirection)
|
||||
if(Index == -1 || pEditor->m_Map.m_vpEnvelopes[Index]->m_Channels == 1)
|
||||
{
|
||||
pSource->m_SoundEnv = Index;
|
||||
|
|
Loading…
Reference in a new issue