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:
bors[bot] 2020-10-26 09:50:06 +00:00 committed by GitHub
commit 331c9f695c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 145 deletions

View file

@ -3718,7 +3718,6 @@ void CEditor::AddSound(const char *pFileName, int StorageType, void *pUser)
// add sound // add sound
CEditorSound *pSound = new CEditorSound(pEditor); CEditorSound *pSound = new CEditorSound(pEditor);
pSound->m_SoundID = SoundId; pSound->m_SoundID = SoundId;
pSound->m_External = 0; // embedded by default
pSound->m_DataSize = (unsigned)DataSize; pSound->m_DataSize = (unsigned)DataSize;
pSound->m_pData = pData; pSound->m_pData = pData;
str_copy(pSound->m_aName, aBuf, sizeof(pSound->m_aName)); 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); io_close(SoundFile);
CEditorSound *pSound = pEditor->m_Map.m_lSounds[pEditor->m_SelectedSound]; CEditorSound *pSound = pEditor->m_Map.m_lSounds[pEditor->m_SelectedSound];
int External = pSound->m_External;
// unload sample // unload sample
pEditor->Sound()->UnloadSample(pSound->m_SoundID); pEditor->Sound()->UnloadSample(pSound->m_SoundID);
@ -3775,7 +3773,6 @@ void CEditor::ReplaceSound(const char *pFileName, int StorageType, void *pUser)
} }
// replace sound // replace sound
pSound->m_External = External;
IStorage::StripPathAndExtension(pFileName, pSound->m_aName, sizeof(pSound->m_aName)); IStorage::StripPathAndExtension(pFileName, pSound->m_aName, sizeof(pSound->m_aName));
pSound->m_SoundID = pEditor->Sound()->LoadOpusFromMem(pData, (unsigned)DataSize, true); pSound->m_SoundID = pEditor->Sound()->LoadOpusFromMem(pData, (unsigned)DataSize, true);
pSound->m_pData = pData; pSound->m_pData = pData;
@ -3851,28 +3848,6 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext)
CUIRect Slot; CUIRect Slot;
View.HSplitTop(2.0f, &Slot, &View); View.HSplitTop(2.0f, &Slot, &View);
View.HSplitTop(12.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")) 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); 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(5.0f, &Slot, &View);
View.HSplitTop(12.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")) if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the sound from the map"))
{ {
delete pSound; delete pSound;
@ -4197,135 +4173,82 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
float SoundStopAt = SoundsHeight - ScrollDifference * (1 - s_ScrollValue); float SoundStopAt = SoundsHeight - ScrollDifference * (1 - s_ScrollValue);
float SoundCur = 0.0f; 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) if(SoundCur > SoundStopAt)
break; 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; SoundCur += 14.0f;
continue;
}
SoundCur += 14.0f;
char aBuf[128]; char aBuf[128];
str_copy(aBuf, m_Map.m_lSounds[i]->m_aName, sizeof(aBuf)); str_copy(aBuf, m_Map.m_lSounds[i]->m_aName, sizeof(aBuf));
ToolBox.HSplitTop(12.0f, &Slot, &ToolBox); ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
int Selected = m_SelectedSound == i; int Selected = m_SelectedSound == i;
for(int x = 0; x < m_Map.m_lGroups.size(); ++x) 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) 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) 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]); CLayerSounds *pLayer = static_cast<CLayerSounds *>(m_Map.m_lGroups[x]->m_lLayers[j]);
if(pLayer->m_Sound == i) if(pLayer->m_Sound == i)
goto done; goto used;
} }
Selected += 2; // Sound is unused Selected += 2; // Sound is unused
done: used:
if(Selected < 2 && e == 1) float FontSize = 10.0f;
Selected += 4; // Sound should be embedded while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w)
FontSize--;
float FontSize = 10.0f; if(int Result = DoButton_Ex(&m_Map.m_lSounds[i], aBuf, Selected, &Slot,
while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w) BUTTON_CONTEXT, "Select sound.", 0, FontSize))
FontSize--; {
m_SelectedSound = i;
if(int Result = DoButton_Ex(&m_Map.m_lSounds[i], aBuf, Selected, &Slot, static int s_PopupSoundID = 0;
BUTTON_CONTEXT, "Select sound.", 0, FontSize)) if(Result == 2)
{ UiInvokePopupMenu(&s_PopupSoundID, 0, UI()->MouseX(), UI()->MouseY(), 120, 43, PopupSound);
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);
} }
// separator ToolBox.HSplitTop(2.0f, 0, &ToolBox);
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();
} }
// 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) 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); 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_SelectedSound == m_Map.m_lSounds.size() - 1)
{ m_SelectedSound = 0;
if(m_Map.m_lSounds[i]->m_External == m_Map.m_lSounds[m_SelectedSound]->m_External) else
{ m_SelectedSound += 1;
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(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE) 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); m_SelectedSound = clamp(m_SelectedSound, 0, m_Map.m_lSounds.size() - 1);
for(int i = m_SelectedSound - 1; i >= 0; i--) if(m_SelectedSound == 0 && m_Map.m_lSounds.size() != 0)
{ m_SelectedSound = m_Map.m_lSounds.size() - 1;
if(m_Map.m_lSounds[i]->m_External == m_Map.m_lSounds[m_SelectedSound]->m_External) else
{ m_SelectedSound -= 1;
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;
}
}
}
} }
CUIRect Slot; //CUIRect Slot;
ToolBox.HSplitTop(5.0f, &Slot, &ToolBox); ToolBox.HSplitTop(5.0f, &Slot, &ToolBox);
// new Sound // new Sound

View file

@ -313,7 +313,6 @@ public:
{ {
m_pEditor = pEditor; m_pEditor = pEditor;
m_aName[0] = 0; m_aName[0] = 0;
m_External = 0;
m_SoundID = 0; m_SoundID = 0;
m_pData = 0x0; m_pData = 0x0;
@ -323,7 +322,6 @@ public:
~CEditorSound(); ~CEditorSound();
int m_SoundID; int m_SoundID;
int m_External;
char m_aName[128]; char m_aName[128];
void *m_pData; void *m_pData;

View file

@ -337,18 +337,10 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
CMapItemSound Item; CMapItemSound Item;
Item.m_Version = 1; 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); Item.m_SoundName = df.AddData(str_length(pSound->m_aName) + 1, pSound->m_aName);
if(pSound->m_External) Item.m_SoundData = df.AddData(pSound->m_DataSize, pSound->m_pData);
{ Item.m_SoundDataSize = pSound->m_DataSize;
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;
}
df.AddItem(MAPITEMTYPE_SOUND, i, sizeof(Item), &Item); 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 // copy base info
CEditorSound *pSound = new CEditorSound(m_pEditor); CEditorSound *pSound = new CEditorSound(m_pEditor);
pSound->m_External = pItem->m_External;
if(pItem->m_External) if(pItem->m_External)
{ {