@@ -41,8 +41,7 @@ class GroupTintCallback
4141 } inline static imguiPersist;
4242
4343public:
44- GroupTintCallback (TrTracePlayer& tracePlayer)
45- : tracePlayer(tracePlayer), imguiEntrySelection(tracePlayer.imguiEntrySelect)
44+ GroupTintCallback () : tracePlayer(TrTracePlayer::Singleton()), imguiEntrySelection(tracePlayer.imguiEntrySelect)
4645 {
4746#ifndef NDEBUG
4847 // sanity check
@@ -391,35 +390,39 @@ class GroupTintCallback
391390 }
392391};
393392
394- static bool inheritSingleTraceFlags = true ;
393+ // returns flag value
394+ static bool DrawEnableFlag (TrRenderEnableFlag flag, const char * label)
395+ {
396+ bool val = flag;
397+ if (ImGui::Checkbox (label, &val))
398+ flag = val;
399+ return val;
400+ }
395401
396402static void DrawMultiTraceEnableFlag (TrRenderEnableOpt opt, const char * label)
397403{
398404 auto & tp = TrTracePlayer::Singleton ();
399405 TrRenderEnableFlag multiFlag = tp.multiTraceRenderEnableCfg [opt];
400406
401- if (inheritSingleTraceFlags )
407+ if (tp. multiEnableFlagsInheritDisabledSingleEnableFlags )
402408 {
403409 TrRenderEnableFlag singleFlag = tp.singleTraceRenderEnableCfg [opt];
404410 ImGui::BeginDisabled (!singleFlag);
405- bool val = multiFlag;
406- if (ImGui::Checkbox (label, &val))
407- multiFlag = val;
411+ DrawEnableFlag (multiFlag, label);
408412 if (!singleFlag)
409413 ImGui::SetItemTooltip (" Disabled in general settings" );
410414 ImGui::EndDisabled ();
411415 }
412416 else
413417 {
414- bool val = multiFlag;
415- if (ImGui::Checkbox (label, &val))
416- multiFlag = val;
418+ DrawEnableFlag (multiFlag, label);
417419 }
418420}
419421
420422static void DrawMultiTraceEnableConfig ()
421423{
422- ImGui::Checkbox (" Inherit disabled single trace flags" , &inheritSingleTraceFlags);
424+ auto & tp = TrTracePlayer::Singleton ();
425+ ImGui::Checkbox (" Inherit disabled single trace flags" , &tp.multiEnableFlagsInheritDisabledSingleEnableFlags );
423426 ImGui::SameLine ();
424427 SptImGui::HelpMarker (
425428 " If a setting is disabled in the general settings,\n "
@@ -440,26 +443,157 @@ static void DrawMultiTraceEnableConfig()
440443 DrawMultiTraceEnableFlag (TR_RENDER_ENABLE_ENT_COLLECT_AABB, " Draw entity collection volume" );
441444}
442445
443- static void DrawSingleTraceConfig () {}
446+ class SingleTraceConfigCallback
447+ {
448+ TrTracePlayer& tracePlayer;
449+ TrRenderStyleConfig& style;
450+ TrRenderEnableConfig& enableFlags;
451+ bool groupsDirty = false ;
452+
453+ public:
454+ SingleTraceConfigCallback ()
455+ : tracePlayer(TrTracePlayer::Singleton())
456+ , style(tracePlayer.mainStyleConfig)
457+ , enableFlags(tracePlayer.singleTraceRenderEnableCfg)
458+ {
459+ }
460+
461+ void Draw ()
462+ {
463+ PlayerPath ();
464+
465+ if (groupsDirty)
466+ tracePlayer.MarkGroupStylesDirty ();
467+ }
468+
469+ private:
470+ static bool ResetButton ()
471+ {
472+ bool ret = ImGui::SmallButton (ICON_CI_DEBUG_RESTART);
473+ ImGui::SetItemTooltip (" reset default values" );
474+ return ret;
475+ }
476+
477+ void SliderFloat (const char * label,
478+ float * v,
479+ float displayMin,
480+ float displayMax,
481+ float actualMin,
482+ float actualMax)
483+ {
484+ if (ImGui::SliderFloat (label, v, displayMin, displayMax))
485+ {
486+ *v = std::max (*v, actualMin);
487+ *v = std::min (*v, actualMax);
488+ groupsDirty = true ;
489+ }
490+ }
491+
492+ void SliderInt (const char * label, int * v, int displayMin, int displayMax, int actualMin, int actualMax)
493+ {
494+ if (ImGui::SliderInt (label, v, displayMin, displayMax))
495+ {
496+ *v = std::max (*v, actualMin);
497+ *v = std::min (*v, actualMax);
498+ groupsDirty = true ;
499+ }
500+ }
501+
502+ struct ScopedEnableSection
503+ {
504+ bool open = false ;
505+ bool enabled = true ;
506+ bool resetButtonPressed = false ; // check for this by hand
507+
508+ ScopedEnableSection (const char * label, TrRenderEnableOpt opt)
509+ {
510+ open = ImGui::TreeNode (label);
511+ if (!open)
512+ return ;
513+ enabled = DrawEnableFlag (TrTracePlayer::Singleton ().singleTraceRenderEnableCfg [opt], " draw" );
514+ ImGui::BeginDisabled (!enabled);
515+ resetButtonPressed = ResetButton ();
516+ }
517+
518+ ~ScopedEnableSection ()
519+ {
520+ if (open)
521+ {
522+ ImGui::EndDisabled ();
523+ ImGui::TreePop ();
524+ }
525+ }
526+ };
527+
528+ void PlayerPath ()
529+ {
530+ ScopedEnableSection scope (" Player path" , TR_RENDER_ENABLE_PLAYER_PATH);
531+ auto & playerPath = style.playerPath ;
532+ if (scope.resetButtonPressed )
533+ playerPath = TrRenderStyleConfig{}.playerPath ;
534+
535+ PlayerPathCones ();
536+ PlayerPathEndpoints ();
537+ // TODO segments
538+ }
539+
540+ void PlayerPathCones ()
541+ {
542+ ScopedEnableSection scope (" Cones" , TR_RENDER_ENABLE_PLAYER_PATH_CONES);
543+ auto & cones = style.playerPath .cones ;
544+ if (scope.resetButtonPressed )
545+ cones = TrRenderStyleConfig{}.playerPath .cones ;
546+
547+ SliderFloat (" opacity" , &cones.opacity , 0 .f , 1 .f , 0 .f , 1 .f );
548+ SliderInt (" circle resolution" , &cones.nCirclePoints , 3 , 15 , 3 , 666 );
549+ SliderFloat (" length" , &cones.length , 0 .1f , 10 .f , 0 .01f , INFINITY);
550+ SliderFloat (" radius" , &cones.radius , 0 .1f , 4 .f , 0 .01f , INFINITY);
551+ SliderInt (" tick interval" , &cones.tickInterval , 5 , 50 , 1 , 666 );
552+ }
553+
554+ void PlayerPathEndpoints ()
555+ {
556+ ScopedEnableSection scope (" Endpoints" , TR_RENDER_ENABLE_PLAYER_PATH_ENDPOINTS);
557+ auto & endpoints = style.playerPath .endpoints ;
558+ if (scope.resetButtonPressed )
559+ endpoints = TrRenderStyleConfig{}.playerPath .endpoints ;
560+
561+ SliderFloat (" opacity" , &endpoints.opacity , 0 .f , 1 .f , 0 .f , 1 .f );
562+ SliderInt (" circle resolution" , &endpoints.nCirclePoints , 3 , 15 , 3 , 666 );
563+ SliderFloat (" radius" , &endpoints.radius , 0 .1f , 10 .f , 0 .01f , INFINITY);
564+ }
565+
566+ void PlayerHull () {
567+ ScopedEnableSection scope (" Player hull" , TR_RENDER_ENABLE_PLAYER_HULL);
568+ auto & playerHull = style.playerHull ;
569+ if (scope.resetButtonPressed )
570+ playerHull = TrRenderStyleConfig{}.playerHull ;
571+
572+
573+ }
574+ };
444575
445576void tr_imgui::RenderStyleTab ()
446577{
447578 // TODO add the other convars here
448579 bool draw = SptImGui::CvarCheckbox (spt_draw_trace, " Draw trace(s)" );
449580 ImGui::BeginDisabled (!draw);
450581
451- auto & tp = TrTracePlayer::Singleton ();
452-
453582 if (ImGui::CollapsingHeader (" Trace groups" ))
454583 {
455- GroupTintCallback groupTints (tp) ;
584+ GroupTintCallback groupTints;
456585 groupTints.Draw ();
457586 }
458587
588+ auto & tp = TrTracePlayer::Singleton ();
589+
459590 ImGui::Text (" Drawing %u trace%s" , tp.nDrawnTracesLastFrame , tp.nDrawnTracesLastFrame == 1 ? " " : " s" );
460591
461592 if (ImGui::CollapsingHeader (" Style settings" ))
462- DrawSingleTraceConfig ();
593+ {
594+ SingleTraceConfigCallback singleTraceConfig;
595+ singleTraceConfig.Draw ();
596+ }
463597
464598 ImGui::BeginDisabled (tp.nDrawnTracesLastFrame < 2 );
465599 if (ImGui::CollapsingHeader (" Multi-trace options" ))
0 commit comments