/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include // Forward Declares struct ImVec2; namespace ImGui { // Notes: Hidden - ImGui Off, Input goes to Game // Visible - ImGui Visible, Input goes to ImGui and consumed from game ( iff discrete input mode is on, else it is not consumed ) // VisibleNoMouse - ImGui Visible, Input goes to Game ( only a state iff discrete input mode is on ) enum class DisplayState { Hidden, Visible, VisibleNoMouse }; // Notes: LockToResolution - Lock ImGui Render to a supplied resolution, regardless of LY Render Resolution // MatchRenderResolution - Render ImGui at Render Resolution // MatchToMaxRenderResolution - Render ImGui at Render Resolution, up to some maximum resolution, then Render at that max resolution. enum class ImGuiResolutionMode { LockToResolution = 0, MatchRenderResolution, MatchToMaxRenderResolution }; // Notes: Contextual - Use the Controller Stick and buttons to navigate ImGui as a contextual menu // Mouse - Use the Controller stick and buttons as a virtual mouse within ImGui. namespace ImGuiControllerModeFlags { typedef AZ::u8 FlagType; constexpr FlagType Contextual = 1 << 0, Mouse = 1 << 1; } // Bus for getting updates from ImGui manager class IImGuiUpdateListener : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiUpdateListener"; } static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; using Bus = AZ::EBus; // ImGui Lifecycle Callbacks virtual void OnImGuiInitialize() {} virtual void OnImGuiUpdate() {} virtual void OnImGuiMainMenuUpdate() {} virtual void OnOpenEditorWindow() {} }; typedef AZ::EBus ImGuiUpdateListenerBus; // Bus for sending events and getting state from the ImGui manager class IImGuiManagerListener : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiManagerListener"; } static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; using Bus = AZ::EBus; virtual DisplayState GetEditorWindowState() const = 0; virtual void SetEditorWindowState(DisplayState state) = 0; virtual DisplayState GetClientMenuBarState() const = 0; virtual void SetClientMenuBarState(DisplayState state) = 0; virtual bool IsControllerSupportModeEnabled(ImGuiControllerModeFlags::FlagType controllerMode) const = 0; virtual void EnableControllerSupportMode(ImGuiControllerModeFlags::FlagType controllerMode, bool enable) = 0; virtual void SetControllerMouseSensitivity(float sensitivity) = 0; virtual float GetControllerMouseSensitivity() const = 0; virtual bool GetEnableDiscreteInputMode() const = 0; virtual void SetEnableDiscreteInputMode(bool enabled) = 0; virtual ImGuiResolutionMode GetResolutionMode() const = 0; virtual void SetResolutionMode(ImGuiResolutionMode state) = 0; virtual const ImVec2& GetImGuiRenderResolution() const = 0; virtual void SetImGuiRenderResolution(const ImVec2& res) = 0; }; typedef AZ::EBus ImGuiManagerListenerBus; // Bus for getting notifications from the IMGUI Entity Outliner class IImGuiEntityOutlinerNotifcations : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiEntityOutlinerNotifcations"; } static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; using Bus = AZ::EBus; // Callback for game code to handle targetting an IMGUI entity virtual void OnImGuiEntityOutlinerTarget(AZ::EntityId target) { (void)target; } }; typedef AZ::EBus ImGuiEntityOutlinerNotifcationBus; // a pair of an entity id, and a typeid, used to represent component rtti type info typedef AZStd::pair ImGuiEntComponentId; // Bus for requests to the IMGUI Entity Outliner class IImGuiEntityOutlinerRequests : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiEntityOutlinerRequests"; } static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; using Bus = AZ::EBus; // Requests for the ImGui Entity Outliner virtual void RemoveEntityView(AZ::EntityId entity) = 0; virtual void RequestEntityView(AZ::EntityId entity) = 0; virtual void RemoveComponentView(ImGuiEntComponentId component) = 0; virtual void RequestComponentView(ImGuiEntComponentId component) = 0; virtual void RequestAllViewsForComponent(const AZ::TypeId& comType) = 0; virtual void EnableTargetViewMode(bool enabled) = 0; virtual void EnableComponentDebug(const AZ::TypeId& comType, int priority = 1, bool enableMenuBar = false) = 0; virtual void SetEnabled(bool enabled) = 0; virtual void AddAutoEnableSearchString(const AZStd::string& searchString) = 0; }; typedef AZ::EBus ImGuiEntityOutlinerRequestBus; // Bus for requests to the IMGUI Asset Explorer class IImGuiAssetExplorerRequests : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiAssetExplorerRequests"; } static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; using Bus = AZ::EBus; // Requests for the ImGui Asset Explorer virtual void SetEnabled(bool enabled) = 0; }; typedef AZ::EBus ImGuiAssetExplorerRequestBus; // Bus for requests to the IMGUI Camera Monitor class IImGuiCameraMonitorRequests : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiCameraMonitorRequests"; } static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; using Bus = AZ::EBus; // Requests for the ImGui Camera Monitor virtual void SetEnabled(bool enabled) = 0; }; typedef AZ::EBus ImGuiCameraMonitorRequestBus; // Bus for getting debug Component updates from ImGui manager class IImGuiUpdateDebugComponentListener : public AZ::EBusTraits { public: static const char* GetUniqueName() { return "IImGuiUpdateDebugComponentListener"; } static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById; using BusIdType = ImGuiEntComponentId; using Bus = AZ::EBus; // AZ_RTTI required on this EBUS, this allows us to iterate through the handlers of this EBUS and deduce their type. AZ_RTTI(IImGuiUpdateDebugComponentListener, "{825B883F-A806-4304-AF82-C412AC5EC27B}"); // OnImGuiDebugLYComponentUpdate - must implement this, this is the callback for a componenet instance // to draw it's required debugging information. virtual void OnImGuiDebugLYComponentUpdate() = 0; // GetComponentDebugPriority - an optional implementation. The Entity Outliner will ask components what their debug priority // is, no override on the handler will return the below value of 1, you can optionally override in the handler to give it // a higher priority. Priority only really matters for giving a shortcut to the highest priority debugging component on a given entity virtual int GetComponentDebugPriority() { return 1; } // GetEnableMenuBar - an optional implementation. Components can define if their debug view uses a menu bar. False by default virtual bool GetEnableMenuBar() { return false; } // Connection Policy, at component connect time, Ask the component what priority they are via ebus, then // register that component type with the priority returned with the Entity Outliner template struct ConnectionPolicy : public AZ::EBusConnectionPolicy { static void Connect(typename Bus::BusPtr& busPtr, typename Bus::Context& context, typename Bus::HandlerNode& handler, typename Bus::Context::ConnectLockGuard& connectLock, const typename Bus::BusIdType& id = 0) { AZ::EBusConnectionPolicy::Connect(busPtr, context, handler, connectLock, id); // Get the debug priority for the component int priority = 1; AZ::EBus::EventResult( priority, id, &AZ::EBus::Events::GetComponentDebugPriority); // Get the debug priority for the component bool enableMenuBar = false; AZ::EBus::EventResult(enableMenuBar, id, &AZ::EBus::Events::GetEnableMenuBar); // Register ImGuiEntityOutlinerRequestBus::Broadcast(&ImGuiEntityOutlinerRequestBus::Events::EnableComponentDebug, id.second, priority, enableMenuBar); } static void Disconnect(typename Bus::Context& context, typename Bus::HandlerNode& handler, typename Bus::BusPtr& busPtr) { AZ::EBusConnectionPolicy::Disconnect(context, handler, busPtr); if (busPtr) { ImGuiEntityOutlinerRequestBus::Broadcast(&ImGuiEntityOutlinerRequestBus::Events::RemoveComponentView, busPtr->m_busId); } } }; }; typedef AZ::EBus ImGuiUpdateDebugComponentListenerBus; }