Skip to content

Commit

Permalink
Merge pull request #71 from S1yGus/70-windowed-mode
Browse files Browse the repository at this point in the history
Add screen mode toggle
  • Loading branch information
S1yGus authored Apr 20, 2024
2 parents f307e61 + b9e2656 commit 3eab67e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Config/DefaultGameUserSettings.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[/Script/Snake_Game.SG_GameUserSettings]
bUseVSync=False
FullscreenMode=1
LastConfirmedFullscreenMode=1
Version=5
Binary file modified Content/UI/WBP_Menu.uasset
Binary file not shown.
20 changes: 20 additions & 0 deletions Source/Snake_Game/UI/SG_MenuWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void USG_MenuWidget::NativeOnInitialized()
StartGameButton->OnClicked.AddDynamic(this, &ThisClass::OnStartGame);
check(QuitGameButton);
QuitGameButton->OnClicked.AddDynamic(this, &ThisClass::OnQuitGame);
check(ToggleScreenModeButton);
ToggleScreenModeButton->OnClicked.AddDynamic(this, &ThisClass::OnToggleScreenMode);

if (auto* GameUserSettings = USG_GameUserSettings::Get())
{
Expand All @@ -36,6 +38,24 @@ void USG_MenuWidget::OnQuitGame()
UKismetSystemLibrary::QuitGame(this, nullptr, EQuitPreference::Type::Quit, false);
}

void USG_MenuWidget::OnToggleScreenMode()
{
if (auto* GameUserSettings = USG_GameUserSettings::Get())
{
const EWindowMode::Type CurrentMode = GameUserSettings->GetFullscreenMode();
if (TArray<FIntPoint> Resolutions; CurrentMode != EWindowMode::Windowed)
{
UKismetSystemLibrary::GetConvenientWindowedResolutions(Resolutions);
if (!Resolutions.IsEmpty())
{
GameUserSettings->SetScreenResolution(Resolutions[0]);
}
}
GameUserSettings->SetFullscreenMode(CurrentMode == EWindowMode::Type::Windowed ? EWindowMode::Type::WindowedFullscreen : EWindowMode::Type::Windowed);
GameUserSettings->ApplyResolutionSettings(false);
}
}

void USG_MenuWidget::OnComboBoxSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{
if (auto* GameUserSettings = USG_GameUserSettings::Get(); GameUserSettings && SelectionType != ESelectInfo::Type::Direct)
Expand Down
6 changes: 6 additions & 0 deletions Source/Snake_Game/UI/SG_MenuWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SNAKE_GAME_API USG_MenuWidget : public UUserWidget
UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> QuitGameButton;

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

UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> SpeedComboBox;

Expand All @@ -49,6 +52,9 @@ class SNAKE_GAME_API USG_MenuWidget : public UUserWidget
UFUNCTION()
void OnQuitGame();

UFUNCTION()
void OnToggleScreenMode();

UFUNCTION()
void OnComboBoxSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
#pragma endregion Functions with Unreal Header Tool metadata
Expand Down

0 comments on commit 3eab67e

Please sign in to comment.