-
Notifications
You must be signed in to change notification settings - Fork 59
/
ECRQuickBarComponent.h
163 lines (118 loc) · 4.15 KB
/
ECRQuickBarComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/ControllerComponent.h"
#include "GameFramework/GameplayMessageSubsystem.h"
#include "ECRQuickBarComponent.generated.h"
class UECRInventoryItemInstance;
class UECREquipmentInstance;
class UECREquipmentManagerComponent;
/** A single channel in quickbar */
USTRUCT(BlueprintType)
struct FECRQuickBarChannel : public FFastArraySerializerItem
{
GENERATED_BODY()
FECRQuickBarChannel();
protected:
int SlotsDefaultNum = 3;
private:
friend struct FECRQuickBar;
friend UECRQuickBarComponent;
UPROPERTY()
FName ChannelName;
UPROPERTY()
TArray<TObjectPtr<UECRInventoryItemInstance>> Slots;
UPROPERTY()
int32 ActiveSlotIndex = -1;
UPROPERTY()
TObjectPtr<UECREquipmentInstance> EquippedItem = nullptr;
};
/** List of inventory items */
USTRUCT(BlueprintType)
struct FECRQuickBar : public FFastArraySerializer
{
GENERATED_BODY()
FECRQuickBar()
: OwnerComponent(nullptr)
{
}
FECRQuickBar(UActorComponent* InOwnerComponent)
: OwnerComponent(InOwnerComponent)
{
}
public:
//~FFastArraySerializer contract
void PreReplicatedRemove(const TArrayView<int32> RemovedIndices, int32 FinalSize);
void PostReplicatedAdd(const TArrayView<int32> AddedIndices, int32 FinalSize);
void PostReplicatedChange(const TArrayView<int32> ChangedIndices, int32 FinalSize);
//~End of FFastArraySerializer contract
bool NetDeltaSerialize(FNetDeltaSerializeInfo& DeltaParms)
{
return FFastArraySerializer::FastArrayDeltaSerialize<FECRQuickBarChannel, FECRQuickBar>(
Channels, DeltaParms, *this);
}
private:
void BroadcastChangeMessage(FECRQuickBarChannel& Channel);
void UnequipItemInActiveSlot(FECRQuickBarChannel& Channel);
void EquipItemInActiveSlot(FECRQuickBarChannel& Channel);
void ClearChannels();
UECREquipmentManagerComponent* FindEquipmentManager() const;
int32 GetIndexOfChannelWithName(FName Name) const;
int32 GetIndexOfChannelWithNameOrCreate(FName Name);
private:
friend UECRQuickBarComponent;
private:
// Replicated list of channels
UPROPERTY()
TArray<FECRQuickBarChannel> Channels;
UPROPERTY()
UActorComponent* OwnerComponent;
};
template <>
struct TStructOpsTypeTraits<FECRQuickBar> : public TStructOpsTypeTraitsBase2<FECRQuickBar>
{
enum { WithNetDeltaSerializer = true };
};
UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
class UECRQuickBarComponent : public UActorComponent
{
GENERATED_BODY()
public:
UECRQuickBarComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
UFUNCTION(BlueprintCallable, BlueprintPure)
TArray<FName> GetChannels() const;
UFUNCTION(BlueprintCallable)
void ClearChannels();
UFUNCTION(BlueprintCallable, Category="ECR")
void CycleActiveSlotForward(FName ChannelName);
UFUNCTION(BlueprintCallable, Category="ECR")
void CycleActiveSlotBackward(FName ChannelName);
UFUNCTION(Server, Reliable, BlueprintCallable, Category="ECR")
void SetActiveSlotIndex(FName ChannelName, int32 NewIndex);
UFUNCTION(BlueprintCallable, BlueprintPure=false)
TArray<UECRInventoryItemInstance*> GetSlots(FName ChannelName) const;
UFUNCTION(BlueprintCallable, BlueprintPure=false)
int32 GetActiveSlotIndex(FName ChannelName) const;
UFUNCTION(BlueprintCallable, BlueprintPure = false)
UECRInventoryItemInstance* GetActiveSlotItem(FName ChannelName) const;
UFUNCTION(BlueprintCallable, BlueprintPure=false)
int32 GetNextFreeItemSlot(FName ChannelName, bool bReturnZeroIfChannelMissing) const;
UFUNCTION(BlueprintCallable, BlueprintPure=false)
int32 GetItemAmountInChannel(FName ChannelName, bool bReturnZeroIfChannelMissing) const;
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
void AddItemToSlot(int32 SlotIndex, UECRInventoryItemInstance* Item);
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
UECRInventoryItemInstance* RemoveItemFromSlot(FName ChannelName, int32 SlotIndex);
private:
UPROPERTY(Replicated)
FECRQuickBar ChannelData;
};
USTRUCT(BlueprintType)
struct FECRQuickBarChannelChangedMessage
{
GENERATED_BODY()
UPROPERTY(BlueprintReadOnly, Category=Quickbar)
FName ChannelName;
UPROPERTY(BlueprintReadOnly, Category=Quickbar)
UActorComponent* QuickBarOwner = nullptr;
};