#pragma once #pragma region CPL License /* Nuclex Unreal Module Copyright (C) 2014-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #include #include #include "ResizableDialogMeshComponent.generated.h" // --------------------------------------------------------------------------------------------- // /// Manages a mesh-based dialog box (for 3D UI) that can be dynamically resized UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class NUCLEX_API UResizableDialogMeshComponent : public UProceduralMeshComponent { GENERATED_BODY() /// Initializes a new resizable dialog mesh to its default settings /// @param objectInitializer Some Unreal Engine initialization crutch UResizableDialogMeshComponent(const FObjectInitializer &objectInitializer); // // UResizableDialogMeshComponent implementation // /// Returns the current size of the client area in the dialog box /// @returns The current client area size public: UFUNCTION(BlueprintCallable) FVector2D GetDialogBoxSize() const; /// Changes the size of the dialog box to fit the specified client area size /// @param newSize New size the client area of the dialog box will have (in world units) public: UFUNCTION(BlueprintCallable) void SetDialogBoxSize(const FVector2D &newSize); // // Internal implementation // /// Called when the game starts or when the actor is spawned into a running game protected: virtual void BeginPlay() override; /// Called when the game ends or when the actor is deleted from the running game /// @param endPlayReason Reason why the component is not in the game anymore protected: virtual void EndPlay(const EEndPlayReason::Type endPlayReason) override; /// Copies the vertices from the template mesh into our internal buffer private: void copyVerticesFromStaticMeshTemplate(); /// Creates a backup of the original vertices to avoid floating point drift private: void backupOriginalVertices(); /// Calculates the inner bounds, center and current client area size of the dialog box private: void calculateMeshMetrics(); /// Forces the procedural mesh to update its vertex buffer from the vertex array private: void forceVertexBufferUpdate(); /// Template mesh that will be used as the dialog box public: UPROPERTY(EditAnywhere, BlueprintReadWrite) UStaticMesh *MeshTemplate; /* The flat axis is X and X shall be the flat axis. /// Axis along which the mesh template is flat public: UPROPERTY(EditAnywhere, BlueprintReadWrite) TEnumAsByte MeshTemplateFlatAxis; */ /// Original procedural mesh vertices for each section (submesh) private: TArray> originalVertices; /// How far from the center the innermost vertices in each quadrant are private: FBox2D innerBounds; /// Center of the dialog box outer bounds private: FVector2D center; /// Current size of the usable client area private: FVector2D clientAreaSize; /// Used to temporarily store the vertex positions for forceVertexBufferUpdate() private: mutable TArray vertices; /// Used to temporarily store the vertex normals for forceVertexBufferUpdate() private: mutable TArray normals; /// Used to temporarily store the vertex UV coordinates for forceVertexBufferUpdate() private: mutable TArray uvs; /// Used to temporarily store the vertex colors for forceVertexBufferUpdate() private: mutable TArray colors; /// Used to temporarily store the vertex tangents for forceVertexBufferUpdate() private: mutable TArray tangents; }; // --------------------------------------------------------------------------------------------- //