实现NPC交互时的绿色高亮效果,通过InteractionHighlightSprite类实现 重构NpcAnimation支持复合纹理渲染,优化高亮效果的性能 添加ShaderManager获取所有加载Shader的方法,优化渲染器uniform更新逻辑
68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "character/CharacterActionTypes.h"
|
|
#include "common/InteractionHighlightSprite.h"
|
|
#include "npc/NpcAnimation.h"
|
|
#include <frostbite2D/2d/actor.h>
|
|
#include <frostbite2D/2d/text_sprite.h>
|
|
#include <array>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace frostbite2D {
|
|
|
|
class NpcObject : public Actor {
|
|
public:
|
|
NpcObject() = default;
|
|
~NpcObject() override = default;
|
|
|
|
bool Construction(int npcId);
|
|
|
|
void SetDirection(int direction);
|
|
void SetNpcPosition(const Vec2& pos);
|
|
void SetWorldPosition(const CharacterWorldPosition& pos);
|
|
void SetInteractable(bool interactable);
|
|
void SetInteractionHighlighted(bool highlighted);
|
|
void BeginInteract();
|
|
void EndInteract();
|
|
|
|
bool CanInteract() const;
|
|
bool IsInteracting() const { return interacting_; }
|
|
bool IsInteractionHighlighted() const { return interactionHighlighted_; }
|
|
int GetNpcId() const { return npcId_; }
|
|
int GetDirection() const { return direction_; }
|
|
const std::string& GetName() const;
|
|
const std::string& GetFieldName() const;
|
|
const std::string& GetDisplayName() const;
|
|
const CharacterWorldPosition& GetWorldPosition() const { return worldPosition_; }
|
|
bool IsAnimationFinished() const;
|
|
|
|
const npc::NpcConfig* GetConfig() const {
|
|
return config_ ? &config_.value() : nullptr;
|
|
}
|
|
|
|
void Update(float deltaTime) override;
|
|
|
|
private:
|
|
void EnsureInteractionHighlight();
|
|
void EnsureNameLabel();
|
|
void RefreshNameLabel();
|
|
void SyncInteractionHighlight();
|
|
void SyncActorPositionFromWorld();
|
|
|
|
int npcId_ = -1;
|
|
int direction_ = 1;
|
|
CharacterWorldPosition worldPosition_;
|
|
std::optional<npc::NpcConfig> config_;
|
|
RefPtr<NpcAnimation> animation_ = nullptr;
|
|
RefPtr<InteractionHighlightSprite> interactionHighlight_ = nullptr;
|
|
std::array<RefPtr<TextSprite>, 8> nameOutlineLabels_;
|
|
RefPtr<TextSprite> nameLabel_ = nullptr;
|
|
bool interactable_ = true;
|
|
bool interacting_ = false;
|
|
bool interactionHighlighted_ = false;
|
|
uint64 syncedHighlightCompositeVersion_ = 0;
|
|
};
|
|
|
|
} // namespace frostbite2D
|