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,30 +4173,14 @@ 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;
if(SoundCur > SoundStopAt)
break;
else if(SoundCur >= SoundStartAt)
{
ToolBox.HSplitTop(15.0f, &Slot, &ToolBox); ToolBox.HSplitTop(15.0f, &Slot, &ToolBox);
if(e == 0)
UI()->DoLabel(&Slot, "Embedded", 12.0f, 0); UI()->DoLabel(&Slot, "Embedded", 12.0f, 0);
else
UI()->DoLabel(&Slot, "External", 12.0f, 0);
}
SoundCur += 15.0f; SoundCur += 15.0f;
for(int i = 0; i < m_Map.m_lSounds.size(); i++) 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) if(SoundCur > SoundStopAt)
break; break;
else if(SoundCur < SoundStartAt) else if(SoundCur < SoundStartAt)
@ -4241,14 +4201,11 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
{ {
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)
Selected += 4; // Sound should be embedded
float FontSize = 10.0f; float FontSize = 10.0f;
while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w) while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w)
FontSize--; FontSize--;
@ -4260,7 +4217,7 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
static int s_PopupSoundID = 0; static int s_PopupSoundID = 0;
if(Result == 2) if(Result == 2)
UiInvokePopupMenu(&s_PopupSoundID, 0, UI()->MouseX(), UI()->MouseY(), 120, 60, PopupSound); UiInvokePopupMenu(&s_PopupSoundID, 0, UI()->MouseX(), UI()->MouseY(), 120, 43, PopupSound);
} }
ToolBox.HSplitTop(2.0f, 0, &ToolBox); ToolBox.HSplitTop(2.0f, 0, &ToolBox);
@ -4268,64 +4225,30 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
// separator // separator
ToolBox.HSplitTop(5.0f, &Slot, &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); IGraphics::CLineItem LineItem(Slot.x, Slot.y + Slot.h / 2, Slot.x + Slot.w, Slot.y + Slot.h / 2);
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->LinesBegin(); Graphics()->LinesBegin();
Graphics()->LinesDraw(&LineItem, 1); Graphics()->LinesDraw(&LineItem, 1);
Graphics()->LinesEnd(); 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_SoundDataSize = 0;
Item.m_SoundData = -1;
}
else
{
Item.m_SoundData = df.AddData(pSound->m_DataSize, pSound->m_pData); Item.m_SoundData = df.AddData(pSound->m_DataSize, pSound->m_pData);
Item.m_SoundDataSize = pSound->m_DataSize; 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)
{ {