From 17983a43d4e8e893eb460f02e9e1106109099777 Mon Sep 17 00:00:00 2001 From: Remi Regnault Date: Mon, 27 May 2024 17:30:18 +0200 Subject: [PATCH] :construction: working on settings page --- .../DouShouQi_App.xcodeproj/project.pbxproj | 16 +++++ .../Settings/CustomSwitchButton.swift | 48 +++++++++++++ .../Views/Menu/MainMenuView.swift | 1 + .../Views/Menu/SettingsView.swift | 71 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 DouShouQi_App/DouShouQi_App/Components/Settings/CustomSwitchButton.swift create mode 100644 DouShouQi_App/DouShouQi_App/Views/Menu/SettingsView.swift diff --git a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj index 13e4fcf..1407c7a 100644 --- a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj +++ b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj @@ -31,6 +31,8 @@ 649B59AE2BF64EAB002BAE38 /* AppImages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59AD2BF64EAB002BAE38 /* AppImages.swift */; }; 649B59B22BF65392002BAE38 /* TextStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59B12BF65392002BAE38 /* TextStyles.swift */; }; 649B59B42BF653E1002BAE38 /* ViewTitleTextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59B32BF653E1002BAE38 /* ViewTitleTextStyle.swift */; }; + EC05BFC42C04C3C4000F7B19 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC05BFC32C04C3C4000F7B19 /* SettingsView.swift */; }; + EC05BFC82C04D832000F7B19 /* CustomSwitchButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC05BFC72C04D832000F7B19 /* CustomSwitchButton.swift */; }; EC62C4EF2BFE367F0048CD0B /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4EE2BFE367F0048CD0B /* SwiftUIView.swift */; }; EC62C4F92C0371660048CD0B /* MusicPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4F82C0371660048CD0B /* MusicPlayer.swift */; }; EC62C4FB2C038BD20048CD0B /* PlayersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4FA2C038BD20048CD0B /* PlayersView.swift */; }; @@ -101,6 +103,8 @@ 649B59AD2BF64EAB002BAE38 /* AppImages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppImages.swift; sourceTree = ""; }; 649B59B12BF65392002BAE38 /* TextStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyles.swift; sourceTree = ""; }; 649B59B32BF653E1002BAE38 /* ViewTitleTextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTitleTextStyle.swift; sourceTree = ""; }; + EC05BFC32C04C3C4000F7B19 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; + EC05BFC72C04D832000F7B19 /* CustomSwitchButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSwitchButton.swift; sourceTree = ""; }; EC62C4EE2BFE367F0048CD0B /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = ""; }; EC62C4F82C0371660048CD0B /* MusicPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicPlayer.swift; sourceTree = ""; }; EC62C4FA2C038BD20048CD0B /* PlayersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayersView.swift; sourceTree = ""; }; @@ -248,6 +252,7 @@ children = ( 649ABF5A2BF60D78002E8894 /* MainMenuView.swift */, EC62C5082C0467240048CD0B /* SplashScreenView.swift */, + EC05BFC32C04C3C4000F7B19 /* SettingsView.swift */, ); path = Menu; sourceTree = ""; @@ -265,6 +270,7 @@ 649ABF5E2BF60ED5002E8894 /* Components */ = { isa = PBXGroup; children = ( + EC05BFC62C04D7C2000F7B19 /* Settings */, 643AB6912BFCEFB70018DA73 /* Game */, 645B4C1C2BFCC95000FD658A /* Player */, 649ABF5F2BF60F2D002E8894 /* MainMenuButton.swift */, @@ -314,6 +320,14 @@ path = TextStyles; sourceTree = ""; }; + EC05BFC62C04D7C2000F7B19 /* Settings */ = { + isa = PBXGroup; + children = ( + EC05BFC72C04D832000F7B19 /* CustomSwitchButton.swift */, + ); + path = Settings; + sourceTree = ""; + }; EC62C5022C045BB90048CD0B /* SoundPlayerClass */ = { isa = PBXGroup; children = ( @@ -477,11 +491,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + EC05BFC42C04C3C4000F7B19 /* SettingsView.swift in Sources */, 643AB69B2BFCFB5C0018DA73 /* HistoricView.swift in Sources */, 6458345E2BF5F92300E18321 /* ContentView.swift in Sources */, 649B59A92BF64C6A002BAE38 /* Colors.swift in Sources */, 649B59B42BF653E1002BAE38 /* ViewTitleTextStyle.swift in Sources */, EC62C5012C045B590048CD0B /* SoundPlayer.swift in Sources */, + EC05BFC82C04D832000F7B19 /* CustomSwitchButton.swift in Sources */, 645B4C252BFCD3C600FD658A /* ScoreBoardView.swift in Sources */, 649B59AE2BF64EAB002BAE38 /* AppImages.swift in Sources */, 649ABF602BF60F2D002E8894 /* MainMenuButton.swift in Sources */, diff --git a/DouShouQi_App/DouShouQi_App/Components/Settings/CustomSwitchButton.swift b/DouShouQi_App/DouShouQi_App/Components/Settings/CustomSwitchButton.swift new file mode 100644 index 0000000..871d815 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Components/Settings/CustomSwitchButton.swift @@ -0,0 +1,48 @@ +// +// CustomSwitchButton.swift +// DouShouQi_App +// +// Created by etudiant on 27/05/2024. +// + +import SwiftUI + +struct CustomSwitchButton: View { + + // Boolean + @Binding var IsOn: Bool + + // Image when Off + var imgNameIsOff: String + var imgIsOffWidth: CGFloat = 50 + var imgIsOffHeight: CGFloat = 50 + + // Image when Off + var imgNameIsOn: String + var imgIsOnWidth: CGFloat = 50 + var imgIsOnHeight: CGFloat = 50 + + var body: some View { + HStack { + Image(imgNameIsOff) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: imgIsOffWidth, height: imgIsOffHeight) + + Toggle("isOn", isOn: $IsOn) + .labelsHidden() + + Image(imgNameIsOn) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: imgIsOnWidth, height: imgIsOnHeight) + } + } +} + +struct CustomSwitchButton_Previews: PreviewProvider { + static var previews: some View { + @State var isOn: Bool = false + CustomSwitchButton(IsOn: $isOn, imgNameIsOff: AppImages.TitleImage, imgNameIsOn: AppImages.TitleImage) + } +} diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift index 6a893d5..e99136c 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -36,6 +36,7 @@ struct MainMenuView: View { MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound") MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound") MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound") + MainMenuButton(text: "Settings", destination: SettingsView(), sound: "TitleScreenButtonSound") } Image(AppImages.SemiLion) .resizable() diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/SettingsView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/SettingsView.swift new file mode 100644 index 0000000..a2c09f7 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/SettingsView.swift @@ -0,0 +1,71 @@ +// +// SettingsView.swift +// DouShouQi_App +// +// Created by etudiant on 27/05/2024. +// + +import SwiftUI + +extension String : Identifiable { + public var id: Self { return self } +} + +struct SettingsView: View { + + @State private var theme = false + @State private var choice = "English" + @State private var sound = false + + var body: some View { + VStack { + TitlePageFrame(Text: "Settings") + + VStack { + Divider() + + HStack { + Text("Theme") + .font(.headline) + + Spacer() + + CustomSwitchButton(IsOn: $theme, imgNameIsOff: AppImages.TitleImage, imgNameIsOn: AppImages.TitleImage) + } + + Divider() + + HStack { + Text("Language") + .font(.headline) + + Spacer() + + Picker("Sort", selection: $choice) { + ForEach(["English", "Français", "Español"]) { + Text($0) + } + } + .pickerStyle(.menu) + } + + Divider() + + VStack(alignment: .leading) { + Toggle("Sound", isOn: $sound) + .toggleStyle(.switch) + .font(.headline) + } + + Divider() + } + .padding(20) + + Spacer() + } + } +} + +#Preview { + SettingsView() +}