├── .gitignore ├── .vsconfig ├── Config ├── DefaultEditor.ini ├── DefaultEditorPerProjectUserSettings.ini ├── DefaultEngine.ini ├── DefaultGame.ini └── DefaultInput.ini ├── InventoryProject.uproject ├── Plugins └── Inventory │ ├── Inventory.uplugin │ ├── Resources │ └── Icon128.png │ └── Source │ └── Inventory │ ├── Inventory.Build.cs │ ├── Private │ ├── EquipmentManagement │ │ ├── Components │ │ │ └── Inv_EquipmentComponent.cpp │ │ ├── EquipActor │ │ │ └── Inv_EquipActor.cpp │ │ └── ProxyMesh │ │ │ └── Inv_ProxyMesh.cpp │ ├── Interaction │ │ ├── Inv_Highlightable.cpp │ │ └── Inv_HighlightableStaticMesh.cpp │ ├── Inventory.cpp │ ├── InventoryManagement │ │ ├── Components │ │ │ └── Inv_InventoryComponent.cpp │ │ ├── FastArray │ │ │ └── Inv_FastArray.cpp │ │ └── Utils │ │ │ └── Inv_InventoryStatics.cpp │ ├── Items │ │ ├── Components │ │ │ └── Inv_ItemComponent.cpp │ │ ├── Fragments │ │ │ ├── Inv_FragmentTags.cpp │ │ │ └── Inv_ItemFragment.cpp │ │ ├── Inv_InventoryItem.cpp │ │ ├── Inv_ItemTags.cpp │ │ └── Manifest │ │ │ └── Inv_ItemManifest.cpp │ ├── Player │ │ └── Inv_PlayerController.cpp │ ├── Types │ │ └── Inv_GridTypes.cpp │ └── Widgets │ │ ├── CharacterDisplay │ │ └── Inv_CharacterDisplay.cpp │ │ ├── Composite │ │ ├── Inv_Composite.cpp │ │ ├── Inv_CompositeBase.cpp │ │ ├── Inv_Leaf.cpp │ │ ├── Inv_Leaf_Image.cpp │ │ ├── Inv_Leaf_LabeledValue.cpp │ │ └── Inv_Leaf_Text.cpp │ │ ├── HUD │ │ ├── Inv_HUDWidget.cpp │ │ └── Inv_InfoMessage.cpp │ │ ├── Inventory │ │ ├── GridSlots │ │ │ ├── Inv_EquippedGridSlot.cpp │ │ │ └── Inv_GridSlot.cpp │ │ ├── HoverItem │ │ │ └── Inv_HoverItem.cpp │ │ ├── InventoryBase │ │ │ └── Inv_InventoryBase.cpp │ │ ├── SlottedItems │ │ │ ├── Inv_EquippedSlottedItem.cpp │ │ │ └── Inv_SlottedItem.cpp │ │ └── Spatial │ │ │ ├── Inv_InventoryGrid.cpp │ │ │ └── Inv_SpatialInventory.cpp │ │ ├── ItemDescription │ │ └── Inv_ItemDescription.cpp │ │ ├── ItemPopUp │ │ └── Inv_ItemPopUp.cpp │ │ └── Utils │ │ └── Inv_WidgetUtils.cpp │ └── Public │ ├── EquipmentManagement │ ├── Components │ │ └── Inv_EquipmentComponent.h │ ├── EquipActor │ │ └── Inv_EquipActor.h │ └── ProxyMesh │ │ └── Inv_ProxyMesh.h │ ├── Interaction │ ├── Inv_Highlightable.h │ └── Inv_HighlightableStaticMesh.h │ ├── Inventory.h │ ├── InventoryManagement │ ├── Components │ │ └── Inv_InventoryComponent.h │ ├── FastArray │ │ └── Inv_FastArray.h │ └── Utils │ │ └── Inv_InventoryStatics.h │ ├── Items │ ├── Components │ │ └── Inv_ItemComponent.h │ ├── Fragments │ │ ├── Inv_FragmentTags.h │ │ └── Inv_ItemFragment.h │ ├── Inv_InventoryItem.h │ ├── Inv_ItemTags.h │ └── Manifest │ │ └── Inv_ItemManifest.h │ ├── Player │ └── Inv_PlayerController.h │ ├── Types │ └── Inv_GridTypes.h │ └── Widgets │ ├── CharacterDisplay │ └── Inv_CharacterDisplay.h │ ├── Composite │ ├── Inv_Composite.h │ ├── Inv_CompositeBase.h │ ├── Inv_Leaf.h │ ├── Inv_Leaf_Image.h │ ├── Inv_Leaf_LabeledValue.h │ └── Inv_Leaf_Text.h │ ├── HUD │ ├── Inv_HUDWidget.h │ └── Inv_InfoMessage.h │ ├── Inventory │ ├── GridSlots │ │ ├── Inv_EquippedGridSlot.h │ │ └── Inv_GridSlot.h │ ├── HoverItem │ │ └── Inv_HoverItem.h │ ├── InventoryBase │ │ └── Inv_InventoryBase.h │ ├── SlottedItems │ │ ├── Inv_EquippedSlottedItem.h │ │ └── Inv_SlottedItem.h │ └── Spatial │ │ ├── Inv_InventoryGrid.h │ │ └── Inv_SpatialInventory.h │ ├── ItemDescription │ └── Inv_ItemDescription.h │ ├── ItemPopUp │ └── Inv_ItemPopUp.h │ └── Utils │ └── Inv_WidgetUtils.h └── Source ├── InventoryProject.Target.cs ├── InventoryProject ├── InventoryProject.Build.cs ├── InventoryProject.cpp ├── InventoryProject.h ├── InventoryProjectCharacter.cpp ├── InventoryProjectCharacter.h ├── InventoryProjectGameMode.cpp └── InventoryProjectGameMode.h └── InventoryProjectEditor.Target.cs /.gitignore: -------------------------------------------------------------------------------- 1 | Binaries 2 | DerivedDataCache 3 | Intermediate 4 | Saved 5 | Build 6 | Content 7 | Plugins/Developer/* 8 | 9 | .idea/ 10 | *.user 11 | *.userosscache 12 | *.sln.docstates 13 | .vscode 14 | .vs 15 | *.VC.db 16 | *.opensdf 17 | *.opendb 18 | *.sdf 19 | *.sln 20 | *.suo 21 | *.xcodeproj 22 | *.xcworkspace -------------------------------------------------------------------------------- /.vsconfig: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "components": [ 4 | "Microsoft.Net.Component.4.6.2.TargetingPack", 5 | "Microsoft.VisualStudio.Component.Unreal.Workspace", 6 | "Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL", 7 | "Microsoft.VisualStudio.Component.VC.14.38.17.8.x86.x64", 8 | "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", 9 | "Microsoft.VisualStudio.Component.Windows11SDK.22621", 10 | "Microsoft.VisualStudio.Workload.CoreEditor", 11 | "Microsoft.VisualStudio.Workload.ManagedDesktop", 12 | "Microsoft.VisualStudio.Workload.NativeDesktop", 13 | "Microsoft.VisualStudio.Workload.NativeGame" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /Config/DefaultEditorPerProjectUserSettings.ini: -------------------------------------------------------------------------------- 1 | [ContentBrowser] 2 | ContentBrowserTab1.SelectedPaths=/Game/ThirdPersonCPP -------------------------------------------------------------------------------- /Config/DefaultEngine.ini: -------------------------------------------------------------------------------- 1 | [/Script/EngineSettings.GameMapsSettings] 2 | GameDefaultMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap 3 | EditorStartupMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap 4 | GlobalDefaultGameMode="/Script/InventoryProject.InventoryProjectGameMode" 5 | 6 | [/Script/Engine.RendererSettings] 7 | r.ReflectionMethod=1 8 | r.GenerateMeshDistanceFields=True 9 | r.DynamicGlobalIlluminationMethod=1 10 | r.Lumen.TraceMeshSDFs=0 11 | r.Shadow.Virtual.Enable=1 12 | r.DefaultFeature.AutoExposure.ExtendDefaultLuminanceRange=True 13 | r.DefaultFeature.AutoExposure.ExtendDefaultLuminanceRange=true 14 | r.AllowStaticLighting=False 15 | 16 | r.SkinCache.CompileShaders=True 17 | 18 | r.RayTracing=True 19 | 20 | r.DefaultFeature.LocalExposure.HighlightContrastScale=0.8 21 | 22 | r.DefaultFeature.LocalExposure.ShadowContrastScale=0.8 23 | 24 | [/Script/WindowsTargetPlatform.WindowsTargetSettings] 25 | DefaultGraphicsRHI=DefaultGraphicsRHI_DX12 26 | DefaultGraphicsRHI=DefaultGraphicsRHI_DX12 27 | -D3D12TargetedShaderFormats=PCD3D_SM5 28 | +D3D12TargetedShaderFormats=PCD3D_SM6 29 | -D3D11TargetedShaderFormats=PCD3D_SM5 30 | +D3D11TargetedShaderFormats=PCD3D_SM5 31 | Compiler=Default 32 | AudioSampleRate=48000 33 | AudioCallbackBufferFrameSize=1024 34 | AudioNumBuffersToEnqueue=1 35 | AudioMaxChannels=0 36 | AudioNumSourceWorkers=4 37 | SpatializationPlugin= 38 | SourceDataOverridePlugin= 39 | ReverbPlugin= 40 | OcclusionPlugin= 41 | CompressionOverrides=(bOverrideCompressionTimes=False,DurationThreshold=5.000000,MaxNumRandomBranches=0,SoundCueQualityIndex=0) 42 | CacheSizeKB=65536 43 | MaxChunkSizeOverrideKB=0 44 | bResampleForDevice=False 45 | MaxSampleRate=48000.000000 46 | HighSampleRate=32000.000000 47 | MedSampleRate=24000.000000 48 | LowSampleRate=12000.000000 49 | MinSampleRate=8000.000000 50 | CompressionQualityModifier=1.000000 51 | AutoStreamingThreshold=0.000000 52 | SoundCueCookQualityIndex=-1 53 | 54 | [/Script/LinuxTargetPlatform.LinuxTargetSettings] 55 | -TargetedRHIs=SF_VULKAN_SM5 56 | +TargetedRHIs=SF_VULKAN_SM6 57 | 58 | [/Script/HardwareTargeting.HardwareTargetingSettings] 59 | TargetedHardwareClass=Desktop 60 | AppliedTargetedHardwareClass=Desktop 61 | DefaultGraphicsPerformance=Maximum 62 | AppliedDefaultGraphicsPerformance=Maximum 63 | 64 | [/Script/Engine.Engine] 65 | +ActiveGameNameRedirects=(OldGameName="TP_ThirdPerson",NewGameName="/Script/InventoryProject") 66 | +ActiveGameNameRedirects=(OldGameName="/Script/TP_ThirdPerson",NewGameName="/Script/InventoryProject") 67 | +ActiveClassRedirects=(OldClassName="TP_ThirdPersonGameMode",NewClassName="InventoryProjectGameMode") 68 | +ActiveClassRedirects=(OldClassName="TP_ThirdPersonCharacter",NewClassName="InventoryProjectCharacter") 69 | 70 | [/Script/AndroidFileServerEditor.AndroidFileServerRuntimeSettings] 71 | bEnablePlugin=True 72 | bAllowNetworkConnection=True 73 | SecurityToken=C143A8DB445F760CBEEABDB5CEB8E65D 74 | bIncludeInShipping=False 75 | bAllowExternalStartInShipping=False 76 | bCompileAFSProject=False 77 | bUseCompression=False 78 | bLogFiles=False 79 | bReportStats=False 80 | ConnectionType=USBOnly 81 | bUseManualIPAddress=False 82 | ManualIPAddress= 83 | 84 | [/Script/Engine.CollisionProfile] 85 | -Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision",bCanModify=False) 86 | -Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ",bCanModify=False) 87 | -Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False) 88 | -Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ",bCanModify=False) 89 | -Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False) 90 | -Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.",bCanModify=False) 91 | -Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ",bCanModify=False) 92 | -Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ",bCanModify=False) 93 | -Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic",Response=ECR_Block),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.",bCanModify=False) 94 | -Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,ObjectTypeName="Pawn",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.",bCanModify=False) 95 | -Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors",bCanModify=False) 96 | -Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors",bCanModify=False) 97 | -Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.",bCanModify=False) 98 | -Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.",bCanModify=False) 99 | -Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.",bCanModify=False) 100 | -Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.",bCanModify=False) 101 | -Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.",bCanModify=False) 102 | -Profiles=(Name="UI",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Block),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False) 103 | +Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision") 104 | +Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ") 105 | +Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") 106 | +Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ") 107 | +Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ") 108 | +Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.") 109 | +Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ") 110 | +Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ") 111 | +Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic"),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.") 112 | +Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.") 113 | +Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors") 114 | +Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors") 115 | +Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.") 116 | +Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.") 117 | +Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.") 118 | +Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.") 119 | +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") 120 | +Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") 121 | +Profiles=(Name="Item",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore),(Channel="ItemTrace")),HelpMessage="For items hit by the Player Controller\'s trace") 122 | +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="ItemTrace") 123 | -ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") 124 | -ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") 125 | -ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic") 126 | -ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor") 127 | -ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic") 128 | +ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") 129 | +ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") 130 | +ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic") 131 | +ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor") 132 | +ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic") 133 | -CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic") 134 | -CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic") 135 | -CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle") 136 | -CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn") 137 | +CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic") 138 | +CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic") 139 | +CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle") 140 | +CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn") 141 | 142 | -------------------------------------------------------------------------------- /Config/DefaultGame.ini: -------------------------------------------------------------------------------- 1 | [/Script/EngineSettings.GeneralProjectSettings] 2 | ProjectID=F0827299451F9BF61485AFBE4175BCD0 3 | ProjectName=Third Person Game Template 4 | -------------------------------------------------------------------------------- /Config/DefaultInput.ini: -------------------------------------------------------------------------------- 1 | 2 | 3 | [/Script/Engine.InputSettings] 4 | -AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 5 | -AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 6 | -AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 7 | -AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 8 | -AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) 9 | -AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) 10 | -AxisConfig=(AxisKeyName="Mouse2D",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) 11 | +AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) 12 | +AxisConfig=(AxisKeyName="MouseWheelAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 13 | +AxisConfig=(AxisKeyName="Gamepad_LeftTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 14 | +AxisConfig=(AxisKeyName="Gamepad_RightTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 15 | +AxisConfig=(AxisKeyName="Gamepad_Special_Left_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 16 | +AxisConfig=(AxisKeyName="Gamepad_Special_Left_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 17 | +AxisConfig=(AxisKeyName="Mouse2D",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) 18 | +AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 19 | +AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 20 | +AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 21 | +AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 22 | +AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) 23 | +AxisConfig=(AxisKeyName="Vive_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 24 | +AxisConfig=(AxisKeyName="Vive_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 25 | +AxisConfig=(AxisKeyName="Vive_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 26 | +AxisConfig=(AxisKeyName="Vive_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 27 | +AxisConfig=(AxisKeyName="Vive_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 28 | +AxisConfig=(AxisKeyName="Vive_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 29 | +AxisConfig=(AxisKeyName="MixedReality_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 30 | +AxisConfig=(AxisKeyName="MixedReality_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 31 | +AxisConfig=(AxisKeyName="MixedReality_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 32 | +AxisConfig=(AxisKeyName="MixedReality_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 33 | +AxisConfig=(AxisKeyName="MixedReality_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 34 | +AxisConfig=(AxisKeyName="MixedReality_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 35 | +AxisConfig=(AxisKeyName="MixedReality_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 36 | +AxisConfig=(AxisKeyName="MixedReality_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 37 | +AxisConfig=(AxisKeyName="MixedReality_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 38 | +AxisConfig=(AxisKeyName="MixedReality_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 39 | +AxisConfig=(AxisKeyName="OculusTouch_Left_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 40 | +AxisConfig=(AxisKeyName="OculusTouch_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 41 | +AxisConfig=(AxisKeyName="OculusTouch_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 42 | +AxisConfig=(AxisKeyName="OculusTouch_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 43 | +AxisConfig=(AxisKeyName="OculusTouch_Right_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 44 | +AxisConfig=(AxisKeyName="OculusTouch_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 45 | +AxisConfig=(AxisKeyName="OculusTouch_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 46 | +AxisConfig=(AxisKeyName="OculusTouch_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 47 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 48 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Grip_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 49 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 50 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 51 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 52 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 53 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 54 | +AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 55 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 56 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Grip_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 57 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 58 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 59 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 60 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 61 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 62 | +AxisConfig=(AxisKeyName="ValveIndex_Right_Trackpad_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 63 | bAltEnterTogglesFullscreen=True 64 | bF11TogglesFullscreen=True 65 | bUseMouseForTouch=False 66 | bEnableMouseSmoothing=True 67 | bEnableFOVScaling=True 68 | bCaptureMouseOnLaunch=True 69 | bEnableLegacyInputScales=True 70 | bEnableMotionControls=True 71 | bFilterInputByPlatformUser=False 72 | bShouldFlushPressedKeysOnViewportFocusLost=True 73 | bAlwaysShowTouchInterface=False 74 | bShowConsoleOnFourFingerTap=True 75 | bEnableGestureRecognizer=False 76 | bUseAutocorrect=False 77 | DefaultViewportMouseCaptureMode=CapturePermanently_IncludingInitialMouseDown 78 | DefaultViewportMouseLockMode=LockOnCapture 79 | FOVScale=0.011110 80 | DoubleClickTime=0.200000 81 | DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput 82 | DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent 83 | DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks 84 | -ConsoleKeys=Tilde 85 | +ConsoleKeys=Tilde 86 | 87 | -------------------------------------------------------------------------------- /InventoryProject.uproject: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "EngineAssociation": "5.5", 4 | "Category": "", 5 | "Description": "", 6 | "Modules": [ 7 | { 8 | "Name": "InventoryProject", 9 | "Type": "Runtime", 10 | "LoadingPhase": "Default" 11 | } 12 | ], 13 | "Plugins": [ 14 | { 15 | "Name": "ModelingToolsEditorMode", 16 | "Enabled": true, 17 | "TargetAllowList": [ 18 | "Editor" 19 | ] 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /Plugins/Inventory/Inventory.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "Inventory", 6 | "Description": "Inventory System", 7 | "Category": "Other", 8 | "CreatedBy": "Druid Mechanics", 9 | "CreatedByURL": "", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": true, 14 | "IsBetaVersion": false, 15 | "IsExperimentalVersion": false, 16 | "Installed": false, 17 | "Modules": [ 18 | { 19 | "Name": "Inventory", 20 | "Type": "Runtime", 21 | "LoadingPhase": "Default" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Plugins/Inventory/Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DruidMech/InventorySystems/c513708e16abcfbcda262b7ca68738ad88de7695/Plugins/Inventory/Resources/Icon128.png -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Inventory.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class Inventory : ModuleRules 6 | { 7 | public Inventory(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicIncludePaths.AddRange( 12 | new string[] { 13 | // ... add public include paths required here ... 14 | } 15 | ); 16 | 17 | 18 | PrivateIncludePaths.AddRange( 19 | new string[] { 20 | // ... add other private include paths required here ... 21 | } 22 | ); 23 | 24 | 25 | PublicDependencyModuleNames.AddRange( 26 | new string[] 27 | { 28 | "Core", 29 | "NetCore", 30 | "StructUtils", 31 | "GameplayTags" 32 | // ... add other public dependencies that you statically link with here ... 33 | } 34 | ); 35 | 36 | 37 | PrivateDependencyModuleNames.AddRange( 38 | new string[] 39 | { 40 | "CoreUObject", 41 | "Engine", 42 | "Slate", 43 | "SlateCore", 44 | "EnhancedInput", 45 | "UMG", 46 | "InputCore" 47 | // ... add private dependencies that you statically link with here ... 48 | } 49 | ); 50 | 51 | 52 | DynamicallyLoadedModuleNames.AddRange( 53 | new string[] 54 | { 55 | // ... add any modules that your module loads dynamically here ... 56 | } 57 | ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/EquipmentManagement/Components/Inv_EquipmentComponent.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "EquipmentManagement/Components/Inv_EquipmentComponent.h" 5 | 6 | #include "EquipmentManagement/EquipActor/Inv_EquipActor.h" 7 | #include "GameFramework/Character.h" 8 | #include "GameFramework/PlayerController.h" 9 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 10 | #include "InventoryManagement/Utils/Inv_InventoryStatics.h" 11 | #include "Items/Inv_InventoryItem.h" 12 | #include "Items/Fragments/Inv_ItemFragment.h" 13 | 14 | 15 | void UInv_EquipmentComponent::SetOwningSkeletalMesh(USkeletalMeshComponent* OwningMesh) 16 | { 17 | OwningSkeletalMesh = OwningMesh; 18 | } 19 | 20 | void UInv_EquipmentComponent::InitializeOwner(APlayerController* PlayerController) 21 | { 22 | if (IsValid(PlayerController)) 23 | { 24 | OwningPlayerController = PlayerController; 25 | } 26 | InitInventoryComponent(); 27 | } 28 | 29 | void UInv_EquipmentComponent::BeginPlay() 30 | { 31 | Super::BeginPlay(); 32 | 33 | InitPlayerController(); 34 | } 35 | 36 | void UInv_EquipmentComponent::InitPlayerController() 37 | { 38 | if (OwningPlayerController = Cast(GetOwner()); OwningPlayerController.IsValid()) 39 | { 40 | if (ACharacter* OwnerCharacter = Cast(OwningPlayerController->GetPawn()); IsValid(OwnerCharacter)) 41 | { 42 | OnPossessedPawnChange(nullptr, OwnerCharacter); 43 | } 44 | else 45 | { 46 | OwningPlayerController->OnPossessedPawnChanged.AddDynamic(this, &ThisClass::OnPossessedPawnChange); 47 | } 48 | } 49 | } 50 | 51 | void UInv_EquipmentComponent::OnPossessedPawnChange(APawn* OldPawn, APawn* NewPawn) 52 | { 53 | if (ACharacter* OwnerCharacter = Cast(NewPawn); IsValid(OwnerCharacter)) 54 | { 55 | OwningSkeletalMesh = OwnerCharacter->GetMesh(); 56 | } 57 | InitInventoryComponent(); 58 | } 59 | 60 | void UInv_EquipmentComponent::InitInventoryComponent() 61 | { 62 | InventoryComponent = UInv_InventoryStatics::GetInventoryComponent(OwningPlayerController.Get()); 63 | if (!InventoryComponent.IsValid()) return; 64 | 65 | if (!InventoryComponent->OnItemEquipped.IsAlreadyBound(this, &ThisClass::OnItemEquipped)) 66 | { 67 | InventoryComponent->OnItemEquipped.AddDynamic(this, &ThisClass::OnItemEquipped); 68 | } 69 | 70 | if (!InventoryComponent->OnItemUnequipped.IsAlreadyBound(this, &ThisClass::OnItemUnequipped)) 71 | { 72 | InventoryComponent->OnItemUnequipped.AddDynamic(this, &ThisClass::OnItemUnequipped); 73 | } 74 | } 75 | 76 | AInv_EquipActor* UInv_EquipmentComponent::SpawnEquippedActor(FInv_EquipmentFragment* EquipmentFragment, const FInv_ItemManifest& Manifest, USkeletalMeshComponent* AttachMesh) 77 | { 78 | AInv_EquipActor* SpawnedEquipActor = EquipmentFragment->SpawnAttachedActor(AttachMesh); 79 | SpawnedEquipActor->SetEquipmentType(EquipmentFragment->GetEquipmentType()); 80 | SpawnedEquipActor->SetOwner(GetOwner()); 81 | EquipmentFragment->SetEquippedActor(SpawnedEquipActor); 82 | return SpawnedEquipActor; 83 | } 84 | 85 | AInv_EquipActor* UInv_EquipmentComponent::FindEquippedActor(const FGameplayTag& EquipmentTypeTag) 86 | { 87 | auto FoundActor = EquippedActors.FindByPredicate([&EquipmentTypeTag](const AInv_EquipActor* EquippedActor) 88 | { 89 | return EquippedActor->GetEquipmentType().MatchesTagExact(EquipmentTypeTag); 90 | }); 91 | return FoundActor ? *FoundActor : nullptr; 92 | } 93 | 94 | void UInv_EquipmentComponent::RemoveEquippedActor(const FGameplayTag& EquipmentTypeTag) 95 | { 96 | if (AInv_EquipActor* EquippedActor = FindEquippedActor(EquipmentTypeTag); IsValid(EquippedActor)) 97 | { 98 | EquippedActors.Remove(EquippedActor); 99 | EquippedActor->Destroy(); 100 | } 101 | } 102 | 103 | void UInv_EquipmentComponent::OnItemEquipped(UInv_InventoryItem* EquippedItem) 104 | { 105 | if (!IsValid(EquippedItem)) return; 106 | if (!OwningPlayerController->HasAuthority()) return; 107 | 108 | FInv_ItemManifest& ItemManifest = EquippedItem->GetItemManifestMutable(); 109 | FInv_EquipmentFragment* EquipmentFragment = ItemManifest.GetFragmentOfTypeMutable(); 110 | if (!EquipmentFragment) return; 111 | 112 | if (!bIsProxy) 113 | { 114 | EquipmentFragment->OnEquip(OwningPlayerController.Get()); 115 | } 116 | 117 | if (!OwningSkeletalMesh.IsValid()) return; 118 | AInv_EquipActor* SpawnedEquipActor = SpawnEquippedActor(EquipmentFragment, ItemManifest, OwningSkeletalMesh.Get()); 119 | 120 | EquippedActors.Add(SpawnedEquipActor); 121 | } 122 | 123 | void UInv_EquipmentComponent::OnItemUnequipped(UInv_InventoryItem* UnequippedItem) 124 | { 125 | if (!IsValid(UnequippedItem)) return; 126 | if (!OwningPlayerController->HasAuthority()) return; 127 | 128 | FInv_ItemManifest& ItemManifest = UnequippedItem->GetItemManifestMutable(); 129 | FInv_EquipmentFragment* EquipmentFragment = ItemManifest.GetFragmentOfTypeMutable(); 130 | if (!EquipmentFragment) return; 131 | 132 | if (!bIsProxy) 133 | { 134 | EquipmentFragment->OnUnequip(OwningPlayerController.Get()); 135 | } 136 | 137 | RemoveEquippedActor(EquipmentFragment->GetEquipmentType()); 138 | } 139 | 140 | 141 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/EquipmentManagement/EquipActor/Inv_EquipActor.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "EquipmentManagement/EquipActor/Inv_EquipActor.h" 5 | 6 | 7 | AInv_EquipActor::AInv_EquipActor() 8 | { 9 | PrimaryActorTick.bCanEverTick = false; 10 | bReplicates = true; 11 | } 12 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/EquipmentManagement/ProxyMesh/Inv_ProxyMesh.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "EquipmentManagement/ProxyMesh/Inv_ProxyMesh.h" 5 | 6 | #include "EquipmentManagement/Components/Inv_EquipmentComponent.h" 7 | #include "GameFramework/Character.h" 8 | 9 | 10 | AInv_ProxyMesh::AInv_ProxyMesh() 11 | { 12 | PrimaryActorTick.bCanEverTick = false; 13 | SetReplicates(false); 14 | 15 | RootComponent = CreateDefaultSubobject("Root"); 16 | 17 | Mesh = CreateDefaultSubobject("Mesh"); 18 | Mesh->SetupAttachment(RootComponent); 19 | 20 | EquipmentComponent = CreateDefaultSubobject("Equipment"); 21 | EquipmentComponent->SetOwningSkeletalMesh(Mesh); 22 | EquipmentComponent->SetIsProxy(true); 23 | } 24 | 25 | void AInv_ProxyMesh::BeginPlay() 26 | { 27 | Super::BeginPlay(); 28 | DelayedInitializeOwner(); 29 | } 30 | 31 | void AInv_ProxyMesh::DelayedInitializeOwner() 32 | { 33 | UWorld* World = GetWorld(); 34 | if (!IsValid(World)) 35 | { 36 | DelayedInitialization(); 37 | return; 38 | } 39 | 40 | APlayerController* PC = World->GetFirstPlayerController(); 41 | if (!IsValid(PC)) 42 | { 43 | DelayedInitialization(); 44 | return; 45 | } 46 | 47 | ACharacter* Character = Cast(PC->GetPawn()); 48 | if (!IsValid(Character)) 49 | { 50 | DelayedInitialization(); 51 | return; 52 | } 53 | 54 | USkeletalMeshComponent* CharacterMesh = Character->GetMesh(); 55 | if (!IsValid(CharacterMesh)) 56 | { 57 | DelayedInitialization(); 58 | return; 59 | } 60 | 61 | SourceMesh = CharacterMesh; 62 | Mesh->SetSkeletalMesh(SourceMesh->GetSkeletalMeshAsset()); 63 | Mesh->SetAnimInstanceClass(SourceMesh->GetAnimInstance()->GetClass()); 64 | 65 | EquipmentComponent->InitializeOwner(PC); 66 | } 67 | 68 | void AInv_ProxyMesh::DelayedInitialization() 69 | { 70 | FTimerDelegate TimerDelegate; 71 | TimerDelegate.BindUObject(this, &ThisClass::DelayedInitializeOwner); 72 | GetWorld()->GetTimerManager().SetTimerForNextTick(TimerDelegate); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Interaction/Inv_Highlightable.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Interaction/Inv_Highlightable.h" 5 | 6 | 7 | // Add default functionality here for any IInv_Highlightable functions that are not pure virtual. 8 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Interaction/Inv_HighlightableStaticMesh.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Interaction/Inv_HighlightableStaticMesh.h" 5 | 6 | void UInv_HighlightableStaticMesh::Highlight_Implementation() 7 | { 8 | SetOverlayMaterial(HighlightMaterial); 9 | } 10 | 11 | void UInv_HighlightableStaticMesh::UnHighlight_Implementation() 12 | { 13 | SetOverlayMaterial(nullptr); 14 | } 15 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Inventory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "Inventory.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FInventoryModule" 6 | 7 | DEFINE_LOG_CATEGORY(LogInventory); 8 | 9 | void FInventoryModule::StartupModule() 10 | { 11 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 12 | } 13 | 14 | void FInventoryModule::ShutdownModule() 15 | { 16 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 17 | // we call this function before unloading the module. 18 | } 19 | 20 | #undef LOCTEXT_NAMESPACE 21 | 22 | IMPLEMENT_MODULE(FInventoryModule, Inventory) -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/InventoryManagement/Components/Inv_InventoryComponent.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 5 | 6 | #include "Items/Components/Inv_ItemComponent.h" 7 | #include "Widgets/Inventory/InventoryBase/Inv_InventoryBase.h" 8 | #include "Net/UnrealNetwork.h" 9 | #include "Items/Inv_InventoryItem.h" 10 | #include "Items/Fragments/Inv_ItemFragment.h" 11 | 12 | 13 | UInv_InventoryComponent::UInv_InventoryComponent() : InventoryList(this) 14 | { 15 | PrimaryComponentTick.bCanEverTick = false; 16 | SetIsReplicatedByDefault(true); 17 | bReplicateUsingRegisteredSubObjectList = true; 18 | bInventoryMenuOpen = false; 19 | } 20 | 21 | void UInv_InventoryComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const 22 | { 23 | Super::GetLifetimeReplicatedProps(OutLifetimeProps); 24 | 25 | DOREPLIFETIME(ThisClass, InventoryList); 26 | } 27 | 28 | void UInv_InventoryComponent::TryAddItem(UInv_ItemComponent* ItemComponent) 29 | { 30 | FInv_SlotAvailabilityResult Result = InventoryMenu->HasRoomForItem(ItemComponent); 31 | 32 | UInv_InventoryItem* FoundItem = InventoryList.FindFirstItemByType(ItemComponent->GetItemManifest().GetItemType()); 33 | Result.Item = FoundItem; 34 | 35 | if (Result.TotalRoomToFill == 0) 36 | { 37 | NoRoomInInventory.Broadcast(); 38 | return; 39 | } 40 | 41 | if (Result.Item.IsValid() && Result.bStackable) 42 | { 43 | // Add stacks to an item that already exists in the inventory. We only want to update the stack count, 44 | // not create a new item of this type. 45 | OnStackChange.Broadcast(Result); 46 | Server_AddStacksToItem(ItemComponent, Result.TotalRoomToFill, Result.Remainder); 47 | } 48 | else if (Result.TotalRoomToFill > 0) 49 | { 50 | // This item type doesn't exist in the inventory. Create a new one and update all pertinent slots. 51 | Server_AddNewItem(ItemComponent, Result.bStackable ? Result.TotalRoomToFill : 0, Result.Remainder); 52 | } 53 | } 54 | 55 | void UInv_InventoryComponent::Server_AddNewItem_Implementation(UInv_ItemComponent* ItemComponent, int32 StackCount, int32 Remainder) 56 | { 57 | UInv_InventoryItem* NewItem = InventoryList.AddEntry(ItemComponent); 58 | NewItem->SetTotalStackCount(StackCount); 59 | 60 | if (GetOwner()->GetNetMode() == NM_ListenServer || GetOwner()->GetNetMode() == NM_Standalone) 61 | { 62 | OnItemAdded.Broadcast(NewItem); 63 | } 64 | 65 | if (Remainder == 0) 66 | { 67 | ItemComponent->PickedUp(); 68 | } 69 | else if (FInv_StackableFragment* StackableFragment = ItemComponent->GetItemManifestMutable().GetFragmentOfTypeMutable()) 70 | { 71 | StackableFragment->SetStackCount(Remainder); 72 | } 73 | } 74 | 75 | void UInv_InventoryComponent::Server_AddStacksToItem_Implementation(UInv_ItemComponent* ItemComponent, int32 StackCount, int32 Remainder) 76 | { 77 | const FGameplayTag& ItemType = IsValid(ItemComponent) ? ItemComponent->GetItemManifest().GetItemType() : FGameplayTag::EmptyTag; 78 | UInv_InventoryItem* Item = InventoryList.FindFirstItemByType(ItemType); 79 | if (!IsValid(Item)) return; 80 | 81 | Item->SetTotalStackCount(Item->GetTotalStackCount() + StackCount); 82 | 83 | if (Remainder == 0) 84 | { 85 | ItemComponent->PickedUp(); 86 | } 87 | else if (FInv_StackableFragment* StackableFragment = ItemComponent->GetItemManifestMutable().GetFragmentOfTypeMutable()) 88 | { 89 | StackableFragment->SetStackCount(Remainder); 90 | } 91 | } 92 | 93 | void UInv_InventoryComponent::Server_DropItem_Implementation(UInv_InventoryItem* Item, int32 StackCount) 94 | { 95 | const int32 NewStackCount = Item->GetTotalStackCount() - StackCount; 96 | if (NewStackCount <= 0) 97 | { 98 | InventoryList.RemoveEntry(Item); 99 | } 100 | else 101 | { 102 | Item->SetTotalStackCount(NewStackCount); 103 | } 104 | 105 | SpawnDroppedItem(Item, StackCount); 106 | } 107 | 108 | void UInv_InventoryComponent::SpawnDroppedItem(UInv_InventoryItem* Item, int32 StackCount) 109 | { 110 | const APawn* OwningPawn = OwningController->GetPawn(); 111 | FVector RotatedForward = OwningPawn->GetActorForwardVector(); 112 | RotatedForward = RotatedForward.RotateAngleAxis(FMath::FRandRange(DropSpawnAngleMin, DropSpawnAngleMax), FVector::UpVector); 113 | FVector SpawnLocation = OwningPawn->GetActorLocation() + RotatedForward * FMath::FRandRange(DropSpawnDistanceMin, DropSpawnDistanceMax); 114 | SpawnLocation.Z -= RelativeSpawnElevation; 115 | const FRotator SpawnRotation = FRotator::ZeroRotator; 116 | 117 | FInv_ItemManifest& ItemManifest = Item->GetItemManifestMutable(); 118 | if (FInv_StackableFragment* StackableFragment = ItemManifest.GetFragmentOfTypeMutable()) 119 | { 120 | StackableFragment->SetStackCount(StackCount); 121 | } 122 | ItemManifest.SpawnPickupActor(this, SpawnLocation, SpawnRotation); 123 | } 124 | 125 | void UInv_InventoryComponent::Server_ConsumeItem_Implementation(UInv_InventoryItem* Item) 126 | { 127 | const int32 NewStackCount = Item->GetTotalStackCount() - 1; 128 | if (NewStackCount <= 0) 129 | { 130 | InventoryList.RemoveEntry(Item); 131 | } 132 | else 133 | { 134 | Item->SetTotalStackCount(NewStackCount); 135 | } 136 | 137 | if (FInv_ConsumableFragment* ConsumableFragment = Item->GetItemManifestMutable().GetFragmentOfTypeMutable()) 138 | { 139 | ConsumableFragment->OnConsume(OwningController.Get()); 140 | } 141 | } 142 | 143 | void UInv_InventoryComponent::Server_EquipSlotClicked_Implementation(UInv_InventoryItem* ItemToEquip, UInv_InventoryItem* ItemToUnequip) 144 | { 145 | Multicast_EquipSlotClicked(ItemToEquip, ItemToUnequip); 146 | } 147 | 148 | void UInv_InventoryComponent::Multicast_EquipSlotClicked_Implementation(UInv_InventoryItem* ItemToEquip, UInv_InventoryItem* ItemToUnequip) 149 | { 150 | // Equipment Component will listen to these delegates 151 | OnItemEquipped.Broadcast(ItemToEquip); 152 | OnItemUnequipped.Broadcast(ItemToUnequip); 153 | } 154 | 155 | void UInv_InventoryComponent::ToggleInventoryMenu() 156 | { 157 | if (bInventoryMenuOpen) 158 | { 159 | CloseInventoryMenu(); 160 | } 161 | else 162 | { 163 | OpenInventoryMenu(); 164 | } 165 | OnInventoryMenuToggled.Broadcast(bInventoryMenuOpen); 166 | } 167 | 168 | void UInv_InventoryComponent::AddRepSubObj(UObject* SubObj) 169 | { 170 | if (IsUsingRegisteredSubObjectList() && IsReadyForReplication() && IsValid(SubObj)) 171 | { 172 | AddReplicatedSubObject(SubObj); 173 | } 174 | } 175 | 176 | void UInv_InventoryComponent::BeginPlay() 177 | { 178 | Super::BeginPlay(); 179 | 180 | ConstructInventory(); 181 | } 182 | 183 | void UInv_InventoryComponent::ConstructInventory() 184 | { 185 | OwningController = Cast(GetOwner()); 186 | checkf(OwningController.IsValid(), TEXT("Inventory Component should have a Player Controller as Owner.")) 187 | if (!OwningController->IsLocalController()) return; 188 | 189 | InventoryMenu = CreateWidget(OwningController.Get(), InventoryMenuClass); 190 | InventoryMenu->AddToViewport(); 191 | CloseInventoryMenu(); 192 | } 193 | 194 | void UInv_InventoryComponent::OpenInventoryMenu() 195 | { 196 | if (!IsValid(InventoryMenu)) return; 197 | 198 | InventoryMenu->SetVisibility(ESlateVisibility::Visible); 199 | bInventoryMenuOpen = true; 200 | 201 | if (!OwningController.IsValid()) return; 202 | 203 | FInputModeGameAndUI InputMode; 204 | OwningController->SetInputMode(InputMode); 205 | OwningController->SetShowMouseCursor(true); 206 | } 207 | 208 | void UInv_InventoryComponent::CloseInventoryMenu() 209 | { 210 | if (!IsValid(InventoryMenu)) return; 211 | 212 | InventoryMenu->SetVisibility(ESlateVisibility::Collapsed); 213 | bInventoryMenuOpen = false; 214 | 215 | if (!OwningController.IsValid()) return; 216 | 217 | FInputModeGameOnly InputMode; 218 | OwningController->SetInputMode(InputMode); 219 | OwningController->SetShowMouseCursor(false); 220 | } 221 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/InventoryManagement/FastArray/Inv_FastArray.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "InventoryManagement/FastArray/Inv_FastArray.h" 3 | 4 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 5 | #include "Items/Inv_InventoryItem.h" 6 | #include "Items/Components/Inv_ItemComponent.h" 7 | 8 | TArray FInv_InventoryFastArray::GetAllItems() const 9 | { 10 | TArray Results; 11 | Results.Reserve(Entries.Num()); 12 | for (const auto& Entry : Entries) 13 | { 14 | if (!IsValid(Entry.Item)) continue; 15 | Results.Add(Entry.Item); 16 | } 17 | return Results; 18 | } 19 | 20 | void FInv_InventoryFastArray::PreReplicatedRemove(const TArrayView RemovedIndices, int32 FinalSize) 21 | { 22 | UInv_InventoryComponent* IC = Cast(OwnerComponent); 23 | if (!IsValid(IC)) return; 24 | 25 | for (int32 Index : RemovedIndices) 26 | { 27 | IC->OnItemRemoved.Broadcast(Entries[Index].Item); 28 | } 29 | } 30 | 31 | void FInv_InventoryFastArray::PostReplicatedAdd(const TArrayView AddedIndices, int32 FinalSize) 32 | { 33 | UInv_InventoryComponent* IC = Cast(OwnerComponent); 34 | if (!IsValid(IC)) return; 35 | 36 | for (int32 Index : AddedIndices) 37 | { 38 | IC->OnItemAdded.Broadcast(Entries[Index].Item); 39 | } 40 | } 41 | 42 | UInv_InventoryItem* FInv_InventoryFastArray::AddEntry(UInv_ItemComponent* ItemComponent) 43 | { 44 | check(OwnerComponent); 45 | AActor* OwningActor = OwnerComponent->GetOwner(); 46 | check(OwningActor->HasAuthority()); 47 | UInv_InventoryComponent* IC = Cast(OwnerComponent); 48 | if (!IsValid(IC)) return nullptr; 49 | 50 | FInv_InventoryEntry& NewEntry = Entries.AddDefaulted_GetRef(); 51 | NewEntry.Item = ItemComponent->GetItemManifest().Manifest(OwningActor); 52 | 53 | IC->AddRepSubObj(NewEntry.Item); 54 | MarkItemDirty(NewEntry); 55 | 56 | return NewEntry.Item; 57 | } 58 | 59 | UInv_InventoryItem* FInv_InventoryFastArray::AddEntry(UInv_InventoryItem* Item) 60 | { 61 | check(OwnerComponent); 62 | AActor* OwningActor = OwnerComponent->GetOwner(); 63 | check(OwningActor->HasAuthority()); 64 | 65 | FInv_InventoryEntry& NewEntry = Entries.AddDefaulted_GetRef(); 66 | NewEntry.Item = Item; 67 | 68 | MarkItemDirty(NewEntry); 69 | return Item; 70 | } 71 | 72 | void FInv_InventoryFastArray::RemoveEntry(UInv_InventoryItem* Item) 73 | { 74 | for (auto EntryIt = Entries.CreateIterator(); EntryIt; ++EntryIt) 75 | { 76 | FInv_InventoryEntry& Entry = *EntryIt; 77 | if (Entry.Item == Item) 78 | { 79 | EntryIt.RemoveCurrent(); 80 | MarkArrayDirty(); 81 | } 82 | } 83 | } 84 | 85 | UInv_InventoryItem* FInv_InventoryFastArray::FindFirstItemByType(const FGameplayTag& ItemType) 86 | { 87 | auto* FoundItem = Entries.FindByPredicate([ItemType = ItemType](const FInv_InventoryEntry& Entry) 88 | { 89 | return IsValid(Entry.Item) && Entry.Item->GetItemManifest().GetItemType().MatchesTagExact(ItemType); 90 | }); 91 | return FoundItem ? FoundItem->Item : nullptr; 92 | } 93 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/InventoryManagement/Utils/Inv_InventoryStatics.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "InventoryManagement/Utils/Inv_InventoryStatics.h" 5 | 6 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 7 | #include "Items/Components/Inv_ItemComponent.h" 8 | #include "Types/Inv_GridTypes.h" 9 | #include "Widgets/Inventory/InventoryBase/Inv_InventoryBase.h" 10 | 11 | UInv_InventoryComponent* UInv_InventoryStatics::GetInventoryComponent(const APlayerController* PlayerController) 12 | { 13 | if (!IsValid(PlayerController)) return nullptr; 14 | UInv_InventoryComponent* InventoryComponent = PlayerController->FindComponentByClass(); 15 | return InventoryComponent; 16 | } 17 | 18 | EInv_ItemCategory UInv_InventoryStatics::GetItemCategoryFromItemComp(UInv_ItemComponent* ItemComp) 19 | { 20 | if (!IsValid(ItemComp)) return EInv_ItemCategory::None; 21 | return ItemComp->GetItemManifest().GetItemCategory(); 22 | } 23 | 24 | void UInv_InventoryStatics::ItemHovered(APlayerController* PC, UInv_InventoryItem* Item) 25 | { 26 | UInv_InventoryComponent* IC = GetInventoryComponent(PC); 27 | if (!IsValid(IC)) return; 28 | 29 | UInv_InventoryBase* InventoryBase = IC->GetInventoryMenu(); 30 | if (!IsValid(InventoryBase)) return; 31 | 32 | if (InventoryBase->HasHoverItem()) return; 33 | 34 | InventoryBase->OnItemHovered(Item); 35 | } 36 | 37 | void UInv_InventoryStatics::ItemUnhovered(APlayerController* PC) 38 | { 39 | UInv_InventoryComponent* IC = GetInventoryComponent(PC); 40 | if (!IsValid(IC)) return; 41 | 42 | UInv_InventoryBase* InventoryBase = IC->GetInventoryMenu(); 43 | if (!IsValid(InventoryBase)) return; 44 | 45 | InventoryBase->OnItemUnHovered(); 46 | } 47 | 48 | UInv_HoverItem* UInv_InventoryStatics::GetHoverItem(APlayerController* PC) 49 | { 50 | UInv_InventoryComponent* IC = GetInventoryComponent(PC); 51 | if (!IsValid(IC)) return nullptr; 52 | 53 | UInv_InventoryBase* InventoryBase = IC->GetInventoryMenu(); 54 | if (!IsValid(InventoryBase)) return nullptr; 55 | 56 | return InventoryBase->GetHoverItem(); 57 | } 58 | 59 | UInv_InventoryBase* UInv_InventoryStatics::GetInventoryWidget(APlayerController* PC) 60 | { 61 | UInv_InventoryComponent* IC = GetInventoryComponent(PC); 62 | if (!IsValid(IC)) return nullptr; 63 | 64 | return IC->GetInventoryMenu(); 65 | } 66 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Items/Components/Inv_ItemComponent.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Items/Components/Inv_ItemComponent.h" 5 | #include "Net/UnrealNetwork.h" 6 | 7 | UInv_ItemComponent::UInv_ItemComponent() 8 | { 9 | PrimaryComponentTick.bCanEverTick = false; 10 | PickupMessage = FString("E - Pick Up"); 11 | SetIsReplicatedByDefault(true); 12 | } 13 | 14 | void UInv_ItemComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const 15 | { 16 | Super::GetLifetimeReplicatedProps(OutLifetimeProps); 17 | 18 | DOREPLIFETIME(ThisClass, ItemManifest); 19 | } 20 | 21 | void UInv_ItemComponent::InitItemManifest(FInv_ItemManifest CopyOfManifest) 22 | { 23 | ItemManifest = CopyOfManifest; 24 | } 25 | 26 | void UInv_ItemComponent::PickedUp() 27 | { 28 | OnPickedUp(); 29 | GetOwner()->Destroy(); 30 | } 31 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Items/Fragments/Inv_FragmentTags.cpp: -------------------------------------------------------------------------------- 1 | #include "Items/Fragments/Inv_FragmentTags.h" 2 | 3 | namespace FragmentTags 4 | { 5 | UE_DEFINE_GAMEPLAY_TAG(GridFragment, "FragmentTags.GridFragment") 6 | UE_DEFINE_GAMEPLAY_TAG(IconFragment, "FragmentTags.IconFragment") 7 | UE_DEFINE_GAMEPLAY_TAG(StackableFragment, "FragmentTags.StackableFragment") 8 | UE_DEFINE_GAMEPLAY_TAG(ConsumableFragment, "FragmentTags.ConsumableFragment") 9 | UE_DEFINE_GAMEPLAY_TAG(EquipmentFragment, "FragmentTags.EquipmentFragment") 10 | 11 | UE_DEFINE_GAMEPLAY_TAG(ItemNameFragment, "FragmentTags.ItemNameFragment") 12 | UE_DEFINE_GAMEPLAY_TAG(PrimaryStatFragment, "FragmentTags.PrimaryStatFragment") 13 | 14 | UE_DEFINE_GAMEPLAY_TAG(ItemTypeFragment, "FragmentTags.ItemTypeFragment") 15 | UE_DEFINE_GAMEPLAY_TAG(FlavorTextFragment, "FragmentTags.FlavorTextFragment") 16 | UE_DEFINE_GAMEPLAY_TAG(SellValueFragment, "FragmentTags.SellValueFragment") 17 | UE_DEFINE_GAMEPLAY_TAG(RequiredLevelFragment, "FragmentTags.RequiredLevelFragment") 18 | 19 | namespace StatMod 20 | { 21 | UE_DEFINE_GAMEPLAY_TAG(StatMod_1, "FragmentTags.StatMod.1") 22 | UE_DEFINE_GAMEPLAY_TAG(StatMod_2, "FragmentTags.StatMod.2") 23 | UE_DEFINE_GAMEPLAY_TAG(StatMod_3, "FragmentTags.StatMod.3") 24 | } 25 | } -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Items/Fragments/Inv_ItemFragment.cpp: -------------------------------------------------------------------------------- 1 | #include "Items/Fragments/Inv_ItemFragment.h" 2 | 3 | #include "EquipmentManagement/EquipActor/Inv_EquipActor.h" 4 | #include "Widgets/Composite/Inv_CompositeBase.h" 5 | #include "Widgets/Composite/Inv_Leaf_Image.h" 6 | #include "Widgets/Composite/Inv_Leaf_LabeledValue.h" 7 | #include "Widgets/Composite/Inv_Leaf_Text.h" 8 | #include "Windows/WindowsApplication.h" 9 | 10 | void FInv_InventoryItemFragment::Assimilate(UInv_CompositeBase* Composite) const 11 | { 12 | if (!MatchesWidgetTag(Composite)) return; 13 | Composite->Expand(); 14 | } 15 | 16 | bool FInv_InventoryItemFragment::MatchesWidgetTag(const UInv_CompositeBase* Composite) const 17 | { 18 | return Composite->GetFragmentTag().MatchesTagExact(GetFragmentTag()); 19 | } 20 | 21 | void FInv_ImageFragment::Assimilate(UInv_CompositeBase* Composite) const 22 | { 23 | FInv_InventoryItemFragment::Assimilate(Composite); 24 | if (!MatchesWidgetTag(Composite)) return; 25 | 26 | UInv_Leaf_Image* Image = Cast(Composite); 27 | if (!IsValid(Image)) return; 28 | 29 | Image->SetImage(Icon); 30 | Image->SetBoxSize(IconDimensions); 31 | Image->SetImageSize(IconDimensions); 32 | } 33 | 34 | void FInv_TextFragment::Assimilate(UInv_CompositeBase* Composite) const 35 | { 36 | FInv_InventoryItemFragment::Assimilate(Composite); 37 | if (!MatchesWidgetTag(Composite)) return; 38 | 39 | UInv_Leaf_Text* LeafText = Cast(Composite); 40 | if (!IsValid(LeafText)) return; 41 | 42 | LeafText->SetText(FragmentText); 43 | } 44 | 45 | void FInv_LabeledNumberFragment::Assimilate(UInv_CompositeBase* Composite) const 46 | { 47 | FInv_InventoryItemFragment::Assimilate(Composite); 48 | if (!MatchesWidgetTag(Composite)) return; 49 | 50 | UInv_Leaf_LabeledValue* LabeledValue = Cast(Composite); 51 | if (!IsValid(LabeledValue)) return; 52 | 53 | LabeledValue->SetText_Label(Text_Label, bCollapseLabel); 54 | 55 | FNumberFormattingOptions Options; 56 | Options.MinimumFractionalDigits = MinFractionalDigits; 57 | Options.MaximumFractionalDigits = MaxFractionalDigits; 58 | 59 | LabeledValue->SetText_Value(FText::AsNumber(Value, &Options), bCollapseValue); 60 | } 61 | 62 | void FInv_LabeledNumberFragment::Manifest() 63 | { 64 | FInv_InventoryItemFragment::Manifest(); 65 | 66 | if (bRandomizeOnManifest) 67 | { 68 | Value = FMath::FRandRange(Min, Max); 69 | } 70 | bRandomizeOnManifest = false; 71 | } 72 | 73 | void FInv_ConsumableFragment::OnConsume(APlayerController* PC) 74 | { 75 | for (auto& Modifier : ConsumeModifiers) 76 | { 77 | auto& ModRef = Modifier.GetMutable(); 78 | ModRef.OnConsume(PC); 79 | } 80 | } 81 | 82 | void FInv_ConsumableFragment::Assimilate(UInv_CompositeBase* Composite) const 83 | { 84 | FInv_InventoryItemFragment::Assimilate(Composite); 85 | for (const auto& Modifier : ConsumeModifiers) 86 | { 87 | const auto& ModRef = Modifier.Get(); 88 | ModRef.Assimilate(Composite); 89 | } 90 | } 91 | 92 | void FInv_ConsumableFragment::Manifest() 93 | { 94 | FInv_InventoryItemFragment::Manifest(); 95 | for (auto& Modifier : ConsumeModifiers) 96 | { 97 | auto& ModRef = Modifier.GetMutable(); 98 | ModRef.Manifest(); 99 | } 100 | } 101 | 102 | void FInv_HealthPotionFragment::OnConsume(APlayerController* PC) 103 | { 104 | // Get a stats component from the PC or the PC->GetPawn() 105 | // or get the Ability System Component and apply a Gameplay Effect 106 | // or call an interface function for Healing() 107 | 108 | GEngine->AddOnScreenDebugMessage( 109 | -1, 110 | 5.f, 111 | FColor::Green, 112 | FString::Printf(TEXT("Health Potion consumed! Healing by: %f"), 113 | GetValue())); 114 | } 115 | 116 | void FInv_ManaPotionFragment::OnConsume(APlayerController* PC) 117 | { 118 | // Replenish mana however you wish 119 | 120 | GEngine->AddOnScreenDebugMessage( 121 | -1, 122 | 5.f, 123 | FColor::Blue, 124 | FString::Printf(TEXT("Mana Potion consumed! Mana replenished by: %f"), 125 | GetValue())); 126 | } 127 | 128 | void FInv_StrengthModifier::OnEquip(APlayerController* PC) 129 | { 130 | GEngine->AddOnScreenDebugMessage( 131 | -1, 132 | 5.f, 133 | FColor::Green, 134 | FString::Printf(TEXT("Strength increased by: %f"), 135 | GetValue())); 136 | } 137 | 138 | void FInv_StrengthModifier::OnUnequip(APlayerController* PC) 139 | { 140 | GEngine->AddOnScreenDebugMessage( 141 | -1, 142 | 5.f, 143 | FColor::Red, 144 | FString::Printf(TEXT("Item unequipped. Strength decreased by: %f"), 145 | GetValue())); 146 | } 147 | 148 | void FInv_ArmorModifier::OnEquip(APlayerController* PC) 149 | { 150 | GEngine->AddOnScreenDebugMessage( 151 | -1, 152 | 5.f, 153 | FColor::Green, 154 | FString::Printf(TEXT("Item equipped. Armor increased by: %f"), 155 | GetValue())); 156 | } 157 | 158 | void FInv_ArmorModifier::OnUnequip(APlayerController* PC) 159 | { 160 | GEngine->AddOnScreenDebugMessage( 161 | -1, 162 | 5.f, 163 | FColor::Red, 164 | FString::Printf(TEXT("Item unequipped. Armor decreased by: %f"), 165 | GetValue())); 166 | } 167 | 168 | void FInv_DamageModifier::OnEquip(APlayerController* PC) 169 | { 170 | GEngine->AddOnScreenDebugMessage( 171 | -1, 172 | 5.f, 173 | FColor::Green, 174 | FString::Printf(TEXT("Item equipped. Damage increased by: %f"), 175 | GetValue())); 176 | } 177 | 178 | void FInv_DamageModifier::OnUnequip(APlayerController* PC) 179 | { 180 | GEngine->AddOnScreenDebugMessage( 181 | -1, 182 | 5.f, 183 | FColor::Red, 184 | FString::Printf(TEXT("Item equipped. Damage increased by: %f"), 185 | GetValue())); 186 | } 187 | 188 | void FInv_EquipmentFragment::OnEquip(APlayerController* PC) 189 | { 190 | if (bEquipped) return; 191 | bEquipped = true; 192 | for (auto& Modifier : EquipModifiers) 193 | { 194 | auto& ModRef = Modifier.GetMutable(); 195 | ModRef.OnEquip(PC); 196 | } 197 | } 198 | 199 | void FInv_EquipmentFragment::OnUnequip(APlayerController* PC) 200 | { 201 | if (!bEquipped) return; 202 | bEquipped = false; 203 | for (auto& Modifier : EquipModifiers) 204 | { 205 | auto& ModRef = Modifier.GetMutable(); 206 | ModRef.OnUnequip(PC); 207 | } 208 | } 209 | 210 | void FInv_EquipmentFragment::Assimilate(UInv_CompositeBase* Composite) const 211 | { 212 | FInv_InventoryItemFragment::Assimilate(Composite); 213 | for (const auto& Modifier : EquipModifiers) 214 | { 215 | const auto& ModRef = Modifier.Get(); 216 | ModRef.Assimilate(Composite); 217 | } 218 | } 219 | 220 | void FInv_EquipmentFragment::Manifest() 221 | { 222 | FInv_InventoryItemFragment::Manifest(); 223 | for (auto& Modifier : EquipModifiers) 224 | { 225 | auto& ModRef = Modifier.GetMutable(); 226 | ModRef.Manifest(); 227 | } 228 | } 229 | 230 | AInv_EquipActor* FInv_EquipmentFragment::SpawnAttachedActor(USkeletalMeshComponent* AttachMesh) const 231 | { 232 | if (!IsValid(EquipActorClass) || !IsValid(AttachMesh)) return nullptr; 233 | 234 | AInv_EquipActor* SpawnedActor = AttachMesh->GetWorld()->SpawnActor(EquipActorClass); 235 | SpawnedActor->AttachToComponent(AttachMesh, FAttachmentTransformRules::SnapToTargetNotIncludingScale, SocketAttachPoint); 236 | 237 | return SpawnedActor; 238 | } 239 | 240 | void FInv_EquipmentFragment::DestroyAttachedActor() const 241 | { 242 | if (EquippedActor.IsValid()) 243 | { 244 | EquippedActor->Destroy(); 245 | } 246 | } 247 | 248 | void FInv_EquipmentFragment::SetEquippedActor(AInv_EquipActor* EquipActor) 249 | { 250 | EquippedActor = EquipActor; 251 | } 252 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Items/Inv_InventoryItem.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Items/Inv_InventoryItem.h" 5 | 6 | #include "Items/Fragments/Inv_ItemFragment.h" 7 | #include "Net/UnrealNetwork.h" 8 | 9 | void UInv_InventoryItem::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const 10 | { 11 | UObject::GetLifetimeReplicatedProps(OutLifetimeProps); 12 | 13 | DOREPLIFETIME(ThisClass, ItemManifest); 14 | DOREPLIFETIME(ThisClass, TotalStackCount); 15 | } 16 | 17 | void UInv_InventoryItem::SetItemManifest(const FInv_ItemManifest& Manifest) 18 | { 19 | ItemManifest = FInstancedStruct::Make(Manifest); 20 | } 21 | 22 | bool UInv_InventoryItem::IsStackable() const 23 | { 24 | const FInv_StackableFragment* Stackable = GetItemManifest().GetFragmentOfType(); 25 | return Stackable != nullptr; 26 | } 27 | 28 | bool UInv_InventoryItem::IsConsumable() const 29 | { 30 | return GetItemManifest().GetItemCategory() == EInv_ItemCategory::Consumable; 31 | } 32 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Items/Inv_ItemTags.cpp: -------------------------------------------------------------------------------- 1 | #include "Items/Inv_ItemTags.h" 2 | 3 | namespace GameItems 4 | { 5 | namespace Equipment 6 | { 7 | namespace Weapons 8 | { 9 | UE_DEFINE_GAMEPLAY_TAG(Axe, "GameItems.Equipment.Weapons.Axe") 10 | UE_DEFINE_GAMEPLAY_TAG(Sword, "GameItems.Equipment.Weapons.Sword") 11 | UE_DEFINE_GAMEPLAY_TAG(Knife, "GameItems.Equipment.Weapons.Knife") 12 | UE_DEFINE_GAMEPLAY_TAG(Bloodthorn, "GameItems.Equipment.Weapons.Bloodthorn") 13 | UE_DEFINE_GAMEPLAY_TAG(NightsEdge, "GameItems.Equipment.Weapons.NightsEdge") 14 | UE_DEFINE_GAMEPLAY_TAG(Shadowbane, "GameItems.Equipment.Weapons.Shadowbane") 15 | UE_DEFINE_GAMEPLAY_TAG(Staff, "GameItems.Equipment.Weapons.Staff") 16 | } 17 | 18 | namespace Cloaks 19 | { 20 | UE_DEFINE_GAMEPLAY_TAG(RedCloak, "GameItems.Equipment.Cloaks.RedCloak") 21 | UE_DEFINE_GAMEPLAY_TAG(BlueCloak, "GameItems.Equipment.Cloaks.BlueCloak") 22 | UE_DEFINE_GAMEPLAY_TAG(GreenCloak, "GameItems.Equipment.Cloaks.GreenCloak") 23 | UE_DEFINE_GAMEPLAY_TAG(YellowCloak, "GameItems.Equipment.Cloaks.YellowCloak") 24 | UE_DEFINE_GAMEPLAY_TAG(DarkGrayCloak, "GameItems.Equipment.Cloaks.DarkGrayCloak") 25 | } 26 | 27 | namespace Masks 28 | { 29 | UE_DEFINE_GAMEPLAY_TAG(SteelMask, "GameItems.Equipment.Masks.SteelMask") 30 | UE_DEFINE_GAMEPLAY_TAG(GreenMask, "GameItems.Equipment.Masks.SteelMask") 31 | UE_DEFINE_GAMEPLAY_TAG(BlueMask, "GameItems.Equipment.Masks.BlueMask") 32 | UE_DEFINE_GAMEPLAY_TAG(YellowMask, "GameItems.Equipment.Masks.YellowMask") 33 | UE_DEFINE_GAMEPLAY_TAG(GrayMask, "GameItems.Equipment.Masks.GrayMask") 34 | } 35 | } 36 | 37 | namespace Consumables 38 | { 39 | namespace Potions 40 | { 41 | namespace Red 42 | { 43 | UE_DEFINE_GAMEPLAY_TAG(Small, "GameItems.Consumables.Potions.Red.Small") 44 | UE_DEFINE_GAMEPLAY_TAG(Large, "GameItems.Consumables.Potions.Red.Large") 45 | } 46 | 47 | namespace Blue 48 | { 49 | UE_DEFINE_GAMEPLAY_TAG(Small, "GameItems.Consumables.Potions.Blue.Small") 50 | UE_DEFINE_GAMEPLAY_TAG(Large, "GameItems.Consumables.Potions.Blue.Large") 51 | } 52 | } 53 | } 54 | 55 | namespace Craftables 56 | { 57 | UE_DEFINE_GAMEPLAY_TAG(FireFernFruit, "GameItems.Craftables.FireFernFruit") 58 | UE_DEFINE_GAMEPLAY_TAG(LuminDaisy, "GameItems.Craftables.LuminDaisy") 59 | UE_DEFINE_GAMEPLAY_TAG(ScorchPetalBlossom, "GameItems.Craftables.ScorchPetalBlossom") 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Items/Manifest/Inv_ItemManifest.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Items/Manifest/Inv_ItemManifest.h" 3 | 4 | #include "Items/Inv_InventoryItem.h" 5 | #include "Items/Components/Inv_ItemComponent.h" 6 | #include "Items/Fragments/Inv_ItemFragment.h" 7 | #include "Widgets/Composite/Inv_CompositeBase.h" 8 | 9 | UInv_InventoryItem* FInv_ItemManifest::Manifest(UObject* NewOuter) 10 | { 11 | UInv_InventoryItem* Item = NewObject(NewOuter, UInv_InventoryItem::StaticClass()); 12 | Item->SetItemManifest(*this); 13 | for (auto& Fragment : Item->GetItemManifestMutable().GetFragmentsMutable()) 14 | { 15 | Fragment.GetMutable().Manifest(); 16 | } 17 | ClearFragments(); 18 | 19 | return Item; 20 | } 21 | 22 | void FInv_ItemManifest::AssimilateInventoryFragments(UInv_CompositeBase* Composite) const 23 | { 24 | const auto& InventoryItemFragments = GetAllFragmentsOfType(); 25 | for (const auto* Fragment : InventoryItemFragments) 26 | { 27 | Composite->ApplyFunction([Fragment](UInv_CompositeBase* Widget) 28 | { 29 | Fragment->Assimilate(Widget); 30 | }); 31 | } 32 | } 33 | 34 | void FInv_ItemManifest::SpawnPickupActor(const UObject* WorldContextObject, const FVector& SpawnLocation, const FRotator& SpawnRotation) 35 | { 36 | if (!IsValid(PickupActorClass) || !IsValid(WorldContextObject)) return; 37 | 38 | AActor* SpawnedActor = WorldContextObject->GetWorld()->SpawnActor(PickupActorClass, SpawnLocation, SpawnRotation); 39 | if (!IsValid(SpawnedActor)) return; 40 | 41 | // Set the item manifest, item category, item type, etc. 42 | UInv_ItemComponent* ItemComp = SpawnedActor->FindComponentByClass(); 43 | check(ItemComp); 44 | 45 | ItemComp->InitItemManifest(*this); 46 | } 47 | 48 | void FInv_ItemManifest::ClearFragments() 49 | { 50 | for (auto& Fragment : Fragments) 51 | { 52 | Fragment.Reset(); 53 | } 54 | Fragments.Empty(); 55 | } 56 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Player/Inv_PlayerController.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Player/Inv_PlayerController.h" 5 | 6 | #include "EnhancedInputComponent.h" 7 | #include "EnhancedInputSubsystems.h" 8 | #include "Interaction/Inv_Highlightable.h" 9 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 10 | #include "Items/Components/Inv_ItemComponent.h" 11 | #include "Kismet/GameplayStatics.h" 12 | #include "Widgets/HUD/Inv_HUDWidget.h" 13 | 14 | AInv_PlayerController::AInv_PlayerController() 15 | { 16 | PrimaryActorTick.bCanEverTick = true; 17 | TraceLength = 500.0; 18 | ItemTraceChannel = ECC_GameTraceChannel1; 19 | } 20 | 21 | void AInv_PlayerController::Tick(float DeltaTime) 22 | { 23 | Super::Tick(DeltaTime); 24 | 25 | TraceForItem(); 26 | } 27 | 28 | void AInv_PlayerController::ToggleInventory() 29 | { 30 | if (!InventoryComponent.IsValid()) return; 31 | InventoryComponent->ToggleInventoryMenu(); 32 | 33 | if (InventoryComponent->IsMenuOpen()) 34 | { 35 | HUDWidget->SetVisibility(ESlateVisibility::Hidden); 36 | } 37 | else 38 | { 39 | HUDWidget->SetVisibility(ESlateVisibility::HitTestInvisible); 40 | } 41 | } 42 | 43 | void AInv_PlayerController::BeginPlay() 44 | { 45 | Super::BeginPlay(); 46 | 47 | UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(GetLocalPlayer()); 48 | if (IsValid(Subsystem)) 49 | { 50 | Subsystem->AddMappingContext(DefaultIMC, 0); 51 | } 52 | 53 | InventoryComponent = FindComponentByClass(); 54 | CreateHUDWidget(); 55 | } 56 | 57 | void AInv_PlayerController::SetupInputComponent() 58 | { 59 | Super::SetupInputComponent(); 60 | 61 | UEnhancedInputComponent* EnhancedInputComponent = CastChecked(InputComponent); 62 | 63 | EnhancedInputComponent->BindAction(PrimaryInteractAction, ETriggerEvent::Started, this, &AInv_PlayerController::PrimaryInteract); 64 | EnhancedInputComponent->BindAction(ToggleInventoryAction, ETriggerEvent::Started, this, &AInv_PlayerController::ToggleInventory); 65 | } 66 | 67 | void AInv_PlayerController::PrimaryInteract() 68 | { 69 | if (!ThisActor.IsValid()) return; 70 | 71 | UInv_ItemComponent* ItemComp = ThisActor->FindComponentByClass(); 72 | if (!IsValid(ItemComp) || !InventoryComponent.IsValid()) return; 73 | 74 | InventoryComponent->TryAddItem(ItemComp); 75 | } 76 | 77 | void AInv_PlayerController::CreateHUDWidget() 78 | { 79 | if (!IsLocalController()) return; 80 | HUDWidget = CreateWidget(this, HUDWidgetClass); 81 | if (IsValid(HUDWidget)) 82 | { 83 | HUDWidget->AddToViewport(); 84 | } 85 | } 86 | 87 | void AInv_PlayerController::TraceForItem() 88 | { 89 | if (!IsValid(GEngine) || !IsValid(GEngine->GameViewport)) return; 90 | FVector2D ViewportSize; 91 | GEngine->GameViewport->GetViewportSize(ViewportSize); 92 | const FVector2D ViewportCenter = ViewportSize / 2.f; 93 | FVector TraceStart; 94 | FVector Forward; 95 | if (!UGameplayStatics::DeprojectScreenToWorld(this, ViewportCenter, TraceStart, Forward)) return; 96 | 97 | const FVector TraceEnd = TraceStart + Forward * TraceLength; 98 | FHitResult HitResult; 99 | GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, ItemTraceChannel); 100 | 101 | LastActor = ThisActor; 102 | ThisActor = HitResult.GetActor(); 103 | 104 | if (!ThisActor.IsValid()) 105 | { 106 | if (IsValid(HUDWidget)) HUDWidget->HidePickupMessage(); 107 | } 108 | 109 | if (ThisActor == LastActor) return; 110 | 111 | if (ThisActor.IsValid()) 112 | { 113 | if (UActorComponent* Highlightable = ThisActor->FindComponentByInterface(UInv_Highlightable::StaticClass()); IsValid(Highlightable)) 114 | { 115 | IInv_Highlightable::Execute_Highlight(Highlightable); 116 | } 117 | 118 | UInv_ItemComponent* ItemComponent = ThisActor->FindComponentByClass(); 119 | if (!IsValid(ItemComponent)) return; 120 | 121 | if (IsValid(HUDWidget)) HUDWidget->ShowPickupMessage(ItemComponent->GetPickupMessage()); 122 | } 123 | 124 | if (LastActor.IsValid()) 125 | { 126 | if (UActorComponent* Highlightable = LastActor->FindComponentByInterface(UInv_Highlightable::StaticClass()); IsValid(Highlightable)) 127 | { 128 | IInv_Highlightable::Execute_UnHighlight(Highlightable); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Types/Inv_GridTypes.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DruidMech/InventorySystems/c513708e16abcfbcda262b7ca68738ad88de7695/Plugins/Inventory/Source/Inventory/Private/Types/Inv_GridTypes.cpp -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/CharacterDisplay/Inv_CharacterDisplay.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/CharacterDisplay/Inv_CharacterDisplay.h" 5 | 6 | #include "Blueprint/WidgetLayoutLibrary.h" 7 | #include "EquipmentManagement/ProxyMesh/Inv_ProxyMesh.h" 8 | #include "Kismet/GameplayStatics.h" 9 | 10 | FReply UInv_CharacterDisplay::NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) 11 | { 12 | CurrentPosition = UWidgetLayoutLibrary::GetMousePositionOnViewport(GetOwningPlayer()); 13 | LastPosition = CurrentPosition; 14 | 15 | bIsDragging = true; 16 | return FReply::Handled(); 17 | } 18 | 19 | FReply UInv_CharacterDisplay::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) 20 | { 21 | bIsDragging = false; 22 | return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent); 23 | } 24 | 25 | void UInv_CharacterDisplay::NativeOnMouseLeave(const FPointerEvent& InMouseEvent) 26 | { 27 | Super::NativeOnMouseLeave(InMouseEvent); 28 | bIsDragging = false; 29 | } 30 | 31 | void UInv_CharacterDisplay::NativeOnInitialized() 32 | { 33 | Super::NativeOnInitialized(); 34 | 35 | TArray Actors; 36 | UGameplayStatics::GetAllActorsOfClass(this, AInv_ProxyMesh::StaticClass(), Actors); 37 | 38 | if (!Actors.IsValidIndex(0)) return; 39 | 40 | AInv_ProxyMesh* ProxyMesh = Cast(Actors[0]); 41 | if (!IsValid(ProxyMesh)) return; 42 | 43 | Mesh = ProxyMesh->GetMesh(); 44 | } 45 | 46 | void UInv_CharacterDisplay::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) 47 | { 48 | Super::NativeTick(MyGeometry, InDeltaTime); 49 | if (!bIsDragging) return; 50 | 51 | LastPosition = CurrentPosition; 52 | CurrentPosition = UWidgetLayoutLibrary::GetMousePositionOnViewport(GetOwningPlayer()); 53 | 54 | const float HorizontalDelta = LastPosition.X - CurrentPosition.X; 55 | 56 | if (!Mesh.IsValid()) return; 57 | Mesh->AddRelativeRotation(FRotator(0.f, HorizontalDelta, 0.f)); 58 | } 59 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Composite/Inv_Composite.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Composite/Inv_Composite.h" 5 | #include "Blueprint/WidgetTree.h" 6 | 7 | void UInv_Composite::NativeOnInitialized() 8 | { 9 | Super::NativeOnInitialized(); 10 | 11 | WidgetTree->ForEachWidget([this](UWidget* Widget) 12 | { 13 | if (UInv_CompositeBase* Composite = Cast(Widget); IsValid(Composite)) 14 | { 15 | Children.Add(Composite); 16 | Composite->Collapse(); 17 | } 18 | }); 19 | } 20 | 21 | void UInv_Composite::ApplyFunction(FuncType Function) 22 | { 23 | for (auto& Child : Children) 24 | { 25 | Child->ApplyFunction(Function); 26 | } 27 | } 28 | 29 | void UInv_Composite::Collapse() 30 | { 31 | for (auto& Child : Children) 32 | { 33 | Child->Collapse(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Composite/Inv_CompositeBase.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Composite/Inv_CompositeBase.h" 5 | 6 | void UInv_CompositeBase::Collapse() 7 | { 8 | SetVisibility(ESlateVisibility::Collapsed); 9 | } 10 | 11 | void UInv_CompositeBase::Expand() 12 | { 13 | SetVisibility(ESlateVisibility::Visible); 14 | } 15 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Composite/Inv_Leaf.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Composite/Inv_Leaf.h" 5 | 6 | void UInv_Leaf::ApplyFunction(FuncType Function) 7 | { 8 | Function(this); 9 | } 10 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Composite/Inv_Leaf_Image.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Composite/Inv_Leaf_Image.h" 5 | 6 | #include "Components/Image.h" 7 | #include "Components/SizeBox.h" 8 | 9 | void UInv_Leaf_Image::SetImage(UTexture2D* Texture) const 10 | { 11 | Image_Icon->SetBrushFromTexture(Texture); 12 | } 13 | 14 | void UInv_Leaf_Image::SetBoxSize(const FVector2D& Size) const 15 | { 16 | SizeBox_Icon->SetWidthOverride(Size.X); 17 | SizeBox_Icon->SetHeightOverride(Size.Y); 18 | } 19 | 20 | void UInv_Leaf_Image::SetImageSize(const FVector2D& Size) const 21 | { 22 | Image_Icon->SetDesiredSizeOverride(Size); 23 | } 24 | 25 | FVector2D UInv_Leaf_Image::GetImageSize() const 26 | { 27 | return Image_Icon->GetDesiredSize(); 28 | } 29 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Composite/Inv_Leaf_LabeledValue.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Composite/Inv_Leaf_LabeledValue.h" 5 | 6 | #include "Components/TextBlock.h" 7 | 8 | void UInv_Leaf_LabeledValue::SetText_Label(const FText& Text, bool bCollapse) const 9 | { 10 | if (bCollapse) 11 | { 12 | Text_Label->SetVisibility(ESlateVisibility::Collapsed); 13 | return; 14 | } 15 | Text_Label->SetText(Text); 16 | } 17 | 18 | void UInv_Leaf_LabeledValue::SetText_Value(const FText& Text, bool bCollapse) const 19 | { 20 | if (bCollapse) 21 | { 22 | Text_Value->SetVisibility(ESlateVisibility::Collapsed); 23 | return; 24 | } 25 | Text_Value->SetText(Text); 26 | } 27 | 28 | void UInv_Leaf_LabeledValue::NativePreConstruct() 29 | { 30 | Super::NativePreConstruct(); 31 | 32 | FSlateFontInfo FontInfo_Label = Text_Label->GetFont(); 33 | FontInfo_Label.Size = FontSize_Label; 34 | 35 | Text_Label->SetFont(FontInfo_Label); 36 | 37 | FSlateFontInfo FontInfo_Value = Text_Value->GetFont(); 38 | FontInfo_Value.Size = FontSize_Value; 39 | 40 | Text_Value->SetFont(FontInfo_Value); 41 | } 42 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Composite/Inv_Leaf_Text.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Composite/Inv_Leaf_Text.h" 5 | 6 | #include "Components/TextBlock.h" 7 | 8 | void UInv_Leaf_Text::SetText(const FText& Text) const 9 | { 10 | Text_LeafText->SetText(Text); 11 | } 12 | 13 | void UInv_Leaf_Text::NativePreConstruct() 14 | { 15 | Super::NativePreConstruct(); 16 | 17 | FSlateFontInfo FontInfo = Text_LeafText->GetFont(); 18 | FontInfo.Size = FontSize; 19 | 20 | Text_LeafText->SetFont(FontInfo); 21 | } 22 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/HUD/Inv_HUDWidget.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/HUD/Inv_HUDWidget.h" 5 | 6 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 7 | #include "InventoryManagement/Utils/Inv_InventoryStatics.h" 8 | #include "Widgets/HUD/Inv_InfoMessage.h" 9 | 10 | void UInv_HUDWidget::NativeOnInitialized() 11 | { 12 | Super::NativeOnInitialized(); 13 | 14 | UInv_InventoryComponent* InventoryComponent = UInv_InventoryStatics::GetInventoryComponent(GetOwningPlayer()); 15 | if (IsValid(InventoryComponent)) 16 | { 17 | InventoryComponent->NoRoomInInventory.AddDynamic(this, &UInv_HUDWidget::OnNoRoom); 18 | } 19 | } 20 | 21 | void UInv_HUDWidget::OnNoRoom() 22 | { 23 | if (!IsValid(InfoMessage)) return; 24 | InfoMessage->SetMessage(FText::FromString("No Room In Inventory.")); 25 | } 26 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/HUD/Inv_InfoMessage.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/HUD/Inv_InfoMessage.h" 5 | 6 | #include "Components/TextBlock.h" 7 | 8 | void UInv_InfoMessage::NativeOnInitialized() 9 | { 10 | Super::NativeOnInitialized(); 11 | 12 | Text_Message->SetText(FText::GetEmpty()); 13 | MessageHide(); 14 | } 15 | 16 | void UInv_InfoMessage::SetMessage(const FText& Message) 17 | { 18 | Text_Message->SetText(Message); 19 | 20 | if (!bIsMessageActive) 21 | { 22 | MessageShow(); 23 | } 24 | bIsMessageActive = true; 25 | 26 | GetWorld()->GetTimerManager().SetTimer(MessageTimer, [this]() 27 | { 28 | MessageHide(); 29 | bIsMessageActive = false; 30 | }, MessageLifetime, false); 31 | } 32 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/GridSlots/Inv_EquippedGridSlot.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/GridSlots/Inv_EquippedGridSlot.h" 5 | 6 | #include "Blueprint/WidgetLayoutLibrary.h" 7 | #include "Components/Image.h" 8 | #include "Components/Overlay.h" 9 | #include "InventoryManagement/Utils/Inv_InventoryStatics.h" 10 | #include "Items/Inv_InventoryItem.h" 11 | #include "Items/Fragments/Inv_FragmentTags.h" 12 | #include "Items/Fragments/Inv_ItemFragment.h" 13 | #include "Widgets/Inventory/HoverItem/Inv_HoverItem.h" 14 | #include "Widgets/Inventory/SlottedItems/Inv_EquippedSlottedItem.h" 15 | #include "Components/OverlaySlot.h" 16 | 17 | void UInv_EquippedGridSlot::NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) 18 | { 19 | if (!IsAvailable()) return; 20 | UInv_HoverItem* HoverItem = UInv_InventoryStatics::GetHoverItem(GetOwningPlayer()); 21 | if (!IsValid(HoverItem)) return; 22 | 23 | if (HoverItem->GetItemType().MatchesTag(EquipmentTypeTag)) 24 | { 25 | SetOccupiedTexture(); 26 | Image_GrayedOutIcon->SetVisibility(ESlateVisibility::Collapsed); 27 | } 28 | } 29 | 30 | void UInv_EquippedGridSlot::NativeOnMouseLeave(const FPointerEvent& InMouseEvent) 31 | { 32 | if (!IsAvailable()) return; 33 | UInv_HoverItem* HoverItem = UInv_InventoryStatics::GetHoverItem(GetOwningPlayer()); 34 | if (!IsValid(HoverItem)) return; 35 | 36 | if (IsValid(EquippedSlottedItem)) return; 37 | 38 | if (HoverItem->GetItemType().MatchesTag(EquipmentTypeTag)) 39 | { 40 | SetUnoccupiedTexture(); 41 | Image_GrayedOutIcon->SetVisibility(ESlateVisibility::Visible); 42 | } 43 | } 44 | 45 | FReply UInv_EquippedGridSlot::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) 46 | { 47 | EquippedGridSlotClicked.Broadcast(this, EquipmentTypeTag); 48 | return FReply::Handled(); 49 | } 50 | 51 | UInv_EquippedSlottedItem* UInv_EquippedGridSlot::OnItemEquipped(UInv_InventoryItem* Item, const FGameplayTag& EquipmentTag, float TileSize) 52 | { 53 | // Check the Equipment Type Tag 54 | if (!EquipmentTag.MatchesTagExact(EquipmentTypeTag)) return nullptr; 55 | 56 | // Get Grid Dimensions 57 | const FInv_GridFragment* GridFragment = GetFragment(Item, FragmentTags::GridFragment); 58 | if (!GridFragment) return nullptr; 59 | const FIntPoint GridDimensions = GridFragment->GetGridSize(); 60 | 61 | // Calculate the Draw Size for the Equipped Slotted Item 62 | const float IconTileWidth = TileSize - GridFragment->GetGridPadding() * 2; 63 | const FVector2D DrawSize = GridDimensions * IconTileWidth; 64 | 65 | // Create the Equipped Slotted Item widget 66 | EquippedSlottedItem = CreateWidget(GetOwningPlayer(), EquippedSlottedItemClass); 67 | 68 | // Set the Slotted Item's Inventory Item 69 | EquippedSlottedItem->SetInventoryItem(Item); 70 | 71 | // Set the Slotted Item's Equipment Type Tag 72 | EquippedSlottedItem->SetEquipmentTypeTag(EquipmentTag); 73 | 74 | // Hide the Stack Count widget on the Slotted Item 75 | EquippedSlottedItem->UpdateStackCount(0); 76 | 77 | // Set Inventory Item on this class (the Equipped Grid Slot) 78 | SetInventoryItem(Item); 79 | 80 | // Set the Image Brush on the Equipped Slotted Item 81 | const FInv_ImageFragment* ImageFragment = GetFragment(Item, FragmentTags::IconFragment); 82 | if (!ImageFragment) return nullptr; 83 | 84 | FSlateBrush Brush; 85 | Brush.SetResourceObject(ImageFragment->GetIcon()); 86 | Brush.DrawAs = ESlateBrushDrawType::Image; 87 | Brush.ImageSize = DrawSize; 88 | 89 | EquippedSlottedItem->SetImageBrush(Brush); 90 | 91 | // Add the Slotted Item as a child to this widget's Overlay 92 | Overlay_Root->AddChildToOverlay(EquippedSlottedItem); 93 | FGeometry OverlayGeometry = Overlay_Root->GetCachedGeometry(); 94 | auto OverlayPos = OverlayGeometry.Position; 95 | auto OverlaySize = OverlayGeometry.Size; 96 | 97 | const float LeftPadding = OverlaySize.X / 2.f - DrawSize.X / 2.f; 98 | const float TopPadding = OverlaySize.Y / 2.f - DrawSize.Y / 2.f; 99 | 100 | UOverlaySlot* OverlaySlot = UWidgetLayoutLibrary::SlotAsOverlaySlot(EquippedSlottedItem); 101 | OverlaySlot->SetPadding(FMargin(LeftPadding, TopPadding)); 102 | 103 | // Return the Equipped Slotted Item widget 104 | return EquippedSlottedItem; 105 | } 106 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/GridSlots/Inv_GridSlot.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/GridSlots/Inv_GridSlot.h" 5 | #include "Items/Inv_InventoryItem.h" 6 | #include "Widgets/ItemPopUp/Inv_ItemPopUp.h" 7 | 8 | #include "Components/Image.h" 9 | 10 | void UInv_GridSlot::NativeOnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) 11 | { 12 | Super::NativeOnMouseEnter(MyGeometry, MouseEvent); 13 | GridSlotHovered.Broadcast(TileIndex, MouseEvent); 14 | } 15 | 16 | void UInv_GridSlot::NativeOnMouseLeave(const FPointerEvent& MouseEvent) 17 | { 18 | Super::NativeOnMouseLeave(MouseEvent); 19 | GridSlotUnhovered.Broadcast(TileIndex, MouseEvent); 20 | } 21 | 22 | FReply UInv_GridSlot::NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) 23 | { 24 | GridSlotClicked.Broadcast(TileIndex, MouseEvent); 25 | return FReply::Handled(); 26 | } 27 | 28 | void UInv_GridSlot::SetInventoryItem(UInv_InventoryItem* Item) 29 | { 30 | InventoryItem = Item; 31 | } 32 | 33 | void UInv_GridSlot::SetItemPopUp(UInv_ItemPopUp* PopUp) 34 | { 35 | ItemPopUp = PopUp; 36 | ItemPopUp->SetGridIndex(GetIndex()); 37 | ItemPopUp->OnNativeDestruct.AddUObject(this, &ThisClass::OnItemPopUpDestruct); 38 | } 39 | 40 | UInv_ItemPopUp* UInv_GridSlot::GetItemPopUp() const 41 | { 42 | return ItemPopUp.Get(); 43 | } 44 | 45 | void UInv_GridSlot::SetOccupiedTexture() 46 | { 47 | GridSlotState = EInv_GridSlotState::Occupied; 48 | Image_GridSlot->SetBrush(Brush_Occupied); 49 | } 50 | 51 | void UInv_GridSlot::SetUnoccupiedTexture() 52 | { 53 | GridSlotState = EInv_GridSlotState::Unoccupied; 54 | Image_GridSlot->SetBrush(Brush_Unoccupied); 55 | } 56 | 57 | void UInv_GridSlot::SetSelectedTexture() 58 | { 59 | GridSlotState = EInv_GridSlotState::Selected; 60 | Image_GridSlot->SetBrush(Brush_Selected); 61 | } 62 | 63 | void UInv_GridSlot::SetGrayedOutTexture() 64 | { 65 | GridSlotState = EInv_GridSlotState::GrayedOut; 66 | Image_GridSlot->SetBrush(Brush_GrayedOut); 67 | } 68 | 69 | void UInv_GridSlot::OnItemPopUpDestruct(UUserWidget* Menu) 70 | { 71 | ItemPopUp.Reset(); 72 | } 73 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/HoverItem/Inv_HoverItem.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/HoverItem/Inv_HoverItem.h" 5 | 6 | #include "Components/Image.h" 7 | #include "Components/TextBlock.h" 8 | #include "Items/Inv_InventoryItem.h" 9 | 10 | void UInv_HoverItem::SetImageBrush(const FSlateBrush& Brush) const 11 | { 12 | Image_Icon->SetBrush(Brush); 13 | } 14 | 15 | void UInv_HoverItem::UpdateStackCount(const int32 Count) 16 | { 17 | StackCount = Count; 18 | if (Count > 0) 19 | { 20 | Text_StackCount->SetText(FText::AsNumber(Count)); 21 | Text_StackCount->SetVisibility(ESlateVisibility::Visible); 22 | } 23 | else 24 | { 25 | Text_StackCount->SetVisibility(ESlateVisibility::Collapsed); 26 | } 27 | } 28 | 29 | FGameplayTag UInv_HoverItem::GetItemType() const 30 | { 31 | if (InventoryItem.IsValid()) 32 | { 33 | return InventoryItem->GetItemManifest().GetItemType(); 34 | } 35 | return FGameplayTag(); 36 | } 37 | 38 | void UInv_HoverItem::SetIsStackable(bool bStacks) 39 | { 40 | bIsStackable = bStacks; 41 | if (!bStacks) 42 | { 43 | Text_StackCount->SetVisibility(ESlateVisibility::Collapsed); 44 | } 45 | } 46 | 47 | UInv_InventoryItem* UInv_HoverItem::GetInventoryItem() const 48 | { 49 | return InventoryItem.Get(); 50 | } 51 | 52 | void UInv_HoverItem::SetInventoryItem(UInv_InventoryItem* Item) 53 | { 54 | InventoryItem = Item; 55 | } 56 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/InventoryBase/Inv_InventoryBase.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/InventoryBase/Inv_InventoryBase.h" 5 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/SlottedItems/Inv_EquippedSlottedItem.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/SlottedItems/Inv_EquippedSlottedItem.h" 5 | 6 | FReply UInv_EquippedSlottedItem::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) 7 | { 8 | OnEquippedSlottedItemClicked.Broadcast(this); 9 | return FReply::Handled(); 10 | } 11 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/SlottedItems/Inv_SlottedItem.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/SlottedItems/Inv_SlottedItem.h" 5 | #include "Items/Inv_InventoryItem.h" 6 | 7 | #include "Components/Image.h" 8 | #include "Components/TextBlock.h" 9 | #include "InventoryManagement/Utils/Inv_InventoryStatics.h" 10 | 11 | FReply UInv_SlottedItem::NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) 12 | { 13 | OnSlottedItemClicked.Broadcast(GridIndex, MouseEvent); 14 | return FReply::Handled(); 15 | } 16 | 17 | void UInv_SlottedItem::NativeOnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) 18 | { 19 | UInv_InventoryStatics::ItemHovered(GetOwningPlayer(), InventoryItem.Get()); 20 | } 21 | 22 | void UInv_SlottedItem::NativeOnMouseLeave(const FPointerEvent& MouseEvent) 23 | { 24 | UInv_InventoryStatics::ItemUnhovered(GetOwningPlayer()); 25 | } 26 | 27 | void UInv_SlottedItem::SetInventoryItem(UInv_InventoryItem* Item) 28 | { 29 | InventoryItem = Item; 30 | } 31 | 32 | void UInv_SlottedItem::SetImageBrush(const FSlateBrush& Brush) const 33 | { 34 | Image_Icon->SetBrush(Brush); 35 | } 36 | 37 | void UInv_SlottedItem::UpdateStackCount(int32 StackCount) 38 | { 39 | if (StackCount > 0) 40 | { 41 | Text_StackCount->SetVisibility(ESlateVisibility::Visible); 42 | Text_StackCount->SetText(FText::AsNumber(StackCount)); 43 | } 44 | else 45 | { 46 | Text_StackCount->SetVisibility(ESlateVisibility::Collapsed); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Inventory/Spatial/Inv_SpatialInventory.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Inventory/Spatial/Inv_SpatialInventory.h" 5 | 6 | #include "Inventory.h" 7 | #include "Components/Button.h" 8 | #include "Components/WidgetSwitcher.h" 9 | #include "InventoryManagement/Utils/Inv_InventoryStatics.h" 10 | #include "Widgets/Inventory/Spatial/Inv_InventoryGrid.h" 11 | #include "Inventory.h" 12 | #include "Blueprint/WidgetLayoutLibrary.h" 13 | #include "Components/CanvasPanel.h" 14 | #include "Components/CanvasPanelSlot.h" 15 | #include "Items/Inv_InventoryItem.h" 16 | #include "Widgets/ItemDescription/Inv_ItemDescription.h" 17 | #include "Blueprint/WidgetTree.h" 18 | #include "InventoryManagement/Components/Inv_InventoryComponent.h" 19 | #include "Items/Fragments/Inv_ItemFragment.h" 20 | #include "Widgets/Inventory/GridSlots/Inv_EquippedGridSlot.h" 21 | #include "Widgets/Inventory/HoverItem/Inv_HoverItem.h" 22 | #include "Widgets/Inventory/SlottedItems/Inv_EquippedSlottedItem.h" 23 | 24 | void UInv_SpatialInventory::NativeOnInitialized() 25 | { 26 | Super::NativeOnInitialized(); 27 | 28 | Button_Equippables->OnClicked.AddDynamic(this, &ThisClass::ShowEquippables); 29 | Button_Consumables->OnClicked.AddDynamic(this, &ThisClass::ShowConsumables); 30 | Button_Craftables->OnClicked.AddDynamic(this, &ThisClass::ShowCraftables); 31 | 32 | Grid_Equippables->SetOwningCanvas(CanvasPanel); 33 | Grid_Consumables->SetOwningCanvas(CanvasPanel); 34 | Grid_Craftables->SetOwningCanvas(CanvasPanel); 35 | 36 | ShowEquippables(); 37 | 38 | WidgetTree->ForEachWidget([this](UWidget* Widget) 39 | { 40 | UInv_EquippedGridSlot* EquippedGridSlot = Cast(Widget); 41 | if (IsValid(EquippedGridSlot)) 42 | { 43 | EquippedGridSlots.Add(EquippedGridSlot); 44 | EquippedGridSlot->EquippedGridSlotClicked.AddDynamic(this, &ThisClass::EquippedGridSlotClicked); 45 | } 46 | }); 47 | } 48 | 49 | void UInv_SpatialInventory::EquippedGridSlotClicked(UInv_EquippedGridSlot* EquippedGridSlot, const FGameplayTag& EquipmentTypeTag) 50 | { 51 | // Check to see if we can equip the Hover Item 52 | if (!CanEquipHoverItem(EquippedGridSlot, EquipmentTypeTag)) return; 53 | 54 | UInv_HoverItem* HoverItem = GetHoverItem(); 55 | 56 | // Create an Equipped Slotted Item and add it to the Equipped Grid Slot (call EquippedGridSlot->OnItemEquipped()) 57 | const float TileSize = UInv_InventoryStatics::GetInventoryWidget(GetOwningPlayer())->GetTileSize(); 58 | UInv_EquippedSlottedItem* EquippedSlottedItem = EquippedGridSlot->OnItemEquipped( 59 | HoverItem->GetInventoryItem(), 60 | EquipmentTypeTag, 61 | TileSize 62 | ); 63 | EquippedSlottedItem->OnEquippedSlottedItemClicked.AddDynamic(this, &ThisClass::EquippedSlottedItemClicked); 64 | 65 | // Inform the server that we've equipped an item (potentially unequipping an item as well) 66 | UInv_InventoryComponent* InventoryComponent = UInv_InventoryStatics::GetInventoryComponent(GetOwningPlayer()); 67 | check(IsValid(InventoryComponent)); 68 | 69 | InventoryComponent->Server_EquipSlotClicked(HoverItem->GetInventoryItem(), nullptr); 70 | 71 | // Clear the Hover Item 72 | Grid_Equippables->ClearHoverItem(); 73 | } 74 | 75 | void UInv_SpatialInventory::EquippedSlottedItemClicked(UInv_EquippedSlottedItem* EquippedSlottedItem) 76 | { 77 | // Remove the Item Description 78 | UInv_InventoryStatics::ItemUnhovered(GetOwningPlayer()); 79 | 80 | if (IsValid(GetHoverItem()) && GetHoverItem()->IsStackable()) return; 81 | 82 | // Get Item to Equip 83 | UInv_InventoryItem* ItemToEquip = IsValid(GetHoverItem()) ? GetHoverItem()->GetInventoryItem() : nullptr; 84 | 85 | // Get Item to Unequip 86 | UInv_InventoryItem* ItemToUnequip = EquippedSlottedItem->GetInventoryItem(); 87 | 88 | // Get the Equipped Grid Slot holding this item 89 | UInv_EquippedGridSlot* EquippedGridSlot = FindSlotWithEquippedItem(ItemToUnequip); 90 | 91 | // Clear the equipped grid slot of this item (set its inventory item to nullptr) 92 | ClearSlotOfItem(EquippedGridSlot); 93 | 94 | // Assign previously equipped item as the hover item 95 | Grid_Equippables->AssignHoverItem(ItemToUnequip); 96 | 97 | // Remove of the equipped slotted item from the equipped grid slot 98 | RemoveEquippedSlottedItem(EquippedSlottedItem); 99 | 100 | // Make a new equipped slotted item (for the item we held in HoverItem) 101 | MakeEquippedSlottedItem(EquippedSlottedItem, EquippedGridSlot, ItemToEquip); 102 | 103 | // Broadcast delegates for OnItemEquipped/OnItemUnequipped (from the IC) 104 | BroadcastSlotClickedDelegates(ItemToEquip, ItemToUnequip); 105 | } 106 | 107 | FReply UInv_SpatialInventory::NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) 108 | { 109 | ActiveGrid->DropItem(); 110 | return FReply::Handled(); 111 | } 112 | 113 | void UInv_SpatialInventory::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) 114 | { 115 | Super::NativeTick(MyGeometry, InDeltaTime); 116 | 117 | if (!IsValid(ItemDescription)) return; 118 | SetItemDescriptionSizeAndPosition(ItemDescription, CanvasPanel); 119 | SetEquippedItemDescriptionSizeAndPosition(ItemDescription, EquippedItemDescription, CanvasPanel); 120 | } 121 | 122 | void UInv_SpatialInventory::SetItemDescriptionSizeAndPosition(UInv_ItemDescription* Description, UCanvasPanel* Canvas) const 123 | { 124 | UCanvasPanelSlot* ItemDescriptionCPS = UWidgetLayoutLibrary::SlotAsCanvasSlot(Description); 125 | if (!IsValid(ItemDescriptionCPS)) return; 126 | 127 | const FVector2D ItemDescriptionSize = Description->GetBoxSize(); 128 | ItemDescriptionCPS->SetSize(ItemDescriptionSize); 129 | 130 | FVector2D ClampedPosition = UInv_WidgetUtils::GetClampedWidgetPosition( 131 | UInv_WidgetUtils::GetWidgetSize(Canvas), 132 | ItemDescriptionSize, 133 | UWidgetLayoutLibrary::GetMousePositionOnViewport(GetOwningPlayer())); 134 | 135 | ItemDescriptionCPS->SetPosition(ClampedPosition); 136 | } 137 | 138 | void UInv_SpatialInventory::SetEquippedItemDescriptionSizeAndPosition(UInv_ItemDescription* Description, UInv_ItemDescription* EquippedDescription, UCanvasPanel* Canvas) const 139 | { 140 | UCanvasPanelSlot* ItemDescriptionCPS = UWidgetLayoutLibrary::SlotAsCanvasSlot(Description); 141 | UCanvasPanelSlot* EquippedItemDescriptionCPS = UWidgetLayoutLibrary::SlotAsCanvasSlot(EquippedDescription); 142 | if (!IsValid(ItemDescriptionCPS) || !IsValid(EquippedItemDescriptionCPS)) return; 143 | 144 | const FVector2D ItemDescriptionSize = Description->GetBoxSize(); 145 | const FVector2D EquippedItemDescriptionSize = EquippedDescription->GetBoxSize(); 146 | 147 | FVector2D ClampedPosition = UInv_WidgetUtils::GetClampedWidgetPosition( 148 | UInv_WidgetUtils::GetWidgetSize(Canvas), 149 | ItemDescriptionSize, 150 | UWidgetLayoutLibrary::GetMousePositionOnViewport(GetOwningPlayer())); 151 | ClampedPosition.X -= EquippedItemDescriptionSize.X; 152 | 153 | EquippedItemDescriptionCPS->SetSize(EquippedItemDescriptionSize); 154 | EquippedItemDescriptionCPS->SetPosition(ClampedPosition); 155 | } 156 | 157 | bool UInv_SpatialInventory::CanEquipHoverItem(UInv_EquippedGridSlot* EquippedGridSlot, const FGameplayTag& EquipmentTypeTag) const 158 | { 159 | if (!IsValid(EquippedGridSlot) || EquippedGridSlot->GetInventoryItem().IsValid()) return false; 160 | 161 | UInv_HoverItem* HoverItem = GetHoverItem(); 162 | if (!IsValid(HoverItem)) return false; 163 | 164 | UInv_InventoryItem* HeldItem = HoverItem->GetInventoryItem(); 165 | 166 | return HasHoverItem() && IsValid(HeldItem) && 167 | !HoverItem->IsStackable() && 168 | HeldItem->GetItemManifest().GetItemCategory() == EInv_ItemCategory::Equippable && 169 | HeldItem->GetItemManifest().GetItemType().MatchesTag(EquipmentTypeTag); 170 | } 171 | 172 | UInv_EquippedGridSlot* UInv_SpatialInventory::FindSlotWithEquippedItem(UInv_InventoryItem* EquippedItem) const 173 | { 174 | auto* FoundEquippedGridSlot = EquippedGridSlots.FindByPredicate([EquippedItem](const UInv_EquippedGridSlot* GridSlot) 175 | { 176 | return GridSlot->GetInventoryItem() == EquippedItem; 177 | }); 178 | return FoundEquippedGridSlot ? *FoundEquippedGridSlot : nullptr; 179 | } 180 | 181 | void UInv_SpatialInventory::ClearSlotOfItem(UInv_EquippedGridSlot* EquippedGridSlot) 182 | { 183 | if (IsValid(EquippedGridSlot)) 184 | { 185 | EquippedGridSlot->SetEquippedSlottedItem(nullptr); 186 | EquippedGridSlot->SetInventoryItem(nullptr); 187 | } 188 | } 189 | 190 | void UInv_SpatialInventory::RemoveEquippedSlottedItem(UInv_EquippedSlottedItem* EquippedSlottedItem) 191 | { 192 | if (!IsValid(EquippedSlottedItem)) return; 193 | 194 | if (EquippedSlottedItem->OnEquippedSlottedItemClicked.IsAlreadyBound(this, &ThisClass::EquippedSlottedItemClicked)) 195 | { 196 | EquippedSlottedItem->OnEquippedSlottedItemClicked.RemoveDynamic(this, &ThisClass::EquippedSlottedItemClicked); 197 | } 198 | EquippedSlottedItem->RemoveFromParent(); 199 | } 200 | 201 | void UInv_SpatialInventory::MakeEquippedSlottedItem(UInv_EquippedSlottedItem* EquippedSlottedItem, UInv_EquippedGridSlot* EquippedGridSlot, UInv_InventoryItem* ItemToEquip) 202 | { 203 | if (!IsValid(EquippedGridSlot)) return; 204 | 205 | UInv_EquippedSlottedItem* SlottedItem = EquippedGridSlot->OnItemEquipped( 206 | ItemToEquip, 207 | EquippedSlottedItem->GetEquipmentTypeTag(), 208 | UInv_InventoryStatics::GetInventoryWidget(GetOwningPlayer())->GetTileSize()); 209 | if (IsValid(SlottedItem)) SlottedItem->OnEquippedSlottedItemClicked.AddDynamic(this, &ThisClass::EquippedSlottedItemClicked); 210 | 211 | EquippedGridSlot->SetEquippedSlottedItem(SlottedItem); 212 | } 213 | 214 | void UInv_SpatialInventory::BroadcastSlotClickedDelegates(UInv_InventoryItem* ItemToEquip, UInv_InventoryItem* ItemToUnequip) const 215 | { 216 | UInv_InventoryComponent* InventoryComponent = UInv_InventoryStatics::GetInventoryComponent(GetOwningPlayer()); 217 | check(IsValid(InventoryComponent)); 218 | InventoryComponent->Server_EquipSlotClicked(ItemToEquip, ItemToUnequip); 219 | } 220 | 221 | FInv_SlotAvailabilityResult UInv_SpatialInventory::HasRoomForItem(UInv_ItemComponent* ItemComponent) const 222 | { 223 | switch (UInv_InventoryStatics::GetItemCategoryFromItemComp(ItemComponent)) 224 | { 225 | case EInv_ItemCategory::Equippable: 226 | return Grid_Equippables->HasRoomForItem(ItemComponent); 227 | case EInv_ItemCategory::Consumable: 228 | return Grid_Consumables->HasRoomForItem(ItemComponent); 229 | case EInv_ItemCategory::Craftable: 230 | return Grid_Craftables->HasRoomForItem(ItemComponent); 231 | default: 232 | UE_LOG(LogInventory, Error, TEXT("ItemComponent doesn't have a valid Item Category.")) 233 | return FInv_SlotAvailabilityResult(); 234 | } 235 | } 236 | 237 | void UInv_SpatialInventory::OnItemHovered(UInv_InventoryItem* Item) 238 | { 239 | const auto& Manifest = Item->GetItemManifest(); 240 | UInv_ItemDescription* DescriptionWidget = GetItemDescription(); 241 | DescriptionWidget->SetVisibility(ESlateVisibility::Collapsed); 242 | 243 | GetOwningPlayer()->GetWorldTimerManager().ClearTimer(DescriptionTimer); 244 | GetOwningPlayer()->GetWorldTimerManager().ClearTimer(EquippedDescriptionTimer); 245 | 246 | FTimerDelegate DescriptionTimerDelegate; 247 | DescriptionTimerDelegate.BindLambda([this, Item, &Manifest, DescriptionWidget]() 248 | { 249 | GetItemDescription()->SetVisibility(ESlateVisibility::HitTestInvisible); 250 | Manifest.AssimilateInventoryFragments(DescriptionWidget); 251 | 252 | // For the second item description, showing the equipped item of this type. 253 | FTimerDelegate EquippedDescriptionTimerDelegate; 254 | EquippedDescriptionTimerDelegate.BindUObject(this, &ThisClass::ShowEquippedItemDescription, Item); 255 | GetOwningPlayer()->GetWorldTimerManager().SetTimer(EquippedDescriptionTimer, EquippedDescriptionTimerDelegate, EquippedDescriptionTimerDelay, false); 256 | }); 257 | 258 | GetOwningPlayer()->GetWorldTimerManager().SetTimer(DescriptionTimer, DescriptionTimerDelegate, DescriptionTimerDelay, false); 259 | } 260 | 261 | void UInv_SpatialInventory::OnItemUnHovered() 262 | { 263 | GetItemDescription()->SetVisibility(ESlateVisibility::Collapsed); 264 | GetOwningPlayer()->GetWorldTimerManager().ClearTimer(DescriptionTimer); 265 | GetEquippedItemDescription()->SetVisibility(ESlateVisibility::Collapsed); 266 | GetOwningPlayer()->GetWorldTimerManager().ClearTimer(EquippedDescriptionTimer); 267 | } 268 | 269 | bool UInv_SpatialInventory::HasHoverItem() const 270 | { 271 | if (Grid_Equippables->HasHoverItem()) return true; 272 | if (Grid_Consumables->HasHoverItem()) return true; 273 | if (Grid_Craftables->HasHoverItem()) return true; 274 | return false; 275 | } 276 | 277 | UInv_HoverItem* UInv_SpatialInventory::GetHoverItem() const 278 | { 279 | if (!ActiveGrid.IsValid()) return nullptr; 280 | return ActiveGrid->GetHoverItem(); 281 | } 282 | 283 | float UInv_SpatialInventory::GetTileSize() const 284 | { 285 | return Grid_Equippables->GetTileSize(); 286 | } 287 | 288 | void UInv_SpatialInventory::ShowEquippedItemDescription(UInv_InventoryItem* Item) 289 | { 290 | const auto& Manifest = Item->GetItemManifest(); 291 | const FInv_EquipmentFragment* EquipmentFragment = Manifest.GetFragmentOfType(); 292 | if (!EquipmentFragment) return; 293 | 294 | const FGameplayTag HoveredEquipmentType = EquipmentFragment->GetEquipmentType(); 295 | 296 | auto EquippedGridSlot = EquippedGridSlots.FindByPredicate([Item](const UInv_EquippedGridSlot* GridSlot) 297 | { 298 | return GridSlot->GetInventoryItem() == Item; 299 | }); 300 | if (EquippedGridSlot != nullptr) return; // The hovered item is already equipped, we're already showing its Item Description 301 | 302 | // It's not equipped, so find the equipped item with the same equipment type 303 | auto FoundEquippedSlot = EquippedGridSlots.FindByPredicate([HoveredEquipmentType](const UInv_EquippedGridSlot* GridSlot) 304 | { 305 | UInv_InventoryItem* InventoryItem = GridSlot->GetInventoryItem().Get(); 306 | return IsValid(InventoryItem) ? InventoryItem->GetItemManifest().GetFragmentOfType()->GetEquipmentType() == HoveredEquipmentType : false ; 307 | }); 308 | UInv_EquippedGridSlot* EquippedSlot = FoundEquippedSlot ? *FoundEquippedSlot : nullptr; 309 | if (!IsValid(EquippedSlot)) return; // No equipped item with the same equipment type 310 | 311 | UInv_InventoryItem* EquippedItem = EquippedSlot->GetInventoryItem().Get(); 312 | if (!IsValid(EquippedItem)) return; 313 | 314 | const auto& EquippedItemManifest = EquippedItem->GetItemManifest(); 315 | UInv_ItemDescription* DescriptionWidget = GetEquippedItemDescription(); 316 | 317 | auto EquippedDescriptionWidget = GetEquippedItemDescription(); 318 | 319 | EquippedDescriptionWidget->Collapse(); 320 | DescriptionWidget->SetVisibility(ESlateVisibility::HitTestInvisible); 321 | EquippedItemManifest.AssimilateInventoryFragments(EquippedDescriptionWidget); 322 | } 323 | 324 | UInv_ItemDescription* UInv_SpatialInventory::GetItemDescription() 325 | { 326 | if (!IsValid(ItemDescription)) 327 | { 328 | ItemDescription = CreateWidget(GetOwningPlayer(), ItemDescriptionClass); 329 | CanvasPanel->AddChild(ItemDescription); 330 | } 331 | return ItemDescription; 332 | } 333 | 334 | UInv_ItemDescription* UInv_SpatialInventory::GetEquippedItemDescription() 335 | { 336 | if (!IsValid(EquippedItemDescription)) 337 | { 338 | EquippedItemDescription = CreateWidget(GetOwningPlayer(), EquippedItemDescriptionClass); 339 | CanvasPanel->AddChild(EquippedItemDescription); 340 | } 341 | return EquippedItemDescription; 342 | } 343 | 344 | void UInv_SpatialInventory::ShowEquippables() 345 | { 346 | SetActiveGrid(Grid_Equippables, Button_Equippables); 347 | } 348 | 349 | void UInv_SpatialInventory::ShowConsumables() 350 | { 351 | SetActiveGrid(Grid_Consumables, Button_Consumables); 352 | } 353 | 354 | void UInv_SpatialInventory::ShowCraftables() 355 | { 356 | SetActiveGrid(Grid_Craftables, Button_Craftables); 357 | } 358 | 359 | void UInv_SpatialInventory::DisableButton(UButton* Button) 360 | { 361 | Button_Equippables->SetIsEnabled(true); 362 | Button_Consumables->SetIsEnabled(true); 363 | Button_Craftables->SetIsEnabled(true); 364 | Button->SetIsEnabled(false); 365 | } 366 | 367 | void UInv_SpatialInventory::SetActiveGrid(UInv_InventoryGrid* Grid, UButton* Button) 368 | { 369 | if (ActiveGrid.IsValid()) 370 | { 371 | ActiveGrid->HideCursor(); 372 | ActiveGrid->OnHide(); 373 | } 374 | ActiveGrid = Grid; 375 | if (ActiveGrid.IsValid()) ActiveGrid->ShowCursor(); 376 | DisableButton(Button); 377 | Switcher->SetActiveWidget(Grid); 378 | } 379 | 380 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/ItemDescription/Inv_ItemDescription.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/ItemDescription/Inv_ItemDescription.h" 5 | 6 | #include "Components/SizeBox.h" 7 | 8 | FVector2D UInv_ItemDescription::GetBoxSize() const 9 | { 10 | return SizeBox->GetDesiredSize(); 11 | } 12 | 13 | void UInv_ItemDescription::SetVisibility(ESlateVisibility InVisibility) 14 | { 15 | for (auto Child : GetChildren()) 16 | { 17 | Child->Collapse(); 18 | } 19 | Super::SetVisibility(InVisibility); 20 | } 21 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/ItemPopUp/Inv_ItemPopUp.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/ItemPopUp/Inv_ItemPopUp.h" 5 | 6 | #include "Components/Button.h" 7 | #include "Components/SizeBox.h" 8 | #include "Components/Slider.h" 9 | #include "Components/TextBlock.h" 10 | 11 | void UInv_ItemPopUp::NativeOnInitialized() 12 | { 13 | Super::NativeOnInitialized(); 14 | 15 | Button_Split->OnClicked.AddDynamic(this, &ThisClass::SplitButtonClicked); 16 | Button_Drop->OnClicked.AddDynamic(this, &ThisClass::DropButtonClicked); 17 | Button_Consume->OnClicked.AddDynamic(this, &ThisClass::ConsumeButtonClicked); 18 | Slider_Split->OnValueChanged.AddDynamic(this, &ThisClass::SliderValueChanged); 19 | } 20 | 21 | void UInv_ItemPopUp::NativeOnMouseLeave(const FPointerEvent& InMouseEvent) 22 | { 23 | Super::NativeOnMouseLeave(InMouseEvent); 24 | RemoveFromParent(); 25 | } 26 | 27 | int32 UInv_ItemPopUp::GetSplitAmount() const 28 | { 29 | return FMath::Floor(Slider_Split->GetValue()); 30 | } 31 | 32 | void UInv_ItemPopUp::SplitButtonClicked() 33 | { 34 | if (OnSplit.ExecuteIfBound(GetSplitAmount(), GridIndex)) 35 | { 36 | RemoveFromParent(); 37 | } 38 | } 39 | 40 | void UInv_ItemPopUp::DropButtonClicked() 41 | { 42 | if (OnDrop.ExecuteIfBound(GridIndex)) 43 | { 44 | RemoveFromParent(); 45 | } 46 | } 47 | 48 | void UInv_ItemPopUp::ConsumeButtonClicked() 49 | { 50 | if (OnConsume.ExecuteIfBound(GridIndex)) 51 | { 52 | RemoveFromParent(); 53 | } 54 | } 55 | 56 | void UInv_ItemPopUp::SliderValueChanged(float Value) 57 | { 58 | Text_SplitAmount->SetText(FText::AsNumber(FMath::Floor(Value))); 59 | } 60 | 61 | void UInv_ItemPopUp::CollapseSplitButton() const 62 | { 63 | Button_Split->SetVisibility(ESlateVisibility::Collapsed); 64 | Slider_Split->SetVisibility(ESlateVisibility::Collapsed); 65 | Text_SplitAmount->SetVisibility(ESlateVisibility::Collapsed); 66 | } 67 | 68 | void UInv_ItemPopUp::CollapseConsumeButton() const 69 | { 70 | Button_Consume->SetVisibility(ESlateVisibility::Collapsed); 71 | } 72 | 73 | void UInv_ItemPopUp::SetSliderParams(const float Max, const float Value) const 74 | { 75 | Slider_Split->SetMaxValue(Max); 76 | Slider_Split->SetMinValue(1); 77 | Slider_Split->SetValue(Value); 78 | Text_SplitAmount->SetText(FText::AsNumber(FMath::Floor(Value))); 79 | } 80 | 81 | FVector2D UInv_ItemPopUp::GetBoxSize() const 82 | { 83 | return FVector2D(SizeBox_Root->GetWidthOverride(), SizeBox_Root->GetHeightOverride()); 84 | } 85 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Private/Widgets/Utils/Inv_WidgetUtils.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "Widgets/Utils/Inv_WidgetUtils.h" 5 | 6 | #include "Blueprint/SlateBlueprintLibrary.h" 7 | #include "Components/Widget.h" 8 | 9 | FVector2D UInv_WidgetUtils::GetWidgetPosition(UWidget* Widget) 10 | { 11 | const FGeometry Geometry = Widget->GetCachedGeometry(); 12 | FVector2D PixelPosition; 13 | FVector2D ViewportPosition; 14 | USlateBlueprintLibrary::LocalToViewport(Widget, Geometry, USlateBlueprintLibrary::GetLocalTopLeft(Geometry), PixelPosition, ViewportPosition); 15 | return ViewportPosition; 16 | } 17 | 18 | FVector2D UInv_WidgetUtils::GetWidgetSize(UWidget* Widget) 19 | { 20 | const FGeometry Geometry = Widget->GetCachedGeometry(); 21 | return Geometry.GetLocalSize(); 22 | } 23 | 24 | bool UInv_WidgetUtils::IsWithinBounds(const FVector2D& BoundaryPos, const FVector2D& WidgetSize, const FVector2D& MousePos) 25 | { 26 | return MousePos.X >= BoundaryPos.X && MousePos.X <= (BoundaryPos.X + WidgetSize.X) && 27 | MousePos.Y >= BoundaryPos.Y && MousePos.Y <= (BoundaryPos.Y + WidgetSize.Y); 28 | } 29 | 30 | FVector2D UInv_WidgetUtils::GetClampedWidgetPosition(const FVector2D& Boundary, const FVector2D& WidgetSize, const FVector2D& MousePos) 31 | { 32 | FVector2D ClampedPosition = MousePos; 33 | 34 | // Adjust horizontal position to ensure that the widget stays within the boundary 35 | if (MousePos.X + WidgetSize.X > Boundary.X) // Widget exceeds the right edge 36 | { 37 | ClampedPosition.X = Boundary.X - WidgetSize.X; 38 | } 39 | if (MousePos.X < 0.f) // Widget exceeds the left edge 40 | { 41 | ClampedPosition.X = 0.f; 42 | } 43 | 44 | // Adjust vertical position to ensure that the widget stays within the boundary 45 | if (MousePos.Y + WidgetSize.Y > Boundary.Y) // Widget exceeds the bottom edge 46 | { 47 | ClampedPosition.Y = Boundary.Y - WidgetSize.Y; 48 | } 49 | if (MousePos.Y < 0.f) // Widget exceeds the top edge 50 | { 51 | ClampedPosition.Y = 0.f; 52 | } 53 | 54 | return ClampedPosition; 55 | } 56 | 57 | int32 UInv_WidgetUtils::GetIndexFromPosition(const FIntPoint& Position, const int32 Columns) 58 | { 59 | return Position.X + Position.Y * Columns; 60 | } 61 | 62 | FIntPoint UInv_WidgetUtils::GetPositionFromIndex(const int32 Index, const int32 Columns) 63 | { 64 | return FIntPoint(Index % Columns, Index / Columns); 65 | } 66 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/EquipmentManagement/Components/Inv_EquipmentComponent.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Components/ActorComponent.h" 7 | #include "Inv_EquipmentComponent.generated.h" 8 | 9 | struct FGameplayTag; 10 | struct FInv_ItemManifest; 11 | struct FInv_EquipmentFragment; 12 | class AInv_EquipActor; 13 | class UInv_InventoryComponent; 14 | class UInv_InventoryItem; 15 | class APlayerController; 16 | class USkeletalMeshComponent; 17 | 18 | UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), Blueprintable) 19 | class INVENTORY_API UInv_EquipmentComponent : public UActorComponent 20 | { 21 | GENERATED_BODY() 22 | 23 | public: 24 | 25 | void SetOwningSkeletalMesh(USkeletalMeshComponent* OwningMesh); 26 | void SetIsProxy(bool bProxy) { bIsProxy = bProxy; } 27 | void InitializeOwner(APlayerController* PlayerController); 28 | protected: 29 | 30 | virtual void BeginPlay() override; 31 | 32 | private: 33 | 34 | TWeakObjectPtr InventoryComponent; 35 | TWeakObjectPtr OwningPlayerController; 36 | TWeakObjectPtr OwningSkeletalMesh; 37 | 38 | UFUNCTION() 39 | void OnItemEquipped(UInv_InventoryItem* EquippedItem); 40 | 41 | UFUNCTION() 42 | void OnItemUnequipped(UInv_InventoryItem* UnequippedItem); 43 | 44 | void InitPlayerController(); 45 | void InitInventoryComponent(); 46 | AInv_EquipActor* SpawnEquippedActor(FInv_EquipmentFragment* EquipmentFragment, const FInv_ItemManifest& Manifest, USkeletalMeshComponent* AttachMesh); 47 | 48 | UPROPERTY() 49 | TArray> EquippedActors; 50 | 51 | AInv_EquipActor* FindEquippedActor(const FGameplayTag& EquipmentTypeTag); 52 | void RemoveEquippedActor(const FGameplayTag& EquipmentTypeTag); 53 | 54 | UFUNCTION() 55 | void OnPossessedPawnChange(APawn* OldPawn, APawn* NewPawn); 56 | 57 | bool bIsProxy{false}; 58 | }; 59 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/EquipmentManagement/EquipActor/Inv_EquipActor.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/Actor.h" 7 | #include "GameplayTagContainer.h" 8 | #include "Inv_EquipActor.generated.h" 9 | 10 | UCLASS() 11 | class INVENTORY_API AInv_EquipActor : public AActor 12 | { 13 | GENERATED_BODY() 14 | 15 | public: 16 | AInv_EquipActor(); 17 | FGameplayTag GetEquipmentType() const { return EquipmentType; } 18 | void SetEquipmentType(FGameplayTag Type) { EquipmentType = Type; } 19 | 20 | private: 21 | 22 | UPROPERTY(EditAnywhere, Category = "Inventory") 23 | FGameplayTag EquipmentType; 24 | }; 25 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/EquipmentManagement/ProxyMesh/Inv_ProxyMesh.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/Actor.h" 7 | #include "Rendering/RenderCommandPipes.h" 8 | #include "Inv_ProxyMesh.generated.h" 9 | 10 | class UInv_EquipmentComponent; 11 | 12 | UCLASS() 13 | class INVENTORY_API AInv_ProxyMesh : public AActor 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | AInv_ProxyMesh(); 19 | USkeletalMeshComponent* GetMesh() const { return Mesh; } 20 | 21 | protected: 22 | virtual void BeginPlay() override; 23 | 24 | private: 25 | 26 | // This is the mesh on the player-controlled Character. 27 | TWeakObjectPtr SourceMesh; 28 | 29 | UPROPERTY(VisibleAnywhere) 30 | TObjectPtr EquipmentComponent; 31 | 32 | // This is the proxy mesh we will see in the Inventory Menu. 33 | UPROPERTY(VisibleAnywhere) 34 | TObjectPtr Mesh; 35 | 36 | FTimerHandle TimerForNextTick; 37 | void DelayedInitializeOwner(); 38 | void DelayedInitialization(); 39 | }; 40 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Interaction/Inv_Highlightable.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "UObject/Interface.h" 7 | #include "Inv_Highlightable.generated.h" 8 | 9 | // This class does not need to be modified. 10 | UINTERFACE() 11 | class UInv_Highlightable : public UInterface 12 | { 13 | GENERATED_BODY() 14 | }; 15 | 16 | /** 17 | * 18 | */ 19 | class INVENTORY_API IInv_Highlightable 20 | { 21 | GENERATED_BODY() 22 | 23 | // Add interface functions to this class. This is the class that will be inherited to implement this interface. 24 | public: 25 | 26 | UFUNCTION(BlueprintNativeEvent, Category = "Inventory") 27 | void Highlight(); 28 | 29 | UFUNCTION(BlueprintNativeEvent, Category = "Inventory") 30 | void UnHighlight(); 31 | }; 32 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Interaction/Inv_HighlightableStaticMesh.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_Highlightable.h" 7 | #include "Components/StaticMeshComponent.h" 8 | #include "Inv_HighlightableStaticMesh.generated.h" 9 | 10 | /** 11 | * 12 | */ 13 | UCLASS() 14 | class INVENTORY_API UInv_HighlightableStaticMesh : public UStaticMeshComponent, public IInv_Highlightable 15 | { 16 | GENERATED_BODY() 17 | public: 18 | virtual void Highlight_Implementation() override; 19 | virtual void UnHighlight_Implementation() override; 20 | 21 | private: 22 | 23 | UPROPERTY(EditAnywhere, Category = "Inventory") 24 | TObjectPtr HighlightMaterial; 25 | }; 26 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Inventory.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "Modules/ModuleManager.h" 6 | 7 | DECLARE_LOG_CATEGORY_EXTERN(LogInventory, Log, All); 8 | 9 | class FInventoryModule : public IModuleInterface 10 | { 11 | public: 12 | 13 | /** IModuleInterface implementation */ 14 | virtual void StartupModule() override; 15 | virtual void ShutdownModule() override; 16 | }; 17 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/InventoryManagement/Components/Inv_InventoryComponent.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Components/ActorComponent.h" 7 | #include "InventoryManagement/FastArray/Inv_FastArray.h" 8 | #include "Inv_InventoryComponent.generated.h" 9 | 10 | class UInv_ItemComponent; 11 | class UInv_InventoryItem; 12 | class UInv_InventoryBase; 13 | 14 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInventoryItemChange, UInv_InventoryItem*, Item); 15 | DECLARE_DYNAMIC_MULTICAST_DELEGATE(FNoRoomInInventory); 16 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FStackChange, const FInv_SlotAvailabilityResult&, Result); 17 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FItemEquipStatusChanged, UInv_InventoryItem*, Item); 18 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInventoryMenuToggled, bool, bOpen); 19 | 20 | UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), Blueprintable) 21 | class INVENTORY_API UInv_InventoryComponent : public UActorComponent 22 | { 23 | GENERATED_BODY() 24 | 25 | public: 26 | UInv_InventoryComponent(); 27 | virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; 28 | 29 | UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category = "Inventory") 30 | void TryAddItem(UInv_ItemComponent* ItemComponent); 31 | 32 | UFUNCTION(Server, Reliable) 33 | void Server_AddNewItem(UInv_ItemComponent* ItemComponent, int32 StackCount, int32 Remainder); 34 | 35 | UFUNCTION(Server, Reliable) 36 | void Server_AddStacksToItem(UInv_ItemComponent* ItemComponent, int32 StackCount, int32 Remainder); 37 | 38 | UFUNCTION(Server, Reliable) 39 | void Server_DropItem(UInv_InventoryItem* Item, int32 StackCount); 40 | 41 | UFUNCTION(Server, Reliable) 42 | void Server_ConsumeItem(UInv_InventoryItem* Item); 43 | 44 | UFUNCTION(Server, Reliable) 45 | void Server_EquipSlotClicked(UInv_InventoryItem* ItemToEquip, UInv_InventoryItem* ItemToUnequip); 46 | 47 | UFUNCTION(NetMulticast, Reliable) 48 | void Multicast_EquipSlotClicked(UInv_InventoryItem* ItemToEquip, UInv_InventoryItem* ItemToUnequip); 49 | 50 | void ToggleInventoryMenu(); 51 | void AddRepSubObj(UObject* SubObj); 52 | void SpawnDroppedItem(UInv_InventoryItem* Item, int32 StackCount); 53 | UInv_InventoryBase* GetInventoryMenu() const { return InventoryMenu; } 54 | bool IsMenuOpen() const { return bInventoryMenuOpen; } 55 | 56 | FInventoryItemChange OnItemAdded; 57 | FInventoryItemChange OnItemRemoved; 58 | FNoRoomInInventory NoRoomInInventory; 59 | FStackChange OnStackChange; 60 | FItemEquipStatusChanged OnItemEquipped; 61 | FItemEquipStatusChanged OnItemUnequipped; 62 | FInventoryMenuToggled OnInventoryMenuToggled; 63 | protected: 64 | virtual void BeginPlay() override; 65 | 66 | private: 67 | 68 | TWeakObjectPtr OwningController; 69 | 70 | void ConstructInventory(); 71 | 72 | UPROPERTY(Replicated) 73 | FInv_InventoryFastArray InventoryList; 74 | 75 | UPROPERTY() 76 | TObjectPtr InventoryMenu; 77 | 78 | UPROPERTY(EditAnywhere, Category = "Inventory") 79 | TSubclassOf InventoryMenuClass; 80 | 81 | bool bInventoryMenuOpen; 82 | void OpenInventoryMenu(); 83 | void CloseInventoryMenu(); 84 | 85 | UPROPERTY(EditAnywhere, Category = "Inventory") 86 | float DropSpawnAngleMin = -85.f; 87 | 88 | UPROPERTY(EditAnywhere, Category = "Inventory") 89 | float DropSpawnAngleMax = 85.f; 90 | 91 | UPROPERTY(EditAnywhere, Category = "Inventory") 92 | float DropSpawnDistanceMin = 10.f; 93 | 94 | UPROPERTY(EditAnywhere, Category = "Inventory") 95 | float DropSpawnDistanceMax = 50.f; 96 | 97 | UPROPERTY(EditAnywhere, Category = "Inventory") 98 | float RelativeSpawnElevation = 70.f; 99 | }; 100 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/InventoryManagement/FastArray/Inv_FastArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CoreMinimal.h" 4 | #include "Net/Serialization/FastArraySerializer.h" 5 | 6 | #include "Inv_FastArray.generated.h" 7 | 8 | struct FGameplayTag; 9 | class UInv_InventoryComponent; 10 | class UInv_InventoryItem; 11 | class UInv_ItemComponent; 12 | 13 | /** A single entry in an inventory */ 14 | USTRUCT(BlueprintType) 15 | struct FInv_InventoryEntry : public FFastArraySerializerItem 16 | { 17 | GENERATED_BODY() 18 | 19 | FInv_InventoryEntry() {} 20 | 21 | private: 22 | friend struct FInv_InventoryFastArray; 23 | friend UInv_InventoryComponent; 24 | 25 | UPROPERTY() 26 | TObjectPtr Item = nullptr; 27 | }; 28 | 29 | /** List of inventory items */ 30 | USTRUCT(BlueprintType) 31 | struct FInv_InventoryFastArray : public FFastArraySerializer 32 | { 33 | GENERATED_BODY() 34 | 35 | FInv_InventoryFastArray() : OwnerComponent(nullptr) {} 36 | FInv_InventoryFastArray(UActorComponent* InOwnerComponent) : OwnerComponent(InOwnerComponent) {} 37 | 38 | TArray GetAllItems() const; 39 | 40 | // FFastArraySerializer contract 41 | void PreReplicatedRemove(const TArrayView RemovedIndices, int32 FinalSize); 42 | void PostReplicatedAdd(const TArrayView AddedIndices, int32 FinalSize); 43 | // End of FFastArraySerializer contract 44 | 45 | bool NetDeltaSerialize(FNetDeltaSerializeInfo& DeltaParams) 46 | { 47 | return FastArrayDeltaSerialize(Entries, DeltaParams, *this); 48 | } 49 | 50 | UInv_InventoryItem* AddEntry(UInv_ItemComponent* ItemComponent); 51 | UInv_InventoryItem* AddEntry(UInv_InventoryItem* Item); 52 | void RemoveEntry(UInv_InventoryItem* Item); 53 | UInv_InventoryItem* FindFirstItemByType(const FGameplayTag& ItemType); 54 | 55 | private: 56 | friend UInv_InventoryComponent; 57 | 58 | // Replicated list of items 59 | UPROPERTY() 60 | TArray Entries; 61 | 62 | UPROPERTY(NotReplicated) 63 | TObjectPtr OwnerComponent; 64 | }; 65 | 66 | template<> 67 | struct TStructOpsTypeTraits : public TStructOpsTypeTraitsBase2 68 | { 69 | enum { WithNetDeltaSerializer = true }; 70 | }; 71 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/InventoryManagement/Utils/Inv_InventoryStatics.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Kismet/BlueprintFunctionLibrary.h" 7 | #include "Widgets/Utils/Inv_WidgetUtils.h" 8 | #include "Inv_InventoryStatics.generated.h" 9 | 10 | class UInv_HoverItem; 11 | class UInv_InventoryBase; 12 | 13 | UCLASS() 14 | class INVENTORY_API UInv_InventoryStatics : public UBlueprintFunctionLibrary 15 | { 16 | GENERATED_BODY() 17 | public: 18 | 19 | UFUNCTION(BlueprintCallable, Category = "Inventory") 20 | static UInv_InventoryComponent* GetInventoryComponent(const APlayerController* PlayerController); 21 | 22 | UFUNCTION(BlueprintCallable, Category = "Inventory") 23 | static EInv_ItemCategory GetItemCategoryFromItemComp(UInv_ItemComponent* ItemComp); 24 | 25 | template 26 | static void ForEach2D(TArray& Array, int32 Index, const FIntPoint& Range2D, int32 GridColumns, const FuncT& Function); 27 | 28 | UFUNCTION(BlueprintCallable, Category = "Inventory") 29 | static void ItemHovered(APlayerController* PC, UInv_InventoryItem* Item); 30 | 31 | UFUNCTION(BlueprintCallable, Category = "Inventory") 32 | static void ItemUnhovered(APlayerController* PC); 33 | 34 | UFUNCTION(BlueprintCallable, Category = "Inventory") 35 | static UInv_HoverItem* GetHoverItem(APlayerController* PC); 36 | 37 | static UInv_InventoryBase* GetInventoryWidget(APlayerController* PC); 38 | }; 39 | 40 | template 41 | void UInv_InventoryStatics::ForEach2D(TArray& Array, int32 Index, const FIntPoint& Range2D, int32 GridColumns, const FuncT& Function) 42 | { 43 | for (int32 j = 0; j < Range2D.Y; ++j) 44 | { 45 | for (int32 i = 0; i < Range2D.X; ++i) 46 | { 47 | const FIntPoint Coordinates = UInv_WidgetUtils::GetPositionFromIndex(Index, GridColumns) + FIntPoint(i, j); 48 | const int32 TileIndex = UInv_WidgetUtils::GetIndexFromPosition(Coordinates, GridColumns); 49 | if (Array.IsValidIndex(TileIndex)) 50 | { 51 | Function(Array[TileIndex]); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Items/Components/Inv_ItemComponent.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Components/ActorComponent.h" 7 | #include "Items/Manifest/Inv_ItemManifest.h" 8 | #include "Inv_ItemComponent.generated.h" 9 | 10 | 11 | UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), Blueprintable) 12 | class INVENTORY_API UInv_ItemComponent : public UActorComponent 13 | { 14 | GENERATED_BODY() 15 | 16 | public: 17 | UInv_ItemComponent(); 18 | virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; 19 | 20 | void InitItemManifest(FInv_ItemManifest CopyOfManifest); 21 | FInv_ItemManifest GetItemManifest() const { return ItemManifest; } 22 | FInv_ItemManifest& GetItemManifestMutable() { return ItemManifest; } 23 | FString GetPickupMessage() const { return PickupMessage; } 24 | void PickedUp(); 25 | protected: 26 | 27 | UFUNCTION(BlueprintImplementableEvent, Category = "Inventory") 28 | void OnPickedUp(); 29 | 30 | private: 31 | 32 | UPROPERTY(Replicated, EditAnywhere, Category = "Inventory") 33 | FInv_ItemManifest ItemManifest; 34 | 35 | UPROPERTY(EditAnywhere, Category = "Inventory") 36 | FString PickupMessage; 37 | }; 38 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Items/Fragments/Inv_FragmentTags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NativeGameplayTags.h" 4 | 5 | namespace FragmentTags 6 | { 7 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(GridFragment) 8 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(IconFragment) 9 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(StackableFragment) 10 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(ConsumableFragment) 11 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(EquipmentFragment) 12 | 13 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(ItemNameFragment) 14 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(PrimaryStatFragment) 15 | 16 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(ItemTypeFragment) 17 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(FlavorTextFragment) 18 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(SellValueFragment) 19 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(RequiredLevelFragment) 20 | 21 | namespace StatMod 22 | { 23 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(StatMod_1) 24 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(StatMod_2) 25 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(StatMod_3) 26 | } 27 | } -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Items/Fragments/Inv_ItemFragment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CoreMinimal.h" 4 | #include "GameplayTagContainer.h" 5 | #include "StructUtils/InstancedStruct.h" 6 | 7 | #include "Inv_ItemFragment.generated.h" 8 | 9 | class APlayerController; 10 | 11 | USTRUCT(BlueprintType) 12 | struct FInv_ItemFragment 13 | { 14 | GENERATED_BODY() 15 | 16 | FInv_ItemFragment() {} 17 | FInv_ItemFragment(const FInv_ItemFragment&) = default; 18 | FInv_ItemFragment& operator=(const FInv_ItemFragment&) = default; 19 | FInv_ItemFragment(FInv_ItemFragment&&) = default; 20 | FInv_ItemFragment& operator=(FInv_ItemFragment&&) = default; 21 | virtual ~FInv_ItemFragment() {} 22 | 23 | FGameplayTag GetFragmentTag() const { return FragmentTag; } 24 | void SetFragmentTag(FGameplayTag Tag) { FragmentTag = Tag; } 25 | virtual void Manifest() {} 26 | 27 | private: 28 | 29 | UPROPERTY(EditAnywhere, Category = "Inventory", meta = (Categories="FragmentTags")) 30 | FGameplayTag FragmentTag = FGameplayTag::EmptyTag; 31 | }; 32 | 33 | /* 34 | * Item fragment specifically for assimilation into a widget. 35 | */ 36 | class UInv_CompositeBase; 37 | USTRUCT(BlueprintType) 38 | struct FInv_InventoryItemFragment : public FInv_ItemFragment 39 | { 40 | GENERATED_BODY() 41 | 42 | virtual void Assimilate(UInv_CompositeBase* Composite) const; 43 | protected: 44 | bool MatchesWidgetTag(const UInv_CompositeBase* Composite) const; 45 | }; 46 | 47 | USTRUCT(BlueprintType) 48 | struct FInv_GridFragment : public FInv_ItemFragment 49 | { 50 | GENERATED_BODY() 51 | 52 | FIntPoint GetGridSize() const { return GridSize; } 53 | void SetGridSize(const FIntPoint& Size) { GridSize = Size; } 54 | float GetGridPadding() const { return GridPadding; } 55 | void SetGridPadding(float Padding) { GridPadding = Padding; } 56 | 57 | private: 58 | 59 | UPROPERTY(EditAnywhere, Category = "Inventory") 60 | FIntPoint GridSize{1, 1}; 61 | 62 | UPROPERTY(EditAnywhere, Category = "Inventory") 63 | float GridPadding{0.f}; 64 | 65 | }; 66 | 67 | USTRUCT(BlueprintType) 68 | struct FInv_ImageFragment : public FInv_InventoryItemFragment 69 | { 70 | GENERATED_BODY() 71 | 72 | UTexture2D* GetIcon() const { return Icon; } 73 | virtual void Assimilate(UInv_CompositeBase* Composite) const override; 74 | 75 | private: 76 | 77 | UPROPERTY(EditAnywhere, Category = "Inventory") 78 | TObjectPtr Icon{nullptr}; 79 | 80 | UPROPERTY(EditAnywhere, Category = "Inventory") 81 | FVector2D IconDimensions{44.f, 44.f}; 82 | }; 83 | 84 | USTRUCT(BlueprintType) 85 | struct FInv_TextFragment : public FInv_InventoryItemFragment 86 | { 87 | GENERATED_BODY() 88 | 89 | FText GetText() const { return FragmentText; } 90 | void SetText(const FText& Text) { FragmentText = Text; } 91 | virtual void Assimilate(UInv_CompositeBase* Composite) const override; 92 | 93 | private: 94 | 95 | UPROPERTY(EditAnywhere, Category = "Inventory") 96 | FText FragmentText; 97 | }; 98 | 99 | USTRUCT(BlueprintType) 100 | struct FInv_LabeledNumberFragment : public FInv_InventoryItemFragment 101 | { 102 | GENERATED_BODY() 103 | 104 | virtual void Assimilate(UInv_CompositeBase* Composite) const override; 105 | virtual void Manifest() override; 106 | float GetValue() const { return Value; } 107 | 108 | // When manifesting for the first time, this fragment will randomize. However, onee equipped 109 | // and dropped, an item should retain the same value, so randomization should not occur. 110 | bool bRandomizeOnManifest{true}; 111 | 112 | private: 113 | 114 | UPROPERTY(EditAnywhere, Category = "Inventory") 115 | FText Text_Label{}; 116 | 117 | UPROPERTY(VisibleAnywhere, Category = "Inventory") 118 | float Value{0.f}; 119 | 120 | UPROPERTY(EditAnywhere, Category = "Inventory") 121 | float Min{0}; 122 | 123 | UPROPERTY(EditAnywhere, Category = "Inventory") 124 | float Max{0}; 125 | 126 | UPROPERTY(EditAnywhere, Category = "Inventory") 127 | bool bCollapseLabel{false}; 128 | 129 | UPROPERTY(EditAnywhere, Category = "Inventory") 130 | bool bCollapseValue{false}; 131 | 132 | UPROPERTY(EditAnywhere, Category = "Inventory") 133 | int32 MinFractionalDigits{1}; 134 | 135 | UPROPERTY(EditAnywhere, Category = "Inventory") 136 | int32 MaxFractionalDigits{1}; 137 | }; 138 | 139 | USTRUCT(BlueprintType) 140 | struct FInv_StackableFragment : public FInv_ItemFragment 141 | { 142 | GENERATED_BODY() 143 | 144 | int32 GetMaxStackSize() const { return MaxStackSize; } 145 | int32 GetStackCount() const { return StackCount; } 146 | void SetStackCount(int32 Count) { StackCount = Count; } 147 | 148 | private: 149 | 150 | UPROPERTY(EditAnywhere, Category = "Inventory") 151 | int32 MaxStackSize{1}; 152 | 153 | UPROPERTY(EditAnywhere, Category = "Inventory") 154 | int32 StackCount{1}; 155 | }; 156 | 157 | 158 | 159 | // Consume Fragments 160 | 161 | USTRUCT(BlueprintType) 162 | struct FInv_ConsumeModifier : public FInv_LabeledNumberFragment 163 | { 164 | GENERATED_BODY() 165 | 166 | virtual void OnConsume(APlayerController* PC) {} 167 | }; 168 | 169 | USTRUCT(BlueprintType) 170 | struct FInv_ConsumableFragment : public FInv_InventoryItemFragment 171 | { 172 | GENERATED_BODY() 173 | 174 | virtual void OnConsume(APlayerController* PC); 175 | virtual void Assimilate(UInv_CompositeBase* Composite) const override; 176 | virtual void Manifest() override; 177 | private: 178 | 179 | UPROPERTY(EditAnywhere, Category = "Inventory", meta = (ExcludeBaseStruct)) 180 | TArray> ConsumeModifiers; 181 | }; 182 | 183 | USTRUCT(BlueprintType) 184 | struct FInv_HealthPotionFragment : public FInv_ConsumeModifier 185 | { 186 | GENERATED_BODY() 187 | 188 | virtual void OnConsume(APlayerController* PC) override; 189 | }; 190 | 191 | USTRUCT(BlueprintType) 192 | struct FInv_ManaPotionFragment : public FInv_ConsumeModifier 193 | { 194 | GENERATED_BODY() 195 | 196 | virtual void OnConsume(APlayerController* PC) override; 197 | }; 198 | 199 | 200 | // Equipment 201 | // 202 | 203 | USTRUCT(BlueprintType) 204 | struct FInv_EquipModifier : public FInv_LabeledNumberFragment 205 | { 206 | GENERATED_BODY() 207 | 208 | virtual void OnEquip(APlayerController* PC) {} 209 | virtual void OnUnequip(APlayerController* PC) {} 210 | }; 211 | 212 | USTRUCT(BlueprintType) 213 | struct FInv_StrengthModifier : public FInv_EquipModifier 214 | { 215 | GENERATED_BODY() 216 | 217 | virtual void OnEquip(APlayerController* PC) override; 218 | virtual void OnUnequip(APlayerController* PC) override; 219 | }; 220 | 221 | USTRUCT(BlueprintType) 222 | struct FInv_ArmorModifier : public FInv_EquipModifier 223 | { 224 | GENERATED_BODY() 225 | 226 | virtual void OnEquip(APlayerController* PC) override; 227 | virtual void OnUnequip(APlayerController* PC) override; 228 | }; 229 | 230 | USTRUCT(BlueprintType) 231 | struct FInv_DamageModifier : public FInv_EquipModifier 232 | { 233 | GENERATED_BODY() 234 | 235 | virtual void OnEquip(APlayerController* PC) override; 236 | virtual void OnUnequip(APlayerController* PC) override; 237 | }; 238 | 239 | class AInv_EquipActor; 240 | USTRUCT(BlueprintType) 241 | struct FInv_EquipmentFragment : public FInv_InventoryItemFragment 242 | { 243 | GENERATED_BODY() 244 | 245 | bool bEquipped{false}; 246 | void OnEquip(APlayerController* PC); 247 | void OnUnequip(APlayerController* PC); 248 | virtual void Assimilate(UInv_CompositeBase* Composite) const override; 249 | virtual void Manifest() override; 250 | 251 | AInv_EquipActor* SpawnAttachedActor(USkeletalMeshComponent* AttachMesh) const; 252 | void DestroyAttachedActor() const; 253 | FGameplayTag GetEquipmentType() const { return EquipmentType; } 254 | void SetEquippedActor(AInv_EquipActor* EquipActor); 255 | 256 | private: 257 | 258 | UPROPERTY(EditAnywhere, Category = "Inventory") 259 | TArray> EquipModifiers; 260 | 261 | UPROPERTY(EditAnywhere, Category = "Inventory") 262 | TSubclassOf EquipActorClass = nullptr; 263 | 264 | TWeakObjectPtr EquippedActor = nullptr; 265 | 266 | UPROPERTY(EditAnywhere, Category = "Inventory") 267 | FName SocketAttachPoint{NAME_None}; 268 | 269 | UPROPERTY(EditAnywhere, Category = "Inventory") 270 | FGameplayTag EquipmentType = FGameplayTag::EmptyTag; 271 | }; 272 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Items/Inv_InventoryItem.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "UObject/Object.h" 7 | #include "Items/Manifest/Inv_ItemManifest.h" 8 | 9 | #include "Inv_InventoryItem.generated.h" 10 | 11 | /** 12 | * 13 | */ 14 | UCLASS() 15 | class INVENTORY_API UInv_InventoryItem : public UObject 16 | { 17 | GENERATED_BODY() 18 | public: 19 | virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; 20 | virtual bool IsSupportedForNetworking() const override { return true; } 21 | 22 | void SetItemManifest(const FInv_ItemManifest& Manifest); 23 | const FInv_ItemManifest& GetItemManifest() const { return ItemManifest.Get(); } 24 | FInv_ItemManifest& GetItemManifestMutable() { return ItemManifest.GetMutable(); } 25 | bool IsStackable() const; 26 | bool IsConsumable() const; 27 | int32 GetTotalStackCount() const { return TotalStackCount; } 28 | void SetTotalStackCount(int32 Count) { TotalStackCount = Count; } 29 | private: 30 | 31 | UPROPERTY(VisibleAnywhere, meta = (BaseStruct = "/Script/Inventory.Inv_ItemManifest"), Replicated) 32 | FInstancedStruct ItemManifest; 33 | 34 | UPROPERTY(Replicated) 35 | int32 TotalStackCount{0}; 36 | }; 37 | 38 | template 39 | const FragmentType* GetFragment(const UInv_InventoryItem* Item, const FGameplayTag& Tag) 40 | { 41 | if (!IsValid(Item)) return nullptr; 42 | 43 | const FInv_ItemManifest& Manifest = Item->GetItemManifest(); 44 | return Manifest.GetFragmentOfTypeWithTag(Tag); 45 | } 46 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Items/Inv_ItemTags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NativeGameplayTags.h" 4 | 5 | namespace GameItems 6 | { 7 | namespace Equipment 8 | { 9 | namespace Weapons 10 | { 11 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Axe) 12 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Sword) 13 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Knife) 14 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Bloodthorn) 15 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(NightsEdge) 16 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Shadowbane) 17 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Staff) 18 | } 19 | 20 | namespace Cloaks 21 | { 22 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(RedCloak) 23 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(BlueCloak) 24 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(GreenCloak) 25 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(YellowCloak) 26 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(DarkGrayCloak) 27 | } 28 | 29 | namespace Masks 30 | { 31 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(SteelMask) 32 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(GreenMask) 33 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(BlueMask) 34 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(YellowMask) 35 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(GrayMask) 36 | } 37 | } 38 | 39 | namespace Consumables 40 | { 41 | namespace Potions 42 | { 43 | namespace Red 44 | { 45 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Small) 46 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Large) 47 | } 48 | 49 | namespace Blue 50 | { 51 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Small) 52 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(Large) 53 | } 54 | } 55 | } 56 | 57 | namespace Craftables 58 | { 59 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(FireFernFruit) 60 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(LuminDaisy) 61 | UE_DECLARE_GAMEPLAY_TAG_EXTERN(ScorchPetalBlossom) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Items/Manifest/Inv_ItemManifest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CoreMinimal.h" 4 | #include "Types/Inv_GridTypes.h" 5 | #include "StructUtils/InstancedStruct.h" 6 | #include "GameplayTagContainer.h" 7 | 8 | #include "Inv_ItemManifest.generated.h" 9 | 10 | /** 11 | * The Item Manifest contains all of the necessary data 12 | * for creating a new Inventory Item 13 | */ 14 | 15 | class UInv_InventoryItem; 16 | struct FInv_ItemFragment; 17 | class UInv_CompositeBase; 18 | 19 | USTRUCT(BlueprintType) 20 | struct INVENTORY_API FInv_ItemManifest 21 | { 22 | GENERATED_BODY() 23 | 24 | TArray>& GetFragmentsMutable() { return Fragments; } 25 | UInv_InventoryItem* Manifest(UObject* NewOuter); 26 | EInv_ItemCategory GetItemCategory() const { return ItemCategory; } 27 | FGameplayTag GetItemType() const { return ItemType; } 28 | void AssimilateInventoryFragments(UInv_CompositeBase* Composite) const; 29 | 30 | template requires std::derived_from 31 | const T* GetFragmentOfTypeWithTag(const FGameplayTag& FragmentTag) const; 32 | 33 | template requires std::derived_from 34 | const T* GetFragmentOfType() const; 35 | 36 | template requires std::derived_from 37 | T* GetFragmentOfTypeMutable(); 38 | 39 | template requires std::derived_from 40 | TArray GetAllFragmentsOfType() const; 41 | 42 | void SpawnPickupActor(const UObject* WorldContextObject, const FVector& SpawnLocation, const FRotator& SpawnRotation); 43 | 44 | private: 45 | 46 | UPROPERTY(EditAnywhere, Category = "Inventory", meta = (ExcludeBaseStruct)) 47 | TArray> Fragments; 48 | 49 | UPROPERTY(EditAnywhere, Category = "Inventory") 50 | EInv_ItemCategory ItemCategory{EInv_ItemCategory::None}; 51 | 52 | UPROPERTY(EditAnywhere, Category = "Inventory", meta = (Categories="GameItems")) 53 | FGameplayTag ItemType; 54 | 55 | UPROPERTY(EditAnywhere, Category = "Inventory") 56 | TSubclassOf PickupActorClass; 57 | 58 | void ClearFragments(); 59 | }; 60 | 61 | 62 | template 63 | requires std::derived_from 64 | const T* FInv_ItemManifest::GetFragmentOfTypeWithTag(const FGameplayTag& FragmentTag) const 65 | { 66 | for (const TInstancedStruct& Fragment : Fragments) 67 | { 68 | if (const T* FragmentPtr = Fragment.GetPtr()) 69 | { 70 | if (!FragmentPtr->GetFragmentTag().MatchesTagExact(FragmentTag)) continue; 71 | return FragmentPtr; 72 | } 73 | } 74 | 75 | return nullptr; 76 | } 77 | 78 | template requires std::derived_from 79 | const T* FInv_ItemManifest::GetFragmentOfType() const 80 | { 81 | for (const TInstancedStruct& Fragment : Fragments) 82 | { 83 | if (const T* FragmentPtr = Fragment.GetPtr()) 84 | { 85 | return FragmentPtr; 86 | } 87 | } 88 | 89 | return nullptr; 90 | } 91 | 92 | template requires std::derived_from 93 | T* FInv_ItemManifest::GetFragmentOfTypeMutable() 94 | { 95 | for (TInstancedStruct& Fragment : Fragments) 96 | { 97 | if (T* FragmentPtr = Fragment.GetMutablePtr()) 98 | { 99 | return FragmentPtr; 100 | } 101 | } 102 | 103 | return nullptr; 104 | } 105 | 106 | template requires std::derived_from 107 | TArray FInv_ItemManifest::GetAllFragmentsOfType() const 108 | { 109 | TArray Result; 110 | for (const TInstancedStruct& Fragment : Fragments) 111 | { 112 | if (const T* FragmentPtr = Fragment.GetPtr()) 113 | { 114 | Result.Add(FragmentPtr); 115 | } 116 | } 117 | return Result; 118 | } 119 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Player/Inv_PlayerController.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/PlayerController.h" 7 | #include "Inv_PlayerController.generated.h" 8 | 9 | class UInv_InventoryComponent; 10 | class UInputMappingContext; 11 | class UInputAction; 12 | class UInv_HUDWidget; 13 | 14 | UCLASS() 15 | class INVENTORY_API AInv_PlayerController : public APlayerController 16 | { 17 | GENERATED_BODY() 18 | public: 19 | AInv_PlayerController(); 20 | virtual void Tick(float DeltaTime) override; 21 | 22 | UFUNCTION(BlueprintCallable, Category = "Inventory") 23 | void ToggleInventory(); 24 | 25 | protected: 26 | virtual void BeginPlay() override; 27 | virtual void SetupInputComponent() override; 28 | 29 | private: 30 | void PrimaryInteract(); 31 | void CreateHUDWidget(); 32 | void TraceForItem(); 33 | 34 | TWeakObjectPtr InventoryComponent; 35 | 36 | UPROPERTY(EditDefaultsOnly, Category = "Inventory") 37 | TObjectPtr DefaultIMC; 38 | 39 | UPROPERTY(EditDefaultsOnly, Category = "Inventory") 40 | TObjectPtr PrimaryInteractAction; 41 | 42 | UPROPERTY(EditDefaultsOnly, Category = "Inventory") 43 | TObjectPtr ToggleInventoryAction; 44 | 45 | UPROPERTY(EditDefaultsOnly, Category = "Inventory") 46 | TSubclassOf HUDWidgetClass; 47 | 48 | UPROPERTY() 49 | TObjectPtr HUDWidget; 50 | 51 | UPROPERTY(EditDefaultsOnly, Category = "Inventory") 52 | double TraceLength; 53 | 54 | UPROPERTY(EditDefaultsOnly, Category = "Inventory") 55 | TEnumAsByte ItemTraceChannel; 56 | 57 | TWeakObjectPtr ThisActor; 58 | TWeakObjectPtr LastActor; 59 | }; 60 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Types/Inv_GridTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Inv_GridTypes.generated.h" 4 | 5 | class UInv_InventoryItem; 6 | 7 | UENUM(BlueprintType) 8 | enum class EInv_ItemCategory : uint8 9 | { 10 | Equippable, 11 | Consumable, 12 | Craftable, 13 | None 14 | }; 15 | 16 | USTRUCT() 17 | struct FInv_SlotAvailability 18 | { 19 | GENERATED_BODY() 20 | 21 | FInv_SlotAvailability() {} 22 | FInv_SlotAvailability(int32 ItemIndex, int32 Room, bool bHasItem) : Index(ItemIndex), AmountToFill(Room), bItemAtIndex(bHasItem) {} 23 | 24 | int32 Index{INDEX_NONE}; 25 | int32 AmountToFill{0}; 26 | bool bItemAtIndex{false}; 27 | }; 28 | 29 | USTRUCT() 30 | struct FInv_SlotAvailabilityResult 31 | { 32 | GENERATED_BODY() 33 | 34 | FInv_SlotAvailabilityResult() {} 35 | 36 | TWeakObjectPtr Item; 37 | int32 TotalRoomToFill{0}; 38 | int32 Remainder{0}; 39 | bool bStackable{false}; 40 | TArray SlotAvailabilities; 41 | }; 42 | 43 | UENUM(BlueprintType) 44 | enum class EInv_TileQuadrant : uint8 45 | { 46 | TopLeft, 47 | TopRight, 48 | BottomLeft, 49 | BottomRight, 50 | None 51 | }; 52 | 53 | USTRUCT(BlueprintType) 54 | struct FInv_TileParameters 55 | { 56 | GENERATED_BODY() 57 | 58 | UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Inventory") 59 | FIntPoint TileCoordinats{}; 60 | 61 | UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Inventory") 62 | int32 TileIndex{INDEX_NONE}; 63 | 64 | UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Inventory") 65 | EInv_TileQuadrant TileQuadrant{EInv_TileQuadrant::None}; 66 | }; 67 | 68 | inline bool operator==(const FInv_TileParameters& A, const FInv_TileParameters& B) 69 | { 70 | return A.TileCoordinats == B.TileCoordinats && A.TileIndex == B.TileIndex && A.TileQuadrant == B.TileQuadrant; 71 | } 72 | 73 | USTRUCT() 74 | struct FInv_SpaceQueryResult 75 | { 76 | GENERATED_BODY() 77 | 78 | // True if the space queried has no items in it 79 | bool bHasSpace{false}; 80 | 81 | // Valid if there's a single item we can swap with 82 | TWeakObjectPtr ValidItem = nullptr; 83 | 84 | // Upper left index of the valid item, if there is one 85 | int32 UpperLeftIndex{INDEX_NONE}; 86 | }; -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/CharacterDisplay/Inv_CharacterDisplay.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Inv_CharacterDisplay.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class INVENTORY_API UInv_CharacterDisplay : public UUserWidget 14 | { 15 | GENERATED_BODY() 16 | public: 17 | virtual FReply NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; 18 | virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override; 19 | virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override; 20 | virtual void NativeOnInitialized() override; 21 | virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; 22 | 23 | private: 24 | 25 | bool bIsDragging{false}; 26 | TWeakObjectPtr Mesh; 27 | 28 | FVector2D CurrentPosition; 29 | FVector2D LastPosition; 30 | }; 31 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Composite/Inv_Composite.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_CompositeBase.h" 7 | #include "Inv_Composite.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class INVENTORY_API UInv_Composite : public UInv_CompositeBase 14 | { 15 | GENERATED_BODY() 16 | public: 17 | virtual void NativeOnInitialized() override; 18 | virtual void ApplyFunction(FuncType Function) override; 19 | virtual void Collapse() override; 20 | TArray GetChildren() { return Children; } 21 | 22 | private: 23 | UPROPERTY() 24 | TArray> Children; 25 | }; 26 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Composite/Inv_CompositeBase.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "GameplayTagContainer.h" 8 | 9 | #include "Inv_CompositeBase.generated.h" 10 | 11 | /** 12 | * 13 | */ 14 | UCLASS() 15 | class INVENTORY_API UInv_CompositeBase : public UUserWidget 16 | { 17 | GENERATED_BODY() 18 | public: 19 | FGameplayTag GetFragmentTag() const { return FragmentTag; } 20 | void SetFragmentTag(const FGameplayTag& Tag) { FragmentTag = Tag; } 21 | virtual void Collapse(); 22 | void Expand(); 23 | 24 | using FuncType = TFunction; 25 | virtual void ApplyFunction(FuncType Function) {} 26 | private: 27 | 28 | UPROPERTY(EditAnywhere, Category = "Inventory") 29 | FGameplayTag FragmentTag; 30 | }; 31 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Composite/Inv_Leaf.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_CompositeBase.h" 7 | #include "Inv_Leaf.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class INVENTORY_API UInv_Leaf : public UInv_CompositeBase 14 | { 15 | GENERATED_BODY() 16 | public: 17 | virtual void ApplyFunction(FuncType Function) override; 18 | }; 19 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Composite/Inv_Leaf_Image.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_Leaf.h" 7 | #include "Inv_Leaf_Image.generated.h" 8 | 9 | class UImage; 10 | class USizeBox; 11 | 12 | UCLASS() 13 | class INVENTORY_API UInv_Leaf_Image : public UInv_Leaf 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | void SetImage(UTexture2D* Texture) const; 19 | void SetBoxSize(const FVector2D& Size) const; 20 | void SetImageSize(const FVector2D& Size) const; 21 | FVector2D GetImageSize() const; 22 | 23 | private: 24 | 25 | UPROPERTY(meta = (BindWidget)) 26 | TObjectPtr Image_Icon; 27 | 28 | UPROPERTY(meta = (BindWidget)) 29 | TObjectPtr SizeBox_Icon; 30 | }; 31 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Composite/Inv_Leaf_LabeledValue.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_Leaf.h" 7 | #include "Inv_Leaf_LabeledValue.generated.h" 8 | 9 | class UTextBlock; 10 | 11 | UCLASS() 12 | class INVENTORY_API UInv_Leaf_LabeledValue : public UInv_Leaf 13 | { 14 | GENERATED_BODY() 15 | public: 16 | 17 | void SetText_Label(const FText& Text, bool bCollapse) const; 18 | void SetText_Value(const FText& Text, bool bCollapse) const; 19 | virtual void NativePreConstruct() override; 20 | 21 | private: 22 | 23 | UPROPERTY(meta = (BindWidget)) 24 | TObjectPtr Text_Label; 25 | 26 | UPROPERTY(meta = (BindWidget)) 27 | TObjectPtr Text_Value; 28 | 29 | UPROPERTY(EditAnywhere, Category = "Inventory") 30 | int32 FontSize_Label{12}; 31 | 32 | UPROPERTY(EditAnywhere, Category = "Inventory") 33 | int32 FontSize_Value{18}; 34 | }; 35 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Composite/Inv_Leaf_Text.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_Leaf.h" 7 | #include "Inv_Leaf_Text.generated.h" 8 | 9 | class UTextBlock; 10 | UCLASS() 11 | class INVENTORY_API UInv_Leaf_Text : public UInv_Leaf 12 | { 13 | GENERATED_BODY() 14 | public: 15 | void SetText(const FText& Text) const; 16 | virtual void NativePreConstruct() override; 17 | 18 | private: 19 | 20 | UPROPERTY(meta = (BindWidget)) 21 | TObjectPtr Text_LeafText; 22 | 23 | UPROPERTY(EditAnywhere, Category = "Inventory") 24 | int32 FontSize{12}; 25 | }; 26 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/HUD/Inv_HUDWidget.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Inv_HUDWidget.generated.h" 8 | 9 | class UInv_InfoMessage; 10 | /** 11 | * 12 | */ 13 | UCLASS() 14 | class INVENTORY_API UInv_HUDWidget : public UUserWidget 15 | { 16 | GENERATED_BODY() 17 | public: 18 | virtual void NativeOnInitialized() override; 19 | 20 | UFUNCTION(BlueprintImplementableEvent, Category = "Inventory") 21 | void ShowPickupMessage(const FString& Message); 22 | 23 | UFUNCTION(BlueprintImplementableEvent, Category = "Inventory") 24 | void HidePickupMessage(); 25 | 26 | private: 27 | 28 | UPROPERTY(meta = (BindWidget)) 29 | TObjectPtr InfoMessage; 30 | 31 | UFUNCTION() 32 | void OnNoRoom(); 33 | }; 34 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/HUD/Inv_InfoMessage.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Inv_InfoMessage.generated.h" 8 | 9 | class UTextBlock; 10 | UCLASS() 11 | class INVENTORY_API UInv_InfoMessage : public UUserWidget 12 | { 13 | GENERATED_BODY() 14 | public: 15 | virtual void NativeOnInitialized() override; 16 | 17 | UFUNCTION(BlueprintImplementableEvent, Category = "Inventory") 18 | void MessageShow(); 19 | 20 | UFUNCTION(BlueprintImplementableEvent, Category = "Inventory") 21 | void MessageHide(); 22 | 23 | void SetMessage(const FText& Message); 24 | 25 | private: 26 | 27 | UPROPERTY(meta = (BindWidget)) 28 | TObjectPtr Text_Message; 29 | 30 | UPROPERTY(EditAnywhere, Category = "Inventory") 31 | float MessageLifetime{3.f}; 32 | 33 | FTimerHandle MessageTimer; 34 | bool bIsMessageActive{false}; 35 | }; 36 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/GridSlots/Inv_EquippedGridSlot.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Inv_GridSlot.h" 7 | #include "GameplayTagContainer.h" 8 | #include "Inv_EquippedGridSlot.generated.h" 9 | 10 | class UInv_EquippedSlottedItem; 11 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FEquippedGridSlotClicked, UInv_EquippedGridSlot*, GridSlot, const FGameplayTag&, EquipmentTypeTag); 12 | 13 | class UImage; 14 | class UOverlay; 15 | UCLASS() 16 | class INVENTORY_API UInv_EquippedGridSlot : public UInv_GridSlot 17 | { 18 | GENERATED_BODY() 19 | public: 20 | virtual void NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override; 21 | virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override; 22 | virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override; 23 | 24 | UInv_EquippedSlottedItem* OnItemEquipped(UInv_InventoryItem* Item, const FGameplayTag& EquipmentTag, float TileSize); 25 | void SetEquippedSlottedItem(UInv_EquippedSlottedItem* Item) { EquippedSlottedItem = Item; } 26 | 27 | FEquippedGridSlotClicked EquippedGridSlotClicked; 28 | 29 | private: 30 | UPROPERTY(EditAnywhere, Category = "Inventory", meta = (Categories = "GameItems.Equipment")) 31 | FGameplayTag EquipmentTypeTag; 32 | 33 | UPROPERTY(meta = (BindWidget)) 34 | TObjectPtr Image_GrayedOutIcon; 35 | 36 | UPROPERTY(EditAnywhere, Category = "Inventory") 37 | TSubclassOf EquippedSlottedItemClass; 38 | 39 | UPROPERTY() 40 | TObjectPtr EquippedSlottedItem; 41 | 42 | UPROPERTY(meta = (BindWidget)) 43 | TObjectPtr Overlay_Root; 44 | }; 45 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/GridSlots/Inv_GridSlot.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Inv_GridSlot.generated.h" 8 | 9 | class UInv_ItemPopUp; 10 | class UInv_InventoryItem; 11 | class UImage; 12 | 13 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FGridSlotEvent, int32, GridIndex, const FPointerEvent&, MouseEvent); 14 | 15 | UENUM(BlueprintType) 16 | enum class EInv_GridSlotState : uint8 17 | { 18 | Unoccupied, 19 | Occupied, 20 | Selected, 21 | GrayedOut 22 | }; 23 | 24 | UCLASS() 25 | class INVENTORY_API UInv_GridSlot : public UUserWidget 26 | { 27 | GENERATED_BODY() 28 | public: 29 | virtual void NativeOnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; 30 | virtual void NativeOnMouseLeave(const FPointerEvent& MouseEvent) override; 31 | virtual FReply NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; 32 | 33 | void SetTileIndex(int32 Index) { TileIndex = Index; } 34 | int32 GetTileIndex() const { return TileIndex; } 35 | EInv_GridSlotState GetGridSlotState() const { return GridSlotState; } 36 | TWeakObjectPtr GetInventoryItem() const { return InventoryItem; } 37 | void SetInventoryItem(UInv_InventoryItem* Item); 38 | int32 GetStackCount() const { return StackCount; } 39 | void SetStackCount(int32 Count) { StackCount = Count; } 40 | int32 GetIndex() const { return TileIndex; } 41 | void SetIndex(int32 Index) { TileIndex = Index; } 42 | int32 GetUpperLeftIndex() const { return UpperLeftIndex; } 43 | void SetUpperLeftIndex(int32 Index) { UpperLeftIndex = Index; } 44 | bool IsAvailable() const { return bAvailable; } 45 | void SetAvailable(bool bIsAvailable) { bAvailable = bIsAvailable; } 46 | void SetItemPopUp(UInv_ItemPopUp* PopUp); 47 | UInv_ItemPopUp* GetItemPopUp() const; 48 | 49 | void SetOccupiedTexture(); 50 | void SetUnoccupiedTexture(); 51 | void SetSelectedTexture(); 52 | void SetGrayedOutTexture(); 53 | 54 | FGridSlotEvent GridSlotClicked; 55 | FGridSlotEvent GridSlotHovered; 56 | FGridSlotEvent GridSlotUnhovered; 57 | private: 58 | int32 StackCount{0}; 59 | bool bAvailable{true}; 60 | int32 TileIndex{INDEX_NONE}; 61 | int32 UpperLeftIndex{INDEX_NONE}; 62 | TWeakObjectPtr InventoryItem; 63 | TWeakObjectPtr ItemPopUp; 64 | 65 | UPROPERTY(meta = (BindWidget)) 66 | TObjectPtr Image_GridSlot; 67 | 68 | UPROPERTY(EditAnywhere, Category = "Inventory") 69 | FSlateBrush Brush_Unoccupied; 70 | 71 | UPROPERTY(EditAnywhere, Category = "Inventory") 72 | FSlateBrush Brush_Occupied; 73 | 74 | UPROPERTY(EditAnywhere, Category = "Inventory") 75 | FSlateBrush Brush_Selected; 76 | 77 | UPROPERTY(EditAnywhere, Category = "Inventory") 78 | FSlateBrush Brush_GrayedOut; 79 | 80 | EInv_GridSlotState GridSlotState; 81 | 82 | UFUNCTION() 83 | void OnItemPopUpDestruct(UUserWidget* Menu); 84 | 85 | }; 86 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/HoverItem/Inv_HoverItem.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameplayTagContainer.h" 7 | #include "Blueprint/UserWidget.h" 8 | #include "Inv_HoverItem.generated.h" 9 | 10 | class UInv_InventoryItem; 11 | /** 12 | * The HoverItem is the item that will appear and follow the mouse 13 | * when an inventory item on the grid has been clicked. 14 | */ 15 | class UImage; 16 | class UTextBlock; 17 | UCLASS() 18 | class INVENTORY_API UInv_HoverItem : public UUserWidget 19 | { 20 | GENERATED_BODY() 21 | public: 22 | void SetImageBrush(const FSlateBrush& Brush) const; 23 | void UpdateStackCount(const int32 Count); 24 | 25 | FGameplayTag GetItemType() const; 26 | int32 GetStackCount() const { return StackCount; } 27 | bool IsStackable() const { return bIsStackable; } 28 | void SetIsStackable(bool bStacks); 29 | int32 GetPreviousGridIndex() const { return PreviousGridIndex; } 30 | void SetPreviousGridIndex(int32 Index) { PreviousGridIndex = Index; } 31 | FIntPoint GetGridDimensions() const { return GridDimensions; } 32 | void SetGridDimensions(const FIntPoint& Dimensions) { GridDimensions = Dimensions; } 33 | UInv_InventoryItem* GetInventoryItem() const; 34 | void SetInventoryItem(UInv_InventoryItem* Item); 35 | 36 | private: 37 | 38 | UPROPERTY(meta = (BindWidget)) 39 | TObjectPtr Image_Icon; 40 | 41 | UPROPERTY(meta = (BindWidget)) 42 | TObjectPtr Text_StackCount; 43 | 44 | int32 PreviousGridIndex; 45 | FIntPoint GridDimensions; 46 | TWeakObjectPtr InventoryItem; 47 | bool bIsStackable{false}; 48 | int32 StackCount{0}; 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/InventoryBase/Inv_InventoryBase.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Types/Inv_GridTypes.h" 8 | #include "Inv_InventoryBase.generated.h" 9 | 10 | class UInv_ItemComponent; 11 | class UInv_InventoryItem; 12 | class UInv_HoverItem; 13 | 14 | UCLASS() 15 | class INVENTORY_API UInv_InventoryBase : public UUserWidget 16 | { 17 | GENERATED_BODY() 18 | public: 19 | virtual FInv_SlotAvailabilityResult HasRoomForItem(UInv_ItemComponent* ItemComponent) const { return FInv_SlotAvailabilityResult(); } 20 | virtual void OnItemHovered(UInv_InventoryItem* Item) {} 21 | virtual void OnItemUnHovered() {} 22 | virtual bool HasHoverItem() const { return false; } 23 | virtual UInv_HoverItem* GetHoverItem() const { return nullptr; } 24 | virtual float GetTileSize() const { return 0.f; } 25 | }; 26 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/SlottedItems/Inv_EquippedSlottedItem.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameplayTagContainer.h" 7 | #include "Inv_SlottedItem.h" 8 | 9 | #include "Inv_EquippedSlottedItem.generated.h" 10 | 11 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FEquippedSlottedItemClicked, class UInv_EquippedSlottedItem*, SlottedItem); 12 | 13 | UCLASS() 14 | class INVENTORY_API UInv_EquippedSlottedItem : public UInv_SlottedItem 15 | { 16 | GENERATED_BODY() 17 | public: 18 | virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override; 19 | 20 | void SetEquipmentTypeTag(const FGameplayTag& Tag) { EquipmentTypeTag = Tag; } 21 | FGameplayTag GetEquipmentTypeTag() const { return EquipmentTypeTag; } 22 | 23 | FEquippedSlottedItemClicked OnEquippedSlottedItemClicked; 24 | private: 25 | 26 | UPROPERTY() 27 | FGameplayTag EquipmentTypeTag; 28 | }; 29 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/SlottedItems/Inv_SlottedItem.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Inv_SlottedItem.generated.h" 8 | 9 | class UInv_InventoryItem; 10 | class UImage; 11 | class UTextBlock; 12 | 13 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSlottedItemClicked, int32, GridIndex, const FPointerEvent&, MouseEvent); 14 | 15 | UCLASS() 16 | class INVENTORY_API UInv_SlottedItem : public UUserWidget 17 | { 18 | GENERATED_BODY() 19 | 20 | public: 21 | virtual FReply NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; 22 | virtual void NativeOnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; 23 | virtual void NativeOnMouseLeave(const FPointerEvent& MouseEvent) override; 24 | 25 | bool IsStackable() const { return bIsStackable; } 26 | void SetIsStackable(bool bStackable) { bIsStackable = bStackable; } 27 | UImage* GetImageIcon() const { return Image_Icon; } 28 | void SetGridIndex(int32 Index) { GridIndex = Index; } 29 | int32 GetGridIndex() const { return GridIndex; } 30 | void SetGridDimensions(const FIntPoint& Dimensions) { GridDimensions = Dimensions; } 31 | FIntPoint GetGridDimensions() const { return GridDimensions; } 32 | void SetInventoryItem(UInv_InventoryItem* Item); 33 | UInv_InventoryItem* GetInventoryItem() const { return InventoryItem.Get(); } 34 | void SetImageBrush(const FSlateBrush& Brush) const; 35 | void UpdateStackCount(int32 StackCount); 36 | 37 | FSlottedItemClicked OnSlottedItemClicked; 38 | private: 39 | 40 | UPROPERTY(meta = (BindWidget)) 41 | TObjectPtr Image_Icon; 42 | 43 | UPROPERTY(meta = (BindWidget)) 44 | TObjectPtr Text_StackCount; 45 | 46 | int32 GridIndex; 47 | FIntPoint GridDimensions; 48 | TWeakObjectPtr InventoryItem; 49 | bool bIsStackable{false}; 50 | }; 51 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/Spatial/Inv_InventoryGrid.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Types/Inv_GridTypes.h" 8 | 9 | #include "Inv_InventoryGrid.generated.h" 10 | 11 | class UInv_ItemPopUp; 12 | class UInv_HoverItem; 13 | struct FInv_ImageFragment; 14 | struct FInv_GridFragment; 15 | class UInv_SlottedItem; 16 | class UInv_ItemComponent; 17 | struct FInv_ItemManifest; 18 | class UCanvasPanel; 19 | class UInv_GridSlot; 20 | class UInv_InventoryComponent; 21 | struct FGameplayTag; 22 | enum class EInv_GridSlotState : uint8; 23 | /** 24 | * 25 | */ 26 | UCLASS() 27 | class INVENTORY_API UInv_InventoryGrid : public UUserWidget 28 | { 29 | GENERATED_BODY() 30 | public: 31 | virtual void NativeOnInitialized() override; 32 | virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; 33 | 34 | EInv_ItemCategory GetItemCategory() const { return ItemCategory; } 35 | FInv_SlotAvailabilityResult HasRoomForItem(const UInv_ItemComponent* ItemComponent); 36 | void ShowCursor(); 37 | void HideCursor(); 38 | void SetOwningCanvas(UCanvasPanel* OwningCanvas); 39 | void DropItem(); 40 | bool HasHoverItem() const; 41 | UInv_HoverItem* GetHoverItem() const; 42 | float GetTileSize() const { return TileSize; } 43 | void ClearHoverItem(); 44 | void AssignHoverItem(UInv_InventoryItem* InventoryItem); 45 | void OnHide(); 46 | 47 | UFUNCTION() 48 | void AddItem(UInv_InventoryItem* Item); 49 | 50 | private: 51 | 52 | TWeakObjectPtr InventoryComponent; 53 | TWeakObjectPtr OwningCanvasPanel; 54 | 55 | void ConstructGrid(); 56 | FInv_SlotAvailabilityResult HasRoomForItem(const UInv_InventoryItem* Item, const int32 StackAmountOverride = -1); 57 | FInv_SlotAvailabilityResult HasRoomForItem(const FInv_ItemManifest& Manifest, const int32 StackAmountOverride = -1); 58 | void AddItemToIndices(const FInv_SlotAvailabilityResult& Result, UInv_InventoryItem* NewItem); 59 | bool MatchesCategory(const UInv_InventoryItem* Item) const; 60 | FVector2D GetDrawSize(const FInv_GridFragment* GridFragment) const; 61 | void SetSlottedItemImage(const UInv_SlottedItem* SlottedItem, const FInv_GridFragment* GridFragment, const FInv_ImageFragment* ImageFragment) const; 62 | void AddItemAtIndex(UInv_InventoryItem* Item, const int32 Index, const bool bStackable, const int32 StackAmount); 63 | UInv_SlottedItem* CreateSlottedItem(UInv_InventoryItem* Item, 64 | const bool bStackable, 65 | const int32 StackAmount, 66 | const FInv_GridFragment* GridFragment, 67 | const FInv_ImageFragment* ImageFragment, 68 | const int32 Index); 69 | void AddSlottedItemToCanvas(const int32 Index, const FInv_GridFragment* GridFragment, UInv_SlottedItem* SlottedItem) const; 70 | void UpdateGridSlots(UInv_InventoryItem* NewItem, const int32 Index, bool bStackableItem, const int32 StackAmount); 71 | bool IsIndexClaimed(const TSet& CheckedIndices, const int32 Index) const; 72 | bool HasRoomAtIndex(const UInv_GridSlot* GridSlot, 73 | const FIntPoint& Dimensions, 74 | const TSet& CheckedIndices, 75 | TSet& OutTentativelyClaimed, 76 | const FGameplayTag& ItemType, 77 | const int32 MaxStackSize); 78 | bool CheckSlotConstraints(const UInv_GridSlot* GridSlot, 79 | const UInv_GridSlot* SubGridSlot, 80 | const TSet& CheckedIndices, 81 | TSet& OutTentativelyClaimed, 82 | const FGameplayTag& ItemType, 83 | const int32 MaxStackSize) const; 84 | FIntPoint GetItemDimensions(const FInv_ItemManifest& Manifest) const; 85 | bool HasValidItem(const UInv_GridSlot* GridSlot) const; 86 | bool IsUpperLeftSlot(const UInv_GridSlot* GridSlot, const UInv_GridSlot* SubGridSlot) const; 87 | bool DoesItemTypeMatch(const UInv_InventoryItem* SubItem, const FGameplayTag& ItemType) const; 88 | bool IsInGridBounds(const int32 StartIndex, const FIntPoint& ItemDimensions) const; 89 | int32 DetermineFillAmountForSlot(const bool bStackable, const int32 MaxStackSize, const int32 AmountToFill, const UInv_GridSlot* GridSlot) const; 90 | int32 GetStackAmount(const UInv_GridSlot* GridSlot) const; 91 | bool IsRightClick(const FPointerEvent& MouseEvent) const; 92 | bool IsLeftClick(const FPointerEvent& MouseEvent) const; 93 | void PickUp(UInv_InventoryItem* ClickedInventoryItem, const int32 GridIndex); 94 | void AssignHoverItem(UInv_InventoryItem* InventoryItem, const int32 GridIndex, const int32 PreviousGridIndex); 95 | void RemoveItemFromGrid(UInv_InventoryItem* InventoryItem, const int32 GridIndex); 96 | void UpdateTileParameters(const FVector2D& CanvasPosition, const FVector2D& MousePosition); 97 | FIntPoint CalculateHoveredCoordinates(const FVector2D& CanvasPosition, const FVector2D& MousePosition) const; 98 | EInv_TileQuadrant CalculateTileQuadrant(const FVector2D& CanvasPosition, const FVector2D& MousePosition) const; 99 | void OnTileParametersUpdated(const FInv_TileParameters& Parameters); 100 | FIntPoint CalculateStartingCoordinate(const FIntPoint& Coordinate, const FIntPoint& Dimensions, const EInv_TileQuadrant Quadrant) const; 101 | FInv_SpaceQueryResult CheckHoverPosition(const FIntPoint& Position, const FIntPoint& Dimensions); 102 | bool CursorExitedCanvas(const FVector2D& BoundaryPos, const FVector2D& BoundarySize, const FVector2D& Location); 103 | void HighlightSlots(const int32 Index, const FIntPoint& Dimensions); 104 | void UnHighlightSlots(const int32 Index, const FIntPoint& Dimensions); 105 | void ChangeHoverType(const int32 Index, const FIntPoint& Dimensions, EInv_GridSlotState GridSlotState); 106 | void PutDownOnIndex(const int32 Index); 107 | UUserWidget* GetVisibleCursorWidget(); 108 | UUserWidget* GetHiddenCursorWidget(); 109 | bool IsSameStackable(const UInv_InventoryItem* ClickedInventoryItem) const; 110 | void SwapWithHoverItem(UInv_InventoryItem* ClickedInventoryItem, const int32 GridIndex); 111 | bool ShouldSwapStackCounts(const int32 RoomInClickedSlot, const int32 HoveredStackCount, const int32 MaxStackSize) const; 112 | void SwapStackCounts(const int32 ClickedStackCount, const int32 HoveredStackCount, const int32 Index); 113 | bool ShouldConsumeHoverItemStacks(const int32 HoveredStackCount, const int32 RoomInClickedSlot) const; 114 | void ConsumeHoverItemStacks(const int32 ClickedStackCount, const int32 HoveredStackCount, const int32 Index); 115 | bool ShouldFillInStack(const int32 RoomInClickedSlot, const int32 HoveredStackCount) const; 116 | void FillInStack(const int32 FillAmount, const int32 Remainder, const int32 Index); 117 | void CreateItemPopUp(const int32 GridIndex); 118 | void PutHoverItemBack(); 119 | 120 | UPROPERTY(EditAnywhere, Category = "Inventory") 121 | TSubclassOf ItemPopUpClass; 122 | 123 | UPROPERTY() 124 | TObjectPtr ItemPopUp; 125 | 126 | UPROPERTY(EditAnywhere, Category = "Inventory") 127 | TSubclassOf VisibleCursorWidgetClass; 128 | 129 | UPROPERTY(EditAnywhere, Category = "Inventory") 130 | TSubclassOf HiddenCursorWidgetClass; 131 | 132 | UPROPERTY() 133 | TObjectPtr VisibleCursorWidget; 134 | 135 | UPROPERTY() 136 | TObjectPtr HiddenCursorWidget; 137 | 138 | UFUNCTION() 139 | void AddStacks(const FInv_SlotAvailabilityResult& Result); 140 | 141 | UFUNCTION() 142 | void OnSlottedItemClicked(int32 GridIndex, const FPointerEvent& MouseEvent); 143 | 144 | UFUNCTION() 145 | void OnGridSlotClicked(int32 GridIndex, const FPointerEvent& MouseEvent); 146 | 147 | UFUNCTION() 148 | void OnGridSlotHovered(int32 GridIndex, const FPointerEvent& MouseEvent); 149 | 150 | UFUNCTION() 151 | void OnGridSlotUnhovered(int32 GridIndex, const FPointerEvent& MouseEvent); 152 | 153 | UFUNCTION() 154 | void OnPopUpMenuSplit(int32 SplitAmount, int32 Index); 155 | 156 | UFUNCTION() 157 | void OnPopUpMenuDrop(int32 Index); 158 | 159 | UFUNCTION() 160 | void OnPopUpMenuConsume(int32 Index); 161 | 162 | UFUNCTION() 163 | void OnInventoryMenuToggled(bool bOpen); 164 | 165 | UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"), Category = "Inventory") 166 | EInv_ItemCategory ItemCategory; 167 | 168 | UPROPERTY() 169 | TArray> GridSlots; 170 | 171 | UPROPERTY(EditAnywhere, Category = "Inventory") 172 | TSubclassOf GridSlotClass; 173 | 174 | UPROPERTY(meta = (BindWidget)) 175 | TObjectPtr CanvasPanel; 176 | 177 | UPROPERTY(EditAnywhere, Category = "Inventory") 178 | TSubclassOf SlottedItemClass; 179 | 180 | UPROPERTY() 181 | TMap> SlottedItems; 182 | 183 | UPROPERTY(EditAnywhere, Category = "Inventory") 184 | int32 Rows; 185 | 186 | UPROPERTY(EditAnywhere, Category = "Inventory") 187 | int32 Columns; 188 | 189 | UPROPERTY(EditAnywhere, Category = "Inventory") 190 | float TileSize; 191 | 192 | UPROPERTY(EditAnywhere, Category = "Inventory") 193 | TSubclassOf HoverItemClass; 194 | 195 | UPROPERTY() 196 | TObjectPtr HoverItem; 197 | 198 | UPROPERTY(EditAnywhere, Category = "Inventory") 199 | FVector2D ItemPopUpOffset; 200 | 201 | FInv_TileParameters TileParameters; 202 | FInv_TileParameters LastTileParameters; 203 | 204 | // Index where an item would be placed if we click on the grid at a valid location 205 | int32 ItemDropIndex{INDEX_NONE}; 206 | FInv_SpaceQueryResult CurrentQueryResult; 207 | bool bMouseWithinCanvas; 208 | bool bLastMouseWithinCanvas; 209 | int32 LastHighlightedIndex; 210 | FIntPoint LastHighlightedDimensions; 211 | }; 212 | 213 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Inventory/Spatial/Inv_SpatialInventory.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Widgets/Inventory/InventoryBase/Inv_InventoryBase.h" 7 | #include "Inv_SpatialInventory.generated.h" 8 | 9 | struct FGameplayTag; 10 | class UInv_EquippedGridSlot; 11 | class UInv_ItemDescription; 12 | class UInv_InventoryGrid; 13 | class UWidgetSwitcher; 14 | class UButton; 15 | class UCanvasPanel; 16 | class UInv_HoverItem; 17 | /** 18 | * 19 | */ 20 | UCLASS() 21 | class INVENTORY_API UInv_SpatialInventory : public UInv_InventoryBase 22 | { 23 | GENERATED_BODY() 24 | public: 25 | virtual void NativeOnInitialized() override; 26 | virtual FReply NativeOnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; 27 | virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; 28 | 29 | virtual FInv_SlotAvailabilityResult HasRoomForItem(UInv_ItemComponent* ItemComponent) const override; 30 | virtual void OnItemHovered(UInv_InventoryItem* Item) override; 31 | virtual void OnItemUnHovered() override; 32 | virtual bool HasHoverItem() const override; 33 | virtual UInv_HoverItem* GetHoverItem() const override; 34 | virtual float GetTileSize() const override; 35 | private: 36 | 37 | UPROPERTY() 38 | TArray> EquippedGridSlots; 39 | 40 | UPROPERTY(meta = (BindWidget)) 41 | TObjectPtr CanvasPanel; 42 | 43 | UPROPERTY(meta = (BindWidget)) 44 | TObjectPtr Switcher; 45 | 46 | UPROPERTY(meta = (BindWidget)) 47 | TObjectPtr Grid_Equippables; 48 | 49 | UPROPERTY(meta = (BindWidget)) 50 | TObjectPtr Grid_Consumables; 51 | 52 | UPROPERTY(meta = (BindWidget)) 53 | TObjectPtr Grid_Craftables; 54 | 55 | UPROPERTY(meta = (BindWidget)) 56 | TObjectPtr Button_Equippables; 57 | 58 | UPROPERTY(meta = (BindWidget)) 59 | TObjectPtr Button_Consumables; 60 | 61 | UPROPERTY(meta = (BindWidget)) 62 | TObjectPtr Button_Craftables; 63 | 64 | UPROPERTY(EditAnywhere, Category = "Inventory") 65 | TSubclassOf ItemDescriptionClass; 66 | 67 | UPROPERTY() 68 | TObjectPtr ItemDescription; 69 | 70 | UPROPERTY(EditAnywhere, Category = "Inventory") 71 | TSubclassOf EquippedItemDescriptionClass; 72 | 73 | UPROPERTY() 74 | TObjectPtr EquippedItemDescription; 75 | 76 | FTimerHandle DescriptionTimer; 77 | FTimerHandle EquippedDescriptionTimer; 78 | 79 | UFUNCTION() 80 | void ShowEquippedItemDescription(UInv_InventoryItem* Item); 81 | 82 | UPROPERTY(EditAnywhere, Category = "Inventory") 83 | float DescriptionTimerDelay = 0.5f; 84 | 85 | UPROPERTY(EditAnywhere, Category = "Inventory") 86 | float EquippedDescriptionTimerDelay = 0.5f; 87 | 88 | UInv_ItemDescription* GetItemDescription(); 89 | UInv_ItemDescription* GetEquippedItemDescription(); 90 | 91 | UFUNCTION() 92 | void ShowEquippables(); 93 | 94 | UFUNCTION() 95 | void ShowConsumables(); 96 | 97 | UFUNCTION() 98 | void ShowCraftables(); 99 | 100 | UFUNCTION() 101 | void EquippedGridSlotClicked(UInv_EquippedGridSlot* EquippedGridSlot, const FGameplayTag& EquipmentTypeTag); 102 | 103 | UFUNCTION() 104 | void EquippedSlottedItemClicked(UInv_EquippedSlottedItem* EquippedSlottedItem); 105 | 106 | void DisableButton(UButton* Button); 107 | void SetActiveGrid(UInv_InventoryGrid* Grid, UButton* Button); 108 | void SetItemDescriptionSizeAndPosition(UInv_ItemDescription* Description, UCanvasPanel* Canvas) const; 109 | void SetEquippedItemDescriptionSizeAndPosition(UInv_ItemDescription* Description, UInv_ItemDescription* EquippedDescription, UCanvasPanel* Canvas) const; 110 | bool CanEquipHoverItem(UInv_EquippedGridSlot* EquippedGridSlot, const FGameplayTag& EquipmentTypeTag) const; 111 | UInv_EquippedGridSlot* FindSlotWithEquippedItem(UInv_InventoryItem* EquippedItem) const; 112 | void ClearSlotOfItem(UInv_EquippedGridSlot* EquippedGridSlot); 113 | void RemoveEquippedSlottedItem(UInv_EquippedSlottedItem* EquippedSlottedItem); 114 | void MakeEquippedSlottedItem(UInv_EquippedSlottedItem* EquippedSlottedItem, UInv_EquippedGridSlot* EquippedGridSlot, UInv_InventoryItem* ItemToEquip); 115 | void BroadcastSlotClickedDelegates(UInv_InventoryItem* ItemToEquip, UInv_InventoryItem* ItemToUnequip) const; 116 | 117 | TWeakObjectPtr ActiveGrid; 118 | }; 119 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/ItemDescription/Inv_ItemDescription.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Widgets/Composite/Inv_Composite.h" 7 | 8 | #include "Inv_ItemDescription.generated.h" 9 | 10 | /** 11 | * 12 | */ 13 | class USizeBox; 14 | UCLASS() 15 | class INVENTORY_API UInv_ItemDescription : public UInv_Composite 16 | { 17 | GENERATED_BODY() 18 | 19 | public: 20 | 21 | FVector2D GetBoxSize() const; 22 | virtual void SetVisibility(ESlateVisibility InVisibility) override; 23 | 24 | private: 25 | 26 | UPROPERTY(meta = (BindWidget)) 27 | TObjectPtr SizeBox; 28 | }; 29 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/ItemPopUp/Inv_ItemPopUp.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Blueprint/UserWidget.h" 7 | #include "Inv_ItemPopUp.generated.h" 8 | 9 | /** 10 | * The item popup widget shows up when right-clicking on an item 11 | * in the inventory grid. 12 | */ 13 | class UButton; 14 | class USlider; 15 | class UTextBlock; 16 | class USizeBox; 17 | 18 | DECLARE_DYNAMIC_DELEGATE_TwoParams(FPopUpMenuSplit, int32, SplitAmount, int32, Index); 19 | DECLARE_DYNAMIC_DELEGATE_OneParam(FPopUpMenuDrop, int32, Index); 20 | DECLARE_DYNAMIC_DELEGATE_OneParam(FPopUpMenuConsume, int32, Index); 21 | 22 | UCLASS() 23 | class INVENTORY_API UInv_ItemPopUp : public UUserWidget 24 | { 25 | GENERATED_BODY() 26 | public: 27 | virtual void NativeOnInitialized() override; 28 | virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override; 29 | 30 | FPopUpMenuSplit OnSplit; 31 | FPopUpMenuDrop OnDrop; 32 | FPopUpMenuConsume OnConsume; 33 | 34 | int32 GetSplitAmount() const; 35 | void CollapseSplitButton() const; 36 | void CollapseConsumeButton() const; 37 | void SetSliderParams(const float Max, const float Value) const; 38 | FVector2D GetBoxSize() const; 39 | void SetGridIndex(int32 Index) { GridIndex = Index; } 40 | int32 GetGridIndex() const { return GridIndex; } 41 | 42 | private: 43 | 44 | UPROPERTY(meta = (BindWidget)) 45 | TObjectPtr Button_Split; 46 | 47 | UPROPERTY(meta = (BindWidget)) 48 | TObjectPtr Button_Drop; 49 | 50 | UPROPERTY(meta = (BindWidget)) 51 | TObjectPtr Button_Consume; 52 | 53 | UPROPERTY(meta = (BindWidget)) 54 | TObjectPtr Slider_Split; 55 | 56 | UPROPERTY(meta = (BindWidget)) 57 | TObjectPtr Text_SplitAmount; 58 | 59 | UPROPERTY(meta = (BindWidget)) 60 | TObjectPtr SizeBox_Root; 61 | 62 | int32 GridIndex{INDEX_NONE}; 63 | 64 | UFUNCTION() 65 | void SplitButtonClicked(); 66 | 67 | UFUNCTION() 68 | void DropButtonClicked(); 69 | 70 | UFUNCTION() 71 | void ConsumeButtonClicked(); 72 | 73 | UFUNCTION() 74 | void SliderValueChanged(float Value); 75 | 76 | }; 77 | -------------------------------------------------------------------------------- /Plugins/Inventory/Source/Inventory/Public/Widgets/Utils/Inv_WidgetUtils.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Kismet/BlueprintFunctionLibrary.h" 7 | #include "Inv_WidgetUtils.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class INVENTORY_API UInv_WidgetUtils : public UBlueprintFunctionLibrary 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | 19 | UFUNCTION(BlueprintCallable, Category = "Inventory") 20 | static FVector2D GetWidgetPosition(UWidget* Widget); 21 | 22 | UFUNCTION(BlueprintCallable, Category = "Inventory") 23 | static FVector2D GetWidgetSize(UWidget* Widget); 24 | 25 | UFUNCTION(BlueprintCallable, Category = "Inventory") 26 | static bool IsWithinBounds(const FVector2D& BoundaryPos, const FVector2D& WidgetSize, const FVector2D& MousePos); 27 | 28 | static FVector2D GetClampedWidgetPosition(const FVector2D& Boundary, const FVector2D& WidgetSize, const FVector2D& MousePos); 29 | 30 | static int32 GetIndexFromPosition(const FIntPoint& Position, const int32 Columns); 31 | static FIntPoint GetPositionFromIndex(const int32 Index, const int32 Columns); 32 | }; 33 | -------------------------------------------------------------------------------- /Source/InventoryProject.Target.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class InventoryProjectTarget : TargetRules 7 | { 8 | public InventoryProjectTarget(TargetInfo Target) : base(Target) 9 | { 10 | Type = TargetType.Game; 11 | DefaultBuildSettings = BuildSettingsVersion.V5; 12 | IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_5; 13 | ExtraModuleNames.Add("InventoryProject"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProject.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class InventoryProject : ModuleRules 6 | { 7 | public InventoryProject(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" }); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProject.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "InventoryProject.h" 4 | #include "Modules/ModuleManager.h" 5 | 6 | IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, InventoryProject, "InventoryProject" ); 7 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProject.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProjectCharacter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "InventoryProjectCharacter.h" 4 | #include "Engine/LocalPlayer.h" 5 | #include "Camera/CameraComponent.h" 6 | #include "Components/CapsuleComponent.h" 7 | #include "GameFramework/CharacterMovementComponent.h" 8 | #include "GameFramework/SpringArmComponent.h" 9 | #include "GameFramework/Controller.h" 10 | #include "EnhancedInputComponent.h" 11 | #include "EnhancedInputSubsystems.h" 12 | #include "InputActionValue.h" 13 | 14 | DEFINE_LOG_CATEGORY(LogTemplateCharacter); 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | // AInventoryProjectCharacter 18 | 19 | AInventoryProjectCharacter::AInventoryProjectCharacter() 20 | { 21 | // Set size for collision capsule 22 | GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); 23 | 24 | // Don't rotate when the controller rotates. Let that just affect the camera. 25 | bUseControllerRotationPitch = false; 26 | bUseControllerRotationYaw = false; 27 | bUseControllerRotationRoll = false; 28 | 29 | // Configure character movement 30 | GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input... 31 | GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate 32 | 33 | // Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint 34 | // instead of recompiling to adjust them 35 | GetCharacterMovement()->JumpZVelocity = 700.f; 36 | GetCharacterMovement()->AirControl = 0.35f; 37 | GetCharacterMovement()->MaxWalkSpeed = 500.f; 38 | GetCharacterMovement()->MinAnalogWalkSpeed = 20.f; 39 | GetCharacterMovement()->BrakingDecelerationWalking = 2000.f; 40 | GetCharacterMovement()->BrakingDecelerationFalling = 1500.0f; 41 | 42 | // Create a camera boom (pulls in towards the player if there is a collision) 43 | CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom")); 44 | CameraBoom->SetupAttachment(RootComponent); 45 | CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character 46 | CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller 47 | 48 | // Create a follow camera 49 | FollowCamera = CreateDefaultSubobject(TEXT("FollowCamera")); 50 | FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation 51 | FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm 52 | 53 | // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 54 | // are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++) 55 | } 56 | 57 | ////////////////////////////////////////////////////////////////////////// 58 | // Input 59 | 60 | void AInventoryProjectCharacter::NotifyControllerChanged() 61 | { 62 | Super::NotifyControllerChanged(); 63 | 64 | // Add Input Mapping Context 65 | if (APlayerController* PlayerController = Cast(Controller)) 66 | { 67 | if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) 68 | { 69 | Subsystem->AddMappingContext(DefaultMappingContext, 0); 70 | } 71 | } 72 | } 73 | 74 | void AInventoryProjectCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) 75 | { 76 | // Set up action bindings 77 | if (UEnhancedInputComponent* EnhancedInputComponent = Cast(PlayerInputComponent)) { 78 | 79 | // Jumping 80 | EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump); 81 | EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping); 82 | 83 | // Moving 84 | EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AInventoryProjectCharacter::Move); 85 | 86 | // Looking 87 | EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AInventoryProjectCharacter::Look); 88 | } 89 | else 90 | { 91 | UE_LOG(LogTemplateCharacter, Error, TEXT("'%s' Failed to find an Enhanced Input component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."), *GetNameSafe(this)); 92 | } 93 | } 94 | 95 | void AInventoryProjectCharacter::Move(const FInputActionValue& Value) 96 | { 97 | // input is a Vector2D 98 | FVector2D MovementVector = Value.Get(); 99 | 100 | if (Controller != nullptr) 101 | { 102 | // find out which way is forward 103 | const FRotator Rotation = Controller->GetControlRotation(); 104 | const FRotator YawRotation(0, Rotation.Yaw, 0); 105 | 106 | // get forward vector 107 | const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); 108 | 109 | // get right vector 110 | const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); 111 | 112 | // add movement 113 | AddMovementInput(ForwardDirection, MovementVector.Y); 114 | AddMovementInput(RightDirection, MovementVector.X); 115 | } 116 | } 117 | 118 | void AInventoryProjectCharacter::Look(const FInputActionValue& Value) 119 | { 120 | // input is a Vector2D 121 | FVector2D LookAxisVector = Value.Get(); 122 | 123 | if (Controller != nullptr) 124 | { 125 | // add yaw and pitch input to controller 126 | AddControllerYawInput(LookAxisVector.X); 127 | AddControllerPitchInput(LookAxisVector.Y); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProjectCharacter.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/Character.h" 7 | #include "Logging/LogMacros.h" 8 | #include "InventoryProjectCharacter.generated.h" 9 | 10 | class USpringArmComponent; 11 | class UCameraComponent; 12 | class UInputMappingContext; 13 | class UInputAction; 14 | struct FInputActionValue; 15 | 16 | DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All); 17 | 18 | UCLASS(config=Game) 19 | class AInventoryProjectCharacter : public ACharacter 20 | { 21 | GENERATED_BODY() 22 | 23 | /** Camera boom positioning the camera behind the character */ 24 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) 25 | USpringArmComponent* CameraBoom; 26 | 27 | /** Follow camera */ 28 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) 29 | UCameraComponent* FollowCamera; 30 | 31 | /** MappingContext */ 32 | UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) 33 | UInputMappingContext* DefaultMappingContext; 34 | 35 | /** Jump Input Action */ 36 | UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) 37 | UInputAction* JumpAction; 38 | 39 | /** Move Input Action */ 40 | UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) 41 | UInputAction* MoveAction; 42 | 43 | /** Look Input Action */ 44 | UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) 45 | UInputAction* LookAction; 46 | 47 | public: 48 | AInventoryProjectCharacter(); 49 | 50 | 51 | protected: 52 | 53 | /** Called for movement input */ 54 | void Move(const FInputActionValue& Value); 55 | 56 | /** Called for looking input */ 57 | void Look(const FInputActionValue& Value); 58 | 59 | 60 | protected: 61 | 62 | virtual void NotifyControllerChanged() override; 63 | 64 | virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; 65 | 66 | public: 67 | /** Returns CameraBoom subobject **/ 68 | FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } 69 | /** Returns FollowCamera subobject **/ 70 | FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; } 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProjectGameMode.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "InventoryProjectGameMode.h" 4 | #include "InventoryProjectCharacter.h" 5 | #include "UObject/ConstructorHelpers.h" 6 | 7 | AInventoryProjectGameMode::AInventoryProjectGameMode() 8 | { 9 | // set default pawn class to our Blueprinted character 10 | static ConstructorHelpers::FClassFinder PlayerPawnBPClass(TEXT("/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter")); 11 | if (PlayerPawnBPClass.Class != NULL) 12 | { 13 | DefaultPawnClass = PlayerPawnBPClass.Class; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/InventoryProject/InventoryProjectGameMode.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/GameModeBase.h" 7 | #include "InventoryProjectGameMode.generated.h" 8 | 9 | UCLASS(minimalapi) 10 | class AInventoryProjectGameMode : public AGameModeBase 11 | { 12 | GENERATED_BODY() 13 | 14 | public: 15 | AInventoryProjectGameMode(); 16 | }; 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Source/InventoryProjectEditor.Target.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class InventoryProjectEditorTarget : TargetRules 7 | { 8 | public InventoryProjectEditorTarget(TargetInfo Target) : base(Target) 9 | { 10 | Type = TargetType.Editor; 11 | DefaultBuildSettings = BuildSettingsVersion.V5; 12 | IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_5; 13 | ExtraModuleNames.Add("InventoryProject"); 14 | } 15 | } 16 | --------------------------------------------------------------------------------