Skip to content

Commit

Permalink
Inventory Refactoring
Browse files Browse the repository at this point in the history
Refactoring Inventory Component ( #98 ) and Inventory Settings ( #167 )
  • Loading branch information
pavlicekdominik committed Nov 17, 2023
1 parent 50743a0 commit fd4b2ac
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,22 @@ void UMounteaInventoryComponent::PostItemUpdated_Implementation(const FInventory
}
}

void UMounteaInventoryComponent::RequestInventoryNotification(const FInventoryUpdateResult& UpdateContext) const
{
const UMounteaInventoryEquipmentSettings* Settings = GetDefault<UMounteaInventoryEquipmentSettings>();
FInventoryNotificationData Data = *Settings->InventoryUpdateData.Find(UpdateContext.ResultID);

if (Data.Weight >= Settings->MinDisplayWeight)
{
if (!UpdateContext.ResultText.IsEmpty())
{
Data.NotificationText = UpdateContext.ResultText;
}

IMounteaInventoryWBPInterface::Execute_CreateInventoryNotification(InventoryWBP, Data);
}
}

void UMounteaInventoryComponent::OnRep_Items()
{
if (const FItemSlot* DirtySlot = InventorySlots.FindByPredicate(
Expand Down Expand Up @@ -1069,34 +1085,6 @@ void UMounteaInventoryComponent::PostItemUpdated_Client_Implementation(const FIn
GetWorld()->GetTimerManager().SetTimer(TimerHandle_RequestItemSyncTimerHandle, TimerDelegate_RequestSyncTimerHandle, Duration_RequestSyncTimerHandle, false);
}

void UMounteaInventoryComponent::RequestInventoryNotification(const FInventoryUpdateResult& UpdateContext) const
{
const UMounteaInventoryEquipmentSettings* Settings = GetDefault<UMounteaInventoryEquipmentSettings>();

FInventoryNotificationData Data; // = *Settings->InventoryUpdateData.Find(UpdateContext.InventoryUpdateResult); BREAKING
if (Data.Weight >= Settings->MinDisplayWeight)
{
if (!UpdateContext.ResultText.IsEmpty())
{
// Data.NotificationText = UpdateContext.UpdateMessage;
}

IMounteaInventoryWBPInterface::Execute_CreateInventoryNotification(InventoryWBP, Data);
}
}

void UMounteaInventoryComponent::RequestItemNotification(const FInventoryUpdateResult& UpdateContext) const
{
const UMounteaInventoryEquipmentSettings* Settings = GetDefault<UMounteaInventoryEquipmentSettings>();
FInventoryNotificationData Data; // = *Settings->ItemUpdateData.Find(UpdateContext.ItemUpdateResult); BREAKING
if (!UpdateContext.ResultText.IsEmpty())
{
// Data.NotificationText = UpdateContext.UpdateMessage;
}

IMounteaInventoryWBPInterface::Execute_CreateInventoryNotification(InventoryWBP, Data);
}



/*===============================================================================
Expand Down Expand Up @@ -1125,7 +1113,6 @@ void UMounteaInventoryComponent::ProcessItemAction_Implementation(UMounteaInvent
Action->ProcessAction(Item);
}


void UMounteaInventoryComponent::PostInventoryUpdated_Client_RequestUpdate(const FInventoryUpdateResult& UpdateContext)
{
if (!GetOwner()) return;
Expand Down Expand Up @@ -1157,7 +1144,7 @@ void UMounteaInventoryComponent::PostItemAdded_Client_RequestUpdate(const FInven
{
InventoryWBP->ProcessMounteaWidgetCommand(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshItemsWidgets, UpdateContext.OptionalPayload);

RequestItemNotification(UpdateContext);
RequestInventoryNotification(UpdateContext);

// Item->GetItemAddedHandle().Broadcast(UpdateContext.UpdateMessage.ToString()); BREAKING
OnItemAdded_Client.Broadcast(UpdateContext);
Expand All @@ -1176,7 +1163,7 @@ void UMounteaInventoryComponent::PostItemRemoved_Client_RequestUpdate(const FInv
{
InventoryWBP->ProcessMounteaWidgetCommand(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RemoveItemWidget, UpdateContext.OptionalPayload);

RequestItemNotification(UpdateContext);
RequestInventoryNotification(UpdateContext);

// Item->GetItemRemovedHandle().Broadcast(UpdateContext.UpdateMessage.ToString()); BREAKING
OnItemRemoved_Client.Broadcast(UpdateContext);
Expand All @@ -1197,7 +1184,7 @@ void UMounteaInventoryComponent::PostItemUpdated_Client_RequestUpdate(const FInv
{
InventoryWBP->ProcessMounteaWidgetCommand(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshItemsWidgets, UpdateContext.OptionalPayload);

RequestItemNotification(UpdateContext);
RequestInventoryNotification(UpdateContext);

// Item->GetItemUpdatedHandle().Broadcast(UpdateContext.UpdateMessage.ToString()); BREAKING
OnItemUpdated_Client.Broadcast(UpdateContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,95 @@ UMounteaInventoryEquipmentSettings::UMounteaInventoryEquipmentSettings()
{
CategoryName = TEXT("Mountea Framework");
SectionName = TEXT("Mountea Inventory & Equipment");

InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::InitializeInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::CreateInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::ShowInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::HideInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshItemsWidgets);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RemoveItemWidget);

EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::InitializeEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::CreateEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::ShowEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::HideEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::RefreshEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::RefreshEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::RefreshItemsWidgets);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::UnequipItemWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::EquipItemWidget);

InventoryUpdateMessages.Add(EInventoryUpdateResult::EIUR_Success, LOCTEXT("InventoryUpdateMessages_Success", "Inventory Updated"));
InventoryUpdateMessages.Add(EInventoryUpdateResult::EIUR_Failed, LOCTEXT("InventoryUpdateMessages_Failed", "Inventory Update Failed"));

ItemsWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemCommands::AddNewItem);
ItemsWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemCommands::UpdateItem);
ItemsWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemCommands::RemoveItem);
// INVENTORY COMMANDS
{
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::InitializeInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::CreateInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::ShowInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::HideInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshInventoryWidget);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RefreshItemsWidgets);
InventoryWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::InventoryCommands::RemoveItemWidget);
}

ItemUpdateMessages.Add(EItemUpdateResult::EIUR_Success_AddItem, LOCTEXT("ItemUpdateMessages_SuccessAdd", "Success - Add Item"));
ItemUpdateMessages.Add(EItemUpdateResult::EIUR_Success_UpdateItem, LOCTEXT("ItemUpdateMessages_SuccessUpdate", "Success - Update Item"));
ItemUpdateMessages.Add(EItemUpdateResult::EIUR_Success_RemovedItem, LOCTEXT("InventoryUpdateMessages_RemovedItem", "Success - Removed Item"));
ItemUpdateMessages.Add(EItemUpdateResult::EIUR_Success_SomeAdd, LOCTEXT("InventoryUpdateMessages_SomeAddItem", "Success - Partially Added"));
ItemUpdateMessages.Add(EItemUpdateResult::EIUR_Failed_InvalidItem, LOCTEXT("InventoryUpdateMessages_InvalidItem", "Failed - Invalid Item"));
ItemUpdateMessages.Add(EItemUpdateResult::EIUR_Failed_LimitReached, LOCTEXT("InventoryUpdateMessages_InvalidItem", "Failed - Max Quantity"));
// EQUIPMENT COMMANDS
{
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::InitializeEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::CreateEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::ShowEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::HideEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::RefreshEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::RefreshEquipmentWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::RefreshItemsWidgets);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::UnequipItemWidget);
EquipmentWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaEquipmentWidgetCommands::EquipmentCommands::EquipItemWidget);
}

ItemTooltipWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemTooltipCommands::CleanupTooltip);
ItemTooltipWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemTooltipCommands::ShowTooltip);
ItemTooltipWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemTooltipCommands::HideTooltip);
// ITEM COMMANDS
{
ItemsWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemCommands::AddNewItem);
ItemsWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemCommands::UpdateItem);
ItemsWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemCommands::RemoveItem);
}

InventoryUpdateData.Add
(
EInventoryUpdateResult::EIUR_Failed,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryNotificationData_Failed", "Inventory Update Failed"), 3.f, FLinearColor(FColor::Red), 1)
);
InventoryUpdateData.Add
(
EInventoryUpdateResult::EIUR_Success,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryNotificationData_Success", "Inventory Updated"), 1.5f, FLinearColor(FColor::White), 0)
);
// ITEM TOOLTIP COMMANDS
{
ItemTooltipWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemTooltipCommands::CleanupTooltip);
ItemTooltipWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemTooltipCommands::ShowTooltip);
ItemTooltipWidgetCommands.Add(MounteaInventoryEquipmentConsts::MounteaInventoryWidgetCommands::ItemTooltipCommands::HideTooltip);
}

// INVENTORY UPDATE DATA SETUP
{
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_Processing,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_Processing", "Server is processing request."), 3.f, FLinearColor(FColor::White), 0)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_OK,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_ItemUpdated", "Added all of the item to the existing stack."), 3.f, FLinearColor(FColor::White), 2)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_Created,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_ItemCreated", "New item created in Inventory."), 3.f, FLinearColor(FColor::White), 2)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_CreatedPart,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_ItemUpdatedPartly", "Added part of the item to the existing stack. Some quantity remains in the source item."), 3.f, FLinearColor(FColor::White), 2)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_MutliStatus,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_ItemQuantityReducedRemoved", "The item has been reduced and removed from the inventory."), 3.f, FLinearColor(FColor::White), 2)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_BadRequest,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_InvalidRequest", "Invalid Request. Item does not exist."), 3.f, FLinearColor(FColor::Red), 10)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_Forbidden,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_InvalidRequest", "Action is forbidden. Action cannot be processed."), 3.f, FLinearColor(FColor::Red), 10)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_NotFound,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_ItemNotFound", "The item was not found in the inventory."), 3.f, FLinearColor(FColor::Red), 10)
);
InventoryUpdateData.Add
(
MounteaInventoryEquipmentConsts::InventoryUpdatedCodes::Status_NotFound,
FInventoryNotificationData(nullptr, LOCTEXT("InventoryUpdateResult_ItemUnknownIssue", "Unhandled Exception."), 3.f, FLinearColor(FColor::Red), 10)
);
}

MinDisplayWeight = 1;

bUIDebug = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class MOUNTEAINVENTORYEQUIPMENT_API UMounteaInventoryComponent : public UActorCo
void PostItemUpdated_Client(const FInventoryUpdateResult& UpdateContext);

void RequestInventoryNotification(const FInventoryUpdateResult& UpdateContext) const;
void RequestItemNotification(const FInventoryUpdateResult& UpdateContext) const;

protected:

Expand Down
Loading

0 comments on commit fd4b2ac

Please sign in to comment.