diff --git a/src/components/modules/d3dbsp.cpp b/src/components/modules/d3dbsp.cpp index db58882..dd00ef0 100644 --- a/src/components/modules/d3dbsp.cpp +++ b/src/components/modules/d3dbsp.cpp @@ -9,7 +9,6 @@ namespace components int d3dbsp::radiant_dobj_count = 0; d3dbsp::radiant_dobj_s d3dbsp::radiant_dobj[512] = {}; - void d3dbsp::dobj_clear_list() { memset(d3dbsp::radiant_dobj, 0, sizeof(d3dbsp::radiant_dobj)); @@ -744,6 +743,22 @@ namespace components } } + void d3dbsp::toggle_radiant_bsp_view(bool show_bsp) + { + if (d3dbsp::Com_IsBspLoaded()) + { + const bool gameview_was_enabled = dvars::radiant_gameview->current.enabled; + + dvars::set_bool(dvars::r_draw_bsp, show_bsp); + gameview::get()->toggle_all_filters(show_bsp); + + if (gameview_was_enabled) + { + components::gameview::p_this->set_state(gameview_was_enabled); + } + } + } + void d3dbsp::compile_fastfile(const std::string& bsp_name) { game::printf_to_console("[BSP] Compiling fastfile for map: %s ... \n", bsp_name.c_str()); @@ -864,8 +879,7 @@ namespace components { if (dvars::bsp_show_bsp_after_compile->current.enabled) { - command::execute("toggle_bsp_radiant"); - dvars::set_bool(dvars::r_draw_bsp, dvars::bsp_show_bsp_after_compile->current.enabled); + toggle_radiant_bsp_view(true); } // slightly delay process generation @@ -1020,6 +1034,8 @@ namespace components /* desc */ "enable to overwrite bsp sunspecular with fakesun settings"); } + + d3dbsp::d3dbsp() { // # diff --git a/src/components/modules/d3dbsp.hpp b/src/components/modules/d3dbsp.hpp index da33370..e7b19ba 100644 --- a/src/components/modules/d3dbsp.hpp +++ b/src/components/modules/d3dbsp.hpp @@ -136,6 +136,8 @@ namespace components static bool radiant_load_bsp(const char* bsppath, bool reload = false); static void reload_bsp(); + static void toggle_radiant_bsp_view(bool show_bsp); + static void compile_fastfile(const std::string& bsp_name); static void compile_bsp(const std::string& bsp_name, bool generate_createfx = false); static void compile_current_map(); diff --git a/src/components/modules/gameview.cpp b/src/components/modules/gameview.cpp index 6fb4901..6c467e0 100644 --- a/src/components/modules/gameview.cpp +++ b/src/components/modules/gameview.cpp @@ -4,6 +4,11 @@ namespace components { gameview* gameview::p_this = nullptr; + gameview* gameview::get() + { + return p_this; + } + void gameview::toggle_all_geo(bool state) { if (!gameview::p_this) @@ -269,6 +274,29 @@ namespace components gameview::all_off = !gameview::all_off; } + void gameview::toggle_all_filters(bool state) + { + // restore states if was toggled manually + if (gameview::get_all_geo_state()) gameview::toggle_all_geo(false); + if (gameview::get_all_ents_state()) gameview::toggle_all_entities(false); + if (gameview::get_all_triggers_state()) gameview::toggle_all_triggers(false); + if (gameview::get_all_others_state()) gameview::toggle_all_others(false); + + // toggle global + gameview::toggle_all_geo(state); + gameview::toggle_all_entities(state); + gameview::toggle_all_triggers(state); + gameview::toggle_all_others(state); + + gameview::all_off = state; + } + + bool gameview::toggle_all_get_state() + { + return all_off; + } + + void gameview::set_state(bool state) { const auto filter = GET_GUI(ggui::filter_dialog); diff --git a/src/components/modules/gameview.hpp b/src/components/modules/gameview.hpp index e09aa68..e12c958 100644 --- a/src/components/modules/gameview.hpp +++ b/src/components/modules/gameview.hpp @@ -10,6 +10,7 @@ namespace components const char* get_name() override { return "gameview"; }; static gameview* p_this; + static gameview* get(); [[nodiscard]] bool get_all_geo_state() const { @@ -36,7 +37,9 @@ namespace components void toggle_all_triggers(bool state); void toggle_all_others(bool state); void toggle_all_filters(); - + void toggle_all_filters(bool state); + bool toggle_all_get_state(); + void set_state(bool state); static void register_dvars(); diff --git a/src/components/modules/renderer.cpp b/src/components/modules/renderer.cpp index 6f517a2..8a4aa99 100644 --- a/src/components/modules/renderer.cpp +++ b/src/components/modules/renderer.cpp @@ -2141,17 +2141,17 @@ namespace components { if (!dvars::r_draw_bsp->current.enabled) { - game::printf_to_console("[Reflections] Turning on bsp view ..."); - command::execute("toggle_bsp_radiant"); + game::printf_to_console("[Reflections] Turning on bsp view ...\n"); + d3dbsp::toggle_radiant_bsp_view(true); } reflectionprobes::generate_reflections_for_bsp(); dvars::set_bool(dvars::r_reflectionprobe_generate, false); - if (dvars::bsp_show_bsp_after_compile->current.enabled) + // turn off bsp view if user doesnt want it on + if (!dvars::bsp_show_bsp_after_compile->current.enabled) { - command::execute("toggle_bsp_radiant"); - dvars::set_bool(dvars::r_draw_bsp, dvars::bsp_show_bsp_after_compile->current.enabled); + d3dbsp::toggle_radiant_bsp_view(false); } if (dvars::bsp_gen_fastfile_on_compile->current.enabled) diff --git a/src/ggui/camera.cpp b/src/ggui/camera.cpp index a7b632a..328027a 100644 --- a/src/ggui/camera.cpp +++ b/src/ggui/camera.cpp @@ -262,7 +262,7 @@ namespace ggui , &toolbar_button_background_active , &toolbar_button_size)) { - components::command::execute("toggle_bsp_radiant"); + components::d3dbsp::toggle_radiant_bsp_view(!show_bsp_icon); } ggui::rtt_handle_windowfocus_overlaywidget(this->rtt_get_hovered_state()); } @@ -285,7 +285,7 @@ namespace ggui static bool hov_toggle_world; - const auto gameview = components::gameview::p_this; + const auto gameview = components::gameview::get(); const bool tstate = gameview->get_all_geo_state() || gameview->get_all_ents_state() || gameview->get_all_triggers_state() || gameview->get_all_others_state(); if (tb->image_togglebutton("toggle_radiant_world" @@ -297,7 +297,7 @@ namespace ggui , &toolbar_button_background_active , &toolbar_button_size)) { - components::command::execute("toggle_filter_all"); + gameview->toggle_all_filters(!tstate); } ggui::rtt_handle_windowfocus_overlaywidget(this->rtt_get_hovered_state()); } diff --git a/src/ggui/menubar.cpp b/src/ggui/menubar.cpp index b780c08..d8b3e60 100644 --- a/src/ggui/menubar.cpp +++ b/src/ggui/menubar.cpp @@ -1006,14 +1006,14 @@ namespace ggui dvars::set_bool(dvars::r_draw_bsp, !dvars::r_draw_bsp->current.enabled); } - if (ImGui::MenuItem("Toggle d3dbsp/radiant", ggui::hotkey_dialog::get_hotkey_for_command("toggle_bsp_radiant").c_str())) + if (ImGui::MenuItem("Toggle d3dbsp/radiant", ggui::hotkey_dialog::get_hotkey_for_command("toggle_bsp_radiant").c_str(), dvars::r_draw_bsp->current.enabled)) { - components::command::execute("toggle_bsp_radiant"); + components::d3dbsp::toggle_radiant_bsp_view(!dvars::r_draw_bsp->current.enabled); } if (ImGui::MenuItem("Draw Radiant World", ggui::hotkey_dialog::get_hotkey_for_command("toggle_filter_all").c_str(), !tstate)) { - components::command::execute("toggle_filter_all"); + gameview->toggle_all_filters(); } ImGui::EndDisabled(); diff --git a/src/ggui/preferences.cpp b/src/ggui/preferences.cpp index 643fed6..b19b3c8 100644 --- a/src/ggui/preferences.cpp +++ b/src/ggui/preferences.cpp @@ -262,8 +262,6 @@ namespace ggui ImGui::title_with_seperator("Toolbar"); ImGui::Checkbox("Draw FPS within the camera window", &dvars::gui_draw_fps->current.enabled); ImGui::Checkbox("Default Open - Toolbar", &dvars::gui_camera_toolbar_defaultopen->current.enabled); - ImGui::Checkbox("Merge BSP/Radiant buttons", &dvars::gui_camera_toolbar_merge_bsp_buttons->current.enabled); TT(dvars::gui_camera_toolbar_merge_bsp_buttons->description); - }); } @@ -399,6 +397,9 @@ namespace ggui ImGui::DvarInt_External("Display aabb Trees", "r_showaabbtrees"); ImGui::DvarInt_External("Display portals", "r_showportals"); + // ----------------- + ImGui::title_with_seperator("Gui"); + ImGui::Checkbox("Merge BSP/Radiant buttons (camera toolbar)", &dvars::gui_camera_toolbar_merge_bsp_buttons->current.enabled); TT(dvars::gui_camera_toolbar_merge_bsp_buttons->description); // ----------------- ImGui::title_with_seperator("BSP Only"); diff --git a/src/ggui/toolbox.cpp b/src/ggui/toolbox.cpp index dc2eb82..faf5a64 100644 --- a/src/ggui/toolbox.cpp +++ b/src/ggui/toolbox.cpp @@ -1634,8 +1634,7 @@ namespace ggui , &cam_toolbar_active_bg , &toolbar_button_size)) { - components::command::execute("toggle_bsp_radiant"); - + components::d3dbsp::toggle_radiant_bsp_view(!dvars::r_draw_bsp->current.enabled); } maxs = ImVec2(mins.x + actual_button_size.x, mins.y + actual_button_size.y); @@ -1678,7 +1677,7 @@ namespace ggui , &cam_toolbar_active_bg , &toolbar_button_size)) { - components::command::execute("toggle_filter_all"); + gameview->toggle_all_filters(!tstate); } maxs = ImVec2(mins.x + actual_button_size.x, mins.y + actual_button_size.y);