mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
Merge #3124
3124: Remove option to make map sounds external r=def- a=Patiga ![2020-10-17-180507_401x333_scrot](https://user-images.githubusercontent.com/44099679/96347669-8dd21080-10a3-11eb-8b24-abdab7f41020.png) Right now it is impossible to have a working external sound. External sounds render unusable the moment the map is saved and given to another player. For the mapper it seems like everything is working since the mapper has the sound file. For anyone else it simply won't work. Since 1. there is no use for it and 2. it adds unnecessary complexity and confusion, I propose removing it entirely. None of the ddnet maps use external sounds, only 25 maps from the map archive have external sounds Please have a look over the changed ui code. Co-authored-by: Patiga <dev@patiga.eu>
This commit is contained in:
commit
331c9f695c
|
@ -3718,7 +3718,6 @@ void CEditor::AddSound(const char *pFileName, int StorageType, void *pUser)
|
|||
// add sound
|
||||
CEditorSound *pSound = new CEditorSound(pEditor);
|
||||
pSound->m_SoundID = SoundId;
|
||||
pSound->m_External = 0; // embedded by default
|
||||
pSound->m_DataSize = (unsigned)DataSize;
|
||||
pSound->m_pData = pData;
|
||||
str_copy(pSound->m_aName, aBuf, sizeof(pSound->m_aName));
|
||||
|
@ -3764,7 +3763,6 @@ void CEditor::ReplaceSound(const char *pFileName, int StorageType, void *pUser)
|
|||
io_close(SoundFile);
|
||||
|
||||
CEditorSound *pSound = pEditor->m_Map.m_lSounds[pEditor->m_SelectedSound];
|
||||
int External = pSound->m_External;
|
||||
|
||||
// unload sample
|
||||
pEditor->Sound()->UnloadSample(pSound->m_SoundID);
|
||||
|
@ -3775,7 +3773,6 @@ void CEditor::ReplaceSound(const char *pFileName, int StorageType, void *pUser)
|
|||
}
|
||||
|
||||
// replace sound
|
||||
pSound->m_External = External;
|
||||
IStorage::StripPathAndExtension(pFileName, pSound->m_aName, sizeof(pSound->m_aName));
|
||||
pSound->m_SoundID = pEditor->Sound()->LoadOpusFromMem(pData, (unsigned)DataSize, true);
|
||||
pSound->m_pData = pData;
|
||||
|
@ -3851,28 +3848,6 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
CUIRect Slot;
|
||||
View.HSplitTop(2.0f, &Slot, &View);
|
||||
View.HSplitTop(12.0f, &Slot, &View);
|
||||
CEditorSound *pSound = pEditor->m_Map.m_lSounds[pEditor->m_SelectedSound];
|
||||
|
||||
static int s_ExternalButton = 0;
|
||||
if(pSound->m_External)
|
||||
{
|
||||
if(pEditor->DoButton_MenuItem(&s_ExternalButton, "Embed", 0, &Slot, 0, "Embeds the sound into the map file."))
|
||||
{
|
||||
pSound->m_External = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pEditor->DoButton_MenuItem(&s_ExternalButton, "Make external", 0, &Slot, 0, "Removes the sound from the map file."))
|
||||
{
|
||||
pSound->m_External = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
View.HSplitTop(5.0f, &Slot, &View);
|
||||
View.HSplitTop(12.0f, &Slot, &View);
|
||||
if(pEditor->DoButton_MenuItem(&s_ReplaceButton, "Replace", 0, &Slot, 0, "Replaces the sound with a new one"))
|
||||
{
|
||||
pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_SOUND, "Replace sound", "Replace", "mapres", "", ReplaceSound, pEditor);
|
||||
|
@ -3881,6 +3856,7 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
|
||||
View.HSplitTop(5.0f, &Slot, &View);
|
||||
View.HSplitTop(12.0f, &Slot, &View);
|
||||
CEditorSound *pSound = pEditor->m_Map.m_lSounds[pEditor->m_SelectedSound];
|
||||
if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the sound from the map"))
|
||||
{
|
||||
delete pSound;
|
||||
|
@ -4197,135 +4173,82 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
|
|||
float SoundStopAt = SoundsHeight - ScrollDifference * (1 - s_ScrollValue);
|
||||
float SoundCur = 0.0f;
|
||||
|
||||
for(int e = 0; e < 2; e++) // two passes, first embedded, then external
|
||||
{
|
||||
CUIRect Slot;
|
||||
CUIRect Slot;
|
||||
|
||||
ToolBox.HSplitTop(15.0f, &Slot, &ToolBox);
|
||||
UI()->DoLabel(&Slot, "Embedded", 12.0f, 0);
|
||||
SoundCur += 15.0f;
|
||||
|
||||
for(int i = 0; i < m_Map.m_lSounds.size(); i++)
|
||||
{
|
||||
if(SoundCur > SoundStopAt)
|
||||
break;
|
||||
else if(SoundCur >= SoundStartAt)
|
||||
else if(SoundCur < SoundStartAt)
|
||||
{
|
||||
ToolBox.HSplitTop(15.0f, &Slot, &ToolBox);
|
||||
if(e == 0)
|
||||
UI()->DoLabel(&Slot, "Embedded", 12.0f, 0);
|
||||
else
|
||||
UI()->DoLabel(&Slot, "External", 12.0f, 0);
|
||||
}
|
||||
SoundCur += 15.0f;
|
||||
|
||||
for(int i = 0; i < m_Map.m_lSounds.size(); i++)
|
||||
{
|
||||
if((e && !m_Map.m_lSounds[i]->m_External) ||
|
||||
(!e && m_Map.m_lSounds[i]->m_External))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(SoundCur > SoundStopAt)
|
||||
break;
|
||||
else if(SoundCur < SoundStartAt)
|
||||
{
|
||||
SoundCur += 14.0f;
|
||||
continue;
|
||||
}
|
||||
SoundCur += 14.0f;
|
||||
continue;
|
||||
}
|
||||
SoundCur += 14.0f;
|
||||
|
||||
char aBuf[128];
|
||||
str_copy(aBuf, m_Map.m_lSounds[i]->m_aName, sizeof(aBuf));
|
||||
ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
|
||||
char aBuf[128];
|
||||
str_copy(aBuf, m_Map.m_lSounds[i]->m_aName, sizeof(aBuf));
|
||||
ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
|
||||
|
||||
int Selected = m_SelectedSound == i;
|
||||
for(int x = 0; x < m_Map.m_lGroups.size(); ++x)
|
||||
for(int j = 0; j < m_Map.m_lGroups[x]->m_lLayers.size(); ++j)
|
||||
if(m_Map.m_lGroups[x]->m_lLayers[j]->m_Type == LAYERTYPE_SOUNDS)
|
||||
{
|
||||
CLayerSounds *pLayer = static_cast<CLayerSounds *>(m_Map.m_lGroups[x]->m_lLayers[j]);
|
||||
if(pLayer->m_Sound == i)
|
||||
goto done;
|
||||
}
|
||||
int Selected = m_SelectedSound == i;
|
||||
for(int x = 0; x < m_Map.m_lGroups.size(); ++x)
|
||||
for(int j = 0; j < m_Map.m_lGroups[x]->m_lLayers.size(); ++j)
|
||||
if(m_Map.m_lGroups[x]->m_lLayers[j]->m_Type == LAYERTYPE_SOUNDS)
|
||||
{
|
||||
CLayerSounds *pLayer = static_cast<CLayerSounds *>(m_Map.m_lGroups[x]->m_lLayers[j]);
|
||||
if(pLayer->m_Sound == i)
|
||||
goto used;
|
||||
}
|
||||
|
||||
Selected += 2; // Sound is unused
|
||||
done:
|
||||
if(Selected < 2 && e == 1)
|
||||
Selected += 4; // Sound should be embedded
|
||||
Selected += 2; // Sound is unused
|
||||
used:
|
||||
float FontSize = 10.0f;
|
||||
while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w)
|
||||
FontSize--;
|
||||
|
||||
float FontSize = 10.0f;
|
||||
while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w)
|
||||
FontSize--;
|
||||
if(int Result = DoButton_Ex(&m_Map.m_lSounds[i], aBuf, Selected, &Slot,
|
||||
BUTTON_CONTEXT, "Select sound.", 0, FontSize))
|
||||
{
|
||||
m_SelectedSound = i;
|
||||
|
||||
if(int Result = DoButton_Ex(&m_Map.m_lSounds[i], aBuf, Selected, &Slot,
|
||||
BUTTON_CONTEXT, "Select sound.", 0, FontSize))
|
||||
{
|
||||
m_SelectedSound = i;
|
||||
|
||||
static int s_PopupSoundID = 0;
|
||||
if(Result == 2)
|
||||
UiInvokePopupMenu(&s_PopupSoundID, 0, UI()->MouseX(), UI()->MouseY(), 120, 60, PopupSound);
|
||||
}
|
||||
|
||||
ToolBox.HSplitTop(2.0f, 0, &ToolBox);
|
||||
static int s_PopupSoundID = 0;
|
||||
if(Result == 2)
|
||||
UiInvokePopupMenu(&s_PopupSoundID, 0, UI()->MouseX(), UI()->MouseY(), 120, 43, PopupSound);
|
||||
}
|
||||
|
||||
// separator
|
||||
ToolBox.HSplitTop(5.0f, &Slot, &ToolBox);
|
||||
SoundCur += 5.0f;
|
||||
IGraphics::CLineItem LineItem(Slot.x, Slot.y + Slot.h / 2, Slot.x + Slot.w, Slot.y + Slot.h / 2);
|
||||
Graphics()->TextureClear();
|
||||
Graphics()->LinesBegin();
|
||||
Graphics()->LinesDraw(&LineItem, 1);
|
||||
Graphics()->LinesEnd();
|
||||
ToolBox.HSplitTop(2.0f, 0, &ToolBox);
|
||||
}
|
||||
|
||||
// separator
|
||||
ToolBox.HSplitTop(5.0f, &Slot, &ToolBox);
|
||||
IGraphics::CLineItem LineItem(Slot.x, Slot.y + Slot.h / 2, Slot.x + Slot.w, Slot.y + Slot.h / 2);
|
||||
Graphics()->TextureClear();
|
||||
Graphics()->LinesBegin();
|
||||
Graphics()->LinesDraw(&LineItem, 1);
|
||||
Graphics()->LinesEnd();
|
||||
|
||||
if(Input()->KeyPress(KEY_DOWN) && m_Dialog == DIALOG_NONE)
|
||||
{
|
||||
int OldSound = m_SelectedSound;
|
||||
m_SelectedSound = clamp(m_SelectedSound, 0, m_Map.m_lSounds.size() - 1);
|
||||
for(int i = m_SelectedSound + 1; i < m_Map.m_lSounds.size(); i++)
|
||||
{
|
||||
if(m_Map.m_lSounds[i]->m_External == m_Map.m_lSounds[m_SelectedSound]->m_External)
|
||||
{
|
||||
m_SelectedSound = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(m_SelectedSound == OldSound && !m_Map.m_lSounds[m_SelectedSound]->m_External)
|
||||
{
|
||||
for(int i = 0; i < m_Map.m_lSounds.size(); i++)
|
||||
{
|
||||
if(m_Map.m_lSounds[i]->m_External)
|
||||
{
|
||||
m_SelectedSound = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_SelectedSound == m_Map.m_lSounds.size() - 1)
|
||||
m_SelectedSound = 0;
|
||||
else
|
||||
m_SelectedSound += 1;
|
||||
}
|
||||
if(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE)
|
||||
{
|
||||
int OldSound = m_SelectedSound;
|
||||
m_SelectedSound = clamp(m_SelectedSound, 0, m_Map.m_lSounds.size() - 1);
|
||||
for(int i = m_SelectedSound - 1; i >= 0; i--)
|
||||
{
|
||||
if(m_Map.m_lSounds[i]->m_External == m_Map.m_lSounds[m_SelectedSound]->m_External)
|
||||
{
|
||||
m_SelectedSound = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(m_SelectedSound == OldSound && m_Map.m_lSounds[m_SelectedSound]->m_External)
|
||||
{
|
||||
for(int i = m_Map.m_lSounds.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if(!m_Map.m_lSounds[i]->m_External)
|
||||
{
|
||||
m_SelectedSound = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_SelectedSound == 0 && m_Map.m_lSounds.size() != 0)
|
||||
m_SelectedSound = m_Map.m_lSounds.size() - 1;
|
||||
else
|
||||
m_SelectedSound -= 1;
|
||||
}
|
||||
|
||||
CUIRect Slot;
|
||||
//CUIRect Slot;
|
||||
ToolBox.HSplitTop(5.0f, &Slot, &ToolBox);
|
||||
|
||||
// new Sound
|
||||
|
|
|
@ -313,7 +313,6 @@ public:
|
|||
{
|
||||
m_pEditor = pEditor;
|
||||
m_aName[0] = 0;
|
||||
m_External = 0;
|
||||
m_SoundID = 0;
|
||||
|
||||
m_pData = 0x0;
|
||||
|
@ -323,7 +322,6 @@ public:
|
|||
~CEditorSound();
|
||||
|
||||
int m_SoundID;
|
||||
int m_External;
|
||||
char m_aName[128];
|
||||
|
||||
void *m_pData;
|
||||
|
|
|
@ -337,18 +337,10 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
CMapItemSound Item;
|
||||
Item.m_Version = 1;
|
||||
|
||||
Item.m_External = pSound->m_External;
|
||||
Item.m_External = 0;
|
||||
Item.m_SoundName = df.AddData(str_length(pSound->m_aName) + 1, pSound->m_aName);
|
||||
if(pSound->m_External)
|
||||
{
|
||||
Item.m_SoundDataSize = 0;
|
||||
Item.m_SoundData = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item.m_SoundData = df.AddData(pSound->m_DataSize, pSound->m_pData);
|
||||
Item.m_SoundDataSize = pSound->m_DataSize;
|
||||
}
|
||||
Item.m_SoundData = df.AddData(pSound->m_DataSize, pSound->m_pData);
|
||||
Item.m_SoundDataSize = pSound->m_DataSize;
|
||||
|
||||
df.AddItem(MAPITEMTYPE_SOUND, i, sizeof(Item), &Item);
|
||||
}
|
||||
|
@ -742,7 +734,6 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
|
||||
// copy base info
|
||||
CEditorSound *pSound = new CEditorSound(m_pEditor);
|
||||
pSound->m_External = pItem->m_External;
|
||||
|
||||
if(pItem->m_External)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue