Skip to content

Commit

Permalink
Finally made everything working from tooltip to drag visual, this com…
Browse files Browse the repository at this point in the history
…mit is with the custom tooltip and dragvisual code
  • Loading branch information
SrujanLokhande committed Sep 24, 2024
1 parent d06ae01 commit 334c5f1
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 204 deletions.
33 changes: 31 additions & 2 deletions .idea/.idea.InventorySystem/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ ManualIPAddress=
+PropertyRedirects=(OldName="/Script/InventorySystem.InteractionWidget.InteractionProgressBar",NewName="/Script/InventorySystem.InteractionWidget.BAR_InteractionProgressBar")
+PropertyRedirects=(OldName="/Script/InventorySystem.InventoryTooltip.TXT_StackSizeText",NewName="/Script/InventorySystem.InventoryTooltip.TXT_MaxStackSize")
+PropertyRedirects=(OldName="/Script/InventorySystem.InventoryWidget.InventoryPanel",NewName="/Script/InventorySystem.InventoryWidget.InventoryWrapBox")
+PropertyRedirects=(OldName="/Script/InventorySystem.Tablet.InventoryWidget",NewName="/Script/InventorySystem.Tablet.InventoryWidgetComponent")
+PropertyRedirects=(OldName="/Script/InventorySystem.Tablet.DragItemVisualWidget",NewName="/Script/InventorySystem.Tablet.DragVisualClass")
+PropertyRedirects=(OldName="/Script/InventorySystem.Tablet.DragVisualWidget",NewName="/Script/InventorySystem.Tablet.DragVisualComponent")
+PropertyRedirects=(OldName="/Script/InventorySystem.Tablet.InventoryWidget",NewName="/Script/InventorySystem.Tablet.InventoryWidgetClass")

[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/InventorySystem/ThirdPerson/Maps/LVL_MainMap.LVL_MainMap
Expand Down
Binary file modified Content/InventorySystem/Blueprints/BP_Tablet.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/InventorySystem/UI/WBP_DragItemVisual.uasset
Binary file not shown.
Binary file modified Content/InventorySystem/UI/WBP_InventoryWidget.uasset
Binary file not shown.
Binary file modified Content/InventorySystem/UI/WBP_MainMenuWidget.uasset
Binary file not shown.
3 changes: 0 additions & 3 deletions Source/InventorySystem/InventorySystemCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ class AInventorySystemCharacter : public ACharacter
void WidgetInteractPressed();
void WidgetInteractReleased();

// UI related functions for tooltip and the drag visual
void CreateUIWidgets();

virtual void Tick(float DeltaSeconds) override;

/** Called for movement input */
Expand Down
110 changes: 97 additions & 13 deletions Source/InventorySystem/Private/Actors/Tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,113 @@
#include "Actors/Tablet.h"

#include "Components/WidgetComponent.h"

#include "Kismet/GameplayStatics.h"
#include "UserInterface/MainMenuWidget.h"
#include "UserInterface/Inventory/DragItemVisual.h"
#include "UserInterface/Inventory/InventoryWidget.h"

// Sets default values
ATablet::ATablet()
{
PrimaryActorTick.bCanEverTick = false;
PrimaryActorTick.bCanEverTick = true;

TabletMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Tablet Mesh"));
SetRootComponent(TabletMesh);

TabletMesh->SetCollisionEnabled(ECollisionEnabled::Type::QueryOnly);

InventoryWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("Tablet Widget"));
InventoryWidget->SetupAttachment(RootComponent);
InventoryWidget->SetDrawAtDesiredSize(true);
InventoryWidget->SetWidgetSpace(EWidgetSpace::World);
InventoryWidget->SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
InventoryWidgetComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("Tablet Widget"));
InventoryWidgetComponent->SetupAttachment(RootComponent);
InventoryWidgetComponent->SetDrawAtDesiredSize(true);
InventoryWidgetComponent->SetWidgetSpace(EWidgetSpace::World);
InventoryWidgetComponent->SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);

// DragVisualComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("Drag Visual Widget"));
// DragVisualComponent->SetupAttachment(RootComponent);
// //DragVisualComponent->SetVisibility(false);
// DragVisualComponent->SetDrawAtDesiredSize(true);
// DragVisualComponent->SetWidgetSpace(EWidgetSpace::World);
// DragVisualComponent->SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
}

// Called when the game starts or when spawned
void ATablet::BeginPlay()
{
Super::BeginPlay();

}
// void ATablet::BeginPlay()
// {
// Super::BeginPlay();
//
// if (InventoryWidgetComponent)
// {
// MainMenuWidgetClass = Cast<UMainMenuWidget>(InventoryWidgetComponent->GetUserWidgetObject());
// if (MainMenuWidgetClass)
// {
// InventoryWidgetClass = MainMenuWidgetClass->GetInventoryWidgetClass();
// InventoryWidgetClass->SetTabletReference(this);
// UE_LOG(LogTemp, Log, TEXT("Tablet: InventoryWidget found and TabletReference set"));
// }
// else
// {
// UE_LOG(LogTemp, Error, TEXT("Tablet: Failed to cast UserWidget to InventoryWidget"));
// }
// }
//
// if (DragVisualComponent)
// {
// DragVisualClass = Cast<UDragItemVisual>(DragVisualComponent->GetUserWidgetObject());
// }
// }
//
// void ATablet::Tick(float DeltaSeconds)
// {
// Super::Tick(DeltaSeconds);
//
// if (DragVisualComponent->IsVisible())
// {
// UpdateDragVisualPosition();
// }
// }
//
// void ATablet::UpdateDragVisualPosition() const
// {
// if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0))
// {
// if (FVector2D MousePosition; PlayerController->GetMousePosition(MousePosition.X, MousePosition.Y))
// {
// FVector WorldDirection;
// if (FVector WorldPosition; UGameplayStatics::DeprojectScreenToWorld(PlayerController, MousePosition, WorldPosition, WorldDirection))
// {
// FVector Start = WorldPosition;
// FVector End = WorldPosition + WorldDirection * 1000.0f;
//
// FHitResult HitResult;
// FCollisionQueryParams QueryParams;
// QueryParams.AddIgnoredActor(this);
//
// if (GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Visibility, QueryParams))
// {
// DragVisualComponent->SetWorldLocation(HitResult.Location);
// DragVisualComponent->SetWorldRotation(HitResult.Normal.Rotation());
// }
// }
// }
// }
// }
//
// void ATablet::StartItemDrag(UItemBase* ItemToDrag)
// {
// if (DragVisualClass && ItemToDrag)
// {
// DragVisualClass->SetItemReference(ItemToDrag);
// DragVisualComponent->SetVisibility(true);
//
// }
// }
//
// void ATablet::EndItemDrag()
// {
// if (DragVisualComponent)
// {
// DragVisualComponent->SetVisibility(false);
// }
// }



Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,55 @@
#include "Components/Image.h"
#include "Components/TextBlock.h"

// void UDragItemVisual::UpdateToolTipContents(UItemBase* ItemIn)
// void UDragItemVisual::NativeConstruct()
// {
// IMG_ItemIcon->SetBrushFromTexture(ItemIn->AssetData.Icon);
// //ItemBorder->SetBrushColor(ItemIn->);
// TXT_ItemQuantity->SetText(FText::AsNumber(ItemIn->ItemQuantity));
// Super::NativeConstruct();
//
// // checking if the item is not stackable then don't show the item quantity
// if (!ItemIn->NumericData.bIsStackable)
// SetVisibility(ESlateVisibility::HitTestInvisible);
// SetColorAndOpacity(FLinearColor(1, 1, 1, 1));
// }
//
// void UDragItemVisual::SetItemReference(UItemBase* ItemIn) const
// {
// if (ItemIn && IMG_ItemIcon)
// {
// TXT_ItemQuantity->SetVisibility(ESlateVisibility::Collapsed);
// }}
// IMG_ItemIcon->SetBrushFromTexture(ItemIn->AssetData.Icon);
//
// if (ItemBorder)
// {
// // Set border color based on item rarity
// switch (ItemIn->ItemRarity)
// {
// case EItemRarity::Common:
// ItemBorder->SetBrushColor(FLinearColor::White);
// break;
// case EItemRarity::Rare:
// ItemBorder->SetBrushColor(FLinearColor::Blue);
// break;
// case EItemRarity::Epic:
// ItemBorder->SetBrushColor(FLinearColor::Red);
// break;
// case EItemRarity::Legendary:
// ItemBorder->SetBrushColor(FLinearColor::Yellow);
// break;
// default:
// ItemBorder->SetBrushColor(FLinearColor::White);
// }
// }
//
// if (TXT_ItemQuantity)
// {
// if (ItemIn->NumericData.bIsStackable)
// {
// TXT_ItemQuantity->SetText(FText::AsNumber(ItemIn->ItemQuantity));
// TXT_ItemQuantity->SetVisibility(ESlateVisibility::Visible);
// }
// else
// {
// TXT_ItemQuantity->SetVisibility(ESlateVisibility::Collapsed);
// }
// }
// }
// }


Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,25 @@
#include "UserInterface/Inventory/DragItemVisual.h"
#include "UserInterface/Inventory/ItemDragDropOperation.h"
#include "Blueprint/WidgetBlueprintLibrary.h"


#include "UserInterface/Inventory/InventoryTooltip.h"

void UInventoryItemSlot::NativeOnInitialized()
{
Super::NativeOnInitialized();

// if(ToolTipClass)
// {
// //ToolTipUI->InventorySlotBeingHovered = this;
//
// // ToolTipUI = CreateWidget<UInventoryTooltip>(this, ToolTipClass);
// // ToolTipUI->AddToViewport(10);
// // ToolTipUI->SetVisibility(ESlateVisibility::Collapsed);
// // SetToolTip(ToolTipUI);
// }
if(ToolTipClass)
{
UInventoryTooltip* Tooltip = CreateWidget<UInventoryTooltip>(this, ToolTipClass);
Tooltip->InventorySlotBeingHovered = this;
//ToolTipUI->AddToViewport(10);
//ToolTipUI->SetVisibility(ESlateVisibility::Collapsed);
SetToolTip(Tooltip);
}
}

void UInventoryItemSlot::NativeConstruct()
{
Super::NativeConstruct();
Super::NativeConstruct();

// changing the color of the image border based on the rarity
if(ItemReference)
Expand Down Expand Up @@ -64,6 +62,18 @@ void UInventoryItemSlot::NativeConstruct()
}
}

// void UInventoryItemSlot::SetItemReference(UItemBase* Item)
// {
// ItemReference = Item;
// UpdateSlotVisual();
// }


// void UInventoryItemSlot::SetTabletReference(ATablet* Tablet)
// {
// TabletReference = Tablet;
// }

FReply UInventoryItemSlot::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
FReply Reply = Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
Expand All @@ -83,25 +93,24 @@ FReply UInventoryItemSlot::NativeOnMouseButtonDown(const FGeometry& InGeometry,
void UInventoryItemSlot::NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent,
UDragDropOperation*& OutOperation)
{
Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);

if (!DragItemVisualClass || !ItemReference) return;
Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);

// for dragging the item actor
if(DragItemVisualClass)
{

const TObjectPtr<UDragItemVisual> DragVisual = CreateWidget<UDragItemVisual>(this, DragItemVisualClass);

DragVisual->IMG_ItemIcon->SetBrushFromTexture(ItemReference->AssetData.Icon);
DragVisual->ItemBorder->SetBrushColor(ItemBorder->GetBrushColor());
DragVisual->TXT_ItemQuantity->SetText(FText::AsNumber(ItemReference->ItemQuantity));

// checking if the item is not stackable then dont show the item quantity
DragVisual->TXT_ItemQuantity->SetText(FText::AsNumber(ItemReference->ItemQuantity));
//
// // checking if the item is not stackable then don't show the item quantity
ItemReference->NumericData.bIsStackable
? DragVisual->TXT_ItemQuantity->SetText(FText::AsNumber(ItemReference->ItemQuantity))
: DragVisual->TXT_ItemQuantity->SetVisibility(ESlateVisibility::Collapsed);

//

//TabletReference->StartItemDrag(ItemReference);

UItemDragDropOperation* DragItemOperation = NewObject<UItemDragDropOperation>();
DragItemOperation->SourceItem = ItemReference;
Expand All @@ -115,16 +124,26 @@ void UInventoryItemSlot::NativeOnDragDetected(const FGeometry& InGeometry, const
}
}

void UInventoryItemSlot::NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
Super::NativeOnMouseEnter(InGeometry, InMouseEvent);
OnMouseEnterDelegate.Broadcast(this);
}
// void UInventoryItemSlot::NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
// {
// Super::NativeOnMouseEnter(InGeometry, InMouseEvent);
// OnMouseEnterDelegate.Broadcast(this);
// }

// void UInventoryItemSlot::NativeOnDragCancelled(const FDragDropEvent& InDragDropEvent, UDragDropOperation* InOperation)
// {
// Super::NativeOnDragCancelled(InDragDropEvent, InOperation);
//
// if (TabletReference)
// {
// TabletReference->EndItemDrag();
// }
// }

void UInventoryItemSlot::NativeOnMouseLeave(const FPointerEvent& InMouseEvent)
{
Super::NativeOnMouseLeave(InMouseEvent);
OnMouseLeaveDelegate.Broadcast(this);
//OnMouseLeaveDelegate.Broadcast(this);
}

bool UInventoryItemSlot::NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent,
Expand Down
Loading

0 comments on commit 334c5f1

Please sign in to comment.