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

Method DoMapSettingsEditBox

src/game/editor/editor_server_settings.cpp:289–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289void CEditor::DoMapSettingsEditBox(CMapSettingsBackend::CContext *pContext, const CUIRect *pRect, float FontSize, float DropdownMaxHeight, int Corners, const char *pToolTip)
290{
291 // Main method to do the full featured map settings edit box
292
293 auto *pLineInput = pContext->LineInput();
294 auto &Context = *pContext;
295 Context.SetFontSize(FontSize);
296
297 // Small utility to render a floating part above the input rect.
298 // Use to display either the error or the current argument name
299 const float PartMargin = 4.0f;
300 auto &&RenderFloatingPart = [&](CUIRect *pInputRect, float x, const char *pStr) {
301 CUIRect Background;
302 Background.x = x - PartMargin;
303 Background.y = pInputRect->y - pInputRect->h - 6.0f;
304 Background.w = TextRender()->TextWidth(FontSize, pStr) + 2 * PartMargin;
305 Background.h = pInputRect->h;
306 Background.Draw(ColorRGBA(0, 0, 0, 0.9f), IGraphics::CORNER_ALL, 3.0f);
307
308 CUIRect Label;
309 Background.VSplitLeft(PartMargin, nullptr, &Label);
310 TextRender()->TextColor(0.8f, 0.8f, 0.8f, 1.0f);
311 Ui()->DoLabel(&Label, pStr, FontSize, TEXTALIGN_ML);
312 TextRender()->TextColor(TextRender()->DefaultTextColor());
313 };
314
315 // If we have a valid command, display the help in the tooltip
316 if(Context.CommandIsValid() && pLineInput->IsActive() && Ui()->HotItem() == nullptr)
317 {
318 Context.GetCommandHelpText(m_aTooltip, sizeof(m_aTooltip));
319 str_append(m_aTooltip, ".");
320 }
321
322 CUIRect ToolBar = *pRect;
323 CUIRect Button;
324 ToolBar.VSplitRight(ToolBar.h, &ToolBar, &Button);
325
326 // Do the unknown command toggle button
327 if(DoButton_FontIcon(&Context.m_AllowUnknownCommands, FontIcon::QUESTION, Context.m_AllowUnknownCommands, &Button, BUTTONFLAG_LEFT, "Disallow/allow unknown or invalid commands.", IGraphics::CORNER_R))
328 {
329 Context.m_AllowUnknownCommands = !Context.m_AllowUnknownCommands;
330 Context.Update();
331 }
332
333 // Color the arguments
334 std::vector<STextColorSplit> vColorSplits;
335 Context.ColorArguments(vColorSplits);
336
337 // Do and render clearable edit box with the colors
338 if(DoClearableEditBox(pLineInput, &ToolBar, FontSize, IGraphics::CORNER_L, "Enter a server setting. Press ctrl+space to show available settings.", vColorSplits))
339 {
340 Context.Update(); // Update the context when contents change
341 Context.m_DropdownContext.m_ShouldHide = false;
342 }
343
344 // Update/track the cursor
345 if(Context.UpdateCursor())
346 Context.m_DropdownContext.m_ShouldHide = false;

Callers

nothing calls this directly

Calls 15

TextRenderFunction · 0.85
UiFunction · 0.85
str_lengthFunction · 0.85
LineInputMethod · 0.80
SetFontSizeMethod · 0.80
TextWidthMethod · 0.80
VSplitLeftMethod · 0.80
TextColorMethod · 0.80
DoLabelMethod · 0.80
DefaultTextColorMethod · 0.80
CommandIsValidMethod · 0.80
HotItemMethod · 0.80

Tested by

no test coverage detected