Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Content/G2I_Game/UI/DA_WidgetsCatalog.uasset
Binary file not shown.
Binary file modified Content/G2I_Game/UI/Elements/DT_RichTextStyles.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/G2I_Game/UI/Menu/WB_MainMenu.uasset
Binary file not shown.
Binary file modified Content/G2I_Game/UI/StringsRu/ST_CommonUI.uasset
Binary file not shown.
Binary file added Content/G2I_Game/UI/StringsRu/ST_Gallery.uasset
Binary file not shown.
16 changes: 16 additions & 0 deletions Source/G2I/Private/UI/G2IUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Menu/Elements/G2IControlListItem.h"
#include "Menu/Elements/G2IControlRow.h"
#include "Menu/Elements/TextRow/G2ITextMultiValuePropertyRow.h"
#include "Menu/Gallery/G2IGalleryWidget.h"
#include "Menu/Options/G2ICharacterControlsWidget.h"
#include "Menu/Options/G2IOptionsWidget.h"

Expand Down Expand Up @@ -644,6 +645,21 @@ void UG2IUIManager::SetActionControl(const FText& ActionName, const FText& KeyNa
}
}

void UG2IUIManager::SetupGalleryWidget(const TFunction<void()>& NewBackAction) const
{
if (!ensure(DisplayManager))
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find %s"), *GetName(),
*UG2IUIDisplayManager::StaticClass()->GetName());
return;
}
if (UG2IGalleryWidget *Widget = Cast<UG2IGalleryWidget>(
DisplayManager->GetWidget(EG2IWidgetNames::Gallery)))
{
Widget->OnBack = NewBackAction;
}
}

void UG2IUIManager::SetupControlsWidget(UWidgetSwitcher* CharacterControlsSwitcher) const
{
if (!ensure(CharacterControlsSwitcher))
Expand Down
22 changes: 22 additions & 0 deletions Source/G2I/Private/UI/Widgets/Menu/G2IMainMenuWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ void UG2IMainMenuWidget::BindDelegates()
{
UE_LOG(LogG2I, Error, TEXT("Creators button isn't existed in %s"), *GetName());
}
if (ensure(GalleryButton))
{
GalleryButton->OnClicked.AddDynamic(this, &ThisClass::OnGalleryButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("Gallery button isn't existed in %s"), *GetName());
}
if (ensure(QuitGameButton))
{
QuitGameButton->OnClicked.AddDynamic(this, &ThisClass::OnQuitGameButtonClicked);
Expand Down Expand Up @@ -122,6 +130,20 @@ void UG2IMainMenuWidget::OnOptionsButtonClicked()
UIManager->SetupOptionsWidget(GetShowCurrentWidgetFunction());
}

void UG2IMainMenuWidget::OnGalleryButtonClicked()
{
if (!ensure(UIManager))
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find %s"), *GetName(),
*UG2IUIManager::StaticClass()->GetName());
return;
}
UIManager->HideWidget(EG2IWidgetNames::MainMenu);
UIManager->OpenWidget(EG2IWidgetNames::Gallery);

UIManager->SetupGalleryWidget(GetShowCurrentWidgetFunction());
}

void UG2IMainMenuWidget::OnQuitGameButtonClicked()
{
if (!ensure(UIManager))
Expand Down
269 changes: 269 additions & 0 deletions Source/G2I/Private/UI/Widgets/Menu/Gallery/G2IGalleryWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
#include "Menu/Gallery/G2IGalleryWidget.h"
#include "G2I.h"
#include "G2IUIManager.h"
#include "G2IWidgetNames.h"
#include "Components/Button.h"
#include "Components/Image.h"

void UG2IGalleryWidget::InitializeAfterManagerLoading()
{
Super::InitializeAfterManagerLoading();

InitializeDefaults();
BindDelegates();
}

void UG2IGalleryWidget::InitializeDefaults()
{
LockEmptySections();
OpenStartImage();
}

void UG2IGalleryWidget::LockEmptySections() const
{
PreviousButton->SetIsEnabled(false);
NextButton->SetIsEnabled(false);
if (IsSectionEmpty(EG2IGallerySectionsName::Locations))
{
LocationsGalleryButton->SetIsEnabled(false);
}
if (IsSectionEmpty(EG2IGallerySectionsName::Environment))
{
EnvironmentGalleryButton->SetIsEnabled(false);
}
if (IsSectionEmpty(EG2IGallerySectionsName::MainCharacters))
{
MainCharactersGalleryButton->SetIsEnabled(false);
}
if (IsSectionEmpty(EG2IGallerySectionsName::MinorCharacters))
{
MinorCharactersGalleryButton->SetIsEnabled(false);
}
if (IsSectionEmpty(EG2IGallerySectionsName::Puzzles))
{
PuzzlesGalleryButton->SetIsEnabled(false);
}
}

void UG2IGalleryWidget::OpenStartImage()
{
if (LocationsGalleryButton->GetIsEnabled())
{
OpenSection(EG2IGallerySectionsName::Locations);
return;
}
if (EnvironmentGalleryButton->GetIsEnabled())
{
OpenSection(EG2IGallerySectionsName::Environment);
return;
}
if (MainCharactersGalleryButton->GetIsEnabled())
{
OpenSection(EG2IGallerySectionsName::MainCharacters);
return;
}
if (MinorCharactersGalleryButton->GetIsEnabled())
{
OpenSection(EG2IGallerySectionsName::MinorCharacters);
return;
}
if (PuzzlesGalleryButton->GetIsEnabled())
{
OpenSection(EG2IGallerySectionsName::Puzzles);
return;
}
}

void UG2IGalleryWidget::BindDelegates()
{
if (ensure(BackButton))
{
BackButton->OnClicked.AddDynamic(this, &ThisClass::OnBackButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find BackButton"), *GetName());
}
if (ensure(PreviousButton))
{
PreviousButton->OnClicked.AddDynamic(this, &ThisClass::OnPreviousButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find PreviousButton"), *GetName());
}
if (ensure(NextButton))
{
NextButton->OnClicked.AddDynamic(this, &ThisClass::OnNextButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find NextButton"), *GetName());
}
if (ensure(LocationsGalleryButton))
{
LocationsGalleryButton->OnClicked.AddDynamic(this, &ThisClass::OnLocationsGalleryButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find Button of Locations Gallery"), *GetName());
}
if (ensure(EnvironmentGalleryButton))
{
EnvironmentGalleryButton->OnClicked.AddDynamic(this, &ThisClass::OnEnvironmentGalleryButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find Button of Environment Gallery"), *GetName());
}
if (ensure(MainCharactersGalleryButton))
{
MainCharactersGalleryButton->OnClicked.AddDynamic(this, &ThisClass::OnMainCharactersGalleryButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find Button of Main Characters Gallery"), *GetName());
}
if (ensure(MinorCharactersGalleryButton))
{
MinorCharactersGalleryButton->OnClicked.AddDynamic(this, &ThisClass::OnMinorCharactersGalleryButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find Button of Minor Characters Gallery"), *GetName());
}
if (ensure(PuzzlesGalleryButton))
{
PuzzlesGalleryButton->OnClicked.AddDynamic(this, &ThisClass::OnPuzzlesGalleryButtonClicked);
}
else
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find Button of Puzzles Gallery"), *GetName());
}
}

void UG2IGalleryWidget::OnBackButtonClicked()
{
if (OnBack)
{
OnBack();
}
else
{
UE_LOG(LogG2I, Log, TEXT("Back function is undefined in %s"), *GetName());
}

if (!ensure(UIManager))
{
UE_LOG(LogG2I, Error, TEXT("%s: Couldn't find %s"), *GetName(),
*UG2IUIManager::StaticClass()->GetName());
return;
}
UIManager->CloseWidget(EG2IWidgetNames::Gallery);
}

void UG2IGalleryWidget::OnPreviousButtonClicked()
{
OpenImage(CurrentIndex - 1);
}

void UG2IGalleryWidget::OnNextButtonClicked()
{
OpenImage(CurrentIndex + 1);
}

void UG2IGalleryWidget::OpenImage(const int32 Index)
{
const auto* SectionPtr = Sections.Find(CurrentSection);
if (!SectionPtr || SectionPtr->SectionImages.IsEmpty())
{
UE_LOG(LogG2I, Warning, TEXT("%s: Attempt to select empty Gallery Section"), *GetName());
return;
}
const int32 NewIndex = (Index + SectionPtr->SectionImages.Num()) % SectionPtr->SectionImages.Num();
if (SetTexture(SectionPtr->SectionImages[NewIndex]))
{
CurrentIndex = NewIndex;
}
}

bool UG2IGalleryWidget::SetTexture(UTexture2D* NewTexture) const
{
if (!NewTexture)
{
UE_LOG(LogG2I, Warning, TEXT("%s: Attempt to set null texture"), *GetName());
return false;
}
CurrentImage->SetBrushFromTexture(NewTexture, true);
return true;
}

bool UG2IGalleryWidget::IsSectionEmpty(const EG2IGallerySectionsName SectionName) const
{
if (const auto *Section = Sections.Find(SectionName))
{
return Section->SectionImages.IsEmpty();
}
return true;
}

void UG2IGalleryWidget::OpenNewSection(const EG2IGallerySectionsName NewSectionName)
{
if (CurrentSection == NewSectionName)
{
return;
}
OpenSection(NewSectionName);
}

void UG2IGalleryWidget::OpenSection(const EG2IGallerySectionsName SectionName)
{
const auto* SectionPtr = Sections.Find(SectionName);
if (!ensure(SectionPtr) || !ensure(!SectionPtr->SectionImages.IsEmpty()))
{
UE_LOG(LogG2I, Error, TEXT("%s: Attempt to select empty Gallery Section"), *GetName());
return;
}

if (SectionPtr->SectionImages.Num() > 1)
{
PreviousButton->SetIsEnabled(true);
NextButton->SetIsEnabled(true);
}
else
{
PreviousButton->SetIsEnabled(false);
NextButton->SetIsEnabled(false);
}

if (SetTexture(SectionPtr->SectionImages[0]))
{
CurrentSection = SectionName;
CurrentIndex = 0;
}
}

void UG2IGalleryWidget::OnLocationsGalleryButtonClicked()
{
OpenNewSection(EG2IGallerySectionsName::Locations);
}

void UG2IGalleryWidget::OnEnvironmentGalleryButtonClicked()
{
OpenNewSection(EG2IGallerySectionsName::Environment);
}

void UG2IGalleryWidget::OnMainCharactersGalleryButtonClicked()
{
OpenNewSection(EG2IGallerySectionsName::MainCharacters);
}

void UG2IGalleryWidget::OnMinorCharactersGalleryButtonClicked()
{
OpenNewSection(EG2IGallerySectionsName::MinorCharacters);
}

void UG2IGalleryWidget::OnPuzzlesGalleryButtonClicked()
{
OpenNewSection(EG2IGallerySectionsName::Puzzles);
}
3 changes: 2 additions & 1 deletion Source/G2I/Public/DataDefinitions/Enums/G2IWidgetNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ enum class EG2IWidgetNames : uint8
EngineerControlsOptions UMETA(DisplayName = "Controls options of engineer widget"),
DaughterControlsOptions UMETA(DisplayName = "Controls options of daughter widget"),
ControlRow UMETA(DisplayName = "Row of control's option"),
LevelLoadingScreen UMETA(DisplayName = "Loading screen widget for levels loading")
LevelLoadingScreen UMETA(DisplayName = "Loading screen widget for levels loading"),
Gallery UMETA(DisplayName = "Gallery widget"),
};
3 changes: 3 additions & 0 deletions Source/G2I/Public/UI/G2IUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,7 @@ class G2I_API UG2IUIManager : public UGameInstanceSubsystem
void ApplyPropertyValue(const UG2IPropertyRow* PropertyRow) const;
void SavePropertyValue(const UG2IPropertyRow* PropertyRow) const;
void SetActionControl(const FText& ActionName, const FText& KeyName, UListView* ControlsList) const;

// ==================== GALLERY WIDGETS ====================
void SetupGalleryWidget(const TFunction<void()>& NewBackAction) const;
};
6 changes: 6 additions & 0 deletions Source/G2I/Public/UI/Widgets/Menu/G2IMainMenuWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class G2I_API UG2IMainMenuWidget : public UG2IUserWidget
UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> CreatorsButton;

UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> GalleryButton;

UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> QuitGameButton;

Expand All @@ -38,6 +41,9 @@ class G2I_API UG2IMainMenuWidget : public UG2IUserWidget
UFUNCTION()
void OnOptionsButtonClicked();

UFUNCTION()
void OnGalleryButtonClicked();

UFUNCTION()
void OnQuitGameButtonClicked();

Expand Down
Loading