🚧 added SettingsVM, rework some views and components to support the SettingsVM

dev_vm_Settings
Rémi REGNAULT 1 year ago
parent 3fb4770608
commit a174135ebd

@ -34,6 +34,7 @@
649B59B22BF65392002BAE38 /* TextStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59B12BF65392002BAE38 /* TextStyles.swift */; };
649B59B42BF653E1002BAE38 /* ViewTitleTextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59B32BF653E1002BAE38 /* ViewTitleTextStyle.swift */; };
64D992722C06281B002ACBC6 /* SystemIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64D992712C06281B002ACBC6 /* SystemIcons.swift */; };
64E00BE32C08B1D500E90544 /* SettingsVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64E00BE22C08B1D500E90544 /* SettingsVM.swift */; };
EC05BFC42C04C3C4000F7B19 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC05BFC32C04C3C4000F7B19 /* SettingsView.swift */; };
EC05BFC82C04D832000F7B19 /* CustomSwitchButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC05BFC72C04D832000F7B19 /* CustomSwitchButton.swift */; };
EC62C4F92C0371660048CD0B /* MusicPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4F82C0371660048CD0B /* MusicPlayer.swift */; };
@ -110,6 +111,7 @@
649B59B12BF65392002BAE38 /* TextStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyles.swift; sourceTree = "<group>"; };
649B59B32BF653E1002BAE38 /* ViewTitleTextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTitleTextStyle.swift; sourceTree = "<group>"; };
64D992712C06281B002ACBC6 /* SystemIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemIcons.swift; sourceTree = "<group>"; };
64E00BE22C08B1D500E90544 /* SettingsVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsVM.swift; sourceTree = "<group>"; };
EC05BFC32C04C3C4000F7B19 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
EC05BFC72C04D832000F7B19 /* CustomSwitchButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSwitchButton.swift; sourceTree = "<group>"; };
EC62C4F82C0371660048CD0B /* MusicPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicPlayer.swift; sourceTree = "<group>"; };
@ -259,6 +261,7 @@
646FA83C2C072284001466BA /* ViewModel */ = {
isa = PBXGroup;
children = (
64E00BE12C08B1BF00E90544 /* Settings */,
646FA83F2C0730B4001466BA /* Game */,
);
path = ViewModel;
@ -347,6 +350,14 @@
path = TextStyles;
sourceTree = "<group>";
};
64E00BE12C08B1BF00E90544 /* Settings */ = {
isa = PBXGroup;
children = (
64E00BE22C08B1D500E90544 /* SettingsVM.swift */,
);
path = Settings;
sourceTree = "<group>";
};
EC05BFC62C04D7C2000F7B19 /* Settings */ = {
isa = PBXGroup;
children = (
@ -531,6 +542,7 @@
EC62C5012C045B590048CD0B /* SoundPlayer.swift in Sources */,
EC05BFC82C04D832000F7B19 /* CustomSwitchButton.swift in Sources */,
64D992722C06281B002ACBC6 /* SystemIcons.swift in Sources */,
64E00BE32C08B1D500E90544 /* SettingsVM.swift in Sources */,
645B4C252BFCD3C600FD658A /* ScoreBoardView.swift in Sources */,
649B59AE2BF64EAB002BAE38 /* AppImages.swift in Sources */,
649ABF602BF60F2D002E8894 /* MainMenuButton.swift in Sources */,

@ -0,0 +1,42 @@
//
// SettingsVM.swift
// DouShouQi_App
//
// Created by Rémi REGNAULT on 30/05/2024.
//
import Foundation
import SwiftUI
public enum Language: String, Identifiable {
case french, english, spanish
public var id: String {
return self.rawValue
}
public var litteral: String {
switch self {
case .french:
return "Français"
case .english:
return "English"
case .spanish:
return "Español"
}
}
static var list: [Language] {
return [.french, .english, .spanish]
}
}
class SettingsVM: ObservableObject {
// Properties
@Published var darkTheme: Bool = false
@Published var language: Language = Language.english
@Published var soundOn: Bool = true
init() {}
}

@ -36,7 +36,7 @@ struct MainMenuView: View {
MainMenuButton(text: "Historique", destination: HistoricView(historicVM: HistoricVM()), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Settings", destination: SettingsView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10)
MainMenuButton(text: "Settings", destination: SettingsView(settingsVM: SettingsVM()), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10)
}
Image(AppImages.SemiLion)
.resizable()

@ -7,15 +7,9 @@
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 = true
@ObservedObject var settingsVM: SettingsVM
var body: some View {
VStack {
@ -30,7 +24,7 @@ struct SettingsView: View {
Spacer()
CustomSwitchButton(IsOn: $theme, imgSystemNameIsOff: SystemIcons.LightTheme, imgSystemNameIsOn: SystemIcons.DarkTheme)
CustomSwitchButton(IsOn: $settingsVM.darkTheme, imgSystemNameIsOff: SystemIcons.LightTheme, imgSystemNameIsOn: SystemIcons.DarkTheme)
}
Divider()
@ -41,9 +35,9 @@ struct SettingsView: View {
Spacer()
Picker("Sort", selection: $choice) {
ForEach(["English", "Français", "Español"]) {
Text($0)
Picker("Language", selection: $settingsVM.language) {
ForEach(Language.list) { language in
Text(language.litteral).tag(language)
}
}
.pickerStyle(.menu)
@ -52,12 +46,12 @@ struct SettingsView: View {
Divider()
HStack {
Text("Theme")
Text("Sound")
.font(.headline)
Spacer()
CustomSwitchButton(IsOn: $sound, imgSystemNameIsOff: SystemIcons.SoundOff, imgSystemNameIsOn: SystemIcons.SoundOn)
CustomSwitchButton(IsOn: $settingsVM.soundOn, imgSystemNameIsOff: SystemIcons.SoundOff, imgSystemNameIsOn: SystemIcons.SoundOn)
}
Divider()
@ -71,6 +65,6 @@ struct SettingsView: View {
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
SettingsView(settingsVM: SettingsVM())
}
}

Loading…
Cancel
Save