Unreal - 인벤토리(4) ( 정렬, 삭제 )

2025. 11. 26. 01:17·Unreal 프로젝트 다이어리/두번째 프로젝트

이전 글에서 이어집니다

2025.11.25 - [Unreal 프로젝트 다이어리/두번째 프로젝트] - Unreal - 인벤토리 (드래그 앤 드롭)

 

Unreal - 인벤토리 (드래그 앤 드롭)

이전 글에서 이어집니다2025.11.23 - [Unreal 프로젝트 다이어리/두번째 프로젝트] - Unreal - 인벤토리 ( 아이템 추가하기 ) Unreal - 인벤토리 ( 아이템 추가하기 )이전글에서 이어집니다2025.11.22 - [Unreal

lucodev.tistory.com

 

 

 

구현한 내용

  • 아이템 정렬 (아이템 번호순)
  • 아이템 삭제 

 

아이템 정렬

아이템 정렬입니다

원래 compare a , b 해야하는데 람다식을 사용하여 줄이고

빈슬롯을 뒤로 보낸뒤 앞에서부터 아이템 ID가 낮은 순서대로 정렬하도록 하였습니다

void UInventoryComponent::SortItemID()
{
	//빈 슬롯을 뒤로 보내고 실제 아이템만 오름차순 정렬
	//Alpha가 빈 슬롯이면 뒤로 Beta가 빈 슬롯이면 Alpha가 앞으로 
	items.Sort([](const FItemSlot& alphaSlot, const FItemSlot& betaSlot)
		{
			//빈슬롯 뒤로 보내기
			if (alphaSlot.isEmpty())
				return false; 
			if (betaSlot.isEmpty())
				return true;  
			return alphaSlot.itemID < betaSlot.itemID; //(오름차순)
		});

	for (int32 i = 0; i < items.Num(); i++)
	{
		onInventoryUpdated.Broadcast(i, items[i]);
	}
}

 

아이템 삭제

삭제의 기능은 역시 두뇌인 InventoryComponent 내에서 구현해두었습니다

bool UInventoryComponent::RemoveItem(int32 slotIndex, int32 count)
{
	if (!items.IsValidIndex(slotIndex))
		return false;

	FItemSlot& slot = items[slotIndex];

	if (slot.isEmpty())
		return false;

	slot.inCount -= count;

	if (slot.inCount <= 0)
	{
		slot.Clear();
	}
	onInventoryUpdated.Broadcast(slotIndex, slot);
	return true;

}

 

인벤토리 위젯에서 드랍 이벤트를 발생시키기위해 해당 함수를 오버라이드하였습니다

virtual bool NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& inDragDropEvent, UDragDropOperation* inOperation) override;

 

DeleteButton위에 드롭이벤트가 발생한다면 RemoveItem함수를 호출하여 전부 Clear 하도록 하였습니다

bool UInventoryWidget::NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& inDragDropEvent, UDragDropOperation* inOperation)
{
	if (!Button_DeleteItem || !inventoryComp)
		return false;

	UInventoryDragDropOper* dragOper = Cast<UInventoryDragDropOper>(inOperation);
	if (!dragOper)
		return false;

	FVector2D mousePos = inDragDropEvent.GetScreenSpacePosition();
	if (Button_DeleteItem->GetCachedGeometry().IsUnderLocation(mousePos))
	{
		int32 slotIdx = dragOper->startSlotIdx;
		FItemSlot slot = inventoryComp->GetItemSlot(slotIdx);
		if (!slot.isEmpty())
			inventoryComp->RemoveItem(slotIdx, slot.inCount);
		return true;
	}
	return false;

}

 

결과

정렬

 

삭제

 

 

 

 

저작자표시 비영리 변경금지 (새창열림)

'Unreal 프로젝트 다이어리 > 두번째 프로젝트' 카테고리의 다른 글

Unreal - 인벤토리(5-2) (UI 디테일 추가)  (0) 2025.11.29
Unreal - 인벤토리(5) ( 아이템 정보 )  (0) 2025.11.28
Unreal - 인벤토리(3) (드래그 앤 드롭)  (0) 2025.11.25
Unreal - 인벤토리(2) ( 아이템 추가하기 )  (0) 2025.11.23
Unreal - 인벤토리(1) ( 크기변경하기, 창옮기기 )  (2) 2025.11.22
'Unreal 프로젝트 다이어리/두번째 프로젝트' 카테고리의 다른 글
  • Unreal - 인벤토리(5-2) (UI 디테일 추가)
  • Unreal - 인벤토리(5) ( 아이템 정보 )
  • Unreal - 인벤토리(3) (드래그 앤 드롭)
  • Unreal - 인벤토리(2) ( 아이템 추가하기 )
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (211) N
      • Unreal 프로젝트 다이어리 (108) N
        • 첫번째 프로젝트 (73)
        • 두번째 프로젝트 (35) N
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 (52)
        • Stack,Queue (7)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (7)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (14)
      • C++ 백준 (4)
      • C++ 팁 (1)
      • 개인 코테 & 스타디 <비공개> (29)
        • 코드 개인보관함 (9)
        • 코딩테스트+@ (11)
        • 알고리즘 스타디 (6)
        • 알고리즘 스타디 과제 (3)
        • 비공개 (0)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    unreal 시퀀스
    언리얼 프로그래스바
    unreal 모션매칭
    언리얼 behavior tree
    언리얼 behaviortree
    언리얼 모션매칭
    언리얼 파쿠르
    unreal 인벤토리
    언리얼 parkour
    언리얼 motionmatching
    언리얼 시퀀스
    Unreal Parkour
    언리얼 ui
    unreal 파쿠르
    언리얼 인벤토리
    언리얼 상호작용
    언리얼 비헤이비어트리
    언리얼 컷씬
    unreal inventory
    언리얼
  • hELLO· Designed By정상우.v4.10.3
lucodev
Unreal - 인벤토리(4) ( 정렬, 삭제 )
상단으로

티스토리툴바