From bcb7722c68372c10e050c5531feaf5f96876c4d0 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 14 Mar 2025 22:37:57 -0500 Subject: [PATCH] VideoCommon: add graphics mod editor control for selecting a camera --- .../Controls/CameraChoiceControl.cpp | 117 ++++++++++++++++++ .../Controls/CameraChoiceControl.h | 15 +++ 2 files changed, 132 insertions(+) create mode 100644 Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.cpp create mode 100644 Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.h diff --git a/Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.cpp b/Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.cpp new file mode 100644 index 0000000000..ca3d920229 --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.cpp @@ -0,0 +1,117 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.h" + +#include + +#include + +#include "Core/System.h" + +#include "VideoCommon/GraphicsModEditor/EditorBackend.h" +#include "VideoCommon/GraphicsModEditor/SceneUtils.h" +#include "VideoCommon/GraphicsModSystem/Runtime/Actions/RelativeCameraAction.h" +#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h" + +namespace GraphicsModEditor::Controls +{ +namespace +{ +ImVec2 camera_button_size{150, 150}; + +std::string GetCameraName(const EditorState& editor_state, GraphicsModSystem::DrawCallID draw_call) +{ + std::string camera_name = ""; + const auto actions = GetActionsForDrawCall(editor_state, draw_call); + if (!actions.empty()) + { + const std::string draw_call_name = GetDrawCallName(editor_state, draw_call); + camera_name = fmt::format("{}/{}", draw_call_name, GetActionName(actions[0])); + } + return camera_name; +} +} // namespace +bool CameraChoiceControl(std::string_view popup_name, EditorState* editor_state, + GraphicsModSystem::DrawCallID* draw_call_chosen) +{ + if (!editor_state) [[unlikely]] + return false; + if (!draw_call_chosen) [[unlikely]] + return false; + + const std::string camera_name = GetCameraName(*editor_state, *draw_call_chosen); + if (camera_name.empty()) + ImGui::Text("Camera: None"); + else + ImGui::Text("Camera: %s", camera_name.c_str()); + + if (ImGui::Button("Pick camera")) + { + ImGui::OpenPopup(popup_name.data()); + } + bool changed = false; + + // Camera popup below + const ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + const ImVec2 size = ImGui::GetMainViewport()->WorkSize; + ImGui::SetNextWindowPos(center, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); + ImGui::SetNextWindowSize(ImVec2(size.x / 4.0f, size.y / 2.0f)); + if (ImGui::BeginPopup(popup_name.data())) + { + const u32 column_count = 5; + u32 current_columns = 0; + u32 cameras_displayed = 0; + + const float search_size = 200.0f; + ImGui::SetNextItemWidth(search_size); + + std::string camera_filter = ""; + ImGui::InputTextWithHint("##", "Search...", &camera_filter); + + if (ImGui::BeginTable("CameraPopupTable", column_count)) + { + ImGui::TableNextRow(); + + auto& manager = Core::System::GetInstance().GetGraphicsModManager(); + auto& backend = static_cast(manager.GetBackend()); + const auto camera_ids = backend.GetCameraManager().GetDrawCallsWithCameras(); + for (const auto& draw_call : camera_ids) + { + const std::string camera_name_in_popup = GetCameraName(*editor_state, draw_call); + if (camera_name_in_popup.empty()) + continue; + if (!camera_filter.empty() && camera_name_in_popup.find(camera_filter) == std::string::npos) + { + continue; + } + + cameras_displayed++; + ImGui::TableNextColumn(); + if (ImGui::Button(camera_name_in_popup.c_str())) + { + *draw_call_chosen = draw_call; + changed = true; + ImGui::CloseCurrentPopup(); + } + + current_columns++; + if (current_columns == column_count) + { + ImGui::TableNextRow(); + current_columns = 0; + } + } + ImGui::EndTable(); + } + + if (cameras_displayed == 0) + { + ImGui::Text("No cameras found"); + } + ImGui::EndPopup(); + } + + return changed; +} +} // namespace GraphicsModEditor::Controls diff --git a/Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.h b/Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.h new file mode 100644 index 0000000000..78d28c664a --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/Controls/CameraChoiceControl.h @@ -0,0 +1,15 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "VideoCommon/GraphicsModEditor/EditorState.h" +#include "VideoCommon/GraphicsModSystem/Types.h" + +namespace GraphicsModEditor::Controls +{ +bool CameraChoiceControl(std::string_view popup_name, EditorState* editor_state, + GraphicsModSystem::DrawCallID* draw_call_chosen); +} // namespace GraphicsModEditor::Controls