MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderSounds

Method RenderSounds

src/game/editor/editor.cpp:4100–4188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4098}
4099
4100void CEditor::RenderSounds(CUIRect ToolBox)
4101{
4102 const float RowHeight = 12.0f;
4103
4104 static CScrollRegion s_ScrollRegion;
4105 vec2 ScrollOffset(0.0f, 0.0f);
4106 CScrollRegionParams ScrollParams;
4107 ScrollParams.m_ScrollbarWidth = 10.0f;
4108 ScrollParams.m_ScrollbarMargin = 3.0f;
4109 ScrollParams.m_ScrollUnit = RowHeight * 5;
4110 s_ScrollRegion.Begin(&ToolBox, &ScrollOffset, &ScrollParams);
4111 ToolBox.y += ScrollOffset.y;
4112
4113 bool ScrollToSelection = false;
4114 if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && !Map()->m_vpSounds.empty())
4115 {
4116 if(Input()->KeyPress(KEY_DOWN))
4117 {
4118 Map()->SelectNextSound();
4119 ScrollToSelection = true;
4120 }
4121 else if(Input()->KeyPress(KEY_UP))
4122 {
4123 Map()->SelectPreviousSound();
4124 ScrollToSelection = true;
4125 }
4126 }
4127
4128 CUIRect Slot;
4129 ToolBox.HSplitTop(RowHeight + 3.0f, &Slot, &ToolBox);
4130 if(s_ScrollRegion.AddRect(Slot))
4131 Ui()->DoLabel(&Slot, "Embedded", 12.0f, TEXTALIGN_MC);
4132
4133 for(int i = 0; i < (int)Map()->m_vpSounds.size(); i++)
4134 {
4135 ToolBox.HSplitTop(RowHeight + 2.0f, &Slot, &ToolBox);
4136 int Selected = Map()->m_SelectedSound == i;
4137 if(!s_ScrollRegion.AddRect(Slot, Selected && ScrollToSelection))
4138 continue;
4139 Slot.HSplitTop(RowHeight, &Slot, nullptr);
4140
4141 const bool SoundUsed = std::any_of(Map()->m_vpGroups.cbegin(), Map()->m_vpGroups.cend(), [i](const auto &pGroup) {
4142 return std::any_of(pGroup->m_vpLayers.cbegin(), pGroup->m_vpLayers.cend(), [i](const auto &pLayer) {
4143 if(pLayer->m_Type == LAYERTYPE_SOUNDS)
4144 return std::static_pointer_cast<CLayerSounds>(pLayer)->m_Sound == i;
4145 return false;
4146 });
4147 });
4148
4149 if(!SoundUsed)
4150 Selected += 2; // Sound is unused
4151
4152 if(int Result = DoButton_Ex(&Map()->m_vpSounds[i], Map()->m_vpSounds[i]->m_aName, Selected, &Slot,
4153 BUTTONFLAG_LEFT | BUTTONFLAG_RIGHT, "Select sound.", IGraphics::CORNER_ALL))
4154 {
4155 Map()->m_SelectedSound = i;
4156
4157 if(Result == 2)

Callers

nothing calls this directly

Calls 15

MapFunction · 0.85
InputFunction · 0.85
UiFunction · 0.85
GraphicsFunction · 0.85
KeyPressMethod · 0.80
SelectNextSoundMethod · 0.80
SelectPreviousSoundMethod · 0.80
HSplitTopMethod · 0.80
AddRectMethod · 0.80
DoLabelMethod · 0.80
DoPopupMenuMethod · 0.80
MouseXMethod · 0.80

Tested by

no test coverage detected