(Feat) Add Craft Systeme
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "InventoryScreenWidget.h"
|
||||
|
||||
#include "Components/Button.h"
|
||||
#include "Components/WidgetSwitcher.h"
|
||||
#include "CraftingWidget.h"
|
||||
#include "FpsPlayer.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "InventoryDragDropOperation.h"
|
||||
#include "InventoryWidget.h"
|
||||
|
||||
void UInventoryScreenWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
if (InventoryTabButton)
|
||||
{
|
||||
InventoryTabButton->OnClicked.AddDynamic(this, &UInventoryScreenWidget::HandleInventoryTabClicked);
|
||||
}
|
||||
|
||||
if (CraftingTabButton)
|
||||
{
|
||||
CraftingTabButton->OnClicked.AddDynamic(this, &UInventoryScreenWidget::HandleCraftingTabClicked);
|
||||
}
|
||||
|
||||
ShowInventoryTab();
|
||||
}
|
||||
|
||||
void UInventoryScreenWidget::BindToOwningPawn()
|
||||
{
|
||||
if (InventoryPage)
|
||||
{
|
||||
InventoryPage->BindToOwningPawn();
|
||||
}
|
||||
|
||||
if (CraftingPage)
|
||||
{
|
||||
CraftingPage->BindToOwningPawn();
|
||||
}
|
||||
}
|
||||
|
||||
bool UInventoryScreenWidget::IsInventoryTabActive() const
|
||||
{
|
||||
return TabSwitcher && InventoryPage && TabSwitcher->GetActiveWidget() == InventoryPage;
|
||||
}
|
||||
|
||||
int32 UInventoryScreenWidget::GetHoveredSlotIndex() const
|
||||
{
|
||||
if (!InventoryPage || !IsInventoryTabActive())
|
||||
{
|
||||
return INDEX_NONE;
|
||||
}
|
||||
|
||||
return InventoryPage->GetHoveredSlotIndex();
|
||||
}
|
||||
|
||||
void UInventoryScreenWidget::ShowInventoryTab()
|
||||
{
|
||||
ShowPage(InventoryPage);
|
||||
}
|
||||
|
||||
void UInventoryScreenWidget::ShowCraftingTab()
|
||||
{
|
||||
ShowPage(CraftingPage);
|
||||
}
|
||||
|
||||
void UInventoryScreenWidget::HandleInventoryTabClicked()
|
||||
{
|
||||
ShowPage(InventoryPage);
|
||||
}
|
||||
|
||||
void UInventoryScreenWidget::HandleCraftingTabClicked()
|
||||
{
|
||||
ShowPage(CraftingPage);
|
||||
}
|
||||
|
||||
void UInventoryScreenWidget::ShowPage(UWidget* Page)
|
||||
{
|
||||
if (!TabSwitcher || !Page)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TabSwitcher->SetActiveWidget(Page);
|
||||
|
||||
// Le bouton de l'onglet courant est desactive : il sert d'indicateur de
|
||||
// position autant que de garde-fou contre un clic sans effet.
|
||||
const bool bInventoryActive = (Page == InventoryPage);
|
||||
|
||||
if (InventoryTabButton)
|
||||
{
|
||||
InventoryTabButton->SetIsEnabled(!bInventoryActive);
|
||||
}
|
||||
|
||||
if (CraftingTabButton)
|
||||
{
|
||||
CraftingTabButton->SetIsEnabled(bInventoryActive);
|
||||
}
|
||||
|
||||
OnTabChanged.Broadcast(bInventoryActive);
|
||||
}
|
||||
|
||||
bool UInventoryScreenWidget::NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent, UDragDropOperation* InOperation)
|
||||
{
|
||||
Super::NativeOnDrop(InGeometry, InDragDropEvent, InOperation);
|
||||
|
||||
// On n'arrive ici que si ni une case ni la page d'inventaire n'ont traite le
|
||||
// depot : les enfants sont consultes en premier et arretent la propagation.
|
||||
const UInventoryDragDropOperation* Payload = Cast<UInventoryDragDropOperation>(InOperation);
|
||||
if (!Payload || Payload->SourceSlotIndex == INDEX_NONE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (const APlayerController* OwningController = GetOwningPlayer())
|
||||
{
|
||||
if (AFpsPlayer* PlayerPawn = Cast<AFpsPlayer>(OwningController->GetPawn()))
|
||||
{
|
||||
PlayerPawn->DropSlot(Payload->SourceSlotIndex, Payload->Quantity);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user