2025-10-10 15:04:08 +08:00

73 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "DeskMode.h"
#include "WindowTransparency.h"
//#include "Features/EditorFeatures.h"
//#include "Features/IPluginsEditorFeature.h"
DEFINE_LOG_CATEGORY_STATIC(LogDeskMode, Log, All);
#define LOCTEXT_NAMESPACE "FDeskModeModule"
void FDeskModeModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
//绑定module注册回调
IModularFeatures& ModularFeatures = IModularFeatures::Get();
ModularFeatures.OnModularFeatureRegistered().AddRaw(this, &FDeskModeModule::OnModularFeatureRegistered);
//防止plugin模块先加载
// if (ModularFeatures.IsModularFeatureAvailable(EditorFeatures::PluginsEditor))
// {
// OnModularFeatureRegistered(EditorFeatures::PluginsEditor, &ModularFeatures.GetModularFeature<IPluginsEditorFeature>(EditorFeatures::PluginsEditor));
// }
}
void FDeskModeModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
if (IsValid(WindowTransparency))
{
#if PLATFORM_WINDOWS
UE_LOG(LogDeskMode, Log, TEXT("WindowTransparency is valid, attempting to restore settings."));
WindowTransparency->RestoreDefaultWindowSettings();
#endif
}
}
void FDeskModeModule::OnModularFeatureRegistered(const FName& Name, IModularFeature* ModularFeature)
{
}
TObjectPtr<class UWindowTransparency> FDeskModeModule::GetWindowTransparency()
{
FDeskModeModule* Module = FModuleManager::GetModulePtr<FDeskModeModule>("DeskMode");
if (Module)
{
Module->WindowTransparency = nullptr;
#if PLATFORM_WINDOWS
if (!Module->WindowTransparency && !IsRunningCommandlet() && !IsRunningDedicatedServer() && GEngine)
{
Module->WindowTransparency = NewObject<UWindowTransparency>();
if (Module->WindowTransparency->Initialize())
{
UE_LOG(LogDeskMode, Log, TEXT("WindowTransparency instance created and initialized."));
}
else
{
UE_LOG(LogDeskMode, Error, TEXT("WindowTransparency instance created but failed to initialize HWND."));
}
}
#endif
return Module->WindowTransparency;
}
UE_LOG(LogDeskMode, Log, TEXT("WindowTransparency is null, GetWindowTransparency() error."));
return nullptr;
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FDeskModeModule, DeskMode)