From 620dee046588f71a6641dc8d1638d3e4bcc92360 Mon Sep 17 00:00:00 2001 From: "adnan.mujkic" Date: Fri, 24 Jul 2026 23:48:29 +0200 Subject: [PATCH] Refactor of some UI logic --- .../AlchemySystem/AlchemyWindow.uasset | 4 +- .../Scripts/Bazar/BP_BazarSellingStand.uasset | 4 +- Content/Scripts/Bazar/WBP_BazarScreen.uasset | 4 +- .../UI/InventoryScreenWrapper.uasset | 4 +- .../Notifications/UI_NotificationPanel.uasset | 4 +- .../ShopAndTradeSystem/WBP_TradeWidget.uasset | 4 +- Content/UI/Calendar/WBP_CalendarScreen.uasset | 4 +- Content/UI/MainMenuScreenUI.uasset | 4 +- Content/UI/MainUI.uasset | 4 +- .../PotionSort/WBP_PotionSort.uasset | 4 +- Content/UI/Modules/UI_AmountPicker.uasset | 4 +- Content/UI/W_DialogueImportant.uasset | 4 +- .../Private/EleriPlayerController.cpp | 208 ++---------------- .../Private/UI/EleriBaseWidget.cpp | 7 +- .../Private/UI/MainGameWidget.cpp | 108 +++++---- .../ProjectEleri/Private/UI/TradeWidget.cpp | 4 +- .../Public/EleriPlayerController.h | 17 -- .../ProjectEleri/Public/UI/MainGameWidget.h | 55 +---- Source/ProjectEleri/Public/UI/TradeWidget.h | 2 +- 19 files changed, 109 insertions(+), 340 deletions(-) diff --git a/Content/Scripts/AlchemySystem/AlchemyWindow.uasset b/Content/Scripts/AlchemySystem/AlchemyWindow.uasset index fcbf534e..f0ec7ec1 100644 --- a/Content/Scripts/AlchemySystem/AlchemyWindow.uasset +++ b/Content/Scripts/AlchemySystem/AlchemyWindow.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b6bad518099f6731d125dcea851086fd0bd6bf57c3d9e7861ecd8075df2cb7fc -size 1588558 +oid sha256:77d34316d142176f43a31c49761a468f660ebbcff9c49a62916c941f9c6c37d5 +size 1585293 diff --git a/Content/Scripts/Bazar/BP_BazarSellingStand.uasset b/Content/Scripts/Bazar/BP_BazarSellingStand.uasset index cff42017..d61c8a25 100644 --- a/Content/Scripts/Bazar/BP_BazarSellingStand.uasset +++ b/Content/Scripts/Bazar/BP_BazarSellingStand.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6633a8124c800d1c41c2a474c93d9f033f23c8a31615fef7d216d041f685740f -size 311616 +oid sha256:bf9fdfca70e82712c66415ebd61724c141f03c32d88544b6dc4e42c520c6a663 +size 315762 diff --git a/Content/Scripts/Bazar/WBP_BazarScreen.uasset b/Content/Scripts/Bazar/WBP_BazarScreen.uasset index 794e99d5..0b14618c 100644 --- a/Content/Scripts/Bazar/WBP_BazarScreen.uasset +++ b/Content/Scripts/Bazar/WBP_BazarScreen.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d8b7f0d6253ec5f8b2806fc7156def1ace4bff1829b564977e627d61c651e456 -size 107890 +oid sha256:205f2a3d3f9435a0c281a2b9a952d306004cf55933f167b05242e5806f491d14 +size 87743 diff --git a/Content/Scripts/InventorySystem/UI/InventoryScreenWrapper.uasset b/Content/Scripts/InventorySystem/UI/InventoryScreenWrapper.uasset index 3ddaba34..7b860ef9 100644 --- a/Content/Scripts/InventorySystem/UI/InventoryScreenWrapper.uasset +++ b/Content/Scripts/InventorySystem/UI/InventoryScreenWrapper.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ecb24f2cb92b0ecc591faebb426847918507f75bd455a7a0a100bae9a1d674df -size 1302772 +oid sha256:695df219fec2690b34607e6620ee80540ca67dadf6bd63d6d7f28c18be2602ad +size 1297466 diff --git a/Content/Scripts/Notifications/UI_NotificationPanel.uasset b/Content/Scripts/Notifications/UI_NotificationPanel.uasset index ebbe94f0..81663bc7 100644 --- a/Content/Scripts/Notifications/UI_NotificationPanel.uasset +++ b/Content/Scripts/Notifications/UI_NotificationPanel.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b0dd827e39d8b8518aa3fb08692098a50a3dbd973e0b1f73b8d37a974e163131 -size 275705 +oid sha256:7400c17902b709f4d02f100b5ba651104bf8d6a48865f86ea2d9a3d5c2c94984 +size 266386 diff --git a/Content/Scripts/ShopAndTradeSystem/WBP_TradeWidget.uasset b/Content/Scripts/ShopAndTradeSystem/WBP_TradeWidget.uasset index 8bb4174b..5c641b42 100644 --- a/Content/Scripts/ShopAndTradeSystem/WBP_TradeWidget.uasset +++ b/Content/Scripts/ShopAndTradeSystem/WBP_TradeWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:73477550b0e9e0ace666b73d4e2fe719d4db52e2815bafb0c8b28c7f603895da -size 871141 +oid sha256:ec77a83c71417c123fce1a6beafd231adec9f14724ba02f3d3210bf6fb16ef10 +size 848560 diff --git a/Content/UI/Calendar/WBP_CalendarScreen.uasset b/Content/UI/Calendar/WBP_CalendarScreen.uasset index edcd300f..3cb5528c 100644 --- a/Content/UI/Calendar/WBP_CalendarScreen.uasset +++ b/Content/UI/Calendar/WBP_CalendarScreen.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:973e3ee2667441c38f83157a5c0431a1b2936f925bdf19d3cf3b9670e43472b9 -size 223876 +oid sha256:e4440d2a1b93e25da4b3d67be3704e5b82a5382e7f50985afb3885707d70be88 +size 211138 diff --git a/Content/UI/MainMenuScreenUI.uasset b/Content/UI/MainMenuScreenUI.uasset index 6a3ad377..93f93f18 100644 --- a/Content/UI/MainMenuScreenUI.uasset +++ b/Content/UI/MainMenuScreenUI.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f986fad7cfa2112aed558adfda06e6b1ad815713217cc59006cb1f4c320caa8b -size 487276 +oid sha256:58e3119c0e15033b789e721ab63a531f0e367e92ba064641bf7d4a8c189443a3 +size 482539 diff --git a/Content/UI/MainUI.uasset b/Content/UI/MainUI.uasset index 870194c0..69eb3a41 100644 --- a/Content/UI/MainUI.uasset +++ b/Content/UI/MainUI.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1fbfd7c81058f72b53d7a326f5e78fc4a5395daa695d33a23d0e82cb84fd2b16 -size 610902 +oid sha256:129d85a04727385a0778b7785a7d3f47b68048a2facabaac45c7b52d1a68f1a8 +size 605217 diff --git a/Content/UI/Minigames/PotionSort/WBP_PotionSort.uasset b/Content/UI/Minigames/PotionSort/WBP_PotionSort.uasset index f80deef8..e7b45c8f 100644 --- a/Content/UI/Minigames/PotionSort/WBP_PotionSort.uasset +++ b/Content/UI/Minigames/PotionSort/WBP_PotionSort.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:84e709ab87fe5324b53e0fed77dd877ce87fc1bd3671b8d8c986ea630249d812 -size 898067 +oid sha256:2dffa69c38860293cd768ca3f20eedbb0ef9baf2a30ae97f2477ac9964f6794c +size 905337 diff --git a/Content/UI/Modules/UI_AmountPicker.uasset b/Content/UI/Modules/UI_AmountPicker.uasset index 4871ae04..4ceeaba9 100644 --- a/Content/UI/Modules/UI_AmountPicker.uasset +++ b/Content/UI/Modules/UI_AmountPicker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:24dc5359b7400de5189b57c2bc8d5b8692c8dc2fbd8ead43b92cd72153e58a75 -size 433851 +oid sha256:26d89e17b0a32b9d69468f007fe2f93c4f3d44de14e8c85930f9b30250f545de +size 435598 diff --git a/Content/UI/W_DialogueImportant.uasset b/Content/UI/W_DialogueImportant.uasset index c03b4ada..46bacc5c 100644 --- a/Content/UI/W_DialogueImportant.uasset +++ b/Content/UI/W_DialogueImportant.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:660b344289d142946928dec69980de5bc0648ec4c360d0bf3d729dcf329ef7a5 -size 191975 +oid sha256:41b35bf01c2d0514374c2cbb1b950d4747c4580d14650ce65a4c74e36ab8d108 +size 191599 diff --git a/Source/ProjectEleri/Private/EleriPlayerController.cpp b/Source/ProjectEleri/Private/EleriPlayerController.cpp index f8cb9010..dca324c9 100644 --- a/Source/ProjectEleri/Private/EleriPlayerController.cpp +++ b/Source/ProjectEleri/Private/EleriPlayerController.cpp @@ -905,31 +905,16 @@ void AEleriPlayerController::OnOrdersToggle(const FInputActionValue &Value) } else { - OrdersUI = CreateWidget(this, OrdersBlueprint); - if (!IsValid(OrdersUI)) - return; - - OrdersUI->AddToViewport(); - AddToMenuStack(OrdersUI); - SetShowMouseCursor(true); - SetInputMode(FInputModeGameAndUI()); - OrdersOpen = true; + } } void AEleriPlayerController::OnCalendarToggle(const FInputActionValue &Value) { - if (Paused || IsDialogueOpen() || (IsInMenu() && !MainGameUI->IsBookOpen()) || !MoveActorsComp || MoveActorsComp->IsRemovingMode()) + if (Paused || IsDialogueOpen() || (IsInMenu() && !MainGameUI->IsCalendarOpen()) || !MoveActorsComp || MoveActorsComp->IsRemovingMode()) return; - if (!MainGameUI->IsCalendarOpen()) - { - OpenCalendarWindow(); - } - else - { - CloseCalendarWindow(); - } + OpenCalendarWindow(); } void AEleriPlayerController::OnBookNextPage(const FInputActionValue &Value) @@ -1031,7 +1016,7 @@ UUserWidget *AEleriPlayerController::OpenBookOfAlchemy(UItemDataAsset *ItemToPre bBookAnimating = true; MainGameUI->GetBookWidget()->Setup(ItemToPresent, false); PlayerCharacter->ToggleBook(true); - MainGameUI->ToggleBookWidget(true); + MainGameUI->OpenWidget(MainGameUI->GetBookWidget()); MainGameUI->ToggleGameMenu(false); @@ -1082,7 +1067,7 @@ void AEleriPlayerController::DisableBookAnimating() void AEleriPlayerController::CloseOrdersUI() { OrdersOpen = false; - RemoveFromMenuStack(OrdersUI); + OrdersUI->RemoveFromParent(); if (MenuStack.Num() == 0) { @@ -1095,33 +1080,15 @@ UMainMenuWidget *AEleriPlayerController::OpenMainMenu() { if (!IsValid(MainGameUI)) return nullptr; - UMainMenuWidget *MainMenu = MainGameUI->GetMainMenuWidget(); - if (!IsValid(MainMenu)) - return nullptr; - AddToMenuStack(MainMenu); - SetInputMode(FInputModeGameAndUI()); - SetShowMouseCursor(true); - MainGameUI->ToggleMainMenuWidget(true); - SetPause(true); + MainGameUI->OpenWidget(MainGameUI->GetMainMenuWidget()); - return MainMenu; + return MainGameUI->GetMainMenuWidget(); } void AEleriPlayerController::CloseMainMenu() { - if (!IsValid(MainGameUI)) - return; - UMainMenuWidget *MainMenu = MainGameUI->GetMainMenuWidget(); - if (!IsValid(MainMenu)) - return; - - RemoveFromMenuStack(MainMenu); - MainGameUI->ToggleMainMenuWidget(false); - SetShowMouseCursor(false); - SetInputMode(FInputModeGameOnly()); - - SetPause(false); + MainGameUI->CloseWidget(MainGameUI->GetMainMenuWidget()); } UEleriBaseWidget *AEleriPlayerController::ToggleAlchemyMenu(bool bOpen) @@ -1139,20 +1106,7 @@ UEleriBaseWidget *AEleriPlayerController::ToggleDialogueWindow(bool bOpen) if (!IsValid(MainGameUI->GetDialogueWidget()) || MainGameUI->GetDialogueWidget()->IsAnimating()) return nullptr; - MainGameUI->ToggleDialogueWidget(bOpen); - MainGameUI->GetDialogueWidget()->ToggleWidget(bOpen); - - if (bOpen) - { - AddToMenuStack(MainGameUI->GetDialogueWidget()); - SetInputMode(FInputModeGameAndUI()); - SetShowMouseCursor(bOpen); - } - else - { - CloseGenericMenu(MainGameUI->GetDialogueWidget()); - } - + MainGameUI->OpenWidget(MainGameUI->GetDialogueWidget()); return MainGameUI->GetDialogueWidget(); } @@ -1161,21 +1115,14 @@ UEleriBaseWidget *AEleriPlayerController::ToggleNotificationWindow(bool bOpen) if (!IsValid(MainGameUI->GetBigNotificationWidget())) return nullptr; - MainGameUI->ToggleBigNotificationWidget(bOpen); - - if (bOpen) + if (MainGameUI->IsBigNotificationOpen()) { - AddToMenuStack(MainGameUI->GetBigNotificationWidget()); - SetInputMode(FInputModeGameAndUI()); + MainGameUI->CloseWidget(MainGameUI->GetBigNotificationWidget()); } else { - CloseGenericMenu(MainGameUI->GetBigNotificationWidget()); - SetInputMode(FInputModeGameOnly()); + MainGameUI->OpenWidget(MainGameUI->GetBigNotificationWidget()); } - SetShowMouseCursor(bOpen); - SetPause(bOpen); - return MainGameUI->GetBigNotificationWidget(); } @@ -1187,132 +1134,22 @@ UTradeWidget *AEleriPlayerController::OpenTradeWindow(UInventoryComponent *Inven if (UMainGameWidget *MainWidget = GetMainGameWidget()) { MainWidget->OpenTradeWidget(Inventory, InRestrictTabs); - UTradeWidget *TradeWidget = MainWidget->GetTradeWidget(); - - AddToMenuStack(TradeWidget); - SetInputMode(FInputModeGameAndUI()); - SetShowMouseCursor(true); - SetPause(true); - - return TradeWidget; + return MainGameUI->GetTradeWidget(); } return nullptr; } -void AEleriPlayerController::CloseTradeWindow() -{ - if (UMainGameWidget *MainWidget = GetMainGameWidget()) - { - UTradeWidget *TradeWidget = MainWidget->GetTradeWidget(); - MainWidget->CloseTradeWidget(); - - RemoveFromMenuStack(TradeWidget); - SetInputMode(FInputModeGameOnly()); - SetShowMouseCursor(false); - SetPause(false); - } -} - UCalendarScreen* AEleriPlayerController::OpenCalendarWindow() { - MainGameUI->ToggleCalendarWidget(true); - AddToMenuStack(MainGameUI->GetCalendarWidget()); - SetInputMode(FInputModeGameAndUI()); - SetShowMouseCursor(true); - SetPause(true); + MainGameUI->OpenWidget(MainGameUI->GetCalendarWidget()); return MainGameUI->GetCalendarWidget(); } -void AEleriPlayerController::CloseCalendarWindow() -{ - MainGameUI->ToggleCalendarWidget(false); - RemoveFromMenuStack(MainGameUI->GetCalendarWidget()); - SetInputMode(FInputModeGameOnly()); - SetShowMouseCursor(false); - SetPause(false); -} - UEleriBaseWidget* AEleriPlayerController::OpenBazarWindow() { - MainGameUI->ToggleBazarWidget(true); - AddToMenuStack(MainGameUI->GetBazarWidget()); - SetInputMode(FInputModeGameAndUI()); - SetShowMouseCursor(true); + MainGameUI->OpenWidget(MainGameUI->GetBazarWidget()); return MainGameUI->GetBazarWidget(); } -void AEleriPlayerController::CloseBazarWindow() { - MainGameUI->ToggleBazarWidget(false); - RemoveFromMenuStack(MainGameUI->GetBazarWidget()); - SetInputMode(FInputModeGameOnly()); - SetShowMouseCursor(false); -} - -void AEleriPlayerController::AddToMenuStack(UUserWidget *Widget) -{ - MenuStack.AddUnique(Widget); - - OnWateringActionEnd(FInputActionValue()); -} - -void AEleriPlayerController::RemoveFromMenuStack(UUserWidget *Widget) -{ - MenuStack.Remove(Widget); -} - -bool AEleriPlayerController::OpenGenericMenu(UUserWidget *Widget, bool CloseOthers = false, bool IgnoreInMenu = false) -{ - if (!IgnoreInMenu && IsInMenu()) - return false; - - for (const UUserWidget *StackWidget : MenuStack) - { - if (StackWidget == Widget) - return false; - } - - if (CloseOthers) - { - for (UUserWidget *StackWidget : MenuStack) - { - StackWidget->RemoveFromParent(); - } - OrdersOpen = false; - } - - AddToMenuStack(Widget); - Widget->AddToViewport(); - SetShowMouseCursor(true); - SetInputMode(FInputModeGameAndUI()); - SetPause(true); - - return true; -} - -void AEleriPlayerController::CloseGenericMenu(UEleriBaseWidget *Widget) -{ - RemoveFromMenuStack(Widget); - Widget->ToggleWidget(false); - if (MenuStack.Num() == 0) - { - SetShowMouseCursor(false); - SetInputMode(FInputModeGameOnly()); - SetPause(false); - } - else - { - MenuStack[MenuStack.Num() - 1]->SetUserFocus(this); - MenuStack[MenuStack.Num() - 1]->SetKeyboardFocus(); - } -} - -void AEleriPlayerController::CloseLastGenericMenu() -{ - if (MenuStack.Num() <= 0 || IsValid(MenuStack[MenuStack.Num() - 1])) - return; - - // CloseGenericMenu(MenuStack[MenuStack.Num() - 1]); -} - void AEleriPlayerController::OnInteract(const FInputActionValue &Value) { if (!IsValid(PlayerCharacter)) @@ -1347,10 +1184,7 @@ void AEleriPlayerController::StartMinigame(EMinigameType MinigameType, const TSo MinigameType == EMinigameType::NONE) return; - if (UEleriBaseWidget *MinigameWidget = MainGameUI->ToggleMinigamesWidget(MinigameType, DataAsset)) - { - OpenGenericMenu(MinigameWidget, false, true); - } + MainGameUI->ToggleMinigamesWidget(MinigameType, DataAsset); } void AEleriPlayerController::CloseMinigame(int32 Score) @@ -1358,13 +1192,9 @@ void AEleriPlayerController::CloseMinigame(int32 Score) if (!IsValid(PlayerCharacter) || !IsValid(MainGameUI) || !MainGameUI->IsAnyMinigameOpen()) return; - if (UEleriBaseWidget *MinigameWidget = MainGameUI->GetCurrentlyOpenMinigameWidget()) + MainGameUI->ToggleMinigamesWidget(EMinigameType::NONE, nullptr); + if (OnMinigameComplete.IsBound()) { - CloseGenericMenu(MinigameWidget); - MainGameUI->ToggleMinigamesWidget(EMinigameType::NONE, nullptr); - if (OnMinigameComplete.IsBound()) - { - OnMinigameComplete.Execute(Score); - } + OnMinigameComplete.Execute(Score); } } diff --git a/Source/ProjectEleri/Private/UI/EleriBaseWidget.cpp b/Source/ProjectEleri/Private/UI/EleriBaseWidget.cpp index 898f18d7..aa4f36ce 100644 --- a/Source/ProjectEleri/Private/UI/EleriBaseWidget.cpp +++ b/Source/ProjectEleri/Private/UI/EleriBaseWidget.cpp @@ -7,12 +7,7 @@ #include "Kismet/GameplayStatics.h" void UEleriBaseWidget::ToggleWidget_Implementation(bool bActive) { - if (bActive) { - //ActivateWidget(); - } - else { - //DeactivateWidget(); - } + SetVisibility(bActive? ESlateVisibility::Visible : ESlateVisibility::Hidden); } void UEleriBaseWidget::HandleUiInputAction_Implementation(EEleriUIInputAction InputAction) diff --git a/Source/ProjectEleri/Private/UI/MainGameWidget.cpp b/Source/ProjectEleri/Private/UI/MainGameWidget.cpp index f8b3953d..24bf02f8 100644 --- a/Source/ProjectEleri/Private/UI/MainGameWidget.cpp +++ b/Source/ProjectEleri/Private/UI/MainGameWidget.cpp @@ -5,11 +5,10 @@ #include "EleriPlayerController.h" #include "EnhancedInputSubsystems.h" #include "Kismet/GameplayStatics.h" -#include "UI/InventoryWidget.h" -#include "UI/MainMenuWidget.h" #include "UI/TradeWidget.h" #include "UI/AlchemyWidget.h" - +#include "ProjectEleri/UI/CalendarScreen.h" +#include "ProjectEleri/DialogueSystem/DialogueWidget.h" void UMainGameWidget::TogglePlaceableUI(bool bEnabled) { @@ -24,14 +23,14 @@ void UMainGameWidget::SwitchKeybindsDisplay(int32 Index) void UMainGameWidget::CloseLastWidget() { if (WidgetStack.IsEmpty()) return; - + CloseWidget(WidgetStack[WidgetStack.Num() - 1]); } void UMainGameWidget::OpenWidget(UEleriBaseWidget* Widget) { if (!Widget) return; - + Widget->ToggleWidget(true); WidgetStack.AddUnique(Widget); CheckOpenWidgets(); @@ -40,89 +39,89 @@ void UMainGameWidget::OpenWidget(UEleriBaseWidget* Widget) void UMainGameWidget::CloseWidget(UEleriBaseWidget* Widget) { if (!Widget) return; - + Widget->ToggleWidget(false); WidgetStack.Remove(Widget); CheckOpenWidgets(); } -void UMainGameWidget::ToggleBookWidget(bool bActive) +bool UMainGameWidget::IsBookOpen() const { - if (bActive) - WidgetStack.AddUnique(GetBookWidget()); - - CheckOpenWidgets(); + return WidgetStack.Contains(Book_Widget); } -void UMainGameWidget::ToggleAlchemyWidget(bool bActive) +bool UMainGameWidget::IsInventoryOpen() const { - AlchemyOpen = bActive; - if (bActive) - WidgetStack.AddUnique(GetAlchemyWidget()); - - CheckOpenWidgets(); + return WidgetStack.Contains(Inventory_Widget); } -void UMainGameWidget::ToggleBigNotificationWidget(bool bActive) +bool UMainGameWidget::IsAlchemyOpen() const { - BigNotificationOpen = bActive; - BigNotification_Widget->ToggleWidget(BigNotificationOpen); + return WidgetStack.Contains(Alchemy_Widget); } -void UMainGameWidget::ToggleDialogueWidget(bool bActive) +bool UMainGameWidget::IsBigNotificationOpen() const { - DialogueOpen = bActive; + return WidgetStack.Contains(BigNotification_Widget); } -UMinigameBaseWidget *UMainGameWidget::ToggleMinigamesWidget(EMinigameType MinigameType, const TSoftObjectPtr &DataAsset) +bool UMainGameWidget::IsDialogueOpen() const +{ + return WidgetStack.Contains(Dialogue_Widget); +} + +UMinigameBaseWidget* UMainGameWidget::ToggleMinigamesWidget(EMinigameType MinigameType, const TSoftObjectPtr& DataAsset) { MinigameOpen = MinigameType; - CurrentlyOpenMinigameWidget = K2_OnMinigameOpen(MinigameOpen, DataAsset); + if (MinigameType == EMinigameType::NONE) + { + CloseWidget(CurrentlyOpenMinigameWidget); + } + else + { + CurrentlyOpenMinigameWidget = K2_OnMinigameOpen(MinigameOpen, DataAsset); + OpenWidget(CurrentlyOpenMinigameWidget); + } + return CurrentlyOpenMinigameWidget; } -void UMainGameWidget::ToggleMainMenuWidget(bool bActive) +bool UMainGameWidget::IsMainMenuOpen() const { - MainMenuOpen = bActive; - MainMenuScreenUI_Widget->ToggleWidget(MainMenuOpen); + return WidgetStack.Contains(MainMenuScreenUI_Widget); } -UEleriBaseWidget *UMainGameWidget::ShowAmountPickerWidget() +UEleriBaseWidget* UMainGameWidget::ShowAmountPickerWidget() { - AmountPicker_Widget->ToggleWidget(true); + OpenWidget(AmountPicker_Widget); return AmountPicker_Widget; } -UEleriBaseWidget *UMainGameWidget::ShowImportantDialoguePromptWidget() +UEleriBaseWidget* UMainGameWidget::ShowImportantDialoguePromptWidget() { - ImportantDialoguePrompt_Widget->ToggleWidget(true); + OpenWidget(ImportantDialoguePrompt_Widget); return ImportantDialoguePrompt_Widget; } -void UMainGameWidget::OpenTradeWidget(UInventoryComponent *Inventory, const TArray& InRestrictTabs) +void UMainGameWidget::OpenTradeWidget(UInventoryComponent* Inventory, const TArray& InRestrictTabs) { - TradeOpen = true; - Trade_Widget->OpenTradeWidget(Inventory, InRestrictTabs); + Trade_Widget->SetupTradeWidget(Inventory, InRestrictTabs); + OpenWidget(GetTradeWidget()); } -void UMainGameWidget::CloseTradeWidget() +bool UMainGameWidget::IsTradeOpen() const { - TradeOpen = false; - Trade_Widget->ToggleWidget(false); - CheckOpenWidgets(); + return WidgetStack.Contains(Trade_Widget); } -void UMainGameWidget::ToggleCalendarWidget(bool bActive) +bool UMainGameWidget::IsCalendarOpen() const { - CalendarOpen = bActive; - Calendar_Widget->ToggleWidget(CalendarOpen); - CheckOpenWidgets(); + return WidgetStack.Contains(Calendar_Widget); } -void UMainGameWidget::ToggleBazarWidget(bool bActive) { - BazarWidgetOpen = bActive; - Bazar_Widget->ToggleWidget(BazarWidgetOpen); - CheckOpenWidgets(); +bool UMainGameWidget::IsBazarWidgetOpen() const +{ + return WidgetStack.Contains(Bazar_Widget); } void UMainGameWidget::CheckOpenWidgets() @@ -131,14 +130,10 @@ void UMainGameWidget::CheckOpenWidgets() { PlayerController = UGameplayStatics::GetPlayerController(this, 0); } - - //const bool bAnyOpenWidgets = IsAlchemyOpen() || IsAnyMinigameOpen() || IsBazarWidgetOpen() || IsBigNotificationOpen() || - // IsBookOpen() || IsCalendarOpen() || IsDialogueOpen() || IsInventoryOpen() || IsMainMenuOpen() || IsTradeOpen(); - + const bool bAnyOpenWidgets = AnyWidgetOpen(); - const bool bShouldBePaused = WidgetStack.Contains(GetBookWidget()); - + if (bAnyOpenWidgets) { PlayerController->SetInputMode(FInputModeGameAndUI()); @@ -147,13 +142,14 @@ void UMainGameWidget::CheckOpenWidgets() { PlayerController->SetInputMode(FInputModeGameOnly()); } - + PlayerController->SetShowMouseCursor(bAnyOpenWidgets); PlayerController->SetPause(bShouldBePaused); - - + + // Get the Enhanced Input Local Player Subsystem from the Local Player related to our Player Controller. - if (UEnhancedInputLocalPlayerSubsystem *Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem( + PlayerController->GetLocalPlayer())) { if (const AEleriPlayerController* EleriPC = Cast(PlayerController)) { diff --git a/Source/ProjectEleri/Private/UI/TradeWidget.cpp b/Source/ProjectEleri/Private/UI/TradeWidget.cpp index 1ff88140..b1238d44 100644 --- a/Source/ProjectEleri/Private/UI/TradeWidget.cpp +++ b/Source/ProjectEleri/Private/UI/TradeWidget.cpp @@ -4,7 +4,7 @@ #include "UI/TradeWidget.h" #include "ProjectEleri/Public/InventoryComponent.h" -void UTradeWidget::OpenTradeWidget(UInventoryComponent* Inventory, const TArray& InRestrictTabs) { +void UTradeWidget::SetupTradeWidget(UInventoryComponent* Inventory, const TArray& InRestrictTabs) { InventoryRef = Inventory; if (InventoryRef) { @@ -13,6 +13,4 @@ void UTradeWidget::OpenTradeWidget(UInventoryComponent* Inventory, const TArray< bIsChest = InventoryRef->IsChest; RestrictedTabs = InRestrictTabs; } - - ToggleWidget(true); } diff --git a/Source/ProjectEleri/Public/EleriPlayerController.h b/Source/ProjectEleri/Public/EleriPlayerController.h index a650f437..0a04397d 100644 --- a/Source/ProjectEleri/Public/EleriPlayerController.h +++ b/Source/ProjectEleri/Public/EleriPlayerController.h @@ -353,29 +353,12 @@ public: UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "InRestrictTabs")) UTradeWidget* OpenTradeWindow(UInventoryComponent* Inventory, const TArray& InRestrictTabs); - UFUNCTION(BlueprintCallable) - void CloseTradeWindow(); UFUNCTION(BlueprintCallable) UCalendarScreen* OpenCalendarWindow(); - UFUNCTION(BlueprintCallable) - void CloseCalendarWindow(); UFUNCTION(BlueprintCallable) UEleriBaseWidget* OpenBazarWindow(); - UFUNCTION(BlueprintCallable) - void CloseBazarWindow(); - - void AddToMenuStack(UUserWidget* Widget); - void RemoveFromMenuStack(UUserWidget* Widget); - UFUNCTION(BlueprintCallable) - bool OpenGenericMenu(UUserWidget* Widget, bool CloseOthers, bool IgnoreInMenu); - - UFUNCTION(BlueprintCallable) - void CloseGenericMenu(UEleriBaseWidget* Widget); - - UFUNCTION(BlueprintCallable) - void CloseLastGenericMenu(); void OnInteract(const FInputActionValue& Value); void OnInteractExit(const FInputActionValue& Value); diff --git a/Source/ProjectEleri/Public/UI/MainGameWidget.h b/Source/ProjectEleri/Public/UI/MainGameWidget.h index fd85bcab..25a5a25d 100644 --- a/Source/ProjectEleri/Public/UI/MainGameWidget.h +++ b/Source/ProjectEleri/Public/UI/MainGameWidget.h @@ -7,15 +7,15 @@ #include "Components/Overlay.h" #include "Components/WidgetSwitcher.h" #include "ProjectEleri/UI/MinigameBaseWidget.h" -#include "ProjectEleri/UI/CalendarScreen.h" #include "ProjectEleri/Public/InventoryComponent.h" #include "MainGameWidget.generated.h" +class UCalendarScreen; +class UAlchemyWidget; class UInventoryWidget; class UBookOfAlchemyWidget; class UInteractionWidget; -class UAlchemyWidget; class UMainMenuWidget; class UTradeWidget; class UDialogueWidget; @@ -68,40 +68,32 @@ public: // Book widget UFUNCTION(BlueprintCallable, BlueprintPure) UBookOfAlchemyWidget *GetBookWidget() { return Book_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleBookWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsBookOpen() const { return WidgetStack.Contains(Book_Widget); } + bool IsBookOpen() const; // Inventory widget UFUNCTION(BlueprintCallable, BlueprintPure) UInventoryWidget *GetInventoryWidget() { return Inventory_Widget; } UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsInventoryOpen() const { return WidgetStack.Contains(Inventory_Widget); } + bool IsInventoryOpen() const; // Alchemy widget UFUNCTION(BlueprintCallable, BlueprintPure) UAlchemyWidget *GetAlchemyWidget() { return Alchemy_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleAlchemyWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsAlchemyOpen() const { return AlchemyOpen; } + bool IsAlchemyOpen() const; // Big Notification widget UFUNCTION(BlueprintCallable, BlueprintPure) UEleriBaseWidget *GetBigNotificationWidget() { return BigNotification_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleBigNotificationWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsBigNotificationOpen() const { return BigNotificationOpen; } + bool IsBigNotificationOpen() const; // Dialogue widget UFUNCTION(BlueprintCallable, BlueprintPure) UDialogueWidget*GetDialogueWidget() { return Dialogue_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleDialogueWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsDialogueOpen() const { return DialogueOpen; } + bool IsDialogueOpen() const; // Minigames widget UFUNCTION(BlueprintCallable) @@ -119,10 +111,8 @@ public: // Main menu widget UFUNCTION(BlueprintCallable, BlueprintPure) UMainMenuWidget *GetMainMenuWidget() { return MainMenuScreenUI_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleMainMenuWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsMainMenuOpen() const { return MainMenuOpen; } + bool IsMainMenuOpen() const; // Amount Picker widget UFUNCTION(BlueprintCallable, BlueprintPure) @@ -140,25 +130,20 @@ public: UFUNCTION(BlueprintCallable, BlueprintPure) UTradeWidget *GetTradeWidget() { return Trade_Widget; } void OpenTradeWidget(UInventoryComponent *Inventory, const TArray& InRestrictTabs = TArray{}); - void CloseTradeWidget(); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsTradeOpen() const { return TradeOpen; } + bool IsTradeOpen() const; // Calendar widget UFUNCTION(BlueprintCallable, BlueprintPure) UCalendarScreen *GetCalendarWidget() { return Calendar_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleCalendarWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsCalendarOpen() const { return CalendarOpen; } + bool IsCalendarOpen() const; // Bazar widget UFUNCTION(BlueprintCallable, BlueprintPure) UEleriBaseWidget* GetBazarWidget() { return Bazar_Widget; } - UFUNCTION(BlueprintCallable) - void ToggleBazarWidget(bool bActive); UFUNCTION(BlueprintCallable, BlueprintPure) - bool IsBazarWidgetOpen() const { return BazarWidgetOpen; } + bool IsBazarWidgetOpen() const; protected: UPROPERTY(BlueprintReadWrite, Category = "Gradient Picker Widget Binding", meta = (BindWidget)) @@ -173,32 +158,22 @@ protected: // Book UPROPERTY(meta = (BindWidget)) UBookOfAlchemyWidget *Book_Widget; - UPROPERTY() - bool BookOpen = false; // Inventory UPROPERTY(meta = (BindWidget)) UInventoryWidget *Inventory_Widget; - UPROPERTY() - bool InventoryOpen = false; // Alchemy UPROPERTY(meta = (BindWidget)) UAlchemyWidget *Alchemy_Widget; - UPROPERTY() - bool AlchemyOpen = false; // Notification Big UPROPERTY(meta = (BindWidget)) UEleriBaseWidget *BigNotification_Widget; - UPROPERTY() - bool BigNotificationOpen = false; // Dialogue UI UPROPERTY(meta = (BindWidget)) UDialogueWidget*Dialogue_Widget; - UPROPERTY() - bool DialogueOpen = false; // Important dialogue prompt UPROPERTY(meta = (BindWidget)) @@ -211,20 +186,14 @@ protected: // Trade UPROPERTY(meta = (BindWidget)) UTradeWidget *Trade_Widget; - UPROPERTY() - bool TradeOpen = false; // Calendar UPROPERTY(meta = (BindWidget)) UCalendarScreen *Calendar_Widget; - UPROPERTY() - bool CalendarOpen = false; // Calendar UPROPERTY(meta = (BindWidget)) UEleriBaseWidget* Bazar_Widget; - UPROPERTY() - bool BazarWidgetOpen = false; // Minigames UI UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (BindWidget)) @@ -237,8 +206,6 @@ protected: // Main Menu UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (BindWidget)) UMainMenuWidget *MainMenuScreenUI_Widget; - UPROPERTY() - bool MainMenuOpen = false; UPROPERTY() APlayerController* PlayerController; diff --git a/Source/ProjectEleri/Public/UI/TradeWidget.h b/Source/ProjectEleri/Public/UI/TradeWidget.h index 13592771..046b5c57 100644 --- a/Source/ProjectEleri/Public/UI/TradeWidget.h +++ b/Source/ProjectEleri/Public/UI/TradeWidget.h @@ -19,7 +19,7 @@ class PROJECTELERI_API UTradeWidget : public UEleriBaseWidget public: UFUNCTION() - void OpenTradeWidget(UInventoryComponent* Inventory, const TArray& InRestrictTabs = TArray{}); + void SetupTradeWidget(UInventoryComponent* Inventory, const TArray& InRestrictTabs = TArray{}); protected: